maroph

OpenSSL: Create/Verify a Timestamp Request

Sep 26th, 2016
402
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. With the help of OpenSSL and curl you can easily create and verify SHA-1 based timestamps.
  2.  
  3. In this sample I will use the FreeTSA (https://freetsa.org/index_en.php) timestamp provider.
  4.  
  5. TSA Certificate: https://freetsa.org/files/tsa.crt
  6. Key modulus (sha256): 899ba3d9f777e2a74bdd34302bc06cb3f7a46ac1f565ee128f79fd5dab99d68b
  7.  
  8. CA Certificate: https://freetsa.org/files/cacert.pem
  9. Key modulus (sha256): a4b1a0a81aef68be1cc985d0f83bd6539cfe84174587f900e15ffe3f65433056
  10.  
  11. Download the certificate files:
  12.  
  13. wget http://freetsa.org/files/tsa.crt
  14. wget http://freetsa.org/files/cacert.pem
  15.  
  16.  
  17. Create timestamp request data
  18.  
  19. openssl ts -query -data data.txt -cert -sha1 -no_nonce \
  20. -config openssl_ts.cnf -out data.txt.ts_req
  21.  
  22. The file openssl_ts.cnf is an empty file.
  23.  
  24. Send the timestamp request and store the response
  25.  
  26. curl -s -S -H 'Content-Type: application/timestamp-query' \
  27. --data-binary @data.txt.ts_req http://freetsa.org/tsr \
  28. -o data.txt.ts_res
  29.  
  30.  
  31. Verify the data with the timestamp response
  32.  
  33. openssl ts -verify -config openssl_ts.cnf \
  34. -in data.txt.ts_res -data data.txt \
  35. -CAfile cacert.pem
  36.  
  37. You should see the following message from OpenSSL
  38.  
  39. Verification: OK
  40.  
  41.  
  42. View the timestap request data on the timestamping providing site
  43.  
  44. The hash value will be stored at the timestamp provider side. If you want to view the stored data, you need the SHA-1 hash value of your document
  45.  
  46. openssl dgst -sha1 data.txt | sed -e 's/^.*= //'
  47.  
  48. aa9e3512f38bafce78040651b54085c69b540d5d
  49.  
  50.  
  51. Now you can request the stored data
  52.  
  53. curl -X POST \
  54. --data "hash=aa9e3512f38bafce78040651b54085c69b540d5d" \
  55. http://freetsa.org/grep.php
  56.  
  57. Time stamp: Sep 26 10:55:17 2016 GMT - Hash Algorithm: sha1 - aa9e3512f38bafce78040651b54085c69b540d5d
Advertisement
Add Comment
Please, Sign In to add comment