2015-05-15 16:13:05 +00:00
|
|
|
package pki
|
|
|
|
|
|
|
|
import (
|
2018-01-08 18:31:38 +00:00
|
|
|
"context"
|
2015-05-15 16:13:05 +00:00
|
|
|
"fmt"
|
|
|
|
|
2019-04-12 21:54:35 +00:00
|
|
|
"github.com/hashicorp/vault/sdk/framework"
|
2019-04-13 07:44:06 +00:00
|
|
|
"github.com/hashicorp/vault/sdk/logical"
|
2015-05-15 16:13:05 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// SecretCertsType is the name used to identify this type
|
|
|
|
const SecretCertsType = "pki"
|
|
|
|
|
|
|
|
func secretCerts(b *backend) *framework.Secret {
|
|
|
|
return &framework.Secret{
|
|
|
|
Type: SecretCertsType,
|
|
|
|
Fields: map[string]*framework.FieldSchema{
|
|
|
|
"certificate": &framework.FieldSchema{
|
2015-06-18 14:44:02 +00:00
|
|
|
Type: framework.TypeString,
|
|
|
|
Description: `The PEM-encoded concatenated certificate and
|
|
|
|
issuing certificate authority`,
|
2015-05-15 16:13:05 +00:00
|
|
|
},
|
|
|
|
"private_key": &framework.FieldSchema{
|
|
|
|
Type: framework.TypeString,
|
|
|
|
Description: "The PEM-encoded private key for the certificate",
|
|
|
|
},
|
|
|
|
"serial": &framework.FieldSchema{
|
2015-06-18 14:44:02 +00:00
|
|
|
Type: framework.TypeString,
|
|
|
|
Description: `The serial number of the certificate, for handy
|
|
|
|
reference`,
|
2015-05-15 16:13:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Revoke: b.secretCredsRevoke,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-08 18:31:38 +00:00
|
|
|
func (b *backend) secretCredsRevoke(ctx context.Context, req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
|
2015-05-15 16:13:05 +00:00
|
|
|
if req.Secret == nil {
|
2016-05-26 14:04:11 +00:00
|
|
|
return nil, fmt.Errorf("secret is nil in request")
|
2015-05-15 16:13:05 +00:00
|
|
|
}
|
|
|
|
|
2015-06-15 17:33:23 +00:00
|
|
|
serialInt, ok := req.Secret.InternalData["serial_number"]
|
2015-05-15 16:13:05 +00:00
|
|
|
if !ok {
|
2016-05-26 14:04:11 +00:00
|
|
|
return nil, fmt.Errorf("could not find serial in internal secret data")
|
2015-05-15 16:13:05 +00:00
|
|
|
}
|
|
|
|
|
2015-06-19 16:48:18 +00:00
|
|
|
b.revokeStorageLock.Lock()
|
|
|
|
defer b.revokeStorageLock.Unlock()
|
2015-06-12 02:28:13 +00:00
|
|
|
|
2018-01-19 06:44:44 +00:00
|
|
|
return revokeCert(ctx, b, req, serialInt.(string), true)
|
2015-05-15 16:13:05 +00:00
|
|
|
}
|