Permalink
Browse files

NowinAcme client with sample Nowin server.

  • Loading branch information...
1 parent 84cfa44 commit da58fe967c158ecf581d1f37e857fcb9260df112 @Bobris committed Dec 21, 2015
Showing with 559,606 additions and 2 deletions.
  1. +14 −2 Nowin.sln
  2. +121 −0 NowinAcme/AcmeProcess.cs
  3. +17 −0 NowinAcme/IAcmeConfiguration.cs
  4. +83 −0 NowinAcme/NowinAcme.cs
  5. +81 −0 NowinAcme/NowinAcme.csproj
  6. +36 −0 NowinAcme/Properties/AssemblyInfo.cs
  7. +11 −0 NowinAcme/app.config
  8. +12 −0 NowinAcme/packages.config
  9. +22 −0 NowinAcmeSample/App.config
  10. +105 −0 NowinAcmeSample/NowinAcmeSample.csproj
  11. +113 −0 NowinAcmeSample/Program.cs
  12. +35 −0 NowinAcmeSample/Properties/AssemblyInfo.cs
  13. +4 −0 NowinAcmeSample/packages.config
  14. BIN packages/Microsoft.AspNet.WebApi.Client.5.2.3/Microsoft.AspNet.WebApi.Client.5.2.3.nupkg
  15. BIN packages/Microsoft.AspNet.WebApi.Client.5.2.3/lib/net45/System.Net.Http.Formatting.dll
  16. +2,094 −0 packages/Microsoft.AspNet.WebApi.Client.5.2.3/lib/net45/System.Net.Http.Formatting.xml
  17. BIN ...et.WebApi.Client.5.2.3/lib/portable-wp8+netcore45+net45+wp81+wpa81/System.Net.Http.Formatting.dll
  18. +4,025 −0 ...et.WebApi.Client.5.2.3/lib/portable-wp8+netcore45+net45+wp81+wpa81/System.Net.Http.Formatting.xml
  19. BIN packages/Newtonsoft.Json.8.0.1-beta3/Newtonsoft.Json.8.0.1-beta3.nupkg
  20. BIN packages/Newtonsoft.Json.8.0.1-beta3/lib/net20/Newtonsoft.Json.dll
  21. +9,653 −0 packages/Newtonsoft.Json.8.0.1-beta3/lib/net20/Newtonsoft.Json.xml
  22. BIN packages/Newtonsoft.Json.8.0.1-beta3/lib/net35/Newtonsoft.Json.dll
  23. +8,796 −0 packages/Newtonsoft.Json.8.0.1-beta3/lib/net35/Newtonsoft.Json.xml
  24. BIN packages/Newtonsoft.Json.8.0.1-beta3/lib/net40/Newtonsoft.Json.dll
  25. +9,103 −0 packages/Newtonsoft.Json.8.0.1-beta3/lib/net40/Newtonsoft.Json.xml
  26. BIN packages/Newtonsoft.Json.8.0.1-beta3/lib/net45/Newtonsoft.Json.dll
  27. +9,103 −0 packages/Newtonsoft.Json.8.0.1-beta3/lib/net45/Newtonsoft.Json.xml
  28. BIN packages/Newtonsoft.Json.8.0.1-beta3/lib/portable-net40+sl5+wp80+win8+wpa81/Newtonsoft.Json.dll
  29. +8,281 −0 packages/Newtonsoft.Json.8.0.1-beta3/lib/portable-net40+sl5+wp80+win8+wpa81/Newtonsoft.Json.xml
  30. BIN ...ages/Newtonsoft.Json.8.0.1-beta3/lib/portable-net45+wp80+win8+wpa81+dnxcore50/Newtonsoft.Json.dll
  31. +8,628 −0 ...ages/Newtonsoft.Json.8.0.1-beta3/lib/portable-net45+wp80+win8+wpa81+dnxcore50/Newtonsoft.Json.xml
  32. +116 −0 packages/Newtonsoft.Json.8.0.1-beta3/tools/install.ps1
  33. BIN packages/Oocx.ACME.0.0.0-beta-75/Oocx.ACME.0.0.0-beta-75.nupkg
  34. BIN packages/Oocx.ACME.0.0.0-beta-75/lib/dnx46/Oocx.ACME.dll
  35. +78 −0 packages/Oocx.ACME.0.0.0-beta-75/lib/dnx46/Oocx.ACME.xml
  36. BIN packages/Oocx.ACME.0.0.0-beta-75/lib/dnxcore50/Oocx.ACME.dll
  37. +78 −0 packages/Oocx.ACME.0.0.0-beta-75/lib/dnxcore50/Oocx.ACME.xml
  38. BIN packages/Oocx.ACME.0.0.0-beta-75/lib/net46/Oocx.ACME.dll
  39. +78 −0 packages/Oocx.ACME.0.0.0-beta-75/lib/net46/Oocx.ACME.xml
  40. BIN packages/Oocx.ACME.Common.0.0.0-beta-75/Oocx.ACME.Common.0.0.0-beta-75.nupkg
  41. BIN packages/Oocx.ACME.Common.0.0.0-beta-75/lib/dnx46/Oocx.ACME.Common.dll
  42. +8 −0 packages/Oocx.ACME.Common.0.0.0-beta-75/lib/dnx46/Oocx.ACME.Common.xml
  43. BIN packages/Oocx.ACME.Common.0.0.0-beta-75/lib/dnxcore50/Oocx.ACME.Common.dll
  44. +8 −0 packages/Oocx.ACME.Common.0.0.0-beta-75/lib/dnxcore50/Oocx.ACME.Common.xml
  45. BIN packages/Oocx.ACME.Common.0.0.0-beta-75/lib/net46/Oocx.ACME.Common.dll
  46. +8 −0 packages/Oocx.ACME.Common.0.0.0-beta-75/lib/net46/Oocx.ACME.Common.xml
  47. BIN packages/Oocx.Asn1PKCS.0.0.0-beta-75/Oocx.Asn1PKCS.0.0.0-beta-75.nupkg
  48. BIN packages/Oocx.Asn1PKCS.0.0.0-beta-75/lib/dnx46/Oocx.Asn1PKCS.dll
  49. +62 −0 packages/Oocx.Asn1PKCS.0.0.0-beta-75/lib/dnx46/Oocx.Asn1PKCS.xml
  50. BIN packages/Oocx.Asn1PKCS.0.0.0-beta-75/lib/dnxcore50/Oocx.Asn1PKCS.dll
  51. +62 −0 packages/Oocx.Asn1PKCS.0.0.0-beta-75/lib/dnxcore50/Oocx.Asn1PKCS.xml
  52. BIN packages/Oocx.Asn1PKCS.0.0.0-beta-75/lib/net46/Oocx.Asn1PKCS.dll
  53. +62 −0 packages/Oocx.Asn1PKCS.0.0.0-beta-75/lib/net46/Oocx.Asn1PKCS.xml
  54. BIN packages/System.Linq.4.0.1-beta-23409/System.Linq.4.0.1-beta-23409.nupkg
  55. BIN packages/System.Linq.4.0.1-beta-23409/lib/dotnet/System.Linq.dll
  56. +1,763 −0 packages/System.Linq.4.0.1-beta-23409/lib/dotnet/System.Linq.xml
  57. +1,763 −0 packages/System.Linq.4.0.1-beta-23409/lib/dotnet/de/System.Linq.xml
  58. +1,853 −0 packages/System.Linq.4.0.1-beta-23409/lib/dotnet/es/System.Linq.xml
  59. +1,898 −0 packages/System.Linq.4.0.1-beta-23409/lib/dotnet/fr/System.Linq.xml
  60. +1,748 −0 packages/System.Linq.4.0.1-beta-23409/lib/dotnet/it/System.Linq.xml
  61. +2,007 −0 packages/System.Linq.4.0.1-beta-23409/lib/dotnet/ja/System.Linq.xml
  62. +1,997 −0 packages/System.Linq.4.0.1-beta-23409/lib/dotnet/ko/System.Linq.xml
  63. +1,561 −0 packages/System.Linq.4.0.1-beta-23409/lib/dotnet/ru/System.Linq.xml
  64. +1,940 −0 packages/System.Linq.4.0.1-beta-23409/lib/dotnet/zh-hans/System.Linq.xml
  65. +1,982 −0 packages/System.Linq.4.0.1-beta-23409/lib/dotnet/zh-hant/System.Linq.xml
  66. 0 packages/System.Linq.4.0.1-beta-23409/lib/net45/_._
  67. BIN packages/System.Linq.4.0.1-beta-23409/lib/netcore50/System.Linq.dll
  68. +1,763 −0 packages/System.Linq.4.0.1-beta-23409/lib/netcore50/System.Linq.xml
  69. 0 packages/System.Linq.4.0.1-beta-23409/lib/win8/_._
  70. 0 packages/System.Linq.4.0.1-beta-23409/lib/wp80/_._
  71. 0 packages/System.Linq.4.0.1-beta-23409/lib/wpa81/_._
  72. BIN packages/System.Linq.4.0.1-beta-23409/ref/dotnet/System.Linq.dll
  73. 0 packages/System.Linq.4.0.1-beta-23409/ref/net45/_._
  74. BIN packages/System.Linq.4.0.1-beta-23409/ref/netcore50/System.Linq.dll
  75. 0 packages/System.Linq.4.0.1-beta-23409/ref/win8/_._
  76. 0 packages/System.Linq.4.0.1-beta-23409/ref/wp80/_._
  77. 0 packages/System.Linq.4.0.1-beta-23409/ref/wpa81/_._
  78. BIN packages/System.Net.Http.4.0.1-beta-23409/System.Net.Http.4.0.1-beta-23409.nupkg
  79. 0 packages/System.Net.Http.4.0.1-beta-23409/lib/net45/_._
  80. 0 packages/System.Net.Http.4.0.1-beta-23409/lib/win8/_._
  81. 0 packages/System.Net.Http.4.0.1-beta-23409/lib/wpa81/_._
  82. BIN packages/System.Net.Http.4.0.1-beta-23409/ref/dotnet/System.Net.Http.dll
  83. 0 packages/System.Net.Http.4.0.1-beta-23409/ref/net45/_._
  84. BIN packages/System.Net.Http.4.0.1-beta-23409/ref/netcore50/System.Net.Http.dll
  85. 0 packages/System.Net.Http.4.0.1-beta-23409/ref/win8/_._
  86. 0 packages/System.Net.Http.4.0.1-beta-23409/ref/wpa81/_._
  87. +19 −0 packages/System.Net.Http.4.0.1-beta-23409/runtime.json
  88. BIN packages/System.Runtime.4.0.21-beta-23409/System.Runtime.4.0.21-beta-23409.nupkg
  89. BIN packages/System.Runtime.4.0.21-beta-23409/lib/DNXCore50/System.Runtime.dll
  90. +15,642 −0 packages/System.Runtime.4.0.21-beta-23409/lib/DNXCore50/System.Runtime.xml
  91. +15,647 −0 packages/System.Runtime.4.0.21-beta-23409/lib/DNXCore50/de/System.Runtime.xml
  92. +15,620 −0 packages/System.Runtime.4.0.21-beta-23409/lib/DNXCore50/es/System.Runtime.xml
  93. +15,856 −0 packages/System.Runtime.4.0.21-beta-23409/lib/DNXCore50/fr/System.Runtime.xml
  94. +15,649 −0 packages/System.Runtime.4.0.21-beta-23409/lib/DNXCore50/it/System.Runtime.xml
  95. +16,970 −0 packages/System.Runtime.4.0.21-beta-23409/lib/DNXCore50/ja/System.Runtime.xml
  96. +16,922 −0 packages/System.Runtime.4.0.21-beta-23409/lib/DNXCore50/ko/System.Runtime.xml
  97. +15,262 −0 packages/System.Runtime.4.0.21-beta-23409/lib/DNXCore50/ru/System.Runtime.xml
  98. +15,922 −0 packages/System.Runtime.4.0.21-beta-23409/lib/DNXCore50/zh-hans/System.Runtime.xml
  99. +15,977 −0 packages/System.Runtime.4.0.21-beta-23409/lib/DNXCore50/zh-hant/System.Runtime.xml
  100. 0 packages/System.Runtime.4.0.21-beta-23409/lib/MonoAndroid10/_._
  101. 0 packages/System.Runtime.4.0.21-beta-23409/lib/MonoTouch10/_._
  102. 0 packages/System.Runtime.4.0.21-beta-23409/lib/net46/_._
  103. BIN packages/System.Runtime.4.0.21-beta-23409/lib/netcore50/System.Runtime.dll
  104. +15,642 −0 packages/System.Runtime.4.0.21-beta-23409/lib/netcore50/System.Runtime.xml
  105. +15,647 −0 packages/System.Runtime.4.0.21-beta-23409/lib/netcore50/de/System.Runtime.xml
  106. +15,620 −0 packages/System.Runtime.4.0.21-beta-23409/lib/netcore50/es/System.Runtime.xml
  107. +15,856 −0 packages/System.Runtime.4.0.21-beta-23409/lib/netcore50/fr/System.Runtime.xml
  108. +15,649 −0 packages/System.Runtime.4.0.21-beta-23409/lib/netcore50/it/System.Runtime.xml
  109. +16,970 −0 packages/System.Runtime.4.0.21-beta-23409/lib/netcore50/ja/System.Runtime.xml
  110. +16,922 −0 packages/System.Runtime.4.0.21-beta-23409/lib/netcore50/ko/System.Runtime.xml
  111. +15,262 −0 packages/System.Runtime.4.0.21-beta-23409/lib/netcore50/ru/System.Runtime.xml
  112. +15,922 −0 packages/System.Runtime.4.0.21-beta-23409/lib/netcore50/zh-hans/System.Runtime.xml
  113. +15,977 −0 packages/System.Runtime.4.0.21-beta-23409/lib/netcore50/zh-hant/System.Runtime.xml
  114. 0 packages/System.Runtime.4.0.21-beta-23409/lib/xamarinios10/_._
  115. 0 packages/System.Runtime.4.0.21-beta-23409/lib/xamarinmac20/_._
  116. 0 packages/System.Runtime.4.0.21-beta-23409/ref/MonoAndroid10/_._
  117. 0 packages/System.Runtime.4.0.21-beta-23409/ref/MonoTouch10/_._
  118. BIN packages/System.Runtime.4.0.21-beta-23409/ref/dotnet/System.Runtime.dll
  119. 0 packages/System.Runtime.4.0.21-beta-23409/ref/net46/_._
  120. 0 packages/System.Runtime.4.0.21-beta-23409/ref/xamarinios10/_._
  121. 0 packages/System.Runtime.4.0.21-beta-23409/ref/xamarinmac20/_._
  122. BIN packages/System.Runtime.4.0.21-beta-23409/runtimes/win8-aot/lib/netcore50/System.Runtime.dll
  123. +15,642 −0 packages/System.Runtime.4.0.21-beta-23409/runtimes/win8-aot/lib/netcore50/System.Runtime.xml
  124. +15,647 −0 packages/System.Runtime.4.0.21-beta-23409/runtimes/win8-aot/lib/netcore50/de/System.Runtime.xml
  125. +15,620 −0 packages/System.Runtime.4.0.21-beta-23409/runtimes/win8-aot/lib/netcore50/es/System.Runtime.xml
  126. +15,856 −0 packages/System.Runtime.4.0.21-beta-23409/runtimes/win8-aot/lib/netcore50/fr/System.Runtime.xml
  127. +15,649 −0 packages/System.Runtime.4.0.21-beta-23409/runtimes/win8-aot/lib/netcore50/it/System.Runtime.xml
  128. +16,970 −0 packages/System.Runtime.4.0.21-beta-23409/runtimes/win8-aot/lib/netcore50/ja/System.Runtime.xml
  129. +16,922 −0 packages/System.Runtime.4.0.21-beta-23409/runtimes/win8-aot/lib/netcore50/ko/System.Runtime.xml
  130. +15,262 −0 packages/System.Runtime.4.0.21-beta-23409/runtimes/win8-aot/lib/netcore50/ru/System.Runtime.xml
  131. +15,922 −0 packages/System.Runtime.4.0.21-beta-23409/runtimes/win8-aot/lib/netcore50/zh-hans/System.Runtime.xml
  132. +15,977 −0 packages/System.Runtime.4.0.21-beta-23409/runtimes/win8-aot/lib/netcore50/zh-hant/System.Runtime.xml
  133. BIN packages/System.Threading.4.0.11-beta-23409/System.Threading.4.0.11-beta-23409.nupkg
  134. 0 packages/System.Threading.4.0.11-beta-23409/lib/MonoAndroid10/_._
  135. 0 packages/System.Threading.4.0.11-beta-23409/lib/MonoTouch10/_._
  136. 0 packages/System.Threading.4.0.11-beta-23409/lib/net46/_._
  137. 0 packages/System.Threading.4.0.11-beta-23409/lib/xamarinios10/_._
  138. 0 packages/System.Threading.4.0.11-beta-23409/lib/xamarinmac20/_._
  139. 0 packages/System.Threading.4.0.11-beta-23409/ref/MonoAndroid10/_._
  140. 0 packages/System.Threading.4.0.11-beta-23409/ref/MonoTouch10/_._
  141. BIN packages/System.Threading.4.0.11-beta-23409/ref/dotnet/System.Threading.dll
  142. 0 packages/System.Threading.4.0.11-beta-23409/ref/net46/_._
  143. 0 packages/System.Threading.4.0.11-beta-23409/ref/xamarinios10/_._
  144. 0 packages/System.Threading.4.0.11-beta-23409/ref/xamarinmac20/_._
  145. +14 −0 packages/System.Threading.4.0.11-beta-23409/runtime.json
View
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 2013
-VisualStudioVersion = 12.0.21005.1
+# Visual Studio 14
+VisualStudioVersion = 14.0.23107.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NowinSample", "NowinSample\NowinSample.csproj", "{59409616-C3C9-4962-B965-2F8E107E51BA}"
EndProject
@@ -13,6 +13,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NowinTests", "NowinTests\No
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OwinHostingSample", "OwinHostingSample\OwinHostingSample.csproj", "{F94CD73D-F902-4A36-BF6E-DF9233D60397}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NowinAcme", "NowinAcme\NowinAcme.csproj", "{8EDEC294-9E0B-4E51-88B7-98C1FA4E00E1}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NowinAcmeSample", "NowinAcmeSample\NowinAcmeSample.csproj", "{39CECD4E-F976-4FB0-8E07-ED9C9A00B647}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -39,6 +43,14 @@ Global
{F94CD73D-F902-4A36-BF6E-DF9233D60397}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F94CD73D-F902-4A36-BF6E-DF9233D60397}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F94CD73D-F902-4A36-BF6E-DF9233D60397}.Release|Any CPU.Build.0 = Release|Any CPU
+ {8EDEC294-9E0B-4E51-88B7-98C1FA4E00E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {8EDEC294-9E0B-4E51-88B7-98C1FA4E00E1}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {8EDEC294-9E0B-4E51-88B7-98C1FA4E00E1}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {8EDEC294-9E0B-4E51-88B7-98C1FA4E00E1}.Release|Any CPU.Build.0 = Release|Any CPU
+ {39CECD4E-F976-4FB0-8E07-ED9C9A00B647}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {39CECD4E-F976-4FB0-8E07-ED9C9A00B647}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {39CECD4E-F976-4FB0-8E07-ED9C9A00B647}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {39CECD4E-F976-4FB0-8E07-ED9C9A00B647}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -0,0 +1,121 @@
+using System;
+using System.Linq;
+using System.Security.Cryptography;
+using System.Security.Cryptography.X509Certificates;
+using System.Text;
+using System.Threading.Tasks;
+using Oocx.ACME.Client;
+using Oocx.ACME.Common;
+using Oocx.ACME.Protocol;
+using Oocx.ACME.Services;
+using Oocx.Asn1PKCS.Asn1BaseTypes;
+using Oocx.Asn1PKCS.PKCS10;
+
+namespace NowinAcme
+{
+ class AcmeProcess
+ {
+ readonly string _email;
+ readonly string _domain;
+ readonly Action<X509Certificate> _certificateUpdater;
+ readonly Action<string, byte[]> _challengeProof;
+ readonly IAcmeClient _client;
+ readonly ICertificateRequestAsn1DEREncoder _certificateRequestEncoder;
+ string _termsOfServiceUri = "https://letsencrypt.org/documents/LE-SA-v1.0.1-July-27-2015.pdf";
+
+ internal AcmeProcess(string email, string domain, Action<X509Certificate> certificateUpdater, Action<string, byte[]> challengeProof)
+ {
+ _email = email;
+ _domain = domain;
+ _certificateUpdater = certificateUpdater;
+ _challengeProof = challengeProof;
+ _client = new AcmeClient("https://acme-v01.api.letsencrypt.org", "keyName", new FileKeyStore(Environment.CurrentDirectory));
+ _certificateRequestEncoder = new CertificateRequestAsn1DEREncoder(new Asn1Serializer());
+ }
+
+ internal async Task StartAsync()
+ {
+ await RegisterWithServer();
+
+ bool isAuthorized = await AuthorizeForDomain(_domain);
+ if (!isAuthorized)
+ {
+ Log.Error($"authorization for domain {_domain} failed");
+ return;
+ }
+
+ var keyPair = GetNewKeyPair();
+
+ var certificateResponse = await RequestCertificateForDomain(_domain, keyPair);
+
+ var csp = new CspParameters { KeyContainerName = "oocx-acme-temp" };
+ var rsa2 = new RSACryptoServiceProvider(csp);
+ rsa2.ImportParameters(keyPair);
+
+ var certificate = new X509Certificate2(certificateResponse.Certificate, "", X509KeyStorageFlags.Exportable) { PrivateKey = rsa2 };
+
+ _certificateUpdater(certificate);
+ }
+
+ async Task<CertificateResponse> RequestCertificateForDomain(string domain, RSAParameters key)
+ {
+ var csr = CreateCertificateRequest(domain, key);
+ return await _client.NewCertificateRequestAsync(csr);
+ }
+
+ static RSAParameters GetNewKeyPair()
+ {
+ var rsa = new RSACryptoServiceProvider(2048);
+ var key = rsa.ExportParameters(true);
+ return key;
+ }
+
+ byte[] CreateCertificateRequest(string domain, RSAParameters key)
+ {
+ var data = new CertificateRequestData(domain, key);
+ var csr = _certificateRequestEncoder.EncodeAsDER(data);
+ return csr;
+ }
+
+ async Task<bool> AuthorizeForDomain(string domain)
+ {
+ var authorization = await _client.NewDnsAuthorizationAsync(domain);
+
+ var challenge = authorization?.Challenges.FirstOrDefault(c => c.Type == "http-01");
+ if (challenge == null)
+ {
+ Log.Error("the server does not accept challenge type http-01");
+ return false;
+ }
+
+ Log.Info($"accepting challenge {challenge.Type}");
+
+ var keyAuthorization = _client.GetKeyAuthorization(challenge.Token);
+ _challengeProof($"/.well-known/acme-challenge/{challenge.Token}", Encoding.ASCII.GetBytes(keyAuthorization));
+ var challengeResult = await _client.CompleteChallengeAsync(challenge);
+ _challengeProof(null, null);
+ return "valid".Equals(challengeResult?.Status, StringComparison.OrdinalIgnoreCase);
+ }
+
+ async Task RegisterWithServer()
+ {
+ var registration = await _client.RegisterAsync(_termsOfServiceUri, new[] { "mailto:" + _email });
+ Log.Info($"Terms of service: {registration.Agreement}");
+ Log.Verbose($"Created at: {registration.CreatedAt}");
+ Log.Verbose($"Id: {registration.Id}");
+ Log.Verbose($"Contact: {string.Join(", ", registration.Contact)}");
+ Log.Verbose($"Initial Ip: {registration.InitialIp}");
+
+ if (!string.IsNullOrWhiteSpace(registration.Location))
+ {
+ Log.Info("accepting terms of service");
+ if (!string.Equals(registration.Agreement, _termsOfServiceUri))
+ {
+ Log.Error($"Cannot accept terms of service. The terms of service uri is '{registration.Agreement}', expected it to be '{_termsOfServiceUri}'.");
+ return;
+ }
+ await _client.UpdateRegistrationAsync(registration.Location, registration.Agreement, new[] { "mailto:" + _email });
+ }
+ }
+ }
+}
@@ -0,0 +1,17 @@
+using System;
+using System.Security.Cryptography.X509Certificates;
+
+namespace NowinAcme
+{
+ public interface IAcmeConfiguration
+ {
+ string Email { get; }
+ string Domain { get; }
+ DateTime LastUpdate { get; }
+ void UpdateCertificate(X509Certificate cert);
+ void LogVerbose(string message, params object[] args);
+ void LogInfo(string message, params object[] args);
+ void LogWarning(string message, params object[] args);
+ void LogError(string message, params object[] args);
+ }
+}
@@ -0,0 +1,83 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Threading.Tasks;
+using Oocx.ACME.Common;
+
+namespace NowinAcme
+{
+ public static class NowinAcme
+ {
+ class LoggerProxy: ILog
+ {
+ readonly IAcmeConfiguration _cfg;
+
+ public LoggerProxy(IAcmeConfiguration cfg)
+ {
+ _cfg = cfg;
+ }
+
+ public void Verbose(string message, params object[] args)
+ {
+ _cfg.LogVerbose(message,args);
+ }
+
+ public void Info(string message, params object[] args)
+ {
+ _cfg.LogInfo(message, args);
+ }
+
+ public void Warning(string message, params object[] args)
+ {
+ _cfg.LogWarning(message, args);
+ }
+
+ public void Error(string message, params object[] args)
+ {
+ _cfg.LogError(message, args);
+ }
+ }
+
+ // This must run on server port 80 - Let's encrypt does not allow anything else
+ public static Func<IDictionary<string, object>, Task> Use(Func<IDictionary<string, object>, Task> next, IAcmeConfiguration cfg)
+ {
+ string challengePath = null;
+ byte[] challengeContent = null;
+ Log.Level = LogLevel.Verbose;
+ Log.Current = new LoggerProxy(cfg);
+ Func<Task, Task> updateWorker = null;
+ updateWorker=async task =>
+ {
+ var utcNow = DateTime.UtcNow;
+ var lastUpdate = cfg.LastUpdate;
+ if (utcNow - lastUpdate > TimeSpan.FromDays(30))
+ {
+ await new AcmeProcess(cfg.Email, cfg.Domain, cfg.UpdateCertificate, (path, content) =>
+ {
+ Log.Info($"SET {path} = {content}");
+
+ challengePath = path;
+ challengeContent = content;
+ }).StartAsync();
+ }
+#pragma warning disable 4014
+ // This cannot be awaited because it has to run once in a while without holding any resources.
+ // ReSharper disable once AssignNullToNotNullAttribute
+ Task.Delay(TimeSpan.FromMinutes(15)).ContinueWith(updateWorker);
+#pragma warning restore 4014
+ };
+ Task.Delay(1).ContinueWith(updateWorker);
+ return env =>
+ {
+ var path = (string)env["owin.RequestPath"];
+ if (path == challengePath)
+ {
+ var respBody = (Stream)env["owin.ResponseBody"];
+ respBody.Write(challengeContent, 0, challengeContent.Length);
+ return Task.CompletedTask;
+ }
+ return next(env);
+ };
+ }
+ }
+}
@@ -0,0 +1,81 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProjectGuid>{8EDEC294-9E0B-4E51-88B7-98C1FA4E00E1}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>NowinAcme</RootNamespace>
+ <AssemblyName>NowinAcme</AssemblyName>
+ <TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <TargetFrameworkProfile />
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
+ <HintPath>..\packages\Newtonsoft.Json.8.0.1-beta3\lib\net45\Newtonsoft.Json.dll</HintPath>
+ <Private>True</Private>
+ </Reference>
+ <Reference Include="Oocx.ACME, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
+ <HintPath>..\packages\Oocx.ACME.0.0.0-beta-75\lib\net46\Oocx.ACME.dll</HintPath>
+ <Private>True</Private>
+ </Reference>
+ <Reference Include="Oocx.ACME.Common, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
+ <HintPath>..\packages\Oocx.ACME.Common.0.0.0-beta-75\lib\net46\Oocx.ACME.Common.dll</HintPath>
+ <Private>True</Private>
+ </Reference>
+ <Reference Include="Oocx.Asn1PKCS, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
+ <HintPath>..\packages\Oocx.Asn1PKCS.0.0.0-beta-75\lib\net46\Oocx.Asn1PKCS.dll</HintPath>
+ <Private>True</Private>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.Core" />
+ <Reference Include="System.Net.Http.Formatting, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
+ <HintPath>..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll</HintPath>
+ <Private>True</Private>
+ </Reference>
+ <Reference Include="System.Xml.Linq" />
+ <Reference Include="System.Data.DataSetExtensions" />
+ <Reference Include="Microsoft.CSharp" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Net.Http" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="AcmeProcess.cs" />
+ <Compile Include="IAcmeConfiguration.cs" />
+ <Compile Include="NowinAcme.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="packages.config" />
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("NowinAcme")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("NowinAcme")]
+[assembly: AssemblyCopyright("Copyright © 2015")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("8edec294-9e0b-4e51-88b7-98c1fa4e00e1")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
View
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+ <runtime>
+ <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+ <dependentAssembly>
+ <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0" />
+ </dependentAssembly>
+ </assemblyBinding>
+ </runtime>
+</configuration>
Oops, something went wrong.

0 comments on commit da58fe9

Please sign in to comment.