Skip to content

Commit

Permalink
fix: check verifierID in token before passing to customAuth
Browse files Browse the repository at this point in the history
  • Loading branch information
metalurgical committed Nov 21, 2024
1 parent ed67ffa commit 919783e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Sources/mpc-core-kit-swift/CoreKitError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public enum CoreKitError: Error {
case noTssTags
case invalidDeviceFactorKey
case invalidTssPubKey
case mismatchedVerifierID
case runtime(_ msg: String)

public var errorDescription: String {
Expand Down Expand Up @@ -94,6 +95,8 @@ public enum CoreKitError: Error {
return msg
case .invalidTssPubKey:
return "Invalid tss public key"
case .mismatchedVerifierID:
return "VerifierID field in idToken does not match verifierID"
}
}
}
9 changes: 7 additions & 2 deletions Sources/mpc-core-kit-swift/MpcCoreKitSwift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,16 @@ public class MpcCoreKit {

public func loginWithJwt(verifier: String, verifierId: String, idToken: String) async throws -> MpcKeyDetails {

let parsedToken = try decode(jwt: idToken)
let verifierIDToken = parsedToken.subject;

if verifierIDToken != verifierId {
throw CoreKitError.mismatchedVerifierID
}

let torusKey = try await customAuth.getTorusKey(verifier: verifier, verifier_id: verifierId, verifierParams: VerifierParams(verifier_id: verifierId), idToken: idToken)

let result = try await login(keyDetails: torusKey, verifier: verifier, verifierId: verifierId)

let parsedToken = try decode(jwt: idToken)

// TODO: Make constructor public in customauth for TorusGenericContainer
let encodedEmptyState = "7b22706172616d73223a7b7d7d"
Expand Down

0 comments on commit 919783e

Please sign in to comment.