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

Merging internal commits for release/8.0 #98376

Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,12 @@ public static void UseAfterDispose()
}
}

[Fact]
public static void EmptyPkcs7ThrowsException()
{
Assert.ThrowsAny<CryptographicException>(() => new X509Certificate2(TestData.EmptyPkcs7));
}

[Fact]
public static void ExportPublicKeyAsPkcs12()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4273,5 +4273,7 @@ internal static DSAParameters GetDSA1024Params()
"C0CC2B115B9D33BD6E528E35670E5A6A8D9CF52199F8D693315C60D9ADAD54EF7FDCED36" +
"0C8C79E84D42AB5CB6355A70951B1ABF1F2B3FB8BEB7E3A8D6BA2293C0DB8C86B0BB060F" +
"0D6DB9939E88B998662A27F092634BBF21F58EEAAA").HexToByteArray();

internal static readonly byte[] EmptyPkcs7 = "300B06092A864886F70D010702".HexToByteArray();
}
}
17 changes: 16 additions & 1 deletion src/native/libs/System.Security.Cryptography.Native/apibridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ int32_t local_X509_get_version(const X509* x509)

X509_PUBKEY* local_X509_get_X509_PUBKEY(const X509* x509)
{
if (x509)
if (x509 && x509->cert_info)
{
return x509->cert_info->key;
}
Expand All @@ -123,13 +123,28 @@ X509_PUBKEY* local_X509_get_X509_PUBKEY(const X509* x509)
int32_t local_X509_PUBKEY_get0_param(
ASN1_OBJECT** palgOid, const uint8_t** pkeyBytes, int* pkeyBytesLen, X509_ALGOR** palg, X509_PUBKEY* pubkey)
{
if (!pubkey)
{
return 0;
}

if (palgOid)
{
if (!pubkey->algor)
{
return 0;
}

*palgOid = pubkey->algor->algorithm;
}

if (pkeyBytes)
{
if (!pubkey->public_key)
{
return 0;
}

*pkeyBytes = pubkey->public_key->data;
*pkeyBytesLen = pubkey->public_key->length;
}
Expand Down
5 changes: 5 additions & 0 deletions src/native/libs/System.Security.Cryptography.Native/openssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,11 @@ BIO* CryptoNative_GetX509NameInfo(X509* x509, int32_t nameType, int32_t forIssue
0 == strncmp(localOid, szOidUpn, sizeof(szOidUpn)))
{
// OTHERNAME->ASN1_TYPE->union.field
if (!value->value)
{
return NULL;
}

str = value->value->value.asn1_string;
}
}
Expand Down
10 changes: 10 additions & 0 deletions src/native/libs/System.Security.Cryptography.Native/pal_pkcs7.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,19 @@ int32_t CryptoNative_GetPkcs7Certificates(PKCS7* p7, X509Stack** certs)
switch (OBJ_obj2nid(p7->type))
{
case NID_pkcs7_signed:
if (!p7->d.sign)
{
return 0;
}

*certs = p7->d.sign->cert;
return 1;
case NID_pkcs7_signedAndEnveloped:
if (!p7->d.signed_and_enveloped)
{
return 0;
}

*certs = p7->d.signed_and_enveloped->cert;
return 1;
}
Expand Down
Loading