Imported Upstream version 4.4.0.182

Former-commit-id: ea38b2115ac3af9a394fe6cddf2be2acd11bc002
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2016-06-14 09:39:34 +00:00
parent ee13743634
commit 180e8b1935
125 changed files with 1658 additions and 521 deletions

View File

@ -148,34 +148,46 @@ namespace System.Security.Cryptography.X509Certificates
}
}
#if !MONOTOUCH && !XAMMAC
public static X509CertificateImpl Import (byte[] rawData, string password, X509KeyStorageFlags keyStorageFlags)
static byte[] PEM (string type, byte[] data)
{
if (nativeHelper != null)
return nativeHelper.Import (rawData, password, keyStorageFlags);
string pem = Encoding.ASCII.GetString (data);
string header = String.Format ("-----BEGIN {0}-----", type);
string footer = String.Format ("-----END {0}-----", type);
int start = pem.IndexOf (header) + header.Length;
int end = pem.IndexOf (footer, start);
string base64 = pem.Substring (start, (end - start));
return Convert.FromBase64String (base64);
}
static byte[] ConvertData (byte[] data)
{
if (data == null || data.Length == 0)
return data;
// does it looks like PEM ?
if (data [0] != 0x30) {
try {
return PEM ("CERTIFICATE", data);
} catch {
// let the implementation take care of it.
}
}
return data;
}
#if !MONOTOUCH && !XAMMAC
static X509CertificateImpl Import (byte[] rawData)
{
MX.X509Certificate x509;
if (password == null) {
try {
x509 = new MX.X509Certificate (rawData);
} catch (Exception e) {
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);
}
}
} else {
// try PKCS#12
try {
x509 = ImportPkcs12 (rawData, password);
}
catch {
// it's possible to supply a (unrequired/unusued) password
// fix bug #79028
x509 = new MX.X509Certificate (rawData);
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);
}
}
@ -183,6 +195,26 @@ namespace System.Security.Cryptography.X509Certificates
}
#endif
public static X509CertificateImpl Import (byte[] rawData, string password, X509KeyStorageFlags keyStorageFlags)
{
if (password == null) {
rawData = ConvertData (rawData);
return Import (rawData);
}
MX.X509Certificate x509;
// try PKCS#12
try {
x509 = ImportPkcs12 (rawData, password);
} catch {
// it's possible to supply a (unrequired/unusued) password
// fix bug #79028
x509 = new MX.X509Certificate (rawData);
}
return new X509CertificateImplMono (x509);
}
public static byte[] Export (X509CertificateImpl impl, X509ContentType contentType, byte[] password)
{
ThrowIfContextInvalid (impl);