Skip to content

Commit

Permalink
eliminate SignPkcs11
Browse files Browse the repository at this point in the history
  • Loading branch information
JackDoanRivian committed Oct 7, 2024
1 parent 3713d19 commit 1abf88a
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 20 deletions.
17 changes: 0 additions & 17 deletions cert/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
"net/netip"
"slices"
"time"

"github.com/slackhq/nebula/pkclient"
)

// TBSCertificate represents a certificate intended to be signed.
Expand Down Expand Up @@ -76,21 +74,6 @@ func (t *TBSCertificate) Sign(signer Certificate, curve Curve, key []byte) (Cert
}
}

func (t *TBSCertificate) SignPkcs11(signer Certificate, curve Curve, client *pkclient.PKClient) (Certificate, error) {
if client == nil {
return nil, fmt.Errorf("pkclient must be non-nil")
}
switch t.Curve {
case Curve_CURVE25519:
return nil, fmt.Errorf("only P256 is supported by PKCS#11")
case Curve_P256:
//todo: verify that pkcs11 hashes for you
return t.SignWith(signer, curve, client.SignASN1)
default:
return nil, fmt.Errorf("invalid curve: %s", t.Curve)
}
}

// SignWith will create a sealed certificate using details provided by the TBSCertificate as long as those
// details do not violate constraints of the signing certificate.
// If the TBSCertificate is a CA then signer must be nil.
Expand Down
2 changes: 1 addition & 1 deletion cmd/nebula-cert/ca.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ func ca(args []string, out io.Writer, errOut io.Writer, pr PasswordReader) error
var b []byte

if isP11 {
c, err = t.SignPkcs11(nil, curve, p11Client)
c, err = t.SignWith(nil, curve, p11Client.SignASN1)
if err != nil {
return fmt.Errorf("error while signing with PKCS#11: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/nebula-cert/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ func signCert(args []string, out io.Writer, errOut io.Writer, pr PasswordReader)
return fmt.Errorf("error while signing: %w", err)
}
} else {
nc, err = t.SignPkcs11(caCert, curve, p11Client)
nc, err = t.SignWith(caCert, curve, p11Client.SignASN1)
if err != nil {
return fmt.Errorf("error while signing with PKCS#11: %w", err)
}
Expand Down Expand Up @@ -346,7 +346,7 @@ func signCert(args []string, out io.Writer, errOut io.Writer, pr PasswordReader)
return fmt.Errorf("error while signing: %w", err)
}
} else {
nc, err = t.SignPkcs11(caCert, curve, p11Client)
nc, err = t.SignWith(caCert, curve, p11Client.SignASN1)
if err != nil {
return fmt.Errorf("error while signing with PKCS#11: %w", err)
}
Expand Down

0 comments on commit 1abf88a

Please sign in to comment.