Skip to content

Commit

Permalink
Add mTLS flag support
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoyla committed Aug 10, 2023
1 parent b5dcb56 commit fd0be4b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
12 changes: 9 additions & 3 deletions src/crypto/tls/handshake_messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,9 @@ func (m *clientHelloMsg) marshal() ([]byte, error) {
if len(m.tlsFlags) > 0 {
exts.AddUint16(extensionTLSFlags)
exts.AddUint16LengthPrefixed(func(exts *cryptobyte.Builder) {
exts.AddBytes(m.tlsFlags)
exts.AddUint8LengthPrefixed(func(exts *cryptobyte.Builder) {
exts.AddBytes(m.tlsFlags)
})
})
}
if len(m.cookie) > 0 {
Expand Down Expand Up @@ -568,9 +570,13 @@ func (m *clientHelloMsg) unmarshal(data []byte) bool {
m.supportedVersions = append(m.supportedVersions, vers)
}
case extensionTLSFlags:
for !extData.Empty() {
var flagsList cryptobyte.String
if !extData.ReadUint8LengthPrefixed(&flagsList) || flagsList.Empty() {
return false
}
for !flagsList.Empty() {
var flagByte uint8
if !extData.ReadUint8(&flagByte) {
if !flagsList.ReadUint8(&flagByte) {
return false
}
m.tlsFlags = append(m.tlsFlags, flagByte)
Expand Down
18 changes: 17 additions & 1 deletion src/crypto/tls/handshake_server_tls13.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,18 @@ GroupSelection:
return errors.New("tls: invalid client key share")
}
if len(hs.clientHello.tlsFlags) != 0 {
tlsFlags, err := decodeFlags(hs.clientHello.tlsFlags)
supportedFlags, err := encodeFlags(hs.c.config.TLSFlagsSupported)
if err != nil {
return errors.New("tls: invalid server flags")
}
var mutuallySupportedFlags []byte
for i, sFB := range supportedFlags {
if i >= len(hs.clientHello.tlsFlags) {
break
}
mutuallySupportedFlags = append(mutuallySupportedFlags, hs.clientHello.tlsFlags[i]&sFB)
}
tlsFlags, err := decodeFlags(mutuallySupportedFlags)
if err == nil {
hs.tlsFlags = tlsFlags
}
Expand Down Expand Up @@ -838,6 +849,11 @@ func (hs *serverHandshakeStateTLS13) sendServerParameters() error {
}

func (hs *serverHandshakeStateTLS13) requestClientCert() bool {
for _, flag := range hs.tlsFlags {
if flag == FlagSupportMTLS {
return true
}
}
return hs.c.config.ClientAuth >= RequestClientCert && !hs.usingPSK
}

Expand Down

0 comments on commit fd0be4b

Please sign in to comment.