Skip to content

Commit 63d688e

Browse files
joevanwanzeeleKFspbsolubleKeyfactor
authored
Fixed date format in revocation request (#33)
Co-authored-by: sbailey <1661003+spbsoluble@users.noreply.github.com> Co-authored-by: Keyfactor <keyfactor@keyfactor.github.io>
1 parent 3c54777 commit 63d688e

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

path_certs.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ func (b *keyfactorBackend) pathFetchCert(ctx context.Context, req *logical.Reque
136136
// this is basically handled by setting contentType or not.
137137
// Errors don't cause an immediate exit, because the raw
138138
// paths still need to return raw output.
139+
139140
b.Logger().Debug("fetching cert, path = " + req.Path)
140141

141142
serial = data.Get("serial").(string)
@@ -485,8 +486,8 @@ func revokeCert(ctx context.Context, b *keyfactorBackend, req *logical.Request,
485486
"Comment": "%s",
486487
"EffectiveDate": "%s"},
487488
"CollectionId": 0
488-
}`, keyfactorId, "via HashiCorp Vault", time.Now().UTC().String())
489-
//b.Logger().Debug("Sending revocation request. payload = " + payload)
489+
}`, keyfactorId, "via HashiCorp Vault", time.Now().Format(time.RFC3339))
490+
b.Logger().Debug("Sending revocation request. payload = " + payload)
490491
httpReq, _ := http.NewRequest("POST", url, strings.NewReader(payload))
491492

492493
httpReq.Header.Add("x-keyfactor-requested-with", "APIClient")
@@ -498,10 +499,13 @@ func revokeCert(ctx context.Context, b *keyfactorBackend, req *logical.Request,
498499
b.Logger().Error("Revoke failed: {{err}}", err)
499500
return nil, err
500501
}
501-
if res.StatusCode != 204 {
502-
r, _ := io.ReadAll(res.Body)
502+
r, _ := io.ReadAll(res.Body)
503+
504+
b.Logger().Debug("response received. Status code " + fmt.Sprint(res.StatusCode) + " response body: \n " + string(r[:]))
505+
if res.StatusCode != 204 && res.StatusCode != 200 {
506+
// r, _ := io.ReadAll(res.Body)
503507
b.Logger().Info("revocation failed: server returned" + fmt.Sprint(res.StatusCode))
504-
b.Logger().Info("error response = " + fmt.Sprint(r))
508+
b.Logger().Info("error response = " + string(r[:]))
505509
return nil, fmt.Errorf("revocation failed: server returned %s\n ", res.Status)
506510
}
507511

@@ -548,8 +552,8 @@ func revokeCert(ctx context.Context, b *keyfactorBackend, req *logical.Request,
548552
}
549553
return logical.ErrorResponse(fmt.Sprintf("certificate with serial %s not found", serial)), nil
550554
}
551-
b.Logger().Info("certEntry key = " + certEntry.Key)
552-
b.Logger().Info("certEntry value = " + string(certEntry.Value))
555+
b.Logger().Debug("certEntry key = " + certEntry.Key)
556+
b.Logger().Debug("certEntry value = " + string(certEntry.Value))
553557

554558
currTime := time.Now()
555559
revInfo.CertificateBytes = certEntry.Value
@@ -565,7 +569,6 @@ func revokeCert(ctx context.Context, b *keyfactorBackend, req *logical.Request,
565569
if err != nil {
566570
return nil, fmt.Errorf("error saving revoked certificate to new location")
567571
}
568-
569572
}
570573

571574
resp := &logical.Response{
@@ -574,7 +577,7 @@ func revokeCert(ctx context.Context, b *keyfactorBackend, req *logical.Request,
574577
},
575578
}
576579
if !revInfo.RevocationTimeUTC.IsZero() {
577-
resp.Data["revocation_time_rfc3339"] = revInfo.RevocationTimeUTC.Format(time.RFC3339Nano)
580+
resp.Data["revocation_time_rfc3339"] = revInfo.RevocationTimeUTC.Format(time.RFC3339)
578581
}
579582
return resp, nil
580583
}

0 commit comments

Comments
 (0)