private void DoWork() { Context = X509Context.Select(Location, false); var Aliases = Context.GetAliases(Constants.DoNotIncludeIfCertNotFound); Aliases.ForEach(p => Result.Add(new X509AliasDescription(p))); var AssignedThumbprints = Aliases.Select(p => p.Certificate.Thumbprint.ToUpper()).ToList(); if (All) { using (var Store = new X509Store(Context.Location)) { Store.Open(OpenFlags.ReadOnly); foreach (X509Certificate2 Cert in Store.Certificates) { if (!AssignedThumbprints.Contains(Cert.Thumbprint.ToUpper())) { Result.Add(new X509AliasDescription(Cert)); } } } } }
private void DoWork() { Console.WriteLine($"Path: {Path}"); var Context = X509Context.Select(Location, true); var Alias = Context.GetAliases(true).FirstOrDefault(p => p.Name.Matches(Name)); if (null != Alias) { if (!Overwrite || !Util.WarnConfirm($"An existing {nameof(X509Alias)} with the name {Name.InQuotes()} exists in the {Context.Name} {nameof(X509Context)}. OK to overwrite?", Constants.Affirm)) { throw new X509CryptoException($"Could not import the certificate. An {nameof(X509Alias)} with the name {Name.InQuotes()} exists in the {Context.Name} {nameof(X509Context)}"); } } var PfxPassword = Util.GetPassword($"Enter the password to unlock {System.IO.Path.GetFileName(Path).InQuotes()}", 0); var thumbprint = X509Utils.InstallCert(Path, PfxPassword, Context); StringBuilder Expression = new StringBuilder($"Added encryption certificate to the {Context.Name} {nameof(X509Context)}. \r\nCertificate Thumbprint: {thumbprint}"); if (null != Alias && Alias.HasCert(Context)) { Alias.ReEncrypt(thumbprint, Context); Expression.AppendLine($"\r\nAll secrets contained in the existing {nameof(X509Alias)} {Alias.Name.InQuotes()} have been re-encrypted using the new certificate."); } else { Alias = new X509Alias(Name, thumbprint, Context, false); Alias.Commit(); Expression.Append($"\r\n {nameof(X509Alias)}: {Name}"); } Util.ConsoleMessage(Expression.ToString()); Result = Alias; }
private void DoWork() { context = X509Context.Select(Location, true); X509Alias Alias = new X509Alias(Name, context); Result = Alias; Console.WriteLine($"Alias {Name.InQuotes()} has been loaded from the {context.Name.InQuotes()} {nameof(X509Context)}"); }
private void DoWork() { context = X509Context.Select(Location, true); if (string.IsNullOrEmpty(Thumbprint)) { Thumbprint = MakeCert(); } X509Alias Alias = new X509Alias(Name, Thumbprint, context, true); Alias.Commit(); Result = Alias; Console.WriteLine($"New alias {Name.InQuotes()} committed to {context.Name.InQuotes()} {nameof(X509Context)}\r\nThumbprint: {Alias.Thumbprint}"); }
private void DoWork() { var Context = X509Context.Select(Location, true); var AliasToImport = X509Alias.Import(Path, Context, Name); if (!Overwrite && X509Alias.AliasExists(AliasToImport)) { throw new X509AliasAlreadyExistsException(AliasToImport); } AliasToImport.Commit(); Util.ConsoleMessage($"{nameof(X509Alias)} {AliasToImport.Name.InQuotes()} has been successfully imported into the {Context.Name} {nameof(X509Context)} from the file {Path.InQuotes()}"); if (!X509CryptoAgent.CertificateExists(AliasToImport)) { Util.ConsoleWarning($"An encryption certificate with thumbprint {AliasToImport.Thumbprint.InQuotes()} could not be found in the {Context.Name} {nameof(X509Context)}. Ensure this certificate is installed on the system before using this alias."); } Result = AliasToImport; }
private void DoWork() { X509Context OldContext, NewContext; OldContext = Alias.Context; if (contextSet) { NewContext = X509Context.Select(Location, false); } else { NewContext = Alias.Context; } if (!X509CryptoAgent.CertificateExists(Thumbprint, NewContext)) { throw new X509CryptoCertificateNotFoundException(Thumbprint, NewContext); } Alias.ReEncrypt(Thumbprint, NewContext); Alias.Commit(); Console.WriteLine($"{nameof(X509Alias)} {Alias.Name} successfully updated. Now using encryption certificate with thumbprint {Thumbprint} from the {NewContext.Name} {nameof(X509Context)}"); }