/
tcplay.3
539 lines (531 loc) · 14 KB
/
tcplay.3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
.\"
.\" Copyright (c) 2011 The DragonFly Project. All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\"
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in
.\" the documentation and/or other materials provided with the
.\" distribution.
.\" 3. Neither the name of The DragonFly Project nor the names of its
.\" contributors may be used to endorse or promote products derived
.\" from this software without specific, prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
.\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
.\" FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
.\" COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
.\" INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
.\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
.\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
.\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd December 07, 2013
.Dt TCPLAY 3
.Os
.Sh NAME
.Nm tc_api_init ,
.Nm tc_api_uninit ,
.Nm tc_api_info_volume ,
.Nm tc_api_info_mapped_volume ,
.Nm tc_api_create_volume ,
.Nm tc_api_modify_volume ,
.Nm tc_api_map_volume ,
.Nm tc_api_unmap_volume ,
.Nm tc_api_check_cipher ,
.Nm tc_api_check_prf_hash ,
.Nm tc_api_get_error_msg ,
.Nm tc_api_get_summary ,
.Nm tc_api_get_state
.Nd TrueCrypt volume management
.Sh LIBRARY
.Lb libtcplay
.Sh SYNOPSIS
.In tcplay_api.h
.Ft int
.Fn tc_api_init "int verbose"
.Ft int
.Fn tc_api_uninit "void"
.Ft int
.Fn tc_api_info_volume "tc_api_opts *api_opts" "tc_api_volinfo *info"
.Ft int
.Fn tc_api_info_mapped_volume "tc_api_opts *api_opts" "tc_api_volinfo *info"
.Ft int
.Fn tc_api_create_volume "tc_api_opts *api_opts"
.Ft int
.Fn tc_api_modify_volume "tc_api_opts *api_opts"
.Ft int
.Fn tc_api_map_volume "tc_api_opts *api_opts"
.Ft int
.Fn tc_api_unmap_volume "tc_api_opts *api_opts"
.Ft int
.Fn tc_api_check_cipher "tc_api_opts *api_opts"
.Ft int
.Fn tc_api_check_prf_hash "tc_api_opts *api_opts"
.Ft const char *
.Fn tc_api_get_error_msg "void"
.Ft const char *
.Fn tc_api_get_summary "void"
.Ft tc_api_state
.Fn tc_api_get_state "float *progress_pct"
.Sh DESCRIPTION
The
.Nm tcplay
library provides an interface to create, query and map
TrueCrypt-compatible
volumes.
.Pp
The
.Fn tc_api_create_volume ,
.Fn tc_api_modify_volume ,
.Fn tc_api_map_volume ,
.Fn tc_api_unmap_volume ,
.Fn tc_api_check_cipher
and
.Fn tc_api_check_prf_hash
functions take a
.Vt tc_api_opts
data structure as only argument, which is defined as follows:
.Bd -literal
typedef struct tc_api_opts {
/* Common fields */
const char *tc_device;
const char *tc_passphrase;
const char **tc_keyfiles;
const char **tc_passphrase_hidden;
const char **tc_keyfiles_hidden;
/* Fields for mapping / info */
const char *tc_map_name;
int tc_protect_hidden;
/* Fields for mapping / info / modify */
int tc_password_retries;
int tc_interactive_prompt;
unsigned long tc_prompt_timeout;
int tc_use_system_encryption;
const char *tc_system_device;
int tc_use_fde;
int tc_use_backup;
int tc_allow_trim;
/* Fields for modify */
const char *tc_new_passphrase;
const char **tc_new_keyfiles;
const char *tc_new_prf_hash;
int tc_use_weak_salt;
/* Fields for creation */
const char *tc_cipher;
const char *tc_prf_hash;
const char *tc_cipher_hidden;
const char *tc_prf_hash_hidden;
size_t tc_size_hidden_in_bytes;
int tc_no_secure_erase;
int tc_use_weak_keys;
} tc_api_opts;
.Ed
.Pp
where the keyfile fields,
.Fa tc_keyfiles ,
.Fa tc_keyfiles_hidden
and
.Fa tc_new_keyfiles
are
.Dv NULL
terminated arrays of key file strings.
.Pp
The
.Fn tc_api_info_volume
and
.Fn tc_api_info_mapped_volume
functions take a
.Vt tc_api_volinfo
data structure as second argument, which is defined as follows:
.Bd -literal
typedef struct tc_api_volinfo {
char tc_device[1024];
char tc_cipher[256];
char tc_prf[64];
int tc_key_bits;
size_t tc_size; /* in bytes */
off_t tc_iv_offset; /* in bytes */
off_t tc_block_offset; /* in bytes */
} tc_api_volinfo;
.Ed
.Pp
The
.Fn tc_api_init
function initializes the library internals and prepares it for use via
the API.
This function has to be called before using any other API function.
If the
.Fa verbose
argument is non-zero, then the library will output information such as
errors via stdout and stderr.
.Pp
The
.Fn tc_api_uninit
function clears up all internal secure memory, such as memory used for
decrypted headers, passphrases, keyfiles, etc.
.Pp
The
.Fn tc_api_info_volume
function retrieves information about a volume using the parameters
specified in the
.Fa api_opts
argument.
All fields except
.Fa tc_map_name
are used in the same way as for
.Fn tc_api_map_volume .
The retrieved information is placed into the
.Fa info
argument.
The
.Fa tc_cipher
and
.Fa tc_prf
fields will contain a string describing the block cipher (chain)
and PBKDF2 PRF algorithm respectively.
The
.Fa tc_key_bits
field gives the total key size used for the block cipher(s).
The
.Fa tc_size
field gives the size of the volume in bytes.
The
.Fa tc_iv_offset
and
.Fa tc_block_offset
fields give the IV and block offset in bytes of the volume,
respectively.
The
.Fa tc_device
field contains the path to the raw encrypted block device.
.Pp
The
.Fn tc_api_info_mapped_volume
is similar to the
.Fn tc_api_info_volume
function, but is to be used on already mapped volumes and
doesn't require any passphrase or keyfiles.
The
.Fa tc_map_name
field in the
.Fa api_opts
parameter determines which mapped volume is to be queried.
The retrieved information is placed into the
.Fa info
argument.
All fields will be populated as when calling
.Fn tc_api_info_volume
except for the
.Fa tc_prf
field, which will contain the string "(unknown)".
.Pp
The
.Fn tc_api_create_volume
function creates a new volume using the parameters specified in the
.Fa api_opts
argument.
The new volume will be created on the device specified by
.Fa tc_device
using the cipher specified by
.Fa tc_cipher
and the pbkdf2 prf hash algorithm specified by
.Fa tc_prf_hash
and using the passphrase and keyfiles specified by
.Fa tc_passphrase
and
.Fa tc_keyfiles
respectively.
If
.Fa tc_size_hidden_in_bytes
is not zero, a hidden volume of the given size will be created, using
the cipher specified by
.Fa tc_cipher_hidden
and the pbkdf2 prf hash algorithm specified by
.Fa tc_prf_hash_hidden .
If
.Fa tc_cipher_hidden
or
.Fa tc_prf_hash_hidden
are
.Dv NULL ,
the same algorithm as for the outer volume will be used.
The passphrase and keyfiles used are specified by
.Fa tc_passphrase_hidden
and
.Fa tc_keyfiles_hidden
respectively.
If
.Fa tc_no_secure_erase
is specified, no erase will be performed.
If
.Fa tc_use_weak_keys
is specified, the key material for the master key will be taken from
.Pa /dev/urandom
instead of
.Pa /dev/random .
This option should never be used other than for testing.
.Pp
The
.Fn tc_api_modify_volume
function modifies a volume (header) according to the parameters specified
in the
.Fa api_opts
parameter.
The volume is specified in
.Fa tc_device .
The
.Fa tc_interactive_prompt
field determines whether the user will be prompted to enter a passphrase
interactively or whether the passphrase in
.Fa tc_passphrase
will be used.
If an interactive prompt is used, the prompt will time out after
.Fa tc_prompt_timeout
seconds.
A value of 0 indicates that no timeout will occur.
The number of passphrase entry retries is defined by
.Fa tc_password_retries .
Depending on the passphrase/keyfiles used
either the outer or the hidden volume header will be modified.
Any keyfiles that are needed to unlock the volume are specified in
.Fa tc_keyfiles .
If
.Fa tc_use_system_encryption
is specified, a device using system encryption can be accessed.
The
.Fa tc_system_device
should point to the parent device (i.e. underlying physical disk),
while the
.Fa tc_device
argument should point to the actual encrypted partition.
If
.Fa tc_use_fde
is specified, the device pointed to by
.Fa tc_device
should be a whole disk device, not any partition.
If
.Fa tc_use_backup
is specified,
.Nm tcplay
will use the backup headers at the end of a volume
instead of the primary headers as template for the modification.
Both the backup and the main header will always be written as part
of a
.Fn tc_api_modify_volume
call.
The
.Fa tc_new_passphrase
and
.Fa tc_new_keyfiles
arguments specify the new passphrase and keyfile(s) to be used, respectively.
The
.Fa tc_new_passphrase
argument will only be used if
.Fa tc_interactive_prompt
is not set, otherwise the user will be prompted for the new passphrase.
The
.Fa tc_new_prf_hash
specifies the PBKDF2 PRF hash algorithm to be used when reencrypting the header.
If it is
.Dv NULL ,
the same PBKDF2 PRF hash function will be used that the header already uses.
If
.Fa tc_use_weak_salt
is set, a weak source of entropy will be used for the salt of both the
main and backup headers.
This option does not affect the entropy of the master volume keys, as these
are not modified.
.Pp
The
.Fn tc_api_map_volume
function maps a volume using the parameters specified in the
.Fa api_opts
argument.
The volume, which will be mapped as
.Fa tc_map_name ,
is specified in
.Fa tc_device .
The
.Fa tc_interactive_prompt
field determines whether the user will be prompted to enter a passphrase
interactively or whether the passphrase in
.Fa tc_passphrase
will be used.
If an interactive prompt is used, the prompt will time out after
.Fa tc_prompt_timeout
seconds.
A value of 0 indicates that no timeout will occur.
The number of passphrase entry retries is defined by
.Fa tc_password_retries .
Depending on the passphrase/keyfiles used
either the outer or the hidden volume will be mapped.
If
.Fa tc_protect_hidden
is specified, the outer volume will be mapped, but its size will be
adjusted so that it does not map over the hidden volume - the hidden
volume will hence be protected from any accidental overwriting.
If
.Fa tc_protect_hidden
is specified, the passphrase and keyfiles for the hidden volume
must be specified in
.Fa tc_passphrase_hidden
and
.Fa tc_keyfiles_hidden .
If
.Fa tc_use_system_encryption
is specified, a device using system encryption can be accessed.
The
.Fa tc_system_device
should point to the parent device (i.e. underlying physical disk),
while the
.Fa tc_device
argument should point to the actual encrypted partition.
If
.Fa tc_use_fde
is specified, the device pointed to by
.Fa tc_device
should be a whole disk device, not any partition.
The device will be mapped or queried as a whole.
To access individual partitions, a utility such as
.Xr kpartx 8
should be used, which will create additional individual mappings
for each partition in the decrypted mapped volume.
For more details on full disk encryption, see
.Xr tcplay 8 .
If
.Fa tc_use_backup
is specified,
.Nm tcplay
will use the backup headers at the end of a volume
instead of the primary headers to access it.
If
.Fa tc_allow_trim
is specified,
.Nm tcplay
will allow TRIM (discards) on the mapped volume.
.Pp
The
.Fn tc_api_unmap_volume
unmaps / closes the volume specified in
.Fa tc_map_name .
.Pp
The
.Fn tc_api_check_cipher
function checks whether the cipher specified in the
.Fa api_opts
argument field
.Fa tc_cipher
is valid.
.Pp
The
.Fn tc_api_check_prf_hash
function checks whether the prf hash algorithm specified in the
.Fa api_opts
argument field
.Fa tc_prf_hash
is valid.
.Pp
The
.Fn tc_api_get_error_msg
function should be called whenver another API function returns
.Dv TC_ERR .
It returns a string containing a description of the error that
occured.
.Pp
The
.Fn tc_api_get_summary
function returns a string containing a summary of the current
progress of a certain operation.
Currently only the volume erasing
part of creating a new volume can provide a summary.
When no summary is available, an empty string is returned.
The output otherwise is equivalent to that of a
.Dv SIGINFO
signal when using
.Xr tcplay 8 .
.Pp
The
.Fn tc_api_get_state
function returns information on the current state of
.Nm tcplay .
Three states are currently reported:
.Bl -tag -width indent
.It Dv TC_STATE_GET_RANDOM
is reported when
.Nm tcplay
is gathering entropy for key material.
.It Dv TC_STATE_ERASE
is reported when the volume is being erased.
.It Dv TC_STATE_UNKNOWN
is reported in all other cases.
.El
.Pp
The two states
.Dv TC_STATE_GET_RANDOM
and
.Dv TC_STATE_ERASE
are reported separately, as they are the only lengthy steps
during the use of tcplay.
The
.Fa progress_pct
parameter, if not
.Dv NULL ,
will be set to the percentage completed so far of these operations.
.Sh NOTES
TrueCrypt limits passphrases to 64 characters (including the terminating
null character).
To be compatible with it,
.Nm tcplay
does the same.
All passphrases (exlcuding keyfiles) are trimmed to 64 characters.
Similarly, keyfiles are limited to a size of 1 MB, but up to 256
keyfiles can be used.
.Sh RETURN VALUES
All functions except
.Fn tc_api_get_error_msg
and
.Fn tc_api_get_summary
return either
.Dv TC_OK
to signal that the operation completed successfully, or
.Dv TC_ERR
to signal that an error occured.
.Pp
The
.Fn tc_api_get_error_msg
and
.Fn tc_api_get_summary
functions always return a valid, but possibly empty, string.
.Pp
The
.Fn tc_api_get_state
function always returns one of:
.Dv TC_STATE_UNKNOWN ,
.Dv TC_STATE_ERASE
or
.Dv TC_STATE_GET_RANDOM .
.Sh COMPATIBILITY
The
.Nm tcplay
library offers full compatibility with TrueCrypt volumes including
hidden
volumes, system encryption (map-only), keyfiles and cipher cascading.
.Sh SEE ALSO
.Xr tcplay 8 ,
.Xr kpartx 8
.Sh HISTORY
The
.Nm tcplay
library appeared in
.Dx 2.11 .
.Sh AUTHORS
.An Alex Hornung