Skip to content

Commit

Permalink
Merge pull request #7 from chainsquad/master
Browse files Browse the repository at this point in the history
feat: Compatibility with vault-acme (fixes fabiolb#900)
  • Loading branch information
aleksraiden committed Feb 25, 2024
2 parents 2037e4a + 21fa2ae commit 0ee9be4
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion cert/vault_pki_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,12 @@ func (s *VaultPKISource) Issue(commonName string) (*tls.Certificate, error) {

b, _ := json.Marshal(resp.Data)
var data struct {
// Try load from regular vault-pki
PrivateKey string `json:"private_key"`
Certificate string `json:"certificate"`
CAChain []string `json:"ca_chain"`
// Try to load data from acme-vault
Certificate2 string `json:"cert"`
}
if err := json.Unmarshal(b, &data); err != nil {
return nil, fmt.Errorf("vault: issue: %s", err)
Expand All @@ -80,12 +83,16 @@ func (s *VaultPKISource) Issue(commonName string) (*tls.Certificate, error) {
if data.PrivateKey == "" {
return nil, fmt.Errorf("vault: issue: missing private key")
}
if data.Certificate == "" {

if data.Certificate == "" && data.Certificate2 == "" {
return nil, fmt.Errorf("vault: issue: missing certificate")
}

key := []byte(data.PrivateKey)
fullChain := []byte(data.Certificate)
if data.Certificate2 != "" {
fullChain = append(fullChain, data.Certificate2...)
}
for _, c := range data.CAChain {
fullChain = append(fullChain, '\n')
fullChain = append(fullChain, []byte(c)...)
Expand Down

0 comments on commit 0ee9be4

Please sign in to comment.