(file: string = daemonKeyPath())
| 42 | |
| 43 | /** The key, when the file holds one that only this user can read; null otherwise. Never creates. */ |
| 44 | export function readDaemonKey(file: string = daemonKeyPath()): Buffer | null { |
| 45 | try { |
| 46 | const stat = fs.lstatSync(file); |
| 47 | if (!stat.isFile()) return null; |
| 48 | if (process.platform !== 'win32' && (stat.uid !== process.getuid?.() || (stat.mode & 0o077) !== 0)) return null; |
| 49 | const key = fs.readFileSync(file); |
| 50 | return key.length >= KEY_BYTES ? key : null; |
| 51 | } catch { |
| 52 | return null; |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * The key, made on first use; the daemon calls this when a client asks for a |
no test coverage detected