2015-06-19 16:48:18 +00:00
|
|
|
package pki
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/hashicorp/vault/logical"
|
|
|
|
"github.com/hashicorp/vault/logical/framework"
|
|
|
|
)
|
|
|
|
|
|
|
|
// CRLConfig holds basic CRL configuration information
|
|
|
|
type crlConfig struct {
|
|
|
|
Expiry string `json:"expiry" mapstructure:"expiry" structs:"expiry"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func pathConfigCRL(b *backend) *framework.Path {
|
|
|
|
return &framework.Path{
|
|
|
|
Pattern: "config/crl",
|
|
|
|
Fields: map[string]*framework.FieldSchema{
|
|
|
|
"expiry": &framework.FieldSchema{
|
|
|
|
Type: framework.TypeString,
|
|
|
|
Description: `The amount of time the generated CRL should be
|
|
|
|
valid; defaults to 72 hours`,
|
|
|
|
Default: "72h",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Callbacks: map[logical.Operation]framework.OperationFunc{
|
2016-08-19 20:48:32 +00:00
|
|
|
logical.ReadOperation: b.pathCRLRead,
|
2016-01-07 15:30:47 +00:00
|
|
|
logical.UpdateOperation: b.pathCRLWrite,
|
2015-06-19 16:48:18 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
HelpSynopsis: pathConfigCRLHelpSyn,
|
|
|
|
HelpDescription: pathConfigCRLHelpDesc,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *backend) CRL(s logical.Storage) (*crlConfig, error) {
|
|
|
|
entry, err := s.Get("config/crl")
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if entry == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
var result crlConfig
|
|
|
|
if err := entry.DecodeJSON(&result); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &result, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *backend) pathCRLRead(
|
|
|
|
req *logical.Request, data *framework.FieldData) (*logical.Response, error) {
|
|
|
|
config, err := b.CRL(req.Storage)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if config == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return &logical.Response{
|
2015-11-19 16:32:18 +00:00
|
|
|
Data: map[string]interface{}{
|
|
|
|
"expiry": config.Expiry,
|
|
|
|
},
|
2015-06-19 16:48:18 +00:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *backend) pathCRLWrite(
|
|
|
|
req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
|
|
|
|
expiry := d.Get("expiry").(string)
|
|
|
|
|
|
|
|
_, err := time.ParseDuration(expiry)
|
|
|
|
if err != nil {
|
|
|
|
return logical.ErrorResponse(fmt.Sprintf("Given expiry could not be decoded: %s", err)), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
config := &crlConfig{
|
|
|
|
Expiry: expiry,
|
|
|
|
}
|
|
|
|
|
|
|
|
entry, err := logical.StorageEntryJSON("config/crl", config)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
err = req.Storage.Put(entry)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
const pathConfigCRLHelpSyn = `
|
|
|
|
Configure the CRL expiration.
|
|
|
|
`
|
|
|
|
|
|
|
|
const pathConfigCRLHelpDesc = `
|
|
|
|
This endpoint allows configuration of the CRL lifetime.
|
|
|
|
`
|