-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Description Add support for rsa-pss signing: - direct local signing - via signing server ## What type of PR is this? (check all applicable) - [x] 🍕 Feature - [ ] 🐛 Bug Fix - [x] 📝 Documentation Update - [ ] 🎨 Style - [ ] 🧑💻 Code Refactor - [ ] 🔥 Performance Improvements - [x] ✅ Test - [ ] 🤖 Build - [ ] 🔁 CI - [ ] 📦 Chore (Release) - [ ] ⏩ Revert ## Related Tickets & Documents <!-- Please use this format link issue numbers: Fixes #123 https://docs.github.com/en/free-pro-team@latest/github/managing-your-work-on-github/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword --> - Related Issue # (issue) - Closes # (issue) - Fixes # (issue) > Remove if not applicable ## Screenshots <!-- Visual changes require screenshots --> ## Added tests? - [ ] 👍 yes - [ ] 🙅 no, because they aren't needed - [ ] 🙋 no, because I need help - [ ] Separate ticket for tests # (issue/pr) Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration ## Added to documentation? - [ ] 📜 README.md - [ ] 🙅 no documentation needed ## Checklist: - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules
- Loading branch information
1 parent
4169646
commit 84bb593
Showing
14 changed files
with
219 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Open Component Model contributors. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package signing_test | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/open-component-model/ocm/pkg/testutils" | ||
|
||
"github.com/open-component-model/ocm/pkg/blobaccess" | ||
"github.com/open-component-model/ocm/pkg/contexts/ocm" | ||
v1 "github.com/open-component-model/ocm/pkg/contexts/ocm/compdesc/meta/v1" | ||
"github.com/open-component-model/ocm/pkg/contexts/ocm/repositories/composition" | ||
"github.com/open-component-model/ocm/pkg/contexts/ocm/resourcetypes" | ||
"github.com/open-component-model/ocm/pkg/contexts/ocm/signing" | ||
"github.com/open-component-model/ocm/pkg/mime" | ||
"github.com/open-component-model/ocm/pkg/signing/handlers/rsa" | ||
rsa_pss "github.com/open-component-model/ocm/pkg/signing/handlers/rsa-pss" | ||
"github.com/open-component-model/ocm/pkg/signing/signutils" | ||
) | ||
|
||
var _ = Describe("Simple signing handlers", func() { | ||
Context("", func() { | ||
ctx := ocm.DefaultContext() | ||
|
||
var cv ocm.ComponentVersionAccess | ||
var pub signutils.GenericPublicKey | ||
var priv signutils.GenericPrivateKey | ||
|
||
BeforeEach(func() { | ||
priv, pub = Must2(rsa.CreateKeyPair()) | ||
cv = composition.NewComponentVersion(ctx, COMPONENTA, VERSION) | ||
MustBeSuccessful(cv.SetResourceBlob(ocm.NewResourceMeta("blob", resourcetypes.PLAIN_TEXT, v1.LocalRelation), blobaccess.ForString(mime.MIME_TEXT, "test data"), "", nil)) | ||
}) | ||
|
||
DescribeTable("rsa handlers", func(kind string) { | ||
Must(signing.SignComponentVersion(cv, "signature", signing.PrivateKey("signature", priv))) | ||
Must(signing.VerifyComponentVersion(cv, "signature", signing.PublicKey("signature", pub))) | ||
}, | ||
Entry("rsa", rsa.Algorithm), | ||
Entry("rsapss", rsa_pss.Algorithm), | ||
) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Open Component Model contributors. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package rsa_pss_signingservice | ||
|
||
import ( | ||
"github.com/open-component-model/ocm/pkg/signing" | ||
"github.com/open-component-model/ocm/pkg/signing/handlers/rsa" | ||
rsa_signingservice "github.com/open-component-model/ocm/pkg/signing/handlers/rsa-signingservice" | ||
) | ||
|
||
// Algorithm defines the type for the RSA PKCS #1 v1.5 signature algorithm. | ||
const ( | ||
Algorithm = rsa.Algorithm | ||
Name = "rsapss-signingservice" | ||
) | ||
|
||
// SignaturePEMBlockAlgorithmHeader defines the header in a signature pem block where the signature algorithm is defined. | ||
const SignaturePEMBlockAlgorithmHeader = rsa_signingservice.SignaturePEMBlockAlgorithmHeader | ||
|
||
func init() { | ||
signing.DefaultHandlerRegistry().RegisterSigner(Name, NewHandler()) | ||
} | ||
|
||
func NewHandler() signing.Signer { | ||
return rsa_signingservice.NewHandlerFor(Algorithm) | ||
} | ||
|
||
type Key = rsa_signingservice.Key | ||
|
||
func PrivateKey(k interface{}) (*Key, error) { | ||
return rsa_signingservice.PrivateKey(k) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Open Component Model contributors. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package rsa_pss | ||
|
||
import ( | ||
"crypto" | ||
"crypto/rsa" | ||
"io" | ||
|
||
"github.com/open-component-model/ocm/pkg/signing" | ||
rsahandler "github.com/open-component-model/ocm/pkg/signing/handlers/rsa" | ||
"github.com/open-component-model/ocm/pkg/signing/signutils" | ||
) | ||
|
||
// Algorithm defines the type for the RSA PKCS #1 v1.5 signature algorithm. | ||
const Algorithm = "RSASSA-PSS" | ||
|
||
// MediaType defines the media type for a plain RSA-PSS signature. | ||
const MediaType = "application/vnd.ocm.signature.rsa.pss" | ||
|
||
// MediaTypePEM is used if the signature contains the public key certificate chain. | ||
const MediaTypePEM = signutils.MediaTypePEM | ||
|
||
func init() { | ||
signing.DefaultHandlerRegistry().RegisterSigner(Algorithm, NewHandler()) | ||
} | ||
|
||
func NewHandler() signing.SignatureHandler { | ||
return rsahandler.NewHandlerFor(RSASSA_PSS) | ||
} | ||
|
||
var RSASSA_PSS = &rsahandler.Method{ | ||
Algorithm: Algorithm, | ||
MediaType: MediaType, | ||
Sign: sign, | ||
Verify: verify, | ||
} | ||
|
||
func sign(rand io.Reader, priv *rsa.PrivateKey, hash crypto.Hash, digest []byte) ([]byte, error) { | ||
return rsa.SignPSS(rand, priv, hash, digest, nil) | ||
} | ||
|
||
func verify(pub *rsa.PublicKey, hash crypto.Hash, digest []byte, sig []byte) error { | ||
return rsa.VerifyPSS(pub, hash, digest, sig, nil) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.