X-Git-Url: https://pere.pagekite.me/gitweb/homepage.git/blobdiff_plain/9446e808bfb54133bd214facce0c83764c8cc731..5aa9d156bcbd561acf67f4658ad00618cb128238:/blog/tags/sikkerhet/index.html diff --git a/blog/tags/sikkerhet/index.html b/blog/tags/sikkerhet/index.html index b9c6550b18..fa72d6e74a 100644 --- a/blog/tags/sikkerhet/index.html +++ b/blog/tags/sikkerhet/index.html @@ -20,6 +20,124 @@

Entries tagged "sikkerhet".

+
+
+ Fetching trusted timestamps using the rfc3161ng python module +
+
+ 8th October 2018 +
+
+

I have earlier covered the basics of trusted timestamping using the +'openssl ts' client. See blog post for +2014, +2016 +and +2017 +for those stories. But some times I want to integrate the timestamping +in other code, and recently I needed to integrate it into Python. +After searching a bit, I found +the +rfc3161 library which seemed like a good fit, but I soon +discovered it only worked for python version 2, and I needed something +that work with python version 3. Luckily I next came across +the rfc3161ng library, +a fork of the original rfc3161 library. Not only is it working with +python 3, it have fixed a few of the bugs in the original library, and +it has an active maintainer. I decided to wrap it up and make it +available in +Debian, and a few days ago it entered Debian unstable and testing.

+ +

Using the library is fairly straight forward. The only slightly +problematic step is to fetch the required certificates to verify the +timestamp. For some services it is straight forward, while for others +I have not yet figured out how to do it. Here is a small standalone +code example based on of the integration tests in the library code:

+ +
+#!/usr/bin/python3
+
+"""
+
+Python 3 script demonstrating how to use the rfc3161ng module to
+get trusted timestamps.
+
+The license of this code is the same as the license of the rfc3161ng
+library, ie MIT/BSD.
+
+"""
+
+import os
+import pyasn1.codec.der
+import rfc3161ng
+import subprocess
+import tempfile
+import urllib.request
+
+def store(f, data):
+    f.write(data)
+    f.flush()
+    f.seek(0)
+
+def fetch(url, f=None):
+    response = urllib.request.urlopen(url)
+    data = response.read()
+    if f:
+        store(f, data)
+    return data
+
+def main():
+    with tempfile.NamedTemporaryFile() as cert_f,\
+    	 tempfile.NamedTemporaryFile() as ca_f,\
+    	 tempfile.NamedTemporaryFile() as msg_f,\
+    	 tempfile.NamedTemporaryFile() as tsr_f:
+
+        # First fetch certificates used by service
+        certificate_data = fetch('https://freetsa.org/files/tsa.crt', cert_f)
+        ca_data_data = fetch('https://freetsa.org/files/cacert.pem', ca_f)
+
+        # Then timestamp the message
+        timestamper = \
+            rfc3161ng.RemoteTimestamper('http://freetsa.org/tsr',
+                                        certificate=certificate_data)
+        data = b"Python forever!\n"
+        tsr = timestamper(data=data, return_tsr=True)
+
+        # Finally, convert message and response to something 'openssl ts' can verify
+        store(msg_f, data)
+        store(tsr_f, pyasn1.codec.der.encoder.encode(tsr))
+        args = ["openssl", "ts", "-verify",
+                "-data", msg_f.name,
+	        "-in", tsr_f.name,
+		"-CAfile", ca_f.name,
+                "-untrusted", cert_f.name]
+        subprocess.check_call(args)
+
+if '__main__' == __name__:
+   main()
+
+ +

The code fetches the required certificates, store them as temporary +files, timestamp a simple message, store the message and timestamp to +disk and ask 'openssl ts' to verify the timestamp. A timestamp is +around 1.5 kiB in size, and should be fairly easy to store for future +use.

+ +

As usual, if you use Bitcoin and want to show your support of my +activities, please send Bitcoin donations to my address +15oWEoG9dUPovwmUL9KWAnYRtNJEkP1u1b.

+ +
+
+ + + Tags: english, sikkerhet. + + +
+
+
+
Stortingsflertallet går inn for ny IP-basert sensurinfrastruktur i Norge @@ -4357,7 +4475,13 @@ betydelige.

  • June (2)
  • -
  • July (4)
  • +
  • July (5)
  • + +
  • August (3)
  • + +
  • September (3)
  • + +
  • October (3)
  • @@ -4644,7 +4768,7 @@ betydelige.

  • bankid (4)
  • -
  • bitcoin (9)
  • +
  • bitcoin (10)
  • bootsystem (17)
  • @@ -4652,7 +4776,7 @@ betydelige.

  • chrpath (2)
  • -
  • debian (160)
  • +
  • debian (163)
  • debian edu (158)
  • @@ -4666,7 +4790,7 @@ betydelige.

  • drivstoffpriser (4)
  • -
  • english (378)
  • +
  • english (388)
  • fiksgatami (23)
  • @@ -4686,6 +4810,8 @@ betydelige.

  • kart (20)
  • +
  • kodi (3)
  • +
  • ldap (9)
  • lego (4)
  • @@ -4704,13 +4830,13 @@ betydelige.

  • norsk (299)
  • -
  • nuug (190)
  • +
  • nuug (191)
  • -
  • offentlig innsyn (33)
  • +
  • offentlig innsyn (34)
  • open311 (2)
  • -
  • opphavsrett (71)
  • +
  • opphavsrett (72)
  • personvern (107)
  • @@ -4730,13 +4856,13 @@ betydelige.

  • scraperwiki (2)
  • -
  • sikkerhet (54)
  • +
  • sikkerhet (55)
  • sitesummary (4)
  • skepsis (5)
  • -
  • standard (55)
  • +
  • standard (56)
  • stavekontroll (6)
  • @@ -4750,9 +4876,9 @@ betydelige.

  • valg (9)
  • -
  • verkidetfri (11)
  • +
  • verkidetfri (12)
  • -
  • video (66)
  • +
  • video (68)
  • vitenskap (4)