41

I installed the GitHub copilot but the extension do not work, always show the following error :

enter image description here

What could I do to solve this ?

Debug Diva
  • 26,058
  • 13
  • 70
  • 123
Mateus
  • 435
  • 1
  • 3
  • 6

9 Answers9

54

Copilot error: “GitHub Copilot could not connect to server. Extension activation failed: self-signed certificate in certificate chain” is generally caused using CoPilot behind a Corporate network.

  • Most corporate networks have a ‘Man-in-the-middle’ appliance that dynamically breaks open all secure SSL traffic leaving home to enter the internet. This ensures they can inspected any traffic leaving, including your online banking. Usually automation scrubs the traffic looking for theft of company secrets or IP and raises alerts. It all gets logged and reviewed further if need be.

  • This action leaves behind a fake cert chain as a fingerprint. The cert for the called site is replaced with a fake, and one signed by the company’s own private CA authority. Hence the self-signed cert in the cert chain error.

  • From any company device (Phones\Laptop) the company CA is already installed as a trusted CA. So the local browsers and other desktop apps trust this faked cert chain - and so do not raise any concerns someone is snooping your secure network traffic (the company does own the network and the device).

  • By default VSCode is not trusting the installed desktop certs, and so it noticed that the GitHub cert is no longer signed by a trusted public CA authority.

  • As Rypox states above, the VSCode extension ‘Win-CA’ (must be set to ‘append’ mode) solves this issue. It tells VSCode to also trust the CA’s installed on the employees desktop. This makes VSCode happy again trusting the fake cert chain. No 'whitelisting' needed and not 'VPN' related. But certinly not that obvious either. An interesting CA trust issue.

  • Confirming this does exist is easy from your browser. Go to any outside site (like Amazon) and review the sites “Cert” to see who the CA’s are (Certification Path). It should ‘not’ contain any reference to your company. Look at that same cert from outside the company network on your own personal laptop.

… “bit of a glitch in the Matrix”, installing Win-CA helps hides it again and all looks back to normal.

Drew2020
  • 556
  • 3
  • 4
34

Had the same issue with a corporate proxy, the win-ca extension resolved it.

In settings switch to append mode (it's not the default)

Restart VsCode

PS: this is a windows only solution (for mac see another post - self signed certificate in certificate chain on github copilot)

Rypox
  • 533
  • 3
  • 8
22

For any MacOS users, I have found that the VSCode extension linhmtran168.mac-ca-vscode can help as well with this. It is similar to the previously mentioned win-ca.

https://marketplace.visualstudio.com/items?itemName=linhmtran168.mac-ca-vscode

Andrew Gremlich
  • 353
  • 4
  • 7
18

On macOS, you can use this script to monkey patch the Copilot extension to make this work:

_VSCODEDIR="$HOME/.vscode/extensions"
_COPILOTDIR=$(ls "${_VSCODEDIR}" | grep -E "github.copilot-[1-9].*" | sort -V | tail -n1) # For copilot
_COPILOTDEVDIR=$(ls "${_VSCODEDIR}" | grep "github.copilot-nightly-" | sort -V | tail -n1) # For copilot-nightly
_EXTENSIONFILEPATH="${_VSCODEDIR}/${_COPILOTDIR}/dist/extension.js"
_DEVEXTENSIONFILEPATH="${_VSCODEDIR}/${_COPILOTDEVDIR}/dist/extension.js"
if [[ -f "$_EXTENSIONFILEPATH" ]]; then
    echo "Found Copilot Extension, applying 'rejectUnauthorized' patches to '$_EXTENSIONFILEPATH'..."
    perl -pi -e 's/,rejectUnauthorized:[a-z]}(?!})/,rejectUnauthorized:false}/g' ${_EXTENSIONFILEPATH}
    sed -i.bak 's/d={...l,/d={...l,rejectUnauthorized:false,/g' ${_EXTENSIONFILEPATH}
else
    echo "Couldn't find the extension.js file for Copilot, please verify paths and try again or ignore if you don't have Copilot..."
fi
if [[ -f "$_DEVEXTENSIONFILEPATH" ]]; then
    echo "Found Copilot-Nightly Extension, applying 'rejectUnauthorized' patches to '$_DEVEXTENSIONFILEPATH'..."
    perl -pi -e 's/,rejectUnauthorized:[a-z]}(?!})/,rejectUnauthorized:false}/g' ${_DEVEXTENSIONFILEPATH}
    sed -i.bak 's/d={...l,/d={...l,rejectUnauthorized:false,/g' ${_DEVEXTENSIONFILEPATH}
else
    echo "Couldn't find the extension.js file for Copilot-Nightly, please verify paths and try again or ignore if you don't have Copilot-Nightly..."
fi

Save as something like monkey-patch-copilot.sh, then chmod +x monkey-patch-copilot.sh. You should then be able to run: ./monkey-patch-copilot.sh to apply the patch.

Note: I am not the original author. This was found on the Copilot feedback forum.

leek
  • 11,803
  • 8
  • 45
  • 61
  • 3
    I'd been looking for a fix for so long. Thank you! – Jonathan Picazo May 14 '22 at 02:09
  • 1
    I'm trying to adapt your script for the PyCharm / IntelliJ plugin. There's no `extension.js` in the dist folder, but `agent.js` and `service.js` exists, and contain `rejectUnauthorized:` a bunch of places. `d={...l` isn't anywhere to find, but I've got `d={...c` and `d={...n`. How do I determine which should be replaced? If I uploaded the files somewhere, would you be willing to help me with this? – Daniel Hjertholm Aug 10 '22 at 09:27
  • 1
    Do you happen to know a fix for PyCharm too? – qichao_he Aug 23 '22 at 13:39
  • If you are using the SSH plugin for vscode, make sure to change the first line to `_VSCODEDIR="$HOME/.vscode-server/extensions"` – LI0131 Oct 27 '22 at 17:37
  • Works on linux as well! – Daniel Bişar Mar 14 '23 at 13:45
6

I found a solution for this which works for me in case of Intellij. I have blogged about it at https://sidd.io/2023/01/github-copilot-self-signed-cert-issue/

At a high level I think the architecture of the plugin might be same :

IDE Native CoPilot Plugin ---making RPC call---> NodeJS based CoPilot Agent

And this NodeJS based CoPilot Agent agent has issues with the Self Signed Certs (at least in my case).

Fix is as follows :

  1. Export the self-signed certificate in discussion
  2. Convert it into .pem format if not already
  3. Export the path of this .pem cert to NODE_EXTRA_CA_CERTS variable
  4. Restart your IDE and it should work
Siddharth
  • 2,046
  • 5
  • 26
  • 41
  • 2
    This answer will help solve the issue for Visual Studio. It feels more correct then installing an extension. – Logic01 Feb 24 '23 at 20:07
  • How do you know which certificate is used for a given VPN provider??? – Nicolas Belley Mar 27 '23 at 12:06
  • @NicolasBelley in my understanding if you have installed an VPN provider on your machine then a Root CA would also have been installed in your machine. Ex: if you are using a Mac then you should check this under "Keychain Access" in "Certificates" and you should find it. – Siddharth Mar 29 '23 at 02:30
  • This works also under Windows for JetBrains IDEs: set `NODE_EXTRA_CA_CERTS` variable in the "Edit environment variables for your account" control panel (no admin needed), to an absolute path like "C:\path\to\ca-bundle.crt" – LCC Apr 11 '23 at 15:35
  • 2
    what certificate "is in discussion"? – hipokito Apr 27 '23 at 20:05
  • Is there any complete step-by-step solution for Visual Studio 2022, yet? How do I "Export the self-signed certificate"?, etc... – Siavash Mortazavi Aug 22 '23 at 17:53
2

Corporate VPN was the problem (same as @mark-derry's).

Jetbrain's PyCharm / DataSpell allows to accept self signed certificates.

VSCode doesn't seem to have this option yet.

Neil
  • 7,482
  • 6
  • 50
  • 56
  • 2
    I tried adding the self signed certificates according to [this](https://www.jetbrains.com/help/idea/settings-tools-server-certificates.html), but it does not work. I also tried **Accept non-trusted certificates automatically**. not working either. Did you manage to make JetBrains/PyCharm copilot plugin work with corporate vpn that has a self signed certificates? – qichao_he Aug 24 '22 at 13:20
1

This looks like a similar error to what I am getting. I believe that the source of this in our corporate network is a ssl inspection process such that when the https traffic is opened and inspected that it breaks the certificate chain and this error shows up. A fix would be to add the GitHub Copilot servers to the ssl inspection whitelist so that that traffic is not inspected.

Mark Derry
  • 31
  • 3
  • have the same problem; unfortunately getting things whitelisted could be quite challenging at the corps – Neil Mar 24 '22 at 07:00
0
  1. Install [win-ca][1] [1]: https://marketplace.visualstudio.com/items?itemName=ukoloff.win-ca

  2. Press CTRL + SHIFT + P Search for @ext:ukoloff.win-ca

  3. Put Win-Ca: Inject to append

  4. Restart the IDE

  5. Start Coding

Sampath Wijesinghe
  • 789
  • 1
  • 11
  • 33
-3

Easy! Method 1 : just excute this code.

git config --global http.sslVerify false

Method 2: FOllow this guide! and Thank me later because I have saved you a time of husel ? :) . you're welcome!

https://mattferderer.com/fix-git-self-signed-certificate-in-certificate-chain-on-windows

Develop4Life
  • 7,581
  • 8
  • 58
  • 76