[Pkg-owncloud-commits] [qtkeychain] 14/115: basic impl for windows
Sandro Knauß
hefee-guest at moszumanska.debian.org
Sat Mar 15 19:25:42 UTC 2014
This is an automated email from the git hooks/post-receive script.
hefee-guest pushed a commit to branch master
in repository qtkeychain.
commit d6ecb94c8ff39c9d67e463b25ac04f1cffc1ab81
Author: Frank Osterfeld <frank.osterfeld at kdab.com>
Date: Sat Oct 29 01:21:07 2011 +0200
basic impl for windows
---
keychain_p.h | 2 +-
keychain_win.cpp | 104 ++++++++++++++++++++++++++++++++++++++++++++++++-------
lib.pro | 1 +
3 files changed, 93 insertions(+), 14 deletions(-)
diff --git a/keychain_p.h b/keychain_p.h
index fe4c8bb..a130b19 100644
--- a/keychain_p.h
+++ b/keychain_p.h
@@ -17,7 +17,7 @@ namespace QKeychain {
class Keychain::Private {
Q_DECLARE_TR_FUNCTIONS(Keychain::Private)
public:
- explicit Private( const QString& s ) : service( s ) {}
+ explicit Private( const QString& s ) : service( s ), error( NoError ) {}
Keychain::Error writeEntryImpl( const QString& account,
const QByteArray& data,
diff --git a/keychain_win.cpp b/keychain_win.cpp
index 1f8fd5b..102427d 100644
--- a/keychain_win.cpp
+++ b/keychain_win.cpp
@@ -8,42 +8,120 @@
*****************************************************************************/
#include "keychain_p.h"
+#include <QSettings>
+
+#include <Windows.h>
+#include <WinCrypt.h>
+
using namespace QKeychain;
Keychain::Error Keychain::Private::readEntryImpl( QByteArray* pw,
- const QString& account,
+ const QString& key,
QString* err ) {
Q_ASSERT( pw );
Q_ASSERT( err );
err->clear();
- *err = tr("Not implemented");
- return OtherError;
+
+ QSettings settings( service );
+ QByteArray encrypted = settings.value( key ).toByteArray();
+ if ( encrypted.isNull() ) {
+ *err = tr("Entry not found");
+ return EntryNotFound;
+ }
+
+ DATA_BLOB blob_in, blob_out;
+
+ blob_in.pbData = reinterpret_cast<BYTE*>( encrypted.data() );
+ blob_in.cbData = encrypted.size();
+
+ const BOOL ret = CryptUnprotectData( &blob_in,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ 0,
+ &blob_out );
+ if ( !ret ) {
+ *err = tr("Could not decrypt data");
+ return OtherError;
+ }
+ *pw = QByteArray( reinterpret_cast<char*>( blob_out.pbData ), blob_out.cbData );
+ SecureZeroMemory( blob_out.pbData, blob_out.cbData );
+ LocalFree( blob_out.pbData );
+ return NoError;
}
-Keychain::Error Keychain::Private::writeEntryImpl( const QString& account,
- const QByteArray& data,
+Keychain::Error Keychain::Private::writeEntryImpl( const QString& key,
+ const QByteArray& data_,
QString* err ) {
Q_ASSERT( err );
err->clear();
- *err = tr("Not implemented");
- return OtherError;
+ QByteArray data = data_;
+ DATA_BLOB blob_in, blob_out;
+ blob_in.pbData = reinterpret_cast<BYTE*>( data.data() );
+ blob_in.cbData = data.size();
+ const BOOL res = CryptProtectData( &blob_in,
+ L"QKeychain-encrypted data",
+ NULL,
+ NULL,
+ NULL,
+ 0,
+ &blob_out );
+ if ( !res ) {
+ *err = tr("Encryption failed"); //TODO more details available?
+ return OtherError;
+ }
+
+ const QByteArray encrypted( reinterpret_cast<char*>( blob_out.pbData ), blob_out.cbData );
+ LocalFree( blob_out.pbData );
+
+ QSettings settings( service );
+ settings.setValue( key, encrypted );
+ settings.sync();
+ if ( settings.status() != QSettings::NoError ) {
+ *err = settings.status() == QSettings::AccessError
+ ? tr("Could not store encrypted data in settings: access error")
+ : tr("Could not store encrypted data in settings: format error");
+ return OtherError;
+ }
+
+ return NoError;
}
-Keychain::Error Keychain::Private::deleteEntryImpl( const QString& account,
+Keychain::Error Keychain::Private::deleteEntryImpl( const QString& key,
QString* err ) {
Q_ASSERT( err );
err->clear();
- *err = tr("Not implemented");
- return OtherError;
+ QSettings settings( service );
+ settings.remove( key );
+ settings.sync();
+ if ( settings.status() != QSettings::NoError ) {
+ *err = settings.status() == QSettings::AccessError
+ ? tr("Could not delete encrypted data from settings: access error")
+ : tr("Could not delete encrypted data from settings: format error");
+ return OtherError;
+ }
+
+ return NoError;
}
Keychain::Error Keychain::Private::entryExistsImpl( bool* exists,
- const QString& account,
+ const QString& key,
QString* err ) {
Q_ASSERT( exists );
Q_ASSERT( err );
err->clear();
- *err = tr("Not implemented");
- return OtherError;
+ *exists = false;
+ QSettings settings( service );
+ const bool ex = settings.contains( key );
+ if ( settings.status() != QSettings::NoError ) {
+ *err = settings.status() == QSettings::AccessError
+ ? tr("Could not read settings: access error")
+ : tr("Could not read settings: format error");
+ return OtherError;
+ }
+
+ *exists = ex;
+ return NoError;
}
diff --git a/lib.pro b/lib.pro
index ddca34c..4adc2df 100644
--- a/lib.pro
+++ b/lib.pro
@@ -16,5 +16,6 @@ macx {
win32 {
DESTDIR = lib
DLLDESTDIR = lib
+ LIBS += -lCrypt32
SOURCES += keychain_win.cpp
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/qtkeychain.git
More information about the Pkg-owncloud-commits
mailing list