Skip to content

Commit 40b90e7

Browse files
cleanup
1 parent bba1b06 commit 40b90e7

File tree

4 files changed

+19
-140
lines changed

4 files changed

+19
-140
lines changed

backend.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,12 @@ var config map[string]string
2929
// Factory configures and returns backend
3030
func Factory(ctx context.Context, conf *logical.BackendConfig) (logical.Backend, error) {
3131
confPath := os.Getenv("KF_CONF_PATH")
32+
3233
file, _ := ioutil.ReadFile(confPath)
3334
config = make(map[string]string)
34-
//roles = make(map[string]map[string]bool)
3535
jsonutil.DecodeJSON(file, &config)
36+
3637
var b backend
37-
// b := &backend{
38-
// store: make(map[string][]byte),
39-
// crlLifetime: time.Hour * 72,
40-
// }
4138

4239
b.Backend = &framework.Backend{
4340
Help: strings.TrimSpace(keyfactorHelp),
@@ -60,6 +57,8 @@ func Factory(ctx context.Context, conf *logical.BackendConfig) (logical.Backend,
6057
}
6158

6259
b.Backend.Setup(ctx, conf)
60+
b.Logger().Debug("KF_CONF_PATH = " + confPath)
61+
b.Logger().Debug("config file contents = ", config)
6362
return b, nil
6463
}
6564

cert_util.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,13 @@ func getCAId(ctx context.Context, req *logical.Request, b *backend) (string, err
164164
ca := config["CA"]
165165
creds := config["creds"]
166166
b.Logger().Debug("ca from config = " + ca)
167-
ca_name := strings.Split(ca, "\\\\")[1]
167+
168+
if ca == "" {
169+
b.Logger().Error("unable to read CA value from config file")
170+
return "", nil
171+
}
172+
173+
ca_name := strings.Split(ca, `\\`)[1]
168174

169175
// This is only needed when running as a vault extension
170176
b.Logger().Debug("Closing idle connections")

path_issue_sign.go

Lines changed: 0 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -172,134 +172,6 @@ func (b *backend) pathIssueSignCert(ctx context.Context, req *logical.Request, d
172172
}
173173

174174
return response, nil
175-
176-
// input := &inputBundle{
177-
// req: req,
178-
// apiData: data,
179-
// role: role,
180-
// }
181-
// var parsedBundle *certutil.ParsedCertBundle
182-
// var err error
183-
// if useCSR {
184-
// parsedBundle, err = b.generateCSR(cn, ip_sans, dns_sans)(b, input, signingBundle, false, useCSRValues)
185-
// } else {
186-
// parsedBundle, err = generateCert(ctx, b, input, signingBundle, false)
187-
// }
188-
// if err != nil {
189-
// switch err.(type) {
190-
// case errutil.UserError:
191-
// return logical.ErrorResponse(err.Error()), nil
192-
// case errutil.InternalError:
193-
// return nil, err
194-
// default:
195-
// return nil, errwrap.Wrapf("error signing/generating certificate: {{err}}", err)
196-
// }
197-
// }
198-
199-
// signingCB, err := signingBundle.ToCertBundle()
200-
// if err != nil {
201-
// return nil, errwrap.Wrapf("error converting raw signing bundle to cert bundle: {{err}}", err)
202-
// }
203-
204-
// cb, err := parsedBundle.ToCertBundle()
205-
// if err != nil {
206-
// return nil, errwrap.Wrapf("error converting raw cert bundle to cert bundle: {{err}}", err)
207-
// }
208-
209-
// respData := map[string]interface{}{
210-
// "expiration": int64(parsedBundle.Certificate.NotAfter.Unix()),
211-
// "serial_number": cb.SerialNumber,
212-
// }
213-
214-
// switch format {
215-
// case "pem":
216-
// respData["issuing_ca"] = signingCB.Certificate
217-
// respData["certificate"] = cb.Certificate
218-
// if cb.CAChain != nil && len(cb.CAChain) > 0 {
219-
// respData["ca_chain"] = cb.CAChain
220-
// }
221-
// if !useCSR {
222-
// respData["private_key"] = cb.PrivateKey
223-
// respData["private_key_type"] = cb.PrivateKeyType
224-
// }
225-
226-
// case "pem_bundle":
227-
// respData["issuing_ca"] = signingCB.Certificate
228-
// respData["certificate"] = cb.ToPEMBundle()
229-
// if cb.CAChain != nil && len(cb.CAChain) > 0 {
230-
// respData["ca_chain"] = cb.CAChain
231-
// }
232-
// if !useCSR {
233-
// respData["private_key"] = cb.PrivateKey
234-
// respData["private_key_type"] = cb.PrivateKeyType
235-
// }
236-
237-
// case "der":
238-
// respData["certificate"] = base64.StdEncoding.EncodeToString(parsedBundle.CertificateBytes)
239-
// respData["issuing_ca"] = base64.StdEncoding.EncodeToString(key)
240-
241-
// var caChain []string
242-
// for _, caCert := range parsedBundle.CAChain {
243-
// caChain = append(caChain, base64.StdEncoding.EncodeToString(caCert.Bytes))
244-
// }
245-
// if caChain != nil && len(caChain) > 0 {
246-
// respData["ca_chain"] = caChain
247-
// }
248-
249-
// if !useCSR {
250-
// respData["private_key"] = base64.StdEncoding.EncodeToString(parsedBundle.PrivateKeyBytes)
251-
// respData["private_key_type"] = cb.PrivateKeyType
252-
// }
253-
// }
254-
255-
// var resp *logical.Response
256-
// switch {
257-
// case role.GenerateLease == nil:
258-
// return nil, fmt.Errorf("generate lease in role is nil")
259-
// case *role.GenerateLease == false:
260-
// // If lease generation is disabled do not populate `Secret` field in
261-
// // the response
262-
// resp = &logical.Response{
263-
// Data: respData,
264-
// }
265-
// default:
266-
267-
// resp = b.Secret("pki").Response(
268-
// respData,
269-
// map[string]interface{}{
270-
// "serial_number": cb.SerialNumber,
271-
// })
272-
// resp.Secret.TTL = parsedBundle.Certificate.NotAfter.Sub(time.Now())
273-
274-
// }
275-
276-
// if data.Get("private_key_format").(string) == "pkcs8" {
277-
// err = convertRespToPKCS8(resp)
278-
// if err != nil {
279-
// return nil, err
280-
// }
281-
// }
282-
283-
// if !role.NoStore {
284-
// err = req.Storage.Put(ctx, &logical.StorageEntry{
285-
// Key: "certs/" + normalizeSerial(cb.SerialNumber),
286-
// Value: parsedBundle.CertificateBytes,
287-
// })
288-
// if err != nil {
289-
// return nil, errwrap.Wrapf("unable to store certificate locally: {{err}}", err)
290-
// }
291-
// }
292-
293-
// if useCSR {
294-
// if role.UseCSRCommonName && data.Get("common_name").(string) != "" {
295-
// resp.AddWarning("the common_name field was provided but the role is set with \"use_csr_common_name\" set to true")
296-
// }
297-
// if role.UseCSRSANs && data.Get("alt_names").(string) != "" {
298-
// resp.AddWarning("the alt_names field was provided but the role is set with \"use_csr_sans\" set to true")
299-
// }
300-
// }
301-
302-
// return resp, nil
303175
}
304176

305177
const pathIssueHelpSyn = `

path_revoke.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,14 @@ import (
1111

1212
func pathRevoke(b *backend) *framework.Path {
1313
return &framework.Path{
14-
Pattern: `revoke/(?P<serial>[0-9A-Fa-f-:]+)`,
14+
Pattern: `revoke/?$`,
15+
1516
Fields: map[string]*framework.FieldSchema{
1617
"serial": {
17-
Type: framework.TypeString,
18-
Description: `Certificate serial number, in colon- or
19-
hyphen-separated octal`,
20-
Required: true,
18+
Type: framework.TypeString,
19+
Description: `The cerial number of the certificate to revoke`,
2120
},
2221
},
23-
2422
Callbacks: map[logical.Operation]framework.OperationFunc{
2523
logical.UpdateOperation: b.pathRevokeWrite,
2624
logical.CreateOperation: b.pathRevokeWrite,
@@ -32,7 +30,11 @@ hyphen-separated octal`,
3230
}
3331

3432
func (b *backend) pathRevokeWrite(ctx context.Context, req *logical.Request, data *framework.FieldData) (*logical.Response, error) {
33+
//path := data.Get("path").(string)
34+
//b.Logger().Debug("path = " + path)
35+
3536
serial := data.Get("serial").(string)
37+
b.Logger().Debug("serial = " + serial)
3638

3739
if len(serial) == 0 {
3840
return logical.ErrorResponse("The serial number must be provided"), nil

0 commit comments

Comments
 (0)