Skip to content

Commit f90f501

Browse files
authored
Merge pull request #1159 from flybyray/proposed-lighthouse-2089-missing-bouncycastle
[#2089 ] upgrade bouncycastle
2 parents 78b25aa + 5405468 commit f90f501

File tree

11 files changed

+1114
-40
lines changed

11 files changed

+1114
-40
lines changed

documentation/manual/production.textile

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,8 @@ bc. # X509 certificates
189189
certificate.key.file=conf/host.key
190190
certificate.file=conf/host.cert
191191
# In case your key file is password protected
192-
certificate.password=secret
192+
# certificate.key.file=conf/host.pass.key
193+
# certificate.password=secret
193194
trustmanager.algorithm=JKS
194195

195196
If you are using keystore:
@@ -202,8 +203,13 @@ Note that the values above are the default values.
202203

203204
You can generate self-signed certificates using *openssl*:
204205

205-
bc. openssl genrsa 1024 > host.key
206-
openssl req -new -x509 -nodes -sha1 -days 365 -key host.key > host.cert
206+
bc. openssl genrsa -des3 -passout pass:secret -out host.pass.key 2048
207+
openssl rsa -passin pass:secret -in host.pass.key -out host.key
208+
openssl req -new -key host.key -out host.csr -subj '/C=GB/ST=Test State or Province/L=Test Locality/O=Organization Name/OU=Organizational Unit Name/CN=Common Name/emailAddress=test@email.address'
209+
openssl x509 -req -days 3650 -in host.csr -signkey host.key -out host.cert
210+
211+
note. the first command creates a password-protected-key ('host.pass.key').
212+
the second command converts/writes the same key ('host.key') without password protection.
207213

208214
If you are using the Java keystore mechanism, then the following properties can be configured in your @application.conf@ file:
209215

framework/dependencies.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ require: &allDependencies
4343
- oauth.signpost -> signpost-core 1.2.1.2
4444
- org.apache.geronimo.specs -> geronimo-servlet_2.5_spec 1.2
4545
- org.apache.ivy -> ivy 2.4.0
46-
- org.bouncycastle -> bcprov-jdk15 1.46
46+
- org.bouncycastle -> bcprov-jdk15on 1.57
47+
- org.bouncycastle -> bcpkix-jdk15on 1.57
4748
- org.codehaus.groovy -> groovy-all 2.4.11
4849
- org.eclipse.jdt.core 3.12.3
4950
- org.hibernate -> hibernate-core 5.2.10.patched
758 KB
Binary file not shown.
-1.73 MB
Binary file not shown.
3.59 MB
Binary file not shown.

framework/src/play/Logger.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
import java.io.PrintWriter;
44
import java.io.StringWriter;
5+
import java.net.URISyntaxException;
56
import java.net.URL;
7+
import java.nio.file.FileSystemNotFoundException;
8+
import java.nio.file.Paths;
69
import java.text.MessageFormat;
710
import java.util.ArrayList;
811
import java.util.List;
@@ -70,10 +73,11 @@ public static void init() {
7073
PropertyConfigurator.configure(shutUp);
7174
} else if (Logger.log4j == null) {
7275

73-
if (log4jConf.getFile().indexOf(Play.applicationPath.getAbsolutePath()) == 0) {
74-
// The log4j configuration file is located somewhere in the application folder,
75-
// so it's probably a custom configuration file
76-
configuredManually = true;
76+
try {
77+
if (Paths.get(log4jConf.toURI()).startsWith(Play.applicationPath.toPath())) {
78+
configuredManually = true;
79+
}
80+
} catch (IllegalArgumentException | FileSystemNotFoundException | SecurityException | URISyntaxException e) {
7781
}
7882
if (isXMLConfig) {
7983
DOMConfigurator.configure(log4jConf);

framework/src/play/server/ssl/SslHttpServerContextFactory.java

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
package play.server.ssl;
22

3+
import org.bouncycastle.jcajce.provider.asymmetric.x509.CertificateFactory;
34
import org.bouncycastle.jce.provider.BouncyCastleProvider;
4-
import org.bouncycastle.openssl.PEMReader;
5-
import org.bouncycastle.openssl.PasswordFinder;
5+
import org.bouncycastle.openssl.PEMDecryptorProvider;
6+
import org.bouncycastle.openssl.PEMEncryptedKeyPair;
7+
import org.bouncycastle.openssl.PEMKeyPair;
8+
import org.bouncycastle.openssl.PEMParser;
9+
import org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter;
10+
import org.bouncycastle.openssl.jcajce.JcePEMDecryptorProviderBuilder;
611
import play.Logger;
712
import play.Play;
813

914
import javax.net.ssl.*;
15+
import java.io.File;
1016
import java.io.FileInputStream;
1117
import java.io.FileReader;
1218
import java.net.Socket;
1319
import java.security.*;
1420
import java.security.cert.X509Certificate;
15-
import java.util.ArrayList;
16-
import java.util.List;
21+
import java.util.Collection;
1722
import java.util.Properties;
1823

1924
public class SslHttpServerContextFactory {
@@ -84,18 +89,22 @@ public PEMKeyManager() {
8489
final Properties p = Play.configuration;
8590
String keyFile = p.getProperty("certificate.key.file", "conf/host.key");
8691

87-
try (PEMReader keyReader = new PEMReader(new FileReader(Play.getFile(keyFile)), new PEMPasswordFinder())) {
88-
key = ((KeyPair) keyReader.readObject()).getPrivate();
89-
90-
try (PEMReader reader = new PEMReader(new FileReader(Play.getFile(p.getProperty("certificate.file", "conf/host.cert"))))) {
91-
X509Certificate cert;
92-
List<X509Certificate> chainVector = new ArrayList<>();
93-
94-
while ((cert = (X509Certificate) reader.readObject()) != null) {
95-
chainVector.add(cert);
96-
}
97-
chain = chainVector.toArray(new X509Certificate[1]);
92+
try (PEMParser keyReader = new PEMParser(new FileReader(Play.getFile(keyFile)))) {
93+
final Object object = keyReader.readObject();
94+
JcaPEMKeyConverter converter = new JcaPEMKeyConverter().setProvider("BC");
95+
final KeyPair keyPair;
96+
if (object instanceof PEMEncryptedKeyPair) {
97+
PEMDecryptorProvider decProv = new JcePEMDecryptorProviderBuilder()
98+
.build(Play.configuration.getProperty("certificate.password", "secret").toCharArray());
99+
keyPair = converter.getKeyPair(((PEMEncryptedKeyPair) object).decryptKeyPair(decProv));
100+
} else {
101+
keyPair = converter.getKeyPair((PEMKeyPair) object);
98102
}
103+
key = keyPair.getPrivate();
104+
105+
final File hostCertFile = Play.getFile(p.getProperty("certificate.file", "conf/host.cert"));
106+
final Collection collection = new CertificateFactory().engineGenerateCertificates(new FileInputStream(hostCertFile));
107+
chain = (X509Certificate[]) collection.toArray(new X509Certificate[collection.size()]);
99108
} catch (Exception e) {
100109
Logger.error(e, "Failed to initialize PEMKeyManager from file %s", keyFile);
101110
}
@@ -136,12 +145,4 @@ public PrivateKey getPrivateKey(String s) {
136145
return key;
137146
}
138147
}
139-
140-
private static class PEMPasswordFinder implements PasswordFinder {
141-
@Override
142-
public char[] getPassword() {
143-
return Play.configuration.getProperty("certificate.password", "secret").toCharArray();
144-
}
145-
}
146-
147148
}

framework/test-src/play/templates/FastTagsTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package play.templates;
22

33
import groovy.lang.Closure;
4+
import org.junit.After;
45
import org.junit.Before;
56
import org.junit.Test;
67
import play.mvc.Http;
@@ -18,15 +19,27 @@
1819
public class FastTagsTest {
1920

2021
private StringWriter out = new StringWriter();
22+
final String backupSystemLineBreak = System.getProperty("line.separator");
2123

2224
@Before
2325
public void setUp() throws Exception {
26+
//if you render html into out
27+
// and expect results with line breaks
28+
// take into account that your tests will fail on other platforms
29+
// force line.separator be the same on any platform
30+
// or use String.format in expected code with the placeholder '%n' for any expected line separation.
31+
System.setProperty("line.separator","\n");
2432
Http.Response.current.set(new Http.Response());
2533
Http.Response.current().encoding = "UTF-8";
2634

2735
Scope.Session.current.set(new Scope.Session());
2836
Scope.Session.current().put("___AT", "1234");
2937
}
38+
@After
39+
public void tearDown() throws Exception {
40+
// restore line.separator
41+
System.setProperty("line.separator", backupSystemLineBreak);
42+
}
3043

3144
@Test
3245
public void _form_simple() throws Exception {

0 commit comments

Comments
 (0)