mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
changed Radix64::decode to return result as std::vector
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@8520 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
6a924cb854
commit
13355a7efe
@ -29,16 +29,12 @@ bool PGPKeyManagement::createMinimalKey(const std::string& pgp_certificate,std::
|
|||||||
|
|
||||||
// 1 - Convert armored key into binary key
|
// 1 - Convert armored key into binary key
|
||||||
//
|
//
|
||||||
|
std::vector<uint8_t> keydata = Radix64::decode(radix_cert) ;
|
||||||
char *keydata = NULL ;
|
|
||||||
size_t len = 0 ;
|
|
||||||
|
|
||||||
Radix64::decode(radix_cert,keydata,len) ;
|
|
||||||
|
|
||||||
size_t new_len ;
|
size_t new_len ;
|
||||||
findLengthOfMinimalKey((unsigned char *)keydata,len,new_len) ;
|
findLengthOfMinimalKey(keydata.data(), keydata.size(), new_len) ;
|
||||||
|
|
||||||
cleaned_certificate = makeArmouredKey((unsigned char*)keydata,new_len,version_string) ;
|
cleaned_certificate = makeArmouredKey(keydata.data(), new_len, version_string) ;
|
||||||
return true ;
|
return true ;
|
||||||
}
|
}
|
||||||
catch(std::exception& e)
|
catch(std::exception& e)
|
||||||
|
@ -251,12 +251,11 @@ bool RsCertificate::initFromString(const std::string& instr,uint32_t& err_code)
|
|||||||
#endif
|
#endif
|
||||||
// 1 - decode the string.
|
// 1 - decode the string.
|
||||||
//
|
//
|
||||||
char *bf = NULL ;
|
std::vector<uint8_t> bf = Radix64::decode(str) ;
|
||||||
size_t size ;
|
size_t size = bf.size();
|
||||||
Radix64::decode(str,bf, size) ;
|
|
||||||
|
|
||||||
bool checksum_check_passed = false ;
|
bool checksum_check_passed = false ;
|
||||||
unsigned char *buf = (unsigned char *)bf ;
|
unsigned char *buf = bf.data() ;
|
||||||
size_t total_s = 0 ;
|
size_t total_s = 0 ;
|
||||||
only_pgp = true ;
|
only_pgp = true ;
|
||||||
uint8_t certificate_version = 0x00 ;
|
uint8_t certificate_version = 0x00 ;
|
||||||
@ -348,7 +347,7 @@ bool RsCertificate::initFromString(const std::string& instr,uint32_t& err_code)
|
|||||||
err_code = CERTIFICATE_PARSING_ERROR_INVALID_CHECKSUM_SECTION ;
|
err_code = CERTIFICATE_PARSING_ERROR_INVALID_CHECKSUM_SECTION ;
|
||||||
return false ;
|
return false ;
|
||||||
}
|
}
|
||||||
uint32_t computed_crc = PGPKeyManagement::compute24bitsCRC((unsigned char *)bf,size-5) ;
|
uint32_t computed_crc = PGPKeyManagement::compute24bitsCRC(bf.data(),size-5) ;
|
||||||
uint32_t certificate_crc = buf[0] + (buf[1] << 8) + (buf[2] << 16) ;
|
uint32_t certificate_crc = buf[0] + (buf[1] << 8) + (buf[2] << 16) ;
|
||||||
|
|
||||||
if(computed_crc != certificate_crc)
|
if(computed_crc != certificate_crc)
|
||||||
@ -386,7 +385,6 @@ bool RsCertificate::initFromString(const std::string& instr,uint32_t& err_code)
|
|||||||
if(total_s != size)
|
if(total_s != size)
|
||||||
std::cerr << "(EE) Certificate contains trailing characters. Weird." << std::endl;
|
std::cerr << "(EE) Certificate contains trailing characters. Weird." << std::endl;
|
||||||
|
|
||||||
delete[] bf ;
|
|
||||||
return true ;
|
return true ;
|
||||||
}
|
}
|
||||||
catch(std::exception& e)
|
catch(std::exception& e)
|
||||||
|
@ -3,11 +3,12 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
class Radix64
|
class Radix64
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static void decode(const std::string& buffer,char *& out, size_t& len)
|
static std::vector<uint8_t> decode(const std::string& buffer)
|
||||||
{
|
{
|
||||||
char val;
|
char val;
|
||||||
int c = 0, c2;/* init c because gcc is not clever
|
int c = 0, c2;/* init c because gcc is not clever
|
||||||
@ -17,7 +18,7 @@ class Radix64
|
|||||||
|
|
||||||
radix64_init();
|
radix64_init();
|
||||||
|
|
||||||
std::vector<char> buf ;
|
std::vector<uint8_t> buf ;
|
||||||
idx = 0;
|
idx = 0;
|
||||||
val = 0;
|
val = 0;
|
||||||
|
|
||||||
@ -94,10 +95,7 @@ again:
|
|||||||
|
|
||||||
idx = idx;
|
idx = idx;
|
||||||
|
|
||||||
len = buf.size() ;
|
return buf;
|
||||||
out = new char[len] ;
|
|
||||||
|
|
||||||
memcpy(out,&buf[0],len) ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************
|
/****************
|
||||||
|
@ -57,16 +57,12 @@ static std::string RecognSigningKeys[NUM_RECOGN_SIGN_KEYS] =
|
|||||||
EVP_PKEY *RsRecogn::loadMasterKey()
|
EVP_PKEY *RsRecogn::loadMasterKey()
|
||||||
{
|
{
|
||||||
/* load master signing key */
|
/* load master signing key */
|
||||||
size_t keylen;
|
std::vector<uint8_t> decoded = Radix64::decode(RecognKey);
|
||||||
char *keyptr;
|
|
||||||
|
|
||||||
Radix64::decode(RecognKey, keyptr, keylen);
|
const unsigned char *keyptr2 = decoded.data();
|
||||||
|
long keylen2 = decoded.size();
|
||||||
const unsigned char *keyptr2 = (const unsigned char *) keyptr;
|
|
||||||
long keylen2 = keylen;
|
|
||||||
|
|
||||||
RSA *rsakey = d2i_RSAPublicKey(NULL, &(keyptr2), keylen2);
|
RSA *rsakey = d2i_RSAPublicKey(NULL, &(keyptr2), keylen2);
|
||||||
delete []keyptr;
|
|
||||||
|
|
||||||
if (!rsakey)
|
if (!rsakey)
|
||||||
{
|
{
|
||||||
@ -102,16 +98,12 @@ bool RsRecogn::loadSigningKeys(std::map<RsGxsId, RsGxsRecognSignerItem *> &signM
|
|||||||
|
|
||||||
for(int i = 0; i < NUM_RECOGN_SIGN_KEYS; i++)
|
for(int i = 0; i < NUM_RECOGN_SIGN_KEYS; i++)
|
||||||
{
|
{
|
||||||
char *signerbuf;
|
std::vector<uint8_t> signerbuf = Radix64::decode(RecognSigningKeys[i]);
|
||||||
size_t len;
|
|
||||||
Radix64::decode(RecognSigningKeys[i], signerbuf, len);
|
|
||||||
|
|
||||||
uint32_t pktsize = len;
|
uint32_t pktsize = signerbuf.size();
|
||||||
RsItem *pktitem = recognSerialiser.deserialise(signerbuf, &pktsize);
|
RsItem *pktitem = recognSerialiser.deserialise(signerbuf.data(), &pktsize);
|
||||||
RsGxsRecognSignerItem *item = dynamic_cast<RsGxsRecognSignerItem *>(pktitem);
|
RsGxsRecognSignerItem *item = dynamic_cast<RsGxsRecognSignerItem *>(pktitem);
|
||||||
|
|
||||||
delete []signerbuf;
|
|
||||||
|
|
||||||
if (!item)
|
if (!item)
|
||||||
{
|
{
|
||||||
#ifdef DEBUG_RECOGN
|
#ifdef DEBUG_RECOGN
|
||||||
@ -527,16 +519,13 @@ std::string RsRecogn::getRsaKeyId(RSA *pubkey)
|
|||||||
RsGxsRecognTagItem *RsRecogn::extractTag(const std::string &encoded)
|
RsGxsRecognTagItem *RsRecogn::extractTag(const std::string &encoded)
|
||||||
{
|
{
|
||||||
// Decode from Radix64 encoded Packet.
|
// Decode from Radix64 encoded Packet.
|
||||||
size_t buflen;
|
|
||||||
char *buffer;
|
|
||||||
uint32_t pktsize;
|
uint32_t pktsize;
|
||||||
|
|
||||||
Radix64::decode(encoded, buffer, buflen);
|
std::vector<uint8_t> buffer = Radix64::decode(encoded);
|
||||||
pktsize = buflen;
|
pktsize = buffer.size();
|
||||||
|
|
||||||
RsGxsRecognSerialiser serialiser;
|
RsGxsRecognSerialiser serialiser;
|
||||||
RsItem *item = serialiser.deserialise(buffer, &pktsize);
|
RsItem *item = serialiser.deserialise(buffer.data(), &pktsize);
|
||||||
delete []buffer;
|
|
||||||
|
|
||||||
if (!item)
|
if (!item)
|
||||||
{
|
{
|
||||||
|
@ -860,14 +860,12 @@ int GeneratePasswordHash(std::string saltBin, std::string password, std::string
|
|||||||
int CheckPasswordHash(std::string pwdHashRadix64, std::string password)
|
int CheckPasswordHash(std::string pwdHashRadix64, std::string password)
|
||||||
{
|
{
|
||||||
char output[1024];
|
char output[1024];
|
||||||
char *buf = NULL;
|
std::vector<uint8_t> buf = Radix64::decode(pwdHashRadix64);
|
||||||
size_t len = 1024;
|
size_t len = buf.size();
|
||||||
Radix64::decode(pwdHashRadix64, buf, len);
|
|
||||||
for(unsigned int i = 0; (i < len) && (i < 1024); i++)
|
for(unsigned int i = 0; (i < len) && (i < 1024); i++)
|
||||||
{
|
{
|
||||||
output[i] = buf[i];
|
output[i] = buf[i];
|
||||||
}
|
}
|
||||||
delete []buf;
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
std::cerr << "CheckPasswordHash() Input: " << pwdHashRadix64;
|
std::cerr << "CheckPasswordHash() Input: " << pwdHashRadix64;
|
||||||
|
Loading…
Reference in New Issue
Block a user