Skip to content

Commit

Permalink
updated COSE expiry header check (#42)
Browse files Browse the repository at this point in the history
* updated COSE envelope implementation per code reivew

Signed-off-by: Patrick Zheng <[email protected]>

* renamed to envelope under cose package

Signed-off-by: Patrick Zheng <[email protected]>

* update per code review

Signed-off-by: Patrick Zheng <[email protected]>

* updated per code review

Signed-off-by: Patrick Zheng <[email protected]>

* clean up

Signed-off-by: Patrick Zheng <[email protected]>

* more clean up

Signed-off-by: Patrick Zheng <[email protected]>

* updated errors according to errors.go

Signed-off-by: Patrick Zheng <[email protected]>

* clean up

Signed-off-by: Patrick Zheng <[email protected]>

* update unit tests

Signed-off-by: Patrick Zheng <[email protected]>

* update unit tests

Signed-off-by: Patrick Zheng <[email protected]>

* update cose unprotected header

Signed-off-by: Patrick Zheng <[email protected]>

* updated COSE expiry header check

Signed-off-by: Patrick Zheng <[email protected]>

* updated COSE expiry header check

Signed-off-by: Patrick Zheng <[email protected]>

Signed-off-by: Patrick Zheng <[email protected]>
  • Loading branch information
patrickzheng200 authored Aug 17, 2022
1 parent dee4d27 commit 52493c5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
10 changes: 6 additions & 4 deletions signature/cose/envelope.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,11 +430,13 @@ func parseProtectedHeaders(protected cose.ProtectedHeader, signerInfo *signature
signerInfo.SignedAttributes.SigningTime = time.Unix(signingTime, 0)

// populate signerInfo.SignedAttributes.Expiry
exp, ok := protected[headerLabelExpiry].(int64)
if !ok {
return &signature.MalformedSignatureError{Msg: "malformed expiry"}
if exp, ok := protected[headerLabelExpiry]; ok {
expiry, ok := exp.(int64)
if !ok {
return &signature.MalformedSignatureError{Msg: "expiry requires int64 type"}
}
signerInfo.SignedAttributes.Expiry = time.Unix(expiry, 0)
}
signerInfo.SignedAttributes.Expiry = time.Unix(exp, 0)

// populate signerInfo.SignedAttributes.ExtendedAttributes
signerInfo.SignedAttributes.ExtendedAttributes, err = generateExtendedAttributes(extendedAttributeKeys, protected)
Expand Down
3 changes: 2 additions & 1 deletion signature/cose/envelope_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ func newSignRequest(signingScheme string) (*signature.SignRequest, error) {
Expiry: time.Now().AddDate(0, 0, 1),
ExtendedSignedAttributes: []signature.Attribute{
{Key: "signedCritKey1", Value: "signedCritValue1", Critical: true},
{Key: "signedKey1", Value: "signedValue1", Critical: false}},
{Key: "signedKey1", Value: "signedValue1", Critical: false},
},
SigningAgent: "NotationUnitTest/1.0.0",
SigningScheme: signature.SigningScheme(signingScheme),
}, nil
Expand Down

0 comments on commit 52493c5

Please sign in to comment.