Skip to content

Commit 1c44402

Browse files
committed
ECC key support
IB-8381 Signed-off-by: Raul Metsma <raul@metsma.ee>
1 parent 9045b12 commit 1c44402

File tree

6 files changed

+161
-145
lines changed

6 files changed

+161
-145
lines changed

.github/workflows/build.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
uses: actions/checkout@v4
1515
- name: Build
1616
run: |
17-
cmake -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64" -S . -B build
17+
cmake -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64" -DCMAKE_BUILD_TYPE=RelWithDebInfo -S . -B build
1818
cmake --build build --target pkgbuild
1919
- name: Archive artifacts
2020
uses: actions/upload-artifact@v4
@@ -43,19 +43,19 @@ jobs:
4343
- name: Install Qt
4444
uses: jurplel/install-qt-action@v4
4545
with:
46-
version: 6.9.1
46+
version: 6.9.2
4747
arch: win64_msvc2022_64
4848
- name: Setup dev env
4949
uses: ilammy/msvc-dev-cmd@v1
5050
with:
5151
arch: x64
5252
- name: Install WiX
5353
run: |
54-
dotnet tool install -g wix --version 6.0.1
55-
wix extension -g add WixToolset.UI.wixext/6.0.1
54+
dotnet tool install -g wix --version 6.0.2
55+
wix extension -g add WixToolset.UI.wixext/6.0.2
5656
- name: Build
5757
run: |
58-
cmake -S . -B build `
58+
cmake -S . -B build -DCMAKE_BUILD_TYPE=RelWithDebInfo `
5959
-DCMAKE_TOOLCHAIN_FILE=${{ env.RUNVCPKG_VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake
6060
cmake --build build --target installer
6161
- name: Archive artifacts

CMakeLists.txt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ set(VERSION ${PROJECT_VERSION}.${BUILD_NUMBER})
1414
set_env( CONFIG_URL "https://id.eesti.ee/config.json" CACHE STRING "Set Config URL" )
1515
set_env( SIGNCERT "" CACHE STRING "Common name of certificate to used sign binaries, empty skip signing" )
1616
add_definitions( -DCONFIG_URL="${CONFIG_URL}" )
17-
string( REPLACE ".json" ".pub" PUB_URL ${CONFIG_URL} )
18-
file( DOWNLOAD ${PUB_URL} ${CMAKE_CURRENT_BINARY_DIR}/config.pub )
17+
string(REPLACE ".json" ".ecpub" PUB_URL ${CONFIG_URL})
18+
message("Fetching pub key: ${PUB_URL}")
19+
file(DOWNLOAD ${PUB_URL} ${CMAKE_CURRENT_BINARY_DIR}/config.ecpub)
1920

2021
if( APPLE )
2122
add_custom_command( OUTPUT config.h
22-
COMMAND xxd -i config.pub config.h
23+
COMMAND xxd -i config.ecpub config.h
2324
COMMENT "Generating config.h"
2425
)
2526
include_directories( ${CMAKE_CURRENT_BINARY_DIR} )
@@ -118,9 +119,9 @@ else()
118119
if(NOT EXISTS ${CMAKE_SOURCE_DIR}/common/CMakeLists.txt)
119120
message(FATAL_ERROR "cmake submodule directory empty, did you 'git clone --recursive'?")
120121
endif()
121-
file( DOWNLOAD ${CONFIG_URL} ${CMAKE_CURRENT_BINARY_DIR}/config.json )
122-
string( REPLACE ".json" ".rsa" RSA_URL ${CONFIG_URL} )
123-
file( DOWNLOAD ${RSA_URL} ${CMAKE_CURRENT_BINARY_DIR}/config.rsa )
122+
file(DOWNLOAD ${CONFIG_URL} ${CMAKE_CURRENT_BINARY_DIR}/config.json)
123+
string(REPLACE ".json" ".ecc" ECC_URL ${CONFIG_URL})
124+
file(DOWNLOAD ${ECC_URL} ${CMAKE_CURRENT_BINARY_DIR}/config.ecc)
124125
set(CONFIG_DIR ${CMAKE_CURRENT_BINARY_DIR})
125126

126127
find_package(OpenSSL 3.0.0 REQUIRED)
@@ -167,7 +168,7 @@ else()
167168
)
168169
qt_add_resources(${PROJECT_NAME} icon FILES appicon.png)
169170
qt_add_resources(${PROJECT_NAME} config BASE ${CONFIG_DIR} PREFIX / FILES
170-
${CONFIG_DIR}/config.json ${CONFIG_DIR}/config.rsa ${CONFIG_DIR}/config.pub
171+
${CONFIG_DIR}/config.json ${CONFIG_DIR}/config.ecc ${CONFIG_DIR}/config.ecpub
171172
)
172173

173174
if(OPENSSL_ROOT_DIR)

common

prefPane/id-updater.m

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,45 @@ - (void)updateAvailable:(NSString *)_available filename:(NSString *)_filename {
235235
});
236236
}
237237

238+
- (BOOL)verifyCMSSignature:(NSData *)signatureData data:(NSData *)data cert:(NSData *)cert {
239+
#define RETURN_IF_OERROR(MSG) if (oserr) { NSLog(MSG); return false; }
240+
CMSDecoderRef decoderRef;
241+
OSStatus oserr = CMSDecoderCreate(&decoderRef);
242+
RETURN_IF_OERROR(@"CMSDecoderCreate")
243+
id decoder = CFBridgingRelease(decoderRef);
244+
245+
oserr = CMSDecoderUpdateMessage((__bridge CMSDecoderRef)decoder, signatureData.bytes, signatureData.length);
246+
RETURN_IF_OERROR(@"CMSDecoderUpdateMessage")
247+
oserr = CMSDecoderFinalizeMessage((__bridge CMSDecoderRef)decoder);
248+
RETURN_IF_OERROR(@"CMSDecoderFinalizeMessage")
249+
oserr = CMSDecoderSetDetachedContent((__bridge CMSDecoderRef)decoder, (__bridge CFDataRef)data);
250+
RETURN_IF_OERROR(@"CMSDecoderSetDetachedContent")
251+
252+
size_t numSignersOut = 0;
253+
oserr = CMSDecoderGetNumSigners((__bridge CMSDecoderRef)decoder, &numSignersOut);
254+
RETURN_IF_OERROR(@"CMSDecoderGetNumSigners")
255+
if (numSignersOut != 1) {
256+
NSLog(@"Invalid number of signers: %lu", numSignersOut);
257+
return false;
258+
}
259+
260+
SecPolicyRef policy = SecPolicyCreateBasicX509();
261+
CMSSignerStatus status;
262+
oserr = CMSDecoderCopySignerStatus((__bridge CMSDecoderRef)decoder, 0, policy, TRUE, &status, nil, nil);
263+
CFRelease(policy);
264+
RETURN_IF_OERROR(@"CMSDecoderCopySignerStatus")
265+
bool isValid = status == kCMSSignerValid;
266+
267+
SecCertificateRef signerCert;
268+
oserr = CMSDecoderCopySignerCert((__bridge CMSDecoderRef)decoder, 0, &signerCert);
269+
RETURN_IF_OERROR(@"CMSDecoderCopySignerCert")
270+
bool isSameCert = [cert isEqualToData:CFBridgingRelease(SecCertificateCopyData(signerCert))];
271+
CFRelease(signerCert);
272+
273+
NSLog(@"Signature is (%d) and cert is equal(%d)", isValid, isSameCert);
274+
return isValid && isSameCert;
275+
}
276+
238277
#pragma mark - Connection delegate
239278

240279
- (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didWriteData:(int64_t)bytesWritten totalBytesWritten:(int64_t)totalBytesWritten totalBytesExpectedToWrite:(int64_t)totalBytesExpectedToWrite {
@@ -309,7 +348,7 @@ - (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTas
309348
}
310349

311350
if([signatureType isEqualToString:@"CMS"]) {
312-
if ([update verifyCMSSignature:signature data:data cert:certData])
351+
if ([self verifyCMSSignature:signature data:data cert:certData])
313352
[NSTask launchedTaskWithLaunchPath:@"/usr/bin/open" arguments:@[path]];
314353
else
315354
{
@@ -371,7 +410,7 @@ - (IBAction)diagnostics:(id)sender {
371410
NSDictionary *versions = @{
372411
@"DigiDoc4": update.digidoc4,
373412
@"Open-EID": update.baseversion,
374-
@"ID-Updater": [update versionInfo:@"ee.ria.ID-updater"],
413+
@"ID-Updater": update.updaterversion,
375414
NSLocalizedString(@"Safari (Extensions) browser plugin", nil): [update versionInfo:@"ee.ria.safari-token-signing"],
376415
NSLocalizedString(@"Safari (NPAPI) browser plugin", nil): [update versionInfo:@"ee.ria.firefox-token-signing"],
377416
NSLocalizedString(@"Chrome/Firefox browser plugin", nil): [update versionInfo:@"ee.ria.chrome-token-signing"],

prefPane/update.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,11 @@ enum {
3939
- (BOOL)checkCertificatePinning:(NSURLAuthenticationChallenge *)challenge;
4040
- (void)request;
4141
- (NSString *)userAgent:(BOOL)diagnostics;
42-
- (BOOL)verifyCMSSignature:(NSData *)signatureData data:(NSData *)data cert:(NSData *)cert;
4342
- (NSString*)versionInfo:(NSString *)pkg;
4443

4544
@property(nonatomic, readonly, getter=getBaseversion) NSString *baseversion;
4645
@property(retain) NSString *updaterversion;
4746
@property(retain) NSString *digidoc4;
48-
@property(retain) NSDictionary *centralConfig;
4947
@property(retain) NSArray *cert_bundle;
5048
@property(assign) id <UpdateDelegate> delegate;
5149
@end

0 commit comments

Comments
 (0)