Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Baulig <martin.baulig@xamarin.com>2015-12-10 04:49:39 +0300
committerMartin Baulig <martin.baulig@xamarin.com>2015-12-10 21:03:47 +0300
commitb1a575a3b5f78a074ea3df36ae4970fcb5d17585 (patch)
treeafdc409928c878bc1412f7fd99fbe1540f831f6b /mcs/class/System/System.Security.Cryptography.X509Certificates
parent2a7060c124c641b55b39b6f452e358996a043a48 (diff)
[corlib]: Cleanup X509Certificate and move the implementation-specific bits into a separate class.
(cherry picked from commit b82b0b8402297854bcceccc4329703024c5aad63)
Diffstat (limited to 'mcs/class/System/System.Security.Cryptography.X509Certificates')
-rw-r--r--mcs/class/System/System.Security.Cryptography.X509Certificates/OSX509Certificates.cs26
1 files changed, 18 insertions, 8 deletions
diff --git a/mcs/class/System/System.Security.Cryptography.X509Certificates/OSX509Certificates.cs b/mcs/class/System/System.Security.Cryptography.X509Certificates/OSX509Certificates.cs
index e4f47a5d363..184e586471d 100644
--- a/mcs/class/System/System.Security.Cryptography.X509Certificates/OSX509Certificates.cs
+++ b/mcs/class/System/System.Security.Cryptography.X509Certificates/OSX509Certificates.cs
@@ -62,6 +62,9 @@ namespace System.Security.Cryptography.X509Certificates {
unsafe extern static IntPtr CFDataCreate (IntPtr allocator, byte *bytes, /* CFIndex */ IntPtr length);
[DllImport (CoreFoundationLibrary)]
+ extern static void CFRetain (IntPtr handle);
+
+ [DllImport (CoreFoundationLibrary)]
extern static void CFRelease (IntPtr handle);
[DllImport (CoreFoundationLibrary)]
@@ -97,6 +100,18 @@ namespace System.Security.Cryptography.X509Certificates {
IntPtr.Zero);
}
}
+
+ static IntPtr GetCertificate (X509Certificate certificate, out IntPtr dataPtr)
+ {
+ var handle = certificate.Handle;
+ if (handle != IntPtr.Zero) {
+ dataPtr = IntPtr.Zero;
+ CFRetain (handle);
+ return handle;
+ }
+ dataPtr = MakeCFData (certificate.GetRawCertData ());
+ return SecCertificateCreateWithData (IntPtr.Zero, dataPtr);
+ }
public static SecTrustResult TrustEvaluateSsl (XX509CertificateCollection certificates, XX509CertificateCollection anchors, string host)
{
@@ -126,19 +141,14 @@ namespace System.Security.Cryptography.X509Certificates {
SecTrustResult result = SecTrustResult.Deny;
try {
- for (int i = 0; i < certCount; i++)
- cfDataPtrs [i] = MakeCFData (certificates [i].GetRawCertData ());
- for (int i = 0; i < anchorCount; i++)
- cfDataAnchorPtrs [i] = MakeCFData (anchors [i].GetRawCertData ());
-
- for (int i = 0; i < certCount; i++){
- secCerts [i] = SecCertificateCreateWithData (IntPtr.Zero, cfDataPtrs [i]);
+ for (int i = 0; i < certCount; i++) {
+ secCerts [i] = GetCertificate (certificates [i], out cfDataPtrs [i]);
if (secCerts [i] == IntPtr.Zero)
return SecTrustResult.Deny;
}
for (int i = 0; i < anchorCount; i++) {
- secCertAnchors [i] = SecCertificateCreateWithData (IntPtr.Zero, cfDataAnchorPtrs [i]);
+ secCertAnchors [i] = GetCertificate (anchors [i], out cfDataAnchorPtrs [i]);
if (secCertAnchors [i] == IntPtr.Zero)
return SecTrustResult.Deny;
}