时间戳响应不正确 - BouncyCastle

发布于 2024-07-21 19:01:52 字数 2184 浏览 3 评论 0原文

尝试使用 BouncyCastle 请求时间戳(RFC 3161)并连接到 http://timestamping.edelweb.fr /服务/茶匙。 我确实从服务器返回了 TimestampResponse,但它似乎没有实际日期。

这是代码:

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();
    }
}

这是问题: 有没有人使用 Bouncycastle 的时间戳库并且碰巧知道不同的状态代码及其含义? 或者只是一般来说为什么这似乎不起作用。

我希望看到日期的这一行只是抛出一个 NullPointer:

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

有谁知道任何其他免费的符合 RFC 3161 的时间戳服务器吗?

如果您想运行代码,则需要 bouncycastle jar,可以从此处下载。 您将需要:提供商、邮件、茶匙。

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

小…楫夜泊 2024-07-28 19:01:52

分析与wireshark的通信,此示例给出了“错误消息摘要”错误。
对我有用的摘要代码是:

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

Analyzing communication with wireshark, this example gives me a "bad message digest" error.
A digest code that works for me is:

    MessageDigest messageDigest = MessageDigest.getInstance("SHA-1");
    messageDigest.update("messageImprint".getBytes());
    byte[] digest = messageDigest.digest();
醉南桥 2024-07-28 19:01:52

我发现这个网站是一个相当好的时间戳资源,它还有一个服务器列表和至少其中一些似乎仍在运行。

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.

谈下烟灰 2024-07-28 19:01:52

问题似乎是内容的格式/长度错误。

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

但我发送的只是:

"hello".getBytes();

从“hello”创建一个正确的 SHA1Digest,并且工作得很好。

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 身份验证,这是一项要求。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文