Skip to content

Commit 6386fc5

Browse files
authored
Merge 1bc7e47 into 0fd1a96
2 parents 0fd1a96 + 1bc7e47 commit 6386fc5

File tree

4 files changed

+146
-92
lines changed

4 files changed

+146
-92
lines changed

v3/api/certificate.go

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ func (c *Client) DownloadCertificate(
196196
thumbprint string,
197197
serialNumber string,
198198
issuerDn string,
199+
collectionId int,
199200
) (*x509.Certificate, []*x509.Certificate, error) {
200201
log.Println("[INFO] Downloading certificate")
201202

@@ -228,6 +229,19 @@ func (c *Client) DownloadCertificate(
228229
ChainOrder: "EndEntityFirst",
229230
}
230231

232+
query := apiQuery{
233+
Query: []StringTuple{},
234+
}
235+
if collectionId > 0 {
236+
log.Println("[DEBUG] RecoverCertificate: Collection ID:", collectionId)
237+
query.Query = append(
238+
query.Query, StringTuple{
239+
"collectionId", fmt.Sprintf("%d", collectionId),
240+
},
241+
)
242+
log.Println("[DEBUG] RecoverCertificate: Query:", query)
243+
}
244+
231245
// Set Keyfactor-specific headers
232246
headers := &apiHeaders{
233247
Headers: []StringTuple{
@@ -242,6 +256,7 @@ func (c *Client) DownloadCertificate(
242256
Endpoint: "Certificates/Download",
243257
Headers: headers,
244258
Payload: payload,
259+
Query: &query,
245260
}
246261

247262
resp, err := c.sendRequest(keyfactorAPIStruct)
@@ -754,30 +769,39 @@ func createSubject(cs CertificateSubject) (string, error) {
754769
var subject string
755770

756771
if cs.SubjectCommonName != "" && cs.SubjectCommonName != "<null>" {
757-
subject = "CN=" + cs.SubjectCommonName + ","
772+
subject = "CN=" + escapeDNValue(cs.SubjectCommonName) + ","
758773
} else {
759774
return "", errors.New("build subject: common name required") // Common name is required!
760775
}
761776
if cs.SubjectOrganizationalUnit != "" && cs.SubjectOrganizationalUnit != "<null>" {
762-
subject += "OU=" + cs.SubjectOrganizationalUnit + ","
777+
subject += "OU=" + escapeDNValue(cs.SubjectOrganizationalUnit) + ","
763778
}
764779
if cs.SubjectOrganization != "" && cs.SubjectOrganization != "<null>" {
765-
subject += "O=" + cs.SubjectOrganization + ","
780+
subject += "O=" + escapeDNValue(cs.SubjectOrganization) + ","
766781
}
767782
if cs.SubjectLocality != "" && cs.SubjectLocality != "<null>" {
768-
subject += "L=" + cs.SubjectLocality + ","
783+
subject += "L=" + escapeDNValue(cs.SubjectLocality) + ","
769784
}
770785
if cs.SubjectState != "" && cs.SubjectState != "<null>" {
771-
subject += "ST=" + cs.SubjectState + ","
786+
subject += "ST=" + escapeDNValue(cs.SubjectState) + ","
772787
}
773788
if cs.SubjectCountry != "" && cs.SubjectCountry != "<null>" {
774-
subject += "C=" + cs.SubjectCountry + ","
789+
subject += "C=" + escapeDNValue(cs.SubjectCountry) + ","
775790
}
776791
subject = strings.TrimRight(subject, ",") // remove trailing comma
777792
log.Printf("[DEBUG] createSubject(): Certificate subject created: %s\n", subject)
778793
return subject, nil
779794
}
780795

796+
// escapeDNValue ensures that a value in a DN is properly escaped if it contains special characters.
797+
func escapeDNValue(value string) string {
798+
// If the value contains a comma, quote it
799+
if strings.Contains(value, ",") {
800+
return `"` + value + `"`
801+
}
802+
return value
803+
}
804+
781805
// validateDeployPFXArgs validates the arguments required to deploy a PFX certificate.
782806
func validateDeployPFXArgs(dpfxa *DeployPFXArgs) error {
783807
if dpfxa.StoreIds == nil {

v3/api/store_models.go

Lines changed: 57 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,20 @@ type UpdateStoreFctArgs struct {
5151
// automatically populated by the CreateStore method. However, if configured, this field will be used.
5252
PropertiesString string `json:"Properties,omitempty"`
5353
// Mapped name-value pair field used to configure properties.
54-
Properties map[string]interface{} `json:"-"`
55-
AgentId string `json:"AgentId"`
56-
AgentAssigned *bool `json:"AgentAssigned,omitempty"`
57-
ContainerName *string `json:"ContainerName,omitempty"`
58-
InventorySchedule *InventorySchedule `json:"InventorySchedule,omitempty"`
59-
ReEnrollmentStatus *ReEnrollmnentConfig `json:"ReEnrollmentStatus,omitempty"`
60-
SetNewPasswordAllowed *bool `json:"SetNewPasswordAllowed,omitempty"`
61-
Password *StorePasswordConfig `json:"Password"`
54+
Properties map[string]interface{} `json:"-"`
55+
AgentId string `json:"AgentId"`
56+
AgentAssigned *bool `json:"AgentAssigned,omitempty"`
57+
ContainerName *string `json:"ContainerName,omitempty"`
58+
InventorySchedule *InventorySchedule `json:"InventorySchedule,omitempty"`
59+
ReEnrollmentStatus *ReEnrollmnentConfig `json:"ReEnrollmentStatus,omitempty"`
60+
SetNewPasswordAllowed *bool `json:"SetNewPasswordAllowed,omitempty"`
61+
Password *UpdateStorePasswordConfig `json:"Password"`
62+
}
63+
64+
type UpdateStorePasswordConfig struct {
65+
SecretValue *string `json:"SecretValue"` // used for setting kf-secret value or No Value (null)
66+
Parameters map[string]string `json:"Parameters"`
67+
Provider int `json:"Provider"`
6268
}
6369

6470
// InventorySchedule holds configuration data for creating an inventory schedule for a certificate store in Keyfactor
@@ -94,34 +100,59 @@ type ReEnrollmnentConfig struct {
94100
}
95101

96102
// StorePasswordConfig configures the password field for a new certificate store.
103+
// TODO: make re-usable struct for Secret type fields
97104
type StorePasswordConfig struct {
98-
Value *string `json:"SecretValue"`
99-
SecretTypeGuid *string `json:"SecretTypeGuid,omitempty"`
100-
InstanceId *string `json:"InstanceId,omitempty"`
105+
Value *string `json:"SecretValue"`
106+
SecretTypeGuid *string `json:"SecretTypeGuid,omitempty"`
107+
InstanceId *string `json:"InstanceId,omitempty"`
108+
InstanceGuid *string `json:"InstanceGuid,omitempty"`
109+
ProvidererTypeParameterValues *[]ProviderTypeParameterValue `json:"ProviderTypeParameterValues"`
110+
ProviderId int `json:"ProviderId"`
111+
IsManaged bool `json:"IsManaged"`
112+
HasValue bool `json:"HasValue"`
101113
} // ProviderTypeParameterValues - Not yet implemented
102114
// ProviderTypeParameterValues ProviderTypeParams - Not implemented
103115

104116
/* Future non-critical functionality */
105117

106-
type ProviderTypeParams struct {
107-
Id string
108-
Value string
109-
InstanceId string
110-
InstanceGuid string
111-
Provider ProviderParams
118+
type ProviderTypeParameterValue struct {
119+
Id int `json:"Id"`
120+
Value *string `json:"Value"`
121+
ParameterId int `json:"ParameterId"` // defaults always to 0, likely deprecated
122+
InstanceId *string `json:"InstanceId"` // defaults null, likely deprecated
123+
InstanceGuid *string `json:"InstanceGuid"`
124+
Provider *string `json:"Provider"` // defaults null, likely deprecated
125+
ProviderTypeParam ProviderTypeParam `json:"ProviderTypeParam"`
112126
}
113127

114-
type ProviderParams struct {
115-
Id int
116-
Name string
117-
Area int
118-
ProviderType ProviderType
128+
type ProviderTypeParam struct {
129+
Id int `json:"Id"`
130+
Name *string `json:"Name"`
131+
DisplayName *string `json:"DisplayName"`
132+
DataType int `json:"DataType"`
133+
InstanceLevel bool `json:"InstanceLevel"`
134+
ProviderType *string `json:"ProviderType"` //defaults null, likely deprecated
119135
}
120136

121-
type ProviderType struct {
122-
Id string
123-
Name string
124-
}
137+
// type ProviderTypeParams struct {
138+
// Id string
139+
// Value string
140+
// InstanceId string
141+
// InstanceGuid string
142+
// Provider ProviderParams
143+
// }
144+
145+
// type ProviderParams struct {
146+
// Id int
147+
// Name string
148+
// Area int
149+
// ProviderType ProviderType
150+
// }
151+
152+
// type ProviderType struct {
153+
// Id string
154+
// Name string
155+
// }
125156

126157
// CertStoreTypeResponse contains the response elements returned from the GetCertificateStoreType method.
127158
type CertStoreTypeResponse struct {

v3/go.mod

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,36 +14,36 @@
1414

1515
module github.com/Keyfactor/keyfactor-go-client/v3
1616

17-
go 1.23
17+
go 1.24
1818

19-
toolchain go1.23.2
19+
toolchain go1.24.5
2020

2121
require (
22-
github.com/Keyfactor/keyfactor-auth-client-go v1.1.1-rc.0
22+
github.com/Keyfactor/keyfactor-auth-client-go v1.3.0
2323
github.com/hashicorp/terraform-plugin-log v0.9.0
2424
github.com/spbsoluble/go-pkcs12 v0.3.3
2525
go.mozilla.org/pkcs7 v0.9.0
2626
)
2727

2828
require (
29-
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.16.0 // indirect
30-
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.8.0 // indirect
31-
github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0 // indirect
32-
github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/azsecrets v1.3.0 // indirect
33-
github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/internal v1.1.0 // indirect
34-
github.com/AzureAD/microsoft-authentication-library-for-go v1.3.2 // indirect
35-
github.com/fatih/color v1.13.0 // indirect
36-
github.com/golang-jwt/jwt/v5 v5.2.1 // indirect
29+
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.18.0 // indirect
30+
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.10.1 // indirect
31+
github.com/Azure/azure-sdk-for-go/sdk/internal v1.11.1 // indirect
32+
github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/azsecrets v1.3.1 // indirect
33+
github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/internal v1.1.1 // indirect
34+
github.com/AzureAD/microsoft-authentication-library-for-go v1.4.2 // indirect
35+
github.com/fatih/color v1.18.0 // indirect
36+
github.com/golang-jwt/jwt/v5 v5.2.2 // indirect
3737
github.com/google/uuid v1.6.0 // indirect
38-
github.com/hashicorp/go-hclog v1.5.0 // indirect
38+
github.com/hashicorp/go-hclog v1.6.3 // indirect
3939
github.com/kylelemons/godebug v1.1.0 // indirect
40-
github.com/mattn/go-colorable v0.1.13 // indirect
41-
github.com/mattn/go-isatty v0.0.19 // indirect
40+
github.com/mattn/go-colorable v0.1.14 // indirect
41+
github.com/mattn/go-isatty v0.0.20 // indirect
4242
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect
43-
golang.org/x/crypto v0.30.0 // indirect
44-
golang.org/x/net v0.32.0 // indirect
45-
golang.org/x/oauth2 v0.24.0 // indirect
46-
golang.org/x/sys v0.28.0 // indirect
47-
golang.org/x/text v0.21.0 // indirect
43+
golang.org/x/crypto v0.39.0 // indirect
44+
golang.org/x/net v0.41.0 // indirect
45+
golang.org/x/oauth2 v0.30.0 // indirect
46+
golang.org/x/sys v0.33.0 // indirect
47+
golang.org/x/text v0.26.0 // indirect
4848
gopkg.in/yaml.v2 v2.4.0 // indirect
4949
)

0 commit comments

Comments
 (0)