public override string ToString() { StringBuilder sb = new StringBuilder(); sb.AppendLine("AllowMultiSigning=" + AllowMultiSigning.ToString()); sb.AppendLine("CertificateFile=" + CertificateFile.ToString()); sb.AppendLine("DisplaySignatureInDocument=" + DisplaySignatureInDocument.ToString()); sb.AppendLine("Enabled=" + Enabled.ToString()); sb.AppendLine("LeftX=" + LeftX.ToString()); sb.AppendLine("LeftY=" + LeftY.ToString()); sb.AppendLine("RightX=" + RightX.ToString()); sb.AppendLine("RightY=" + RightY.ToString()); sb.AppendLine("SignContact=" + SignContact.ToString()); sb.AppendLine("SignLocation=" + SignLocation.ToString()); sb.AppendLine("SignReason=" + SignReason.ToString()); sb.AppendLine("SignatureCustomPage=" + SignatureCustomPage.ToString()); sb.AppendLine("SignaturePage=" + SignaturePage.ToString()); sb.AppendLine("SignaturePassword="******"TimeServerIsSecured=" + TimeServerIsSecured.ToString()); sb.AppendLine("TimeServerLoginName=" + TimeServerLoginName.ToString()); sb.AppendLine("TimeServerPassword="******"TimeServerUrl=" + TimeServerUrl.ToString()); return(sb.ToString()); }
private void AddCertificates(CertificateList uploadedCertificates) { if (_azureService.Components.CloudConfig.Role != null) { foreach (ServiceConfigurationSchema.Certificate certElement in _azureService.Components.CloudConfig.Role.SelectMany(r => r.Certificates).Distinct()) { if (uploadedCertificates == null || (uploadedCertificates.Count <Certificate>(c => c.Thumbprint.Equals( certElement.thumbprint, StringComparison.OrdinalIgnoreCase)) < 1)) { X509Certificate2 cert = General.GetCertificateFromStore(certElement.thumbprint); CertificateFile certFile = null; try { certFile = new CertificateFile { Data = Convert.ToBase64String(cert.Export(X509ContentType.Pfx, string.Empty)), Password = string.Empty, CertificateFormat = "pfx" }; } catch (CryptographicException exception) { throw new ArgumentException(string.Format(Resources.CertificatePrivateKeyAccessError, certElement.name), exception); } RetryCall(subscription => Channel.AddCertificates(subscription, _hostedServiceName, certFile)); WaitForCertificateToBeAdded(certElement); } } } }
public void Do_not_add_duplicate_files() { var certificate = new Certificate(); var file = new CertificateFile(); certificate.NewFile(file); certificate.NewFile(file); Assert.That(certificate.CertificateFiles.Count, Is.EqualTo(1)); }
public IAsyncResult BeginAddCertificates(string subscriptionId, string serviceName, CertificateFile input, AsyncCallback callback, object state) { SimpleServiceManagementAsyncResult result = new SimpleServiceManagementAsyncResult(); result.Values["subscriptionId"] = subscriptionId; result.Values["serviceName"] = serviceName; result.Values["input"] = input; result.Values["callback"] = callback; result.Values["state"] = state; return result; }
public void Create_HashesStream() { using (var stream = new MemoryStream(Encoding.UTF8.GetBytes("abc"))) { var file = CertificateFile.Create(stream); Assert.Equal("a9993e364706816aba3e25717850c26c9cd0d89d", file.Sha1Thumbprint); Assert.Equal("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", file.Sha256Thumbprint); } }
public void Create_HashesEmptyStream() { using (var stream = new MemoryStream()) { var file = CertificateFile.Create(stream); Assert.Equal("da39a3ee5e6b4b0d3255bfef95601890afd80709", file.Sha1Thumbprint); Assert.Equal("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", file.Sha256Thumbprint); } }
public void Create_CreatesReadOnlyCopyOfStream() { using (var stream = new MemoryStream()) { var file = CertificateFile.Create(stream); Assert.False(file.Stream.CanWrite); Assert.Equal(0, file.Stream.Position); Assert.NotSame(stream, file.Stream); } }
protected override void PerformOperation(IServiceManagement channel) { var input = new CertificateFile() { CertificateFormat = Cert_format, Password = Cert_Password, }; input.Data = Convert.ToBase64String(File.ReadAllBytes(Cert_file)); Console.WriteLine("Adding Certificate"); channel.AddCertificates(SubscriptionId, HostedServiceName, input); }
internal void ExecuteCommand() { Password = Password ?? string.Empty; var certData = GetCertificateData(); var certificateFile = new CertificateFile { Data = Convert.ToBase64String(certData), Password = Password, CertificateFormat = "pfx" }; ExecuteClientActionInOCS(null, CommandRuntime.ToString(), s => this.Channel.AddCertificates(s, this.ServiceName, certificateFile)); }
/// <summary> /// Connect to an Azure subscription and obtain a certificate. /// </summary> /// <returns>The asynchronous operation identifier.</returns> protected override string AzureExecute() { CertificateFile file = this.CreateFileFromCertificate(); try { this.RetryCall(s => this.Channel.AddCertificates(s, this.ServiceName.Get(this.ActivityContext), file)); return(BaseAzureAsynchronousActivity.RetrieveOperationId()); } catch (EndpointNotFoundException ex) { this.LogBuildMessage(ex.Message); return(null); } }
public static CertificateFile Create(X509Certificate2 certificate, bool dropPrivateKey) { if (dropPrivateKey) { certificate = DropPrivateKey(certificate); } var password = CertUtils.RandomBase64PasswordString(); var certificateData = GetCertificateData(certificate, password); var certificateFile = new CertificateFile { Data = Convert.ToBase64String(certificateData), Password = password, CertificateFormat = "pfx" }; return certificateFile; }
public static CertificateFile Create(X509Certificate2 certificate, bool dropPrivateKey) { if (dropPrivateKey) { certificate = DropPrivateKey(certificate); } var password = CertUtils.RandomBase64PasswordString(); var certificateData = GetCertificateData(certificate, password); var certificateFile = new CertificateFile { Data = Convert.ToBase64String(certificateData), Password = password, CertificateFormat = "pfx" }; return(certificateFile); }
private void AddFile(string certificatesPath, string certificateFilename, IList <CertificateFile> list) { var originFileName = Path.Combine(certificatesPath, certificateFilename); if (File.Exists(originFileName)) { var tempFile = Path.GetTempFileName(); File.Copy(originFileName, tempFile, true); var certificateFile = new CertificateFile(tempFile, certificateFilename, originFileName); if (String.IsNullOrWhiteSpace(certificateFile.Extension) || (!certificateFile.Extension.Equals(".tif", StringComparison.OrdinalIgnoreCase) && !certificateFile.Extension.Equals(".jpg", StringComparison.OrdinalIgnoreCase))) { certificateFile.Extension = ".tif"; } list.Add(certificateFile); } }
public Certificate Certificate(Catalog catalog, string certificateSource = null) { var serial = DateTime.Today.ToShortDateString(); var certificate = new Certificate { SerialNumber = serial, Product = catalog }; var certificateFile = new CertificateFile { CertificateSourceId = certificateSource, Extension = ".tif" }; certificate.Files.Add(certificateFile); session.Save(certificateFile); session.Save(certificate); return(certificate); }
private void verifyCertificate(string path) { var disallowed = false; try { var certificate = new CertificateFile(new X509Certificate2(path)); disallowed = certificate.IsDisallowed; certificate.Dispose(); } catch (CryptographicException ex) { error($"Certificate error: {ex.Message}, path={path}"); } if (disallowed) { if (clean) { try { File.Delete(path); log($"Verified {path}: Disallowed and deleted."); } catch (Exception ex) { error($"Error deleting file {path}: {ex.Message}"); } } else { log($"Verified {path}: Disallowed."); } } else { log($"Verified {path}: NOT disallowed."); } }
internal void AddCertificateProcess() { Action <string> action = null; this.ValidateParameters(); byte[] certificateData = this.GetCertificateData(); CertificateFile certificateFile = new CertificateFile(); certificateFile.Data = Convert.ToBase64String(certificateData); certificateFile.Password = this.Password; certificateFile.CertificateFormat = "pfx"; CertificateFile certificateFile1 = certificateFile; using (OperationContextScope operationContextScope = new OperationContextScope((IContextChannel)base.Channel)) { try { AddAzureCertificateCommand addAzureCertificateCommand = this; if (action == null) { action = (string s) => base.Channel.AddCertificates(s, this.ServiceName, certificateFile1); } ((CmdletBase <IServiceManagement>)addAzureCertificateCommand).RetryCall(action); Operation operation = base.WaitForOperation(base.CommandRuntime.ToString()); ManagementOperationContext managementOperationContext = new ManagementOperationContext(); managementOperationContext.set_OperationDescription(base.CommandRuntime.ToString()); managementOperationContext.set_OperationId(operation.OperationTrackingId); managementOperationContext.set_OperationStatus(operation.Status); ManagementOperationContext managementOperationContext1 = managementOperationContext; base.WriteObject(managementOperationContext1, true); } catch (CommunicationException communicationException1) { CommunicationException communicationException = communicationException1; this.WriteErrorDetails(communicationException); } } }
private void GetCertificateFile() { this.CertificateInfoGroup.Visibility = Visibility.Collapsed; var password = this.CertPasswordText.Password; var certFile = this.OpenFileDialog(); if (certFile != null) { try { var certificate = string.IsNullOrEmpty(password) ? new X509Certificate2(certFile.Content) : new X509Certificate2(certFile.Content, password); this.PrintCertificateInfo(certificate); _lastSelectedCertificate = certificate; _lastSelectedFile = certFile; } catch (CryptographicException e) { MessageBox.Show(e.Message, $"Can't open: {certFile.FileName}"); } } }
private void AddCertificates(CertificateList uploadedCertificates, PublishContext context) { string name = context.ServiceName; AzureService cloudServiceProject = new AzureService(context.RootPath, null); if (cloudServiceProject.Components.CloudConfig.Role != null) { foreach (ConfigCertificate certElement in cloudServiceProject.Components.CloudConfig.Role. SelectMany(r => r.Certificates ?? new ConfigCertificate[0]).Distinct()) { if (uploadedCertificates == null || (uploadedCertificates.Count(c => c.Thumbprint.Equals( certElement.thumbprint, StringComparison.OrdinalIgnoreCase)) < 1)) { X509Certificate2 cert = General.GetCertificateFromStore(certElement.thumbprint); CertificateFile certFile = null; try { certFile = new CertificateFile { Data = Convert.ToBase64String(cert.Export(X509ContentType.Pfx, string.Empty)), Password = string.Empty, CertificateFormat = "pfx" }; } catch (CryptographicException exception) { throw new ArgumentException(string.Format( Resources.CertificatePrivateKeyAccessError, certElement.name), exception); } CallSync(() => ServiceManagementChannel.AddCertificates(subscriptionId, name, certFile)); } } } }
private void AddCertificates(CertificateList uploadedCertificates, PublishContext context) { string name = context.ServiceName; CloudServiceProject cloudServiceProject = new CloudServiceProject(context.RootPath, null); if (cloudServiceProject.Components.CloudConfig.Role != null) { foreach (ConfigCertificate certElement in cloudServiceProject.Components.CloudConfig.Role. SelectMany(r => r.Certificates ?? new ConfigCertificate[0]).Distinct()) { if (uploadedCertificates == null || (uploadedCertificates.Count(c => c.Thumbprint.Equals( certElement.thumbprint, StringComparison.OrdinalIgnoreCase)) < 1)) { X509Certificate2 cert = General.GetCertificateFromStore(certElement.thumbprint); CertificateFile certFile = null; try { certFile = new CertificateFile { Data = Convert.ToBase64String(cert.Export(X509ContentType.Pfx, string.Empty)), Password = string.Empty, CertificateFormat = "pfx" }; } catch (CryptographicException exception) { throw new ArgumentException(string.Format( Resources.CertificatePrivateKeyAccessError, certElement.name), exception); } CallSync(() => ServiceManagementChannel.AddCertificates(subscriptionId, name, certFile)); } } } }
public override bool Equals(object o) { if (!(o is Signature)) { return(false); } Signature v = o as Signature; if (!AllowMultiSigning.Equals(v.AllowMultiSigning)) { return(false); } if (!CertificateFile.Equals(v.CertificateFile)) { return(false); } if (!DisplaySignatureInDocument.Equals(v.DisplaySignatureInDocument)) { return(false); } if (!Enabled.Equals(v.Enabled)) { return(false); } if (!LeftX.Equals(v.LeftX)) { return(false); } if (!LeftY.Equals(v.LeftY)) { return(false); } if (!RightX.Equals(v.RightX)) { return(false); } if (!RightY.Equals(v.RightY)) { return(false); } if (!SignContact.Equals(v.SignContact)) { return(false); } if (!SignLocation.Equals(v.SignLocation)) { return(false); } if (!SignReason.Equals(v.SignReason)) { return(false); } if (!SignatureCustomPage.Equals(v.SignatureCustomPage)) { return(false); } if (!SignaturePage.Equals(v.SignaturePage)) { return(false); } if (!SignaturePassword.Equals(v.SignaturePassword)) { return(false); } if (!TimeServerAccountId.Equals(v.TimeServerAccountId)) { return(false); } return(true); }
public void Create_WhenStreamIsNull_Throws() { var exception = Assert.Throws <ArgumentNullException>(() => CertificateFile.Create(stream: null)); Assert.Equal("stream", exception.ParamName); }
internal void ExecuteCommand() { Password = Password ?? string.Empty; var certData = GetCertificateData(); var certificateFile = new CertificateFile { Data = Convert.ToBase64String(certData), Password = Password, CertificateFormat = Resources.Pfx_CertificateFormat }; ExecuteClientActionInOCS(null, CommandRuntime.ToString(), s => this.Channel.AddCertificates(s, this.ServiceName, certificateFile)); }
public static void AddCertificates(this IServiceManagement proxy, string subscriptionId, string serviceName, CertificateFile input) { proxy.EndAddCertificates(proxy.BeginAddCertificates(subscriptionId, serviceName, input, null, null)); }
private CertificateFile Find(CertificateFile file) { return (CertificateFile.Queryable.FirstOrDefault( e => e.CertificateSource.Id == file.CertificateSource.Id && e.ExternalFileId == file.ExternalFileId)); }
private void AddCertificates(CertificateList uploadedCertificates) { if (_azureService.Components.CloudConfig.Role != null) { foreach (ServiceConfigurationSchema.Certificate certElement in _azureService.Components.CloudConfig.Role.SelectMany(r => r.Certificates).Distinct()) { if (uploadedCertificates == null || (uploadedCertificates.Count<Certificate>(c => c.Thumbprint.Equals( certElement.thumbprint, StringComparison.OrdinalIgnoreCase)) < 1)) { X509Certificate2 cert = General.GetCertificateFromStore(certElement.thumbprint); CertificateFile certFile = null; try { certFile = new CertificateFile { Data = Convert.ToBase64String(cert.Export(X509ContentType.Pfx, string.Empty)), Password = string.Empty, CertificateFormat = "pfx" }; } catch (CryptographicException exception) { throw new ArgumentException(string.Format(Resources.CertificatePrivateKeyAccessError, certElement.name), exception); } RetryCall(subscription => Channel.AddCertificates(subscription, _hostedServiceName, certFile)); WaitForCertificateToBeAdded(certElement); } } } }