The timestamp response is incorrect - BouncyCastle

Trying to request a timestamp (RFC 3161) using a BouncyCastle and connecting to http://timestamping.edelweb.fr/service/tsp . I get a TimestampResponse back from the server, but it seems to have no 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 the Bouncycastle library for timestamps and found out about different status codes and what they mean? Or just in general, why this usually doesn't work.

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

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

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

, bouncycastle, . : , , tsp.

+3
3

, /.

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

, , :

"hello".getBytes();

SHA1Digest 'hello', .

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;

Digistamp TSA, HTTP-, .

+1

wirehark, " ". , , :

    MessageDigest messageDigest = MessageDigest.getInstance("SHA-1");
    messageDigest.update("messageImprint".getBytes());
    byte[] digest = messageDigest.digest();
+3

I found this site, which is a pretty good resource for Timestamps, and also has a list of servers, and at least some of them seem to still work.

0
source

Source: https://habr.com/ru/post/1709175/


All Articles