Skip to content

Commit 4e0017f

Browse files
authored
Refactor SigningInfoProvider and update AboutView
Refactor SigningInfoProvider to improve certificate parsing and error handling. Update AboutView to reflect changes in signing information display.
1 parent 42fcab8 commit 4e0017f

File tree

1 file changed

+30
-13
lines changed

1 file changed

+30
-13
lines changed

Sources/prosign/views/AboutView.swift

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@ import SwiftUI
22
import Security
33
import Foundation
44

5-
let kSecOIDX509V1ValidityNotAfter = "2.5.29.24" as CFString
6-
let kSecPropertyKeyValue = "value" as CFString
7-
let errSecSuccess: OSStatus = 0
8-
95
struct Credit: Identifiable {
106
var id = UUID()
117
var name: String
@@ -118,16 +114,37 @@ final class SigningInfoProvider: ObservableObject {
118114
self.certCommonName = name
119115
}
120116

121-
// Try to get NotAfter (expiry) using SecCertificateCopyValues (available on iOS)
122-
var valuesRef: CFDictionary?
123-
let oids = [kSecOIDX509V1ValidityNotAfter] as CFArray
124-
let status = SecCertificateCopyValues(secCert, oids, &valuesRef)
125-
if status == errSecSuccess, let values = valuesRef as? [String: Any],
126-
let notAfterEntry = values[kSecOIDX509V1ValidityNotAfter as String] as? [String: Any],
127-
let expiry = notAfterEntry[kSecPropertyKeyValue as String] as? Date {
128-
self.certExpiry = expiry
117+
// Parse expiry date from DER data (iOS-compatible method)
118+
guard let decodedString = String(data: der, encoding: .ascii) else {
119+
self.certExpiry = nil
120+
return
121+
}
122+
123+
var notValidBeforeDate = ""
124+
var notValidAfterDate = ""
125+
var foundWWDRCA = false
126+
127+
decodedString.enumerateLines { line, _ in
128+
if foundWWDRCA && (notValidBeforeDate.isEmpty || notValidAfterDate.isEmpty) {
129+
let certificateData = line.prefix(13)
130+
if notValidBeforeDate.isEmpty && !certificateData.isEmpty {
131+
notValidBeforeDate = String(certificateData)
132+
} else if notValidAfterDate.isEmpty && !certificateData.isEmpty {
133+
notValidAfterDate = String(certificateData)
134+
}
135+
}
136+
if line.contains("Apple Worldwide Developer Relations Certification Authority") {
137+
foundWWDRCA = true
138+
}
139+
}
140+
141+
let formatter = DateFormatter()
142+
formatter.dateFormat = "yyMMddHHmmss'Z'"
143+
formatter.timeZone = TimeZone(secondsFromGMT: 0) // UTC
144+
145+
if let notAfter = formatter.date(from: notValidAfterDate) {
146+
self.certExpiry = notAfter
129147
} else {
130-
// If SecCertificateCopyValues didn't return a Date (rare), leave nil.
131148
self.certExpiry = nil
132149
}
133150
}

0 commit comments

Comments
 (0)