Skip to content

Commit

Permalink
Merge pull request #54 from niscy-eudiw/IssuerSigned-CBOR
Browse files Browse the repository at this point in the history
Load and use document data as IssuerSigned array
  • Loading branch information
phisakel authored May 29, 2024
2 parents b57a84b + 240aa07 commit 2ee1be7
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 19 deletions.
12 changes: 6 additions & 6 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/eu-digital-identity-wallet/eudi-lib-ios-iso18013-data-model.git",
"state" : {
"revision" : "39134521d5c8df9302e60a1d98d3cb6405253d12",
"version" : "0.2.4"
"revision" : "bf62cc73ae2cea61e98020d2d037c153500207e7",
"version" : "0.2.5"
}
},
{
"identity" : "eudi-lib-ios-iso18013-data-transfer",
"kind" : "remoteSourceControl",
"location" : "https://github.com/eu-digital-identity-wallet/eudi-lib-ios-iso18013-data-transfer.git",
"state" : {
"revision" : "8840a914bd12f060b94b749fbf5a1af62799522c",
"version" : "0.2.5"
"revision" : "bf4b3d68fe600d502a2860c9d409f88877d2ec1a",
"version" : "0.2.6"
}
},
{
Expand Down Expand Up @@ -77,8 +77,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/eu-digital-identity-wallet/eudi-lib-ios-wallet-storage.git",
"state" : {
"revision" : "f66412818bc51b4f5b9fa6777914677da8ecf0c2",
"version" : "0.1.8"
"revision" : "10a4ab52f6224b49f098f0386a00268cb782010d",
"version" : "0.1.9"
}
},
{
Expand Down
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ let package = Package(
dependencies: [
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
.package(url: "https://github.com/apple/swift-log.git", from: "1.5.3"),
.package(url: "https://github.com/eu-digital-identity-wallet/eudi-lib-ios-iso18013-data-transfer.git", .upToNextMajor(from: "0.2.5")),
.package(url: "https://github.com/eu-digital-identity-wallet/eudi-lib-ios-wallet-storage.git", .upToNextMajor(from: "0.1.7")),
.package(url: "https://github.com/eu-digital-identity-wallet/eudi-lib-ios-iso18013-data-transfer.git", .upToNextMajor(from: "0.2.6")),
.package(url: "https://github.com/eu-digital-identity-wallet/eudi-lib-ios-wallet-storage.git", .upToNextMajor(from: "0.1.9")),
.package(url: "https://github.com/eu-digital-identity-wallet/eudi-lib-ios-siop-openid4vp-swift.git", exact: "0.0.74"),
.package(url: "https://github.com/eu-digital-identity-wallet/eudi-lib-ios-openid4vci-swift.git", exact: "0.0.7"),
],
Expand Down
18 changes: 13 additions & 5 deletions Sources/eudi-lib-ios-wallet-kit/EudiWallet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import WalletStorage
import LocalAuthentication
import CryptoKit
import OpenID4VCI
import SwiftCBOR

/// User wallet implementation
public final class EudiWallet: ObservableObject {
Expand Down Expand Up @@ -96,14 +97,21 @@ public final class EudiWallet: ObservableObject {
}

func finalizeIssuing(id: String, data: Data, docType: String?, format: DataFormat, issueReq: IssueRequest, openId4VCIService: OpenId4VCIService) async throws -> WalletStorage.Document {
let iss = IssuerSigned(data: [UInt8](data))
let deviceResponse = iss != nil ? nil : DeviceResponse(data: [UInt8](data))
guard let ddt = DocDataType(rawValue: format.rawValue) else { throw WalletError(description: "Invalid format \(format.rawValue)") }
let docTypeToSave = docType ?? (format == .cbor ? DeviceResponse(data: [UInt8](data))?.documents?.first?.docType : nil)
let docTypeToSave = docType ?? (format == .cbor ? iss?.issuerAuth.mso.docType ?? deviceResponse?.documents?.first?.docType : nil)
var dataToSave: Data? = data
if let deviceResponse {
if let iss = deviceResponse.documents?.first?.issuerSigned { dataToSave = Data(iss.encode(options: CBOROptions())) } else { dataToSave = nil }
}
guard let docTypeToSave else { throw WalletError(description: "Unknown document type") }
guard let dataToSave else { throw WalletError(description: "Issued data cannot be recognized") }
var issued: WalletStorage.Document
if !openId4VCIService.usedSecureEnclave {
issued = WalletStorage.Document(id: id, docType: docTypeToSave, docDataType: ddt, data: data, privateKeyType: .x963EncodedP256, privateKey: issueReq.keyData, createdAt: Date())
issued = WalletStorage.Document(id: id, docType: docTypeToSave, docDataType: ddt, data: dataToSave, privateKeyType: .x963EncodedP256, privateKey: issueReq.keyData, createdAt: Date())
} else {
issued = WalletStorage.Document(id: id, docType: docTypeToSave, docDataType: ddt, data: data, privateKeyType: .secureEnclaveP256, privateKey: issueReq.keyData, createdAt: Date())
issued = WalletStorage.Document(id: id, docType: docTypeToSave, docDataType: ddt, data: dataToSave, privateKeyType: .secureEnclaveP256, privateKey: issueReq.keyData, createdAt: Date())
}
try issueReq.saveToStorage(storage.storageService)
try endIssueDocument(issued)
Expand Down Expand Up @@ -186,7 +194,7 @@ public final class EudiWallet: ObservableObject {
try? storageService.deleteDocuments()
let docSamples = (sampleDataFiles ?? ["EUDI_sample_data"]).compactMap { Data(name:$0) }
.compactMap(SignUpResponse.decomposeCBORSignupResponse(data:)).flatMap {$0}
.map { Document(docType: $0.docType, docDataType: .cbor, data: $0.drData, privateKeyType: .x963EncodedP256, privateKey: $0.pkData, createdAt: Date.distantPast, modifiedAt: nil) }
.map { Document(docType: $0.docType, docDataType: .cbor, data: $0.issData, privateKeyType: .x963EncodedP256, privateKey: $0.pkData, createdAt: Date.distantPast, modifiedAt: nil) }
do {
for docSample in docSamples {
try storageService.saveDocument(docSample, allowOverwrite: true)
Expand All @@ -212,7 +220,7 @@ public final class EudiWallet: ObservableObject {
if let docType { guard docs.count > 0 else { throw WalletError(description: "No documents of type \(docType) found") } }
let cborsWithKeys = docs.compactMap { $0.getCborData() }
guard cborsWithKeys.count > 0 else { throw WalletError(description: "Documents decode error") }
parameters = [InitializeKeys.document_signup_response_obj.rawValue: cborsWithKeys.map(\.dr), InitializeKeys.device_private_key_obj.rawValue: cborsWithKeys.map(\.dpk)]
parameters = [InitializeKeys.document_signup_issuer_signed_obj.rawValue: cborsWithKeys.map(\.iss), InitializeKeys.device_private_key_obj.rawValue: cborsWithKeys.map(\.dpk)]
if let trustedReaderCertificates { parameters[InitializeKeys.trusted_certificates.rawValue] = trustedReaderCertificates }
parameters[InitializeKeys.device_auth_method.rawValue] = deviceAuthMethod.rawValue
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import X509
public class OpenId4VpService: PresentationService {
public var status: TransferStatus = .initialized
var openid4VPlink: String
var docs: [DeviceResponse]!
var docs: [IssuerSigned]!
var iaca: [SecCertificate]!
var dauthMethod: DeviceAuthMethod
var devicePrivateKeys: [CoseKeyPrivate]!
Expand Down Expand Up @@ -114,7 +114,7 @@ public class OpenId4VpService: PresentationService {
return
}
logger.info("Openid4vp request items: \(itemsToSend)")
guard let (deviceResponse, _, _) = try MdocHelpers.getDeviceResponseToSend(deviceRequest: nil, deviceResponses: docs, selectedItems: itemsToSend, eReaderKey: eReaderPub, devicePrivateKeys: devicePrivateKeys, sessionTranscript: sessionTranscript, dauthMethod: .deviceSignature) else { throw PresentationSession.makeError(str: "DOCUMENT_ERROR") }
guard let (deviceResponse, _, _) = try MdocHelpers.getDeviceResponseToSend(deviceRequest: nil, issuerSigned: docs, selectedItems: itemsToSend, eReaderKey: eReaderPub, devicePrivateKeys: devicePrivateKeys, sessionTranscript: sessionTranscript, dauthMethod: .deviceSignature) else { throw PresentationSession.makeError(str: "DOCUMENT_ERROR") }
// Obtain consent
let vpTokenStr = Data(deviceResponse.toCBOR(options: CBOROptions()).encode()).base64URLEncodedString()
try await SendVpToken(vpTokenStr, pd, resolved, onSuccess)
Expand Down
8 changes: 4 additions & 4 deletions Sources/eudi-lib-ios-wallet-kit/Services/StorageManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ public class StorageManager: ObservableObject {
}

func toModel(doc: WalletStorage.Document) -> (any MdocDecodable)? {
guard let (dr,dpk) = doc.getCborData() else { return nil }
guard let (iss,dpk) = doc.getCborData() else { return nil }
return switch doc.docType {
case EuPidModel.euPidDocType: EuPidModel(id: doc.id, createdAt: doc.createdAt, response: dr, devicePrivateKey: dpk)
case IsoMdlModel.isoDocType: IsoMdlModel(id: doc.id, createdAt: doc.createdAt, response: dr, devicePrivateKey: dpk)
default: GenericMdocModel(id: doc.id, createdAt: doc.createdAt, response: dr, devicePrivateKey: dpk, docType: doc.docType, title: doc.docType.translated())
case EuPidModel.euPidDocType: EuPidModel(id: doc.id, createdAt: doc.createdAt, issuerSigned: iss, devicePrivateKey: dpk)
case IsoMdlModel.isoDocType: IsoMdlModel(id: doc.id, createdAt: doc.createdAt, issuerSigned: iss, devicePrivateKey: dpk)
default: GenericMdocModel(id: doc.id, createdAt: doc.createdAt, issuerSigned: iss, devicePrivateKey: dpk, docType: doc.docType, title: doc.docType.translated())
}
}

Expand Down

0 comments on commit 2ee1be7

Please sign in to comment.