mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-12 11:02:30 -04:00
fixed auto-tests in pgp directory
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6047 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
d1752bbdcb
commit
05df11117c
10 changed files with 168 additions and 50 deletions
|
@ -1,6 +1,7 @@
|
||||||
|
|
||||||
RS_TOP_DIR = ../..
|
RS_TOP_DIR = ../..
|
||||||
DHT_TOP_DIR = ../../../../libbitdht/src
|
DHT_TOP_DIR = ../../../../libbitdht/src
|
||||||
|
OPS_TOP_DIR = ../../../../openpgpsdk/src
|
||||||
OPENPGP_INCLUDE_DIR = ../../../../openpgpsdk/src
|
OPENPGP_INCLUDE_DIR = ../../../../openpgpsdk/src
|
||||||
|
|
||||||
##### Define any flags that are needed for this section #######
|
##### Define any flags that are needed for this section #######
|
||||||
|
|
|
@ -1,12 +1,15 @@
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <util/utest.h>
|
||||||
#include <common/argstream.h>
|
#include <common/argstream.h>
|
||||||
//#include <pqi/cleanupxpgp.h>
|
//#include <pqi/cleanupxpgp.h>
|
||||||
#include <retroshare/rspeers.h>
|
#include <retroshare/rspeers.h>
|
||||||
#include <pgp/rscertificate.h>
|
#include <pgp/rscertificate.h>
|
||||||
#include <pgp/pgphandler.h>
|
#include <pgp/pgphandler.h>
|
||||||
|
|
||||||
|
INITTEST() ;
|
||||||
|
|
||||||
int main(int argc,char *argv[])
|
int main(int argc,char *argv[])
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -23,8 +26,7 @@ int main(int argc,char *argv[])
|
||||||
|
|
||||||
FILE *f = fopen(keyfile.c_str(),"rb") ;
|
FILE *f = fopen(keyfile.c_str(),"rb") ;
|
||||||
|
|
||||||
if(f == NULL)
|
CHECK(f != NULL) ;
|
||||||
throw std::runtime_error("Cannot open file. Sorry.") ;
|
|
||||||
|
|
||||||
std::string res ;
|
std::string res ;
|
||||||
char c ;
|
char c ;
|
||||||
|
@ -72,17 +74,30 @@ int main(int argc,char *argv[])
|
||||||
std::list<std::string> signers ;
|
std::list<std::string> signers ;
|
||||||
|
|
||||||
PGPHandler handler("toto1","toto2","toto3","toto4") ;
|
PGPHandler handler("toto1","toto2","toto3","toto4") ;
|
||||||
handler.getGPGDetailsFromBinaryBlock(cert.pgp_key(),cert.pgp_key_size(),key_id,name,signers) ;
|
handler.getGPGDetailsFromBinaryBlock(cert.pgp_key(),cert.pgp_key_size(),key_id,name,signers) ;
|
||||||
|
|
||||||
|
CHECK(key_id == "660FB771727CE286") ;
|
||||||
|
CHECK(name == "Cyril-test (generated by Retroshare) <cyril.soler@imag.fr>") ;
|
||||||
|
|
||||||
std::cerr << "Details loaded from certificate:" << std::endl;
|
std::cerr << "Details loaded from certificate:" << std::endl;
|
||||||
std::cerr << "PGP id\t: " << key_id << std::endl;
|
std::cerr << "PGP id\t: " << key_id << std::endl;
|
||||||
std::cerr << "Key name\t: " << name << std::endl;
|
std::cerr << "Key name\t: " << name << std::endl;
|
||||||
std::cerr << "Signers\t:" << std::endl;
|
std::cerr << "Signers\t:" << std::endl;
|
||||||
|
|
||||||
|
bool found = false ;
|
||||||
|
|
||||||
for(std::list<std::string>::const_iterator it(signers.begin());it!=signers.end();++it)
|
for(std::list<std::string>::const_iterator it(signers.begin());it!=signers.end();++it)
|
||||||
|
{
|
||||||
std::cerr << " " << *it << std::endl;
|
std::cerr << " " << *it << std::endl;
|
||||||
|
|
||||||
return 0;
|
if(*it == key_id)
|
||||||
|
found = true ;
|
||||||
|
}
|
||||||
|
CHECK(found) ;
|
||||||
|
|
||||||
|
FINALREPORT("Test certificate parsing") ;
|
||||||
|
|
||||||
|
return TESTRESULT();
|
||||||
}
|
}
|
||||||
catch(std::exception& e)
|
catch(std::exception& e)
|
||||||
{
|
{
|
||||||
|
|
15
libretroshare/src/tests/pgp/test_certificate.newformat.rsc
Normal file
15
libretroshare/src/tests/pgp/test_certificate.newformat.rsc
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
Af8AAAKHmQENBEyoe/MBCAC9rKm/ehp9Iv1XrOiKIyj1X5nJzQ660+OhmQf4lbJv
|
||||||
|
krcnvdrdcmlfZQfupWMXHo7A3+27lOpfTvA1xpO8Gze0bRbLsbpx2dARjLUzXJAI
|
||||||
|
FNCYzH5xlIixxOwgX3tinKfoP3WvZv+nYBac/HeAPUW8BVqx6Y6V/gM3c71XNf9u
|
||||||
|
hPgArN0jvLOeqAJY+lACJZYlAIw6Jt2FzarC+orWndkvrsgrWmdxkorfZKBfdNwd
|
||||||
|
f1YYrpUmGaf51x4DkrMWpfHxS8b6cgOmSN3LeAC8LCm5oEXPfNgaRehN9LKrSmcp
|
||||||
|
cPS2jvDipgGBx+nL7gytCREMJkJoxppXQpVt1whaFDJVABEBAAG0OkN5cmlsLXRl
|
||||||
|
c3QgKGdlbmVyYXRlZCBieSBSZXRyb3NoYXJlKSA8Y3lyaWwuc29sZXJAaW1hZy5m
|
||||||
|
cj6JATgEEwECACIFAkyoe/MCGy8GCwkIBwMCBhUIAgkKCwQWAgMBAh4BAheAAAoJ
|
||||||
|
EGYPt3FyfOKG+h0H/A+vvryYmGcGFl82D4M0mAPAlbjZFkGCB8qJJSFuor55GJ3V
|
||||||
|
8pBb4UK7jnLhQhqsdXxAawT9R5RzTDITWHkS4KVaFalOYLxQ8x4s31FWXUiprAvJ
|
||||||
|
AIVw9gnBC7kDLro2irCljZB5ro8fsg0SJ0ZFc4cZMPZxnMKm5ovC6WggbblyaHrR
|
||||||
|
rV8jhHFIR+RG9/nnw0PgvGOmV9f4Q0a/7E18AxdBXYMZSp7p/mwbQdkqgm7p73bg
|
||||||
|
7E2Zz/Fhg1/PguwjlDal+HyUEPDvcPG41NAKwpMeL78qVJTQcBzzo1Irqj5f5UFJ
|
||||||
|
p4/H7QDlEsz/ZGxXXq3PdAP5BICwiOD44G9dIUECBlLktZUcsQMGwKgAZxyxBAAG
|
||||||
|
BmxhcHRvcAUQXVLApuPC+s1X/RPnFumDgQ==
|
21
libretroshare/src/tests/pgp/test_certificate.oldformat.rsc
Normal file
21
libretroshare/src/tests/pgp/test_certificate.oldformat.rsc
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
-----BEGIN PGP PUBLIC KEY BLOCK-----
|
||||||
|
Version: OpenPGP:SDK v0.9
|
||||||
|
|
||||||
|
mQENBEyoe/MBCAC9rKm/ehp9Iv1XrOiKIyj1X5nJzQ660+OhmQf4lbJvkrcnvdrd
|
||||||
|
cmlfZQfupWMXHo7A3+27lOpfTvA1xpO8Gze0bRbLsbpx2dARjLUzXJAIFNCYzH5x
|
||||||
|
lIixxOwgX3tinKfoP3WvZv+nYBac/HeAPUW8BVqx6Y6V/gM3c71XNf9uhPgArN0j
|
||||||
|
vLOeqAJY+lACJZYlAIw6Jt2FzarC+orWndkvrsgrWmdxkorfZKBfdNwdf1YYrpUm
|
||||||
|
Gaf51x4DkrMWpfHxS8b6cgOmSN3LeAC8LCm5oEXPfNgaRehN9LKrSmcpcPS2jvDi
|
||||||
|
pgGBx+nL7gytCREMJkJoxppXQpVt1whaFDJVABEBAAG0OkN5cmlsLXRlc3QgKGdl
|
||||||
|
bmVyYXRlZCBieSBSZXRyb3NoYXJlKSA8Y3lyaWwuc29sZXJAaW1hZy5mcj6JATgE
|
||||||
|
EwECACIFAkyoe/MCGy8GCwkIBwMCBhUIAgkKCwQWAgMBAh4BAheAAAoJEGYPt3Fy
|
||||||
|
fOKG+h0H/A+vvryYmGcGFl82D4M0mAPAlbjZFkGCB8qJJSFuor55GJ3V8pBb4UK7
|
||||||
|
jnLhQhqsdXxAawT9R5RzTDITWHkS4KVaFalOYLxQ8x4s31FWXUiprAvJAIVw9gnB
|
||||||
|
C7kDLro2irCljZB5ro8fsg0SJ0ZFc4cZMPZxnMKm5ovC6WggbblyaHrRrV8jhHFI
|
||||||
|
R+RG9/nnw0PgvGOmV9f4Q0a/7E18AxdBXYMZSp7p/mwbQdkqgm7p73bg7E2Zz/Fh
|
||||||
|
g1/PguwjlDal+HyUEPDvcPG41NAKwpMeL78qVJTQcBzzo1Irqj5f5UFJp4/H7QDl
|
||||||
|
Esz/ZGxXXq3PdAP5BICwiOD44G9dIUE=
|
||||||
|
=BWkb
|
||||||
|
-----END PGP PUBLIC KEY BLOCK-----
|
||||||
|
--SSLID--5d52c0a6e3c2facd57fd13e716e98381;--LOCATION--laptop;
|
||||||
|
--LOCAL--192.168.0.103:7345;--EXT--82.228.181.149:7345;
|
|
@ -10,8 +10,11 @@ extern "C"
|
||||||
#include <openpgpsdk/util.h>
|
#include <openpgpsdk/util.h>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include <util/utest.h>
|
||||||
#include <common/argstream.h>
|
#include <common/argstream.h>
|
||||||
|
|
||||||
|
INITTEST() ;
|
||||||
|
|
||||||
int main(int argc,char *argv[])
|
int main(int argc,char *argv[])
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -36,8 +39,7 @@ int main(int argc,char *argv[])
|
||||||
kr->nkeys_allocated = 0 ;
|
kr->nkeys_allocated = 0 ;
|
||||||
kr->keys = 0 ;
|
kr->keys = 0 ;
|
||||||
|
|
||||||
if(ops_false == ops_keyring_read_from_file(kr,armoured, keyfile.c_str()))
|
CHECK(ops_false != ops_keyring_read_from_file(kr,armoured, keyfile.c_str())) ;
|
||||||
throw std::runtime_error("PGPHandler::readKeyRing(): cannot read key file. File corrupted, or missing/superfluous armour parameter.") ;
|
|
||||||
|
|
||||||
for(int i=0;i<kr->nkeys;++i)
|
for(int i=0;i<kr->nkeys;++i)
|
||||||
{
|
{
|
||||||
|
@ -48,7 +50,9 @@ int main(int argc,char *argv[])
|
||||||
|
|
||||||
ops_list_packets(const_cast<char *>(keyfile.c_str()),armoured,kr,NULL) ;
|
ops_list_packets(const_cast<char *>(keyfile.c_str()),armoured,kr,NULL) ;
|
||||||
|
|
||||||
return 0 ;
|
FINALREPORT("Test key parsing") ;
|
||||||
|
|
||||||
|
return TESTRESULT() ;
|
||||||
}
|
}
|
||||||
catch(std::exception& e)
|
catch(std::exception& e)
|
||||||
{
|
{
|
||||||
|
|
2
libretroshare/src/tests/pgp/test_key_parsing.sh
Normal file
2
libretroshare/src/tests/pgp/test_key_parsing.sh
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
#!/bin/sh
|
||||||
|
./test_key_parsing -i test_pubring.gpg
|
|
@ -4,10 +4,17 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <pgp/pgphandler.h>
|
#include <pgp/pgphandler.h>
|
||||||
|
#include <util/utest.h>
|
||||||
#include <common/argstream.h>
|
#include <common/argstream.h>
|
||||||
|
|
||||||
|
INITTEST() ;
|
||||||
|
|
||||||
|
static std::string static_passphrase = "" ;
|
||||||
static std::string passphrase_callback(void *data,const char *uid_info,const char *what,int prev_was_bad)
|
static std::string passphrase_callback(void *data,const char *uid_info,const char *what,int prev_was_bad)
|
||||||
{
|
{
|
||||||
|
if(!static_passphrase.empty())
|
||||||
|
return static_passphrase ;
|
||||||
|
|
||||||
if(prev_was_bad)
|
if(prev_was_bad)
|
||||||
std::cerr << "Bad passphrase." << std::endl;
|
std::cerr << "Bad passphrase." << std::endl;
|
||||||
|
|
||||||
|
@ -95,6 +102,7 @@ int main(int argc,char *argv[])
|
||||||
bool test_output = false ;
|
bool test_output = false ;
|
||||||
bool test_signature = false ;
|
bool test_signature = false ;
|
||||||
bool test_passphrase_callback = false ;
|
bool test_passphrase_callback = false ;
|
||||||
|
bool full_test = false ;
|
||||||
|
|
||||||
std::string key_id_string = "" ;
|
std::string key_id_string = "" ;
|
||||||
std::string secring_file = "" ;
|
std::string secring_file = "" ;
|
||||||
|
@ -107,6 +115,7 @@ int main(int argc,char *argv[])
|
||||||
>> option('4',"keygen",test_gen_key,"Test key generation.")
|
>> option('4',"keygen",test_gen_key,"Test key generation.")
|
||||||
>> option('5',"signature",test_signature,"Test signature.")
|
>> option('5',"signature",test_signature,"Test signature.")
|
||||||
>> option('6',"output",test_output,"Test output.")
|
>> option('6',"output",test_output,"Test output.")
|
||||||
|
>> option('F',"fulltest",full_test,"Test everything.")
|
||||||
>> parameter('f',"file",file_to_encrypt,"File to encrypt. Used with -3",false)
|
>> parameter('f',"file",file_to_encrypt,"File to encrypt. Used with -3",false)
|
||||||
>> parameter('p',"pubring",pubring_file,"Public keyring file.",false)
|
>> parameter('p',"pubring",pubring_file,"Public keyring file.",false)
|
||||||
>> parameter('s',"secring",secring_file,"Secret keyring file.",false)
|
>> parameter('s',"secring",secring_file,"Secret keyring file.",false)
|
||||||
|
@ -115,20 +124,23 @@ int main(int argc,char *argv[])
|
||||||
|
|
||||||
as.defaultErrorHandling() ;
|
as.defaultErrorHandling() ;
|
||||||
|
|
||||||
|
if(!full_test)
|
||||||
if(test_pgpid_type + test_keyring_read + test_file_encryption + test_gen_key + test_signature + test_output != 1)
|
if(test_pgpid_type + test_keyring_read + test_file_encryption + test_gen_key + test_signature + test_output != 1)
|
||||||
{
|
{
|
||||||
std::cerr << "Options 1 to 6 are mutually exclusive." << std::endl;
|
std::cerr << "Options 1 to 6 are mutually exclusive." << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if(test_pgpid_type)
|
if(full_test || test_pgpid_type)
|
||||||
{
|
{
|
||||||
// test pgp ids.
|
// test pgp ids.
|
||||||
//
|
//
|
||||||
PGPIdType id = PGPIdType(std::string("3e5b22140ef56abb")) ;
|
std::string st("3e5b22140ef56abb") ;
|
||||||
|
PGPIdType id = PGPIdType(std::string(st)) ;
|
||||||
|
|
||||||
//std::cerr << "Id is : " << std::hex << id.toUInt64() << std::endl;
|
//std::cerr << "Id is : " << std::hex << id.toUInt64() << std::endl;
|
||||||
std::cerr << "Id st : " << id.toStdString() << std::endl;
|
std::cerr << "Id st : " << id.toStdString() << std::endl;
|
||||||
return 0 ;
|
|
||||||
|
CHECK(id.toStdString(false) == st) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
// test PGPHandler
|
// test PGPHandler
|
||||||
|
@ -144,7 +156,38 @@ int main(int argc,char *argv[])
|
||||||
PGPHandler::setPassphraseCallback(&passphrase_callback) ;
|
PGPHandler::setPassphraseCallback(&passphrase_callback) ;
|
||||||
PGPHandler pgph(pubring,secring,trustdb,lockfile) ;
|
PGPHandler pgph(pubring,secring,trustdb,lockfile) ;
|
||||||
|
|
||||||
if(test_keyring_read)
|
std::string email_str("test@gmail.com") ;
|
||||||
|
std::string name_str("test") ;
|
||||||
|
std::string passw_str("test00") ;
|
||||||
|
PGPIdType cert_id ; ;
|
||||||
|
|
||||||
|
if(full_test || test_gen_key)
|
||||||
|
{
|
||||||
|
std::cerr << "Now generating a new PGP certificate: " << std::endl;
|
||||||
|
std::cerr << " email: " << email_str << std::endl;
|
||||||
|
std::cerr << " passw: " << passw_str << std::endl;
|
||||||
|
std::cerr << " name : " << name_str << std::endl;
|
||||||
|
|
||||||
|
PGPIdType newid ;
|
||||||
|
std::string errString ;
|
||||||
|
static_passphrase = passw_str ;
|
||||||
|
|
||||||
|
bool res = pgph.GeneratePGPCertificate(name_str, email_str, passw_str, newid, errString) ;
|
||||||
|
|
||||||
|
cert_id = newid ;
|
||||||
|
|
||||||
|
CHECK(res) ;
|
||||||
|
|
||||||
|
if(!res)
|
||||||
|
std::cerr << "Generation of certificate returned error: " << errString << std::endl;
|
||||||
|
else
|
||||||
|
std::cerr << "Certificate generation success. New id = " << newid.toStdString() << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(full_test)
|
||||||
|
key_id_string = cert_id.toStdString(true) ;
|
||||||
|
|
||||||
|
if(full_test || test_keyring_read)
|
||||||
{
|
{
|
||||||
pgph.printKeys() ;
|
pgph.printKeys() ;
|
||||||
|
|
||||||
|
@ -156,33 +199,18 @@ int main(int argc,char *argv[])
|
||||||
std::list<PGPIdType> lst ;
|
std::list<PGPIdType> lst ;
|
||||||
pgph.availableGPGCertificatesWithPrivateKeys(lst) ;
|
pgph.availableGPGCertificatesWithPrivateKeys(lst) ;
|
||||||
|
|
||||||
|
bool found = false ;
|
||||||
|
|
||||||
for(std::list<PGPIdType>::const_iterator it(lst.begin());it!=lst.end();++it)
|
for(std::list<PGPIdType>::const_iterator it(lst.begin());it!=lst.end();++it)
|
||||||
std::cerr << "Found id : " << (*it).toStdString() << std::endl;
|
|
||||||
return 0 ;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(test_gen_key)
|
|
||||||
{
|
{
|
||||||
std::string email_str("test@gmail.com") ;
|
std::cerr << "Found id : " << (*it).toStdString() << std::endl;
|
||||||
std::string name_str("test") ;
|
if(cert_id == *it)
|
||||||
std::string passw_str("test00") ;
|
found = true ;
|
||||||
|
}
|
||||||
std::cerr << "Now generating a new PGP certificate: " << std::endl;
|
CHECK(found) ;
|
||||||
std::cerr << " email: " << email_str << std::endl;
|
|
||||||
std::cerr << " passw: " << passw_str << std::endl;
|
|
||||||
std::cerr << " name : " << name_str << std::endl;
|
|
||||||
|
|
||||||
PGPIdType newid ;
|
|
||||||
std::string errString ;
|
|
||||||
|
|
||||||
if(!pgph.GeneratePGPCertificate(name_str, email_str, passw_str, newid, errString))
|
|
||||||
std::cerr << "Generation of certificate returned error: " << errString << std::endl;
|
|
||||||
else
|
|
||||||
std::cerr << "Certificate generation success. New id = " << newid.toStdString() << std::endl;
|
|
||||||
return 0 ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(test_output)
|
if(full_test || test_output)
|
||||||
{
|
{
|
||||||
PGPIdType id2( (key_id_string.empty())?askForKeyId(pgph):key_id_string) ;
|
PGPIdType id2( (key_id_string.empty())?askForKeyId(pgph):key_id_string) ;
|
||||||
|
|
||||||
|
@ -197,8 +225,9 @@ int main(int argc,char *argv[])
|
||||||
|
|
||||||
std::cerr << "Loaded cert id: " << id3.toStdString() << ", Error string=\"" << error_string << "\"" << std::endl;
|
std::cerr << "Loaded cert id: " << id3.toStdString() << ", Error string=\"" << error_string << "\"" << std::endl;
|
||||||
|
|
||||||
|
CHECK(id3 == id2) ;
|
||||||
|
|
||||||
std::cerr << cert << std::endl;
|
std::cerr << cert << std::endl;
|
||||||
return 0 ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(test_passphrase_callback)
|
if(test_passphrase_callback)
|
||||||
|
@ -207,10 +236,9 @@ int main(int argc,char *argv[])
|
||||||
std::string newid = "XXXXXXXXXXXXXXXX" ;
|
std::string newid = "XXXXXXXXXXXXXXXX" ;
|
||||||
std::string pass = passphrase_callback(NULL,newid.c_str(),"Please enter password: ",false) ;
|
std::string pass = passphrase_callback(NULL,newid.c_str(),"Please enter password: ",false) ;
|
||||||
std::cerr << "Password = \"" << pass << "\"" << std::endl;
|
std::cerr << "Password = \"" << pass << "\"" << std::endl;
|
||||||
return 0 ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(test_signature)
|
if(full_test || test_signature)
|
||||||
{
|
{
|
||||||
if(key_id_string.empty())
|
if(key_id_string.empty())
|
||||||
key_id_string = askForKeyId(pgph) ;
|
key_id_string = askForKeyId(pgph) ;
|
||||||
|
@ -228,7 +256,11 @@ int main(int argc,char *argv[])
|
||||||
unsigned char sign[1000] ;
|
unsigned char sign[1000] ;
|
||||||
uint32_t signlen = 1000 ;
|
uint32_t signlen = 1000 ;
|
||||||
|
|
||||||
if(!pgph.SignDataBin(key_id,test_bin,BUFF_LEN,sign,&signlen))
|
bool res = pgph.SignDataBin(key_id,test_bin,BUFF_LEN,sign,&signlen) ;
|
||||||
|
|
||||||
|
CHECK(res) ;
|
||||||
|
|
||||||
|
if(!res)
|
||||||
std::cerr << "Signature error." << std::endl;
|
std::cerr << "Signature error." << std::endl;
|
||||||
else
|
else
|
||||||
std::cerr << "Signature success." << std::endl;
|
std::cerr << "Signature success." << std::endl;
|
||||||
|
@ -238,10 +270,17 @@ int main(int argc,char *argv[])
|
||||||
std::cerr << "Now verifying signature..." << std::endl;
|
std::cerr << "Now verifying signature..." << std::endl;
|
||||||
|
|
||||||
PGPFingerprintType fingerprint ;
|
PGPFingerprintType fingerprint ;
|
||||||
if(!pgph.getKeyFingerprint(key_id,fingerprint) )
|
res = pgph.getKeyFingerprint(key_id,fingerprint);
|
||||||
|
|
||||||
|
CHECK(res) ;
|
||||||
|
|
||||||
|
if(!res)
|
||||||
std::cerr << "Cannot find fingerprint of key id " << key_id.toStdString() << std::endl;
|
std::cerr << "Cannot find fingerprint of key id " << key_id.toStdString() << std::endl;
|
||||||
|
|
||||||
if(!pgph.VerifySignBin(test_bin,BUFF_LEN,sign,signlen,fingerprint))
|
res = pgph.VerifySignBin(test_bin,BUFF_LEN,sign,signlen,fingerprint) ;
|
||||||
|
CHECK(res) ;
|
||||||
|
|
||||||
|
if(!res)
|
||||||
std::cerr << "Signature verification failed." << std::endl;
|
std::cerr << "Signature verification failed." << std::endl;
|
||||||
else
|
else
|
||||||
std::cerr << "Signature verification worked!" << std::endl;
|
std::cerr << "Signature verification worked!" << std::endl;
|
||||||
|
@ -249,7 +288,7 @@ int main(int argc,char *argv[])
|
||||||
delete[] test_bin ;
|
delete[] test_bin ;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(test_file_encryption)
|
if(full_test || test_file_encryption)
|
||||||
{
|
{
|
||||||
if(key_id_string.empty())
|
if(key_id_string.empty())
|
||||||
key_id_string = askForKeyId(pgph) ;
|
key_id_string = askForKeyId(pgph) ;
|
||||||
|
@ -260,7 +299,11 @@ int main(int argc,char *argv[])
|
||||||
|
|
||||||
std::cerr << "Checking encrypted file creation: streaming chain \"" << text_to_encrypt << "\" to file " << outfile << " with key " << key_id.toStdString() << std::endl;
|
std::cerr << "Checking encrypted file creation: streaming chain \"" << text_to_encrypt << "\" to file " << outfile << " with key " << key_id.toStdString() << std::endl;
|
||||||
|
|
||||||
if(!pgph.encryptTextToFile(key_id,text_to_encrypt,outfile))
|
bool res = pgph.encryptTextToFile(key_id,text_to_encrypt,outfile) ;
|
||||||
|
|
||||||
|
CHECK(res) ;
|
||||||
|
|
||||||
|
if(!res)
|
||||||
std::cerr << "Encryption failed" << std::endl;
|
std::cerr << "Encryption failed" << std::endl;
|
||||||
else
|
else
|
||||||
std::cerr << "Encryption success" << std::endl;
|
std::cerr << "Encryption success" << std::endl;
|
||||||
|
@ -268,15 +311,21 @@ int main(int argc,char *argv[])
|
||||||
std::string decrypted_text = "" ;
|
std::string decrypted_text = "" ;
|
||||||
outfile = "crypted_toto.pgp" ;
|
outfile = "crypted_toto.pgp" ;
|
||||||
|
|
||||||
if(!pgph.decryptTextFromFile(key_id,decrypted_text,outfile))
|
res = pgph.decryptTextFromFile(key_id,decrypted_text,outfile) ;
|
||||||
|
|
||||||
|
CHECK(res) ;
|
||||||
|
|
||||||
|
if(!res)
|
||||||
std::cerr << "Decryption failed" << std::endl;
|
std::cerr << "Decryption failed" << std::endl;
|
||||||
else
|
else
|
||||||
std::cerr << "Decryption success" << std::endl;
|
std::cerr << "Decryption success" << std::endl;
|
||||||
|
|
||||||
std::cerr << "Decrypted text: \"" << decrypted_text << "\"" << std::endl;
|
std::cerr << "Decrypted text: \"" << decrypted_text << "\"" << std::endl;
|
||||||
return 0 ;
|
|
||||||
|
CHECK(decrypted_text == text_to_encrypt) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0 ;
|
FINALREPORT("PGP Handler test") ;
|
||||||
|
return TESTRESULT() ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
4
libretroshare/src/tests/pgp/test_pgp_handler.sh
Normal file
4
libretroshare/src/tests/pgp/test_pgp_handler.sh
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
./test_pgp_handler -F
|
||||||
|
|
|
@ -3,8 +3,11 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <util/utest.h>
|
||||||
#include <pgp/pgphandler.h>
|
#include <pgp/pgphandler.h>
|
||||||
|
|
||||||
|
INITTEST() ;
|
||||||
|
|
||||||
static std::string passphrase_callback(void *data,const char *uid_info,const char *what,int prev_was_bad)
|
static std::string passphrase_callback(void *data,const char *uid_info,const char *what,int prev_was_bad)
|
||||||
{
|
{
|
||||||
return std::string(getpass(what)) ;
|
return std::string(getpass(what)) ;
|
||||||
|
@ -46,5 +49,9 @@ int main(int argc,char *argv[])
|
||||||
PGPHandler pgph(pubring,secring,trustdb,lockfil) ;
|
PGPHandler pgph(pubring,secring,trustdb,lockfil) ;
|
||||||
|
|
||||||
pgph.printKeys() ;
|
pgph.printKeys() ;
|
||||||
|
|
||||||
|
FINALREPORT("Signature parsing") ;
|
||||||
|
|
||||||
|
return TESTRESULT() ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
BIN
libretroshare/src/tests/pgp/test_pubring.gpg
Normal file
BIN
libretroshare/src/tests/pgp/test_pubring.gpg
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue