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

Add support for RS256, COSEAlgorithmIdentifier -257 #140

Closed
wants to merge 1 commit into from

Conversation

hslatman
Copy link
Contributor

@hslatman hslatman commented Apr 4, 2023

This PR adds support for RSASSA PKCS#1 v1.5 signing and verification. I started with just RS256, but I can add the others too if this PR will be considered to be merged at some point.

Let me know if you want the tests to be more like a table; currently they're more like multiple copies.

I noticed that registering an algorithm was removed with #101, but I could use the RS256 (and potentially others) for some things, primarily for checking/validating values to be valid COSE values. Adding in the RS256 in all required places seemed to be the way to go, or will RegisterAlgorithm be reconsidered? I noticed signing and verifying can be done backed by a user-provided Signer and Verifier. Should I remove the signing and verification code, and just keep the AlgorithmRS256 around?

@hslatman hslatman force-pushed the rsassa-pkcs1-v1_5 branch 3 times, most recently from 5ca7980 to 8bab3b9 Compare April 4, 2023 13:36
Signed-off-by: Herman Slatman <hermanslatman@hotmail.com>
@codecov
Copy link

codecov bot commented Apr 4, 2023

Codecov Report

Merging #140 (a745f5a) into main (bfa9f54) will increase coverage by 0.09%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #140      +/-   ##
==========================================
+ Coverage   92.77%   92.87%   +0.09%     
==========================================
  Files          10       10              
  Lines        1024     1038      +14     
==========================================
+ Hits          950      964      +14     
  Misses         49       49              
  Partials       25       25              
Impacted Files Coverage Δ
algorithm.go 100.00% <100.00%> (ø)
rsa.go 100.00% <100.00%> (ø)
signer.go 100.00% <100.00%> (ø)
verifier.go 100.00% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@thomas-fossati
Copy link
Contributor

Hi @hslatman, thanks very much for initiating the contribution, much appreciated!

As you probably know already RS256 is not amongst the recommended algorithms for COSE -- and for pretty good reasons :-)

So, it'd be good if you could file an associated issue where you describe the use case and where we can have a conversation on requirements, caveats, etc.

cheers!

@hslatman
Copy link
Contributor Author

hslatman commented Apr 4, 2023

Thank you, @thomas-fossati,

I've opened an issue: #141.

For my use case, having just the AlgorithmRS256 as a constant is probably fine. There's still a way to use RSASSA PKCS#1 v1.5 with the external Signer and Verifier approach, so that could be used if one needs it. The actual implementation could also be in a separate package, providing broader/legacy/interoperability cipher support, thus keeping the core go-cose package small and clean.

@thomas-fossati
Copy link
Contributor

Thank you, @thomas-fossati,

I've opened an issue: #141.

Fantastic, thanks! I'm on holiday until the 11th, so I can't join the discussion until then.

@SteveLasker @qmuntal @shizhMSFT @roywill @yogeshbdeshpande could you please chime in so we don't let Herman wait too long? TIA

@yogeshbdeshpande
Copy link
Contributor

@hslatman Request please create a new PR fr adding the RS256 constant

@@ -22,6 +22,10 @@ const (
// Requires an available crypto.SHA512.
AlgorithmPS512 Algorithm = -39

// RSASSA-PKCS1-v1_5 using SHA-256 by RFC 8812.
// Requires an available crypto.SHA256.
AlgorithmRS256 Algorithm = -257
Copy link
Contributor

Choose a reason for hiding this comment

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

consider a link / comment to webauthn: https://www.w3.org/TR/webauthn-2/#sctn-sample-registration

return ErrVerification
switch rv.alg {
case AlgorithmRS256:
if err := rsa.VerifyPKCS1v15(rv.key, hash, digest, signature); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe you want to remove this part

}

// set up signer for RS256
algRS256 := AlgorithmRS256
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe you want to remove this part

@SteveLasker
Copy link
Contributor

Thanks, @hslatman for the PR and discussion #141
After discussion with the maintainers, we'd like to keep the constant and remove the additional code.
Much appreciated for your engagement.

Copy link
Contributor

@OR13 OR13 left a comment

Choose a reason for hiding this comment

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

seems like folks are requesting the constant be kept but APIs on it throw some error related to it not being supported, without using an external signer

@roywill
Copy link

roywill commented Aug 11, 2023

We are not going to implement this algorithms but allowed the constant to be added in another pull request

@roywill roywill closed this Aug 11, 2023
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.

6 participants