Skip to content

Commit 2e8f2e8

Browse files
committed
fix(certificates): Remove POST field validation, let Command return the error.
1 parent 591d6c2 commit 2e8f2e8

1 file changed

Lines changed: 5 additions & 27 deletions

File tree

v3/api/certificate.go

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -36,27 +36,6 @@ import (
3636
func (c *Client) EnrollPFX(ea *EnrollPFXFctArgs) (*EnrollResponse, error) {
3737
log.Println("[INFO] Enrolling PFX certificate with Keyfactor")
3838

39-
/* Ensure required inputs exist */
40-
var missingFields []string
41-
42-
// TODO: Probably a better way to express these if blocks
43-
if ea.Template == "" {
44-
missingFields = append(missingFields, "Template")
45-
}
46-
if ea.CertificateAuthority == "" {
47-
missingFields = append(missingFields, "CertificateAuthority")
48-
}
49-
if ea.CertFormat == "" {
50-
missingFields = append(missingFields, "CertFormat")
51-
}
52-
//if ea.Password == "" {
53-
// missingFields = append(missingFields, "Password")
54-
//}
55-
56-
if len(missingFields) > 0 {
57-
return nil, errors.New("Required field(s) missing: " + strings.Join(missingFields, ", "))
58-
}
59-
6039
// Set Keyfactor-specific headers
6140
headers := &apiHeaders{
6241
Headers: []StringTuple{
@@ -116,9 +95,6 @@ func (c *Client) EnrollPFXV2(ea *EnrollPFXFctArgsV2) (*EnrollResponseV2, error)
11695
if ea.Template == "" && ea.EnrollmentPatternId == 0 {
11796
missingFields = append(missingFields, "Template or EnrollmentPatternId")
11897
}
119-
if ea.CertificateAuthority == "" {
120-
missingFields = append(missingFields, "CertificateAuthority")
121-
}
12298
if ea.CertFormat == "" {
12399
missingFields = append(missingFields, "CertFormat")
124100
}
@@ -344,13 +320,15 @@ func findLeafCert(certs []*x509.Certificate) *x509.Certificate {
344320
// enrollment. Required fields to complete a CSR enrollment are:
345321
// - CSR : string
346322
// - Template : string (or EnrollmentPatternId on Command v25+)
347-
// - CertificateAuthority : string
323+
// - CertificateAuthority : string (optional when using a template or enrollment pattern)
348324
func (c *Client) EnrollCSR(ea *EnrollCSRFctArgs) (*EnrollResponse, error) {
349325
log.Println("[INFO] Signing CSR with Keyfactor")
350326

351327
/* Ensure required inputs exist.
352-
On Command v25+ an EnrollmentPatternId can substitute for Template. */
353-
if (ea.Template == "" && ea.EnrollmentPatternId == 0) || (ea.CertificateAuthority == "") {
328+
On Command v25+ an EnrollmentPatternId can substitute for Template.
329+
CertificateAuthority is optional when a template or enrollment pattern is provided;
330+
it is only required when enrolling against a standalone CA. */
331+
if ea.Template == "" && ea.EnrollmentPatternId == 0 {
354332
return nil, errors.New("invalid or nonexistent values required for csr enrollment")
355333
}
356334

0 commit comments

Comments
 (0)