@@ -51,7 +51,7 @@ const (
5151)
5252
5353var (
54- AuditHeader = []string {"Thumbprint" , "CertID" , "StoreID" , "StoreType" , "Machine" , "Path" , "AddCert" , "RemoveCert" , "Deployed" }
54+ AuditHeader = []string {"Thumbprint" , "CertID" , "SubjectName" , "Issuer" , " StoreID" , "StoreType" , "Machine" , "Path" , "AddCert" , "RemoveCert" , "Deployed" }
5555 StoreHeader = []string {"StoreID" , "StoreType" , "StoreMachine" , "StorePath" }
5656 CertHeader = []string {"Thumbprint" }
5757)
@@ -115,6 +115,7 @@ func generateAuditReport(addCerts map[string]string, removeCerts map[string]stri
115115 }
116116 certLookup , err := kfClient .GetCertificateContext (& certLookupReq )
117117 if err != nil {
118+ fmt .Printf ("Error looking up certificate %s: %s\n " , cert , err )
118119 log .Printf ("[ERROR] Error looking up cert: %s\n %v" , cert , err )
119120 continue
120121 }
@@ -123,20 +124,20 @@ func generateAuditReport(addCerts map[string]string, removeCerts map[string]stri
123124 for _ , store := range stores {
124125 if _ , ok := store .Thumbprints [cert ]; ok {
125126 // Cert is already in the store do nothing
126- row := []string {cert , certIDStr , store .ID , store .Type , store .Machine , store .Path , "false" , "false" , "true" }
127+ row := []string {cert , certIDStr , certLookup . IssuedDN , certLookup . IssuerDN , store .ID , store .Type , store .Machine , store .Path , "false" , "false" , "true" }
127128 data = append (data , row )
128129 wErr := csvWriter .Write (row )
129130 if wErr != nil {
130- fmt .Printf ("%s " , wErr )
131+ fmt .Printf ("Error writing audit file row: %s \n " , wErr )
131132 log .Printf ("[ERROR] Error writing audit row: %s" , wErr )
132133 }
133134 } else {
134135 // Cert is not deployed to this store and will need to be added
135- row := []string {cert , certIDStr , store .ID , store .Type , store .Machine , store .Path , "true" , "false" , "false" }
136+ row := []string {cert , certIDStr , certLookup . IssuedDN , certLookup . IssuerDN , store .ID , store .Type , store .Machine , store .Path , "true" , "false" , "false" }
136137 data = append (data , row )
137138 wErr := csvWriter .Write (row )
138139 if wErr != nil {
139- fmt .Printf ("%s " , wErr )
140+ fmt .Printf ("Error writing audit file row: %s \n " , wErr )
140141 log .Printf ("[ERROR] Error writing audit row: %s" , wErr )
141142 }
142143 actions [cert ] = append (actions [cert ], ROTAction {
@@ -259,10 +260,11 @@ func reconcileRoots(actions map[string][]ROTAction, kfClient *api.Client, dryRun
259260 }
260261 _ , err := kfClient .RemoveCertificateFromStores (& removeReq )
261262 if err != nil {
262- fmt .Printf ("Error removing cert %s (%d) from store %s (%s): %s" , a .Thumbprint , a .CertID , a .StoreID , a .StorePath , err )
263- log .Fatalf ("[ERROR] Error removing cert from store: %s" , err )
263+ fmt .Printf ("Error removing cert %s (ID: %d) from store %s (%s): %s\n " , a .Thumbprint , a .CertID , a .StoreID , a .StorePath , err )
264+ // log.Fatalf("[ERROR] Error removing cert from store: %s", err)
264265 }
265266 } else {
267+ fmt .Printf ("DRY RUN: Would have removed cert %s from store %s\n " , thumbprint , a .StoreID )
266268 log .Printf ("[INFO] DRY RUN: Would have removed cert %s from store %s" , thumbprint , a .StoreID )
267269 }
268270 }
@@ -325,7 +327,19 @@ var (
325327 rotCmd = & cobra.Command {
326328 Use : "rot" ,
327329 Short : "Root of trust utility" ,
328- Long : `Root of trust allows you to manage your trusted roots using Keyfactor certificate stores.` ,
330+ Long : `Root of trust allows you to manage your trusted roots using Keyfactor certificate stores.
331+ For example if you wish to add a list of "root" certs to a list of certificate stores you would simply generate and fill
332+ out the template CSV file. These template files can be generated with the following commands:
333+ kfutil stores rot generate-template --type certs
334+ kfutil stores rot generate-template --type stores
335+ Once those files are filled out you can use the following command to add the certs to the stores:
336+ kfutil stores rot audit --certs-file <certs-file> --stores-file <stores-file>
337+ Will generate a CSV report file 'rot_audit.csv' of what actions will be taken. If those actions are correct you can run
338+ the following command to actually perform the actions:
339+ kfutil stores rot reconcile --certs-file <certs-file> --stores-file <stores-file>
340+ OR if you want to used the audit report file generated you can run this command:
341+ kfutil stores rot reconcile --import-csv <audit-file>
342+ ` ,
329343 }
330344 rotAuditCmd = & cobra.Command {
331345 Use : "audit" ,
@@ -389,6 +403,7 @@ var (
389403 }
390404
391405 if ! isRootStore (apiResp , inventory , minCerts , maxLeaves , maxKeys ) {
406+ fmt .Printf ("Store %s is not a root store, skipping.\n " , entry [0 ])
392407 log .Printf ("[WARN] Store %s is not a root store" , apiResp .Id )
393408 continue
394409 } else {
@@ -437,11 +452,11 @@ var (
437452 // Read in the remove removeCerts CSV
438453 var certsToRemove = make (map [string ]string )
439454 if removeRootsFile != "" {
440- certsToRemove , rErr : = readCertsFile (removeRootsFile , kfClient )
441- if rErr != nil {
442- fmt .Printf ("Error reading removeCerts file: %s" , rErr )
443- log .Fatalf ("Error reading removeCerts file: %s" , rErr )
444- }
455+ certsToRemove , _ = readCertsFile (removeRootsFile , kfClient )
456+ // if rErr != nil {
457+ // fmt.Printf("Error reading removeCerts file: %s", rErr)
458+ // log.Fatalf("Error reading removeCerts file: %s", rErr)
459+ // }
445460 removeCertsJSON , _ := json .Marshal (certsToRemove )
446461 log .Printf ("[DEBUG] remove certs JSON: %s" , string (removeCertsJSON ))
447462 } else {
@@ -731,6 +746,7 @@ var (
731746 }
732747 file , err := os .Create (filePath )
733748 if err != nil {
749+ fmt .Printf ("Error creating file: %s" , err )
734750 log .Fatal ("Cannot create file" , err )
735751 }
736752
@@ -759,7 +775,7 @@ var (
759775 log .Fatal ("Cannot write to file" , err )
760776 }
761777 }
762-
778+ fmt . Printf ( "Template file created at %s" , filePath )
763779 },
764780 RunE : nil ,
765781 PostRun : nil ,
0 commit comments