I am trying to implement a timestamp request as seen here: http://bouncy-castle.1462172.n4.nabble.com/Timestamp-request-and-response-td1558231.html In j2se it works fine, but on android I get an IllegalAccessError. Logcat output :
FATAL EXCEPTION: main
java.lang.IllegalAccessError: tried to access method org.bouncycastle.asn1.DERBoolean.<init>:(Z)V from class org.bouncycastle.tsp.TimeStampRequestGenerator
at org.bouncycastle.tsp.TimeStampRequestGenerator.setCertReq(Unknown Source)
at org.ats.ats.onCreate(ats.java:30)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
at android.app.ActivityThread.access$2300(ActivityThread.java:125)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)
W/ActivityManager( 59): Force finishing activity org.ats/.ats
It is necessary for me to ask for the Certificate in the TSResponse. Android api is 2.2 My code:
TimeStampRequestGenerator reqgen = new TimeStampRequestGenerator();
reqgen.setCertReq(true);
MessageDigest messageDigest = MessageDigest.getInstance("SHA-1");
messageDigest.update("messageImprint".getBytes());
byte[] digest = messageDigest.digest();
String ocspUrl = "http://egtstamp.egroup.hu:80/tsa";
OutputStream out = null;
TimeStampRequest req = reqgen.generate(TSPAlgorithms.SHA1, digest);
byte request[] = req.getEncoded();
URL url = new URL(ocspUrl);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setDoOutput(true);
con.setDoInput(true);
con.setRequestMethod("POST");
con.setRequestProperty("Content-type", "application/timestamp-query");
con.setRequestProperty("Content-length", String.valueOf(request.length));
out = con.getOutputStream();
out.write(request);
out.flush();