Skip to content

Commit 8d7c8c8

Browse files
authored
Release 2.0.3. (#19)
* Added a switch to control syncing of fields deactivated in DigiCert. * Updated readme_source.md with new config section. Fixes ab#47725, ab#46882
1 parent fdfb502 commit 8d7c8c8

File tree

6 files changed

+30
-16
lines changed

6 files changed

+30
-16
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
Version 2.0.3
2+
3+
Added a setting to enable or disable syncing deactivated custom fields from DigiCert.
4+
15
Version 2.0.2
26

37
Fixed issue with additional_emails field not syncing.

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ A tool to automatically synchronize metadata fields and their content from DigiC
66

77

88

9-
10-
119
## Support for Digicert Metadata Sync
1210

1311
Digicert Metadata Sync is open source and there is **no SLA** for this tool/library/client. Keyfactor will address issues as resources become available. Keyfactor customers may request escalation by opening up a support ticket through their Keyfactor representative.
@@ -16,7 +14,6 @@ Digicert Metadata Sync is open source and there is **no SLA** for this tool/libr
1614

1715

1816

19-
2017
## Overview
2118
This tool primarily sets up metadata fields in Keyfactor for the custom metadata fields in DigiCert, which are named as such, but can also setup metadata fields in Keyfactor for non-custom fields available in DigiCert and unavailable in Keyfactor by default, such as the Digicert Cert ID and the Organization contact. These fields are referred to as manual fields in the context of this tool. After setting up these fields, the tool proceeds to update the contents of these fields. This tool only adds metadata to certificates that have already been imported into Keyfactor. Additionally, this tool requires a properly installed and functioning AnyGateway configured to work with Keyfactor and Digicert.
2219

@@ -44,6 +41,8 @@ This should include the common prefix all DigiCert certs have in your Keyfactor
4441
This setting enables the tool to import all of the custom metadata fields included in DigiCert and sync all of their data.
4542
- <b>ReplaceDigicertWhiteSpaceCharacterInName</b>
4643
In case the ImportAllCustomDigicertFields setting is used, this is necessary to for metadata field label conversion. DigiCert supports spaces in labels and Keyfactor does not, so this replaces the spaces in the name with your character sequence of choice.
44+
- <b>ImportDataForDeactivatedDigiCertFields</b>
45+
If this is enabled, custom metadata fields that were deactivated in DigiCert will also be synced, and the data stored in these fields in certificates will be too.
4746

4847
### manualfields.json settings
4948
This file is used to specify which metadata fields should be synced up.

digicert-metadata-sync/App.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
<add key="KeyfactorDigicertIssuedCertQueryTerm" value="DigiCert" />
1111
<add key="ImportAllCustomDigicertFields" value="False" />
1212
<add key="ReplaceDigicertWhiteSpaceCharacterInName" value="_-_" />
13+
<add key="ImportDataForDeactivatedDigiCertFields" value="False" />
1314
</appSettings>
1415
</configuration>

digicert-metadata-sync/GrabCustomFieldsFromDigiCert.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using Keyfactor.Logging;
1616
using Microsoft.Extensions.Logging;
1717
using Newtonsoft.Json;
18+
using NLog.Time;
1819
using RestSharp;
1920
using RestSharp.Authenticators;
2021

@@ -24,8 +25,9 @@ namespace DigicertMetadataSync;
2425
// It will only add new fields.
2526
partial class DigicertSync
2627
{
27-
public static List<CustomDigicertMetadataInstance> GrabCustomFieldsFromDigiCert(string apikey)
28+
public static List<CustomDigicertMetadataInstance> GrabCustomFieldsFromDigiCert(string apikey, bool importdeactivated)
2829
{
30+
ILogger logger = LogHandler.GetClassLogger<DigicertSync>();
2931
var digicertclient = new RestClient();
3032
var customfieldsretrieval = "https://www.digicert.com/services/v2/account/metadata";
3133
var digicertrequest = new RestRequest(customfieldsretrieval);
@@ -36,8 +38,12 @@ public static List<CustomDigicertMetadataInstance> GrabCustomFieldsFromDigiCert(
3638
int lengthofresponse = trimmeddigicertresponse.Length;
3739
trimmeddigicertresponse = trimmeddigicertresponse.Remove(lengthofresponse - 1, 1);
3840
var fieldlist = JsonConvert.DeserializeObject<List<CustomDigicertMetadataInstance>>(trimmeddigicertresponse);
41+
if (importdeactivated == false)
42+
{
43+
fieldlist.RemoveAll(unit => unit.is_active == false);
44+
}
3945
Console.WriteLine("Obtained custom fields from DigiCert.");
40-
_logger.Debug("Obtained custom fields from DigiCert.");
46+
logger.LogDebug("Obtained custom fields from DigiCert.");
4147
return fieldlist;
4248
}
4349
}

digicert-metadata-sync/MetadataSync.cs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using RestSharp;
1212
using RestSharp.Authenticators;
1313
using ConfigurationManager = System.Configuration.ConfigurationManager;
14+
//using Keyfactor.Logging;
1415

1516
namespace DigicertMetadataSync;
1617

@@ -26,6 +27,7 @@ public static void Main(string[] args)
2627
var digicertapikeytopperm = ConfigurationManager.AppSettings.Get("DigicertAPIKeyTopPerm");
2728
var keyfactorusername = ConfigurationManager.AppSettings.Get("KeyfactorDomainAndUser");
2829
var keyfactorpassword = ConfigurationManager.AppSettings.Get("KeyfactorPassword");
30+
var importdeactivated = Convert.ToBoolean(ConfigurationManager.AppSettings.Get("ImportDataForDeactivatedDigiCertFields"));
2931
var replacementcharacter = ConfigurationManager.AppSettings.Get("ReplaceDigicertWhiteSpaceCharacterInName");
3032
var importallcustomdigicertfields =
3133
Convert.ToBoolean(ConfigurationManager.AppSettings.Get("ImportAllCustomDigicertFields"));
@@ -75,7 +77,7 @@ public static void Main(string[] args)
7577
_logger.Debug("Got list of custom fields from Keyfactor.");
7678

7779
//Getting list of custom metadata fields on DigiCert
78-
var customdigicertmetadatafieldlist = GrabCustomFieldsFromDigiCert(digicertapikey);
80+
var customdigicertmetadatafieldlist = GrabCustomFieldsFromDigiCert(digicertapikey, importdeactivated);
7981

8082
//Convert DigiCert custom fields to Keyfactor appropriate ones
8183
//This depends on whether the setting to import all fields was enabled or not
@@ -253,11 +255,11 @@ CURRENTLY REPLACING WITH "_-_" AS STAND IN FOR SPACE CHARACTER.
253255

254256
// Grabbing the list again from digicert, populating ids for new ones
255257
//Getting list of custom metadata fields on DigiCert
256-
var updatedmetadatafieldlist = GrabCustomFieldsFromDigiCert(digicertapikey);
258+
var updatedmetadatafieldlist = GrabCustomFieldsFromDigiCert(digicertapikey, importdeactivated);
257259
foreach (var subitem in updatedmetadatafieldlist)
258-
foreach (var fulllistitem in fullcustomdgfieldlist)
259-
if (subitem.label == fulllistitem.label)
260-
fulllistitem.id = subitem.id;
260+
foreach (var fulllistitem in fullcustomdgfieldlist)
261+
if (subitem.label == fulllistitem.label)
262+
fulllistitem.id = subitem.id;
261263

262264
var totalcertsprocessed = 0;
263265
var numcertsdatauploaded = 0;
@@ -389,9 +391,9 @@ CURRENTLY REPLACING WITH "_-_" AS STAND IN FOR SPACE CHARACTER.
389391
//Find matching certificate via Keyfactor ID
390392
var test = digicertcertinstance["certificate"]["serial_number"].ToString().ToUpper();
391393
var query = from kfcertlocal in certlist
392-
where kfcertlocal.SerialNumber ==
393-
digicertcertinstance["certificate"]["serial_number"].ToString().ToUpper()
394-
select kfcertlocal;
394+
where kfcertlocal.SerialNumber ==
395+
digicertcertinstance["certificate"]["serial_number"].ToString().ToUpper()
396+
select kfcertlocal;
395397
var certificateid = query.FirstOrDefault().Id;
396398

397399

@@ -412,9 +414,9 @@ CURRENTLY REPLACING WITH "_-_" AS STAND IN FOR SPACE CHARACTER.
412414
{
413415
//Using custom names
414416
var metadatanamequery = from customfieldinstance in kfcustomfields
415-
where customfieldinstance.DigicertFieldName ==
416-
metadatafieldinstance["label"]
417-
select customfieldinstance;
417+
where customfieldinstance.DigicertFieldName ==
418+
metadatafieldinstance["label"]
419+
select customfieldinstance;
418420
if (metadatanamequery.FirstOrDefault() != null)
419421
payloadforkf.Metadata[metadatanamequery.FirstOrDefault().DigicertFieldName] =
420422
metadatafieldinstance["value"];

readme_source.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ This should include the common prefix all DigiCert certs have in your Keyfactor
2525
This setting enables the tool to import all of the custom metadata fields included in DigiCert and sync all of their data.
2626
- <b>ReplaceDigicertWhiteSpaceCharacterInName</b>
2727
In case the ImportAllCustomDigicertFields setting is used, this is necessary to for metadata field label conversion. DigiCert supports spaces in labels and Keyfactor does not, so this replaces the spaces in the name with your character sequence of choice.
28+
- <b>ImportDataForDeactivatedDigiCertFields</b>
29+
If this is enabled, custom metadata fields that were deactivated in DigiCert will also be synced, and the data stored in these fields in certificates will be too.
2830

2931
### manualfields.json settings
3032
This file is used to specify which metadata fields should be synced up.

0 commit comments

Comments
 (0)