Skip to content

Commit

Permalink
Merge pull request #688 from prey/apple-silicon
Browse files Browse the repository at this point in the history
macOS universal installer
  • Loading branch information
SoraKenji authored Dec 13, 2022
2 parents d821c0c + 175e9ac commit f672258
Show file tree
Hide file tree
Showing 20 changed files with 2,883 additions and 1,801 deletions.
257 changes: 146 additions & 111 deletions lib/agent/plugins/control-panel/secure.js
Original file line number Diff line number Diff line change
@@ -1,79 +1,92 @@
var JSEncrypt = require('node-jsencrypt'),
cp = require('child_process'),
keys = require('./api/keys'),
devices = require('./api/devices'),
common = require('./../../common'),
storage = require('./../../utils/storage'),
system = require('./../../../system'),
account = require('./../../../conf/account'),
exec = cp.exec,
run_as_user = system.run_as_logged_user,
logger = common.logger.prefix('config'),
os_name = process.platform.replace('darwin', 'mac').replace('win32', 'windows');
var JSEncrypt = require('node-jsencrypt'),
cp = require('child_process'),
keys = require('./api/keys'),
devices = require('./api/devices'),
common = require('./../../common'),
storage = require('./../../utils/storage'),
system = require('./../../../system'),
account = require('./../../../conf/account'),
exec = cp.exec,
run_as_user = system.run_as_logged_user,
logger = common.logger.prefix('config'),
os_name = process.platform
.replace('darwin', 'mac')
.replace('win32', 'windows');

var crypt,
data,
private_key,
public_key,
public_keys = {},
decoded_key;

var protocol = common.config.get('control-panel.protocol'),
host = common.config.get('control-panel.host'),
panel_host = host == 'solid.preyproject.com' ? 'panel.preyproject.com' : host
base = protocol + '://' + panel_host,
auth_url = base + '/auth/configuration/start';

var notify_linked = function(hardware) {
auth_url,
private_key,
public_key,
public_keys = {},
base;

var protocol = common.config.get('control-panel.protocol'),
host = common.config.get('control-panel.host'),
panel_host = host == 'solid.preyproject.com' ? 'panel.preyproject.com' : host;
(base = protocol + '://' + panel_host),
(auth_url = base + '/auth/configuration/start');

var notify_linked = function (hardware) {
if (!common.helpers.running_on_background()) return;
var data = {
"message": {
"status" : "ok",
"token" : public_keys.b64_formatted,
"api_key" : keys.get().api,
"device_key": keys.get().device,
"version" : common.version,
"hardware" : hardware
}
}
setTimeout(function() {
devices.post_sso_status(data, function(err) {
if (err) logger.error("Unable to notify success status: " + err.message)
})
message: {
status: 'ok',
token: public_keys.b64_formatted,
api_key: keys.get().api,
device_key: keys.get().device,
version: common.version,
hardware: hardware,
},
};
setTimeout(function () {
devices.post_sso_status(data, function (err) {
if (err) logger.error('Unable to notify success status: ' + err.message);
});
}, 2000);
}
};

var notify_error = function() {
var notify_error = function () {
if (!common.helpers.running_on_background()) return;
var data = {
"message": {
"status" : "error",
"token" : public_keys.b64_formatted
}
}
setTimeout(function() {
devices.post_sso_status(data, function(err) {
if (err) logger.error("Unable to notify error status: " + err.message)
})
message: {
status: 'error',
token: public_keys.b64_formatted,
},
};
setTimeout(function () {
devices.post_sso_status(data, function (err) {
if (err) logger.error('Unable to notify error status: ' + err.message);
});
}, 2000);
}

var format_public_key = function(public_key, cb) {
public_keys.default = public_key;
public_keys.formatted = public_key.replace(/\n/g,'').split('BEGIN PUBLIC KEY-----').pop().split('-----END').shift();
public_keys.b64_formatted = Buffer.from(public_keys.formatted).toString('base64');
};

var format_public_key = function (public_key, cb) {
public_keys.default = public_key;
public_keys.formatted = public_key
.replace(/\n/g, '')
.split('BEGIN PUBLIC KEY-----')
.pop()
.split('-----END')
.shift();
public_keys.b64_formatted = Buffer.from(public_keys.formatted).toString(
'base64'
);

return cb();
}
};

exports.generate_keys = function(cb) {
storage.do('all', {type: 'keys'}, (err, values) => {
if (err || !values) return cb(new Error("Error reading stored security keys"));
exports.generate_keys = function (cb) {
storage.do('all', { type: 'keys' }, (err, values) => {
if (err || !values)
return cb(new Error('Error reading stored security keys'));

// Read stored keys if they exists
if (values.some(value => value.id === "public_key") && values.some(value => value.id === "private_key")) {
var private_key_b64 = values.find(x => x.id == 'private_key').value;
var public_key_b64 = values.find(x => x.id == 'public_key').value;
if (
values.some((value) => value.id === 'public_key') &&
values.some((value) => value.id === 'private_key')
) {
var private_key_b64 = values.find((x) => x.id == 'private_key').value;
var public_key_b64 = values.find((x) => x.id == 'public_key').value;

private_key = Buffer.from(private_key_b64, 'base64').toString();
public_key = Buffer.from(public_key_b64, 'base64').toString();
Expand All @@ -84,102 +97,124 @@ exports.generate_keys = function(cb) {

format_public_key(public_key, cb);

// Create and store new keys
// Create and store new keys
} else {
crypt = new JSEncrypt()
crypt = new JSEncrypt();
private_key = crypt.getPrivateKey();
public_key = crypt.getPublicKey();

crypt.setPublicKey(public_key);
crypt.setPrivateKey(private_key);

storage.do('set', {type: 'keys', id: 'public_key', data: {value: Buffer.from(public_key).toString('base64')}}, (err) => {
if (err) return cb(new Error("Error storing public security key"));
storage.do('set', {type: 'keys', id: 'private_key', data: {value: Buffer.from(private_key).toString('base64')}}, (err) => {
if (err) return cb(new Error("Error storing private security key"));
format_public_key(public_key, cb);
})
})
storage.do(
'set',
{
type: 'keys',
id: 'public_key',
data: { value: Buffer.from(public_key).toString('base64') },
},
(err) => {
if (err) return cb(new Error('Error storing public security key'));
storage.do(
'set',
{
type: 'keys',
id: 'private_key',
data: { value: Buffer.from(private_key).toString('base64') },
},
(err) => {
if (err)
return cb(new Error('Error storing private security key'));
format_public_key(public_key, cb);
}
);
}
);
}
});
}
};

exports.open_config = function(device_key, cb) {
setTimeout(function() {
var lang = common.system.lang || 'en',
child_err;
exports.open_config = function (device_key, cb) {
setTimeout(function () {
var lang = common.system.lang || 'en';

exports.generate_keys(function(err) {
exports.generate_keys(function (err) {
if (err) return cb(err);
var keys = {
device_key : device_key,
device_key: device_key,
client_version: common.version,
public_key : public_key,
language : lang
}
public_key: public_key,
language: lang,
};

var encoded_keys = Buffer.from(JSON.stringify(keys, null, 0)).toString('base64'),
link = auth_url + '/' + encoded_keys;
var encoded_keys = Buffer.from(JSON.stringify(keys, null, 0)).toString(
'base64'
),
link = auth_url + '/' + encoded_keys;

if (os_name == 'windows')
return exec('rundll32 url.dll,FileProtocolHandler ' + link, cb);
else if (os_name == 'mac')
return run_as_user('open', [link], cb);
else if (os_name == 'mac') return run_as_user('open', [link], cb);
// Open the logged user's default browser, the prey user doesn't have one
// For linux
cb();
system.get_logged_user((error, logged_user) => {
if(error) return;

exec(`sudo -u ${logged_user} ${common.root_path}/lib/agent/utils/openwebbrowser.sh ${link} &`,
{
timeout: 200
}, (err, stderr, stdout) => {
if(err || stderr) return;
process.exit();
});
if (error) return;

exec(
`sudo -u ${logged_user} ${common.root_path}/lib/agent/utils/openwebbrowser.sh ${link} &`,
{
timeout: 200,
},
(err, stderr) => {
if (err || stderr) return;
process.exit();
}
);
});
return;
});
}, 3000);
}
};

exports.reset_keys = function(cb) {
storage.do('del', {type: 'keys', id: 'private_key'}, (err) => {
exports.reset_keys = function (cb) {
storage.do('del', { type: 'keys', id: 'private_key' }, (err) => {
if (err) return cb(err);
storage.do('del', {type: 'keys', id: 'private_key'}, (err) => {
storage.do('del', { type: 'keys', id: 'private_key' }, (err) => {
if (err) return cb(err);
public_keys = {};
exports.generate_keys(cb);
})
})
}
});
});
};

exports.decrypt_and_notify = function(encrypted_key, cb) {
exports.decrypt_and_notify = function (encrypted_key, cb) {
var decrypted_key;

try {
decrypted_key = crypt.decrypt(encrypted_key);
} catch(e) {
var err = new Error("Unable to decrypt api key: " + e);
} catch (e) {
var err = new Error('Unable to decrypt api key: ' + e);
logger.error(err.message);
notify_error();
return cb(err)
return cb(err);
}

if (decrypted_key) {
var key = { '-a': decrypted_key }
account.authorize(key, function(err, out) {
var key = { '-a': decrypted_key };
account.authorize(key, function (err) {
return cb && cb(err);
});
} else {
notify_error();
var err = new Error("Decryted api key unavailable");
err = new Error('Decryted api key unavailable');
logger.error(err.message);
return cb(err);
}
}
};

exports.public_keys = function() { return public_keys; };
exports.public_keys = function () {
return public_keys;
};
exports.notify_linked = notify_linked;
exports.notify_error = notify_error;
exports.notify_error = notify_error;
Binary file removed lib/agent/utils/Prey.app/Contents/CodeResources
Binary file not shown.
16 changes: 9 additions & 7 deletions lib/agent/utils/Prey.app/Contents/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>BuildMachineOSBuild</key>
<string>18G103</string>
<string>21G115</string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
Expand Down Expand Up @@ -31,17 +31,19 @@
<key>DTCompiler</key>
<string>com.apple.compilers.llvm.clang.1_0</string>
<key>DTPlatformBuild</key>
<string>11A1027</string>
<string>14A400</string>
<key>DTPlatformName</key>
<string>macosx</string>
<key>DTPlatformVersion</key>
<string>GM</string>
<string>12.3</string>
<key>DTSDKBuild</key>
<string>19A547</string>
<string>21E226</string>
<key>DTSDKName</key>
<string>macosx10.15</string>
<string>macosx12.3</string>
<key>DTXcode</key>
<string>1110</string>
<string>1401</string>
<key>DTXcodeBuild</key>
<string>11A1027</string>
<string>14A400</string>
<key>LSMinimumSystemVersion</key>
<string>10.7</string>
<key>LSUIElement</key>
Expand Down
Binary file modified lib/agent/utils/Prey.app/Contents/MacOS/Prey
Binary file not shown.
Binary file modified lib/agent/utils/Prey.app/Contents/Resources/AppIcon.icns
Binary file not shown.
Binary file modified lib/agent/utils/Prey.app/Contents/Resources/Assets.car
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit f672258

Please sign in to comment.