Skip to content

Commit

Permalink
Add standardized names to cert viewer.
Browse files Browse the repository at this point in the history
  • Loading branch information
yspreen committed Apr 28, 2021
1 parent 99ea524 commit 7d71733
Show file tree
Hide file tree
Showing 9 changed files with 466 additions and 330 deletions.
20 changes: 12 additions & 8 deletions DGCAVerifier.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
CE157F9B262E2A9F00FE4821 /* SwiftCBOR.CBOR.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE157F9A262E2A9F00FE4821 /* SwiftCBOR.CBOR.swift */; };
CE1BDF99262A4CD600766F97 /* X509.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE1BDF98262A4CD600766F97 /* X509.swift */; };
CE1D1EF6263597A2004C8919 /* LocalData.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE1D1EF5263597A2004C8919 /* LocalData.swift */; };
CE37B638263756BF00DEE13D /* JSONSchema in Frameworks */ = {isa = PBXBuildFile; productRef = CE37B637263756BF00DEE13D /* JSONSchema */; };
CE37B643263867D700DEE13D /* SecureBackground.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE37B642263867D700DEE13D /* SecureBackground.swift */; };
CE3CC93C2628A7820079FB78 /* ASN1.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE3CC93B2628A7820079FB78 /* ASN1.swift */; };
CE3CC9442628C2130079FB78 /* CBOR.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE3CC9432628C2130079FB78 /* CBOR.swift */; };
CE44798D26304D8F009A836B /* JSONSchema in Frameworks */ = {isa = PBXBuildFile; productRef = CE44798C26304D8F009A836B /* JSONSchema */; };
CE44799226306C86009A836B /* String.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE44799126306C86009A836B /* String.swift */; };
CE44799726306C9B009A836B /* Data+Base45.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE44799626306C9B009A836B /* Data+Base45.swift */; };
CE582DC12635AE5F008F35D7 /* SecureStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE582DC02635AE5F008F35D7 /* SecureStorage.swift */; };
Expand All @@ -47,6 +47,7 @@
CEC2C4C22625ED030056E406 /* ZLib.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEC2C4BF2625ED030056E406 /* ZLib.swift */; };
CEC2C4C32625ED030056E406 /* JWK.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEC2C4C02625ED030056E406 /* JWK.swift */; };
CEC2C4C42625ED030056E406 /* Base45.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEC2C4C12625ED030056E406 /* Base45.swift */; };
CED2726026398683003D47A9 /* UIFont.swift in Sources */ = {isa = PBXBuildFile; fileRef = CED2725F26398683003D47A9 /* UIFont.swift */; };
CEFAD86D2625F164009AFEF9 /* Signature.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEFAD86C2625F164009AFEF9 /* Signature.swift */; };
CEFAD8722625F29E009AFEF9 /* String+JSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEFAD8712625F29E009AFEF9 /* String+JSON.swift */; };
CEFAD87A26271414009AFEF9 /* COSE.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEFAD87926271414009AFEF9 /* COSE.swift */; };
Expand Down Expand Up @@ -113,6 +114,7 @@
CEC2C4BF2625ED030056E406 /* ZLib.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ZLib.swift; sourceTree = "<group>"; };
CEC2C4C02625ED030056E406 /* JWK.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JWK.swift; sourceTree = "<group>"; };
CEC2C4C12625ED030056E406 /* Base45.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Base45.swift; sourceTree = "<group>"; };
CED2725F26398683003D47A9 /* UIFont.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIFont.swift; sourceTree = "<group>"; };
CEFAD86C2625F164009AFEF9 /* Signature.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Signature.swift; sourceTree = "<group>"; };
CEFAD8712625F29E009AFEF9 /* String+JSON.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+JSON.swift"; sourceTree = "<group>"; };
CEFAD87926271414009AFEF9 /* COSE.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = COSE.swift; sourceTree = "<group>"; };
Expand All @@ -126,8 +128,8 @@
buildActionMask = 2147483647;
files = (
CE8912FB2634C6B900CB92AF /* Alamofire in Frameworks */,
CE37B638263756BF00DEE13D /* JSONSchema in Frameworks */,
CE157F87262E24DE00FE4821 /* SwiftyJSON in Frameworks */,
CE44798D26304D8F009A836B /* JSONSchema in Frameworks */,
CE7DE7FA2625EF18007E6694 /* SwiftCBOR in Frameworks */,
CE13CF00262DCC180070C80E /* FloatingPanel in Frameworks */,
);
Expand Down Expand Up @@ -190,6 +192,7 @@
CE157F9A262E2A9F00FE4821 /* SwiftCBOR.CBOR.swift */,
CE44799126306C86009A836B /* String.swift */,
CE44799626306C9B009A836B /* Data+Base45.swift */,
CED2725F26398683003D47A9 /* UIFont.swift */,
);
path = Extensions;
sourceTree = "<group>";
Expand Down Expand Up @@ -318,8 +321,8 @@
CE7DE7F92625EF18007E6694 /* SwiftCBOR */,
CE13CEFF262DCC180070C80E /* FloatingPanel */,
CE157F86262E24DE00FE4821 /* SwiftyJSON */,
CE44798C26304D8F009A836B /* JSONSchema */,
CE8912FA2634C6B900CB92AF /* Alamofire */,
CE37B637263756BF00DEE13D /* JSONSchema */,
);
productName = DGCAVerifier;
productReference = CEA6D6E8261F8D2700715333 /* DGCAVerifier.app */;
Expand Down Expand Up @@ -396,8 +399,8 @@
CE7DE7F82625EF18007E6694 /* XCRemoteSwiftPackageReference "SwiftCBOR" */,
CE13CEFE262DCC180070C80E /* XCRemoteSwiftPackageReference "FloatingPanel" */,
CE157F85262E24DE00FE4821 /* XCRemoteSwiftPackageReference "SwiftyJSON" */,
CE44798B26304D8F009A836B /* XCRemoteSwiftPackageReference "JSONSchema" */,
CE8912F92634C6B900CB92AF /* XCRemoteSwiftPackageReference "Alamofire" */,
CE37B636263756BF00DEE13D /* XCRemoteSwiftPackageReference "JSONSchema" */,
);
productRefGroup = CEA6D6E9261F8D2700715333 /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -461,6 +464,7 @@
CE157F81262E1F7A00FE4821 /* Date.swift in Sources */,
CE1D1EF6263597A2004C8919 /* LocalData.swift in Sources */,
CE1BDF99262A4CD600766F97 /* X509.swift in Sources */,
CED2726026398683003D47A9 /* UIFont.swift in Sources */,
CEA1555D262F63B30024B7AC /* EuDgcSchema.swift in Sources */,
CEA6D6F0261F8D2700715333 /* Scan.swift in Sources */,
CE3CC93C2628A7820079FB78 /* ASN1.swift in Sources */,
Expand Down Expand Up @@ -829,9 +833,9 @@
minimumVersion = 5.0.1;
};
};
CE44798B26304D8F009A836B /* XCRemoteSwiftPackageReference "JSONSchema" */ = {
CE37B636263756BF00DEE13D /* XCRemoteSwiftPackageReference "JSONSchema" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/eu-digital-green-certificates/JSONSchema.swift";
repositoryURL = "https://github.com/jnewc/JSONSchema.swift";
requirement = {
branch = master;
kind = branch;
Expand Down Expand Up @@ -866,9 +870,9 @@
package = CE157F85262E24DE00FE4821 /* XCRemoteSwiftPackageReference "SwiftyJSON" */;
productName = SwiftyJSON;
};
CE44798C26304D8F009A836B /* JSONSchema */ = {
CE37B637263756BF00DEE13D /* JSONSchema */ = {
isa = XCSwiftPackageProductDependency;
package = CE44798B26304D8F009A836B /* XCRemoteSwiftPackageReference "JSONSchema" */;
package = CE37B636263756BF00DEE13D /* XCRemoteSwiftPackageReference "JSONSchema" */;
productName = JSONSchema;
};
CE7DE7F92625EF18007E6694 /* SwiftCBOR */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
},
{
"package": "JSONSchema",
"repositoryURL": "https://github.com/eu-digital-green-certificates/JSONSchema.swift",
"repositoryURL": "https://github.com/jnewc/JSONSchema.swift",
"state": {
"branch": "master",
"revision": "adb480fe1c1e285c131bff465f641aebc986d736",
"revision": "4637ac1cf57745c29003738f36e1b6c232fbd1a6",
"version": null
}
},
Expand Down
12 changes: 12 additions & 0 deletions DGCAVerifier/Components/InfoCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,17 @@ class InfoCell: UITableViewCell {
func draw(_ info: InfoSection) {
headerLabel?.text = info.header
contentLabel?.text = info.content
let fontSize = contentLabel.font.pointSize
let fontWeight = contentLabel.font.weight
switch info.style {
case .fixedWidthFont:
if #available(iOS 13.0, *) {
contentLabel.font = .monospacedSystemFont(ofSize: fontSize, weight: fontWeight)
} else {
contentLabel.font = .monospacedDigitSystemFont(ofSize: fontSize, weight: fontWeight)
}
default:
contentLabel.font = .systemFont(ofSize: fontSize, weight: fontWeight)
}
}
}
4 changes: 4 additions & 0 deletions DGCAVerifier/Extensions/String.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,8 @@ extension String {
subscript(i: Int) -> String {
return String(self[index(startIndex, offsetBy: i)])
}

static var zeroWidthSpace: String {
"\u{200B}"
}
}
65 changes: 65 additions & 0 deletions DGCAVerifier/Extensions/UIFont.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//
/*-
* ---license-start
* eu-digital-green-certificates / dgca-verifier-app-ios
* ---
* Copyright (C) 2021 T-Systems International GmbH and all other contributors
* ---
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ---license-end
*/
//
// UIFont.swift
// DGCAVerifier
//
// Created by Yannick Spreen on 4/28/21.
//
// https://stackoverflow.com/a/48688917/2585092
//

import UIKit


extension UIFont {
var weight: UIFont.Weight {
let fontAttributeKey = UIFontDescriptor.AttributeName.init(rawValue: "NSCTFontUIUsageAttribute")

if let fontWeight = self.fontDescriptor.fontAttributes[fontAttributeKey] as? String {
switch fontWeight {
case "CTFontBoldUsage":
return UIFont.Weight.bold
case "CTFontBlackUsage":
return UIFont.Weight.black
case "CTFontHeavyUsage":
return UIFont.Weight.heavy
case "CTFontUltraLightUsage":
return UIFont.Weight.ultraLight
case "CTFontThinUsage":
return UIFont.Weight.thin
case "CTFontLightUsage":
return UIFont.Weight.light
case "CTFontMediumUsage":
return UIFont.Weight.medium
case "CTFontDemiUsage":
return UIFont.Weight.semibold
case "CTFontRegularUsage":
return UIFont.Weight.regular

default:
return UIFont.Weight.regular
}
}

return UIFont.Weight.regular
}
}
74 changes: 45 additions & 29 deletions DGCAVerifier/Models/HCert.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,13 @@ enum ClaimKey: String {
enum AttributeKey: String {
case firstName
case lastName
case firstNameStandardized
case lastNameStandardized
case gender
case dateOfBirth
case testStatements
case vaccineStatements
case recoveryStatements
case personIdentifiers
case identifierType = "t"
case identifierCountry = "c"
case identifierValue = "i"
case vaccineShotNo = "seq"
case vaccineShotTotal = "tot"
}
Expand All @@ -69,19 +67,26 @@ let identifierNames: [String: String] = [
]

let attributeKeys: [AttributeKey: [String]] = [
.firstName: ["sub", "gn"],
.lastName: ["sub", "fn"],
.gender: ["sub", "gen"],
.dateOfBirth: ["sub", "dob"],
.personIdentifiers: ["sub", "id"],
.testStatements: ["tst"],
.vaccineStatements: ["vac"],
.recoveryStatements: ["rec"],
.firstName: ["nam", "gn"],
.lastName: ["nam", "fn"],
.firstNameStandardized: ["nam", "gnt"],
.lastNameStandardized: ["nam", "fnt"],
.gender: ["nam", "gen"],
.dateOfBirth: ["dob"],
.testStatements: ["t"],
.vaccineStatements: ["v"],
.recoveryStatements: ["r"],
]

enum InfoSectionStyle {
case normal
case fixedWidthFont
}

struct InfoSection {
var header: String
var content: String
var style = InfoSectionStyle.normal
}

struct HCert {
Expand Down Expand Up @@ -156,11 +161,35 @@ struct HCert {

var info: [InfoSection] {
var info = [
InfoSection(header: "Certificate Type", content: type.rawValue),
InfoSection(
header: "Certificate Type",
content: type.rawValue
),
] + personIdentifiers
if let date = dateOfBirth {
info += [
InfoSection(header: "Date of Birth", content: date.localDateString),
InfoSection(
header: "Date of Birth",
content: date.localDateString
),
]
}
if let last = get(.lastNameStandardized).string {
info += [
InfoSection(
header: "Standardised Family Name",
content: last.replacingOccurrences(of: "<", with: String.zeroWidthSpace + "<"),
style: .fixedWidthFont
),
]
}
if let first = get(.firstNameStandardized).string {
info += [
InfoSection(
header: "Standardised Given Name",
content: first.replacingOccurrences(of: "<", with: String.zeroWidthSpace + "<"),
style: .fixedWidthFont
),
]
}
return info
Expand All @@ -185,21 +214,8 @@ struct HCert {
}

var personIdentifiers: [InfoSection] {
guard let identifiers = get(.personIdentifiers).array else {
return []
}
return identifiers.map {
let type = $0[AttributeKey.identifierType.rawValue].string ?? ""
let country = $0[AttributeKey.identifierCountry.rawValue].string
let value = $0[AttributeKey.identifierValue.rawValue].string ?? ""

var header = identifierNames[type] ?? "Unknown Identifier"
if let country = country {
header += " (\(country))"
}

return InfoSection(header: header, content: value)
}
/// Note from author: Identifiers were previously planned, but got removed *for now*.
[]
}

var testStatements: [JSON] {
Expand Down
9 changes: 3 additions & 6 deletions DGCAVerifier/Services/GatewayConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ struct GatewayConnection {
timer = Timer.scheduledTimer(withTimeInterval: 60.0, repeats: true) {
_ in trigger()
}
timer?.tolerance = 1.0
timer?.tolerance = 5.0
trigger()
}

Expand All @@ -113,11 +113,8 @@ struct GatewayConnection {

static func status() {
certStatus { validKids in
var invalid = [String]()
for key in LocalData.sharedInstance.encodedPublicKeys.keys {
if !validKids.contains(key) {
invalid.append(key)
}
let invalid = LocalData.sharedInstance.encodedPublicKeys.keys.filter {
!validKids.contains($0)
}
for key in invalid {
LocalData.sharedInstance.encodedPublicKeys.removeValue(forKey: key)
Expand Down
Loading

0 comments on commit 7d71733

Please sign in to comment.