19 #include <boost/test/unit_test.hpp> 20 #include <boost/filesystem.hpp> 34 namespace fs = boost::filesystem;
36 BOOST_AUTO_TEST_SUITE(Crypto)
44 testPath +=
"/KeyStoreTests";
46 cnote <<
"Testing Key Store...";
49 BOOST_REQUIRE_MESSAGE(s.length() > 0,
"Contents of 'KeyStoreTests/basic_tests.json' is empty. Have you cloned the 'tests' repo branch develop?");
58 cdebug <<
"read uuid" << u;
59 bytesSec s = store.secret(u, [&](){
return o[
"password"].get_str(); });
70 string importFile = importDir.
path() +
"/import.json";
75 "ciphertext": "d69313b6470ac1942f75d72ebf8818a0d484ac78478a132ee081cd954d6bd7a9", 76 "cipherparams": { "iv": "ffffffffffffffffffffffffffffffff" }, 78 "kdfparams": { "dklen": 32, "c": 262144, "prf": "hmac-sha256", "salt": "c82ef14476014cbf438081a42709e2ed" }, 79 "mac": "cf6bfbcc77142a22c4a908784b4a16f1023a1d0e2aff404c20158fa4f1587177", 80 "cipher": "aes-128-ctr", 83 "id": "abb67040-8dbe-0dad-fc39-2b082ef0ee5f" 85 string password =
"bar";
86 string priv =
"0202020202020202020202020202020202020202020202020202020202020202";
93 uuid = store.importKey(importFile);
99 fs::remove(importFile);
110 for (
string const& password: {
"foobar",
""})
113 string priv =
"0202020202020202020202020202020202020202020202020202020202020202";
134 for (
string const& password: {
"foobar",
""})
137 string priv =
"0202020202020202020202020202020202020202020202020202020202020202";
144 uuid = store.importSecret(&privateBytes, password);
161 string password =
"foobar";
162 string priv =
"0202020202020202020202020202020202020202020202020202020202020202";
178 BOOST_CHECK(store.secret(uuid, [&](){ return
"abcdefg"; }).empty());
186 string password =
"foobar";
187 string changedPassword =
"abcdefg";
188 string priv =
"0202020202020202020202020202020202020202020202020202020202020202";
202 BOOST_CHECK(store.secret(uuid, [&](){ return
"abcdefg"; }).empty());
203 BOOST_CHECK(store.recode(uuid, changedPassword, [&](){ return password; }));
207 BOOST_CHECK(store.secret(uuid, [&](){ return password; }).empty());
213 BOOST_CHECK(store.secret(uuid, [&](){ return password; }).empty());
const Object & get_obj() const
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
std::string toHex(T const &_data, int _w=2, HexPrefix _prefix=HexPrefix::DontAdd)
void writeFile(std::string const &_file, bytesConstRef _data, bool _writeDeleteRename=false)
Write the given binary data into the given file, replacing the file if it pre-exists.
secure_vector< byte > bytesSec
std::hash for asio::adress
std::string contentsString(std::string const &_file)
Retrieve and returns the contents of the given file as a std::string.
std::vector< T > const & makeInsecure() const
bytes fromHex(std::string const &_s, WhenError _throw=WhenError::DontThrow)
bool read_string(const String_type &s, Value_type &value)
std::vector< byte > bytes
std::string getTestPath()
Fixed-size raw-byte array container type, with an API optimised for storing hashes.
mConfig::Object_type mObject
Value_type::String_type write_string(const Value_type &value, bool pretty)
#define BOOST_FIXTURE_TEST_SUITE(a, b)
std::string const & path() const
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_AUTO_TEST_SUITE_END()
Manages encrypted keys stored in a certain directory on disk.
BOOST_AUTO_TEST_CASE(basic_tests)
std::string get_str(std::string::const_iterator begin, std::string::const_iterator end)
temporary directory implementation It creates temporary directory in the given path.
Helper functions to work with json::spirit and test files.
#define BOOST_CHECK(expr)