Skip to content

Commit

Permalink
latest
Browse files Browse the repository at this point in the history
  • Loading branch information
nk1tz committed Oct 18, 2024
1 parent 062b5fc commit 2d13a8f
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
dist
.DS_Store
out/
out/
.env
20 changes: 20 additions & 0 deletions entitlements.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.cs.allow-unsigned-executable-memory</key>
<true/>
<key>com.apple.security.cs.allow-jit</key>
<true/>
<key>com.apple.security.cs.disable-library-validation</key>
<true/>
<key>com.apple.security.cs.allow-dyld-environment-variables</key>
<true/>
<key>com.apple.security.inherit</key>
<true/>
<key>com.apple.security.automation.apple-events</key>
<true/>
<key>com.apple.security.cs.debugger</key>
<true/>
</dict>
</plist>
20 changes: 19 additions & 1 deletion forge.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
require("dotenv").config();

const { FusesPlugin } = require("@electron-forge/plugin-fuses");
const { FuseV1Options, FuseVersion } = require("@electron/fuses");

module.exports = {
packagerConfig: {
asar: false, // Disable ASAR packaging
asar: false,
icon: "./icons/icon",
// osxSign: {
// identity: "Apple Development: Joe Brauckmann (Z7RDUD6WJ5)",
// "hardened-runtime": true,
// entitlements: "entitlements.plist",
// "entitlements-inherit": "entitlements.plist",
// "signature-flags": "library",
// "gatekeeper-assess": false,
// verbose: true, // Add this line for more detailed logging
// },
// osxNotarize: {
// tool: "notarytool",
// appleId: process.env.APPLE_ID,
// appleIdPassword: process.env.APPLE_PASSWORD,
// teamId: process.env.APPLE_TEAM_ID,
// },
// ignore: [/^\/src/, /^\/test/, /^\/scripts/, /^\/\.vscode/, /^\/\.git/],
},
rebuildConfig: {
force: true,
Expand Down
10 changes: 10 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,20 @@
background-color: rgba(255, 255, 255, 0.3);
border-radius: 4px;
}

/* Add this new style for YubiKey messages */
#yubikey-message {
color: #00ff00; /* Bright green color */
font-weight: bold;
}
</style>
</head>
<body>
<h1>GPG Bridge</h1>
<!-- Updated YubiKey message div -->
<div id="yubikey-prompt" style="display: none">
<p id="yubikey-message"></p>
</div>
<div id="status">Checking server status...</div>
<div id="log-container"></div>

Expand Down
48 changes: 41 additions & 7 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
console.log("Current PATH:", process.env.PATH);

const { app, BrowserWindow, Tray, Menu } = require("electron");
const path = require("path");
const WebSocket = require("ws");
Expand Down Expand Up @@ -160,6 +158,12 @@ async function handleSignRequest(ws, messageToSign, fingerprint) {
communication: "Signing process started. Please touch your YubiKey.",
});

// Send a message to the renderer process to update the UI
sendToRenderer(
"yubikey-touch-required",
"You may need to touch your YubiKey to sign."
);

if (!GPG_PATH) {
const errorMsg = "GPG executable not found.";
console.error(errorMsg);
Expand Down Expand Up @@ -217,6 +221,8 @@ async function handleSignRequest(ws, messageToSign, fingerprint) {
message: messageToSign,
signature: stdout,
});
// Inform the renderer that the signing is complete
sendToRenderer("yubikey-touch-complete", "Signing process completed.");
} else {
// Signing failed
console.error("GPG signing process failed:", stderr);
Expand Down Expand Up @@ -297,10 +303,16 @@ async function getGpgKeys() {
const armoredKeys = await Promise.all(
keys.map((key) =>
execPromise(
`gpg --export --armor --export-options export-minimal ${key.fingerprint}!`
`${GPG_PATH} --export --armor --export-options export-minimal ${key.fingerprint}!`
).then(
({ stdout }) => stdout,
() => "Failed to retrieve pubkey."
({ stdout }) => {
console.log("Armored key:", stdout);
return stdout;
},
(err) => {
console.error("Failed to retrieve pubkey.", err);
return "Failed to retrieve pubkey.";
}
)
)
);
Expand Down Expand Up @@ -368,12 +380,32 @@ async function findGpgPath() {
"/opt/homebrew/bin/gpg", // For Apple Silicon Macs with Homebrew
"/usr/bin/gpg",
"/bin/gpg",
"C:\\Program Files (x86)\\GnuPG\\bin\\gpg.exe", // Windows path
"C:\\Program Files\\GnuPG\\bin\\gpg.exe", // Windows path
"/opt/local/bin/gpg", // MacPorts installation path
"/snap/bin/gpg", // Snap package installation path on Linux

"C:\\Program Files (x86)\\GnuPG\\bin\\gpg.exe", // Windows path (32-bit)
"C:\\Program Files\\GnuPG\\bin\\gpg.exe", // Windows path (64-bit)
"C:\\Program Files\\Git\\usr\\bin\\gpg.exe", // Git for Windows path

process.env.ProgramFiles + "\\GnuPG\\bin\\gpg.exe", // Dynamic Windows path
process.env["ProgramFiles(x86)"] + "\\GnuPG\\bin\\gpg.exe", // Dynamic Windows path (32-bit)

// Add more paths if needed
];

// Check if gpg is in PATH
try {
const { stdout } = await execPromise("which gpg || where gpg");
console.log("which gpg || where gpg", stdout.trim());
if (stdout.trim()) {
possiblePaths.unshift(stdout.trim());
}
} catch (error) {
console.log("GPG not found in PATH");
}

for (const path of possiblePaths) {
console.log("Checking path hard coded path:", path);
try {
await fs.access(path, fs.constants.X_OK);
console.log("GPG found at:", path);
Expand All @@ -394,6 +426,8 @@ app.whenReady().then(async () => {
createTray();
setupLogging();

console.log("Current PATH:", process.env.PATH);

const GPG_PATH = await findGpgPath();
console.log("Using GPG path:", GPG_PATH);

Expand Down
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"@electron-forge/plugin-fuses": "^7.5.0",
"@electron-forge/publisher-github": "^7.5.0",
"@electron/fuses": "^1.8.0",
"dotenv": "^16.4.5",
"electron": "^33.0.1"
}
}
10 changes: 10 additions & 0 deletions preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,13 @@ contextBridge.exposeInMainWorld("electronAPI", {
onLogMessage: (callback) =>
ipcRenderer.on("log-message", (event, message) => callback(message)),
});

contextBridge.exposeInMainWorld("electron", {
onYubiKeyTouchRequired: (callback) => {
ipcRenderer.on("yubikey-touch-required", (_, message) => callback(message));
},

onYubiKeyTouchComplete: (callback) => {
ipcRenderer.on("yubikey-touch-complete", (_, message) => callback(message));
},
});
12 changes: 12 additions & 0 deletions renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,15 @@ window.api.onServerStatus((event, data) => {
statusElement.textContent = "WebSocket server is not running";
}
});

window.electron.onYubiKeyTouchRequired((message) => {
document.getElementById("yubikey-message").textContent = message;
document.getElementById("yubikey-prompt").style.display = "block";
});

window.electron.onYubiKeyTouchComplete((message) => {
document.getElementById("yubikey-message").textContent = message;
setTimeout(() => {
document.getElementById("yubikey-prompt").style.display = "none";
}, 3000);
});

0 comments on commit 2d13a8f

Please sign in to comment.