@@ -34,7 +34,8 @@ import (
3434// EnrollPFX takes arguments for EnrollPFXFctArgs to facilitate a call to Keyfactor
3535// that enrolls a PFX certificate with the supplied arguments.
3636func (c * Client ) EnrollPFX (ea * EnrollPFXFctArgs ) (* EnrollResponse , error ) {
37- // 0
37+ log .Println ("[INFO] Enrolling PFX certificate with Keyfactor" )
38+
3839 /* Ensure required inputs exist */
3940 var missingFields []string
4041
@@ -106,7 +107,8 @@ func (c *Client) EnrollPFX(ea *EnrollPFXFctArgs) (*EnrollResponse, error) {
106107}
107108
108109func (c * Client ) EnrollPFXV2 (ea * EnrollPFXFctArgsV2 ) (* EnrollResponseV2 , error ) {
109- // 0
110+ log .Println ("[INFO] Enrolling PFX certificate with Keyfactor" )
111+
110112 /* Ensure required inputs exist */
111113 var missingFields []string
112114
@@ -160,7 +162,8 @@ func (c *Client) EnrollPFXV2(ea *EnrollPFXFctArgsV2) (*EnrollResponseV2, error)
160162 Payload : & ea ,
161163 }
162164
163- // 0
165+ log .Println ("[TRACE] Request: " , keyfactorAPIStruct )
166+
164167 resp , err := c .sendRequest (keyfactorAPIStruct )
165168 if err != nil {
166169 return nil , err
@@ -194,7 +197,8 @@ func (c *Client) DownloadCertificate(
194197 serialNumber string ,
195198 issuerDn string ,
196199) (* x509.Certificate , []* x509.Certificate , error ) {
197- // 0
200+ log .Println ("[INFO] Downloading certificate" )
201+
198202 /* The download certificate endpoint requires one of the following to retrieve a cert:
199203 - CertID
200204 - Thumbprint
@@ -282,7 +286,8 @@ func (c *Client) DownloadCertificate(
282286// - Template : string
283287// - CertificateAuthority : string
284288func (c * Client ) EnrollCSR (ea * EnrollCSRFctArgs ) (* EnrollResponse , error ) {
285- // 0
289+ log .Println ("[INFO] Signing CSR with Keyfactor" )
290+
286291 /* Ensure required inputs exist */
287292 if (ea .Template == "" ) || (ea .CertificateAuthority == "" ) {
288293 return nil , errors .New ("invalid or nonexistent values required for csr enrollment" )
@@ -328,9 +333,9 @@ func (c *Client) EnrollCSR(ea *EnrollCSRFctArgs) (*EnrollResponse, error) {
328333// - CertificateIds : []int
329334// - Comment : string
330335func (c * Client ) RevokeCert (rvargs * RevokeCertArgs ) error {
331- // 0
336+ log . Println ( "[INFO] Revoking certificates" )
332337 //for _, certs := range rvargs.CertificateIds {
333- // // 0
338+ // log.Printf("[TRACE] Revoking ID %d", certs)
334339 //}
335340
336341 // Fields required by revoke cert API request are cert ID & comment
@@ -640,8 +645,8 @@ func (c *Client) RecoverCertificate(
640645 password string ,
641646 collectionId int ,
642647) (interface {}, * x509.Certificate , []* x509.Certificate , error ) {
643- // 0
644- // 0
648+ log . Println ( "[DEBUG] Enter RecoverCertificate" )
649+ log . Println ( "[INFO] Recovering certificate ID:" , certId )
645650 /* The download certificate endpoint requires one of the following to retrieve a cert:
646651 - CertID
647652 - Thumbprint
@@ -659,10 +664,11 @@ func (c *Client) RecoverCertificate(
659664 }
660665
661666 if ! validInput {
662- // 0
667+ log . Println ( "[ERROR] RecoverCertificate: certID, thumbprint, or serial number AND issuer DN required to download certificate" )
663668 return nil , nil , nil , fmt .Errorf ("certID, thumbprint, or serial number AND issuer DN required to download certificate" )
664669 }
665- // 0
670+ log .Println ("[DEBUG] RecoverCertificate: Valid input" )
671+
666672 if password == "" {
667673 return nil , nil , nil , fmt .Errorf ("password required to recover private key with certificate" )
668674 }
@@ -676,7 +682,7 @@ func (c *Client) RecoverCertificate(
676682 IncludeChain : true ,
677683 }
678684
679- // 0
685+ log . Println ( "[DEBUG] RecoverCertificate: Recovering certificate with args:" , rca )
680686 // Set Keyfactor-specific headers
681687 headers := & apiHeaders {
682688 Headers : []StringTuple {
@@ -691,16 +697,16 @@ func (c *Client) RecoverCertificate(
691697 Query : []StringTuple {},
692698 }
693699 if collectionId > 0 {
694- // 0
700+ log . Println ( "[DEBUG] RecoverCertificate: Collection ID:" , collectionId )
695701 query .Query = append (
696702 query .Query , StringTuple {
697703 "collectionId" , fmt .Sprintf ("%d" , collectionId ),
698704 },
699705 )
700- // 0
706+ log . Println ( "[DEBUG] RecoverCertificate: Query:" , query )
701707 }
702708
703- // 0
709+ log . Println ( "[DEBUG] RecoverCertificate: Creating recover certificate request" )
704710 keyfactorAPIStruct := & request {
705711 Method : "POST" ,
706712 Endpoint : "Certificates/Recover" ,
@@ -709,37 +715,37 @@ func (c *Client) RecoverCertificate(
709715 Query : & query ,
710716 }
711717
712- // 0
718+ log . Println ( "[INFO] Attempting to recover certificate from Keyfactor Command" )
713719 resp , err := c .sendRequest (keyfactorAPIStruct )
714720 if err != nil {
715721 log .Println ("[ERROR] RecoverCertificate: Error recovering certificate from Keyfactor Command" , err .Error ())
716722 return nil , nil , nil , err
717723 }
718724
719725 jsonResp := & recoverCertResponse {}
720- // 0
726+ log . Println ( "[DEBUG] RecoverCertificate: Decoding response" )
721727 err = json .NewDecoder (resp .Body ).Decode (& jsonResp )
722728 if err != nil {
723729 log .Println ("[ERROR] RecoverCertificate: Error decoding response from Keyfactor Command" , err .Error ())
724730 return nil , nil , nil , err
725731 }
726732
727- // 0
733+ log . Println ( "[DEBUG] RecoverCertificate: Decoding PFX" )
728734 pfxDer , err := base64 .StdEncoding .DecodeString (jsonResp .PFX )
729735 if err != nil {
730736 log .Println ("[ERROR] RecoverCertificate: Error decoding PFX" , err .Error ())
731737 return nil , nil , nil , err
732738 }
733739
734- // 0
740+ log . Println ( "[DEBUG] RecoverCertificate: Decoding PFX chain" )
735741 priv , leaf , chain , err := pkcs12 .DecodeChain (pfxDer , rca .Password )
736742 if err != nil {
737743 log .Println ("[ERROR] RecoverCertificate: Error decoding PFX chain" , err .Error ())
738744 return nil , nil , nil , err
739745 }
740746
741- // 0
742- // 0
747+ log . Println ( "[INFO] Recovered certificate successfully" )
748+ log . Println ( "[DEBUG] RecoverCertificate: " , leaf , chain )
743749 return priv , leaf , chain , nil
744750}
745751
@@ -794,7 +800,7 @@ func validateDeployPFXArgs(dpfxa *DeployPFXArgs) error {
794800
795801// decodePKCS12Blob decodes a PKCS12 blob.
796802func decodePKCS12Blob (resp * EnrollResponse ) error {
797- // 0
803+ log . Println ( "[TRACE] Decoding certificate" )
798804 // Keyfactor returns base-64 PFX (PKCS#12) or zipped certificate. Decode here.
799805 if resp .CertificateInformation .PKCS12Blob != "" {
800806 cert , err := base64 .StdEncoding .DecodeString (resp .CertificateInformation .PKCS12Blob )
0 commit comments