Skip to content
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

Changes for Secure Enclave use #14

Merged
merged 9 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Documentation/Reference/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- [BlePresentationService](classes/BlePresentationService.md)
- [EudiWallet](classes/EudiWallet.md)
- [FaultPresentationService](classes/FaultPresentationService.md)
- [OpenId4VCIService](classes/OpenId4VCIService.md)
- [OpenId4VpService](classes/OpenId4VpService.md)
- [PresentationSession](classes/PresentationSession.md)
- [StorageManager](classes/StorageManager.md)
Expand All @@ -23,6 +24,7 @@

- [DataFormat](enums/DataFormat.md)
- [FlowType](enums/FlowType.md)
- [OpenId4VCIError](enums/OpenId4VCIError.md)
- [StorageType](enums/StorageType.md)

## Extensions
Expand All @@ -35,4 +37,4 @@

- [RequestItems](typealiases/RequestItems.md)

This file was generated by [SourceDocs](https://github.com/eneko/SourceDocs) on 2024-01-17 20:51:33 +0000
This file was generated by [SourceDocs](https://github.com/eneko/SourceDocs) on 2024-01-29 17:50:11 +0000
81 changes: 58 additions & 23 deletions Documentation/Reference/classes/EudiWallet.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,23 @@
- `standard`
- `userAuthenticationRequired`
- `trustedReaderCertificates`
- `deviceAuthMethod`
- `verifierApiUri`
- `vciIssuerUrl`
- `vciClientId`
- `vciRedirectUri`
- `openID4VciIssuerUrl`
- `openID4VciClientId`
- `useSecureEnclave`
- [Methods](#methods)
- `init(storageType:serviceName:accessGroup:trustedReaderCertificates:userAuthenticationRequired:verifierApiUri:vciIssuerUrl:vciClientId:vciRedirectUri:)`
- `issueDocument(docType:format:useSecureEnclave:)`
- `beginIssueDocument(id:)`
- `init(storageType:serviceName:accessGroup:trustedReaderCertificates:userAuthenticationRequired:verifierApiUri:openID4VciIssuerUrl:openID4VciClientId:)`
- `issueDocument(docType:format:)`
- `beginIssueDocument(id:privateKeyType:)`
- `endIssueDocument(_:)`
- `loadDocuments()`
- `deleteDocuments()`
- `loadSampleData(sampleDataFiles:)`
- `prepareServiceDataParameters(docType:dataFormat:)`
- `beginPresentation(flow:docType:dataFormat:)`
- `beginPresentation(service:)`
- `authorizedAction(dismiss:action:)`
- `authorizedAction(action:disabled:dismiss:localizedReason:)`

```swift
public final class EudiWallet: ObservableObject
Expand All @@ -39,6 +40,8 @@ User wallet implementation
public private(set) var storage: StorageManager
```

Storage manager instance

### `standard`

```swift
Expand All @@ -63,6 +66,14 @@ public var trustedReaderCertificates: [Data]?

Trusted root certificates to validate the reader authentication certificate included in the proximity request

### `deviceAuthMethod`

```swift
public var deviceAuthMethod: DeviceAuthMethod = .deviceMac
```

Method to perform mdoc authentication (MAC or signature). Defaults to device MAC

### `verifierApiUri`

```swift
Expand All @@ -71,46 +82,61 @@ public var verifierApiUri: String?

OpenID4VP verifier api URL (used for preregistered clients)

### `vciIssuerUrl`
### `openID4VciIssuerUrl`

```swift
public var vciIssuerUrl: String?
public var openID4VciIssuerUrl: String?
```

### `vciClientId`
OpenID4VCI issuer url

### `openID4VciClientId`

```swift
public var vciClientId: String?
public var openID4VciClientId: String?
```

### `vciRedirectUri`
OpenID4VCI client id

### `useSecureEnclave`

```swift
public var vciRedirectUri: String = "eudi-openid4ci://authorize/"
public var useSecureEnclave: Bool
```

Use iPhone Secure Enclave to protect keys and perform cryptographic operations. Defaults to true (if available)

## Methods
### `init(storageType:serviceName:accessGroup:trustedReaderCertificates:userAuthenticationRequired:verifierApiUri:vciIssuerUrl:vciClientId:vciRedirectUri:)`
### `init(storageType:serviceName:accessGroup:trustedReaderCertificates:userAuthenticationRequired:verifierApiUri:openID4VciIssuerUrl:openID4VciClientId:)`

```swift
public init(storageType: StorageType = .keyChain, serviceName: String = "eudiw", accessGroup: String? = nil, trustedReaderCertificates: [Data]? = nil, userAuthenticationRequired: Bool = true, verifierApiUri: String? = nil, vciIssuerUrl: String? = nil, vciClientId: String? = nil, vciRedirectUri: String? = nil)
public init(storageType: StorageType = .keyChain, serviceName: String = "eudiw", accessGroup: String? = nil, trustedReaderCertificates: [Data]? = nil, userAuthenticationRequired: Bool = true, verifierApiUri: String? = nil, openID4VciIssuerUrl: String? = nil, openID4VciClientId: String? = nil)
```

### `issueDocument(docType:format:useSecureEnclave:)`
Initialize a wallet instance. All parameters are optional.

### `issueDocument(docType:format:)`

```swift
@discardableResult public func issueDocument(docType: String, format: DataFormat = .cbor, useSecureEnclave: Bool = false) async throws -> WalletStorage.Document
@discardableResult public func issueDocument(docType: String, format: DataFormat = .cbor) async throws -> WalletStorage.Document
```

### `beginIssueDocument(id:)`
Issue a document with the given docType using OpenId4Vci protocol

If ``userAuthenticationRequired`` is true, user authentication is required. The authentication prompt message has localisation key "issue_document"
- Parameters:
- docType: Document type
- format: Optional format type. Defaults to cbor
- Returns: The document issued. It is saved in storage.

### `beginIssueDocument(id:privateKeyType:)`

```swift
public func beginIssueDocument(id: String) async throws -> IssueRequest
public func beginIssueDocument(id: String, privateKeyType: PrivateKeyType = .secureEnclaveP256) async throws -> IssueRequest
```

Issue a document and save in wallet storage
Begin issuing a document by generating an issue request

** Not tested **
- Parameters:
- id: Document identifier
- issuer: Issuer function
Expand All @@ -128,6 +154,15 @@ Issue a document and save in wallet storage
public func endIssueDocument(_ issued: WalletStorage.Document) throws
```

End issuing by saving the issuing document (and its private key) in storage
- Parameter issued: The issued document

#### Parameters

| Name | Description |
| ---- | ----------- |
| issued | The issued document |

### `loadDocuments()`

```swift
Expand Down Expand Up @@ -228,10 +263,10 @@ Begin attestation presentation to a verifier
| docType | DocType of documents to present (optional) |
| dataFormat | Exchanged data `Format` type |

### `authorizedAction(dismiss:action:)`
### `authorizedAction(action:disabled:dismiss:localizedReason:)`

```swift
public static func authorizedAction(dismiss: () -> Void, action: () async throws -> Void) async throws
public static func authorizedAction(action: () async throws -> Void, disabled: Bool, dismiss: () -> Void, localizedReason: String) async throws
```

Perform an action after user authorization via TouchID/FaceID/Passcode
Expand Down
42 changes: 42 additions & 0 deletions Documentation/Reference/classes/OpenId4VCIService.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
**CLASS**

# `OpenId4VCIService`

**Contents**

- [Methods](#methods)
- `issueDocument(docType:format:useSecureEnclave:)`
- `presentationAnchor(for:)`

```swift
public class OpenId4VCIService: NSObject, ASWebAuthenticationPresentationContextProviding
```

## Methods
### `issueDocument(docType:format:useSecureEnclave:)`

```swift
public func issueDocument(docType: String, format: DataFormat, useSecureEnclave: Bool) async throws -> Data
```

Issue a document with the given `docType` using OpenId4Vci protocol
- Parameters:
- docType: the docType of the document to be issued
- format: format of the exchanged data
- useSecureEnclave: use secure enclave to protect the private key
- Returns: The data of the document

#### Parameters

| Name | Description |
| ---- | ----------- |
| docType | the docType of the document to be issued |
| format | format of the exchanged data |
| useSecureEnclave | use secure enclave to protect the private key |

### `presentationAnchor(for:)`

```swift
public func presentationAnchor(for session: ASWebAuthenticationSession)
-> ASPresentationAnchor
```
6 changes: 3 additions & 3 deletions Documentation/Reference/classes/PresentationSession.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
- `status`
- `deviceEngagement`
- [Methods](#methods)
- `init(presentationService:)`
- `init(presentationService:userAuthenticationRequired:)`
- `makeError(str:)`
- `makeError(code:str:)`
- `startQrEngagement()`
Expand Down Expand Up @@ -93,10 +93,10 @@ Status of the data transfer.
Device engagement data (QR image data for the BLE flow)

## Methods
### `init(presentationService:)`
### `init(presentationService:userAuthenticationRequired:)`

```swift
public init(presentationService: any PresentationService)
public init(presentationService: any PresentationService, userAuthenticationRequired: Bool)
```

### `makeError(str:)`
Expand Down
70 changes: 70 additions & 0 deletions Documentation/Reference/enums/OpenId4VCIError.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
**ENUM**

# `OpenId4VCIError`

**Contents**

- [Cases](#cases)
- `authRequestFailed(_:)`
- `authorizeResponseNoUrl`
- `authorizeResponseNoCode`
- `tokenRequestFailed(_:)`
- `tokenResponseNoData`
- `tokenResponseInvalidData(_:)`
- `dataNotValid`
- [Properties](#properties)
- `localizedDescription`

```swift
public enum OpenId4VCIError: LocalizedError
```

## Cases
### `authRequestFailed(_:)`

```swift
case authRequestFailed(Error)
```

### `authorizeResponseNoUrl`

```swift
case authorizeResponseNoUrl
```

### `authorizeResponseNoCode`

```swift
case authorizeResponseNoCode
```

### `tokenRequestFailed(_:)`

```swift
case tokenRequestFailed(Error)
```

### `tokenResponseNoData`

```swift
case tokenResponseNoData
```

### `tokenResponseInvalidData(_:)`

```swift
case tokenResponseInvalidData(String)
```

### `dataNotValid`

```swift
case dataNotValid
```

## Properties
### `localizedDescription`

```swift
public var localizedDescription: String
```
16 changes: 8 additions & 8 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/eu-digital-identity-wallet/eudi-lib-ios-iso18013-data-model.git",
"state" : {
"revision" : "7f7f98e53de6f75796be405265cb060a4a1073d5",
"version" : "0.1.8"
"revision" : "f9811c94bdd6ea756a14f00aff9507eb932ae03d",
"version" : "0.2.0"
}
},
{
Expand All @@ -41,8 +41,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/eu-digital-identity-wallet/eudi-lib-ios-iso18013-security.git",
"state" : {
"revision" : "be8092f90ae8ce669f6a88c1ac5345d31e44ecd8",
"version" : "0.1.6"
"revision" : "4c8b26fbdbcf8c6110a0e12ba49c59c8158a1b12",
"version" : "0.1.7"
}
},
{
Expand Down Expand Up @@ -86,8 +86,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/KittyMac/Hitch.git",
"state" : {
"revision" : "49e0c7250edc237e05631b47534bd4839951b413",
"version" : "0.4.116"
"revision" : "b23dba215ecaf089996b6975cdc996376ce27cd5",
"version" : "0.4.117"
}
},
{
Expand Down Expand Up @@ -203,8 +203,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-log.git",
"state" : {
"revision" : "532d8b529501fb73a2455b179e0bbb6d49b652ed",
"version" : "1.5.3"
"revision" : "e97a6fcb1ab07462881ac165fdbb37f067e205d5",
"version" : "1.5.4"
}
},
{
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ After the request is received the ``presentationSession.disclosedDocuments`` con
The library provides the functionality to issue documents using OpenID4VCI. To issue a document
using this functionality, EudiWallet must be property initialized.
To issue a document using OpenID4VCI, you need to know the document's docType.
If ``userAuthenticationRequired`` is true, user authentication is required. The authentication prompt message has localisation key "issue_document".
```swift
wallet.vciIssuerUrl = "https://eudi.netcompany-intrasoft.com/pid-issuer"
wallet.vciClientId = "wallet-dev"
wallet.vciRedirectUri = "eudi-openid4ci://authorize/" // this is the default value,if not specified
wallet.openID4VciIssuerUrl = "https://eudi.netcompany-intrasoft.com/pid-issuer"
wallet.openID4VciClientId = "wallet-dev"
do {
let doc = try await userWallet.issueDocument(docType: EuPidModel.euPidDocType, format: .cbor)
// document has been added to wallet storage, you can display it
Expand Down
Loading
Loading