Skip to content

Commit b2b9088

Browse files
fixed issue when passing ca names that include spaces.
1 parent 9b9fd2c commit b2b9088

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

cert_util.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -408,19 +408,21 @@ func fetchCertIssuedByCA(ctx context.Context, req *logical.Request, b *keyfactor
408408
// This is only needed when running as a vault extension
409409
b.Logger().Debug("Closing idle connections")
410410
client.httpClient.CloseIdleConnections()
411+
caName = strings.Replace(caName, " ", "%20", -1)
412+
reqUrl := config.KeyfactorUrl + "/" + config.CommandAPIPath + "/Certificates?pq.queryString=CA%20-eq%20%22" + caName + "%20%22&ReturnLimit=1"
411413

412-
url := config.KeyfactorUrl + "/" + config.CommandAPIPath + "/Certificates?pq.queryString=CA%20-eq%20%22" + caName + "%22%20&ReturnLimit=1"
413-
b.Logger().Debug("url: " + url)
414+
b.Logger().Debug("url: " + reqUrl)
414415

415-
httpReq, err := http.NewRequest("GET", url, nil)
416+
httpReq, err := http.NewRequest("GET", reqUrl, nil)
416417
if err != nil {
417418
b.Logger().Info("Error forming request: {{err}}", err)
418419
}
420+
419421
httpReq.Header.Add("x-keyfactor-requested-with", "APIClient")
420422
httpReq.Header.Add("content-type", "application/json")
421423

422424
// Send request and check status
423-
b.Logger().Debug("About to connect to " + config.KeyfactorUrl + "for cert retrieval")
425+
b.Logger().Debug("About to connect to " + reqUrl + "for cert retrieval")
424426
res, err := client.httpClient.Do(httpReq)
425427
if err != nil {
426428
b.Logger().Info("failed getting cert: {{err}}", err)
@@ -472,12 +474,12 @@ func fetchChainAndCAForCert(ctx context.Context, req *logical.Request, b *keyfac
472474
client.httpClient.CloseIdleConnections()
473475

474476
// Build request
475-
url := config.KeyfactorUrl + "/" + config.CommandAPIPath + "/Certificates/Download"
476-
b.Logger().Debug("url: " + url)
477+
reqUrl := config.KeyfactorUrl + "/" + config.CommandAPIPath + "/Certificates/Download"
478+
b.Logger().Debug("url: " + reqUrl)
477479
bodyContent := fmt.Sprintf(`{"CertID": %d, "IncludeChain": true, "ChainOrder": "endentityfirst" }`, kfCertId)
478480
payload := strings.NewReader(bodyContent)
479481
b.Logger().Debug("body: " + bodyContent)
480-
httpReq, err := http.NewRequest("POST", url, payload)
482+
httpReq, err := http.NewRequest("POST", reqUrl, payload)
481483
if err != nil {
482484
b.Logger().Info("Error forming request: %s", err)
483485
}
@@ -489,7 +491,7 @@ func fetchChainAndCAForCert(ctx context.Context, req *logical.Request, b *keyfac
489491
b.Logger().Debug("About to connect to " + config.KeyfactorUrl + "for cert retrieval")
490492
res, err := client.httpClient.Do(httpReq)
491493
if err != nil {
492-
b.Logger().Info("failed getting cert: %s", err)
494+
b.Logger().Info(fmt.Sprintf("failed getting cert: %s", err))
493495
return nil, "", err
494496
}
495497
if res.StatusCode != 200 {

0 commit comments

Comments
 (0)