@doko/react-native-yubikit 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -0
- package/README.md +126 -0
- package/RNYubikit.podspec +22 -0
- package/android/build.gradle +63 -0
- package/android/src/main/AndroidManifest.xml +9 -0
- package/android/src/main/java/com/yubikit/YubiKitManagerHolder.kt +330 -0
- package/android/src/main/java/com/yubikit/YubikitCoreModule.kt +142 -0
- package/android/src/main/java/com/yubikit/YubikitFidoModule.kt +418 -0
- package/android/src/main/java/com/yubikit/YubikitManagementModule.kt +132 -0
- package/android/src/main/java/com/yubikit/YubikitOathModule.kt +224 -0
- package/android/src/main/java/com/yubikit/YubikitOpenPgpModule.kt +317 -0
- package/android/src/main/java/com/yubikit/YubikitPackage.kt +44 -0
- package/android/src/main/java/com/yubikit/YubikitPivModule.kt +310 -0
- package/android/src/main/java/com/yubikit/YubikitSupportModule.kt +108 -0
- package/android/src/main/java/com/yubikit/YubikitYubiOtpModule.kt +248 -0
- package/android/src/main/java/com/yubikit/utils/YubikitUtils.kt +321 -0
- package/ios/YubikitCore.h +5 -0
- package/ios/YubikitCore.mm +101 -0
- package/ios/YubikitDeviceInfoHelper.h +13 -0
- package/ios/YubikitDeviceInfoHelper.mm +110 -0
- package/ios/YubikitFido.h +5 -0
- package/ios/YubikitFido.mm +373 -0
- package/ios/YubikitManagement.h +5 -0
- package/ios/YubikitManagement.mm +153 -0
- package/ios/YubikitManager.h +27 -0
- package/ios/YubikitManager.m +169 -0
- package/ios/YubikitOath.h +5 -0
- package/ios/YubikitOath.mm +583 -0
- package/ios/YubikitOpenPgp.h +5 -0
- package/ios/YubikitOpenPgp.mm +210 -0
- package/ios/YubikitPiv.h +5 -0
- package/ios/YubikitPiv.mm +813 -0
- package/ios/YubikitSupport.h +5 -0
- package/ios/YubikitSupport.mm +58 -0
- package/ios/YubikitYubiOtp.h +5 -0
- package/ios/YubikitYubiOtp.mm +120 -0
- package/lib/module/core.js +34 -0
- package/lib/module/core.js.map +1 -0
- package/lib/module/fido.js +40 -0
- package/lib/module/fido.js.map +1 -0
- package/lib/module/hooks/index.js +5 -0
- package/lib/module/hooks/index.js.map +1 -0
- package/lib/module/hooks/use-yubikey.js +12 -0
- package/lib/module/hooks/use-yubikey.js.map +1 -0
- package/lib/module/hooks/yubikey-provider.js +85 -0
- package/lib/module/hooks/yubikey-provider.js.map +1 -0
- package/lib/module/index.js +12 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/management.js +17 -0
- package/lib/module/management.js.map +1 -0
- package/lib/module/oath.js +53 -0
- package/lib/module/oath.js.map +1 -0
- package/lib/module/openpgp.js +89 -0
- package/lib/module/openpgp.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/piv.js +71 -0
- package/lib/module/piv.js.map +1 -0
- package/lib/module/specs/NativeYubikitCore.js +10 -0
- package/lib/module/specs/NativeYubikitCore.js.map +1 -0
- package/lib/module/specs/NativeYubikitFido.js +5 -0
- package/lib/module/specs/NativeYubikitFido.js.map +1 -0
- package/lib/module/specs/NativeYubikitManagement.js +5 -0
- package/lib/module/specs/NativeYubikitManagement.js.map +1 -0
- package/lib/module/specs/NativeYubikitOath.js +5 -0
- package/lib/module/specs/NativeYubikitOath.js.map +1 -0
- package/lib/module/specs/NativeYubikitOpenPgp.js +5 -0
- package/lib/module/specs/NativeYubikitOpenPgp.js.map +1 -0
- package/lib/module/specs/NativeYubikitPiv.js +5 -0
- package/lib/module/specs/NativeYubikitPiv.js.map +1 -0
- package/lib/module/specs/NativeYubikitSupport.js +5 -0
- package/lib/module/specs/NativeYubikitSupport.js.map +1 -0
- package/lib/module/specs/NativeYubikitYubiOtp.js +5 -0
- package/lib/module/specs/NativeYubikitYubiOtp.js.map +1 -0
- package/lib/module/support.js +11 -0
- package/lib/module/support.js.map +1 -0
- package/lib/module/types.js +2 -0
- package/lib/module/types.js.map +1 -0
- package/lib/module/yubiotp.js +32 -0
- package/lib/module/yubiotp.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/core.d.ts +14 -0
- package/lib/typescript/src/core.d.ts.map +1 -0
- package/lib/typescript/src/fido.d.ts +24 -0
- package/lib/typescript/src/fido.d.ts.map +1 -0
- package/lib/typescript/src/hooks/index.d.ts +3 -0
- package/lib/typescript/src/hooks/index.d.ts.map +1 -0
- package/lib/typescript/src/hooks/use-yubikey.d.ts +3 -0
- package/lib/typescript/src/hooks/use-yubikey.d.ts.map +1 -0
- package/lib/typescript/src/hooks/yubikey-provider.d.ts +23 -0
- package/lib/typescript/src/hooks/yubikey-provider.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +10 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/management.d.ts +8 -0
- package/lib/typescript/src/management.d.ts.map +1 -0
- package/lib/typescript/src/oath.d.ts +20 -0
- package/lib/typescript/src/oath.d.ts.map +1 -0
- package/lib/typescript/src/openpgp.d.ts +35 -0
- package/lib/typescript/src/openpgp.d.ts.map +1 -0
- package/lib/typescript/src/piv.d.ts +26 -0
- package/lib/typescript/src/piv.d.ts.map +1 -0
- package/lib/typescript/src/specs/NativeYubikitCore.d.ts +49 -0
- package/lib/typescript/src/specs/NativeYubikitCore.d.ts.map +1 -0
- package/lib/typescript/src/specs/NativeYubikitFido.d.ts +121 -0
- package/lib/typescript/src/specs/NativeYubikitFido.d.ts.map +1 -0
- package/lib/typescript/src/specs/NativeYubikitManagement.d.ts +53 -0
- package/lib/typescript/src/specs/NativeYubikitManagement.d.ts.map +1 -0
- package/lib/typescript/src/specs/NativeYubikitOath.d.ts +70 -0
- package/lib/typescript/src/specs/NativeYubikitOath.d.ts.map +1 -0
- package/lib/typescript/src/specs/NativeYubikitOpenPgp.d.ts +53 -0
- package/lib/typescript/src/specs/NativeYubikitOpenPgp.d.ts.map +1 -0
- package/lib/typescript/src/specs/NativeYubikitPiv.d.ts +47 -0
- package/lib/typescript/src/specs/NativeYubikitPiv.d.ts.map +1 -0
- package/lib/typescript/src/specs/NativeYubikitSupport.d.ts +49 -0
- package/lib/typescript/src/specs/NativeYubikitSupport.d.ts.map +1 -0
- package/lib/typescript/src/specs/NativeYubikitYubiOtp.d.ts +45 -0
- package/lib/typescript/src/specs/NativeYubikitYubiOtp.d.ts.map +1 -0
- package/lib/typescript/src/support.d.ts +6 -0
- package/lib/typescript/src/support.d.ts.map +1 -0
- package/lib/typescript/src/types.d.ts +293 -0
- package/lib/typescript/src/types.d.ts.map +1 -0
- package/lib/typescript/src/yubiotp.d.ts +13 -0
- package/lib/typescript/src/yubiotp.d.ts.map +1 -0
- package/package.json +181 -0
- package/src/core.ts +58 -0
- package/src/fido.ts +112 -0
- package/src/hooks/index.tsx +2 -0
- package/src/hooks/use-yubikey.tsx +10 -0
- package/src/hooks/yubikey-provider.tsx +146 -0
- package/src/index.tsx +10 -0
- package/src/management.ts +44 -0
- package/src/oath.ts +134 -0
- package/src/openpgp.ts +220 -0
- package/src/piv.ts +193 -0
- package/src/specs/NativeYubikitCore.ts +68 -0
- package/src/specs/NativeYubikitFido.ts +149 -0
- package/src/specs/NativeYubikitManagement.ts +78 -0
- package/src/specs/NativeYubikitOath.ts +110 -0
- package/src/specs/NativeYubikitOpenPgp.ts +148 -0
- package/src/specs/NativeYubikitPiv.ts +108 -0
- package/src/specs/NativeYubikitSupport.ts +61 -0
- package/src/specs/NativeYubikitYubiOtp.ts +82 -0
- package/src/support.ts +18 -0
- package/src/types.ts +404 -0
- package/src/yubiotp.ts +96 -0
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
#import "YubikitManager.h"
|
|
2
|
+
|
|
3
|
+
@interface YubikitManager ()
|
|
4
|
+
@property(nonatomic, strong) NSMutableDictionary<NSString *, id<YKFConnectionProtocol>> *connections;
|
|
5
|
+
@property(nonatomic, strong) NSMutableDictionary<NSString *, NSString *> *deviceTransports;
|
|
6
|
+
@property(nonatomic, assign) BOOL usbActive;
|
|
7
|
+
@property(nonatomic, assign) BOOL nfcActive;
|
|
8
|
+
@end
|
|
9
|
+
|
|
10
|
+
@implementation YubikitManager
|
|
11
|
+
|
|
12
|
+
+ (instancetype)shared {
|
|
13
|
+
static YubikitManager *shared = nil;
|
|
14
|
+
static dispatch_once_t onceToken;
|
|
15
|
+
dispatch_once(&onceToken, ^{
|
|
16
|
+
shared = [[self alloc] init];
|
|
17
|
+
});
|
|
18
|
+
return shared;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
- (instancetype)init {
|
|
22
|
+
self = [super init];
|
|
23
|
+
if (self) {
|
|
24
|
+
_connections = [NSMutableDictionary dictionary];
|
|
25
|
+
_deviceTransports = [NSMutableDictionary dictionary];
|
|
26
|
+
_usbActive = NO;
|
|
27
|
+
_nfcActive = NO;
|
|
28
|
+
}
|
|
29
|
+
return self;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
- (void)startUsbDiscovery {
|
|
33
|
+
if (self.usbActive) return;
|
|
34
|
+
self.usbActive = YES;
|
|
35
|
+
[YubiKitManager shared].delegate = self;
|
|
36
|
+
[[YubiKitManager shared] startAccessoryConnection];
|
|
37
|
+
if (@available(iOS 16.0, *)) {
|
|
38
|
+
[[YubiKitManager shared] startSmartCardConnection];
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
- (void)stopUsbDiscovery {
|
|
43
|
+
if (!self.usbActive) return;
|
|
44
|
+
self.usbActive = NO;
|
|
45
|
+
[[YubiKitManager shared] stopAccessoryConnection];
|
|
46
|
+
if (@available(iOS 16.0, *)) {
|
|
47
|
+
[[YubiKitManager shared] stopSmartCardConnection];
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
- (void)startNfcDiscovery {
|
|
52
|
+
if (self.nfcActive) return;
|
|
53
|
+
self.nfcActive = YES;
|
|
54
|
+
[YubiKitManager shared].delegate = self;
|
|
55
|
+
[[YubiKitManager shared] startNFCConnection];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
- (void)stopNfcDiscovery {
|
|
59
|
+
if (!self.nfcActive) return;
|
|
60
|
+
self.nfcActive = NO;
|
|
61
|
+
[[YubiKitManager shared] stopNFCConnection];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
- (nullable id<YKFConnectionProtocol>)connectionForHandle:(NSString *)handle {
|
|
65
|
+
return self.connections[handle];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
- (void)removeConnectionForHandle:(NSString *)handle {
|
|
69
|
+
[self.connections removeObjectForKey:handle];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
- (NSArray<NSDictionary *> *)listDevices {
|
|
73
|
+
NSMutableArray<NSDictionary *> *result = [NSMutableArray array];
|
|
74
|
+
[self.connections enumerateKeysAndObjectsUsingBlock:^(NSString *handle, id<YKFConnectionProtocol> connection, BOOL *stop) {
|
|
75
|
+
[result addObject:[self deviceDictForHandle:handle connection:connection]];
|
|
76
|
+
}];
|
|
77
|
+
return result;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
#pragma mark - Event emission
|
|
81
|
+
|
|
82
|
+
- (NSDictionary *)deviceDictForHandle:(NSString *)handle connection:(id<YKFConnectionProtocol>)connection {
|
|
83
|
+
NSString *transport = self.deviceTransports[handle] ?: @"usb";
|
|
84
|
+
// Every YKFConnectionProtocol-conforming connection (NFC/Accessory/SmartCard) exposes
|
|
85
|
+
// the same set of session accessors (oathSession/pivSession/fido2Session/
|
|
86
|
+
// challengeResponseSession/managementSession) regardless of transport - unlike
|
|
87
|
+
// Android, where SmartCardConnection/OtpConnection/FidoConnection are distinct
|
|
88
|
+
// connection objects that a device may or may not support. The previous check here
|
|
89
|
+
// (`isKindOfClass:[YKFSmartCardConnection class]] || conformsToProtocol:...`) was a
|
|
90
|
+
// tautology, since every value in `connections` already conforms to the protocol by
|
|
91
|
+
// its declared type - it always reported only SmartCardConnection.
|
|
92
|
+
NSArray<NSString *> *supportedConnections = @[@"SmartCardConnection", @"OtpConnection", @"FidoConnection"];
|
|
93
|
+
return @{
|
|
94
|
+
@"handle": handle,
|
|
95
|
+
@"transport": transport,
|
|
96
|
+
@"supportedConnections": supportedConnections
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
- (void)emitAttachedForHandle:(NSString *)handle connection:(id<YKFConnectionProtocol>)connection {
|
|
101
|
+
if (self.eventHandler == nil) return;
|
|
102
|
+
self.eventHandler(@"attached", @{@"device": [self deviceDictForHandle:handle connection:connection]});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
- (void)emitDetachedForHandle:(NSString *)handle {
|
|
106
|
+
if (self.eventHandler == nil) return;
|
|
107
|
+
self.eventHandler(@"detached", @{@"handle": handle});
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
- (void)emitErrorWithMessage:(NSString *)message {
|
|
111
|
+
if (self.eventHandler == nil) return;
|
|
112
|
+
self.eventHandler(@"error", @{@"error": message});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
#pragma mark - YKFManagerDelegate
|
|
116
|
+
|
|
117
|
+
- (void)didConnectNFC:(YKFNFCConnection *)connection {
|
|
118
|
+
NSString *handle = [[NSUUID UUID] UUIDString];
|
|
119
|
+
self.connections[handle] = connection;
|
|
120
|
+
self.deviceTransports[handle] = @"nfc";
|
|
121
|
+
[self emitAttachedForHandle:handle connection:connection];
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
- (void)didDisconnectNFC:(YKFNFCConnection *)connection error:(NSError *)error {
|
|
125
|
+
[self removeConnectionForConnection:connection];
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
- (void)didConnectAccessory:(YKFAccessoryConnection *)connection {
|
|
129
|
+
NSString *handle = [[NSUUID UUID] UUIDString];
|
|
130
|
+
self.connections[handle] = connection;
|
|
131
|
+
self.deviceTransports[handle] = @"usb";
|
|
132
|
+
[self emitAttachedForHandle:handle connection:connection];
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
- (void)didDisconnectAccessory:(YKFAccessoryConnection *)connection error:(NSError *)error {
|
|
136
|
+
[self removeConnectionForConnection:connection];
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
- (void)didConnectSmartCard:(YKFSmartCardConnection *)connection API_AVAILABLE(ios(16.0)) {
|
|
140
|
+
NSString *handle = [[NSUUID UUID] UUIDString];
|
|
141
|
+
self.connections[handle] = connection;
|
|
142
|
+
self.deviceTransports[handle] = @"usb";
|
|
143
|
+
[self emitAttachedForHandle:handle connection:connection];
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
- (void)didDisconnectSmartCard:(YKFSmartCardConnection *)connection error:(NSError *)error API_AVAILABLE(ios(16.0)) {
|
|
147
|
+
[self removeConnectionForConnection:connection];
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
- (void)didFailConnectingSmartCard:(NSError *)error {
|
|
151
|
+
[self emitErrorWithMessage:error.localizedDescription ?: @"Failed to connect smart card"];
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
- (void)didFailConnectingNFC:(NSError *)error {
|
|
155
|
+
[self emitErrorWithMessage:error.localizedDescription ?: @"Failed to connect NFC"];
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
#pragma mark - Private
|
|
159
|
+
|
|
160
|
+
- (void)removeConnectionForConnection:(id<YKFConnectionProtocol>)connection {
|
|
161
|
+
NSArray<NSString *> *keys = [self.connections allKeysForObject:connection];
|
|
162
|
+
for (NSString *key in keys) {
|
|
163
|
+
[self.connections removeObjectForKey:key];
|
|
164
|
+
[self.deviceTransports removeObjectForKey:key];
|
|
165
|
+
[self emitDetachedForHandle:key];
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
@end
|