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

feat: Configure java connector to check CN instance name. Fixes #1995 #1996

Merged
merged 1 commit into from
Jun 3, 2024

Conversation

hessjcg
Copy link
Collaborator

@hessjcg hessjcg commented May 22, 2024

This code will make that the connector checks that the server certificate's subject CN field matches the instance name
before allowing the TLS handshake to proceed.

This introduces new classes that are always installed as trust managers on all TLS connections to ensure that the TLS logic correctly checks that the server certificate's CN field matches the instance.

  • InstanceCheckingTrustManager - Delegates to default TLS trust manager, then checks the CN field.
  • InstanceCheckingTrustManagerFactory and InstanceCheckingTrustManagerFactorySpi - Installs
    our custom trust manager into connector TLS sockets.

The ConscryptWorkaroundTrustManagerFactory and ConscryptWorkaroundTrustManagerFactorySpi classes are no longer necessary. Logic to detect Conscrypt and use the workaround ConscryptWorkaroundTrustManager moves into InstanceCheckingTrustManagerFactorySpi.

@hessjcg hessjcg force-pushed the gh-1995-check-cn branch 4 times, most recently from 3e90ff4 to 13b73d3 Compare May 29, 2024 15:01
@hessjcg hessjcg marked this pull request as ready for review May 29, 2024 15:04
@hessjcg hessjcg requested a review from a team as a code owner May 29, 2024 15:04
Copy link
Member

@enocom enocom left a comment

Choose a reason for hiding this comment

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

Do we have a test that verifies a common name mismatch fails the TLS handshake?

@hessjcg
Copy link
Collaborator Author

hessjcg commented May 29, 2024

I added a test for a CN mismatch.

@hessjcg
Copy link
Collaborator Author

hessjcg commented May 29, 2024

@jackwotherspoon We need to manually test this with a domain-scoped instance. Can you do that?

@jackwotherspoon
Copy link
Collaborator

jackwotherspoon commented May 29, 2024

@jackwotherspoon We need to manually test this with a domain-scoped instance. Can you do that?

@hessjcg sure, for manually testing should I just run the integration tests? Will that suffice?

@hessjcg
Copy link
Collaborator Author

hessjcg commented May 29, 2024

@jackwotherspoon: Yes, it will be sufficient to run the integration tests at the domain-scoped instance.

@@ -62,6 +62,8 @@ public class CloudSqlCoreTestingBase {

ListenableFuture<KeyPair> clientKeyPair;

public CloudSqlCoreTestingBase() {}
Copy link
Member

Choose a reason for hiding this comment

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

FWIW In my opinion, this base class deserves to be split up into small composable units. As is, it's an awkward tool.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

+1. Maybe in a different PR.

FakeSslServer sslServer = new FakeSslServer();
ConnectionConfig config =
new ConnectionConfig.Builder()
.withCloudSqlInstance("myProject:myRegion:otherInstance")
Copy link
Member

Choose a reason for hiding this comment

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

nit: let's make this blatantly wrong, e.g., "wrongwrongwrong" or something similar that catches the eye.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed.

@hessjcg hessjcg enabled auto-merge (squash) June 3, 2024 19:47
@hessjcg hessjcg merged commit 9346117 into main Jun 3, 2024
17 checks passed
@hessjcg hessjcg deleted the gh-1995-check-cn branch June 3, 2024 19:54
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.

3 participants