-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
fix: pregenerate https certificate #6173
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
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 | ||
XbS5MsfUZcOsfp6GTynJ3xUHY1CV76x7YI4tQ5RAWT+EEHihDA4zbh49LoqlTNOE | ||
+pEeOF3bcqAehmLAicEfZU7iUrVKxZ9xpJebRLYBRO/MGEaXf4tp5VcTYgIlyA1p | ||
cx8eAfKiZsiCVpTkY4lBTB9YGhfQqLr7O9aAzeCxTpjY9cJ7tUWEWv2Ybt88SSGa | ||
7iiXLJixAoGBAOSzW6u9oxkTGY1Uy8L8SrXyox3dCwTDdqcS0okboE3dYks84g7M | ||
knrVq3mIh8Kc6SHW2RLaxpPvSGdJywYT+sUEMwF/ZZlIzZEtXOroHgU+2L0y/9Ie | ||
+mu6MBWEdzUWo6AmLK4XGyiqpwqDGpka0P3sai544VamInjjErRX81ebAoGBAMbf | ||
CbnjNg0J05LizUVtXT/9v/PheofXYXEuThpGYi97HgaiOUKgIwn+o0k/o+Wxbgpq | ||
wYTIQNQklUo4/eQbOMqRR1YVy20ylpfJOIS6AJBDKkoLBzyi5IbYspCnd25VYZ+c | ||
MZ1jkmu6qlNXsPxtN9GLrQSluS2r07qTgfM8C92/AoGAGzyVFU3/Z5QTvfY0UiNz | ||
zll4Pa0+i7GvptQiCLwmij9sXmOA1JxecYyS4GV3LaE8TpBkx88QSTv9Fnf+Wtn0 | ||
SpRmcq42blvyR3DsmPlN4fgLHfU97EtOLZg988IT5Fmu4PrK5WzRCjXQsPrOJx+/ | ||
dg460xAIXiZpApageqPi0jMCgYEAkNxCf28sHg88WFBw6dOiC0zRF9r0oCKZThJG | ||
vgjq2F88HeTpBMkU/ODJHEAJKPU3jMr6r7gW0PDc9jXRaukRUyzD48b4aVBiNapT | ||
SwsaAfuKwGiMGvUktbz/RTNXYb074UGrOlQfge10yESmHRmJgU/W9f2ph8UT82Ij | ||
VIQ2uI0CgYEAzVpC6C/Lx9dVmE6V7evZuE3g67zlMwd7U//X5eKAp0bUnrGTmy/3 | ||
5bNHELUrVPEfG4IVIHIb1jTIJHECyTUpw0xDsVzdgsP+BShPBjiJLjMTIy/o53pX | ||
lTNpkrXUtt5OIGC6cMx6nHuWIpfBjMa6vtfAOfzl6tt7o5v3rmaqemU= | ||
-----END RSA PRIVATE KEY----- | ||
-----BEGIN CERTIFICATE----- | ||
MIID9zCCAt+gAwIBAgIJQD4HLTmP5m8qMA0GCSqGSIb3DQEBCwUAMGkxFDASBgNV | ||
BAMTC2V4YW1wbGUub3JnMQswCQYDVQQGEwJVUzER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ejkb61/R8FMqu9homnD+UY3UCoLxNbkk/j9jo | ||
xkFJPFv0RZQp0gR+F+zcvM+P62cwyLv4C5JcC2JV8GsOdg8io1RJpUxkl/SDHPXy | ||
v7xmJuW7Tzp163adOZSack2EfFYAEI5XCzacIR9Je2vclMHNqSur0u9l67JNeO5H | ||
r11T0xHE2WSYlMyWcjvEDX9BT/aGQnV+FPAh56loLNFdRIbOXKexH26Wkleyaaot | ||
14Z1+PZPkw/FeLo= | ||
-----END CERTIFICATE----- |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this link does not work, createCertificate.js does not exist in the webpack-dev-server repo current master. Skimming the repo it looks like they only offer configuration options for bringing your own cert, no auto- or pregenerated certs There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We were talking with @userquin that it may also be better for us to do the same. Maybe in Vite 3.0 we can remove the autogenerated cert to push users to create secure certificates |
||
* | ||
* 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) |
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.
Just to clarify: is it safe to commit a private key to repo?
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.
This is a key that will only be used during development, and to trick the browser, it isn't a secure HTTPS certificate. But what we currently do isn't secure either. I'm still not sure if this is possible, but at least with the people we have discussed so far, it looks like inlining the cert is the same as generating it locally with fixed params.
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.
@TrySound should we add a comment in the .pem so people finding this private key in our repo would not be surprised? Looks like anything before the
-----BEGIN
should be ignored by parsers: https://stackoverflow.com/questions/19578812/comments-in-a-pem-fileSeems there are some parsers that have issues but it may be worth trying. Or any other idea to avoid getting security complaints once we merge this PR?
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.
Is this really needed at all? i'd rather not put a private key into a public repo for whatever reason. Someone takes it and uses it to target developers using vite in a social engineering/phishing attack.
Even without a public private key, a centralized cert is a bad idea imho. If you want to do this, generate the whole thing on the client side and preferably throw away the key afterwards so no other certs can be created.
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.
@dominikg the same answer I gave @patak-dev privately in discord
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.
@dominikg aren't we doing the same already with selfsigned with static params? I was under the impression that this cert couldn't be exploited as it is just an insecure hack to get the browser to comply even if you get a warning during development.
If having a global cert is more insecure than generating one with selfsigned, we shouldn't merge this PR. Would you explain a bit how this works?
If we don't merge this one, another option to remove selfsigned would be to deprecate this insecure feature, and add a new plugin/docs to push users to create a proper certificate, and then we can remove it in 3.0, as others are proposing in other messages