Skip to content
This repository was archived by the owner on Jun 11, 2024. It is now read-only.
This repository was 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

Description

@mirosyn

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions