|
|
@ -66,6 +66,33 @@ func (c *UConn) HandshakeAddress() net.Address {
|
|
|
|
return net.ParseAddress(state.ServerName)
|
|
|
|
return net.ParseAddress(state.ServerName)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// WebsocketHandshake basically calls UConn.Handshake inside it but it will only send
|
|
|
|
|
|
|
|
// http/1.1 in its ALPN.
|
|
|
|
|
|
|
|
func (c *UConn) WebsocketHandshake() error {
|
|
|
|
|
|
|
|
// Build the handshake state. This will apply every variable of the TLS of the
|
|
|
|
|
|
|
|
// fingerprint in the UConn
|
|
|
|
|
|
|
|
if err := c.BuildHandshakeState(); err != nil {
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Iterate over extensions and check for utls.ALPNExtension
|
|
|
|
|
|
|
|
hasALPNExtension := false
|
|
|
|
|
|
|
|
for _, extension := range c.Extensions {
|
|
|
|
|
|
|
|
if alpn, ok := extension.(*utls.ALPNExtension); ok {
|
|
|
|
|
|
|
|
hasALPNExtension = true
|
|
|
|
|
|
|
|
alpn.AlpnProtocols = []string{"http/1.1"}
|
|
|
|
|
|
|
|
break
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if !hasALPNExtension { // Append extension if doesn't exists
|
|
|
|
|
|
|
|
c.Extensions = append(c.Extensions, &utls.ALPNExtension{AlpnProtocols: []string{"http/1.1"}})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Rebuild the client hello and do the handshake
|
|
|
|
|
|
|
|
if err := c.BuildHandshakeState(); err != nil {
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return c.Handshake()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (c *UConn) NegotiatedProtocol() (name string, mutual bool) {
|
|
|
|
func (c *UConn) NegotiatedProtocol() (name string, mutual bool) {
|
|
|
|
state := c.ConnectionState()
|
|
|
|
state := c.ConnectionState()
|
|
|
|
return state.NegotiatedProtocol, state.NegotiatedProtocolIsMutual
|
|
|
|
return state.NegotiatedProtocol, state.NegotiatedProtocolIsMutual
|
|
|
|