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

COSE envelope implementation updates #26

Closed
wants to merge 37 commits into from
Closed
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
2994a36
feat: add cose support by refining signer module (#25)
binbin-li Aug 8, 2022
a45a51e
refactor: refine the envelope and signer to enhance extensiblity (#27)
binbin-li Aug 9, 2022
2e99fe0
refactor: rename custom errors (#29)
binbin-li Aug 10, 2022
0553376
Merge branch 'main' into cose
shizhMSFT Aug 10, 2022
b64ffd6
refactor: use internal envelope to verify (#31)
binbin-li Aug 11, 2022
bb1fc31
implement jws (#30)
JeyJeyGao Aug 11, 2022
2786c0b
feat: add missing VerifyAuthenticity (#33)
binbin-li Aug 11, 2022
ab66bb3
feat: implemented COSE Envelope (#28)
patrickzheng200 Aug 11, 2022
c515e7a
refactor: add common logic to base envelope (#35)
binbin-li Aug 15, 2022
c23a945
updated COSE envelope implementation per code review (#36)
patrickzheng200 Aug 16, 2022
046e0ee
feat: validate key and cert while creating local signer (#40)
binbin-li Aug 16, 2022
be20e83
feat: add jwt sign (#34)
JeyJeyGao Aug 17, 2022
dee4d27
COSE update unprotected header (#41)
patrickzheng200 Aug 17, 2022
52493c5
updated COSE expiry header check (#42)
patrickzheng200 Aug 17, 2022
e5da201
fix: update envelope.Payload() logic (#44)
JeyJeyGao Aug 18, 2022
8aef2e4
doc: add signature documents (#39)
binbin-li Aug 19, 2022
a69de85
test: add signature unit tests (#43)
binbin-li Aug 19, 2022
8b03c75
Updated COSE envelope unit tests (#45)
patrickzheng200 Aug 19, 2022
9757c1e
added extended attribute getter for notation-go (#46)
patrickzheng200 Aug 22, 2022
70a31c0
updated COSE envelope unit tests (#47)
patrickzheng200 Aug 22, 2022
563993b
refactor: refactor signer and envelope to make Sign() return certs as…
binbin-li Aug 23, 2022
c3aae6e
test: fix broken unit tests (#49)
binbin-li Aug 23, 2022
a2fb618
fix: fix the certs validation in envelope.Sign() (#51)
binbin-li Aug 23, 2022
9d165b7
updated COSE envelope for the certification chain changes (#50)
patrickzheng200 Aug 24, 2022
b97da9b
updated to latest go-cose (#54)
patrickzheng200 Aug 25, 2022
1421844
refector & test: update to support new signature.Signer interface (#52)
JeyJeyGao Aug 26, 2022
157fd17
Added COSE conformance tests (#55)
patrickzheng200 Aug 26, 2022
89bf762
add getSigningMethod (#56)
JeyJeyGao Aug 26, 2022
80a50e6
add conformance test (#57)
JeyJeyGao Aug 29, 2022
d442f4e
updated errors related code (#60)
patrickzheng200 Aug 30, 2022
8681e4f
quick fix (#61)
patrickzheng200 Aug 31, 2022
1a9373f
fix: update jwt.Claims (#62)
JeyJeyGao Aug 31, 2022
60059d5
renamed TestSignatureNotFoundError to TestSignatureEnvelopeNotFoundEr…
patrickzheng200 Aug 31, 2022
7bf2b3e
quick update regarding verification plugin (#65)
patrickzheng200 Sep 1, 2022
25e1806
Updated cose branch (#69)
patrickzheng200 Sep 7, 2022
8cdaf86
fix: fix unit test error code (#70)
JeyJeyGao Sep 7, 2022
afc4874
refactor: sync changes from stage/cose branch (#74)
binbin-li Sep 14, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@ module github.com/notaryproject/notation-core-go
go 1.17

require github.com/golang-jwt/jwt/v4 v4.4.1

require (
github.com/fxamacker/cbor/v2 v2.4.0 // indirect
github.com/veraison/go-cose v1.0.0-rc.1
github.com/x448/float16 v0.8.4 // indirect
)
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
github.com/fxamacker/cbor/v2 v2.4.0 h1:ri0ArlOR+5XunOP8CRUowT0pSJOwhW098ZCUyskZD88=
github.com/fxamacker/cbor/v2 v2.4.0/go.mod h1:TA1xS00nchWmaBnEIxPSE5oHLuJBAVvqrtAnWBwBCVo=
github.com/golang-jwt/jwt/v4 v4.4.1 h1:pC5DB52sCeK48Wlb9oPcdhnjkz1TKt1D/P7WKJ0kUcQ=
github.com/golang-jwt/jwt/v4 v4.4.1/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
github.com/veraison/go-cose v1.0.0-rc.1 h1:4qA7dbFJGvt7gcqv5MCIyCQvN+NpHFPkW7do3EeDLb8=
github.com/veraison/go-cose v1.0.0-rc.1/go.mod h1:7ziE85vSq4ScFTg6wyoMXjucIGOf4JkFEZi/an96Ct4=
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
106 changes: 106 additions & 0 deletions signature/algorithm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package signature

import (
"crypto"
"crypto/ecdsa"
"crypto/rsa"
"crypto/x509"
"fmt"
)

// Algorithm lists supported algorithms.
type Algorithm int

// One of following supported specs
// https://github.com/notaryproject/notaryproject/blob/main/signature-specification.md#algorithm-selection
const (
AlgorithmPS256 Algorithm = 1 + iota // RSASSA-PSS with SHA-256
AlgorithmPS384 // RSASSA-PSS with SHA-384
AlgorithmPS512 // RSASSA-PSS with SHA-512
AlgorithmES256 // ECDSA on secp256r1 with SHA-256
AlgorithmES384 // ECDSA on secp384r1 with SHA-384
AlgorithmES512 // ECDSA on secp521r1 with SHA-512
)

// KeyType defines the key type
type KeyType int

const (
KeyTypeRSA KeyType = 1 + iota // KeyType RSA
KeyTypeEC // KeyType EC
)

// KeySpec defines a key type and size.
type KeySpec struct {
Type KeyType
Size int
}

// Hash returns the hash function of the algorithm
func (alg Algorithm) Hash() crypto.Hash {
switch alg {
case AlgorithmPS256, AlgorithmES256:
return crypto.SHA256
case AlgorithmPS384, AlgorithmES384:
return crypto.SHA384
case AlgorithmPS512, AlgorithmES512:
return crypto.SHA512
}
return 0
}

// ExtractKeySpec extracts keySpec from the signing certificate
func ExtractKeySpec(signingCert *x509.Certificate) (KeySpec, error) {
switch key := signingCert.PublicKey.(type) {
case *rsa.PublicKey:
switch bitSize := key.Size() << 3; bitSize {
qmuntal marked this conversation as resolved.
Show resolved Hide resolved
case 2048, 3072, 4096:
return KeySpec{
Type: KeyTypeRSA,
Size: bitSize,
}, nil
default:
return KeySpec{}, &UnsupportedSigningKeyError{
fmt.Sprintf("rsa key size %d is not supported", bitSize),
}
}
case *ecdsa.PublicKey:
switch bitSize := key.Curve.Params().BitSize; bitSize {
case 256, 384, 521:
return KeySpec{
Type: KeyTypeEC,
Size: bitSize,
}, nil
default:
return KeySpec{}, &UnsupportedSigningKeyError{
fmt.Sprintf("ecdsa key size %d is not supported", bitSize),
}
}
}
return KeySpec{}, fmt.Errorf("invalid public key type")
}

// SignatureAlgorithm returns the signing algorithm associated with KeyType k.
func (k KeySpec) SignatureAlgorithm() Algorithm {
switch k.Type {
case KeyTypeEC:
switch k.Size {
case 256:
return AlgorithmES256
case 384:
return AlgorithmES384
case 521:
return AlgorithmES512
}
case KeyTypeRSA:
switch k.Size {
case 2048:
return AlgorithmPS256
case 3072:
return AlgorithmPS384
case 4096:
return AlgorithmPS512
}
}
return 0
}
Loading