Skip to content
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

Self-signed cert generation issue with pem (OpenSSL v3). Fixed by using devcert #1503

Merged
merged 2 commits into from
Dec 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"prepublishOnly": "npm run lint && npm run build:all && npm run build-declaration",
"update-latest-release": "git checkout master && git branch -D latest-release || git checkout -b latest-release && git push -f origin/latest-release",
"start": "node bin/signalk-server",
"test-only": "mocha --require ts-node/register --extensions ts,tsx,js --timeout 10000 --exit 'test/**/*.[jt]s' 'lib/**/*.test.js'",
"test-only": "mocha --require ts-node/register --extensions ts,tsx,js --timeout 20000 --exit 'test/**/*.[jt]s' 'lib/**/*.test.js'",
"test": "npm run build && npm run test-only && npm run ci-lint",
"typedoc": "typedoc",
"heroku-postbuild": "npm run build:all",
Expand Down Expand Up @@ -99,6 +99,7 @@
"debug": "^4.3.3",
"deep-get-set": "^1.1.0",
"dev-null-stream": "0.0.1",
"devcert": "^1.2.2",
"dnssd2": "1.0.0",
"errorhandler": "^1.3.0",
"express": "^4.10.4",
Expand All @@ -121,7 +122,6 @@
"ms": "^2.1.2",
"ncp": "^2.0.0",
"node-fetch": "^2.6.0",
"pem": "^1.14.3",
"primus": "^7.0.0",
"semver": "^7.1.1",
"split": "^1.0.0",
Expand Down Expand Up @@ -151,7 +151,6 @@
"@types/mocha": "^8.2.0",
"@types/ncp": "^2.0.5",
"@types/node-fetch": "^2.5.3",
"@types/pem": "^1.9.6",
"@types/semver": "^7.1.0",
"@types/serialport": "^8.0.1",
"@types/split": "^1.0.0",
Expand Down
37 changes: 15 additions & 22 deletions src/security.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
} from 'fs'
import _ from 'lodash'
import path from 'path'
import pem from 'pem'
import { certificateFor } from 'devcert'
import { Mode } from 'stat-mode'
import { WithConfig } from './app'
import { createDebug } from './debug'
Expand Down Expand Up @@ -349,27 +349,20 @@ export function createCertificateOptions(
) {
const location = app.config.configPath ? app.config.configPath : './settings'
debug(`Creating certificate files in ${location}`)
pem.createCertificate(
{
days: 360,
selfSigned: true
},
(err: any, keys: any) => {
if (err) {
console.error('Could not create SSL certificate:' + err.message)
throw err
} else {
writeFileSync(keyFile, keys.serviceKey)
chmodSync(keyFile, '600')
writeFileSync(certFile, keys.certificate)
chmodSync(certFile, '600')
cb(null, {
key: keys.serviceKey,
cert: keys.certificate
})
}
}
)
certificateFor([
'localhost'
])
.then(({ key, cert }) => {
writeFileSync(keyFile, key)
chmodSync(keyFile, '600')
writeFileSync(certFile, cert)
chmodSync(certFile, '600')
cb(null, {
key: key,
cert: cert
})
})
.catch(console.error);
}

export function requestAccess(
Expand Down