xref: /freebsd/lib/geom/eli/geli.8 (revision 6419bb52)
1.\" Copyright (c) 2005-2019 Pawel Jakub Dawidek <pawel@dawidek.net>
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\"
13.\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
14.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
17.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23.\" SUCH DAMAGE.
24.\"
25.\" $FreeBSD$
26.\"
27.Dd April 14, 2020
28.Dt GELI 8
29.Os
30.Sh NAME
31.Nm geli
32.Nd "control utility for the cryptographic GEOM class"
33.Sh SYNOPSIS
34To compile GEOM_ELI into your kernel, add the following lines to your kernel
35configuration file:
36.Bd -ragged -offset indent
37.Cd "device crypto"
38.Cd "options GEOM_ELI"
39.Ed
40.Pp
41Alternatively, to load the GEOM_ELI module at boot time, add the following line
42to your
43.Xr loader.conf 5 :
44.Bd -literal -offset indent
45geom_eli_load="YES"
46.Ed
47.Pp
48Usage of the
49.Nm
50utility:
51.Pp
52.Nm
53.Cm init
54.Op Fl bdgPRTv
55.Op Fl a Ar aalgo
56.Op Fl B Ar backupfile
57.Op Fl e Ar ealgo
58.Op Fl i Ar iterations
59.Op Fl J Ar newpassfile
60.Op Fl K Ar newkeyfile
61.Op Fl l Ar keylen
62.Op Fl s Ar sectorsize
63.Op Fl V Ar version
64.Ar prov ...
65.Nm
66.Cm label - an alias for
67.Cm init
68.Nm
69.Cm attach
70.Op Fl Cdprv
71.Op Fl n Ar keyno
72.Op Fl j Ar passfile
73.Op Fl k Ar keyfile
74.Ar prov ...
75.Nm
76.Cm detach
77.Op Fl fl
78.Ar prov ...
79.Nm
80.Cm stop - an alias for
81.Cm detach
82.Nm
83.Cm onetime
84.Op Fl dRT
85.Op Fl a Ar aalgo
86.Op Fl e Ar ealgo
87.Op Fl l Ar keylen
88.Op Fl s Ar sectorsize
89.Ar prov
90.Nm
91.Cm configure
92.Op Fl bBdDgGrRtT
93.Ar prov ...
94.Nm
95.Cm setkey
96.Op Fl pPv
97.Op Fl i Ar iterations
98.Op Fl j Ar passfile
99.Op Fl J Ar newpassfile
100.Op Fl k Ar keyfile
101.Op Fl K Ar newkeyfile
102.Op Fl n Ar keyno
103.Ar prov
104.Nm
105.Cm delkey
106.Op Fl afv
107.Op Fl n Ar keyno
108.Ar prov
109.Nm
110.Cm kill
111.Op Fl av
112.Op Ar prov ...
113.Nm
114.Cm backup
115.Op Fl v
116.Ar prov
117.Ar file
118.Nm
119.Cm restore
120.Op Fl fv
121.Ar file
122.Ar prov
123.Nm
124.Cm suspend
125.Op Fl v
126.Fl a | Ar prov ...
127.Nm
128.Cm resume
129.Op Fl pv
130.Op Fl j Ar passfile
131.Op Fl k Ar keyfile
132.Ar prov
133.Nm
134.Cm resize
135.Op Fl v
136.Fl s Ar oldsize
137.Ar prov
138.Nm
139.Cm version
140.Op Ar prov ...
141.Nm
142.Cm clear
143.Op Fl v
144.Ar prov ...
145.Nm
146.Cm dump
147.Op Fl v
148.Ar prov ...
149.Nm
150.Cm list
151.Nm
152.Cm status
153.Nm
154.Cm load
155.Nm
156.Cm unload
157.Sh DESCRIPTION
158The
159.Nm
160utility is used to configure encryption on GEOM providers.
161.Pp
162The following is a list of the most important features:
163.Pp
164.Bl -bullet -offset indent -compact
165.It
166Utilizes the
167.Xr crypto 9
168framework, so when there is crypto hardware available,
169.Nm
170will make use of it automatically.
171.It
172Supports many cryptographic algorithms (currently
173.Nm AES-XTS ,
174.Nm AES-CBC ,
175and
176.Nm Camellia-CBC ) .
177.It
178Can optionally perform data authentication (integrity verification) utilizing
179one of the following algorithms:
180.Nm HMAC/SHA1 ,
181.Nm HMAC/RIPEMD160 ,
182.Nm HMAC/SHA256 ,
183.Nm HMAC/SHA384
184or
185.Nm HMAC/SHA512 .
186.It
187Can create a User Key from up to two, piecewise components: a passphrase
188entered via prompt or read from one or more passfiles; a keyfile read from
189one or more files.
190.It
191Allows encryption of the root partition.
192The user is asked for the passphrase before the root filesystem is mounted.
193.It
194Strengthens the passphrase component of the User Key with:
195.Rs
196.%A B. Kaliski
197.%T "PKCS #5: Password-Based Cryptography Specification, Version 2.0."
198.%R RFC
199.%N 2898
200.Re
201.It
202Allows the use of two independent User Keys (e.g., a
203.Qq "user key"
204and a
205.Qq "company key" ) .
206.It
207It is fast -
208.Nm
209performs simple sector-to-sector encryption.
210.It
211Allows the encrypted Master Key to be backed up and restored,
212so that if a user has to quickly destroy key material,
213it is possible to get the data back by restoring keys from
214backup.
215.It
216Providers can be configured to automatically detach on last close,
217so users do not have to remember to detach providers after unmounting
218the filesystems.
219.It
220Allows attaching a provider with a random, one-time Master Key,
221which is useful for swap partitions and temporary filesystems.
222.It
223Allows verification of data integrity (data authentication).
224.It
225Allows suspending and resuming encrypted devices.
226.El
227.Pp
228The first argument to
229.Nm
230indicates an action to be performed:
231.Bl -tag -width ".Cm configure"
232.It Cm init
233Initialize providers which need to be encrypted.
234If multiple providers are listed as arguments, they will all be initialized
235with the same passphrase and/or User Key.
236A unique salt will be randomly generated for each provider to ensure the
237Master Key for each is unique.
238Here you can set up the cryptographic algorithm to use, Data Key length,
239etc.
240The last sector of the providers is used to store metadata.
241The
242.Cm init
243subcommand also automatically writes metadata backups to
244.Pa /var/backups/<prov>.eli
245file.
246The metadata can be recovered with the
247.Cm restore
248subcommand described below.
249.Pp
250Additional options include:
251.Bl -tag -width ".Fl J Ar newpassfile"
252.It Fl a Ar aalgo
253Enable data integrity verification (authentication) using the given algorithm.
254This will reduce the size of storage available and also reduce speed.
255For example, when using 4096 bytes sector and
256.Nm HMAC/SHA256
257algorithm, 89% of the original provider storage will be available for use.
258Currently supported algorithms are:
259.Nm HMAC/SHA1 ,
260.Nm HMAC/RIPEMD160 ,
261.Nm HMAC/SHA256 ,
262.Nm HMAC/SHA384
263and
264.Nm HMAC/SHA512 .
265If the option is not given, there will be no authentication, only encryption.
266The recommended algorithm is
267.Nm HMAC/SHA256 .
268.It Fl b
269Try to decrypt this partition during boot, before the root partition is mounted.
270This makes it possible to use an encrypted root partition.
271One will still need bootable unencrypted storage with a
272.Pa /boot/
273directory, which can be a CD-ROM disc or USB pen-drive, that can be removed
274after boot.
275.It Fl B Ar backupfile
276File name to use for metadata backup instead of the default
277.Pa /var/backups/<prov>.eli .
278To inhibit backups, you can use
279.Pa none
280as the
281.Ar backupfile .
282If multiple providers were initialized in the one command, you can use
283.Pa PROV
284(all upper-case) in the file name, and it will be replaced with the provider
285name.
286If
287.Pa PROV
288is not found in the file name and multiple providers were initialized in the
289one command,
290.Pa -<prov>
291will be appended to the end of the file name specified.
292.It Fl d
293When entering the passphrase to boot from this encrypted root filesystem, echo
294.Ql *
295characters.
296This makes the length of the passphrase visible.
297.It Fl e Ar ealgo
298Encryption algorithm to use.
299Currently supported algorithms are:
300.Nm AES-XTS ,
301.Nm AES-CBC ,
302.Nm Camellia-CBC ,
303and
304.Nm NULL .
305The default and recommended algorithm is
306.Nm AES-XTS .
307.Nm NULL
308is unencrypted.
309.It Fl g
310Enable booting from this encrypted root filesystem.
311The boot loader prompts for the passphrase and loads
312.Xr loader 8
313from the encrypted partition.
314.It Fl i Ar iterations
315Number of iterations to use with PKCS#5v2 when processing User Key
316passphrase component.
317If this option is not specified,
318.Nm
319will find the number of iterations which is equal to 2 seconds of crypto work.
320If 0 is given, PKCS#5v2 will not be used.
321PKCS#5v2 processing is performed once, after all parts of the passphrase
322component have been read.
323.It Fl J Ar newpassfile
324Specifies a file which contains the passphrase component of the User Key
325(or part of it).
326If
327.Ar newpassfile
328is given as -, standard input will be used.
329Only the first line (excluding new-line character) is taken from the given file.
330This argument can be specified multiple times, which has the effect of
331reassembling a single passphrase split across multiple files.
332Cannot be combined with the
333.Fl P
334option.
335.It Fl K Ar newkeyfile
336Specifies a file which contains the keyfile component of the User Key
337(or part of it).
338If
339.Ar newkeyfile
340is given as -, standard input will be used.
341This argument can be specified multiple times, which has the effect of
342reassembling a single keyfile split across multiple keyfile parts.
343.It Fl l Ar keylen
344Data Key length to use with the given cryptographic algorithm.
345If the length is not specified, the selected algorithm uses its
346.Em default
347key length.
348.Bl -ohang -offset indent
349.It Nm AES-XTS
350.Em 128 ,
351256
352.It Nm AES-CBC , Nm Camellia-CBC
353.Em 128 ,
354192,
355256
356.El
357.It Fl P
358Do not use a passphrase as a component of the User Key.
359Cannot be combined with the
360.Fl J
361option.
362.It Fl s Ar sectorsize
363Change decrypted provider's sector size.
364Increasing the sector size allows increased performance,
365because encryption/decryption which requires an initialization vector
366is done per sector; fewer sectors means less computational work.
367.It Fl R
368Turn off automatic expansion.
369By default, if the underlying provider grows, the encrypted provider will
370grow automatically too.
371The metadata will be moved to the new location.
372If automatic expansion if turned off and the underlying provider changes
373size, attaching encrypted provider will no longer be possible as the metadata
374will no longer be located in the last sector.
375In this case
376.Nm GELI
377will only log the previous size of the underlying provider, so metadata can
378be found easier, if resize was done by mistake.
379.It Fl T
380Don't pass through
381.Dv BIO_DELETE
382calls (i.e., TRIM/UNMAP).
383This can prevent an attacker from knowing how much space you're actually
384using and which sectors contain live data, but will also prevent the
385backing store (SSD, etc) from reclaiming space you're not using, which
386may degrade its performance and lifespan.
387The underlying provider may or may not actually obliterate the deleted
388sectors when TRIM is enabled, so it should not be considered to add any
389security.
390.It Fl V Ar version
391Metadata version to use.
392This option is helpful when creating a provider that may be used by older
393.Nm FreeBSD/GELI
394versions.
395Consult the
396.Sx HISTORY
397section to find which metadata version is supported by which
398.Fx
399version.
400Note that using an older version of metadata may limit the number of
401features available.
402.El
403.It Cm attach
404Attach the given providers.
405The encrypted Master Keys are loaded from the metadata and decrypted
406using the given passphrase/keyfile and new GEOM providers are created
407using the specified provider names.
408A
409.Qq .eli
410suffix is added to the user specified provider names.
411Multiple providers can only be attached with a single
412.Cm attach
413command if they all have the same passphrase and keyfiles.
414.Pp
415Additional options include:
416.Bl -tag -width ".Fl j Ar passfile"
417.It Fl C
418Do a dry-run decryption.
419This is useful to verify passphrase and keyfile without decrypting the device.
420.It Fl d
421If specified, the decrypted providers are detached automatically on last close,
422so the user does not have to remember to detach
423providers after unmounting the filesystems.
424This only works when providers were opened for writing, and will not work if
425the filesystems on the providers were mounted read-only.
426Probably a better choice is the
427.Fl l
428option for the
429.Cm detach
430subcommand.
431.It Fl n Ar keyno
432Specifies the index number of the Master Key copy to use (could be 0 or 1).
433If the index number is not provided all keys will be tested.
434.It Fl j Ar passfile
435Specifies a file which contains the passphrase component of the User Key
436(or part of it).
437For more information see the description of the
438.Fl J
439option for the
440.Cm init
441subcommand.
442The same passfiles are used for all listed providers.
443.It Fl k Ar keyfile
444Specifies a file which contains the keyfile component of the User Key
445(or part of it).
446For more information see the description of the
447.Fl K
448option for the
449.Cm init
450subcommand.
451The same keyfiles are used for all listed providers.
452.It Fl p
453Do not use a passphrase as a component of the User Keys.
454Cannot be combined with the
455.Fl j
456option.
457.It Fl r
458Attach read-only providers.
459They are not opened for writing.
460.El
461.It Cm detach
462Detach the given providers, which means remove the devfs entry
463and clear the Master Key and Data Keys from memory.
464.Pp
465Additional options include:
466.Bl -tag -width ".Fl f"
467.It Fl f
468Force detach - detach even if the provider is open.
469.It Fl l
470Mark provider to detach on last close, after the last filesystem has been
471unmounted.
472If this option is specified, the provider will not be detached
473while it is open, but will be automatically detached when it is closed for the
474last time even if it was only opened for reading.
475.El
476.It Cm onetime
477Attach the given providers with a random, one-time (ephemeral) Master Key.
478The command can be used to encrypt swap partitions or temporary filesystems.
479.Pp
480Additional options include:
481.Bl -tag -width ".Fl a Ar sectorsize"
482.It Fl a Ar aalgo
483Enable data integrity verification (authentication).
484For more information, see the description of the
485.Cm init
486subcommand.
487.It Fl e Ar ealgo
488Encryption algorithm to use.
489For more information, see the description of the
490.Cm init
491subcommand.
492.It Fl d
493Detach on last close, after the last filesystem has been unmounted.
494Note: this option is not usable for temporary filesystems as the provider is
495detached after the filesystem has been created.
496It still can, and should, be used for swap partitions.
497For more information, see the description of the
498.Cm attach
499subcommand.
500.It Fl l Ar keylen
501Data Key length to use with the given cryptographic algorithm.
502For more information, see the description of the
503.Cm init
504subcommand.
505.It Fl s Ar sectorsize
506Change decrypted provider's sector size.
507For more information, see the description of the
508.Cm init
509subcommand.
510.It Fl R
511Turn off automatic expansion.
512For more information, see the description of the
513.Cm init
514subcommand.
515.It Fl T
516Disable TRIM/UNMAP passthru.
517For more information, see the description of the
518.Cm init
519subcommand.
520.El
521.It Cm configure
522Change configuration of the given providers.
523.Pp
524Additional options include:
525.Bl -tag -width ".Fl b"
526.It Fl b
527Set the BOOT flag on the given providers.
528For more information, see the description of the
529.Cm init
530subcommand.
531.It Fl B
532Remove the BOOT flag from the given providers.
533.It Fl d
534When entering the passphrase to boot from this encrypted root filesystem, echo
535.Ql *
536characters.
537This makes the length of the passphrase visible.
538.It Fl D
539Disable echoing of any characters when a passphrase is entered to boot from this
540encrypted root filesystem.
541This hides the passphrase length.
542.It Fl g
543Enable booting from this encrypted root filesystem.
544The boot loader prompts for the passphrase and loads
545.Xr loader 8
546from the encrypted partition.
547.It Fl G
548Deactivate booting from this encrypted root partition.
549.It Fl r
550Turn on automatic expansion.
551For more information, see the description of the
552.Cm init
553subcommand.
554.It Fl R
555Turn off automatic expansion.
556.It Fl t
557Enable TRIM/UNMAP passthru.
558For more information, see the description of the
559.Cm init
560subcommand.
561.It Fl T
562Disable TRIM/UNMAP passthru.
563.El
564.It Cm setkey
565Install a copy of the Master Key into the selected slot, encrypted with
566a new User Key.
567If the selected slot is populated, replace the existing copy.
568A provider has one Master Key, which can be stored in one or both slots,
569each encrypted with an independent User Key.
570With the
571.Cm init
572subcommand, only key number 0 is initialized.
573The User Key can be changed at any time: for an attached provider,
574for a detached provider, or on the backup file.
575When a provider is attached, the user does not have to provide
576an existing passphrase/keyfile.
577.Pp
578Additional options include:
579.Bl -tag -width ".Fl J Ar newpassfile"
580.It Fl i Ar iterations
581Number of iterations to use with PKCS#5v2.
582If 0 is given, PKCS#5v2 will not be used.
583To be able to use this option with the
584.Cm setkey
585subcommand, only one key has to be defined and this key must be changed.
586.It Fl j Ar passfile
587Specifies a file which contains the passphrase component of a current User Key
588(or part of it).
589.It Fl J Ar newpassfile
590Specifies a file which contains the passphrase component of the new User Key
591(or part of it).
592.It Fl k Ar keyfile
593Specifies a file which contains the keyfile component of a current User Key
594(or part of it).
595.It Fl K Ar newkeyfile
596Specifies a file which contains the keyfile component of the new User Key
597(or part of it).
598.It Fl n Ar keyno
599Specifies the index number of the Master Key copy to change (could be 0 or 1).
600If the provider is attached and no key number is given, the key
601used for attaching the provider will be changed.
602If the provider is detached (or we are operating on a backup file)
603and no key number is given, the first Master Key copy to be successfully
604decrypted with the provided User Key passphrase/keyfile will be changed.
605.It Fl p
606Do not use a passphrase as a component of the current User Key.
607Cannot be combined with the
608.Fl j
609option.
610.It Fl P
611Do not use a passphrase as a component of the new User Key.
612Cannot be combined with the
613.Fl J
614option.
615.El
616.It Cm delkey
617Destroy (overwrite with random data) the selected Master Key copy.
618If one is destroying keys for an attached provider, the provider
619will not be detached even if all copies of the Master Key are destroyed.
620It can even be rescued with the
621.Cm setkey
622subcommand because the Master Key is still in memory.
623.Pp
624Additional options include:
625.Bl -tag -width ".Fl a Ar keyno"
626.It Fl a
627Destroy all copies of the Master Key (does not need
628.Fl f
629option).
630.It Fl f
631Force key destruction.
632This option is needed to destroy the last copy of the Master Key.
633.It Fl n Ar keyno
634Specifies the index number of the Master Key copy.
635If the provider is attached and no key number is given, the key
636used for attaching the provider will be destroyed.
637If provider is detached (or we are operating on a backup file) the key number
638has to be given.
639.El
640.It Cm kill
641This command should be used only in emergency situations.
642It will destroy all copies of the Master Key on a given provider and will
643detach it forcibly (if it is attached).
644This is absolutely a one-way command - if you do not have a metadata
645backup, your data is gone for good.
646In case the provider was attached with the
647.Fl r
648flag, the keys will not be destroyed, only the provider will be detached.
649.Pp
650Additional options include:
651.Bl -tag -width ".Fl a"
652.It Fl a
653If specified, all currently attached providers will be killed.
654.El
655.It Cm backup
656Backup metadata from the given provider to the given file.
657.It Cm restore
658Restore metadata from the given file to the given provider.
659.Pp
660Additional options include:
661.Bl -tag -width ".Fl f"
662.It Fl f
663Metadata contains the size of the provider to ensure that the correct
664partition or slice is attached.
665If an attempt is made to restore metadata to a provider that has a different
666size,
667.Nm
668will refuse to restore the data unless the
669.Fl f
670switch is used.
671If the partition or slice has been grown, the
672.Cm resize
673subcommand should be used rather than attempting to relocate the metadata
674through
675.Cm backup
676and
677.Cm restore .
678.El
679.It Cm suspend
680Suspend device by waiting for all inflight requests to finish, clearing all
681sensitive information such as the Master Key and Data Keys from kernel memory,
682and blocking all further I/O requests until the
683.Cm resume
684subcommand is executed.
685This functionality is useful for laptops.
686Suspending a laptop should not leave an encrypted device attached.
687The
688.Cm suspend
689subcommand can be used rather than closing all files and directories from
690filesystems on the encrypted device, unmounting the filesystem, and
691detaching the device.
692Any access to the encrypted device will be blocked until the Master Key is
693reloaded through the
694.Cm resume
695subcommand.
696Thus there is no need to close nor unmount anything.
697The
698.Cm suspend
699subcommand does not work with devices created with the
700.Cm onetime
701subcommand.
702Please note that sensitive data might still be present in memory locations
703such as the filesystem cache after suspending an encrypted device.
704.Pp
705Additional options include:
706.Bl -tag -width ".Fl a"
707.It Fl a
708Suspend all
709.Nm
710devices.
711.El
712.It Cm resume
713Resume previously suspended device.
714The caller must ensure that executing this subcommand does not access the
715suspended device, leading to a deadlock.
716For example, suspending a device which contains the filesystem where the
717.Nm
718utility is stored is a bad idea.
719.Pp
720Additional options include:
721.Bl -tag -width ".Fl j Ar passfile"
722.It Fl j Ar passfile
723Specifies a file which contains the passphrase component of the User Key,
724or part of it.
725For more information see the description of the
726.Fl J
727option for the
728.Cm init
729subcommand.
730.It Fl k Ar keyfile
731Specifies a file which contains the keyfile component of the User Key,
732or part of it.
733For more information see the description of the
734.Fl K
735option for the
736.Cm init
737subcommand.
738.It Fl p
739Do not use a passphrase as a component of the User Key.
740Cannot be combined with the
741.Fl j
742option.
743.El
744.It Cm resize
745Inform
746.Nm
747that the provider has been resized.
748The old metadata block is relocated to the correct position at the end of the
749provider and the provider size is updated.
750.Pp
751Additional options include:
752.Bl -tag -width ".Fl s Ar oldsize"
753.It Fl s Ar oldsize
754The size of the provider before it was resized.
755.El
756.It Cm version
757If no arguments are given, the
758.Cm version
759subcommand will print the version of
760.Nm
761userland utility as well as the version of the
762.Nm ELI
763GEOM class.
764.Pp
765If GEOM providers are specified, the
766.Cm version
767subcommand will print metadata version used by each of them.
768.It Cm clear
769Clear metadata from the given providers.
770.Em WARNING :
771This will erase with zeros the encrypted Master Key copies stored in the
772metadata.
773.It Cm dump
774Dump metadata stored on the given providers.
775.It Cm list
776See
777.Xr geom 8 .
778.It Cm status
779See
780.Xr geom 8 .
781.It Cm load
782See
783.Xr geom 8 .
784.It Cm unload
785See
786.Xr geom 8 .
787.El
788.Pp
789Additional options include:
790.Bl -tag -width ".Fl v"
791.It Fl v
792Be more verbose.
793.El
794.Sh KEY SUMMARY
795.Ss Master Key
796Upon
797.Cm init ,
798the
799.Nm
800utility generates a random Master Key for the provider.
801The Master Key never changes during the lifetime of the provider.
802Each copy of the provider metadata, active or backed up to a file, can store
803up to two, independently-encrypted copies of the Master Key.
804.Ss User Key
805Each stored copy of the Master Key is encrypted with a User Key, which
806is generated by the
807.Nm
808utility from a passphrase and/or a keyfile.
809The
810.Nm
811utility first reads all parts of the keyfile in the order specified on the
812command line, then reads all parts of the stored passphrase in the order
813specified on the command line.
814If no passphrase parts are specified, the system prompts the user to enter
815the passphrase.
816The passphrase is optionally strengthened by PKCS#5v2.
817The User Key is a digest computed over the concatenated keyfile and passphrase.
818.Ss Data Key
819During operation, one or more Data Keys are deterministically derived by
820the kernel from the Master Key and cached in memory.
821The number of Data Keys used by a given provider, and the way they are
822derived, depend on the GELI version and whether the provider is configured to
823use data authentication.
824.Sh SYSCTL VARIABLES
825The following
826.Xr sysctl 8
827variables can be used to control the behavior of the
828.Nm ELI
829GEOM class.
830The default value is shown next to each variable.
831Some variables can also be set in
832.Pa /boot/loader.conf .
833.Bl -tag -width indent
834.It Va kern.geom.eli.version
835Version number of the
836.Nm ELI
837GEOM class.
838.It Va kern.geom.eli.debug : No 0
839Debug level of the
840.Nm ELI
841GEOM class.
842This can be set to a number between 0 and 3 inclusive.
843If set to 0, minimal debug information is printed.
844If set to 3, the
845maximum amount of debug information is printed.
846.It Va kern.geom.eli.tries : No 3
847Number of times a user is asked for the passphrase.
848This is only used for providers which are attached on boot,
849before the root filesystem is mounted.
850If set to 0, attaching providers on boot will be disabled.
851This variable should be set in
852.Pa /boot/loader.conf .
853.It Va kern.geom.eli.overwrites : No 5
854Specifies how many times the Master Key is overwritten
855with random values when it is destroyed.
856After this operation it is filled with zeros.
857.It Va kern.geom.eli.visible_passphrase : No 0
858If set to 1, the passphrase entered on boot will be visible.
859This alternative should be used with caution as the entered
860passphrase can be logged and exposed via
861.Xr dmesg 8 .
862This variable should be set in
863.Pa /boot/loader.conf .
864.It Va kern.geom.eli.threads : No 0
865Specifies how many kernel threads should be used for doing software
866cryptography.
867Its purpose is to increase performance on SMP systems.
868If set to 0, a CPU-pinned thread will be started for every active CPU.
869.It Va kern.geom.eli.batch : No 0
870When set to 1, can speed-up crypto operations by using batching.
871Batching reduces the number of interrupts by responding to a group of
872crypto requests with one interrupt.
873The crypto card and the driver has to support this feature.
874.It Va kern.geom.eli.key_cache_limit : No 8192
875Specifies how many Data Keys to cache.
876The default limit
877(8192 keys) will allow caching of all keys for a 4TB provider with 512 byte
878sectors and will take around 1MB of memory.
879.It Va kern.geom.eli.key_cache_hits
880Reports how many times we were looking up a Data Key and it was already in
881cache.
882This sysctl is not updated for providers that need fewer Data Keys than
883the limit specified in
884.Va kern.geom.eli.key_cache_limit .
885.It Va kern.geom.eli.key_cache_misses
886Reports how many times we were looking up a Data Key and it was not in cache.
887This sysctl is not updated for providers that need fewer Data Keys than the limit
888specified in
889.Va kern.geom.eli.key_cache_limit .
890.El
891.Sh EXIT STATUS
892Exit status is 0 on success, and 1 if the command fails.
893.Sh EXAMPLES
894Initialize a provider which is going to be encrypted with a
895passphrase and random data from a file on the user's pen drive.
896Use 4kB sector size.
897Attach the provider, create a filesystem, and mount it.
898Do the work.
899Unmount the provider and detach it:
900.Bd -literal -offset indent
901# dd if=/dev/random of=/mnt/pendrive/da2.key bs=64 count=1
902# geli init -s 4096 -K /mnt/pendrive/da2.key /dev/da2
903Enter new passphrase:
904Reenter new passphrase:
905# geli attach -k /mnt/pendrive/da2.key /dev/da2
906Enter passphrase:
907# dd if=/dev/random of=/dev/da2.eli bs=1m
908# newfs /dev/da2.eli
909# mount /dev/da2.eli /mnt/secret
910\&...
911# umount /mnt/secret
912# geli detach da2.eli
913.Ed
914.Pp
915Create an encrypted provider, but use two User Keys:
916one for your employee and one for you as the company's security officer
917(so it is not a tragedy if the employee
918.Qq accidentally
919forgets his passphrase):
920.Bd -literal -offset indent
921# geli init /dev/da2
922Enter new passphrase:	(enter security officer's passphrase)
923Reenter new passphrase:
924# geli setkey -n 1 /dev/da2
925Enter passphrase:	(enter security officer's passphrase)
926Enter new passphrase:	(let your employee enter his passphrase ...)
927Reenter new passphrase:	(... twice)
928.Ed
929.Pp
930You are the security officer in your company.
931Create an encrypted provider for use by the user, but remember that users
932forget their passphrases, so backup the Master Key with your own random key:
933.Bd -literal -offset indent
934# dd if=/dev/random of=/mnt/pendrive/keys/`hostname` bs=64 count=1
935# geli init -P -K /mnt/pendrive/keys/`hostname` /dev/ada0s1e
936# geli backup /dev/ada0s1e /mnt/pendrive/backups/`hostname`
937(use key number 0, so the encrypted Master Key will be re-encrypted by this)
938# geli setkey -n 0 -k /mnt/pendrive/keys/`hostname` /dev/ada0s1e
939(allow the user to enter his passphrase)
940Enter new passphrase:
941Reenter new passphrase:
942.Ed
943.Pp
944Encrypted swap partition setup:
945.Bd -literal -offset indent
946# dd if=/dev/random of=/dev/ada0s1b bs=1m
947# geli onetime -d ada0s1b
948# swapon /dev/ada0s1b.eli
949.Ed
950.Pp
951The example below shows how to configure two providers which will be attached
952on boot, before the root filesystem is mounted.
953One of them is using passphrase and three keyfile parts and the other is
954using only a keyfile in one part:
955.Bd -literal -offset indent
956# dd if=/dev/random of=/dev/da0 bs=1m
957# dd if=/dev/random of=/boot/keys/da0.key0 bs=32k count=1
958# dd if=/dev/random of=/boot/keys/da0.key1 bs=32k count=1
959# dd if=/dev/random of=/boot/keys/da0.key2 bs=32k count=1
960# geli init -b -K /boot/keys/da0.key0 -K /boot/keys/da0.key1 -K /boot/keys/da0.key2 da0
961Enter new passphrase:
962Reenter new passphrase:
963# dd if=/dev/random of=/dev/da1s3a bs=1m
964# dd if=/dev/random of=/boot/keys/da1s3a.key bs=128k count=1
965# geli init -b -P -K /boot/keys/da1s3a.key da1s3a
966.Ed
967.Pp
968The providers are initialized, now we have to add these lines to
969.Pa /boot/loader.conf :
970.Bd -literal -offset indent
971geli_da0_keyfile0_load="YES"
972geli_da0_keyfile0_type="da0:geli_keyfile0"
973geli_da0_keyfile0_name="/boot/keys/da0.key0"
974geli_da0_keyfile1_load="YES"
975geli_da0_keyfile1_type="da0:geli_keyfile1"
976geli_da0_keyfile1_name="/boot/keys/da0.key1"
977geli_da0_keyfile2_load="YES"
978geli_da0_keyfile2_type="da0:geli_keyfile2"
979geli_da0_keyfile2_name="/boot/keys/da0.key2"
980
981geli_da1s3a_keyfile0_load="YES"
982geli_da1s3a_keyfile0_type="da1s3a:geli_keyfile0"
983geli_da1s3a_keyfile0_name="/boot/keys/da1s3a.key"
984.Ed
985.Pp
986If there is only one keyfile, the index might be omitted:
987.Bd -literal -offset indent
988geli_da1s3a_keyfile_load="YES"
989geli_da1s3a_keyfile_type="da1s3a:geli_keyfile"
990geli_da1s3a_keyfile_name="/boot/keys/da1s3a.key"
991.Ed
992.Pp
993By convention, these loader variables are called
994.Sm off
995.Va geli_ No < Ar device No > Va _load .
996.Sm on
997However, the actual name prefix before
998.Va _load , _type ,
999or
1000.Va _name
1001does not matter.
1002At boot time, the
1003.Nm
1004module searches through all
1005.Sm off
1006.No < Va prefix No > Va _type No -like
1007.Sm on
1008variables that have a value of
1009.Sm off
1010.Dq < Ar device No > :geli_keyfile .
1011.Sm on
1012The paths to keyfiles are then extracted from
1013.Sm off
1014.No < Ar prefix No > Va _name
1015.Sm on
1016variables.
1017In the example above,
1018.Ar prefix
1019is
1020.Dq Li geli_da1s3a_keyfile .
1021.Pp
1022Not only configure encryption, but also data integrity verification using
1023.Nm HMAC/SHA256 .
1024.Bd -literal -offset indent
1025# geli init -a hmac/sha256 -s 4096 /dev/da0
1026Enter new passphrase:
1027Reenter new passphrase:
1028# geli attach /dev/da0
1029Enter passphrase:
1030# dd if=/dev/random of=/dev/da0.eli bs=1m
1031# newfs /dev/da0.eli
1032# mount /dev/da0.eli /mnt/secret
1033.Ed
1034.Pp
1035.Cm geli
1036writes the metadata backup by default to the
1037.Pa /var/backups/<prov>.eli
1038file.
1039If the metadata is lost in any way (e.g., by accidental overwrite), it can be restored.
1040Consider the following situation:
1041.Bd -literal -offset indent
1042# geli init /dev/da0
1043Enter new passphrase:
1044Reenter new passphrase:
1045
1046Metadata backup can be found in /var/backups/da0.eli and
1047can be restored with the following command:
1048
1049	# geli restore /var/backups/da0.eli /dev/da0
1050
1051# geli clear /dev/da0
1052# geli attach /dev/da0
1053geli: Cannot read metadata from /dev/da0: Invalid argument.
1054# geli restore /var/backups/da0.eli /dev/da0
1055# geli attach /dev/da0
1056Enter passphrase:
1057.Ed
1058.Pp
1059If an encrypted filesystem is extended, it is necessary to relocate and
1060update the metadata:
1061.Bd -literal -offset indent
1062# gpart create -s GPT ada0
1063# gpart add -s 1g -t freebsd-ufs -i 1 ada0
1064# geli init -K keyfile -P ada0p1
1065# gpart resize -s 2g -i 1 ada0
1066# geli resize -s 1g ada0p1
1067# geli attach -k keyfile -p ada0p1
1068.Ed
1069.Pp
1070Initialize provider with the passphrase split into two files.
1071The provider can be attached using those two files or by entering
1072.Dq foobar
1073as the passphrase at the
1074.Nm
1075prompt:
1076.Bd -literal -offset indent
1077# echo foo > da0.pass0
1078# echo bar > da0.pass1
1079# geli init -J da0.pass0 -J da0.pass1 da0
1080# geli attach -j da0.pass0 -j da0.pass1 da0
1081# geli detach da0
1082# geli attach da0
1083Enter passphrase: foobar
1084.Ed
1085.Pp
1086Suspend all
1087.Nm
1088devices on a laptop, suspend the laptop, then resume devices one by one after
1089resuming the laptop:
1090.Bd -literal -offset indent
1091# geli suspend -a
1092# zzz
1093<resume your laptop>
1094# geli resume -p -k keyfile gpt/secret
1095# geli resume gpt/private
1096Enter passphrase:
1097.Ed
1098.Sh ENCRYPTION MODES
1099.Nm
1100supports two encryption modes:
1101.Nm XTS ,
1102which was standardized as
1103.Nm IEEE P1619
1104and
1105.Nm CBC
1106with unpredictable IV.
1107The
1108.Nm CBC
1109mode used by
1110.Nm
1111is very similar to the mode
1112.Nm ESSIV .
1113.Sh DATA AUTHENTICATION
1114.Nm
1115can verify data integrity when an authentication algorithm is specified.
1116When data corruption/modification is detected,
1117.Nm
1118will not return any data, but instead will return an error
1119.Pq Er EINVAL .
1120The offset and size of the corrupted data will be printed on the console.
1121It is important to know against which attacks
1122.Nm
1123provides protection for your data.
1124If data is modified in-place or copied from one place on the disk
1125to another even without modification,
1126.Nm
1127should be able to detect such a change.
1128If an attacker can remember the encrypted data, he can overwrite any future
1129changes with the data he owns without it being noticed.
1130In other words
1131.Nm
1132will not protect your data against replay attacks.
1133.Pp
1134It is recommended to write to the whole provider before first use,
1135in order to make sure that all sectors and their corresponding
1136checksums are properly initialized into a consistent state.
1137One can safely ignore data authentication errors that occur immediately
1138after the first time a provider is attached and before it is
1139initialized in this way.
1140.Sh SEE ALSO
1141.Xr crypto 4 ,
1142.Xr gbde 4 ,
1143.Xr geom 4 ,
1144.Xr loader.conf 5 ,
1145.Xr gbde 8 ,
1146.Xr geom 8 ,
1147.Xr crypto 9
1148.Sh HISTORY
1149The
1150.Nm
1151utility appeared in
1152.Fx 6.0 .
1153Support for the
1154.Nm Camellia
1155block cipher was implemented by Yoshisato Yanagisawa in
1156.Fx 7.0 .
1157.Pp
1158Highest
1159.Nm GELI
1160metadata version supported by the given FreeBSD version:
1161.Bl -column -offset indent ".Sy FreeBSD" ".Sy version"
1162.It Sy FreeBSD Ta Sy GELI
1163.It Sy version Ta Sy version
1164.Pp
1165.It Li 6.0 Ta 0
1166.It Li 6.1 Ta 0
1167.It Li 6.2 Ta 3
1168.It Li 6.3 Ta 3
1169.It Li 6.4 Ta 3
1170.Pp
1171.It Li 7.0 Ta 3
1172.It Li 7.1 Ta 3
1173.It Li 7.2 Ta 3
1174.It Li 7.3 Ta 3
1175.It Li 7.4 Ta 3
1176.Pp
1177.It Li 8.0 Ta 3
1178.It Li 8.1 Ta 3
1179.It Li 8.2 Ta 5
1180.Pp
1181.It Li 9.0 Ta 6
1182.Pp
1183.It Li 10.0 Ta 7
1184.El
1185.Sh AUTHORS
1186.An Pawel Jakub Dawidek Aq Mt pjd@FreeBSD.org
1187