mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
added test program for identity import
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6926 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
e2384724c3
commit
214375ede1
@ -11,8 +11,8 @@ OPENPGP_INCLUDE_DIR = ../../../../openpgpsdk/src
|
||||
include $(RS_TOP_DIR)/tests/scripts/config.mk
|
||||
###############################################################
|
||||
|
||||
TESTOBJ = test_pgp_handler.o test_pgp_signature_parsing.o test_key_parsing.o test_certificate.o
|
||||
TESTS = test_pgp_handler test_pgp_signature_parsing test_key_parsing test_certificate
|
||||
TESTOBJ = test_pgp_handler.o test_pgp_signature_parsing.o test_key_parsing.o test_certificate.o test_identity_import.o
|
||||
TESTS = test_pgp_handler test_pgp_signature_parsing test_key_parsing test_certificate test_identity_import
|
||||
|
||||
#rsbaseitem_test
|
||||
|
||||
@ -21,6 +21,9 @@ all: tests
|
||||
test_certificate : test_certificate.o
|
||||
$(CC) $(CFLAGS) -o test_certificate test_certificate.o $(OBJ) $(LIBS) -L../../../../openpgpsdk/src/lib/ -lops -lbz2
|
||||
|
||||
test_identity_import : test_identity_import.o
|
||||
$(CC) $(CFLAGS) -o test_identity_import test_identity_import.o $(OBJ) $(LIBS) -L../../../../openpgpsdk/src/lib/ -lops -lbz2
|
||||
|
||||
test_pgp_handler : test_pgp_handler.o
|
||||
$(CC) $(CFLAGS) -o test_pgp_handler test_pgp_handler.o $(OBJ) $(LIBS) -L../../../../openpgpsdk/src/lib/ -lops -lbz2
|
||||
|
||||
|
@ -10,6 +10,18 @@
|
||||
|
||||
INITTEST() ;
|
||||
|
||||
static std::string pgp_pwd_cb(void * /*hook*/, const char *uid_hint, const char * /*passphrase_info*/, int prev_was_bad)
|
||||
{
|
||||
#define GPG_DEBUG2
|
||||
#ifdef GPG_DEBUG2
|
||||
fprintf(stderr, "pgp_pwd_callback() called.\n");
|
||||
#endif
|
||||
std::string password;
|
||||
|
||||
std::cerr << "SHould not be called!" << std::endl;
|
||||
return password ;
|
||||
}
|
||||
|
||||
int main(int argc,char *argv[])
|
||||
{
|
||||
try
|
||||
@ -95,6 +107,25 @@ int main(int argc,char *argv[])
|
||||
}
|
||||
CHECK(found) ;
|
||||
|
||||
// try to load the certificate.
|
||||
|
||||
std::cerr << "Checking that the certificate is imported correctly" << std::endl;
|
||||
|
||||
std::string error_string ;
|
||||
PGPIdType found_id ;
|
||||
|
||||
PGPHandler::setPassphraseCallback(pgp_pwd_cb) ;
|
||||
PGPHandler pgph("pubring.pgp","secring.pgp","trustdb.pgp","lock") ;
|
||||
|
||||
bool result = pgph.LoadCertificateFromString(res,found_id,error_string) ;
|
||||
|
||||
if(!result)
|
||||
std::cerr << "Certificate error: " << error_string << std::endl;
|
||||
else
|
||||
std::cerr << "Certificate loaded correctly. Id = " << found_id.toStdString() << std::endl;
|
||||
|
||||
CHECK(result) ;
|
||||
|
||||
FINALREPORT("Test certificate parsing") ;
|
||||
|
||||
return TESTRESULT();
|
||||
|
56
libretroshare/src/tests/pgp/test_identity_import.c
Normal file
56
libretroshare/src/tests/pgp/test_identity_import.c
Normal file
@ -0,0 +1,56 @@
|
||||
#include <fstream>
|
||||
#include <string.h>
|
||||
|
||||
#include <util/utest.h>
|
||||
#include <util/argstream.h>
|
||||
//#include <pqi/cleanupxpgp.h>
|
||||
#include <retroshare/rspeers.h>
|
||||
#include <pgp/rscertificate.h>
|
||||
#include <pgp/pgphandler.h>
|
||||
|
||||
INITTEST() ;
|
||||
|
||||
static std::string pgp_pwd_cb(void * /*hook*/, const char *uid_hint, const char * /*passphrase_info*/, int prev_was_bad)
|
||||
{
|
||||
#define GPG_DEBUG2
|
||||
#ifdef GPG_DEBUG2
|
||||
fprintf(stderr, "pgp_pwd_callback() called.\n");
|
||||
#endif
|
||||
std::string password;
|
||||
|
||||
std::cerr << "SHould not be called!" << std::endl;
|
||||
return password ;
|
||||
}
|
||||
|
||||
int main(int argc,char *argv[])
|
||||
{
|
||||
try
|
||||
{
|
||||
argstream as(argc,argv) ;
|
||||
std::string idfile ;
|
||||
bool clean_cert = false ;
|
||||
|
||||
as >> parameter('i',"input",idfile,"input retroshare identity file, ascii format",true)
|
||||
>> help() ;
|
||||
|
||||
as.defaultErrorHandling() ;
|
||||
|
||||
PGPHandler handler("toto1","toto2","toto3","toto4") ;
|
||||
|
||||
PGPIdType imported_key_id ;
|
||||
std::string import_error_string ;
|
||||
|
||||
bool res = handler.importGPGKeyPair(idfile,imported_key_id,import_error_string) ;
|
||||
|
||||
if(!res)
|
||||
std::cerr << "Identity Import error: " << import_error_string << std::endl;
|
||||
|
||||
CHECK(res) ;
|
||||
}
|
||||
catch(std::exception& e)
|
||||
{
|
||||
std::cerr << "Exception never handled: " << e.what() << std::endl;
|
||||
return 1 ;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user