Skip to content

Commit 1e8a2d1

Browse files
committed
[feature] Switch from GNU Crypto to Bouncy Castle
1 parent d11e98f commit 1e8a2d1

File tree

12 files changed

+38
-389
lines changed

12 files changed

+38
-389
lines changed

.classpath

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
<classpathentry kind="lib" path="extensions/webdav/lib/mime-util-2.1.3.jar"/>
8282
<classpathentry kind="lib" path="lib/optional/isorelax-20041111.jar"/>
8383
<classpathentry kind="lib" path="lib/optional/xqjapi-1.0-fr.jar"/>
84-
<classpathentry kind="lib" path="lib/core/gnu-crypto-2.0.1.jar"/>
84+
<classpathentry kind="lib" path="lib/core/bcprov-jdk15on-1.60.jar"/>
8585
<classpathentry kind="lib" path="tools/jetty/lib/existdb-favicon.jar"/>
8686
<classpathentry kind="lib" path="tools/jetty/lib/asm-6.0.jar"/>
8787
<classpathentry kind="lib" path="tools/jetty/lib/asm-commons-6.0.jar"/>

conf.xml.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@
211211
<!--
212212
Trigger for registering the GNU Crypto JCE Provider with Java
213213
-->
214-
<trigger class="org.exist.security.GnuCryptoJceProviderStartupTrigger"/>
214+
<trigger class="org.exist.security.BouncyCastleJceProviderStartupTrigger"/>
215215

216216
<!--
217217
Trigger for registering eXists XML:DB URL handler with Java

lib/core/bcprov-jdk15on-1.60.jar

4 MB
Binary file not shown.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright (c) 2000 - 2017 The Legion of the Bouncy Castle Inc. (http://www.bouncycastle.org)
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

lib/core/gnu-crypto-2.0.1.jar

-584 KB
Binary file not shown.

lib/core/gnu-crypto-COPYING.txt

Lines changed: 0 additions & 340 deletions
This file was deleted.

lib/core/gnu-crypto-LICENSE.txt

Lines changed: 0 additions & 20 deletions
This file was deleted.

nbproject/project.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ file.reference.javax.transaction-api-1.2.jar=tools/jetty/lib/javax.transaction-a
2424
file.reference.jcip-annotations-1.0.jar=lib/core/jcip-annotations-1.0.jar
2525
file.reference.cglib-nodep-3.2.6.jar=lib/core/cglib-nodep-3.2.6.jar
2626
file.reference.easymock-3.6.jar=lib/test/easymock-3.6.jar
27-
file.reference.gnu-crypto-2.0.1.jar=lib/core/gnu-crypto-2.0.1.jar
27+
file.reference.bcprov-jdk15on-1.60.jar=lib/core/bcprov-jdk15on-1.60.jar
2828
file.reference.jetty-jndi-9.4.10.v20180503.jar=tools/jetty/lib/jetty-jndi-9.4.10.v20180503.jar
2929
file.reference.jna-4.5.0.jar=tools/yajsw/lib/core/jna/jna-4.5.0.jar
3030
file.reference.jna-platform-4.5.0.jar=tools/yajsw/lib/core/jna/jna-platform-4.5.0.jar
@@ -297,7 +297,7 @@ javac.classpath=\
297297
${file.reference.xmlrpc-common-3.1.3.jar}:\
298298
${file.reference.xmlrpc-server-3.1.3.jar}:\
299299
${file.reference.jackson-core-2.9.5.jar}:\
300-
${file.reference.gnu-crypto-2.0.1.jar}:\
300+
${file.reference.bcprov-jdk15on-1.60.jar}:\
301301
${file.reference.cglib-nodep-3.2.6.jar}:\
302302
${file.reference.jcip-annotations-1.0.jar}:\
303303
${file.reference.commons-compress-1.17.jar}:\

src/org/exist/security/GnuCryptoJceProviderStartupTrigger.java renamed to src/org/exist/security/BouncyCastleJceProviderStartupTrigger.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import org.apache.logging.log4j.LogManager;
2323
import org.apache.logging.log4j.Logger;
24+
import org.bouncycastle.jce.provider.BouncyCastleProvider;
2425
import org.exist.storage.DBBroker;
2526
import org.exist.storage.StartupTrigger;
2627
import org.exist.storage.txn.Txn;
@@ -29,21 +30,21 @@
2930
import java.util.Map;
3031

3132
/**
32-
* Startup Trigger to register the GNU Crypto JCE Provider
33+
* Startup Trigger to register the Bouncy Castle JCE Provider
3334
*
3435
* @author Adam Retter <[email protected]>
3536
*/
36-
public class GnuCryptoJceProviderStartupTrigger implements StartupTrigger {
37+
public class BouncyCastleJceProviderStartupTrigger implements StartupTrigger {
3738

3839
private final static Logger LOG = LogManager.getLogger(
39-
GnuCryptoJceProviderStartupTrigger.class);
40+
BouncyCastleJceProviderStartupTrigger.class);
4041

4142
@Override
4243
public void execute(final DBBroker sysBroker, final Txn transaction,
43-
final Map<String, List<? extends Object>> params) {
44+
final Map<String, List<? extends Object>> params) {
4445

45-
java.security.Security.addProvider(new gnu.crypto.jce.GnuCrypto());
46+
java.security.Security.addProvider(new BouncyCastleProvider());
4647

47-
LOG.info("Registered JCE Security Provider: gnu.crypto.jce.GnuCrypto");
48+
LOG.info("Registered JCE Security Provider: org.bouncycastle.jce.provider.BouncyCastleProvider");
4849
}
4950
}

src/org/exist/security/internal/Password.java

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,24 @@
1919
*/
2020
package org.exist.security.internal;
2121

22-
import gnu.crypto.hash.MD5;
23-
import gnu.crypto.hash.RipeMD160;
2422
import java.util.regex.Matcher;
2523
import java.util.regex.Pattern;
2624
import org.apache.commons.codec.binary.Base64;
25+
import org.bouncycastle.crypto.digests.GeneralDigest;
26+
import org.bouncycastle.crypto.digests.MD5Digest;
27+
import org.bouncycastle.crypto.digests.RIPEMD160Digest;
2728
import org.exist.security.Account;
2829
import org.exist.security.Credential;
2930
import org.exist.security.MessageDigester;
3031

32+
import static java.nio.charset.StandardCharsets.UTF_8;
33+
3134
/**
3235
* @author <a href="mailto:[email protected]">Dmitriy Shabanov</a>
3336
* @author <a href="mailto:[email protected]">Adam Retter</a>
3437
*
3538
*/
3639
public class Password implements Credential {
37-
38-
//TODO switch over to using jBCrypt
3940

4041
public enum Hash {
4142
MD5,
@@ -108,22 +109,22 @@ final byte[] hash(String p) {
108109
}
109110
}
110111

111-
final byte[] ripemd160Hash(String p) {
112+
final byte[] ripemd160Hash(final String p) {
112113
//ripemd160 hash
113-
final RipeMD160 ripemd160 = new RipeMD160();
114-
final byte[] data = p.getBytes();
115-
ripemd160.update(data, 0, data.length);
116-
final byte[] hash = ripemd160.digest();
117-
return hash;
114+
return digest(p, new RIPEMD160Digest());
118115
}
119116

120-
final byte[] md5Hash(String p) {
121-
//md5 hash
122-
final MD5 md5 = new MD5();
123-
final byte[] data = p.getBytes();
124-
md5.update(data, 0, data.length);
125-
final byte[] hash = md5.digest();
126-
return hash;
117+
final byte[] md5Hash(final String p) {
118+
return digest(p, new MD5Digest());
119+
}
120+
121+
private static byte[] digest(final String s, final GeneralDigest generalDigest) {
122+
final byte[] data = s.getBytes();
123+
generalDigest.update(data, 0, data.length);
124+
125+
final byte[] digest = new byte[generalDigest.getDigestSize()];
126+
generalDigest.doFinal(digest, 0);
127+
return digest;
127128
}
128129

129130

0 commit comments

Comments
 (0)