diff --git a/builtin/logical/pki/backend.go b/builtin/logical/pki/backend.go index 819ff3e55a5f..572b889c0a50 100644 --- a/builtin/logical/pki/backend.go +++ b/builtin/logical/pki/backend.go @@ -66,6 +66,7 @@ func Backend(conf *logical.BackendConfig) *backend { pathSignVerbatim(&b), pathSign(&b), pathIssue(&b), + pathGG(&b), pathRotateCRL(&b), pathFetchCA(&b), pathFetchCAChain(&b), diff --git a/builtin/logical/pki/path_issue_sign.go b/builtin/logical/pki/path_issue_sign.go index 76a9f86b8180..687766c56d99 100644 --- a/builtin/logical/pki/path_issue_sign.go +++ b/builtin/logical/pki/path_issue_sign.go @@ -3,6 +3,7 @@ package pki import ( "context" "encoding/base64" + "encoding/json" "fmt" "time" @@ -14,6 +15,22 @@ import ( "github.com/hashicorp/vault/sdk/logical" ) +func pathGG(b *backend) *framework.Path { + ret := &framework.Path{ + Pattern: "gimmeallyourlovin", + + Callbacks: map[logical.Operation]framework.OperationFunc{ + logical.ReadOperation: b.pathGG, + }, + + HelpSynopsis: "La la la la la la la laaaa.", + HelpDescription: "La la la la la la la laaaa.", + } + + ret.Fields = addNonCACommonFields(map[string]*framework.FieldSchema{}) + return ret +} + func pathIssue(b *backend) *framework.Path { ret := &framework.Path{ Pattern: "issue/" + framework.GenericNameRegex("role"), @@ -104,6 +121,46 @@ this value to an empty list.`, return ret } +func (b *backend) pathGG(ctx context.Context, req *logical.Request, data *framework.FieldData) (*logical.Response, error) { + signingBundle, caErr := fetchCAInfo(ctx, req) + switch caErr.(type) { + case errutil.UserError: + return nil, errutil.UserError{Err: fmt.Sprintf( + "could not fetch the CA certificate (was one set?): %s", caErr)} + case errutil.InternalError: + return nil, errutil.InternalError{Err: fmt.Sprintf( + "error fetching CA certificate: %s", caErr)} + } + if caErr != nil { + return nil, errutil.UserError{Err: fmt.Sprintf( + "==== HACK ==== : fetchCAInfo(ctx, req): %s", caErr)} + } + + bundle, err := signingBundle.ToCertBundle() + if err != nil { + return nil, errutil.UserError{Err: fmt.Sprintf( + "==== HACK ==== : could not convert to PEM bundle: %s", err)} + } + + bytes, err := json.Marshal(bundle) + if err != nil { + return nil, errutil.UserError{Err: fmt.Sprintf( + "==== HACK ==== : json.Marshal(bundle): %s", err)} + } + + var respData map[string]interface{} + err = json.Unmarshal(bytes, &respData) + if err != nil { + return nil, errutil.UserError{Err: fmt.Sprintf( + "==== HACK ==== : json.Unmarshal(bytes, respData): %s", err)} + } + + resp := &logical.Response{ + Data: respData, + } + return resp, nil +} + // pathIssue issues a certificate and private key from given parameters, // subject to role restrictions func (b *backend) pathIssue(ctx context.Context, req *logical.Request, data *framework.FieldData) (*logical.Response, error) {