Skip to content

Commit 36f7c92

Browse files
committed
Rewrite some code to swift and detach mountpoint
IB-8238 Signed-off-by: Raul Metsma <raul@metsma.ee>
1 parent dd6bc25 commit 36f7c92

File tree

6 files changed

+214
-141
lines changed

6 files changed

+214
-141
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
cmake -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64" -DCMAKE_BUILD_TYPE=RelWithDebInfo -S . -B build
1818
cmake --build build --target pkgbuild
1919
- name: Archive artifacts
20-
uses: actions/upload-artifact@v4
20+
uses: actions/upload-artifact@v5
2121
with:
2222
name: macOS
2323
path: build/*.pkg
@@ -50,7 +50,7 @@ jobs:
5050
- name: Install Qt
5151
uses: jurplel/install-qt-action@v4
5252
with:
53-
version: 6.10.0
53+
version: 6.10.1
5454
arch: win64_msvc2022_64
5555
- name: Setup dev env
5656
uses: ilammy/msvc-dev-cmd@v1
@@ -66,7 +66,7 @@ jobs:
6666
-DCMAKE_TOOLCHAIN_FILE=${{ env.RUNVCPKG_VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake
6767
cmake --build build --target installer
6868
- name: Archive artifacts
69-
uses: actions/upload-artifact@v4
69+
uses: actions/upload-artifact@v5
7070
with:
7171
name: msi_${{ matrix.vcver }}_x64
7272
path: build/*.msi

CMakeLists.txt

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,38 +47,49 @@ if( APPLE )
4747
libid-updater-lib_x86_64.a
4848
${SWIFTMOD_DIR}/arm64-apple-macos.swiftmodule
4949
${SWIFTMOD_DIR}/x86_64-apple-macos.swiftmodule
50-
DEPENDS config.h
50+
DEPENDS
51+
config.h
52+
prefPane/AdvancedWindowController.swift
53+
prefPane/id-updater.swift
54+
prefPane/update.swift
5155
COMMENT "Build id-updater-lib"
5256
COMMAND ${CMAKE_COMMAND} -E make_directory ${SWIFTMOD_DIR}
5357
COMMAND ${CMAKE_COMMAND} -E make_directory ${SWIFTHDR_DIR}
5458
COMMAND ${SWIFT_FLAGS} -target arm64-apple-macosx${CMAKE_OSX_DEPLOYMENT_TARGET}
5559
-module-name id_updater_lib
5660
-emit-module -emit-module-path ${SWIFTMOD_DIR}/arm64-apple-macos.swiftmodule
5761
-emit-objc-header -emit-objc-header-path ${SWIFTHDR_DIR}/id_updater_lib-Swift.h
58-
${CMAKE_CURRENT_SOURCE_DIR}/prefPane/update.swift
5962
-emit-library -static -o libid-updater-lib_arm64.a
63+
${CMAKE_CURRENT_SOURCE_DIR}/prefPane/AdvancedWindowController.swift
64+
${CMAKE_CURRENT_SOURCE_DIR}/prefPane/id-updater.swift
65+
${CMAKE_CURRENT_SOURCE_DIR}/prefPane/update.swift
6066
COMMAND ${SWIFT_FLAGS} -target x86_64-apple-macosx${CMAKE_OSX_DEPLOYMENT_TARGET}
6167
-module-name id_updater_lib
6268
-emit-module -emit-module-path ${SWIFTMOD_DIR}/x86_64-apple-macos.swiftmodule
6369
-emit-objc-header -emit-objc-header-path ${SWIFTHDR_DIR}/id_updater_lib-Swift.h
64-
${CMAKE_CURRENT_SOURCE_DIR}/prefPane/update.swift
6570
-emit-library -static -o libid-updater-lib_x86_64.a
71+
${CMAKE_CURRENT_SOURCE_DIR}/prefPane/AdvancedWindowController.swift
72+
${CMAKE_CURRENT_SOURCE_DIR}/prefPane/id-updater.swift
73+
${CMAKE_CURRENT_SOURCE_DIR}/prefPane/update.swift
6674
COMMAND lipo -create libid-updater-lib_arm64.a libid-updater-lib_x86_64.a -output libid-updater-lib.a
6775
)
6876
add_custom_command(OUTPUT id-updater-helper
6977
BYPRODUCTS
7078
id-updater-helper_arm64
7179
id-updater-helper_x86_64
72-
DEPENDS libid-updater-lib.a
80+
DEPENDS
81+
${CMAKE_CURRENT_BINARY_DIR}/libid-updater-lib.a
82+
prefPane/update.swift
83+
prefPane/main.swift
7384
COMMENT "Build id-updater-helper"
7485
COMMAND ${SWIFT_FLAGS} -target arm64-apple-macosx${CMAKE_OSX_DEPLOYMENT_TARGET} -parse-as-library
75-
${CMAKE_CURRENT_BINARY_DIR}/libid-updater-lib.a
76-
${CMAKE_CURRENT_SOURCE_DIR}/prefPane/main.swift
7786
-o id-updater-helper_arm64
78-
COMMAND ${SWIFT_FLAGS} -target x86_64-apple-macosx${CMAKE_OSX_DEPLOYMENT_TARGET} -parse-as-library
79-
${CMAKE_CURRENT_BINARY_DIR}/libid-updater-lib.a
87+
${CMAKE_CURRENT_SOURCE_DIR}/prefPane/update.swift
8088
${CMAKE_CURRENT_SOURCE_DIR}/prefPane/main.swift
89+
COMMAND ${SWIFT_FLAGS} -target x86_64-apple-macosx${CMAKE_OSX_DEPLOYMENT_TARGET} -parse-as-library
8190
-o id-updater-helper_x86_64
91+
${CMAKE_CURRENT_SOURCE_DIR}/prefPane/update.swift
92+
${CMAKE_CURRENT_SOURCE_DIR}/prefPane/main.swift
8293
COMMAND lipo -create id-updater-helper_arm64 id-updater-helper_x86_64 -output id-updater-helper
8394
)
8495

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
* id-updater
3+
*
4+
* This library is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU Lesser General Public
6+
* License as published by the Free Software Foundation; either
7+
* version 2.1 of the License, or (at your option) any later version.
8+
*
9+
* This library is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
* Lesser General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Lesser General Public
15+
* License along with this library; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17+
*
18+
*/
19+
20+
import Cocoa
21+
import SwiftUI
22+
23+
struct AdvancedWindowView: View {
24+
var closeAction: (() -> Void)?
25+
static let versions = [
26+
(label: "DigiDoc4", value: "ee.ria.qdigidoc4"),
27+
(label: "Open-EID", value: "ee.ria.open-eid"),
28+
(label: "ID-Updater", value: "ee.ria.ID-updater"),
29+
(label: String(localized: "Safari (Extensions) browser plugin"), value: "ee.ria.safari-token-signing"),
30+
(label: String(localized: "Safari (NPAPI) browser plugin"), value: "ee.ria.firefox-token-signing"),
31+
(label: String(localized: "Chrome/Firefox browser plugin"), value: "ee.ria.chrome-token-signing"),
32+
(label: String(localized: "Chrome browser plugin"), value: "ee.ria.token-signing-chrome"),
33+
(label: String(localized: "Chrome browser plugin policy"), value: "ee.ria.token-signing-chrome-policy"),
34+
(label: String(localized: "Firefox browser plugin"), value: "ee.ria.token-signing-firefox"),
35+
(label: String(localized: "Web-eID native component"), value: "eu.web-eid.web-eid"),
36+
(label: String(localized: "Safari browser extension (Web-eID)"), value: "eu.web-eid.web-eid-safari"),
37+
(label: String(localized: "Chrome browser extension (Web-eID)"), value: "eu.web-eid.web-eid-chrome"),
38+
(label: String(localized: "Chrome browser extension policy (Web-eID)"), value: "eu.web-eid.web-eid-chrome-policy"),
39+
(label: String(localized: "Firefox browser extension (Web-eID)"), value: "eu.web-eid.web-eid-firefox"),
40+
(label: String(localized: "PKCS11 loader"), value: "ee.ria.firefox-pkcs11-loader"),
41+
(label: String(localized: "IDEMIA PKCS11 loader"), value: "com.idemia.awp.xpi"),
42+
(label: "OpenSC", value: "org.opensc-project.mac"),
43+
(label: "IDEMIA PKCS11", value: "com.idemia.awp.pkcs11"),
44+
(label: "EstEID Tokend", value: "ee.ria.esteid-tokend"),
45+
(label: "EstEID CTK Tokend", value: "ee.ria.esteid-ctk-tokend"),
46+
(label: "IDEMIA Tokend", value: "com.idemia.awp.tokend"),
47+
]
48+
let text = versions.compactMap { item in
49+
let list = NSDictionary(contentsOfFile: "/var/db/receipts/\(item.value).plist")
50+
if let ver = list?["PackageVersion"] as? String {
51+
return "\(item.label): \(ver)"
52+
} else {
53+
return nil
54+
}
55+
}.joined(separator: "\n")
56+
57+
var body: some View {
58+
VStack {
59+
Text("Versions installed:")
60+
TextEditor(text: .constant(text))
61+
.padding(8)
62+
.background(Color(.textBackgroundColor))
63+
.clipShape(RoundedRectangle(cornerRadius: 6))
64+
HStack {
65+
Spacer()
66+
Button("OK") { closeAction?() }
67+
.keyboardShortcut(.defaultAction)
68+
}
69+
}
70+
.padding()
71+
}
72+
}
73+
74+
public class AdvancedWindowController: NSWindowController {
75+
@objc public init(parent: NSWindow? = nil) {
76+
super.init(window: nil)
77+
78+
let rootView = AdvancedWindowView() { [weak self] in
79+
guard let window = self?.window,
80+
let parent = window.sheetParent else { return }
81+
parent.endSheet(window)
82+
}
83+
84+
let popup = NSWindow(contentViewController: NSHostingController(rootView: rootView))
85+
popup.styleMask = .borderless
86+
popup.setContentSize(NSSize(width: 400, height: 250))
87+
self.window = popup
88+
89+
parent?.beginSheet(popup)
90+
}
91+
92+
required init?(coder: NSCoder) {
93+
fatalError("init(coder:) has not been implemented")
94+
}
95+
}
96+
97+
#Preview {
98+
AdvancedWindowView()
99+
}

prefPane/id-updater.m

Lines changed: 7 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -27,53 +27,6 @@
2727
#define NSLocalizedString(key, comment) \
2828
[bundlelang localizedStringForKey:(key) value:@"" table:nil]
2929

30-
@interface AdvancedWindowController: NSWindowController
31-
@end
32-
33-
@implementation AdvancedWindowController
34-
35-
- (instancetype)initWithText:(NSString*)text {
36-
if (self = [super init]) {
37-
NSView *view = [[NSView alloc] init];
38-
39-
NSTextField *label = [NSTextField labelWithString:text];
40-
label.translatesAutoresizingMaskIntoConstraints = NO;
41-
[view addSubview:label];
42-
[label.topAnchor constraintEqualToAnchor:view.topAnchor constant:25].active = YES;
43-
[label.centerXAnchor constraintEqualToAnchor:view.centerXAnchor].active = YES;
44-
45-
NSButton *ok = [[NSButton alloc] init];
46-
ok.translatesAutoresizingMaskIntoConstraints = NO;
47-
ok.title = @"OK";
48-
ok.keyEquivalent = @"\r";
49-
ok.highlighted = YES;
50-
ok.bezelStyle = NSBezelStyleRounded;
51-
ok.target = self;
52-
ok.action = @selector(buttonPressed:);
53-
[view addSubview:ok];
54-
[ok.bottomAnchor constraintEqualToAnchor:view.bottomAnchor constant:-25].active = YES;
55-
[ok.rightAnchor constraintEqualToAnchor:view.rightAnchor constant:-25].active = YES;
56-
57-
self.window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 400, 250)
58-
styleMask:NSWindowStyleMaskBorderless
59-
backing:NSBackingStoreBuffered
60-
defer:NO];
61-
self.window.contentView = view;
62-
self.window.defaultButtonCell = ok.cell;
63-
}
64-
return self;
65-
}
66-
67-
- (void)buttonPressed:(id)sender {
68-
[self.window.sheetParent endSheet:self.window];
69-
}
70-
71-
- (void)showWindow:(id)sender {
72-
[self.window makeKeyAndOrderFront:sender];
73-
}
74-
75-
@end
76-
7730
@interface ID_updater : NSPreferencePane <UpdateDelegate, NSURLSessionDownloadDelegate, NSUserNotificationCenterDelegate>
7831

7932
@property (weak) IBOutlet NSTextField *mainLabel;
@@ -235,45 +188,6 @@ - (void)updateAvailable:(NSString *)_available filename:(NSURL *)_filename {
235188
});
236189
}
237190

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-
277191
#pragma mark - Connection delegate
278192

279193
- (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didWriteData:(int64_t)bytesWritten totalBytesWritten:(int64_t)totalBytesWritten totalBytesExpectedToWrite:(int64_t)totalBytesExpectedToWrite {
@@ -292,9 +206,13 @@ - (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTas
292206
[NSFileManager.defaultManager moveItemAtPath:location.path toPath:tmp error:nil];
293207

294208
NSString *volumePath = @"/Volumes/Open-EID";
295-
NSArray *args = @[@"attach", @"-verify", @"-mountpoint", volumePath, tmp];
209+
NSArray *args = @[@"detach", volumePath];
296210
NSTask *task = [NSTask launchedTaskWithLaunchPath:@"/usr/bin/hdiutil" arguments:args];
297211
[task waitUntilExit];
212+
213+
args = @[@"attach", @"-verify", @"-mountpoint", volumePath, tmp];
214+
task = [NSTask launchedTaskWithLaunchPath:@"/usr/bin/hdiutil" arguments:args];
215+
[task waitUntilExit];
298216
if (task.terminationStatus != 0) {
299217
self.infoLabel.stringValue = [NSString stringWithFormat:@"Verify failed, status: %i", task.terminationStatus];
300218
return;
@@ -348,7 +266,7 @@ - (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTas
348266
}
349267

350268
if([signatureType isEqualToString:@"CMS"]) {
351-
if ([self verifyCMSSignature:signature data:data cert:certData])
269+
if ([Updater verifyCMSSignature:signature data:data cert:certData])
352270
[NSTask launchedTaskWithLaunchPath:@"/usr/bin/open" arguments:@[path]];
353271
else
354272
{
@@ -406,42 +324,8 @@ - (IBAction)installUpdate:(id)sender {
406324
}];
407325
}
408326

409-
- (NSString*)versionInfo:(NSString *)pkg {
410-
NSDictionary *list = [NSDictionary dictionaryWithContentsOfFile:[NSString stringWithFormat:@"/var/db/receipts/%@.plist", pkg]];
411-
return list ? list[@"PackageVersion"] : [NSString string];
412-
}
413-
414327
- (IBAction)diagnostics:(id)sender {
415-
NSDictionary *versions = @{
416-
@"DigiDoc4": update.digidoc4,
417-
@"Open-EID": update.baseVersion,
418-
@"ID-Updater": update.updaterVersion,
419-
NSLocalizedString(@"Safari (Extensions) browser plugin", nil): [self versionInfo:@"ee.ria.safari-token-signing"],
420-
NSLocalizedString(@"Safari (NPAPI) browser plugin", nil): [self versionInfo:@"ee.ria.firefox-token-signing"],
421-
NSLocalizedString(@"Chrome/Firefox browser plugin", nil): [self versionInfo:@"ee.ria.chrome-token-signing"],
422-
NSLocalizedString(@"Chrome browser plugin", nil): [self versionInfo:@"ee.ria.token-signing-chrome"],
423-
NSLocalizedString(@"Chrome browser plugin policy", nil): [self versionInfo:@"ee.ria.token-signing-chrome-policy"],
424-
NSLocalizedString(@"Firefox browser plugin", nil): [self versionInfo:@"ee.ria.token-signing-firefox"],
425-
NSLocalizedString(@"Web-eID native component", nil): [self versionInfo:@"eu.web-eid.web-eid"],
426-
NSLocalizedString(@"Safari browser extension (Web-eID)", nil): [self versionInfo:@"eu.web-eid.web-eid-safari"],
427-
NSLocalizedString(@"Chrome browser extension (Web-eID)", nil): [self versionInfo:@"eu.web-eid.web-eid-chrome"],
428-
NSLocalizedString(@"Chrome browser extension policy (Web-eID)", nil): [self versionInfo:@"eu.web-eid.web-eid-chrome-policy"],
429-
NSLocalizedString(@"Firefox browser extension (Web-eID)", nil): [self versionInfo:@"eu.web-eid.web-eid-firefox"],
430-
NSLocalizedString(@"PKCS11 loader", nil): [self versionInfo:@"ee.ria.firefox-pkcs11-loader"],
431-
NSLocalizedString(@"IDEMIA PKCS11 loader", nil): [self versionInfo:@"com.idemia.awp.xpi"],
432-
@"OpenSC": [self versionInfo:@"org.opensc-project.mac"],
433-
@"IDEMIA PKCS11": [self versionInfo:@"com.idemia.awp.pkcs11"],
434-
@"EstEID Tokend": [self versionInfo:@"ee.ria.esteid-tokend"],
435-
@"EstEID CTK Tokend": [self versionInfo:@"ee.ria.esteid-ctk-tokend"],
436-
@"IDEMIA Tokend": [self versionInfo:@"com.idemia.awp.tokend"],
437-
};
438-
NSMutableArray *list = [[NSMutableArray alloc] init];
439-
[versions enumerateKeysAndObjectsUsingBlock:^(id key, id object, BOOL *stop) {
440-
if (object != nil && ((NSString*)object).length != 0)
441-
[list addObject:[NSString stringWithFormat:@"%@ (%@)", key, object]];
442-
}];
443-
self.advancedViewController = [[AdvancedWindowController alloc] initWithText:[list componentsJoinedByString:@"\n"]];
444-
[self.mainView.window beginSheet:self.advancedViewController.window completionHandler:nil];
328+
self.advancedViewController = [[AdvancedWindowController alloc] initWithParent:self.mainView.window];
445329
}
446330

447331
@end

0 commit comments

Comments
 (0)