Skip to content

Commit 2853a80

Browse files
authored
Merge pull request #2787 from UltimateHackingKeyboard/feat-handle-invalid-signature
feat: show invalid codesign signature alert
2 parents ac5c486 + 45f36b2 commit 2853a80

File tree

10 files changed

+98
-10
lines changed

10 files changed

+98
-10
lines changed

packages/uhk-agent/src/electron-main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ async function createWindow() {
118118

119119
setMenu(win, options.devtools);
120120
deviceService = new DeviceService(logger, win, uhkHidDeviceService, uhkOperations, options, packagesDir);
121-
appUpdateService = new AppUpdateService(logger, win, app);
121+
appUpdateService = new AppUpdateService(logger, win, options);
122122
appService = new AppService(logger, win, deviceService, options, packagesDir);
123123
sudoService = new SudoService(logger, options, deviceService, packagesDir);
124124
// and load the index.html of the app.

packages/uhk-agent/src/services/app-update.service.ts

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,15 @@ import { autoUpdater } from 'electron-updater';
33
import { UpdateInfo, ProgressInfo } from 'builder-util-runtime';
44
import isDev from 'electron-is-dev';
55
import storage from 'electron-settings';
6-
7-
import { ApplicationSettings, IpcEvents, LogService } from 'uhk-common';
6+
import { inspect } from 'node:util';
7+
8+
import {
9+
ApplicationSettings,
10+
CommandLineArgs,
11+
ERR_UPDATER_INVALID_SIGNATURE,
12+
IpcEvents,
13+
LogService,
14+
} from 'uhk-common';
815
import { MainServiceBase } from './main-service-base';
916
import { getUpdaterLoggerService } from '../util';
1017

@@ -16,13 +23,20 @@ export class AppUpdateService extends MainServiceBase {
1623

1724
constructor(protected logService: LogService,
1825
protected win: Electron.BrowserWindow,
19-
private app: Electron.App) {
26+
private options: CommandLineArgs) {
2027
super(logService, win);
2128

2229
autoUpdater.logger = getUpdaterLoggerService(logService);
2330

2431
this.initListeners();
2532
logService.misc('[AppUpdateService] init success');
33+
34+
if (options['simulate-invalid-codesign-signature']) {
35+
logService.misc('[AppUpdateService] init simulate invalid codesign timer');
36+
setTimeout(() => {
37+
this.sendIpcToWindow(IpcEvents.autoUpdater.autoUpdateError, ERR_UPDATER_INVALID_SIGNATURE);
38+
}, 10000)
39+
}
2640
}
2741

2842
private initListeners() {
@@ -44,11 +58,17 @@ export class AppUpdateService extends MainServiceBase {
4458
}
4559
});
4660

47-
autoUpdater.on('error', (ev: any, err: string) => {
48-
this.logService.error('[AppUpdateService] error', err);
61+
autoUpdater.on('error', (error: Error, message: string) => {
62+
this.logService.error('[AppUpdateService] error', inspect(error));
63+
this.logService.error('[AppUpdateService] error message', message);
64+
if ((error as NodeJS.ErrnoException)?.code === ERR_UPDATER_INVALID_SIGNATURE) {
65+
this.sendIpcToWindow(IpcEvents.autoUpdater.autoUpdateError, ERR_UPDATER_INVALID_SIGNATURE);
66+
return
67+
}
68+
4969
let msg = 'Electron updater error';
50-
if (err) {
51-
msg = err.substr(0, 100);
70+
if (message) {
71+
msg = message.substring(0, 100);
5272
}
5373

5474
this.sendIpcToWindow(IpcEvents.autoUpdater.autoUpdateError, msg);

packages/uhk-agent/src/util/command-line.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const optionDefinitions: commandLineArgs.OptionDefinition[] = [
2121
{ name: 'reenumerate-and-exit', type: String },
2222
{ name: 'report-id', type: Number },
2323
{ name: 'serial-number', type: String },
24+
{ name: 'simulate-invalid-codesign-signature', type: Boolean },
2425
{ name: 'spe', type: Boolean }, // simulate privilege escalation error
2526
{ name: 'usb-interface', type: Number },
2627
{ name: 'usb-non-blocking', type: Boolean },
@@ -120,6 +121,11 @@ const sections: commandLineUsage.Section[] = [
120121
description: 'Use the specified USB device that serial-number is matching.',
121122
type: String
122123
},
124+
{
125+
name: 'simulate-invalid-codesign-signature',
126+
description: 'Agent shows the invalid code sign signature error 10 seconds after start',
127+
type: Boolean
128+
},
123129
{
124130
name: 'spe',
125131
description: 'Simulate privilege escalation error',

packages/uhk-common/src/models/command-line-args.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ export interface CommandLineArgs extends DeviceIdentifier {
8383
* Report Id that used for USB communication
8484
*/
8585
'report-id'?: number;
86+
87+
/**
88+
* Agent shows the invalid code sign signature error 10 seconds after start
89+
*/
90+
'simulate-invalid-codesign-signature'?: boolean;
8691
/**
8792
* simulate privilege escalation error
8893
*/

packages/uhk-common/src/util/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ export namespace Constants {
77
}
88

99
export const UHK_EEPROM_SIZE = 32768;
10+
export const ERR_UPDATER_INVALID_SIGNATURE = 'ERR_UPDATER_INVALID_SIGNATURE'

packages/uhk-web/src/app/app.component.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,18 @@
6565
<out-of-space-warning *ngIf="outOfSpaceWarning.show"
6666
[@showOutOfSpaceWarning]
6767
[state]="outOfSpaceWarning"></out-of-space-warning>
68+
<ng-template #manuallyUpdateNotification>
69+
<p class="notifier__notification-message">
70+
Agent's digital signature has changed. Please <a href="https://uhk.io/agent" class="alert-link" externalUrl>update it manually</a> this time. Agent will auto-update afterward.
71+
</p>
72+
<button
73+
class="notifier__notification-button"
74+
type="button"
75+
title="dismiss"
76+
(click)="dismissUpdateErrorNotification()"
77+
>
78+
<svg class="notifier__notification-button-icon" viewBox="0 0 24 24" width="20" height="20">
79+
<path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z" />
80+
</svg>
81+
</button>
82+
</ng-template>

packages/uhk-web/src/app/app.component.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import { Component, HostListener, OnDestroy, ChangeDetectorRef, ViewChild } from '@angular/core';
22
import { ActivatedRoute, Event, NavigationEnd, Router } from '@angular/router';
33
import { animate, style, transition, trigger } from '@angular/animations';
4+
import { NotifierService } from '@ert78gb/angular-notifier';
45
import { faPuzzlePiece, faArrowUp } from '@fortawesome/free-solid-svg-icons';
6+
import { Actions, ofType } from '@ngrx/effects';
57
import { SplitGutterInteractionEvent } from 'angular-split';
68
import { Observable, Subscription } from 'rxjs';
79
import { Action, Store } from '@ngrx/store';
10+
import { ERR_UPDATER_INVALID_SIGNATURE } from 'uhk-common';
811

12+
import { ActionTypes as AppUpdateActionTypes } from './store/actions/app-update.action';
913
import { DoNotUpdateAppAction, UpdateAppAction } from './store/actions/app-update.action';
1014
import { EnableUsbStackTestAction, UpdateFirmwareAction } from './store/actions/device';
1115
import {
@@ -102,6 +106,7 @@ import { SecondSideMenuContainerComponent } from './components/side-menu';
102106
})
103107
export class MainAppComponent implements OnDestroy {
104108
@ViewChild(SecondSideMenuContainerComponent) secondarySideMenuContainer: SecondSideMenuContainerComponent;
109+
@ViewChild('manuallyUpdateNotification', { static: true }) manuallyUpdateNotificationTmpl;
105110

106111
donglePairingState: DonglePairingState;
107112
newPairedDevicesState: BleAddingState;
@@ -120,6 +125,7 @@ export class MainAppComponent implements OnDestroy {
120125
bottom: 0
121126
};
122127
statusBuffer: string;
128+
private actionsSubscription: Subscription;
123129
private donglePairingStateSubscription: Subscription;
124130
private newPairedDevicesStateSubscription: Subscription;
125131
private errorPanelHeightSubscription: Subscription;
@@ -136,7 +142,22 @@ export class MainAppComponent implements OnDestroy {
136142
constructor(private store: Store<AppState>,
137143
private route: ActivatedRoute,
138144
private router: Router,
139-
private cdRef: ChangeDetectorRef) {
145+
private cdRef: ChangeDetectorRef,
146+
private actions$: Actions,
147+
private notificationService: NotifierService,
148+
) {
149+
this.actionsSubscription = actions$.pipe(
150+
ofType(AppUpdateActionTypes.InvalidCodesignSignature)
151+
)
152+
.subscribe(() => {
153+
notificationService.show({
154+
message: '',
155+
type: 'info',
156+
template: this.manuallyUpdateNotificationTmpl,
157+
id: ERR_UPDATER_INVALID_SIGNATURE,
158+
})
159+
})
160+
140161
this.donglePairingStateSubscription = store.select(getDonglePairingState)
141162
.subscribe(data => {
142163
this.donglePairingState = data;
@@ -211,6 +232,7 @@ export class MainAppComponent implements OnDestroy {
211232
}
212233

213234
ngOnDestroy(): void {
235+
this.actionsSubscription.unsubscribe();
214236
this.donglePairingStateSubscription.unsubscribe();
215237
this.newPairedDevicesStateSubscription.unsubscribe();
216238
this.errorPanelHeightSubscription.unsubscribe();
@@ -263,6 +285,10 @@ export class MainAppComponent implements OnDestroy {
263285
this.store.dispatch(new CloseErrorPanelAction());
264286
}
265287

288+
dismissUpdateErrorNotification(): void {
289+
this.notificationService.hide(ERR_UPDATER_INVALID_SIGNATURE);
290+
}
291+
266292
showErrorPanel(): void {
267293
this.store.dispatch(new ShowErrorPanelAction());
268294
}

packages/uhk-web/src/app/store/actions/app-update.action.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { UpdateInfo } from '../../models/update-info';
44

55
export enum ActionTypes {
66
ForceUpdate = '[app-update] force update',
7+
InvalidCodesignSignature = '[app-update] invalid codesign signature',
78
UpdateAvailable = '[app-update] update available',
89
UpdateApp = '[app-update] update app',
910
DoNotUpdateApp = '[app-update] do not update app',
@@ -16,6 +17,10 @@ export class ForceUpdateAction implements Action {
1617
type = ActionTypes.ForceUpdate;
1718
}
1819

20+
export class InvalidCodesignSignatureAction implements Action {
21+
type = ActionTypes.InvalidCodesignSignature;
22+
}
23+
1924
export class UpdateAvailableAction implements Action {
2025
type = ActionTypes.UpdateAvailable;
2126
}
@@ -48,6 +53,7 @@ export class UpdateErrorAction implements Action {
4853

4954
export type Actions
5055
= UpdateAvailableAction
56+
| InvalidCodesignSignatureAction
5157
| UpdateAppAction
5258
| DoNotUpdateAppAction
5359
| UpdateDownloadedAction

packages/uhk-web/src/app/store/effects/app-update.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import { Actions, createEffect, ofType } from '@ngrx/effects';
44
import { EMPTY } from 'rxjs';
55
import { first, map, tap, withLatestFrom } from 'rxjs/operators';
66

7-
import { LogService, NotificationType } from 'uhk-common';
7+
import { ERR_UPDATER_INVALID_SIGNATURE, LogService, NotificationType } from 'uhk-common';
88

99
import {
1010
ActionTypes,
1111
ForceUpdateAction,
12+
InvalidCodesignSignatureAction,
1213
UpdateAppAction,
1314
UpdateAvailableAction,
1415
UpdateErrorAction
@@ -74,6 +75,10 @@ export class AppUpdateEffect {
7475
ofType<UpdateErrorAction>(ActionTypes.UpdateError),
7576
map(action => action.payload),
7677
map((message: string) => {
78+
if (message === ERR_UPDATER_INVALID_SIGNATURE) {
79+
return new InvalidCodesignSignatureAction();
80+
}
81+
7782
return new ShowNotificationAction({
7883
type: NotificationType.Error,
7984
message

packages/uhk-web/src/styles/_global.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,3 +321,7 @@ mwl-confirmation-popover-window {
321321
cursor: not-allowed;
322322
}
323323
}
324+
325+
.alert-link {
326+
text-decoration: underline;
327+
}

0 commit comments

Comments
 (0)