|
14 | 14 | using Microsoft.Extensions.Logging; |
15 | 15 | using Newtonsoft.Json; |
16 | 16 | using System.Linq; |
| 17 | +using Keyfactor.PKI.X509; |
| 18 | + |
17 | 19 |
|
18 | 20 | namespace Keyfactor.AnyGateway.SslStore |
19 | 21 | { |
@@ -323,15 +325,30 @@ public async Task<AnyCAPluginCertificate> GetSingleRecord(string caRequestId) |
323 | 325 | var orderStatusRequest = _requestManager.GetOrderStatusRequest(caRequestId); |
324 | 326 | _logger.LogTrace($"orderStatusRequest JSON {JsonConvert.SerializeObject(orderStatusRequest)}"); |
325 | 327 |
|
326 | | - var certResponse = await client.SubmitOrderStatusRequestAsync(orderStatusRequest); |
327 | | - _logger.LogTrace($"certResponse JSON {JsonConvert.SerializeObject(certResponse)}"); |
| 328 | + var orderStatusResponse = await client.SubmitOrderStatusRequestAsync(orderStatusRequest); |
| 329 | + _logger.LogTrace($"orderStatusResponse JSON {JsonConvert.SerializeObject(orderStatusResponse)}"); |
| 330 | + |
| 331 | + var certStatus = _requestManager.MapReturnStatus(orderStatusResponse?.OrderStatus.MajorStatus); |
| 332 | + var certificate = string.Empty; |
| 333 | + |
| 334 | + if (certStatus == (int)EndEntityStatus.GENERATED) |
| 335 | + { |
| 336 | + var downloadCertificateRequest = _requestManager.GetCertificateRequest(caRequestId); |
| 337 | + var certResponse = await client.SubmitDownloadCertificateAsync(downloadCertificateRequest); |
| 338 | + if (!certResponse.AuthResponse.IsError) |
| 339 | + { |
| 340 | + var fullChain = string.Join("\n", certResponse.Certificates.Select(c => c.FileContent)); |
| 341 | + var endEntityCert = X509Utilities.ExtractEndEntityCertificateContents(fullChain, null); |
| 342 | + certificate = Convert.ToBase64String(endEntityCert.RawData); |
| 343 | + } |
| 344 | + } |
328 | 345 |
|
329 | 346 | _logger.MethodExit(); |
330 | 347 | return new AnyCAPluginCertificate |
331 | 348 | { |
332 | 349 | CARequestID = caRequestId, |
333 | | - Certificate = string.Empty, |
334 | | - Status = _requestManager.MapReturnStatus(certResponse?.OrderStatus.MajorStatus) |
| 350 | + Certificate = certificate, |
| 351 | + Status = certStatus |
335 | 352 | }; |
336 | 353 | } |
337 | 354 |
|
@@ -378,10 +395,12 @@ public async Task Synchronize(BlockingCollection<AnyCAPluginCertificate> blockin |
378 | 395 | var certResponse = await client.SubmitDownloadCertificateAsync(downloadCertificateRequest); |
379 | 396 | if (!certResponse.AuthResponse.IsError) |
380 | 397 | { |
381 | | - fileContent = _requestManager.GetCertificateContent(certResponse.Certificates, orderStatusResponse.CommonName); |
| 398 | + var fullChain = string.Join("\n", certResponse.Certificates.Select(c => c.FileContent)); |
| 399 | + var endEntityCert = X509Utilities.ExtractEndEntityCertificateContents(fullChain, null); |
| 400 | + fileContent = Convert.ToBase64String(endEntityCert.RawData); |
382 | 401 | } |
383 | 402 | } |
384 | | - |
| 403 | + |
385 | 404 | if ((certStatus == (int)EndEntityStatus.GENERATED && fileContent.Length > 0) || |
386 | 405 | certStatus == (int)EndEntityStatus.REVOKED) |
387 | 406 | { |
|
0 commit comments