Skip to content

Add Support for Encoding in PBES2#47

Closed
Tookmund wants to merge 37 commits intoSSLMate:masterfrom
Tookmund:pbes2
Closed

Add Support for Encoding in PBES2#47
Tookmund wants to merge 37 commits intoSSLMate:masterfrom
Tookmund:pbes2

Conversation

@Tookmund
Copy link
Copy Markdown

With the release of OpenSSL v3, openssl now defaults to "AES password based encryption (PBES2 with PBKDF2 and AES-256-CBC) for private keys and certificates, the PBKDF2 and MAC key derivation iteration count of PKCS12_DEFAULT_ITER (currently 2048), and MAC algorithm HMAC with SHA2-256."
https://www.openssl.org/docs/man3.0/man3/PKCS12_create.html
All other formats are now considered legacy.

This PR builds on the configuration work done in #39 , simply adding support for PBES2 as an algorithm choice.
This doesn't support encoding in every algorithm that could be used for PBES2, but only the exact format used by OpenSSL.
Other formats are left as a future enhancement, and will likely require a rethink of the interface used to select algorithms in #39.

Additionally this solves #44 by bumping the x/crypto dependency to 0.9.0. This appears to work without any changes required.

pschou and others added 30 commits September 14, 2022 08:30
Copy link
Copy Markdown

@maraino maraino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't looked at the full PR, only at the KDF parameters. I am not a go-pkcs12 mainteiner.

safebags.go Outdated
kdf.Algorithm = oidPBKDF2
kdfParams.Salt.Tag = asn1.TagOctetString
kdfParams.Salt.Bytes = salt
kdfParams.Iterations = 2048
Copy link
Copy Markdown

@maraino maraino May 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2048 iterations are very low for current standards.

Consider the following facts:

  • In 2017, Nist minimum recommendation was 10,000
  • In December 2022, the OWASP Foundation increased its previous recommendation of 310,000 to 600,000 or more.
  • 1password uses 650,000.
  • LastPass now recommends at least 600,000 - it was very criticized because old users only used 5,000 iterations by default.

My recommendation would be to use 600k by default and add some way to change it.

safebags.go Outdated
if err != nil {
return nil, errors.New("pkcs12: error encoding PBES2 params: " + err.Error())
}
} else if paramBytes, err = asn1.Marshal(pbeParams{Salt: randomSalt, Iterations: 2048}); err != nil {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PBES1 will likely use only SHA-1. The OWASP recommendation for PBKDF2-HMAC-SHA1 is 1,300,000 iterations. And PBKDF2 supersedes PBKDF1 which is the one used by PBES1.

@Tookmund
Copy link
Copy Markdown
Author

Tookmund commented Jul 4, 2023

I've defaulted to 2048 in most places, since that's still what OpenSSL uses, but I've increased SafeEncode to the standard 600,000 iterations.

AGWA added a commit that referenced this pull request Jul 14, 2023
Instead of calling pkcs12.Encode, call the Encode method of an Encoder.
(Likewise for EncodeTrustStore and EncodeTrustStoreEntries.)

The following Encoders are available:

* Legacy, for the current behavior.

* LegacyDESCerts, to use 3DES for encrypting certificates (Closes #36, Closes #35).

* Passwordless, to create password-less trust stores like Java 18 (Closes #10).

* Openssl3, to match OpenSSL's modern algorithm choices (Closes #47).

* Modern, to always use the most modern choices.
@Tookmund
Copy link
Copy Markdown
Author

Closed in favor of #48

@Tookmund Tookmund closed this Jul 15, 2023
@AGWA AGWA added the feature label Jul 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants