Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Replace deprecated function EncryptPEMBlock #1312

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/ctlog/createctconfig/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ var (
// TODO: Support ed25519
keyType = flag.String("keytype", "ecdsa", "Which private key to generate [rsa,ecdsa]")
curveType = flag.String("curvetype", "p256", "Curve type to use [p256, p384,p521]")
keyPassword = flag.String("key-password", "test", "Password for encrypting the PEM key")
keyPassword = flag.String("key-password", "", "Password for encrypting the PEM key")

// Supported elliptic curve functions.
supportedCurves = map[string]elliptic.Curve{
Expand Down
2 changes: 1 addition & 1 deletion cmd/fulcio/createcerts/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func createAll() ([]byte, []byte, []byte, string, error) {
// Encrypt the pem
block, err = pemutil.EncryptPKCS8PrivateKey(rand.Reader, block.Bytes, []byte(pwd), x509.PEMCipherAES256)
if err != nil {
return nil, nil, nil, "", fmt.Errorf("EncryptPEMBlock failed: %w", err)
return nil, nil, nil, "", fmt.Errorf("EncryptPKCS8PrivateKey failed: %w", err)
}

privPEM := pem.EncodeToMemory(block)
Expand Down
3 changes: 2 additions & 1 deletion cmd/tsa/createcertchain/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"os"

"github.com/google/uuid"
"go.step.sm/crypto/pemutil"

"github.com/sigstore/scaffolding/pkg/secret"
"github.com/sigstore/sigstore/pkg/cryptoutils"
Expand Down Expand Up @@ -98,7 +99,7 @@ func main() {
}
// Encrypt the pem with a uuid
pwd := uuid.New().String()
encryptedBlock, err := x509.EncryptPEMBlock(rand.Reader, block.Type, block.Bytes, []byte(pwd), x509.PEMCipherAES256) // nolint
encryptedBlock, err := pemutil.EncryptPKCS8PrivateKey(rand.Reader, block.Bytes, []byte(pwd), x509.PEMCipherAES256)
if err != nil {
logging.FromContext(ctx).Fatalf("Failed to encrypt private key: %v", err)
}
Expand Down
10 changes: 6 additions & 4 deletions pkg/ctlog/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,12 +326,14 @@ func (c *Config) marshalSecrets() (map[string][]byte, error) {
Bytes: marshalledPrivKey,
}
// Encrypt the pem
encryptedBlock, err := x509.EncryptPEMBlock(rand.Reader, block.Type, block.Bytes, []byte(c.PrivKeyPassword), x509.PEMCipherAES256) // nolint
if err != nil {
return nil, fmt.Errorf("failed to encrypt private key: %w", err)
if c.PrivKeyPassword != "" {
block, err = x509.EncryptPEMBlock(rand.Reader, block.Type, block.Bytes, []byte(c.PrivKeyPassword), x509.PEMCipherAES256) // nolint
if err != nil {
return nil, fmt.Errorf("failed to encrypt private key: %w", err)
}
}

privPEM := pem.EncodeToMemory(encryptedBlock)
privPEM := pem.EncodeToMemory(block)
if privPEM == nil {
return nil, fmt.Errorf("failed to encode encrypted private key")
}
Expand Down
Loading