@@ -16,6 +16,7 @@ import (
1616 "errors"
1717 "fmt"
1818 "io"
19+ math_rand "math/rand"
1920 "net"
2021 "os"
2122 "os/exec"
@@ -539,6 +540,90 @@ func testCrossVersionResume(t *testing.T, version uint16) {
539540 }
540541}
541542
543+ func TestTLSFlags (t * testing.T ) {
544+ serverConfig := & Config {
545+ Certificates : []Certificate {{
546+ Certificate : [][]byte {testRSACertificate },
547+ PrivateKey : testRSAPrivateKey ,
548+ }},
549+ TLSFlagsSupported : []TLSFlag {0x50 },
550+ }
551+ clientCert , err := X509KeyPair ([]byte (clientECDSACertificatePEM ), []byte (clientECDSAKeyPEM ))
552+ if err != nil {
553+ t .Fatalf ("couldn't load client certs" )
554+ }
555+ var flags = make ([]TLSFlag , 10 , 100 )
556+ for i := 0 ; i < math_rand .Intn (100 )+ 1 ; i ++ {
557+ flags = append (flags , TLSFlag (math_rand .Intn (2040 )))
558+ }
559+ clientConfig := & Config {
560+ TLSFlagsSupported : flags ,
561+ InsecureSkipVerify : true ,
562+ Certificates : []Certificate {clientCert },
563+ }
564+ state , _ , err := testHandshake (t , clientConfig , serverConfig )
565+ if err != nil {
566+ t .Fatalf ("handshake failed: %s" , err )
567+ }
568+ found := false
569+ for _ , flag := range state .PeerTLSFlags {
570+ found = found || (flag == 0x50 )
571+ }
572+ if found && (state .AgreedTLSFlags [0 ] != TLSFlag (0x50 )) {
573+ t .Fatalf ("Failed to agree correct flags" )
574+ }
575+ if ! state .RequestClientCert == found {
576+ t .Fatalf ("Failed to request client cert" )
577+ }
578+ if (len (state .PeerCertificates ) == 0 ) == found {
579+ t .Fatalf ("Didn't receive correct client certs" )
580+ }
581+ }
582+
583+ func TestTLSFlagsReqmTLS (t * testing.T ) {
584+ serverConfig := & Config {
585+ Certificates : []Certificate {{
586+ Certificate : [][]byte {testRSACertificate },
587+ PrivateKey : testRSAPrivateKey ,
588+ }},
589+ TLSFlagsSupported : []TLSFlag {0x50 },
590+ }
591+ clientCert , err := X509KeyPair ([]byte (clientECDSACertificatePEM ), []byte (clientECDSAKeyPEM ))
592+ if err != nil {
593+ t .Fatalf ("couldn't load client certs" )
594+ }
595+ var flags = make ([]TLSFlag , 10 , 100 )
596+ for i := 0 ; i < math_rand .Intn (100 ); i ++ {
597+ flags = append (flags , TLSFlag (math_rand .Intn (2040 )))
598+ }
599+ flags = append (flags , TLSFlag (0x50 ))
600+ clientConfig := & Config {
601+ TLSFlagsSupported : flags ,
602+ InsecureSkipVerify : true ,
603+ Certificates : []Certificate {clientCert },
604+ }
605+ state , _ , err := testHandshake (t , clientConfig , serverConfig )
606+ if err != nil {
607+ t .Fatalf ("handshake failed: %s" , err )
608+ }
609+ found := false
610+ for _ , flag := range state .PeerTLSFlags {
611+ found = found || (flag == 0x50 )
612+ }
613+ if ! found {
614+ t .Fatalf ("req mTLS Flag not found" )
615+ }
616+ if state .AgreedTLSFlags [0 ] != TLSFlag (0x50 ) {
617+ t .Fatalf ("Failed to agree correct flags" )
618+ }
619+ if ! state .RequestClientCert {
620+ t .Fatalf ("Failed to request client cert" )
621+ }
622+ if len (state .PeerCertificates ) == 0 {
623+ t .Fatalf ("Didn't receive correct client certs" )
624+ }
625+ }
626+
542627// Note: see comment in handshake_test.go for details of how the reference
543628// tests work.
544629
0 commit comments