Imported Upstream version 4.4.0.122

Former-commit-id: a99f46acaeba3ab496c7afc02c29b839e30a0d0b
This commit is contained in:
Xamarin Public Jenkins
2016-04-12 13:19:31 -04:00
parent a632333cc7
commit d444f0caa4
118 changed files with 4121 additions and 1632 deletions

View File

@ -0,0 +1,35 @@
//
// INativeCertificateHelper.cs
//
// Author:
// Martin Baulig <martin.baulig@xamarin.com>
//
// Copyright (c) 2016 Xamarin, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
namespace System.Security.Cryptography.X509Certificates
{
internal interface INativeCertificateHelper
{
X509CertificateImpl Import (byte[] data, string password, X509KeyStorageFlags flags);
X509CertificateImpl Import (X509Certificate cert);
}
}

View File

@ -109,17 +109,44 @@ namespace System.Security.Cryptography.X509Certificates {
impl = X509Helper.InitFromHandle (handle);
}
internal X509Certificate (X509CertificateImpl impl)
{
if (impl == null)
throw new ArgumentNullException ("impl");
this.impl = X509Helper.InitFromCertificate (impl);
}
public X509Certificate (System.Security.Cryptography.X509Certificates.X509Certificate cert)
{
if (cert == null)
throw new ArgumentNullException ("cert");
X509Helper.ThrowIfContextInvalid (cert.impl);
impl = X509Helper.InitFromCertificate (cert.impl);
impl = X509Helper.InitFromCertificate (cert);
hideDates = false;
}
internal void ImportHandle (X509CertificateImpl impl)
{
Reset ();
this.impl = impl;
}
internal X509CertificateImpl Impl {
get {
X509Helper.ThrowIfContextInvalid (impl);
return impl;
}
}
internal bool IsValid {
get { return X509Helper.IsValid (impl); }
}
internal void ThrowIfContextInvalid ()
{
X509Helper.ThrowIfContextInvalid (impl);
}
// public methods
@ -161,7 +188,7 @@ namespace System.Security.Cryptography.X509Certificates {
return null;
X509Helper.ThrowIfContextInvalid (impl);
return impl.GetEffectiveDateString ().ToString ();
return impl.GetValidFrom ().ToLocalTime ().ToString ();
}
// strangly there are no DateTime returning function
@ -171,7 +198,7 @@ namespace System.Security.Cryptography.X509Certificates {
return null;
X509Helper.ThrowIfContextInvalid (impl);
return impl.GetExpirationDateString ().ToString ();
return impl.GetValidUntil ().ToLocalTime ().ToString ();
}
// well maybe someday there'll be support for PGP or SPKI ?

View File

@ -45,17 +45,15 @@ namespace System.Security.Cryptography.X509Certificates
public abstract X509CertificateImpl Clone ();
public abstract string GetSubjectSummary ();
public abstract string GetIssuerName (bool legacyV1Mode);
public abstract string GetSubjectName (bool legacyV1Mode);
public abstract byte[] GetRawCertData ();
public abstract DateTime GetEffectiveDateString ();
public abstract DateTime GetValidFrom ();
public abstract DateTime GetExpirationDateString ();
public abstract DateTime GetValidUntil ();
byte[] cachedCertificateHash;

View File

@ -66,12 +66,6 @@ namespace System.Security.Cryptography.X509Certificates
return MX.X501.ToString (x509.GetIssuerName (), true, ", ", true);
}
public override string GetSubjectSummary ()
{
ThrowIfContextInvalid ();
return x509.SubjectName;
}
public override string GetSubjectName (bool legacyV1Mode)
{
ThrowIfContextInvalid ();
@ -94,16 +88,16 @@ namespace System.Security.Cryptography.X509Certificates
return sha.ComputeHash (x509.RawData);
}
public override DateTime GetEffectiveDateString ()
public override DateTime GetValidFrom ()
{
ThrowIfContextInvalid ();
return x509.ValidFrom.ToLocalTime ();
return x509.ValidFrom;
}
public override DateTime GetExpirationDateString ()
public override DateTime GetValidUntil ()
{
ThrowIfContextInvalid ();
return x509.ValidUntil.ToLocalTime ();
return x509.ValidUntil;
}
public override bool Equals (X509CertificateImpl other, out bool result)
@ -164,8 +158,8 @@ namespace System.Security.Cryptography.X509Certificates
StringBuilder sb = new StringBuilder ();
sb.AppendFormat ("[Subject]{0} {1}{0}{0}", nl, GetSubjectName (false));
sb.AppendFormat ("[Issuer]{0} {1}{0}{0}", nl, GetIssuerName (false));
sb.AppendFormat ("[Not Before]{0} {1}{0}{0}", nl, GetEffectiveDateString ());
sb.AppendFormat ("[Not After]{0} {1}{0}{0}", nl, GetExpirationDateString ());
sb.AppendFormat ("[Not Before]{0} {1}{0}{0}", nl, GetValidFrom ().ToLocalTime ());
sb.AppendFormat ("[Not After]{0} {1}{0}{0}", nl, GetValidUntil ().ToLocalTime ());
sb.AppendFormat ("[Thumbprint]{0} {1}{0}", nl, X509Helper.ToHexString (GetCertHash ()));
sb.Append (nl);
return sb.ToString ();

View File

@ -30,6 +30,7 @@
//
using System;
using System.Text;
using System.Threading;
using System.Runtime.InteropServices;
#if !NET_2_1
using System.Security.Permissions;
@ -40,6 +41,14 @@ namespace System.Security.Cryptography.X509Certificates
{
static partial class X509Helper
{
static INativeCertificateHelper nativeHelper;
internal static void InstallNativeHelper (INativeCertificateHelper helper)
{
if (nativeHelper == null)
Interlocked.CompareExchange (ref nativeHelper, helper, null);
}
#if !NET_2_1
// typedef struct _CERT_CONTEXT {
// DWORD dwCertEncodingType;
@ -77,6 +86,14 @@ namespace System.Security.Cryptography.X509Certificates
}
#endif
public static X509CertificateImpl InitFromCertificate (X509Certificate cert)
{
if (nativeHelper != null)
return nativeHelper.Import (cert);
return InitFromCertificate (cert.Impl);
}
public static X509CertificateImpl InitFromCertificate (X509CertificateImpl impl)
{
ThrowIfContextInvalid (impl);
@ -134,6 +151,9 @@ namespace System.Security.Cryptography.X509Certificates
#if !MONOTOUCH && !XAMMAC
public static X509CertificateImpl Import (byte[] rawData, string password, X509KeyStorageFlags keyStorageFlags)
{
if (nativeHelper != null)
return nativeHelper.Import (rawData, password, keyStorageFlags);
MX.X509Certificate x509;
if (password == null) {
try {