remove the store of the pgp password

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@2008 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
joss17 2010-01-13 21:06:53 +00:00
parent 9c17aced37
commit 45b2287d41
5 changed files with 85 additions and 141 deletions

View File

@ -35,8 +35,7 @@ AuthGPG *AuthGPG::instance_gpg = new AuthGPG();
/* Turn a set of parameters into a string */ /* Turn a set of parameters into a string */
static std::string setKeyPairParams(bool useRsa, unsigned int blen, static std::string setKeyPairParams(bool useRsa, unsigned int blen,
std::string name, std::string comment, std::string email, 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); static gpgme_key_t getKey(gpgme_ctx_t, std::string, std::string, std::string);
@ -94,22 +93,22 @@ gpg_error_t pgp_pwd_callback(void *hook, const char *uid_hint, const char *passp
static char *PgpPassword = NULL; static char *PgpPassword = NULL;
bool AuthGPG::setPGPPassword_locked(std::string pwd) //bool AuthGPG::setPGPPassword_locked(std::string pwd)
{ //{
/* reset it while we change it */ // /* reset it while we change it */
gpgme_set_passphrase_cb(CTX, NULL, NULL); // gpgme_set_passphrase_cb(CTX, NULL, NULL);
//
if (PgpPassword) // if (PgpPassword)
free(PgpPassword); // free(PgpPassword);
PgpPassword = (char *) malloc(pwd.length() + 1); // PgpPassword = (char *) malloc(pwd.length() + 1);
memcpy(PgpPassword, pwd.c_str(), pwd.length()); // memcpy(PgpPassword, pwd.c_str(), pwd.length());
PgpPassword[pwd.length()] = '\0'; // PgpPassword[pwd.length()] = '\0';
//
fprintf(stderr, "AuthGPG::setPGPPassword_locked() called\n"); // fprintf(stderr, "AuthGPG::setPGPPassword_locked() called\n");
gpgme_set_passphrase_cb(CTX, pgp_pwd_callback, (void *) PgpPassword); // gpgme_set_passphrase_cb(CTX, pgp_pwd_callback, (void *) PgpPassword);
//
return true; // return true;
} //}
AuthGPG::AuthGPG() AuthGPG::AuthGPG()
@ -284,74 +283,30 @@ int AuthGPG::GPGInit(std::string ownId)
storeAllKeys_locked(); storeAllKeys_locked();
printAllKeys_locked(); printAllKeys_locked();
gpgme_set_passphrase_cb(CTX, pgp_pwd_callback, (void *) NULL);
std::cerr << "AuthGPG::GPGInit finished." << std::endl; std::cerr << "AuthGPG::GPGInit finished." << std::endl;
return true; return true;
} }
int AuthGPG::GPGInit(std::string name, std::string comment,
std::string email, std::string inPassphrase)
{
RsStackMutex stack(pgpMtx); /******* LOCKED ******/
gpgme_key_t newKey;
gpgme_genkey_result_t result;
gpg_error_t ERR;
if (!gpgmeInit) {
return 0;
}
if(GPG_ERR_NO_ERROR != (ERR = gpgme_op_genkey(CTX, setKeyPairParams(true, 2048, name, comment, email, \
passphrase).c_str(), NULL, NULL))) {
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;
}
mOwnGpgCert.name = name;
mOwnGpgCert.email = email;
mOwnGpgCert.fpr = newKey->subkeys->fpr;
mOwnGpgCert.id = newKey->subkeys->keyid;
mOwnGpgCert.key = newKey;
this->passphrase = inPassphrase;
setPGPPassword_locked(inPassphrase);
mOwnGpgId = mOwnGpgCert.id;
gpgmeKeySelected = true;
storeAllKeys_locked();
printAllKeys_locked();
return 1;
}
AuthGPG::~AuthGPG() AuthGPG::~AuthGPG()
{ {
} }
int AuthGPG::LoadGPGPassword(std::string pwd) //int AuthGPG::LoadGPGPassword(std::string pwd)
{ //{
RsStackMutex stack(pgpMtx); /******* LOCKED ******/ // RsStackMutex stack(pgpMtx); /******* LOCKED ******/
//
if (!gpgmeInit) { // if (!gpgmeInit) {
return 0; // return 0;
} // }
//
this->passphrase = pwd; // this->passphrase = pwd;
setPGPPassword_locked(pwd); // setPGPPassword_locked(pwd);
//
return 1; // return 1;
} //}
@ -1254,7 +1209,7 @@ int AuthGPG::privateSignCertificate(std::string id)
gpgme_key_t signKey = it->second.key; gpgme_key_t signKey = it->second.key;
gpgme_key_t ownKey = mOwnGpgCert.key; gpgme_key_t ownKey = mOwnGpgCert.key;
class SignParams sparams("0", passphrase); class SignParams sparams("0");
class EditParams params(SIGN_START, &sparams); class EditParams params(SIGN_START, &sparams);
gpgme_data_t out; gpgme_data_t out;
gpg_error_t ERR; gpg_error_t ERR;
@ -1357,19 +1312,19 @@ void AuthGPG::createDummyFriends()
// create key params for a few dummies // create key params for a few dummies
std::string friend1 = setKeyPairParams(true, DUMMY_KEY_LEN, "friend89", std::string friend1 = setKeyPairParams(true, DUMMY_KEY_LEN, "friend89",
"I am your first friend", "friend1@friend.com", "1234"); "I am your first friend", "friend1@friend.com");
std::string friend2 = setKeyPairParams(true, DUMMY_KEY_LEN, "friend2", std::string friend2 = setKeyPairParams(true, DUMMY_KEY_LEN, "friend2",
"I am your second friend", "friend2@friend.com", "2345"); "I am your second friend", "friend2@friend.com");
std::string friend3 = setKeyPairParams(true, DUMMY_KEY_LEN, "friend3", std::string friend3 = setKeyPairParams(true, DUMMY_KEY_LEN, "friend3",
"I am your third friend", "friend3@friend.com", "3456"); "I am your third friend", "friend3@friend.com");
// params for others // params for others
std::string other1 = setKeyPairParams(true, DUMMY_KEY_LEN, "other89", std::string other1 = setKeyPairParams(true, DUMMY_KEY_LEN, "other89",
"I am your first other", "other@other.com", "1234"); "I am your first other", "other@other.com");
std::string other2 = setKeyPairParams(true, DUMMY_KEY_LEN, "other2", std::string other2 = setKeyPairParams(true, DUMMY_KEY_LEN, "other2",
"I am your second other", "other2@other.com", "2345"); "I am your second other", "other2@other.com");
std::string other3 = setKeyPairParams(true, DUMMY_KEY_LEN, "other3", std::string other3 = setKeyPairParams(true, DUMMY_KEY_LEN, "other3",
"I am your third other", "other3@other.com", "3456"); "I am your third other", "other3@other.com");
gpgme_error_t rc = GPG_ERR_NO_ERROR; // assume OK gpgme_error_t rc = GPG_ERR_NO_ERROR; // assume OK
rc = gpgme_op_genkey(CTX, friend1.c_str(), NULL, NULL); rc = gpgme_op_genkey(CTX, friend1.c_str(), NULL, NULL);
@ -1385,8 +1340,7 @@ void AuthGPG::createDummyFriends()
} }
static std::string setKeyPairParams(bool useRsa, unsigned int blen, static std::string setKeyPairParams(bool useRsa, unsigned int blen,
std::string name, std::string comment, std::string email, std::string name, std::string comment, std::string email)
std::string inPassphrase)
{ {
std::ostringstream params; std::ostringstream params;
params << "<GnupgKeyParms format=\"internal\">"<< std::endl; params << "<GnupgKeyParms format=\"internal\">"<< std::endl;
@ -1412,7 +1366,6 @@ static std::string setKeyPairParams(bool useRsa, unsigned int blen,
params << "Name-Comment: "<< comment << std::endl; params << "Name-Comment: "<< comment << std::endl;
params << "Name-Email: "<< email << std::endl; params << "Name-Email: "<< email << std::endl;
params << "Expire-Date: 0"<< std::endl; params << "Expire-Date: 0"<< std::endl;
params << "Passphrase: "<< inPassphrase << std::endl;
params << "</GnupgKeyParms>"<< std::endl; params << "</GnupgKeyParms>"<< std::endl;
return params.str(); return params.str();
@ -1645,27 +1598,27 @@ static gpg_error_t keySignCallback(void *opaque, gpgme_status_code_t status, \
params->err = gpg_error (GPG_ERR_GENERAL); params->err = gpg_error (GPG_ERR_GENERAL);
} }
break; break;
case SIGN_ENTER_PASSPHRASE: // case SIGN_ENTER_PASSPHRASE:
fprintf(stderr,"keySignCallback SIGN_ENTER_PASSPHRASE\n"); // fprintf(stderr,"keySignCallback SIGN_ENTER_PASSPHRASE\n");
//
if(status == GPGME_STATUS_GET_HIDDEN && // if(status == GPGME_STATUS_GET_HIDDEN &&
(!std::string("passphrase.enter").compare(args))) // (!std::string("passphrase.enter").compare(args)))
{ // {
params->state = SIGN_CONFIRM; // params->state = SIGN_CONFIRM;
result = sparams->passphrase.c_str(); // result = sparams->passphrase.c_str();
} // }
// If using pgp_pwd_callback, then never have to enter passphrase this way. // // If using pgp_pwd_callback, then never have to enter passphrase this way.
// must catch GOOD_PASSPHRASE to move on. // // must catch GOOD_PASSPHRASE to move on.
else if (status == GPGME_STATUS_GOOD_PASSPHRASE) // else if (status == GPGME_STATUS_GOOD_PASSPHRASE)
{ // {
params->state = SIGN_CONFIRM; // params->state = SIGN_CONFIRM;
} // }
else // else
{ // {
params->state = SIGN_ERROR; // params->state = SIGN_ERROR;
params->err = gpg_error (GPG_ERR_GENERAL); // params->err = gpg_error (GPG_ERR_GENERAL);
} // }
break; // break;
case SIGN_CONFIRM: case SIGN_CONFIRM:
fprintf(stderr,"keySignCallback SIGN_CONFIRM\n"); fprintf(stderr,"keySignCallback SIGN_CONFIRM\n");

View File

@ -83,7 +83,6 @@ class AuthGPG
private: private:
/* Internal functions */ /* Internal functions */
bool setPGPPassword_locked(std::string pwd);
bool DoOwnSignature_locked(const void *, unsigned int, void *, unsigned int *); bool DoOwnSignature_locked(const void *, unsigned int, void *, unsigned int *);
bool VerifySignature_locked(const void *data, int datalen, const void *sig, unsigned int siglen); bool VerifySignature_locked(const void *data, int datalen, const void *sig, unsigned int siglen);
@ -107,10 +106,6 @@ class AuthGPG
bool availablePGPCertificates(std::list<std::string> &ids); bool availablePGPCertificates(std::list<std::string> &ids);
int GPGInit(std::string ownId); int GPGInit(std::string ownId);
int GPGInit(std::string name, std::string comment,
std::string email, std::string passwd); /* create it */
int LoadGPGPassword(std::string pwd);
/* SKTAN */ /* SKTAN */
void showData(gpgme_data_t dh); void showData(gpgme_data_t dh);
@ -227,8 +222,6 @@ private:
std::string mX509id; std::string mX509id;
gpgcert mOwnGpgCert; gpgcert mOwnGpgCert;
std::string passphrase;
}; };
/* Sign a key */ /* Sign a key */
@ -295,11 +288,9 @@ class SignParams
public: public:
std::string checkLvl; std::string checkLvl;
std::string passphrase;
SignParams(std::string checkLvl, std::string passphrase) { SignParams(std::string checkLvl) {
this->checkLvl = checkLvl; this->checkLvl = checkLvl;
this->passphrase = passphrase;
} }
}; };

View File

@ -809,23 +809,23 @@ bool RsInit::SelectGPGAccount(std::string id)
} }
bool RsInit::LoadGPGPassword(std::string inPGPpasswd) //bool RsInit::LoadGPGPassword(std::string inPGPpasswd)
{ //{
//
bool ok = false; // bool ok = false;
if (0 < AuthGPG::getAuthGPG() -> LoadGPGPassword(inPGPpasswd)) // if (0 < AuthGPG::getAuthGPG() -> LoadGPGPassword(inPGPpasswd))
{ // {
ok = true; // ok = true;
std::cerr << "PGP LoadPwd Success!"; // std::cerr << "PGP LoadPwd Success!";
std::cerr << std::endl; // std::cerr << std::endl;
} // }
else // else
{ // {
std::cerr << "PGP LoadPwd Failed!"; // std::cerr << "PGP LoadPwd Failed!";
std::cerr << std::endl; // std::cerr << std::endl;
} // }
return ok; // return ok;
} //}
bool GeneratePGPCertificate(std::string name, std::string comment, std::string email, std::string passwd, std::string &pgpId, std::string &errString) bool GeneratePGPCertificate(std::string name, std::string comment, std::string email, std::string passwd, std::string &pgpId, std::string &errString)

View File

@ -166,7 +166,7 @@ void GenCertDialog::genPerson()
/* Initialise the PGP user first */ /* Initialise the PGP user first */
RsInit::SelectGPGAccount(PGPId); RsInit::SelectGPGAccount(PGPId);
RsInit::LoadGPGPassword(PGPpasswd); //RsInit::LoadGPGPassword(PGPpasswd);
std::string sslId; std::string sslId;
bool okGen = RsInit::GenerateSSLCertificate(genName, genOrg, genLoc, genCountry, sslPasswd, sslId, err); bool okGen = RsInit::GenerateSSLCertificate(genName, genOrg, genLoc, genCountry, sslPasswd, sslId, err);

View File

@ -172,7 +172,7 @@ void StartDialog::loadPerson()
gpgId, gpgName, gpgEmail, sslName)) gpgId, gpgName, gpgEmail, sslName))
{ {
RsInit::SelectGPGAccount(gpgId); RsInit::SelectGPGAccount(gpgId);
RsInit::LoadGPGPassword(gpgPasswd); //RsInit::LoadGPGPassword(gpgPasswd);
} }
#else #else
#endif #endif