Skip to content

Commit

Permalink
Fix ruby userpass incompatible pointer without breaking using user pw…
Browse files Browse the repository at this point in the history
…d when bl doesn't have one
  • Loading branch information
Romain Coltel committed Nov 6, 2020
1 parent f12deba commit 40fe0fa
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion include/dislocker/accesses/user_pass/user_pass.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
*/

int get_vmk_from_user_pass(dis_metadata_t dis_meta, dis_config_t* cfg, void** vmk_datum);
int get_vmk_from_user_pass2(dis_metadata_t dis_meta, dis_config_t* cfg, void** vmk_datum);
int get_vmk_from_user_pass2(dis_metadata_t dis_meta, uint8_t** user_password, void** vmk_datum);

int user_key(const uint8_t *user_password, const uint8_t *salt, uint8_t *result_key);

Expand Down
2 changes: 1 addition & 1 deletion src/accesses/accesses.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ static VALUE rb_get_vmk_from_userpass(VALUE self, VALUE rb_userpass)
userpass = (uint8_t*) StringValuePtr(rb_userpass);

/* Get the VMK */
if(!get_vmk_from_user_pass2(dis_accesses->metadata, userpass, &vmk_datum))
if(!get_vmk_from_user_pass2(dis_accesses->metadata, &userpass, &vmk_datum))
rb_raise(rb_eRuntimeError, "Couldn't retrieve the VMK");

/* Save it */
Expand Down
32 changes: 16 additions & 16 deletions src/accesses/user_pass/user_pass.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,32 +44,32 @@ int get_vmk_from_user_pass(dis_metadata_t dis_meta,
dis_config_t* cfg,
void** vmk_datum)
{
return get_vmk_from_user_pass2(dis_meta, cfg, vmk_datum);
return get_vmk_from_user_pass2(dis_meta, &cfg->user_password, vmk_datum);
}


/**
* Get the VMK datum using a user password
*
* @param dataset The dataset of BitLocker's metadata on the volume
* @param cfg The configuration structure
* @param user_password The user password provided
* @param vmk_datum The datum_key_t found, containing the unencrypted VMK
* @return TRUE if result can be trusted, FALSE otherwise
*/
int get_vmk_from_user_pass2(dis_metadata_t dis_meta,
dis_config_t* cfg,
uint8_t** user_password,
void** vmk_datum)
{
// Check parameters
if(!dis_meta)
if(!dis_meta || !user_password)
return FALSE;

uint8_t user_hash[32] = {0,};
uint8_t salt[16] = {0,};

/* If the user password wasn't provide, ask for it */
if(!cfg->user_password)
if(!prompt_up(&cfg->user_password))
if(!*user_password)
if(!prompt_up(user_password))
{
dis_printf(L_ERROR, "Cannot get valid user password. Abort.\n");
return FALSE;
Expand All @@ -78,7 +78,7 @@ int get_vmk_from_user_pass2(dis_metadata_t dis_meta,
dis_printf(
L_DEBUG,
"Using the user password: '%s'.\n",
(char *) cfg->user_password
(char *) *user_password
);


Expand All @@ -96,8 +96,8 @@ int get_vmk_from_user_pass2(dis_metadata_t dis_meta,
"Error, can't find a valid and matching VMK datum. Abort.\n"
);
*vmk_datum = NULL;
memclean((char*) cfg->user_password, strlen((char*) cfg->user_password));
cfg->user_password = NULL;
memclean((char*) *user_password, strlen((char*) *user_password));
*user_password = NULL;
return FALSE;
}

Expand All @@ -124,8 +124,8 @@ int get_vmk_from_user_pass2(dis_metadata_t dis_meta,
);
dis_free(type_str);
*vmk_datum = NULL;
memclean( (char*) cfg->user_password, strlen((char*) cfg->user_password));
cfg->user_password = NULL;
memclean( (char*) *user_password, strlen((char*) *user_password));
*user_password = NULL;
return FALSE;
}

Expand All @@ -149,8 +149,8 @@ int get_vmk_from_user_pass2(dis_metadata_t dis_meta,
"Internal failure, abort.\n"
);
*vmk_datum = NULL;
memclean((char*) cfg->user_password, strlen((char*) cfg->user_password));
cfg->user_password = NULL;
memclean((char*) *user_password, strlen((char*) *user_password));
*user_password = NULL;
return FALSE;
}

Expand All @@ -159,12 +159,12 @@ int get_vmk_from_user_pass2(dis_metadata_t dis_meta,
* We have all the things we need to compute the intermediate key from
* the user password, so do it!
*/
if(!user_key(cfg->user_password, salt, user_hash))
if(!user_key(*user_password, salt, user_hash))
{
dis_printf(L_CRITICAL, "Can't stretch the user password, aborting.\n");
*vmk_datum = NULL;
memclean((char*) cfg->user_password, strlen((char*) cfg->user_password));
cfg->user_password = NULL;
memclean((char*) *user_password, strlen((char*) *user_password));
*user_password = NULL;
return FALSE;
}

Expand Down

0 comments on commit 40fe0fa

Please sign in to comment.