diff --git a/README.md b/README.md index 4257580..f090aa5 100644 --- a/README.md +++ b/README.md @@ -173,6 +173,8 @@ export default function App() { setFlow( new AusweisAuthFlow({ debug: true, + // Can set to true to allow simulator cards. In this case `onEnterPin` and `onAttachCard` won't be called + allowSimulatorCard: false, onEnterPin: ({ attemptsRemaining }) => { // Mock incorrect pin entry return attemptsRemaining === 1 ? '123456' : '123123' diff --git a/ausweis-example/app/index.tsx b/ausweis-example/app/index.tsx index 830e82e..ade561a 100644 --- a/ausweis-example/app/index.tsx +++ b/ausweis-example/app/index.tsx @@ -24,6 +24,8 @@ export default function App() { setFlow( new AusweisAuthFlow({ debug: true, + // Can set to true to allow simulator cards + allowSimulatorCard: false, onEnterPin: ({ attemptsRemaining }) => { // Mock incorrect pin entry return attemptsRemaining === 1 ? '123456' : '123123' diff --git a/ios/AusweisSdk.podspec b/ios/AusweisSdk.podspec index fc5ca29..06d4643 100644 --- a/ios/AusweisSdk.podspec +++ b/ios/AusweisSdk.podspec @@ -25,5 +25,5 @@ Pod::Spec.new do |s| s.source_files = "**/*.{h,m,swift}" - s.dependency 'AusweisApp2' + s.dependency 'AusweisApp2', '2.2.1' end diff --git a/src/AusweisAuthFlow.ts b/src/AusweisAuthFlow.ts index af7fdff..1e3aca0 100644 --- a/src/AusweisAuthFlow.ts +++ b/src/AusweisAuthFlow.ts @@ -37,7 +37,7 @@ export interface AusweisAuthFlowOptions { /** * callback that will be called when a card is attached/detached from the NFC scanner. */ - onCardAttachedChanged?: (options: { isCardAttached: boolean }) => void + onCardAttachedChanged?: (options: { isCardAttached: boolean; isSimulator: boolean }) => void /** * callback that will be called with status updates on the auth flow progress. @@ -110,6 +110,11 @@ export interface AusweisAuthFlowOptions { */ debug?: boolean + /** + * Will enable the use of a simulator card if available. Note that this can only be used in test environments + */ + allowSimulatorCard?: boolean + iosNfcModalMessages?: AusweisSdkRunAuthCommand['messages'] } @@ -125,6 +130,7 @@ export class AusweisAuthFlow { private messageListener?: Subscription private sentCommands: Array = [] private isSdkInitialized = false + private isSimulatorCardAttached = false public constructor(private options: AusweisAuthFlowOptions) {} @@ -239,10 +245,21 @@ export class AusweisAuthFlow { if (message.msg === 'READER') { // If card is empty object the card is unknown, we see that as no card attached for this flow - const isCardAttached = message.card !== null && message.card !== undefined && Object.keys(message.card).length > 0 + const isSimulator = message.name === 'Simulator' + const isCardAttached = + message.attached && + (isSimulator || (message.card !== null && message.card !== undefined && Object.keys(message.card).length > 0)) + + if (isSimulator) this.isSimulatorCardAttached = isCardAttached + console.log({ + isCardAttached, + isSimulator, + isSimulatorCardAttached: this.isSimulatorCardAttached, + }) this.options.onCardAttachedChanged?.({ isCardAttached, + isSimulator, }) } @@ -253,6 +270,13 @@ export class AusweisAuthFlow { } if (message.msg === 'INSERT_CARD') { + if (this.options.allowSimulatorCard && this.isSimulatorCardAttached) { + this.sendCommand({ + cmd: 'SET_CARD', + name: 'Simulator', + }) + return + } this.options.onAttachCard?.() } @@ -316,6 +340,13 @@ export class AusweisAuthFlow { const retryCounter = message.reader.card?.retryCounter ?? 3 try { + if (this.options.allowSimulatorCard && this.isSimulatorCardAttached) { + this.sendCommand({ + cmd: 'SET_PIN', + }) + return + } + // The attempts remaining is weird. The retryCounter when 1 will require the CAN. If it's 0 it requires // the PUK. We don't support setting CAN / PUK in this flow so we substract 1 from the retry counter. // There is the case however if the user unlocked the card using CAN in e.g. the Ausweis App (not SDK) diff --git a/src/AusweisSdkCommands.ts b/src/AusweisSdkCommands.ts index 47ede45..8dc58f0 100644 --- a/src/AusweisSdkCommands.ts +++ b/src/AusweisSdkCommands.ts @@ -171,10 +171,12 @@ export interface AusweisSdkInterruptCommand extends BaseAusweisSdkCommandPayload /** * SET_PIN command payload to set the PIN of inserted card. + * + * `value` can be omitted in case of simulator card. */ export interface AusweisSdkSetPinCommand extends BaseAusweisSdkCommandPayload { cmd: 'SET_PIN' - value: string + value?: string } /**