Solved

Paypal encryption buttons: Java error:

Posted on 2014-01-18
7
1,335 Views
Last Modified: 2016-03-24
Hi,

I'm trying to run some shell program but I get the errors:

bash build-app2.sh

Be sure Java version is at least 1.4
java version "1.7.0_25"
OpenJDK Runtime Environment (rhel-2.3.10.5.el5_9-i386)
OpenJDK Client VM (build 23.7-b01, mixed mode)


CLASSPATH=
.:/home/myultrat/ssl/paypal/crypto-150/jars/bcprov-jdk14-124.jar:/home/myultrat/ssl/paypal/crypto-150/jars/bcpg-jdk14-124.jar:/home/myultrat/ssl/paypal/crypto-150/jars/bctest-jdk14-124.jar:/home/myultrat/ssl/paypal/crypto-150/jars/bcmail-jdk14-124.jar

compiling java files ...
ButtonEncryption.java:16: error: package org.bouncycastle.cms does not exist
import org.bouncycastle.cms.CMSException;
                           ^
com/paypal/crypto/sample/ClientSide.java:26: error: package org.bouncycastle.cms does not exist
import org.bouncycastle.cms.CMSEnvelopedData;
                           ^
com/paypal/crypto/sample/ClientSide.java:27: error: package org.bouncycastle.cms does not exist
import org.bouncycastle.cms.CMSEnvelopedDataGenerator;
                           ^
com/paypal/crypto/sample/ClientSide.java:28: error: package org.bouncycastle.cms does not exist
import org.bouncycastle.cms.CMSException;
                           ^
com/paypal/crypto/sample/ClientSide.java:29: error: package org.bouncycastle.cms does not exist
import org.bouncycastle.cms.CMSProcessableByteArray;
                           ^
com/paypal/crypto/sample/ClientSide.java:30: error: package org.bouncycastle.cms does not exist
import org.bouncycastle.cms.CMSSignedData;
                           ^
com/paypal/crypto/sample/ClientSide.java:31: error: package org.bouncycastle.cms does not exist
import org.bouncycastle.cms.CMSSignedDataGenerator;
                           ^
com/paypal/crypto/sample/ClientSide.java:32: error: package org.bouncycastle.openssl does not exist
import org.bouncycastle.openssl.PEMReader;
                               ^
com/paypal/crypto/sample/ClientSide.java:33: error: package org.bouncycastle.util.encoders does not exist
import org.bouncycastle.util.encoders.Base64;
                                     ^
com/paypal/crypto/sample/ClientSide.java:67: error: cannot find symbol
                        CMSException
                        ^
  symbol:   class CMSException
  location: class ClientSide
ButtonEncryption.java:32: error: package org.bouncycastle.jce.provider does not exist
                Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
                                                                      ^
ButtonEncryption.java:116: error: cannot find symbol
                catch (CMSException e)
                       ^
  symbol:   class CMSException
  location: class ButtonEncryption
com/paypal/crypto/sample/ClientSide.java:94: error: cannot find symbol
                CMSSignedDataGenerator signedGenerator = new CMSSignedDataGenerator();
                ^
  symbol:   class CMSSignedDataGenerator
  location: class ClientSide
com/paypal/crypto/sample/ClientSide.java:94: error: cannot find symbol
                CMSSignedDataGenerator signedGenerator = new CMSSignedDataGenerator();
                                                             ^
  symbol:   class CMSSignedDataGenerator
  location: class ClientSide
com/paypal/crypto/sample/ClientSide.java:96: error: cannot find symbol
                signedGenerator.addSigner( privateKey, certificate, CMSSignedDataGenerator.DIGEST_SHA1 );
                                                                    ^
  symbol:   variable CMSSignedDataGenerator
  location: class ClientSide
com/paypal/crypto/sample/ClientSide.java:103: error: cannot find symbol
                CMSProcessableByteArray cmsByteArray = new CMSProcessableByteArray(data);
                ^
  symbol:   class CMSProcessableByteArray
  location: class ClientSide
com/paypal/crypto/sample/ClientSide.java:103: error: cannot find symbol
                CMSProcessableByteArray cmsByteArray = new CMSProcessableByteArray(data);
                                                           ^
  symbol:   class CMSProcessableByteArray
  location: class ClientSide
com/paypal/crypto/sample/ClientSide.java:108: error: cannot find symbol
                CMSSignedData signedData = signedGenerator.generate(cmsByteArray, true, "BC");
                ^
  symbol:   class CMSSignedData
  location: class ClientSide
com/paypal/crypto/sample/ClientSide.java:112: error: cannot find symbol
                CMSEnvelopedDataGenerator envGenerator = new CMSEnvelopedDataGenerator();
                ^
  symbol:   class CMSEnvelopedDataGenerator
  location: class ClientSide
com/paypal/crypto/sample/ClientSide.java:112: error: cannot find symbol
                CMSEnvelopedDataGenerator envGenerator = new CMSEnvelopedDataGenerator();
                                                             ^
  symbol:   class CMSEnvelopedDataGenerator
  location: class ClientSide
com/paypal/crypto/sample/ClientSide.java:114: error: cannot find symbol
                CMSEnvelopedData envData = envGenerator.generate( new CMSProcessableByteArray(signed),
                ^
  symbol:   class CMSEnvelopedData
  location: class ClientSide
com/paypal/crypto/sample/ClientSide.java:114: error: cannot find symbol
                CMSEnvelopedData envData = envGenerator.generate( new CMSProcessableByteArray(signed),
                                                                      ^
  symbol:   class CMSProcessableByteArray
  location: class ClientSide
com/paypal/crypto/sample/ClientSide.java:115: error: cannot find symbol
                                CMSEnvelopedDataGenerator.DES_EDE3_CBC, "BC" );
                                ^
  symbol:   variable CMSEnvelopedDataGenerator
  location: class ClientSide
com/paypal/crypto/sample/ClientSide.java:129: error: cannot find symbol
                byte[] stringBytes = Base64.encode(bytes);
                                     ^
  symbol:   variable Base64
  location: class ClientSide
Note: com/paypal/crypto/sample/ClientSide.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
24 errors
Done!!!!!

Open in new window



The bouncycastle files are in the paths of this file.

Here's the code:

#!/bin/bash

#export CRYPTO_HOME="/x/home/dhan/java_client/crypto-124"
export CRYPTO_HOME="/home/myultrat/ssl/paypal/crypto-150"

if [ ! -d ${CRYPTO_HOME} ]; then
	echo cannot find crypto distribution ...
	return 1;
fi

CLASSPATH="."
CLASSPATH="$CLASSPATH:$CRYPTO_HOME/jars/bcprov-jdk14-124.jar"
CLASSPATH="$CLASSPATH:$CRYPTO_HOME/jars/bcpg-jdk14-124.jar"
CLASSPATH="$CLASSPATH:$CRYPTO_HOME/jars/bctest-jdk14-124.jar"
CLASSPATH="$CLASSPATH:$CRYPTO_HOME/jars/bcmail-jdk14-124.jar"
export CLASSPATH

#JAVA=/x/contrib/j2sdk1.4.0/bin/java
#JAVAC=/x/contrib/j2sdk1.4.0/bin/javac
#JAR=/x/contrib/j2sdk1.4.0/bin/jar

JAVA=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.25/bin/java
JAVAC=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.25/bin/javac
JAR=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.25/bin/jar

echo
echo "Be sure Java version is at least 1.4"
$JAVA -version
echo ; echo ; #sleep 3


echo "CLASSPATH="
echo $CLASSPATH
echo

echo compiling java files ...
$JAVAC -g -classpath "$CLASSPATH" 	                \
	ButtonEncryption.java	\
	com/paypal/crypto/sample/*.java

echo "Done!!!!!"

Open in new window


What's wrong with the code or my paths?

Thank you,
Victor
0
Comment
Question by:Victor Kimura
  • 4
  • 3
7 Comments
 

Author Comment

by:Victor Kimura
ID: 39790657
I noticed in the ButtonEncryption.java file the import packages are listed as:

import com.paypal.crypto.sample.*;

import java.io.*;
import java.security.InvalidAlgorithmParameterException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.Security;
import java.security.UnrecoverableKeyException;
import java.security.cert.CertStoreException;
import java.security.cert.CertificateException;
import org.bouncycastle.cms.CMSException;

Open in new window


Is there a way for me to download the:
package org.bouncycastle.cms
manually and then compile. If so, how?

I see in the bouncycastle site docs that package is described:
http://www.bouncycastle.org/docs/pkixdocs1.5on/index.html

The ClientSide.java file has other problems.

These are the import statements for this file:

 */
package com.paypal.crypto.sample;

import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.security.InvalidAlgorithmParameterException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.PrivateKey;
import java.security.UnrecoverableKeyException;
import java.security.cert.CertStore;
import java.security.cert.CertStoreException;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.CollectionCertStoreParameters;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Enumeration;

import org.bouncycastle.cms.CMSEnvelopedData;
import org.bouncycastle.cms.CMSEnvelopedDataGenerator;
import org.bouncycastle.cms.CMSException;
import org.bouncycastle.cms.CMSProcessableByteArray;
import org.bouncycastle.cms.CMSSignedData;
import org.bouncycastle.cms.CMSSignedDataGenerator;
import org.bouncycastle.openssl.PEMReader;
import org.bouncycastle.util.encoders.Base64;

Open in new window

ButtonEncryption.java
ClientSide.java
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 500 total points
ID: 39790665
Your paths are incomplete. CMSException you might find should be in a jar with the prefix 'bcpkix'
0
 

Author Comment

by:Victor Kimura
ID: 39791523
@CEHJ, thank you! I noticed since you told me that that my filenames were incorrect.

So I corrected them.

I'm down to 6 errors. Something about package org.bouncycastle.openssl error. Where do I get this package?

bash build-app4.sh
Be sure Java version is at least 1.4
java version "1.7.0_25"
OpenJDK Runtime Environment (rhel-2.3.10.5.el5_9-i386)
OpenJDK Client VM (build 23.7-b01, mixed mode)


CLASSPATH=
.:/home/myultrat/ssl/paypal/crypto-150/jars/bcprov-jdk15on-150.jar:/home/myultrat/ssl/paypal/crypto-150/jars/bcpg-jdk15on-150.jar:/home/myultrat/ssl/paypal/crypto-150/jars/bctest-jdk15on-150.jar:/home/myultrat/ssl/paypal/crypto-150/jars/bcmail-jdk15on-150.jar:/home/myultrat/ssl/paypal/crypto-150/jars/bcpkix-jdk15on-150.jar:/home/myultrat/ssl/paypal/crypto-150/jars/bcprov-debug-jdk15on-150.jar:/home/myultrat/ssl/paypal/crypto-150/jars/bcprov-ext-debug-jdk15on-150.jar:/home/myultrat/ssl/paypal/crypto-150/jars/bcprov-ext-jdk15on-150.jar
compiling java files ...
com/paypal/crypto/sample/ClientSide.java:32: error: cannot find symbol
import org.bouncycastle.openssl.PEMReader;
                               ^
  symbol:   class PEMReader
  location: package org.bouncycastle.openssl
com/paypal/crypto/sample/ClientSide.java:96: error: cannot find symbol
                signedGenerator.addSigner( privateKey, certificate, CMSSignedDataGenerator.DIGEST_SHA1 );
                               ^
  symbol:   method addSigner(PrivateKey,X509Certificate,String)
  location: variable signedGenerator of type CMSSignedDataGenerator
com/paypal/crypto/sample/ClientSide.java:101: error: cannot find symbol
                signedGenerator.addCertificatesAndCRLs(certStore);
                               ^
  symbol:   method addCertificatesAndCRLs(CertStore)
  location: variable signedGenerator of type CMSSignedDataGenerator
com/paypal/crypto/sample/ClientSide.java:108: error: no suitable method found for generate(CMSProcessableByteArray,boolean,String)
                CMSSignedData signedData = signedGenerator.generate(cmsByteArray, true, "BC");
                                                          ^
    method CMSSignedDataGenerator.generate(CMSTypedData,boolean) is not applicable
      (actual and formal argument lists differ in length)
    method CMSSignedDataGenerator.generate(CMSTypedData) is not applicable
      (actual and formal argument lists differ in length)
com/paypal/crypto/sample/ClientSide.java:113: error: cannot find symbol
                envGenerator.addKeyTransRecipient(payPalCert);
                            ^
  symbol:   method addKeyTransRecipient(X509Certificate)
  location: variable envGenerator of type CMSEnvelopedDataGenerator
com/paypal/crypto/sample/ClientSide.java:114: error: method generate in class CMSEnvelopedDataGenerator cannot be applied to given types;
                CMSEnvelopedData envData = envGenerator.generate( new CMSProcessableByteArray(signed),
                                                       ^
  required: CMSTypedData,OutputEncryptor
  found: CMSProcessableByteArray,String,String
  reason: actual and formal argument lists differ in length
Note: com/paypal/crypto/sample/ClientSide.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
6 errors
Done!!!!!

Open in new window


Here's my build-app4.sh code:

#!/bin/bash

#export CRYPTO_HOME="/x/home/dhan/java_client/crypto-124"
export CRYPTO_HOME=/home/myultrat/ssl/paypal/crypto-150

if test ! -d $CRYPTO_HOME; then
	echo cannot find crypto distribution ...
	return 1;
fi

CLASSPATH="."
CLASSPATH="$CLASSPATH:$CRYPTO_HOME/jars/bcprov-jdk15on-150.jar"
CLASSPATH="$CLASSPATH:$CRYPTO_HOME/jars/bcpg-jdk15on-150.jar"
CLASSPATH="$CLASSPATH:$CRYPTO_HOME/jars/bctest-jdk15on-150.jar"
CLASSPATH="$CLASSPATH:$CRYPTO_HOME/jars/bcmail-jdk15on-150.jar"
CLASSPATH="$CLASSPATH:$CRYPTO_HOME/jars/bcpkix-jdk15on-150.jar"
CLASSPATH="$CLASSPATH:$CRYPTO_HOME/jars/bcprov-debug-jdk15on-150.jar"
CLASSPATH="$CLASSPATH:$CRYPTO_HOME/jars/bcprov-ext-debug-jdk15on-150.jar"
CLASSPATH="$CLASSPATH:$CRYPTO_HOME/jars/bcprov-ext-jdk15on-150.jar"
export CLASSPATH

#JAVA=/x/contrib/j2sdk1.4.0/bin/java
#JAVAC=/x/contrib/j2sdk1.4.0/bin/javac
#JAR=/x/contrib/j2sdk1.4.0/bin/jar

JAVA=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.25/bin/java
JAVAC=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.25/bin/javac
JAR=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.25/bin/jar
export JAVA
export JAVAC
export JAR

echo "Be sure Java version is at least 1.4"
$JAVA -version
echo ; echo ; #sleep 3

echo "CLASSPATH="
echo $CLASSPATH

echo compiling java files ...
$JAVAC -g -classpath "$CLASSPATH" 	                \
	ButtonEncryption.java	\
	com/paypal/crypto/sample/*.java

echo "Done!!!!!"

Open in new window


Attaching as a file too.
build-app4.sh
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 39792059
 symbol:   method addCertificatesAndCRLs(CertStore)
  location: variable signedGenerator of type CMSSignedDataGenerator
com/paypal/crypto/sample/ClientSide.java:108: error: no suitable method found for generate(CMSProcessableByteArray,boolean,String)
                CMSSignedData signedData = signedGenerator.generate(cmsByteArray, true, "BC");
                                             

Open in new window

That i'm afraid, is quite serious. I would guess that code is tied to the very specific version of the Bouncy Castle api that is in your examples. I looked for that very specific version on the BC site briefly and couldn't find it. You might have to contact them to get that exact version. The version you're currently using is incompatible.

Of course, my comments are based on the assumption that the code you've got did actually compile with the correct dependencies at the time it was written.

If the above solution proves impossible, the only other solution (if you can find updated code) is to update the code yourself using the current BC api. This would be better in the long run
0
 

Assisted Solution

by:Victor Kimura
Victor Kimura earned 0 total points
ID: 39794361
@CEHJ, Thanks!

I posted on the bouncycastle mailing list and this is the response. It's what you said too and they just confirmed deprecated code. I don't know why Paypal posts stuff that is deprecated though. Spent a fair bit of time to figure that Paypal's code contains deprecated methods.

----

It’s deprecated according to this, I’d check your implementation and update it to work with PEMParser instead of PEMReader.
 
http://www.bouncycastle.org/docs/pkixdocs1.3/org/bouncycastle/openssl/PEMReader.html

----

Knew I missed one somewhere... for the most part the class was deleted as part of the deprecation clean up in the bcpkix package.

Will's response is otherwise correct though, use PEMParser instead. You can find examples of use of it in:

org.bouncycastle.openssl.test.ParserTest

if you need further help.

Regards,

David Hook

---
0
 

Author Closing Comment

by:Victor Kimura
ID: 39808420
response from bouncycastle mailing list added.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 39808487
:)

Well done to you for documenting the response from the BC people

Badly done to Paypal for not updating their BC code !
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now