Skip to content

Commit fdc6e95

Browse files
committed
Review feedback
1 parent f8e1ae6 commit fdc6e95

File tree

3 files changed

+15
-17
lines changed

3 files changed

+15
-17
lines changed

driver/src/main/java/org/neo4j/driver/internal/security/SecurityPlanImpl.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public static SecurityPlan forSystemCASignedCertificates( boolean requiresHostna
6363
return new SecurityPlanImpl( true, sslContext, requiresHostnameVerification, requiresRevocationChecking );
6464
}
6565

66-
public static SSLContext configureSSLContext( File customCertFile, boolean requiresRevocationChecking )
66+
private static SSLContext configureSSLContext( File customCertFile, boolean requiresRevocationChecking )
6767
throws GeneralSecurityException, IOException
6868
{
6969
KeyStore trustedKeyStore = KeyStore.getInstance( KeyStore.getDefaultType() );
@@ -85,18 +85,16 @@ public static SSLContext configureSSLContext( File customCertFile, boolean requi
8585
// sets checking of stapled ocsp response
8686
pkixBuilderParameters.setRevocationEnabled( requiresRevocationChecking );
8787

88-
// enables status_request exentension in client hello
88+
// enables status_request extension in client hello
8989
if ( requiresRevocationChecking )
9090
{
9191
System.setProperty( "jdk.tls.client.enableStatusRequestExtension", "true" );
9292
}
9393

94-
// Create TrustManager from TrustedKeyStore
95-
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance( TrustManagerFactory.getDefaultAlgorithm() );
96-
trustManagerFactory.init( new CertPathTrustManagerParameters( pkixBuilderParameters ) );
97-
9894
SSLContext sslContext = SSLContext.getInstance( "TLS" );
9995

96+
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance( TrustManagerFactory.getDefaultAlgorithm() );
97+
trustManagerFactory.init( new CertPathTrustManagerParameters( pkixBuilderParameters ) );
10098
sslContext.init( new KeyManager[0], trustManagerFactory.getTrustManagers(), null );
10199

102100
return sslContext;

driver/src/main/java/org/neo4j/driver/internal/util/CertificateTool.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
/**
3737
* A tool used to save, load certs, etc.
3838
*/
39-
public class CertificateTool
39+
public final class CertificateTool
4040
{
4141
private static final String BEGIN_CERT = "-----BEGIN CERTIFICATE-----";
4242
private static final String END_CERT = "-----END CERTIFICATE-----";
@@ -170,6 +170,10 @@ public static String X509CertToString( String cert )
170170
String cert64CharPerLine = cert.replaceAll( "(.{64})", "$1\n" );
171171
return BEGIN_CERT + "\n" + cert64CharPerLine + "\n"+ END_CERT + "\n";
172172
}
173+
174+
private CertificateTool()
175+
{
176+
}
173177
}
174178

175179

driver/src/test/java/org/neo4j/driver/internal/SecuritySettingsTest.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,11 @@
2323
import org.junit.jupiter.params.provider.MethodSource;
2424

2525
import java.util.stream.Stream;
26-
import javax.net.ssl.SSLContext;
2726

2827
import org.neo4j.driver.Config;
2928
import org.neo4j.driver.exceptions.ClientException;
3029
import org.neo4j.driver.internal.security.SecurityPlan;
3130

32-
import static org.junit.Assert.assertEquals;
3331
import static org.junit.jupiter.api.Assertions.assertFalse;
3432
import static org.junit.jupiter.api.Assertions.assertThrows;
3533
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -75,11 +73,9 @@ void testSystemCertCompatibleConfiguration( String scheme ) throws Exception
7573

7674
SecurityPlan securityPlan = securitySettings.createSecurityPlan( scheme );
7775

78-
SSLContext defaultContext = SSLContext.getDefault();
79-
8076
assertTrue( securityPlan.requiresEncryption() );
8177
assertTrue( securityPlan.requiresHostnameVerification() );
82-
assertEquals( defaultContext, securityPlan.sslContext() );
78+
assertFalse( securityPlan.requiresRevocationChecking() );
8379
}
8480

8581
@ParameterizedTest
@@ -140,7 +136,7 @@ void testThrowsOnUserCustomizedTrustConfigurationAndEncryption( String scheme )
140136
assertTrue( ex.getMessage().contains( String.format( "Scheme %s is not configurable with manual encryption and trust settings", scheme ) ));
141137
}
142138

143-
@ParameterizedTest()
139+
@ParameterizedTest
144140
@MethodSource( "unencryptedSchemes" )
145141
void testNoEncryption( String scheme )
146142
{
@@ -151,7 +147,7 @@ void testNoEncryption( String scheme )
151147
assertFalse( securityPlan.requiresEncryption() );
152148
}
153149

154-
@ParameterizedTest()
150+
@ParameterizedTest
155151
@MethodSource( "unencryptedSchemes" )
156152
void testConfiguredEncryption( String scheme )
157153
{
@@ -163,7 +159,7 @@ void testConfiguredEncryption( String scheme )
163159
assertTrue( securityPlan.requiresEncryption() );
164160
}
165161

166-
@ParameterizedTest()
162+
@ParameterizedTest
167163
@MethodSource( "unencryptedSchemes" )
168164
void testConfiguredAllCertificates( String scheme)
169165
{
@@ -177,7 +173,7 @@ void testConfiguredAllCertificates( String scheme)
177173
assertTrue( securityPlan.requiresEncryption() );
178174
}
179175

180-
@ParameterizedTest()
176+
@ParameterizedTest
181177
@MethodSource( "unencryptedSchemes" )
182178
void testConfigureRevocationChecking( String scheme )
183179
{
@@ -191,7 +187,7 @@ void testConfigureRevocationChecking( String scheme )
191187
assertTrue( securityPlan.requiresRevocationChecking() );
192188
}
193189

194-
@ParameterizedTest()
190+
@ParameterizedTest
195191
@MethodSource( "unencryptedSchemes" )
196192
void testRevocationCheckingDisabledByDefault( String scheme )
197193
{

0 commit comments

Comments
 (0)