Skip to content

Commit 67150f3

Browse files
authored
Merge pull request #332 from sjkp/feature/v2api
Upgrade to Lets Encrypt v2 API
2 parents c753c31 + 3940868 commit 67150f3

25 files changed

+224
-858
lines changed

LetsEncrypt-SiteExtension.sln

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
3030
EndProject
3131
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ACMESharp", "ACMESharp", "{E4B09348-2E98-4A58-8D5A-B55231D6A2E3}"
3232
EndProject
33-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ACMESharp", "ACMESharp\ACMESharp\ACMESharp\ACMESharp.csproj", "{D551234B-0A8D-4DEE-8178-A81998DF0EDB}"
34-
EndProject
35-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ACMESharp.PKI.Providers.BouncyCastle", "ACMESharp\ACMESharp\ACMESharp.PKI.Providers.BouncyCastle\ACMESharp.PKI.Providers.BouncyCastle.csproj", "{473BFF7D-C7F0-471D-B7A3-19AD9ADFDBA9}"
36-
EndProject
3733
Global
3834
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3935
Debug|Any CPU = Debug|Any CPU
@@ -104,38 +100,10 @@ Global
104100
{284F0226-F481-4C10-A408-4146FDBB71CC}.Release|x64.Build.0 = Release|x64
105101
{284F0226-F481-4C10-A408-4146FDBB71CC}.Release|x86.ActiveCfg = Release|x86
106102
{284F0226-F481-4C10-A408-4146FDBB71CC}.Release|x86.Build.0 = Release|x86
107-
{D551234B-0A8D-4DEE-8178-A81998DF0EDB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
108-
{D551234B-0A8D-4DEE-8178-A81998DF0EDB}.Debug|Any CPU.Build.0 = Debug|Any CPU
109-
{D551234B-0A8D-4DEE-8178-A81998DF0EDB}.Debug|x64.ActiveCfg = Debug|Any CPU
110-
{D551234B-0A8D-4DEE-8178-A81998DF0EDB}.Debug|x64.Build.0 = Debug|Any CPU
111-
{D551234B-0A8D-4DEE-8178-A81998DF0EDB}.Debug|x86.ActiveCfg = Debug|Any CPU
112-
{D551234B-0A8D-4DEE-8178-A81998DF0EDB}.Debug|x86.Build.0 = Debug|Any CPU
113-
{D551234B-0A8D-4DEE-8178-A81998DF0EDB}.Release|Any CPU.ActiveCfg = Release|Any CPU
114-
{D551234B-0A8D-4DEE-8178-A81998DF0EDB}.Release|Any CPU.Build.0 = Release|Any CPU
115-
{D551234B-0A8D-4DEE-8178-A81998DF0EDB}.Release|x64.ActiveCfg = Release|Any CPU
116-
{D551234B-0A8D-4DEE-8178-A81998DF0EDB}.Release|x64.Build.0 = Release|Any CPU
117-
{D551234B-0A8D-4DEE-8178-A81998DF0EDB}.Release|x86.ActiveCfg = Release|Any CPU
118-
{D551234B-0A8D-4DEE-8178-A81998DF0EDB}.Release|x86.Build.0 = Release|Any CPU
119-
{473BFF7D-C7F0-471D-B7A3-19AD9ADFDBA9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
120-
{473BFF7D-C7F0-471D-B7A3-19AD9ADFDBA9}.Debug|Any CPU.Build.0 = Debug|Any CPU
121-
{473BFF7D-C7F0-471D-B7A3-19AD9ADFDBA9}.Debug|x64.ActiveCfg = Debug|Any CPU
122-
{473BFF7D-C7F0-471D-B7A3-19AD9ADFDBA9}.Debug|x64.Build.0 = Debug|Any CPU
123-
{473BFF7D-C7F0-471D-B7A3-19AD9ADFDBA9}.Debug|x86.ActiveCfg = Debug|Any CPU
124-
{473BFF7D-C7F0-471D-B7A3-19AD9ADFDBA9}.Debug|x86.Build.0 = Debug|Any CPU
125-
{473BFF7D-C7F0-471D-B7A3-19AD9ADFDBA9}.Release|Any CPU.ActiveCfg = Release|Any CPU
126-
{473BFF7D-C7F0-471D-B7A3-19AD9ADFDBA9}.Release|Any CPU.Build.0 = Release|Any CPU
127-
{473BFF7D-C7F0-471D-B7A3-19AD9ADFDBA9}.Release|x64.ActiveCfg = Release|Any CPU
128-
{473BFF7D-C7F0-471D-B7A3-19AD9ADFDBA9}.Release|x64.Build.0 = Release|Any CPU
129-
{473BFF7D-C7F0-471D-B7A3-19AD9ADFDBA9}.Release|x86.ActiveCfg = Release|Any CPU
130-
{473BFF7D-C7F0-471D-B7A3-19AD9ADFDBA9}.Release|x86.Build.0 = Release|Any CPU
131103
EndGlobalSection
132104
GlobalSection(SolutionProperties) = preSolution
133105
HideSolutionNode = FALSE
134106
EndGlobalSection
135-
GlobalSection(NestedProjects) = preSolution
136-
{D551234B-0A8D-4DEE-8178-A81998DF0EDB} = {E4B09348-2E98-4A58-8D5A-B55231D6A2E3}
137-
{473BFF7D-C7F0-471D-B7A3-19AD9ADFDBA9} = {E4B09348-2E98-4A58-8D5A-B55231D6A2E3}
138-
EndGlobalSection
139107
GlobalSection(ExtensibilityGlobals) = postSolution
140108
SolutionGuid = {CE278D6B-F8FA-4F40-A67B-A8367F40FCA4}
141109
EndGlobalSection

LetsEncrypt-SiteExtension/Controllers/Api/CertificateController.cs

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -83,69 +83,5 @@ public async Task<IHttpActionResult> GenerateAndInstallBlob(HttpKuduInstallModel
8383

8484
return Ok(await mgr.AddCertificate());
8585
}
86-
87-
/// <summary>
88-
/// Requests a Let's Encrypt certificate using the DNS challenge, using Azure DNS.
89-
/// </summary>
90-
/// <param name="model"></param>
91-
/// <param name="apiversion"></param>
92-
/// <returns></returns>
93-
[HttpPost]
94-
[Route("api/certificates/challengeprovider/dns/azure")]
95-
[ResponseType(typeof(CertificateInstallModel))]
96-
public async Task<IHttpActionResult> Generate(DnsAzureModel model, [FromUri(Name = "api-version")]string apiversion = null)
97-
{
98-
if (!ModelState.IsValid)
99-
{
100-
return BadRequest(ModelState);
101-
}
102-
103-
var res = await CertificateManager.RequestDnsChallengeCertificate(model.AzureDnsEnvironment, model.AcmeConfig);
104-
105-
return Ok(res);
106-
}
107-
108-
/// <summary>
109-
/// Requests a Let's Encrypt certificate using the DNS challenge, using Azure DNS.
110-
/// </summary>
111-
/// <param name="model"></param>
112-
/// <param name="apiversion"></param>
113-
/// <returns></returns>
114-
[HttpPost]
115-
[Route("api/certificates/challengeprovider/dns-v2/azure")]
116-
[ResponseType(typeof(CertificateInstallModel))]
117-
public async Task<IHttpActionResult> Generate_v2(DnsAzureModel model, [FromUri(Name = "api-version")]string apiversion = null)
118-
{
119-
if (!ModelState.IsValid)
120-
{
121-
return BadRequest(ModelState);
122-
}
123-
124-
var res = await CertificateManager.RequestDnsChallengeCertificate(model.AzureDnsEnvironment, model.AcmeConfig);
125-
126-
return Ok(res);
127-
}
128-
129-
/// <summary>
130-
/// Requests a Let's Encrypt certificate using the DNS challenge, using Azure DNS. The
131-
/// certificate is installed to the web app.
132-
/// </summary>
133-
/// <param name="model"></param>
134-
/// <param name="apiversion"></param>
135-
/// <returns></returns>
136-
[HttpPost]
137-
[Route("api/certificates/challengeprovider/dns/azure/certificateinstall/azurewebapp")]
138-
[ResponseType(typeof(CertificateInstallModel))]
139-
public async Task<IHttpActionResult> GenerateAndInstall(DnsAzureInstallModel model, [FromUri(Name = "api-version")]string apiversion = null)
140-
{
141-
if (!ModelState.IsValid)
142-
{
143-
return BadRequest(ModelState);
144-
}
145-
146-
var mgr = CertificateManager.CreateAzureDnsWebAppCertificateManager(model.AzureWebAppEnvironment, model.AcmeConfig, model.CertificateSettings, model);
147-
148-
return Ok(await mgr.AddCertificate());
149-
}
15086
}
15187
}

LetsEncrypt-SiteExtension/Controllers/HomeController.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,19 +230,18 @@ public async Task<ActionResult> Install(RequestAndInstallModel model)
230230
Name = "email",
231231
Value = model.Email
232232
});
233-
var baseUri = model.UseStaging == false ? "https://acme-v01.api.letsencrypt.org/" : "https://acme-staging.api.letsencrypt.org/";
234233
s.Add(new SettingEntry()
235234
{
236-
Name = "baseUri",
237-
Value = baseUri
235+
Name = "useStaging",
236+
Value = model.UseStaging.ToString()
238237
});
239238
SettingsStore.Instance.Save(s);
240239
var settings = new AppSettingsAuthConfig();
241240
var target = new AcmeConfig()
242241
{
243242
RegistrationEmail = model.Email,
244243
Host = model.Hostnames.First(),
245-
BaseUri = baseUri,
244+
UseProduction = !model.UseStaging,
246245
AlternateNames = model.Hostnames.Skip(1).ToList(),
247246
PFXPassword = settings.PFXPassword,
248247
RSAKeyLength = settings.RSAKeyLength,

LetsEncrypt-SiteExtension/Web.config

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,14 @@
133133
<assemblyIdentity name="System.Xml.ReaderWriter" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
134134
<bindingRedirect oldVersion="0.0.0.0-4.1.0.0" newVersion="4.1.0.0" />
135135
</dependentAssembly>
136+
<dependentAssembly>
137+
<assemblyIdentity name="System.Web.Http.WebHost" publicKeyToken="31bf3856ad364e35" culture="neutral" />
138+
<bindingRedirect oldVersion="0.0.0.0-5.2.7.0" newVersion="5.2.7.0" />
139+
</dependentAssembly>
140+
<dependentAssembly>
141+
<assemblyIdentity name="BouncyCastle.Crypto" publicKeyToken="0e99375e54769942" culture="neutral" />
142+
<bindingRedirect oldVersion="0.0.0.0-1.8.5.0" newVersion="1.8.5.0" />
143+
</dependentAssembly>
136144
</assemblyBinding>
137145
</runtime>
138146
<system.codedom>

LetsEncrypt.SiteExtension.Core/CertificateManager.cs

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -93,32 +93,6 @@ public static CertificateManager CreateKuduWebAppCertificateManager(IAzureWebApp
9393
return new CertificateManager(settings, acmeConfig, new WebAppCertificateService(settings, certSettings), new KuduFileSystemAuthorizationChallengeProvider(settings, authProviderConfig));
9494
}
9595

96-
/// <summary>
97-
/// Returns a <see cref="CertificateManager"/> configured to use DNS Challenge, placing the challenge record in Azure DNS,
98-
/// and assigning the obtained certificate directly to the web app service.
99-
/// </summary>
100-
/// <param name="settings"></param>
101-
/// <param name="acmeConfig"></param>
102-
/// <param name="certSettings"></param>
103-
/// <param name="dnsEnvironment"></param>
104-
/// <returns></returns>
105-
public static CertificateManager CreateAzureDnsWebAppCertificateManager(IAzureWebAppEnvironment settings, IAcmeConfig acmeConfig, IWebAppCertificateSettings certSettings, IAzureDnsEnvironment dnsEnvironment)
106-
{
107-
return new CertificateManager(settings, acmeConfig, new WebAppCertificateService(settings, certSettings), new AzureDnsAuthorizationChallengeProvider(dnsEnvironment));
108-
}
109-
110-
/// <summary>
111-
/// Request a certificate from lets encrypt using the DNS challenge, placing the challenge record in Azure DNS.
112-
/// The certifiacte is not assigned, but just returned.
113-
/// </summary>
114-
/// <param name="azureDnsEnvironment"></param>
115-
/// <param name="acmeConfig"></param>
116-
/// <returns></returns>
117-
public static async Task<CertificateInstallModel> RequestDnsChallengeCertificate(IAzureDnsEnvironment azureDnsEnvironment, IAcmeConfig acmeConfig)
118-
{
119-
return await new CertificateManager(null, acmeConfig, null, new AzureDnsAuthorizationChallengeProvider(azureDnsEnvironment)).RequestInternalAsync(acmeConfig);
120-
}
121-
12296

12397
/// <summary>
12498
/// Used for automatic installation of letsencrypt certificate
@@ -186,7 +160,8 @@ public async Task<List<CertificateInstallModel>> RenewCertificate(bool skipInsta
186160

187161
RegistrationEmail = this.acmeConfig.RegistrationEmail ?? ss.FirstOrDefault(s => s.Name == "email").Value,
188162
Host = sslStates.First().Name,
189-
BaseUri = this.acmeConfig.BaseUri ?? ss.FirstOrDefault(s => s.Name == "baseUri").Value,
163+
BaseUri = this.acmeConfig.BaseUri,
164+
UseProduction = !bool.Parse(ss.FirstOrDefault(s => s.Name == "useStaging")?.Value ?? false.ToString()),
190165
AlternateNames = sslStates.Skip(1).Select(s => s.Name).ToList(),
191166
PFXPassword = this.acmeConfig.PFXPassword,
192167
RSAKeyLength = this.acmeConfig.RSAKeyLength

LetsEncrypt.SiteExtension.Core/LetsEncrypt.Azure.Core.csproj

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@
6969
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
7070
</PropertyGroup>
7171
<ItemGroup>
72+
<Reference Include="BouncyCastle.Crypto, Version=1.8.5.0, Culture=neutral, PublicKeyToken=0e99375e54769942, processorArchitecture=MSIL">
73+
<HintPath>..\packages\Portable.BouncyCastle.1.8.5\lib\net40\BouncyCastle.Crypto.dll</HintPath>
74+
</Reference>
75+
<Reference Include="Certes, Version=2.3.3.0, Culture=neutral, PublicKeyToken=308b9c08e7effcb1, processorArchitecture=MSIL">
76+
<HintPath>..\packages\Certes.2.3.3\lib\net45\Certes.dll</HintPath>
77+
</Reference>
7278
<Reference Include="Microsoft.Azure.KeyVault.Core, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
7379
<HintPath>..\packages\Microsoft.Azure.KeyVault.Core.3.0.1\lib\net452\Microsoft.Azure.KeyVault.Core.dll</HintPath>
7480
</Reference>
@@ -164,6 +170,9 @@
164170
<Reference Include="System.Security.Cryptography.X509Certificates, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
165171
<HintPath>..\packages\System.Security.Cryptography.X509Certificates.4.3.2\lib\net46\System.Security.Cryptography.X509Certificates.dll</HintPath>
166172
</Reference>
173+
<Reference Include="System.ValueTuple, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
174+
<HintPath>..\packages\System.ValueTuple.4.4.0\lib\netstandard1.0\System.ValueTuple.dll</HintPath>
175+
</Reference>
167176
<Reference Include="System.Web" />
168177
<Reference Include="System.Xml.Linq" />
169178
<Reference Include="System.Data.DataSetExtensions" />
@@ -192,11 +201,9 @@
192201
<Compile Include="Models\KuduModels.cs" />
193202
<Compile Include="Models\SettingEntry.cs" />
194203
<Compile Include="Properties\AssemblyInfo.cs" />
195-
<Compile Include="Services\PathProvider.cs" />
196204
<Compile Include="Services\AcmeService.cs" />
205+
<Compile Include="Services\PathProvider.cs" />
197206
<Compile Include="Services\AppServiceCerticiateCertificateService.cs" />
198-
<Compile Include="Services\AzureDnsAuthorizationChallengeProvider.cs" />
199-
<Compile Include="Services\BaseDnsAuthorizationChallengeProvider.cs" />
200207
<Compile Include="Services\BaseHttpAuthorizationChallengeProvider.cs" />
201208
<Compile Include="Services\BlobStorageAuthorizationChallengeProvider.cs" />
202209
<Compile Include="Services\WebAppCertificateService.cs" />
@@ -222,16 +229,6 @@
222229
<SubType>Designer</SubType>
223230
</None>
224231
</ItemGroup>
225-
<ItemGroup>
226-
<ProjectReference Include="..\ACMESharp\ACMESharp\ACMESharp.PKI.Providers.BouncyCastle\ACMESharp.PKI.Providers.BouncyCastle.csproj">
227-
<Project>{473bff7d-c7f0-471d-b7a3-19ad9adfdba9}</Project>
228-
<Name>ACMESharp.PKI.Providers.BouncyCastle</Name>
229-
</ProjectReference>
230-
<ProjectReference Include="..\ACMESharp\ACMESharp\ACMESharp\ACMESharp.csproj">
231-
<Project>{d551234b-0a8d-4dee-8178-a81998df0edb}</Project>
232-
<Name>ACMESharp</Name>
233-
</ProjectReference>
234-
</ItemGroup>
235232
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
236233
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
237234
Other similar extension points exist, see Microsoft.Common.targets.

LetsEncrypt.SiteExtension.Core/LetsEncrypt.Azure.Core.nuspec

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<metadata>
44
<id>letsencrypt.azure.core</id>
55
<title>Azure Let's Encrypt</title>
6-
<version>0.9.6</version>
6+
<version>1.0.1</version>
77
<authors>SJKP</authors>
88
<licenseUrl>http://opensource.org/licenses/Apache-2.0</licenseUrl>
99
<projectUrl>https://github.com/sjkp/letsencrypt-siteextension</projectUrl>
@@ -16,11 +16,7 @@
1616
<dependency id="Microsoft.Azure.Management.Websites" version="2.0.1" />
1717
<dependency id="Microsoft.IdentityModel.Clients.ActiveDirectory" version="3.14.0"></dependency>
1818
<dependency id="Newtonsoft.Json" version="12.0.1" />
19-
<dependency id="BouncyCastle" version="1.8.1" />
19+
<dependency id="BouncyCastle" version="1.8.5" />
2020
</dependencies>
2121
</metadata>
22-
<files>
23-
<file src="..\ACMESharp\ACMESharp\ACMESharp\bin\Release\ACMESharp.dll" target="lib\net46"></file>
24-
<file src="..\ACMESharp\ACMESharp\ACMESharp.PKI.Providers.BouncyCastle\bin\Release\ACMESharp.PKI.Providers.BouncyCastle.dll" target="lib\net46"></file>
25-
</files>
2622
</package>

0 commit comments

Comments
 (0)