mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-03 14:45:12 -04:00
add key generation at startup if no gpg key found
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@2068 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
28882efe03
commit
af68fa36ce
7 changed files with 189 additions and 197 deletions
|
@ -38,6 +38,9 @@ AuthGPG *AuthGPG::instance_gpg = new AuthGPG();
|
|||
/* Turn a set of parameters into a string */
|
||||
static std::string setKeyPairParams(bool useRsa, unsigned int blen,
|
||||
std::string name, std::string comment, std::string email);
|
||||
static std::string setKeyPairParams(bool useRsa, unsigned int blen,
|
||||
std::string name, std::string comment, std::string email,
|
||||
std::string inPassphrase);
|
||||
|
||||
static gpgme_key_t getKey(gpgme_ctx_t, std::string, std::string, std::string);
|
||||
|
||||
|
@ -266,6 +269,7 @@ bool AuthGPG::availableGPGCertificatesWithPrivateKeys(std::list<std::string> &id
|
|||
int AuthGPG::GPGInit(std::string ownId)
|
||||
{
|
||||
RsStackMutex stack(pgpMtx); /******* LOCKED ******/
|
||||
std::cerr << "AuthGPG::GPGInit() called with own gpg id : " << ownId << std::endl;
|
||||
|
||||
gpgme_key_t newKey;
|
||||
gpg_error_t ERR;
|
||||
|
@ -840,13 +844,32 @@ bool AuthGPG::active()
|
|||
{
|
||||
//RsStackMutex stack(pgpMtx); /******* LOCKED ******/
|
||||
|
||||
return ((gpgmeInit) && (gpgmeKeySelected) && (gpgmeX509Selected));
|
||||
return ((gpgmeInit) && (gpgmeKeySelected));
|
||||
}
|
||||
|
||||
int AuthGPG::InitAuth()
|
||||
{
|
||||
gpgmeX509Selected = true;
|
||||
return 1;
|
||||
bool AuthGPG::GeneratePGPCertificate(std::string name, std::string email, std::string passwd, std::string &pgpId, std::string &errString) {
|
||||
gpgme_key_t newKey;
|
||||
gpgme_genkey_result_t result;
|
||||
gpg_error_t ERR;
|
||||
|
||||
if(GPG_ERR_NO_ERROR != (ERR = gpgme_op_genkey(CTX, setKeyPairParams(true, 2048, name, "generated by Retroshare", email, \
|
||||
passwd).c_str(), NULL, NULL))) {
|
||||
ProcessPGPmeError(ERR);
|
||||
std::cerr << "Error generating the key" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if((result = gpgme_op_genkey_result(CTX)) == NULL)
|
||||
return 0;
|
||||
|
||||
|
||||
if(GPG_ERR_NO_ERROR != (ERR = gpgme_get_key(CTX, result->fpr, &newKey, 1))) {
|
||||
std::cerr << "Error reading own key" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
pgpId = newKey->subkeys->keyid;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AuthGPG::CloseAuth()
|
||||
|
@ -1514,6 +1537,39 @@ static std::string setKeyPairParams(bool useRsa, unsigned int blen,
|
|||
return params.str();
|
||||
}
|
||||
|
||||
static std::string setKeyPairParams(bool useRsa, unsigned int blen,
|
||||
std::string name, std::string comment, std::string email,
|
||||
std::string inPassphrase)
|
||||
{
|
||||
std::ostringstream params;
|
||||
params << "<GnupgKeyParms format=\"internal\">"<< std::endl;
|
||||
if (useRsa)
|
||||
{
|
||||
params << "Key-Type: RSA"<< std::endl;
|
||||
if (blen < 1024)
|
||||
{
|
||||
std::cerr << "Weak Key... strengthing..."<< std::endl;
|
||||
blen = 1024;
|
||||
}
|
||||
blen = ((blen / 512) * 512); /* make multiple of 512 */
|
||||
params << "Key-Length: "<< blen << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
params << "Key-Type: DSA"<< std::endl;
|
||||
params << "Key-Length: 1024"<< std::endl;
|
||||
params << "Subkey-Type: ELG-E"<< std::endl;
|
||||
params << "Subkey-Length: 1024"<< std::endl;
|
||||
}
|
||||
params << "Name-Real: "<< name << std::endl;
|
||||
params << "Name-Comment: "<< comment << std::endl;
|
||||
params << "Name-Email: "<< email << std::endl;
|
||||
params << "Expire-Date: 0"<< std::endl;
|
||||
params << "Passphrase: "<< inPassphrase << std::endl;
|
||||
params << "</GnupgKeyParms>"<< std::endl;
|
||||
|
||||
return params.str();
|
||||
}
|
||||
|
||||
|
||||
/* Author: Shiva
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue