@appzung/react-native-code-push 8.3.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/CodePush.podspec +3 -3
  3. package/LICENSE.md +1 -1
  4. package/README.md +159 -296
  5. package/android/app/.gradle/config.properties +2 -0
  6. package/android/app/build.gradle +2 -0
  7. package/android/app/local.properties +8 -0
  8. package/android/app/src/main/AndroidManifest.xml +1 -2
  9. package/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java +27 -21
  10. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushBuilder.java +5 -5
  11. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushConstants.java +1 -1
  12. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushDialog.java +1 -1
  13. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushInstallMode.java +2 -2
  14. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushInvalidPublicKeyException.java +2 -2
  15. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushInvalidUpdateException.java +1 -1
  16. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushMalformedDataException.java +2 -2
  17. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java +5 -5
  18. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushNotInitializedException.java +2 -2
  19. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushTelemetryManager.java +14 -14
  20. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUnknownException.java +2 -2
  21. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUpdateManager.java +1 -1
  22. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUpdateState.java +2 -2
  23. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUpdateUtils.java +16 -9
  24. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUtils.java +1 -1
  25. package/android/app/src/main/java/com/microsoft/codepush/react/DownloadProgress.java +1 -1
  26. package/android/app/src/main/java/com/microsoft/codepush/react/DownloadProgressCallback.java +1 -1
  27. package/android/app/src/main/java/com/microsoft/codepush/react/FileUtils.java +1 -1
  28. package/android/app/src/main/java/com/microsoft/codepush/react/ReactInstanceHolder.java +1 -1
  29. package/android/app/src/main/java/com/microsoft/codepush/react/SettingsManager.java +1 -1
  30. package/android/app/src/main/java/com/microsoft/codepush/react/TLSSocketFactory.java +1 -1
  31. package/android/build.gradle +3 -0
  32. package/android/codepush.gradle +3 -3
  33. package/docs/advanced-usage.md +56 -0
  34. package/docs/api-android.md +12 -75
  35. package/docs/api-ios.md +5 -17
  36. package/docs/api-js.md +18 -55
  37. package/docs/setup-android.md +15 -397
  38. package/docs/setup-ios.md +24 -198
  39. package/docs/setup-windows.md +7 -74
  40. package/ios/CodePush/CodePush.h +4 -4
  41. package/ios/CodePush/CodePush.m +10 -9
  42. package/ios/CodePush/CodePushConfig.m +14 -11
  43. package/ios/CodePush/CodePushPackage.m +60 -60
  44. package/ios/CodePush/CodePushTelemetryManager.m +13 -13
  45. package/ios/CodePush.xcodeproj/project.pbxproj +24 -470
  46. package/ios/PrivacyInfo.xcprivacy +31 -0
  47. package/package.json +27 -24
  48. package/react-native.config.js +1 -1
  49. package/scripts/generateBundledResourcesHash.js +1 -1
  50. package/scripts/getFilesInFolder.js +1 -1
  51. package/scripts/recordFilesBeforeBundleCommand.js +1 -1
  52. package/typings/react-native-code-push.d.ts +22 -22
  53. package/windows/CodePush/CodePushConfig.cpp +3 -3
  54. package/windows/CodePush/CodePushConfig.h +3 -3
  55. package/windows/CodePush/CodePushNativeModule.cpp +27 -27
  56. package/windows/CodePush/CodePushNativeModule.h +4 -4
  57. package/windows/CodePush/CodePushTelemetryManager.cpp +12 -12
  58. package/windows/CodePush/CodePushTelemetryManager.h +1 -1
  59. package/.azurepipelines/build-rn-code-push-1es.yml +0 -104
  60. package/.azurepipelines/test-rn-code-push.yml +0 -94
  61. package/.config/CredScanSuppressions.json +0 -14
  62. package/SECURITY.md +0 -41
  63. package/docs/multi-deployment-testing-android.md +0 -148
  64. package/docs/multi-deployment-testing-ios.md +0 -59
  65. package/ios/CodePush/Base64/Base64/MF_Base64Additions.h +0 -34
  66. package/ios/CodePush/Base64/Base64/MF_Base64Additions.m +0 -252
  67. package/ios/CodePush/Base64/README.md +0 -47
  68. package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithm.h +0 -69
  69. package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithmFactory.h +0 -16
  70. package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithmFactory.m +0 -51
  71. package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithmNone.h +0 -15
  72. package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithmNone.m +0 -55
  73. package/ios/CodePush/JWT/Core/Algorithms/ESFamily/JWTAlgorithmESBase.h +0 -24
  74. package/ios/CodePush/JWT/Core/Algorithms/ESFamily/JWTAlgorithmESBase.m +0 -41
  75. package/ios/CodePush/JWT/Core/Algorithms/HSFamily/JWTAlgorithmHSBase.h +0 -28
  76. package/ios/CodePush/JWT/Core/Algorithms/HSFamily/JWTAlgorithmHSBase.m +0 -205
  77. package/ios/CodePush/JWT/Core/Algorithms/Holders/JWTAlgorithmDataHolder.h +0 -103
  78. package/ios/CodePush/JWT/Core/Algorithms/Holders/JWTAlgorithmDataHolder.m +0 -322
  79. package/ios/CodePush/JWT/Core/Algorithms/Holders/JWTAlgorithmDataHolderChain.h +0 -37
  80. package/ios/CodePush/JWT/Core/Algorithms/Holders/JWTAlgorithmDataHolderChain.m +0 -145
  81. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/JWTAlgorithmRSBase.h +0 -35
  82. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/JWTAlgorithmRSBase.m +0 -551
  83. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/JWTRSAlgorithm.h +0 -23
  84. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoKey.h +0 -43
  85. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoKey.m +0 -230
  86. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoKeyExtractor.h +0 -31
  87. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoKeyExtractor.m +0 -113
  88. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoSecurity.h +0 -38
  89. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoSecurity.m +0 -500
  90. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaim.h +0 -18
  91. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaim.m +0 -214
  92. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSet.h +0 -23
  93. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSet.m +0 -29
  94. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSetSerializer.h +0 -19
  95. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSetSerializer.m +0 -68
  96. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSetVerifier.h +0 -18
  97. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSetVerifier.m +0 -72
  98. package/ios/CodePush/JWT/Core/Coding/JWTCoding+ResultTypes.h +0 -67
  99. package/ios/CodePush/JWT/Core/Coding/JWTCoding+ResultTypes.m +0 -111
  100. package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionOne.h +0 -119
  101. package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionOne.m +0 -307
  102. package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionThree.h +0 -94
  103. package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionThree.m +0 -619
  104. package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionTwo.h +0 -164
  105. package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionTwo.m +0 -514
  106. package/ios/CodePush/JWT/Core/Coding/JWTCoding.h +0 -24
  107. package/ios/CodePush/JWT/Core/Coding/JWTCoding.m +0 -11
  108. package/ios/CodePush/JWT/Core/FrameworkSupplement/JWT.h +0 -52
  109. package/ios/CodePush/JWT/Core/FrameworkSupplement/Map.modulemap +0 -5
  110. package/ios/CodePush/JWT/Core/Supplement/JWTBase64Coder.h +0 -28
  111. package/ios/CodePush/JWT/Core/Supplement/JWTBase64Coder.m +0 -70
  112. package/ios/CodePush/JWT/Core/Supplement/JWTDeprecations.h +0 -22
  113. package/ios/CodePush/JWT/Core/Supplement/JWTErrorDescription.h +0 -34
  114. package/ios/CodePush/JWT/Core/Supplement/JWTErrorDescription.m +0 -73
  115. package/ios/CodePush/JWT/LICENSE +0 -19
  116. package/ios/CodePush/JWT/README.md +0 -489
  117. package/ios/CodePush/SSZipArchive/Common.h +0 -81
  118. package/ios/CodePush/SSZipArchive/README.md +0 -1
  119. package/ios/CodePush/SSZipArchive/SSZipArchive.h +0 -76
  120. package/ios/CodePush/SSZipArchive/SSZipArchive.m +0 -691
  121. package/ios/CodePush/SSZipArchive/aes/aes.h +0 -198
  122. package/ios/CodePush/SSZipArchive/aes/aes_via_ace.h +0 -541
  123. package/ios/CodePush/SSZipArchive/aes/aescrypt.c +0 -294
  124. package/ios/CodePush/SSZipArchive/aes/aeskey.c +0 -548
  125. package/ios/CodePush/SSZipArchive/aes/aesopt.h +0 -739
  126. package/ios/CodePush/SSZipArchive/aes/aestab.c +0 -391
  127. package/ios/CodePush/SSZipArchive/aes/aestab.h +0 -173
  128. package/ios/CodePush/SSZipArchive/aes/brg_endian.h +0 -126
  129. package/ios/CodePush/SSZipArchive/aes/brg_types.h +0 -219
  130. package/ios/CodePush/SSZipArchive/aes/entropy.c +0 -54
  131. package/ios/CodePush/SSZipArchive/aes/entropy.h +0 -16
  132. package/ios/CodePush/SSZipArchive/aes/fileenc.c +0 -144
  133. package/ios/CodePush/SSZipArchive/aes/fileenc.h +0 -121
  134. package/ios/CodePush/SSZipArchive/aes/hmac.c +0 -145
  135. package/ios/CodePush/SSZipArchive/aes/hmac.h +0 -103
  136. package/ios/CodePush/SSZipArchive/aes/prng.c +0 -155
  137. package/ios/CodePush/SSZipArchive/aes/prng.h +0 -82
  138. package/ios/CodePush/SSZipArchive/aes/pwd2key.c +0 -103
  139. package/ios/CodePush/SSZipArchive/aes/pwd2key.h +0 -57
  140. package/ios/CodePush/SSZipArchive/aes/sha1.c +0 -258
  141. package/ios/CodePush/SSZipArchive/aes/sha1.h +0 -73
  142. package/ios/CodePush/SSZipArchive/minizip/crypt.h +0 -130
  143. package/ios/CodePush/SSZipArchive/minizip/ioapi.c +0 -369
  144. package/ios/CodePush/SSZipArchive/minizip/ioapi.h +0 -175
  145. package/ios/CodePush/SSZipArchive/minizip/mztools.c +0 -284
  146. package/ios/CodePush/SSZipArchive/minizip/mztools.h +0 -31
  147. package/ios/CodePush/SSZipArchive/minizip/unzip.c +0 -1839
  148. package/ios/CodePush/SSZipArchive/minizip/unzip.h +0 -248
  149. package/ios/CodePush/SSZipArchive/minizip/zip.c +0 -1910
  150. package/ios/CodePush/SSZipArchive/minizip/zip.h +0 -202
  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