fixed memory issue, added signature verification (uncomplete)

git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-OpenPGP@5072 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2012-04-01 21:10:54 +00:00
parent 33a37054e8
commit eb448cbaaf
4 changed files with 35 additions and 2 deletions

View File

@ -11,6 +11,7 @@ extern "C" {
#include <openpgpsdk/armour.h>
#include <openpgpsdk/keyring.h>
#include <openpgpsdk/readerwriter.h>
#include <openpgpsdk/validate.h>
}
#include "pgphandler.h"
@ -229,7 +230,14 @@ bool PGPHandler::GeneratePGPCertificate(const std::string& name, const std::stri
std::cerr << "Added new secret key with id " << pgpId.toStdString() << " to secret keyring." << std::endl;
// We should store it in the keyring.
// 5 - copy the private key to the public keyring
addNewKeyToOPSKeyring(_pubring,tmp_keyring->keys[0]) ;
_public_keyring_map[ pgpId.toUInt64() ] = _pubring->nkeys-1 ;
std::cerr << "Added new public key with id " << pgpId.toStdString() << " to public keyring." << std::endl;
// 6 - clean
ops_keyring_free(tmp_keyring) ;
free(tmp_keyring) ;
@ -380,3 +388,18 @@ bool PGPHandler::SignDataBin(const PGPIdType& id,const void *data, const uint32_
return true ;
}
bool PGPHandler::VerifySignBin(const void *data, uint32_t data_len, unsigned char *sign, unsigned int sign_len, const std::string &withfingerprint)
{
ops_memory_t *mem = ops_memory_new() ;
ops_memory_add(mem,(unsigned char *)sign,sign_len) ;
ops_validate_result_t *result = (ops_validate_result_t*)ops_mallocz(sizeof(ops_validate_result_t)) ;
ops_boolean_t res = ops_validate_mem(result, mem, ops_false, _pubring);
ops_validate_result_free(result) ;
// no need to clear mem. It's already deleted by ops_validate_mem (weird but true).
return res ;
}

View File

@ -51,7 +51,7 @@ class PGPHandler
bool TrustCertificate(const PGPIdType& id, int trustlvl);
bool SignDataBin(const PGPIdType& id,const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen) ;
bool VerifySignBin(const void*, uint32_t, unsigned char*, unsigned int, const std::string &withfingerprint) { return false ; }
bool VerifySignBin(const void *data, uint32_t data_len, unsigned char *sign, unsigned int sign_len, const std::string &withfingerprint) ;
// Debug stuff.
virtual void printKeys() const ;

View File

@ -84,6 +84,13 @@ int main(int argc,char *argv[])
std::cerr << "Signature error." << std::endl;
else
std::cerr << "Signature success." << std::endl;
std::cerr << "Now verifying signature..." << std::endl;
if(!pgph.VerifySignBin(test_bin,13,sign,signlen,""))
std::cerr << "Signature verification failed." << std::endl;
else
std::cerr << "Signature verification worked!" << std::endl;
return 0 ;
}

View File

@ -3032,6 +3032,9 @@ static int ops_parse_one_packet(ops_parse_info_t *pinfo,
pinfo->rinfo.asize=0;
CBP(pinfo,OPS_PARSER_PACKET_END,&content);
}
else
C.packet.raw = NULL ;
pinfo->rinfo.alength=0;
free(C.packet.raw) ;