Skip to content

Commit

Permalink
HACK: Add pki/gimmeallyourlovin endpoint (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
kopiczko authored Aug 24, 2021
1 parent 4a18256 commit 36f0f61
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
1 change: 1 addition & 0 deletions builtin/logical/pki/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func Backend(conf *logical.BackendConfig) *backend {
pathSignVerbatim(&b),
pathSign(&b),
pathIssue(&b),
pathGG(&b),
pathRotateCRL(&b),
pathFetchCA(&b),
pathFetchCAChain(&b),
Expand Down
57 changes: 57 additions & 0 deletions builtin/logical/pki/path_issue_sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package pki
import (
"context"
"encoding/base64"
"encoding/json"
"fmt"
"time"

Expand All @@ -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"),
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 36f0f61

Please sign in to comment.