| 47 | } |
| 48 | |
| 49 | func readClientHello(reader io.Reader) (*tls.ClientHelloInfo, error) { |
| 50 | var hello *tls.ClientHelloInfo |
| 51 | |
| 52 | // Note that Handshake always fails because the readOnlyConn is not a real connection. |
| 53 | // As long as the Client Hello is successfully read, the failure should only happen after GetConfigForClient is called, |
| 54 | // so we only care about the error if hello was never set. |
| 55 | err := tls.Server(readOnlyConn{reader: reader}, &tls.Config{ |
| 56 | GetConfigForClient: func(argHello *tls.ClientHelloInfo) (*tls.Config, error) { |
| 57 | hello = &tls.ClientHelloInfo{} |
| 58 | *hello = *argHello |
| 59 | return nil, nil |
| 60 | }, |
| 61 | }).Handshake() |
| 62 | |
| 63 | if hello == nil { |
| 64 | return nil, err |
| 65 | } |
| 66 | return hello, nil |
| 67 | } |
| 68 | |
| 69 | type readOnlyConn struct { |
| 70 | reader io.Reader |