Skip to content

use Alg when available (parse rsa) #9

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
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
33 changes: 18 additions & 15 deletions internal/jwk/jwk_parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,24 +76,27 @@ func (jwe jwkEntry) parseRSA() (*key, error) {
N: &n,
}

/* // there is no alg...
switch {
case jwe.RsaAlg == "RS256" && len(nbuf) == 256:
// First use RsaAlg is we know it
// Else determine Alg using N len
//
// Potential issue found: Gitlab is sending Alg = RS256 but len(nbuf) is 512...
//
switch jwe.RsaAlg {
case "RS256":
return &key{pub: &r, hash: crypto.SHA256}, nil
case jwe.RsaAlg == "RS384" && len(nbuf) == 384:
case "RS384":
return &key{pub: &r, hash: crypto.SHA384}, nil
case jwe.RsaAlg == "RS512" && len(nbuf) == 512:
return &key{pub: &r, hash: crypto.SHA512}, nil
}
*/

switch len(nbuf) {
case 256:
return &key{pub: &r, hash: crypto.SHA256}, nil
case 384:
return &key{pub: &r, hash: crypto.SHA384}, nil
case 512:
case "RS512":
return &key{pub: &r, hash: crypto.SHA512}, nil
default:
switch len(nbuf) {
case 256:
return &key{pub: &r, hash: crypto.SHA256}, nil
case 384:
return &key{pub: &r, hash: crypto.SHA384}, nil
case 512:
return &key{pub: &r, hash: crypto.SHA512}, nil
}
}

return nil, ErrParse
Expand Down