readClientHello reads a ClientHello message and selects the protocol version.
(ctx context.Context)
| 129 | |
| 130 | // readClientHello reads a ClientHello message and selects the protocol version. |
| 131 | func (c *Conn) readClientHello(ctx context.Context) (*clientHelloMsg, error) { |
| 132 | msg, err := c.readHandshake() |
| 133 | if err != nil { |
| 134 | return nil, err |
| 135 | } |
| 136 | clientHello, ok := msg.(*clientHelloMsg) |
| 137 | if !ok { |
| 138 | c.sendAlert(alertUnexpectedMessage) |
| 139 | return nil, unexpectedMessageError(clientHello, msg) |
| 140 | } |
| 141 | |
| 142 | var configForClient *Config |
| 143 | originalConfig := c.config |
| 144 | if c.config.GetConfigForClient != nil { |
| 145 | chi := clientHelloInfo(ctx, c, clientHello) |
| 146 | if configForClient, err = c.config.GetConfigForClient(chi); err != nil { |
| 147 | c.sendAlert(alertInternalError) |
| 148 | return nil, err |
| 149 | } else if configForClient != nil { |
| 150 | c.config = configForClient |
| 151 | } |
| 152 | } |
| 153 | c.ticketKeys = originalConfig.ticketKeys(configForClient) |
| 154 | |
| 155 | clientVersions := clientHello.supportedVersions |
| 156 | if len(clientHello.supportedVersions) == 0 { |
| 157 | clientVersions = supportedVersionsFromMax(clientHello.vers) |
| 158 | } |
| 159 | c.vers, ok = c.config.mutualVersion(roleClient, clientVersions) |
| 160 | if !ok { |
| 161 | c.sendAlert(alertProtocolVersion) |
| 162 | return nil, fmt.Errorf("tls: client offered only unsupported versions: %x", clientVersions) |
| 163 | } |
| 164 | c.haveVers = true |
| 165 | c.in.version = c.vers |
| 166 | c.out.version = c.vers |
| 167 | |
| 168 | return clientHello, nil |
| 169 | } |
| 170 | |
| 171 | func (hs *serverHandshakeState) processClientHello() error { |
| 172 | c := hs.c |
no test coverage detected