Skip to content

Commit

Permalink
Fix for issue 418 with unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
mschexnaydre committed Oct 17, 2023
1 parent 7faf25f commit e35badb
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 11 deletions.
3 changes: 1 addition & 2 deletions AUTHORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,12 @@ ManuelBk <[email protected]>
Michael Zabka <[email protected]>
Michiel De Backker <[email protected]>
Rachel Chen <[email protected]>
Michael Schexnaydre <[email protected]>
Robert Eperjesi <[email protected]>
Ryan Gordon <[email protected]>
Sam Lancia <[email protected]>
Sean <[email protected]>
Sean DuBois <[email protected]>
Sean DuBois <[email protected]>
Sean DuBois <[email protected]>
Sean DuBois <[email protected]>
Shelikhoo <[email protected]>
Stefan Tatschner <[email protected]>
Expand Down
10 changes: 9 additions & 1 deletion conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,14 @@ func TestClientCertificate(t *testing.T) {
ClientAuth: RequireAnyClientCert,
},
},
"RequestClientCert_cert_sigscheme": { // specify signature algorithm
clientCfg: &Config{RootCAs: srvCAPool, Certificates: []tls.Certificate{cert}},
serverCfg: &Config{
SignatureSchemes:[]tls.SignatureScheme{tls.ECDSAWithP521AndSHA512},
Certificates: []tls.Certificate{srvCert},
ClientAuth: RequestClientCert,
},
},
"RequestClientCert_cert": {
clientCfg: &Config{RootCAs: srvCAPool, Certificates: []tls.Certificate{cert}},
serverCfg: &Config{
Expand Down Expand Up @@ -1352,7 +1360,7 @@ func TestServerCertificate(t *testing.T) {
}},
},
"good_ca_custom_verify_peer": {
clientCfg: &Config{
clientCfg: &Config{
RootCAs: caPool,
VerifyPeerCertificate: func([][]byte, [][]*x509.Certificate) error {
return errWrongCert
Expand Down
7 changes: 1 addition & 6 deletions crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"crypto/ed25519"
"crypto/rand"
"crypto/rsa"
"crypto/sha256"
"crypto/x509"
"encoding/asn1"
"encoding/binary"
Expand Down Expand Up @@ -118,11 +117,7 @@ func generateCertificateVerify(handshakeBodies []byte, privateKey crypto.Private
return p.Sign(rand.Reader, handshakeBodies, crypto.Hash(0))
}

h := sha256.New()
if _, err := h.Write(handshakeBodies); err != nil {
return nil, err
}
hashed := h.Sum(nil)
hashed := hashAlgorithm.Digest(handshakeBodies)

switch p := privateKey.(type) {
case *ecdsa.PrivateKey:
Expand Down
3 changes: 2 additions & 1 deletion flight3handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ func flight3Parse(ctx context.Context, c flightConn, state *State, cache *handsh
}
}

if _, ok := msgs[handshake.TypeCertificateRequest].(*handshake.MessageCertificateRequest); ok {
if creq, ok := msgs[handshake.TypeCertificateRequest].(*handshake.MessageCertificateRequest); ok {
state.remoteCertRequestAlgs = creq.SignatureHashAlgorithms
state.remoteRequestedCertificate = true
}

Expand Down
3 changes: 2 additions & 1 deletion flight5handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ func flight5Generate(c flightConn, state *State, cache *handshakeCache, cfg *han
), merged...)

// Find compatible signature scheme
signatureHashAlgo, err := signaturehash.SelectSignatureScheme(cfg.localSignatureSchemes, privateKey)

signatureHashAlgo, err := signaturehash.SelectSignatureScheme(state.remoteCertRequestAlgs, privateKey)
if err != nil {
return nil, &alert.Alert{Level: alert.Fatal, Description: alert.InsufficientSecurity}, err
}
Expand Down
2 changes: 2 additions & 0 deletions state.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/pion/dtls/v2/pkg/crypto/elliptic"
"github.com/pion/dtls/v2/pkg/crypto/prf"
"github.com/pion/dtls/v2/pkg/crypto/signaturehash"
"github.com/pion/dtls/v2/pkg/protocol/handshake"
"github.com/pion/transport/v3/replaydetector"
)
Expand Down Expand Up @@ -53,6 +54,7 @@ type State struct {
handshakeSendSequence int
handshakeRecvSequence int
serverName string
remoteCertRequestAlgs []signaturehash.Algorithm
remoteRequestedCertificate bool // Did we get a CertificateRequest
localCertificatesVerify []byte // cache CertificateVerify
localVerifyData []byte // cached VerifyData
Expand Down

0 comments on commit e35badb

Please sign in to comment.