public void CreateNewCertificate() { var certificate = new Certificate() { Name = "test.cert.1", Description = "Test Certificate 1", Password = "******" }; CertificateRow newCertificate = null; try { this.certificateRepository.CreateCertificate(certificate); string key = certificate.Id.ToString(); newCertificate = this.certificateTable.Query.Where(c => c.RowKey == key).FirstOrDefault(); Assert.IsNotNull(newCertificate); } finally { if (newCertificate != null) { this.certificateTable.DeleteEntity(newCertificate); } } }
public void CreateCertificate(Certificate certificate) { this.certificateTable.AddEntity(certificate.ToRow()); if (certificate.Content != null) { this.certificateBlobContainer.SaveFile(certificate.Id.ToString(), certificate.Content, CertificateContentType); } }
public X509Certificate2 InstallCertificate(Certificate certificate, X509Store store) { byte[] content = this.certificateBlobContainer.GetBytes(certificate.Id.ToString()); var cert = new X509Certificate2(content, certificate.Password); store.Open(OpenFlags.ReadWrite); store.Add(cert); TraceHelper.TraceInformation("Certificate {0} installed; Friendly Name: {1}", certificate.Name, cert.FriendlyName); return cert; }
public ActionResult Create(CertificateCreateModel model, HttpPostedFileBase file) { try { var certificate = new Certificate() { Name = model.Name, Description = model.Description, Password = model.Password }; if ((file == null) || string.IsNullOrEmpty(file.FileName)) { var msg = "A pfx certificate file must be specified"; ModelState.AddModelError("file", msg); ViewBag.CertificateError = msg; return View(); } else if (!Path.GetExtension(file.FileName).Equals(".pfx", StringComparison.OrdinalIgnoreCase)) { var msg = "Only pfx certificates can be uploaded"; ModelState.AddModelError("file", msg); ViewBag.CertificateError = msg; return View(); } if (file.ContentLength > 0) { byte[] buffer = new byte[file.ContentLength]; file.InputStream.Read(buffer, 0, file.ContentLength); certificate.Content = buffer; } this.certificateRepository.CreateCertificate(certificate); return RedirectToAction("Index"); } catch { return View(); } }
public void CreateNewCertificateWithContent() { var certificate = new Certificate() { Name = "test.cert.1", Description = "Test Certificate 1", Password = "******", Content = File.ReadAllBytes("azureacceleratorstest.cloudapp.net.pfx") }; CertificateRow newcertificate = null; try { this.certificateRepository.CreateCertificate(certificate); string key = certificate.Id.ToString(); newcertificate = this.certificateTable.Query.Where(c => c.RowKey == key).FirstOrDefault(); Assert.IsNotNull(newcertificate); Stream stream = this.certificateBlobContainer.GetFile(key); Assert.IsNotNull(stream); stream.Close(); } finally { if (newcertificate != null) { this.certificateTable.DeleteEntity(newcertificate); } this.certificateBlobContainer.Delete(certificate.Id.ToString()); } }
public void UpdateCertificate(Certificate certificate) { this.certificateTable.AddOrUpdateEntity(certificate.ToRow()); }