|
| 1 | +/* |
| 2 | + * GNU AGPL-3.0 License |
| 3 | + * |
| 4 | + * Copyright (c) 2021 - present core.ai . All rights reserved. |
| 5 | + * |
| 6 | + * This program is free software: you can redistribute it and/or modify it under |
| 7 | + * the terms of the GNU Affero General Public License as published by the Free |
| 8 | + * Software Foundation, either version 3 of the License, or (at your option) any later version. |
| 9 | + * |
| 10 | + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 11 | + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 12 | + * See the GNU Affero General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU Affero General Public License |
| 15 | + * along with this program. If not, see https://opensource.org/licenses/AGPL-3.0. |
| 16 | + * |
| 17 | + */ |
| 18 | + |
| 19 | +/*global logger*/ |
| 20 | + |
| 21 | +/** |
| 22 | + * Shared Login Service |
| 23 | + * |
| 24 | + * This module contains shared login service functionality used by both |
| 25 | + * browser and desktop login implementations, including entitlements management. |
| 26 | + */ |
| 27 | + |
| 28 | +define(function (require, exports, module) { |
| 29 | + const KernalModeTrust = window.KernalModeTrust; |
| 30 | + if(!KernalModeTrust){ |
| 31 | + // integrated extensions will have access to kernal mode, but not external extensions |
| 32 | + throw new Error("manage-licenses should have access to KernalModeTrust. Cannot boot without trust ring"); |
| 33 | + } |
| 34 | + |
| 35 | + async function _getLinuxDeviceID() { |
| 36 | + const LINUX_DEVICE_ID_FILE = Phoenix.VFS.getTauriVirtualPath('/etc/machine-id'); |
| 37 | + const result = await Phoenix.VFS.readFileResolves(LINUX_DEVICE_ID_FILE, 'utf8'); |
| 38 | + if(result.error || !result.data) { |
| 39 | + logger.reportError(result.error, `Failed to read machine-id file for licensing`); |
| 40 | + return null; |
| 41 | + } |
| 42 | + return KernalModeTrust.generateDataSignature(result.data.trim()); // \n and spaces are trimmed, just id please |
| 43 | + } |
| 44 | + |
| 45 | + async function _getDeviceID() { |
| 46 | + if(!Phoenix.isNativeApp) { |
| 47 | + // We only grant device licenses to desktop apps. Browsers cannot be uniquely device identified obviously. |
| 48 | + return null; |
| 49 | + } |
| 50 | + switch (Phoenix.platform) { |
| 51 | + case 'linux': return _getLinuxDeviceID(); |
| 52 | + default: return null; |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + async function showManageLicensesDialog() { |
| 57 | + alert(`machine id is: ${await _getDeviceID()}`); |
| 58 | + } |
| 59 | + |
| 60 | + exports.showManageLicensesDialog = showManageLicensesDialog; |
| 61 | +}); |
0 commit comments