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