@algocare/react-native-code-push 12.6.4 → 13.0.0-rc.0
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.podspec +6 -8
- package/README.md +343 -586
- package/android/app/build.gradle +2 -1
- package/android/app/proguard-rules.pro +14 -0
- package/android/app/src/debug/AndroidManifest.xml +9 -0
- package/android/app/src/main/AndroidManifest.xml +1 -2
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java +14 -139
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushConstants.java +0 -3
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java +108 -63
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUpdateManager.java +2 -33
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUpdateUtils.java +13 -109
- package/android/build.gradle +3 -0
- package/app.plugin.js +1 -0
- package/bin/code-push.js +6 -0
- package/cli/commands/bundleCommand/bundleCodePush.ts +118 -0
- package/cli/commands/bundleCommand/index.ts +34 -0
- package/cli/commands/createHistoryCommand/createReleaseHistory.ts +37 -0
- package/cli/commands/createHistoryCommand/createReleaseHistoryList.ts +40 -0
- package/cli/commands/createHistoryCommand/index.ts +44 -0
- package/cli/commands/createPullRequestHistoryCommand/createPullRequestHistory.ts +33 -0
- package/cli/commands/createPullRequestHistoryCommand/index.ts +31 -0
- package/cli/commands/createPullRequestReleaseCommand/addToPullRequestRelease.ts +71 -0
- package/cli/commands/createPullRequestReleaseCommand/createPullRequestRelease.ts +75 -0
- package/cli/commands/createPullRequestReleaseCommand/index.ts +74 -0
- package/cli/commands/getPackageHashCommand/index.ts +45 -0
- package/cli/commands/initCommand/index.ts +14 -0
- package/cli/commands/initCommand/initAndroid.ts +91 -0
- package/cli/commands/initCommand/initIos.ts +123 -0
- package/cli/commands/initCommand/test/initAndroid.test.ts +128 -0
- package/cli/commands/initCommand/test/initIos.test.ts +99 -0
- package/cli/commands/releaseCommand/addToReleaseHistory.ts +57 -0
- package/cli/commands/releaseCommand/index.ts +90 -0
- package/cli/commands/releaseCommand/release.ts +105 -0
- package/cli/commands/removePullRequestHistoryCommand/index.ts +37 -0
- package/cli/commands/removePullRequestHistoryCommand/removePullRequestHistory.ts +28 -0
- package/cli/commands/showHistoryCommand/index.ts +31 -0
- package/cli/commands/updateHistoryCommand/index.ts +55 -0
- package/cli/commands/updateHistoryCommand/updateReleaseHistory.ts +42 -0
- package/cli/constant.ts +4 -0
- package/cli/dist/commands/bundleCommand/bundleCodePush.js +65 -0
- package/cli/dist/commands/bundleCommand/index.js +15 -0
- package/cli/dist/commands/createHistoryCommand/createReleaseHistory.js +25 -0
- package/cli/dist/commands/createHistoryCommand/createReleaseHistoryList.js +27 -0
- package/cli/dist/commands/createHistoryCommand/index.js +20 -0
- package/cli/dist/commands/createPullRequestHistoryCommand/createPullRequestHistory.js +23 -0
- package/cli/dist/commands/createPullRequestHistoryCommand/index.js +15 -0
- package/cli/dist/commands/createPullRequestReleaseCommand/addToPullRequestRelease.js +51 -0
- package/cli/dist/commands/createPullRequestReleaseCommand/createPullRequestRelease.js +39 -0
- package/cli/dist/commands/createPullRequestReleaseCommand/index.js +35 -0
- package/cli/dist/commands/getPackageHashCommand/index.js +26 -0
- package/cli/dist/commands/initCommand/index.js +12 -0
- package/cli/dist/commands/initCommand/initAndroid.js +73 -0
- package/cli/dist/commands/initCommand/initIos.js +108 -0
- package/cli/dist/commands/initCommand/test/initAndroid.test.js +113 -0
- package/cli/dist/commands/initCommand/test/initIos.test.js +95 -0
- package/cli/dist/commands/releaseCommand/addToReleaseHistory.js +35 -0
- package/cli/dist/commands/releaseCommand/index.js +45 -0
- package/cli/dist/commands/releaseCommand/release.js +62 -0
- package/cli/dist/commands/removePullRequestHistoryCommand/index.js +19 -0
- package/cli/dist/commands/removePullRequestHistoryCommand/removePullRequestHistory.js +18 -0
- package/cli/dist/commands/showHistoryCommand/index.js +15 -0
- package/cli/dist/commands/updateHistoryCommand/index.js +31 -0
- package/cli/dist/commands/updateHistoryCommand/updateReleaseHistory.js +28 -0
- package/cli/dist/constant.js +4 -0
- package/cli/dist/functions/getReactTempDir.js +10 -0
- package/cli/{functions → dist/functions}/makeCodePushBundle.js +5 -11
- package/cli/{functions → dist/functions}/prepareToBundleJS.js +2 -5
- package/cli/dist/functions/runExpoBundleCommand.js +35 -0
- package/cli/{functions → dist/functions}/runHermesEmitBinaryCommand.js +36 -71
- package/cli/{functions → dist/functions}/runReactNativeBundleCommand.js +19 -24
- package/cli/dist/index.js +54 -0
- package/cli/dist/utils/datetime.js +17 -0
- package/cli/dist/utils/file-utils.js +19 -0
- package/cli/dist/utils/fsUtils.js +44 -0
- package/cli/{utils → dist/utils}/hash-utils.js +19 -130
- package/cli/{utils → dist/utils}/promisfied-fs.js +5 -16
- package/cli/dist/utils/showLogo.js +21 -0
- package/cli/dist/utils/unzip.js +41 -0
- package/cli/{utils → dist/utils}/zip.js +15 -51
- package/cli/functions/{getReactTempDir.js → getReactTempDir.ts} +2 -6
- package/cli/functions/makeCodePushBundle.ts +26 -0
- package/cli/functions/prepareToBundleJS.ts +10 -0
- package/cli/functions/runExpoBundleCommand.ts +45 -0
- package/cli/functions/runHermesEmitBinaryCommand.ts +203 -0
- package/cli/functions/runReactNativeBundleCommand.ts +67 -0
- package/cli/index.ts +68 -0
- package/cli/package.json +35 -0
- package/cli/utils/datetime.ts +19 -0
- package/cli/utils/{file-utils.js → file-utils.ts} +4 -21
- package/cli/utils/fsUtils.ts +50 -0
- package/cli/utils/hash-utils.ts +143 -0
- package/cli/utils/promisfied-fs.ts +19 -0
- package/cli/utils/{showLogo.js → showLogo.ts} +4 -6
- package/cli/utils/unzip.ts +46 -0
- package/cli/utils/zip.ts +65 -0
- package/expo/plugin/withCodePush.js +14 -0
- package/expo/plugin/withCodePushAndroid.js +92 -0
- package/expo/plugin/withCodePushIos.js +143 -0
- package/ios/CodePush/CodePush.h +0 -16
- package/ios/CodePush/CodePush.m +30 -20
- package/ios/CodePush/CodePushConfig.m +1 -11
- package/ios/CodePush/CodePushPackage.m +12 -69
- package/ios/CodePush/CodePushUpdateUtils.m +1 -91
- package/ios/CodePush/SSZipArchive/Info.plist +26 -0
- package/ios/CodePush/SSZipArchive/README.md +1 -1
- package/ios/CodePush/SSZipArchive/SSZipArchive.h +129 -27
- package/ios/CodePush/SSZipArchive/SSZipArchive.m +1119 -314
- package/ios/CodePush/SSZipArchive/SSZipCommon.h +71 -0
- package/ios/CodePush/SSZipArchive/Supporting Files/PrivacyInfo.xcprivacy +23 -0
- package/ios/CodePush/SSZipArchive/include/ZipArchive.h +25 -0
- package/ios/CodePush/SSZipArchive/minizip/LICENSE +17 -0
- package/ios/CodePush/SSZipArchive/minizip/mz.h +273 -0
- package/ios/CodePush/SSZipArchive/minizip/mz_compat.c +1306 -0
- package/ios/CodePush/SSZipArchive/minizip/mz_compat.h +346 -0
- package/ios/CodePush/SSZipArchive/minizip/mz_crypt.c +187 -0
- package/ios/CodePush/SSZipArchive/minizip/mz_crypt.h +65 -0
- package/ios/CodePush/SSZipArchive/minizip/mz_crypt_apple.c +526 -0
- package/ios/CodePush/SSZipArchive/minizip/mz_os.c +348 -0
- package/ios/CodePush/SSZipArchive/minizip/mz_os.h +176 -0
- package/ios/CodePush/SSZipArchive/minizip/mz_os_posix.c +350 -0
- package/ios/CodePush/SSZipArchive/minizip/mz_strm.c +556 -0
- package/ios/CodePush/SSZipArchive/minizip/mz_strm.h +132 -0
- package/ios/CodePush/SSZipArchive/minizip/mz_strm_buf.c +383 -0
- package/ios/CodePush/SSZipArchive/minizip/mz_strm_buf.h +42 -0
- package/ios/CodePush/SSZipArchive/minizip/mz_strm_mem.c +269 -0
- package/ios/CodePush/SSZipArchive/minizip/mz_strm_mem.h +48 -0
- package/ios/CodePush/SSZipArchive/minizip/mz_strm_os.h +40 -0
- package/ios/CodePush/SSZipArchive/minizip/mz_strm_os_posix.c +203 -0
- package/ios/CodePush/SSZipArchive/minizip/mz_strm_pkcrypt.c +334 -0
- package/ios/CodePush/SSZipArchive/minizip/mz_strm_pkcrypt.h +46 -0
- package/ios/CodePush/SSZipArchive/minizip/mz_strm_split.c +429 -0
- package/ios/CodePush/SSZipArchive/minizip/mz_strm_split.h +43 -0
- package/ios/CodePush/SSZipArchive/minizip/mz_strm_wzaes.c +360 -0
- package/ios/CodePush/SSZipArchive/minizip/mz_strm_wzaes.h +46 -0
- package/ios/CodePush/SSZipArchive/minizip/mz_strm_zlib.c +389 -0
- package/ios/CodePush/SSZipArchive/minizip/mz_strm_zlib.h +43 -0
- package/ios/CodePush/SSZipArchive/minizip/mz_zip.c +2782 -0
- package/ios/CodePush/SSZipArchive/minizip/mz_zip.h +262 -0
- package/ios/CodePush/SSZipArchive/minizip/mz_zip_rw.c +1942 -0
- package/ios/CodePush/SSZipArchive/minizip/mz_zip_rw.h +285 -0
- package/ios/CodePush.xcodeproj/project.pbxproj +244 -453
- package/ios/PrivacyInfo.xcprivacy +31 -0
- package/package.json +68 -42
- package/react-native.config.js +1 -1
- package/{AlertAdapter.js → src/AlertAdapter.js} +5 -5
- package/src/CodePush.js +947 -0
- package/{package-mixins.js → src/package-mixins.js} +1 -1
- package/{versioning → src/versioning}/BaseVersioning.js +12 -1
- package/{versioning → src/versioning}/SemverVersioning.test.js +78 -0
- package/typings/react-native-code-push.d.ts +559 -495
- package/.claude/commands/release.md +0 -78
- package/.claude/skills/npm-release/SKILL.md +0 -89
- package/CLAUDE.md +0 -83
- package/CONTRIBUTING.md +0 -134
- package/CodePush.js +0 -972
- package/SECURITY.md +0 -41
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushBuilder.java +0 -37
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushInvalidPublicKeyException.java +0 -12
- package/android/app/src/main/java/com/microsoft/codepush/react/ReactInstanceHolder.java +0 -17
- package/android/codepush.gradle +0 -162
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +0 -5
- package/android/gradlew +0 -164
- package/android/gradlew.bat +0 -90
- package/babel.config.js +0 -3
- package/cli/commands/bundleCommand/bundleCodePush.js +0 -57
- package/cli/commands/bundleCommand/index.js +0 -55
- package/cli/commands/common.js +0 -245
- package/cli/commands/createHistoryCommand/createReleaseHistory.js +0 -42
- package/cli/commands/createHistoryCommand/createReleaseHistoryList.js +0 -52
- package/cli/commands/createHistoryCommand/index.js +0 -95
- package/cli/commands/createPullRequestHistoryCommand/createPullRequestHistory.js +0 -34
- package/cli/commands/createPullRequestHistoryCommand/index.js +0 -29
- package/cli/commands/createPullRequestReleaseCommand/addToPullRequestRelease.js +0 -74
- package/cli/commands/createPullRequestReleaseCommand/createPullRequestRelease.js +0 -91
- package/cli/commands/createPullRequestReleaseCommand/index.js +0 -68
- package/cli/commands/getPackageHashCommand/index.js +0 -42
- package/cli/commands/releaseCommand/addToReleaseHistory.js +0 -85
- package/cli/commands/releaseCommand/index.js +0 -151
- package/cli/commands/releaseCommand/release.js +0 -121
- package/cli/commands/removePullRequestHistoryCommand/index.js +0 -28
- package/cli/commands/removePullRequestHistoryCommand/removePullRequestHistory.js +0 -23
- package/cli/commands/showHistoryCommand/index.js +0 -88
- package/cli/commands/updateHistoryCommand/index.js +0 -123
- package/cli/commands/updateHistoryCommand/updateReleaseHistory.js +0 -69
- package/cli/constant.js +0 -8
- package/cli/index.js +0 -63
- package/cli/utils/datetime.js +0 -22
- package/cli/utils/fsUtils.js +0 -64
- package/cli/utils/version.js +0 -26
- package/code-push.config.example.supabase.ts +0 -114
- package/code-push.config.js +0 -229
- package/code-push.config.ts +0 -175
- package/docs/api-android.md +0 -83
- package/docs/api-ios.md +0 -31
- package/docs/api-js.md +0 -592
- package/docs/multi-deployment-testing-android.md +0 -148
- package/docs/multi-deployment-testing-ios.md +0 -59
- package/docs/setup-android.md +0 -482
- package/docs/setup-ios.md +0 -280
- package/eslint.config.mjs +0 -32
- 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/Common.h +0 -81
- package/ios/CodePush/SSZipArchive/aes/aes.h +0 -198
- package/ios/CodePush/SSZipArchive/aes/aes_via_ace.h +0 -541
- package/ios/CodePush/SSZipArchive/aes/aescrypt.c +0 -294
- package/ios/CodePush/SSZipArchive/aes/aeskey.c +0 -548
- package/ios/CodePush/SSZipArchive/aes/aesopt.h +0 -739
- package/ios/CodePush/SSZipArchive/aes/aestab.c +0 -391
- package/ios/CodePush/SSZipArchive/aes/aestab.h +0 -173
- package/ios/CodePush/SSZipArchive/aes/brg_endian.h +0 -126
- package/ios/CodePush/SSZipArchive/aes/brg_types.h +0 -219
- package/ios/CodePush/SSZipArchive/aes/entropy.c +0 -54
- package/ios/CodePush/SSZipArchive/aes/entropy.h +0 -16
- package/ios/CodePush/SSZipArchive/aes/fileenc.c +0 -144
- package/ios/CodePush/SSZipArchive/aes/fileenc.h +0 -121
- package/ios/CodePush/SSZipArchive/aes/hmac.c +0 -145
- package/ios/CodePush/SSZipArchive/aes/hmac.h +0 -103
- package/ios/CodePush/SSZipArchive/aes/prng.c +0 -155
- package/ios/CodePush/SSZipArchive/aes/prng.h +0 -82
- package/ios/CodePush/SSZipArchive/aes/pwd2key.c +0 -103
- package/ios/CodePush/SSZipArchive/aes/pwd2key.h +0 -57
- package/ios/CodePush/SSZipArchive/aes/sha1.c +0 -258
- package/ios/CodePush/SSZipArchive/aes/sha1.h +0 -73
- package/ios/CodePush/SSZipArchive/minizip/crypt.h +0 -130
- package/ios/CodePush/SSZipArchive/minizip/ioapi.c +0 -369
- package/ios/CodePush/SSZipArchive/minizip/ioapi.h +0 -175
- package/ios/CodePush/SSZipArchive/minizip/mztools.c +0 -284
- package/ios/CodePush/SSZipArchive/minizip/mztools.h +0 -31
- package/ios/CodePush/SSZipArchive/minizip/unzip.c +0 -1839
- package/ios/CodePush/SSZipArchive/minizip/unzip.h +0 -248
- package/ios/CodePush/SSZipArchive/minizip/zip.c +0 -1910
- package/ios/CodePush/SSZipArchive/minizip/zip.h +0 -202
- package/scripts/generateBundledResourcesHash.js +0 -125
- package/scripts/getFilesInFolder.js +0 -19
- package/scripts/recordFilesBeforeBundleCommand.js +0 -41
- package/scripts/release.sh +0 -86
- package/tsconfig.json +0 -20
- package/tslint.json +0 -32
- /package/{logging.js → src/logging.js} +0 -0
- /package/{versioning → src/versioning}/BaseVersioning.test.js +0 -0
- /package/{versioning → src/versioning}/IncrementalVersioning.js +0 -0
- /package/{versioning → src/versioning}/IncrementalVersioning.test.js +0 -0
- /package/{versioning → src/versioning}/SemverVersioning.js +0 -0
- /package/{versioning → src/versioning}/index.js +0 -0
|
@@ -0,0 +1,526 @@
|
|
|
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
|