-
Notifications
You must be signed in to change notification settings - Fork 29
RSA Support #88
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
RSA Support #88
Changes from all commits
5b16cb6
b9cb168
e664d4f
39df53c
63bc684
f6e3159
2d95a7e
a5921f6
7df1b80
835f398
793d53a
41d4e0a
e9205fd
15a1a73
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
dscreve marked this conversation as resolved.
Show resolved
Hide resolved
dscreve marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,8 +76,7 @@ enum CredentialPublicKey: Sendable { | |
case .ellipticKey: | ||
self = try .ec2(EC2PublicKey(publicKeyObject: publicKeyObject, algorithm: algorithm)) | ||
case .rsaKey: | ||
throw WebAuthnError.unsupported | ||
// self = try .rsa(RSAPublicKeyData(publicKeyObject: publicKeyObject, algorithm: algorithm)) | ||
self = try .rsa(RSAPublicKeyData(publicKeyObject: publicKeyObject, algorithm: algorithm)) | ||
case .octetKey: | ||
throw WebAuthnError.unsupported | ||
// self = try .okp(OKPPublicKey(publicKeyObject: publicKeyObject, algorithm: algorithm)) | ||
|
@@ -153,11 +152,12 @@ struct EC2PublicKey: PublicKey, Sendable { | |
.isValidSignature(ecdsaSignature, for: data) else { | ||
throw WebAuthnError.invalidSignature | ||
} | ||
default: | ||
dscreve marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I still think we may want to list out the unsupported types here to catch new key sizes in the future, but the list may be a long one, so just a nit. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm less worried about this. The want to throw an unsupported and any new supported ones will need to be added to the switch to make tests pass |
||
throw WebAuthnError.unsupportedCredentialPublicKeyAlgorithm | ||
} | ||
} | ||
} | ||
|
||
/// Currently not in use | ||
struct RSAPublicKeyData: PublicKey, Sendable { | ||
let algorithm: COSEAlgorithmIdentifier | ||
// swiftlint:disable:next identifier_name | ||
|
@@ -184,26 +184,21 @@ struct RSAPublicKeyData: PublicKey, Sendable { | |
} | ||
|
||
func verify(signature: some DataProtocol, data: some DataProtocol) throws { | ||
throw WebAuthnError.unsupported | ||
// let rsaSignature = _RSA.Signing.RSASignature(derRepresentation: signature) | ||
|
||
// var rsaPadding: _RSA.Signing.Padding | ||
// switch algorithm { | ||
// case .algRS1, .algRS256, .algRS384, .algRS512: | ||
// rsaPadding = .insecurePKCS1v1_5 | ||
// case .algPS256, .algPS384, .algPS512: | ||
// rsaPadding = .PSS | ||
// default: | ||
// throw WebAuthnError.unsupportedCOSEAlgorithmForRSAPublicKey | ||
// } | ||
|
||
// guard try _RSA.Signing.PublicKey(rawRepresentation: rawRepresentation).isValidSignature( | ||
// rsaSignature, | ||
// for: data, | ||
// padding: rsaPadding | ||
// ) else { | ||
// throw WebAuthnError.invalidSignature | ||
// } | ||
let rsaSignature = _RSA.Signing.RSASignature(rawRepresentation: signature) | ||
|
||
var rsaPadding: _RSA.Signing.Padding | ||
switch algorithm { | ||
case .algRS1, .algRS256, .algRS384, .algRS512: | ||
rsaPadding = .insecurePKCS1v1_5 | ||
case .algPS256, .algPS384, .algPS512: | ||
rsaPadding = .PSS | ||
default: | ||
throw WebAuthnError.unsupportedCOSEAlgorithmForRSAPublicKey | ||
} | ||
|
||
let publicKey = try _RSA.Signing.PublicKey(n: n, e: e) | ||
guard publicKey.isValidSignature(rsaSignature, for: data, padding: rsaPadding) | ||
else { throw WebAuthnError.invalidSignature } | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@0xTim Do you happen to know if there is an earlier version that supports RSA? My local package.resolved file initially didn't work, but I already lost the version it was locked to by the time I realized I could search from there. I think https://github.com/apple/swift-crypto/releases/tag/3.8.1 is the earliest we can go, but perhaps you know of an earlier version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think there is
(And to be honest I'd be happy to just start with the latest release anyway)