Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: avoid private api on Mac App Store #804

Merged
merged 2 commits into from
Oct 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions mz_crypt_apple.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@

/***************************************************************************/

/* Avoid use of private API for iOS, Apple does not allow it on App Store. Zip format doesn't need GCM. */
#if !TARGET_OS_IPHONE
#ifndef MZ_TARGET_APPSTORE
#define MZ_TARGET_APPSTORE 0
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I should have defaulted it to 1, @nmoinvaz .
Can you add a commit to flip the default value?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

#endif

/* Avoid use of private API for App Store as Apple does not allow it. Zip format doesn't need GCM. */
#if !MZ_TARGET_APPSTORE
enum {
kCCModeGCM = 11,
};
Expand Down Expand Up @@ -227,7 +231,7 @@ int32_t mz_crypt_aes_encrypt(void *handle, const void *aad, int32_t aad_size, ui
return MZ_PARAM_ERROR;

if (aes->mode == MZ_AES_MODE_GCM) {
#if TARGET_OS_IPHONE
#if MZ_TARGET_APPSTORE
return MZ_SUPPORT_ERROR;
#else
if (aad && aad_size > 0) {
Expand All @@ -251,14 +255,14 @@ int32_t mz_crypt_aes_encrypt(void *handle, const void *aad, int32_t aad_size, ui

int32_t mz_crypt_aes_encrypt_final(void *handle, uint8_t *buf, int32_t size, uint8_t *tag, int32_t tag_size) {
mz_crypt_aes *aes = (mz_crypt_aes *)handle;
#if !TARGET_OS_IPHONE
#if !MZ_TARGET_APPSTORE
size_t tag_outsize = tag_size;
#endif

if (!aes || !tag || !tag_size || !aes->crypt || aes->mode != MZ_AES_MODE_GCM)
return MZ_PARAM_ERROR;

#if TARGET_OS_IPHONE
#if MZ_TARGET_APPSTORE
return MZ_SUPPORT_ERROR;
#else
aes->error = CCCryptorGCMEncrypt(aes->crypt, buf, size, buf);
Expand All @@ -282,7 +286,7 @@ int32_t mz_crypt_aes_decrypt(void *handle, const void *aad, int32_t aad_size, ui
return MZ_PARAM_ERROR;

if (aes->mode == MZ_AES_MODE_GCM) {
#if TARGET_OS_IPHONE
#if MZ_TARGET_APPSTORE
return MZ_SUPPORT_ERROR;
#else
if (aad && aad_size > 0) {
Expand All @@ -306,7 +310,7 @@ int32_t mz_crypt_aes_decrypt(void *handle, const void *aad, int32_t aad_size, ui

int32_t mz_crypt_aes_decrypt_final(void *handle, uint8_t *buf, int32_t size, const uint8_t *tag, int32_t tag_length) {
mz_crypt_aes *aes = (mz_crypt_aes *)handle;
#if !TARGET_OS_IPHONE
#if !MZ_TARGET_APPSTORE
uint8_t tag_actual_buf[MZ_AES_BLOCK_SIZE];
size_t tag_actual_len = sizeof(tag_actual_buf);
uint8_t *tag_actual = tag_actual_buf;
Expand All @@ -317,7 +321,7 @@ int32_t mz_crypt_aes_decrypt_final(void *handle, uint8_t *buf, int32_t size, con
if (!aes || !tag || !tag_length || !aes->crypt || aes->mode != MZ_AES_MODE_GCM)
return MZ_PARAM_ERROR;

#if TARGET_OS_IPHONE
#if MZ_TARGET_APPSTORE
return MZ_SUPPORT_ERROR;
#else
aes->error = CCCryptorGCMDecrypt(aes->crypt, buf, size, buf);
Expand Down Expand Up @@ -353,7 +357,7 @@ static int32_t mz_crypt_aes_set_key(void *handle, const void *key, int32_t key_l
else if (aes->mode == MZ_AES_MODE_ECB)
mode = kCCModeECB;
else if (aes->mode == MZ_AES_MODE_GCM)
#if !TARGET_OS_IPHONE
#if !MZ_TARGET_APPSTORE
mode = kCCModeGCM;
#else
return MZ_SUPPORT_ERROR;
Expand All @@ -369,7 +373,7 @@ static int32_t mz_crypt_aes_set_key(void *handle, const void *key, int32_t key_l
if (aes->error != kCCSuccess)
return MZ_HASH_ERROR;

#if !TARGET_OS_IPHONE
#if !MZ_TARGET_APPSTORE
if (aes->mode == MZ_AES_MODE_GCM) {
aes->error = CCCryptorGCMAddIV(aes->crypt, iv, iv_length);

Expand Down
Loading