mirror of
https://github.com/amnezia-vpn/amnezia-client.git
synced 2026-06-23 02:00:20 +07:00
Secure settings rework
This commit is contained in:
@@ -35,58 +35,3 @@ void MobileUtils::shareText(const QStringList& filesToSend) {
|
||||
}
|
||||
}
|
||||
|
||||
bool MobileUtils::deleteFromKeychain(const QString& tag) {
|
||||
NSData* nsTag = [tag.toNSString() dataUsingEncoding:NSUTF8StringEncoding];
|
||||
|
||||
NSDictionary *deleteQuery = @{ (id)kSecAttrAccount: nsTag,
|
||||
(id)kSecClass: (id)kSecClassGenericPassword,
|
||||
};
|
||||
|
||||
OSStatus status = SecItemDelete((__bridge CFDictionaryRef)deleteQuery);
|
||||
if (status != errSecSuccess) {
|
||||
qDebug() << "Error deleteFromKeychain" << status;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void MobileUtils::writeToKeychain(const QString& tag, const QByteArray& value) {
|
||||
deleteFromKeychain(tag);
|
||||
|
||||
NSData* nsTag = [tag.toNSString() dataUsingEncoding:NSUTF8StringEncoding];
|
||||
NSData* nsValue = value.toNSData();
|
||||
|
||||
NSDictionary* addQuery = @{ (id)kSecAttrAccount: nsTag,
|
||||
(id)kSecClass: (id)kSecClassGenericPassword,
|
||||
(id)kSecValueData: nsValue,
|
||||
};
|
||||
|
||||
OSStatus status = SecItemAdd((__bridge CFDictionaryRef)addQuery, NULL);
|
||||
if (status != errSecSuccess) {
|
||||
qDebug() << "Error writeToKeychain" << status;
|
||||
}
|
||||
}
|
||||
|
||||
QByteArray MobileUtils::readFromKeychain(const QString& tag) {
|
||||
NSData* nsTag = [tag.toNSString() dataUsingEncoding:NSUTF8StringEncoding];
|
||||
NSData* nsValue = NULL;
|
||||
|
||||
NSDictionary *getQuery = @{ (id)kSecAttrAccount: nsTag,
|
||||
(id)kSecClass: (id)kSecClassGenericPassword,
|
||||
(id)kSecMatchLimit: (id)kSecMatchLimitOne,
|
||||
(id)kSecReturnData: @YES,
|
||||
};
|
||||
|
||||
OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef)getQuery,
|
||||
(CFTypeRef *)&nsValue);
|
||||
if (status != errSecSuccess) {
|
||||
qDebug() << "Error readFromKeychain" << status;
|
||||
}
|
||||
|
||||
QByteArray result;
|
||||
if (nsValue) {
|
||||
result = QByteArray::fromNSData(nsValue);
|
||||
CFRelease(nsValue);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user