Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

savePrivateKeyAsPemFile, passwordForPrivateKey cannot be null even though java docs say it can be #304

Open
mirosyn opened this issue Aug 31, 2020 · 0 comments

Comments

@mirosyn
Copy link

mirosyn commented Aug 31, 2020

Describe the bug
Method's RootCertificateGenerator.savePrivateKeyAsPemFile(File file, String passwordForPrivateKey) java docs says that passwordForPrivateKey can be null, but if password is set to null method BouncyCastleSecurityProviderTool .encodePrivateKeyAsPem will throw IllegalArgumentException("You must specify a password when serializing a private key");

Method's java docs:

/**
     * Saves the private key as PEM-encoded data to a file, using the specified password to encrypt the private key and
     * the {@link #DEFAULT_PEM_ENCRYPTION_ALGORITHM}. If the password is null, the private key will be stored unencrypted.
     * In general, private keys should not be stored unencrypted.
     *
     * @param file                  file to save the private key to
     * @param passwordForPrivateKey password to protect the private key
     */
    public void savePrivateKeyAsPemFile(File file, String passwordForPrivateKey) { ... }

To Reproduce
Steps to reproduce the behavior:
To reproduce this you can create a unit test similar to this:

    RootCertificateGenerator rootCertificateGenerator = RootCertificateGenerator.builder().build();

    rootCertificateGenerator.saveRootCertificateAsPemFile(new File(TEMP_FILE_PATH_CERT));
    rootCertificateGenerator.savePrivateKeyAsPemFile(new File(TEMP_FILE_PATH_PRIVATE), null);

Expected behavior
Saving the private key without the password should be possible, i.e passwordForPrivateKey should be allowed to be null.

Please complete the following information:

  • OS: N/A
  • Browser N/A
  • Version: 'com.browserup', name: 'browserup-proxy-mitm', version: '2.1.1'

Additional context
Add any other context about the problem here.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant