1 <?xml version=
"1.0" encoding=
"ISO-8859-1"?>
2 <rss version='
2.0' xmlns:lj='http://www.livejournal.org/rss/lj/
1.0/'
>
4 <title>Petter Reinholdtsen - Entries from October
2018</title>
5 <description>Entries from October
2018</description>
6 <link>http://people.skolelinux.org/pere/blog/
</link>
10 <title>Fetching trusted timestamps using the rfc3161ng python module
</title>
11 <link>http://people.skolelinux.org/pere/blog/Fetching_trusted_timestamps_using_the_rfc3161ng_python_module.html
</link>
12 <guid isPermaLink=
"true">http://people.skolelinux.org/pere/blog/Fetching_trusted_timestamps_using_the_rfc3161ng_python_module.html
</guid>
13 <pubDate>Mon,
8 Oct
2018 12:
30:
00 +
0200</pubDate>
14 <description><p
>I have earlier covered the basics of trusted timestamping using the
15 'openssl ts
' client. See blog post for
16 <a href=
"http://people.skolelinux.org/pere/blog/Public_Trusted_Timestamping_services_for_everyone.html
">2014</a
>,
17 <a href=
"http://people.skolelinux.org/pere/blog/syslog_trusted_timestamp___chain_of_trusted_timestamps_for_your_syslog.html
">2016</a
>
19 <a href=
"http://people.skolelinux.org/pere/blog/Idea_for_storing_trusted_timestamps_in_a_Noark_5_archive.html
">2017</a
>
20 for those stories. But some times I want to integrate the timestamping
21 in other code, and recently I needed to integrate it into Python.
22 After searching a bit, I found
23 <a href=
"https://dev.entrouvert.org/projects/python-rfc3161
">the
24 rfc3161 library
</a
> which seemed like a good fit, but I soon
25 discovered it only worked for python version
2, and I needed something
26 that work with python version
3. Luckily I next came across
27 <a href=
"https://github.com/trbs/rfc3161ng/
">the rfc3161ng library
</a
>,
28 a fork of the original rfc3161 library. Not only is it working with
29 python
3, it have fixed a few of the bugs in the original library, and
30 it has an active maintainer. I decided to wrap it up and make it
31 <a href=
"https://tracker.debian.org/pkg/python-rfc3161ng
">available in
32 Debian
</a
>, and a few days ago it entered Debian unstable and testing.
</p
>
34 <p
>Using the library is fairly straight forward. The only slightly
35 problematic step is to fetch the required certificates to verify the
36 timestamp. For some services it is straight forward, while for others
37 I have not yet figured out how to do it. Here is a small standalone
38 code example based on of the integration tests in the library code:
</p
>
45 Python
3 script demonstrating how to use the rfc3161ng module to
46 get trusted timestamps.
48 The license of this code is the same as the license of the rfc3161ng
54 import pyasn1.codec.der
65 def fetch(url, f=None):
66 response = urllib.request.urlopen(url)
67 data = response.read()
73 with tempfile.NamedTemporaryFile() as cert_f,\
74 tempfile.NamedTemporaryFile() as ca_f,\
75 tempfile.NamedTemporaryFile() as msg_f,\
76 tempfile.NamedTemporaryFile() as tsr_f:
78 # First fetch certificates used by service
79 certificate_data = fetch(
'https://freetsa.org/files/tsa.crt
', cert_f)
80 ca_data_data = fetch(
'https://freetsa.org/files/cacert.pem
', ca_f)
82 # Then timestamp the message
84 rfc3161ng.RemoteTimestamper(
'http://freetsa.org/tsr
',
85 certificate=certificate_data)
86 data = b
"Python forever!\n
"
87 tsr = timestamper(data=data, return_tsr=True)
89 # Finally, convert message and response to something
'openssl ts
' can verify
91 store(tsr_f, pyasn1.codec.der.encoder.encode(tsr))
92 args = [
"openssl
",
"ts
",
"-verify
",
93 "-data
", msg_f.name,
94 "-in
", tsr_f.name,
95 "-CAfile
", ca_f.name,
96 "-untrusted
", cert_f.name]
97 subprocess.check_call(args)
99 if
'__main__
' == __name__:
103 <p
>The code fetches the required certificates, store them as temporary
104 files, timestamp a simple message, store the message and timestamp to
105 disk and ask
'openssl ts
' to verify the timestamp. A timestamp is
106 around
1.5 kiB in size, and should be fairly easy to store for future
109 <p
>As usual, if you use Bitcoin and want to show your support of my
110 activities, please send Bitcoin donations to my address
111 <b
><a href=
"bitcoin:
15oWEoG9dUPovwmUL9KWAnYRtNJEkP1u1b
">15oWEoG9dUPovwmUL9KWAnYRtNJEkP1u1b
</a
></b
>.
</p
>
116 <title>Automatic Google Drive sync using grive in Debian
</title>
117 <link>http://people.skolelinux.org/pere/blog/Automatic_Google_Drive_sync_using_grive_in_Debian.html
</link>
118 <guid isPermaLink=
"true">http://people.skolelinux.org/pere/blog/Automatic_Google_Drive_sync_using_grive_in_Debian.html
</guid>
119 <pubDate>Thu,
4 Oct
2018 15:
20:
00 +
0200</pubDate>
120 <description><p
>A few days, I rescued a Windows victim over to Debian. To try to
121 rescue the remains, I helped set up automatic sync with Google Drive.
122 I did not find any sensible Debian package handling this
123 automatically, so I rebuild the grive2 source from
124 <a href=
"http://www.webupd8.org/
">the Ubuntu UPD8 PPA
</a
> to do the
125 task and added a autostart desktop entry and a small shell script to
126 run in the background while the user is logged in to do the sync.
127 Here is a sketch of the setup for future reference.
</p
>
129 <p
>I first created
<tt
>~/googledrive
</tt
>, entered the directory and
130 ran
'<tt
>grive -a
</tt
>' to authenticate the machine/user. Next, I
131 created a autostart hook in
<tt
>~/.config/autostart/grive.desktop
</tt
>
132 to start the sync when the user log in:
</p
>
134 <p
><blockquote
><pre
>
136 Name=Google drive autosync
138 Exec=/home/user/bin/grive-sync
139 </pre
></blockquote
></p
>
141 <p
>Finally, I wrote the
<tt
>~/bin/grive-sync
</tt
> script to sync
142 ~/googledrive/ with the files in Google Drive.
</p
>
144 <p
><blockquote
><pre
>
149 if [
"$syncpid
" ] ; then
153 trap cleanup EXIT INT QUIT
154 /usr/lib/grive/grive-sync.sh listen googledrive
2>&1 | sed
"s%^%$
0:%
" &
157 if ! xhost
>/dev/null
2>&1 ; then
158 echo
"no DISPLAY, exiting as the user probably logged out
"
161 if [ ! -e /run/user/
1000/grive-sync.sh_googledrive ] ; then
162 /usr/lib/grive/grive-sync.sh sync googledrive
165 done
2>&1 | sed
"s%^%$
0:%
"
166 </pre
></blockquote
></p
>
168 <p
>Feel free to use the setup if you want. It can be assumed to be
169 GNU GPL v2 licensed (or any later version, at your leisure), but I
170 doubt this code is possible to claim copyright on.
</p
>
172 <p
>As usual, if you use Bitcoin and want to show your support of my
173 activities, please send Bitcoin donations to my address
174 <b
><a href=
"bitcoin:
15oWEoG9dUPovwmUL9KWAnYRtNJEkP1u1b
">15oWEoG9dUPovwmUL9KWAnYRtNJEkP1u1b
</a
></b
>.
</p
>