Code formatting for TRIS test client and server
This commit is contained in:
parent
9557e92e52
commit
3f720fc50c
@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
|
"crypto/x509"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -10,7 +11,6 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
"crypto/x509"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type ZeroRTT_t int
|
type ZeroRTT_t int
|
||||||
@ -18,21 +18,21 @@ type PubKeyAlgo_t int
|
|||||||
|
|
||||||
// Bitset
|
// Bitset
|
||||||
const (
|
const (
|
||||||
ZeroRTT_None ZeroRTT_t = 0
|
ZeroRTT_None ZeroRTT_t = 0
|
||||||
ZeroRTT_Offer = 1 << 0
|
ZeroRTT_Offer = 1 << 0
|
||||||
ZeroRTT_Accept = 1 << 1
|
ZeroRTT_Accept = 1 << 1
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
PubKeyRSA PubKeyAlgo_t = iota
|
PubKeyRSA PubKeyAlgo_t = iota
|
||||||
PubKeyECDSA
|
PubKeyECDSA
|
||||||
)
|
)
|
||||||
|
|
||||||
type server struct {
|
type server struct {
|
||||||
Address string
|
Address string
|
||||||
ZeroRTT ZeroRTT_t
|
ZeroRTT ZeroRTT_t
|
||||||
PubKey PubKeyAlgo_t
|
PubKey PubKeyAlgo_t
|
||||||
ClientAuthMethod tls.ClientAuthType
|
ClientAuthMethod tls.ClientAuthType
|
||||||
}
|
}
|
||||||
|
|
||||||
var tlsVersionToName = map[uint16]string{
|
var tlsVersionToName = map[uint16]string{
|
||||||
@ -46,11 +46,11 @@ var tlsVersionToName = map[uint16]string{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewServer() *server {
|
func NewServer() *server {
|
||||||
s := new(server)
|
s := new(server)
|
||||||
s.ClientAuthMethod = tls.NoClientCert
|
s.ClientAuthMethod = tls.NoClientCert
|
||||||
s.ZeroRTT = ZeroRTT_None
|
s.ZeroRTT = ZeroRTT_None
|
||||||
s.Address = "0.0.0.1:443"
|
s.Address = "0.0.0.1:443"
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *server) start() {
|
func (s *server) start() {
|
||||||
@ -62,7 +62,7 @@ func (s *server) start() {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
var Max0RTTDataSize uint32
|
var Max0RTTDataSize uint32
|
||||||
if ((s.ZeroRTT&ZeroRTT_Offer) == ZeroRTT_Offer) {
|
if (s.ZeroRTT & ZeroRTT_Offer) == ZeroRTT_Offer {
|
||||||
Max0RTTDataSize = 100 * 1024
|
Max0RTTDataSize = 100 * 1024
|
||||||
}
|
}
|
||||||
var keyLogWriter io.Writer
|
var keyLogWriter io.Writer
|
||||||
@ -82,7 +82,7 @@ func (s *server) start() {
|
|||||||
TLSConfig: &tls.Config{
|
TLSConfig: &tls.Config{
|
||||||
Certificates: []tls.Certificate{cert},
|
Certificates: []tls.Certificate{cert},
|
||||||
Max0RTTDataSize: Max0RTTDataSize,
|
Max0RTTDataSize: Max0RTTDataSize,
|
||||||
Accept0RTTData: (s.ZeroRTT&ZeroRTT_Accept) == ZeroRTT_Accept,
|
Accept0RTTData: (s.ZeroRTT & ZeroRTT_Accept) == ZeroRTT_Accept,
|
||||||
KeyLogWriter: keyLogWriter,
|
KeyLogWriter: keyLogWriter,
|
||||||
GetConfigForClient: func(*tls.ClientHelloInfo) (*tls.Config, error) {
|
GetConfigForClient: func(*tls.ClientHelloInfo) (*tls.Config, error) {
|
||||||
// If we send the first flight too fast, NSS sends empty early data.
|
// If we send the first flight too fast, NSS sends empty early data.
|
||||||
@ -91,7 +91,7 @@ func (s *server) start() {
|
|||||||
},
|
},
|
||||||
MaxVersion: tls.VersionTLS13,
|
MaxVersion: tls.VersionTLS13,
|
||||||
ClientAuth: s.ClientAuthMethod,
|
ClientAuth: s.ClientAuthMethod,
|
||||||
ClientCAs: clientCAs,
|
ClientCAs: clientCAs,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
log.Fatal(httpServer.ListenAndServeTLS("", ""))
|
log.Fatal(httpServer.ListenAndServeTLS("", ""))
|
||||||
@ -99,32 +99,32 @@ func (s *server) start() {
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
s := NewServer()
|
s := NewServer()
|
||||||
|
|
||||||
arg_addr := flag.String("b" , "0.0.0.0:443", "Address:port used for binding")
|
arg_addr := flag.String("b", "0.0.0.0:443", "Address:port used for binding")
|
||||||
arg_palg := flag.String("palg", "rsa", "Public algorithm to use: rsa or ecdsa")
|
arg_palg := flag.String("palg", "rsa", "Public algorithm to use: rsa or ecdsa")
|
||||||
arg_zerortt := flag.String("rtt0", "n", `0-RTT, accepts following values [n: None, a: Accept, o: Offer, oa: Offer and Accept]`)
|
arg_zerortt := flag.String("rtt0", "n", `0-RTT, accepts following values [n: None, a: Accept, o: Offer, oa: Offer and Accept]`)
|
||||||
arg_confirm := flag.Bool("rtt0ack", false, "0-RTT confirm")
|
arg_confirm := flag.Bool("rtt0ack", false, "0-RTT confirm")
|
||||||
arg_clientauth := flag.Bool("cliauth", false, "Performs client authentication (RequireAndVerifyClientCert used)")
|
arg_clientauth := flag.Bool("cliauth", false, "Performs client authentication (RequireAndVerifyClientCert used)")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
s.Address=*arg_addr
|
s.Address = *arg_addr
|
||||||
|
|
||||||
if *arg_palg == "ecdsa" {
|
if *arg_palg == "ecdsa" {
|
||||||
s.PubKey = PubKeyECDSA
|
s.PubKey = PubKeyECDSA
|
||||||
}
|
}
|
||||||
|
|
||||||
if *arg_zerortt == "a" {
|
if *arg_zerortt == "a" {
|
||||||
s.ZeroRTT = ZeroRTT_Accept
|
s.ZeroRTT = ZeroRTT_Accept
|
||||||
} else if *arg_zerortt == "o" {
|
} else if *arg_zerortt == "o" {
|
||||||
s.ZeroRTT = ZeroRTT_Offer
|
s.ZeroRTT = ZeroRTT_Offer
|
||||||
} else if *arg_zerortt == "oa" {
|
} else if *arg_zerortt == "oa" {
|
||||||
s.ZeroRTT = ZeroRTT_Offer | ZeroRTT_Accept
|
s.ZeroRTT = ZeroRTT_Offer | ZeroRTT_Accept
|
||||||
}
|
}
|
||||||
|
|
||||||
if *arg_clientauth {
|
if *arg_clientauth {
|
||||||
s.ClientAuthMethod = tls.RequireAndVerifyClientCert
|
s.ClientAuthMethod = tls.RequireAndVerifyClientCert
|
||||||
}
|
}
|
||||||
|
|
||||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
tlsConn := r.Context().Value(http.TLSConnContextKey).(*tls.Conn)
|
tlsConn := r.Context().Value(http.TLSConnContextKey).(*tls.Conn)
|
||||||
@ -212,7 +212,7 @@ ClMLEiNJQ0OMxAIaRtb2RehD4q3OWlpWf6joJ36PRBqL8T5+f2x6Tg3c64UR+QPX
|
|||||||
98UcCQHHdEhm7y2z5Z2Wt0B48tZ+UAxDEoEwMghNyw7wUD79IRlXGYypBnXaMuLX
|
98UcCQHHdEhm7y2z5Z2Wt0B48tZ+UAxDEoEwMghNyw7wUD79IRlXGYypBnXaMuLX
|
||||||
46aGxbsSQ7Rfg62Co3JG7vo+eJd0AoZHrtFUnfM8V70IFzMBZnSwRslHRJe56Q==
|
46aGxbsSQ7Rfg62Co3JG7vo+eJd0AoZHrtFUnfM8V70IFzMBZnSwRslHRJe56Q==
|
||||||
-----END CERTIFICATE-----`
|
-----END CERTIFICATE-----`
|
||||||
rsaCa_client = `-----BEGIN CERTIFICATE-----
|
rsaCa_client = `-----BEGIN CERTIFICATE-----
|
||||||
MIIFYDCCA0igAwIBAgIJAPpBgIvtQb1EMA0GCSqGSIb3DQEBCwUAMEUxCzAJBgNV
|
MIIFYDCCA0igAwIBAgIJAPpBgIvtQb1EMA0GCSqGSIb3DQEBCwUAMEUxCzAJBgNV
|
||||||
BAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBX
|
BAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBX
|
||||||
aWRnaXRzIFB0eSBMdGQwHhcNMTgwMjEzMjAxNjA3WhcNMTkwMjEzMjAxNjA3WjBF
|
aWRnaXRzIFB0eSBMdGQwHhcNMTgwMjEzMjAxNjA3WhcNMTkwMjEzMjAxNjA3WjBF
|
||||||
|
@ -28,8 +28,8 @@ var cipherSuiteIdToName = map[uint16]string{
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Client struct {
|
type Client struct {
|
||||||
KeyLogWriter io.Writer
|
KeyLogWriter io.Writer
|
||||||
failed uint
|
failed uint
|
||||||
client_cert tls.Certificate
|
client_cert tls.Certificate
|
||||||
client_certpool *x509.CertPool
|
client_certpool *x509.CertPool
|
||||||
}
|
}
|
||||||
@ -127,7 +127,6 @@ func main() {
|
|||||||
client.run(addr, tls.VersionTLS12, tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256)
|
client.run(addr, tls.VersionTLS12, tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
client.run(addr, tls.VersionTLS13, tls.TLS_CHACHA20_POLY1305_SHA256)
|
client.run(addr, tls.VersionTLS13, tls.TLS_CHACHA20_POLY1305_SHA256)
|
||||||
client.run(addr, tls.VersionTLS13, tls.TLS_AES_128_GCM_SHA256)
|
client.run(addr, tls.VersionTLS13, tls.TLS_AES_128_GCM_SHA256)
|
||||||
client.run(addr, tls.VersionTLS13, tls.TLS_AES_256_GCM_SHA384)
|
client.run(addr, tls.VersionTLS13, tls.TLS_AES_256_GCM_SHA384)
|
||||||
@ -226,4 +225,3 @@ LAoibwDU1NC8/3MfOBYMe6Qklu3kjexOJrfdo0Z7Khgd9F8A4tKwslUndSSlAfKF
|
|||||||
2rjfqabVMZMLZ2XEbA4W5JTfaZS4YYGcrjY7+i7OsnSxoYG2sb+xlQ==
|
2rjfqabVMZMLZ2XEbA4W5JTfaZS4YYGcrjY7+i7OsnSxoYG2sb+xlQ==
|
||||||
-----END RSA PRIVATE KEY-----`
|
-----END RSA PRIVATE KEY-----`
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user