{"id":9659,"date":"2022-11-21T17:43:06","date_gmt":"2022-11-21T17:43:06","guid":{"rendered":"https:\/\/stevepedwards.today\/DebianAdmin\/?p=9525"},"modified":"2023-10-29T02:25:57","modified_gmt":"2023-10-29T02:25:57","slug":"vs-code-live-server-ssl-settings","status":"publish","type":"post","link":"https:\/\/stevepedwards.today\/DebianAdmin\/vs-code-live-server-ssl-settings\/","title":{"rendered":"VS Code Live Server SSL Settings"},"content":{"rendered":"<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_9659\" class=\"pvc_stats all  \" data-element-id=\"9659\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n<p>First you need to set up an SSL certificate for your VS code PC to mimic a Cert Authority locally, so on my Win11 laptop I have installed WSL Ubuntu so openssl can be run to use linux commands for the following cert setup. It doesn't matter what nonsense values you put in the certificate fields, as it's not a real certificate - except for the pass phrase you use that openssl will generate the encrypted keys.<\/p>\n<p>WSL for windows can be installed from Powershell if you prefer linux.<\/p>\n<p><a href=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2022\/11\/WSL.png\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-9528 aligncenter\" src=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2022\/11\/WSL.png\" alt=\"\" width=\"1025\" height=\"432\" \/><\/a><\/p>\n<p>I have opened a WSL terminal in VS Code in my Source Control projects folder. I will create the cert files\/keys here also.<\/p>\n<p>If you are not linux comfortable then DL openssl for windows from the web and learn how to use it that way...can't help you there right now.<\/p>\n<p>step 1: Install openssl\/create public key:<\/p>\n<p>stevee@laptop:\/mnt\/c\/MyShare\/SourceControl$ <span style=\"color: #0000ff;\">sudo apt install openssl<\/span><\/p>\n<p>1. create a private key<br \/>\n<span style=\"color: #0000ff;\">openssl genrsa -aes256 -out localhost.key 2048<\/span><br \/>\n\/\/ you will be prompted to provide a password<br \/>\n\/\/this will create localhost.key (call it whatever you like)<br \/>\n<span style=\"color: #ff0000;\">Enter PEM pass phrase:<\/span><br \/>\n<span style=\"color: #ff0000;\">Verifying - Enter PEM pass phrase:<\/span><\/p>\n<p>stevee@localhost:~$<span style=\"color: #0000ff;\"> ls -l\u00a0<\/span><br \/>\n<span style=\"color: #ff0000;\">-rwxrwxrwx 1 stevee stevee 1766 Nov 21 18:14 localhost.key<\/span><\/p>\n<p>Step 2: make Certificate Signing Request (CSR)<\/p>\n<p>stevee@localhost:~$ <span style=\"color: #0000ff;\">openssl req -new -key localhost.key -out localhost.csr<\/span><br \/>\n<span style=\"color: #ff0000;\">Enter pass phrase for server.key:<\/span><br \/>\nYou are about to be asked to enter information that will be incorporated<br \/>\ninto your certificate request.<br \/>\nWhat you are about to enter is what is called a Distinguished Name or a DN.<br \/>\nThere are quite a few fields but you can leave some blank<br \/>\nFor some fields there will be a default value,<br \/>\nIf you enter '.', the field will be left blank.<br \/>\n-----<br \/>\n<span style=\"color: #ff0000;\">Country Name (2 letter code) [AU]:UK<\/span><br \/>\n<span style=\"color: #ff0000;\">State or Province Name (full name) [Some-State]:cornwall<\/span><br \/>\n<span style=\"color: #ff0000;\">Locality Name (eg, city) []:redruth<\/span><br \/>\n<span style=\"color: #ff0000;\">Organization Name (eg, company) [Internet Widgits Pty Ltd]:localhost<\/span><br \/>\n<span style=\"color: #ff0000;\">Organizational Unit Name (eg, section) []:localhost<\/span><br \/>\n<span style=\"color: #ff0000;\">Common Name (e.g. server FQDN or YOUR name) []:localhost<\/span><br \/>\n<span style=\"color: #ff0000;\">Email Address []:<\/span><\/p>\n<p><span style=\"color: #ff0000;\">Please enter the following 'extra' attributes<\/span><br \/>\n<span style=\"color: #ff0000;\">to be sent with your certificate request<\/span><br \/>\n<span style=\"color: #ff0000;\">A challenge password []: xxx<\/span><\/p>\n<p>In VS Code\u00a0 install the Live Server Extension by Ritwick Dey:<\/p>\n<p><a href=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2022\/11\/LServer.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-9527\" src=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2022\/11\/LServer.png\" alt=\"\" width=\"1928\" height=\"1040\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>To add the user.JSON code for the SSL settings, go to File\/Preferences\/Settings and click the tiny, top right \"open settings\" icon:<\/p>\n<p><a href=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2022\/11\/usericon-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-9536\" src=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2022\/11\/usericon-1.png\" alt=\"\" width=\"1889\" height=\"177\" \/><\/a><\/p>\n<p>Paste this code from the Live server docs site:<\/p>\n<p><a href=\"https:\/\/github.com\/ritwickdey\/vscode-live-server\/blob\/master\/docs\/settings.md\">https:\/\/github.com\/ritwickdey\/vscode-live-server\/blob\/master\/docs\/settings.md<\/a><\/p>\n<p>Amend to suit your folders where you placed your keys:<\/p>\n<pre class=\"lang:default decode:true\">{\r\n  \"liveServer.settings.root\" : \"\/\",\r\n  \"liveServer.settings.port\" : 5501,\r\n    \"liveServer.settings.http\": {\r\n      \"enable\": true,\r\n      <span style=\"color: #ff0000;\">\"cert\": \"C:\\MyShare\\SourceControl\\localhost.pem\",\r\n      \"key\": \"C:\\MyShare\\SourceControl\\localhost.key\",<\/span>\r\n      \"passphrase\": \"urpasswd\"\r\n    }\r\n  }<\/pre>\n<p>&nbsp;<\/p>\n<p>Close the Live Server if running.<\/p>\n<p>Now open a project index.html file by right click, and open live server again.<\/p>\n<p>You should see a browser warning as the cert is not real and not verified by an online Certificate Authority obviously, but click Advanced and proceed to site and traffic WILL be encrypted and you VS Code projects emulating being served from an real http server. Note the new port number 5501.<\/p>\n<p><a href=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2022\/11\/SSLPage.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-9532\" src=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2022\/11\/SSLPage.png\" alt=\"\" width=\"1921\" height=\"1033\" \/><\/a><\/p>\n<p>If you r click the Not Secure you can see the invalid certificate:<\/p>\n<p><a href=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2022\/11\/Invalidcert.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-9539\" src=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2022\/11\/Invalidcert.png\" alt=\"\" width=\"1921\" height=\"1033\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_9659\" class=\"pvc_stats all  \" data-element-id=\"9659\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n<p>First you need to set up an SSL certificate for your VS code PC to mimic a Cert Authority locally, so on my Win11 laptop I have installed WSL Ubuntu so openssl can be run to use linux commands for the following cert setup. It doesn't matter what nonsense values you put in the certificate <a href=\"https:\/\/stevepedwards.today\/DebianAdmin\/vs-code-live-server-ssl-settings\/\" class=\"more-link\">...<span class=\"screen-reader-text\">\u00a0 VS Code Live Server SSL Settings<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-9659","post","type-post","status-publish","format-standard","hentry","category-post"],"a3_pvc":{"activated":true,"total_views":9,"today_views":0},"_links":{"self":[{"href":"https:\/\/stevepedwards.today\/DebianAdmin\/wp-json\/wp\/v2\/posts\/9659","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/stevepedwards.today\/DebianAdmin\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/stevepedwards.today\/DebianAdmin\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/stevepedwards.today\/DebianAdmin\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/stevepedwards.today\/DebianAdmin\/wp-json\/wp\/v2\/comments?post=9659"}],"version-history":[{"count":3,"href":"https:\/\/stevepedwards.today\/DebianAdmin\/wp-json\/wp\/v2\/posts\/9659\/revisions"}],"predecessor-version":[{"id":10094,"href":"https:\/\/stevepedwards.today\/DebianAdmin\/wp-json\/wp\/v2\/posts\/9659\/revisions\/10094"}],"wp:attachment":[{"href":"https:\/\/stevepedwards.today\/DebianAdmin\/wp-json\/wp\/v2\/media?parent=9659"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/stevepedwards.today\/DebianAdmin\/wp-json\/wp\/v2\/categories?post=9659"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/stevepedwards.today\/DebianAdmin\/wp-json\/wp\/v2\/tags?post=9659"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}