@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.
- package/CodePush.js +22 -19
- package/LICENSE.md +1 -1
- package/README.md +159 -298
- package/android/app/.gradle/config.properties +2 -0
- package/android/app/build.gradle +1 -1
- package/android/app/local.properties +8 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java +27 -21
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushBuilder.java +5 -5
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushConstants.java +1 -1
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushDialog.java +1 -1
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushInstallMode.java +2 -2
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushInvalidPublicKeyException.java +2 -2
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushInvalidUpdateException.java +1 -1
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushMalformedDataException.java +2 -2
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java +5 -5
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushNotInitializedException.java +2 -2
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushTelemetryManager.java +14 -14
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUnknownException.java +2 -2
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUpdateManager.java +1 -1
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUpdateState.java +2 -2
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUpdateUtils.java +1 -1
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUtils.java +1 -1
- package/android/app/src/main/java/com/microsoft/codepush/react/DownloadProgress.java +1 -1
- package/android/app/src/main/java/com/microsoft/codepush/react/DownloadProgressCallback.java +1 -1
- package/android/app/src/main/java/com/microsoft/codepush/react/FileUtils.java +1 -1
- package/android/app/src/main/java/com/microsoft/codepush/react/ReactInstanceHolder.java +1 -1
- package/android/app/src/main/java/com/microsoft/codepush/react/SettingsManager.java +1 -1
- package/android/app/src/main/java/com/microsoft/codepush/react/TLSSocketFactory.java +1 -1
- package/android/build.gradle +1 -1
- package/android/codepush.gradle +3 -3
- package/docs/advanced-usage.md +56 -0
- package/docs/api-android.md +12 -75
- package/docs/api-ios.md +5 -17
- package/docs/api-js.md +18 -55
- package/docs/setup-android.md +15 -397
- package/docs/setup-ios.md +24 -198
- package/docs/setup-windows.md +7 -74
- package/ios/CodePush/CodePush.h +4 -4
- package/ios/CodePush/CodePush.m +8 -8
- package/ios/CodePush/CodePushConfig.m +14 -11
- package/ios/CodePush/CodePushPackage.m +60 -60
- package/ios/CodePush/CodePushTelemetryManager.m +13 -13
- package/ios/CodePush.xcodeproj/project.pbxproj +1 -562
- package/package.json +27 -24
- package/react-native.config.js +1 -1
- package/scripts/generateBundledResourcesHash.js +1 -1
- package/scripts/getFilesInFolder.js +1 -1
- package/scripts/recordFilesBeforeBundleCommand.js +1 -1
- package/typings/react-native-code-push.d.ts +22 -22
- package/windows/CodePush/CodePushConfig.cpp +3 -3
- package/windows/CodePush/CodePushConfig.h +3 -3
- package/windows/CodePush/CodePushNativeModule.cpp +27 -27
- package/windows/CodePush/CodePushNativeModule.h +4 -4
- package/windows/CodePush/CodePushTelemetryManager.cpp +12 -12
- package/windows/CodePush/CodePushTelemetryManager.h +1 -1
- package/.azurepipelines/build-rn-code-push-1es.yml +0 -104
- package/.azurepipelines/test-rn-code-push.yml +0 -94
- package/.config/CredScanSuppressions.json +0 -14
- package/SECURITY.md +0 -41
- package/docs/multi-deployment-testing-android.md +0 -148
- package/docs/multi-deployment-testing-ios.md +0 -59
- package/ios/CodePush/Base64/Base64/MF_Base64Additions.h +0 -34
- package/ios/CodePush/Base64/Base64/MF_Base64Additions.m +0 -252
- package/ios/CodePush/Base64/README.md +0 -47
- package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithm.h +0 -69
- package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithmFactory.h +0 -16
- package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithmFactory.m +0 -51
- package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithmNone.h +0 -15
- package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithmNone.m +0 -55
- package/ios/CodePush/JWT/Core/Algorithms/ESFamily/JWTAlgorithmESBase.h +0 -24
- package/ios/CodePush/JWT/Core/Algorithms/ESFamily/JWTAlgorithmESBase.m +0 -41
- package/ios/CodePush/JWT/Core/Algorithms/HSFamily/JWTAlgorithmHSBase.h +0 -28
- package/ios/CodePush/JWT/Core/Algorithms/HSFamily/JWTAlgorithmHSBase.m +0 -205
- package/ios/CodePush/JWT/Core/Algorithms/Holders/JWTAlgorithmDataHolder.h +0 -103
- package/ios/CodePush/JWT/Core/Algorithms/Holders/JWTAlgorithmDataHolder.m +0 -322
- package/ios/CodePush/JWT/Core/Algorithms/Holders/JWTAlgorithmDataHolderChain.h +0 -37
- package/ios/CodePush/JWT/Core/Algorithms/Holders/JWTAlgorithmDataHolderChain.m +0 -145
- package/ios/CodePush/JWT/Core/Algorithms/RSFamily/JWTAlgorithmRSBase.h +0 -35
- package/ios/CodePush/JWT/Core/Algorithms/RSFamily/JWTAlgorithmRSBase.m +0 -551
- package/ios/CodePush/JWT/Core/Algorithms/RSFamily/JWTRSAlgorithm.h +0 -23
- package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoKey.h +0 -43
- package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoKey.m +0 -230
- package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoKeyExtractor.h +0 -31
- package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoKeyExtractor.m +0 -113
- package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoSecurity.h +0 -38
- package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoSecurity.m +0 -500
- package/ios/CodePush/JWT/Core/ClaimSet/JWTClaim.h +0 -18
- package/ios/CodePush/JWT/Core/ClaimSet/JWTClaim.m +0 -214
- package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSet.h +0 -23
- package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSet.m +0 -29
- package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSetSerializer.h +0 -19
- package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSetSerializer.m +0 -68
- package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSetVerifier.h +0 -18
- package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSetVerifier.m +0 -72
- package/ios/CodePush/JWT/Core/Coding/JWTCoding+ResultTypes.h +0 -67
- package/ios/CodePush/JWT/Core/Coding/JWTCoding+ResultTypes.m +0 -111
- package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionOne.h +0 -119
- package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionOne.m +0 -307
- package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionThree.h +0 -94
- package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionThree.m +0 -619
- package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionTwo.h +0 -164
- package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionTwo.m +0 -514
- package/ios/CodePush/JWT/Core/Coding/JWTCoding.h +0 -24
- package/ios/CodePush/JWT/Core/Coding/JWTCoding.m +0 -11
- package/ios/CodePush/JWT/Core/FrameworkSupplement/JWT.h +0 -52
- package/ios/CodePush/JWT/Core/FrameworkSupplement/Map.modulemap +0 -5
- package/ios/CodePush/JWT/Core/Supplement/JWTBase64Coder.h +0 -28
- package/ios/CodePush/JWT/Core/Supplement/JWTBase64Coder.m +0 -70
- package/ios/CodePush/JWT/Core/Supplement/JWTDeprecations.h +0 -22
- package/ios/CodePush/JWT/Core/Supplement/JWTErrorDescription.h +0 -34
- package/ios/CodePush/JWT/Core/Supplement/JWTErrorDescription.m +0 -73
- package/ios/CodePush/JWT/LICENSE +0 -19
- package/ios/CodePush/JWT/README.md +0 -489
- package/ios/CodePush/SSZipArchive/Info.plist +0 -26
- package/ios/CodePush/SSZipArchive/README.md +0 -1
- package/ios/CodePush/SSZipArchive/SSZipArchive.h +0 -178
- package/ios/CodePush/SSZipArchive/SSZipArchive.m +0 -1496
- package/ios/CodePush/SSZipArchive/SSZipCommon.h +0 -71
- package/ios/CodePush/SSZipArchive/Supporting Files/PrivacyInfo.xcprivacy +0 -23
- package/ios/CodePush/SSZipArchive/include/ZipArchive.h +0 -25
- package/ios/CodePush/SSZipArchive/minizip/LICENSE +0 -17
- package/ios/CodePush/SSZipArchive/minizip/mz.h +0 -273
- package/ios/CodePush/SSZipArchive/minizip/mz_compat.c +0 -1306
- package/ios/CodePush/SSZipArchive/minizip/mz_compat.h +0 -346
- package/ios/CodePush/SSZipArchive/minizip/mz_crypt.c +0 -187
- package/ios/CodePush/SSZipArchive/minizip/mz_crypt.h +0 -65
- package/ios/CodePush/SSZipArchive/minizip/mz_crypt_apple.c +0 -526
- package/ios/CodePush/SSZipArchive/minizip/mz_os.c +0 -348
- package/ios/CodePush/SSZipArchive/minizip/mz_os.h +0 -176
- package/ios/CodePush/SSZipArchive/minizip/mz_os_posix.c +0 -350
- package/ios/CodePush/SSZipArchive/minizip/mz_strm.c +0 -556
- package/ios/CodePush/SSZipArchive/minizip/mz_strm.h +0 -132
- package/ios/CodePush/SSZipArchive/minizip/mz_strm_buf.c +0 -383
- package/ios/CodePush/SSZipArchive/minizip/mz_strm_buf.h +0 -42
- package/ios/CodePush/SSZipArchive/minizip/mz_strm_mem.c +0 -269
- package/ios/CodePush/SSZipArchive/minizip/mz_strm_mem.h +0 -48
- package/ios/CodePush/SSZipArchive/minizip/mz_strm_os.h +0 -40
- package/ios/CodePush/SSZipArchive/minizip/mz_strm_os_posix.c +0 -203
- package/ios/CodePush/SSZipArchive/minizip/mz_strm_pkcrypt.c +0 -334
- package/ios/CodePush/SSZipArchive/minizip/mz_strm_pkcrypt.h +0 -46
- package/ios/CodePush/SSZipArchive/minizip/mz_strm_split.c +0 -429
- package/ios/CodePush/SSZipArchive/minizip/mz_strm_split.h +0 -43
- package/ios/CodePush/SSZipArchive/minizip/mz_strm_wzaes.c +0 -360
- package/ios/CodePush/SSZipArchive/minizip/mz_strm_wzaes.h +0 -46
- package/ios/CodePush/SSZipArchive/minizip/mz_strm_zlib.c +0 -389
- package/ios/CodePush/SSZipArchive/minizip/mz_strm_zlib.h +0 -43
- package/ios/CodePush/SSZipArchive/minizip/mz_zip.c +0 -2782
- package/ios/CodePush/SSZipArchive/minizip/mz_zip.h +0 -262
- package/ios/CodePush/SSZipArchive/minizip/mz_zip_rw.c +0 -1942
- package/ios/CodePush/SSZipArchive/minizip/mz_zip_rw.h +0 -285
- package/scripts/postlink/android/postlink.js +0 -87
- package/scripts/postlink/ios/postlink.js +0 -116
- package/scripts/postlink/run.js +0 -11
- package/scripts/postunlink/android/postunlink.js +0 -74
- package/scripts/postunlink/ios/postunlink.js +0 -87
- package/scripts/postunlink/run.js +0 -11
- package/scripts/tools/linkToolsAndroid.js +0 -57
- package/scripts/tools/linkToolsIos.js +0 -130
- package/windows-legacy/CodePush/CodePush.csproj +0 -128
- package/windows-legacy/CodePush/CodePushUtils.cs +0 -47
- package/windows-legacy/CodePush/FileUtils.cs +0 -40
- package/windows-legacy/CodePush/Properties/AssemblyInfo.cs +0 -29
- package/windows-legacy/CodePush/Properties/CodePush.rd.xml +0 -33
- package/windows-legacy/CodePush/UpdateManager.cs +0 -305
- package/windows-legacy/CodePush/UpdateUtils.cs +0 -46
- package/windows-legacy/CodePush.Net46/Adapters/Http/HttpProgress.cs +0 -28
- package/windows-legacy/CodePush.Net46/Adapters/Storage/ApplicationDataContainer.cs +0 -106
- package/windows-legacy/CodePush.Net46/CodePush.Net46.csproj +0 -103
- package/windows-legacy/CodePush.Net46/CodePushUtils.cs +0 -158
- package/windows-legacy/CodePush.Net46/FileUtils.cs +0 -55
- package/windows-legacy/CodePush.Net46/Properties/AssemblyInfo.cs +0 -36
- package/windows-legacy/CodePush.Net46/UpdateManager.cs +0 -330
- package/windows-legacy/CodePush.Net46/UpdateUtils.cs +0 -70
- package/windows-legacy/CodePush.Net46/packages.config +0 -5
- package/windows-legacy/CodePush.Net46.Test/ApplicationDataContainerTest.cs +0 -105
- package/windows-legacy/CodePush.Net46.Test/CodePush.Net46.Test.csproj +0 -137
- package/windows-legacy/CodePush.Net46.Test/Properties/AssemblyInfo.cs +0 -36
- package/windows-legacy/CodePush.Net46.Test/TelemetryManagerTest.cs +0 -117
- package/windows-legacy/CodePush.Net46.Test/app.config +0 -11
- package/windows-legacy/CodePush.Net46.Test/packages.config +0 -4
- package/windows-legacy/CodePush.Shared/CodePush.Shared.projitems +0 -22
- package/windows-legacy/CodePush.Shared/CodePush.Shared.shproj +0 -13
- package/windows-legacy/CodePush.Shared/CodePushConstants.cs +0 -35
- package/windows-legacy/CodePush.Shared/CodePushNativeModule.cs +0 -329
- package/windows-legacy/CodePush.Shared/CodePushReactPackage.cs +0 -235
- package/windows-legacy/CodePush.Shared/CodePushUtils.cs +0 -70
- package/windows-legacy/CodePush.Shared/InstallMode.cs +0 -9
- package/windows-legacy/CodePush.Shared/MinimumBackgroundListener.cs +0 -44
- package/windows-legacy/CodePush.Shared/SettingsManager.cs +0 -148
- package/windows-legacy/CodePush.Shared/TelemetryManager.cs +0 -250
- package/windows-legacy/CodePush.Shared/UpdateState.cs +0 -9
|
@@ -1,526 +0,0 @@
|
|
|
1
|
-
/* mz_crypt_apple.c -- Crypto/hash functions for Apple
|
|
2
|
-
part of the minizip-ng project
|
|
3
|
-
|
|
4
|
-
Copyright (C) Nathan Moinvaziri
|
|
5
|
-
https://github.com/zlib-ng/minizip-ng
|
|
6
|
-
|
|
7
|
-
This program is distributed under the terms of the same license as zlib.
|
|
8
|
-
See the accompanying LICENSE file for the full text of the license.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
#include "mz.h"
|
|
12
|
-
|
|
13
|
-
#include <CoreFoundation/CoreFoundation.h>
|
|
14
|
-
#include <CommonCrypto/CommonCryptor.h>
|
|
15
|
-
#include <CommonCrypto/CommonDigest.h>
|
|
16
|
-
#include <CommonCrypto/CommonHMAC.h>
|
|
17
|
-
#include <Security/Security.h>
|
|
18
|
-
#include <Security/SecPolicy.h>
|
|
19
|
-
|
|
20
|
-
/***************************************************************************/
|
|
21
|
-
|
|
22
|
-
int32_t mz_crypt_rand(uint8_t *buf, int32_t size) {
|
|
23
|
-
if (SecRandomCopyBytes(kSecRandomDefault, size, buf) != errSecSuccess)
|
|
24
|
-
return 0;
|
|
25
|
-
return size;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/***************************************************************************/
|
|
29
|
-
|
|
30
|
-
typedef struct mz_crypt_sha_s {
|
|
31
|
-
union {
|
|
32
|
-
CC_SHA1_CTX ctx1;
|
|
33
|
-
CC_SHA256_CTX ctx256;
|
|
34
|
-
CC_SHA512_CTX ctx512;
|
|
35
|
-
};
|
|
36
|
-
int32_t error;
|
|
37
|
-
int32_t initialized;
|
|
38
|
-
uint16_t algorithm;
|
|
39
|
-
} mz_crypt_sha;
|
|
40
|
-
|
|
41
|
-
/***************************************************************************/
|
|
42
|
-
|
|
43
|
-
static const uint8_t mz_crypt_sha_digest_size[] = {
|
|
44
|
-
MZ_HASH_SHA1_SIZE, 0, MZ_HASH_SHA224_SIZE,
|
|
45
|
-
MZ_HASH_SHA256_SIZE, MZ_HASH_SHA384_SIZE, MZ_HASH_SHA512_SIZE
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
/***************************************************************************/
|
|
49
|
-
|
|
50
|
-
void mz_crypt_sha_reset(void *handle) {
|
|
51
|
-
mz_crypt_sha *sha = (mz_crypt_sha *)handle;
|
|
52
|
-
|
|
53
|
-
sha->error = 0;
|
|
54
|
-
sha->initialized = 0;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
int32_t mz_crypt_sha_begin(void *handle) {
|
|
58
|
-
mz_crypt_sha *sha = (mz_crypt_sha *)handle;
|
|
59
|
-
|
|
60
|
-
if (!sha)
|
|
61
|
-
return MZ_PARAM_ERROR;
|
|
62
|
-
|
|
63
|
-
mz_crypt_sha_reset(handle);
|
|
64
|
-
|
|
65
|
-
switch (sha->algorithm) {
|
|
66
|
-
case MZ_HASH_SHA1:
|
|
67
|
-
sha->error = CC_SHA1_Init(&sha->ctx1);
|
|
68
|
-
break;
|
|
69
|
-
case MZ_HASH_SHA224:
|
|
70
|
-
sha->error = CC_SHA224_Init(&sha->ctx256);
|
|
71
|
-
break;
|
|
72
|
-
case MZ_HASH_SHA256:
|
|
73
|
-
sha->error = CC_SHA256_Init(&sha->ctx256);
|
|
74
|
-
break;
|
|
75
|
-
case MZ_HASH_SHA384:
|
|
76
|
-
sha->error = CC_SHA384_Init(&sha->ctx512);
|
|
77
|
-
break;
|
|
78
|
-
case MZ_HASH_SHA512:
|
|
79
|
-
sha->error = CC_SHA512_Init(&sha->ctx512);
|
|
80
|
-
break;
|
|
81
|
-
default:
|
|
82
|
-
return MZ_PARAM_ERROR;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
if (!sha->error)
|
|
86
|
-
return MZ_HASH_ERROR;
|
|
87
|
-
|
|
88
|
-
sha->initialized = 1;
|
|
89
|
-
return MZ_OK;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
int32_t mz_crypt_sha_update(void *handle, const void *buf, int32_t size) {
|
|
93
|
-
mz_crypt_sha *sha = (mz_crypt_sha *)handle;
|
|
94
|
-
|
|
95
|
-
if (!sha || !buf || !sha->initialized)
|
|
96
|
-
return MZ_PARAM_ERROR;
|
|
97
|
-
|
|
98
|
-
switch (sha->algorithm) {
|
|
99
|
-
case MZ_HASH_SHA1:
|
|
100
|
-
sha->error = CC_SHA1_Update(&sha->ctx1, buf, size);
|
|
101
|
-
break;
|
|
102
|
-
case MZ_HASH_SHA224:
|
|
103
|
-
sha->error = CC_SHA224_Update(&sha->ctx256, buf, size);
|
|
104
|
-
break;
|
|
105
|
-
case MZ_HASH_SHA256:
|
|
106
|
-
sha->error = CC_SHA256_Update(&sha->ctx256, buf, size);
|
|
107
|
-
break;
|
|
108
|
-
case MZ_HASH_SHA384:
|
|
109
|
-
sha->error = CC_SHA384_Update(&sha->ctx512, buf, size);
|
|
110
|
-
break;
|
|
111
|
-
case MZ_HASH_SHA512:
|
|
112
|
-
sha->error = CC_SHA512_Update(&sha->ctx512, buf, size);
|
|
113
|
-
break;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
if (!sha->error)
|
|
117
|
-
return MZ_HASH_ERROR;
|
|
118
|
-
|
|
119
|
-
return size;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
int32_t mz_crypt_sha_end(void *handle, uint8_t *digest, int32_t digest_size) {
|
|
123
|
-
mz_crypt_sha *sha = (mz_crypt_sha *)handle;
|
|
124
|
-
|
|
125
|
-
if (!sha || !digest || !sha->initialized)
|
|
126
|
-
return MZ_PARAM_ERROR;
|
|
127
|
-
if (digest_size < mz_crypt_sha_digest_size[sha->algorithm - MZ_HASH_SHA1])
|
|
128
|
-
return MZ_PARAM_ERROR;
|
|
129
|
-
|
|
130
|
-
switch (sha->algorithm) {
|
|
131
|
-
case MZ_HASH_SHA1:
|
|
132
|
-
sha->error = CC_SHA1_Final(digest, &sha->ctx1);
|
|
133
|
-
break;
|
|
134
|
-
case MZ_HASH_SHA224:
|
|
135
|
-
sha->error = CC_SHA224_Final(digest, &sha->ctx256);
|
|
136
|
-
break;
|
|
137
|
-
case MZ_HASH_SHA256:
|
|
138
|
-
sha->error = CC_SHA256_Final(digest, &sha->ctx256);
|
|
139
|
-
break;
|
|
140
|
-
case MZ_HASH_SHA384:
|
|
141
|
-
sha->error = CC_SHA384_Final(digest, &sha->ctx512);
|
|
142
|
-
break;
|
|
143
|
-
case MZ_HASH_SHA512:
|
|
144
|
-
sha->error = CC_SHA512_Final(digest, &sha->ctx512);
|
|
145
|
-
break;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
if (!sha->error)
|
|
149
|
-
return MZ_HASH_ERROR;
|
|
150
|
-
|
|
151
|
-
return MZ_OK;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
void mz_crypt_sha_set_algorithm(void *handle, uint16_t algorithm) {
|
|
155
|
-
mz_crypt_sha *sha = (mz_crypt_sha *)handle;
|
|
156
|
-
if (MZ_HASH_SHA1 <= algorithm && algorithm <= MZ_HASH_SHA512)
|
|
157
|
-
sha->algorithm = algorithm;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
void *mz_crypt_sha_create(void **handle) {
|
|
161
|
-
mz_crypt_sha *sha = NULL;
|
|
162
|
-
|
|
163
|
-
sha = (mz_crypt_sha *)calloc(1, sizeof(mz_crypt_sha));
|
|
164
|
-
if (sha) {
|
|
165
|
-
memset(sha, 0, sizeof(mz_crypt_sha));
|
|
166
|
-
sha->algorithm = MZ_HASH_SHA256;
|
|
167
|
-
}
|
|
168
|
-
if (handle)
|
|
169
|
-
*handle = sha;
|
|
170
|
-
|
|
171
|
-
return sha;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
void mz_crypt_sha_delete(void **handle) {
|
|
175
|
-
mz_crypt_sha *sha = NULL;
|
|
176
|
-
if (!handle)
|
|
177
|
-
return;
|
|
178
|
-
sha = (mz_crypt_sha *)*handle;
|
|
179
|
-
if (sha) {
|
|
180
|
-
mz_crypt_sha_reset(*handle);
|
|
181
|
-
free(sha);
|
|
182
|
-
}
|
|
183
|
-
*handle = NULL;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
/***************************************************************************/
|
|
187
|
-
|
|
188
|
-
typedef struct mz_crypt_aes_s {
|
|
189
|
-
CCCryptorRef crypt;
|
|
190
|
-
int32_t mode;
|
|
191
|
-
int32_t error;
|
|
192
|
-
} mz_crypt_aes;
|
|
193
|
-
|
|
194
|
-
/***************************************************************************/
|
|
195
|
-
|
|
196
|
-
void mz_crypt_aes_reset(void *handle) {
|
|
197
|
-
mz_crypt_aes *aes = (mz_crypt_aes *)handle;
|
|
198
|
-
|
|
199
|
-
if (aes->crypt)
|
|
200
|
-
CCCryptorRelease(aes->crypt);
|
|
201
|
-
aes->crypt = NULL;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
int32_t mz_crypt_aes_encrypt(void *handle, uint8_t *buf, int32_t size) {
|
|
205
|
-
mz_crypt_aes *aes = (mz_crypt_aes *)handle;
|
|
206
|
-
size_t data_moved = 0;
|
|
207
|
-
|
|
208
|
-
if (!aes || !buf)
|
|
209
|
-
return MZ_PARAM_ERROR;
|
|
210
|
-
if (size != MZ_AES_BLOCK_SIZE)
|
|
211
|
-
return MZ_PARAM_ERROR;
|
|
212
|
-
|
|
213
|
-
aes->error = CCCryptorUpdate(aes->crypt, buf, size, buf, size, &data_moved);
|
|
214
|
-
|
|
215
|
-
if (aes->error != kCCSuccess)
|
|
216
|
-
return MZ_HASH_ERROR;
|
|
217
|
-
|
|
218
|
-
return size;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
int32_t mz_crypt_aes_decrypt(void *handle, uint8_t *buf, int32_t size) {
|
|
222
|
-
mz_crypt_aes *aes = (mz_crypt_aes *)handle;
|
|
223
|
-
size_t data_moved = 0;
|
|
224
|
-
|
|
225
|
-
if (!aes || !buf)
|
|
226
|
-
return MZ_PARAM_ERROR;
|
|
227
|
-
if (size != MZ_AES_BLOCK_SIZE)
|
|
228
|
-
return MZ_PARAM_ERROR;
|
|
229
|
-
|
|
230
|
-
aes->error = CCCryptorUpdate(aes->crypt, buf, size, buf, size, &data_moved);
|
|
231
|
-
|
|
232
|
-
if (aes->error != kCCSuccess)
|
|
233
|
-
return MZ_HASH_ERROR;
|
|
234
|
-
|
|
235
|
-
return size;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
int32_t mz_crypt_aes_set_encrypt_key(void *handle, const void *key, int32_t key_length) {
|
|
239
|
-
mz_crypt_aes *aes = (mz_crypt_aes *)handle;
|
|
240
|
-
|
|
241
|
-
if (!aes || !key || !key_length)
|
|
242
|
-
return MZ_PARAM_ERROR;
|
|
243
|
-
|
|
244
|
-
mz_crypt_aes_reset(handle);
|
|
245
|
-
|
|
246
|
-
aes->error = CCCryptorCreate(kCCEncrypt, kCCAlgorithmAES, kCCOptionECBMode,
|
|
247
|
-
key, key_length, NULL, &aes->crypt);
|
|
248
|
-
|
|
249
|
-
if (aes->error != kCCSuccess)
|
|
250
|
-
return MZ_HASH_ERROR;
|
|
251
|
-
|
|
252
|
-
return MZ_OK;
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
int32_t mz_crypt_aes_set_decrypt_key(void *handle, const void *key, int32_t key_length) {
|
|
256
|
-
mz_crypt_aes *aes = (mz_crypt_aes *)handle;
|
|
257
|
-
|
|
258
|
-
if (!aes || !key || !key_length)
|
|
259
|
-
return MZ_PARAM_ERROR;
|
|
260
|
-
|
|
261
|
-
mz_crypt_aes_reset(handle);
|
|
262
|
-
|
|
263
|
-
aes->error = CCCryptorCreate(kCCDecrypt, kCCAlgorithmAES, kCCOptionECBMode,
|
|
264
|
-
key, key_length, NULL, &aes->crypt);
|
|
265
|
-
|
|
266
|
-
if (aes->error != kCCSuccess)
|
|
267
|
-
return MZ_HASH_ERROR;
|
|
268
|
-
|
|
269
|
-
return MZ_OK;
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
void mz_crypt_aes_set_mode(void *handle, int32_t mode) {
|
|
273
|
-
mz_crypt_aes *aes = (mz_crypt_aes *)handle;
|
|
274
|
-
aes->mode = mode;
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
void *mz_crypt_aes_create(void **handle) {
|
|
278
|
-
mz_crypt_aes *aes = NULL;
|
|
279
|
-
|
|
280
|
-
aes = (mz_crypt_aes *)calloc(1, sizeof(mz_crypt_aes));
|
|
281
|
-
if (handle)
|
|
282
|
-
*handle = aes;
|
|
283
|
-
|
|
284
|
-
return aes;
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
void mz_crypt_aes_delete(void **handle) {
|
|
288
|
-
mz_crypt_aes *aes = NULL;
|
|
289
|
-
if (!handle)
|
|
290
|
-
return;
|
|
291
|
-
aes = (mz_crypt_aes *)*handle;
|
|
292
|
-
if (aes) {
|
|
293
|
-
mz_crypt_aes_reset(*handle);
|
|
294
|
-
free(aes);
|
|
295
|
-
}
|
|
296
|
-
*handle = NULL;
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
/***************************************************************************/
|
|
300
|
-
|
|
301
|
-
typedef struct mz_crypt_hmac_s {
|
|
302
|
-
CCHmacContext ctx;
|
|
303
|
-
int32_t initialized;
|
|
304
|
-
int32_t error;
|
|
305
|
-
uint16_t algorithm;
|
|
306
|
-
} mz_crypt_hmac;
|
|
307
|
-
|
|
308
|
-
/***************************************************************************/
|
|
309
|
-
|
|
310
|
-
static void mz_crypt_hmac_free(void *handle) {
|
|
311
|
-
mz_crypt_hmac *hmac = (mz_crypt_hmac *)handle;
|
|
312
|
-
memset(&hmac->ctx, 0, sizeof(hmac->ctx));
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
void mz_crypt_hmac_reset(void *handle) {
|
|
316
|
-
mz_crypt_hmac *hmac = (mz_crypt_hmac *)handle;
|
|
317
|
-
mz_crypt_hmac_free(handle);
|
|
318
|
-
hmac->error = 0;
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
int32_t mz_crypt_hmac_init(void *handle, const void *key, int32_t key_length) {
|
|
322
|
-
mz_crypt_hmac *hmac = (mz_crypt_hmac *)handle;
|
|
323
|
-
CCHmacAlgorithm algorithm = 0;
|
|
324
|
-
|
|
325
|
-
if (!hmac || !key)
|
|
326
|
-
return MZ_PARAM_ERROR;
|
|
327
|
-
|
|
328
|
-
mz_crypt_hmac_reset(handle);
|
|
329
|
-
|
|
330
|
-
if (hmac->algorithm == MZ_HASH_SHA1)
|
|
331
|
-
algorithm = kCCHmacAlgSHA1;
|
|
332
|
-
else if (hmac->algorithm == MZ_HASH_SHA256)
|
|
333
|
-
algorithm = kCCHmacAlgSHA256;
|
|
334
|
-
else
|
|
335
|
-
return MZ_PARAM_ERROR;
|
|
336
|
-
|
|
337
|
-
CCHmacInit(&hmac->ctx, algorithm, key, key_length);
|
|
338
|
-
return MZ_OK;
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
int32_t mz_crypt_hmac_update(void *handle, const void *buf, int32_t size) {
|
|
342
|
-
mz_crypt_hmac *hmac = (mz_crypt_hmac *)handle;
|
|
343
|
-
|
|
344
|
-
if (!hmac || !buf)
|
|
345
|
-
return MZ_PARAM_ERROR;
|
|
346
|
-
|
|
347
|
-
CCHmacUpdate(&hmac->ctx, buf, size);
|
|
348
|
-
return MZ_OK;
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
int32_t mz_crypt_hmac_end(void *handle, uint8_t *digest, int32_t digest_size) {
|
|
352
|
-
mz_crypt_hmac *hmac = (mz_crypt_hmac *)handle;
|
|
353
|
-
|
|
354
|
-
if (!hmac || !digest)
|
|
355
|
-
return MZ_PARAM_ERROR;
|
|
356
|
-
|
|
357
|
-
if (hmac->algorithm == MZ_HASH_SHA1) {
|
|
358
|
-
if (digest_size < MZ_HASH_SHA1_SIZE)
|
|
359
|
-
return MZ_BUF_ERROR;
|
|
360
|
-
CCHmacFinal(&hmac->ctx, digest);
|
|
361
|
-
} else {
|
|
362
|
-
if (digest_size < MZ_HASH_SHA256_SIZE)
|
|
363
|
-
return MZ_BUF_ERROR;
|
|
364
|
-
CCHmacFinal(&hmac->ctx, digest);
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
return MZ_OK;
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
void mz_crypt_hmac_set_algorithm(void *handle, uint16_t algorithm) {
|
|
371
|
-
mz_crypt_hmac *hmac = (mz_crypt_hmac *)handle;
|
|
372
|
-
hmac->algorithm = algorithm;
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
int32_t mz_crypt_hmac_copy(void *src_handle, void *target_handle) {
|
|
376
|
-
mz_crypt_hmac *source = (mz_crypt_hmac *)src_handle;
|
|
377
|
-
mz_crypt_hmac *target = (mz_crypt_hmac *)target_handle;
|
|
378
|
-
|
|
379
|
-
if (!source || !target)
|
|
380
|
-
return MZ_PARAM_ERROR;
|
|
381
|
-
|
|
382
|
-
memcpy(&target->ctx, &source->ctx, sizeof(CCHmacContext));
|
|
383
|
-
return MZ_OK;
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
void *mz_crypt_hmac_create(void **handle) {
|
|
387
|
-
mz_crypt_hmac *hmac = NULL;
|
|
388
|
-
|
|
389
|
-
hmac = (mz_crypt_hmac *)calloc(1, sizeof(mz_crypt_hmac));
|
|
390
|
-
if (hmac)
|
|
391
|
-
hmac->algorithm = MZ_HASH_SHA256;
|
|
392
|
-
if (handle)
|
|
393
|
-
*handle = hmac;
|
|
394
|
-
|
|
395
|
-
return hmac;
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
void mz_crypt_hmac_delete(void **handle) {
|
|
399
|
-
mz_crypt_hmac *hmac = NULL;
|
|
400
|
-
if (!handle)
|
|
401
|
-
return;
|
|
402
|
-
hmac = (mz_crypt_hmac *)*handle;
|
|
403
|
-
if (hmac) {
|
|
404
|
-
mz_crypt_hmac_free(*handle);
|
|
405
|
-
free(hmac);
|
|
406
|
-
}
|
|
407
|
-
*handle = NULL;
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
/***************************************************************************/
|
|
411
|
-
|
|
412
|
-
#if defined(MZ_ZIP_SIGNING)
|
|
413
|
-
int32_t mz_crypt_sign(uint8_t *message, int32_t message_size, uint8_t *cert_data, int32_t cert_data_size,
|
|
414
|
-
const char *cert_pwd, uint8_t **signature, int32_t *signature_size) {
|
|
415
|
-
CFStringRef password_ref = NULL;
|
|
416
|
-
CFDictionaryRef options_dict = NULL;
|
|
417
|
-
CFDictionaryRef identity_trust = NULL;
|
|
418
|
-
CFDataRef signature_out = NULL;
|
|
419
|
-
CFDataRef pkcs12_data = NULL;
|
|
420
|
-
CFArrayRef items = 0;
|
|
421
|
-
SecIdentityRef identity = NULL;
|
|
422
|
-
SecTrustRef trust = NULL;
|
|
423
|
-
OSStatus status = noErr;
|
|
424
|
-
const void *options_key[2] = {kSecImportExportPassphrase, kSecReturnRef};
|
|
425
|
-
const void *options_values[2] = {0, kCFBooleanTrue};
|
|
426
|
-
int32_t err = MZ_SIGN_ERROR;
|
|
427
|
-
|
|
428
|
-
if (!message || !cert_data || !signature || !signature_size)
|
|
429
|
-
return MZ_PARAM_ERROR;
|
|
430
|
-
|
|
431
|
-
*signature = NULL;
|
|
432
|
-
*signature_size = 0;
|
|
433
|
-
|
|
434
|
-
password_ref = CFStringCreateWithCString(0, cert_pwd, kCFStringEncodingUTF8);
|
|
435
|
-
options_values[0] = password_ref;
|
|
436
|
-
|
|
437
|
-
options_dict = CFDictionaryCreate(0, options_key, options_values, 2, 0, 0);
|
|
438
|
-
if (options_dict)
|
|
439
|
-
pkcs12_data = CFDataCreate(0, cert_data, cert_data_size);
|
|
440
|
-
if (pkcs12_data)
|
|
441
|
-
status = SecPKCS12Import(pkcs12_data, options_dict, &items);
|
|
442
|
-
if (status == noErr)
|
|
443
|
-
identity_trust = CFArrayGetValueAtIndex(items, 0);
|
|
444
|
-
if (identity_trust)
|
|
445
|
-
identity = (SecIdentityRef)CFDictionaryGetValue(identity_trust, kSecImportItemIdentity);
|
|
446
|
-
if (identity)
|
|
447
|
-
trust = (SecTrustRef)CFDictionaryGetValue(identity_trust, kSecImportItemTrust);
|
|
448
|
-
if (trust) {
|
|
449
|
-
status = CMSEncodeContent(identity, NULL, NULL, FALSE, 0, message, message_size, &signature_out);
|
|
450
|
-
|
|
451
|
-
if (status == errSecSuccess) {
|
|
452
|
-
*signature_size = CFDataGetLength(signature_out);
|
|
453
|
-
*signature = (uint8_t *)malloc(*signature_size);
|
|
454
|
-
|
|
455
|
-
memcpy(*signature, CFDataGetBytePtr(signature_out), *signature_size);
|
|
456
|
-
|
|
457
|
-
err = MZ_OK;
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
if (signature_out)
|
|
462
|
-
CFRelease(signature_out);
|
|
463
|
-
if (items)
|
|
464
|
-
CFRelease(items);
|
|
465
|
-
if (pkcs12_data)
|
|
466
|
-
CFRelease(pkcs12_data);
|
|
467
|
-
if (options_dict)
|
|
468
|
-
CFRelease(options_dict);
|
|
469
|
-
if (password_ref)
|
|
470
|
-
CFRelease(password_ref);
|
|
471
|
-
|
|
472
|
-
return err;
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
int32_t mz_crypt_sign_verify(uint8_t *message, int32_t message_size, uint8_t *signature, int32_t signature_size) {
|
|
476
|
-
CMSDecoderRef decoder = NULL;
|
|
477
|
-
CMSSignerStatus signer_status = 0;
|
|
478
|
-
CFDataRef message_out = NULL;
|
|
479
|
-
SecPolicyRef trust_policy = NULL;
|
|
480
|
-
OSStatus status = noErr;
|
|
481
|
-
OSStatus verify_status = noErr;
|
|
482
|
-
size_t signer_count = 0;
|
|
483
|
-
size_t i = 0;
|
|
484
|
-
int32_t err = MZ_SIGN_ERROR;
|
|
485
|
-
|
|
486
|
-
if (!message || !signature)
|
|
487
|
-
return MZ_PARAM_ERROR;
|
|
488
|
-
|
|
489
|
-
status = CMSDecoderCreate(&decoder);
|
|
490
|
-
if (status == errSecSuccess)
|
|
491
|
-
status = CMSDecoderUpdateMessage(decoder, signature, signature_size);
|
|
492
|
-
if (status == errSecSuccess)
|
|
493
|
-
status = CMSDecoderFinalizeMessage(decoder);
|
|
494
|
-
if (status == errSecSuccess)
|
|
495
|
-
trust_policy = SecPolicyCreateBasicX509();
|
|
496
|
-
|
|
497
|
-
if (status == errSecSuccess && trust_policy) {
|
|
498
|
-
CMSDecoderGetNumSigners(decoder, &signer_count);
|
|
499
|
-
if (signer_count > 0)
|
|
500
|
-
err = MZ_OK;
|
|
501
|
-
for (i = 0; i < signer_count; i += 1) {
|
|
502
|
-
status = CMSDecoderCopySignerStatus(decoder, i, trust_policy, TRUE, &signer_status, NULL, &verify_status);
|
|
503
|
-
if (status != errSecSuccess || verify_status != 0 || signer_status != kCMSSignerValid) {
|
|
504
|
-
err = MZ_SIGN_ERROR;
|
|
505
|
-
break;
|
|
506
|
-
}
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
if (err == MZ_OK) {
|
|
511
|
-
status = CMSDecoderCopyContent(decoder, &message_out);
|
|
512
|
-
if ((status != errSecSuccess) ||
|
|
513
|
-
(CFDataGetLength(message_out) != message_size) ||
|
|
514
|
-
(memcmp(message, CFDataGetBytePtr(message_out), message_size) != 0))
|
|
515
|
-
err = MZ_SIGN_ERROR;
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
if (trust_policy)
|
|
519
|
-
CFRelease(trust_policy);
|
|
520
|
-
if (decoder)
|
|
521
|
-
CFRelease(decoder);
|
|
522
|
-
|
|
523
|
-
return err;
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
#endif
|