-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
118 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import 'dart:typed_data'; | ||
|
||
import 'package:convert/convert.dart'; | ||
import 'package:dart_pcsc/dart_pcsc.dart'; | ||
import 'package:fido2/fido2.dart'; | ||
|
||
class CtapCcid extends CtapDevice { | ||
final Card _card; | ||
|
||
CtapCcid(this._card); | ||
|
||
@override | ||
Future<CtapResponse<List<int>>> transceive(List<int> command) async { | ||
List<int> lc; | ||
if (command.length <= 255) { | ||
lc = [command.length]; | ||
} else { | ||
lc = [0, command.length >> 8, command.length & 0xff]; | ||
} | ||
List<int> capdu = [0x80, 0x10, 0x00, 0x00, ...lc, ...command]; | ||
List<int> rapdu = List.empty(); | ||
do { | ||
if (rapdu.length >= 2) { | ||
var remain = rapdu[rapdu.length - 1]; | ||
capdu = [0x80, 0xC0, 0x00, 0x00, remain]; | ||
rapdu = rapdu.sublist(0, rapdu.length - 2); | ||
} | ||
rapdu += await _card.transmit(Uint8List.fromList(capdu)); | ||
} while (rapdu.length >= 2 && rapdu[rapdu.length - 2] == 0x61); | ||
return CtapResponse(rapdu[0], rapdu.sublist(1, rapdu.length - 2)); | ||
} | ||
} | ||
|
||
void main() async { | ||
final context = Context(Scope.user); | ||
try { | ||
await context.establish(); | ||
|
||
Card card = await context.connect( | ||
'Canokeys Canokey', | ||
ShareMode.shared, | ||
Protocol.any, | ||
); | ||
|
||
Uint8List resp = await card.transmit( | ||
Uint8List.fromList(hex.decode('00A4040008A0000006472F0001')), | ||
); | ||
int status = (resp[resp.length - 2] << 8) + resp[resp.length - 1]; | ||
print('Status: 0x${status.toRadixString(16)}'); | ||
|
||
CtapDevice device = CtapCcid(card); | ||
final ctap = await Ctap2.create(device); | ||
print(ctap.info.versions); | ||
final cp = await ClientPin.create(ctap); | ||
print(await cp.getPinRetries()); | ||
|
||
await card.disconnect(Disposition.resetCard); | ||
} finally { | ||
await context.release(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,5 +14,6 @@ dependencies: | |
quiver: ^3.2.1 | ||
|
||
dev_dependencies: | ||
lints: ^2.1.0 | ||
lints: ^3.0.0 | ||
test: ^1.24.0 | ||
dart_pcsc: ^2.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters