github.com/10XDev/rclone@v1.52.3-0.20200626220027-16af9ab76b2a/docs/content/crypt.md (about) 1 --- 2 title: "Crypt" 3 description: "Encryption overlay remote" 4 --- 5 6 {{< icon "fa fa-lock" >}}Crypt 7 ---------------------------------------- 8 9 The `crypt` remote encrypts and decrypts another remote. 10 11 To use it first set up the underlying remote following the config 12 instructions for that remote. You can also use a local pathname 13 instead of a remote which will encrypt and decrypt from that directory 14 which might be useful for encrypting onto a USB stick for example. 15 16 First check your chosen remote is working - we'll call it 17 `remote:path` in these docs. Note that anything inside `remote:path` 18 will be encrypted and anything outside won't. This means that if you 19 are using a bucket based remote (eg S3, B2, swift) then you should 20 probably put the bucket in the remote `s3:bucket`. If you just use 21 `s3:` then rclone will make encrypted bucket names too (if using file 22 name encryption) which may or may not be what you want. 23 24 Now configure `crypt` using `rclone config`. We will call this one 25 `secret` to differentiate it from the `remote`. 26 27 ``` 28 No remotes found - make a new one 29 n) New remote 30 s) Set configuration password 31 q) Quit config 32 n/s/q> n 33 name> secret 34 Type of storage to configure. 35 Choose a number from below, or type in your own value 36 [snip] 37 XX / Encrypt/Decrypt a remote 38 \ "crypt" 39 [snip] 40 Storage> crypt 41 Remote to encrypt/decrypt. 42 Normally should contain a ':' and a path, eg "myremote:path/to/dir", 43 "myremote:bucket" or maybe "myremote:" (not recommended). 44 remote> remote:path 45 How to encrypt the filenames. 46 Choose a number from below, or type in your own value 47 1 / Don't encrypt the file names. Adds a ".bin" extension only. 48 \ "off" 49 2 / Encrypt the filenames see the docs for the details. 50 \ "standard" 51 3 / Very simple filename obfuscation. 52 \ "obfuscate" 53 filename_encryption> 2 54 Option to either encrypt directory names or leave them intact. 55 Choose a number from below, or type in your own value 56 1 / Encrypt directory names. 57 \ "true" 58 2 / Don't encrypt directory names, leave them intact. 59 \ "false" 60 filename_encryption> 1 61 Password or pass phrase for encryption. 62 y) Yes type in my own password 63 g) Generate random password 64 y/g> y 65 Enter the password: 66 password: 67 Confirm the password: 68 password: 69 Password or pass phrase for salt. Optional but recommended. 70 Should be different to the previous password. 71 y) Yes type in my own password 72 g) Generate random password 73 n) No leave this optional password blank 74 y/g/n> g 75 Password strength in bits. 76 64 is just about memorable 77 128 is secure 78 1024 is the maximum 79 Bits> 128 80 Your password is: JAsJvRcgR-_veXNfy_sGmQ 81 Use this password? 82 y) Yes 83 n) No 84 y/n> y 85 Remote config 86 -------------------- 87 [secret] 88 remote = remote:path 89 filename_encryption = standard 90 password = *** ENCRYPTED *** 91 password2 = *** ENCRYPTED *** 92 -------------------- 93 y) Yes this is OK 94 e) Edit this remote 95 d) Delete this remote 96 y/e/d> y 97 ``` 98 99 **Important** The password is stored in the config file is lightly 100 obscured so it isn't immediately obvious what it is. It is in no way 101 secure unless you use config file encryption. 102 103 A long passphrase is recommended, or you can use a random one. 104 105 The obscured password is created by using AES-CTR with a static key, with 106 the salt stored verbatim at the beginning of the obscured password. This 107 static key is shared by between all versions of rclone. 108 109 If you reconfigure rclone with the same passwords/passphrases 110 elsewhere it will be compatible, but the obscured version will be different 111 due to the different salt. 112 113 Note that rclone does not encrypt 114 115 * file length - this can be calculated within 16 bytes 116 * modification time - used for syncing 117 118 ## Specifying the remote ## 119 120 In normal use, make sure the remote has a `:` in. If you specify the 121 remote without a `:` then rclone will use a local directory of that 122 name. So if you use a remote of `/path/to/secret/files` then rclone 123 will encrypt stuff to that directory. If you use a remote of `name` 124 then rclone will put files in a directory called `name` in the current 125 directory. 126 127 If you specify the remote as `remote:path/to/dir` then rclone will 128 store encrypted files in `path/to/dir` on the remote. If you are using 129 file name encryption, then when you save files to 130 `secret:subdir/subfile` this will store them in the unencrypted path 131 `path/to/dir` but the `subdir/subpath` bit will be encrypted. 132 133 Note that unless you want encrypted bucket names (which are difficult 134 to manage because you won't know what directory they represent in web 135 interfaces etc), you should probably specify a bucket, eg 136 `remote:secretbucket` when using bucket based remotes such as S3, 137 Swift, Hubic, B2, GCS. 138 139 ## Example ## 140 141 To test I made a little directory of files using "standard" file name 142 encryption. 143 144 ``` 145 plaintext/ 146 ├── file0.txt 147 ├── file1.txt 148 └── subdir 149 ├── file2.txt 150 ├── file3.txt 151 └── subsubdir 152 └── file4.txt 153 ``` 154 155 Copy these to the remote and list them back 156 157 ``` 158 $ rclone -q copy plaintext secret: 159 $ rclone -q ls secret: 160 7 file1.txt 161 6 file0.txt 162 8 subdir/file2.txt 163 10 subdir/subsubdir/file4.txt 164 9 subdir/file3.txt 165 ``` 166 167 Now see what that looked like when encrypted 168 169 ``` 170 $ rclone -q ls remote:path 171 55 hagjclgavj2mbiqm6u6cnjjqcg 172 54 v05749mltvv1tf4onltun46gls 173 57 86vhrsv86mpbtd3a0akjuqslj8/dlj7fkq4kdq72emafg7a7s41uo 174 58 86vhrsv86mpbtd3a0akjuqslj8/7uu829995du6o42n32otfhjqp4/b9pausrfansjth5ob3jkdqd4lc 175 56 86vhrsv86mpbtd3a0akjuqslj8/8njh1sk437gttmep3p70g81aps 176 ``` 177 178 Note that this retains the directory structure which means you can do this 179 180 ``` 181 $ rclone -q ls secret:subdir 182 8 file2.txt 183 9 file3.txt 184 10 subsubdir/file4.txt 185 ``` 186 187 If don't use file name encryption then the remote will look like this 188 - note the `.bin` extensions added to prevent the cloud provider 189 attempting to interpret the data. 190 191 ``` 192 $ rclone -q ls remote:path 193 54 file0.txt.bin 194 57 subdir/file3.txt.bin 195 56 subdir/file2.txt.bin 196 58 subdir/subsubdir/file4.txt.bin 197 55 file1.txt.bin 198 ``` 199 200 ### File name encryption modes ### 201 202 Here are some of the features of the file name encryption modes 203 204 Off 205 206 * doesn't hide file names or directory structure 207 * allows for longer file names (~246 characters) 208 * can use sub paths and copy single files 209 210 Standard 211 212 * file names encrypted 213 * file names can't be as long (~143 characters) 214 * can use sub paths and copy single files 215 * directory structure visible 216 * identical files names will have identical uploaded names 217 * can use shortcuts to shorten the directory recursion 218 219 Obfuscation 220 221 This is a simple "rotate" of the filename, with each file having a rot 222 distance based on the filename. We store the distance at the beginning 223 of the filename. So a file called "hello" may become "53.jgnnq". 224 225 This is not a strong encryption of filenames, but it may stop automated 226 scanning tools from picking up on filename patterns. As such it's an 227 intermediate between "off" and "standard". The advantage is that it 228 allows for longer path segment names. 229 230 There is a possibility with some unicode based filenames that the 231 obfuscation is weak and may map lower case characters to upper case 232 equivalents. You can not rely on this for strong protection. 233 234 * file names very lightly obfuscated 235 * file names can be longer than standard encryption 236 * can use sub paths and copy single files 237 * directory structure visible 238 * identical files names will have identical uploaded names 239 240 Cloud storage systems have various limits on file name length and 241 total path length which you are more likely to hit using "Standard" 242 file name encryption. If you keep your file names to below 156 243 characters in length then you should be OK on all providers. 244 245 There may be an even more secure file name encryption mode in the 246 future which will address the long file name problem. 247 248 ### Directory name encryption ### 249 Crypt offers the option of encrypting dir names or leaving them intact. 250 There are two options: 251 252 True 253 254 Encrypts the whole file path including directory names 255 Example: 256 `1/12/123.txt` is encrypted to 257 `p0e52nreeaj0a5ea7s64m4j72s/l42g6771hnv3an9cgc8cr2n1ng/qgm4avr35m5loi1th53ato71v0` 258 259 False 260 261 Only encrypts file names, skips directory names 262 Example: 263 `1/12/123.txt` is encrypted to 264 `1/12/qgm4avr35m5loi1th53ato71v0` 265 266 267 ### Modified time and hashes ### 268 269 Crypt stores modification times using the underlying remote so support 270 depends on that. 271 272 Hashes are not stored for crypt. However the data integrity is 273 protected by an extremely strong crypto authenticator. 274 275 Note that you should use the `rclone cryptcheck` command to check the 276 integrity of a crypted remote instead of `rclone check` which can't 277 check the checksums properly. 278 279 {{< rem autogenerated options start" - DO NOT EDIT - instead edit fs.RegInfo in backend/crypt/crypt.go then run make backenddocs" >}} 280 ### Standard Options 281 282 Here are the standard options specific to crypt (Encrypt/Decrypt a remote). 283 284 #### --crypt-remote 285 286 Remote to encrypt/decrypt. 287 Normally should contain a ':' and a path, eg "myremote:path/to/dir", 288 "myremote:bucket" or maybe "myremote:" (not recommended). 289 290 - Config: remote 291 - Env Var: RCLONE_CRYPT_REMOTE 292 - Type: string 293 - Default: "" 294 295 #### --crypt-filename-encryption 296 297 How to encrypt the filenames. 298 299 - Config: filename_encryption 300 - Env Var: RCLONE_CRYPT_FILENAME_ENCRYPTION 301 - Type: string 302 - Default: "standard" 303 - Examples: 304 - "standard" 305 - Encrypt the filenames see the docs for the details. 306 - "obfuscate" 307 - Very simple filename obfuscation. 308 - "off" 309 - Don't encrypt the file names. Adds a ".bin" extension only. 310 311 #### --crypt-directory-name-encryption 312 313 Option to either encrypt directory names or leave them intact. 314 315 NB If filename_encryption is "off" then this option will do nothing. 316 317 - Config: directory_name_encryption 318 - Env Var: RCLONE_CRYPT_DIRECTORY_NAME_ENCRYPTION 319 - Type: bool 320 - Default: true 321 - Examples: 322 - "true" 323 - Encrypt directory names. 324 - "false" 325 - Don't encrypt directory names, leave them intact. 326 327 #### --crypt-password 328 329 Password or pass phrase for encryption. 330 331 **NB** Input to this must be obscured - see [rclone obscure](/commands/rclone_obscure/). 332 333 - Config: password 334 - Env Var: RCLONE_CRYPT_PASSWORD 335 - Type: string 336 - Default: "" 337 338 #### --crypt-password2 339 340 Password or pass phrase for salt. Optional but recommended. 341 Should be different to the previous password. 342 343 **NB** Input to this must be obscured - see [rclone obscure](/commands/rclone_obscure/). 344 345 - Config: password2 346 - Env Var: RCLONE_CRYPT_PASSWORD2 347 - Type: string 348 - Default: "" 349 350 ### Advanced Options 351 352 Here are the advanced options specific to crypt (Encrypt/Decrypt a remote). 353 354 #### --crypt-show-mapping 355 356 For all files listed show how the names encrypt. 357 358 If this flag is set then for each file that the remote is asked to 359 list, it will log (at level INFO) a line stating the decrypted file 360 name and the encrypted file name. 361 362 This is so you can work out which encrypted names are which decrypted 363 names just in case you need to do something with the encrypted file 364 names, or for debugging purposes. 365 366 - Config: show_mapping 367 - Env Var: RCLONE_CRYPT_SHOW_MAPPING 368 - Type: bool 369 - Default: false 370 371 ### Backend commands 372 373 Here are the commands specific to the crypt backend. 374 375 Run them with 376 377 rclone backend COMMAND remote: 378 379 The help below will explain what arguments each command takes. 380 381 See [the "rclone backend" command](/commands/rclone_backend/) for more 382 info on how to pass options and arguments. 383 384 These can be run on a running backend using the rc command 385 [backend/command](/rc/#backend/command). 386 387 #### encode 388 389 Encode the given filename(s) 390 391 rclone backend encode remote: [options] [<arguments>+] 392 393 This encodes the filenames given as arguments returning a list of 394 strings of the encoded results. 395 396 Usage Example: 397 398 rclone backend encode crypt: file1 [file2...] 399 rclone rc backend/command command=encode fs=crypt: file1 [file2...] 400 401 402 #### decode 403 404 Decode the given filename(s) 405 406 rclone backend decode remote: [options] [<arguments>+] 407 408 This decodes the filenames given as arguments returning a list of 409 strings of the decoded results. It will return an error if any of the 410 inputs are invalid. 411 412 Usage Example: 413 414 rclone backend decode crypt: encryptedfile1 [encryptedfile2...] 415 rclone rc backend/command command=decode fs=crypt: encryptedfile1 [encryptedfile2...] 416 417 418 {{< rem autogenerated options stop >}} 419 420 ## Backing up a crypted remote ## 421 422 If you wish to backup a crypted remote, it is recommended that you use 423 `rclone sync` on the encrypted files, and make sure the passwords are 424 the same in the new encrypted remote. 425 426 This will have the following advantages 427 428 * `rclone sync` will check the checksums while copying 429 * you can use `rclone check` between the encrypted remotes 430 * you don't decrypt and encrypt unnecessarily 431 432 For example, let's say you have your original remote at `remote:` with 433 the encrypted version at `eremote:` with path `remote:crypt`. You 434 would then set up the new remote `remote2:` and then the encrypted 435 version `eremote2:` with path `remote2:crypt` using the same passwords 436 as `eremote:`. 437 438 To sync the two remotes you would do 439 440 rclone sync remote:crypt remote2:crypt 441 442 And to check the integrity you would do 443 444 rclone check remote:crypt remote2:crypt 445 446 ## File formats ## 447 448 ### File encryption ### 449 450 Files are encrypted 1:1 source file to destination object. The file 451 has a header and is divided into chunks. 452 453 #### Header #### 454 455 * 8 bytes magic string `RCLONE\x00\x00` 456 * 24 bytes Nonce (IV) 457 458 The initial nonce is generated from the operating systems crypto 459 strong random number generator. The nonce is incremented for each 460 chunk read making sure each nonce is unique for each block written. 461 The chance of a nonce being re-used is minuscule. If you wrote an 462 exabyte of data (10¹⁸ bytes) you would have a probability of 463 approximately 2×10⁻³² of re-using a nonce. 464 465 #### Chunk #### 466 467 Each chunk will contain 64kB of data, except for the last one which 468 may have less data. The data chunk is in standard NACL secretbox 469 format. Secretbox uses XSalsa20 and Poly1305 to encrypt and 470 authenticate messages. 471 472 Each chunk contains: 473 474 * 16 Bytes of Poly1305 authenticator 475 * 1 - 65536 bytes XSalsa20 encrypted data 476 477 64k chunk size was chosen as the best performing chunk size (the 478 authenticator takes too much time below this and the performance drops 479 off due to cache effects above this). Note that these chunks are 480 buffered in memory so they can't be too big. 481 482 This uses a 32 byte (256 bit key) key derived from the user password. 483 484 #### Examples #### 485 486 1 byte file will encrypt to 487 488 * 32 bytes header 489 * 17 bytes data chunk 490 491 49 bytes total 492 493 1MB (1048576 bytes) file will encrypt to 494 495 * 32 bytes header 496 * 16 chunks of 65568 bytes 497 498 1049120 bytes total (a 0.05% overhead). This is the overhead for big 499 files. 500 501 ### Name encryption ### 502 503 File names are encrypted segment by segment - the path is broken up 504 into `/` separated strings and these are encrypted individually. 505 506 File segments are padded using PKCS#7 to a multiple of 16 bytes 507 before encryption. 508 509 They are then encrypted with EME using AES with 256 bit key. EME 510 (ECB-Mix-ECB) is a wide-block encryption mode presented in the 2003 511 paper "A Parallelizable Enciphering Mode" by Halevi and Rogaway. 512 513 This makes for deterministic encryption which is what we want - the 514 same filename must encrypt to the same thing otherwise we can't find 515 it on the cloud storage system. 516 517 This means that 518 519 * filenames with the same name will encrypt the same 520 * filenames which start the same won't have a common prefix 521 522 This uses a 32 byte key (256 bits) and a 16 byte (128 bits) IV both of 523 which are derived from the user password. 524 525 After encryption they are written out using a modified version of 526 standard `base32` encoding as described in RFC4648. The standard 527 encoding is modified in two ways: 528 529 * it becomes lower case (no-one likes upper case filenames!) 530 * we strip the padding character `=` 531 532 `base32` is used rather than the more efficient `base64` so rclone can be 533 used on case insensitive remotes (eg Windows, Amazon Drive). 534 535 ### Key derivation ### 536 537 Rclone uses `scrypt` with parameters `N=16384, r=8, p=1` with an 538 optional user supplied salt (password2) to derive the 32+32+16 = 80 539 bytes of key material required. If the user doesn't supply a salt 540 then rclone uses an internal one. 541 542 `scrypt` makes it impractical to mount a dictionary attack on rclone 543 encrypted data. For full protection against this you should always use 544 a salt.