You've already forked linux-packaging-mono
Imported Upstream version 4.3.2.467
Former-commit-id: 9c2cb47f45fa221e661ab616387c9cda183f283d
This commit is contained in:
@@ -21,12 +21,14 @@
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
#if SECURITY_DEP
|
||||
#if MONO_X509_ALIAS
|
||||
extern alias PrebuiltSystem;
|
||||
#endif
|
||||
|
||||
#if MONOTOUCH || MONODROID
|
||||
using MSX = Mono.Security.X509;
|
||||
#if MONO_X509_ALIAS
|
||||
using XX509CertificateCollection = PrebuiltSystem::System.Security.Cryptography.X509Certificates.X509CertificateCollection;
|
||||
#else
|
||||
extern alias MonoSecurity;
|
||||
using MSX = MonoSecurity::Mono.Security.X509;
|
||||
using XX509CertificateCollection = System.Security.Cryptography.X509Certificates.X509CertificateCollection;
|
||||
#endif
|
||||
|
||||
using System;
|
||||
@@ -44,6 +46,9 @@ namespace System.Security.Cryptography.X509Certificates {
|
||||
[DllImport (SecurityLibrary)]
|
||||
extern static /* OSStatus */ int SecTrustCreateWithCertificates (IntPtr certOrCertArray, IntPtr policies, out IntPtr sectrustref);
|
||||
|
||||
[DllImport (SecurityLibrary)]
|
||||
extern static /* OSStatus */ int SecTrustSetAnchorCertificates (IntPtr /* SecTrustRef */ trust, IntPtr /* CFArrayRef */ anchorCertificates);
|
||||
|
||||
[DllImport (SecurityLibrary)]
|
||||
extern static IntPtr SecPolicyCreateSSL ([MarshalAs (UnmanagedType.I1)] bool server, IntPtr cfStringHostname);
|
||||
|
||||
@@ -56,6 +61,9 @@ namespace System.Security.Cryptography.X509Certificates {
|
||||
[DllImport (CoreFoundationLibrary)]
|
||||
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);
|
||||
|
||||
@@ -92,59 +100,98 @@ 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 (MSX.X509CertificateCollection certificates, string host)
|
||||
public static SecTrustResult TrustEvaluateSsl (XX509CertificateCollection certificates, XX509CertificateCollection anchors, string host)
|
||||
{
|
||||
if (certificates == null)
|
||||
return SecTrustResult.Deny;
|
||||
|
||||
try {
|
||||
return _TrustEvaluateSsl (certificates, host);
|
||||
return _TrustEvaluateSsl (certificates, anchors, host);
|
||||
} catch {
|
||||
return SecTrustResult.Deny;
|
||||
}
|
||||
}
|
||||
|
||||
static SecTrustResult _TrustEvaluateSsl (MSX.X509CertificateCollection certificates, string hostName)
|
||||
|
||||
static SecTrustResult _TrustEvaluateSsl (XX509CertificateCollection certificates, XX509CertificateCollection anchors, string hostName)
|
||||
{
|
||||
int certCount = certificates.Count;
|
||||
int anchorCount = anchors != null ? anchors.Count : 0;
|
||||
IntPtr [] cfDataPtrs = new IntPtr [certCount];
|
||||
IntPtr [] secCerts = new IntPtr [certCount];
|
||||
IntPtr [] cfDataAnchorPtrs = new IntPtr [anchorCount];
|
||||
IntPtr [] secCertAnchors = new IntPtr [anchorCount];
|
||||
IntPtr certArray = IntPtr.Zero;
|
||||
IntPtr anchorArray = IntPtr.Zero;
|
||||
IntPtr sslsecpolicy = IntPtr.Zero;
|
||||
IntPtr host = IntPtr.Zero;
|
||||
IntPtr sectrust = IntPtr.Zero;
|
||||
SecTrustResult result = SecTrustResult.Deny;
|
||||
|
||||
try {
|
||||
for (int i = 0; i < certCount; i++)
|
||||
cfDataPtrs [i] = MakeCFData (certificates [i].RawData);
|
||||
|
||||
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] = GetCertificate (anchors [i], out cfDataAnchorPtrs [i]);
|
||||
if (secCertAnchors [i] == IntPtr.Zero)
|
||||
return SecTrustResult.Deny;
|
||||
}
|
||||
|
||||
certArray = FromIntPtrs (secCerts);
|
||||
|
||||
host = CFStringCreateWithCharacters (IntPtr.Zero, hostName, (IntPtr) hostName.Length);
|
||||
sslsecpolicy = SecPolicyCreateSSL (true, host);
|
||||
|
||||
int code = SecTrustCreateWithCertificates (certArray, sslsecpolicy, out sectrust);
|
||||
if (code == 0)
|
||||
code = SecTrustEvaluate (sectrust, out result);
|
||||
if (code != 0)
|
||||
return SecTrustResult.Deny;
|
||||
|
||||
if (anchorCount > 0) {
|
||||
anchorArray = FromIntPtrs (secCertAnchors);
|
||||
SecTrustSetAnchorCertificates (sectrust, anchorArray);
|
||||
}
|
||||
|
||||
code = SecTrustEvaluate (sectrust, out result);
|
||||
return result;
|
||||
} finally {
|
||||
for (int i = 0; i < certCount; i++)
|
||||
if (cfDataPtrs [i] != IntPtr.Zero)
|
||||
CFRelease (cfDataPtrs [i]);
|
||||
|
||||
for (int i = 0; i < anchorCount; i++)
|
||||
if (cfDataAnchorPtrs [i] != IntPtr.Zero)
|
||||
CFRelease (cfDataAnchorPtrs [i]);
|
||||
|
||||
if (certArray != IntPtr.Zero)
|
||||
CFRelease (certArray);
|
||||
|
||||
if (anchorArray != IntPtr.Zero)
|
||||
CFRelease (anchorArray);
|
||||
|
||||
for (int i = 0; i < certCount; i++)
|
||||
if (secCerts [i] != IntPtr.Zero)
|
||||
CFRelease (secCerts [i]);
|
||||
|
||||
for (int i = 0; i < anchorCount; i++)
|
||||
if (secCertAnchors [i] != IntPtr.Zero)
|
||||
CFRelease (secCertAnchors [i]);
|
||||
|
||||
if (sslsecpolicy != IntPtr.Zero)
|
||||
CFRelease (sslsecpolicy);
|
||||
if (host != IntPtr.Zero)
|
||||
|
||||
@@ -31,15 +31,15 @@
|
||||
|
||||
#if SECURITY_DEP
|
||||
|
||||
#if MONOTOUCH || MONODROID
|
||||
using Mono.Security;
|
||||
using Mono.Security.Cryptography;
|
||||
using MSX = Mono.Security.X509;
|
||||
#else
|
||||
#if MONO_SECURITY_ALIAS
|
||||
extern alias MonoSecurity;
|
||||
using MonoSecurity::Mono.Security;
|
||||
using MonoSecurity::Mono.Security.Cryptography;
|
||||
using MSX = MonoSecurity::Mono.Security.X509;
|
||||
#else
|
||||
using Mono.Security;
|
||||
using Mono.Security.Cryptography;
|
||||
using MSX = Mono.Security.X509;
|
||||
#endif
|
||||
|
||||
namespace System.Security.Cryptography.X509Certificates {
|
||||
|
||||
@@ -28,13 +28,13 @@
|
||||
|
||||
#if SECURITY_DEP
|
||||
|
||||
#if MONOTOUCH || MONODROID
|
||||
using Mono.Security;
|
||||
using MX = Mono.Security.X509;
|
||||
#else
|
||||
#if MONO_SECURITY_ALIAS
|
||||
extern alias MonoSecurity;
|
||||
using MonoSecurity::Mono.Security;
|
||||
using MX = MonoSecurity::Mono.Security.X509;
|
||||
#else
|
||||
using Mono.Security;
|
||||
using MX = Mono.Security.X509;
|
||||
#endif
|
||||
|
||||
using System.Collections;
|
||||
|
||||
@@ -31,11 +31,11 @@
|
||||
|
||||
#if SECURITY_DEP
|
||||
|
||||
#if MONOTOUCH || MONODROID
|
||||
using Mono.Security;
|
||||
#else
|
||||
#if MONO_SECURITY_ALIAS
|
||||
extern alias MonoSecurity;
|
||||
using MonoSecurity::Mono.Security;
|
||||
#else
|
||||
using Mono.Security;
|
||||
#endif
|
||||
|
||||
using System.Text;
|
||||
|
||||
@@ -29,22 +29,22 @@
|
||||
|
||||
#if SECURITY_DEP
|
||||
|
||||
#if MONOTOUCH || MONODROID
|
||||
using Mono.Security;
|
||||
using Mono.Security.Cryptography;
|
||||
using MX = Mono.Security.X509;
|
||||
#else
|
||||
#if MONO_SECURITY_ALIAS
|
||||
extern alias MonoSecurity;
|
||||
|
||||
using MonoSecurity::Mono.Security;
|
||||
using MonoSecurity::Mono.Security.Cryptography;
|
||||
using MX = MonoSecurity::Mono.Security.X509;
|
||||
#else
|
||||
using Mono.Security;
|
||||
using Mono.Security.Cryptography;
|
||||
using MX = Mono.Security.X509;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
|
||||
namespace System.Security.Cryptography.X509Certificates {
|
||||
|
||||
@@ -534,6 +534,47 @@ namespace System.Security.Cryptography.X509Certificates {
|
||||
Import (rawData, (string)null, keyStorageFlags);
|
||||
}
|
||||
|
||||
[MonoTODO ("X509ContentType.SerializedCert is not supported")]
|
||||
public override byte[] Export (X509ContentType contentType, string password)
|
||||
{
|
||||
if (_cert == null)
|
||||
throw new CryptographicException (empty_error);
|
||||
|
||||
switch (contentType) {
|
||||
case X509ContentType.Cert:
|
||||
return _cert.RawData;
|
||||
case X509ContentType.Pfx: // this includes Pkcs12
|
||||
return ExportPkcs12 (password);
|
||||
case X509ContentType.SerializedCert:
|
||||
// TODO
|
||||
throw new NotSupportedException ();
|
||||
default:
|
||||
string msg = Locale.GetText ("This certificate format '{0}' cannot be exported.", contentType);
|
||||
throw new CryptographicException (msg);
|
||||
}
|
||||
}
|
||||
|
||||
byte[] ExportPkcs12 (string password)
|
||||
{
|
||||
var pfx = new MX.PKCS12 ();
|
||||
try {
|
||||
var attrs = new Hashtable ();
|
||||
var localKeyId = new ArrayList ();
|
||||
localKeyId.Add (new byte[] { 1, 0, 0, 0 });
|
||||
attrs.Add (MX.PKCS9.localKeyId, localKeyId);
|
||||
|
||||
if (password != null)
|
||||
pfx.Password = password;
|
||||
pfx.AddCertificate (_cert, attrs);
|
||||
var privateKey = PrivateKey;
|
||||
if (privateKey != null)
|
||||
pfx.AddPkcs8ShroudedKeyBag (privateKey, attrs);
|
||||
return pfx.GetBytes ();
|
||||
} finally {
|
||||
pfx.Password = null;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Reset ()
|
||||
{
|
||||
_cert = null;
|
||||
|
||||
@@ -30,11 +30,11 @@
|
||||
|
||||
#if SECURITY_DEP
|
||||
|
||||
#if MONOTOUCH || MONODROID
|
||||
using MX = Mono.Security.X509;
|
||||
#else
|
||||
#if MONO_SECURITY_ALIAS
|
||||
extern alias MonoSecurity;
|
||||
using MX = MonoSecurity::Mono.Security.X509;
|
||||
#else
|
||||
using MX = Mono.Security.X509;
|
||||
#endif
|
||||
|
||||
using System.Collections;
|
||||
|
||||
@@ -28,11 +28,11 @@
|
||||
|
||||
#if SECURITY_DEP
|
||||
|
||||
#if MONOTOUCH || MONODROID
|
||||
using Mono.Security;
|
||||
#else
|
||||
#if MONO_SECURITY_ALIAS
|
||||
extern alias MonoSecurity;
|
||||
using MonoSecurity::Mono.Security;
|
||||
#else
|
||||
using Mono.Security;
|
||||
#endif
|
||||
|
||||
using System.Text;
|
||||
|
||||
@@ -31,13 +31,13 @@
|
||||
|
||||
#if SECURITY_DEP
|
||||
|
||||
#if MONOTOUCH || MONODROID
|
||||
using Mono.Security;
|
||||
using MX = Mono.Security.X509;
|
||||
#else
|
||||
#if MONO_SECURITY_ALIAS
|
||||
extern alias MonoSecurity;
|
||||
using MonoSecurity::Mono.Security;
|
||||
using MX = MonoSecurity::Mono.Security.X509;
|
||||
#else
|
||||
using Mono.Security;
|
||||
using MX = Mono.Security.X509;
|
||||
#endif
|
||||
|
||||
using System.Collections;
|
||||
|
||||
@@ -30,11 +30,11 @@
|
||||
|
||||
#if SECURITY_DEP
|
||||
|
||||
#if MONOTOUCH || MONODROID
|
||||
using Mono.Security;
|
||||
#else
|
||||
#if MONO_SECURITY_ALIAS
|
||||
extern alias MonoSecurity;
|
||||
using MonoSecurity::Mono.Security;
|
||||
#else
|
||||
using Mono.Security;
|
||||
#endif
|
||||
|
||||
using System.Text;
|
||||
|
||||
@@ -29,11 +29,11 @@
|
||||
|
||||
#if SECURITY_DEP
|
||||
|
||||
#if MONOTOUCH || MONODROID
|
||||
using MX = Mono.Security.X509;
|
||||
#else
|
||||
#if MONO_SECURITY_ALIAS
|
||||
extern alias MonoSecurity;
|
||||
using MX = MonoSecurity::Mono.Security.X509;
|
||||
#else
|
||||
using MX = Mono.Security.X509;
|
||||
#endif
|
||||
|
||||
using System.Security.Permissions;
|
||||
|
||||
@@ -30,13 +30,13 @@
|
||||
|
||||
#if SECURITY_DEP
|
||||
|
||||
#if MONOTOUCH || MONODROID
|
||||
using Mono.Security;
|
||||
using Mono.Security.Cryptography;
|
||||
#else
|
||||
#if MONO_SECURITY_ALIAS
|
||||
extern alias MonoSecurity;
|
||||
using MonoSecurity::Mono.Security;
|
||||
using MonoSecurity::Mono.Security.Cryptography;
|
||||
#else
|
||||
using Mono.Security;
|
||||
using Mono.Security.Cryptography;
|
||||
#endif
|
||||
|
||||
using System.Text;
|
||||
|
||||
Reference in New Issue
Block a user