Skip to content

Instantly share code, notes, and snippets.

@sarimarton
Last active April 24, 2024 06:59
Show Gist options
  • Star 22 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save sarimarton/55779cf95028860ea2126e61a6b377d0 to your computer and use it in GitHub Desktop.
Save sarimarton/55779cf95028860ea2126e61a6b377d0 to your computer and use it in GitHub Desktop.
Fix Github Copilot in dealing with self-signed certificates
# [2023-05-25] Added Copilot Chat, and VSCode Insiders
# [2023-05-20] Add VSCode Insiders variant
# [2023-02-22] Added Copilot Labs
# Fix Github Co-pilot self-signed cert problem
# See: https://github.com/orgs/community/discussions/8866#discussioncomment-3517831
# Note
#
# To make Github Copilot/Nightly/Labs/Chat work, you might need additional
# steps.
# ----------------------------------------------
# - The bash script is solid. Keep the fixing command run on shell start.
# - Sign out of github from vscode, lower left corner. Ref:
# https://docs.github.com/en/copilot/troubleshooting-github-copilot/troubleshooting-common-issues-with-github-copilot#error-github-copilot-could-not-connect-to-server-extension-activation-failed
# - Reload window, sign back in, make sure you're using the Chrome window with
# the right profile (with which you're logged in to the right account), reload
# window
# - Check VSCode Output pane
# - if EAI_AGAIN error happens, in particular under WSL, this worked:
# - sudo sh -c "echo nameserver 8.8.8.8 > /etc/resolv.conf"
# - Ref: https://github.com/community/community/discussions/19499#discussioncomment-5026421
# - As for Labs/Chat, check their webpage, there might be a waiting list, or
# terms to accept before you get access. The error message in the Output pane
# should give you a hint about it.
fix_github_copilot() {
local silent_mode=$1
apply_patch() {
local vscode_dir=$1
local regex_pattern=$2
local extension_name=$3
local extensions_path="$HOME/${vscode_dir}/extensions"
local copilot_dir=$(ls "${extensions_path}" | grep -E "${regex_pattern}" | sort -V | tail -n1) || return
local extension_filepath="${extensions_path}/${copilot_dir}/dist/extension.js"
if [[ -f "$extension_filepath" ]]; then
if [[ $silent_mode != 'silent' ]]; then
echo "Found $extension_name extension, applying 'rejectUnauthorized' patches to '$extension_filepath'"
fi
perl -pi -e 's/,rejectUnauthorized:[a-z]}(?!})/,rejectUnauthorized:false}/g' ${extension_filepath} || echo "Perl patch failed"
sed -i.bak 's/d={...l,/d={...l,rejectUnauthorized:false,/g' ${extension_filepath} || echo "Sed patch failed"
fi
}
perform_fix() {
if [[ -d "$HOME/$1" ]]; then
apply_patch "$1" "github.copilot-[0-9].*" "Copilot"
apply_patch "$1" "github.copilot-nightly-[0-9].*" "Copilot Nightly"
apply_patch "$1" "github.copilot-labs-[0-9].*" "Copilot Labs"
apply_patch "$1" "github.copilot-chat-[0-9].*" "Copilot Chat"
fi
}
perform_fix ".vscode"
perform_fix ".vscode-server"
perform_fix ".vscode-insiders"
perform_fix ".vscode-server-insiders"
unset -f apply_patch
unset -f perform_fix
}
fix_github_copilot silent
@JADGardner
Copy link

Thanks for this!

@s1lvester
Copy link

Thank you! Works like a Charm for remote Editors!

@shlomo20
Copy link

shlomo20 commented Mar 23, 2023

Thanks! I tried so many things, this is the only thing that worked for me!!!
although it didn't work for GitHub.copilot-labs....

@sarimarton
Copy link
Author

sarimarton commented Mar 23, 2023

@shlomo20 I have extra notes on copilot labs on my company laptop, I just paste it here as is:

Make Github Copilot/Nightly/Labs/Chat work

@OTgiraffe
Copy link

Thanks, It work for me

@armand-hoxha25
Copy link

Thank you so much!

@jtele2
Copy link

jtele2 commented May 25, 2023

Does this work with Github Copilot Chat?

I answered my own question by adding this line to the script, and following the direction per @shlomo20 above. Thanks guys!

patch_ext "$1" "github.copilot-chat-[0-9].*" "Copilot Chat"

@sarimarton
Copy link
Author

Thanks @jtele2, I've added the line.

@jtele2
Copy link

jtele2 commented May 26, 2023

Thank you @sarimarton, and I've also mentioned your gist here: microsoft/vscode-copilot-release#136

@selabie68
Copy link

It would appear they have patched this out now.

The proxy connection couldn't be established due to an untrusted self-signed certificate, or your Copilot license might not support their use.

@jtele2
Copy link

jtele2 commented Aug 16, 2023

@selabie68 What do you mean - it is no longer a work-around anymore?

@mrsoo
Copy link

mrsoo commented Nov 20, 2023

thanks you so much <3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment