Bouncy Castle

anyone using the lib? do I need to add the whole library if I only need to use one algorithm for encrypting a binary file?

[129 byte] By [Morninga] at [2007-11-27 10:51:55]
# 1

at morning I saw the name bouncy castle in forum. but I didn't know what it was.

but know I no.

I'm nowgoing to use it. I have a pdf from nokia showing a sample which uses bouncy castle. read this! it whould help you.

The size of the Bouncy Castle JAR file for J2ME is about 530 kilobytes. The size is due to the large number of ciphers, digests, and utility classes implemented in Bouncy Castle. Since one would normally use only one or two of those algorithms, obfuscation is a very effective means to reduce the size of the MIDlets JAR file.

One commonly used obfuscator is Proguard, which is very effective in reducing the size of the JAR file by removing unnecessary classes and methods. Proguard has been incorporated into Suns Wireless Toolkit, but the default obfuscation parameters are not adequate for processing the Bouncy Castle API.

The obfuscation of Bouncy Castle presents some special challenges. In particular, some of the algorithms require Java classes that are not available in CLDC. Examples of this are the java.security.SecureRandom and java.math.BigInteger classes. To solve this problem, Bouncy Castles J2ME version ships with implementation of those classes for J2ME. This creates an important difficulty because MIDP implementation should reject classes that are under the java and javax packages for security reasons.

Obfuscation with Proguard doesnt necessarily solve this problem, since package names are preserved. For example, the java.security.SecureRandom class will become java.security.a and the device will reject it anyway. Proguard offers a solution the defaultpackage option. This option will move all the classes to a specific package or remove the package name altogether. It should be noted that by using the defaultpackage option the MIDlet main class package name will change. The JAD and MANIFEST files must reflect this to work properly.

If it becomes necessary to unpack the already obfuscated JAR file (for instance, for preverification), it is also wise to use the dontusemixedcaseclassnames option. Otherwise, Proguard may rename the classes using letters in upper- and lowercases like a and A, when it runs out of names. This may happen when obfuscating Bouncy Castle because of the large number of classes involved. Mixed-case classes are legal but there can be problems when unpacking the file in operating systems that dont distinguish files with different cases.

Below is a possible Proguard configuration file that will correctly obfuscate Bouncy Castle:

-libraryjars midpapi.zip

-injars EncryptedSMS.jar

-outjar EncryptedSMS_o.jar

-keep -keep public class * extends javax.microedition.midlet.MIDlet

-defaultpackage

-dontusemixedcaseclassnames

etaa at 2007-7-29 11:34:20 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 2

> anyone using the lib?

There are many using this one... u can find its popularity only by searching it in this forum.

> do I need to add the whole

> library if I only need to use one algorithm for

> encrypting a binary file?

No way, it will make ur application unacceptably big.

Rather, identify only the required classes for the encryption u are using. If u keep the class files in the lib folder in your project (if using WTK), invoking Proguard directly and providing the necessary settings may also help to reduce the unwanted classes from the obfuscated jar. U can find some help from here : https://www6.software.ibm.com/developerworks/education/wi-encrypt/

Remember one thing, BouncyCastle uses some core java classes and it have those classes in the lib, but a cldc/midp device does not recognize any package starting with java or javax, so the application have to be obfuscated at the highest level.

find_suvro@SDNa at 2007-7-29 11:34:20 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 3

thanks for the reply! I went to ibm site, it requires login? I am using netbean, when I obfuscate with following arguments, it gave warning messages

Obfuscator arguments:

-dontusemixedcaseclassnames

-defaultpackage ''

-overloadaggressively

-keep public class ** extends javax.microedition.midlet.MIDlet {

public *;

}

Warning: org.bouncycastle.math.ec.IntArray: can't find referenced method 'java.lang.Object clone()' in class java.lang.Object

Warning: there were 1 unresolved references to program class members.

Your input classes appear to be inconsistent.

You may need to recompile them and try again.

Morninga at 2007-7-29 11:34:20 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 4

> thanks for the reply! I went to ibm site, it requires

> login?

well... u can register urself there... its free....

I am using netbean, when I obfuscate with

> following arguments, it gave warning messages

>

> Obfuscator arguments:

>-dontusemixedcaseclassnames

> -defaultpackage ''

>-overloadaggressively

> -keep public class ** extends

> javax.microedition.midlet.MIDlet {

> public *;

>

>

> Warning: org.bouncycastle.math.ec.IntArray: can't

> find referenced method 'java.lang.Object clone()' in

> class java.lang.Object

> Warning: there were 1 unresolved references to

> program class members.

> Your input classes appear to be

> inconsistent.

> You may need to recompile them and try again.

And this I don't no why this is giving 'cuz I never did have any this kind of error... make it sure that u have the latest release... may be u should download the jar once more..

tell me how are u doing this means just adding the jar as library to the project or u are deploying the class files with your project ?

find_suvro@SDNa at 2007-7-29 11:34:20 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 5

I gave some errors to and I don't know now that this was one of them or not.

but net beans offered that if you want you can Ignore warnings by a command like -ignorewarnings(may be).

I did that and successfully obfuscated bouncy castle. to a jar with 21 kb size

the program will run but I don't know if it is possible to have some errors in run time because of that ignorance.

any one knows something

etaa at 2007-7-29 11:34:20 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 6

Test your app on the real device. That is the best way to know this.

find_suvro@SDNa at 2007-7-29 11:34:20 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 7

are you with me?

what do you mean by testing? do you say that if the midlet starts up, there will be no error?

etaa at 2007-7-29 11:34:20 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 8

In ur previous post u told that u have successfully make the jar ignoring the warnings. By testing I mean to say that deploy that in the device, if it is successfully installed, u are thru the first step (preverification on the phone). Then start the app, do the necessary actions and then if u have the required output, it is a success, otherwise ur jar is missing something.

Now let me tell u, I have so far only done a hex and a triple DES encryption with it and so far so good: no errors at all with bouncycastle (only first time I got an authentication failure error as it was not properly obfuscated).

And also make it sure u are using the lightweight version of it i.e. version for J2ME CLDC devices.

find_suvro@SDNa at 2007-7-29 11:34:20 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 9

ok! then I must test all possible inputs and outputs.

and my bouncy castle version is the one you said.

something else

when I obfuscate my project using net beans.my jad file and jar's manifest file will not contain the midlet name although I had kept the midlet clas name using -keep option.

this meens I can't debug my program.

any way to solve it?

etaa at 2007-7-29 11:34:20 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 10

Strange !!! What else can I say...

If u are using the default highest level obfuscation supplied by Netbeans, this is the supplied settings : Obfuscator arguments:

-dontusemixedcaseclassnames

-defaultpackage ''

-overloadaggressively

-keep public class ** extends javax.microedition.midlet.MIDlet {

public *;

}

Well mine was in a package and it remains there after obfuscation. May be you can give it a try.

find_suvro@SDNa at 2007-7-29 11:34:20 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 11

how angry!!!

I have did it for the first time. It didn't work.

I did it again for ensurance.

it works!!!!

I can just say :

Excuse me

etaa at 2007-7-29 11:34:20 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 12

No!

my main project was another one.

it is yet giving errors.

forget it. I will found some way

etaa at 2007-7-29 11:34:20 > top of Java-index,Java Mobility Forums,Java ME Technologies...