Skip to content

Commit 5cfaa96

Browse files
authored
iOS: Enable System.Net.Security.Native and parts of System.Security.Cryptography.Native.Apple (dotnet#33970)
Unavailable APIs are excluded via #if for now.
1 parent 6c64754 commit 5cfaa96

21 files changed

Lines changed: 57 additions & 18 deletions

src/libraries/Native/Unix/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,13 @@ add_subdirectory(System.Native)
197197

198198
if (NOT CLR_CMAKE_TARGET_ARCH_WASM AND NOT CLR_CMAKE_TARGET_IOS) # TODO: reenable for iOS
199199
add_subdirectory(System.Globalization.Native)
200-
add_subdirectory(System.Net.Security.Native)
201200

202201
# disable System.Security.Cryptography.Native build on iOS,
203202
# only used for interacting with OpenSSL which isn't useful there
204203
add_subdirectory(System.Security.Cryptography.Native)
205204
endif()
206205

207206
if(CLR_CMAKE_TARGET_OSX OR CLR_CMAKE_TARGET_IOS)
207+
add_subdirectory(System.Net.Security.Native)
208208
add_subdirectory(System.Security.Cryptography.Native.Apple)
209209
endif()

src/libraries/Native/Unix/System.Security.Cryptography.Native.Apple/CMakeLists.txt

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,24 @@ find_library(SECURITY_LIBRARY Security)
55

66
set(NATIVECRYPTO_SOURCES
77
pal_digest.c
8+
pal_ecc.c
89
pal_hmac.c
10+
pal_keyagree.c
11+
pal_keychain.c
912
pal_random.c
13+
pal_rsa.c
14+
pal_sec.c
15+
pal_seckey.c
16+
pal_signverify.c
17+
pal_ssl.c
1018
pal_symmetric.c
19+
pal_trust.c
20+
pal_x509.c
21+
pal_x509chain.c
1122
)
1223

13-
if (NOT CLR_CMAKE_TARGET_IOS) # TODO: reenable more sources
14-
set(NATIVECRYPTO_SOURCES
15-
${NATIVECRYPTO_SOURCES}
16-
pal_ecc.c
17-
pal_keyagree.c
18-
pal_keychain.c
19-
pal_rsa.c
20-
pal_sec.c
21-
pal_seckey.c
22-
pal_signverify.c
23-
pal_ssl.c
24-
pal_trust.c
25-
pal_x509.c
26-
pal_x509chain.c
27-
)
24+
if (CLR_CMAKE_TARGET_IOS)
25+
add_definitions(-DTARGET_IOS)
2826
endif()
2927

3028
add_library(System.Security.Cryptography.Native.Apple

src/libraries/Native/Unix/System.Security.Cryptography.Native.Apple/pal_ecc.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include "pal_ecc.h"
66

7+
#ifndef TARGET_IOS
78
int32_t AppleCryptoNative_EccGenerateKey(
89
int32_t keySizeBits, SecKeychainRef tempKeychain, SecKeyRef* pPublicKey, SecKeyRef* pPrivateKey, int32_t* pOSStatus)
910
{
@@ -51,6 +52,7 @@ int32_t AppleCryptoNative_EccGenerateKey(
5152
*pOSStatus = status;
5253
return status == noErr;
5354
}
55+
#endif
5456

5557
uint64_t AppleCryptoNative_EccGetKeySizeInBits(SecKeyRef publicKey)
5658
{

src/libraries/Native/Unix/System.Security.Cryptography.Native.Apple/pal_ecc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <Security/Security.h>
1111

12+
#ifndef TARGET_IOS
1213
/*
1314
Generate an ECC keypair of the specified size.
1415
@@ -19,6 +20,7 @@ PALEXPORT int32_t AppleCryptoNative_EccGenerateKey(int32_t keySizeBits,
1920
SecKeyRef* pPublicKey,
2021
SecKeyRef* pPrivateKey,
2122
int32_t* pOSStatus);
23+
#endif
2224

2325
/*
2426
Get the keysize, in bits, of an ECC key.

src/libraries/Native/Unix/System.Security.Cryptography.Native.Apple/pal_keychain.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "pal_keychain.h"
66
#include "pal_utilities.h"
77

8+
#ifndef TARGET_IOS
89
int32_t AppleCryptoNative_SecKeychainItemCopyKeychain(SecKeychainItemRef item, SecKeychainRef* pKeychainOut)
910
{
1011
if (pKeychainOut != NULL)
@@ -465,3 +466,4 @@ AppleCryptoNative_X509StoreRemoveCertificate(CFTypeRef certOrIdentity, SecKeycha
465466
CFRelease(cert);
466467
return *pOSStatus == noErr;
467468
}
469+
#endif

src/libraries/Native/Unix/System.Security.Cryptography.Native.Apple/pal_keychain.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <Security/Security.h>
1111

12+
#ifndef TARGET_IOS
1213
/*
1314
Get a CFRetain()ed SecKeychainRef value for the keychain to which the keychain item belongs.
1415
@@ -137,3 +138,4 @@ pOSStatus: Receives the last OSStatus value..
137138
*/
138139
PALEXPORT int32_t
139140
AppleCryptoNative_X509StoreRemoveCertificate(CFTypeRef certOrIdentity, SecKeychainRef keychain, uint8_t isReadOnlyMode, int32_t* pOSStatus);
141+
#endif

src/libraries/Native/Unix/System.Security.Cryptography.Native.Apple/pal_rsa.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include "pal_rsa.h"
66

7+
#ifndef TARGET_IOS
78
static int32_t ExecuteCFDataTransform(
89
SecTransformRef xform, uint8_t* pbData, int32_t cbData, CFDataRef* pDataOut, CFErrorRef* pErrorOut);
910

@@ -267,6 +268,7 @@ static int32_t ExecuteCFDataTransform(
267268

268269
return ret;
269270
}
271+
#endif
270272

271273
static int32_t RsaPrimitive(SecKeyRef key,
272274
uint8_t* pbData,

src/libraries/Native/Unix/System.Security.Cryptography.Native.Apple/pal_rsa.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include <Security/Security.h>
1212

13+
#ifndef TARGET_IOS
1314
/*
1415
Generate a new RSA keypair with the specified key size, in bits.
1516
@@ -60,6 +61,7 @@ Follows pal_seckey return conventions.
6061
*/
6162
PALEXPORT int32_t AppleCryptoNative_RsaEncryptPkcs(
6263
SecKeyRef publicKey, uint8_t* pbData, int32_t cbData, CFDataRef* pEncryptedOut, CFErrorRef* pErrorOut);
64+
#endif
6365

6466
/*
6567
Apply an RSA private key to a signing operation on data which was already padded.

src/libraries/Native/Unix/System.Security.Cryptography.Native.Apple/pal_sec.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
#include "pal_sec.h"
66

7+
#ifndef TARGET_IOS
78
CFStringRef AppleCryptoNative_SecCopyErrorMessageString(int32_t osStatus)
89
{
910
return SecCopyErrorMessageString(osStatus, NULL);
1011
}
12+
#endif

src/libraries/Native/Unix/System.Security.Cryptography.Native.Apple/pal_sec.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010

1111
#include <Security/Security.h>
1212

13+
#ifndef TARGET_IOS
1314
/*
1415
Get an error message for an OSStatus error from the security library.
1516
1617
Returns NULL if no message is available for the code.
1718
*/
1819
PALEXPORT CFStringRef AppleCryptoNative_SecCopyErrorMessageString(OSStatus osStatus);
20+
#endif

0 commit comments

Comments
 (0)