1 Introduction
2 ------------
3
4 MoinMessage provides a library for creating, signing, encrypting, decrypting,
5 and verifying PGP/GPG content in Python along with mechanisms for updating
6 MoinMoin Wiki instances with such content such that contributors can be
7 identified from their PGP signatures and such details used to authenticate
8 their contributions.
9
10 Configuring GPG for a Wiki
11 --------------------------
12
13 Initialise a homedir for GPG and configure it using filesystem ACL (access
14 control list) properties:
15
16 ./scripts/init_wiki_keyring.sh WIKI WEBUSER
17
18 Here, WIKI should be replaced by the top-level Wiki instance directory, and
19 WEBUSER should be the name of the user under which the Web server operates.
20
21 Note that this script may need re-running after the homedir has been changed
22 by gpg operations as gpg likes to remove permissions from various files.
23
24 To be in any way useful, signing keys must be made available within this
25 homedir so that incoming messages can have their senders verified.
26
27 To see the keys available to you in your own environment:
28
29 gpg --list-keys --with-fingerprint
30
31 The full fingerprints are used when defining a user mapping in the Wiki, and
32 the --with-fingerprint option is used to show them. Otherwise, only the last
33 eight characters of the fingerprints are shown.
34
35 Export the public key used when signing messages from your own environment:
36
37 gpg --armor --output 1C1AAF83.asc --export 1C1AAF83
38
39 Import the key into the Wiki's GPG homedir:
40
41 gpg --homedir wiki/gnupg --import 1C1AAF83.asc
42
43 For the Wiki to receive encrypted data, a key for the Wiki must be created:
44
45 gpg --homedir wiki/gnupg --gen-key
46
47 For the Wiki environment to be able to use the key, password access must be
48 disabled. This can be done by either not specifying a password or by removing
49 it later using the --edit-key option.
50
51 Export the Wiki's key for encrypting messages sent to the Wiki:
52
53 gpg --homedir wiki/gnupg --armor --output 0891463A.asc --export 0891463A
54
55 This exported key can now be imported into your own environment:
56
57 gpg --import 0891463A.asc
58
59 Configuring the Wiki
60 --------------------
61
62 In the Wiki configuration, define the following settings:
63
64 moinmessage_gpg_homedir
65 This sets the path to the homedir initialised above.
66
67 moinmessage_gpg_users_page (optional, default is MoinMessageUserDict)
68 This provides a mapping from key fingerprints to Moin usernames.
69
70 moinmessage_gpg_signing_users_page (optional, default is MoinMessageSigningUserDict)
71 This provides a mapping from Moin usernames to key fingerprints.
72
73 moinmessage_gpg_recipients_page (optional, default is MoinMessageRecipientsDict)
74 This provides a mapping from recipients to remote URLs and key fingerprints.
75 Each user can define the named page as a subpage of their own home page.
76 If no such personal mapping exists, a common mapping exists relative to the
77 site root.
78
79 moinmessage_reject_messages_without_dates (optional, default is True)
80 This causes messages sent to a Wiki using the PostMessage action to be
81 rejected if date information is missing.
82
83 For signature verification to function, the following needs to be added:
84
85 from MoinMoin.auth.pgp import PGPAuth
86
87 This should import an authentication handler installed when the MoinMessage
88 software is installed as an extension package.
89
90 Within the configuration class itself, the auth setting needs to be updated to
91 include PGPAuth in the list of registered handlers. For example:
92
93 auth = [MoinAuth(), PGPAuth()]
94
95 This would permit the traditional Moin authentication and add signature-based
96 authentication so that messages can be accepted by the Wiki.
97
98 Fingerprints and Keys
99 ---------------------
100
101 All fingerprints mentioned in the various configuration pages must exclude
102 space characters - that is, the letters and digits must appear together in a
103 continuous block of text - and refer to keys available in the Wiki homedir.
104
105 The Fingerprint-to-Username Mapping
106 -----------------------------------
107
108 The mapping from fingerprints to usernames typically defined by the
109 MoinMessageUserDict page is a WikiDict having the following general format:
110
111 fingerprint:: username
112
113 Each fingerprint corresponds to a key used by a person wanting to send
114 messages to the Wiki to sign such messages.
115
116 Each username must correspond to a registered user in the Wiki.
117
118 The Username-to-Signing Key Mapping
119 -----------------------------------
120
121 The mapping from usernames to fingerprints typically defined by the
122 MoinMessageSigningUserDict page is a WikiDict having the following general
123 format:
124
125 username:: fingerprint
126
127 Each fingerprint corresponds to a key available in the Wiki's GPG homedir
128 generated for the purpose of signing the specified user's messages. Such a key
129 is not the same as one used by a person to send messages to the Wiki since
130 only the public key used to verify such messages should be known to the Wiki.
131
132 The Recipients Mapping
133 ----------------------
134
135 The mapping from recipients to remote URLs and fingerprints typically defined
136 by the MoinMessageRecipientsDict page is a WikiDict having the following
137 general format:
138
139 recipient:: location ... [ fingerprint ]
140
141 Locations are specified as follows:
142
143 type=value
144
145 Where the type is "page", the accompanying value must be a page name
146 indicating a page that provides a message store that will accept messages.
147
148 Where the type is "url", the accompanying value must be a URL that must itself
149 refer to a resource that can accept MoinMessage content.
150
151 Where a location of type "url" has been given, a fingerprint must accompany
152 this information in order to encrypt messages sent to the specified resource.
153
154 Each fingerprint corresponds to a key used by the Wiki to encrypt messages and
155 by the remote site (as identified by the URL) to decrypt messages.
156
157 Quick Start: Signing, Encrypting and Sending Messages
158 -----------------------------------------------------
159
160 To send a message signed and encrypted to a resource on localhost:
161
162 python tests/test_send.py 1C1AAF83 0891463A http://localhost/wiki/ShareTest \
163 collection update 'An update to the Wiki.' 'Another update.'
164
165 Here, the first identifier is a reference to the signing key (over which you
166 have complete control), and the second identifier is a reference to the
167 encryption key (which is a public key published for the Wiki).
168
169 This needs password protection to be removed from the secret key in the Web
170 server environment. It also uses a modified trust model when invoking gpg in
171 order to avoid complaints about the identity of the sender during encryption.
172
173 Below, the mechanisms employed are illustrated through the use of the other
174 test programs.
175
176 Signing
177 -------
178
179 Prepare a message signed with a "detached signature" (note that this does not
180 seem to be what gpg calls a detached signature with the --detach-sig option):
181
182 python tests/test_message.py collection update 'An update to the Wiki.' \
183 'Another update.' \
184 | python tests/test_sign.py 1C1AAF83
185
186 The complicated recipe based on the individual operations is as follows:
187
188 python tests/test_message.py collection update 'An update to the Wiki.' \
189 'Another update.' \
190 > test.txt \
191 && cat test.txt \
192 | gpg --armor -u 1C1AAF83 --detach-sig \
193 | python tests/test_sign_wrap.py test.txt
194
195 Encryption
196 ----------
197
198 Prepare a message with an encrypted payload using the above key:
199
200 python tests/test_message.py collection update 'An update to the Wiki.' \
201 'Another update.' \
202 | python tests/test_encrypt.py 0891463A
203
204 The complicated recipe based on the individual operations is as follows:
205
206 python tests/test_message.py collection update 'An update to the Wiki.' \
207 'Another update.' \
208 > test.txt \
209 && cat test.txt \
210 | gpg --armor -r 0891463A --encrypt --trust-model always \
211 | python tests/test_encrypt_wrap.py
212
213 Note that "--trust-model always" is used only to avoid prompting issues.
214
215 Signing and Encrypting
216 ----------------------
217
218 Sign and encrypt a message:
219
220 python tests/test_message.py collection update 'An update to the Wiki.' \
221 'Another update.' \
222 | python tests/test_sign.py 1C1AAF83 \
223 | python tests/test_encrypt.py 0891463A
224
225 The complicated recipe based on the individual operations is as follows:
226
227 python tests/test_message.py collection update 'An update to the Wiki.' \
228 'Another update.' \
229 > test.txt \
230 && cat test.txt \
231 | gpg --armor -u 1C1AAF83 --detach-sig \
232 | python tests/test_sign_wrap.py test.txt \
233 | gpg --armor -r 0891463A --encrypt --trust-model always \
234 | python tests/test_encrypt_wrap.py
235
236 Posting a Message
237 -----------------
238
239 To post a signed and/or encrypted message, output from the above activities
240 can be piped into the following command:
241
242 python tests/test_post.py http://localhost/wiki/ShareTest
243
244 Here, the resource "/wiki/ShareTest" on localhost is presented with the
245 message.
246
247 Fetching Messages
248 -----------------
249
250 To fetch messages from a message store associated with a page, the following
251 command can be used:
252
253 python tests/test_fetch.py 1C1AAF83 0891463A http://localhost/wiki/ShareTest \
254 RETR
255
256 This should retrieve all messages from the store associated with the
257 "/wiki/ShareTest" resource on localhost.
258
259 The Message Format
260 ------------------
261
262 Messages are MIME-encoded and consist of one or more update fragments. Where
263 the "Update-Type" header is present and set to a value of "collection", a
264 multipart message describes as many updates as there are parts. Otherwise,
265 only a single update is described by the message.
266
267 For each update, the "Update-Action" header indicates the action to be taken
268 with the update content. Where it is absent, the content is inserted into the
269 Wiki page specified in the request; where it is present and set to "replace",
270 the content replaces all content on the Wiki page; where it is set to "store",
271 the content is stored in a message store associated with the Wiki page.
272
273 Each update may describe multiple representations of some content by employing
274 a multipart section containing parts for each of the representations.
275 Alternatively, a single message part may describe a single representation.