|
| 1 | +mrcrypt: Multi-Region Encryption |
| 2 | +================================ |
| 3 | + |
| 4 | +mrcrypt is a command-line tool that allows you to encrypt secrets in |
| 5 | +multiple AWS regions using KMS keys using a technique called `Envelope |
| 6 | +Encryption <http://docs.aws.amazon.com/kms/latest/developerguide/workflow.html>`__. |
| 7 | +It is intended to be used with the `AWS Encryption SDK for |
| 8 | +Java <https://github.com/awslabs/aws-encryption-sdk-java>`__, but could |
| 9 | +be used on its own. |
| 10 | + |
| 11 | +Compatability with the AWS Encryption SDK |
| 12 | +''''''''''''''''''''''''''''''''''''''''' |
| 13 | + |
| 14 | +**All files encrypted with mrcrypt can be decrypted with the AWS |
| 15 | +Encryption SDK.** But not all files encrypted with the AWS Encryption |
| 16 | +SDK can be decrypted by mrcrypt. |
| 17 | + |
| 18 | +Currently, mrcrypt only supports the AWS Encryption SDK's default (and |
| 19 | +most secure) cryptographic algorithm: |
| 20 | + |
| 21 | +- Content Type: Framed |
| 22 | +- Frame size: 4096 |
| 23 | +- Algorithm: ALG\_AES\_256\_GCM\_IV12\_TAG16\_HKDF\_SHA384\_ECDSA\_P384 |
| 24 | + |
| 25 | +Support for the remaining algorithms are planned, but files encrypted |
| 26 | +with the AWS Encryption SDK using one of the other algorithms are |
| 27 | +currently not supported in mrcrypt. |
| 28 | + |
| 29 | +Also, the AWS Encryption SDK creates files using elliptic curve point |
| 30 | +compression. Files created with mrcrypt do not use point compression |
| 31 | +because they are not currently supported in |
| 32 | +`Cryptography <https://github.com/pyca/cryptography>`__, a Python |
| 33 | +package mrcrypt uses. The uncompressed points are just as secure as the |
| 34 | +compressed points, but files are a few bytes larger. The AWS Encryption |
| 35 | +SDK can decrypt files that use uncompressed points, meaning all files |
| 36 | +created with mrcrypt are compatible with the AWS Encryption SDK. |
| 37 | + |
| 38 | +Installation |
| 39 | +------------ |
| 40 | + |
| 41 | +To install mrcrypt simply clone the repo, and run ``pip install .`` |
| 42 | +inside of the directory: |
| 43 | + |
| 44 | +:: |
| 45 | + |
| 46 | + git clone ssh://git@stash.ops.aol.com:2022/identity_services/mrcrypt.git |
| 47 | + cd mrcrypt |
| 48 | + pip install . |
| 49 | + |
| 50 | +**Note:** mrcrypt uses the Python package |
| 51 | +`Cryptography <https://github.com/pyca/cryptography>`__ which depends on |
| 52 | +``libffi``. You may need to install it on your system if |
| 53 | +``pip install .`` fails. For more specific instructions for your OS: |
| 54 | +https://cryptography.io/en/latest/installation/ |
| 55 | + |
| 56 | +Usage |
| 57 | +----- |
| 58 | + |
| 59 | +:: |
| 60 | + |
| 61 | + usage: mrcrypt [-h] [-p PROFILE] [-e ENCRYPTION_CONTEXT] [-d] [-o OUTFILE] |
| 62 | + {encrypt,decrypt} ... |
| 63 | + |
| 64 | + Multi Region Encryption. A tool for managing secrets across multiple AWS |
| 65 | + regions. |
| 66 | + |
| 67 | + positional arguments: |
| 68 | + {encrypt,decrypt} |
| 69 | + |
| 70 | + optional arguments: |
| 71 | + -h, --help show this help message and exit |
| 72 | + -p PROFILE, --profile PROFILE |
| 73 | + The profile to use |
| 74 | + -e ENCRYPTION_CONTEXT, --encryption_context ENCRYPTION_CONTEXT |
| 75 | + An encryption context to use. (Cannot have whitespace) |
| 76 | + -d, --debug Enable more output for debugging |
| 77 | + -o OUTFILE, --outfile OUTFILE |
| 78 | + The file to write the results to |
| 79 | + |
| 80 | +Both the encrypt, and decrypt commands can encrypt and decrypt files in |
| 81 | +directories recursively. |
| 82 | + |
| 83 | +Named Profiles |
| 84 | +'''''''''''''' |
| 85 | + |
| 86 | +If you have multiple named profiles in your ``~/.aws/credentials`` file, |
| 87 | +you can specify one using the ``-p`` argument. |
| 88 | + |
| 89 | +:: |
| 90 | + |
| 91 | + mrcrypt -p my_profile encrypt alias/master-key secrets.txt |
| 92 | + |
| 93 | +Encryption Context |
| 94 | +'''''''''''''''''' |
| 95 | + |
| 96 | +You can specify an `encryption |
| 97 | +context <http://docs.aws.amazon.com/kms/latest/developerguide/encryption-context.html>`__ |
| 98 | +using the ``-e`` argument. This flag takes a JSON object with no spaces: |
| 99 | + |
| 100 | +:: |
| 101 | + |
| 102 | + # encrypt |
| 103 | + mrcrypt -e '{"key":"value","key2":"value2"}' encrypt alias/master-key secrets.txt |
| 104 | + |
| 105 | + # decrypt |
| 106 | + mrcrypt -e '{"key":"value","key2":"value2"}' decrypt secrets.txt.encrypted |
| 107 | + |
| 108 | +Output file name |
| 109 | +'''''''''''''''' |
| 110 | + |
| 111 | +If you want to specify the output filename, you can use the ``-o`` |
| 112 | +argument. |
| 113 | + |
| 114 | +``# Encrypt 'file.txt' writing the output into 'encrypted-file.txt' mrcrypt -o encrypted-file.txt encrypt alias/master-key file.txt`` |
| 115 | + |
| 116 | +By default, when encrypting, mrcrypt will create a file with the same |
| 117 | +file name as the input file with ``.encrypted`` appended to the end. |
| 118 | +When decrypting, if the file ends with ``.encrypted`` it will write the |
| 119 | +plaintext output to a file of the same name but without the |
| 120 | +``.encrypted``. |
| 121 | + |
| 122 | +Encryption |
| 123 | +---------- |
| 124 | + |
| 125 | +:: |
| 126 | + |
| 127 | + usage: mrcrypt encrypt [-h] [-r REGIONS [REGIONS ...]] [-e ENCRYPTION_CONTEXT] |
| 128 | + key_id filename |
| 129 | + |
| 130 | + Encrypts a file or directory recursively |
| 131 | + |
| 132 | + positional arguments: |
| 133 | + key_id An identifier for a customer master key. |
| 134 | + filename The file or directory to encrypt. Use a - to read from |
| 135 | + stdin |
| 136 | + |
| 137 | + optional arguments: |
| 138 | + -h, --help show this help message and exit |
| 139 | + -r REGIONS [REGIONS ...], --regions REGIONS [REGIONS ...] |
| 140 | + A list of regions to encrypt with KMS. End the list |
| 141 | + with -- |
| 142 | + -e ENCRYPTION_CONTEXT, --encryption_context ENCRYPTION_CONTEXT |
| 143 | + An encryption context to use |
| 144 | + |
| 145 | +**Example:** Encrypt ``secrets.txt`` with the key alias |
| 146 | +``alias/master-key`` in the regions ``us-east-1`` and ``us-west-2``: |
| 147 | + |
| 148 | +``mrcrypt encrypt -r us-east-1 us-west-2 -- alias/master-key secrets.txt`` |
| 149 | + |
| 150 | +Decryption |
| 151 | +---------- |
| 152 | + |
| 153 | +:: |
| 154 | + |
| 155 | + usage: mrcrypt decrypt [-h] filename |
| 156 | + |
| 157 | + Decrypts a file |
| 158 | + |
| 159 | + positional arguments: |
| 160 | + filename The file or directory to decrypt. Use a - to read from stdin |
| 161 | + |
| 162 | + optional arguments: |
| 163 | + -h, --help show this help message and exit |
| 164 | + |
| 165 | +**Example:** To decrypt ``secrets.txt.encrypted``: |
| 166 | + |
| 167 | +:: |
| 168 | + |
| 169 | + mrcrypt decrypt secrets.txt.encrypted |
| 170 | + |
| 171 | +**Note:** Be careful when decrypting a directory. If the directory |
| 172 | +contains files that are not encrypted, it will fail. |
| 173 | + |
| 174 | +Testing |
| 175 | +''''''' |
| 176 | + |
| 177 | +Running tests for mrcrypt is easy if you have ``tox`` installed. Simply |
| 178 | +run ``tox`` at the project's root. |
0 commit comments