creating browser socket in a group container on macOS

This commit is contained in:
antelle 2021-04-15 20:38:13 +02:00
parent dc5ada1c04
commit 566e2fb35d
No known key found for this signature in database
GPG Key ID: 63C9777AAB7C563C
8 changed files with 45 additions and 13 deletions

View File

@ -47,7 +47,8 @@ module.exports = function (grunt) {
const webpackOptions = {
date,
beta: !!grunt.option('beta'),
sha
sha,
appleTeamId: getCodeSignConfig()?.teamId
};
const windowsAppVersionString = {
@ -755,7 +756,7 @@ module.exports = function (grunt) {
cmakeConfigure: ['-DCMAKE_OSX_ARCHITECTURES=x86_64']
},
files: {
'tmp/desktop/KeeWeb-darwin-x64/KeeWeb.app/Contents/MacOS/keeweb-native-messaging-host':
'tmp/desktop/KeeWeb-darwin-x64/KeeWeb.app/Contents/MacOS/util/keeweb-native-messaging-host':
'extension/native-messaging-host'
}
},
@ -765,7 +766,7 @@ module.exports = function (grunt) {
cmakeConfigure: ['-DCMAKE_OSX_ARCHITECTURES=arm64']
},
files: {
'tmp/desktop/KeeWeb-darwin-arm64/KeeWeb.app/Contents/MacOS/keeweb-native-messaging-host':
'tmp/desktop/KeeWeb-darwin-arm64/KeeWeb.app/Contents/MacOS/util/keeweb-native-messaging-host':
'extension/native-messaging-host'
}
},

View File

@ -55,9 +55,21 @@ const BrowserExtensionConnector = {
window.removeEventListener('message', this.browserWindowMessage);
},
isSocketNameTooLong(socketName) {
const maxLength = process.platform === 'win32' ? 256 : 104;
return socketName.length > maxLength;
},
startDesktopAppListener() {
Launcher.closeOldBrowserExtensionSocket(() => {
Launcher.prepareBrowserExtensionSocket(() => {
const sockName = Launcher.getBrowserExtensionSocketName();
if (this.isSocketNameTooLong(sockName)) {
logger.error(
"Socket name is too big, browser connection won't be possible, probably OS username is very long.",
sockName
);
return;
}
const { createServer } = Launcher.req('net');
this.connectedSockets = [];
this.connectedSocketState = new WeakMap();

View File

@ -290,16 +290,23 @@ const Launcher = {
return this.getMainWindow().isMaximized();
},
getBrowserExtensionSocketName() {
const userInfo = this.req('os').userInfo();
if (process.platform === 'win32') {
return `\\\\.\\pipe\\keeweb-browser-${userInfo.username}`;
const { username, uid } = this.req('os').userInfo();
if (process.platform === 'darwin') {
const teamId = RuntimeInfo.appleTeamId;
return `/Users/${username}/Library/Group Containers/${teamId}.keeweb/browser.sock`;
} else if (process.platform === 'win32') {
return `\\\\.\\pipe\\keeweb-browser-${username}`;
} else {
const sockFileName = `keeweb-browser-${userInfo.uid}.sock`;
const sockFileName = `keeweb-browser-${uid}.sock`;
return this.joinPath(this.remoteApp().getPath('temp'), sockFileName);
}
},
closeOldBrowserExtensionSocket(done) {
if (process.platform === 'win32') {
prepareBrowserExtensionSocket(done) {
if (process.platform === 'darwin') {
const dir = this.req('path').dirname(this.getBrowserExtensionSocketName());
const fs = this.req('fs');
fs.mkdir(dir, () => done());
} else if (process.platform === 'win32') {
done();
} else {
this.deleteFile(this.getBrowserExtensionSocketName(), done);

View File

@ -3,7 +3,8 @@ const RuntimeInfo = {
beta: !!'@@BETA',
buildDate: '@@DATE',
commit: '@@COMMIT',
devMode: '@@DEVMODE'
devMode: '@@DEVMODE',
appleTeamId: '@@APPLE_TEAM_ID'
};
export { RuntimeInfo };

View File

@ -130,7 +130,8 @@ function config(options) {
search: /@@COMMIT/g,
replace: options.sha
},
{ search: /@@DEVMODE/g, replace: devMode ? '1' : '' }
{ search: /@@DEVMODE/g, replace: devMode ? '1' : '' },
{ search: /@@APPLE_TEAM_ID/g, replace: options.appleTeamId }
]
}
},

View File

@ -204,6 +204,9 @@ std::string keeweb_pipe_name() {
} else {
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32)
pipe_name = "\\\\.\\pipe\\keeweb-browser-" + std::string{user_info.username};
#elif __APPLE__
pipe_name = "/Users/" + std::string{user_info.username} +
"/Library/Group Containers/3LE7JZ657W.keeweb/browser.sock";
#else
pipe_name = std::filesystem::temp_directory_path() /
("keeweb-browser-" + std::to_string(user_info.uid) + ".sock");

View File

@ -11,7 +11,10 @@ describe('KeeWeb extension native module host', function () {
const userInfo = os.userInfo();
let sockPath;
let hostPath;
if (process.platform === 'win32') {
if (process.platform === 'darwin') {
sockPath = `/Users/${userInfo.username}/Library/Group Containers/3LE7JZ657W.keeweb/browser.sock`;
hostPath = 'build/keeweb-native-messaging-host';
} else if (process.platform === 'win32') {
sockPath = `\\\\.\\pipe\\keeweb-browser-${userInfo.username}`;
hostPath = 'build\\Debug\\keeweb-native-messaging-host.exe';
} else {

View File

@ -12,6 +12,10 @@
<array>
<string>3LE7JZ657W.net.antelle.keeweb</string>
</array>
<key>com.apple.security.application-groups</key>
<array>
<string>3LE7JZ657W.keeweb</string>
</array>
<key>com.apple.application-identifier</key>
<string>3LE7JZ657W.net.antelle.keeweb</string>
<key>com.apple.developer.team-identifier</key>