@@ -21,6 +21,7 @@ import (
2121 "encoding/pem"
2222 "errors"
2323 "fmt"
24+ "log"
2425 "net/http"
2526 "strconv"
2627 "strings"
@@ -33,7 +34,7 @@ import (
3334// EnrollPFX takes arguments for EnrollPFXFctArgs to facilitate a call to Keyfactor
3435// that enrolls a PFX certificate with the supplied arguments.
3536func (c * Client ) EnrollPFX (ea * EnrollPFXFctArgs ) (* EnrollResponse , error ) {
36- // log.println ("[INFO] Enrolling PFX certificate with Keyfactor")
37+ log .Println ("[INFO] Enrolling PFX certificate with Keyfactor" )
3738
3839 /* Ensure required inputs exist */
3940 var missingFields []string
@@ -106,7 +107,7 @@ func (c *Client) EnrollPFX(ea *EnrollPFXFctArgs) (*EnrollResponse, error) {
106107}
107108
108109func (c * Client ) EnrollPFXV2 (ea * EnrollPFXFctArgsV2 ) (* EnrollResponseV2 , error ) {
109- // log.println ("[INFO] Enrolling PFX certificate with Keyfactor")
110+ log .Println ("[INFO] Enrolling PFX certificate with Keyfactor" )
110111
111112 /* Ensure required inputs exist */
112113 var missingFields []string
@@ -161,6 +162,8 @@ func (c *Client) EnrollPFXV2(ea *EnrollPFXFctArgsV2) (*EnrollResponseV2, error)
161162 Payload : & ea ,
162163 }
163164
165+ log .Println ("[TRACE] Request: " , keyfactorAPIStruct )
166+
164167 resp , err := c .sendRequest (keyfactorAPIStruct )
165168 if err != nil {
166169 return nil , err
@@ -194,7 +197,7 @@ func (c *Client) DownloadCertificate(
194197 serialNumber string ,
195198 issuerDn string ,
196199) (* x509.Certificate , []* x509.Certificate , error ) {
197- // log.println ("[INFO] Downloading certificate")
200+ log .Println ("[INFO] Downloading certificate" )
198201
199202 /* The download certificate endpoint requires one of the following to retrieve a cert:
200203 - CertID
@@ -283,7 +286,7 @@ func (c *Client) DownloadCertificate(
283286// - Template : string
284287// - CertificateAuthority : string
285288func (c * Client ) EnrollCSR (ea * EnrollCSRFctArgs ) (* EnrollResponse , error ) {
286- // log.println ("[INFO] Signing CSR with Keyfactor")
289+ log .Println ("[INFO] Signing CSR with Keyfactor" )
287290
288291 /* Ensure required inputs exist */
289292 if (ea .Template == "" ) || (ea .CertificateAuthority == "" ) {
@@ -330,9 +333,9 @@ func (c *Client) EnrollCSR(ea *EnrollCSRFctArgs) (*EnrollResponse, error) {
330333// - CertificateIds : []int
331334// - Comment : string
332335func (c * Client ) RevokeCert (rvargs * RevokeCertArgs ) error {
333- // log.println ("[INFO] Revoking certificates")
336+ log .Println ("[INFO] Revoking certificates" )
334337 //for _, certs := range rvargs.CertificateIds {
335- // // log.printf ("[TRACE] Revoking ID %d", certs)
338+ // log.Printf ("[TRACE] Revoking ID %d", certs)
336339 //}
337340
338341 // Fields required by revoke cert API request are cert ID & comment
@@ -642,8 +645,8 @@ func (c *Client) RecoverCertificate(
642645 password string ,
643646 collectionId int ,
644647) (interface {}, * x509.Certificate , []* x509.Certificate , error ) {
645- // log.println ("[DEBUG] Enter RecoverCertificate")
646- // log.println ("[INFO] Recovering certificate ID:", certId)
648+ log .Println ("[DEBUG] Enter RecoverCertificate" )
649+ log .Println ("[INFO] Recovering certificate ID:" , certId )
647650 /* The download certificate endpoint requires one of the following to retrieve a cert:
648651 - CertID
649652 - Thumbprint
@@ -661,10 +664,10 @@ func (c *Client) RecoverCertificate(
661664 }
662665
663666 if ! validInput {
664- // log.println ("[ERROR] RecoverCertificate: certID, thumbprint, or serial number AND issuer DN required to download certificate")
667+ log .Println ("[ERROR] RecoverCertificate: certID, thumbprint, or serial number AND issuer DN required to download certificate" )
665668 return nil , nil , nil , fmt .Errorf ("certID, thumbprint, or serial number AND issuer DN required to download certificate" )
666669 }
667- // log.println ("[DEBUG] RecoverCertificate: Valid input")
670+ log .Println ("[DEBUG] RecoverCertificate: Valid input" )
668671
669672 if password == "" {
670673 return nil , nil , nil , fmt .Errorf ("password required to recover private key with certificate" )
@@ -679,7 +682,7 @@ func (c *Client) RecoverCertificate(
679682 IncludeChain : true ,
680683 }
681684
682- // log.println ("[DEBUG] RecoverCertificate: Recovering certificate with args:", rca)
685+ log .Println ("[DEBUG] RecoverCertificate: Recovering certificate with args:" , rca )
683686 // Set Keyfactor-specific headers
684687 headers := & apiHeaders {
685688 Headers : []StringTuple {
@@ -694,16 +697,16 @@ func (c *Client) RecoverCertificate(
694697 Query : []StringTuple {},
695698 }
696699 if collectionId > 0 {
697- // log.println ("[DEBUG] RecoverCertificate: Collection ID:", collectionId)
700+ log .Println ("[DEBUG] RecoverCertificate: Collection ID:" , collectionId )
698701 query .Query = append (
699702 query .Query , StringTuple {
700703 "collectionId" , fmt .Sprintf ("%d" , collectionId ),
701704 },
702705 )
703- // log.println ("[DEBUG] RecoverCertificate: Query:", query)
706+ log .Println ("[DEBUG] RecoverCertificate: Query:" , query )
704707 }
705708
706- // log.println ("[DEBUG] RecoverCertificate: Creating recover certificate request")
709+ log .Println ("[DEBUG] RecoverCertificate: Creating recover certificate request" )
707710 keyfactorAPIStruct := & request {
708711 Method : "POST" ,
709712 Endpoint : "Certificates/Recover" ,
@@ -712,37 +715,37 @@ func (c *Client) RecoverCertificate(
712715 Query : & query ,
713716 }
714717
715- // log.println ("[INFO] Attempting to recover certificate from Keyfactor Command")
718+ log .Println ("[INFO] Attempting to recover certificate from Keyfactor Command" )
716719 resp , err := c .sendRequest (keyfactorAPIStruct )
717720 if err != nil {
718- // log.println ("[ERROR] RecoverCertificate: Error recovering certificate from Keyfactor Command", err.Error())
721+ log .Println ("[ERROR] RecoverCertificate: Error recovering certificate from Keyfactor Command" , err .Error ())
719722 return nil , nil , nil , err
720723 }
721724
722725 jsonResp := & recoverCertResponse {}
723- // log.println ("[DEBUG] RecoverCertificate: Decoding response")
726+ log .Println ("[DEBUG] RecoverCertificate: Decoding response" )
724727 err = json .NewDecoder (resp .Body ).Decode (& jsonResp )
725728 if err != nil {
726- // log.println ("[ERROR] RecoverCertificate: Error decoding response from Keyfactor Command", err.Error())
729+ log .Println ("[ERROR] RecoverCertificate: Error decoding response from Keyfactor Command" , err .Error ())
727730 return nil , nil , nil , err
728731 }
729732
730- // log.println ("[DEBUG] RecoverCertificate: Decoding PFX")
733+ log .Println ("[DEBUG] RecoverCertificate: Decoding PFX" )
731734 pfxDer , err := base64 .StdEncoding .DecodeString (jsonResp .PFX )
732735 if err != nil {
733- // log.println ("[ERROR] RecoverCertificate: Error decoding PFX", err.Error())
736+ log .Println ("[ERROR] RecoverCertificate: Error decoding PFX" , err .Error ())
734737 return nil , nil , nil , err
735738 }
736739
737- // log.println ("[DEBUG] RecoverCertificate: Decoding PFX chain")
740+ log .Println ("[DEBUG] RecoverCertificate: Decoding PFX chain" )
738741 priv , leaf , chain , err := pkcs12 .DecodeChain (pfxDer , rca .Password )
739742 if err != nil {
740- // log.println ("[ERROR] RecoverCertificate: Error decoding PFX chain", err.Error())
743+ log .Println ("[ERROR] RecoverCertificate: Error decoding PFX chain" , err .Error ())
741744 return nil , nil , nil , err
742745 }
743746
744- // log.println ("[INFO] Recovered certificate successfully")
745- //// log.println ("[DEBUG] RecoverCertificate: ", leaf, chain)
747+ log .Println ("[INFO] Recovered certificate successfully" )
748+ log .Println ("[DEBUG] RecoverCertificate: " , leaf , chain )
746749 return priv , leaf , chain , nil
747750}
748751
@@ -771,7 +774,7 @@ func createSubject(cs CertificateSubject) (string, error) {
771774 subject += "C=" + cs .SubjectCountry + ","
772775 }
773776 subject = strings .TrimRight (subject , "," ) // remove trailing comma
774- // log.printf ("[DEBUG] createSubject(): Certificate subject created: %s\n", subject)
777+ log .Printf ("[DEBUG] createSubject(): Certificate subject created: %s\n " , subject )
775778 return subject , nil
776779}
777780
@@ -797,7 +800,7 @@ func validateDeployPFXArgs(dpfxa *DeployPFXArgs) error {
797800
798801// decodePKCS12Blob decodes a PKCS12 blob.
799802func decodePKCS12Blob (resp * EnrollResponse ) error {
800- // log.println ("[TRACE] Decoding certificate")
803+ log .Println ("[TRACE] Decoding certificate" )
801804 // Keyfactor returns base-64 PFX (PKCS#12) or zipped certificate. Decode here.
802805 if resp .CertificateInformation .PKCS12Blob != "" {
803806 cert , err := base64 .StdEncoding .DecodeString (resp .CertificateInformation .PKCS12Blob )
0 commit comments