parent
5239909668
commit
ba79a12cd8
|
@ -47,16 +47,34 @@ class InstallCACommand: Command {
|
|||
func run() throws {
|
||||
let url = URL(fileURLWithPath: options.path!)
|
||||
let certificate = try Certificate.load(from: url)
|
||||
let sha1 = certificate.sha1
|
||||
|
||||
let certificateName = certificate.subjectSummary ?? "<unknown certificate>"
|
||||
|
||||
for device in try Simctl.flatListDevices().filter(using: filteringOptions) {
|
||||
let trustStore = TrustStore(uuid: device.udid)
|
||||
if !trustStore.exists && options.dryRun {
|
||||
print("Would install '\(certificateName)' into '\(device.name)'.")
|
||||
continue
|
||||
}
|
||||
|
||||
let connection = try trustStore.open()
|
||||
if try connection.hasCertificate(with: sha1) {
|
||||
if options.dryRun {
|
||||
print("Would skip installing '\(certificateName)' into '\(device.name)' – it's already there.")
|
||||
} else {
|
||||
print("Not installing '\(certificateName)' into '\(device.name)' – it's already there.")
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
if options.dryRun {
|
||||
print("Would install \(certificateName) into \(device.name).")
|
||||
print("Would install '\(certificateName)' into '\(device.name)'.")
|
||||
} else {
|
||||
print("Installing \(certificateName) into \(device.name).")
|
||||
let trustStore = TrustStore(uuid: device.udid)
|
||||
print("Installing '\(certificateName)' into '\(device.name)'.")
|
||||
try trustStore.open().addCertificate(certificate)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -41,6 +41,10 @@ struct Certificate {
|
|||
return SecCertificateCopySubjectSummary(certificate) as String?
|
||||
}
|
||||
|
||||
var sha1: Data {
|
||||
return Digest.sha1(data)
|
||||
}
|
||||
|
||||
func normalizedSubjectSequence() throws -> Data {
|
||||
var error: Unmanaged<CFError>?
|
||||
guard let data = SecCertificateCopyNormalizedSubjectContent(certificate, &error) else {
|
||||
|
|
|
@ -85,5 +85,9 @@ struct TrustStore {
|
|||
)
|
||||
try connection.run(insert)
|
||||
}
|
||||
|
||||
func hasCertificate(with sha1: Data) throws -> Bool {
|
||||
return try connection.pluck(tsettings.where(sha1Column == sha1.datatypeValue)) != nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue