Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Baulig <mabaul@microsoft.com>2019-06-07 20:13:48 +0300
committerGitHub <noreply@github.com>2019-06-07 20:13:48 +0300
commitac908dd334e122e98e063a5c50a3ee66aa245cd7 (patch)
tree56bea7f73c64b11a7abbc334efba8783045f90d2 /mcs/class/System
parent277bbdaada789bb9b61a71aa45475d914b457494 (diff)
Implement RSACertificateExtensions.CopyWithPrivateKey(). #14152. (#14860)
* Implement RSACertificateExtensions.CopyWithPrivateKey(). #14152. * RSACertificateExtensions.CopyWithPrivateKey(): implement. Since `RSACertificateExtensions` lives in `System.Core` and only `mscorlib` internals (but not `System` internals) are visible to it, we need to use a little trick here: * System.Security.Cryptography.X509Certificates.X509CertificateImpl: add new abstract methods CopyWithPrivateKey() and CreateCertificate(). * System.Security.Cryptography.X509Certificates.X509Certificate2Impl: sealed implement them here. The `httpcfg` tool, only checks whether the key is valid, so we don't really need to call `CopyWithPrivateKey()` (which requires us to take a dependency on `System.Core`). * Do the same thing in HttpListener.
Diffstat (limited to 'mcs/class/System')
-rw-r--r--mcs/class/System/System.Net/HttpListener.Mono.cs4
-rw-r--r--mcs/class/System/System.Security.Cryptography.X509Certificates/X509Certificate2Impl.cs12
2 files changed, 14 insertions, 2 deletions
diff --git a/mcs/class/System/System.Net/HttpListener.Mono.cs b/mcs/class/System/System.Net/HttpListener.Mono.cs
index 5e673b9d5f0..c95c725ade9 100644
--- a/mcs/class/System/System.Net/HttpListener.Mono.cs
+++ b/mcs/class/System/System.Net/HttpListener.Mono.cs
@@ -80,8 +80,8 @@ namespace System.Net {
if (!File.Exists (pvk_file))
return null;
var cert = new X509Certificate2 (cert_file);
- cert.PrivateKey = PrivateKey.CreateFromFile (pvk_file).RSA;
- certificate = cert;
+ var privateKey = PrivateKey.CreateFromFile (pvk_file).RSA;
+ certificate = new X509Certificate2 ((X509Certificate2Impl)cert.Impl.CopyWithPrivateKey (privateKey));
return certificate;
} catch {
// ignore errors
diff --git a/mcs/class/System/System.Security.Cryptography.X509Certificates/X509Certificate2Impl.cs b/mcs/class/System/System.Security.Cryptography.X509Certificates/X509Certificate2Impl.cs
index a454ea07ada..6c6ad684a34 100644
--- a/mcs/class/System/System.Security.Cryptography.X509Certificates/X509Certificate2Impl.cs
+++ b/mcs/class/System/System.Security.Cryptography.X509Certificates/X509Certificate2Impl.cs
@@ -83,6 +83,18 @@ namespace System.Security.Cryptography.X509Certificates
public abstract void AppendPrivateKeyInfo (StringBuilder sb);
+ public sealed override X509CertificateImpl CopyWithPrivateKey (RSA privateKey)
+ {
+ var impl = (X509Certificate2Impl)Clone ();
+ impl.PrivateKey = privateKey;
+ return impl;
+ }
+
+ public sealed override X509Certificate CreateCertificate ()
+ {
+ return new X509Certificate2 (this);
+ }
+
public abstract void Reset ();
}
}