Imported Upstream version 6.0.0.172

Former-commit-id: f3cc9b82f3e5bd8f0fd3ebc098f789556b44e9cd
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2019-04-12 14:10:50 +00:00
parent 8016999e4d
commit 64ac736ec5
32155 changed files with 3981439 additions and 75368 deletions

View File

@@ -50,7 +50,7 @@ namespace Mono.AppleTls
SafeSecIdentityHandle serverIdentity;
SafeSecIdentityHandle clientIdentity;
X509Certificate remoteCertificate;
X509Certificate2 remoteCertificate;
X509Certificate localClientCertificate;
MonoTlsConnectionInfo connectionInfo;
bool isAuthenticated;
@@ -247,7 +247,7 @@ namespace Mono.AppleTls
bool ok;
SecTrust trust = null;
X509CertificateCollection certificates = null;
X509Certificate2Collection certificates = null;
try {
trust = GetPeerTrust (!IsServer);
@@ -261,18 +261,18 @@ namespace Mono.AppleTls
if (trust.Count > 1)
Debug ("WARNING: Got multiple certificates in SecTrust!");
certificates = new X509CertificateCollection ();
certificates = new X509Certificate2Collection ();
for (int i = 0; i < trust.Count; i++)
certificates.Add (trust.GetCertificate (i));
remoteCertificate = new X509Certificate (certificates [0]);
remoteCertificate = new X509Certificate2 (certificates [0]);
Debug ("Got peer trust: {0}", remoteCertificate);
}
ok = ValidateCertificate (certificates);
} catch (Exception ex) {
Debug ("Certificate validation failed: {0}", ex);
throw new TlsException (AlertDescription.CertificateUnknown, "Certificate validation threw exception.");
throw;
} finally {
if (trust != null)
trust.Dispose ();
@@ -395,7 +395,7 @@ namespace Mono.AppleTls
get { return localClientCertificate; }
}
public override X509Certificate RemoteCertificate {
public override X509Certificate2 RemoteCertificate {
get { return remoteCertificate; }
}

View File

@@ -1,5 +1,6 @@
// Copyright 2011-2015 Xamarin Inc. All rights reserved.
using System;
using ObjCRuntimeInternal;
namespace Mono.AppleTls {
@@ -309,10 +310,8 @@ namespace Mono.AppleTls {
VerifyActionFailed = -67825, /* A verify action has failed. */
InvalidCertAuthority = -67826, /* The certificate authority was not valid. */
InvalidCRLAuthority = -67827, /* The CRL authority was not valid. */
#if MONOMAC
[Obsolete ("Use InvalidCRLAuthority")]
InvaldCRLAuthority = InvalidCRLAuthority,
#endif
InvalidCRLEncoding = -67828, /* The CRL encoding was not valid. */
InvalidCRLType = -67829, /* The CRL type was not valid. */
InvalidCRL = -67830, /* The CRL was not valid. */
@@ -338,10 +337,8 @@ namespace Mono.AppleTls {
InvalidTupleGroup = -67850, /* The tuple group was not valid. */
InvalidBaseACLs = -67851, /* The base ACLs are not valid. */
InvalidTupleCredentials = -67852, /* The tuple credentials are not valid. */
#if MONOMAC
[Obsolete ("Use InvalidTupleCredentials")]
InvalidTupleCredendtials = InvalidTupleCredentials,
#endif
InvalidEncoding = -67853, /* The encoding was not valid. */
InvalidValidityPeriod = -67854, /* The validity period was not valid. */
InvalidRequestor = -67855, /* The requestor was not valid. */

View File

@@ -115,7 +115,7 @@ namespace Mono.AppleTls {
[DllImport (AppleTlsContext.SecurityLibrary)]
extern static IntPtr /* SecCertificateRef */ SecTrustGetCertificateAtIndex (IntPtr /* SecTrustRef */ trust, IntPtr /* CFIndex */ ix);
internal X509Certificate GetCertificate (int index)
internal X509Certificate2 GetCertificate (int index)
{
if (handle == IntPtr.Zero)
throw new ObjectDisposedException ("SecTrust");
@@ -124,7 +124,7 @@ namespace Mono.AppleTls {
var ptr = SecTrustGetCertificateAtIndex (handle, (IntPtr)index);
var impl = new X509CertificateImplApple (ptr, false);
return new X509Certificate (impl);
return new X509Certificate2 (impl);
}
[DllImport (AppleTlsContext.SecurityLibrary)]

View File

@@ -1,4 +1,3 @@
#if MONO_FEATURE_APPLETLS || MONO_FEATURE_APPLE_X509
#if MONO_SECURITY_ALIAS
extern alias MonoSecurity;
#endif
@@ -19,7 +18,7 @@ using XamMac.CoreFoundation;
namespace Mono.AppleTls
{
class X509CertificateImplApple : X509CertificateImpl
class X509CertificateImplApple : X509Certificate2ImplUnix
{
IntPtr handle;
X509CertificateImpl fallback;
@@ -57,18 +56,17 @@ namespace Mono.AppleTls
[DllImport (CFHelpers.SecurityLibrary)]
extern static IntPtr SecCertificateCopyData (IntPtr cert);
public override byte[] RawData {
get {
ThrowIfContextInvalid ();
var data = SecCertificateCopyData (handle);
if (data == IntPtr.Zero)
throw new ArgumentException ("Not a valid certificate");
protected 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);
}
try {
return CFHelpers.FetchDataBuffer (data);
} finally {
CFHelpers.CFRelease (data);
}
}
@@ -81,15 +79,6 @@ namespace Mono.AppleTls
return ret;
}
public override byte[] Thumbprint {
get {
// FIXME: might just return 'null' when 'lazy' is true.
ThrowIfContextInvalid ();
SHA1 sha = SHA1.Create ();
return sha.ComputeHash (RawData);
}
}
public override bool Equals (X509CertificateImpl other, out bool result)
{
var otherAppleImpl = other as X509CertificateImplApple;
@@ -111,52 +100,43 @@ namespace Mono.AppleTls
fallback = new X509Certificate2ImplMono (mxCert);
}
public X509CertificateImpl FallbackImpl {
get {
MustFallback ();
return fallback;
}
#region X509Certificate2Impl implementation
/*
* The AppleTls backend does not support X509Certificate2 yet, so we can safely throw
* PlatformNotSupportedException here.
*/
public override bool HasPrivateKey => throw new PlatformNotSupportedException ();
public override AsymmetricAlgorithm PrivateKey {
get => throw new PlatformNotSupportedException ();
set => throw new PlatformNotSupportedException ();
}
public override string Subject => FallbackImpl.Subject;
public override string Issuer => FallbackImpl.Issuer;
public override string LegacySubject => FallbackImpl.LegacySubject;
public override string LegacyIssuer => FallbackImpl.LegacyIssuer;
public override DateTime NotAfter => FallbackImpl.NotAfter;
public override DateTime NotBefore => FallbackImpl.NotBefore;
public override string KeyAlgorithm => FallbackImpl.KeyAlgorithm;
public override byte[] KeyAlgorithmParameters => FallbackImpl.KeyAlgorithmParameters;
public override byte[] PublicKeyValue => FallbackImpl.PublicKeyValue;
public override byte[] SerialNumber => FallbackImpl.SerialNumber;
public override byte[] Export (X509ContentType contentType, SafePasswordHandle password)
public override RSA GetRSAPrivateKey ()
{
ThrowIfContextInvalid ();
switch (contentType) {
case X509ContentType.Cert:
return RawData;
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);
}
throw new PlatformNotSupportedException ();
}
public override DSA GetDSAPrivateKey ()
{
throw new PlatformNotSupportedException ();
}
public override PublicKey PublicKey => throw new PlatformNotSupportedException ();
internal override X509CertificateImplCollection IntermediateCertificates => throw new PlatformNotSupportedException ();
internal override X509Certificate2Impl FallbackImpl => throw new PlatformNotSupportedException ();
public override bool Verify (X509Certificate2 thisCertificate)
{
throw new PlatformNotSupportedException ();
}
#endregion
protected override void Dispose (bool disposing)
{
if (handle != IntPtr.Zero){
@@ -170,4 +150,3 @@ namespace Mono.AppleTls
}
}
}
#endif