You've already forked linux-packaging-mono
Imported Upstream version 4.8.0.459
Former-commit-id: 2a5b9df2014f72665850c7f885e7aed54704a53a
This commit is contained in:
parent
a355c1b831
commit
e5cd25ff4f
@@ -48,6 +48,10 @@ namespace Mono.Btls
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[DllImport (BTLS_DYLIB)]
|
||||
extern static IntPtr mono_btls_key_new ();
|
||||
|
||||
[DllImport (BTLS_DYLIB)]
|
||||
extern static void mono_btls_key_free (IntPtr handle);
|
||||
|
||||
@@ -63,6 +67,9 @@ namespace Mono.Btls
|
||||
[DllImport (BTLS_DYLIB)]
|
||||
extern static int mono_btls_key_is_rsa (IntPtr handle);
|
||||
|
||||
[DllImport (BTLS_DYLIB)]
|
||||
extern static int mono_btls_key_assign_rsa_private_key (IntPtr handle, byte[] der, int der_length);
|
||||
|
||||
new internal BoringKeyHandle Handle {
|
||||
get { return (BoringKeyHandle)base.Handle; }
|
||||
}
|
||||
@@ -99,6 +106,18 @@ namespace Mono.Btls
|
||||
CheckError (copy != IntPtr.Zero);
|
||||
return new MonoBtlsKey (new BoringKeyHandle (copy));
|
||||
}
|
||||
|
||||
public static MonoBtlsKey CreateFromRSAPrivateKey (System.Security.Cryptography.RSA privateKey)
|
||||
{
|
||||
var keyData = Mono.Security.Cryptography.PKCS8.PrivateKeyInfo.Encode (privateKey);
|
||||
var key = new MonoBtlsKey (new BoringKeyHandle (mono_btls_key_new ()));
|
||||
|
||||
var ret = mono_btls_key_assign_rsa_private_key (key.Handle.DangerousGetHandle (), keyData, keyData.Length);
|
||||
if (ret == 0)
|
||||
throw new MonoBtlsException ("Assigning private key failed.");
|
||||
|
||||
return key;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -218,12 +218,10 @@ namespace Mono.Btls
|
||||
|
||||
public static string GetSystemStoreLocation ()
|
||||
{
|
||||
#if ANDROID
|
||||
#if MONODROID
|
||||
return "/system/etc/security/cacerts";
|
||||
#else
|
||||
var appData = Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData);
|
||||
var path = Path.Combine (appData, ".mono", "certs", "NewTrust");
|
||||
return path;
|
||||
return MonoBtlsX509StoreManager.GetStorePath (MonoBtlsX509StoreType.MachineTrustedRoots);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace Mono.Btls
|
||||
static class MonoBtlsX509StoreManager
|
||||
{
|
||||
static bool initialized;
|
||||
#if !ANDROID
|
||||
#if !MONODROID
|
||||
static string machineTrustedRootPath;
|
||||
static string machineIntermediateCAPath;
|
||||
static string machineUntrustedPath;
|
||||
@@ -70,7 +70,7 @@ namespace Mono.Btls
|
||||
|
||||
static void DoInitialize ()
|
||||
{
|
||||
#if !ANDROID
|
||||
#if !MONODROID
|
||||
var userPath = MX.X509StoreManager.NewCurrentUserPath;
|
||||
userTrustedRootPath = Path.Combine (userPath, MX.X509Stores.Names.TrustedRoot);
|
||||
userIntermediateCAPath = Path.Combine (userPath, MX.X509Stores.Names.IntermediateCA);
|
||||
@@ -85,7 +85,7 @@ namespace Mono.Btls
|
||||
|
||||
public static bool HasStore (MonoBtlsX509StoreType type)
|
||||
{
|
||||
#if ANDROID
|
||||
#if MONODROID
|
||||
return false;
|
||||
#else
|
||||
var path = GetStorePath (type);
|
||||
@@ -95,7 +95,7 @@ namespace Mono.Btls
|
||||
|
||||
public static string GetStorePath (MonoBtlsX509StoreType type)
|
||||
{
|
||||
#if ANDROID
|
||||
#if MONODROID
|
||||
throw new NotSupportedException ();
|
||||
#else
|
||||
Initialize ();
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace Mono.Btls
|
||||
class X509CertificateImplBtls : X509Certificate2Impl
|
||||
{
|
||||
MonoBtlsX509 x509;
|
||||
MonoBtlsKey privateKey;
|
||||
MonoBtlsKey nativePrivateKey;
|
||||
X500DistinguishedName subjectName;
|
||||
X500DistinguishedName issuerName;
|
||||
X509CertificateImplCollection intermediateCerts;
|
||||
@@ -70,7 +70,8 @@ namespace Mono.Btls
|
||||
{
|
||||
disallowFallback = other.disallowFallback;
|
||||
x509 = other.x509 != null ? other.x509.Copy () : null;
|
||||
privateKey = other.privateKey != null ? other.privateKey.Copy () : null;
|
||||
nativePrivateKey = other.nativePrivateKey != null ? other.nativePrivateKey.Copy () : null;
|
||||
fallback = other.fallback != null ? (X509Certificate2Impl)other.fallback.Clone () : null;
|
||||
if (other.intermediateCerts != null)
|
||||
intermediateCerts = other.intermediateCerts.Clone ();
|
||||
}
|
||||
@@ -104,7 +105,13 @@ namespace Mono.Btls
|
||||
internal MonoBtlsKey NativePrivateKey {
|
||||
get {
|
||||
ThrowIfContextInvalid ();
|
||||
return privateKey;
|
||||
if (nativePrivateKey == null && FallbackImpl.HasPrivateKey) {
|
||||
var key = FallbackImpl.PrivateKey as RSA;
|
||||
if (key == null)
|
||||
throw new NotSupportedException ("Currently only supports RSA private keys.");
|
||||
nativePrivateKey = MonoBtlsKey.CreateFromRSAPrivateKey (key);
|
||||
}
|
||||
return nativePrivateKey;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -270,7 +277,7 @@ namespace Mono.Btls
|
||||
}
|
||||
|
||||
public override bool HasPrivateKey {
|
||||
get { return privateKey != null; }
|
||||
get { return nativePrivateKey != null || FallbackImpl.HasPrivateKey; }
|
||||
}
|
||||
|
||||
public override X500DistinguishedName IssuerName {
|
||||
@@ -290,12 +297,15 @@ namespace Mono.Btls
|
||||
|
||||
public override AsymmetricAlgorithm PrivateKey {
|
||||
get {
|
||||
if (privateKey == null || !privateKey.IsRsa)
|
||||
return null;
|
||||
var bytes = privateKey.GetBytes (true);
|
||||
if (nativePrivateKey == null || !nativePrivateKey.IsRsa)
|
||||
return FallbackImpl.PrivateKey;
|
||||
var bytes = nativePrivateKey.GetBytes (true);
|
||||
return PKCS8.PrivateKeyInfo.DecodeRSA (bytes);
|
||||
}
|
||||
set { FallbackImpl.PrivateKey = value; }
|
||||
set {
|
||||
nativePrivateKey = null;
|
||||
FallbackImpl.PrivateKey = value;
|
||||
}
|
||||
}
|
||||
|
||||
public override PublicKey PublicKey {
|
||||
@@ -343,6 +353,7 @@ namespace Mono.Btls
|
||||
|
||||
public override void Import (byte[] data, string password, X509KeyStorageFlags keyStorageFlags)
|
||||
{
|
||||
Reset ();
|
||||
if (password == null) {
|
||||
try {
|
||||
Import (data);
|
||||
@@ -399,7 +410,7 @@ namespace Mono.Btls
|
||||
|
||||
x509 = pkcs12.GetCertificate (0);
|
||||
if (pkcs12.HasPrivateKey)
|
||||
privateKey = pkcs12.GetPrivateKey ();
|
||||
nativePrivateKey = pkcs12.GetPrivateKey ();
|
||||
if (pkcs12.Count > 1) {
|
||||
intermediateCerts = new X509CertificateImplCollection ();
|
||||
for (int i = 0; i < pkcs12.Count; i++) {
|
||||
@@ -476,9 +487,8 @@ namespace Mono.Btls
|
||||
x509.Dispose ();
|
||||
x509 = null;
|
||||
}
|
||||
if (privateKey != null) {
|
||||
privateKey = null;
|
||||
privateKey = null;
|
||||
if (nativePrivateKey != null) {
|
||||
nativePrivateKey = null;
|
||||
}
|
||||
subjectName = null;
|
||||
issuerName = null;
|
||||
|
||||
Reference in New Issue
Block a user