2015-05-15 16:13:05 +00:00
|
|
|
package pki
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2016-03-08 15:51:59 +00:00
|
|
|
"strings"
|
2015-05-15 16:13:05 +00:00
|
|
|
|
2015-06-19 16:48:18 +00:00
|
|
|
"github.com/hashicorp/vault/helper/certutil"
|
2015-05-15 16:13:05 +00:00
|
|
|
"github.com/hashicorp/vault/logical"
|
|
|
|
"github.com/hashicorp/vault/logical/framework"
|
|
|
|
)
|
|
|
|
|
|
|
|
func pathRevoke(b *backend) *framework.Path {
|
|
|
|
return &framework.Path{
|
|
|
|
Pattern: `revoke`,
|
|
|
|
Fields: map[string]*framework.FieldSchema{
|
2015-06-15 17:33:23 +00:00
|
|
|
"serial_number": &framework.FieldSchema{
|
2015-06-18 14:44:02 +00:00
|
|
|
Type: framework.TypeString,
|
|
|
|
Description: `Certificate serial number, in colon- or
|
|
|
|
hyphen-separated octal`,
|
2015-05-15 16:13:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Callbacks: map[logical.Operation]framework.OperationFunc{
|
2016-01-07 15:30:47 +00:00
|
|
|
logical.UpdateOperation: b.pathRevokeWrite,
|
2015-05-15 16:13:05 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
HelpSynopsis: pathRevokeHelpSyn,
|
|
|
|
HelpDescription: pathRevokeHelpDesc,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func pathRotateCRL(b *backend) *framework.Path {
|
|
|
|
return &framework.Path{
|
|
|
|
Pattern: `crl/rotate`,
|
|
|
|
|
|
|
|
Callbacks: map[logical.Operation]framework.OperationFunc{
|
|
|
|
logical.ReadOperation: b.pathRotateCRLRead,
|
|
|
|
},
|
|
|
|
|
|
|
|
HelpSynopsis: pathRotateCRLHelpSyn,
|
|
|
|
HelpDescription: pathRotateCRLHelpDesc,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *backend) pathRevokeWrite(req *logical.Request, data *framework.FieldData) (*logical.Response, error) {
|
2015-06-15 17:33:23 +00:00
|
|
|
serial := data.Get("serial_number").(string)
|
2015-05-15 16:13:05 +00:00
|
|
|
if len(serial) == 0 {
|
|
|
|
return logical.ErrorResponse("The serial number must be provided"), nil
|
|
|
|
}
|
|
|
|
|
2016-03-08 15:51:59 +00:00
|
|
|
// We store and identify by lowercase colon-separated hex, but other
|
|
|
|
// utilities use dashes and/or uppercase, so normalize
|
|
|
|
serial = strings.Replace(strings.ToLower(serial), "-", ":", -1)
|
|
|
|
|
2015-06-19 16:48:18 +00:00
|
|
|
b.revokeStorageLock.Lock()
|
|
|
|
defer b.revokeStorageLock.Unlock()
|
2015-06-12 02:28:13 +00:00
|
|
|
|
2016-05-09 23:53:28 +00:00
|
|
|
return revokeCert(b, req, serial, false)
|
2015-05-15 16:13:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (b *backend) pathRotateCRLRead(req *logical.Request, data *framework.FieldData) (*logical.Response, error) {
|
2016-02-24 21:19:01 +00:00
|
|
|
b.revokeStorageLock.RLock()
|
|
|
|
defer b.revokeStorageLock.RUnlock()
|
2015-06-19 16:48:18 +00:00
|
|
|
|
|
|
|
crlErr := buildCRL(b, req)
|
|
|
|
switch crlErr.(type) {
|
|
|
|
case certutil.UserError:
|
|
|
|
return logical.ErrorResponse(fmt.Sprintf("Error during CRL building: %s", crlErr)), nil
|
|
|
|
case certutil.InternalError:
|
|
|
|
return nil, fmt.Errorf("Error encountered during CRL building: %s", crlErr)
|
|
|
|
default:
|
|
|
|
return &logical.Response{
|
|
|
|
Data: map[string]interface{}{
|
|
|
|
"success": true,
|
|
|
|
},
|
|
|
|
}, nil
|
2015-05-15 16:13:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const pathRevokeHelpSyn = `
|
|
|
|
Revoke a certificate by serial number.
|
|
|
|
`
|
|
|
|
|
|
|
|
const pathRevokeHelpDesc = `
|
|
|
|
This allows certificates to be revoked using its serial number. A root token is required.
|
|
|
|
`
|
|
|
|
|
|
|
|
const pathRotateCRLHelpSyn = `
|
|
|
|
Force a rebuild of the CRL.
|
|
|
|
`
|
|
|
|
|
|
|
|
const pathRotateCRLHelpDesc = `
|
|
|
|
Force a rebuild of the CRL. This can be used to remove expired certificates from it if no certificates have been revoked. A root token is required.
|
|
|
|
`
|