Skip to content

Commit 76e8038

Browse files
authored
Merge pull request #36 from Keyfactor/v3
v3.0.0
2 parents 76b10d5 + 7778c60 commit 76e8038

35 files changed

+5153
-90
lines changed

v2/api/agent.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@ package api
1717
import (
1818
"encoding/json"
1919
"fmt"
20+
"log"
2021
"regexp"
2122
)
2223

2324
// GetAgentList returns a list of orchestrators registered in the Keyfactor instance
2425
func (c *Client) GetAgentList() ([]Agent, error) {
25-
//log.println("[INFO] Getting a list of agents registered in Keyfactor")
26+
log.Println("[INFO] Getting a list of agents registered in Keyfactor")
2627

2728
// Set Keyfactor-specific headers
2829
headers := &apiHeaders{
@@ -53,7 +54,7 @@ func (c *Client) GetAgentList() ([]Agent, error) {
5354
}
5455

5556
func (c *Client) GetAgent(id string) ([]Agent, error) {
56-
//log.println("[INFO] Getting agent by ID or name.")
57+
log.Println("[INFO] Getting agent by ID or name.")
5758

5859
// Set Keyfactor-specific headers
5960
headers := &apiHeaders{
@@ -105,7 +106,7 @@ func (c *Client) GetAgent(id string) ([]Agent, error) {
105106
}
106107

107108
func (c *Client) ApproveAgent(id string) (string, error) {
108-
//log.printf("[INFO] Approving agent %s in Keyfactor.\n", id)
109+
log.Printf("[INFO] Approving agent %s in Keyfactor.\n", id)
109110

110111
// Set Keyfactor-specific headers
111112
headers := &apiHeaders{
@@ -140,7 +141,7 @@ func (c *Client) ApproveAgent(id string) (string, error) {
140141
}
141142

142143
func (c *Client) DisApproveAgent(id string) (string, error) {
143-
//log.printf("[INFO] Disapproving agent %s in Keyfactor.\n", id)
144+
log.Printf("[INFO] Disapproving agent %s in Keyfactor.\n", id)
144145

145146
// Set Keyfactor-specific headers
146147
headers := &apiHeaders{
@@ -175,7 +176,7 @@ func (c *Client) DisApproveAgent(id string) (string, error) {
175176
}
176177

177178
func (c *Client) ResetAgent(id string) (string, error) {
178-
//log.printf("[INFO] Resetting agent %s in Keyfactor.\n", id)
179+
log.Printf("[INFO] Resetting agent %s in Keyfactor.\n", id)
179180

180181
// Set Keyfactor-specific headers
181182
headers := &apiHeaders{
@@ -209,7 +210,7 @@ func (c *Client) ResetAgent(id string) (string, error) {
209210
}
210211

211212
func (c *Client) FetchAgentLogs(id string) (string, error) {
212-
//log.printf("[INFO] Fetching agent logs for %s.\n", id)
213+
log.Printf("[INFO] Fetching agent logs for %s.\n", id)
213214

214215
// Set Keyfactor-specific headers
215216
headers := &apiHeaders{

v2/api/ca.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ package api
1616

1717
import (
1818
"encoding/json"
19+
"log"
1920
)
2021

2122
// GetCAList returns a list of certificate authorities supported by the Keyfactor instance
2223
func (c *Client) GetCAList() ([]CA, error) {
23-
//log.println("[INFO] Getting a list of CAs from Keyfactor instance")
24+
log.Println("[INFO] Getting a list of CAs from Keyfactor instance")
2425

2526
// Set Keyfactor-specific headers
2627
headers := &apiHeaders{

v2/api/certificate.go

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
3536
func (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

108109
func (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
285288
func (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
332335
func (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.
799802
func 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

Comments
 (0)