Skip to content

Commit

Permalink
Verify all certs against local key db.
Browse files Browse the repository at this point in the history
  • Loading branch information
yspreen committed Apr 27, 2021
1 parent f4a95be commit 3fb64e8
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions DGCAVerifier/Models/HCert.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,24 @@ struct HCert {
}
#endif
print(header)
// print(body)
#if DEBUG
print(body)
#endif
return true
}

init?(from cborData: Data) {
let headerStr = CBOR.header(from: cborData)?.toString() ?? "{}"
let bodyStr = CBOR.payload(from: cborData)?.toString() ?? "{}"
rawData = cborData
guard
let headerStr = CBOR.header(from: cborData)?.toString(),
let bodyStr = CBOR.payload(from: cborData)?.toString(),
let kid = CBOR.kid(from: cborData)
else {
return nil
}
kidStr = KID.string(from: kid)
header = JSON(parseJSON: headerStr)
var body = JSON(parseJSON: bodyStr)
// print(body)
if body[ClaimKey.HCERT.rawValue].exists() {
body = body[ClaimKey.HCERT.rawValue]
}
Expand Down Expand Up @@ -158,6 +166,8 @@ struct HCert {
return info
}

var rawData: Data
var kidStr: String
var header: JSON
var body: JSON

Expand Down Expand Up @@ -224,7 +234,7 @@ struct HCert {
return .test
}
var isValid: Bool {
return Int.random(in: 0...9) < 5
return COSE.verify(rawData, with: LocalData.sharedInstance.encodedPublicKeys[kidStr] ?? "")
}
var validity: HCertValidity {
return isValid ? .valid : .invalid
Expand Down

0 comments on commit 3fb64e8

Please sign in to comment.