"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "zuluCrypt-cli/lib/open_luks.c" between
zuluCrypt-5.7.0.tar.xz and zuluCrypt-5.7.1.tar.xz

About: zuluCrypt is a simple but feature rich solution for hard drives encryption. It can manage PLAIN dm-crypt, LUKS, TrueCrypt and VeraCrypt encrypted volumes.

open_luks.c  (zuluCrypt-5.7.0.tar.xz):open_luks.c  (zuluCrypt-5.7.1.tar.xz)
skipping to change at line 36 skipping to change at line 36
* This header file is created by the build process and it checks if the version of cryptsetup >= 1.4.0 * This header file is created by the build process and it checks if the version of cryptsetup >= 1.4.0
*/ */
#include "luks_external_header.h" #include "luks_external_header.h"
static int zuluExit( int st,struct crypt_device * cd ) static int zuluExit( int st,struct crypt_device * cd )
{ {
crypt_free( cd ) ; crypt_free( cd ) ;
return st ; return st ;
} }
static int zuluExit_1( int r,struct crypt_device * cd,stringList_t stl )
{
crypt_free( cd ) ;
/*
* zuluCryptDeleteFile_1() is defined in open_path_security.c
*/
zuluCryptDeleteFile_1( StringListStringAtFirstPlace( stl ) ) ;
StringListDelete( &stl ) ;
return r ;
}
static int _open_luks_2( const char * device,const resolve_path_t * opt ) static int _open_luks_2( const char * device,const resolve_path_t * opt )
{ {
struct crypt_device * cd ; struct crypt_device * cd ;
uint32_t flags ; uint32_t flags ;
int st ; int st ;
/* /*
* open_struct_t is defined in includes.h * open_struct_t is defined in includes.h
*/ */
const open_struct_t * opts = opt->args ; const open_struct_t * opts = opt->args ;
if( zuluCryptPathIsNotValid( device ) ){ if( zuluCryptPathIsNotValid( device ) ){
return 3 ; return 3 ;
} }
if( crypt_init( &cd,device ) != 0 ){ if( opts->luks_detached_header ){
return 2 ;
}
if( crypt_load( cd,NULL,NULL ) != 0 ){
return zuluExit( 2,cd ) ;
}
if( opt->open_mode == O_RDONLY ){
flags = CRYPT_ACTIVATE_READONLY ;
}else{
flags = CRYPT_ACTIVATE_ALLOW_DISCARDS ;
}
st = crypt_activate_by_passphrase( cd,opts->mapper_name,CRYPT_ANY_SLOT,
opts->key,opts->key_len,flags ) ;
if( st >= 0 ){
return zuluExit( 0,cd ) ;
}else if( st == -1 ){
return zuluExit( 1,cd ) ;
}else{
return zuluExit( 2,cd ) ;
}
}
#if LUKS_EXTERNAL_HEADER #if LUKS_EXTERNAL_HEADER
/* if( crypt_init( &cd,opts->luks_detached_header ) != 0 ){
* This functionality is enabled with cryptsetup >= 1.4.0
*/
static int _open_luks_1( const char * device,const resolve_path_t * opt )
{
u_int32_t key_len ;
u_int32_t flags ;
u_int32_t luks_header_file_size ;
u_int32_t buffer_size ;
stringList_t stl ;
string_t * xt_0 = StringListArray( &stl,4 ) ;
string_t * xt_1 = xt_0 + 1 ;
string_t * xt_2 = xt_0 + 2 ;
string_t * xt_3 = xt_0 + 3 ;
const char * cipher ;
const char * mode ;
struct crypt_device * cd = NULL ; return 1 ;
}
struct crypt_params_plain plain ;
/*
* open_struct_t is defined in includes.h
*/
const open_struct_t * opts = opt->args ;
const size_t e = sizeof( u_int32_t ) ;
char * key_0 ;
const char * key ;
const char * luks_header_file ;
const char * luks_header_file_contents ;
size_t size ;
memset( &plain,'\0',sizeof( struct crypt_params_plain ) ) ;
plain.hash = NULL ;
plain.offset = 256 ;
plain.skip = 256 ;
plain.size = 0 ;
buffer_size = opts->key_len ;
if( buffer_size < 1048576 + 8 || buffer_size > ZULUCRYPT_LUKS2_MAX_HEADER
_SIZE * 2 ){
/*
* the structure is expected to be atleast 1MB + 8 bytes
*/
return 1 ;
}
/* if( crypt_load( cd,NULL,NULL ) != 0 ){
* opts->key variable is expected to hold a structure made up of 4 compon
ents.
* first component at offset 0 is a u_int32_t structure holding the size
of the passphrase
* Second component at offset 4 is a u_int32_t structure holding the size
of the contents of luks header
* third component at offset 8 is the passphrase to unlock the LUKS volu
me.
* last component is at offset that marks the end of the third componen
t.Where this offset will be depends on the length of the passphrase
*/
memcpy( &key_len,opts->key,e ) ; return zuluExit( 2,cd ) ;
key = opts->key + e + e ; }
memcpy( &luks_header_file_size,opts->key + e,e ) ; if( crypt_set_data_device( cd,device ) != 0 ){
luks_header_file_contents = opts->key + e + e + key_len ;
if( key_len + luks_header_file_size + e + e != buffer_size ){ return zuluExit( 1,cd ) ;
/* }
* malformed structure detected #else
*/
return 1 ;
}
if( luks_header_file_size < 1048576 || luks_header_file_size > ZULUCRYPT_
LUKS2_MAX_HEADER_SIZE ){
/*
* luks header backup or detached header is expected to be greate
r than 1MB but less than
* ZULUCRYPT_LUKS2_MAX_HEADER_SIZE
*/
return 1 ; return 1 ;
} #endif
/* }else{
* zuluCryptCreateKeyFile() is defined in open_tcrypt.c if( crypt_init( &cd,device ) != 0 ){
*/
*xt_0 = zuluCryptCreateKeyFile( luks_header_file_contents,luks_header_fil
e_size,"luks_header_file-" ) ;
luks_header_file = StringContent( *xt_0 ) ;
if( crypt_init( &cd,luks_header_file ) != 0 ){ return 2 ;
}
return zuluExit_1( 1,cd,stl ) ; if( crypt_load( cd,NULL,NULL ) != 0 ){
}
if( crypt_load( cd,NULL,NULL ) != 0 ){
return zuluExit_1( 1,cd,stl ) ; return zuluExit( 2,cd ) ;
}
} }
if( opt->open_mode == O_RDONLY ){ if( opt->open_mode == O_RDONLY ){
flags = CRYPT_ACTIVATE_READONLY ; flags = CRYPT_ACTIVATE_READONLY ;
}else{ }else{
flags = CRYPT_ACTIVATE_ALLOW_DISCARDS ; flags = CRYPT_ACTIVATE_ALLOW_DISCARDS ;
} }
if( opts->luks_detached_header ){ st = crypt_activate_by_passphrase( cd,opts->mapper_name,CRYPT_ANY_SLOT,
opts->key,opts->key_len,flags ) ;
if( crypt_set_data_device( cd,device ) != 0 ){
return zuluExit_1( 1,cd,stl ) ;
}
if( crypt_activate_by_passphrase( cd,opts->mapper_name,
CRYPT_ANY_SLOT,key,key_len,flag
s ) < 0 ){
return zuluExit_1( 1,cd,stl ) ;
}else{
return zuluExit_1( 0,cd,stl ) ;
}
}else if( opts->general_detached_header ){
size = crypt_get_volume_key_size( cd ) ;
*xt_1 = StringBuffer( size ) ;
key_0 = ( char * ) StringContent( *xt_1 ) ;
if( crypt_volume_key_get( cd,CRYPT_ANY_SLOT,key_0,&size,key,key_l
en ) < 0 ){
return zuluExit_1( 1,cd,stl ) ;
}
*xt_2 = String( crypt_get_cipher( cd ) ) ;
*xt_3 = String( crypt_get_cipher_mode( cd ) ) ;
crypt_free( cd ) ;
if( crypt_init( &cd,device ) != 0 ){
return zuluExit_1( 1,cd,stl ) ;
}
cipher = StringContent( *xt_2 ) ;
mode = StringContent( *xt_3 ) ;
if( crypt_format( cd,CRYPT_PLAIN,cipher,mode,NULL,NULL,size,&plai n ) != 0 ){ if( st >= 0 ){
return zuluExit_1( 1,cd,stl ) ; return zuluExit( 0,cd ) ;
}
if( crypt_activate_by_volume_key( cd,opts->mapper_name,key_0,size ,flags ) != 0 ){ }else if( st == -1 ){
return zuluExit_1( 1,cd,stl ) ; return zuluExit( 1,cd ) ;
}else{
return zuluExit_1( 0,cd,stl ) ;
}
}else{ }else{
return zuluExit_1( 1,cd,stl ) ; return zuluExit( 2,cd ) ;
} }
} }
#else
static int _open_luks_1( const char * device,const resolve_path_t * opts )
{
if( 0 && device && opts ){;}
return 1 ;
}
#endif
int zuluCryptOpenLuks( const char * device,const char * mapper, int zuluCryptOpenLuks( const char * device,const char * mapper,
const char * mode,const char * key,size_t key_len ) const char * mode,const char * key,size_t key_len )
{ {
open_struct_t opts ; open_struct_t opts ;
memset( &opts,'\0',sizeof( open_struct_t ) ) ; memset( &opts,'\0',sizeof( open_struct_t ) ) ;
opts.device = device ; opts.device = device ;
opts.mapper_name = mapper ; opts.mapper_name = mapper ;
opts.m_opts = mode ; opts.m_opts = mode ;
opts.key = key ; opts.key = key ;
opts.key_len = key_len; opts.key_len = key_len;
return zuluCryptOpenLuks_2( &opts ) ; return zuluCryptOpenLuks_2( &opts ) ;
} }
int zuluCryptOpenLuks_1( const open_struct_t * opts ) int zuluCryptOpenLuks_1( const open_struct_t * opts )
{ {
/* return zuluCryptOpenLuks_2( opts ) ;
* zuluCryptResolveDevicePath_0() is defined in resolve_path.c
*/
return zuluCryptResolveDevicePath_0( _open_luks_1,opts,2 ) ;
} }
int zuluCryptOpenLuks_2( const open_struct_t * opts ) int zuluCryptOpenLuks_2( const open_struct_t * opts )
{ {
/* /*
* zuluCryptResolveDevicePath_0() is defined in resolve_path.c * zuluCryptResolveDevicePath_0() is defined in resolve_path.c
*/ */
return zuluCryptResolveDevicePath_0( _open_luks_2,opts,2 ) ; return zuluCryptResolveDevicePath_0( _open_luks_2,opts,2 ) ;
} }
 End of changes. 20 change blocks. 
206 lines changed or deleted 27 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)