Skip to content

Commit

Permalink
Fix comments of the code review
Browse files Browse the repository at this point in the history
  • Loading branch information
maraino committed Dec 6, 2023
1 parent b568818 commit 7a84055
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 9 additions & 3 deletions x509util/certificate_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,13 @@ func (c *CertificateRequest) GetCertificateRequest() (*x509.CertificateRequest,
return nil, errors.Wrap(err, "error creating certificate request")
}

// Prepend challenge password and sign again
// If a challenge password is provided, encode and prepend it as a challenge
// password attribute.
//
// The challengePassword attribute doesn't follow the ASN.1 encoding of
// [pkix.AttributeTypeAndValueSET] used in the deprecated
// [x509.CertificateRequest.Attributes], so this requires some low-level
// ASN.1 operations.
if c.ChallengePassword != "" {
asn1Data, err = c.addChallengePassword(asn1Data)
if err != nil {
Expand All @@ -160,8 +166,8 @@ func (c *CertificateRequest) GetCertificateRequest() (*x509.CertificateRequest,
// addChallengePassword unmarshals the asn1Data into a certificateRequest and
// creates a new one with the challengePassword.
func (c *CertificateRequest) addChallengePassword(asn1Data []byte) ([]byte, error) {
// Marshal challengePassword to ans1.RawValue
// Build challengePassword attribute (RFC 2985 section-5.4)
// Build challengePassword attribute (RFC 2985 section-5.4). The resulting
// bytes will be added as an asn1.RawValue in the RawAttributes.
var builder cryptobyte.Builder
builder.AddASN1(cryptobyte_asn1.SEQUENCE, func(child *cryptobyte.Builder) {
child.AddASN1ObjectIdentifier(oidChallengePassword)
Expand Down
2 changes: 1 addition & 1 deletion x509util/certificate_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ func TestCertificateRequest_GetCertificateRequest_challengePassword(t *testing.T
SignatureAlgorithm: SignatureAlgorithm(x509.SHA256WithRSA),
Signer: rsaKey,
}, expectedUTF8String, assert.NoError},
{"fail challengePAssword", &CertificateRequest{
{"fail challengePassword", &CertificateRequest{
Subject: Subject{CommonName: "commonName"},
DNSNames: []string{"foo.com"},
EmailAddresses: []string{"[email protected]"},
Expand Down

0 comments on commit 7a84055

Please sign in to comment.