tlshandshake/lib.go

81 satır
3.1 KiB
Go
Ham Kalıcı Bağlantı Normal Görünüm Geçmiş

2019-05-11 00:09:36 +01:00
package tlshandshake
import (
"fmt"
2019-05-12 19:06:55 +01:00
"os"
2019-05-11 00:09:36 +01:00
2019-05-23 18:59:58 +01:00
"github.com/henrydcase/th5"
2019-05-11 00:09:36 +01:00
)
2019-05-12 19:06:55 +01:00
type Client struct {
2019-05-23 18:59:58 +01:00
TLS th5.Config
2019-05-12 19:06:55 +01:00
Addr string
}
2019-05-11 00:09:36 +01:00
var TlsVersionToName = map[uint16]string{
2019-05-23 18:59:58 +01:00
th5.VersionTLS10: "1.0",
th5.VersionTLS11: "1.1",
th5.VersionTLS12: "1.2",
th5.VersionTLS13: "1.3",
2019-05-11 00:09:36 +01:00
}
var CipherSuiteIdToName = map[uint16]string{
2019-05-23 18:59:58 +01:00
th5.TLS_AES_128_GCM_SHA256: "TLS_AES_128_GCM_SHA256",
th5.TLS_AES_256_GCM_SHA384: "TLS_AES_256_GCM_SHA384",
th5.TLS_CHACHA20_POLY1305_SHA256: "TLS_CHACHA20_POLY1305_SHA256",
th5.TLS_RSA_WITH_RC4_128_SHA: "TLS_RSA_WITH_RC4_128_SHA",
th5.TLS_RSA_WITH_3DES_EDE_CBC_SHA: "TLS_RSA_WITH_3DES_EDE_CBC_SHA",
th5.TLS_RSA_WITH_AES_128_CBC_SHA: "TLS_RSA_WITH_AES_128_CBC_SHA",
th5.TLS_RSA_WITH_AES_256_CBC_SHA: "TLS_RSA_WITH_AES_256_CBC_SHA",
th5.TLS_RSA_WITH_AES_128_CBC_SHA256: "TLS_RSA_WITH_AES_128_CBC_SHA256",
th5.TLS_RSA_WITH_AES_128_GCM_SHA256: "TLS_RSA_WITH_AES_128_GCM_SHA256",
th5.TLS_RSA_WITH_AES_256_GCM_SHA384: "TLS_RSA_WITH_AES_256_GCM_SHA384",
th5.TLS_ECDHE_ECDSA_WITH_RC4_128_SHA: "TLS_ECDHE_ECDSA_WITH_RC4_128_SHA",
th5.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA: "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA",
th5.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA: "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA",
th5.TLS_ECDHE_RSA_WITH_RC4_128_SHA: "TLS_ECDHE_RSA_WITH_RC4_128_SHA",
th5.TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA: "TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA",
th5.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA: "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA",
th5.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA: "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA",
th5.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256: "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256",
th5.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256: "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256",
th5.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256: "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256",
th5.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256: "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256",
th5.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384: "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384",
th5.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384: "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384",
th5.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305: "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305",
th5.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305: "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305",
2019-05-11 00:09:36 +01:00
}
var NamedGroupsToName = map[uint16]string{
2019-05-23 18:59:58 +01:00
uint16(th5.HybridSIDHp503Curve25519): "X25519-SIDHp503",
uint16(th5.HybridSIKEp503Curve25519): "X25519-SIKEp503",
uint16(th5.X25519): "X25519",
uint16(th5.CurveP256): "P-256",
uint16(th5.CurveP384): "P-384",
uint16(th5.CurveP521): "P-521",
2019-05-11 00:09:36 +01:00
}
func NewClient() *Client {
var c Client
c.TLS.InsecureSkipVerify = true
return &c
}
func (c *Client) Run() {
2019-05-23 18:59:58 +01:00
con, err := th5.Dial("tcp", c.Addr, &c.TLS)
2019-05-11 00:09:36 +01:00
if err != nil {
fmt.Printf("handshake failed: %v\n\n", err)
2019-05-12 19:06:55 +01:00
os.Exit(1)
2019-05-11 00:09:36 +01:00
}
defer con.Close()
2019-05-12 19:06:55 +01:00
printTlsState(con)
2019-05-11 00:09:36 +01:00
}
func (c *Client) Clone() *Client {
var clone Client
clone.TLS = *c.TLS.Clone()
clone.Addr = c.Addr
return &clone
}