This commit is contained in:
sydneymorton 2020-10-06 12:57:44 -07:00
Родитель 9cc7ba713c
Коммит ab18700634
8 изменённых файлов: 26 добавлений и 17 удалений

Просмотреть файл

@ -14,6 +14,7 @@
5518CC7425264CAD00C7A21B /* PresentationResponseContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5518CC7325264CAD00C7A21B /* PresentationResponseContainer.swift */; };
5518CC7625264D5700C7A21B /* ResponseMappings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5518CC7525264D5700C7A21B /* ResponseMappings.swift */; };
551F30432527DC050081D5E7 /* FormatterHelpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 551F30422527DC050081D5E7 /* FormatterHelpers.swift */; };
551F3057252D02AB0081D5E7 /* TokenTimeConstraints.swift in Sources */ = {isa = PBXBuildFile; fileRef = 551F3056252D02AB0081D5E7 /* TokenTimeConstraints.swift */; };
55575738251BC575009979AB /* VCEntities.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5557572E251BC575009979AB /* VCEntities.framework */; };
5557573D251BC575009979AB /* VCEntitiesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5557573C251BC575009979AB /* VCEntitiesTests.swift */; };
5557573F251BC575009979AB /* VCEntities.h in Headers */ = {isa = PBXBuildFile; fileRef = 55575731251BC575009979AB /* VCEntities.h */; settings = {ATTRIBUTES = (Public, ); }; };
@ -82,6 +83,7 @@
5518CC7325264CAD00C7A21B /* PresentationResponseContainer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PresentationResponseContainer.swift; sourceTree = "<group>"; };
5518CC7525264D5700C7A21B /* ResponseMappings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ResponseMappings.swift; sourceTree = "<group>"; };
551F30422527DC050081D5E7 /* FormatterHelpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FormatterHelpers.swift; sourceTree = "<group>"; };
551F3056252D02AB0081D5E7 /* TokenTimeConstraints.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TokenTimeConstraints.swift; sourceTree = "<group>"; };
5557572E251BC575009979AB /* VCEntities.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = VCEntities.framework; sourceTree = BUILT_PRODUCTS_DIR; };
55575731251BC575009979AB /* VCEntities.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VCEntities.h; sourceTree = "<group>"; };
55575732251BC575009979AB /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
@ -319,6 +321,7 @@
5518CC7125264C6F00C7A21B /* PresentationResponseFormatter.swift */,
555CE08925267FE500C1C938 /* VerifiablePresentationFormatter.swift */,
551F30422527DC050081D5E7 /* FormatterHelpers.swift */,
551F3056252D02AB0081D5E7 /* TokenTimeConstraints.swift */,
);
path = formatters;
sourceTree = "<group>";
@ -486,6 +489,7 @@
5584E4A02525656500A9DE58 /* SchemaDescriptor.swift in Sources */,
55575766251BC6CF009979AB /* LogoDisplayDescriptor.swift in Sources */,
5557576F251BC6CF009979AB /* IdTokenDescriptor.swift in Sources */,
551F3057252D02AB0081D5E7 /* TokenTimeConstraints.swift in Sources */,
555CE08A25267FE500C1C938 /* VerifiablePresentationFormatter.swift in Sources */,
55575772251BC6CF009979AB /* ServiceDescriptor.swift in Sources */,
5557576E251BC6CF009979AB /* ClaimDescriptor.swift in Sources */,

Просмотреть файл

@ -5,10 +5,10 @@
import VCJwt
func createIatAndExp(expiryInSeconds: Int) -> (Double, Double) {
func createTokenTimeConstraints(expiryInSeconds: Int) -> TokenTimeConstraints {
let iat = (Date().timeIntervalSince1970).rounded(.down)
let exp = iat + Double(expiryInSeconds)
return (iat, exp)
return TokenTimeConstraints(issuedAt: iat, expiration: exp)
}
func formatHeaders(usingIdentifier identifier: MockIdentifier) -> Header {

Просмотреть файл

@ -4,7 +4,6 @@
*--------------------------------------------------------------------------------------------*/
import VCJwt
import VCCrypto
public protocol IssuanceResponseFormatting {
func format(response: IssuanceResponseContainer, usingIdentifier identifier: MockIdentifier) throws -> IssuanceResponse
@ -33,7 +32,7 @@ public class IssuanceResponseFormatter: IssuanceResponseFormatting {
private func formatClaims(response: IssuanceResponseContainer, usingIdentifier identifier: MockIdentifier) throws -> IssuanceResponseClaims {
let publicKey = try signer.getPublicJwk(from: identifier.keyId, withKeyId: identifier.keyReference)
let (iat, exp) = createIatAndExp(expiryInSeconds: response.expiryInSeconds)
let timeConstraints = createTokenTimeConstraints(expiryInSeconds: response.expiryInSeconds)
return IssuanceResponseClaims(publicKeyThumbprint: try publicKey.getThumbprint(),
audience: response.audience,
@ -42,8 +41,8 @@ public class IssuanceResponseFormatter: IssuanceResponseFormatting {
contract: response.contractUri,
jti: UUID().uuidString,
attestations: self.formatAttestations(response: response),
iat: iat,
exp: exp)
iat: timeConstraints.issuedAt,
exp: timeConstraints.expiration)
}
private func formatAttestations(response: IssuanceResponseContainer) -> AttestationResponseDescriptor? {

Просмотреть файл

@ -4,7 +4,6 @@
*--------------------------------------------------------------------------------------------*/
import VCJwt
import VCCrypto
let CREDENTIAL_PATH = "$.attestations.presentations."
let CREDENTIAL_ENCODING = "base64Url"
@ -38,7 +37,7 @@ public class PresentationResponseFormatter: PresentationResponseFormatting {
private func formatClaims(response: PresentationResponseContainer, usingIdentifier identifier: MockIdentifier) throws -> PresentationResponseClaims {
let publicKey = try signer.getPublicJwk(from: identifier.keyId, withKeyId: identifier.keyReference)
let (iat, exp) = createIatAndExp(expiryInSeconds: response.expiryInSeconds)
let timeConstraints = createTokenTimeConstraints(expiryInSeconds: response.expiryInSeconds)
var presentationSubmission: PresentationSubmission? = nil
var attestations: AttestationResponseDescriptor? = nil
@ -56,8 +55,8 @@ public class PresentationResponseFormatter: PresentationResponseFormatting {
attestations: attestations,
state: response.request.content.state,
nonce: response.request.content.nonce,
iat: iat,
exp: exp)
iat: timeConstraints.issuedAt,
exp: timeConstraints.expiration)
}
private func formatPresentationSubmission(response: PresentationResponseContainer, keyType: String) -> PresentationSubmission {

Просмотреть файл

@ -0,0 +1,10 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
struct TokenTimeConstraints {
let issuedAt: Double
let expiration: Double
}

Просмотреть файл

@ -23,7 +23,7 @@ class VerifiablePresentationFormatter {
usingIdentifier identifier: MockIdentifier) throws -> VerifiablePresentation {
let headers = formatHeaders(usingIdentifier: identifier)
let (iat, exp) = createIatAndExp(expiryInSeconds: exp)
let timeConstraints = createTokenTimeConstraints(expiryInSeconds: exp)
let verifiablePresentationDescriptor = try self.createVerifiablePresentationDescriptor(toWrap: vc)
let vpClaims = VerifiablePresentationClaims(vpId: UUID().uuidString,
@ -31,8 +31,8 @@ class VerifiablePresentationFormatter {
verifiablePresentation: verifiablePresentationDescriptor,
issuerOfVp: identifier.id,
audience: audience,
iat: iat,
exp: exp)
iat: timeConstraints.issuedAt,
exp: timeConstraints.expiration)
var token = JwsToken<VerifiablePresentationClaims>(headers: headers, content: vpClaims)
try token.sign(using: self.signer, withSecret: identifier.keyId)

Просмотреть файл

@ -20,7 +20,5 @@ public struct PresentationResponseContainer {
self.audience = presentationRequest.content.redirectURI
self.request = presentationRequest
self.expiryInSeconds = exp
print(request.content.redirectURI)
}
}

Просмотреть файл

@ -46,15 +46,14 @@ public struct ECPublicJwk: Codable {
}
public func getThumbprint() throws -> String {
let hashAlgorithm = Sha256()
guard let encodedJwk = self.getMinimumAlphabeticJwk().data(using: .utf8) else {
throw VCJwtError.unableToParseString
}
print(String(data: encodedJwk, encoding: .utf8)!)
let hash = hashAlgorithm.hash(data: encodedJwk)
// print(String(data: hash, encoding: .utf8)!)
return hash.base64URLEncodedString()
}
}