代码之家  ›  专栏  ›  技术社区  ›  willcodejavaforfood

时间戳响应不正确-BouncyCastle

  •  3
  • willcodejavaforfood  · 技术社区  · 15 年前

    尝试使用BouncyCastle并连接到请求时间戳(RFC 3161) http://timestamping.edelweb.fr/service/tsp . 我确实从服务器得到了一个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的库作为时间戳,并且碰巧知道不同的状态码及其含义?或者只是一般来说,为什么这似乎不起作用。

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

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

    here . 您将需要:提供商、邮件、tsp。

    谢谢

    3 回复  |  直到 13 年前
        1
  •  3
  •   endre    13 年前

    在分析与wireshark的通信时,本例给出了一个“错误消息摘要”错误。 适用于我的摘要代码是:

        MessageDigest messageDigest = MessageDigest.getInstance("SHA-1");
        messageDigest.update("messageImprint".getBytes());
        byte[] digest = messageDigest.digest();
    
        2
  •  1
  •   willcodejavaforfood    15 年前

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

        3
  •  0
  •   willcodejavaforfood    15 年前

    this 这是一个相当好的时间戳资源,它也有一个服务器列表,其中至少有几个似乎仍在运行。

    推荐文章