Skip to content

Commit

Permalink
try to remove password storage logic
Browse files Browse the repository at this point in the history
  • Loading branch information
pompurin404 committed Oct 16, 2024
1 parent 636a59e commit 713b133
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 19 deletions.
4 changes: 2 additions & 2 deletions aur/mihomo-party-bin/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ sha256sums_aarch64=('8cd7398b8fc1cd70d41e386af9995cbddc1043d9018391c29f056f14357
package() {
bsdtar -xf data.tar.xz -C "${pkgdir}/"
chmod +x ${pkgdir}/opt/mihomo-party/mihomo-party
chmod +x ${pkgdir}/opt/mihomo-party/resources/sidecar/mihomo
chmod +x ${pkgdir}/opt/mihomo-party/resources/sidecar/mihomo-alpha
chmod +sx ${pkgdir}/opt/mihomo-party/resources/sidecar/mihomo
chmod +sx ${pkgdir}/opt/mihomo-party/resources/sidecar/mihomo-alpha
install -Dm755 "${srcdir}/${_pkgname}.sh" "${pkgdir}/usr/bin/${_pkgname}"
sed -i '3s!/opt/mihomo-party/mihomo-party!mihomo-party!' "${pkgdir}/usr/share/applications/${_pkgname}.desktop"

Expand Down
4 changes: 2 additions & 2 deletions aur/mihomo-party-electron-bin/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ package() {
asar extract $srcdir/opt/mihomo-party/resources/app.asar ${pkgdir}/opt/mihomo-party
cp -r $srcdir/opt/mihomo-party/resources/sidecar ${pkgdir}/opt/mihomo-party/resources/
cp -r $srcdir/opt/mihomo-party/resources/files ${pkgdir}/opt/mihomo-party/resources/
chmod +x ${pkgdir}/opt/mihomo-party/resources/sidecar/mihomo
chmod +x ${pkgdir}/opt/mihomo-party/resources/sidecar/mihomo-alpha
chmod +sx ${pkgdir}/opt/mihomo-party/resources/sidecar/mihomo
chmod +sx ${pkgdir}/opt/mihomo-party/resources/sidecar/mihomo-alpha
install -Dm755 "${srcdir}/${_pkgname}.sh" "${pkgdir}/usr/bin/${_pkgname}"
install -Dm644 "${_pkgname}.desktop" "${pkgdir}/usr/share/applications/${_pkgname}.desktop"
install -Dm644 "${pkgdir}/opt/mihomo-party/resources/icon.png" "${pkgdir}/usr/share/icons/hicolor/512x512/apps/${_pkgname}.png"
Expand Down
4 changes: 2 additions & 2 deletions aur/mihomo-party-electron/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ package() {
asar extract $srcdir/${_pkgname}-${pkgver}/dist/linux-unpacked/resources/app.asar ${pkgdir}/opt/mihomo-party
cp -r $srcdir/${_pkgname}-${pkgver}/extra/sidecar ${pkgdir}/opt/mihomo-party/resources/
cp -r $srcdir/${_pkgname}-${pkgver}/extra/files ${pkgdir}/opt/mihomo-party/resources/
chmod +x ${pkgdir}/opt/mihomo-party/resources/sidecar/mihomo
chmod +x ${pkgdir}/opt/mihomo-party/resources/sidecar/mihomo-alpha
chmod +sx ${pkgdir}/opt/mihomo-party/resources/sidecar/mihomo
chmod +sx ${pkgdir}/opt/mihomo-party/resources/sidecar/mihomo-alpha
install -Dm755 "${_pkgname}.sh" "${pkgdir}/usr/bin/${_pkgname}"
install -Dm644 "${_pkgname}.desktop" "${pkgdir}/usr/share/applications/${_pkgname}.desktop"
install -Dm644 "${pkgdir}/opt/mihomo-party/resources/icon.png" "${pkgdir}/usr/share/icons/hicolor/512x512/apps/${_pkgname}.png"
Expand Down
4 changes: 2 additions & 2 deletions aur/mihomo-party-git/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ package() {
bsdtar -xf mihomo-party-linux-$(jq '.version' $srcdir/${_pkgname}/package.json | tr -d 'v"')*.deb
bsdtar -xf data.tar.xz -C "${pkgdir}/"
chmod +x ${pkgdir}/opt/mihomo-party/mihomo-party
chmod +x ${pkgdir}/opt/mihomo-party/resources/sidecar/mihomo
chmod +x ${pkgdir}/opt/mihomo-party/resources/sidecar/mihomo-alpha
chmod +sx ${pkgdir}/opt/mihomo-party/resources/sidecar/mihomo
chmod +sx ${pkgdir}/opt/mihomo-party/resources/sidecar/mihomo-alpha
install -Dm755 "${srcdir}/../${_pkgname}.sh" "${pkgdir}/usr/bin/${_pkgname}"
sed -i '3s!/opt/mihomo-party/mihomo-party!mihomo-party!' "${pkgdir}/usr/share/applications/${_pkgname}.desktop"

Expand Down
4 changes: 2 additions & 2 deletions aur/mihomo-party/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ package() {
bsdtar -xf mihomo-party-linux-${pkgver}*.deb
bsdtar -xf data.tar.xz -C "${pkgdir}/"
chmod +x ${pkgdir}/opt/mihomo-party/mihomo-party
chmod +x ${pkgdir}/opt/mihomo-party/resources/sidecar/mihomo
chmod +x ${pkgdir}/opt/mihomo-party/resources/sidecar/mihomo-alpha
chmod +sx ${pkgdir}/opt/mihomo-party/resources/sidecar/mihomo
chmod +sx ${pkgdir}/opt/mihomo-party/resources/sidecar/mihomo-alpha
install -Dm755 "${srcdir}/../${pkgname}.sh" "${pkgdir}/usr/bin/${pkgname}"
sed -i '3s!/opt/mihomo-party/mihomo-party!mihomo-party!' "${pkgdir}/usr/share/applications/${pkgname}.desktop"

Expand Down
2 changes: 2 additions & 0 deletions build/linux/deb/postinst → build/linux/postinst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ else
fi

chmod 4755 '/opt/mihomo-party/chrome-sandbox' || true
chmod +sx /opt/mihomo-party/resources/sidecar/mihomo
chmod +sx /opt/mihomo-party/resources/sidecar/mihomo-alpha

if hash update-mime-database 2>/dev/null; then
update-mime-database /usr/share/mime || true
Expand Down
4 changes: 3 additions & 1 deletion electron-builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ linux:
category: Utility
artifactName: ${name}-linux-${version}-${arch}.${ext}
deb:
afterInstall: 'build/linux/deb/postinst'
afterInstall: 'build/linux/postinst'
rpm:
afterInstall: 'build/linux/postinst'
npmRebuild: true
publish: []
8 changes: 2 additions & 6 deletions src/main/core/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export async function startCore(detached = false): Promise<Promise<void>[]> {
try {
process.kill(pid, 'SIGINT')
} catch {
if (process.platform !== 'win32' && encryptedPassword && isEncryptionAvailable()) {
if (process.platform === 'darwin' && encryptedPassword && isEncryptionAvailable()) {
const execPromise = promisify(exec)
const password = safeStorage.decryptString(Buffer.from(encryptedPassword))
try {
Expand Down Expand Up @@ -243,16 +243,12 @@ async function checkProfile(): Promise<void> {
}

export async function autoGrantCorePermition(corePath: string): Promise<void> {
if (process.platform === 'win32') return
if (process.platform !== 'darwin') return
const { encryptedPassword } = await getAppConfig()
const execPromise = promisify(exec)
if (encryptedPassword && isEncryptionAvailable()) {
try {
const password = safeStorage.decryptString(Buffer.from(encryptedPassword))
if (process.platform === 'linux') {
await execPromise(`echo "${password}" | sudo -S chown root:root "${corePath}"`)
await execPromise(`echo "${password}" | sudo -S chmod +sx "${corePath}"`)
}
if (process.platform === 'darwin') {
await execPromise(`echo "${password}" | sudo -S chown root:admin "${corePath}"`)
await execPromise(`echo "${password}" | sudo -S chmod +sx "${corePath}"`)
Expand Down
7 changes: 6 additions & 1 deletion src/main/utils/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ async function migration(): Promise<void> {
envType = [process.platform === 'win32' ? 'powershell' : 'bash'],
useSubStore = true,
showFloatingWindow = false,
disableTray = false
disableTray = false,
encryptedPassword
} = await getAppConfig()
const {
'external-controller-pipe': externalControllerPipe,
Expand Down Expand Up @@ -214,6 +215,10 @@ async function migration(): Promise<void> {
if (!showFloatingWindow && disableTray) {
await patchAppConfig({ disableTray: false })
}
// remove password
if (process.platform === 'linux' && encryptedPassword) {
await patchAppConfig({ encryptedPassword: undefined })
}
}

function initDeeplink(): void {
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/src/components/sider/tun-switcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const TunSwitcher: React.FC = () => {
})
const transform = tf ? { x: tf.x, y: tf.y, scaleX: 1, scaleY: 1 } : null
const onChange = async (enable: boolean): Promise<void> => {
if (enable && platform !== 'win32') {
if (enable && platform === 'darwin') {
const encryptionAvailable = await isEncryptionAvailable()
if (!appConfig?.encryptedPassword && encryptionAvailable) {
setOpenPasswordModal(true)
Expand Down

0 comments on commit 713b133

Please sign in to comment.