Skip to content
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

Automate configuring Dev Proxy certificate on Linux #601

Open
plachance-qohash opened this issue Mar 11, 2024 · 5 comments
Open

Automate configuring Dev Proxy certificate on Linux #601

plachance-qohash opened this issue Mar 11, 2024 · 5 comments
Assignees
Labels
enhancement New feature or request work in progress

Comments

@plachance-qohash
Copy link

plachance-qohash commented Mar 11, 2024

Description

Hey everyone,

I've been trying to get devproxy to work on Linux for HTTPS proxying, but I'm hitting a wall.
It works fine with HTTP, and on Windows, it's working as per the documentation.
However, when I switch to Linux, HTTPS isn't cooperating.

I even tried exporting the Windows certificate and adding it to the trusted root certificates on Linux, but no luck there.

I've checked the docs, but I can't seem to find a fix. Any help or advice would be greatly appreciated!

I tried on Ubuntu app (Windows 11 pro wsl2)
I tried on Ubuntu 18.04
I tried on a Docker container based on Ubuntu 22.04

Thanks!

Expected behaviour

The devproxy binary should register a root certificate when --install-cert is used

Actual behaviour

Any attempt to access a website through the proxy with HTTPS results with an error.

Steps to reproduce

Install dev proxy on a Linux (ubuntu) environment following documented instructions.

cd ~/devproxy
./devproxy --install-cert --log-level trace

Output is:

Loading plugin RetryAfterPlugin from: /home/patrick/devproxy/plugins/dev-proxy-plugins.dll
Loading plugin GenericRandomErrorPlugin from: /home/patrick/devproxy/plugins/dev-proxy-plugins.dll
8 error responses loaded from /home/patrick/devproxy/devproxy-errors.json
Listening on 127.0.0.1:8000...
  WARNING: Configure your operating system to use this proxy's port and address [127.0.0.1:8000](http://127.0.0.1:8000/)
Press CTRL+C to stop Dev Proxy

Open another terminal and try this:

wget -e use_proxy=yes -e https_proxy=https://127.0.0.1:8000/ https://jsonplaceholder.typicode.com/posts

The output:

Connecting to 127.0.0.1:8000... connected.
ERROR: cannot verify [jsonplaceholder.typicode.com](http://jsonplaceholder.typicode.com/)'s certificate, issued by ‘CN=Dev Proxy CA’:
  Unable to locally verify the issuer's authority.
To connect to [jsonplaceholder.typicode.com](http://jsonplaceholder.typicode.com/) insecurely, use `--no-check-certificate'.

If we follow recommendation and add --no-check-certificate, it works

 request     GET https://jsonplaceholder.typicode.com/posts
     api   ╭ Passed through
           ╰ GET https://jsonplaceholder.typicode.com/posts

Dev Proxy Version

0.15.0

Operating system (environment)

Linux

Shell

bash

Configuration file

{
"$schema": "https://raw.githubusercontent.com/microsoft/dev-proxy/main/schemas/v0.15.0/rc.schema.json",
"plugins": [
{
"name": "RetryAfterPlugin",
"enabled": true,
"pluginPath": "~appFolder/plugins/dev-proxy-plugins.dll"
},
{
"name": "GenericRandomErrorPlugin",
"enabled": true,
"pluginPath": "~appFolder/plugins/dev-proxy-plugins.dll",
"configSection": "genericRandomErrorPlugin"
}
],
"urlsToWatch": [
"https://jsonplaceholder.typicode.com/*"
],
"genericRandomErrorPlugin": {
"errorsFile": "devproxy-errors.json"
},
"rate": 50,
"labelMode": "text",
"logLevel": "information",
"newVersionNotification": "stable"
}

Additional Info

No response

@plachance-qohash plachance-qohash added the bug Something isn't working label Mar 11, 2024
@plachance-qohash
Copy link
Author

My attempt to use windows' rootCert.pfx:

Open git bash, and navigate to my windows' devproxy install directory.
openssl pkcs12 -in .\rootCert.pfx -out rootCert.crt -nodes

Then extract the certificate and copy it in a new file named dev-proxy-ca.crt

Switch to Ubuntu.

sudo cp dev-proxy-ca.crt /usr/local/share/ca-certificates/
sudo chmod 644 /usr/local/share/ca-certificates/dev-proxy-ca.crt
sudo update-ca-certificates

Output:

Updating certificates in /etc/ssl/certs...
rehash: warning: skipping ca-certificates.crt,it does not contain exactly one certificate or CRL
1 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d...

Adding debian:dev-proxy-ca.pem
done.
done.

Retrying the same test above (see steps to reproduce) and it still fails with the same error.

@plachance-qohash
Copy link
Author

plachance-qohash commented Mar 12, 2024

I found a workaround.

Using Ubuntu 18.04, VSCode and the latest .net sdk,
I built the repository, set a breakpoint in the Proxy engine and started the app with --install-cert.
Stepping through the code, I was able to locate the certificate written during the initial start of the proxy.
The certificate installation still doesn't work but we can find the pfx file under this directory: ~/.config/dev-proxy/rootCert.pfx

Using the same procedure I described in my previous comment for the Windows certificate, it is now working as expected.

Important notes:

  • The certificate can't be reused. If it doesn't exist, a new certificate is created. If you test locally on your work desktop, you can't copy the certificate to another linux environment.
  • If the proxy runs in a docker container, the certificate is created in the [working dir]/dev-proxy/rootCert.pfx
  • If you want to use the docker container as proxy for your host machine you need to docker cp the file on the host and register the public certificate in the host trust store.

@waldekmastykarz
Copy link
Collaborator

Thank you for reaching out to us @plachance-qohash and sorry for the lack of clarity on our part. Like you noticed, we don't automatically register the root cert on Linux at the moment. I appreciate you digging into it and sharing your findings with us. It'll help us extend proxy with automatic setup on Linux. Speaking of which, would you be willing to contribute an equivalent of the macOS certificate setup script for Linux?

@waldekmastykarz waldekmastykarz added enhancement New feature or request and removed bug Something isn't working labels Mar 12, 2024
@waldekmastykarz waldekmastykarz changed the title [BUG]: Issue with Devproxy in Linux for HTTPS Proxy Automate configuring Dev Proxy certificate on Linux Mar 12, 2024
@plachance-qohash
Copy link
Author

plachance-qohash commented Mar 15, 2024

Hello @waldekmastykarz
Yes, I will be happy to contribute a script for Linux configuration. Additionally, I will post a comment on how to utilize the dev-proxy within a Docker container and Docker Compose, enabling integration tests. I am currently working on the setup, and I'll share my findings in this thread as soon as possible.

@waldekmastykarz
Copy link
Collaborator

Awesome! Looking forward to it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request work in progress
Projects
None yet
Development

No branches or pull requests

2 participants