row editing

This commit is contained in:
Mark Gregory
2026-10-21 11:43:43 +01:00
parent 1d8e8702a8
commit face625f23
2 changed files with 68 additions and 6 deletions
+42 -6
View File
@@ -74,17 +74,53 @@ enum PasswordStore {
return "" return ""
} }
static func save(_ password: String, id: UUID) { @discardableResult
static func save(_ password: String, id: UUID) -> Bool {
let query: [String: Any] = [ let query: [String: Any] = [
kSecClass as String: kSecClassGenericPassword, kSecClass as String: kSecClassGenericPassword,
kSecAttrService as String: service, kSecAttrService as String: service,
kSecAttrAccount as String: id.uuidString kSecAttrAccount as String: id.uuidString
] ]
SecItemDelete(query as CFDictionary)
guard !password.isEmpty else { return } if password.isEmpty {
var attributes = query let status = SecItemDelete(query as CFDictionary)
attributes[kSecValueData as String] = Data(password.utf8) return status == errSecSuccess || status == errSecItemNotFound
SecItemAdd(attributes as CFDictionary, nil) }
let data = Data(password.utf8)
let update: [String: Any] = [
kSecValueData as String: data
]
let updateStatus = SecItemUpdate(
query as CFDictionary,
update as CFDictionary
)
if updateStatus == errSecSuccess {
return true
}
if updateStatus == errSecItemNotFound {
var attributes = query
attributes[kSecValueData as String] = data
let addStatus = SecItemAdd(
attributes as CFDictionary,
nil
)
if addStatus == errSecSuccess {
return true
}
NSLog("DBSyn Keychain add failed: %d", addStatus)
return false
}
NSLog("DBSyn Keychain update failed: %d", updateStatus)
return false
} }
static func delete(_ id: UUID) { static func delete(_ id: UUID) {
+26
View File
@@ -422,6 +422,13 @@ final class MySQLWireConnection {
) )
} }
let plugin = (try? c.nulString()) ?? "mysql_native_password" let plugin = (try? c.nulString()) ?? "mysql_native_password"
NSLog(
"DBSyn MySQL authentication: plugin=%@ saltLength=%d tlsRequired=%@",
plugin,
salt.count,
requireTLS ? "YES" : "NO"
)
if requireTLS { if requireTLS {
let clientSSL = 0x00000800 let clientSSL = 0x00000800
guard capabilities & clientSSL != 0 else { guard capabilities & clientSSL != 0 else {
@@ -443,6 +450,13 @@ final class MySQLWireConnection {
body += Array(plugin.utf8) + [0] body += Array(plugin.utf8) + [0]
try send(body) try send(body)
var reply = try readPacket() var reply = try readPacket()
NSLog(
"DBSyn MySQL initial authentication response: type=0x%02X length=%d",
Int(reply.first ?? 0),
reply.count
)
try checkError(reply) try checkError(reply)
var currentPlugin = plugin var currentPlugin = plugin
var currentSalt = Array(salt) var currentSalt = Array(salt)
@@ -461,6 +475,12 @@ final class MySQLWireConnection {
guard currentPlugin == "caching_sha2_password", reply.count >= 2 else { guard currentPlugin == "caching_sha2_password", reply.count >= 2 else {
throw MySQLWireError(message: "Unsupported authentication continuation") throw MySQLWireError(message: "Unsupported authentication continuation")
} }
NSLog(
"DBSyn MySQL authentication continuation: code=0x%02X TLS=%@",
Int(reply[1]),
tlsActive ? "YES" : "NO"
)
switch reply[1] { switch reply[1] {
case 0x03: // Fast authentication accepted; wait for OK. case 0x03: // Fast authentication accepted; wait for OK.
reply = try readPacket() reply = try readPacket()
@@ -496,6 +516,12 @@ final class MySQLWireConnection {
throw MySQLWireError(message: "Unsupported caching_sha2_password response: \(reply[1])") throw MySQLWireError(message: "Unsupported caching_sha2_password response: \(reply[1])")
} }
} }
NSLog(
"DBSyn MySQL final authentication response: type=0x%02X length=%d",
Int(reply.first ?? 0),
reply.count
)
try checkError(reply) try checkError(reply)
guard reply.first == 0x00 else { throw MySQLWireError(message: "Authentication did not complete") } guard reply.first == 0x00 else { throw MySQLWireError(message: "Authentication did not complete") }
if !database.isEmpty { _ = try query("USE `\(database.replacingOccurrences(of: "`", with: "``"))`") } if !database.isEmpty { _ = try query("USE `\(database.replacingOccurrences(of: "`", with: "``"))`") }