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

FakeKS restored to self-signed. Add FakeChainedKS. #125

Merged

Conversation

ignasi35
Copy link
Contributor

@ignasi35 ignasi35 commented Oct 5, 2018

Using a keyStore with multiple privateKeyPair entries to create an SSLContext with a default KeyManagerFactory has the consequence that you can't set what key should be used. There are mechanisms to setup SNI or to allow connection-specific key selection. Until those are necessary and implemented, using a single-key KeyStore is the simplest option.

Note: we could create a collection of tools to create several KeyStore's (one for the CA, another for the server, a third one for client-side SSL auth) but that's not the purpose of this PR.

Fixes #115

Copy link
Member

@dwijnand dwijnand left a comment

Choose a reason for hiding this comment

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

LGTM. One question.

val SignatureAlgorithmName = "SHA256withRSA"
val KeyPairAlgorithmName = "RSA"
val KeyPairKeyLength = 2048 // 2048 is the NIST acceptable key length until 2030
val KeystoreType = "PKCS12"
Copy link
Member

Choose a reason for hiding this comment

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

Is this change intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. kyetool keeps alerting jks is proprietary and recommending a migration:

$ keytool -keystore generated.keystore -list
Enter keystore password:

*****************  WARNING WARNING WARNING  *****************
* The integrity of the information stored in your keystore  *
* has NOT been verified!  In order to verify its integrity, *
* you must provide your keystore password.                  *
*****************  WARNING WARNING WARNING  *****************

Keystore type: jks
Keystore provider: SUN

Your keystore contains 4 entries

playgeneratedtrusted, Sep 20, 2018, trustedCertEntry,
Certificate fingerprint (SHA1): F3:7E:F7:12:BC:73:EB:A7:CF:AF:C7:49:CD:3A:B1:C1:F0:1B:75:98
playgenerated, Sep 20, 2018, PrivateKeyEntry,
Certificate fingerprint (SHA1): F3:7E:F7:12:BC:73:EB:A7:CF:AF:C7:49:CD:3A:B1:C1:F0:1B:75:98
playgeneratedcatrusted, Sep 20, 2018, trustedCertEntry,
Certificate fingerprint (SHA1): 4C:F3:C9:5E:D8:F1:83:46:BD:89:7C:1F:7D:BD:24:EB:94:9C:E8:8E
playgeneratedca, Sep 20, 2018, PrivateKeyEntry,
Certificate fingerprint (SHA1): 4C:F3:C9:5E:D8:F1:83:46:BD:89:7C:1F:7D:BD:24:EB:94:9C:E8:8E

Warning:
The JKS keystore uses a proprietary format. It is recommended to migrate to PKCS12 which is an industry standard format using "keytool -importkeystore -srckeystore generated.keystore -destkeystore generated.keystore -deststoretype pkcs12".

vs

$ keytool -keystore selfsigned.keystore -list
Enter keystore password:

*****************  WARNING WARNING WARNING  *****************
* The integrity of the information stored in your keystore  *
* has NOT been verified!  In order to verify its integrity, *
* you must provide your keystore password.                  *
*****************  WARNING WARNING WARNING  *****************

Keystore type: jks
Keystore provider: SUN

Your keystore contains 1 entry

sslconfig-selfsigned, Oct 5, 2018, PrivateKeyEntry,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, the trust entry on the selfsigned.keystore isn't listed. Is it really added?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See #115

Copy link
Contributor Author

@ignasi35 ignasi35 left a comment

Choose a reason for hiding this comment

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

This is an early commit of changes in "FakeXyz tools for dev mode and testkit".

There's still code duplication and API improvements we could make.


val DistinguishedName = "CN=localhost, OU=Unit Testing, O=Mavericks, L=SSL Config Base 1, ST=Cyberspace, C=CY"
val keyPassword: Array[Char] = EMPTY_PASSWORD
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The above two objects keep the certificate-specific constants. Below are the Keystore-specific constants. Future refactors could extract this data structures into case classes, etc... and extract duplicate code from FakeKeyStore+FakeChainedKeyStore.

val KeystoreType = "PKCS12"
val SignatureAlgorithmOID: ObjectIdentifier = AlgorithmId.sha256WithRSAEncryption_oid
val keystorePassword: Array[Char] = EMPTY_PASSWORD
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This set of constants is duplicate in FakeKeyStore.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we make them reference each other? Or even remove the duplication at all?

certInfo.set(CertificateAlgorithmId.NAME + "." + CertificateAlgorithmId.ALGORITHM, actualAlgorithm)
val newCert = new X509CertImpl(certInfo)
newCert.sign(keyPair.getPrivate, KeystoreSettings.SignatureAlgorithmName)
newCert
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The two methods above have a lot of duplication amongst themselves and with some other code in FakeKeyStore

val KeyPairKeyLength = 2048 // 2048 is the NIST acceptable key length until 2030
val KeystoreType = "PKCS12"
val SignatureAlgorithmOID: ObjectIdentifier = AlgorithmId.sha256WithRSAEncryption_oid
val keystorePassword: Array[Char] = EMPTY_PASSWORD
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Some cleanup.

val SignatureAlgorithmName = "SHA256withRSA"
val KeyPairAlgorithmName = "RSA"
val KeyPairKeyLength = 2048 // 2048 is the NIST acceptable key length until 2030
val KeystoreType = "PKCS12"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

KeyStore's no longer default to JKS. Instead the default is PKCS12

@ignasi35
Copy link
Contributor Author

ignasi35 commented Oct 5, 2018

With this change the naming conventions change slightly:

  • FakeKeyStore generates selfsigned.keystore. Contains selfsigned-*"
  • FakeChainedKeyStore generates chained.keystore Contains {ca,user}-*"

Copy link
Contributor

@marcospereira marcospereira left a comment

Choose a reason for hiding this comment

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

Some questions:

  • Can we avoid adding the duplications before merging?
  • How hard is to add tests for FakeChainedKeyStore?
  • Would it be simpler to have a parameter (chained: Boolean = false?) and handle the different behavior instead of having a new object/class?

val KeystoreType = "PKCS12"
val SignatureAlgorithmOID: ObjectIdentifier = AlgorithmId.sha256WithRSAEncryption_oid
val keystorePassword: Array[Char] = EMPTY_PASSWORD
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we make them reference each other? Or even remove the duplication at all?

@ignasi35
Copy link
Contributor Author

ignasi35 commented Oct 5, 2018

I added the duplication to focus on having something we can uses ASAP.

IMHO all FakeXyz tools shohhuld be moved out of ssl-config-core and into a new ssl-config-testkit.

Need to log off now, but will be back tonight to improve the code.

@dwijnand dwijnand merged commit d271f76 into lightbend:master Oct 5, 2018
@ignasi35 ignasi35 mentioned this pull request Oct 5, 2018
ignasi35 pushed a commit to playframework/playframework that referenced this pull request Oct 8, 2018
## Purpose

Update ssl-config to version 0.3.5

## References

* lightbend/ssl-config#125
* lagom/lagom#1610
@wsargent
Copy link
Contributor

wsargent commented Nov 1, 2018

Note: we could create a collection of tools to create several KeyStore's (one for the CA, another for the server, a third one for client-side SSL auth) but that's not the purpose of this PR.

https://github.com/tersesystems/securitybuilder#x509certificatecreator :-)

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

Successfully merging this pull request may close these issues.

4 participants