public StatusMessage SubmitCertificate(string certAlias) { try { var result = ACMESharpUtils.SubmitCertificate(certAlias, protectSensitiveFileStorage: UseEFSForSensitiveFiles); return(new StatusMessage { IsOK = true, Result = result }); } catch (Exception exp) { if (exp is ACMESharp.AcmeClient.AcmeWebException) { var aex = (ACMESharp.AcmeClient.AcmeWebException)exp; return(new StatusMessage { IsOK = false, Message = aex.Message, Result = aex }); } else { return(new StatusMessage { IsOK = false, Message = exp.Message, Result = exp }); } } }
public APIResult SubmitCertificate(string certAlias) { try { var result = ACMESharpUtils.SubmitCertificate(certAlias); return(new APIResult { IsOK = true, Result = result }); } catch (Exception exp) { if (exp is ACMESharp.AcmeClient.AcmeWebException) { var aex = (ACMESharp.AcmeClient.AcmeWebException)exp; return(new APIResult { IsOK = false, Message = aex.Message, Result = aex }); } else { return(new APIResult { IsOK = false, Message = exp.Message, Result = exp }); } } }
static void Main(string[] args) { Trace.EnableConsole(); Trace.EnableFile(); if (!CheckParmeter()) { return; } Trace.Info("check config ok!~"); InitializeVault(); Trace.Info("init vault ok!~"); try { ACMESharpUtils.NewRegistration("", new string[] { "mailto:" + Config.Mail }, true); } catch (Exception ex) { Trace.Error("registration error", ex); return; } Trace.Info("registration ok!~"); try { ACMESharpUtils.NewIdentifier("dns1", Config.Domain); } catch (Exception ex) { Trace.Error("newidentityfier error", ex); return; } Trace.Info("newidentityfier ok!~"); try { AuthorizationState state = ACMESharpUtils.CompleteChallenge("dns1", "http-01", "manual"); if (!CreateChallengeFile(state)) { Trace.Error("create challenge file erro"); return; } } catch (Exception ex) { Trace.Error("complete challenge error", ex); return; } Trace.Info("challege ok"); try { ACMESharpUtils.SubmitChallenge("dns1", "http-01"); } catch (Exception ex) { Trace.Error("submit challenge error", ex); return; } Trace.Info("submit challage ok!~"); Trace.Info("wait LE identifier"); DateTime startT = DateTime.Now; bool result = false; while ((DateTime.Now - startT).TotalSeconds < 300) { AuthorizationState state = null; try { state = ACMESharpUtils.UpdateIdentifier("dns1", "http-01"); } catch (Exception ex) { Trace.Error("update identifier error"); return; } if (state == null) { Trace.Error("update identifier state is null"); return; } var subResultState = state.Challenges.First <ACMESharp.AuthorizeChallenge>(item => item.Type == "http-01"); if (subResultState == null) { SaveState(state); Trace.Error("state is null"); return; } if (subResultState.Status.Equals("valid", StringComparison.CurrentCultureIgnoreCase)) { result = true; break; } else if (subResultState.Status.Equals("invalid", StringComparison.CurrentCultureIgnoreCase)) { SaveState(state); Trace.Error("state is invalid"); return; } else { Trace.Info(DateTime.Now.ToString("HH:mm:ss") + ",status is:" + subResultState.Status); } System.Threading.Thread.Sleep(5000); } if (!result) { Trace.Error("update identifer timeout"); return; } Trace.Info("update identifier ok!~"); try { ACMESharpUtils.NewCertificate("cert1", "dns1", null); } catch (Exception ex) { Trace.Error("new certificate erro", ex); return; } Trace.Info("new certificate is ok!~"); try { ACMESharpUtils.SubmitCertificate("cert1"); } catch (Exception ex) { Trace.Error("submit certificateerro", ex); return; } Trace.Info("submit certificate is ok!~"); try { CertificateInfo info = ACMESharpUtils.UpdateCertificate("cert1"); } catch (Exception ex) { Trace.Error("update certificate erro", ex); return; } Trace.Info("update certificate is ok!~"); if (!GenericCertificate()) { return; } Trace.Info("success!~"); if (Environment.UserInteractive) { Trace.Info("Enter press any key exit!~"); Console.ReadKey(); } }