return SecIdentityCopyPrivateKey(identity, pPrivateKeyOut);
}
+int32_t AppleCryptoNative_X509GetRawData(SecCertificateRef cert, CFDataRef* ppDataOut, int32_t* pOSStatus)
+{
+ if (cert == NULL || ppDataOut == NULL || pOSStatus == NULL)
+ {
+ if (ppDataOut != NULL)
+ *ppDataOut = NULL;
+ if (pOSStatus != NULL)
+ *pOSStatus = noErr;
+ return kErrorBadInput;
+ }
+
+ *ppDataOut = SecCertificateCopyData(cert);
+ *pOSStatus = *ppDataOut == NULL ? errSecParam : noErr;
+ return (*pOSStatus == noErr);
+}
+
#if !defined(TARGET_MACCATALYST) && !defined(TARGET_IOS) && !defined(TARGET_TVOS)
static int32_t ReadX509(uint8_t* pbData,
int32_t cbData,
return *pOSStatus == noErr;
}
-int32_t AppleCryptoNative_X509GetRawData(SecCertificateRef cert, CFDataRef* ppDataOut, int32_t* pOSStatus)
-{
- if (ppDataOut != NULL)
- *ppDataOut = NULL;
- if (pOSStatus != NULL)
- *pOSStatus = noErr;
-
- if (cert == NULL || ppDataOut == NULL || pOSStatus == NULL)
- return kErrorBadInput;
-
- SecExternalFormat dataFormat = kSecFormatX509Cert;
- SecItemImportExportKeyParameters keyParams;
- memset(&keyParams, 0, sizeof(SecItemImportExportKeyParameters));
-
- keyParams.version = SEC_KEY_IMPORT_EXPORT_PARAMS_VERSION;
-
- *pOSStatus = SecItemExport(cert, dataFormat, 0, &keyParams, ppDataOut);
- return (*pOSStatus == noErr);
-}
-
static OSStatus AddKeyToKeychain(SecKeyRef privateKey, SecKeychainRef targetKeychain, SecKeyRef* importedKey)
{
// This is quite similar to pal_seckey's ExportImportKey, but
*/
PALEXPORT int32_t AppleCryptoNative_X509CopyPrivateKeyFromIdentity(SecIdentityRef identity, SecKeyRef* pPrivateKeyOut);
+/*
+Extract the DER encoded value of a certificate (public portion only).
+
+Returns 1 on success, 0 on failure, any other value indicates invalid state.
+
+Output:
+ppDataOut: Receives a CFDataRef with the exported blob
+pOSStatus: Receives the result of SecItemExport
+*/
+PALEXPORT int32_t AppleCryptoNative_X509GetRawData(SecCertificateRef cert, CFDataRef* ppDataOut, int32_t* pOSStatus);
+
#if !defined(TARGET_MACCATALYST) && !defined(TARGET_IOS) && !defined(TARGET_TVOS)
/*
Read cbData bytes of data from pbData and interpret it to a collection of certificates (or identities).
int32_t* pOSStatus);
/*
-Extract the DER encoded value of a certificate (public portion only).
-
-Returns 1 on success, 0 on failure, any other value indicates invalid state.
-
-Output:
-ppDataOut: Receives a CFDataRef with the exported blob
-pOSStatus: Receives the result of SecItemExport
-*/
-PALEXPORT int32_t AppleCryptoNative_X509GetRawData(SecCertificateRef cert, CFDataRef* ppDataOut, int32_t* pOSStatus);
-
-/*
Find a SecIdentityRef for the given cert and private key in the target keychain.
If the key does not belong to any keychain it is added to the target keychain and left there.
If the certificate does not belong to the target keychain it is added and removed.