You've already forked linux-packaging-mono
Imported Upstream version 4.8.0.309
Former-commit-id: 5f9c6ae75f295e057a7d2971f3a6df4656fa8850
This commit is contained in:
parent
ee1447783b
commit
94b2861243
@@ -60,14 +60,9 @@ using System.Runtime.InteropServices;
|
||||
[assembly: AssemblyDelaySign (true)]
|
||||
[assembly: AssemblyKeyFile ("../mono.pub")]
|
||||
|
||||
#if NET_2_1
|
||||
#if MOBILE
|
||||
[assembly: InternalsVisibleTo ("System, PublicKey=00240000048000009400000006020000002400005253413100040000010001008D56C76F9E8649383049F383C44BE0EC204181822A6C31CF5EB7EF486944D032188EA1D3920763712CCB12D75FB77E9811149E6148E5D32FBAAB37611C1878DDC19E20EF135D0CB2CFF2BFEC3D115810C3D9069638FE4BE215DBF795861920E5AB6F7DB2E2CEEF136AC23D5DD2BF031700AEC232F6C6B1C785B4305C123B37AB")]
|
||||
#else
|
||||
[assembly: InternalsVisibleTo ("System, PublicKey=00000000000000000400000000000000")]
|
||||
#endif
|
||||
|
||||
[assembly: InternalsVisibleTo ("Mono.Security.Providers.NewTls, PublicKey=002400000480000094000000060200000024000052534131000400000100010079159977d2d03a8e6bea7a2e74e8d1afcc93e8851974952bb480a12c9134474d04062447c37e0e68c080536fcf3c3fbe2ff9c979ce998475e506e8ce82dd5b0f350dc10e93bf2eeecf874b24770c5081dbea7447fddafa277b22de47d6ffea449674a4f9fccf84d15069089380284dbdd35f46cdff12a1bd78e4ef0065d016df")]
|
||||
[assembly: InternalsVisibleTo ("Mono.Security.Providers.OldTls, PublicKey=002400000480000094000000060200000024000052534131000400000100010079159977d2d03a8e6bea7a2e74e8d1afcc93e8851974952bb480a12c9134474d04062447c37e0e68c080536fcf3c3fbe2ff9c979ce998475e506e8ce82dd5b0f350dc10e93bf2eeecf874b24770c5081dbea7447fddafa277b22de47d6ffea449674a4f9fccf84d15069089380284dbdd35f46cdff12a1bd78e4ef0065d016df")]
|
||||
[assembly: InternalsVisibleTo ("Mono.Security.Providers.DotNet, PublicKey=002400000480000094000000060200000024000052534131000400000100010079159977d2d03a8e6bea7a2e74e8d1afcc93e8851974952bb480a12c9134474d04062447c37e0e68c080536fcf3c3fbe2ff9c979ce998475e506e8ce82dd5b0f350dc10e93bf2eeecf874b24770c5081dbea7447fddafa277b22de47d6ffea449674a4f9fccf84d15069089380284dbdd35f46cdff12a1bd78e4ef0065d016df")]
|
||||
[assembly: InternalsVisibleTo ("Mono.Security.Providers.NewSystemSource, PublicKey=002400000480000094000000060200000024000052534131000400000100010079159977d2d03a8e6bea7a2e74e8d1afcc93e8851974952bb480a12c9134474d04062447c37e0e68c080536fcf3c3fbe2ff9c979ce998475e506e8ce82dd5b0f350dc10e93bf2eeecf874b24770c5081dbea7447fddafa277b22de47d6ffea449674a4f9fccf84d15069089380284dbdd35f46cdff12a1bd78e4ef0065d016df")]
|
||||
[assembly: InternalsVisibleTo ("Xamarin.BoringTls, PublicKey=002400000480000094000000060200000024000052534131000400001100000099dd12eda85767ae6f06023ee28e711c7e5a212462095c83868c29db75eddf6d8e296e03824c14fedd5f55553fed0b6173be3cc985a4b7f9fb7c83ccff8ba3938563b3d1f45a81122f12a1bcb73edcaad61a8456c7595a6da5184b4dd9d10f011b949ef1391fccfeab1ba62aa51c267ef8bd57ef1b6ba5a4c515d0badb81a78f")]
|
||||
|
||||
@@ -103,13 +103,6 @@ namespace Mono.Security.Interface
|
||||
* Internal use only.
|
||||
*/
|
||||
ValidationResult ValidateCertificate (string targetHost, bool serverMode, X509Certificate leaf, X509Chain chain);
|
||||
|
||||
/*
|
||||
* On OS X and Mobile, the @chain will be initialized with the @certificates, but not actually built.
|
||||
*/
|
||||
bool InvokeSystemValidator (
|
||||
string targetHost, bool serverMode, X509CertificateCollection certificates,
|
||||
X509Chain chain, ref MonoSslPolicyErrors errors, ref int status11);
|
||||
}
|
||||
|
||||
public static class CertificateValidationHelper
|
||||
@@ -148,17 +141,23 @@ namespace Mono.Security.Interface
|
||||
/*
|
||||
* Internal API, intended to be used by MonoTlsProvider implementations.
|
||||
*/
|
||||
internal static ICertificateValidator2 GetInternalValidator (MonoTlsSettings settings, MonoTlsProvider provider)
|
||||
{
|
||||
return (ICertificateValidator2)NoReflectionHelper.GetInternalValidator (provider, settings);
|
||||
}
|
||||
|
||||
[Obsolete ("Use GetInternalValidator")]
|
||||
internal static ICertificateValidator2 GetDefaultValidator (MonoTlsSettings settings, MonoTlsProvider provider)
|
||||
{
|
||||
return (ICertificateValidator2)NoReflectionHelper.GetDefaultCertificateValidator (provider, settings);
|
||||
return GetInternalValidator (settings, provider);
|
||||
}
|
||||
|
||||
/*
|
||||
* Use this overloaded version in user code.
|
||||
*/
|
||||
public static ICertificateValidator GetValidator (MonoTlsSettings settings, MonoTlsProvider provider = null)
|
||||
public static ICertificateValidator GetValidator (MonoTlsSettings settings)
|
||||
{
|
||||
return GetDefaultValidator (settings, provider);
|
||||
return (ICertificateValidator)NoReflectionHelper.GetDefaultValidator (settings);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ namespace Mono.Security.Interface
|
||||
/// <summary>
|
||||
/// RFC 2246 A.5
|
||||
/// </summary>
|
||||
[CLSCompliant (false)]
|
||||
public enum CipherSuiteCode : ushort
|
||||
{
|
||||
TLS_NULL_WITH_NULL_NULL = 0x0000,
|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
//
|
||||
// IMonoTlsContext.cs
|
||||
//
|
||||
// Author:
|
||||
// Martin Baulig <martin.baulig@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2015 Xamarin, Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
|
||||
namespace Mono.Security.Interface
|
||||
{
|
||||
interface IMonoTlsContext : IDisposable
|
||||
{
|
||||
bool IsServer {
|
||||
get;
|
||||
}
|
||||
|
||||
bool IsValid {
|
||||
get;
|
||||
}
|
||||
|
||||
void Initialize (IMonoTlsEventSink eventSink);
|
||||
|
||||
bool HasCredentials {
|
||||
get;
|
||||
}
|
||||
|
||||
void SetCertificate (X509Certificate certificate, AsymmetricAlgorithm privateKey);
|
||||
|
||||
int GenerateNextToken (IBufferOffsetSize incoming, out IBufferOffsetSize outgoing);
|
||||
|
||||
int EncryptMessage (ref IBufferOffsetSize incoming);
|
||||
|
||||
int DecryptMessage (ref IBufferOffsetSize incoming);
|
||||
|
||||
bool ReceivedCloseNotify {
|
||||
get;
|
||||
}
|
||||
|
||||
byte[] CreateCloseNotify ();
|
||||
|
||||
byte[] CreateHelloRequest ();
|
||||
|
||||
X509Certificate GetRemoteCertificate (out X509CertificateCollection remoteCertificateStore);
|
||||
|
||||
bool VerifyRemoteCertificate ();
|
||||
|
||||
MonoTlsConnectionInfo GetConnectionInfo ();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ namespace Mono.Security.Interface
|
||||
{
|
||||
public class MonoTlsConnectionInfo
|
||||
{
|
||||
[CLSCompliant (false)]
|
||||
public CipherSuiteCode CipherSuiteCode {
|
||||
get; set;
|
||||
}
|
||||
@@ -49,6 +50,10 @@ namespace Mono.Security.Interface
|
||||
get; set;
|
||||
}
|
||||
|
||||
public string PeerDomainName {
|
||||
get; set;
|
||||
}
|
||||
|
||||
public override string ToString ()
|
||||
{
|
||||
return string.Format ("[MonoTlsConnectionInfo: {0}:{1}]", ProtocolVersion, CipherSuiteCode);
|
||||
|
||||
@@ -145,14 +145,6 @@ namespace Mono.Security.Interface
|
||||
#endregion
|
||||
|
||||
#region Certificate Validation
|
||||
|
||||
/*
|
||||
* Allows a TLS provider to provide a custom system certificiate validator.
|
||||
*/
|
||||
internal virtual bool HasCustomSystemCertificateValidator {
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
/*
|
||||
* If @serverMode is true, then we're a server and want to validate a certificate
|
||||
* that we received from a client.
|
||||
@@ -162,32 +154,10 @@ namespace Mono.Security.Interface
|
||||
* Returns `true` if certificate validation has been performed and `false` to invoke the
|
||||
* default system validator.
|
||||
*/
|
||||
internal virtual bool InvokeSystemCertificateValidator (
|
||||
internal abstract bool ValidateCertificate (
|
||||
ICertificateValidator2 validator, string targetHost, bool serverMode,
|
||||
X509CertificateCollection certificates, bool wantsChain, ref X509Chain chain,
|
||||
out bool success, ref MonoSslPolicyErrors errors, ref int status11)
|
||||
{
|
||||
throw new InvalidOperationException ();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Manged SSPI
|
||||
|
||||
/*
|
||||
* The managed SSPI implementation from the new TLS code.
|
||||
*/
|
||||
|
||||
internal abstract bool SupportsTlsContext {
|
||||
get;
|
||||
}
|
||||
|
||||
internal abstract IMonoTlsContext CreateTlsContext (
|
||||
string hostname, bool serverMode, TlsProtocols protocolFlags,
|
||||
X509Certificate serverCertificate, X509CertificateCollection clientCertificates,
|
||||
bool remoteCertRequired, MonoEncryptionPolicy encryptionPolicy,
|
||||
MonoTlsSettings settings);
|
||||
|
||||
ref MonoSslPolicyErrors errors, ref int status11);
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,37 @@ namespace Mono.Security.Interface
|
||||
public static partial class MonoTlsProviderFactory
|
||||
{
|
||||
/*
|
||||
* Returns the currently installed @MonoTlsProvider, falling back to the default one.
|
||||
* TLS Provider Initialization
|
||||
* ===========================
|
||||
*
|
||||
* The "global" TLS Provider (returned by GetProvider()) may only be modified at
|
||||
* application startup (before any of the TLS / Certificate code has been used).
|
||||
*
|
||||
* On mobile, the default provider is specified at compile time using a property
|
||||
* in the .csproj file (which can be set from the IDE). When using the linker, all
|
||||
* other providers will be linked-out, so you won't be able to choose a different
|
||||
* provider at run-time.
|
||||
*
|
||||
* On desktop, the default provider can be specified with the MONO_TLS_PROVIDER
|
||||
* environment variable. The following options are currently supported:
|
||||
*
|
||||
* "default" - let Mono pick the best one for you (recommended)
|
||||
* "old" or "legacy" - Mono's old managed TLS implementation
|
||||
* "appletls" (currently XamMac only, set via .csproj property)
|
||||
* "btls" - the new boringssl based provider (coming soon).
|
||||
*
|
||||
* On all platforms (except mobile with linker), you can call
|
||||
*
|
||||
* MonoTlsProviderFactory.Initialize(string)
|
||||
*
|
||||
* to use a different provider.
|
||||
*
|
||||
*/
|
||||
|
||||
#region Provider Initialization
|
||||
|
||||
/*
|
||||
* Returns the global @MonoTlsProvider, initializing the TLS Subsystem if necessary.
|
||||
*
|
||||
* This method throws @NotSupportedException if no TLS Provider can be found.
|
||||
*/
|
||||
@@ -49,42 +79,64 @@ namespace Mono.Security.Interface
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the default @MonoTlsProvider.
|
||||
*
|
||||
* This method throws @NotSupportedException if no TLS Provider can be found.
|
||||
* Check whether the TLS Subsystem is initialized.
|
||||
*/
|
||||
public static MonoTlsProvider GetDefaultProvider ()
|
||||
{
|
||||
return (MonoTlsProvider)NoReflectionHelper.GetDefaultProvider ();
|
||||
}
|
||||
|
||||
/*
|
||||
* GetProvider() attempts to load and install the default provider and throws on error.
|
||||
*
|
||||
* This property checks whether a provider has previously been installed by a call
|
||||
* to either GetProvider() or InstallProvider().
|
||||
*
|
||||
*/
|
||||
public static bool HasProvider {
|
||||
public static bool IsInitialized {
|
||||
get {
|
||||
return NoReflectionHelper.HasProvider;
|
||||
return NoReflectionHelper.IsInitialized;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Selects the default TLS Provider.
|
||||
*
|
||||
* May only be called at application startup and will throw
|
||||
* @InvalidOperationException if a provider has already been installed.
|
||||
* Initialize the TLS Subsystem.
|
||||
*
|
||||
* This method may be called at any time. It ensures that the TLS Subsystem is
|
||||
* initialized and a provider available.
|
||||
*/
|
||||
public static void SetDefaultProvider (string name)
|
||||
public static void Initialize ()
|
||||
{
|
||||
NoReflectionHelper.SetDefaultProvider (name);
|
||||
NoReflectionHelper.Initialize ();
|
||||
}
|
||||
|
||||
public static MonoTlsProvider GetProvider (string name)
|
||||
/*
|
||||
* Initialize the TLS Subsystem with a specific provider.
|
||||
*
|
||||
* May only be called at application startup (before any of the TLS / Certificate
|
||||
* APIs have been used).
|
||||
*
|
||||
* Throws @NotSupportedException if the TLS Subsystem is already initialized
|
||||
* (@IsInitialized returns true) or the requested provider is not supported.
|
||||
*
|
||||
* On mobile, this will always throw @NotSupportedException when using the linker.
|
||||
*/
|
||||
public static void Initialize (string provider)
|
||||
{
|
||||
return (MonoTlsProvider)NoReflectionHelper.GetProvider (name);
|
||||
NoReflectionHelper.Initialize (provider);
|
||||
}
|
||||
|
||||
/*
|
||||
* Checks whether @provider is supported.
|
||||
*
|
||||
* On mobile, this will always return false when using the linker.
|
||||
*/
|
||||
public static bool IsProviderSupported (string provider)
|
||||
{
|
||||
return NoReflectionHelper.IsProviderSupported (provider);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Call-by-call selection
|
||||
|
||||
/*
|
||||
* Returns the requested TLS Provider, for use with the call-by-call APIs below.
|
||||
*
|
||||
* Throw @NotSupportedException if the requested provider is not supported or
|
||||
* when using the linker on mobile.
|
||||
*/
|
||||
public static MonoTlsProvider GetProvider (string provider)
|
||||
{
|
||||
return (MonoTlsProvider)NoReflectionHelper.GetProvider (provider);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -108,6 +160,24 @@ namespace Mono.Security.Interface
|
||||
{
|
||||
return (IMonoSslStream)NoReflectionHelper.GetMonoSslStream (stream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Obsolete APIs
|
||||
|
||||
[Obsolete]
|
||||
public static MonoTlsProvider GetDefaultProvider ()
|
||||
{
|
||||
return GetProvider ();
|
||||
}
|
||||
|
||||
[Obsolete]
|
||||
public static void SetDefaultProvider (string name)
|
||||
{
|
||||
Initialize (name);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -82,6 +82,7 @@ namespace Mono.Security.Interface
|
||||
get; set;
|
||||
}
|
||||
|
||||
[CLSCompliant (false)]
|
||||
public CipherSuiteCode[] EnabledCiphers {
|
||||
get; set;
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace Mono.Security.Protocol.Tls
|
||||
{
|
||||
if (!isInitialized)
|
||||
{
|
||||
#if !NET_2_1
|
||||
#if !MOBILE
|
||||
Debug.Listeners.Add(new TextWriterTraceListener(Console.Out));
|
||||
// Debug.Listeners.Add(new TextWriterTraceListener(@"c:\ssl.log"));
|
||||
Debug.AutoFlush = true;
|
||||
|
||||
@@ -38,6 +38,8 @@ using System.Security.Cryptography;
|
||||
using Mono.Security.Cryptography;
|
||||
using Mono.Security.X509.Extensions;
|
||||
|
||||
using SSCX = System.Security.Cryptography.X509Certificates;
|
||||
|
||||
namespace Mono.Security.X509 {
|
||||
|
||||
#if INSIDE_CORLIB
|
||||
@@ -51,12 +53,14 @@ namespace Mono.Security.X509 {
|
||||
private X509CertificateCollection _certificates;
|
||||
private ArrayList _crls;
|
||||
private bool _crl;
|
||||
private bool _newFormat;
|
||||
private string _name;
|
||||
|
||||
internal X509Store (string path, bool crl)
|
||||
internal X509Store (string path, bool crl, bool newFormat)
|
||||
{
|
||||
_storePath = path;
|
||||
_crl = crl;
|
||||
_newFormat = newFormat;
|
||||
}
|
||||
|
||||
// properties
|
||||
@@ -126,6 +130,11 @@ namespace Mono.Security.X509 {
|
||||
{
|
||||
CheckStore (_storePath, true);
|
||||
|
||||
if (_newFormat) {
|
||||
ImportNewFormat (certificate);
|
||||
return;
|
||||
}
|
||||
|
||||
string filename = Path.Combine (_storePath, GetUniqueName (certificate));
|
||||
if (!File.Exists (filename)) {
|
||||
filename = Path.Combine (_storePath, GetUniqueNameWithSerial (certificate));
|
||||
@@ -148,7 +157,7 @@ namespace Mono.Security.X509 {
|
||||
ClearCertificates (); // We have modified the store on disk. So forget the old state.
|
||||
}
|
||||
}
|
||||
#if !NET_2_1
|
||||
#if !MOBILE
|
||||
// Try to save privateKey if available..
|
||||
CspParameters cspParams = new CspParameters ();
|
||||
cspParams.KeyContainerName = CryptoConvert.ToHex (certificate.Hash);
|
||||
@@ -165,6 +174,9 @@ namespace Mono.Security.X509 {
|
||||
{
|
||||
CheckStore (_storePath, true);
|
||||
|
||||
if (_newFormat)
|
||||
throw new NotSupportedException ();
|
||||
|
||||
string filename = Path.Combine (_storePath, GetUniqueName (crl));
|
||||
if (!File.Exists (filename)) {
|
||||
using (FileStream fs = File.Create (filename)) {
|
||||
@@ -177,6 +189,11 @@ namespace Mono.Security.X509 {
|
||||
|
||||
public void Remove (X509Certificate certificate)
|
||||
{
|
||||
if (_newFormat) {
|
||||
RemoveNewFormat (certificate);
|
||||
return;
|
||||
}
|
||||
|
||||
string filename = Path.Combine (_storePath, GetUniqueNameWithSerial (certificate));
|
||||
if (File.Exists (filename)) {
|
||||
File.Delete (filename);
|
||||
@@ -192,6 +209,9 @@ namespace Mono.Security.X509 {
|
||||
|
||||
public void Remove (X509Crl crl)
|
||||
{
|
||||
if (_newFormat)
|
||||
throw new NotSupportedException ();
|
||||
|
||||
string filename = Path.Combine (_storePath, GetUniqueName (crl));
|
||||
if (File.Exists (filename)) {
|
||||
File.Delete (filename);
|
||||
@@ -199,6 +219,41 @@ namespace Mono.Security.X509 {
|
||||
}
|
||||
}
|
||||
|
||||
// new format
|
||||
|
||||
void ImportNewFormat (X509Certificate certificate)
|
||||
{
|
||||
#if INSIDE_CORLIB
|
||||
throw new NotSupportedException ();
|
||||
#else
|
||||
using (var sscxCert = new SSCX.X509Certificate (certificate.RawData)) {
|
||||
var hash = SSCX.X509Helper2.GetSubjectNameHash (sscxCert);
|
||||
var filename = Path.Combine (_storePath, string.Format ("{0:x8}.0", hash));
|
||||
if (!File.Exists (filename)) {
|
||||
using (FileStream fs = File.Create (filename))
|
||||
SSCX.X509Helper2.ExportAsPEM (sscxCert, fs, true);
|
||||
ClearCertificates ();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void RemoveNewFormat (X509Certificate certificate)
|
||||
{
|
||||
#if INSIDE_CORLIB
|
||||
throw new NotSupportedException ();
|
||||
#else
|
||||
using (var sscxCert = new SSCX.X509Certificate (certificate.RawData)) {
|
||||
var hash = SSCX.X509Helper2.GetSubjectNameHash (sscxCert);
|
||||
var filename = Path.Combine (_storePath, string.Format ("{0:x8}.0", hash));
|
||||
if (File.Exists (filename)) {
|
||||
File.Delete (filename);
|
||||
ClearCertificates ();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// private stuff
|
||||
|
||||
private string GetUniqueNameWithSerial (X509Certificate certificate)
|
||||
@@ -279,7 +334,7 @@ namespace Mono.Security.X509 {
|
||||
{
|
||||
byte[] data = Load (filename);
|
||||
X509Certificate cert = new X509Certificate (data);
|
||||
#if !NET_2_1
|
||||
#if !MOBILE
|
||||
// If privateKey it's available, load it too..
|
||||
CspParameters cspParams = new CspParameters ();
|
||||
cspParams.KeyContainerName = CryptoConvert.ToHex (cert.Hash);
|
||||
@@ -371,7 +426,7 @@ namespace Mono.Security.X509 {
|
||||
}
|
||||
return list;
|
||||
}
|
||||
#if !NET_2_1
|
||||
#if !MOBILE
|
||||
private void ImportPrivateKey (X509Certificate certificate, CspParameters cspParams)
|
||||
{
|
||||
RSACryptoServiceProvider rsaCsp = certificate.RSA as RSACryptoServiceProvider;
|
||||
|
||||
@@ -45,8 +45,12 @@ namespace Mono.Security.X509 {
|
||||
|
||||
static private string _userPath;
|
||||
static private string _localMachinePath;
|
||||
static private string _newUserPath;
|
||||
static private string _newLocalMachinePath;
|
||||
static private X509Stores _userStore;
|
||||
static private X509Stores _machineStore;
|
||||
static private X509Stores _newUserStore;
|
||||
static private X509Stores _newMachineStore;
|
||||
|
||||
private X509StoreManager ()
|
||||
{
|
||||
@@ -55,10 +59,10 @@ namespace Mono.Security.X509 {
|
||||
internal static string CurrentUserPath {
|
||||
get {
|
||||
if (_userPath == null) {
|
||||
_userPath = Path.Combine(
|
||||
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
|
||||
_userPath = Path.Combine (
|
||||
Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData),
|
||||
".mono");
|
||||
_userPath = Path.Combine(_userPath, "certs");
|
||||
_userPath = Path.Combine (_userPath, "certs");
|
||||
}
|
||||
return _userPath;
|
||||
}
|
||||
@@ -76,10 +80,34 @@ namespace Mono.Security.X509 {
|
||||
}
|
||||
}
|
||||
|
||||
internal static string NewCurrentUserPath {
|
||||
get {
|
||||
if (_newUserPath == null) {
|
||||
_newUserPath = Path.Combine (
|
||||
Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData),
|
||||
".mono");
|
||||
_newUserPath = Path.Combine (_newUserPath, "new-certs");
|
||||
}
|
||||
return _newUserPath;
|
||||
}
|
||||
}
|
||||
|
||||
internal static string NewLocalMachinePath {
|
||||
get {
|
||||
if (_newLocalMachinePath == null) {
|
||||
_newLocalMachinePath = Path.Combine (
|
||||
Environment.GetFolderPath (Environment.SpecialFolder.CommonApplicationData),
|
||||
".mono");
|
||||
_newLocalMachinePath = Path.Combine (_newLocalMachinePath, "new-certs");
|
||||
}
|
||||
return _newLocalMachinePath;
|
||||
}
|
||||
}
|
||||
|
||||
static public X509Stores CurrentUser {
|
||||
get {
|
||||
if (_userStore == null)
|
||||
_userStore = new X509Stores(CurrentUserPath);
|
||||
_userStore = new X509Stores (CurrentUserPath, false);
|
||||
|
||||
return _userStore;
|
||||
}
|
||||
@@ -88,12 +116,30 @@ namespace Mono.Security.X509 {
|
||||
static public X509Stores LocalMachine {
|
||||
get {
|
||||
if (_machineStore == null)
|
||||
_machineStore = new X509Stores (LocalMachinePath);
|
||||
_machineStore = new X509Stores (LocalMachinePath, false);
|
||||
|
||||
return _machineStore;
|
||||
}
|
||||
}
|
||||
|
||||
static public X509Stores NewCurrentUser {
|
||||
get {
|
||||
if (_newUserStore == null)
|
||||
_newUserStore = new X509Stores (NewCurrentUserPath, true);
|
||||
|
||||
return _newUserStore;
|
||||
}
|
||||
}
|
||||
|
||||
static public X509Stores NewLocalMachine {
|
||||
get {
|
||||
if (_newMachineStore == null)
|
||||
_newMachineStore = new X509Stores (NewLocalMachinePath, true);
|
||||
|
||||
return _newMachineStore;
|
||||
}
|
||||
}
|
||||
|
||||
// Merged stores collections
|
||||
// we need to look at both the user and the machine (entreprise)
|
||||
// certificates/CRLs when building/validating a chain
|
||||
|
||||
@@ -44,15 +44,17 @@ namespace Mono.Security.X509 {
|
||||
class X509Stores {
|
||||
|
||||
private string _storePath;
|
||||
private bool _newFormat;
|
||||
private X509Store _personal;
|
||||
private X509Store _other;
|
||||
private X509Store _intermediate;
|
||||
private X509Store _trusted;
|
||||
private X509Store _untrusted;
|
||||
|
||||
internal X509Stores (string path)
|
||||
internal X509Stores (string path, bool newFormat)
|
||||
{
|
||||
_storePath = path;
|
||||
_newFormat = newFormat;
|
||||
}
|
||||
|
||||
// properties
|
||||
@@ -61,7 +63,7 @@ namespace Mono.Security.X509 {
|
||||
get {
|
||||
if (_personal == null) {
|
||||
string path = Path.Combine (_storePath, Names.Personal);
|
||||
_personal = new X509Store (path, false);
|
||||
_personal = new X509Store (path, false, false);
|
||||
}
|
||||
return _personal;
|
||||
}
|
||||
@@ -71,7 +73,7 @@ namespace Mono.Security.X509 {
|
||||
get {
|
||||
if (_other == null) {
|
||||
string path = Path.Combine (_storePath, Names.OtherPeople);
|
||||
_other = new X509Store (path, false);
|
||||
_other = new X509Store (path, false, false);
|
||||
}
|
||||
return _other;
|
||||
}
|
||||
@@ -81,7 +83,7 @@ namespace Mono.Security.X509 {
|
||||
get {
|
||||
if (_intermediate == null) {
|
||||
string path = Path.Combine (_storePath, Names.IntermediateCA);
|
||||
_intermediate = new X509Store (path, true);
|
||||
_intermediate = new X509Store (path, true, _newFormat);
|
||||
}
|
||||
return _intermediate;
|
||||
}
|
||||
@@ -91,7 +93,7 @@ namespace Mono.Security.X509 {
|
||||
get {
|
||||
if (_trusted == null) {
|
||||
string path = Path.Combine (_storePath, Names.TrustedRoot);
|
||||
_trusted = new X509Store (path, true);
|
||||
_trusted = new X509Store (path, true, _newFormat);
|
||||
}
|
||||
return _trusted;
|
||||
}
|
||||
@@ -101,7 +103,7 @@ namespace Mono.Security.X509 {
|
||||
get {
|
||||
if (_untrusted == null) {
|
||||
string path = Path.Combine (_storePath, Names.Untrusted);
|
||||
_untrusted = new X509Store (path, false);
|
||||
_untrusted = new X509Store (path, false, _newFormat);
|
||||
}
|
||||
return _untrusted;
|
||||
}
|
||||
@@ -138,7 +140,7 @@ namespace Mono.Security.X509 {
|
||||
if (!create && !Directory.Exists (path))
|
||||
return null;
|
||||
|
||||
return new X509Store (path, true);
|
||||
return new X509Store (path, true, false);
|
||||
}
|
||||
|
||||
// names
|
||||
@@ -151,7 +153,7 @@ namespace Mono.Security.X509 {
|
||||
public const string IntermediateCA = "CA";
|
||||
public const string TrustedRoot = "Trust";
|
||||
public const string Untrusted = "Disallowed";
|
||||
|
||||
|
||||
public Names () {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,7 +143,6 @@
|
||||
./Mono.Security.Interface/HashAlgorithmType.cs
|
||||
./Mono.Security.Interface/IBufferOffsetSize.cs
|
||||
./Mono.Security.Interface/IMonoTlsEventSink.cs
|
||||
./Mono.Security.Interface/IMonoTlsContext.cs
|
||||
./Mono.Security.Interface/IMonoSslStream.cs
|
||||
./Mono.Security.Interface/MonoTlsConnectionInfo.cs
|
||||
./Mono.Security.Interface/MonoTlsProvider.cs
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace MonoTests.Mono.Math {
|
||||
|
||||
protected void Expect (BigInteger actual, BigInteger expected)
|
||||
{
|
||||
Assertion.AssertEquals (Name, expected, actual);
|
||||
Assert.AreEqual (expected, actual, Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,12 +81,12 @@ namespace MonoTests.Mono.Math {
|
||||
|
||||
private void ExpectComposite (BigInteger bi)
|
||||
{
|
||||
Assertion.AssertEquals (false, bi.IsProbablePrime ());
|
||||
Assert.AreEqual (false, bi.IsProbablePrime ());
|
||||
}
|
||||
|
||||
private void ExpectPrime (BigInteger bi)
|
||||
{
|
||||
Assertion.AssertEquals (true, bi.IsProbablePrime ());
|
||||
Assert.AreEqual (true, bi.IsProbablePrime ());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,7 +195,7 @@ namespace MonoTests.Mono.Math {
|
||||
// Adapted from http://lists.ximian.com/archives/public/mono-devel-list/2003-November/003026.html
|
||||
// Note: these primes are taken from RFC 2412 [http://www.faqs.org/rfcs/rfc2412.html]
|
||||
[TestFixture]
|
||||
public class Rfc2412WellTestedPrimes : Assertion {
|
||||
public class Rfc2412WellTestedPrimes {
|
||||
|
||||
// E.1. Well-Known Group 1: A 768 bit prime
|
||||
[Test]
|
||||
@@ -203,8 +203,8 @@ namespace MonoTests.Mono.Math {
|
||||
{
|
||||
string prime = "1552518092300708935130918131258481755631334049434514313202351194902966239949102107258669453876591642442910007680288864229150803718918046342632727613031282983744380820890196288509170691316593175367469551763119843371637221007210577919";
|
||||
BigInteger bi = BigInteger.Parse (prime);
|
||||
Assert ("isProbablePrime-768", bi.IsProbablePrime ());
|
||||
AssertEquals ("ToString()", prime, bi.ToString ());
|
||||
Assert.IsTrue (bi.IsProbablePrime (), "isProbablePrime-768");
|
||||
Assert.AreEqual (prime, bi.ToString (), "ToString()");
|
||||
}
|
||||
|
||||
// E.2. Well-Known Group 2: A 1024 bit prime
|
||||
@@ -213,8 +213,8 @@ namespace MonoTests.Mono.Math {
|
||||
{
|
||||
string prime = "179769313486231590770839156793787453197860296048756011706444423684197180216158519368947833795864925541502180565485980503646440548199239100050792877003355816639229553136239076508735759914822574862575007425302077447712589550957937778424442426617334727629299387668709205606050270810842907692932019128194467627007";
|
||||
BigInteger bi = BigInteger.Parse (prime);
|
||||
Assert ("isProbablePrime-1024", bi.IsProbablePrime ());
|
||||
AssertEquals ("ToString()", prime, bi.ToString ());
|
||||
Assert.IsTrue (bi.IsProbablePrime (), "isProbablePrime-1024");
|
||||
Assert.AreEqual (prime, bi.ToString (), "ToString()");
|
||||
}
|
||||
|
||||
// Note: E.3 and E.4 are for Elliptic Curve Groups
|
||||
@@ -225,8 +225,8 @@ namespace MonoTests.Mono.Math {
|
||||
{
|
||||
string prime = "2410312426921032588552076022197566074856950548502459942654116941958108831682612228890093858261341614673227141477904012196503648957050582631942730706805009223062734745341073406696246014589361659774041027169249453200378729434170325843778659198143763193776859869524088940195577346119843545301547043747207749969763750084308926339295559968882457872412993810129130294592999947926365264059284647209730384947211681434464714438488520940127459844288859336526896320919633919";
|
||||
BigInteger bi = BigInteger.Parse (prime);
|
||||
Assert ("isProbablePrime-1536", bi.IsProbablePrime ());
|
||||
AssertEquals ("ToString()", prime, bi.ToString ());
|
||||
Assert.IsTrue (bi.IsProbablePrime (), "isProbablePrime-1536");
|
||||
Assert.AreEqual (prime, bi.ToString (), "ToString()");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace MonoTests.Mono.Math {
|
||||
ContextData ctx = (ContextData)Context;
|
||||
|
||||
|
||||
Assertion.AssertEquals (ctx.bits, bits);
|
||||
Assert.AreEqual (ctx.bits, bits);
|
||||
uint d = ctx.testData;
|
||||
|
||||
for (uint i = (uint)bits - 2; d > 0; i--, d >>= 1)
|
||||
@@ -65,7 +65,7 @@ namespace MonoTests.Mono.Math {
|
||||
Assert.IsTrue (p.TestBit (1));
|
||||
uint d = ctx.testData;
|
||||
for (uint j = 128 - 2; d > 0; j--, d >>= 1)
|
||||
Assertion.AssertEquals ((d&1) == 1, p.TestBit (j));
|
||||
Assert.AreEqual ((d&1) == 1, p.TestBit (j));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ namespace MonoTests.Mono.Security.Authenticode {
|
||||
// makecert -n "CN=PVK1" -sv 1.pvk 1.cer
|
||||
|
||||
[TestFixture]
|
||||
public class PrivateKeyTest : Assertion {
|
||||
public class PrivateKeyTest {
|
||||
|
||||
// because most crypto stuff works with byte[] buffers
|
||||
static public void AssertEquals (string msg, byte[] array1, byte[] array2)
|
||||
@@ -76,9 +76,9 @@ public class PrivateKeyTest : Assertion {
|
||||
if ((array1 == null) && (array2 == null))
|
||||
return;
|
||||
if (array1 == null)
|
||||
Fail (msg + " -> First array is NULL");
|
||||
Assert.Fail (msg + " -> First array is NULL");
|
||||
if (array2 == null)
|
||||
Fail (msg + " -> Second array is NULL");
|
||||
Assert.Fail (msg + " -> Second array is NULL");
|
||||
|
||||
bool a = (array1.Length == array2.Length);
|
||||
if (a) {
|
||||
@@ -93,7 +93,7 @@ public class PrivateKeyTest : Assertion {
|
||||
msg += " -> Expected " + BitConverter.ToString (array1, 0);
|
||||
msg += " is different than " + BitConverter.ToString (array2, 0);
|
||||
}
|
||||
Assert (msg, a);
|
||||
Assert.IsTrue (a, msg);
|
||||
}
|
||||
|
||||
string testfile;
|
||||
@@ -152,10 +152,10 @@ public class PrivateKeyTest : Assertion {
|
||||
{
|
||||
WriteBuffer (nopwd);
|
||||
PrivateKey pvk = PrivateKey.CreateFromFile (testfile);
|
||||
AssertNotNull ("msnopwd.RSA", pvk.RSA);
|
||||
Assert ("msnopwd.Encrypted", !pvk.Encrypted);
|
||||
Assert ("msnopwd.Weak", pvk.Weak);
|
||||
AssertEquals ("msnopwd.KeyType", 2, pvk.KeyType);
|
||||
Assert.IsNotNull (pvk.RSA, "msnopwd.RSA");
|
||||
Assert.IsTrue (!pvk.Encrypted, "msnopwd.Encrypted");
|
||||
Assert.IsTrue (pvk.Weak, "msnopwd.Weak");
|
||||
Assert.AreEqual (2, pvk.KeyType, "msnopwd.KeyType");
|
||||
}
|
||||
|
||||
// this will convert a PVK file without a password to a PVK file
|
||||
@@ -168,11 +168,11 @@ public class PrivateKeyTest : Assertion {
|
||||
string rsa1 = pvk.RSA.ToXmlString (true);
|
||||
pvk.Save (testfile, "password");
|
||||
pvk = PrivateKey.CreateFromFile (testfile, "password");
|
||||
AssertNotNull ("topwd.RSA", pvk.RSA);
|
||||
Assert.IsNotNull (pvk.RSA, "topwd.RSA");
|
||||
string rsa2 = pvk.RSA.ToXmlString (true);
|
||||
AssertEquals ("topwd.RSA identical", rsa1, rsa2);
|
||||
Assert ("topwd.Encrypted", pvk.Encrypted);
|
||||
Assert ("topwd.Weak", pvk.Weak);
|
||||
Assert.AreEqual (rsa1, rsa2, "topwd.RSA identical");
|
||||
Assert.IsTrue (pvk.Encrypted, "topwd.Encrypted");
|
||||
Assert.IsTrue (pvk.Weak, "topwd.Weak");
|
||||
}
|
||||
|
||||
// this will convert a PVK file without a password to a PVK file
|
||||
@@ -186,11 +186,11 @@ public class PrivateKeyTest : Assertion {
|
||||
pvk.Weak = false; // we want strong crypto
|
||||
pvk.Save (testfile, "password");
|
||||
pvk = PrivateKey.CreateFromFile (testfile, "password");
|
||||
AssertNotNull ("topwd.RSA", pvk.RSA);
|
||||
Assert.IsNotNull (pvk.RSA, "topwd.RSA");
|
||||
string rsa2 = pvk.RSA.ToXmlString (true);
|
||||
AssertEquals ("topwd.RSA identical", rsa1, rsa2);
|
||||
Assert ("topwd.Encrypted", pvk.Encrypted);
|
||||
Assert ("topwd.Weak", !pvk.Weak);
|
||||
Assert.AreEqual (rsa1, rsa2, "topwd.RSA identical");
|
||||
Assert.IsTrue (pvk.Encrypted, "topwd.Encrypted");
|
||||
Assert.IsTrue (!pvk.Weak, "topwd.Weak");
|
||||
}
|
||||
|
||||
static byte[] pwd = {
|
||||
@@ -229,9 +229,9 @@ public class PrivateKeyTest : Assertion {
|
||||
{
|
||||
WriteBuffer (pwd);
|
||||
PrivateKey pvk = PrivateKey.CreateFromFile (testfile, "password");
|
||||
AssertNotNull ("mspwd.RSA", pvk.RSA);
|
||||
Assert ("mspwd.Encrypted", pvk.Encrypted);
|
||||
Assert ("mspwd.Weak", pvk.Weak);
|
||||
Assert.IsNotNull (pvk.RSA, "mspwd.RSA");
|
||||
Assert.IsTrue (pvk.Encrypted, "mspwd.Encrypted");
|
||||
Assert.IsTrue (pvk.Weak, "mspwd.Weak");
|
||||
}
|
||||
|
||||
// this will convert a PVK file with a password to a PVK file
|
||||
@@ -244,11 +244,11 @@ public class PrivateKeyTest : Assertion {
|
||||
string rsa1 = pvk.RSA.ToXmlString (true);
|
||||
pvk.Save (testfile);
|
||||
pvk = PrivateKey.CreateFromFile (testfile);
|
||||
AssertNotNull ("nomorepwd.RSA", pvk.RSA);
|
||||
Assert.IsNotNull (pvk.RSA, "nomorepwd.RSA");
|
||||
string rsa2 = pvk.RSA.ToXmlString (true);
|
||||
AssertEquals ("nomorepwd.RSA identical", rsa1, rsa2);
|
||||
Assert ("nomorepwd.Encrypted", !pvk.Encrypted);
|
||||
Assert ("nomorepwd.Weak", pvk.Weak);
|
||||
Assert.AreEqual (rsa1, rsa2, "nomorepwd.RSA identical");
|
||||
Assert.IsTrue (!pvk.Encrypted, "nomorepwd.Encrypted");
|
||||
Assert.IsTrue (pvk.Weak, "nomorepwd.Weak");
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -261,11 +261,11 @@ public class PrivateKeyTest : Assertion {
|
||||
pvk.Save (testfile, "mono");
|
||||
|
||||
pvk = PrivateKey.CreateFromFile (testfile, "mono");
|
||||
AssertNotNull ("new.RSA", pvk.RSA);
|
||||
Assert.IsNotNull (pvk.RSA, "new.RSA");
|
||||
string rsa2 = pvk.RSA.ToXmlString (true);
|
||||
AssertEquals ("new.RSA identical", rsa1, rsa2);
|
||||
Assert ("new.Encrypted", pvk.Encrypted);
|
||||
Assert ("new.Weak", !pvk.Weak);
|
||||
Assert.AreEqual (rsa1, rsa2, "new.RSA identical");
|
||||
Assert.IsTrue (pvk.Encrypted, "new.Encrypted");
|
||||
Assert.IsTrue (!pvk.Weak, "new.Weak");
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -15,7 +15,7 @@ using Mono.Security.Cryptography;
|
||||
namespace MonoTests.Mono.Security.Cryptography {
|
||||
|
||||
[TestFixture]
|
||||
public class CryptoConvertTest : Assertion {
|
||||
public class CryptoConvertTest {
|
||||
|
||||
// because most crypto stuff works with byte[] buffers
|
||||
static public void AssertEquals (string msg, byte[] array1, byte[] array2)
|
||||
@@ -23,9 +23,9 @@ namespace MonoTests.Mono.Security.Cryptography {
|
||||
if ((array1 == null) && (array2 == null))
|
||||
return;
|
||||
if (array1 == null)
|
||||
Fail (msg + " -> First array is NULL");
|
||||
Assert.Fail (msg + " -> First array is NULL");
|
||||
if (array2 == null)
|
||||
Fail (msg + " -> Second array is NULL");
|
||||
Assert.Fail (msg + " -> Second array is NULL");
|
||||
|
||||
bool a = (array1.Length == array2.Length);
|
||||
if (a) {
|
||||
@@ -38,7 +38,7 @@ namespace MonoTests.Mono.Security.Cryptography {
|
||||
}
|
||||
msg += " -> Expected " + BitConverter.ToString (array1, 0);
|
||||
msg += " is different than " + BitConverter.ToString (array2, 0);
|
||||
Assert (msg, a);
|
||||
Assert.IsTrue (a, msg);
|
||||
}
|
||||
|
||||
// strongname generated using "sn -k unit.snk"
|
||||
@@ -163,16 +163,16 @@ namespace MonoTests.Mono.Security.Cryptography {
|
||||
{
|
||||
// keypair
|
||||
RSA rsa = CryptoConvert.FromCapiKeyBlob (strongName, 0);
|
||||
AssertEquals ("KeyPair", strongNameString, rsa.ToXmlString (true));
|
||||
AssertEquals ("PublicKey-1", strongNamePublicKeyString, rsa.ToXmlString (false));
|
||||
Assert.AreEqual (strongNameString, rsa.ToXmlString (true), "KeyPair");
|
||||
Assert.AreEqual (strongNamePublicKeyString, rsa.ToXmlString (false), "PublicKey-1");
|
||||
|
||||
// public key (direct)
|
||||
rsa = CryptoConvert.FromCapiKeyBlob (strongNamePublicKey, 12);
|
||||
AssertEquals ("PublicKey-2", strongNamePublicKeyString, rsa.ToXmlString (false));
|
||||
Assert.AreEqual (strongNamePublicKeyString, rsa.ToXmlString (false), "PublicKey-2");
|
||||
|
||||
// public key (indirect - inside header)
|
||||
rsa = CryptoConvert.FromCapiKeyBlob (strongNamePublicKey, 0);
|
||||
AssertEquals ("PublicKey-3", strongNamePublicKeyString, rsa.ToXmlString (false));
|
||||
Assert.AreEqual (strongNamePublicKeyString, rsa.ToXmlString (false), "PublicKey-3");
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -201,7 +201,7 @@ namespace MonoTests.Mono.Security.Cryptography {
|
||||
public void FromCapiPrivateKeyBlob ()
|
||||
{
|
||||
RSA rsa = CryptoConvert.FromCapiPrivateKeyBlob (strongName, 0);
|
||||
AssertEquals ("KeyPair", strongNameString, rsa.ToXmlString (true));
|
||||
Assert.AreEqual (strongNameString, rsa.ToXmlString (true), "KeyPair");
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -229,7 +229,7 @@ namespace MonoTests.Mono.Security.Cryptography {
|
||||
public void FromCapiPublicKeyBlob ()
|
||||
{
|
||||
RSA rsa = CryptoConvert.FromCapiPublicKeyBlob (strongNamePublicKey, 12);
|
||||
AssertEquals ("PublicKey", strongNamePublicKeyString, rsa.ToXmlString (false));
|
||||
Assert.AreEqual (strongNamePublicKeyString, rsa.ToXmlString (false), "PublicKey");
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -262,12 +262,12 @@ namespace MonoTests.Mono.Security.Cryptography {
|
||||
AssertEquals ("RSA-KeyPair", strongName, keypair);
|
||||
|
||||
byte[] publicKey = CryptoConvert.ToCapiKeyBlob (rsa, false);
|
||||
AssertEquals ("RSA-PublicKey", BitConverter.ToString (strongNamePublicKey, 12), BitConverter.ToString (publicKey));
|
||||
Assert.AreEqual (BitConverter.ToString (strongNamePublicKey, 12), BitConverter.ToString (publicKey), "RSA-PublicKey");
|
||||
|
||||
AsymmetricAlgorithm dsa = DSA.Create ();
|
||||
dsa.FromXmlString (dsaKeyPairString);
|
||||
AssertEquals ("DSA-KeyPair", dsaPrivBlob, CryptoConvert.ToCapiKeyBlob (dsa, true));
|
||||
AssertEquals ("DSA-PublicKey", BitConverter.ToString (dsaPubBlob), BitConverter.ToString (CryptoConvert.ToCapiKeyBlob (dsa, false)));
|
||||
Assert.AreEqual (BitConverter.ToString (dsaPubBlob), BitConverter.ToString (CryptoConvert.ToCapiKeyBlob (dsa, false)), "DSA-PublicKey");
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -279,7 +279,7 @@ namespace MonoTests.Mono.Security.Cryptography {
|
||||
AssertEquals ("KeyPair", strongName, keypair);
|
||||
|
||||
byte[] publicKey = CryptoConvert.ToCapiKeyBlob (rsa, false);
|
||||
AssertEquals ("PublicKey", BitConverter.ToString (strongNamePublicKey, 12), BitConverter.ToString (publicKey));
|
||||
Assert.AreEqual (BitConverter.ToString (strongNamePublicKey, 12), BitConverter.ToString (publicKey), "PublicKey");
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -323,11 +323,11 @@ namespace MonoTests.Mono.Security.Cryptography {
|
||||
// full keypair
|
||||
rsa.FromXmlString (strongNameString);
|
||||
byte[] publicKey = CryptoConvert.ToCapiPublicKeyBlob (rsa);
|
||||
AssertEquals ("PublicKey-1", BitConverter.ToString (strongNamePublicKey, 12), BitConverter.ToString (publicKey));
|
||||
Assert.AreEqual (BitConverter.ToString (strongNamePublicKey, 12), BitConverter.ToString (publicKey), "PublicKey-1");
|
||||
// public key only
|
||||
rsa.FromXmlString (strongNamePublicKeyString);
|
||||
publicKey = CryptoConvert.ToCapiPublicKeyBlob (rsa);
|
||||
AssertEquals ("PublicKey-2", BitConverter.ToString (strongNamePublicKey, 12), BitConverter.ToString (publicKey));
|
||||
Assert.AreEqual (BitConverter.ToString (strongNamePublicKey, 12), BitConverter.ToString (publicKey), "PublicKey-2");
|
||||
}
|
||||
|
||||
/* DSA key tests */
|
||||
@@ -419,8 +419,8 @@ namespace MonoTests.Mono.Security.Cryptography {
|
||||
public void FromCapiKeyBlobDSA ()
|
||||
{
|
||||
DSA dsa = CryptoConvert.FromCapiKeyBlobDSA (dsaPrivBlob);
|
||||
AssertEquals ("KeyPair", dsaKeyPairString, dsa.ToXmlString (true));
|
||||
AssertEquals ("PublicKey", dsaPubKeyString, dsa.ToXmlString (false));
|
||||
Assert.AreEqual (dsaKeyPairString, dsa.ToXmlString (true), "KeyPair");
|
||||
Assert.AreEqual (dsaPubKeyString, dsa.ToXmlString (false), "PublicKey");
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -449,7 +449,7 @@ namespace MonoTests.Mono.Security.Cryptography {
|
||||
public void FromCapiPrivateKeyBlobDSA ()
|
||||
{
|
||||
DSA dsa = CryptoConvert.FromCapiPrivateKeyBlobDSA (dsaPrivBlob, 0);
|
||||
AssertEquals ("KeyPair", dsaKeyPairString, dsa.ToXmlString (true));
|
||||
Assert.AreEqual (dsaKeyPairString, dsa.ToXmlString (true), "KeyPair");
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -478,7 +478,7 @@ namespace MonoTests.Mono.Security.Cryptography {
|
||||
public void FromCapiPublicKeyBlobDSA ()
|
||||
{
|
||||
DSA dsa = CryptoConvert.FromCapiPublicKeyBlobDSA (dsaPubBlob, 0);
|
||||
AssertEquals ("PublicKey", dsaPubKeyString, dsa.ToXmlString (false));
|
||||
Assert.AreEqual (dsaPubKeyString, dsa.ToXmlString (false), "PublicKey");
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -512,7 +512,7 @@ namespace MonoTests.Mono.Security.Cryptography {
|
||||
AssertEquals ("KeyPair", dsaPrivBlob, keypair);
|
||||
|
||||
byte[] pubkey = CryptoConvert.ToCapiKeyBlob (dsa, false);
|
||||
AssertEquals ("PublicKey", BitConverter.ToString (dsaPubBlob), BitConverter.ToString (pubkey));
|
||||
Assert.AreEqual (BitConverter.ToString (dsaPubBlob), BitConverter.ToString (pubkey), "PublicKey");
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -548,20 +548,20 @@ namespace MonoTests.Mono.Security.Cryptography {
|
||||
// full keypair
|
||||
dsa.FromXmlString (dsaKeyPairString);
|
||||
byte[] pubkey = CryptoConvert.ToCapiPublicKeyBlob (dsa);
|
||||
AssertEquals ("PublicKey-1", BitConverter.ToString (dsaPubBlob), BitConverter.ToString (pubkey));
|
||||
Assert.AreEqual (BitConverter.ToString (dsaPubBlob), BitConverter.ToString (pubkey), "PublicKey-1");
|
||||
|
||||
// public key only
|
||||
dsa.FromXmlString (dsaPubKeyString);
|
||||
pubkey = CryptoConvert.ToCapiPublicKeyBlob (dsa);
|
||||
AssertEquals ("PublicKey-2", BitConverter.ToString (dsaPubBlob), BitConverter.ToString (pubkey));
|
||||
Assert.AreEqual (BitConverter.ToString (dsaPubBlob), BitConverter.ToString (pubkey), "PublicKey-2");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FromHex ()
|
||||
{
|
||||
AssertNull ("FromHex(null)", CryptoConvert.FromHex (null));
|
||||
Assert.IsNull (CryptoConvert.FromHex (null), "FromHex(null)");
|
||||
string result = BitConverter.ToString (CryptoConvert.FromHex ("0123456789aBcDeF"));
|
||||
AssertEquals ("0123456789abcdef", "01-23-45-67-89-AB-CD-EF", result);
|
||||
Assert.AreEqual ("01-23-45-67-89-AB-CD-EF", result, "0123456789abcdef");
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -581,9 +581,9 @@ namespace MonoTests.Mono.Security.Cryptography {
|
||||
[Test]
|
||||
public void ToHex ()
|
||||
{
|
||||
AssertNull ("FromHex(null)", CryptoConvert.FromHex (null));
|
||||
Assert.IsNull (CryptoConvert.FromHex (null), "FromHex(null)");
|
||||
byte[] data = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef };
|
||||
AssertEquals ("0123456789abcdef", "0123456789ABCDEF", CryptoConvert.ToHex (data));
|
||||
Assert.AreEqual ("0123456789ABCDEF", CryptoConvert.ToHex (data), "0123456789abcdef");
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -595,8 +595,8 @@ namespace MonoTests.Mono.Security.Cryptography {
|
||||
RSA rsa = CryptoConvert.FromCapiKeyBlob (strongNameNUnit, 0);
|
||||
// note the bad D parameters !!!
|
||||
// this only works because CRT is being used
|
||||
AssertEquals ("KeyPair", "<RSAKeyValue><Modulus>rB8h0TaMs8fWA+5WMdcjOjejCZwhYwuFHUZPS0cC9TOG6FJtvlHPpZLQAg0xfLr2SivPRol1Xw9SqhuaYQNJA7sAaOb8Rvgmx93XbmcNotY9ob4TGaesk+M8VsdexsIJ3WlyLbmRlf0EjT52nboyauEL3UC85zkMjW1LNb8LSs8=</Modulus><Exponent>AQAB</Exponent><P>2d4pGForvc792ztFxhNuzxIihDnXp+qK9F8t/NduhRBdu+JXK4d8a9EGwzpMxLUPlHjCZfXRraZiSQszkH+nzQ==</P><Q>yj9BeGmOrucOUCNZYTtXI0ykzz+1g+cVMSxi+6xzoLEOqmdE4gjcWaxak4MF1+pIR6UycnNa/jg1LBl7MKxpCw==</Q><DP>cMkAjznG4Sjx4/dIRKU0vP/PXJIxIR1bN+y5+uVvsnTpgWVH6SHneE0qahCZQ0/UM/Fb+bqLBJFY2iVxWUGslQ==</DP><DQ>gz6TXPGbLzMv3Z9i5C8e+ABHv1pHj6ZI4VU9kraxfmkH7FsBn3FClUq8qJdRFnGpoBy65Pyo4upUzx5mDAsGSw==</DQ><InverseQ>x+UShV+0d9cicoiB9fkSLqpLDyF4dYzVu0uqX0eCcoGJpk19jtSaMI3Eo8VN6MJAW1zrRy+MA1Fqb9qeThLqZQ==</InverseQ><D>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</D></RSAKeyValue>", rsa.ToXmlString (true));
|
||||
AssertEquals ("PublicKey", "<RSAKeyValue><Modulus>rB8h0TaMs8fWA+5WMdcjOjejCZwhYwuFHUZPS0cC9TOG6FJtvlHPpZLQAg0xfLr2SivPRol1Xw9SqhuaYQNJA7sAaOb8Rvgmx93XbmcNotY9ob4TGaesk+M8VsdexsIJ3WlyLbmRlf0EjT52nboyauEL3UC85zkMjW1LNb8LSs8=</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>", rsa.ToXmlString (false));
|
||||
Assert.AreEqual ("<RSAKeyValue><Modulus>rB8h0TaMs8fWA+5WMdcjOjejCZwhYwuFHUZPS0cC9TOG6FJtvlHPpZLQAg0xfLr2SivPRol1Xw9SqhuaYQNJA7sAaOb8Rvgmx93XbmcNotY9ob4TGaesk+M8VsdexsIJ3WlyLbmRlf0EjT52nboyauEL3UC85zkMjW1LNb8LSs8=</Modulus><Exponent>AQAB</Exponent><P>2d4pGForvc792ztFxhNuzxIihDnXp+qK9F8t/NduhRBdu+JXK4d8a9EGwzpMxLUPlHjCZfXRraZiSQszkH+nzQ==</P><Q>yj9BeGmOrucOUCNZYTtXI0ykzz+1g+cVMSxi+6xzoLEOqmdE4gjcWaxak4MF1+pIR6UycnNa/jg1LBl7MKxpCw==</Q><DP>cMkAjznG4Sjx4/dIRKU0vP/PXJIxIR1bN+y5+uVvsnTpgWVH6SHneE0qahCZQ0/UM/Fb+bqLBJFY2iVxWUGslQ==</DP><DQ>gz6TXPGbLzMv3Z9i5C8e+ABHv1pHj6ZI4VU9kraxfmkH7FsBn3FClUq8qJdRFnGpoBy65Pyo4upUzx5mDAsGSw==</DQ><InverseQ>x+UShV+0d9cicoiB9fkSLqpLDyF4dYzVu0uqX0eCcoGJpk19jtSaMI3Eo8VN6MJAW1zrRy+MA1Fqb9qeThLqZQ==</InverseQ><D>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</D></RSAKeyValue>", rsa.ToXmlString (true), "KeyPair");
|
||||
Assert.AreEqual ("<RSAKeyValue><Modulus>rB8h0TaMs8fWA+5WMdcjOjejCZwhYwuFHUZPS0cC9TOG6FJtvlHPpZLQAg0xfLr2SivPRol1Xw9SqhuaYQNJA7sAaOb8Rvgmx93XbmcNotY9ob4TGaesk+M8VsdexsIJ3WlyLbmRlf0EjT52nboyauEL3UC85zkMjW1LNb8LSs8=</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>", rsa.ToXmlString (false), "PublicKey");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace MonoTests.Mono.Security.Cryptography {
|
||||
// http://www.ietf.org/rfc/rfc2631.txt
|
||||
|
||||
[TestFixture]
|
||||
public class DiffieHellmanManagedTest : Assertion {
|
||||
public class DiffieHellmanManagedTest {
|
||||
|
||||
// because most crypto stuff works with byte[] buffers
|
||||
static public void AssertEquals (string msg, byte[] array1, byte[] array2)
|
||||
@@ -32,9 +32,9 @@ namespace MonoTests.Mono.Security.Cryptography {
|
||||
if ((array1 == null) && (array2 == null))
|
||||
return;
|
||||
if (array1 == null)
|
||||
Assertion.Fail (msg + " -> First array is NULL");
|
||||
Assert.Fail (msg + " -> First array is NULL");
|
||||
if (array2 == null)
|
||||
Assertion.Fail (msg + " -> Second array is NULL");
|
||||
Assert.Fail (msg + " -> Second array is NULL");
|
||||
|
||||
bool a = (array1.Length == array2.Length);
|
||||
if (a) {
|
||||
@@ -49,7 +49,7 @@ namespace MonoTests.Mono.Security.Cryptography {
|
||||
msg += " -> Expected " + BitConverter.ToString (array1, 0);
|
||||
msg += " is different than " + BitConverter.ToString (array2, 0);
|
||||
}
|
||||
Assertion.Assert (msg, a);
|
||||
Assert.IsTrue (a, msg);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -70,7 +70,7 @@ namespace MonoTests.Mono.Security.Cryptography {
|
||||
// let the second DH instance compute the shared secret using the first DH public key
|
||||
byte[] dh2k = dh2.DecryptKeyExchange (ke1);
|
||||
// both shared secrets are the same
|
||||
AssertEquals ("Shared Secret", dh1k, dh2k);
|
||||
Assert.AreEqual (dh1k, dh2k, "Shared Secret");
|
||||
}
|
||||
|
||||
// TODO: More is needed !
|
||||
|
||||
File diff suppressed because one or more lines are too long
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user