Skip to content

Commit

Permalink
refactor(core): migrate installations to new certificates
Browse files Browse the repository at this point in the history
Migrate installations to new certificates, with device IDs
following the protocol v8 constraints.
  • Loading branch information
andyholmes committed Jan 18, 2025
1 parent a16d138 commit 8efb3ae
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/service/daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import system from 'system';
import './init.js';

import Config from '../config.js';
import Device from './device.js';
import Manager from './manager.js';
import * as ServiceUI from './ui/service.js';

Expand All @@ -41,10 +42,49 @@ const Service = GObject.registerClass({
GLib.set_prgname('gsconnect');
GLib.set_application_name('GSConnect');

// TODO: remove after a reasonable period of time
this._migrateConfiguration();

// Command-line
this._initOptions();
}

_migrateConfiguration() {
if (Device.validateId(this.settings.get_string('id')))
return;

// Remove the old certificate, serving as the single source of truth
// for the device ID
try {
Gio.File.new_build_filenamev([Config.CONFIGDIR, 'certificate.pem'])
.delete(null);
Gio.File.new_build_filenamev([Config.CONFIGDIR, 'private.pem'])
.delete(null);
} catch {
// Silence errors
}

// For each device, remove it entirely if it violates the device ID
// constraints, otherwise mark it unpaired to preserve the settings.
for (const deviceId of this.settings.get_strv('devices')) {
if (!Device.validateId(deviceId)) {
this._removeDevice(deviceId);
} else {
const settings = new Gio.Settings({
settings_schema: Config.GSCHEMA.lookup(
'org.gnome.Shell.Extensions.GSConnect.Device',
true
),
path: `/org/gnome/shell/extensions/gsconnect/device/${deviceId}/`,
});
settings.set_boolean('paired', false);
}
}

// Finally, reset the service ID to trigger re-generation.
this.settings.reset('id');
}

get settings() {
if (this._settings === undefined) {
this._settings = new Gio.Settings({
Expand Down

0 comments on commit 8efb3ae

Please sign in to comment.