paul@11 | 1 | Introduction
|
paul@11 | 2 | ------------
|
paul@11 | 3 |
|
paul@11 | 4 | MoinMessage provides a library for creating, signing, encrypting, decrypting,
|
paul@12 | 5 | and verifying PGP/GPG content in Python along with mechanisms for updating
|
paul@51 | 6 | MoinMoin wiki instances with such content such that contributors can be
|
paul@11 | 7 | identified from their PGP signatures and such details used to authenticate
|
paul@63 | 8 | their contributions. It also permits PGP/GPG content to be stored in dedicated
|
paul@63 | 9 | message stores when received, enabling further processing of received content
|
paul@63 | 10 | and other means of perusal of such content.
|
paul@11 | 11 |
|
paul@11 | 12 | Configuring GPG for a Wiki
|
paul@11 | 13 | --------------------------
|
paul@11 | 14 |
|
paul@37 | 15 | Initialise a homedir for GPG and configure it using filesystem ACL (access
|
paul@37 | 16 | control list) properties:
|
paul@11 | 17 |
|
paul@12 | 18 | ./scripts/init_wiki_keyring.sh WIKI WEBUSER
|
paul@12 | 19 |
|
paul@51 | 20 | Here, WIKI should be replaced by the top-level wiki instance directory, and
|
paul@12 | 21 | WEBUSER should be the name of the user under which the Web server operates.
|
paul@12 | 22 |
|
paul@12 | 23 | Note that this script may need re-running after the homedir has been changed
|
paul@12 | 24 | by gpg operations as gpg likes to remove permissions from various files.
|
paul@11 | 25 |
|
paul@11 | 26 | To be in any way useful, signing keys must be made available within this
|
paul@11 | 27 | homedir so that incoming messages can have their senders verified.
|
paul@11 | 28 |
|
paul@11 | 29 | To see the keys available to you in your own environment:
|
paul@11 | 30 |
|
paul@11 | 31 | gpg --list-keys --with-fingerprint
|
paul@11 | 32 |
|
paul@51 | 33 | The full fingerprints are used when defining a user mapping in the wiki, and
|
paul@11 | 34 | the --with-fingerprint option is used to show them. Otherwise, only the last
|
paul@11 | 35 | eight characters of the fingerprints are shown.
|
paul@11 | 36 |
|
paul@11 | 37 | Export the public key used when signing messages from your own environment:
|
paul@11 | 38 |
|
paul@11 | 39 | gpg --armor --output 1C1AAF83.asc --export 1C1AAF83
|
paul@11 | 40 |
|
paul@51 | 41 | Import the key into the wiki's GPG homedir:
|
paul@11 | 42 |
|
paul@65 | 43 | gpg --homedir WIKI/gnupg --import 1C1AAF83.asc
|
paul@11 | 44 |
|
paul@51 | 45 | For the wiki to receive encrypted data, a key for the wiki must be created:
|
paul@11 | 46 |
|
paul@65 | 47 | gpg --homedir WIKI/gnupg --gen-key
|
paul@11 | 48 |
|
paul@51 | 49 | For the wiki environment to be able to use the key, password access must be
|
paul@12 | 50 | disabled. This can be done by either not specifying a password or by removing
|
paul@59 | 51 | it later using the --edit-key option:
|
paul@59 | 52 |
|
paul@65 | 53 | gpg --homedir WIKI/gnupg --edit-key 0891463A
|
paul@59 | 54 | passwd
|
paul@12 | 55 |
|
paul@51 | 56 | Export the wiki's key for encrypting messages sent to the wiki:
|
paul@11 | 57 |
|
paul@65 | 58 | gpg --homedir WIKI/gnupg --armor --output 0891463A.asc --export 0891463A
|
paul@11 | 59 |
|
paul@11 | 60 | This exported key can now be imported into your own environment:
|
paul@11 | 61 |
|
paul@11 | 62 | gpg --import 0891463A.asc
|
paul@11 | 63 |
|
paul@11 | 64 | Configuring the Wiki
|
paul@11 | 65 | --------------------
|
paul@11 | 66 |
|
paul@51 | 67 | In the wiki configuration, define the following settings:
|
paul@11 | 68 |
|
paul@11 | 69 | moinmessage_gpg_homedir
|
paul@11 | 70 | This sets the path to the homedir initialised above.
|
paul@11 | 71 |
|
paul@11 | 72 | moinmessage_gpg_users_page (optional, default is MoinMessageUserDict)
|
paul@11 | 73 | This provides a mapping from key fingerprints to Moin usernames.
|
paul@11 | 74 |
|
paul@12 | 75 | moinmessage_gpg_signing_users_page (optional, default is MoinMessageSigningUserDict)
|
paul@12 | 76 | This provides a mapping from Moin usernames to key fingerprints.
|
paul@12 | 77 |
|
paul@65 | 78 | moinmessage_gpg_relaying_user (optional)
|
paul@65 | 79 | This specifies the username of a special user who will sign relayed
|
paul@65 | 80 | messages. Partner wikis will need to record the details of this user in
|
paul@65 | 81 | their fingerprint-to-user mapping (see moinmessage_gpg_users_page) to be
|
paul@65 | 82 | able to receive messages from this wiki.
|
paul@65 | 83 |
|
paul@12 | 84 | moinmessage_gpg_recipients_page (optional, default is MoinMessageRecipientsDict)
|
paul@12 | 85 | This provides a mapping from recipients to remote URLs and key fingerprints.
|
paul@37 | 86 | Each user can define the named page as a subpage of their own home page.
|
paul@37 | 87 | If no such personal mapping exists, a common mapping exists relative to the
|
paul@37 | 88 | site root.
|
paul@12 | 89 |
|
paul@20 | 90 | moinmessage_reject_messages_without_dates (optional, default is True)
|
paul@51 | 91 | This causes messages sent to a wiki using the PostMessage action to be
|
paul@20 | 92 | rejected if date information is missing.
|
paul@20 | 93 |
|
paul@40 | 94 | moinmessage_static_files (optional, may refer to the built-in htdocs directory)
|
paul@40 | 95 | This explicitly defines the path to static resources used by Moin, enabling
|
paul@40 | 96 | such resources to be attached to messages. When set, the path must refer to
|
paul@40 | 97 | the htdocs directory (possibly renamed) containing the different theme
|
paul@65 | 98 | resource directories, together with the robots.txt and favicon.ico files.
|
paul@40 | 99 |
|
paul@38 | 100 | For signature verification to function, the following needs to be added:
|
paul@38 | 101 |
|
paul@38 | 102 | from MoinMoin.auth.pgp import PGPAuth
|
paul@38 | 103 |
|
paul@38 | 104 | This should import an authentication handler installed when the MoinMessage
|
paul@38 | 105 | software is installed as an extension package.
|
paul@38 | 106 |
|
paul@38 | 107 | Within the configuration class itself, the auth setting needs to be updated to
|
paul@38 | 108 | include PGPAuth in the list of registered handlers. For example:
|
paul@38 | 109 |
|
paul@38 | 110 | auth = [MoinAuth(), PGPAuth()]
|
paul@38 | 111 |
|
paul@38 | 112 | This would permit the traditional Moin authentication and add signature-based
|
paul@51 | 113 | authentication so that messages can be accepted by the wiki.
|
paul@38 | 114 |
|
paul@12 | 115 | Fingerprints and Keys
|
paul@12 | 116 | ---------------------
|
paul@12 | 117 |
|
paul@12 | 118 | All fingerprints mentioned in the various configuration pages must exclude
|
paul@12 | 119 | space characters - that is, the letters and digits must appear together in a
|
paul@51 | 120 | continuous block of text - and refer to keys available in the wiki homedir.
|
paul@12 | 121 |
|
paul@11 | 122 | The Fingerprint-to-Username Mapping
|
paul@11 | 123 | -----------------------------------
|
paul@11 | 124 |
|
paul@12 | 125 | The mapping from fingerprints to usernames typically defined by the
|
paul@12 | 126 | MoinMessageUserDict page is a WikiDict having the following general format:
|
paul@11 | 127 |
|
paul@11 | 128 | fingerprint:: username
|
paul@11 | 129 |
|
paul@12 | 130 | Each fingerprint corresponds to a key used by a person wanting to send
|
paul@51 | 131 | messages to the wiki to sign such messages.
|
paul@11 | 132 |
|
paul@51 | 133 | Each username must correspond to a registered user in the wiki.
|
paul@11 | 134 |
|
paul@65 | 135 | If a wiki is to perform message relaying, receiving messages from partner
|
paul@65 | 136 | wikis and sending them on, a user is required for this purpose. You could
|
paul@65 | 137 | create such a user as follows:
|
paul@65 | 138 |
|
paul@65 | 139 | moin --config-dir=WIKI account create --name=MessageRelay --email=messagerelay
|
paul@65 | 140 |
|
paul@65 | 141 | (You may need to run this command as the Web server user to be able to change
|
paul@65 | 142 | the wiki installation, as well as indicating the full path to the moin program
|
paul@65 | 143 | either as the program name or by setting the PATH.)
|
paul@65 | 144 |
|
paul@65 | 145 | After doing this, you could define an entry for the relaying user as follows:
|
paul@65 | 146 |
|
paul@65 | 147 | fingerprint:: MessageRelay
|
paul@65 | 148 |
|
paul@65 | 149 | Here, "fingerprint" should be substituted for a key fingerprint used by a
|
paul@65 | 150 | partner wiki to sign messages that it then sends to this wiki. See the next
|
paul@65 | 151 | section for more information on signing keys and identities.
|
paul@65 | 152 |
|
paul@65 | 153 | It may very well be the case that more than one partner wiki will be sending
|
paul@65 | 154 | messages to this wiki: the signing key fingerprint of each partner wiki can be
|
paul@65 | 155 | added to this mapping and specify the same relaying user; there is no
|
paul@65 | 156 | restriction on each fingerprint needing to map to a different user.
|
paul@65 | 157 |
|
paul@12 | 158 | The Username-to-Signing Key Mapping
|
paul@12 | 159 | -----------------------------------
|
paul@12 | 160 |
|
paul@12 | 161 | The mapping from usernames to fingerprints typically defined by the
|
paul@12 | 162 | MoinMessageSigningUserDict page is a WikiDict having the following general
|
paul@12 | 163 | format:
|
paul@12 | 164 |
|
paul@12 | 165 | username:: fingerprint
|
paul@12 | 166 |
|
paul@51 | 167 | Each fingerprint corresponds to a key available in the wiki's GPG homedir
|
paul@12 | 168 | generated for the purpose of signing the specified user's messages. Such a key
|
paul@51 | 169 | is not the same as one used by a person to send messages to the wiki since
|
paul@51 | 170 | only the public key is available to the wiki when verifying such messages,
|
paul@51 | 171 | whereas the signing of messages requires access to a private key. Thus, the
|
paul@51 | 172 | signing process employs a special private key known to the wiki for a user.
|
paul@12 | 173 |
|
paul@65 | 174 | If a wiki is to perform message relaying, the special relaying user must be
|
paul@65 | 175 | defined in this mapping together with an appropriate key fingerprint. You can
|
paul@65 | 176 | use the key generated during the wiki's configuration (see "Configuring GPG
|
paul@65 | 177 | for a Wiki" above) for this purpose. This fingerprint can then be used by
|
paul@65 | 178 | partner wikis in their fingerprint-to-user mapping in order to verify incoming
|
paul@65 | 179 | messages and to process them as relayed messages.
|
paul@65 | 180 |
|
paul@12 | 181 | The Recipients Mapping
|
paul@12 | 182 | ----------------------
|
paul@12 | 183 |
|
paul@12 | 184 | The mapping from recipients to remote URLs and fingerprints typically defined
|
paul@12 | 185 | by the MoinMessageRecipientsDict page is a WikiDict having the following
|
paul@12 | 186 | general format:
|
paul@12 | 187 |
|
paul@43 | 188 | recipient:: type location [ fingerprint ]
|
paul@27 | 189 |
|
paul@43 | 190 | Where the type is "page", the accompanying location must be a page name
|
paul@28 | 191 | indicating a page that provides a message store that will accept messages.
|
paul@63 | 192 | The affected page resides on the same wiki and is thus a bare page name, not
|
paul@63 | 193 | the URL of a page on the same or another wiki.
|
paul@12 | 194 |
|
paul@43 | 195 | Where the type is "url", the accompanying location must be a URL that must
|
paul@43 | 196 | itself refer to a resource that can accept MoinMessage content.
|
paul@12 | 197 |
|
paul@43 | 198 | Where a type of "url" has been given, a fingerprint must accompany this
|
paul@43 | 199 | information in order to encrypt messages sent to the specified resource.
|
paul@27 | 200 |
|
paul@51 | 201 | Each fingerprint corresponds to a key used by the wiki to encrypt messages and
|
paul@27 | 202 | by the remote site (as identified by the URL) to decrypt messages.
|
paul@12 | 203 |
|
paul@55 | 204 | Each wiki user can have their own recipients mapping by making a page, called
|
paul@55 | 205 | MoinMessageRecipientsDict unless overridden by the configuration, as a subpage
|
paul@55 | 206 | of their own home page.
|
paul@55 | 207 |
|
paul@11 | 208 | Quick Start: Signing, Encrypting and Sending Messages
|
paul@11 | 209 | -----------------------------------------------------
|
paul@11 | 210 |
|
paul@11 | 211 | To send a message signed and encrypted to a resource on localhost:
|
paul@11 | 212 |
|
paul@12 | 213 | python tests/test_send.py 1C1AAF83 0891463A http://localhost/wiki/ShareTest \
|
paul@51 | 214 | collection update 'An update to the wiki.' 'Another update.'
|
paul@11 | 215 |
|
paul@11 | 216 | Here, the first identifier is a reference to the signing key (over which you
|
paul@11 | 217 | have complete control), and the second identifier is a reference to the
|
paul@51 | 218 | encryption key (which is a public key published for the wiki).
|
paul@11 | 219 |
|
paul@11 | 220 | This needs password protection to be removed from the secret key in the Web
|
paul@12 | 221 | server environment. It also uses a modified trust model when invoking gpg in
|
paul@12 | 222 | order to avoid complaints about the identity of the sender during encryption.
|
paul@11 | 223 |
|
paul@45 | 224 | To sign the encrypted message for forwarding, the above command is modified:
|
paul@45 | 225 |
|
paul@45 | 226 | python tests/test_send.py 1C1AAF83 0891463A --forward 1C1AAF83 \
|
paul@45 | 227 | http://localhost/wiki/ShareTest \
|
paul@51 | 228 | collection update 'An update to the wiki.' 'Another update.'
|
paul@45 | 229 |
|
paul@11 | 230 | Below, the mechanisms employed are illustrated through the use of the other
|
paul@11 | 231 | test programs.
|
paul@11 | 232 |
|
paul@11 | 233 | Signing
|
paul@11 | 234 | -------
|
paul@11 | 235 |
|
paul@11 | 236 | Prepare a message signed with a "detached signature" (note that this does not
|
paul@11 | 237 | seem to be what gpg calls a detached signature with the --detach-sig option):
|
paul@11 | 238 |
|
paul@51 | 239 | python tests/test_message.py collection update 'An update to the wiki.' \
|
paul@16 | 240 | 'Another update.' \
|
paul@11 | 241 | | python tests/test_sign.py 1C1AAF83
|
paul@11 | 242 |
|
paul@11 | 243 | The complicated recipe based on the individual operations is as follows:
|
paul@11 | 244 |
|
paul@51 | 245 | python tests/test_message.py collection update 'An update to the wiki.' \
|
paul@16 | 246 | 'Another update.' \
|
paul@11 | 247 | > test.txt \
|
paul@11 | 248 | && cat test.txt \
|
paul@11 | 249 | | gpg --armor -u 1C1AAF83 --detach-sig \
|
paul@11 | 250 | | python tests/test_sign_wrap.py test.txt
|
paul@11 | 251 |
|
paul@11 | 252 | Encryption
|
paul@11 | 253 | ----------
|
paul@11 | 254 |
|
paul@11 | 255 | Prepare a message with an encrypted payload using the above key:
|
paul@11 | 256 |
|
paul@51 | 257 | python tests/test_message.py collection update 'An update to the wiki.' \
|
paul@16 | 258 | 'Another update.' \
|
paul@11 | 259 | | python tests/test_encrypt.py 0891463A
|
paul@11 | 260 |
|
paul@11 | 261 | The complicated recipe based on the individual operations is as follows:
|
paul@11 | 262 |
|
paul@51 | 263 | python tests/test_message.py collection update 'An update to the wiki.' \
|
paul@16 | 264 | 'Another update.' \
|
paul@11 | 265 | > test.txt \
|
paul@11 | 266 | && cat test.txt \
|
paul@11 | 267 | | gpg --armor -r 0891463A --encrypt --trust-model always \
|
paul@11 | 268 | | python tests/test_encrypt_wrap.py
|
paul@11 | 269 |
|
paul@11 | 270 | Note that "--trust-model always" is used only to avoid prompting issues.
|
paul@11 | 271 |
|
paul@11 | 272 | Signing and Encrypting
|
paul@11 | 273 | ----------------------
|
paul@11 | 274 |
|
paul@12 | 275 | Sign and encrypt a message:
|
paul@11 | 276 |
|
paul@51 | 277 | python tests/test_message.py collection update 'An update to the wiki.' \
|
paul@16 | 278 | 'Another update.' \
|
paul@11 | 279 | | python tests/test_sign.py 1C1AAF83 \
|
paul@11 | 280 | | python tests/test_encrypt.py 0891463A
|
paul@11 | 281 |
|
paul@11 | 282 | The complicated recipe based on the individual operations is as follows:
|
paul@11 | 283 |
|
paul@51 | 284 | python tests/test_message.py collection update 'An update to the wiki.' \
|
paul@16 | 285 | 'Another update.' \
|
paul@11 | 286 | > test.txt \
|
paul@11 | 287 | && cat test.txt \
|
paul@11 | 288 | | gpg --armor -u 1C1AAF83 --detach-sig \
|
paul@11 | 289 | | python tests/test_sign_wrap.py test.txt \
|
paul@11 | 290 | | gpg --armor -r 0891463A --encrypt --trust-model always \
|
paul@11 | 291 | | python tests/test_encrypt_wrap.py
|
paul@11 | 292 |
|
paul@45 | 293 | Signing and Encrypting then Signing
|
paul@45 | 294 | -----------------------------------
|
paul@45 | 295 |
|
paul@45 | 296 | Where a message is to be forwarded and not decrypted, it will be signed by the
|
paul@45 | 297 | author, encrypted, but then signed by the forwarder (perhaps initially the
|
paul@45 | 298 | author):
|
paul@45 | 299 |
|
paul@51 | 300 | python tests/test_message.py collection update 'An update to the wiki.' \
|
paul@45 | 301 | 'Another update.' \
|
paul@45 | 302 | | python tests/test_sign.py 1C1AAF83 \
|
paul@45 | 303 | | python tests/test_encrypt.py 0891463A \
|
paul@45 | 304 | | python tests/test_sign.py 1C1AAF83
|
paul@45 | 305 |
|
paul@45 | 306 | The complicated recipe based on the individual operations is as follows:
|
paul@45 | 307 |
|
paul@51 | 308 | python tests/test_message.py collection update 'An update to the wiki.' \
|
paul@45 | 309 | 'Another update.' \
|
paul@45 | 310 | > test.txt \
|
paul@45 | 311 | && cat test.txt \
|
paul@45 | 312 | | gpg --armor -u 1C1AAF83 --detach-sig \
|
paul@45 | 313 | | python tests/test_sign_wrap.py test.txt \
|
paul@45 | 314 | | gpg --armor -r 0891463A --encrypt --trust-model always \
|
paul@45 | 315 | | python tests/test_encrypt_wrap.py \
|
paul@45 | 316 | > test2.txt \
|
paul@45 | 317 | && cat test2.txt \
|
paul@45 | 318 | | gpg --armor -u 1C1AAF83 --detach-sig \
|
paul@45 | 319 | | python tests/test_sign_wrap.py test2.txt
|
paul@45 | 320 |
|
paul@11 | 321 | Posting a Message
|
paul@11 | 322 | -----------------
|
paul@11 | 323 |
|
paul@11 | 324 | To post a signed and/or encrypted message, output from the above activities
|
paul@11 | 325 | can be piped into the following command:
|
paul@11 | 326 |
|
paul@12 | 327 | python tests/test_post.py http://localhost/wiki/ShareTest
|
paul@11 | 328 |
|
paul@11 | 329 | Here, the resource "/wiki/ShareTest" on localhost is presented with the
|
paul@11 | 330 | message.
|
paul@16 | 331 |
|
paul@32 | 332 | Fetching Messages
|
paul@32 | 333 | -----------------
|
paul@32 | 334 |
|
paul@32 | 335 | To fetch messages from a message store associated with a page, the following
|
paul@32 | 336 | command can be used:
|
paul@32 | 337 |
|
paul@32 | 338 | python tests/test_fetch.py 1C1AAF83 0891463A http://localhost/wiki/ShareTest \
|
paul@32 | 339 | RETR
|
paul@32 | 340 |
|
paul@32 | 341 | This should retrieve all messages from the store associated with the
|
paul@32 | 342 | "/wiki/ShareTest" resource on localhost.
|
paul@32 | 343 |
|
paul@16 | 344 | The Message Format
|
paul@16 | 345 | ------------------
|
paul@16 | 346 |
|
paul@16 | 347 | Messages are MIME-encoded and consist of one or more update fragments. Where
|
paul@16 | 348 | the "Update-Type" header is present and set to a value of "collection", a
|
paul@16 | 349 | multipart message describes as many updates as there are parts. Otherwise,
|
paul@16 | 350 | only a single update is described by the message.
|
paul@16 | 351 |
|
paul@16 | 352 | For each update, the "Update-Action" header indicates the action to be taken
|
paul@16 | 353 | with the update content. Where it is absent, the content is inserted into the
|
paul@51 | 354 | wiki page specified in the request; where it is present and set to "replace",
|
paul@51 | 355 | the content replaces all content on the wiki page; where it is set to "store",
|
paul@51 | 356 | the content is stored in a message store associated with the wiki page.
|
paul@16 | 357 |
|
paul@16 | 358 | Each update may describe multiple representations of some content by employing
|
paul@44 | 359 | a multipart/alternative section containing parts for each of the
|
paul@44 | 360 | representations. Alternatively, a single message part may describe a single
|
paul@44 | 361 | representation.
|
paul@44 | 362 |
|
paul@44 | 363 | HTTP Methods
|
paul@44 | 364 | ------------
|
paul@44 | 365 |
|
paul@44 | 366 | Since MoinMoin seems to reserve POST methods for request/entity bodies that
|
paul@44 | 367 | contain HTML form data, it is necessary to use alternative methods to post
|
paul@44 | 368 | messages to a site served by MoinMoin and to fetch messages from such a site.
|
paul@57 | 369 | Consequently, MoinMessage uses PUT to post and fetch messages. Unfortunately,
|
paul@57 | 370 | MoinMoin 1.9 prevents the use of GET with request/entity bodies, and so the
|
paul@57 | 371 | natural usage of GET to fetch messages cannot be employed.
|
paul@54 | 372 |
|
paul@54 | 373 | Contact, Copyright and Licence Information
|
paul@54 | 374 | ------------------------------------------
|
paul@54 | 375 |
|
paul@54 | 376 | See the following Web page for more information about this work:
|
paul@54 | 377 |
|
paul@54 | 378 | http://moinmo.in/ActionMarket/MoinMessage
|
paul@54 | 379 |
|
paul@54 | 380 | The author can be contacted at the following e-mail address:
|
paul@54 | 381 |
|
paul@54 | 382 | paul@boddie.org.uk
|
paul@54 | 383 |
|
paul@54 | 384 | Copyright and licence information can be found in the docs directory - see
|
paul@54 | 385 | docs/COPYING.txt and docs/LICENCE.txt for more information.
|
paul@54 | 386 |
|
paul@54 | 387 | Dependencies
|
paul@54 | 388 | ------------
|
paul@54 | 389 |
|
paul@54 | 390 | MoinMessage has the following basic dependencies:
|
paul@54 | 391 |
|
paul@54 | 392 | Packages Release Information
|
paul@54 | 393 | -------- -------------------
|
paul@54 | 394 |
|
paul@54 | 395 | MoinSupport Tested with 0.4
|
paul@54 | 396 | Source: http://hgweb.boddie.org.uk/MoinSupport
|