Skip to content
Open
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
5 changes: 3 additions & 2 deletions Modules/CommonsLib/Sources/CommonsLib/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import Foundation

public struct Constants {
public struct Container {
public static let SignedContainerFolder = "SignedContainers"
public static let CryptoContainerFolder = "CryptoContainers"
public static let DefaultName = "newFile"
public static let ContainerExtensions = [
Extension.Asice,
Expand Down Expand Up @@ -83,9 +81,12 @@ public struct Constants {
public struct Identifier {
public static let Group = "group.ee.ria.digidoc.ios"
public static let GroupDownload = "group.ee.ria.digidoc.ios.download"
public static let GroupLastOpenedAttribute = "group.ee.ria.digidoc.ios.lastOpened"
}

public struct Folder {
public static let SignedContainerFolder = "SignedContainers"
public static let CryptoContainerFolder = "CryptoContainers"
public static let Temp = "tempfiles"
public static let Shared = "shareddownloads"
public static let SavedFiles = "savedfiles"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ public extension Container {
.singleton
}

var fileInspector: Factory<FileInspectorProtocol> {
self { FileInspector() }
}

var urlResourceChecker: Factory<URLResourceCheckerProtocol> {
self { URLResourceChecker() }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*
*/

public struct ProxyInfo: Sendable {
public struct ProxyInfo: Sendable, Equatable {
public var option: ProxySettingsOption
public var host: String
public var port: Int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ public struct ConfigurationProvider: Codable, Sendable, Equatable {
public let tslUrl: URL
public let tslCerts: [Data]
public let tsaUrl: URL
public let ocspIssuers: [String: String]
public let ldapPersonUrls: [URL]
public let ldapPersonUrl: URL
public let ldapCorpUrl: URL
Expand All @@ -90,7 +89,6 @@ public struct ConfigurationProvider: Codable, Sendable, Equatable {
case tslUrl = "TSL-URL"
case tslCerts = "TSL-CERTS"
case tsaUrl = "TSA-URL"
case ocspIssuers = "OCSP-URL-ISSUER"
case ldapPersonUrls = "LDAP-PERSON-URLS"
case ldapPersonUrl = "LDAP-PERSON-URL"
case ldapCorpUrl = "LDAP-CORP-URL"
Expand Down Expand Up @@ -123,7 +121,6 @@ public struct ConfigurationProvider: Codable, Sendable, Equatable {
try container.encode(tslUrl, forKey: .tslUrl)
try container.encode(tslCerts, forKey: .tslCerts)
try container.encode(tsaUrl, forKey: .tsaUrl)
try container.encode(ocspIssuers, forKey: .ocspIssuers)
try container.encode(ldapPersonUrl, forKey: .ldapPersonUrl)
try container.encode(ldapPersonUrls, forKey: .ldapPersonUrls)
try container.encode(ldapCorpUrl, forKey: .ldapCorpUrl)
Expand All @@ -147,7 +144,6 @@ public struct ConfigurationProvider: Codable, Sendable, Equatable {
tslUrl = try container.decode(URL.self, forKey: .tslUrl)
tslCerts = try container.decode([Data].self, forKey: .tslCerts)
tsaUrl = try container.decode(URL.self, forKey: .tsaUrl)
ocspIssuers = try container.decode([String: String].self, forKey: .ocspIssuers)
ldapPersonUrls = try container.decode([URL].self, forKey: .ldapPersonUrls)
ldapPersonUrl = try container.decode(URL.self, forKey: .ldapPersonUrl)
ldapCorpUrl = try container.decode(URL.self, forKey: .ldapCorpUrl)
Expand Down Expand Up @@ -178,7 +174,6 @@ public struct ConfigurationProvider: Codable, Sendable, Equatable {
tslUrl: URL,
tslCerts: [Data],
tsaUrl: URL,
ocspIssuers: [String: String],
ldapPersonUrls: [URL],
ldapPersonUrl: URL,
ldapCorpUrl: URL,
Expand All @@ -200,7 +195,6 @@ public struct ConfigurationProvider: Codable, Sendable, Equatable {
self.tslUrl = tslUrl
self.tslCerts = tslCerts
self.tsaUrl = tsaUrl
self.ocspIssuers = ocspIssuers
self.ldapPersonUrls = ldapPersonUrls
self.ldapPersonUrl = ldapPersonUrl
self.ldapCorpUrl = ldapCorpUrl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@
*/

import Foundation
import OSLog
import Alamofire
import CommonsLib

public actor CentralConfigurationService: CentralConfigurationServiceProtocol {

private static let logger = Logger(subsystem: "ee.ria.digidoc.RIADigiDoc", category: "CentralConfigurationService")

private let userAgent: String
private let configurationProperty: ConfigurationProperty
private let session: Session?
Expand All @@ -46,12 +49,19 @@ public actor CentralConfigurationService: CentralConfigurationServiceProtocol {
)

let url = "\(await configurationProperty.centralConfigurationServiceUrl)/config.json"
let response: String = try await session.request(url)
.validate()
.serializingString()
.value

return response
do {
let response: String = try await session.request(url)
.validate()
.serializingString()
.value

return response
} catch {
CentralConfigurationService.logger
.error("Unable to fetch central configuration: \(error)")
throw URLError(.resourceUnavailable)
}
}

public func fetchPublicKey(
Expand All @@ -63,12 +73,19 @@ public actor CentralConfigurationService: CentralConfigurationServiceProtocol {
)

let url = "\(await configurationProperty.centralConfigurationServiceUrl)/config.pub"
let response: String = try await session.request(url)
.validate()
.serializingString()
.value

return response
do {
let response: String = try await session.request(url)
.validate()
.serializingString()
.value

return response
} catch {
CentralConfigurationService.logger
.error("Unable to fetch central configuration public key: \(error)")
throw URLError(.resourceUnavailable)
}
}

public func fetchSignature(
Expand All @@ -80,16 +97,22 @@ public actor CentralConfigurationService: CentralConfigurationServiceProtocol {
)

let url = "\(await configurationProperty.centralConfigurationServiceUrl)/config.rsa"
let responseData: Data = try await session.request(url)
.validate()
.serializingData()
.value

guard let responseString = String(data: responseData, encoding: .utf8) else {
throw URLError(.cannotDecodeContentData)
do {
let responseData: Data = try await session.request(url)
.validate()
.serializingData()
.value

guard let responseString = String(data: responseData, encoding: .utf8) else {
throw URLError(.cannotDecodeContentData)
}

return responseString
} catch {
CentralConfigurationService.logger
.error("Unable to fetch central configuration signature: \(error)")
throw URLError(.resourceUnavailable)
}

return responseString
}

private func constructHttpClient(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ struct CentralConfigurationServiceTests {
session: session
)

await #expect(throws: Alamofire.AFError.self) {
await #expect(throws: Error.self) {
try await errorService.fetchConfiguration(proxyInfo: ProxyInfo())
}
}
Expand Down Expand Up @@ -175,7 +175,7 @@ struct CentralConfigurationServiceTests {
session: session
)

await #expect(throws: Alamofire.AFError.self) {
await #expect(throws: Error.self) {
try await errorService.fetchPublicKey(proxyInfo: ProxyInfo())
}
}
Expand Down Expand Up @@ -245,7 +245,7 @@ struct CentralConfigurationServiceTests {
session: session
)

await #expect(throws: Alamofire.AFError.self) {
await #expect(throws: Error.self) {
try await errorService.fetchSignature(proxyInfo: ProxyInfo())
}
}
Expand Down
2 changes: 0 additions & 2 deletions Modules/ConfigLib/Tests/Mocks/TestConfigurationProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public class TestConfigurationProvider {
tslUrl: String = "https://tsl.someUrl.abc",
tslCerts: [String] = ["cert1", "cert2"],
tsaUrl: String = "https://tsa.someUrl.abc",
ocspIssuers: [String: String] = ["url1": "issuer1"],
ldapPersonUrls: [String] = [
"https://ldap-person.someUrl.abc",
"https://ldap-person.someUrl2.abc"
Expand Down Expand Up @@ -103,7 +102,6 @@ public class TestConfigurationProvider {
tslUrl: tslURL,
tslCerts: tslCertsData,
tsaUrl: tsaURL,
ocspIssuers: ocspIssuers,
ldapPersonUrls: ldapPersonURLs,
ldapPersonUrl: ldapPersonURL,
ldapCorpUrl: ldapCorpURL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@ void setProxyPass(NSString *proxyPass) {
return digidoc::ConfCurrent::TSLUrl();
}

std::vector<digidoc::X509Cert> TSLCerts() const final {
NSMutableArray<NSData *> *certBundle = [NSMutableArray arrayWithArray:currentConf.TSLCERTS];

if (certBundle != nil && certBundle.count > 0) {
return toX509Certs(certBundle);
}

return digidoc::ConfCurrent::TSLCerts();
}

std::vector<digidoc::X509Cert> TSCerts() const override {
NSMutableArray<NSData *> *certBundle = [NSMutableArray arrayWithArray:currentConf.CERTBUNDLE];

Expand All @@ -111,15 +121,6 @@ void setProxyPass(NSString *proxyPass) {

return digidoc::ConfCurrent::TSUrl();
}

std::string ocsp(const std::string &issuer) const final {
NSString *ocspIssuer = [NSString stringWithUTF8String:issuer.c_str()];
NSString *ocspUrl = currentConf.OCSPISSUERS[ocspIssuer];
if (ocspUrl != nil && ocspUrl.length > 0) {
return ocspUrl.UTF8String;
}
return digidoc::ConfCurrent::ocsp(issuer);
}

std::string proxyHost() const final {
if (_proxyHost && _proxyHost.length > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,10 @@ + (void)addDataFilesToContainerWithPath:(NSString *)containerPath
std::vector<digidoc::Exception> causes = e.causes();
NSDictionary *userInfo = @{
NSLocalizedDescriptionKey: [NSString stringWithUTF8String:e.msg().c_str()],
@"causes": [ExceptionUtil exceptionCauses:static_cast<void *>(&causes)]
@"causes": @{
@"exceptions": [ExceptionUtil exceptionCauses:static_cast<void *>(&causes)],
@"fileName": dataFilePath.lastPathComponent
}
};

NSError *addFileError = [NSError errorWithDomain:@"LibdigidocLib" code:e.code() userInfo:userInfo];
Expand All @@ -289,7 +292,9 @@ + (void)addDataFilesToContainerWithPath:(NSString *)containerPath
NSLocalizedDescriptionKey: summary,
@"failedFileCount": @(failedCount),
@"totalFileCount": @(totalFileCount),
@"causes": errors
@"causes": @{
@"errors": errors
}
};
NSError *combined = [NSError errorWithDomain:@"LibdigidocLib" code:1 userInfo:info];
completion(combined);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
@property (nonatomic, strong) NSArray<NSData *> *TSLCERTS;
@property (nonatomic, strong) NSArray<NSData *> *LDAPCERTS;
@property (nonatomic, strong) NSURL *TSAURL;
@property (nonatomic, strong) NSDictionary *OCSPISSUERS;
@property (nonatomic, strong) NSArray<NSData *> *CERTBUNDLE;

- (instancetype)initWithConf:(int)logLevel
Expand All @@ -42,7 +41,6 @@
TSLCERTS:(NSArray<NSData *> *)TSLCERTS
LDAPCERTS:(NSArray<NSData *> *)LDAPCERTS
TSAURL:(NSURL *)TSAURL
OCSPISSUERS:(NSDictionary *)OCSPISSUERS
CERTBUNDLE:(NSArray<NSData *> *)CERTBUNDLE;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ - (instancetype)initWithConf:(int)logLevel
TSLCERTS:(NSArray<NSData *> *)TSLCERTS
LDAPCERTS:(NSArray<NSData *> *)LDAPCERTS
TSAURL:(NSURL *)TSAURL
OCSPISSUERS:(NSDictionary *)OCSPISSUERS
CERTBUNDLE:(NSArray<NSData *> *)CERTBUNDLE {
self = [super init];
if (self) {
Expand All @@ -42,7 +41,6 @@ - (instancetype)initWithConf:(int)logLevel
_TSLCERTS = TSLCERTS;
_LDAPCERTS = LDAPCERTS;
_TSAURL = TSAURL;
_OCSPISSUERS = OCSPISSUERS;
_CERTBUNDLE = CERTBUNDLE;
}
return self;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ NS_ASSUME_NONNULL_BEGIN

@interface DigiDocSigningWrapper : NSObject

+ (void)prepareSignature:(NSData *)cert containerPath:(NSString *)containerPath roleData:(DigiDocRoleData *)roleData userAgent:(NSString *)userAgent completion:(void (^)(NSData * _Nullable dataToSign, NSError * _Nullable error))completion;
+ (void)addSignature:(NSData *)data completion:(void (^)(BOOL valid, NSError * _Nullable error))completion;
- (void)prepareSignature:(NSData *)cert containerPath:(NSString *)containerPath roleData:(DigiDocRoleData *)roleData userAgent:(NSString *)userAgent completion:(void (^)(NSData * _Nullable dataToSign, NSError * _Nullable error))completion;
- (void)addSignature:(NSData *)data completion:(void (^)(BOOL valid, NSError * _Nullable error))completion;

@end

Expand Down
Loading