From 6543d713e4fdf2c3891b499e45e298a6784f312e Mon Sep 17 00:00:00 2001 From: Gioacchino Mazzurco Date: Sun, 21 Oct 2018 17:12:13 +0200 Subject: [PATCH] JSON API import/export PGP key to file --- libresapi/src/api/RsControlModule.cpp | 2 +- libretroshare/src/retroshare/rsinit.h | 25 ++++++++++++++++++++---- libretroshare/src/rsserver/rsaccounts.cc | 7 +++++-- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/libresapi/src/api/RsControlModule.cpp b/libresapi/src/api/RsControlModule.cpp index debd3ce34..c5d596ab3 100644 --- a/libresapi/src/api/RsControlModule.cpp +++ b/libresapi/src/api/RsControlModule.cpp @@ -449,7 +449,7 @@ void RsControlModule::handleImportPgp(Request &req, Response &resp) RsPgpId pgp_id; std::string error_string; - if(RsAccounts::ImportIdentityFromString(key_string, pgp_id, error_string)) + if(RsAccounts::importIdentityFromString(key_string, pgp_id, error_string)) { resp.mDataStream << makeKeyValueReference("pgp_id", pgp_id); resp.setOk(); diff --git a/libretroshare/src/retroshare/rsinit.h b/libretroshare/src/retroshare/rsinit.h index f81bfaddf..3d51eff01 100644 --- a/libretroshare/src/retroshare/rsinit.h +++ b/libretroshare/src/retroshare/rsinit.h @@ -176,9 +176,26 @@ public: static int GetPGPLoginDetails(const RsPgpId& id, std::string &name, std::string &email); static bool GeneratePGPCertificate(const std::string&, const std::string& email, const std::string& passwd, RsPgpId &pgpId, const int keynumbits, std::string &errString); - // PGP Support Functions. - static bool ExportIdentity(const std::string& fname,const RsPgpId& pgp_id) ; - static bool ImportIdentity(const std::string& fname,RsPgpId& imported_pgp_id,std::string& import_error) ; + /** + * @brief Export full encrypted PGP identity to file + * @jsonapi{development} + * @param[in] filePath path of certificate file + * @param[in] pgpId PGP id to export + * @return true on success, false otherwise + */ + static bool ExportIdentity( const std::string& filePath, + const RsPgpId& pgpId ); + + /** + * @brief Import full encrypted PGP identity from file + * @jsonapi{development,unauthenticated} + * @param[in] filePath path of certificate file + * @param[out] pgpId storage for the PGP fingerprint of the imported key + * @param[out] errorMsg storage for eventual human readable error message + * @return true on success, false otherwise + */ + static bool ImportIdentity( + const std::string& filePath, RsPgpId& pgpId, std::string& errorMsg ); /** * @brief Import full encrypted PGP identity from string @@ -188,7 +205,7 @@ public: * @param[out] errorMsg storage for eventual human readable error message * @return true on success, false otherwise */ - static bool ImportIdentityFromString( + static bool importIdentityFromString( const std::string& data, RsPgpId& pgpId, std::string& errorMsg ); diff --git a/libretroshare/src/rsserver/rsaccounts.cc b/libretroshare/src/rsserver/rsaccounts.cc index 17ab2d8cc..1203a63a2 100644 --- a/libretroshare/src/rsserver/rsaccounts.cc +++ b/libretroshare/src/rsserver/rsaccounts.cc @@ -1347,9 +1347,12 @@ bool RsAccounts::ImportIdentity(const std::string& fname,RsPgpId& imported_pg return rsAccountsDetails->importIdentity(fname,imported_pgp_id,import_error); } -bool RsAccounts::ImportIdentityFromString(const std::string& data,RsPgpId& imported_pgp_id,std::string& import_error) +bool RsAccounts::importIdentityFromString( + const std::string& data, RsPgpId& imported_pgp_id, + std::string& import_error ) { - return rsAccountsDetails->importIdentityFromString(data,imported_pgp_id,import_error); + return rsAccountsDetails-> + importIdentityFromString(data, imported_pgp_id, import_error); } /*static*/ bool RsAccounts::exportIdentityToString(