Make “remove-ca” command work

This commit is contained in:
Simon Kågedal Reimer 2019-05-30 17:14:56 +02:00
parent ef3c94f6bc
commit eb5032ad6f
2 changed files with 10 additions and 3 deletions

View File

@ -46,13 +46,15 @@ class RemoveCACommand: Command {
} }
private func removeCertificates(in trustStore: TrustStore, deviceName: String, dry: Bool) throws { private func removeCertificates(in trustStore: TrustStore, deviceName: String, dry: Bool) throws {
for row in try trustStore.open().rows() { let connection = try trustStore.open()
for row in try connection.rows() {
let certificate = try row.validatedCertificate() let certificate = try row.validatedCertificate()
let name = certificate.subjectSummary ?? "<unknown certificate>" let name = certificate.subjectSummary ?? "<unknown certificate>"
if dry { if dry {
print(" - Would remove certificate \(name) from \(deviceName)") print("Would remove certificate \(name) from \(deviceName).")
} else { } else {
print(" - REMOVING certificate \(name) from \(deviceName)") print("Removing certificate \(name) from \(deviceName).")
try connection.removeCertificate(with: row.sha1)
} }
} }
} }

View File

@ -69,5 +69,10 @@ struct TrustStore {
} }
} }
} }
func removeCertificate(with sha1: Data) throws {
let query: Delete = tsettings.where(sha1Column == sha1.datatypeValue).delete()
try connection.run(query)
}
} }
} }