Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates the SignedCorim Sign method to include certificates #168

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Akhilesh-max
Copy link
Contributor

Attempts -- #159

@Akhilesh-max
Copy link
Contributor Author

Akhilesh-max commented Feb 14, 2025

Hi @thomas-fossati, I am still working on the corresponding tests.

Copy link
Contributor

@thomas-fossati thomas-fossati left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

I have left a few comments inline.

From an API design perspective, instead of changing the Sign's signature (apologies for the pun) I think it'd be better to add two new methods on the SignedCorim object to configure the end-entity cert and intermediate(s):

func (o *SignedCorim) AddSigningCert(der []byte) error { /* */ }
func (o *SignedCorim) AddIntemediateCerts(der []byte) error { /* */ }

// populated.
func (o *SignedCorim) Sign(signer cose.Signer) ([]byte, error) {
// The target SignedCorim must have its UnsignedCorim field correctly populated.
func (o *SignedCorim) Sign(signer cose.Signer, leafCert, intermediateCert []byte) ([]byte, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We cannot make any assumptions on the depth of the cert chain, i.e., the number of intermediate certs could be > 1.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Techinically, it could be 0 as well. Though unlikely, its possible the signing cert will be signed by the root CA cert.

Comment on lines +140 to +142
if leafCert == nil || intermediateCert == nil {
return nil, errors.New("nil certs")
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to continue supporting the case of signed CoRIMs that rely on out-of-band means for communicating the verification key material.

Therefore, we shouldn't return an error here; continue as usual, just avoid adding the header.

Comment on lines +171 to +174
protectedHeadersCBOR, err := cbor.Marshal(protectedHeaders)
if err != nil {
return nil, fmt.Errorf("failed CBOR encoding of protected headers: %w", err)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this stage, this needs to remain an array - see https://www.rfc-editor.org/rfc/rfc9360.html#tab-1

The COSE library will take care of CBOR encoding.

Comment on lines +32 to +34
type ProtectedHeader struct {
X5Chain [][]byte `cbor:"33,keyasint,omitempty"`
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this isn't needed.

o.message.Headers.Protected.SetAlgorithm(alg)
o.message.Headers.Protected[cose.HeaderLabelContentType] = ContentType
o.message.Headers.Protected[HeaderLabelCorimMeta] = metaCBOR
o.message.Headers.Protected[33] = protectedHeadersCBOR
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than 33, you can use cose.HeaderLabelX5Chain

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants