/// <summary> /// Finalizes the certificate order. /// </summary> /// <param name="context">The order context.</param> /// <param name="csr">The CSR.</param> /// <param name="key">The private key for the certificate.</param> /// <returns> /// The order finalized. /// </returns> public static async Task <Order> Finalize(this IOrderContext context, CsrInfo csr, IKey key) { var builder = await context.CreateCsr(key); foreach (var(name, value) in csr.Fields) { builder.AddName(name, value); } if (string.IsNullOrWhiteSpace(csr.CommonName)) { builder.AddName("CN", builder.SubjectAlternativeNames[0]); } return(await context.Finalize(builder.Generate())); }
public void CanSetInfo() { var csr = new CsrInfo { CommonName = "CommonName", Locality = "Locality", CountryName = "CountryName", Organization = "Organization", OrganizationUnit = "OrganizationUnit", State = "State", }; Assert.Equal("CommonName", csr.Fields.Single(f => f.name == "CN").value); Assert.Equal("Locality", csr.Fields.Single(f => f.name == "L").value); Assert.Equal("CountryName", csr.Fields.Single(f => f.name == "C").value); Assert.Equal("Organization", csr.Fields.Single(f => f.name == "O").value); Assert.Equal("OrganizationUnit", csr.Fields.Single(f => f.name == "OU").value); Assert.Equal("State", csr.Fields.Single(f => f.name == "ST").value); }
/// <summary> /// Finalizes and download the certifcate for the order. /// </summary> /// <param name="context">The order context.</param> /// <param name="csr">The CSR.</param> /// <param name="key">The private key for the certificate.</param> /// <returns> /// The certificate generated. /// </returns> public static async Task <CertificateChain> Generate(this IOrderContext context, CsrInfo csr, IKey key) { var order = await context.Resource(); if (order.Status != OrderStatus.Ready && // draft-11 order.Status != OrderStatus.Pending) // pre draft-11 { throw new AcmeException(string.Format(Strings.ErrorInvalidOrderStatusForFinalize, order.Status)); } order = await context.Finalize(csr, key); if (order.Status != OrderStatus.Valid) { throw new AcmeException(Strings.ErrorFinalizeFailed); } return(await context.Download()); }
/// <summary> /// Finalizes and download the certifcate for the order. /// </summary> /// <param name="context">The order context.</param> /// <param name="csr">The CSR.</param> /// <param name="key">The private key for the certificate.</param> /// <returns> /// The certificate generated. /// </returns> public static async Task <CertificateChain> Generate(this IOrderContext context, CsrInfo csr, IKey key) { var order = await context.Resource(); if (order.Status != OrderStatus.Pending) { throw new Exception($"Can not finalize order with status {order.Status}."); } order = await context.Finalize(csr, key); if (order.Status != OrderStatus.Valid) { throw new Exception("Failto finalize order."); } return(await context.Download()); }
/// <summary> /// Finalizes and download the certifcate for the order. /// </summary> /// <param name="context">The order context.</param> /// <param name="csr">The CSR.</param> /// <param name="key">The private key for the certificate.</param> /// <param name="retryCount">Number of retries when the Order is in 'processing' state. (default = 1)</param> /// <param name="preferredChain">The preferred Root Certificate.</param> /// <returns> /// The certificate generated. /// </returns> public static async Task <CertificateChain> Generate(this IOrderContext context, CsrInfo csr, IKey key, string preferredChain = null, int retryCount = 1) { var order = await context.Resource(); if (order.Status != OrderStatus.Ready && // draft-11 order.Status != OrderStatus.Pending) // pre draft-11 { throw new AcmeException(string.Format(Strings.ErrorInvalidOrderStatusForFinalize, order.Status)); } order = await context.Finalize(csr, key); while (order.Status == OrderStatus.Processing && retryCount-- > 0) { await Task.Delay(TimeSpan.FromSeconds(Math.Max(context.RetryAfter, 1))); order = await context.Resource(); } if (order.Status != OrderStatus.Valid) { throw new AcmeException(Strings.ErrorFinalizeFailed); } return(await context.Download(preferredChain)); }