mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-21 04:44:25 -04:00
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:
parent
b7dcbf3ef2
commit
ce5e6d3949
7 changed files with 73 additions and 68 deletions
|
@ -12,8 +12,10 @@ extern "C" {
|
||||||
#include <openpgpsdk/keyring.h>
|
#include <openpgpsdk/keyring.h>
|
||||||
#include <openpgpsdk/readerwriter.h>
|
#include <openpgpsdk/readerwriter.h>
|
||||||
#include <openpgpsdk/validate.h>
|
#include <openpgpsdk/validate.h>
|
||||||
|
#include <openpgpsdk/../../src/parse_local.h>
|
||||||
}
|
}
|
||||||
#include "pgphandler.h"
|
#include "pgphandler.h"
|
||||||
|
#include "retroshare/rsiface.h" // For rsicontrol.
|
||||||
|
|
||||||
std::string PGPIdType::toStdString() const
|
std::string PGPIdType::toStdString() const
|
||||||
{
|
{
|
||||||
|
@ -206,7 +208,7 @@ void PGPHandler::initCertificateInfo(PGPCertificateInfo& cert,const ops_keydata_
|
||||||
std::string namestring( (char *)keydata->uids[0].user_id ) ;
|
std::string namestring( (char *)keydata->uids[0].user_id ) ;
|
||||||
|
|
||||||
cert._name = "" ;
|
cert._name = "" ;
|
||||||
int i=0;
|
uint32_t i=0;
|
||||||
while(i < namestring.length() && namestring[i] != '(' && namestring[i] != '<') { cert._name += namestring[i] ; ++i ;}
|
while(i < namestring.length() && namestring[i] != '(' && namestring[i] != '<') { cert._name += namestring[i] ; ++i ;}
|
||||||
|
|
||||||
std::string& next = (namestring[i] == '(')?cert._comment:cert._email ;
|
std::string& next = (namestring[i] == '(')?cert._comment:cert._email ;
|
||||||
|
@ -308,22 +310,30 @@ bool PGPHandler::availableGPGCertificatesWithPrivateKeys(std::list<PGPIdType>& i
|
||||||
return true ;
|
return true ;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ops_parse_cb_return_t cb_get_passphrase(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo __attribute__((unused)))
|
static ops_parse_cb_return_t cb_get_passphrase(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo)// __attribute__((unused)))
|
||||||
{
|
{
|
||||||
const ops_parser_content_union_t *content=&content_->content;
|
const ops_parser_content_union_t *content=&content_->content;
|
||||||
// validate_key_cb_arg_t *arg=ops_parse_cb_get_arg(cbinfo);
|
// validate_key_cb_arg_t *arg=ops_parse_cb_get_arg(cbinfo);
|
||||||
// ops_error_t **errors=ops_parse_cb_get_errors(cbinfo);
|
// ops_error_t **errors=ops_parse_cb_get_errors(cbinfo);
|
||||||
|
|
||||||
|
bool prev_was_bad = false ;
|
||||||
|
|
||||||
switch(content_->tag)
|
switch(content_->tag)
|
||||||
{
|
{
|
||||||
|
case OPS_PARSER_CMD_GET_SK_PASSPHRASE_PREV_WAS_BAD: prev_was_bad = true ;
|
||||||
case OPS_PARSER_CMD_GET_SK_PASSPHRASE:
|
case OPS_PARSER_CMD_GET_SK_PASSPHRASE:
|
||||||
{
|
{
|
||||||
std::string passwd = getpass("Please enter passwd:") ;
|
std::string passwd;
|
||||||
*(content->secret_key_passphrase.passphrase)= (char *)ops_mallocz(passwd.length()+1) ;
|
std::string uid_hint = std::string((const char *)cbinfo->cryptinfo.keydata->uids[0].user_id) + "(" + PGPIdType(cbinfo->cryptinfo.keydata->key_id).toStdString()+")" ;
|
||||||
memcpy(*(content->secret_key_passphrase.passphrase),passwd.c_str(),passwd.length()) ;
|
|
||||||
return OPS_KEEP_MEMORY;
|
if (rsicontrol->getNotify().askForPassword(uid_hint, prev_was_bad, passwd) == false)
|
||||||
}
|
return OPS_RELEASE_MEMORY;
|
||||||
break;
|
|
||||||
|
*(content->secret_key_passphrase.passphrase)= (char *)ops_mallocz(passwd.length()+1) ;
|
||||||
|
memcpy(*(content->secret_key_passphrase.passphrase),passwd.c_str(),passwd.length()) ;
|
||||||
|
return OPS_KEEP_MEMORY;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -701,10 +711,12 @@ void PGPHandler::setAcceptConnexion(const PGPIdType& id,bool b)
|
||||||
std::map<std::string,PGPCertificateInfo>::iterator res = _public_keyring_map.find(id.toStdString()) ;
|
std::map<std::string,PGPCertificateInfo>::iterator res = _public_keyring_map.find(id.toStdString()) ;
|
||||||
|
|
||||||
if(res != _public_keyring_map.end())
|
if(res != _public_keyring_map.end())
|
||||||
|
{
|
||||||
if(b)
|
if(b)
|
||||||
res->second._flags |= PGPCertificateInfo::PGP_CERTIFICATE_FLAG_ACCEPT_CONNEXION ;
|
res->second._flags |= PGPCertificateInfo::PGP_CERTIFICATE_FLAG_ACCEPT_CONNEXION ;
|
||||||
else
|
else
|
||||||
res->second._flags &= ~PGPCertificateInfo::PGP_CERTIFICATE_FLAG_ACCEPT_CONNEXION ;
|
res->second._flags &= ~PGPCertificateInfo::PGP_CERTIFICATE_FLAG_ACCEPT_CONNEXION ;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PGPHandler::getGPGFilteredList(std::list<PGPIdType>& list,bool (*filter)(const PGPCertificateInfo&)) const
|
bool PGPHandler::getGPGFilteredList(std::list<PGPIdType>& list,bool (*filter)(const PGPCertificateInfo&)) const
|
||||||
|
|
|
@ -84,27 +84,6 @@ std::string pgp_pwd_callback(void * /*hook*/, const char *uid_hint, const char *
|
||||||
rsicontrol->getNotify().askForPassword(uid_hint, prev_was_bad, password) ;
|
rsicontrol->getNotify().askForPassword(uid_hint, prev_was_bad, password) ;
|
||||||
|
|
||||||
return password ;
|
return password ;
|
||||||
|
|
||||||
// #ifdef GPG_DEBUG2
|
|
||||||
// std::cerr << "pgp_pwd_callback() got GPG passwd from gui." << std::endl;
|
|
||||||
// #endif
|
|
||||||
//
|
|
||||||
// if((void*)fd != NULL)
|
|
||||||
// {
|
|
||||||
// #ifndef WINDOWS_SYS
|
|
||||||
// write(fd, password.c_str(), password.size());
|
|
||||||
// write(fd, "\n", 1); /* needs a new line? */
|
|
||||||
// #else
|
|
||||||
// DWORD written = 0;
|
|
||||||
// HANDLE winFd = (HANDLE) fd;
|
|
||||||
// WriteFile(winFd, password.c_str(), password.size(), &written, NULL);
|
|
||||||
// WriteFile(winFd, "\n", 1, &written, NULL);
|
|
||||||
// #endif
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// #ifdef GPG_DEBUG2
|
|
||||||
// fprintf(stderr, "pgp_pwd_callback() password setted\n");
|
|
||||||
// #endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AuthGPG::init(const std::string& path_to_public_keyring,const std::string& path_to_secret_keyring)
|
void AuthGPG::init(const std::string& path_to_public_keyring,const std::string& path_to_secret_keyring)
|
||||||
|
|
|
@ -152,6 +152,7 @@ enum ops_content_tag_t
|
||||||
/* commands to the callback */
|
/* commands to the callback */
|
||||||
OPS_PARSER_CMD_GET_SK_PASSPHRASE =0x400,
|
OPS_PARSER_CMD_GET_SK_PASSPHRASE =0x400,
|
||||||
OPS_PARSER_CMD_GET_SECRET_KEY =0x400+1,
|
OPS_PARSER_CMD_GET_SECRET_KEY =0x400+1,
|
||||||
|
OPS_PARSER_CMD_GET_SK_PASSPHRASE_PREV_WAS_BAD =0x400+2,
|
||||||
|
|
||||||
|
|
||||||
/* Errors */
|
/* Errors */
|
||||||
|
|
|
@ -506,6 +506,7 @@ callback_write_parsed(const ops_parser_content_t *content_,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OPS_PARSER_CMD_GET_SK_PASSPHRASE:
|
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 callback_cmd_get_secret_key_passphrase(content_,cbinfo);
|
||||||
return cbinfo->cryptinfo.cb_get_passphrase(content_, cbinfo);
|
return cbinfo->cryptinfo.cb_get_passphrase(content_, cbinfo);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -921,6 +921,7 @@ void ops_parser_content_free(ops_parser_content_t *c)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OPS_PARSER_CMD_GET_SK_PASSPHRASE:
|
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);
|
ops_cmd_get_passphrase_free(&c->content.secret_key_passphrase);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
@ -348,51 +348,61 @@ callback_pk_session_key(const ops_parser_content_t *content_,ops_parse_cb_info_t
|
||||||
|
|
||||||
ops_parse_cb_return_t
|
ops_parse_cb_return_t
|
||||||
callback_cmd_get_secret_key(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo)
|
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;
|
ops_parser_content_union_t* content=(ops_parser_content_union_t *)&content_->content;
|
||||||
const ops_secret_key_t *secret;
|
const ops_secret_key_t *secret;
|
||||||
ops_parser_content_t pc;
|
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:
|
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);
|
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))
|
if (!cbinfo->cryptinfo.keydata || !ops_is_key_secret(cbinfo->cryptinfo.keydata))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* now get the key from the data */
|
/* now get the key from the data */
|
||||||
secret=ops_get_secret_key_from_data(cbinfo->cryptinfo.keydata);
|
secret=ops_get_secret_key_from_data(cbinfo->cryptinfo.keydata);
|
||||||
while(!secret)
|
int tag_to_use = OPS_PARSER_CMD_GET_SK_PASSPHRASE ;
|
||||||
{
|
int nbtries = 0 ;
|
||||||
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;
|
|
||||||
|
|
||||||
default:
|
while( (!secret) && nbtries++ < 3)
|
||||||
// return callback_general(content_,cbinfo);
|
{
|
||||||
break;
|
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)
|
char *ops_get_passphrase(void)
|
||||||
{
|
{
|
||||||
|
|
|
@ -35,6 +35,7 @@ linux-* {
|
||||||
QMAKE_CXXFLAGS *= -D_FILE_OFFSET_BITS=64
|
QMAKE_CXXFLAGS *= -D_FILE_OFFSET_BITS=64
|
||||||
|
|
||||||
PRE_TARGETDEPS *= ../../libretroshare/src/lib/libretroshare.a
|
PRE_TARGETDEPS *= ../../libretroshare/src/lib/libretroshare.a
|
||||||
|
PRE_TARGETDEPS *= ../../openpgpsdk/lib/libops.a
|
||||||
|
|
||||||
LIBS += ../../libretroshare/src/lib/libretroshare.a
|
LIBS += ../../libretroshare/src/lib/libretroshare.a
|
||||||
LIBS += ../../openpgpsdk/lib/libops.a -lbz2
|
LIBS += ../../openpgpsdk/lib/libops.a -lbz2
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue