Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import UtilsLib

public actor WebEidAuthService: WebEidAuthServiceProtocol, Loggable {

init() {}
private let appVersionUrl: String

init(appVersion: String = BundleUtil.getBundleShortVersionString()) {
appVersionUrl = "https://id.eesti.ee/releases/v\(appVersion)"
}

public func buildAuthToken(
authCert: Data,
Expand All @@ -26,8 +30,8 @@ public actor WebEidAuthService: WebEidAuthServiceProtocol, Loggable {
var token: [String: Any] = [
"algorithm": algorithm,
"unverifiedCertificate": authCert.base64EncodedString(),
// TODO: hardcoded? NB! clarify with RIA
"issuerApp": "https://web-eid.eu/web-eid-mobile-app/releases/v1.0.0",
"issuerApp": appVersionUrl,
"appVersion": appVersionUrl,
"signature": signature.base64EncodedString()
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct WebEidAuthServiceTests {
// swiftlint:enable line_length

init() async throws {
service = WebEidAuthService()
service = WebEidAuthService(appVersion: "3.2.0")
}

@Test
Expand All @@ -29,7 +29,8 @@ struct WebEidAuthServiceTests {
let signature = Data(base64Encoded: testSignature) ?? Data()
let token: [String: Any] = [
"unverifiedCertificate": testAuthCert,
"issuerApp": "https://web-eid.eu/web-eid-mobile-app/releases/v1.0.0",
"issuerApp": "https://id.eesti.ee/releases/v3.2.0",
"appVersion": "https://id.eesti.ee/releases/v3.2.0",
"algorithm": "ES384",
"format": "web-eid:1.0",
"signature": testSignature]
Expand All @@ -53,7 +54,8 @@ struct WebEidAuthServiceTests {
let signCert = Data(base64Encoded: testSignCert) ?? Data()
let signature = Data(base64Encoded: testSignature) ?? Data()
let token: [String: Any] = [
"issuerApp": "https://web-eid.eu/web-eid-mobile-app/releases/v1.0.0",
"issuerApp": "https://id.eesti.ee/releases/v3.2.0",
"appVersion": "https://id.eesti.ee/releases/v3.2.0",
"format": "web-eid:1.1",
"algorithm": "ES384",
"unverifiedCertificate": testAuthCert,
Expand Down Expand Up @@ -88,6 +90,24 @@ struct WebEidAuthServiceTests {
#expect(result.count == expected.count)
}

@Test
func buildAuthToken_setsIssuerAppAndAppVersionToIdEestiEeReleaseUrl() async throws {
let authCert = Data(base64Encoded: testAuthCert) ?? Data()
let signature = Data(base64Encoded: testSignature) ?? Data()

let data = try await service.buildAuthToken(
authCert: authCert,
signingCert: nil,
signature: signature
)

let token = try #require(
try JSONSerialization.jsonObject(with: data) as? [String: Any]
)
#expect(token["issuerApp"] as? String == "https://id.eesti.ee/releases/v3.2.0")
#expect(token["appVersion"] as? String == "https://id.eesti.ee/releases/v3.2.0")
}

@Test
func buildAuthToken_throwinvalidCertificateWhenCertIsInvalid() async throws {
let invalidCert = Data([0x00, 0x01, 0x02])
Expand Down
Loading