-
-
Notifications
You must be signed in to change notification settings - Fork 71
Added code to validate Ed25519ph signatures to harden against DNS spo… #649
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,6 +2,7 @@ import { | |||||||||||||||||||||||||||
| CanvasItem, | ||||||||||||||||||||||||||||
| ClassType, | ||||||||||||||||||||||||||||
| CSVDialog, | ||||||||||||||||||||||||||||
| DownloadDetails, | ||||||||||||||||||||||||||||
| events, | ||||||||||||||||||||||||||||
| Functions, | ||||||||||||||||||||||||||||
| HandleDimensionPayload, | ||||||||||||||||||||||||||||
|
|
@@ -27,6 +28,8 @@ import {exec,spawn} from 'child_process'; | |||||||||||||||||||||||||||
| import decompress from 'decompress'; | ||||||||||||||||||||||||||||
| import {promisify} from 'util'; | ||||||||||||||||||||||||||||
| import {net, safeStorage } from 'electron'; | ||||||||||||||||||||||||||||
| import { createReadStream, rmSync } from 'fs'; | ||||||||||||||||||||||||||||
| import { createHash, verify } from 'crypto'; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| function semVer(version: string) { | ||||||||||||||||||||||||||||
| const pattern=/(\d+)\.(\d+)\.(\d+)/; | ||||||||||||||||||||||||||||
|
|
@@ -88,6 +91,37 @@ try { | |||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| const publicKey=Buffer.from('\n-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEA3v8OynE8ZrGrXR062RtF37xLxRBlvBEy8/6os7Z7P1c=\n-----END PUBLIC KEY-----'); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| async function verifyFile(filePath: string, signature: string): Promise<boolean> { | ||||||||||||||||||||||||||||
| return new Promise((resolve, reject) => { | ||||||||||||||||||||||||||||
| // 1. Create a SHA-512 hash stream (Standard for Ed25519ph) | ||||||||||||||||||||||||||||
| const hash = createHash('sha512'); | ||||||||||||||||||||||||||||
| const stream = createReadStream(filePath); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| stream.on('data', (chunk) => hash.update(chunk)); | ||||||||||||||||||||||||||||
| stream.on('error', (err) => reject(err)); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| stream.on('end', () => { | ||||||||||||||||||||||||||||
| const digest = hash.digest(); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| // 2. Verify using the 'ed25519' algorithm with the digest | ||||||||||||||||||||||||||||
| // In Node.js, for Ed25519ph, we pass the digest and set dsaEncoding | ||||||||||||||||||||||||||||
|
highperformancecoder marked this conversation as resolved.
Outdated
|
||||||||||||||||||||||||||||
| const isValid = verify( | ||||||||||||||||||||||||||||
| undefined, | ||||||||||||||||||||||||||||
| digest, | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| key: publicKey, | ||||||||||||||||||||||||||||
| format: 'pem', | ||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
| // In Node.js, for Ed25519ph, we pass the digest and set dsaEncoding | |
| const isValid = verify( | |
| undefined, | |
| digest, | |
| { | |
| key: publicKey, | |
| format: 'pem', | |
| }, | |
| // Pass the PEM-encoded public key directly to crypto.verify | |
| const isValid = verify( | |
| undefined, | |
| digest, | |
| publicKey, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the doc, passing an Object implicitly creates a KeyObject from createPublicKey. What is wrong with that?
Copilot
AI
Apr 21, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Throwing a string (throw '...') loses stack/context and makes error handling inconsistent. Throw an Error instance instead so callers (and the catch block) get a meaningful message + stack trace.
| throw 'Download has invalid signature, removed for safety'; | |
| throw new Error('Download has invalid signature, removed for safety'); |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,4 +1,4 @@ | ||||||||||
| import { defaultBackgroundColor } from '@minsky/shared'; | ||||||||||
| import { defaultBackgroundColor, DownloadDetails } from '@minsky/shared'; | ||||||||||
| import Store from 'electron-store'; | ||||||||||
| import {homedir} from 'node:os'; | ||||||||||
|
|
||||||||||
|
|
@@ -18,7 +18,7 @@ interface MinskyStore { | |||||||||
| preferences: MinskyPreferences; | ||||||||||
| defaultModelDirectory: string; | ||||||||||
| defaultDataDirectory: string; | ||||||||||
| ravelPlugin: string; // used for post installation installation of Ravel | ||||||||||
| ravelPlugin: DownloadDetails; // used for post installation installation of Ravel | ||||||||||
|
||||||||||
| ravelPlugin: DownloadDetails; // used for post installation installation of Ravel | |
| ravelPlugin: DownloadDetails | null; // used for post installation installation of Ravel |
Copilot
AI
Apr 21, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo in comment: "post installation installation" repeats a word; please correct it to avoid confusion.
| ravelPlugin: DownloadDetails; // used for post installation installation of Ravel | |
| ravelPlugin: DownloadDetails; // used for post installation of Ravel |
Uh oh!
There was an error while loading. Please reload this page.