Imported Upstream version 4.6.0.125

Former-commit-id: a2155e9bd80020e49e72e86c44da02a8ac0e57a4
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2016-08-03 10:59:49 +00:00
parent a569aebcfd
commit e79aa3c0ed
17047 changed files with 3137615 additions and 392334 deletions

View File

@@ -1,203 +0,0 @@
2010-03-16 Jb Evain <jbevain@novell.com>
* X509KeyStorageFlags.cs, X509ContentType.cs, X509Certificate.cs
X509Certificate20.cs: use MOONLIGHT symbol to disambiguate
MonoTouch and Moonlight code.
2009-09-22 Sebastien Pouliot <sebastien@ximian.com>
* X509Certificate20.cs: Don't depend on SecureString for NET_2_1
2009-05-02 Sebastien Pouliot <sebastien@ximian.com>
* X509Certificate.cs: Remove code to initialize from an handle
in NET_2_1 since this is only possible from Windows and would be
SC anyway.
2009-04-30 Sebastien Pouliot <sebastien@ximian.com>
* X509Certificate.cs: Remove CreateFromSignedFile from NET_2_1
since it's unneeded and bring more code and [SecuritySafeCritical]
API into the assemblies.
2008-08-18 Sebastien Pouliot <sebastien@ximian.com>
* X509Certificate[20].cs: Silverlight 2.0 does not implement either
IDeserializationCallback or ISerializable interfaces for this type.
2008-08-08 Sebastien Pouliot <sebastien@ximian.com>
* X509Certificate20.cs: Remove reference to X509ContentType.Pfx and
SerializedCert since they are not available in SL 2.0
* X509ContentType.cs: Remove values not available in SL 2.0
* X509KeyStorageFlags.cs: Remove values not available in SL 2.0
2008-07-02 Andreas Nahr <ClassDevelopment@A-SoftTech.com>
* X509Certificate.cs: Fix parameter names
2008-01-12 Sebastien Pouliot <sebastien@ximian.com>
* X509Certificate.cs: Don't wrap our own COMException inside another
one. This will provide a better error message to the user (or tool)
2007-01-05 Sebastien Pouliot <sebastien@ximian.com>
* X509Certificate.cs: Now that the ASN.1 converted DateTime is
"clearly" UTC (in 2.0) we need to adjust GetEffectiveDateString and
GetExpirationDateString methods to return the local time.
2006-11-17 Sebastien Pouliot <sebastien@ximian.com>
* X509Certificate.cs: Fix Equals to throw a CryptographicException, in
2.0 profile, if the certificate instance is empty.
* X509Certificate20.cs: Fix Reset method to reset every fields (as the
instance can be reused in 2.0). Updated MonoTODO attributes.
2006-11-08 Sebastien Pouliot <sebastien@ximian.com>
* X509Certificate.cs: Refactored 2.0 support (partial class) and added
some missing features. All unit tests now works in both 1.x and 2.0.
* X509Certificate20.cs: Partial class for 2.0 specific properties and
methods for X509Certificate class.
2006-10-08 Sebastien Pouliot <sebastien@ximian.com>
* X509Certificate.cs: Ensure we can load certificates from read-only
files (fix bug #79616). Refactored to avoid code duplication.
2006-08-08 Sebastien Pouliot <sebastien@ximian.com>
* X509Certificate.cs: A unrequired password can be supplied to the
2.0 ctors.
2006-07-31 Atsushi Enomoto <atsushi@ximian.com>
* X509Certificate.cs :
In 2.0 IntPtr constructor reject IntPtr.Zero as invalid handle.
In 2.0 copy constructor rejects null argument.
Equals() should return false if the argument cert is null.
Also if both x509 and raw data are null it caused NRE.
2005-11-09 Sebastien Pouliot <sebastien@ximian.com>
* X509ContentType.cs: Removed extra [Serializable] (2.0).
2005-09-25 Sebastien Pouliot <sebastien@ximian.com>
* X509Certificate.cs: Fix date/time reporting for NET_2_0 profile (bug
fixed in 2.0).
2005-04-27 Sebastien Pouliot <sebastien@ximian.com>
* X509Certificate.cs: Updated features for 2.0.
2005-04-24 Sebastien Pouliot <sebastien@ximian.com>
* X509Certificate.cs: Add [ComVisible (true)] to class, add new Issuer
and Subject properties. Removed some [ComVisible (false)] on methods.
* X509ContentType.cs: Add [ComVisible (true)] to enum.
* X509KeyStorageFlags.cs: Add [ComVisible (true)] to enum.
2005-03-24 Sebastien Pouliot <sebastien@ximian.com>
* X509Certificate.cs: Added Demand for UnmanagedCode to ctor(IntPtr).
Return "empty" certificate when IntPtr.Zero is used with ctor(IntPtr).
Don't wrap SecurityException inside COMException for Authenticode.
2004-11-30 Sebastien Pouliot <sebastien@ximian.com>
* X509Certificate.cs: Added ComVisible attributes to match 2.0 October
Preview. Prepared Import and Export to be plugged with PKCS#12 code.
* X509ContentType.cs: Fixed typo (dnd) in comments.
2004-09-07 Sebastien Pouliot <sebastien@ximian.com>
* X509Certificate.cs: CreateFromSignedFile now throw the COMException
if the specified file isn't signed (before this was done by
AuthenticodeDeformatter). More details are available on failure.
2004-07-08 Sebastien Pouliot <sebastien@ximian.com>
* X509Certificate.cs: Added new Equals(Object). Moved [Serializable]
so it's compiled by all profiles. Added missing MonoTODO.
* X509ContentType.cs: Added new (from 1.2) Pkcs12 enum member. Added
missing [Serializable] attribute.
* X509KeyStorageFlags.cs: Specified all flags values. Added missing
[Serializable] attribute.
2004-07-07 Sebastien Pouliot <sebastien@ximian.com>
* X509Certificate.cs: Fixed NET_2_0 directives.
* X509ContentType.cs: New enum in Fx 2.0.
* X509KeyStorageFlags.cs: New flags in Fx 2.0.
2003-12-15 Sebastien Pouliot <spouliot@videotron.ca>
* X509Certificate.cs: Removed old (commented) Authenticode stuff.
Added new stuff for 1.2 (stub).
2003-10-12 Sebastien Pouliot <spouliot@videotron.ca>
* X509Certificate.cs: Implements CreateFromSignedFile using
Authenticode related classes.
2003-06-02 Sebastien Pouliot <spouliot@videotron.ca>
* X509Certificate.cs: Implements X509Certificate(IntPtr)
constructor for compatibility with CryptoAPI.
2003-04-23 Sebastien Pouliot <spouliot@videotron.ca>
* X509Certificate.cs: Fixed issues for null certificate
(special case where object exists without any certificate)
which made PublisherTest fails.
2003-03-15 Sebastien Pouliot <spouliot@videotron.ca>
* X509Certificate.cs: Now use Mono.Security.X509.X509Certificate.
2003-02-08 Sebastien Pouliot <spouliot@videotron.ca>
* X509Certificate.cs: Changes to refer Mono.Security (for ASN1)
2002-12-27 Sebastien Pouliot <spouliot@videotron.ca>
* ASN1.cs: New. Updated ASN1 classes for X509Certificate that can
now be reused for other tools (like Cert2Spc). Classes are marked
internal so they cannot be reused from outside corlib (for
compatibility with MS implementation).
* X509Certificate.cs: Removed all ASN1 classes from file.
2002-12-26 Sebastien Pouliot <spouliot@videotron.ca>
* X509Certificate.cs: Fixed the date issue (again). Time was
converted to local time then ajusted to Pacific time. Now time
is kept (internally) as UTC and correct (-8) to Pacific when shown.
Changed Authenticode signature detection and removed debugging code.
2002-12-22 Sebastien Pouliot <spouliot@videotron.ca>
* X509Certificate.cs: Completed CreateFromSignedFile. Added a new
internal constructor so Publisher (and the related classes) can
create a X509Certificate object which return null dates (for both
GetEffectiveDateString and GetExpirationDateString methods).
2002-12-15 Sebastien Pouliot <spouliot@videotron.ca>
* X509Certificate.cs: Fixed the date issue. MS implementation always
return the local time for Pacific (GMT-8). Added ToString() and changed
some protected to private to please corcompare.
2002-11-03 Sebastien Pouliot <spouliot@videotron.ca>
* X509Certificate.cs: Updated some DN cases and some minor time issues.
GetEffectiveDateString and GetExpirationDateString still don't match
MS implementation (however they seems, most of the time, to be on par
with the Windows Certificate Viewer - crtmgr.exe).
2002-11-02 Sebastien Pouliot <spouliot@videotron.ca>
* ChangeLog: New. First entry ;-)
* X509Certificates.cs: New. Almost complete - except
CryptoAPI link, CreateFromSignedFile and some date issues.

View File

@@ -0,0 +1,199 @@
using System;
using System.Text;
using System.Runtime.InteropServices;
using XamMac.CoreFoundation;
using MX = Mono.Security.X509;
namespace System.Security.Cryptography.X509Certificates
{
class X509CertificateImplApple : X509CertificateImpl
{
IntPtr handle;
X509CertificateImpl fallback;
public X509CertificateImplApple (IntPtr handle, bool owns)
{
this.handle = handle;
if (!owns)
CFHelpers.CFRetain (handle);
}
public override bool IsValid {
get { return handle != IntPtr.Zero; }
}
public override IntPtr Handle {
get { return handle; }
}
public override IntPtr GetNativeAppleCertificate ()
{
ThrowIfContextInvalid ();
return handle;
}
public override X509CertificateImpl Clone ()
{
ThrowIfContextInvalid ();
return new X509CertificateImplApple (handle, false);
}
[DllImport (CFHelpers.SecurityLibrary)]
extern static IntPtr SecCertificateCopySubjectSummary (IntPtr cert);
[DllImport (CFHelpers.SecurityLibrary)]
extern static IntPtr SecCertificateCopyData (IntPtr cert);
public override byte[] GetRawCertData ()
{
ThrowIfContextInvalid ();
var data = SecCertificateCopyData (handle);
if (data == IntPtr.Zero)
throw new ArgumentException ("Not a valid certificate");
try {
return CFHelpers.FetchDataBuffer (data);
} finally {
CFHelpers.CFRelease (data);
}
}
public string GetSubjectSummary ()
{
ThrowIfContextInvalid ();
IntPtr cfstr = SecCertificateCopySubjectSummary (handle);
string ret = CFHelpers.FetchString (cfstr);
CFHelpers.CFRelease (cfstr);
return ret;
}
protected override byte[] GetCertHash (bool lazy)
{
// FIXME: might just return 'null' when 'lazy' is true.
ThrowIfContextInvalid ();
SHA1 sha = SHA1.Create ();
return sha.ComputeHash (GetRawCertData ());
}
public override bool Equals (X509CertificateImpl other, out bool result)
{
var otherAppleImpl = other as X509CertificateImplApple;
if (otherAppleImpl != null && otherAppleImpl.handle == handle) {
result = true;
return true;
}
result = false;
return false;
}
void MustFallback ()
{
ThrowIfContextInvalid ();
if (fallback != null)
return;
var mxCert = new MX.X509Certificate (GetRawCertData ());
fallback = new X509CertificateImplMono (mxCert);
}
public X509CertificateImpl FallbackImpl {
get {
MustFallback ();
return fallback;
}
}
public override string GetSubjectName (bool legacyV1Mode)
{
return FallbackImpl.GetSubjectName (legacyV1Mode);
}
public override string GetIssuerName (bool legacyV1Mode)
{
return FallbackImpl.GetIssuerName (legacyV1Mode);
}
public override DateTime GetValidFrom ()
{
return FallbackImpl.GetValidFrom ();
}
public override DateTime GetValidUntil ()
{
return FallbackImpl.GetValidUntil ();
}
public override string GetKeyAlgorithm ()
{
return FallbackImpl.GetKeyAlgorithm ();
}
public override byte[] GetKeyAlgorithmParameters ()
{
return FallbackImpl.GetKeyAlgorithmParameters ();
}
public override byte[] GetPublicKey ()
{
return FallbackImpl.GetPublicKey ();
}
public override byte[] GetSerialNumber ()
{
return FallbackImpl.GetSerialNumber ();
}
public override byte[] Export (X509ContentType contentType, byte[] password)
{
ThrowIfContextInvalid ();
switch (contentType) {
case X509ContentType.Cert:
return GetRawCertData ();
case X509ContentType.Pfx: // this includes Pkcs12
// TODO
throw new NotSupportedException ();
case X509ContentType.SerializedCert:
// TODO
throw new NotSupportedException ();
default:
string msg = Locale.GetText ("This certificate format '{0}' cannot be exported.", contentType);
throw new CryptographicException (msg);
}
}
public override string ToString (bool full)
{
ThrowIfContextInvalid ();
if (!full || fallback == null) {
var summary = GetSubjectSummary ();
return string.Format ("[X509Certificate: {0}]", summary);
}
string nl = Environment.NewLine;
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, 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 ();
}
protected override void Dispose (bool disposing)
{
if (handle != IntPtr.Zero){
CFHelpers.CFRelease (handle);
handle = IntPtr.Zero;
}
if (fallback != null) {
fallback.Dispose ();
fallback = null;
}
}
}
}

View File

@@ -0,0 +1,37 @@
using System;
using System.Runtime.InteropServices;
using MX = Mono.Security.X509;
using XamMac.CoreFoundation;
namespace System.Security.Cryptography.X509Certificates
{
static partial class X509Helper
{
public static X509CertificateImpl InitFromHandle (IntPtr handle)
{
return new X509CertificateImplApple (handle, false);
}
static X509CertificateImpl Import (byte[] rawData)
{
var handle = CFHelpers.CreateCertificateFromData (rawData);
if (handle != IntPtr.Zero)
return new X509CertificateImplApple (handle, true);
MX.X509Certificate x509;
try {
x509 = new MX.X509Certificate (rawData);
} catch (Exception e) {
try {
x509 = ImportPkcs12 (rawData, null);
} catch {
string msg = Locale.GetText ("Unable to decode certificate.");
// inner exception is the original (not second) exception
throw new CryptographicException (msg, e);
}
}
return new X509CertificateImplMono (x509);
}
}
}