fixed password handling

git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-OpenPGP@5127 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2012-04-29 11:57:03 +00:00
parent b7dcbf3ef2
commit ce5e6d3949
7 changed files with 73 additions and 68 deletions

View file

@ -506,6 +506,7 @@ callback_write_parsed(const ops_parser_content_t *content_,
break;
case OPS_PARSER_CMD_GET_SK_PASSPHRASE:
case OPS_PARSER_CMD_GET_SK_PASSPHRASE_PREV_WAS_BAD:
// return callback_cmd_get_secret_key_passphrase(content_,cbinfo);
return cbinfo->cryptinfo.cb_get_passphrase(content_, cbinfo);
break;

View file

@ -921,6 +921,7 @@ void ops_parser_content_free(ops_parser_content_t *c)
break;
case OPS_PARSER_CMD_GET_SK_PASSPHRASE:
case OPS_PARSER_CMD_GET_SK_PASSPHRASE_PREV_WAS_BAD:
ops_cmd_get_passphrase_free(&c->content.secret_key_passphrase);
break;

View file

@ -348,51 +348,61 @@ callback_pk_session_key(const ops_parser_content_t *content_,ops_parse_cb_info_t
ops_parse_cb_return_t
callback_cmd_get_secret_key(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo)
{
ops_parser_content_union_t* content=(ops_parser_content_union_t *)&content_->content;
const ops_secret_key_t *secret;
ops_parser_content_t pc;
{
ops_parser_content_union_t* content=(ops_parser_content_union_t *)&content_->content;
const ops_secret_key_t *secret;
ops_parser_content_t pc;
OPS_USED(cbinfo);
OPS_USED(cbinfo);
// ops_print_packet(content_);
// ops_print_packet(content_);
switch(content_->tag)
switch(content_->tag)
{
case OPS_PARSER_CMD_GET_SECRET_KEY:
cbinfo->cryptinfo.keydata=ops_keyring_find_key_by_id(cbinfo->cryptinfo.keyring,content->get_secret_key.pk_session_key->key_id);
if (!cbinfo->cryptinfo.keydata || !ops_is_key_secret(cbinfo->cryptinfo.keydata))
return 0;
case OPS_PARSER_CMD_GET_SECRET_KEY:
cbinfo->cryptinfo.keydata=ops_keyring_find_key_by_id(cbinfo->cryptinfo.keyring,content->get_secret_key.pk_session_key->key_id);
if (!cbinfo->cryptinfo.keydata || !ops_is_key_secret(cbinfo->cryptinfo.keydata))
return 0;
/* now get the key from the data */
secret=ops_get_secret_key_from_data(cbinfo->cryptinfo.keydata);
while(!secret)
{
if (!cbinfo->cryptinfo.passphrase)
{
memset(&pc,'\0',sizeof pc);
pc.content.secret_key_passphrase.passphrase=&cbinfo->cryptinfo.passphrase;
CB(cbinfo,OPS_PARSER_CMD_GET_SK_PASSPHRASE,&pc);
if (!cbinfo->cryptinfo.passphrase)
{
fprintf(stderr,"can't get passphrase\n");
assert(0);
}
}
/* then it must be encrypted */
secret=ops_decrypt_secret_key_from_data(cbinfo->cryptinfo.keydata,cbinfo->cryptinfo.passphrase);
}
*content->get_secret_key.secret_key=secret;
break;
/* now get the key from the data */
secret=ops_get_secret_key_from_data(cbinfo->cryptinfo.keydata);
int tag_to_use = OPS_PARSER_CMD_GET_SK_PASSPHRASE ;
int nbtries = 0 ;
default:
// return callback_general(content_,cbinfo);
break;
while( (!secret) && nbtries++ < 3)
{
if (!cbinfo->cryptinfo.passphrase)
{
memset(&pc,'\0',sizeof pc);
pc.content.secret_key_passphrase.passphrase=&cbinfo->cryptinfo.passphrase;
CB(cbinfo,tag_to_use,&pc);
if (!cbinfo->cryptinfo.passphrase)
{
fprintf(stderr,"can't get passphrase\n");
assert(0);
}
}
/* then it must be encrypted */
secret=ops_decrypt_secret_key_from_data(cbinfo->cryptinfo.keydata,cbinfo->cryptinfo.passphrase);
free(cbinfo->cryptinfo.passphrase) ;
cbinfo->cryptinfo.passphrase = NULL ;
tag_to_use = OPS_PARSER_CMD_GET_SK_PASSPHRASE_PREV_WAS_BAD ;
}
if(!secret)
return 0 ;
*content->get_secret_key.secret_key=secret;
break;
default:
// return callback_general(content_,cbinfo);
break;
}
return OPS_RELEASE_MEMORY;
}
return OPS_RELEASE_MEMORY;
}
char *ops_get_passphrase(void)
{