@appzung/react-native-code-push 9.0.2 → 10.0.0-rc1

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.
Files changed (191) hide show
  1. package/CodePush.js +22 -19
  2. package/LICENSE.md +1 -1
  3. package/README.md +159 -298
  4. package/android/app/.gradle/config.properties +2 -0
  5. package/android/app/build.gradle +1 -1
  6. package/android/app/local.properties +8 -0
  7. package/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java +27 -21
  8. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushBuilder.java +5 -5
  9. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushConstants.java +1 -1
  10. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushDialog.java +1 -1
  11. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushInstallMode.java +2 -2
  12. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushInvalidPublicKeyException.java +2 -2
  13. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushInvalidUpdateException.java +1 -1
  14. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushMalformedDataException.java +2 -2
  15. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java +5 -5
  16. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushNotInitializedException.java +2 -2
  17. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushTelemetryManager.java +14 -14
  18. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUnknownException.java +2 -2
  19. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUpdateManager.java +1 -1
  20. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUpdateState.java +2 -2
  21. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUpdateUtils.java +1 -1
  22. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUtils.java +1 -1
  23. package/android/app/src/main/java/com/microsoft/codepush/react/DownloadProgress.java +1 -1
  24. package/android/app/src/main/java/com/microsoft/codepush/react/DownloadProgressCallback.java +1 -1
  25. package/android/app/src/main/java/com/microsoft/codepush/react/FileUtils.java +1 -1
  26. package/android/app/src/main/java/com/microsoft/codepush/react/ReactInstanceHolder.java +1 -1
  27. package/android/app/src/main/java/com/microsoft/codepush/react/SettingsManager.java +1 -1
  28. package/android/app/src/main/java/com/microsoft/codepush/react/TLSSocketFactory.java +1 -1
  29. package/android/build.gradle +1 -1
  30. package/android/codepush.gradle +3 -3
  31. package/docs/advanced-usage.md +56 -0
  32. package/docs/api-android.md +12 -75
  33. package/docs/api-ios.md +5 -17
  34. package/docs/api-js.md +18 -55
  35. package/docs/setup-android.md +15 -397
  36. package/docs/setup-ios.md +24 -198
  37. package/docs/setup-windows.md +7 -74
  38. package/ios/CodePush/CodePush.h +4 -4
  39. package/ios/CodePush/CodePush.m +8 -8
  40. package/ios/CodePush/CodePushConfig.m +14 -11
  41. package/ios/CodePush/CodePushPackage.m +60 -60
  42. package/ios/CodePush/CodePushTelemetryManager.m +13 -13
  43. package/ios/CodePush.xcodeproj/project.pbxproj +1 -562
  44. package/package.json +27 -24
  45. package/react-native.config.js +1 -1
  46. package/scripts/generateBundledResourcesHash.js +1 -1
  47. package/scripts/getFilesInFolder.js +1 -1
  48. package/scripts/recordFilesBeforeBundleCommand.js +1 -1
  49. package/typings/react-native-code-push.d.ts +22 -22
  50. package/windows/CodePush/CodePushConfig.cpp +3 -3
  51. package/windows/CodePush/CodePushConfig.h +3 -3
  52. package/windows/CodePush/CodePushNativeModule.cpp +27 -27
  53. package/windows/CodePush/CodePushNativeModule.h +4 -4
  54. package/windows/CodePush/CodePushTelemetryManager.cpp +12 -12
  55. package/windows/CodePush/CodePushTelemetryManager.h +1 -1
  56. package/.azurepipelines/build-rn-code-push-1es.yml +0 -104
  57. package/.azurepipelines/test-rn-code-push.yml +0 -94
  58. package/.config/CredScanSuppressions.json +0 -14
  59. package/SECURITY.md +0 -41
  60. package/docs/multi-deployment-testing-android.md +0 -148
  61. package/docs/multi-deployment-testing-ios.md +0 -59
  62. package/ios/CodePush/Base64/Base64/MF_Base64Additions.h +0 -34
  63. package/ios/CodePush/Base64/Base64/MF_Base64Additions.m +0 -252
  64. package/ios/CodePush/Base64/README.md +0 -47
  65. package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithm.h +0 -69
  66. package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithmFactory.h +0 -16
  67. package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithmFactory.m +0 -51
  68. package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithmNone.h +0 -15
  69. package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithmNone.m +0 -55
  70. package/ios/CodePush/JWT/Core/Algorithms/ESFamily/JWTAlgorithmESBase.h +0 -24
  71. package/ios/CodePush/JWT/Core/Algorithms/ESFamily/JWTAlgorithmESBase.m +0 -41
  72. package/ios/CodePush/JWT/Core/Algorithms/HSFamily/JWTAlgorithmHSBase.h +0 -28
  73. package/ios/CodePush/JWT/Core/Algorithms/HSFamily/JWTAlgorithmHSBase.m +0 -205
  74. package/ios/CodePush/JWT/Core/Algorithms/Holders/JWTAlgorithmDataHolder.h +0 -103
  75. package/ios/CodePush/JWT/Core/Algorithms/Holders/JWTAlgorithmDataHolder.m +0 -322
  76. package/ios/CodePush/JWT/Core/Algorithms/Holders/JWTAlgorithmDataHolderChain.h +0 -37
  77. package/ios/CodePush/JWT/Core/Algorithms/Holders/JWTAlgorithmDataHolderChain.m +0 -145
  78. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/JWTAlgorithmRSBase.h +0 -35
  79. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/JWTAlgorithmRSBase.m +0 -551
  80. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/JWTRSAlgorithm.h +0 -23
  81. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoKey.h +0 -43
  82. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoKey.m +0 -230
  83. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoKeyExtractor.h +0 -31
  84. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoKeyExtractor.m +0 -113
  85. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoSecurity.h +0 -38
  86. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoSecurity.m +0 -500
  87. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaim.h +0 -18
  88. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaim.m +0 -214
  89. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSet.h +0 -23
  90. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSet.m +0 -29
  91. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSetSerializer.h +0 -19
  92. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSetSerializer.m +0 -68
  93. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSetVerifier.h +0 -18
  94. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSetVerifier.m +0 -72
  95. package/ios/CodePush/JWT/Core/Coding/JWTCoding+ResultTypes.h +0 -67
  96. package/ios/CodePush/JWT/Core/Coding/JWTCoding+ResultTypes.m +0 -111
  97. package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionOne.h +0 -119
  98. package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionOne.m +0 -307
  99. package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionThree.h +0 -94
  100. package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionThree.m +0 -619
  101. package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionTwo.h +0 -164
  102. package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionTwo.m +0 -514
  103. package/ios/CodePush/JWT/Core/Coding/JWTCoding.h +0 -24
  104. package/ios/CodePush/JWT/Core/Coding/JWTCoding.m +0 -11
  105. package/ios/CodePush/JWT/Core/FrameworkSupplement/JWT.h +0 -52
  106. package/ios/CodePush/JWT/Core/FrameworkSupplement/Map.modulemap +0 -5
  107. package/ios/CodePush/JWT/Core/Supplement/JWTBase64Coder.h +0 -28
  108. package/ios/CodePush/JWT/Core/Supplement/JWTBase64Coder.m +0 -70
  109. package/ios/CodePush/JWT/Core/Supplement/JWTDeprecations.h +0 -22
  110. package/ios/CodePush/JWT/Core/Supplement/JWTErrorDescription.h +0 -34
  111. package/ios/CodePush/JWT/Core/Supplement/JWTErrorDescription.m +0 -73
  112. package/ios/CodePush/JWT/LICENSE +0 -19
  113. package/ios/CodePush/JWT/README.md +0 -489
  114. package/ios/CodePush/SSZipArchive/Info.plist +0 -26
  115. package/ios/CodePush/SSZipArchive/README.md +0 -1
  116. package/ios/CodePush/SSZipArchive/SSZipArchive.h +0 -178
  117. package/ios/CodePush/SSZipArchive/SSZipArchive.m +0 -1496
  118. package/ios/CodePush/SSZipArchive/SSZipCommon.h +0 -71
  119. package/ios/CodePush/SSZipArchive/Supporting Files/PrivacyInfo.xcprivacy +0 -23
  120. package/ios/CodePush/SSZipArchive/include/ZipArchive.h +0 -25
  121. package/ios/CodePush/SSZipArchive/minizip/LICENSE +0 -17
  122. package/ios/CodePush/SSZipArchive/minizip/mz.h +0 -273
  123. package/ios/CodePush/SSZipArchive/minizip/mz_compat.c +0 -1306
  124. package/ios/CodePush/SSZipArchive/minizip/mz_compat.h +0 -346
  125. package/ios/CodePush/SSZipArchive/minizip/mz_crypt.c +0 -187
  126. package/ios/CodePush/SSZipArchive/minizip/mz_crypt.h +0 -65
  127. package/ios/CodePush/SSZipArchive/minizip/mz_crypt_apple.c +0 -526
  128. package/ios/CodePush/SSZipArchive/minizip/mz_os.c +0 -348
  129. package/ios/CodePush/SSZipArchive/minizip/mz_os.h +0 -176
  130. package/ios/CodePush/SSZipArchive/minizip/mz_os_posix.c +0 -350
  131. package/ios/CodePush/SSZipArchive/minizip/mz_strm.c +0 -556
  132. package/ios/CodePush/SSZipArchive/minizip/mz_strm.h +0 -132
  133. package/ios/CodePush/SSZipArchive/minizip/mz_strm_buf.c +0 -383
  134. package/ios/CodePush/SSZipArchive/minizip/mz_strm_buf.h +0 -42
  135. package/ios/CodePush/SSZipArchive/minizip/mz_strm_mem.c +0 -269
  136. package/ios/CodePush/SSZipArchive/minizip/mz_strm_mem.h +0 -48
  137. package/ios/CodePush/SSZipArchive/minizip/mz_strm_os.h +0 -40
  138. package/ios/CodePush/SSZipArchive/minizip/mz_strm_os_posix.c +0 -203
  139. package/ios/CodePush/SSZipArchive/minizip/mz_strm_pkcrypt.c +0 -334
  140. package/ios/CodePush/SSZipArchive/minizip/mz_strm_pkcrypt.h +0 -46
  141. package/ios/CodePush/SSZipArchive/minizip/mz_strm_split.c +0 -429
  142. package/ios/CodePush/SSZipArchive/minizip/mz_strm_split.h +0 -43
  143. package/ios/CodePush/SSZipArchive/minizip/mz_strm_wzaes.c +0 -360
  144. package/ios/CodePush/SSZipArchive/minizip/mz_strm_wzaes.h +0 -46
  145. package/ios/CodePush/SSZipArchive/minizip/mz_strm_zlib.c +0 -389
  146. package/ios/CodePush/SSZipArchive/minizip/mz_strm_zlib.h +0 -43
  147. package/ios/CodePush/SSZipArchive/minizip/mz_zip.c +0 -2782
  148. package/ios/CodePush/SSZipArchive/minizip/mz_zip.h +0 -262
  149. package/ios/CodePush/SSZipArchive/minizip/mz_zip_rw.c +0 -1942
  150. package/ios/CodePush/SSZipArchive/minizip/mz_zip_rw.h +0 -285
  151. package/scripts/postlink/android/postlink.js +0 -87
  152. package/scripts/postlink/ios/postlink.js +0 -116
  153. package/scripts/postlink/run.js +0 -11
  154. package/scripts/postunlink/android/postunlink.js +0 -74
  155. package/scripts/postunlink/ios/postunlink.js +0 -87
  156. package/scripts/postunlink/run.js +0 -11
  157. package/scripts/tools/linkToolsAndroid.js +0 -57
  158. package/scripts/tools/linkToolsIos.js +0 -130
  159. package/windows-legacy/CodePush/CodePush.csproj +0 -128
  160. package/windows-legacy/CodePush/CodePushUtils.cs +0 -47
  161. package/windows-legacy/CodePush/FileUtils.cs +0 -40
  162. package/windows-legacy/CodePush/Properties/AssemblyInfo.cs +0 -29
  163. package/windows-legacy/CodePush/Properties/CodePush.rd.xml +0 -33
  164. package/windows-legacy/CodePush/UpdateManager.cs +0 -305
  165. package/windows-legacy/CodePush/UpdateUtils.cs +0 -46
  166. package/windows-legacy/CodePush.Net46/Adapters/Http/HttpProgress.cs +0 -28
  167. package/windows-legacy/CodePush.Net46/Adapters/Storage/ApplicationDataContainer.cs +0 -106
  168. package/windows-legacy/CodePush.Net46/CodePush.Net46.csproj +0 -103
  169. package/windows-legacy/CodePush.Net46/CodePushUtils.cs +0 -158
  170. package/windows-legacy/CodePush.Net46/FileUtils.cs +0 -55
  171. package/windows-legacy/CodePush.Net46/Properties/AssemblyInfo.cs +0 -36
  172. package/windows-legacy/CodePush.Net46/UpdateManager.cs +0 -330
  173. package/windows-legacy/CodePush.Net46/UpdateUtils.cs +0 -70
  174. package/windows-legacy/CodePush.Net46/packages.config +0 -5
  175. package/windows-legacy/CodePush.Net46.Test/ApplicationDataContainerTest.cs +0 -105
  176. package/windows-legacy/CodePush.Net46.Test/CodePush.Net46.Test.csproj +0 -137
  177. package/windows-legacy/CodePush.Net46.Test/Properties/AssemblyInfo.cs +0 -36
  178. package/windows-legacy/CodePush.Net46.Test/TelemetryManagerTest.cs +0 -117
  179. package/windows-legacy/CodePush.Net46.Test/app.config +0 -11
  180. package/windows-legacy/CodePush.Net46.Test/packages.config +0 -4
  181. package/windows-legacy/CodePush.Shared/CodePush.Shared.projitems +0 -22
  182. package/windows-legacy/CodePush.Shared/CodePush.Shared.shproj +0 -13
  183. package/windows-legacy/CodePush.Shared/CodePushConstants.cs +0 -35
  184. package/windows-legacy/CodePush.Shared/CodePushNativeModule.cs +0 -329
  185. package/windows-legacy/CodePush.Shared/CodePushReactPackage.cs +0 -235
  186. package/windows-legacy/CodePush.Shared/CodePushUtils.cs +0 -70
  187. package/windows-legacy/CodePush.Shared/InstallMode.cs +0 -9
  188. package/windows-legacy/CodePush.Shared/MinimumBackgroundListener.cs +0 -44
  189. package/windows-legacy/CodePush.Shared/SettingsManager.cs +0 -148
  190. package/windows-legacy/CodePush.Shared/TelemetryManager.cs +0 -250
  191. package/windows-legacy/CodePush.Shared/UpdateState.cs +0 -9
@@ -1,551 +0,0 @@
1
- //
2
- // JWTAlgorithmRSBase.m
3
- // JWT
4
- //
5
- // Created by Lobanov Dmitry on 13.03.16.
6
- // Copyright © 2016 Karma. All rights reserved.
7
- //
8
-
9
- #import "JWTAlgorithmRSBase.h"
10
- #import "JWTBase64Coder.h"
11
- #import "JWTCryptoSecurity.h"
12
- #import "JWTCryptoKeyExtractor.h"
13
- #import "JWTCryptoKey.h"
14
- #import "JWTAlgorithmFactory.h"
15
- #import <CommonCrypto/CommonCrypto.h>
16
- /*
17
- * * Possible inheritence *
18
- *
19
- *
20
- * RSBase (Public + Create-category)
21
- * / \
22
- * / \
23
- * RSBaseMac RSBaseIOS
24
- * \ ifdef /
25
- * \ /
26
- * RSFamilyMember
27
- * |
28
- * RSFamilyMemberMutable
29
- *
30
- */
31
-
32
- NSString *const JWTAlgorithmNameRS256 = @"RS256";
33
- NSString *const JWTAlgorithmNameRS384 = @"RS384";
34
- NSString *const JWTAlgorithmNameRS512 = @"RS512";
35
-
36
- @interface JWTAlgorithmRSBase()
37
- @property (nonatomic, readonly) id <JWTCryptoKeyExtractorProtocol> keyExtractor;
38
- @end
39
-
40
- @implementation JWTAlgorithmRSBase
41
-
42
- #pragma mark - NSCopying
43
- - (id)copyWithZone:(NSZone *)zone {
44
- // create new.
45
- id <JWTRSAlgorithm> algorithm = (id<JWTRSAlgorithm>)[JWTAlgorithmFactory algorithmByName:[self name]];
46
- algorithm.privateKeyCertificatePassphrase = self.privateKeyCertificatePassphrase;
47
- algorithm.keyExtractorType = self.keyExtractorType;
48
- algorithm.signKey = self.signKey;
49
- algorithm.verifyKey = self.verifyKey;
50
- return algorithm;
51
- }
52
-
53
- @synthesize privateKeyCertificatePassphrase;
54
- @synthesize keyExtractorType;
55
- @synthesize signKey;
56
- @synthesize verifyKey;
57
- - (id<JWTCryptoKeyExtractorProtocol>) keyExtractor {
58
- return [JWTCryptoKeyExtractor createWithType:self.keyExtractorType];
59
- }
60
- #pragma mark - Override
61
- - (size_t)ccSHANumberDigestLength {
62
- @throw [[NSException alloc] initWithName:NSInternalInconsistencyException reason:@"ccSHANumberDigestLength property should be overriden" userInfo:nil];
63
- }
64
-
65
- - (uint32_t)secPaddingPKCS1SHANumber {
66
- @throw [[NSException alloc] initWithName:NSInternalInconsistencyException reason:@"secPaddingPKCS1SHANumber property should be overriden" userInfo:nil];
67
- }
68
-
69
- - (unsigned char *)CC_SHANumberWithData:(const void *)data withLength:(CC_LONG)len withHashBytes:(unsigned char *)hashBytes {
70
- return nil;
71
- }
72
-
73
- - (NSString *)name {
74
- return @"RSBase";
75
- }
76
-
77
- #pragma mark - JWTAlgorithm
78
- - (NSData *)signHash:(NSData *)hash key:(NSData *)key error:(NSError *__autoreleasing *)error {
79
- NSData *result = nil;
80
- if (self.signKey || self.keyExtractor) {
81
- NSError *extractKeyError = nil;
82
- id <JWTCryptoKeyProtocol> keyItem = self.signKey ?: [self.keyExtractor keyFromData:key parameters:@{ [JWTCryptoKeyExtractor parametersKeyCertificatePassphrase] : self.privateKeyCertificatePassphrase ?: [NSNull null] } error:&extractKeyError];
83
-
84
- if (extractKeyError || keyItem == nil) {
85
- // tell about error
86
- if (extractKeyError && error) {
87
- *error = extractKeyError;
88
- }
89
- NSError *removeError = nil;
90
- [JWTCryptoSecurity removeKeyByTag:keyItem.tag error:&removeError];
91
- if (removeError && error) {
92
- *error = removeError;
93
- }
94
- }
95
- else {
96
- result = [self signData:hash withKey:keyItem.key];
97
- }
98
- }
99
- else {
100
- SecIdentityRef identity = nil;
101
- SecTrustRef trust = nil;
102
-
103
- // [JWTCryptoSecurity extractIdentityAndTrustFromPKCS12:inPKCS12Data password:keyPassword identity:outIdentity trust:outTrust];
104
- [JWTCryptoSecurity extractIdentityAndTrustFromPKCS12:(__bridge CFDataRef)(key) password: (__bridge CFStringRef)(self.privateKeyCertificatePassphrase) identity:&identity trust:&trust];
105
-
106
- if (identity && trust) {
107
- SecKeyRef privateKey;
108
- SecIdentityCopyPrivateKey(identity, &privateKey);
109
- result = [self signData:hash withKey:privateKey];
110
-
111
- if (privateKey) {
112
- CFRelease(privateKey);
113
- }
114
- }
115
-
116
- if (identity) {
117
- CFRelease(identity);
118
- }
119
-
120
- if (trust) {
121
- CFRelease(trust);
122
- }
123
- }
124
- return result;
125
- }
126
- - (BOOL)verifyHash:(NSData *)hash signature:(NSData *)signature key:(NSData *)key error:(NSError *__autoreleasing *)error {
127
- if (self.verifyKey || self.keyExtractor) {
128
- NSError *extractKeyError = nil;
129
- id<JWTCryptoKeyProtocol> keyItem = self.verifyKey?: [self.keyExtractor keyFromData:key parameters:nil error:&extractKeyError];
130
- BOOL verified = NO;
131
-
132
- if (extractKeyError || keyItem == nil) {
133
- // error while getting key.
134
- // cleanup.
135
- // tell about error
136
- if (extractKeyError && error) {
137
- *error = extractKeyError;
138
- }
139
- NSError *removeError = nil;
140
- [JWTCryptoSecurity removeKeyByTag:keyItem.tag error:&removeError];
141
- if (removeError && error) {
142
- //???
143
- *error = removeError;
144
- }
145
- return verified;
146
- }
147
- else {
148
- verified = [self verifyData:hash witSignature:signature withKey:keyItem.key];
149
- }
150
-
151
- NSError *removeError = nil;
152
- [JWTCryptoSecurity removeKeyByTag:keyItem.tag error:&removeError];
153
-
154
- if (error && removeError) {
155
- *error = removeError;
156
- }
157
-
158
- return verified;
159
- }
160
- else {
161
- SecKeyRef publicKey = [JWTCryptoSecurity publicKeyFromCertificate:key];
162
- // TODO: special error handling here.
163
- // add error handling later?
164
- if (publicKey != NULL) {
165
- BOOL verified = [self verifyData:hash witSignature:signature withKey:publicKey];
166
- CFRelease(publicKey);
167
- return verified;
168
- }
169
- }
170
- return NO;
171
- }
172
-
173
- - (NSData *)encodePayload:(NSString *)theString withSecret:(NSString *)theSecret {
174
- return [self encodePayloadData:[theString dataUsingEncoding:NSUTF8StringEncoding] withSecret:[JWTBase64Coder dataWithBase64UrlEncodedString:theSecret]];
175
- }
176
- - (NSData *)encodePayloadData:(NSData *)theStringData withSecret:(NSData *)theSecretData {
177
- return [self signHash:theStringData key:theSecretData error:nil];
178
- }
179
- - (BOOL)verifySignedInput:(NSString *)input withSignature:(NSString *)signature verificationKey:(NSString *)verificationKey {
180
- NSData *certificateData = [JWTBase64Coder dataWithBase64UrlEncodedString:verificationKey];
181
- return [self verifySignedInput:input withSignature:signature verificationKeyData:certificateData];
182
- }
183
- - (BOOL)verifySignedInput:(NSString *)input withSignature:(NSString *)signature verificationKeyData:(NSData *)verificationKeyData {
184
- return [self verifyHash:[input dataUsingEncoding:NSUTF8StringEncoding] signature:[JWTBase64Coder dataWithBase64UrlEncodedString:signature] key:verificationKeyData error:nil];
185
- }
186
-
187
- #pragma mark - Private ( Override-part depends on platform )
188
- - (BOOL)verifyData:(NSData *)plainData witSignature:(NSData *)signature withKey:(SecKeyRef) publicKey {
189
- return NO;
190
- }
191
-
192
- - (NSData *)signData:(NSData *)plainData withKey:(SecKeyRef)privateKey {
193
- return nil;
194
- }
195
- @end
196
-
197
- #if TARGET_OS_MAC && TARGET_OS_IPHONE
198
- @interface JWTAlgorithmRSBaseIOS : JWTAlgorithmRSBase @end
199
- @implementation JWTAlgorithmRSBaseIOS
200
- - (BOOL)verifyData:(NSData *)plainData witSignature:(NSData *)signature withKey:(SecKeyRef) publicKey {
201
- size_t signedHashBytesSize = SecKeyGetBlockSize(publicKey);
202
- const void* signedHashBytes = [signature bytes];
203
-
204
- size_t hashBytesSize = self.ccSHANumberDigestLength;
205
- uint8_t* hashBytes = malloc(hashBytesSize);
206
- if (![self CC_SHANumberWithData:[plainData bytes] withLength:(CC_LONG)[plainData length] withHashBytes:hashBytes]) {
207
- return false;
208
- }
209
-
210
- OSStatus status = SecKeyRawVerify(publicKey,
211
- self.secPaddingPKCS1SHANumber,
212
- hashBytes,
213
- hashBytesSize,
214
- signedHashBytes,
215
- signedHashBytesSize);
216
-
217
- return status == errSecSuccess;
218
- }
219
-
220
- - (NSData *)signData:(NSData *)plainData withKey:(SecKeyRef)privateKey {
221
- size_t signedHashBytesSize = SecKeyGetBlockSize(privateKey);
222
- uint8_t* signedHashBytes = malloc(signedHashBytesSize);
223
- memset(signedHashBytes, 0x0, signedHashBytesSize);
224
-
225
- size_t hashBytesSize = self.ccSHANumberDigestLength;
226
- uint8_t* hashBytes = malloc(hashBytesSize);
227
-
228
- // ([plainData bytes], (CC_LONG)[plainData length], hashBytes)
229
- unsigned char *str = [self CC_SHANumberWithData:[plainData bytes] withLength:(CC_LONG)[plainData length] withHashBytes:hashBytes];
230
-
231
- if (!str) {
232
- return nil;
233
- }
234
-
235
- SecKeyRawSign(privateKey,
236
- self.secPaddingPKCS1SHANumber,
237
- hashBytes,
238
- hashBytesSize,
239
- signedHashBytes,
240
- &signedHashBytesSize);
241
-
242
- NSData* signedHash = [NSData dataWithBytes:signedHashBytes
243
- length:(NSUInteger)signedHashBytesSize];
244
-
245
- if (hashBytes) {
246
- free(hashBytes);
247
- }
248
-
249
- if (signedHashBytes) {
250
- free(signedHashBytes);
251
- }
252
-
253
- return signedHash;
254
- }
255
- @end
256
- #endif
257
-
258
- #if TARGET_OS_MAC && !TARGET_OS_IPHONE
259
- @interface JWTAlgorithmRSBaseMac : JWTAlgorithmRSBase
260
- @end
261
-
262
- @implementation JWTAlgorithmRSBaseMac
263
- - (NSData *)executeTransform:(SecTransformRef)transform withInput:(NSData *)input withDigestType:(CFStringRef)type withDigestLength:(NSNumber *)length withFalseResult:(CFTypeRef)falseResultRef {
264
- CFErrorRef errorRef = NULL;
265
-
266
- CFTypeRef resultRef = NULL;
267
- NSData *resultData = nil;
268
-
269
-
270
- BOOL success = transform != NULL;
271
- //TODO: after import algorithm by pem, this code seems not working well.
272
- //error: Error Domain=com.apple.security.transforms.error Code=6 "Invalid digest algorithm for RSA signature, choose one of: SHA1, SHA2 (512bits, 348bits, 256bits, or 224 bits), MD2, or MD5"
273
- //TODO: add error inout parameter to this method.
274
- if (success) {
275
- // setup digest type
276
- success = SecTransformSetAttribute(transform, kSecDigestTypeAttribute, type, &errorRef);
277
- }
278
-
279
- if (success) {
280
- // digest length
281
- success = SecTransformSetAttribute(transform, kSecDigestLengthAttribute, (__bridge CFNumberRef)length, &errorRef);
282
- }
283
-
284
- if (success) {
285
- // set input
286
- success = SecTransformSetAttribute(transform, kSecTransformInputAttributeName, (__bridge CFDataRef)input, &errorRef);
287
- }
288
-
289
- if (success) {
290
- // execute
291
- resultRef = SecTransformExecute(transform, &errorRef);
292
- success = (resultRef != falseResultRef);
293
- }
294
-
295
- BOOL positiveResult = success; // resultRef != falseResultRef
296
-
297
- // error
298
- if (errorRef != NULL) {
299
- NSLog(@"%@ error: %@", self.debugDescription, (__bridge NSError *)errorRef);
300
- }
301
- else {
302
- if (positiveResult) {
303
- resultData = (__bridge NSData *)resultRef;
304
- }
305
- }
306
-
307
- // release
308
- if (transform != NULL) {
309
- CFRelease(transform);
310
- }
311
-
312
- if (errorRef != NULL) {
313
- CFRelease(errorRef);
314
- }
315
-
316
- if (resultRef != NULL) {
317
- CFRelease(resultRef);
318
- }
319
-
320
- return resultData;
321
- }
322
- - (BOOL)verifyData:(NSData *)plainData witSignature:(NSData *)signature withKey:(SecKeyRef) publicKey {
323
-
324
- size_t signedHashBytesSize = SecKeyGetBlockSize(publicKey);
325
- //const void* signedHashBytes = [signature bytes];
326
-
327
- size_t hashBytesSize = self.ccSHANumberDigestLength;
328
- uint8_t* hashBytes = malloc(hashBytesSize);
329
- if (![self CC_SHANumberWithData:[plainData bytes] withLength:(CC_LONG)[plainData length] withHashBytes:hashBytes]) {
330
- return false;
331
- }
332
-
333
- // verify for iOS
334
- // OSStatus status = SecKeyRawVerify(publicKey,
335
- // self.secPaddingPKCS1SHANumber,
336
- // hashBytes,
337
- // hashBytesSize,
338
- // signedHashBytes,
339
- // signedHashBytesSize);
340
- // return status == errSecSuccess;
341
-
342
- CFErrorRef errorRef = NULL;
343
- SecTransformRef transform = SecVerifyTransformCreate(publicKey, (__bridge CFDataRef)signature, &errorRef);
344
-
345
- // verification. false result is kCFBooleanFalse
346
- BOOL result = [self executeTransform:transform withInput:plainData withDigestType:kSecDigestSHA2 withDigestLength:@(signedHashBytesSize) withFalseResult:kCFBooleanFalse] != nil;
347
-
348
- if (errorRef != NULL) {
349
- CFRelease(errorRef);
350
- }
351
-
352
- return result;
353
- }
354
-
355
- - (NSData *)signData:(NSData *)plainData withKey:(SecKeyRef)privateKey {
356
- size_t signedHashBytesSize = SecKeyGetBlockSize(privateKey);
357
- //uint8_t* signedHashBytes = malloc(signedHashBytesSize);
358
- //memset(signedHashBytes, 0x0, signedHashBytesSize);
359
-
360
- size_t hashBytesSize = self.ccSHANumberDigestLength;
361
- uint8_t* hashBytes = malloc(hashBytesSize);
362
-
363
- /**
364
- for sha256
365
- CC_SHANumberWithData() is CC_SHA256()
366
- self.secPaddingPKCS1SHANumber = kSecPaddingPKCS1SHA256
367
- self.ccSHANumberDigestLength = CC_SHA256_DIGEST_LENGTH
368
- */
369
- unsigned char *str = [self CC_SHANumberWithData:[plainData bytes] withLength:(CC_LONG)[plainData length] withHashBytes:hashBytes];
370
-
371
- if (!str) {
372
- return nil;
373
- }
374
-
375
- CFErrorRef errorRef = NULL;
376
-
377
- SecTransformRef transform = SecSignTransformCreate(privateKey, &errorRef);
378
-
379
- /** iOS
380
- SecKeyRawSign(privateKey,
381
- self.secPaddingPKCS1SHANumber,
382
- hashBytes,
383
- hashBytesSize,
384
- signedHashBytes,
385
- &signedHashBytesSize);
386
-
387
- NSData* signedHash = [NSData dataWithBytes:signedHashBytes
388
- length:(NSUInteger)signedHashBytesSize];
389
-
390
- */
391
-
392
- NSData *resultData = nil;
393
- // signing: false result is NULL.
394
- // it will release error.
395
- resultData = [self executeTransform:transform withInput:plainData withDigestType:kSecDigestSHA2 withDigestLength:@(signedHashBytesSize) withFalseResult:NULL];
396
-
397
- if (errorRef != NULL) {
398
- CFRelease(errorRef);
399
- }
400
-
401
- return resultData;
402
- }
403
- @end
404
- #endif
405
-
406
-
407
- // MacOS OR iOS is Base
408
- #if TARGET_OS_MAC && !TARGET_OS_IPHONE
409
- @interface JWTAlgorithmRSFamilyMember : JWTAlgorithmRSBaseMac @end
410
- #else
411
- @interface JWTAlgorithmRSFamilyMember : JWTAlgorithmRSBaseIOS @end
412
- #endif
413
-
414
- @interface JWTAlgorithmRS256 : JWTAlgorithmRSFamilyMember @end
415
- @interface JWTAlgorithmRS384 : JWTAlgorithmRSFamilyMember @end
416
- @interface JWTAlgorithmRS512 : JWTAlgorithmRSFamilyMember @end
417
-
418
- @implementation JWTAlgorithmRSFamilyMember
419
- - (uint32_t)secPaddingPKCS1SHANumber {
420
- return 0;
421
- }
422
- @end
423
-
424
- @implementation JWTAlgorithmRS256
425
-
426
- - (size_t)ccSHANumberDigestLength {
427
- return CC_SHA256_DIGEST_LENGTH;
428
- }
429
-
430
- #if TARGET_OS_MAC && TARGET_OS_IPHONE
431
- - (uint32_t)secPaddingPKCS1SHANumber {
432
- return kSecPaddingPKCS1SHA256;
433
- }
434
- #endif
435
-
436
- - (unsigned char *)CC_SHANumberWithData:(const void *)data withLength:(CC_LONG)len withHashBytes:(unsigned char *)hashBytes {
437
- return CC_SHA256(data, len, hashBytes);
438
- }
439
-
440
- - (NSString *)name {
441
- return JWTAlgorithmNameRS256;
442
- }
443
-
444
- @end
445
-
446
- @implementation JWTAlgorithmRS384
447
-
448
- - (size_t)ccSHANumberDigestLength {
449
- return CC_SHA384_DIGEST_LENGTH;
450
- }
451
-
452
- #if TARGET_OS_MAC && TARGET_OS_IPHONE
453
- - (uint32_t)secPaddingPKCS1SHANumber {
454
- return kSecPaddingPKCS1SHA384;
455
- }
456
- #endif
457
-
458
- - (unsigned char *)CC_SHANumberWithData:(const void *)data withLength:(CC_LONG)len withHashBytes:(unsigned char *)hashBytes {
459
- return CC_SHA384(data, len, hashBytes);
460
- }
461
-
462
- - (NSString *)name {
463
- return JWTAlgorithmNameRS384;
464
- }
465
-
466
- @end
467
-
468
- @implementation JWTAlgorithmRS512
469
-
470
- - (size_t)ccSHANumberDigestLength {
471
- return CC_SHA512_DIGEST_LENGTH;
472
- }
473
-
474
- #if TARGET_OS_MAC && TARGET_OS_IPHONE
475
- - (uint32_t)secPaddingPKCS1SHANumber {
476
- return kSecPaddingPKCS1SHA512;
477
- }
478
- #endif
479
-
480
- - (unsigned char *)CC_SHANumberWithData:(const void *)data withLength:(CC_LONG)len withHashBytes:(unsigned char *)hashBytes {
481
- return CC_SHA512(data, len, hashBytes);
482
- }
483
-
484
- - (NSString *)name {
485
- return JWTAlgorithmNameRS512;
486
- }
487
-
488
- @end
489
-
490
-
491
- @interface JWTAlgorithmRSFamilyMemberMutable : JWTAlgorithmRSFamilyMember
492
-
493
- @property (assign, nonatomic, readwrite) size_t ccSHANumberDigestLength;
494
- @property (assign, nonatomic, readwrite) uint32_t secPaddingPKCS1SHANumber;
495
- @property (copy, nonatomic, readwrite) unsigned char * (^ccShaNumberWithData)(const void *data, CC_LONG len, unsigned char *hashBytes);
496
- @property (copy, nonatomic, readwrite) NSString *name;
497
- @end
498
-
499
- @implementation JWTAlgorithmRSFamilyMemberMutable
500
-
501
- @synthesize ccSHANumberDigestLength = _ccSHANumberDigestLength;
502
- @synthesize secPaddingPKCS1SHANumber = _secPaddingPKCS1SHANumber;
503
- @synthesize name = _name;
504
-
505
- - (size_t)ccSHANumberDigestLength {
506
- return _ccSHANumberDigestLength;
507
- }
508
-
509
- - (uint32_t)secPaddingPKCS1SHANumber {
510
- return _secPaddingPKCS1SHANumber;
511
- }
512
-
513
- - (unsigned char *)CC_SHANumberWithData:(const void *)data withLength:(uint32_t)len withHashBytes:(unsigned char *)hashBytes {
514
- unsigned char *result = [super CC_SHANumberWithData:data withLength:len withHashBytes:hashBytes];
515
- if (!result && self.ccShaNumberWithData) {
516
- result = self.ccShaNumberWithData(data, len, hashBytes);
517
- }
518
- return result;
519
- }
520
-
521
- @end
522
-
523
-
524
- @implementation JWTAlgorithmRSBase (Create)
525
-
526
- + (instancetype)algorithm256 {
527
- return [JWTAlgorithmRS256 new];
528
- }
529
-
530
- + (instancetype)algorithm384 {
531
- return [JWTAlgorithmRS384 new];
532
- }
533
-
534
- + (instancetype)algorithm512 {
535
- return [JWTAlgorithmRS512 new];
536
- }
537
-
538
- + (instancetype)mutableAlgorithm {
539
- JWTAlgorithmRSFamilyMemberMutable *base = [JWTAlgorithmRSFamilyMemberMutable new];
540
- base.ccSHANumberDigestLength = CC_SHA256_DIGEST_LENGTH;
541
-
542
- //set to something ok
543
- //base.secPaddingPKCS1SHANumber = kSecPaddingPKCS1SHA256;
544
- base.ccShaNumberWithData = ^unsigned char *(const void *data, CC_LONG len, unsigned char *hashBytes){
545
- return CC_SHA256(data, len, hashBytes);
546
- };
547
- base.name = @"RS256";
548
- return base;
549
- }
550
-
551
- @end
@@ -1,23 +0,0 @@
1
- //
2
- // Created by Marcelo Schroeder on 12/03/2016.
3
- // Copyright (c) 2016 Karma. All rights reserved.
4
- //
5
-
6
- #import <Foundation/Foundation.h>
7
- #import "JWTAlgorithm.h"
8
- @protocol JWTCryptoKeyProtocol;
9
-
10
- @protocol JWTAsymmetricKeysAlgorithm <JWTAlgorithm>
11
-
12
- @optional
13
- @property(nonatomic, readwrite, copy) NSString *keyExtractorType;
14
- @property(nonatomic, readwrite, strong) id<JWTCryptoKeyProtocol> signKey;
15
- @property(nonatomic, readwrite, strong) id<JWTCryptoKeyProtocol> verifyKey;
16
-
17
- @end
18
-
19
- @protocol JWTRSAlgorithm <JWTAsymmetricKeysAlgorithm, NSCopying>
20
-
21
- @required
22
- @property(nonatomic, readwrite, copy) NSString *privateKeyCertificatePassphrase;
23
- @end
@@ -1,43 +0,0 @@
1
- //
2
- // JWTCryptoKey.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 <NSObject>
13
- @property (copy, nonatomic, readonly) NSString *tag;
14
- @property (assign, nonatomic, readonly) SecKeyRef key;
15
- @property (copy, nonatomic, readonly) NSData *rawKey;
16
- @end
17
-
18
- @interface JWTCryptoKeyBuilder : NSObject
19
- @property (assign, nonatomic, readonly) NSString *keyType;
20
- - (instancetype)keyTypeRSA;
21
- - (instancetype)keyTypeEC;
22
- @end
23
-
24
- @interface JWTCryptoKey : NSObject<JWTCryptoKeyProtocol>
25
- - (instancetype)initWithData:(NSData *)data parameters:(NSDictionary *)parameters error:(NSError *__autoreleasing*)error; //NS_DESIGNATED_INITIALIZER
26
- - (instancetype)initWithBase64String:(NSString *)base64String parameters:(NSDictionary *)parameters error:(NSError *__autoreleasing*)error;
27
- - (instancetype)initWithPemEncoded:(NSString *)encoded parameters:(NSDictionary *)parameters error:(NSError *__autoreleasing*)error;
28
- - (instancetype)initWithPemAtURL:(NSURL *)url parameters:(NSDictionary *)parameters error:(NSError *__autoreleasing*)error;
29
- @end
30
-
31
- @interface JWTCryptoKey (Parameters)
32
- + (NSString *)parametersKeyBuilder;
33
- @end
34
-
35
- @interface JWTCryptoKeyPublic : JWTCryptoKey
36
- - (instancetype)initWithCertificateData:(NSData *)certificateData parameters:(NSDictionary *)parameters error:(NSError *__autoreleasing*)error; //NS_DESIGNATED_INITIALIZER;
37
- - (instancetype)initWithCertificateBase64String:(NSString *)certificateString parameters:(NSDictionary *)parameters error:(NSError *__autoreleasing*)error;
38
- @end
39
-
40
- @interface JWTCryptoKeyPrivate : JWTCryptoKey
41
- - (instancetype)initWithP12Data:(NSData *)p12Data withPassphrase:(NSString *)passphrase parameters:(NSDictionary *)parameters error:(NSError *__autoreleasing*)error; //NS_DESIGNATED_INITIALIZER;
42
- - (instancetype)initWithP12AtURL:(NSURL *)url withPassphrase:(NSString *)passphrase parameters:(NSDictionary *)parameters error:(NSError *__autoreleasing*)error;
43
- @end