@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,51 @@
|
|
|
1
|
+
//
|
|
2
|
+
// JWTAlgorithmFactory.m
|
|
3
|
+
// JWT
|
|
4
|
+
//
|
|
5
|
+
// Created by Lobanov Dmitry on 07.10.15.
|
|
6
|
+
// Copyright © 2015 Karma. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
#import "JWTAlgorithmFactory.h"
|
|
10
|
+
#import "JWTAlgorithmHSBase.h"
|
|
11
|
+
#import "JWTAlgorithmRSBase.h"
|
|
12
|
+
#import "JWTAlgorithmNone.h"
|
|
13
|
+
|
|
14
|
+
// not implemented.
|
|
15
|
+
NSString *const JWTAlgorithmNameES256 = @"ES256";
|
|
16
|
+
NSString *const JWTAlgorithmNameES384 = @"ES384";
|
|
17
|
+
NSString *const JWTAlgorithmNameES512 = @"ES512";
|
|
18
|
+
|
|
19
|
+
@implementation JWTAlgorithmFactory
|
|
20
|
+
|
|
21
|
+
+ (NSArray *)algorithms {
|
|
22
|
+
return @[
|
|
23
|
+
[JWTAlgorithmNone new],
|
|
24
|
+
[JWTAlgorithmHSBase algorithm256],
|
|
25
|
+
[JWTAlgorithmHSBase algorithm384],
|
|
26
|
+
[JWTAlgorithmHSBase algorithm512],
|
|
27
|
+
[JWTAlgorithmRSBase algorithm256],
|
|
28
|
+
[JWTAlgorithmRSBase algorithm384],
|
|
29
|
+
[JWTAlgorithmRSBase algorithm512]
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
+ (id<JWTAlgorithm>)algorithmByName:(NSString *)name {
|
|
35
|
+
id<JWTAlgorithm> algorithm = nil;
|
|
36
|
+
|
|
37
|
+
NSString *algName = [name copy];
|
|
38
|
+
|
|
39
|
+
NSUInteger index = [[self algorithms] indexOfObjectPassingTest:^BOOL(id<JWTAlgorithm> obj, NSUInteger idx, BOOL *stop) {
|
|
40
|
+
// lowercase comparison
|
|
41
|
+
return [obj.name.lowercaseString isEqualToString:algName.lowercaseString];
|
|
42
|
+
}];
|
|
43
|
+
|
|
44
|
+
if (index != NSNotFound) {
|
|
45
|
+
algorithm = [self algorithms][index];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return algorithm;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
@end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//
|
|
2
|
+
// JWTAlgorithmNone.h
|
|
3
|
+
// JWT
|
|
4
|
+
//
|
|
5
|
+
// Created by Lobanov Dmitry on 16.10.15.
|
|
6
|
+
// Copyright © 2015 Karma. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
#import <Foundation/Foundation.h>
|
|
10
|
+
#import "JWTAlgorithm.h"
|
|
11
|
+
extern NSString *const JWTAlgorithmNameNone;
|
|
12
|
+
|
|
13
|
+
@interface JWTAlgorithmNone : NSObject <JWTAlgorithm>
|
|
14
|
+
|
|
15
|
+
@end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
//
|
|
2
|
+
// JWTAlgorithmNone.m
|
|
3
|
+
// JWT
|
|
4
|
+
//
|
|
5
|
+
// Created by Lobanov Dmitry on 16.10.15.
|
|
6
|
+
// Copyright © 2015 Karma. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
#import "JWTAlgorithmNone.h"
|
|
10
|
+
NSString *const JWTAlgorithmNameNone = @"none";
|
|
11
|
+
|
|
12
|
+
@implementation JWTAlgorithmNone
|
|
13
|
+
|
|
14
|
+
- (NSString *)name {
|
|
15
|
+
return JWTAlgorithmNameNone;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
- (NSData *)signHash:(NSData *)hash key:(NSData *)key error:(NSError *__autoreleasing *)error {
|
|
19
|
+
return [NSData data];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
- (BOOL)verifyHash:(NSData *)hash signature:(NSData *)signature key:(NSData *)key error:(NSError *__autoreleasing *)error {
|
|
23
|
+
//if a secret is provided, this isn't the None algorithm
|
|
24
|
+
if (key && key.length > 0) {
|
|
25
|
+
return NO;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
//If the signature isn't blank, this isn't the None algorithm
|
|
29
|
+
if (signature && signature.length > 0) {
|
|
30
|
+
return NO;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return YES;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
- (NSData *)encodePayload:(NSString *)theString withSecret:(NSString *)theSecret {
|
|
37
|
+
return [self encodePayloadData:[theSecret dataUsingEncoding:NSUTF8StringEncoding] withSecret:[theSecret dataUsingEncoding:NSUTF8StringEncoding]];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
- (NSData *)encodePayloadData:(NSData *)theStringData withSecret:(NSData *)theSecretData
|
|
41
|
+
{
|
|
42
|
+
return [self signHash:theStringData key:theSecretData error:nil];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
- (BOOL)verifySignedInput:(NSString *)input withSignature:(NSString *)signature verificationKey:(NSString *)verificationKey
|
|
46
|
+
{
|
|
47
|
+
return [self verifySignedInput:input withSignature:signature verificationKeyData:verificationKey];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
- (BOOL)verifySignedInput:(NSString *)input withSignature:(NSString *)signature verificationKeyData:(NSData *)verificationKeyData
|
|
51
|
+
{
|
|
52
|
+
return [self verifyHash:[input dataUsingEncoding:NSUTF8StringEncoding] signature:[signature dataUsingEncoding:NSUTF8StringEncoding] key:verificationKeyData error:nil];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
@end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//
|
|
2
|
+
// JWTAlgorithmESBase.h
|
|
3
|
+
// Pods
|
|
4
|
+
//
|
|
5
|
+
// Created by Lobanov Dmitry on 12.02.17.
|
|
6
|
+
//
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
#import <Foundation/Foundation.h>
|
|
10
|
+
#import "JWTRSAlgorithm.h"
|
|
11
|
+
extern NSString *const JWTAlgorithmNameES256;
|
|
12
|
+
extern NSString *const JWTAlgorithmNameES384;
|
|
13
|
+
extern NSString *const JWTAlgorithmNameES512;
|
|
14
|
+
@interface JWTAlgorithmESBase : NSObject @end
|
|
15
|
+
|
|
16
|
+
@interface JWTAlgorithmESBase (JWTAsymmetricKeysAlgorithm) <JWTAsymmetricKeysAlgorithm> @end
|
|
17
|
+
|
|
18
|
+
@interface JWTAlgorithmESBase (Create)
|
|
19
|
+
|
|
20
|
+
+ (instancetype)algorithm256;
|
|
21
|
+
+ (instancetype)algorithm384;
|
|
22
|
+
+ (instancetype)algorithm512;
|
|
23
|
+
|
|
24
|
+
@end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
//
|
|
2
|
+
// JWTAlgorithmESBase.m
|
|
3
|
+
// Pods
|
|
4
|
+
//
|
|
5
|
+
// Created by Lobanov Dmitry on 12.02.17.
|
|
6
|
+
//
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
#import "JWTAlgorithmESBase.h"
|
|
10
|
+
#import <CommonCrypto/CommonCryptor.h>
|
|
11
|
+
@interface JWTAlgorithmESBase ()
|
|
12
|
+
|
|
13
|
+
@end
|
|
14
|
+
@implementation JWTAlgorithmESBase
|
|
15
|
+
@synthesize keyExtractorType;
|
|
16
|
+
@synthesize signKey;
|
|
17
|
+
@synthesize verifyKey;
|
|
18
|
+
@end
|
|
19
|
+
|
|
20
|
+
// thanks! https://github.com/soyersoyer/SwCrypt
|
|
21
|
+
@interface JWTAlgorithmESBase (ImportKeys)
|
|
22
|
+
- (void)importKey;
|
|
23
|
+
//importKey(publicKey, format: .importKeyBinary, keyType: .keyPublic)
|
|
24
|
+
@end
|
|
25
|
+
@implementation JWTAlgorithmESBase (ImportKeys)
|
|
26
|
+
- (void)importKey {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
@end
|
|
30
|
+
|
|
31
|
+
@implementation JWTAlgorithmESBase (JWTAsymmetricKeysAlgorithm)
|
|
32
|
+
- (NSString *)name {
|
|
33
|
+
return @"ESBase";
|
|
34
|
+
}
|
|
35
|
+
- (NSData *)signHash:(NSData *)hash key:(NSData *)key error:(NSError *__autoreleasing *)error {
|
|
36
|
+
return nil;
|
|
37
|
+
}
|
|
38
|
+
- (BOOL)verifyHash:(NSData *)hash signature:(NSData *)signature key:(NSData *)key error:(NSError *__autoreleasing *)error {
|
|
39
|
+
return NO;
|
|
40
|
+
}
|
|
41
|
+
@end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
//
|
|
2
|
+
// JWTAlgorithmHSBase.h
|
|
3
|
+
// JWT
|
|
4
|
+
//
|
|
5
|
+
// Created by Lobanov Dmitry on 13.03.16.
|
|
6
|
+
// Copyright © 2016 Karma. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
#import <Foundation/Foundation.h>
|
|
10
|
+
#import "JWTAlgorithm.h"
|
|
11
|
+
extern NSString *const JWTAlgorithmNameHS256;
|
|
12
|
+
extern NSString *const JWTAlgorithmNameHS384;
|
|
13
|
+
extern NSString *const JWTAlgorithmNameHS512;
|
|
14
|
+
|
|
15
|
+
@interface JWTAlgorithmHSBase : NSObject <JWTAlgorithm>
|
|
16
|
+
|
|
17
|
+
@property (assign, nonatomic, readonly) size_t ccSHANumberDigestLength;
|
|
18
|
+
@property (assign, nonatomic, readonly) uint32_t ccHmacAlgSHANumber;
|
|
19
|
+
|
|
20
|
+
@end
|
|
21
|
+
|
|
22
|
+
@interface JWTAlgorithmHSBase (Create)
|
|
23
|
+
|
|
24
|
+
+ (instancetype)algorithm256;
|
|
25
|
+
+ (instancetype)algorithm384;
|
|
26
|
+
+ (instancetype)algorithm512;
|
|
27
|
+
|
|
28
|
+
@end
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
//
|
|
2
|
+
// JWTAlgorithmHSBase.m
|
|
3
|
+
// JWT
|
|
4
|
+
//
|
|
5
|
+
// Created by Lobanov Dmitry on 13.03.16.
|
|
6
|
+
// Copyright © 2016 Karma. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
#import "JWTAlgorithmHSBase.h"
|
|
10
|
+
#import "JWTBase64Coder.h"
|
|
11
|
+
#import <CommonCrypto/CommonCrypto.h>
|
|
12
|
+
#import <CommonCrypto/CommonHMAC.h>
|
|
13
|
+
|
|
14
|
+
NSString *const JWTAlgorithmNameHS256 = @"HS256";
|
|
15
|
+
NSString *const JWTAlgorithmNameHS384 = @"HS384";
|
|
16
|
+
NSString *const JWTAlgorithmNameHS512 = @"HS512";
|
|
17
|
+
|
|
18
|
+
@interface JWTAlgorithmHSBase () @end
|
|
19
|
+
|
|
20
|
+
@implementation JWTAlgorithmHSBase
|
|
21
|
+
|
|
22
|
+
- (size_t)ccSHANumberDigestLength {
|
|
23
|
+
@throw [[NSException alloc] initWithName:NSInternalInconsistencyException reason:@"ccSHANumberDigestLength property should be overriden" userInfo:nil];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
- (uint32_t)ccHmacAlgSHANumber {
|
|
27
|
+
@throw [[NSException alloc] initWithName:NSInternalInconsistencyException reason:@"ccHmacAlgSHANumber property should be overriden" userInfo:nil];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
- (NSData *)signHash:(NSData *)hash key:(NSData *)key error:(NSError *__autoreleasing *)error {
|
|
31
|
+
size_t amount = self.ccSHANumberDigestLength;
|
|
32
|
+
size_t fullSize = amount * sizeof(unsigned char);
|
|
33
|
+
unsigned char* cHMAC = malloc(fullSize);
|
|
34
|
+
CCHmacAlgorithm ccAlg = self.ccHmacAlgSHANumber;
|
|
35
|
+
|
|
36
|
+
CCHmac(ccAlg, key.bytes, key.length, hash.bytes, hash.length, cHMAC);
|
|
37
|
+
|
|
38
|
+
NSData *result = [[NSData alloc] initWithBytes:cHMAC length:fullSize];
|
|
39
|
+
free(cHMAC);
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
- (BOOL)verifyHash:(NSData *)hash signature:(NSData *)signature key:(NSData *)key error:(NSError *__autoreleasing *)error {
|
|
44
|
+
NSData *expectedSignatureData = [self signHash:hash key:key error:error];
|
|
45
|
+
return [expectedSignatureData isEqualToData:signature];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
- (NSString *)name;
|
|
49
|
+
{
|
|
50
|
+
return @"HSBase";
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
- (NSData *)encodePayload:(NSString *)theString withSecret:(NSString *)theSecret;
|
|
54
|
+
{
|
|
55
|
+
NSData *inputData = [theString dataUsingEncoding:NSUTF8StringEncoding];
|
|
56
|
+
NSData *secretData = [theSecret dataUsingEncoding:NSUTF8StringEncoding];
|
|
57
|
+
//[JWTBase64Coder dataWithBase64UrlEncodedString:theSecret];
|
|
58
|
+
return [self encodePayloadData:inputData withSecret:secretData];
|
|
59
|
+
// const char *cString = [theString cStringUsingEncoding:NSUTF8StringEncoding];
|
|
60
|
+
// const char *cSecret = [theSecret cStringUsingEncoding:NSUTF8StringEncoding];
|
|
61
|
+
//
|
|
62
|
+
// size_t amount = self.ccSHANumberDigestLength;
|
|
63
|
+
// size_t fullSize = amount * sizeof(unsigned char);
|
|
64
|
+
// unsigned char* cHMAC = malloc(fullSize);
|
|
65
|
+
// CCHmacAlgorithm ccAlg = self.ccHmacAlgSHANumber;
|
|
66
|
+
//
|
|
67
|
+
// CCHmac(ccAlg, cSecret, strlen(cSecret), cString, strlen(cString), cHMAC);
|
|
68
|
+
//
|
|
69
|
+
// NSData *returnData = [[NSData alloc] initWithBytes:cHMAC length:fullSize];
|
|
70
|
+
// free(cHMAC);
|
|
71
|
+
// return returnData;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
- (NSData *)encodePayloadData:(NSData *)theStringData withSecret:(NSData *)theSecretData
|
|
75
|
+
{
|
|
76
|
+
return [self signHash:theStringData key:theSecretData error:nil];
|
|
77
|
+
// size_t amount = self.ccSHANumberDigestLength;
|
|
78
|
+
// size_t fullSize = amount * sizeof(unsigned char);
|
|
79
|
+
// unsigned char* cHMAC = malloc(fullSize);
|
|
80
|
+
// CCHmacAlgorithm ccAlg = self.ccHmacAlgSHANumber;
|
|
81
|
+
//
|
|
82
|
+
// CCHmac(ccAlg, theSecretData.bytes, [theSecretData length], theStringData.bytes, [theStringData length], cHMAC);
|
|
83
|
+
//
|
|
84
|
+
// NSData *returnData = [[NSData alloc] initWithBytes:cHMAC length:fullSize];
|
|
85
|
+
// free(cHMAC);
|
|
86
|
+
// return returnData;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
- (BOOL)verifySignedInput:(NSString *)input withSignature:(NSString *)signature verificationKey:(NSString *)verificationKey
|
|
90
|
+
{
|
|
91
|
+
NSData *verificationKeyData = [verificationKey dataUsingEncoding:NSUTF8StringEncoding];
|
|
92
|
+
return [self verifySignedInput:input withSignature:signature verificationKeyData:verificationKeyData];
|
|
93
|
+
// NSData *expectedSignatureData = [self encodePayload:input withSecret:verificationKey];
|
|
94
|
+
// NSString *expectedSignature = [JWTBase64Coder base64UrlEncodedStringWithData:expectedSignatureData];
|
|
95
|
+
//
|
|
96
|
+
// return [expectedSignature isEqualToString:signature];
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
- (BOOL)verifySignedInput:(NSString *)input withSignature:(NSString *)signature verificationKeyData:(NSData *)verificationKeyData {
|
|
100
|
+
NSData *signatureData = [JWTBase64Coder dataWithBase64UrlEncodedString:signature];
|
|
101
|
+
NSData *inputData = [input dataUsingEncoding:NSUTF8StringEncoding];//[JWTBase64Coder dataWithBase64UrlEncodedString:input];
|
|
102
|
+
return [self verifyHash:inputData signature:signatureData key:verificationKeyData error:nil ];
|
|
103
|
+
// const char *cString = [input cStringUsingEncoding:NSUTF8StringEncoding];
|
|
104
|
+
// NSData *inputData = [NSData dataWithBytes:cString length:strlen(cString)];
|
|
105
|
+
//
|
|
106
|
+
// NSData *expectedSignatureData = [self encodePayloadData:inputData withSecret:verificationKeyData];
|
|
107
|
+
// NSString *expectedSignature = [JWTBase64Coder base64UrlEncodedStringWithData:expectedSignatureData];
|
|
108
|
+
//
|
|
109
|
+
// return [expectedSignature isEqualToString:signature];
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
@end
|
|
113
|
+
|
|
114
|
+
@interface JWTAlgorithmHSFamilyMember : JWTAlgorithmHSBase @end
|
|
115
|
+
@implementation JWTAlgorithmHSFamilyMember @end
|
|
116
|
+
|
|
117
|
+
@interface JWTAlgorithmHS256 : JWTAlgorithmHSBase @end
|
|
118
|
+
@interface JWTAlgorithmHS384 : JWTAlgorithmHSBase @end
|
|
119
|
+
@interface JWTAlgorithmHS512 : JWTAlgorithmHSBase @end
|
|
120
|
+
|
|
121
|
+
@implementation JWTAlgorithmHS256
|
|
122
|
+
|
|
123
|
+
- (size_t)ccSHANumberDigestLength {
|
|
124
|
+
return CC_SHA256_DIGEST_LENGTH;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
- (uint32_t)ccHmacAlgSHANumber {
|
|
128
|
+
return kCCHmacAlgSHA256;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
- (NSString *)name {
|
|
132
|
+
return @"HS256";
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
@end
|
|
136
|
+
|
|
137
|
+
@implementation JWTAlgorithmHS384
|
|
138
|
+
|
|
139
|
+
- (size_t)ccSHANumberDigestLength {
|
|
140
|
+
return CC_SHA384_DIGEST_LENGTH;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
- (uint32_t)ccHmacAlgSHANumber {
|
|
144
|
+
return kCCHmacAlgSHA384;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
- (NSString *)name {
|
|
148
|
+
return @"HS384";
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
@end
|
|
152
|
+
|
|
153
|
+
@implementation JWTAlgorithmHS512
|
|
154
|
+
|
|
155
|
+
- (size_t)ccSHANumberDigestLength {
|
|
156
|
+
return CC_SHA512_DIGEST_LENGTH;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
- (uint32_t)ccHmacAlgSHANumber {
|
|
160
|
+
return kCCHmacAlgSHA512;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
- (NSString *)name {
|
|
164
|
+
return @"HS512";
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
@end
|
|
168
|
+
|
|
169
|
+
@interface JWTAlgorithmHSFamilyMemberMutable : JWTAlgorithmHSFamilyMember
|
|
170
|
+
@property (assign, nonatomic, readwrite) size_t ccSHANumberDigestLength;
|
|
171
|
+
@property (assign, nonatomic, readwrite) uint32_t ccHmacAlgSHANumber;
|
|
172
|
+
@property (copy, nonatomic, readwrite) NSString *name;
|
|
173
|
+
@end
|
|
174
|
+
|
|
175
|
+
@implementation JWTAlgorithmHSFamilyMemberMutable
|
|
176
|
+
|
|
177
|
+
@synthesize ccSHANumberDigestLength = _ccSHANumberDigestLength;
|
|
178
|
+
@synthesize ccHmacAlgSHANumber = _ccHmacAlgSHANumber;
|
|
179
|
+
@synthesize name = _name;
|
|
180
|
+
|
|
181
|
+
- (size_t)ccSHANumberDigestLength {
|
|
182
|
+
return _ccSHANumberDigestLength;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
- (uint32_t)ccHmacAlgSHANumber {
|
|
186
|
+
return _ccHmacAlgSHANumber;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
@end
|
|
190
|
+
|
|
191
|
+
@implementation JWTAlgorithmHSBase (Create)
|
|
192
|
+
|
|
193
|
+
+ (instancetype)algorithm256 {
|
|
194
|
+
return [JWTAlgorithmHS256 new];
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
+ (instancetype)algorithm384 {
|
|
198
|
+
return [JWTAlgorithmHS384 new];
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
+ (instancetype)algorithm512 {
|
|
202
|
+
return [JWTAlgorithmHS512 new];
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
@end
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
//
|
|
2
|
+
// JWTAlgorithmDataHolder.h
|
|
3
|
+
// JWT
|
|
4
|
+
//
|
|
5
|
+
// Created by Lobanov Dmitry on 31.08.16.
|
|
6
|
+
// Copyright © 2016 Karma. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
#import <Foundation/Foundation.h>
|
|
10
|
+
#import "JWTAlgorithm.h"
|
|
11
|
+
#import "JWTDeprecations.h"
|
|
12
|
+
#import "JWTBase64Coder.h"
|
|
13
|
+
|
|
14
|
+
// TODO: available in 3.0
|
|
15
|
+
// All methods with secret as NSString in algorithms will be deprecated or removed.
|
|
16
|
+
|
|
17
|
+
@protocol JWTAlgorithmDataHolderProtocol <NSObject, NSCopying>
|
|
18
|
+
/**
|
|
19
|
+
The verification key to use when encoding/decoding a JWT in data form
|
|
20
|
+
*/
|
|
21
|
+
@property (copy, nonatomic, readwrite) NSData *internalSecretData;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
The <JWTAlgorithm> to use for encoding a JWT
|
|
25
|
+
*/
|
|
26
|
+
@property (strong, nonatomic, readwrite) id <JWTAlgorithm> internalAlgorithm;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
The <JWTStringCoder__Protocol> string coder. It converts data to string and vice versa.
|
|
30
|
+
*/
|
|
31
|
+
@property (strong, nonatomic, readwrite) id <JWTStringCoder__Protocol> internalStringCoder;
|
|
32
|
+
@end
|
|
33
|
+
|
|
34
|
+
@interface JWTAlgorithmBaseDataHolder : NSObject <JWTAlgorithmDataHolderProtocol>
|
|
35
|
+
|
|
36
|
+
#pragma mark - Getters
|
|
37
|
+
/**
|
|
38
|
+
The verification key to use when encoding/decoding a JWT
|
|
39
|
+
*/
|
|
40
|
+
@property (copy, nonatomic, readonly) NSString *internalSecret;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
The algorithm name to use for decoding the JWT. Required unless force decode is true
|
|
44
|
+
*/
|
|
45
|
+
@property (copy, nonatomic, readonly) NSString *internalAlgorithmName;
|
|
46
|
+
|
|
47
|
+
#pragma mark - Setters
|
|
48
|
+
/**
|
|
49
|
+
Sets jwtSecret and returns the JWTAlgorithmBaseDataHolder to allow for method chaining
|
|
50
|
+
*/
|
|
51
|
+
@property (copy, nonatomic, readonly) JWTAlgorithmBaseDataHolder *(^secret)(NSString *secret);
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
Sets jwtSecretData and returns the JWTAlgorithmBaseDataHolder to allow for method chaining
|
|
55
|
+
*/
|
|
56
|
+
@property (copy, nonatomic, readonly) JWTAlgorithmBaseDataHolder *(^secretData)(NSData *secretData);
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
Sets jwtAlgorithm and returns the JWTAlgorithmBaseDataHolder to allow for method chaining
|
|
60
|
+
*/
|
|
61
|
+
@property (copy, nonatomic, readonly) JWTAlgorithmBaseDataHolder *(^algorithm)(id<JWTAlgorithm>algorithm);
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
Sets jwtAlgorithmName and returns the JWTAlgorithmBaseDataHolder to allow for method chaining. See list of names in appropriate headers.
|
|
65
|
+
*/
|
|
66
|
+
@property (copy, nonatomic, readonly) JWTAlgorithmBaseDataHolder *(^algorithmName)(NSString *algorithmName);
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
Sets stringCoder and returns the JWTAlgorithmBaseDataHolder to allow for method chaining. See list of names in appropriate headers.
|
|
70
|
+
*/
|
|
71
|
+
@property (copy, nonatomic, readonly) JWTAlgorithmBaseDataHolder *(^stringCoder)(id<JWTStringCoder__Protocol> stringCoder);
|
|
72
|
+
@end
|
|
73
|
+
|
|
74
|
+
@protocol JWTAlgorithmDataHolderCreateProtocol <NSObject>
|
|
75
|
+
|
|
76
|
+
+ (instancetype)createWithAlgorithm256;
|
|
77
|
+
+ (instancetype)createWithAlgorithm384;
|
|
78
|
+
+ (instancetype)createWithAlgorithm512;
|
|
79
|
+
|
|
80
|
+
@end
|
|
81
|
+
|
|
82
|
+
@interface JWTAlgorithmNoneDataHolder : JWTAlgorithmBaseDataHolder @end
|
|
83
|
+
@interface JWTAlgorithmHSFamilyDataHolder : JWTAlgorithmBaseDataHolder <JWTAlgorithmDataHolderCreateProtocol>
|
|
84
|
+
@end
|
|
85
|
+
@protocol JWTCryptoKeyProtocol;
|
|
86
|
+
@interface JWTAlgorithmRSFamilyDataHolder : JWTAlgorithmBaseDataHolder <JWTAlgorithmDataHolderCreateProtocol>
|
|
87
|
+
#pragma mark - Getters
|
|
88
|
+
/**
|
|
89
|
+
The passphrase for the PKCS12 blob, which represents the certificate containing the private key for the RS algorithms.
|
|
90
|
+
*/
|
|
91
|
+
@property (copy, nonatomic, readonly) NSString *internalPrivateKeyCertificatePassphrase;
|
|
92
|
+
@property (copy, nonatomic, readonly) NSString *internalKeyExtractorType;
|
|
93
|
+
@property (strong, nonatomic, readonly) id<JWTCryptoKeyProtocol> internalSignKey;
|
|
94
|
+
@property (strong, nonatomic, readonly) id<JWTCryptoKeyProtocol> internalVerifyKey;
|
|
95
|
+
#pragma mark - Setters
|
|
96
|
+
/**
|
|
97
|
+
Sets jwtPrivateKeyCertificatePassphrase and returns the JWTAlgorithmRSFamilyDataHolder to allow for method chaining
|
|
98
|
+
*/
|
|
99
|
+
@property (copy, nonatomic, readonly) JWTAlgorithmRSFamilyDataHolder *(^privateKeyCertificatePassphrase)(NSString *privateKeyCertificatePassphrase);
|
|
100
|
+
@property (copy, nonatomic, readonly) JWTAlgorithmRSFamilyDataHolder *(^keyExtractorType)(NSString *keyExtractorType);
|
|
101
|
+
@property (copy, nonatomic, readonly) JWTAlgorithmRSFamilyDataHolder *(^signKey)(id<JWTCryptoKeyProtocol> signKey);
|
|
102
|
+
@property (copy, nonatomic, readonly) JWTAlgorithmRSFamilyDataHolder *(^verifyKey)(id<JWTCryptoKeyProtocol> verifyKey);
|
|
103
|
+
@end
|