#include <klay/filesystem.h>
#include <klay/exception.h>
+
#include <rmi/common.h>
+#include <logger.h>
+#include <ode-key-storage-plugin/ode-key-storage-plugin.h>
+
namespace ode {
namespace {
unsigned char* token = NULL;
size_t token_len = 0;
int ret = storeFn(key.data(), key.size(), &token, &token_len);
- if (ret != 0)
+ if (ret != ODE_KSP_ERROR_NONE)
throw runtime::Exception(std::string("Storing the key failed with ") +
std::to_string(ret));
unsigned char* key = NULL;
size_t key_len = 0;
int ret = loadFn(token.data(), token.size(), &key, &key_len);
- if (ret != 0)
+ if (ret != ODE_KSP_ERROR_NONE)
throw runtime::Exception(std::string("Loading the key failed with ") +
std::to_string(ret));
void KeyStoragePlugin::remove(const BinaryData& token)
{
int ret = removeFn(token.data(), token.size());
- if (ret != 0)
+ if (ret == ODE_KSP_ERROR_NO_SUCH_FILE) {
+ INFO(SINK, "Key storage plugin does not recognize the token. Ignoring.");
+ return;
+ }
+ if (ret != ODE_KSP_ERROR_NONE)
throw runtime::Exception(std::string("Removing the key failed with ") +
std::to_string(ret));
}
{
size_t tokenSize;
+ if (!file.exists()) {
+ token.clear();
+ return;
+ }
file.open(O_RDONLY);
file.read(&tokenSize, sizeof(tokenSize));
{
std::lock_guard<std::mutex> lock(opGuard);
- auto& up = KeyStoragePlugin::Instance();
- auto token = up.store(key);
+ BinaryData token;
runtime::File file(getTokenFileName(device));
+ readToken(file, token);
+
+ auto& up = KeyStoragePlugin::Instance();
+
+ // remove previous entry if necessary
+ if (!token.empty())
+ up.remove(token);
+
+ token = up.store(key);
writeToken(file, token);
}
runtime::File file(getTokenFileName(device));
readToken(file, token);
+ if (token.empty())
+ throw runtime::Exception("Token opening failed");
+
auto& up = KeyStoragePlugin::Instance();
return up.load(token);
}
runtime::File file(getTokenFileName(device));
readToken(file, token);
+ // already removed
+ if (token.empty()) {
+ INFO(SINK, "Token for " + device + " does not exist. Ignoring.");
+ return;
+ }
+
auto& up = KeyStoragePlugin::Instance();
up.remove(token);