Skip to content

Commit e503852

Browse files
committed
change ca cert import mode default to CA_ONLY
1 parent 6619460 commit e503852

File tree

5 files changed

+31
-6
lines changed

5 files changed

+31
-6
lines changed

server/src/main/java/password/pwm/AppProperty.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public enum AppProperty
4545
AUDIT_SYSLOG_CEF_HEADER_PRODUCT ( "audit.syslog.cef.header.product" ),
4646
AUDIT_SYSLOG_CEF_HEADER_SEVERITY ( "audit.syslog.cef.header.severity" ),
4747
AUDIT_SYSLOG_CEF_HEADER_VENDOR ( "audit.syslog.cef.header.vendor" ),
48+
AUDIT_SYSLOG_CEF_MAX_EXTENSION_CHARS ( "audit.syslog.cef.maxExtensionChars" ),
4849
AUDIT_SYSLOG_MAX_MESSAGE_LENGTH ( "audit.syslog.message.length" ),
4950
AUDIT_SYSLOG_TRUNCATE_MESSAGE ( "audit.syslog.message.truncateMsg" ),
5051
AUTH_ALLOW_SSO_WITH_UNKNOWN_PW ( "auth.allowSSOwithUnknownPassword" ),
@@ -324,6 +325,7 @@ public enum AppProperty
324325
SECURITY_SHAREDHISTORY_HASH_NAME ( "security.sharedHistory.hashName" ),
325326
SECURITY_SHAREDHISTORY_CASE_INSENSITIVE ( "security.sharedHistory.caseInsensitive" ),
326327
SECURITY_SHAREDHISTORY_SALT_LENGTH ( "security.sharedHistory.saltLength" ),
328+
SECURITY_CERTIFICATES_ALLOW_SELF_SIGNED ( "security.certs.allowSelfSigned" ),
327329
SECURITY_CERTIFICATES_VALIDATE_TIMESTAMPS ( "security.certs.validateTimestamps" ),
328330
SECURITY_CONFIG_MIN_SECURITY_KEY_LENGTH ( "security.config.minSecurityKeyLength" ),
329331
SECURITY_DEFAULT_EPHEMERAL_BLOCK_ALG ( "security.defaultEphemeralBlockAlg" ),

server/src/main/java/password/pwm/util/secure/X509Utils.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,12 +320,14 @@ public static class CertMatchingTrustManager implements X509TrustManager
320320
{
321321
final List<X509Certificate> trustedCertificates;
322322
final boolean validateTimestamps;
323+
final boolean allowSelfSigned;
323324
final CertificateMatchingMode certificateMatchingMode;
324325

325326
public CertMatchingTrustManager( final Configuration config, final List<X509Certificate> trustedCertificates )
326327
{
327328
this.trustedCertificates = new ArrayList<>( trustedCertificates );
328329
validateTimestamps = config != null && Boolean.parseBoolean( config.readAppProperty( AppProperty.SECURITY_CERTIFICATES_VALIDATE_TIMESTAMPS ) );
330+
allowSelfSigned = config != null && Boolean.parseBoolean( config.readAppProperty( AppProperty.SECURITY_CERTIFICATES_ALLOW_SELF_SIGNED ) );
329331
certificateMatchingMode = config == null
330332
? CertificateMatchingMode.CERTIFICATE_CHAIN
331333
: config.readCertificateMatchingMode();
@@ -339,25 +341,42 @@ public void checkClientTrusted( final X509Certificate[] x509Certificates, final
339341
@Override
340342
public void checkServerTrusted( final X509Certificate[] x509Certificates, final String s ) throws CertificateException
341343
{
344+
final List<X509Certificate> trustedRootCA = X509Utils.identifyRootCACertificate( trustedCertificates );
345+
final List<X509Certificate> remoteCertificates = Arrays.asList( x509Certificates );
346+
if ( trustedCertificates.size() == 1 && trustedRootCA.isEmpty() && remoteCertificates.size() == 1 )
347+
{
348+
if ( allowSelfSigned )
349+
{
350+
doValidation( remoteCertificates, trustedCertificates, validateTimestamps );
351+
return;
352+
}
353+
else
354+
{
355+
final String msg = "unable to trust self-signed certificate due to app property '"
356+
+ AppProperty.SECURITY_CERTIFICATES_ALLOW_SELF_SIGNED.getKey() + "'";
357+
throw new CertificateException( msg );
358+
}
359+
}
360+
361+
342362
switch ( certificateMatchingMode )
343363
{
344364
case CERTIFICATE_CHAIN:
345365
{
346-
doValidation( trustedCertificates, Arrays.asList( x509Certificates ), validateTimestamps );
366+
doValidation( trustedCertificates, remoteCertificates, validateTimestamps );
347367
break;
348368
}
349369

350370
case CA_ONLY:
351371
{
352-
final List<X509Certificate> trustedRootCA = X509Utils.identifyRootCACertificate( trustedCertificates );
353372
if ( trustedRootCA.isEmpty() )
354373
{
355374
final String errorMsg = "no root CA certificates in configuration trust store for this operation";
356375
throw new CertificateException( errorMsg );
357376
}
358377
doValidation(
359378
trustedRootCA,
360-
X509Utils.identifyRootCACertificate( Arrays.asList( x509Certificates ) ),
379+
X509Utils.identifyRootCACertificate( remoteCertificates ),
361380
validateTimestamps
362381
);
363382
break;

server/src/main/resources/password/pwm/AppProperty.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ audit.syslog.cef.timezone=Zulu
3636
audit.syslog.cef.header.product=@PwmAppName@
3737
audit.syslog.cef.header.severity=Medium
3838
audit.syslog.cef.header.vendor=@PwmVendorName@
39+
audit.syslog.cef.maxExtensionChars=1023
3940
audit.syslog.message.length=900
4041
audit.syslog.message.truncateMsg=[truncated]
4142
auth.allowSSOwithUnknownPassword=true
@@ -303,6 +304,7 @@ security.sharedHistory.hashIterations=100000
303304
security.sharedHistory.hashName=SHA-512
304305
security.sharedHistory.caseInsensitive=true
305306
security.sharedHistory.saltLength=64
307+
security.certs.allowSelfSigned=true
306308
security.certs.validateTimestamps=false
307309
security.defaultEphemeralBlockAlg=AES128_GCM
308310
security.defaultEphemeralHashAlg=SHA512

server/src/main/resources/password/pwm/config/PwmSetting.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1569,7 +1569,7 @@
15691569
</setting>
15701570
<setting hidden="false" key="security.certificate.validationMode" level="2">
15711571
<default>
1572-
<value>CERTIFICATE_CHAIN</value>
1572+
<value>CA_ONLY</value>
15731573
</default>
15741574
<options>
15751575
<option value="CA_ONLY">Root Certificate Only</option>

server/src/test/java/password/pwm/http/client/PwmHttpClientTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.apache.http.HttpResponse;
3030
import org.apache.http.client.HttpClient;
3131
import org.apache.http.client.methods.HttpGet;
32+
import org.apache.http.entity.ContentType;
3233
import org.junit.Assert;
3334
import org.junit.Rule;
3435
import org.junit.Test;
@@ -39,6 +40,7 @@
3940
import password.pwm.config.PwmSetting;
4041
import password.pwm.config.stored.StoredConfigurationImpl;
4142
import password.pwm.error.PwmUnrecoverableException;
43+
import password.pwm.http.HttpHeader;
4244

4345
import javax.net.ssl.SSLHandshakeException;
4446
import java.io.InputStream;
@@ -149,7 +151,7 @@ public void testGetHttpClientSslWithCertificates() throws Exception
149151
// Stub out our local HTTP server
150152
wireMockRule.stubFor( WireMock.get( WireMock.urlEqualTo( "/simpleHello" ) )
151153
.willReturn( WireMock.aResponse()
152-
.withHeader( "Content-Type", "text/plain" )
154+
.withHeader( HttpHeader.ContentType.getHttpName(), ContentType.TEXT_PLAIN.getMimeType() )
153155
.withBody( "PwmAbout from the local mock server" ) ) );
154156

155157
final PwmHttpClientConfiguration pwmHttpClientConfiguration = PwmHttpClientConfiguration.builder()
@@ -181,7 +183,7 @@ public void testGetHttpClientProxyHello() throws Exception
181183
// Stub out our local HTTP server
182184
wireMockRule.stubFor( WireMock.get( WireMock.urlEqualTo( "/simpleHello" ) )
183185
.willReturn( WireMock.aResponse()
184-
.withHeader( "Content-Type", "text/plain" )
186+
.withHeader( HttpHeader.ContentType.getHttpName(), ContentType.TEXT_PLAIN.getMimeType() )
185187
.withBody( "PwmAbout from the local mock server" ) ) );
186188

187189
// Stub out some mock object behavior

0 commit comments

Comments
 (0)