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 <patrickzheng@microsoft.com>

* renamed to envelope under cose package

Signed-off-by: Patrick Zheng <patrickzheng@microsoft.com>

* update per code review

Signed-off-by: Patrick Zheng <patrickzheng@microsoft.com>

* updated per code review

Signed-off-by: Patrick Zheng <patrickzheng@microsoft.com>

* clean up

Signed-off-by: Patrick Zheng <patrickzheng@microsoft.com>

* more clean up

Signed-off-by: Patrick Zheng <patrickzheng@microsoft.com>

* updated errors according to errors.go

Signed-off-by: Patrick Zheng <patrickzheng@microsoft.com>

* clean up

Signed-off-by: Patrick Zheng <patrickzheng@microsoft.com>

* update unit tests

Signed-off-by: Patrick Zheng <patrickzheng@microsoft.com>

* update unit tests

Signed-off-by: Patrick Zheng <patrickzheng@microsoft.com>

* update cose unprotected header

Signed-off-by: Patrick Zheng <patrickzheng@microsoft.com>

* updated COSE expiry header check

Signed-off-by: Patrick Zheng <patrickzheng@microsoft.com>

* updated COSE expiry header check

Signed-off-by: Patrick Zheng <patrickzheng@microsoft.com>

Signed-off-by: Patrick Zheng <patrickzheng@microsoft.com>
  • Loading branch information
patrickzheng200 committed 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.