mirror of
https://github.com/slackhq/nebula.git
synced 2026-11-16 21:06:52 +01:00
cert: Name the post-quantum algorithms of a version 3 certificate with a PQSuite, like its curve, and pick the hybrid subtype by the suite's KEM
This commit is contained in:
1 parent
84e28c62ea
commit
656164b259
29 files changed
+1124
-365
No files matched your search
+25
-2
@@ -94,7 +94,8 @@ func NewMachine(
|
||||
|
||||
// Version 3 certificates go with hybrid patterns and nothing else, the
|
||||
// classical and phase 1 subtypes use the v2 form instead.
|
||||
if info.hybrid != (version == cert.Version3) {
|
||||
hybrid := info.kem != nil
|
||||
if hybrid != (version == cert.Version3) {
|
||||
return nil, fmt.Errorf("%w: %v", ErrCertVersionMismatch, version)
|
||||
}
|
||||
|
||||
@@ -102,6 +103,11 @@ func NewMachine(
|
||||
if cred == nil {
|
||||
return nil, fmt.Errorf("%w: %v", ErrNoCredential, version)
|
||||
}
|
||||
if hybrid {
|
||||
if err := checkHybridSuite(subtype, cred.Cert); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
hs, err := cred.buildHandshakeState(initiator, info)
|
||||
if err != nil {
|
||||
@@ -112,7 +118,7 @@ func NewMachine(
|
||||
hs: hs,
|
||||
subtype: subtype,
|
||||
msgs: info.msgs,
|
||||
hybrid: info.hybrid,
|
||||
hybrid: hybrid,
|
||||
getCred: getCred,
|
||||
allocIndex: allocIndex,
|
||||
verifier: verifier,
|
||||
@@ -390,6 +396,16 @@ func (m *Machine) processPayload(msg []byte, flags msgFlags) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// checkHybridSuite checks that a version 3 certificate's suite uses the KEM of
|
||||
// the hybrid subtype.
|
||||
func checkHybridSuite(subtype header.MessageSubType, c cert.Certificate) error {
|
||||
suite := cert.PQSuiteOf(c)
|
||||
if st, ok := HybridSubtype(suite); !ok || st != subtype {
|
||||
return fmt.Errorf("%w: %v", ErrPQSuiteMismatch, suite)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Machine) validateCert(payload Payload) error {
|
||||
// A v3 certificate only ever comes with a hybrid pattern, and a hybrid
|
||||
// pattern only ever with one. The composite static key would not recombine
|
||||
@@ -420,6 +436,13 @@ func (m *Machine) validateCert(payload Payload) error {
|
||||
return ErrPublicKeyMismatch
|
||||
}
|
||||
|
||||
if m.hybrid {
|
||||
if err := checkHybridSuite(m.subtype, rc); err != nil {
|
||||
m.failed = true
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// Version negotiation, if the peer sent a different version and we have it, switch
|
||||
if rc.Version() != m.myVersion {
|
||||
if m.getCred(rc.Version()) != nil {
|
||||
|
||||
Reference in new issue
Block a user