views:

788

answers:

2

Hi,

Trying to request a timestamp (RFC 3161) by using BouncyCastle and connecting to http://timestamping.edelweb.fr/service/tsp. I do get a TimestampResponse back from the server but it seems to be without an actual date.

This is the code:

public static void main(String[] args) {
    String ocspUrl = "http://timestamping.edelweb.fr/service/tsp";
    byte[] digest = "hello".getBytes();
    OutputStream out = null;

    try {
        TimeStampRequestGenerator reqgen = new TimeStampRequestGenerator();
        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();

        if (con.getResponseCode() != HttpURLConnection.HTTP_OK) {
            throw new IOException("Received HTTP error: " + con.getResponseCode() + " - " + con.getResponseMessage());
        }
        InputStream in = con.getInputStream();
        TimeStampResp resp = TimeStampResp.getInstance(new ASN1InputStream(in).readObject());
        TimeStampResponse response = new TimeStampResponse(resp);
        response.validate(req);
        System.out.println(response.getTimeStampToken().getTimeStampInfo().getGenTime());
    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

Here is the question(s): Has anyone used Bouncycastle's library for timestamps and happens to know about the different status codes and what they mean? Or just in general why this wont seem to work.

This line where I expect to see a date just throws a NullPointer:

System.out.println(response.getTimeStampToken().getTimeStampInfo().getGenTime());

Does anyone know of any other RFC 3161 compliant timestamp servers that are free?

If you would like to run the code you need the bouncycastle jars which can be downloaded from here. You will need: provider, mail, tsp.

Thanks

+1  A: 

I found this site which is a rather good resource for Timestamps and it also has a list of servers and at least a few of them seems to still be operational.

willcodejavaforfood
A: 

The problem seems to be that the content is of the wrong format/length.

TimeStampRequest req = reqgen.generate(TSPAlgorithms.SHA1, digest);

But what I sent in was just:

"hello".getBytes();

Creating a proper SHA1Digest from 'hello' and this work just fine.

static public byte[] calculateMessageDigest()
  throws NoSuchAlgorithmException, IOException {
 SHA1Digest md = new SHA1Digest();

 byte[] dataBytes = "helloooooooooooooo".getBytes();
 int nread = dataBytes.length;
 md.update(dataBytes, 0, nread);
 byte[] result = new byte[32];
 md.doFinal(result, 0);
 return result;

I also ended up using Digistamp as my TSA since they support http authentication which was a requirement.

willcodejavaforfood