github.com/ooni/psiphon/tunnel-core@v0.0.0-20230105123940-fe12a24c96ee/oovendor/quic-go/internal/qtls/go115.go (about) 1 //go:build go1.15 && !go1.16 2 // +build go1.15,!go1.16 3 4 package qtls 5 6 import ( 7 "crypto" 8 "crypto/cipher" 9 "crypto/tls" 10 "net" 11 "unsafe" 12 13 "github.com/ooni/psiphon/tunnel-core/oovendor/qtls-go1-15" 14 ) 15 16 type ( 17 // Alert is a TLS alert 18 Alert = qtls.Alert 19 // A Certificate is qtls.Certificate. 20 Certificate = qtls.Certificate 21 // CertificateRequestInfo contains inforamtion about a certificate request. 22 CertificateRequestInfo = qtls.CertificateRequestInfo 23 // A CipherSuiteTLS13 is a cipher suite for TLS 1.3 24 CipherSuiteTLS13 = qtls.CipherSuiteTLS13 25 // ClientHelloInfo contains information about a ClientHello. 26 ClientHelloInfo = qtls.ClientHelloInfo 27 // ClientSessionCache is a cache used for session resumption. 28 ClientSessionCache = qtls.ClientSessionCache 29 // ClientSessionState is a state needed for session resumption. 30 ClientSessionState = qtls.ClientSessionState 31 // A Config is a qtls.Config. 32 Config = qtls.Config 33 // A Conn is a qtls.Conn. 34 Conn = qtls.Conn 35 // ConnectionState contains information about the state of the connection. 36 ConnectionState = qtls.ConnectionStateWith0RTT 37 // EncryptionLevel is the encryption level of a message. 38 EncryptionLevel = qtls.EncryptionLevel 39 // Extension is a TLS extension 40 Extension = qtls.Extension 41 // ExtraConfig is the qtls.ExtraConfig 42 ExtraConfig = qtls.ExtraConfig 43 // RecordLayer is a qtls RecordLayer. 44 RecordLayer = qtls.RecordLayer 45 ) 46 47 const ( 48 // EncryptionHandshake is the Handshake encryption level 49 EncryptionHandshake = qtls.EncryptionHandshake 50 // Encryption0RTT is the 0-RTT encryption level 51 Encryption0RTT = qtls.Encryption0RTT 52 // EncryptionApplication is the application data encryption level 53 EncryptionApplication = qtls.EncryptionApplication 54 ) 55 56 // AEADAESGCMTLS13 creates a new AES-GCM AEAD for TLS 1.3 57 func AEADAESGCMTLS13(key, fixedNonce []byte) cipher.AEAD { 58 return qtls.AEADAESGCMTLS13(key, fixedNonce) 59 } 60 61 // Client returns a new TLS client side connection. 62 func Client(conn net.Conn, config *Config, extraConfig *ExtraConfig) *Conn { 63 return qtls.Client(conn, config, extraConfig) 64 } 65 66 // Server returns a new TLS server side connection. 67 func Server(conn net.Conn, config *Config, extraConfig *ExtraConfig) *Conn { 68 return qtls.Server(conn, config, extraConfig) 69 } 70 71 func GetConnectionState(conn *Conn) ConnectionState { 72 return conn.ConnectionStateWith0RTT() 73 } 74 75 // ToTLSConnectionState extracts the tls.ConnectionState 76 func ToTLSConnectionState(cs ConnectionState) tls.ConnectionState { 77 return cs.ConnectionState 78 } 79 80 type cipherSuiteTLS13 struct { 81 ID uint16 82 KeyLen int 83 AEAD func(key, fixedNonce []byte) cipher.AEAD 84 Hash crypto.Hash 85 } 86 87 //go:linkname cipherSuiteTLS13ByID github.com/ooni/psiphon/tunnel-core/oovendor/qtls-go1-15.cipherSuiteTLS13ByID 88 func cipherSuiteTLS13ByID(id uint16) *cipherSuiteTLS13 89 90 // CipherSuiteTLS13ByID gets a TLS 1.3 cipher suite. 91 func CipherSuiteTLS13ByID(id uint16) *CipherSuiteTLS13 { 92 val := cipherSuiteTLS13ByID(id) 93 cs := (*cipherSuiteTLS13)(unsafe.Pointer(val)) 94 return &qtls.CipherSuiteTLS13{ 95 ID: cs.ID, 96 KeyLen: cs.KeyLen, 97 AEAD: cs.AEAD, 98 Hash: cs.Hash, 99 } 100 } 101 102 // [Psiphon] 103 104 func ReadClientHelloRandom(data []byte) ([]byte, error) { 105 return qtls.ReadClientHelloRandom(data) 106 }