github.com/xhghs/rclone@v1.51.1-0.20200430155106-e186a28cced8/docs/content/crypt.md (about)

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