Skip to content

Commit 183afc6

Browse files
authored
Fix issue #3104 (#3182)
Reset securerandom.strongAlgorithms Reorg setup of BouncyCastleFipsProvider
1 parent ea6d3f3 commit 183afc6

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

server/src/main/java/org/cloudfoundry/identity/uaa/provider/saml/IdentityZoneConfig.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.cloudfoundry.identity.uaa.provider.saml;
22

3+
import lombok.extern.slf4j.Slf4j;
34
import org.bouncycastle.jcajce.provider.BouncyCastleFipsProvider;
45
import org.cloudfoundry.identity.uaa.zone.IdentityZoneHolder;
56
import org.cloudfoundry.identity.uaa.zone.IdentityZoneProvisioning;
@@ -11,10 +12,20 @@
1112
import java.security.Security;
1213

1314
@Configuration
15+
@Slf4j
1416
public class IdentityZoneConfig {
1517

1618
@Bean
1719
public BouncyCastleFipsProvider setUpBouncyCastle() {
20+
// Ensure non blocking random if system property java.security.egd is set
21+
if (System.getProperty("java.security.egd", "/random").endsWith("/urandom") &&
22+
!Security.getProperty("securerandom.strongAlgorithms").contains("NativePRNGNonBlocking")) {
23+
String originalStrongAlgorithm = Security.getProperty("securerandom.strongAlgorithms");
24+
log.info("Current securerandom.strongAlgorithms: {}", originalStrongAlgorithm);
25+
String newStrongAlgorithm = "NativePRNGNonBlocking:SUN," + originalStrongAlgorithm;
26+
log.info("New securerandom.strongAlgorithms: {}", newStrongAlgorithm);
27+
Security.setProperty("securerandom.strongAlgorithms", newStrongAlgorithm);
28+
}
1829
BouncyCastleFipsProvider provider = new BouncyCastleFipsProvider();
1930
Security.addProvider(provider);
2031
return provider;

server/src/main/java/org/cloudfoundry/identity/uaa/provider/saml/SamlKeyManagerFactory.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,10 @@
1414
package org.cloudfoundry.identity.uaa.provider.saml;
1515

1616
import lombok.extern.slf4j.Slf4j;
17-
import org.bouncycastle.jcajce.provider.BouncyCastleFipsProvider;
1817
import org.cloudfoundry.identity.uaa.saml.SamlKey;
1918
import org.cloudfoundry.identity.uaa.util.KeyWithCert;
2019
import org.cloudfoundry.identity.uaa.zone.SamlConfig;
2120

22-
import java.security.Security;
2321
import java.security.cert.CertificateException;
2422
import java.util.ArrayList;
2523
import java.util.Collections;
@@ -54,10 +52,6 @@ public SamlKeyManager getKeyManager(SamlConfig config) {
5452

5553
abstract static class BaseSamlKeyManagerImpl implements SamlKeyManager {
5654

57-
static {
58-
Security.addProvider(new BouncyCastleFipsProvider());
59-
}
60-
6155
protected List<KeyWithCert> convertList(List<SamlKey> samlKeys) {
6256
List<KeyWithCert> result = new ArrayList<>();
6357
for (SamlKey k : samlKeys) {

server/src/main/java/org/cloudfoundry/identity/uaa/provider/saml/SamlRelyingPartyRegistrationRepositoryConfig.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.springframework.beans.factory.annotation.Value;
99
import org.springframework.context.annotation.Bean;
1010
import org.springframework.context.annotation.Configuration;
11+
import org.springframework.context.annotation.DependsOn;
1112
import org.springframework.security.saml2.Saml2Exception;
1213
import org.springframework.security.saml2.provider.service.registration.InMemoryRelyingPartyRegistrationRepository;
1314
import org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration;
@@ -42,6 +43,7 @@ public SamlRelyingPartyRegistrationRepositoryConfig(@Qualifier("samlEntityID") S
4243
}
4344

4445
@Autowired
46+
@DependsOn({"setUpBouncyCastle"})
4547
@Bean
4648
RelyingPartyRegistrationRepository relyingPartyRegistrationRepository(SamlIdentityProviderConfigurator samlIdentityProviderConfigurator) {
4749
SamlKeyManagerFactory.SamlConfigPropsSamlKeyManagerImpl samlKeyManager = new SamlKeyManagerFactory.SamlConfigPropsSamlKeyManagerImpl(samlConfigProps);

0 commit comments

Comments
 (0)