Skip to content

Commit

Permalink
Merge pull request #60 from niscy-eudiw/feature/jose-swift-3-0-0
Browse files Browse the repository at this point in the history
[fix] jose-swift 3.0.0 upstream update
  • Loading branch information
dtsiflit authored Sep 26, 2024
2 parents 894b2de + b790e87 commit 2f4e943
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 19 deletions.
6 changes: 3 additions & 3 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@
{
"identity" : "joseswift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/niscy-eudiw/JOSESwift.git",
"location" : "https://github.com/airsidemobile/JOSESwift.git",
"state" : {
"revision" : "518cedba79ef18867191811b161471298b6cb7c8",
"version" : "2.4.1-gcm"
"revision" : "c2664a902e75c0426a1d43132bd4babc6fd173d3",
"version" : "3.0.0"
}
},
{
Expand Down
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ let package = Package(
],
dependencies: [
.package(
url: "https://github.com/niscy-eudiw/JOSESwift.git",
exact: "2.4.1-gcm"
url: "https://github.com/airsidemobile/JOSESwift.git",
from: "3.0.0"
),
.package(
url: "https://github.com/birdrides/mockingbird.git",
Expand Down
4 changes: 2 additions & 2 deletions Sources/Main/Attestation/VerifierAttestationIssuer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ actor VerifierAttestationIssuer {

let publicKey: SecKey = try! KeyController.generateECDHPublicKey(from: self.algAndKey.key)
let verifier: Verifier? = .init(
verifyingAlgorithm: .ES256,
signatureAlgorithm: .ES256,
key: publicKey
)
return verifier
Expand Down Expand Up @@ -85,7 +85,7 @@ actor VerifierAttestationIssuer {
payload.toThrowingJSONData()
),
signer: .init(
signingAlgorithm: algAndKey.algorithm,
signatureAlgorithm: algAndKey.algorithm,
key: algAndKey.key
)!
)
Expand Down
4 changes: 2 additions & 2 deletions Sources/Main/Encryption/ResponseSignerEncryptor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ private extension ResponseSignerEncryptor {
jwsAlgorithm: SignatureAlgorithm,
keySet: WebKeySet,
signingKey: SecKey
) throws -> (key: WebKeySet.Key, signer: Signer<SecKey>) {
) throws -> (key: WebKeySet.Key, signer: Signer) {
let key = try keySet.keys.first { key in
key.alg == jwsAlgorithm.rawValue
} ?? { throw ValidatedAuthorizationError.invalidJWTWebKeySet }()
Expand All @@ -220,7 +220,7 @@ private extension ResponseSignerEncryptor {
}

guard let signer = Signer(
signingAlgorithm: signatureAlgorithm,
signatureAlgorithm: signatureAlgorithm,
key: signingKey
) else {
throw ValidatedAuthorizationError.invalidSigningKey
Expand Down
15 changes: 12 additions & 3 deletions Sources/Main/Validators/AccessValidator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,10 @@ public actor AccessValidator {

let publicKey = try RSAPublicKey(data: key.toDictionary().toThrowingJSONData())
let secKey = try publicKey.converted(to: SecKey.self)
if let verifier = Verifier(verifyingAlgorithm: algorithm, key: secKey) {
if let verifier = Verifier(
signatureAlgorithm: algorithm,
key: secKey
) {
let isValid = jws.isValid(for: verifier)
if !isValid {
throw ValidatedAuthorizationError.validationError("Unable to verify signature")
Expand All @@ -236,11 +239,17 @@ public extension AccessValidator {
let keyType = keyAttributes?[kSecAttrKeyType as CFString] as? String

if keyType == (kSecAttrKeyTypeRSA as String) {
if let verifier = Verifier(verifyingAlgorithm: .RS256, key: publicKey) {
if let verifier = Verifier(
signatureAlgorithm: .RS256,
key: publicKey
) {
_ = try jws.validate(using: verifier)
}
} else if keyType == (kSecAttrKeyTypeEC as String) {
if let verifier = Verifier(verifyingAlgorithm: .ES256, key: publicKey) {
if let verifier = Verifier(
signatureAlgorithm: .ES256,
key: publicKey
) {
_ = try jws.validate(using: verifier)
}
}
Expand Down
12 changes: 9 additions & 3 deletions Sources/Utilities/JOSE/JOSEController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,20 @@ public class JOSEController {
private extension JOSEController {

func verifier(algorithhm: SignatureAlgorithm, publicKey: SecKey) throws -> Verifier {
guard let verifier = Verifier(verifyingAlgorithm: algorithhm, key: publicKey) else {
guard let verifier = Verifier(
signatureAlgorithm: algorithhm,
key: publicKey
) else {
throw JOSEError.invalidVerifier
}
return verifier
}

func signer(algorithhm: SignatureAlgorithm, privateKey: SecKey) throws -> Signer<SecKey> {
guard let signer = Signer(signingAlgorithm: algorithhm, key: privateKey) else {
func signer(algorithhm: SignatureAlgorithm, privateKey: SecKey) throws -> Signer {
guard let signer = Signer(
signatureAlgorithm: algorithhm,
key: privateKey
) else {
throw JOSEError.invalidSigner
}
return signer
Expand Down
5 changes: 4 additions & 1 deletion Tests/Utilities/ResponseSignerEncryptorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ final class ResponseSignerEncryptorTests: DiXCTest {

// Verify signature
let jws = try JWS(compactSerialization: response)
guard let verifier: Verifier = Verifier(verifyingAlgorithm: .RS256, key: publicKey) else {
guard let verifier: Verifier = Verifier(
signatureAlgorithm: .RS256,
key: publicKey
) else {
XCTAssert(false, "Invalid Verifier")
return
}
Expand Down
6 changes: 3 additions & 3 deletions Tests/Validators/JarJwtSignatureValidatorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ final class JarJwtSignatureValidatorTests: XCTestCase {
"client_id_scheme": scheme
].toThrowingJSONData()),
signer: Signer(
signingAlgorithm: algorithm,
signatureAlgorithm: algorithm,
key: walletConfig.signingKey
)!
)
Expand Down Expand Up @@ -91,7 +91,7 @@ final class JarJwtSignatureValidatorTests: XCTestCase {
"client_id_scheme": scheme
].toThrowingJSONData()),
signer: Signer(
signingAlgorithm: algorithm,
signatureAlgorithm: algorithm,
key: walletConfig.signingKey
)!
)
Expand Down Expand Up @@ -130,7 +130,7 @@ final class JarJwtSignatureValidatorTests: XCTestCase {
"client_id_scheme": scheme
].toThrowingJSONData()),
signer: Signer(
signingAlgorithm: algorithm,
signatureAlgorithm: algorithm,
key: walletConfig.signingKey
)!
)
Expand Down

0 comments on commit 2f4e943

Please sign in to comment.