make it compile

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@2002 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
joss17 2010-01-13 20:58:58 +00:00
parent c23407cae3
commit a0a64fb588
17 changed files with 188 additions and 191 deletions

View file

@ -1,5 +1,5 @@
/*
* libretroshare/src gpgauthmgr.cc
* libretroshare/src AuthGPG.cc
*
* GnuPG/GPGme interface for RetroShare.
*
@ -39,7 +39,7 @@
*
* GPG Functions:
* ValidateCertificate() calls,
* bool GPGAuthMgr::AuthX509(X509 *x509)
* bool AuthGPG::AuthX509(X509 *x509)
* VerifySignature()
*
* VerifyX509Callback()
@ -120,7 +120,12 @@ gpg_error_t pgp_pwd_callback(void *hook, const char *uid_hint, const char *passp
static char *PgpPassword = NULL;
bool GPGAuthMgr::setPGPPassword_locked(std::string pwd)
AuthGPG *AuthGPG::getAuthGPG()
{
return &instance_gpgroot;
}
bool AuthGPG::setPGPPassword_locked(std::string pwd)
{
/* reset it while we change it */
gpgme_set_passphrase_cb(CTX, NULL, NULL);
@ -131,14 +136,14 @@ bool GPGAuthMgr::setPGPPassword_locked(std::string pwd)
memcpy(PgpPassword, pwd.c_str(), pwd.length());
PgpPassword[pwd.length()] = '\0';
fprintf(stderr, "GPGAuthMgr::setPGPPassword_locked() called\n");
fprintf(stderr, "AuthGPG::setPGPPassword_locked() called\n");
gpgme_set_passphrase_cb(CTX, pgp_pwd_callback, (void *) PgpPassword);
return true;
}
GPGAuthMgr::GPGAuthMgr()
AuthGPG::AuthGPG()
:gpgmeInit(false)
{
RsStackMutex stack(pgpMtx); /******* LOCKED ******/
@ -216,13 +221,13 @@ GPGAuthMgr::GPGAuthMgr()
updateTrustAllKeys_locked();
}
bool GPGAuthMgr::getPGPEngineFileName(std::string &fileName)
bool AuthGPG::getPGPEngineFileName(std::string &fileName)
{
if (!INFO) {
return false;
} else {
fileName = std::string(INFO->file_name);
std :: cerr << "GPGAuthMgr::getPGPEngineFileName() : " << fileName << std::endl;
std :: cerr << "AuthGPG::getPGPEngineFileName() : " << fileName << std::endl;
return true;
}
}
@ -235,7 +240,7 @@ bool GPGAuthMgr::getPGPEngineFileName(std::string &fileName)
* returns false if GnuPG is not available.
*/
bool GPGAuthMgr::availablePGPCertificates(std::list<std::string> &ids)
bool AuthGPG::availablePGPCertificates(std::list<std::string> &ids)
{
RsStackMutex stack(pgpMtx); /******* LOCKED ******/
@ -265,12 +270,12 @@ bool GPGAuthMgr::availablePGPCertificates(std::list<std::string> &ids)
if (KEY->subkeys)
{
ids.push_back(KEY->subkeys->keyid);
std::cerr << "GPGAuthMgr::availablePGPCertificates() Added: "
std::cerr << "AuthGPG::availablePGPCertificates() Added: "
<< KEY->subkeys->keyid << std::endl;
}
else
{
std::cerr << "GPGAuthMgr::availablePGPCertificates() Missing subkey"
std::cerr << "AuthGPG::availablePGPCertificates() Missing subkey"
<< std::endl;
}
}
@ -282,7 +287,7 @@ bool GPGAuthMgr::availablePGPCertificates(std::list<std::string> &ids)
return false;
}
std::cerr << "GPGAuthMgr::availablePGPCertificates() Secret Key Count: " << i << std::endl;
std::cerr << "AuthGPG::availablePGPCertificates() Secret Key Count: " << i << std::endl;
/* return false if there are no private keys */
return (i > 0);
@ -295,7 +300,7 @@ bool GPGAuthMgr::availablePGPCertificates(std::list<std::string> &ids)
* This function must be called successfully (return == 1)
* before anything else can be done. (except above fn).
*/
int GPGAuthMgr::GPGInit(std::string ownId)
int AuthGPG::GPGInit(std::string ownId)
{
RsStackMutex stack(pgpMtx); /******* LOCKED ******/
@ -334,7 +339,7 @@ int GPGAuthMgr::GPGInit(std::string ownId)
return true;
}
int GPGAuthMgr::GPGInit(std::string name, std::string comment,
int AuthGPG::GPGInit(std::string name, std::string comment,
std::string email, std::string inPassphrase)
{
RsStackMutex stack(pgpMtx); /******* LOCKED ******/
@ -377,11 +382,11 @@ int GPGAuthMgr::GPGInit(std::string name, std::string comment,
return 1;
}
GPGAuthMgr::~GPGAuthMgr()
AuthGPG::~AuthGPG()
{
}
int GPGAuthMgr::LoadGPGPassword(std::string pwd)
int AuthGPG::LoadGPGPassword(std::string pwd)
{
RsStackMutex stack(pgpMtx); /******* LOCKED ******/
@ -398,9 +403,9 @@ int GPGAuthMgr::LoadGPGPassword(std::string pwd)
// store all keys in map mKeyList to avoid callin gpgme exe repeatedly
bool GPGAuthMgr::storeAllKeys_locked()
bool AuthGPG::storeAllKeys_locked()
{
std::cerr << "GPGAuthMgr::storeAllKeys_locked()";
std::cerr << "AuthGPG::storeAllKeys_locked()";
std::cerr << std::endl;
gpg_error_t ERR;
@ -411,7 +416,7 @@ bool GPGAuthMgr::storeAllKeys_locked()
return false;
}
std::cerr << "GPGAuthMgr::storeAllKeys_locked() clearing existing ones";
std::cerr << "AuthGPG::storeAllKeys_locked() clearing existing ones";
std::cerr << std::endl;
mKeyList.clear();
@ -557,7 +562,7 @@ bool GPGAuthMgr::storeAllKeys_locked()
}
// update trust on all available keys.
bool GPGAuthMgr::updateTrustAllKeys_locked()
bool AuthGPG::updateTrustAllKeys_locked()
{
gpg_error_t ERR;
if (!gpgmeInit)
@ -628,7 +633,7 @@ bool GPGAuthMgr::updateTrustAllKeys_locked()
return true;
}
bool GPGAuthMgr::printAllKeys_locked()
bool AuthGPG::printAllKeys_locked()
{
certmap::const_iterator it;
@ -671,7 +676,7 @@ bool GPGAuthMgr::printAllKeys_locked()
return true;
}
bool GPGAuthMgr::printOwnKeys_locked()
bool AuthGPG::printOwnKeys_locked()
{
certmap::iterator it;
@ -691,7 +696,7 @@ bool GPGAuthMgr::printOwnKeys_locked()
return true;
}
bool GPGAuthMgr::printKeys()
bool AuthGPG::printKeys()
{
RsStackMutex stack(pgpMtx); /******* LOCKED ******/
printAllKeys_locked();
@ -750,13 +755,13 @@ void print_pgpme_verify_summary(unsigned int summary)
}
bool GPGAuthMgr::DoOwnSignature_locked(const void *data, unsigned int datalen, void *buf_sigout, unsigned int *outl)
bool AuthGPG::DoOwnSignature_locked(const void *data, unsigned int datalen, void *buf_sigout, unsigned int *outl)
{
/* setup signers */
gpgme_signers_clear(CTX);
if (GPG_ERR_NO_ERROR != gpgme_signers_add(CTX, mOwnGpgCert.key))
{
std::cerr << "GPGAuthMgr::DoOwnSignature() Error Adding Signer";
std::cerr << "AuthGPG::DoOwnSignature() Error Adding Signer";
std::cerr << std::endl;
}
@ -782,7 +787,7 @@ bool GPGAuthMgr::DoOwnSignature_locked(const void *data, unsigned int datalen, v
if (GPG_ERR_NO_ERROR != (ERR = gpgme_op_sign(CTX,gpgmeData, gpgmeSig, mode)))
{
ProcessPGPmeError(ERR);
std::cerr << "GPGAuthMgr::Sign FAILED ERR: " << ERR;
std::cerr << "AuthGPG::Sign FAILED ERR: " << ERR;
std::cerr << std::endl;
return false;
}
@ -802,13 +807,13 @@ bool GPGAuthMgr::DoOwnSignature_locked(const void *data, unsigned int datalen, v
gpgme_new_signature_t sg = res->signatures;
while(ik != NULL)
{
fprintf(stderr, "GPGAuthMgr::Sign, Invalid by: %s\n", ik->fpr);
fprintf(stderr, "AuthGPG::Sign, Invalid by: %s\n", ik->fpr);
ik = ik->next;
}
while(sg != NULL)
{
fprintf(stderr, "GPGAuthMgr::Signed by: %s\n", sg->fpr);
fprintf(stderr, "AuthGPG::Signed by: %s\n", sg->fpr);
sg = sg->next;
}
@ -817,7 +822,7 @@ bool GPGAuthMgr::DoOwnSignature_locked(const void *data, unsigned int datalen, v
int len2 = len;
gpgme_data_write (gpgmeSig, "", 1); // to be able to convert it into a string
char *export_sig = gpgme_data_release_and_get_mem(gpgmeSig, &len);
fprintf(stderr, "GPGAuthMgr::Signature len: %d \n", len2);
fprintf(stderr, "AuthGPG::Signature len: %d \n", len2);
if (len < *outl)
{
*outl = len;
@ -832,7 +837,7 @@ bool GPGAuthMgr::DoOwnSignature_locked(const void *data, unsigned int datalen, v
/* import to GnuPG and other Certificates */
bool GPGAuthMgr::VerifySignature_locked(const void *data, int datalen, const void *sig, unsigned int siglen)
bool AuthGPG::VerifySignature_locked(const void *data, int datalen, const void *sig, unsigned int siglen)
{
gpgme_data_t gpgmeSig;
gpgme_data_t gpgmeData;
@ -860,7 +865,7 @@ bool GPGAuthMgr::VerifySignature_locked(const void *data, int datalen, const voi
if (GPG_ERR_NO_ERROR != (ERR = gpgme_op_verify(CTX,gpgmeSig, gpgmeData, NULL)))
{
ProcessPGPmeError(ERR);
std::cerr << "GPGAuthMgr::Verify FAILED";
std::cerr << "AuthGPG::Verify FAILED";
std::cerr << std::endl;
}
@ -881,12 +886,12 @@ bool GPGAuthMgr::VerifySignature_locked(const void *data, int datalen, const voi
while(sg != NULL)
{
fprintf(stderr, "GPGAuthMgr::Verify Sig by: %s, Result: %d\n", sg->fpr, sg->summary);
fprintf(stderr, "AuthGPG::Verify Sig by: %s, Result: %d\n", sg->fpr, sg->summary);
print_pgpme_verify_summary(sg->summary);
if (sg->summary & GPGME_SIGSUM_VALID)
{
fprintf(stderr, "GPGAuthMgr::VerifySignature() OK\n");
fprintf(stderr, "AuthGPG::VerifySignature() OK\n");
valid = true;
}
@ -899,7 +904,7 @@ bool GPGAuthMgr::VerifySignature_locked(const void *data, int datalen, const voi
/* extract id(s)! */
if (!valid)
{
fprintf(stderr, "GPGAuthMgr::VerifySignature() FAILED\n");
fprintf(stderr, "AuthGPG::VerifySignature() FAILED\n");
}
@ -909,27 +914,27 @@ bool GPGAuthMgr::VerifySignature_locked(const void *data, int datalen, const voi
bool GPGAuthMgr::active()
bool AuthGPG::active()
{
RsStackMutex stack(pgpMtx); /******* LOCKED ******/
return ((gpgmeInit) && (gpgmeKeySelected) && (gpgmeX509Selected));
}
int GPGAuthMgr::InitAuth()
int AuthGPG::InitAuth()
{
gpgmeX509Selected = true;
return 1;
}
bool GPGAuthMgr::CloseAuth()
bool AuthGPG::CloseAuth()
{
return true;
}
#if 0 /**** no saving here! let AuthSSL store directories! ****/
int GPGAuthMgr::setConfigDirectories(std::string confFile, std::string neighDir)
int AuthGPG::setConfigDirectories(std::string confFile, std::string neighDir)
{
return 1;
}
@ -937,7 +942,7 @@ int GPGAuthMgr::setConfigDirectories(std::string confFile, std::string neigh
#endif
/**** These Two are common */
std::string GPGAuthMgr::getPGPName(GPG_id id)
std::string AuthGPG::getPGPName(GPG_id id)
{
RsStackMutex stack(pgpMtx); /******* LOCKED ******/
@ -949,7 +954,7 @@ std::string GPGAuthMgr::getPGPName(GPG_id id)
}
/**** These Two are common */
std::string GPGAuthMgr::getPGPEmail(GPG_id id)
std::string AuthGPG::getPGPEmail(GPG_id id)
{
RsStackMutex stack(pgpMtx); /******* LOCKED ******/
@ -962,14 +967,14 @@ std::string GPGAuthMgr::getPGPEmail(GPG_id id)
/**** GPG versions ***/
std::string GPGAuthMgr::PGPOwnId()
std::string AuthGPG::PGPOwnId()
{
RsStackMutex stack(pgpMtx); /******* LOCKED ******/
return mOwnId;
}
bool GPGAuthMgr::getPGPAllList(std::list<std::string> &ids)
bool AuthGPG::getPGPAllList(std::list<std::string> &ids)
{
RsStackMutex stack(pgpMtx); /******* LOCKED ******/
@ -982,14 +987,14 @@ bool GPGAuthMgr::getPGPAllList(std::list<std::string> &ids)
return true;
}
bool GPGAuthMgr::decryptText(gpgme_data_t CIPHER, gpgme_data_t PLAIN) {
bool AuthGPG::decryptText(gpgme_data_t CIPHER, gpgme_data_t PLAIN) {
RsStackMutex stack(pgpMtx); /******* LOCKED ******/
gpgme_set_armor (CTX, 1);
gpg_error_t ERR;
if (GPG_ERR_NO_ERROR != (ERR = gpgme_op_decrypt (CTX, CIPHER, PLAIN)))
{
ProcessPGPmeError(ERR);
std::cerr << "GPGAuthMgr::decryptText() Error decrypting text.";
std::cerr << "AuthGPG::decryptText() Error decrypting text.";
std::cerr << std::endl;
return false;
}
@ -997,7 +1002,7 @@ bool GPGAuthMgr::decryptText(gpgme_data_t CIPHER, gpgme_data_t PLAIN) {
return true;
}
bool GPGAuthMgr::encryptText(gpgme_data_t PLAIN, gpgme_data_t CIPHER) {
bool AuthGPG::encryptText(gpgme_data_t PLAIN, gpgme_data_t CIPHER) {
RsStackMutex stack(pgpMtx); /******* LOCKED ******/
gpgme_encrypt_flags_t* flags = new gpgme_encrypt_flags_t();
@ -1007,7 +1012,7 @@ bool GPGAuthMgr::encryptText(gpgme_data_t PLAIN, gpgme_data_t CIPHER) {
if (GPG_ERR_NO_ERROR != (ERR = gpgme_op_encrypt(CTX, keys, *flags, PLAIN, CIPHER)))
{
ProcessPGPmeError(ERR);
std::cerr << "GPGAuthMgr::encryptText() Error encrypting text.";
std::cerr << "AuthGPG::encryptText() Error encrypting text.";
std::cerr << std::endl;
return false;
}
@ -1015,7 +1020,7 @@ bool GPGAuthMgr::encryptText(gpgme_data_t PLAIN, gpgme_data_t CIPHER) {
return true;
}
bool GPGAuthMgr::getPGPAuthenticatedList(std::list<std::string> &ids)
bool AuthGPG::getPGPAuthenticatedList(std::list<std::string> &ids)
{
RsStackMutex stack(pgpMtx); /******* LOCKED ******/
@ -1030,7 +1035,7 @@ bool GPGAuthMgr::getPGPAuthenticatedList(std::list<std::string> &ids)
return true;
}
bool GPGAuthMgr::getPGPUnknownList(std::list<std::string> &ids)
bool AuthGPG::getPGPUnknownList(std::list<std::string> &ids)
{
RsStackMutex stack(pgpMtx); /******* LOCKED ******/
@ -1046,7 +1051,7 @@ bool GPGAuthMgr::getPGPUnknownList(std::list<std::string> &ids)
}
bool GPGAuthMgr::isPGPValid(GPG_id id)
bool AuthGPG::isPGPValid(GPG_id id)
{
RsStackMutex stack(pgpMtx); /******* LOCKED ******/
@ -1055,7 +1060,7 @@ bool GPGAuthMgr::isPGPValid(GPG_id id)
}
bool GPGAuthMgr::isPGPAuthenticated(GPG_id id)
bool AuthGPG::isPGPAuthenticated(GPG_id id)
{
RsStackMutex stack(pgpMtx); /******* LOCKED ******/
@ -1081,22 +1086,22 @@ bool GPGAuthMgr::isPGPAuthenticated(GPG_id id)
#if 0
bool GPGAuthMgr::FinalSaveCertificates()
bool AuthGPG::FinalSaveCertificates()
{
return false;
}
bool GPGAuthMgr::CheckSaveCertificates()
bool AuthGPG::CheckSaveCertificates()
{
return false;
}
bool GPGAuthMgr::saveCertificates()
bool AuthGPG::saveCertificates()
{
return false;
}
bool GPGAuthMgr::loadCertificates()
bool AuthGPG::loadCertificates()
{
return false;
}
@ -1113,11 +1118,11 @@ bool GPGAuthMgr::loadCertificates()
/* SKTAN : do not know how to use std::string id */
std::string GPGAuthMgr::SaveCertificateToString(std::string id)
std::string AuthGPG::SaveCertificateToString(std::string id)
{
if (!isPGPValid(id)) {
std::cerr << "GPGAuthMgr::SaveCertificateToString() unknown ID" << std::endl;
std::cerr << "AuthGPG::SaveCertificateToString() unknown ID" << std::endl;
std::string emptystr;
return emptystr;
}
@ -1163,7 +1168,7 @@ std::string GPGAuthMgr::SaveCertificateToString(std::string id)
}
/* import to GnuPG and other Certificates */
bool GPGAuthMgr::LoadCertificateFromString(std::string str)
bool AuthGPG::LoadCertificateFromString(std::string str)
{
RsStackMutex stack(pgpMtx); /******* LOCKED ******/
@ -1181,7 +1186,7 @@ bool GPGAuthMgr::LoadCertificateFromString(std::string str)
if (GPG_ERR_NO_ERROR != gpgme_op_import (CTX,gpgmeData))
{
std::cerr << "GPGAuthMgr::Error Importing Certificate";
std::cerr << "AuthGPG::Error Importing Certificate";
std::cerr << std::endl;
return false ;
}
@ -1221,7 +1226,7 @@ bool GPGAuthMgr::LoadCertificateFromString(std::string str)
/*************************************/
/* Auth takes SSL Certificate */
bool GPGAuthMgr::AuthCertificate(GPG_id pgpid)
bool AuthGPG::AuthCertificate(GPG_id pgpid)
{
if (isPGPAuthenticated(pgpid))
{
@ -1237,10 +1242,10 @@ bool GPGAuthMgr::AuthCertificate(GPG_id pgpid)
}
/* These take PGP Ids */
bool GPGAuthMgr::SignCertificate(GPG_id id)
bool AuthGPG::SignCertificate(GPG_id id)
{
std::cerr << "GPGAuthMgr::SignCertificate(" << id << ")";
std::cerr << "AuthGPG::SignCertificate(" << id << ")";
std::cerr << std::endl;
@ -1257,48 +1262,48 @@ bool GPGAuthMgr::SignCertificate(GPG_id id)
return true;
}
bool GPGAuthMgr::RevokeCertificate(std::string id)
bool AuthGPG::RevokeCertificate(std::string id)
{
RsStackMutex stack(pgpMtx); /******* LOCKED ******/
std::cerr << "GPGAuthMgr::RevokeCertificate(" << id << ")";
std::cerr << "AuthGPG::RevokeCertificate(" << id << ")";
std::cerr << std::endl;
return false;
}
bool GPGAuthMgr::TrustCertificate(std::string id, bool trust)
bool AuthGPG::TrustCertificate(std::string id, bool trust)
{
RsStackMutex stack(pgpMtx); /******* LOCKED ******/
std::cerr << "GPGAuthMgr::TrustCertificate(" << id << "," << trust << ")";
std::cerr << "AuthGPG::TrustCertificate(" << id << "," << trust << ")";
std::cerr << std::endl;
return false;
}
bool GPGAuthMgr::SignData(std::string input, std::string &sign)
bool AuthGPG::SignData(std::string input, std::string &sign)
{
return false;
}
bool GPGAuthMgr::SignData(const void *data, const uint32_t len, std::string &sign)
bool AuthGPG::SignData(const void *data, const uint32_t len, std::string &sign)
{
return false;
}
bool GPGAuthMgr::SignDataBin(std::string input, unsigned char *sign, unsigned int *signlen)
bool AuthGPG::SignDataBin(std::string input, unsigned char *sign, unsigned int *signlen)
{
return false;
}
bool GPGAuthMgr::SignDataBin(const void *data, unsigned int datalen, unsigned char *sign, unsigned int *signlen) {
bool AuthGPG::SignDataBin(const void *data, unsigned int datalen, unsigned char *sign, unsigned int *signlen) {
return DoOwnSignature_locked(data, datalen,
sign, signlen);
}
bool GPGAuthMgr::VerifySignBin(const void *data, uint32_t datalen, unsigned char *sign, unsigned int signlen) {
bool AuthGPG::VerifySignBin(const void *data, uint32_t datalen, unsigned char *sign, unsigned int signlen) {
return VerifySignature_locked(data, datalen,
sign, signlen);
}
@ -1306,7 +1311,7 @@ bool GPGAuthMgr::VerifySignBin(const void *data, uint32_t datalen, unsigned char
/* Sign/Trust stuff */
int GPGAuthMgr::privateSignCertificate(std::string id)
int AuthGPG::privateSignCertificate(std::string id)
{
RsStackMutex stack(pgpMtx); /******* LOCKED ******/
@ -1349,20 +1354,20 @@ int GPGAuthMgr::privateSignCertificate(std::string id)
}
/* revoke the signature on Certificate */
int GPGAuthMgr::privateRevokeCertificate(std::string id)
int AuthGPG::privateRevokeCertificate(std::string id)
{
RsStackMutex stack(pgpMtx); /******* LOCKED ******/
return 0;
}
int GPGAuthMgr::privateTrustCertificate(std::string id, int trustlvl)
int AuthGPG::privateTrustCertificate(std::string id, int trustlvl)
{
RsStackMutex stack(pgpMtx); /******* LOCKED ******/
/* The certificate should be in Peers list ??? */
if(!isAuthenticated(id)) {
if(!isPGPAuthenticated(id)) {
std::cerr << "Invalid Certificate" << std::endl;
return 0;
}
@ -1387,7 +1392,7 @@ int GPGAuthMgr::privateTrustCertificate(std::string id, int trustlvl)
/* This function to print Data */
void GPGAuthMgr::showData(gpgme_data_t dh)
void AuthGPG::showData(gpgme_data_t dh)
{
#define BUF_SIZE 512
char buf[BUF_SIZE + 1];
@ -1420,7 +1425,7 @@ void GPGAuthMgr::showData(gpgme_data_t dh)
* Create a number of friends and add them to the Map of "others" -- people who
* are known but are not allowed to access retroshare
*/
void GPGAuthMgr::createDummyFriends()
void AuthGPG::createDummyFriends()
{
const unsigned int DUMMY_KEY_LEN = 2048;

View file

@ -40,8 +40,6 @@
#define GPG_id std::string
class AuthGPG;
/* gpgcert is the identifier for a person.
* It is a wrapper class for a GPGme OpenPGP certificate.
*/
@ -76,7 +74,7 @@ class gpgcert
*/
typedef std::map<std::string, gpgcert> certmap;
class GPGAuthMgr
class AuthGPG
{
private:
@ -99,10 +97,12 @@ class GPGAuthMgr
public:
GPGAuthMgr();
~GPGAuthMgr();
AuthGPG();
~AuthGPG();
bool availablePGPCertificates(std::list<std::string> &ids);
static AuthGPG *getAuthGPG();
bool availablePGPCertificates(std::list<std::string> &ids);
//get the pgpg engine used by the pgp functions
bool getPGPEngineFileName(std::string &fileName);
@ -154,7 +154,6 @@ class GPGAuthMgr
****/
/* get Details from the Certificates */
bool isAuthenticated(std::string id);
std::string getPGPName(GPG_id pgp_id);
std::string getPGPEmail(GPG_id pgp_id);
@ -224,10 +223,9 @@ class GPGAuthMgr
bool checkSignature(std::string id, std::string hash, std::string signature);
private:
RsMutex pgpMtx;
RsMutex pgpMtx;
/* Below is protected via the mutex */
certmap mKeyList;
@ -248,13 +246,7 @@ bool checkSignature(std::string id, std::string hash, std::string signature);
};
// the single instance of this
static GPGAuthMgr instance_gpgroot;
GPGAuthMgr *getAuthGPG()
{
return &instance_gpgroot;
}
static AuthGPG instance_gpgroot;
/* Sign a key */

View file

@ -32,6 +32,7 @@
#include "cleanupxpgp.h"
#include "pqinetwork.h"
#include "authgpg.h"
/******************** notify of new Cert **************************/
#include "pqinotify.h"
@ -64,6 +65,12 @@ sslcert::sslcert(X509 *x509, std::string pid)
authed = false;
}
sslcert::sslcert()
{
email = "";
authed = false;
}
X509_REQ *GenerateX509Req(
std::string pkey_file, std::string passwd,
std::string name, std::string email, std::string org,
@ -394,6 +401,12 @@ AuthSSL::AuthSSL()
{
}
AuthSSL *AuthSSL::getAuthSSL()
{
return &instance_sslroot;
//return NULL;
}
bool AuthSSL::active()
{
return init;
@ -1899,7 +1912,7 @@ X509 *AuthSSL::SignX509Req(X509_REQ *req, long days)
std::cerr << "Digest Applied: len: " << hashoutl << std::endl;
/* NOW Sign via GPG Functions */
if (!getAuthGPG()->SignDataBin(buf_hashout, hashoutl, buf_sigout, (unsigned int *) &sigoutl))
if (!AuthGPG::getAuthGPG()->SignDataBin(buf_hashout, hashoutl, buf_sigout, (unsigned int *) &sigoutl))
{
sigoutl = 0;
goto err;
@ -2011,7 +2024,7 @@ bool AuthSSL::AuthX509(X509 *x509)
memmove(buf_sigout, signature->data, sigoutl);
/* NOW Sign via GPG Functions */
if (!getAuthGPG()->VerifySignBin(buf_hashout, hashoutl, buf_sigout, (unsigned int) sigoutl))
if (!AuthGPG::getAuthGPG()->VerifySignBin(buf_hashout, hashoutl, buf_sigout, (unsigned int) sigoutl))
{
sigoutl = 0;
goto err;
@ -2131,7 +2144,7 @@ int pem_passwd_cb(char *buf, int size, int rwflag, void *password)
static int verify_x509_callback(int preverify_ok, X509_STORE_CTX *ctx)
{
return getAuthSSL()->VerifyX509Callback(preverify_ok, ctx);
return AuthSSL::getAuthSSL()->VerifyX509Callback(preverify_ok, ctx);
}
@ -2243,7 +2256,7 @@ int LoadCheckX509andGetName(const char *cert_file, std::string &userName, std::s
bool valid = false;
if (x509)
{
valid = getAuthSSL()->ValidateCertificate(x509, userId);
valid =AuthSSL::getAuthSSL()->ValidateCertificate(x509, userId);
}
if (valid)
@ -2296,7 +2309,7 @@ int LoadCheckX509andGetIssuerName(const char *cert_file, std::string &issuerName
bool valid = false;
if (x509)
{
valid = getAuthSSL()->ValidateCertificate(x509, userId);
valid = AuthSSL::getAuthSSL()->ValidateCertificate(x509, userId);
}
if (valid)

View file

@ -48,8 +48,6 @@
#include <string>
#include <map>
#include "authgpg.h"
#include "util/rsthreads.h"
#include "pqi/pqi_base.h"
@ -89,7 +87,10 @@ class AuthSSL
{
public:
/* Initialisation Functions (Unique) */
// the single instance of this
static AuthSSL *getAuthSSL();
/* Initialisation Functions (Unique) */
AuthSSL();
bool validateOwnCertificate(X509 *x509, EVP_PKEY *pkey);
@ -115,7 +116,7 @@ virtual bool isValid(std::string id);
virtual bool isAuthenticated(std::string id);
virtual std::string getName(std::string id);
virtual std::string getIssuerName(std::string id);
virtual GPG_id getGPGId(SSL_id id);
virtual std::string getGPGId(SSL_id id);
virtual bool getCertDetails(std::string id, sslcert &cert);
/* first party trust info (dummy) */
@ -185,11 +186,9 @@ bool CheckCertificate(std::string peerId, X509 *x509); /* check that they are e
bool loadCertificates(bool &oldFormat, std::map<std::string, std::string> &keyValueMap);
private:
/* Helper Functions */
bool ProcessX509(X509 *x509, std::string &id);
X509 * loadX509FromPEM(std::string pem);
@ -204,7 +203,7 @@ bool locked_FindCert(std::string id, sslcert **cert);
/* Data */
RsMutex sslMtx; /**** LOCKING */
RsMutex sslMtx; /**** LOCKING */
int init;
std::string mCertConfigFile;
@ -222,15 +221,9 @@ bool locked_FindCert(std::string id, sslcert **cert);
};
// the single instance of this, but only when SSL Only
// the single instance of this
static AuthSSL instance_sslroot;
AuthSSL *getAuthSSL()
{
return &instance_sslroot;
}
X509_REQ *GenerateX509Req(
std::string pkey_file, std::string passwd,
std::string name, std::string email, std::string org,
@ -249,12 +242,6 @@ std::string getX509OrgString(X509_NAME *name);
std::string getX509LocString(X509_NAME *name);
std::string getX509CountryString(X509_NAME *name);
#if 0
std::list<std::string> getXPGPsigners(XPGP *cert);
std::string getXPGPAuthCode(XPGP *xpgp);
#endif
std::string getX509Info(X509 *cert);
bool getX509id(X509 *x509, std::string &xid);

View file

@ -160,7 +160,7 @@ void p3ConfigMgr::saveConfiguration()
/* sign data */
std::string signature;
getAuthSSL()->SignData(membio->memptr(), membio->memsize(), signature);
AuthSSL::getAuthSSL()->SignData(membio->memptr(), membio->memsize(), signature);
#ifdef CONFIG_DEBUG
std::cerr << "p3ConfigMgr::saveConfiguration() MetaFile Signature:";
@ -274,7 +274,7 @@ void p3ConfigMgr::loadConfiguration()
/* get signature */
std::string signature;
getAuthSSL()->SignData(membio->memptr(), membio->memsize(), signature);
AuthSSL::getAuthSSL()->SignData(membio->memptr(), membio->memsize(), signature);
#ifdef CONFIG_DEBUG
std::cerr << "p3ConfigMgr::loadConfiguration() New MetaFile Signature:";

View file

@ -135,8 +135,8 @@ p3ConnectMgr::p3ConnectMgr()
mStatusChanged(false)
{
/* setup basics of own state */
ownState.id = getAuthSSL()->OwnId();
ownState.name = getAuthSSL()->getName(ownState.id);
ownState.id = AuthSSL::getAuthSSL()->OwnId();
ownState.name = AuthSSL::getAuthSSL()->getName(ownState.id);
ownState.netMode = RS_NET_MODE_UDP;
//use_extr_addr_finder = true ;
@ -1342,7 +1342,7 @@ void p3ConnectMgr::tickMonitors()
const std::string p3ConnectMgr::getOwnId()
{
return getAuthSSL()->OwnId();
return AuthSSL::getAuthSSL()->OwnId();
}
@ -1374,7 +1374,7 @@ bool p3ConnectMgr::isOnline(std::string id)
else
{
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::isOnline(" << id << ") is Not Friend" << std::endl << "p3ConnectMgr::isOnline() OwnId: " << getAuthSSL()->OwnId() << std::endl;
std::cerr << "p3ConnectMgr::isOnline(" << id << ") is Not Friend" << std::endl << "p3ConnectMgr::isOnline() OwnId: " << AuthSSL::getAuthSSL()->OwnId() << std::endl;
#endif
/* not a friend */
}
@ -2014,7 +2014,7 @@ bool p3ConnectMgr::addFriend(std::string id, uint32_t netMode, uint32_t visState
}
/* check with the AuthMgr if its authorised */
if (!getAuthSSL()->isAuthenticated(id))
if (!AuthSSL::getAuthSSL()->isAuthenticated(id))
{
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::addFriend() Failed Authentication" << std::endl;
@ -2065,7 +2065,7 @@ bool p3ConnectMgr::addFriend(std::string id, uint32_t netMode, uint32_t visState
/* get details from AuthMgr */
sslcert detail;
if (!getAuthSSL()->getCertDetails(id, detail))
if (!AuthSSL::getAuthSSL()->getCertDetails(id, detail))
{
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::addFriend() Failed to get Details" << std::endl;
@ -2174,7 +2174,7 @@ bool p3ConnectMgr::addNeighbour(std::string id)
}
/* check with the AuthMgr if its valid */
if (!getAuthSSL()->isValid(id))
if (!AuthSSL::getAuthSSL()->isValid(id))
{
/* no auth */
return false;
@ -2182,7 +2182,7 @@ bool p3ConnectMgr::addNeighbour(std::string id)
/* get details from AuthMgr */
sslcert detail;
if (!getAuthSSL()->getCertDetails(id, detail))
if (!AuthSSL::getAuthSSL()->getCertDetails(id, detail))
{
/* no details */
return false;
@ -2459,7 +2459,7 @@ bool p3ConnectMgr::retryConnectNotify(std::string id)
bool p3ConnectMgr::setLocalAddress(std::string id, struct sockaddr_in addr)
{
if (id == getAuthSSL()->OwnId())
if (id == AuthSSL::getAuthSSL()->OwnId())
{
{
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
@ -2509,7 +2509,7 @@ bool p3ConnectMgr::setLocalAddress(std::string id, struct sockaddr_in addr)
bool p3ConnectMgr::setExtAddress(std::string id, struct sockaddr_in addr)
{
if (id == getAuthSSL()->OwnId())
if (id == AuthSSL::getAuthSSL()->OwnId())
{
if (ownState.currentserveraddr.sin_addr.s_addr != addr.sin_addr.s_addr ||
ownState.currentserveraddr.sin_port != addr.sin_port) {
@ -2609,7 +2609,7 @@ bool p3ConnectMgr::setAddressList(std::string id, std::list<IpAddressTimed> I
bool p3ConnectMgr::setNetworkMode(std::string id, uint32_t netMode)
{
if (id == getAuthSSL()->OwnId())
if (id == AuthSSL::getAuthSSL()->OwnId())
{
uint32_t visState = ownState.visState;
setOwnNetConfig(netMode, visState);
@ -2639,7 +2639,7 @@ bool p3ConnectMgr::setNetworkMode(std::string id, uint32_t netMode)
bool p3ConnectMgr::setVisState(std::string id, uint32_t visState)
{
if (id == getAuthSSL()->OwnId())
if (id == AuthSSL::getAuthSSL()->OwnId())
{
uint32_t netMode = ownState.netMode;
setOwnNetConfig(netMode, visState);