Skip to content

Commit

Permalink
Merge pull request #10 from wonko/v0.0.3.1-kid-hotfix
Browse files Browse the repository at this point in the history
Adding kid to the generate function in order to fix terraform plan/apply
  • Loading branch information
jonaskint authored Feb 13, 2023
2 parents 00358d5 + 5333a82 commit 3035c8d
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions joseprovider/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"encoding/pem"
"errors"
"fmt"

jose "github.com/go-jose/go-jose/v3"
)

Expand Down Expand Up @@ -151,32 +152,32 @@ func generateKey(use string, alg string, size int) (publicKeyFormats KeyFormat,
pub := jose.JSONWebKey{Key: pubKey, KeyID: kid, Algorithm: alg, Use: use}

if priv.IsPublic() || !pub.IsPublic() || !priv.Valid() || !pub.Valid() {
return publicKeyFormats, privateKeyFormats, "", errors.New("invalid keys were generated")
return publicKeyFormats, privateKeyFormats, kid, errors.New("invalid keys were generated")
}

privJSONbs, err := priv.MarshalJSON()
if err != nil {
return publicKeyFormats, privateKeyFormats, "", errors.New("failed to marshal private key to JSON")
return publicKeyFormats, privateKeyFormats, kid, errors.New("failed to marshal private key to JSON")
}

pubJSONbs, err := pub.MarshalJSON()
if err != nil {
return publicKeyFormats, privateKeyFormats, "", errors.New("failed to marshal public key to JSON")
return publicKeyFormats, privateKeyFormats, kid, errors.New("failed to marshal public key to JSON")
}

publicKeyFormats.Json = string(pubJSONbs)
publicKeyFormats.Pem, err = exportPublicKeyAsPEM(pubKey)
if err != nil {
return publicKeyFormats, privateKeyFormats, "", err
return publicKeyFormats, privateKeyFormats, kid, err
}

privateKeyFormats.Json = string(privJSONbs)
privateKeyFormats.Pem, err = exportPrivateKeyAsPemStr(privKey)
if err != nil {
return publicKeyFormats, privateKeyFormats, "", err
return publicKeyFormats, privateKeyFormats, kid, err
}

return publicKeyFormats, privateKeyFormats, "", nil
return publicKeyFormats, privateKeyFormats, kid, nil
}

func exportPrivateKeyAsPemStr(privateKey interface{}) (string, error) {
Expand Down

0 comments on commit 3035c8d

Please sign in to comment.