@appzung/react-native-code-push 5.7.1
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/AlertAdapter.js +24 -0
- package/CONTRIBUTING.md +136 -0
- package/CodePush.js +666 -0
- package/CodePush.podspec +27 -0
- package/LICENSE.md +13 -0
- package/README.md +386 -0
- package/RestartManager.js +59 -0
- package/android/app/build.gradle +31 -0
- package/android/app/proguard-rules.pro +25 -0
- package/android/app/src/main/AndroidManifest.xml +10 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java +395 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushBuilder.java +37 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushConstants.java +34 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushDialog.java +102 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushInstallMode.java +16 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushInvalidPublicKeyException.java +12 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushInvalidUpdateException.java +7 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushMalformedDataException.java +12 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java +641 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushNotInitializedException.java +12 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushTelemetryManager.java +175 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUnknownException.java +12 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUpdateManager.java +369 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUpdateState.java +15 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUpdateUtils.java +267 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUtils.java +236 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/DownloadProgress.java +30 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/DownloadProgressCallback.java +5 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/FileUtils.java +190 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/ReactInstanceHolder.java +17 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/SettingsManager.java +173 -0
- package/android/build.gradle +20 -0
- package/android/codepush.gradle +113 -0
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +5 -0
- package/android/gradle.properties +20 -0
- package/android/gradlew +164 -0
- package/android/gradlew.bat +90 -0
- package/android/settings.gradle +1 -0
- package/docs/api-android.md +65 -0
- package/docs/api-ios.md +31 -0
- package/docs/api-js.md +592 -0
- package/docs/multi-deployment-testing-android.md +107 -0
- package/docs/multi-deployment-testing-ios.md +53 -0
- package/docs/setup-android.md +406 -0
- package/docs/setup-ios.md +229 -0
- package/docs/setup-windows.md +65 -0
- package/gulpfile.js +302 -0
- package/ios/CodePush/Base64/Base64/MF_Base64Additions.h +34 -0
- package/ios/CodePush/Base64/Base64/MF_Base64Additions.m +252 -0
- package/ios/CodePush/Base64/README.md +47 -0
- package/ios/CodePush/CodePush.h +235 -0
- package/ios/CodePush/CodePush.m +1041 -0
- package/ios/CodePush/CodePushConfig.m +116 -0
- package/ios/CodePush/CodePushDownloadHandler.m +130 -0
- package/ios/CodePush/CodePushErrorUtils.m +20 -0
- package/ios/CodePush/CodePushPackage.m +598 -0
- package/ios/CodePush/CodePushTelemetryManager.m +175 -0
- package/ios/CodePush/CodePushUpdateUtils.m +376 -0
- package/ios/CodePush/CodePushUtils.m +9 -0
- package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithm.h +69 -0
- package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithmFactory.h +16 -0
- package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithmFactory.m +51 -0
- package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithmNone.h +15 -0
- package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithmNone.m +55 -0
- package/ios/CodePush/JWT/Core/Algorithms/ESFamily/JWTAlgorithmESBase.h +24 -0
- package/ios/CodePush/JWT/Core/Algorithms/ESFamily/JWTAlgorithmESBase.m +41 -0
- package/ios/CodePush/JWT/Core/Algorithms/HSFamily/JWTAlgorithmHSBase.h +28 -0
- package/ios/CodePush/JWT/Core/Algorithms/HSFamily/JWTAlgorithmHSBase.m +205 -0
- package/ios/CodePush/JWT/Core/Algorithms/Holders/JWTAlgorithmDataHolder.h +103 -0
- package/ios/CodePush/JWT/Core/Algorithms/Holders/JWTAlgorithmDataHolder.m +322 -0
- package/ios/CodePush/JWT/Core/Algorithms/Holders/JWTAlgorithmDataHolderChain.h +37 -0
- package/ios/CodePush/JWT/Core/Algorithms/Holders/JWTAlgorithmDataHolderChain.m +145 -0
- package/ios/CodePush/JWT/Core/Algorithms/RSFamily/JWTAlgorithmRSBase.h +35 -0
- package/ios/CodePush/JWT/Core/Algorithms/RSFamily/JWTAlgorithmRSBase.m +551 -0
- package/ios/CodePush/JWT/Core/Algorithms/RSFamily/JWTRSAlgorithm.h +23 -0
- package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoKey.h +43 -0
- package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoKey.m +230 -0
- package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoKeyExtractor.h +31 -0
- package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoKeyExtractor.m +113 -0
- package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoSecurity.h +38 -0
- package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoSecurity.m +500 -0
- package/ios/CodePush/JWT/Core/ClaimSet/JWTClaim.h +18 -0
- package/ios/CodePush/JWT/Core/ClaimSet/JWTClaim.m +214 -0
- package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSet.h +23 -0
- package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSet.m +29 -0
- package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSetSerializer.h +19 -0
- package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSetSerializer.m +68 -0
- package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSetVerifier.h +18 -0
- package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSetVerifier.m +72 -0
- package/ios/CodePush/JWT/Core/Coding/JWTCoding+ResultTypes.h +67 -0
- package/ios/CodePush/JWT/Core/Coding/JWTCoding+ResultTypes.m +111 -0
- package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionOne.h +119 -0
- package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionOne.m +307 -0
- package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionThree.h +94 -0
- package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionThree.m +619 -0
- package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionTwo.h +164 -0
- package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionTwo.m +514 -0
- package/ios/CodePush/JWT/Core/Coding/JWTCoding.h +24 -0
- package/ios/CodePush/JWT/Core/Coding/JWTCoding.m +11 -0
- package/ios/CodePush/JWT/Core/FrameworkSupplement/JWT.h +52 -0
- package/ios/CodePush/JWT/Core/FrameworkSupplement/Map.modulemap +5 -0
- package/ios/CodePush/JWT/Core/Supplement/JWTBase64Coder.h +28 -0
- package/ios/CodePush/JWT/Core/Supplement/JWTBase64Coder.m +70 -0
- package/ios/CodePush/JWT/Core/Supplement/JWTDeprecations.h +22 -0
- package/ios/CodePush/JWT/Core/Supplement/JWTErrorDescription.h +34 -0
- package/ios/CodePush/JWT/Core/Supplement/JWTErrorDescription.m +73 -0
- package/ios/CodePush/JWT/LICENSE +19 -0
- package/ios/CodePush/JWT/README.md +489 -0
- package/ios/CodePush/RCTConvert+CodePushInstallMode.m +20 -0
- package/ios/CodePush/RCTConvert+CodePushUpdateState.m +20 -0
- package/ios/CodePush/SSZipArchive/Common.h +81 -0
- package/ios/CodePush/SSZipArchive/README.md +1 -0
- package/ios/CodePush/SSZipArchive/SSZipArchive.h +76 -0
- package/ios/CodePush/SSZipArchive/SSZipArchive.m +691 -0
- package/ios/CodePush/SSZipArchive/aes/aes.h +198 -0
- package/ios/CodePush/SSZipArchive/aes/aes_via_ace.h +541 -0
- package/ios/CodePush/SSZipArchive/aes/aescrypt.c +294 -0
- package/ios/CodePush/SSZipArchive/aes/aeskey.c +548 -0
- package/ios/CodePush/SSZipArchive/aes/aesopt.h +739 -0
- package/ios/CodePush/SSZipArchive/aes/aestab.c +391 -0
- package/ios/CodePush/SSZipArchive/aes/aestab.h +173 -0
- package/ios/CodePush/SSZipArchive/aes/brg_endian.h +126 -0
- package/ios/CodePush/SSZipArchive/aes/brg_types.h +219 -0
- package/ios/CodePush/SSZipArchive/aes/entropy.c +54 -0
- package/ios/CodePush/SSZipArchive/aes/entropy.h +16 -0
- package/ios/CodePush/SSZipArchive/aes/fileenc.c +144 -0
- package/ios/CodePush/SSZipArchive/aes/fileenc.h +121 -0
- package/ios/CodePush/SSZipArchive/aes/hmac.c +145 -0
- package/ios/CodePush/SSZipArchive/aes/hmac.h +103 -0
- package/ios/CodePush/SSZipArchive/aes/prng.c +155 -0
- package/ios/CodePush/SSZipArchive/aes/prng.h +82 -0
- package/ios/CodePush/SSZipArchive/aes/pwd2key.c +103 -0
- package/ios/CodePush/SSZipArchive/aes/pwd2key.h +57 -0
- package/ios/CodePush/SSZipArchive/aes/sha1.c +258 -0
- package/ios/CodePush/SSZipArchive/aes/sha1.h +73 -0
- package/ios/CodePush/SSZipArchive/minizip/crypt.h +130 -0
- package/ios/CodePush/SSZipArchive/minizip/ioapi.c +369 -0
- package/ios/CodePush/SSZipArchive/minizip/ioapi.h +175 -0
- package/ios/CodePush/SSZipArchive/minizip/mztools.c +284 -0
- package/ios/CodePush/SSZipArchive/minizip/mztools.h +31 -0
- package/ios/CodePush/SSZipArchive/minizip/unzip.c +1839 -0
- package/ios/CodePush/SSZipArchive/minizip/unzip.h +248 -0
- package/ios/CodePush/SSZipArchive/minizip/zip.c +1910 -0
- package/ios/CodePush/SSZipArchive/minizip/zip.h +202 -0
- package/ios/CodePush.xcodeproj/project.pbxproj +937 -0
- package/ios/CodePush.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
- package/ios/CodePush.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
- package/logging.js +6 -0
- package/package-mixins.js +69 -0
- package/package.json +47 -0
- package/request-fetch-adapter.js +52 -0
- package/scripts/generateBundledResourcesHash.js +125 -0
- package/scripts/getFilesInFolder.js +19 -0
- package/scripts/postlink/android/postlink.js +87 -0
- package/scripts/postlink/ios/postlink.js +116 -0
- package/scripts/postlink/run.js +11 -0
- package/scripts/postunlink/android/postunlink.js +74 -0
- package/scripts/postunlink/ios/postunlink.js +87 -0
- package/scripts/postunlink/run.js +11 -0
- package/scripts/recordFilesBeforeBundleCommand.js +41 -0
- package/scripts/tools/linkToolsAndroid.js +57 -0
- package/scripts/tools/linkToolsIos.js +130 -0
- package/typings/react-native-code-push.d.ts +446 -0
- package/windows/CodePush/CodePush.csproj +128 -0
- package/windows/CodePush/CodePushUtils.cs +47 -0
- package/windows/CodePush/FileUtils.cs +40 -0
- package/windows/CodePush/Properties/AssemblyInfo.cs +29 -0
- package/windows/CodePush/Properties/CodePush.rd.xml +33 -0
- package/windows/CodePush/UpdateManager.cs +305 -0
- package/windows/CodePush/UpdateUtils.cs +46 -0
- package/windows/CodePush.Net46/Adapters/Http/HttpProgress.cs +28 -0
- package/windows/CodePush.Net46/Adapters/Storage/ApplicationDataContainer.cs +106 -0
- package/windows/CodePush.Net46/CodePush.Net46.csproj +103 -0
- package/windows/CodePush.Net46/CodePushUtils.cs +158 -0
- package/windows/CodePush.Net46/FileUtils.cs +55 -0
- package/windows/CodePush.Net46/Properties/AssemblyInfo.cs +36 -0
- package/windows/CodePush.Net46/UpdateManager.cs +330 -0
- package/windows/CodePush.Net46/UpdateUtils.cs +70 -0
- package/windows/CodePush.Net46/packages.config +5 -0
- package/windows/CodePush.Shared/CodePush.Shared.projitems +22 -0
- package/windows/CodePush.Shared/CodePush.Shared.shproj +13 -0
- package/windows/CodePush.Shared/CodePushConstants.cs +35 -0
- package/windows/CodePush.Shared/CodePushNativeModule.cs +329 -0
- package/windows/CodePush.Shared/CodePushReactPackage.cs +235 -0
- package/windows/CodePush.Shared/CodePushUtils.cs +70 -0
- package/windows/CodePush.Shared/InstallMode.cs +9 -0
- package/windows/CodePush.Shared/MinimumBackgroundListener.cs +44 -0
- package/windows/CodePush.Shared/SettingsManager.cs +148 -0
- package/windows/CodePush.Shared/TelemetryManager.cs +250 -0
- package/windows/CodePush.Shared/UpdateState.cs +9 -0
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
//
|
|
2
|
+
// JWTCryptoKey.m
|
|
3
|
+
// JWT
|
|
4
|
+
//
|
|
5
|
+
// Created by Lobanov Dmitry on 04.02.17.
|
|
6
|
+
// Copyright © 2017 JWTIO. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
#import "JWTCryptoKey.h"
|
|
10
|
+
#import "JWTCryptoSecurity.h"
|
|
11
|
+
#import "JWTBase64Coder.h"
|
|
12
|
+
@interface JWTCryptoKeyBuilder()
|
|
13
|
+
+ (NSString *)keyTypeRSA;
|
|
14
|
+
+ (NSString *)keyTypeEC;
|
|
15
|
+
@property (assign, nonatomic, readwrite) BOOL public;
|
|
16
|
+
@property (assign, nonatomic, readwrite) NSString *keyType;
|
|
17
|
+
@property (nonatomic, readonly) BOOL withKeyTypeRSA;
|
|
18
|
+
@property (nonatomic, readonly) BOOL withKeyTypeEC;
|
|
19
|
+
@end
|
|
20
|
+
@implementation JWTCryptoKeyBuilder
|
|
21
|
+
+ (NSString *)keyTypeRSA {
|
|
22
|
+
return @"RSA";
|
|
23
|
+
}
|
|
24
|
+
+ (NSString *)keyTypeEC {
|
|
25
|
+
return @"EC";
|
|
26
|
+
}
|
|
27
|
+
- (instancetype)keyTypeRSA {
|
|
28
|
+
self.keyType = [self.class keyTypeRSA];
|
|
29
|
+
return self;
|
|
30
|
+
}
|
|
31
|
+
- (instancetype)keyTypeEC {
|
|
32
|
+
self.keyType = [self.class keyTypeEC];
|
|
33
|
+
return self;
|
|
34
|
+
}
|
|
35
|
+
- (BOOL)withKeyTypeRSA {
|
|
36
|
+
return [self.keyType isEqualToString:self.class.keyTypeRSA];
|
|
37
|
+
}
|
|
38
|
+
- (BOOL)withKeyTypeEC {
|
|
39
|
+
return [self.keyType isEqualToString:self.class.keyTypeEC];
|
|
40
|
+
}
|
|
41
|
+
@end
|
|
42
|
+
@interface JWTCryptoKey ()
|
|
43
|
+
@property (copy, nonatomic, readwrite) NSString *tag;
|
|
44
|
+
@property (assign, nonatomic, readwrite) SecKeyRef key;
|
|
45
|
+
@property (copy, nonatomic, readwrite) NSData *rawKey;
|
|
46
|
+
@end
|
|
47
|
+
@interface JWTCryptoKey (Class)
|
|
48
|
+
+ (NSString *)uniqueTag;
|
|
49
|
+
@end
|
|
50
|
+
@implementation JWTCryptoKey (Class)
|
|
51
|
+
+ (NSString *)uniqueTag {
|
|
52
|
+
return [[NSUUID UUID].UUIDString stringByReplacingOccurrencesOfString:@"-" withString:@""].lowercaseString;
|
|
53
|
+
}
|
|
54
|
+
@end
|
|
55
|
+
@implementation JWTCryptoKey (Parameters)
|
|
56
|
+
+ (NSString *)parametersKeyBuilder {
|
|
57
|
+
return NSStringFromSelector(_cmd);
|
|
58
|
+
}
|
|
59
|
+
@end
|
|
60
|
+
@interface JWTCryptoKey (ParametersExtraction)
|
|
61
|
+
- (NSString *)extractedSecKeyTypeWithParameters:(NSDictionary *)parameters;
|
|
62
|
+
- (JWTCryptoKeyBuilder *)extractedBuilderWithParameters:(NSDictionary *)parameters;
|
|
63
|
+
@end
|
|
64
|
+
// Consider that both methods in this category should return non-nullable values
|
|
65
|
+
@implementation JWTCryptoKey (ParametersExtraction)
|
|
66
|
+
// Parameters are nil at that moment, could be used later for some purposes
|
|
67
|
+
- (JWTCryptoKeyBuilder *)extractedBuilderWithParameters:(NSDictionary *)parameters {
|
|
68
|
+
return (JWTCryptoKeyBuilder *)parameters[[self.class parametersKeyBuilder]] ?: [JWTCryptoKeyBuilder new].keyTypeRSA;
|
|
69
|
+
}
|
|
70
|
+
// Parameters are nil at that moment, could be used later for some purposes
|
|
71
|
+
- (NSString *)extractedSecKeyTypeWithParameters:(NSDictionary *)parameters {
|
|
72
|
+
JWTCryptoKeyBuilder *builder = [self extractedBuilderWithParameters:parameters];
|
|
73
|
+
NSString *result = nil;
|
|
74
|
+
if (builder.withKeyTypeEC) {
|
|
75
|
+
result = [JWTCryptoSecurity keyTypeEC];
|
|
76
|
+
}
|
|
77
|
+
return result ?: [JWTCryptoSecurity keyTypeRSA];
|
|
78
|
+
}
|
|
79
|
+
@end
|
|
80
|
+
@implementation JWTCryptoKey
|
|
81
|
+
- (instancetype)initWithData:(NSData *)data parameters:(NSDictionary *)parameters error:(NSError *__autoreleasing*)error {
|
|
82
|
+
return [super init];
|
|
83
|
+
}
|
|
84
|
+
- (instancetype)initWithBase64String:(NSString *)base64String parameters:(NSDictionary *)parameters error:(NSError *__autoreleasing*)error {
|
|
85
|
+
return [self initWithData:[JWTBase64Coder dataWithBase64UrlEncodedString:base64String] parameters:parameters error:error];
|
|
86
|
+
}
|
|
87
|
+
- (instancetype)initWithPemEncoded:(NSString *)encoded parameters:(NSDictionary *)parameters error:(NSError *__autoreleasing*)error {
|
|
88
|
+
//TODO: check correctness.
|
|
89
|
+
//maybe use clean initWithBase64String and remove ?: encoded tail.
|
|
90
|
+
NSString *clean = [JWTCryptoSecurity keyFromPemFileContent:encoded] ?: encoded;//[JWTCryptoSecurity stringByRemovingPemHeadersFromString:encoded];
|
|
91
|
+
return [self initWithBase64String:clean parameters:parameters error:error];
|
|
92
|
+
}
|
|
93
|
+
- (instancetype)initWithPemAtURL:(NSURL *)url parameters:(NSDictionary *)parameters error:(NSError *__autoreleasing*)error {
|
|
94
|
+
// contents of url
|
|
95
|
+
NSError *contentsExtractingError = nil;
|
|
96
|
+
NSString *pemEncoded = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:&contentsExtractingError];
|
|
97
|
+
if (error && contentsExtractingError) {
|
|
98
|
+
*error = contentsExtractingError;
|
|
99
|
+
return nil;
|
|
100
|
+
}
|
|
101
|
+
return [self initWithPemEncoded:pemEncoded parameters:parameters error:error];
|
|
102
|
+
}
|
|
103
|
+
@end
|
|
104
|
+
@implementation JWTCryptoKeyPublic
|
|
105
|
+
- (instancetype)initWithData:(NSData *)data parameters:(NSDictionary *)parameters error:(NSError *__autoreleasing*)error {
|
|
106
|
+
self = [super initWithData:data parameters:parameters error:error];
|
|
107
|
+
if (self) {
|
|
108
|
+
self.tag = [self.class uniqueTag];
|
|
109
|
+
|
|
110
|
+
if (!data) {
|
|
111
|
+
return nil;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
NSError *removingHeaderError = nil;
|
|
115
|
+
// asks builder
|
|
116
|
+
|
|
117
|
+
JWTCryptoKeyBuilder *builder = [self extractedBuilderWithParameters:parameters];
|
|
118
|
+
NSData *keyData = data;
|
|
119
|
+
if (builder.withKeyTypeRSA) {
|
|
120
|
+
keyData = [JWTCryptoSecurity dataByRemovingPublicKeyHeader:data error:&removingHeaderError];
|
|
121
|
+
if (!keyData || removingHeaderError) {
|
|
122
|
+
if (error && removingHeaderError != nil) {
|
|
123
|
+
*error = removingHeaderError;
|
|
124
|
+
}
|
|
125
|
+
return nil;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (builder.withKeyTypeEC) {
|
|
130
|
+
// unknown here.
|
|
131
|
+
// process keyData before passing it to JWTCryptoSecurity+addKey... method.
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
NSError *addKeyError = nil;
|
|
135
|
+
|
|
136
|
+
self.key = [JWTCryptoSecurity addKeyWithData:keyData asPublic:YES tag:self.tag type:[self extractedSecKeyTypeWithParameters:parameters] error:&addKeyError];
|
|
137
|
+
if (!self.key || addKeyError) {
|
|
138
|
+
if (error && addKeyError != nil) {
|
|
139
|
+
*error = removingHeaderError;
|
|
140
|
+
}
|
|
141
|
+
return nil;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return self;
|
|
145
|
+
}
|
|
146
|
+
- (instancetype)initWithCertificateData:(NSData *)certificateData parameters:(NSDictionary *)parameters error:(NSError *__autoreleasing*)error {
|
|
147
|
+
SecKeyRef key = [JWTCryptoSecurity publicKeyFromCertificate:certificateData];
|
|
148
|
+
if (!key) {
|
|
149
|
+
// error: Public certificate incorrect.
|
|
150
|
+
return nil;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (self = [super init]) {
|
|
154
|
+
self.key = key;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return self;
|
|
158
|
+
}
|
|
159
|
+
- (instancetype)initWithCertificateBase64String:(NSString *)certificate parameters:(NSDictionary *)parameters error:(NSError *__autoreleasing*)error {
|
|
160
|
+
// cleanup certificate if needed.
|
|
161
|
+
// call initWithCertificateData:(NSData *)certificateData
|
|
162
|
+
NSData *certificateData = nil;
|
|
163
|
+
return [self initWithCertificateData:certificateData parameters:parameters error:error];
|
|
164
|
+
}
|
|
165
|
+
@end
|
|
166
|
+
|
|
167
|
+
@implementation JWTCryptoKeyPrivate
|
|
168
|
+
- (instancetype)initWithData:(NSData *)data parameters:(NSDictionary *)parameters error:(NSError *__autoreleasing*)error {
|
|
169
|
+
self = [super initWithData:data parameters:parameters error:error];
|
|
170
|
+
if (self) {
|
|
171
|
+
self.tag = [self.class uniqueTag];
|
|
172
|
+
NSError *addKeyError = nil;
|
|
173
|
+
if (!data) {
|
|
174
|
+
// error: no data?
|
|
175
|
+
// or put it in superclass?
|
|
176
|
+
return nil;
|
|
177
|
+
}
|
|
178
|
+
self.key = [JWTCryptoSecurity addKeyWithData:data asPublic:NO tag:self.tag type:[self extractedSecKeyTypeWithParameters:parameters] error:&addKeyError];
|
|
179
|
+
if (!self.key || addKeyError) {
|
|
180
|
+
if (error && addKeyError) {
|
|
181
|
+
*error = addKeyError;
|
|
182
|
+
}
|
|
183
|
+
return nil;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return self;
|
|
187
|
+
}
|
|
188
|
+
// Exists
|
|
189
|
+
- (instancetype)initWithP12AtURL:(NSURL *)url withPassphrase:(NSString *)passphrase parameters:(NSDictionary *)parameters error:(NSError *__autoreleasing*)error {
|
|
190
|
+
// take data.
|
|
191
|
+
// cleanup if needed.
|
|
192
|
+
NSData *data = [NSData dataWithContentsOfURL:url];
|
|
193
|
+
return [self initWithP12Data:data withPassphrase:passphrase parameters:parameters error:error];
|
|
194
|
+
}
|
|
195
|
+
- (instancetype)initWithP12Data:(NSData *)p12Data withPassphrase:(NSString *)passphrase parameters:(NSDictionary *)parameters error:(NSError *__autoreleasing*)error {
|
|
196
|
+
if (p12Data == nil) {
|
|
197
|
+
return nil;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// cleanup if needed.
|
|
201
|
+
SecIdentityRef identity = nil;
|
|
202
|
+
SecTrustRef trust = nil;
|
|
203
|
+
[JWTCryptoSecurity extractIdentityAndTrustFromPKCS12:(__bridge CFDataRef)p12Data password:(__bridge CFStringRef)passphrase identity:&identity trust:&trust];
|
|
204
|
+
BOOL identityAndTrust = identity && trust;
|
|
205
|
+
|
|
206
|
+
if (identityAndTrust) {
|
|
207
|
+
self = [super init];
|
|
208
|
+
SecKeyRef privateKey;
|
|
209
|
+
SecIdentityCopyPrivateKey(identity, &privateKey);
|
|
210
|
+
if (self) {
|
|
211
|
+
self.key = privateKey;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (identity) {
|
|
216
|
+
CFRelease(identity);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
if (trust) {
|
|
220
|
+
CFRelease(trust);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (!identityAndTrust) {
|
|
224
|
+
//error: no identity and trust.
|
|
225
|
+
return nil;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
return self;
|
|
229
|
+
}
|
|
230
|
+
@end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
//
|
|
2
|
+
// JWTCryptoKeyExtractor.h
|
|
3
|
+
// JWT
|
|
4
|
+
//
|
|
5
|
+
// Created by Lobanov Dmitry on 04.02.17.
|
|
6
|
+
// Copyright © 2017 JWTIO. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
#import <Foundation/Foundation.h>
|
|
10
|
+
#import <Security/Security.h>
|
|
11
|
+
|
|
12
|
+
@protocol JWTCryptoKeyProtocol;
|
|
13
|
+
@protocol JWTCryptoKeyExtractorProtocol <NSObject>
|
|
14
|
+
@optional
|
|
15
|
+
- (id<JWTCryptoKeyProtocol>)keyFromString:(NSString *)string parameters:(NSDictionary *)parameters error:(NSError *__autoreleasing*)error;
|
|
16
|
+
- (id<JWTCryptoKeyProtocol>)keyFromData:(NSData *)data parameters:(NSDictionary *)parameters error:(NSError *__autoreleasing*)error;
|
|
17
|
+
@end
|
|
18
|
+
|
|
19
|
+
@interface JWTCryptoKeyExtractor : NSObject <JWTCryptoKeyExtractorProtocol>
|
|
20
|
+
@property (copy, nonatomic, readonly) NSString *type;
|
|
21
|
+
+ (NSString *)type;
|
|
22
|
+
+ (NSString *)parametersKeyCertificatePassphrase;
|
|
23
|
+
@end
|
|
24
|
+
|
|
25
|
+
@interface JWTCryptoKeyExtractor (ClassCluster)
|
|
26
|
+
+ (instancetype)publicKeyWithCertificate;
|
|
27
|
+
+ (instancetype)privateKeyInP12;
|
|
28
|
+
+ (instancetype)publicKeyWithPEMBase64;
|
|
29
|
+
+ (instancetype)privateKeyWithPEMBase64;
|
|
30
|
+
+ (instancetype)createWithType:(NSString *)type;
|
|
31
|
+
@end
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
//
|
|
2
|
+
// JWTCryptoKeyExtractor.m
|
|
3
|
+
// JWT
|
|
4
|
+
//
|
|
5
|
+
// Created by Lobanov Dmitry on 04.02.17.
|
|
6
|
+
// Copyright © 2017 JWTIO. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
#import "JWTCryptoKeyExtractor.h"
|
|
10
|
+
#import "JWTCryptoKey.h"
|
|
11
|
+
#import "JWTBase64Coder.h"
|
|
12
|
+
|
|
13
|
+
@implementation JWTCryptoKeyExtractor
|
|
14
|
+
- (NSString *)type {
|
|
15
|
+
return self.class.type;
|
|
16
|
+
}
|
|
17
|
+
+ (NSString *)type {
|
|
18
|
+
return NSStringFromClass(self);
|
|
19
|
+
}
|
|
20
|
+
+ (NSString *)parametersKeyCertificatePassphrase {
|
|
21
|
+
return NSStringFromSelector(_cmd);
|
|
22
|
+
}
|
|
23
|
+
- (id<JWTCryptoKeyProtocol>)keyFromData:(NSData *)data parameters:(NSDictionary *)parameters error:(NSError *__autoreleasing *)error {
|
|
24
|
+
#pragma message "Not Implemented"
|
|
25
|
+
if (error) {
|
|
26
|
+
*error = [NSError errorWithDomain:@"io.jwt.crypto.rsa" code:-100 userInfo:@{
|
|
27
|
+
NSLocalizedDescriptionKey : @"Method not implemented"
|
|
28
|
+
}];
|
|
29
|
+
}
|
|
30
|
+
return nil;
|
|
31
|
+
}
|
|
32
|
+
- (id<JWTCryptoKeyProtocol>)keyFromString:(NSString *)string parameters:(NSDictionary *)parameters error:(NSError *__autoreleasing *)error {
|
|
33
|
+
if (error) {
|
|
34
|
+
*error = [NSError errorWithDomain:@"io.jwt.crypto.rsa" code:-100 userInfo:@{
|
|
35
|
+
NSLocalizedDescriptionKey : @"Method not implemented"
|
|
36
|
+
}];
|
|
37
|
+
}
|
|
38
|
+
return nil;
|
|
39
|
+
}
|
|
40
|
+
@end
|
|
41
|
+
|
|
42
|
+
@interface JWTCryptoKeyExtractor_Public_Pem_Certificate : JWTCryptoKeyExtractor @end
|
|
43
|
+
|
|
44
|
+
@implementation JWTCryptoKeyExtractor_Public_Pem_Certificate
|
|
45
|
+
- (id<JWTCryptoKeyProtocol>)keyFromData:(NSData *)data parameters:(NSDictionary *)parameters error:(NSError *__autoreleasing *)error {
|
|
46
|
+
return [[JWTCryptoKeyPublic alloc] initWithCertificateData:data parameters:parameters error:error];
|
|
47
|
+
}
|
|
48
|
+
@end
|
|
49
|
+
|
|
50
|
+
@interface JWTCryptoKeyExtractor_Private_P12 : JWTCryptoKeyExtractor @end
|
|
51
|
+
|
|
52
|
+
@implementation JWTCryptoKeyExtractor_Private_P12
|
|
53
|
+
- (id<JWTCryptoKeyProtocol>)keyFromData:(NSData *)data parameters:(NSDictionary *)parameters error:(NSError *__autoreleasing *)error {
|
|
54
|
+
NSString *certificatePassphrase = parameters[self.class.parametersKeyCertificatePassphrase];
|
|
55
|
+
if ([certificatePassphrase isEqual:[NSNull null]]) {
|
|
56
|
+
certificatePassphrase = nil;
|
|
57
|
+
}
|
|
58
|
+
return [[JWTCryptoKeyPrivate alloc] initWithP12Data:data withPassphrase:certificatePassphrase parameters:parameters error:error];
|
|
59
|
+
}
|
|
60
|
+
@end
|
|
61
|
+
|
|
62
|
+
@interface JWTCryptoKeyExtractor_Public_Pem_Key : JWTCryptoKeyExtractor @end
|
|
63
|
+
|
|
64
|
+
@implementation JWTCryptoKeyExtractor_Public_Pem_Key
|
|
65
|
+
- (id<JWTCryptoKeyProtocol>)keyFromData:(NSData *)data parameters:(NSDictionary *)parameters error:(NSError *__autoreleasing *)error {
|
|
66
|
+
return [self keyFromString:[JWTBase64Coder base64UrlEncodedStringWithData:data] parameters:parameters error:error];
|
|
67
|
+
}
|
|
68
|
+
- (id<JWTCryptoKeyProtocol>)keyFromString:(NSString *)string parameters:(NSDictionary *)parameters error:(NSError *__autoreleasing *)error {
|
|
69
|
+
return [[JWTCryptoKeyPublic alloc] initWithPemEncoded:string parameters:parameters error:error];
|
|
70
|
+
}
|
|
71
|
+
@end
|
|
72
|
+
|
|
73
|
+
@interface JWTCryptoKeyExtractor_Private_Pem_Key : JWTCryptoKeyExtractor @end
|
|
74
|
+
|
|
75
|
+
@implementation JWTCryptoKeyExtractor_Private_Pem_Key
|
|
76
|
+
- (id<JWTCryptoKeyProtocol>)keyFromData:(NSData *)data parameters:(NSDictionary *)parameters error:(NSError *__autoreleasing *)error {
|
|
77
|
+
return [self keyFromString:[JWTBase64Coder base64UrlEncodedStringWithData:data] parameters:parameters error:error];
|
|
78
|
+
}
|
|
79
|
+
- (id<JWTCryptoKeyProtocol>)keyFromString:(NSString *)string parameters:(NSDictionary *)parameters error:(NSError *__autoreleasing *)error {
|
|
80
|
+
return [[JWTCryptoKeyPrivate alloc] initWithPemEncoded:string parameters:parameters error:error];
|
|
81
|
+
}
|
|
82
|
+
@end
|
|
83
|
+
|
|
84
|
+
@implementation JWTCryptoKeyExtractor (ClassCluster)
|
|
85
|
+
+ (instancetype)publicKeyWithCertificate {
|
|
86
|
+
return [JWTCryptoKeyExtractor_Public_Pem_Certificate new];
|
|
87
|
+
}
|
|
88
|
+
+ (instancetype)privateKeyInP12 {
|
|
89
|
+
return [JWTCryptoKeyExtractor_Private_P12 new];
|
|
90
|
+
}
|
|
91
|
+
+ (instancetype)publicKeyWithPEMBase64 {
|
|
92
|
+
return [JWTCryptoKeyExtractor_Public_Pem_Key new];
|
|
93
|
+
}
|
|
94
|
+
+ (instancetype)privateKeyWithPEMBase64 {
|
|
95
|
+
return [JWTCryptoKeyExtractor_Private_Pem_Key new];
|
|
96
|
+
}
|
|
97
|
+
+ (NSArray *)availableExtractors {
|
|
98
|
+
return @[
|
|
99
|
+
[self publicKeyWithCertificate],
|
|
100
|
+
[self privateKeyInP12],
|
|
101
|
+
[self publicKeyWithPEMBase64],
|
|
102
|
+
[self privateKeyWithPEMBase64]
|
|
103
|
+
];
|
|
104
|
+
}
|
|
105
|
+
+ (NSDictionary *)typesAndExtractors {
|
|
106
|
+
static NSDictionary *dictionary = nil;
|
|
107
|
+
return dictionary ?: (dictionary = [[NSDictionary alloc] initWithObjects:[self availableExtractors] forKeys:[[self availableExtractors] valueForKey:@"type"]],
|
|
108
|
+
dictionary);
|
|
109
|
+
}
|
|
110
|
+
+ (instancetype)createWithType:(NSString *)type {
|
|
111
|
+
return [self typesAndExtractors][type];
|
|
112
|
+
}
|
|
113
|
+
@end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
//
|
|
2
|
+
// JWTCryptoSecurity.h
|
|
3
|
+
// JWT
|
|
4
|
+
//
|
|
5
|
+
// Created by Lobanov Dmitry on 04.02.17.
|
|
6
|
+
// Copyright © 2017 JWTIO. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
#import <Foundation/Foundation.h>
|
|
10
|
+
#import <Security/Security.h>
|
|
11
|
+
// Thanks for https://github.com/TakeScoop/SwiftyRSA!
|
|
12
|
+
@interface JWTCryptoSecurity : NSObject
|
|
13
|
+
+ (NSString *)keyTypeRSA;
|
|
14
|
+
+ (NSString *)keyTypeEC;
|
|
15
|
+
+ (SecKeyRef)addKeyWithData:(NSData *)data asPublic:(BOOL)public tag:(NSString *)tag type:(NSString *)type error:(NSError *__autoreleasing*)error;
|
|
16
|
+
+ (SecKeyRef)addKeyWithData:(NSData *)data asPublic:(BOOL)public tag:(NSString *)tag error:(NSError *__autoreleasing*)error;
|
|
17
|
+
+ (SecKeyRef)keyByTag:(NSString *)tag error:(NSError *__autoreleasing*)error;
|
|
18
|
+
+ (void)removeKeyByTag:(NSString *)tag error:(NSError *__autoreleasing*)error;
|
|
19
|
+
@end
|
|
20
|
+
|
|
21
|
+
@interface JWTCryptoSecurity (Certificates)
|
|
22
|
+
+ (OSStatus)extractIdentityAndTrustFromPKCS12:(CFDataRef)inPKCS12Data password:(CFStringRef)password identity:(SecIdentityRef *)outIdentity trust:(SecTrustRef *)outTrust;
|
|
23
|
+
+ (SecKeyRef)publicKeyFromCertificate:(NSData *)certificateData;
|
|
24
|
+
@end
|
|
25
|
+
|
|
26
|
+
@interface JWTCryptoSecurity (Pem)
|
|
27
|
+
+ (NSString *)certificateFromPemFileContent:(NSString *)content;
|
|
28
|
+
+ (NSString *)keyFromPemFileContent:(NSString *)content;
|
|
29
|
+
+ (NSArray *)itemsFromPemFileContent:(NSString *)content byRegex:(NSRegularExpression *)expression;
|
|
30
|
+
+ (NSString *)certificateFromPemFileWithName:(NSString *)name;
|
|
31
|
+
+ (NSString *)keyFromPemFileWithName:(NSString *)name;
|
|
32
|
+
+ (NSArray *)itemsFromPemFileWithName:(NSString *)name byRegex:(NSRegularExpression *)expression;
|
|
33
|
+
+ (NSString *)stringByRemovingPemHeadersFromString:(NSString *)string;
|
|
34
|
+
@end
|
|
35
|
+
|
|
36
|
+
@interface JWTCryptoSecurity (PublicKey)
|
|
37
|
+
+ (NSData *)dataByRemovingPublicKeyHeader:(NSData *)data error:(NSError *__autoreleasing*)error;
|
|
38
|
+
@end
|