Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
node-forge used inside selfsigned is a bit package https://packagephobia.com/result?p=node-forge Sadly there is no js-only alternative (only `openssl` wrappers). While testing this feature (server.https: true) I found chrome detects the certificate is insecure though still allows to access the page with https after proceeding warning wall. So as there is not much value in using so big dependency to generate insecure certificates @patak-dev got an idea to pregenerate single certificate and publish it with vite. This need to be tested on various machines though before releasing. I made the certificate expire in 10 years. Let's cross our fingers this will be enough. ``` du -ck dist/node ``` before: 12348 after: 9812
- Loading branch information
Showing
6 changed files
with
143 additions
and
472 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
-----BEGIN RSA PRIVATE KEY----- | ||
MIIEpQIBAAKCAQEAsan51A4X8wLmf/sqn/CiosFSeLnnFG3xUtSspLpudNOAu+Ai | ||
3j8+fYpUknGztKEOZll+o55r2QNyoUgO6n7BVgixxr/iVjvs+SEVWsxYfl/jYZU5 | ||
pqJPlzqJKkvKA08kHFSQuXUyPkA0YbjSo1sJInyY2lUAxK3gSKaTUdRRpLO29Bx2 | ||
WNOPGGWAjjI85slagiskH+rXabX7Nsp0JMz4ZL0cQHgYBM97VfwumqHOVU+dWzgK | ||
ituQDut17qFndVtQMMhQzRzz8sMb2H9i9YWTr6ateBSKHmNACaMPiYO5w8RXNggh | ||
LhGbxUOCqb4CqB2DKc6QX4ijzdxSD7eYyNgrpQIDAQABAoIBAQCC6iFxpMD5DNYU | ||
0FtkZ8kv7Qx8cWBZqXn980EUUVw7Me7Wgh6vbiL6FwiisK4fF96ohKHQp1gJHYVG | ||
WvbCzIxifR2iupppuNax7TLzKUi8NqQyr+c/ZrMHWNbiF97P+W0+gwHx5u4S+PSg | ||
XbS5MsfUZcOsfp6GTynJ3xUHY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FpboIGbHZoLm1lgggqLmx2aC5tZYIFWzo6MV2H | ||
BH8AAAGHEP6AAAAAAAAAAAAAAAAAAAEwDQYJKoZIhvcNAQELBQADggEBABNxJ19s | ||
U95jrFFaH0So4mOJqtnLlm4eCCOjAhLv7r+Pyqy4ZKoXwagopk46ehx5W888lDin | ||
Zzp2ij1o6Ry286lldT/wf8SOlWRejkb61/R8FMqu9homnD+UY3UCoLxNbkk/j9jo | ||
xkFJPFv0RZQp0gR+F+zcvM+P62cwyLv4C5JcC2JV8GsOdg8io1RJpUxkl/SDHPXy | ||
v7xmJuW7Tzp163adOZSack2EfFYAEI5XCzacIR9Je2vclMHNqSur0u9l67JNeO5H | ||
r11T0xHE2WSYlMyWcjvEDX9BT/aGQnV+FPAh56loLNFdRIbOXKexH26Wkleyaaot | ||
14Z1+PZPkw/FeLo= | ||
-----END CERTIFICATE----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import fs from 'fs' | ||
import path from 'path' | ||
import { generate } from 'selfsigned' | ||
|
||
/** | ||
* https://github.com/webpack/webpack-dev-server/blob/master/lib/utils/createCertificate.js | ||
* | ||
* Copyright JS Foundation and other contributors | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file at | ||
* https://github.com/webpack/webpack-dev-server/blob/master/LICENSE | ||
*/ | ||
function createCertificate() { | ||
const pems = generate(null, { | ||
algorithm: 'sha256', | ||
days: 3650, // 10 years should be enough for development-only insecure certificate | ||
keySize: 2048, | ||
extensions: [ | ||
// { | ||
// name: 'basicConstraints', | ||
// cA: true, | ||
// }, | ||
{ | ||
name: 'keyUsage', | ||
keyCertSign: true, | ||
digitalSignature: true, | ||
nonRepudiation: true, | ||
keyEncipherment: true, | ||
dataEncipherment: true | ||
}, | ||
{ | ||
name: 'extKeyUsage', | ||
serverAuth: true, | ||
clientAuth: true, | ||
codeSigning: true, | ||
timeStamping: true | ||
}, | ||
{ | ||
name: 'subjectAltName', | ||
altNames: [ | ||
{ | ||
// type 2 is DNS | ||
type: 2, | ||
value: 'localhost' | ||
}, | ||
{ | ||
type: 2, | ||
value: 'localhost.localdomain' | ||
}, | ||
{ | ||
type: 2, | ||
value: 'lvh.me' | ||
}, | ||
{ | ||
type: 2, | ||
value: '*.lvh.me' | ||
}, | ||
{ | ||
type: 2, | ||
value: '[::1]' | ||
}, | ||
{ | ||
// type 7 is IP | ||
type: 7, | ||
ip: '127.0.0.1' | ||
}, | ||
{ | ||
type: 7, | ||
ip: 'fe80::1' | ||
} | ||
] | ||
} | ||
] | ||
}) | ||
return pems.private + pems.cert | ||
} | ||
|
||
const cert = createCertificate() | ||
fs.writeFileSync(path.join(__dirname, '..', 'dev-cert.pem'), cert) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters