#else
public
#endif
- sealed class X509StoreManager {\r
-\r
+ sealed class X509StoreManager {
+
static private string _userPath;
static private string _localMachinePath;
static private X509Stores _userStore;
}
internal static string CurrentUserPath {
- get {\r
- if (_userPath == null) {\r
- _userPath = Path.Combine(\r
- Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),\r
- ".mono");\r
- _userPath = Path.Combine(_userPath, "certs");\r
- }\r
+ get {
+ if (_userPath == null) {
+ _userPath = Path.Combine(
+ Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
+ ".mono");
+ _userPath = Path.Combine(_userPath, "certs");
+ }
return _userPath;
}
- }\r
-\r
- internal static string LocalMachinePath {\r
- get {\r
+ }
+
+ internal static string LocalMachinePath {
+ get {
if (_localMachinePath == null) {
_localMachinePath = Path.Combine (
Environment.GetFolderPath (Environment.SpecialFolder.CommonApplicationData),
".mono");
- _localMachinePath = Path.Combine (_localMachinePath, "certs");\r
- }\r
- return _localMachinePath;\r
- }\r
+ _localMachinePath = Path.Combine (_localMachinePath, "certs");
+ }
+ return _localMachinePath;
+ }
}
static public X509Stores CurrentUser {
get {
- if (_userStore == null)\r
+ if (_userStore == null)
_userStore = new X509Stores(CurrentUserPath);
return _userStore;
#else
public
#endif
- sealed class X509StoreManager {\r
-\r
+ sealed class X509StoreManager {
+
static private string _userPath;
static private string _localMachinePath;
static private X509Stores _userStore;
}
internal static string CurrentUserPath {
- get {\r
- if (_userPath == null) {\r
- _userPath = Path.Combine(\r
- Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),\r
- ".mono");\r
- _userPath = Path.Combine(_userPath, "certs");\r
- }\r
+ get {
+ if (_userPath == null) {
+ _userPath = Path.Combine(
+ Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
+ ".mono");
+ _userPath = Path.Combine(_userPath, "certs");
+ }
return _userPath;
}
- }\r
-\r
- internal static string LocalMachinePath {\r
- get {\r
+ }
+
+ internal static string LocalMachinePath {
+ get {
if (_localMachinePath == null) {
_localMachinePath = Path.Combine (
Environment.GetFolderPath (Environment.SpecialFolder.CommonApplicationData),
".mono");
- _localMachinePath = Path.Combine (_localMachinePath, "certs");\r
- }\r
- return _localMachinePath;\r
- }\r
+ _localMachinePath = Path.Combine (_localMachinePath, "certs");
+ }
+ return _localMachinePath;
+ }
}
static public X509Stores CurrentUser {
get {
- if (_userStore == null)\r
+ if (_userStore == null)
_userStore = new X509Stores(CurrentUserPath);
return _userStore;
//
using System;
-using System.Collections;\r
+using System.Collections;
using System.Globalization;
-using System.IO;\r
+using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Reflection;
Console.WriteLine ("\t-del\t\tRemove a certificate, CRL or CTL to specified store");
Console.WriteLine ("\t-put\t\tCopy a certificate, CRL or CTL from a store to a file");
Console.WriteLine ("\t-list\t\tList certificates, CRL ot CTL in the specified store.");
- Console.WriteLine ("\t-ssl\t\tDownload and add certificates from an SSL session");\r
+ Console.WriteLine ("\t-ssl\t\tDownload and add certificates from an SSL session");
Console.WriteLine ("\t-importKey\tImport PKCS12 privateKey to keypair store.");
Console.WriteLine ("object types");
Console.WriteLine ("\t-c\t\tadd/del/put certificates");
Console.WriteLine ("\t-ctl\t\tadd/del/put certificate trust lists [unsupported]");
Console.WriteLine ("other options");
Console.WriteLine ("\t-m\t\tuse the machine certificate store (default to user)");
- Console.WriteLine ("\t-v\t\tverbose mode (display status for every steps)");\r
+ Console.WriteLine ("\t-v\t\tverbose mode (display status for every steps)");
Console.WriteLine ("\t-p [password]\tPassword used to decrypt PKCS12");
Console.WriteLine ("\t-?\t\th[elp]\tDisplay this help message");
Console.WriteLine ();
case "TLS":
action = Action.Ssl;
break;
- case "IMPORTKEY":\r
- action = Action.ImportKey;\r
+ case "IMPORTKEY":
+ action = Action.ImportKey;
break;
}
return action;
coll.Add (x509);
break;
case ".P12":
- case ".PFX":\r
- PKCS12 p12 = password == null ? PKCS12.LoadFromFile (filename)\r
- : PKCS12.LoadFromFile (filename, password);\r
- X509CertificateCollection tmp = new X509CertificateCollection (p12.Certificates);\r
-\r
- for (int i = 0; i != p12.Keys.Count; i++) {\r
- X509Certificate cert = p12.Certificates[i];\r
- RSACryptoServiceProvider pk = p12.Keys[i] as RSACryptoServiceProvider;\r
-\r
- if (pk == null || pk.PublicOnly)\r
- continue;\r
-\r
- if (verbose)\r
- Console.WriteLine ("Found key for certificate: {0}", cert.SubjectName);\r
-\r
- tmp[0].RSA = pk;\r
- }\r
+ case ".PFX":
+ PKCS12 p12 = password == null ? PKCS12.LoadFromFile (filename)
+ : PKCS12.LoadFromFile (filename, password);
+ X509CertificateCollection tmp = new X509CertificateCollection (p12.Certificates);
+
+ for (int i = 0; i != p12.Keys.Count; i++) {
+ X509Certificate cert = p12.Certificates[i];
+ RSACryptoServiceProvider pk = p12.Keys[i] as RSACryptoServiceProvider;
+
+ if (pk == null || pk.PublicOnly)
+ continue;
+
+ if (verbose)
+ Console.WriteLine ("Found key for certificate: {0}", cert.SubjectName);
+
+ tmp[0].RSA = pk;
+ }
coll.AddRange(tmp);
- p12 = null;\r
+ p12 = null;
break;
default:
Console.WriteLine ("Unknown file extension: {0}",
Console.WriteLine (" Private Key: {0}", ((rsaCsp != null && !rsaCsp.PublicOnly)
|| (rsaManaged != null && !rsaManaged.PublicOnly)));
CspParameters cspParams = new CspParameters ();
- cspParams.KeyContainerName = CryptoConvert.ToHex (x509.Hash);\r
- cspParams.Flags = machine ? CspProviderFlags.UseMachineKeyStore : 0;\r
- KeyPairPersistence kpp = new KeyPairPersistence (cspParams);\r
+ cspParams.KeyContainerName = CryptoConvert.ToHex (x509.Hash);
+ cspParams.Flags = machine ? CspProviderFlags.UseMachineKeyStore : 0;
+ KeyPairPersistence kpp = new KeyPairPersistence (cspParams);
Console.WriteLine (" KeyPair Key: {0}", kpp.Load ());
}
Console.WriteLine ();
{
switch (type) {
case ObjectType.Certificate:
- X509CertificateCollection coll = LoadCertificates (file, password, verbose);\r
+ X509CertificateCollection coll = LoadCertificates (file, password, verbose);
int count = 0;
- foreach (X509Certificate x509 in coll) {\r
- RSACryptoServiceProvider pk = x509.RSA as RSACryptoServiceProvider;\r
-\r
- if (pk == null || pk.PublicOnly)\r
- continue;\r
-\r
- CspParameters csp = new CspParameters ();\r
- csp.KeyContainerName = CryptoConvert.ToHex (x509.Hash);\r
- csp.Flags = machine ? CspProviderFlags.UseMachineKeyStore : 0;\r
- RSACryptoServiceProvider rsa = new RSACryptoServiceProvider (csp);\r
- rsa.ImportParameters (pk.ExportParameters (true));\r
- rsa.PersistKeyInCsp = true;\r
+ foreach (X509Certificate x509 in coll) {
+ RSACryptoServiceProvider pk = x509.RSA as RSACryptoServiceProvider;
+
+ if (pk == null || pk.PublicOnly)
+ continue;
+
+ CspParameters csp = new CspParameters ();
+ csp.KeyContainerName = CryptoConvert.ToHex (x509.Hash);
+ csp.Flags = machine ? CspProviderFlags.UseMachineKeyStore : 0;
+ RSACryptoServiceProvider rsa = new RSACryptoServiceProvider (csp);
+ rsa.ImportParameters (pk.ExportParameters (true));
+ rsa.PersistKeyInCsp = true;
count++;
}
Console.WriteLine ("{0} keys(s) imported to KeyPair {1} persister.",
[STAThread]
static void Main (string[] args)
- {\r
+ {
string password = null;
Header ();
if (machine)
n++;
- if (GetCommand (args [n]) == "P")\r
- {\r
- n++;\r
- password = args[n++];\r
+ if (GetCommand (args [n]) == "P")
+ {
+ n++;
+ password = args[n++];
}
X509Store store = null;
case Action.Ssl:
Ssl (file, machine, verbose);
break;
- case Action.ImportKey:\r
- ImportKey (type, machine, file, password, verbose);\r
+ case Action.ImportKey:
+ ImportKey (type, machine, file, password, verbose);
break;
default:
throw new NotSupportedException (action.ToString ());