2009-05-27 128 views
3

试图通过使用BouncyCastle请求时间戳(RFC 3161)并连接到http://timestamping.edelweb.fr/service/tsp。我确实从服务器获取了TimestampResponse,但它似乎没有实际的日期。时间戳响应不正确 - BouncyCastle

这是代码:

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

这里的问题(S): 有没有人使用BouncyCastle的图书馆的时间戳和碰巧了解不同的状态代码,他们是什么意思?或者只是为什么这似乎不起作用。

这条线,我希望看到一个日期只是抛出一个空指针:

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

有谁知道,不含任何其他RFC 3161兼容的时间戳服务器?

如果您想运行代码,您需要可以从here下载的bouncycastle罐子。你将需要:提供者,邮件,茶匙。

感谢

回答

1

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

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

但我派到只是:

"hello".getBytes(); 

创建从“你好”适当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身份验证这是一个必要条件。

0

我发现this网站这是一个时间戳相当不错的资源,它也有服务器的列表,并至少有几个人似乎仍然是可操作的。

+1

的链接断开(404) – 2012-05-18 09:54:01

3

用wireshark分析通信,这个例子给我一个“错误的消息摘要”错误。 一个摘要的代码为我的作品是:

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