static void Main (string[] args)
{
string password = null;
Header ();
if (args.Length < 2) {
Help ();
return;
}
Action action = GetAction (args [0]);
ObjectType type = ObjectType.None;
int n = 1;
if (action != Action.Ssl) {
type = GetObjectType (args [n]);
if (type != ObjectType.None)
n++;
}
bool verbose = (GetCommand (args [n]) == "V");
if (verbose)
n++;
bool machine = (GetCommand (args [n]) == "M");
if (machine)
n++;
if (GetCommand (args [n]) == "P")
{
n++;
password = args[n++];
}
X509Store store = null;
string storeName = null;
if (action != Action.Ssl) {
if ((action == Action.None) || (type == ObjectType.None)) {
Help ();
return;
}
if (type == ObjectType.CTL) {
Console.WriteLine ("CTL are not supported");
return;
}
storeName = args [n++];
store = GetStoreFromName (storeName, machine);
if (store == null) {
Console.WriteLine ("Invalid Store: {0}", storeName);
Console.WriteLine ("Valid stores are: {0}, {1}, {2}, {3} and {4}",
X509Stores.Names.Personal,
X509Stores.Names.OtherPeople,
X509Stores.Names.IntermediateCA,
X509Stores.Names.TrustedRoot,
X509Stores.Names.Untrusted);
return;
}
}
string file = (n < args.Length) ? args [n] : null;
// now action!
try {
switch (action) {
case Action.Add:
Add (type, store, file, password, verbose);
break;
case Action.Delete:
Delete (type, store, file, verbose);
break;
case Action.Put:
Put (type, store, file, password, verbose);
break;
case Action.List:
List (type, store, machine, file, verbose);
break;
case Action.Ssl:
Ssl (file, machine, verbose);
break;
case Action.ImportKey:
ImportKey (type, machine, file, password, verbose);
break;
default:
throw new NotSupportedException (action.ToString ());
}
}
catch (UnauthorizedAccessException uae) {
Console.WriteLine ("Access to the {0} '{1}' certificate store has been denied.",
(machine ? "machine" : "user"), storeName);
if (verbose) {
Console.WriteLine (uae);
}
}
}
}