summaryrefslogtreecommitdiffstats
path: root/common/resourceaccess.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2017-09-18 11:40:41 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2017-09-18 11:40:45 +0200
commita7e7f7fdd2a9d38921476d57f305c9cd4459a556 (patch)
treed9ad3bdc3e275004a54f508025f0d52227ab18cb /common/resourceaccess.cpp
parentea2e02ad656640c17d520b5a22c168c3c1faef56 (diff)
downloadsink-a7e7f7fdd2a9d38921476d57f305c9cd4459a556.tar.gz
sink-a7e7f7fdd2a9d38921476d57f305c9cd4459a556.zip
Avoid storing the password in the configuration
The password (or any other secret), is now cached in the client process (in-memory only), and delivered to the resource via command. The resource avoids doing any operations against the source until the secret is available.
Diffstat (limited to 'common/resourceaccess.cpp')
-rw-r--r--common/resourceaccess.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/common/resourceaccess.cpp b/common/resourceaccess.cpp
index 35fa46c..5ed3609 100644
--- a/common/resourceaccess.cpp
+++ b/common/resourceaccess.cpp
@@ -32,9 +32,11 @@
32#include "common/revisionreplayed_generated.h" 32#include "common/revisionreplayed_generated.h"
33#include "common/inspection_generated.h" 33#include "common/inspection_generated.h"
34#include "common/flush_generated.h" 34#include "common/flush_generated.h"
35#include "common/secret_generated.h"
35#include "common/entitybuffer.h" 36#include "common/entitybuffer.h"
36#include "common/bufferutils.h" 37#include "common/bufferutils.h"
37#include "common/test.h" 38#include "common/test.h"
39#include "common/secretstore.h"
38#include "log.h" 40#include "log.h"
39 41
40#include <QCoreApplication> 42#include <QCoreApplication>
@@ -234,6 +236,12 @@ ResourceAccess::ResourceAccess(const QByteArray &resourceInstanceIdentifier, con
234{ 236{
235 mResourceStatus = Sink::ApplicationDomain::NoStatus; 237 mResourceStatus = Sink::ApplicationDomain::NoStatus;
236 SinkTrace() << "Starting access"; 238 SinkTrace() << "Starting access";
239
240 QObject::connect(&SecretStore::instance(), &SecretStore::secretAvailable, this, [this] (const QByteArray &resourceId) {
241 if (resourceId == d->resourceInstanceIdentifier) {
242 sendSecret(SecretStore::instance().resourceSecret(d->resourceInstanceIdentifier)).exec();
243 }
244 });
237} 245}
238 246
239ResourceAccess::~ResourceAccess() 247ResourceAccess::~ResourceAccess()
@@ -387,6 +395,15 @@ KAsync::Job<void> ResourceAccess::sendFlushCommand(int flushType, const QByteArr
387 return sendCommand(Sink::Commands::FlushCommand, fbb); 395 return sendCommand(Sink::Commands::FlushCommand, fbb);
388} 396}
389 397
398KAsync::Job<void> ResourceAccess::sendSecret(const QString &secret)
399{
400 flatbuffers::FlatBufferBuilder fbb;
401 auto s = fbb.CreateString(secret.toStdString());
402 auto location = Sink::Commands::CreateSecret(fbb, s);
403 Sink::Commands::FinishSecretBuffer(fbb, location);
404 return sendCommand(Sink::Commands::SecretCommand, fbb);
405}
406
390void ResourceAccess::open() 407void ResourceAccess::open()
391{ 408{
392 if (d->socket && d->socket->isValid()) { 409 if (d->socket && d->socket->isValid()) {
@@ -483,6 +500,11 @@ void ResourceAccess::connected()
483 Commands::write(d->socket.data(), ++d->messageId, Commands::HandshakeCommand, fbb); 500 Commands::write(d->socket.data(), ++d->messageId, Commands::HandshakeCommand, fbb);
484 } 501 }
485 502
503 auto secret = SecretStore::instance().resourceSecret(d->resourceInstanceIdentifier);
504 if (!secret.isEmpty()) {
505 sendSecret(secret).exec();
506 }
507
486 // Reenqueue pending commands, we failed to send them 508 // Reenqueue pending commands, we failed to send them
487 processPendingCommandQueue(); 509 processPendingCommandQueue();
488 // Send queued commands 510 // Send queued commands