时间戳响应不正确 - BouncyCastle

尝试使用BouncyCastle并连接到http://timestamping.edelweb.fr/service/tsp来请求时间戳(RFC 3161)。我确实从服务器返回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罐子。您将需要:提供者,邮件,茶匙。 谢谢     
已邀请:
分析与wireshark的通信,这个例子给我一个“错误的消息摘要”错误。 适合我的摘要代码是:
    MessageDigest messageDigest = MessageDigest.getInstance("SHA-1");
    messageDigest.update("messageImprint".getBytes());
    byte[] digest = messageDigest.digest();
    
问题似乎是内容格式/长度错误。
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认证,这是一项要求。     
我发现这个站点对于Timestamps来说是一个相当不错的资源,它还有一个服务器列表,其中至少有一些似乎仍在运行。     

要回复问题请先登录注册