Secure config WIP
This commit is contained in:
parent
b5890340e3
commit
14384131f4
7 changed files with 83 additions and 28 deletions
|
|
@ -2,5 +2,5 @@
|
|||
|
||||
void MobileUtils::shareText(const QStringList&) {}
|
||||
|
||||
void MobileUtils::writeToKeychain(const QString&, const QString&) {}
|
||||
QString MobileUtils::readFromKeychain(const QString&) { return {}; }
|
||||
void MobileUtils::writeToKeychain(const QString&, const QByteArray &) {}
|
||||
QByteArray MobileUtils::readFromKeychain(const QString&) { return {}; }
|
||||
|
|
|
|||
|
|
@ -13,8 +13,9 @@ public:
|
|||
public slots:
|
||||
static void shareText(const QStringList& filesToSend);
|
||||
|
||||
static void writeToKeychain(const QString& tag, const QString& value);
|
||||
static QString readFromKeychain(const QString& tag);
|
||||
static void writeToKeychain(const QString& tag, const QByteArray& value);
|
||||
static bool deleteFromKeychain(const QString& tag);
|
||||
static QByteArray readFromKeychain(const QString& tag);
|
||||
};
|
||||
|
||||
#endif // MOBILEUTILS_H
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ void MobileUtils::shareText(const QStringList& filesToSend) {
|
|||
}
|
||||
}
|
||||
|
||||
bool deleteFromKeychain(const QString& tag) {
|
||||
bool MobileUtils::deleteFromKeychain(const QString& tag) {
|
||||
NSData* nsTag = [tag.toNSString() dataUsingEncoding:NSUTF8StringEncoding];
|
||||
|
||||
NSDictionary *deleteQuery = @{ (id)kSecAttrAccount: nsTag,
|
||||
|
|
@ -46,17 +46,14 @@ bool deleteFromKeychain(const QString& tag) {
|
|||
if (status != errSecSuccess) {
|
||||
qDebug() << "Error deleteFromKeychain" << status;
|
||||
return false;
|
||||
} else {
|
||||
qDebug() << "OK deleteFromKeychain";
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void MobileUtils::writeToKeychain(const QString& tag, const QString& value) {
|
||||
void MobileUtils::writeToKeychain(const QString& tag, const QByteArray& value) {
|
||||
deleteFromKeychain(tag);
|
||||
|
||||
NSData* nsTag = [tag.toNSString() dataUsingEncoding:NSUTF8StringEncoding];
|
||||
NSData* nsValue = [value.toNSString() dataUsingEncoding:NSUTF8StringEncoding];
|
||||
NSData* nsValue = value.toNSData();
|
||||
|
||||
NSDictionary* addQuery = @{ (id)kSecAttrAccount: nsTag,
|
||||
(id)kSecClass: (id)kSecClassGenericPassword,
|
||||
|
|
@ -66,12 +63,10 @@ void MobileUtils::writeToKeychain(const QString& tag, const QString& value) {
|
|||
OSStatus status = SecItemAdd((__bridge CFDictionaryRef)addQuery, NULL);
|
||||
if (status != errSecSuccess) {
|
||||
qDebug() << "Error writeToKeychain" << status;
|
||||
} else {
|
||||
qDebug() << "OK writeToKeychain";
|
||||
}
|
||||
}
|
||||
|
||||
QString MobileUtils::readFromKeychain(const QString& tag) {
|
||||
QByteArray MobileUtils::readFromKeychain(const QString& tag) {
|
||||
NSData* nsTag = [tag.toNSString() dataUsingEncoding:NSUTF8StringEncoding];
|
||||
NSData* nsValue = NULL;
|
||||
|
||||
|
|
@ -85,11 +80,9 @@ QString MobileUtils::readFromKeychain(const QString& tag) {
|
|||
(CFTypeRef *)&nsValue);
|
||||
if (status != errSecSuccess) {
|
||||
qDebug() << "Error readFromKeychain" << status;
|
||||
} else {
|
||||
qDebug() << "OK readFromKeychain" << nsValue;
|
||||
}
|
||||
|
||||
QString result;
|
||||
QByteArray result;
|
||||
if (nsValue) {
|
||||
result = QByteArray::fromNSData(nsValue);
|
||||
CFRelease(nsValue);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue