added code to generate 3072 and 4096 bit PGP keys at startup (Patch from Serhaf)

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7841 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2015-01-12 22:02:43 +00:00
parent 7bc98f1cd5
commit 8cb3ae6d2e
9 changed files with 75 additions and 37 deletions

View file

@ -360,7 +360,7 @@ bool PGPHandler::availableGPGCertificatesWithPrivateKeys(std::list<RsPgpId>& ids
return true ;
}
bool PGPHandler::GeneratePGPCertificate(const std::string& name, const std::string& email, const std::string& passphrase, RsPgpId& pgpId, std::string& errString)
bool PGPHandler::GeneratePGPCertificate(const std::string& name, const std::string& email, const std::string& passphrase, RsPgpId& pgpId, const int keynumbits, std::string& errString)
{
// Some basic checks
@ -384,13 +384,16 @@ bool PGPHandler::GeneratePGPCertificate(const std::string& name, const std::stri
errString = std::string("(EE) passphrase in certificate exceeds the maximum allowed passphrase size") ;
return false ;
}
if(keynumbits % 1024 != 0)
{
errString = std::string("(EE) RSA key length is not a multiple of 1024") ;
return false ;
}
// Now the real thing
RsStackMutex mtx(pgphandlerMtx) ; // lock access to PGP memory structures.
RsStackFileLock flck(_pgp_lock_filename) ; // lock access to PGP directory.
static const int KEY_NUMBITS = 2048 ;
// 1 - generate keypair - RSA-2048
//
ops_user_id_t uid ;
@ -398,7 +401,7 @@ bool PGPHandler::GeneratePGPCertificate(const std::string& name, const std::stri
uid.user_id = (unsigned char *)s ;
unsigned long int e = 65537 ; // some prime number
ops_keydata_t *key = ops_rsa_create_selfsigned_keypair(KEY_NUMBITS,e,&uid) ;
ops_keydata_t *key = ops_rsa_create_selfsigned_keypair(keynumbits, e, &uid) ;
free(s) ;
@ -409,7 +412,7 @@ bool PGPHandler::GeneratePGPCertificate(const std::string& name, const std::stri
ops_create_info_t *cinfo = NULL ;
ops_memory_t *buf = NULL ;
ops_setup_memory_write(&cinfo, &buf, 0);
ops_setup_memory_write(&cinfo, &buf, 0);
if(!ops_write_transferable_secret_key(key,(unsigned char *)passphrase.c_str(),passphrase.length(),ops_false,cinfo))
{

View file

@ -77,7 +77,7 @@ class PGPHandler
bool exportGPGKeyPair(const std::string& filename,const RsPgpId& exported_id) const ;
bool availableGPGCertificatesWithPrivateKeys(std::list<RsPgpId>& ids);
bool GeneratePGPCertificate(const std::string& name, const std::string& email, const std::string& passwd, RsPgpId& pgpId, std::string& errString) ;
bool GeneratePGPCertificate(const std::string& name, const std::string& email, const std::string& passwd, RsPgpId& pgpId, const int keynumbits, std::string& errString) ;
bool LoadCertificateFromString(const std::string& pem, RsPgpId& gpg_id, std::string& error_string);

View file

@ -329,11 +329,11 @@ bool AuthGPG::active()
return gpgKeySelected;
}
bool AuthGPG::GeneratePGPCertificate(const std::string& name, const std::string& email, const std::string& passwd, RsPgpId& pgpId, std::string& errString)
bool AuthGPG::GeneratePGPCertificate(const std::string& name, const std::string& email, const std::string& passwd, RsPgpId& pgpId, const int keynumbits, std::string& errString)
{
RsStackMutex stack(gpgMtxEngine); /******* LOCKED ******/
return PGPHandler::GeneratePGPCertificate(name, email, passwd, pgpId, errString) ;
return PGPHandler::GeneratePGPCertificate(name, email, passwd, pgpId, keynumbits, errString) ;
}
/**** These Two are common */

View file

@ -135,7 +135,7 @@ class AuthGPG: public p3Config, public RsThread, public PGPHandler
/* Init by generating new Own PGP Cert, or selecting existing PGP Cert */
virtual int GPGInit(const RsPgpId &ownId);
virtual bool GeneratePGPCertificate(const std::string& name, const std::string& email, const std::string& passwd, RsPgpId &pgpId, std::string &errString);
virtual bool GeneratePGPCertificate(const std::string& name, const std::string& email, const std::string& passwd, RsPgpId &pgpId, const int keynumbits, std::string &errString);
/*********************************************************************************/
/************************* STAGE 3 ***********************************************/

View file

@ -139,7 +139,7 @@ namespace RsAccounts
// PGP Accounts.
int GetPGPLogins(std::list<RsPgpId> &pgpIds);
int GetPGPLoginDetails(const RsPgpId& id, std::string &name, std::string &email);
bool GeneratePGPCertificate(const std::string&, const std::string& email, const std::string& passwd, RsPgpId &pgpId, std::string &errString);
bool GeneratePGPCertificate(const std::string&, const std::string& email, const std::string& passwd, RsPgpId &pgpId, const int keynumbits, std::string &errString);
// PGP Support Functions.
bool ExportIdentity(const std::string& fname,const RsPgpId& pgp_id) ;

View file

@ -840,9 +840,9 @@ bool RsAccountsDetail::SelectPGPAccount(const RsPgpId& pgpId)
}
bool RsAccountsDetail::GeneratePGPCertificate(const std::string& name, const std::string& email, const std::string& passwd, RsPgpId &pgpId, std::string &errString)
bool RsAccountsDetail::GeneratePGPCertificate(const std::string& name, const std::string& email, const std::string& passwd, RsPgpId &pgpId, const int keynumbits, std::string &errString)
{
return AuthGPG::getAuthGPG()->GeneratePGPCertificate(name, email, passwd, pgpId, errString);
return AuthGPG::getAuthGPG()->GeneratePGPCertificate(name, email, passwd, pgpId, keynumbits, errString);
}
// PGP Support Functions.
@ -1222,9 +1222,9 @@ int RsAccounts::GetPGPLoginDetails(const RsPgpId& id, std::string &name, std
return rsAccounts->GetPGPLoginDetails(id, name, email);
}
bool RsAccounts::GeneratePGPCertificate(const std::string &name, const std::string& email, const std::string& passwd, RsPgpId &pgpId, std::string &errString)
bool RsAccounts::GeneratePGPCertificate(const std::string &name, const std::string& email, const std::string& passwd, RsPgpId &pgpId, const int keynumbits, std::string &errString)
{
return rsAccounts->GeneratePGPCertificate(name, email, passwd, pgpId, errString);
return rsAccounts->GeneratePGPCertificate(name, email, passwd, pgpId, keynumbits, errString);
}
// PGP Support Functions.

View file

@ -89,7 +89,7 @@ class RsAccountsDetail
int GetPGPLogins(std::list<RsPgpId> &pgpIds);
int GetPGPLoginDetails(const RsPgpId& id, std::string &name, std::string &email);
bool GeneratePGPCertificate(const std::string&, const std::string& email, const std::string& passwd, RsPgpId &pgpId, std::string &errString);
bool GeneratePGPCertificate(const std::string&, const std::string& email, const std::string& passwd, RsPgpId &pgpId, const int keynumbits, std::string &errString);
bool SelectPGPAccount(const RsPgpId& pgpId);