diff --git a/LetsEncrypt.postman_collection.json b/LetsEncrypt.postman_collection.json index a678f23..ae8aaab 100644 --- a/LetsEncrypt.postman_collection.json +++ b/LetsEncrypt.postman_collection.json @@ -49,27 +49,6 @@ }, "response": [] }, - { - "name": "terms of service", - "request": { - "method": "GET", - "header": [], - "url": { - "raw": "http://localhost:8080/CertsFlow/TermsOfService/{{sessionId}}", - "protocol": "http", - "host": [ - "localhost" - ], - "port": "8080", - "path": [ - "CertsFlow", - "TermsOfService", - "{{sessionId}}" - ] - } - }, - "response": [] - }, { "name": "configure client", "event": [ @@ -130,6 +109,27 @@ }, "response": [] }, + { + "name": "terms of service", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "http://localhost:8080/CertsFlow/TermsOfService/{{sessionId}}", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "CertsFlow", + "TermsOfService", + "{{sessionId}}" + ] + } + }, + "response": [] + }, { "name": "init", "event": [ @@ -276,7 +276,7 @@ ], "body": { "mode": "raw", - "raw": "{\r\n \"hostnames\": [\r\n \"maks-it.com\"\r\n ],\r\n \"challengeType\": \"http-01\"\r\n}", + "raw": "{\r\n \"hostnames\": [\r\n \"staging.maks-it.com\"\r\n ],\r\n \"challengeType\": \"http-01\"\r\n}", "options": { "raw": { "language": "json" @@ -326,9 +326,10 @@ "method": "GET", "header": [], "url": { - "raw": "http://maks-it.com/.well-known/acme-challenge/{{challenge}}", + "raw": "http://staging.maks-it.com/.well-known/acme-challenge/{{challenge}}", "protocol": "http", "host": [ + "staging", "maks-it", "com" ], @@ -396,7 +397,7 @@ ], "body": { "mode": "raw", - "raw": "{\r\n \"hostnames\": [\r\n \"maks-it.com\"\r\n ]\r\n}", + "raw": "{\r\n \"hostnames\": [\r\n \"staging.maks-it.com\"\r\n ]\r\n}", "options": { "raw": { "language": "json" @@ -435,7 +436,7 @@ ], "body": { "mode": "raw", - "raw": "{\r\n \"hostnames\": [\r\n \"maks-it.com\"\r\n ]\r\n}", + "raw": "{\r\n \"hostnames\": [\r\n \"staging.maks-it.com\"\r\n ]\r\n}", "options": { "raw": { "language": "json" @@ -474,7 +475,7 @@ ], "body": { "mode": "raw", - "raw": "{\r\n \"hostnames\": [\r\n \"maks-it.com\"\r\n ]\r\n}", + "raw": "{\r\n \"hostnames\": [\r\n \"staging.maks-it.com\"\r\n ]\r\n}", "options": { "raw": { "language": "json" diff --git a/src/LetsEncrypt/Services/LetsEncryptService.cs b/src/LetsEncrypt/Services/LetsEncryptService.cs index 4aed135..667d438 100644 --- a/src/LetsEncrypt/Services/LetsEncryptService.cs +++ b/src/LetsEncrypt/Services/LetsEncryptService.cs @@ -12,6 +12,7 @@ using MaksIT.LetsEncrypt.Models.Requests; using MaksIT.LetsEncrypt.Entities.Jws; using DomainResults.Common; using System.Net.Http.Headers; +using System.Security.Principal; namespace MaksIT.LetsEncrypt.Services; @@ -100,10 +101,13 @@ public class LetsEncryptService : ILetsEncryptService { if (cache != null && cache.AccountKey != null) { state.Cache = cache; accountKey.ImportCspBlob(cache.AccountKey); + + state.JwsService = new JwsService(accountKey); + state.JwsService.SetKeyId(cache.Location.ToString()); } else { // New Account request - state.JwsService = new JwsService(accountKey); + var letsEncryptOrder = new Account { TermsOfServiceAgreed = true, @@ -111,6 +115,10 @@ public class LetsEncryptService : ILetsEncryptService { }; var (account, postAccountResult) = await SendAsync(sessionId, HttpMethod.Post, state.Directory.NewAccount, false, letsEncryptOrder); + if (!postAccountResult.IsSuccess || account?.Result?.Location == null) + return postAccountResult; + + state.JwsService = new JwsService(accountKey); state.JwsService.SetKeyId(account.Result.Location.ToString()); if (account.Result.Status != "valid") {