|
24 | 24 | using System.Collections.Concurrent;
|
25 | 25 | using System.Drawing.Printing;
|
26 | 26 | using System.Diagnostics.CodeAnalysis;
|
| 27 | +using static Keyfactor.Orchestrators.Common.OrchestratorConstants; |
| 28 | +using static Org.BouncyCastle.Math.EC.ECCurve; |
27 | 29 |
|
28 | 30 | namespace Keyfactor.Extensions.Orchestrator.F5Orchestrator
|
29 | 31 | {
|
@@ -350,6 +352,35 @@ private X509Certificate2Collection GetCertificateEntry(string path)
|
350 | 352 | return c.ToX509Certificate2Collection();
|
351 | 353 | }
|
352 | 354 |
|
| 355 | + public List<F5SSLProfile> GetSSLProfiles(int pageSize) |
| 356 | + { |
| 357 | + LogHandlerCommon.MethodEntry(logger, CertificateStore, "GetSSLProfiles"); |
| 358 | + string partition = CertificateStore.StorePath; |
| 359 | + string query = $"/mgmt/tm/ltm/profile/client-ssl?$top={pageSize}&$skip=0"; |
| 360 | + F5PagedSSLProfiles pagedProfiles = REST.Get<F5PagedSSLProfiles>(query); |
| 361 | + List<F5SSLProfile> profiles = new List<F5SSLProfile>(); |
| 362 | + |
| 363 | + if (pagedProfiles.totalItems == 0 || pagedProfiles.items?.Length == 0) |
| 364 | + { |
| 365 | + return profiles; |
| 366 | + } |
| 367 | + |
| 368 | + for (int i = pagedProfiles.pageIndex; i <= pagedProfiles.totalPages; i++) |
| 369 | + { |
| 370 | + profiles.AddRange(pagedProfiles.items); |
| 371 | + |
| 372 | + // The current paged profile will contain a link to the next set, unless the end has been reached |
| 373 | + if (string.IsNullOrEmpty(pagedProfiles.nextLink)) { break; } |
| 374 | + |
| 375 | + // Get the next page of profiles |
| 376 | + query = pagedProfiles.nextLink.Replace("https://localhost", ""); |
| 377 | + pagedProfiles = REST.Get<F5PagedSSLProfiles>(query); |
| 378 | + } |
| 379 | + |
| 380 | + LogHandlerCommon.MethodExit(logger, CertificateStore, "GetSSLProfiles"); |
| 381 | + return profiles; |
| 382 | + } |
| 383 | + |
353 | 384 | private void SetItemStatus(CurrentInventoryItem agentInventoryItem)
|
354 | 385 | {
|
355 | 386 | LogHandlerCommon.MethodEntry(logger, CertificateStore, "SetItemStatus");
|
@@ -609,67 +640,79 @@ private List<X509Certificate2> ReorderPEMLIst(List<X509Certificate2> certList)
|
609 | 640 | // WebServer
|
610 | 641 | #endregion
|
611 | 642 |
|
612 |
| - #region SSL Profiles |
| 643 | + #region SSL Certificates |
613 | 644 |
|
614 |
| - public List<CurrentInventoryItem> GetSSLProfiles(int pageSize) |
| 645 | + public List<CurrentInventoryItem> GetCertificateEntries(int pageSize) |
615 | 646 | {
|
616 |
| - LogHandlerCommon.MethodEntry(logger, CertificateStore, "GetSSLProfiles"); |
| 647 | + LogHandlerCommon.MethodEntry(logger, CertificateStore, "GetCertificateEntries"); |
617 | 648 | string partition = CertificateStore.StorePath;
|
618 | 649 | string query = $"/mgmt/tm/sys/file/ssl-cert?$filter=partition+eq+{partition}&$select=name,keyType,isBundle&$top={pageSize}&$skip=0";
|
619 |
| - F5PagedSSLProfiles pagedProfiles = REST.Get<F5PagedSSLProfiles>(query); |
620 |
| - List<F5SSLProfile> profiles = new List<F5SSLProfile>(); |
| 650 | + F5PagedSSLCertificates pagedCertificates = REST.Get<F5PagedSSLCertificates>(query); |
| 651 | + List<F5SSLCertificate> certificates = new List<F5SSLCertificate>(); |
621 | 652 | List<CurrentInventoryItem> inventory = new List<CurrentInventoryItem>();
|
622 | 653 |
|
623 |
| - if (pagedProfiles.totalItems == 0 || pagedProfiles.items?.Length == 0) |
| 654 | + LogHandlerCommon.Debug(logger, CertificateStore, $"Getting SSL Profiles from '{CertificateStore.StorePath}'"); |
| 655 | + List<F5SSLProfile> sslProfiles = GetSSLProfiles(pageSize); |
| 656 | + |
| 657 | + if (pagedCertificates.totalItems == 0 || pagedCertificates.items?.Length == 0) |
624 | 658 | {
|
625 |
| - LogHandlerCommon.Trace(logger, CertificateStore, $"No SSL profiles found in partition '{partition}'"); |
626 |
| - LogHandlerCommon.MethodExit(logger, CertificateStore, "GetSSLProfiles"); |
| 659 | + LogHandlerCommon.Trace(logger, CertificateStore, $"No SSL certificates found in partition '{partition}'"); |
| 660 | + LogHandlerCommon.MethodExit(logger, CertificateStore, "GetCertificateEntries"); |
627 | 661 | return inventory;
|
628 | 662 | }
|
629 | 663 | else
|
630 | 664 | {
|
631 |
| - LogHandlerCommon.Trace(logger, CertificateStore, $"Compiling {pagedProfiles.totalPages} pages containing {pagedProfiles.totalItems} total inventory entries"); |
| 665 | + LogHandlerCommon.Trace(logger, CertificateStore, $"Compiling {pagedCertificates.totalPages} pages containing {pagedCertificates.totalItems} total inventory entries"); |
632 | 666 | }
|
633 | 667 |
|
634 |
| - // Collected all of the profile entry names |
635 |
| - for (int i = pagedProfiles.pageIndex; i <= pagedProfiles.totalPages; i++) |
| 668 | + // Collected all of the certificate entry names |
| 669 | + for (int i = pagedCertificates.pageIndex; i <= pagedCertificates.totalPages; i++) |
636 | 670 | {
|
637 |
| - profiles.AddRange(pagedProfiles.items); |
| 671 | + certificates.AddRange(pagedCertificates.items); |
638 | 672 |
|
639 |
| - // The current paged profile will contain a link to the next set, unless the end has been reached |
640 |
| - if (string.IsNullOrEmpty(pagedProfiles.nextLink)) { break; } |
| 673 | + // The current paged certificate list will contain a link to the next set, unless the end has been reached |
| 674 | + if (string.IsNullOrEmpty(pagedCertificates.nextLink)) { break; } |
641 | 675 |
|
642 |
| - // Get the next page of profiles |
643 |
| - query = pagedProfiles.nextLink.Replace("https://localhost", ""); |
644 |
| - pagedProfiles = REST.Get<F5PagedSSLProfiles>(query); |
| 676 | + // Get the next page of certificates |
| 677 | + query = pagedCertificates.nextLink.Replace("https://localhost", ""); |
| 678 | + pagedCertificates = REST.Get<F5PagedSSLCertificates>(query); |
645 | 679 | }
|
646 | 680 |
|
647 | 681 | // Compile the entries into inventory items
|
648 |
| - for (int i = 0; i < profiles.Count; i++) |
| 682 | + for (int i = 0; i < certificates.Count; i++) |
649 | 683 | {
|
650 | 684 | try
|
651 | 685 | {
|
652 |
| - LogHandlerCommon.Trace(logger, CertificateStore, $"Processing alias {profiles[i].name}"); |
| 686 | + LogHandlerCommon.Trace(logger, CertificateStore, $"Processing alias {certificates[i].name}"); |
653 | 687 | // Exclude 'ca-bundle.crt' as that can only be managed by F5
|
654 |
| - if (profiles[i].name.Equals("ca-bundle.crt", StringComparison.OrdinalIgnoreCase) |
655 |
| - || profiles[i].name.Equals("f5-ca-bundle.crt", StringComparison.OrdinalIgnoreCase)) |
| 688 | + if (certificates[i].name.Equals("ca-bundle.crt", StringComparison.OrdinalIgnoreCase) |
| 689 | + || certificates[i].name.Equals("f5-ca-bundle.crt", StringComparison.OrdinalIgnoreCase)) |
656 | 690 | {
|
657 |
| - LogHandlerCommon.Trace(logger, CertificateStore, $"Skipping '{profiles[i].name}' because it is managed by F5"); |
| 691 | + LogHandlerCommon.Trace(logger, CertificateStore, $"Skipping '{certificates[i].name}' because it is managed by F5"); |
658 | 692 | continue;
|
659 | 693 | }
|
660 |
| - inventory.Add(GetInventoryItem(partition, profiles[i].name, true)); |
| 694 | + CurrentInventoryItem inventoryItem = GetInventoryItem(partition, certificates[i].name, true); |
| 695 | + Dictionary<string, object> parameters = new Dictionary<string, object>(); |
| 696 | + |
| 697 | + string certName = $"/{partition}/{inventoryItem.Alias}"; |
| 698 | + string sslProfileNames = string.Join(",", sslProfiles.Where(p => p.cert == certName).Select(p => p.name)); |
| 699 | + if (!string.IsNullOrEmpty(sslProfileNames)) |
| 700 | + parameters.Add("SSLProfiles", sslProfileNames); |
| 701 | + inventoryItem.Parameters = parameters; |
| 702 | + |
| 703 | + inventory.Add(inventoryItem); |
661 | 704 | }
|
662 | 705 | catch (Exception ex)
|
663 | 706 | {
|
664 |
| - LogHandlerCommon.Error(logger, CertificateStore, ExceptionHandler.FlattenExceptionMessages(ex, $"Unable to process inventory item {profiles[i].name}.")); |
| 707 | + LogHandlerCommon.Error(logger, CertificateStore, ExceptionHandler.FlattenExceptionMessages(ex, $"Unable to process inventory item {certificates[i].name}.")); |
665 | 708 | }
|
666 | 709 | }
|
667 | 710 |
|
668 |
| - LogHandlerCommon.MethodExit(logger, CertificateStore, "GetSSLProfiles"); |
| 711 | + LogHandlerCommon.MethodExit(logger, CertificateStore, "GetCertificateEntries"); |
669 | 712 | return inventory;
|
670 | 713 | }
|
671 | 714 |
|
672 |
| - // SSL Profiles |
| 715 | + // SSL Certificates |
673 | 716 | #endregion
|
674 | 717 |
|
675 | 718 | #region Auth & Version
|
|
0 commit comments