BouncyCastle issue

 24 Replies
 0 Subscribed to this topic
 27 Subscribed to this forum
Sort:
Author
Messages
brihyn
Veteran Member Send Private Message
Posts: 95
Veteran Member
Having trouble with the BouncyCastle tests.

Pasting the procedure I used to set this up:
a.Copy bcprov-jdk16-145.jar to both D:\IBM\WebSphere\AppServer\java\lib\ext (creating the folder if necessary) and
D:\jdk\jre\lib\ext

b.Copy local_policy.jar and US_export_policy.jar to D:\jdk\jre\lib\security (first renaming the two files in D:\jdk\jre\lib\security to something else for backup purposes)

c. Open the file D:\IBM\WebSphere\AppServer\java\jre\lib\security\java.security with Notepad++ (found in the installs\utils folder).

d. Add a new line after security.provider.3: security.provider.4=org.bouncycastle.jce.provider.BouncyCastleProvider

e. Increment all numbers on the following lines

f. Do the same for D:\jdk\jre\lib\security\java.security

g. Test with the following procedure:
i. Open command prompt window and go to D:\LawsonInstalls\BouncyCastle
ii. Type the following command:
d:\jdk\bin\java.exe –cp bctest-jdk16-145.jar org.bouncycastle.crypto.test.RegressionTest > jdkcrypto.out 2>&1

Below are my java.security settings:
security.provider.1=com.ibm.crypto.provider.IBMJCE
security.provider.2=com.ibm.jsse.IBMJSSEProvider
security.provider.3=com.ibm.jsse2.IBMJSSEProvider2
security.provider.4=org.bouncycastle.jce.provider.BouncyCastleProvider
security.provider.5=com.ibm.security.jgss.IBMJGSSProvider
security.provider.6=com.ibm.security.cert.IBMCertPath
security.provider.7=com.ibm.crypto.pkcs11impl.provider.IBMPKCS11Impl
security.provider.8=com.ibm.security.cmskeystore.CMSProvider
security.provider.9=com.ibm.security.jgss.mech.spnego.IBMSPNEGO
security.provider.10=com.ibm.security.sasl.IBMSASL
security.provider.11=com.ibm.xml.crypto.IBMXMLCryptoProvider
security.provider.12=com.ibm.xml.enc.IBMXMLEncProvider
security.provider.13=org.apache.harmony.security.provider.PolicyProvider

My test results are as follows:
java.lang.NoClassDefFoundError: –cp
Caused by: java.lang.ClassNotFoundException: –cp
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: –cp. Program will exit.
Exception in thread "main"

Ideas? I downloaded the 2 policy files from IBM's site.


John Henley
Send Private Message
Posts: 3351
Make sure you have bctest-jdk16-145.jar in the directory you are testing from (e.g., D:\LawsonInstalls\BouncyCastle).
Also, you might be mixing up the Sun Java JDK and the IBM JDK--they are different and have different ..\java\jre\lib\security\java.security files
So when you are testing the Sun Java, use d:\jdk\bin\java.exe, but when testing IBM's, use D:\IBM\WebSphere\AppServer\java\bin\java.exe
Thanks for using the LawsonGuru.com forums!
John
brihyn
Veteran Member Send Private Message
Posts: 95
Veteran Member
Thanks, John.
I do indeed have the .jar in the file I'm testing from.
I just tried running the java.exe from the IBM/Websphere folder, and ended up with the same results (and I edited both java.security files to include the bouncycastle line)
John Henley
Send Private Message
Posts: 3351
Which java version are you using?
> E:\jdk\bin\java.exe -version
> D:\IBM\WebSphere\AppServer\java\bin\java.exe -version
Thanks for using the LawsonGuru.com forums!
John
brihyn
Veteran Member Send Private Message
Posts: 95
Veteran Member
Pasting so I don't risk losing any of the version info:
D:\LawsonInstalls\BouncyCastle>D:\IBM\WebSphere\AppServer\java\bin\java.exe -version
java version "1.6.0"
Java(TM) SE Runtime Environment (build pwa6460sr7ifix-20100220_01(SR7+IZ70326))
IBM J9 VM (build 2.4, JRE 1.6.0 IBM J9 2.4 Windows Server 2008 amd64-64 jvmwa646
0sr7-20100219_54049 (JIT enabled, AOT enabled)
J9VM - 20100219_054049
JIT - r9_20091123_13891
GC - 20100216_AA)
JCL - 20091202_01

D:\LawsonInstalls\BouncyCastle>d:\jdk\bin\java.exe -version
java version "1.6.0_21"
Java(TM) SE Runtime Environment (build 1.6.0_21-b07)
Java HotSpot(TM) 64-Bit Server VM (build 17.0-b17, mixed mode)
John Henley
Send Private Message
Posts: 3351
Whenever doing a Bouncy Castle install, document and perform entire process first for Sun Java JDK, then the process for IBM WebSphere Java JDK (there are some differences, such as the policy .jar files are different and the java.security entries are different). Your instructions appear to be jumbled/mixed between the two, and that is likely leading to your problems. Also, make sure the version of the bc*.jar files matches which JDK version you are using...ie.. bcprov-jdk16*.jar goes with JDK 1.6; bcprov-jdk15*.jar goes with JDK 1.5, etc.
Thanks for using the LawsonGuru.com forums!
John
brihyn
Veteran Member Send Private Message
Posts: 95
Veteran Member
I'll make the suggested changes, thanks.
However, am I right in assuming the versions are ok based on my last post?
Jimmy Chiu
Veteran Member Send Private Message
Posts: 641
Veteran Member
You should be using the bcprov-ext-jdk16-145.jar.

There are two sets of JCE, one from SUN and one from IBM. they apply to the corresponding JDKs.

Recheck all the steps. You missed something during the install.
brihyn
Veteran Member Send Private Message
Posts: 95
Veteran Member
Edited my procedure as suggested (shown below). I originally only had the IBM JCE...I have downloaded the one from Sun as well, and copied it's files out. I'm getting two slightly different errors tho....

Procedure:
23. Install Bouncy Castle Encryption
a. Copy bcprov-jdk16-145.jar to both D:\IBM\WebSphere\AppServer\java\lib\ext (creating the folder if necessary) and D:\jdk\jre\lib\ext


b. Copy local_policy.jar and US_export_policy.jar from the D:\LawsonInstalls\BouncyCastle\Sun directory to D:\jdk\jre\lib\security (first renaming the two files in D:\jdk\jre\lib\security to something else for backup purposes)

c. Open the file D:\jdk\jre\lib\security\java.security with Notepad++ (found in the installs\utils folder).

d. Add a new line after security.provider.3: security.provider.4=org.bouncycastle.jce.provider.BouncyCastleProvider

e. Increment all numbers on the following lines


f. Copy local_policy.jar and US_export_policy.jar from the D:\LawsonInstalls\BouncyCastle\IBM directory to D:\IBM\WebSphere\AppServer\java\jre\lib\security

g. Open the file D:\IBM\WebSphere\AppServer\java\jre\lib\security\java.security with Notepad++ (found in the installs\utils folder).

h. Add a new line after security.provider.3: security.provider.4=org.bouncycastle.jce.provider.BouncyCastleProvider

i. Increment all numbers on the following lines

j. Create an environment variable named WASJAVA and set it to D:\IBM\WebSphere\AppServer\java\bin


k. Test with the following procedure:
i. Open command prompt window and go to D:\LawsonInstalls\BouncyCastle
ii. Type the following command:
d:\jdk\bin\java.exe –cp bctest-jdk16-145.jar org.bouncycastle.crypto.test.RegressionTest > jdkcrypto1.out 2>&1
iii. Type the following command:
%WASJAVA%\java.exe –cp bctest-jdk16-145.jar org.bouncycastle.crypto.test.RegressionTest > jdkcrypto2.out 2>&1
iv. Both Outfiles may have some errors, bbut must say DESede: Okay

Result from the JDK test:
java.lang.NoClassDefFoundError: –cp
Caused by: java.lang.ClassNotFoundException: –cp
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: –cp. Program will exit.
Exception in thread "main"

Result from the IBM test:
Exception in thread "main" java.lang.NoClassDefFoundError: ?cp
Caused by: java.lang.ClassNotFoundException: ?cp
at java.net.URLClassLoader.findClass(URLClassLoader.java:421)
at java.lang.ClassLoader.loadClass(ClassLoader.java:652)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:346)
at java.lang.ClassLoader.loadClass(ClassLoader.java:618)
Could not find the main class: –cp. Program will exit.

The IBM test was copy/pasted right from my procedure, and I've double-checked that i used -cp, not ?cp

John Henley
Send Private Message
Posts: 3351
Make sure you are copying bcprov-jdk16-145.jar to the correct location.
For example, you have:
Copy bcprov-jdk16-145.jar to D:\IBM\WebSphere\AppServer\java\lib\ext
Should be
Copy bcprov-jdk16-145.jar to D:\IBM\WebSphere\AppServer\java\jre\lib\ext
Thanks for using the LawsonGuru.com forums!
John
John Henley
Send Private Message
Posts: 3351
One other idea; the copy/paste might be the problem, since neither one is working. If you are copy/pasting from Word, the document might have the -cp stored as an emdash instead of a real dash. Try typing in the command without doing the cut/paste,
Thanks for using the LawsonGuru.com forums!
John
brihyn
Veteran Member Send Private Message
Posts: 95
Veteran Member
Ahh, progress.
John-
both of your posts were correct. I had the file in the wrong directory in IBM and I think the copy/paste was also a culprit. Here's the errors I get now:

SUN:
java.lang.NoClassDefFoundError: org/bouncycastle/crypto/DataLengthException
at org.bouncycastle.crypto.test.RegressionTest.(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.bouncycastle.crypto.DataLengthException
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 1 more
Could not find the main class: org.bouncycastle.crypto.test.RegressionTest. Program will exit.
Exception in thread "main"

IBM:
Exception in thread "main" java.lang.NoClassDefFoundError: org.bouncycastle.crypto.engines.IDEAEngine
at org.bouncycastle.crypto.test.IDEATest.(Unknown Source)
at java.lang.J9VMInternals.initializeImpl(Native Method)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:200)
at org.bouncycastle.crypto.test.RegressionTest.(Unknown Source)
at java.lang.J9VMInternals.initializeImpl(Native Method)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:200)
Caused by: java.lang.ClassNotFoundException: org.bouncycastle.crypto.engines.IDEAEngine
at java.net.URLClassLoader.findClass(URLClassLoader.java:421)
at java.lang.ClassLoader.loadClass(ClassLoader.java:652)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:346)
at java.lang.ClassLoader.loadClass(ClassLoader.java:618)
... 6 more
Could not find the main class: org.bouncycastle.crypto.test.RegressionTest. Program will exit
John Henley
Send Private Message
Posts: 3351
Are you getting these on the jce tests?
if so I think you have bad JCE Sun / IBM policy .jar files
Thanks for using the LawsonGuru.com forums!
John
brihyn
Veteran Member Send Private Message
Posts: 95
Veteran Member
It's definitely possibly...I had a bit of trouble finding them, however they were both downloaded from respective sites (IBM.com/Sun's site).
Would someone have links to the correct downloads just so I know I have the correct ones?
Jeff White
Veteran Member Send Private Message
Posts: 83
Veteran Member
Just wondering if you are using the "unrestricted.zip" file for the Websphere side?

Jeff
brihyn
Veteran Member Send Private Message
Posts: 95
Veteran Member
Just verified and yes, I felt a bit more confident on the IBM file, and it was indeed the unrestricted.zip.
Jimmy Chiu
Veteran Member Send Private Message
Posts: 641
Veteran Member
IBM JCE links (works i just tested), you will need to create an IBM profile to download

https://www14.software.ib...gin.do?source=jcesdk
brihyn
Veteran Member Send Private Message
Posts: 95
Veteran Member
Still getting the same error running the IBM Java.exe. Just to confirm, I just need to drop the 2 jar files into the directory..no running or configuring from there, correct?
I'm just about to the point of having our Systems team relaod this virtual back to the original state before I installed anything...WAS is still not working correctly, and at this point I'm thinking there were too many minor configuration issues that are probably now all snowballing to cause me all sorts of issues, but I'd still love to figure this piece out before I get to that point
brihyn
Veteran Member Send Private Message
Posts: 95
Veteran Member
Almost there. The IBM side was failing because I was using bcprov-jdk16-145.jar instead of bcprov-ext-jdk16-145.jar. I now get an ok test on the IBM side, but the JDK side is still failing with
java.lang.NoClassDefFoundError: org/bouncycastle/crypto/DataLengthException
at org.bouncycastle.crypto.test.RegressionTest.(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.bouncycastle.crypto.DataLengthException
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 1 more
Could not find the main class: org.bouncycastle.crypto.test.RegressionTest. Program will exit.
Exception in thread "main"

I have the jar files copied to D:\JDK\jre\lib\ext
Could this be the issue? any other ideas? I'm getting so close, I'd really like to put this issue to rest.
-Brian Hynes
brihyn
Veteran Member Send Private Message
Posts: 95
Veteran Member
And, I guess, is this indeed the correct command for testing on the JDK side?
d:\jdk\bin\java.exe –cp bctest-jdk16-145.jar org.bouncycastle.crypto.test.RegressionTest > jdkcrypto1.txt 2>&1
Jimmy Chiu
Veteran Member Send Private Message
Posts: 641
Veteran Member
when you do a "where java" in command prompt, what do you see?

Also, when you install Sun JDK 1.6.0.21, it installs JDK and JRE. Apply BC to both of them and test again.
brihyn
Veteran Member Send Private Message
Posts: 95
Veteran Member
where java gives d:\jdk\bin
c:\windows\system32\
and
d:\jdk\jre\bin

Where should the .jar file be on the jdk side? d:\jdk\lib\ext? (ext doesn't exist by default)
Jimmy Chiu
Veteran Member Send Private Message
Posts: 641
Veteran Member
When i install Sun JDK. I usually specify D:\JDK for the jdk install. Then the second part of the install for JRE I usually specify D:\JRE for example, so it would be clear.

Then I would set:
JAVA_HOME = D:\JDK
LAW_JAVA_BIN = D:\JDK\bin etc

After that, put bcprov-ext-jdk16-145.jar in:
D:\JDK\jre\lib\ext (this location is for the JDK install)
D:\JRE\lib\ext (this location is for the JRE install)

put your sun JCE files (local_policy.jar/US_export_policy.jar) in:
D:\JDK\jre\lib\security
D:\JRE\lib\security

modify the java.security files in:
D:\JDK\jre\lib\security
D:\JRE\lib\security

under your PATH variables in system properties:
D:\JDK\bin should come BEFORE
c:\windows\system32 and d:\jdk\jre\bin
brihyn
Veteran Member Send Private Message
Posts: 95
Veteran Member
just figured it out...
I don't know if this is because i'm on a 64 bit server, but that's my hunch...
In D:\jdk, I have both a JRE folder and JRE6 folder. I made all of the changes that I was previously making in JRE also in JRE6. The tests now work successfully.
Thanks to everyone for helping!
Jimmy Chiu
Veteran Member Send Private Message
Posts: 641
Veteran Member
Your JRE folder is the first part of the JDK install, then you probably specified JRE6 for your JRE install. That's why.