Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Commit

Permalink
Drop pal_asn1_print in favor of the managed code
Browse files Browse the repository at this point in the history
* Drop pal_asn1_print in favor of the managed code that is already used on macOS.

* Add handling of T61 strings to ManagedCertificateFinder.DerStringToManagedString.
  • Loading branch information
filipnavara authored and omajid committed Jan 17, 2019
1 parent 7f5ccbd commit 3fd578c
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 209 deletions.

This file was deleted.

28 changes: 0 additions & 28 deletions src/Common/src/Microsoft/Win32/SafeHandles/Asn1SafeHandles.Unix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,34 +68,6 @@ public override bool IsInvalid
}
}

internal sealed class SafeAsn1StringHandle : SafeHandle
{
private SafeAsn1StringHandle() :
base(IntPtr.Zero, ownsHandle: true)
{
}

protected override bool ReleaseHandle()
{
Interop.Crypto.Asn1StringFree(handle);
SetHandle(IntPtr.Zero);
return true;
}

public override bool IsInvalid
{
get { return handle == IntPtr.Zero; }
}
}

internal sealed class SafeSharedAsn1StringHandle : SafeInteriorHandle
{
private SafeSharedAsn1StringHandle() :
base(IntPtr.Zero, ownsHandle: true)
{
}
}

internal sealed class SafeSharedAsn1IntegerHandle : SafeInteriorHandle
{
private SafeSharedAsn1IntegerHandle() :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

#include "pal_asn1_print.h"

/*
* This file is completely unused. It's kept around for compatiblity between
* servicing updates.
*/

static_assert(PAL_B_ASN1_NUMERICSTRING == B_ASN1_NUMERICSTRING, "");
static_assert(PAL_B_ASN1_PRINTABLESTRING == B_ASN1_PRINTABLESTRING, "");
static_assert(PAL_B_ASN1_T61STRING == B_ASN1_T61STRING, "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
#include "pal_types.h"
#include "opensslshim.h"

/*
* This file is completely unused. It's kept around for compatiblity between
* servicing updates.
*/

/*
Flags for the 'type' parameter of CryptoNative_DecodeAsn1TypeBytes.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,34 +22,6 @@ public AppleCertificateFinder(X509Certificate2Collection findFrom, X509Certifica
{
}

protected override string DerStringToManagedString(byte[] anyString)
{
DerSequenceReader reader = DerSequenceReader.CreateForPayload(anyString);

var tag = (DerSequenceReader.DerTag)reader.PeekTag();
string value = null;

switch (tag)
{
case DerSequenceReader.DerTag.BMPString:
value = reader.ReadBMPString();
break;
case DerSequenceReader.DerTag.IA5String:
value = reader.ReadIA5String();
break;
case DerSequenceReader.DerTag.PrintableString:
value = reader.ReadPrintableString();
break;
case DerSequenceReader.DerTag.UTF8String:
value = reader.ReadUtf8String();
break;

// Ignore anything we don't know how to read.
}

return value;
}

protected override byte[] GetSubjectPublicKeyInfo(X509Certificate2 cert)
{
AppleCertificatePal pal = (AppleCertificatePal)cert.Pal;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,36 @@ public void FindByTimeExpired(DateTime dateTime)
FindCore(cert => cert.NotAfter < normalized);
}

protected abstract string DerStringToManagedString(byte[] anyString);
private string DerStringToManagedString(byte[] anyString)
{
DerSequenceReader reader = DerSequenceReader.CreateForPayload(anyString);

var tag = (DerSequenceReader.DerTag)reader.PeekTag();
string value = null;

switch (tag)
{
case DerSequenceReader.DerTag.BMPString:
value = reader.ReadBMPString();
break;
case DerSequenceReader.DerTag.IA5String:
value = reader.ReadIA5String();
break;
case DerSequenceReader.DerTag.PrintableString:
value = reader.ReadPrintableString();
break;
case DerSequenceReader.DerTag.UTF8String:
value = reader.ReadUtf8String();
break;
case DerSequenceReader.DerTag.T61String:
value = reader.ReadT61String();
break;

// Ignore anything we don't know how to read.
}

return value;
}

public void FindByTemplateName(string templateName)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ internal OpenSslCertificateFinder(X509Certificate2Collection findFrom, X509Certi
{
}

protected override string DerStringToManagedString(byte[] anyString)
{
return Interop.Crypto.DerStringToManagedString(anyString);
}

protected override byte[] GetSubjectPublicKeyInfo(X509Certificate2 cert)
{
OpenSslX509CertificateReader certPal = (OpenSslX509CertificateReader)cert.Pal;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,6 @@
<Compile Include="$(CommonPath)\Interop\Unix\System.Security.Cryptography.Native\Interop.ASN1.GetIntegerBytes.cs">
<Link>Common\Interop\Unix\System.Security.Cryptography.Native\Interop.ASN1.GetIntegerBytes.cs</Link>
</Compile>
<Compile Include="$(CommonPath)\Interop\Unix\System.Security.Cryptography.Native\Interop.ASN1.Print.cs">
<Link>Common\Interop\Unix\System.Security.Cryptography.Native\Interop.ASN1.Print.cs</Link>
</Compile>
<Compile Include="$(CommonPath)\Interop\Unix\System.Security.Cryptography.Native\Interop.Bignum.cs">
<Link>Common\Interop\Unix\System.Security.Cryptography.Native\Interop.Bignum.cs</Link>
</Compile>
Expand Down

0 comments on commit 3fd578c

Please sign in to comment.