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

Add support for encrypted private keys #3650

Closed
barkbay opened this issue Aug 21, 2020 · 0 comments · Fixed by #3651
Closed

Add support for encrypted private keys #3650

barkbay opened this issue Aug 21, 2020 · 0 comments · Fixed by #3651
Assignees
Labels
>bug Something isn't working v1.3.0

Comments

@barkbay
Copy link
Contributor

barkbay commented Aug 21, 2020

ECK attempts to validate the certificates provided by the user, including the private key:

switch {
case block.Type == "PRIVATE KEY":
return parsePKCS8PrivateKey(block.Bytes)
case block.Type == "RSA PRIVATE KEY" && len(block.Headers) == 0:
return x509.ParsePKCS1PrivateKey(block.Bytes)
default:
return nil, errors.New("expected PEM block to contain an RSA private key")

But the private key of the certificate might be encrypted, in that case ECK should not attempt to parse it.

We should add a case statement to detect this situation and not attempt to decode the key. IsEncryptedPEMBlock might be a good candidate to detect such a situation, with something along those lines for instance:

	switch {
	case x509.IsEncryptedPEMBlock(block):
		// Private key is encrypted, do not attempt to parse it
		return nil, nil
	case block.Type == "PRIVATE KEY":
		return parsePKCS8PrivateKey(block.Bytes)
	case block.Type == "RSA PRIVATE KEY" && len(block.Headers) == 0:
		return x509.ParsePKCS1PrivateKey(block.Bytes)
	default:
		return nil, errors.New("expected PEM block to contain an RSA private key")
	}
@barkbay barkbay added >bug Something isn't working v1.3.0 labels Aug 21, 2020
@barkbay barkbay self-assigned this Aug 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug Something isn't working v1.3.0
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant