Commit 616fb9e1 authored by Aral Balkan's avatar Aral Balkan
Browse files

Re-implement Windows support

parent 5e2d752e
......@@ -5,12 +5,16 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [7.0.5] - In progress...
## [7.0.5] - 2021-03-19
### Fixed
- Installation on macOS. This was failing because of differences in how the graphical sudo prompt affects file permissions between Linux and macOS.
### Added
- Re-implemented Windows support (tested/supported only on Windows 10, under Windows Terminal, with PowerShell).
## [7.0.4] - 2021-03-17
### Added
......
......@@ -152,28 +152,52 @@ process.stdout.write(` ╰─ Initialising mkcert… `)
// to only enter their password once instead of multiple times, once for each command
// (due to how sudo-prompt works), we first create a shell script and then we execute that.
//
// TODO: Figure out what to do for Windows.
const shellScriptTemplate = `#!/bin/bash
set -e
# Install mkcert and create the certificate authority
${mkcertBinary} -install
# Create the certificates
${mkcertBinary} ${certificateDetails}
# Reset file permissions to regular account
chown -R ${account} ${settingsPath}
`
// For Windows, we create and use a separate PowerShell script.
let shellScriptTemplate
let shellScriptFileName
let shellScriptCommand
const platform = os.platform()
if (platform === 'linux' || platform === 'darwin') {
shellScriptFileName = 'install-mkcert.sh'
shellScriptCommand = `CAROOT=${settingsPath} /tmp/install-mkcert.sh`
shellScriptTemplate = `#!/bin/bash
set -e
# Install mkcert and create the certificate authority
${mkcertBinary} -install
# Create the certificates
${mkcertBinary} ${certificateDetails}
# Reset file permissions to regular account
chown -R ${account} ${settingsPath}
`
} else if (platform === 'win32') {
shellScriptFileName = 'install-mkcert.ps1'
shellScriptCommand = 'powershell.exe /tmp/install-mkcert.ps1'
shellScriptTemplate = `
# Set the environment variable
$env:CAROOT="${settingsPath}"
# Install mkcert and create the certificate authority
${mkcertBinary} -install
# Create the certificates
${mkcertBinary} ${certificateDetails}
`
} else {
throw new Error(`Sorry, this module is not tested or supported on your platform (${platform}).`)
}
fs.writeFileSync('/tmp/install-mkcert.sh', shellScriptTemplate, {mode: 0o755})
fs.writeFileSync(`/tmp/${shellScriptFileName}`, shellScriptTemplate, {mode: 0o755})
await (() => {
return new Promise((resolve, reject) => {
const options = { name: 'Auto Encrypt Localhost' }
// Note: mkcert uses the CAROOT environment variable to know where to create/find the certificate authority.
sudoPrompt.exec(`CAROOT=${settingsPath} /tmp/install-mkcert.sh`, options, function(error, stdout, stderr) {
sudoPrompt.exec(shellScriptCommand, options, function(error, stdout, stderr) {
if (error) reject(error)
resolve()
})
......
......@@ -15,6 +15,7 @@ export default function installCertutil () {
} else if (platform === 'win32') {
// Do nothing. According to the mkcert documentation, certutil is not
// required on Windows.
console.log('done.')
} else {
// Unknown platform. This should have been caught earlier. Panic.
throw new Error(' ╰─ 🤯 Panic: Unknown platform detected.', platform)
......
{
"name": "@small-tech/auto-encrypt-localhost",
"version": "7.0.4",
"version": "7.0.5",
"description": "Automatically provisions and installs locally-trusted TLS certificates for Node.js https servers (including Express.js, etc.) using mkcert.",
"keywords": [
"mkcert",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment