@@ -38,9 +38,13 @@ var rotCmd = &cobra.Command{
3838 var lookupFailures []string
3939 kfClient , _ := initClient ()
4040 storesFile , _ := cmd .Flags ().GetString ("stores" )
41- certsFile , _ := cmd .Flags ().GetString ("certs" )
41+ addRootsFile , _ := cmd .Flags ().GetString ("add-certs" )
42+ removeRootsFile , _ := cmd .Flags ().GetString ("remove-certs" )
43+ dryRun , _ := cmd .Flags ().GetBool ("dry-run" )
4244 log .Printf ("[DEBUG] storesFile: %s" , storesFile )
43- log .Printf ("[DEBUG] certsFile: %s" , certsFile )
45+ log .Printf ("[DEBUG] addRootsFile: %s" , addRootsFile )
46+ log .Printf ("[DEBUG] removeRootsFile: %s" , removeRootsFile )
47+ log .Printf ("[DEBUG] dryRun: %t" , dryRun )
4448
4549 // Read in the stores CSV
4650 csvFile , _ := os .Open (storesFile )
@@ -69,31 +73,65 @@ var rotCmd = &cobra.Command{
6973 storesJson , _ := json .Marshal (stores )
7074 fmt .Println (string (storesJson ))
7175
72- // Read in the certs CSV
73- csvFile , _ = os .Open (certsFile )
74- reader = csv .NewReader (bufio .NewReader (csvFile ))
75- certEntries , _ := reader .ReadAll ()
76- var certs = make (map [string ]RotCert )
77- for _ , entry := range certEntries {
78- if entry [0 ] == "CertId" || entry [0 ] == "thumbprint" {
79- continue // Skip header
76+ // Read in the add addCerts CSV
77+ var addCerts = make (map [string ]RotCert )
78+ if addRootsFile != "" {
79+ addCerts , err := readCertsFile (addRootsFile )
80+ if err != nil {
81+ log .Fatalf ("Error reading addCerts file: %s" , err )
8082 }
81- certs [entry [0 ]] = RotCert {
82- ThumbPrint : entry [0 ],
83+ addCertsJson , _ := json .Marshal (addCerts )
84+ fmt .Printf ("[DEBUG] add certs JSON: %s" , string (addCertsJson ))
85+ fmt .Println ("add rot called" )
86+ } else {
87+ log .Printf ("[DEBUG] No addCerts file specified" )
88+ log .Printf ("[DEBUG] No addCerts = %s" , addCerts )
89+ }
90+
91+ // Read in the remove removeCerts CSV
92+ var removeCerts = make (map [string ]RotCert )
93+ if removeRootsFile != "" {
94+ removeCerts , err := readCertsFile (removeRootsFile )
95+ if err != nil {
96+ log .Fatalf ("Error reading removeCerts file: %s" , err )
8397 }
84- // Get certificate context
85- //args := &api.GetCertificateContextArgs{
86- // IncludeMetadata: boolToPointer(true),
87- // IncludeLocations: boolToPointer(true),
88- // CollectionId: nil,
89- // Id: certificateIdInt,
90- //}
91- //cResp, err := r.p.client.GetCertificateContext(args)
98+ removeCertsJson , _ := json .Marshal (removeCerts )
99+ fmt .Println (string (removeCertsJson ))
100+ fmt .Println ("remove rot called" )
101+ } else {
102+ log .Printf ("[DEBUG] No removeCerts file specified" )
103+ log .Printf ("[DEBUG] No removeCerts = %s" , removeCerts )
92104 }
93- fmt .Println ("rot called" )
94105 },
95106}
96107
108+ func readCertsFile (certsFilePath string ) (map [string ]RotCert , error ) {
109+ // Read in the cert CSV
110+ csvFile , _ := os .Open (certsFilePath )
111+ reader := csv .NewReader (bufio .NewReader (csvFile ))
112+ certEntries , _ := reader .ReadAll ()
113+ var certs = make (map [string ]RotCert )
114+ for _ , entry := range certEntries {
115+ switch entry [0 ] {
116+ case "CertId" , "thumbprint" , "id" , "certId" , "Thumbprint" :
117+ continue // Skip header
118+ }
119+
120+ certs [entry [0 ]] = RotCert {
121+ ThumbPrint : entry [0 ],
122+ }
123+ // Get certificate context
124+ //args := &api.GetCertificateContextArgs{
125+ // IncludeMetadata: boolToPointer(true),
126+ // IncludeLocations: boolToPointer(true),
127+ // CollectionId: nil,
128+ // Id: certificateIdInt,
129+ //}
130+ //cResp, err := r.p.client.GetCertificateContext(args)
131+ }
132+ return certs , nil
133+ }
134+
97135var rotGenStoreTemplateCmd = & cobra.Command {
98136 Use : "generate-template-rot" ,
99137 Short : "For generating Root Of Trust template(s)" ,
@@ -177,7 +215,10 @@ func init() {
177215 var certs string
178216 rotCmd .Flags ().StringVarP (& stores , "stores" , "s" , "" , "CSV file containing cert stores to enroll into" )
179217 rotCmd .MarkFlagRequired ("stores" )
180- rotCmd .Flags ().StringVarP (& certs , "certs" , "c" , "" , "CSV file containing cert(s) to enroll into the defined cert stores" )
218+ rotCmd .Flags ().StringVarP (& certs , "add-certs" , "a" , "" , "CSV file containing cert(s) to enroll into the defined cert stores" )
219+ rotCmd .Flags ().StringVarP (& certs , "remove-certs" , "r" , "" , "CSV file containing cert(s) to remove from the defined cert stores" )
220+
221+ rotCmd .Flags ().BoolP ("dry-run" , "d" , false , "Dry run mode" )
181222 rotCmd .MarkFlagRequired ("certs" )
182223 storesCmd .AddCommand (rotGenStoreTemplateCmd )
183224 rotGenStoreTemplateCmd .Flags ().String ("outpath" , "template.csv" , "Output file to write the template to" )
0 commit comments