Browse Source

adding key_reset functions0

PYADPT-55
Volker Birk 6 years ago
parent
commit
a0cb1c4860
  1. 8
      src/identity.cc
  2. 2
      src/identity.hh
  3. 51
      src/pEpmodule.cc
  4. 4
      src/pEpmodule.hh

8
src/identity.cc

@ -9,6 +9,7 @@
#include <sstream> #include <sstream>
#include <pEp/identity_list.h> #include <pEp/identity_list.h>
#include <pEp/keymanagement.h> #include <pEp/keymanagement.h>
#include <pEp/key_reset.h>
#include <pEp/message_api.h> #include <pEp/message_api.h>
namespace pEp { namespace pEp {
@ -148,6 +149,13 @@ namespace pEp {
update_identity(*this); update_identity(*this);
} }
void Identity::key_reset(string fpr)
{
PEP_STATUS status = ::key_reset_identity(adapter.session(), *this,
fpr != "" ? fpr.c_str() : nullptr);
_throw_status(status);
}
Myself::Myself(string address, string username, string user_id, string lang) Myself::Myself(string address, string username, string user_id, string lang)
: Identity(address, username, user_id, "", 0, lang) : Identity(address, username, user_id, "", 0, lang)

2
src/identity.hh

@ -63,6 +63,8 @@ namespace pEp {
Identity deepcopy(dict& memo); Identity deepcopy(dict& memo);
virtual void update(); virtual void update();
void key_reset(string fpr="");
}; };
class Myself : public Identity { class Myself : public Identity {

51
src/pEpmodule.cc

@ -13,6 +13,7 @@
#include <mutex> #include <mutex>
#include <pEp/key_reset.h>
#include <pEp/message_api.h> #include <pEp/message_api.h>
#include <pEp/sync_api.h> #include <pEp/sync_api.h>
@ -32,6 +33,27 @@ namespace pEp {
::config_unencrypted_subject(adapter.session(), enable); ::config_unencrypted_subject(adapter.session(), enable);
} }
void key_reset_user(string user_id, string fpr)
{
if (user_id == "")
throw invalid_argument("user_id required");
PEP_STATUS status = ::key_reset_user(adapter.session(),
user_id.c_str(), fpr != "" ? fpr.c_str() : nullptr);
_throw_status(status);
}
void key_reset_user2(string user_id)
{
key_reset_user(user_id, "");
}
void key_reset_all_own_keys()
{
PEP_STATUS status = ::key_reset_all_own_keys(adapter.session());
_throw_status(status);
}
scope *_scope = NULL; scope *_scope = NULL;
static const char *version_string = "p≡p Python adapter version 0.3"; static const char *version_string = "p≡p Python adapter version 0.3";
@ -98,6 +120,23 @@ BOOST_PYTHON_MODULE(pEp)
def("unencrypted_subject", pEp::PythonAdapter::config_unencrypted_subject, def("unencrypted_subject", pEp::PythonAdapter::config_unencrypted_subject,
"do not encrypt the subject of messages"); "do not encrypt the subject of messages");
def("key_reset", pEp::PythonAdapter::key_reset_user,
"reset the default database status for the user / keypair provided\n"
"This will effectively perform key_reset on each identity\n"
"associated with the key and user_id, if a key is provided, and for\n"
"each key (and all of their identities) if an fpr is not.");
def("key_reset", pEp::PythonAdapter::key_reset_user2,
"reset the default database status for the user / keypair provided\n"
"This will effectively perform key_reset on each identity\n"
"associated with the key and user_id, if a key is provided, and for\n"
"each key (and all of their identities) if an fpr is not.");
def("key_reset_all_own_keys", pEp::PythonAdapter::key_reset_all_own_keys,
"revoke and mistrust all own keys, generate new keys for all\n"
"own identities, and opportunistically communicate key reset\n"
"information to people we have recently contacted.");
auto identity_class = class_<pEp::PythonAdapter::Identity>("Identity", auto identity_class = class_<pEp::PythonAdapter::Identity>("Identity",
"Identity(address, username, user_id='', fpr='', comm_type=0, lang='en')\n" "Identity(address, username, user_id='', fpr='', comm_type=0, lang='en')\n"
"\n" "\n"
@ -123,9 +162,17 @@ BOOST_PYTHON_MODULE(pEp)
.def(boost::python::init<string, string, string, string, int, string>()) .def(boost::python::init<string, string, string, string, int, string>())
.def("__repr__", &pEp::PythonAdapter::Identity::_repr) .def("__repr__", &pEp::PythonAdapter::Identity::_repr)
.def("__str__", &pEp::PythonAdapter::Identity::_str, .def("__str__", &pEp::PythonAdapter::Identity::_str,
"string representation of this identity\n" "string representation of this identity\n"
"following the pattern 'username < address >'\n" "following the pattern 'username < address >'\n"
) )
.def("key_reset", &pEp::PythonAdapter::Identity::key_reset,
boost::python::arg("fpr")=object(""),
"reset the default database status for the identity / keypair provided. If this\n"
"corresponds to the own user and a private key, also revoke the key, generate a\n"
"new one, and communicate the reset to recently contacted pEp partners for this\n"
"identity. If it does not, remove the key from the keyring; the key's status is\n"
"completely fresh on next contact from the partner.")
.add_property("address", (string(pEp::PythonAdapter::Identity::*)()) &pEp::PythonAdapter::Identity::address, .add_property("address", (string(pEp::PythonAdapter::Identity::*)()) &pEp::PythonAdapter::Identity::address,
(void(pEp::PythonAdapter::Identity::*)(string)) &pEp::PythonAdapter::Identity::address, (void(pEp::PythonAdapter::Identity::*)(string)) &pEp::PythonAdapter::Identity::address,
"email address or URI") "email address or URI")

4
src/pEpmodule.hh

@ -9,6 +9,10 @@
namespace pEp { namespace pEp {
namespace PythonAdapter { namespace PythonAdapter {
extern string device_name; extern string device_name;
void config_passive_mode(bool enable);
void config_unencrypted_subject(bool enable);
void key_reset_user(string user_id, string fpr);
void key_reset_all_own_keys();
void _throw_status(PEP_STATUS status); void _throw_status(PEP_STATUS status);
void messageToSend(Message msg); void messageToSend(Message msg);
PEP_STATUS _messageToSend(::message *msg); PEP_STATUS _messageToSend(::message *msg);

Loading…
Cancel
Save