Skip to content

Commit

Permalink
drafted fix
Browse files Browse the repository at this point in the history
  • Loading branch information
maryamariyan committed Jun 29, 2018
1 parent 331f135 commit ed3262d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.

#include "pal_x509.h"
#include <dlfcn.h>

static const int32_t kErrOutItemsNull = -3;
static const int32_t kErrOutItemsEmpty = -2;
Expand Down Expand Up @@ -52,7 +53,19 @@ AppleCryptoNative_X509GetPublicKey(SecCertificateRef cert, SecKeyRef* pPublicKey
if (cert == NULL || pPublicKeyOut == NULL || pOSStatusOut == NULL)
return kErrorBadInput;

*pOSStatusOut = SecCertificateCopyPublicKey(cert, pPublicKeyOut);
// SecCertificateCopyPublicKey was deprecated in 10.14, so use SecCertificateCopyKey on the systems that have it (10.14+),
// and SecCertificateCopyPublicKey on the systems that don’t.
SecKeyRef (*secCertificateCopyKey)(SecCertificateRef);
OSStatus (*secCertificateCopyPublicKey)(SecCertificateRef, SecKeyRef*);
if ((secCertificateCopyKey = (SecKeyRef (*)(SecCertificateRef))dlsym(RTLD_DEFAULT, "SecCertificateCopyKey")) != NULL)
{
*pPublicKeyOut = (*secCertificateCopyKey)(cert);
}
else
{
assert((secCertificateCopyPublicKey = (OSStatus (*)(SecCertificateRef, SecKeyRef*))dlsym(RTLD_DEFAULT, "SecCertificateCopyPublicKey")) != NULL);
*pOSStatusOut = (*secCertificateCopyPublicKey)(cert, pPublicKeyOut);
}
return (*pOSStatusOut == noErr);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Returns 1 on success, 0 on failure, any other value on invalid state.
Output:
pPublicKeyOut: Receives a CFRetain()ed SecKeyRef for the public key
pOSStatusOut: Receives the result of SecCertificateCopyPublicKey
pOSStatusOut: Receives the result of SecCertificateCopyKey
*/
DLLEXPORT int32_t
AppleCryptoNative_X509GetPublicKey(SecCertificateRef cert, SecKeyRef* pPublicKeyOut, int32_t* pOSStatusOut);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ public AsymmetricAlgorithm DecodePublicKey(Oid oid, byte[] encodedKeyValue, byte
case Oids.RsaRsa:
return new RSAImplementation.RSASecurityTransforms(key);
case Oids.DsaDsa:
if (key.IsInvalid)
{
// SecCertificateCopyKey returns null for DSA, so fall back to manually building it.
return DecodeDsaPublicKey(encodedKeyValue, encodedParameters);
}
return new DSAImplementation.DSASecurityTransforms(key);
case Oids.Ecc:
return new ECDsaImplementation.ECDsaSecurityTransforms(key);
Expand Down

0 comments on commit ed3262d

Please sign in to comment.