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

Implement HTTPS Proxy Support #3816

Closed
cooperlees opened this issue Jun 6, 2019 · 2 comments · Fixed by #5992
Closed

Implement HTTPS Proxy Support #3816

cooperlees opened this issue Jun 6, 2019 · 2 comments · Fixed by #5992

Comments

@cooperlees
Copy link

cooperlees commented Jun 6, 2019

Long story short

Once TLS in TLS support is added to asyncio (https://bugs.python.org/issue37179) is landed to (hopefully) Python 3.8 we should plan including support for HTTPS Proxy servers if Python >= 3.8.

Expected behaviour

Have the ability to use no authentication HTTPS proxies and Authentication via using custom SSL Contexts: Example Code

Actual behaviour

Today we get explicitly told aiohttp can't do HTTPS proxies:

[cooper:~:( (aiohttp_auth_proxy))]$ python3.7 aioclient.py
HTTPS proxies https://proxy:1443 are not supported, ignoring

Steps to reproduce

Set via the environment or other means to use an HTTPS proxy.

#! /usr/bin/env python3
 
import asyncio
import logging
import os
import ssl
import sys
import time
 
import aiohttp
 
 
PROXY_PORT = 1443
PROXY_HOSTNAME = "https://proxy.company.com"
EXTERNAL_ENDPOINT = "https://www.google.com"
CA_BUNDLE = "/var/certs/ca.pem"
 
 
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
logger.addHandler(logging.StreamHandler(sys.stdout))
 
 
async def run_example():
    cert = os.environ["TLS_CL_CERT_PATH"]
    key = os.environ["TLS_CL_KEY_PATH"]
 
    if not cert or not key:
        raise ValueError("Missing key TLS cert settings.")
 
    # For the example lets ensure HTTPS_PROXY is set
    os.environ["HTTPS_PROXY"] = f"{PROXY_HOSTNAME}:{PROXY_PORT}"
 
    # Setup SSL Fun
    ssl_ctx = ssl.create_default_context(cafile=CA_BUNDLE)
    ssl_ctx.load_cert_chain(cert, key)
    conn = aiohttp.TCPConnector(ssl=ssl_ctx)
 
    start_time = time.time()
    # trust_env allows HTTP(s)_PROXY vars to work
    async with aiohttp.ClientSession(connector=conn, trust_env=True) as session:
        async with session.get(EXTERNAL_ENDPOINT) as response:
            logger.info(
                "Received response with status code "
                + f"{response.status} in {time.time() - start_time}s"
            )
 
 
if __name__ == "__main__":
    asyncio.run(run_example())

Your environment

  • Python 3.7.3
  • aiohttp 3.5.4
@cooperlees
Copy link
Author

cooperlees commented Jul 9, 2020

@1st1 has stated that this should work with uvloop. Would a PR be accepted that allow's uvloop enabled programs to work until we get the stdlib asyncio loop to have working TLS in TLS?

@webknjaz
Copy link
Member

webknjaz commented Jul 9, 2020

I think so

webknjaz added a commit to bmbouter/aiohttp that referenced this issue Oct 5, 2021
Resolves aio-libs#3816
Resolves aio-libs#4268

Co-Authored-By: Brian Bouterse <[email protected]>
Co-Authored-By: Jordan Borean <[email protected]>
Co-Authored-By: Sviatoslav Sydorenko <[email protected]>
webknjaz added a commit to bmbouter/aiohttp that referenced this issue Oct 5, 2021
Resolves aio-libs#3816
Resolves aio-libs#4268

Co-Authored-By: Brian Bouterse <[email protected]>
Co-Authored-By: Jordan Borean <[email protected]>
Co-Authored-By: Sviatoslav Sydorenko <[email protected]>
webknjaz added a commit to bmbouter/aiohttp that referenced this issue Oct 5, 2021
This patch opens up the code path and adds the implementation that
allows end-users to start sending HTTPS requests through
HTTPS proxies.

The support for TLS-in-TLS (needed for this to work) in the stdlib is
kinda available since Python 3.7 but is disabled for `asyncio` with an
attribute/flag/toggle. When the upstream CPython enables it finally,
aiohttp v3.8+ will be able to work with it out of the box.

Currently the tests monkey-patch `asyncio` in order to verify that
this works. The users who are willing to do the same, will be able to
take advantage of it right now. Eventually (hopefully starting Python
3.11), the need for monkey-patching should be eliminated.

Refs:
* https://bugs.python.org/issue37179
* python/cpython#28073
* https://docs.aiohttp.org/en/stable/client_advanced.html#proxy-support
* aio-libs#6044

Resolves aio-libs#3816
Resolves aio-libs#4268

Co-Authored-By: Brian Bouterse <[email protected]>
Co-Authored-By: Jordan Borean <[email protected]>
Co-Authored-By: Sviatoslav Sydorenko <[email protected]>
webknjaz added a commit to bmbouter/aiohttp that referenced this issue Oct 5, 2021
This patch opens up the code path and adds the implementation that
allows end-users to start sending HTTPS requests through
HTTPS proxies.

The support for TLS-in-TLS (needed for this to work) in the stdlib is
kinda available since Python 3.7 but is disabled for `asyncio` with an
attribute/flag/toggle. When the upstream CPython enables it finally,
aiohttp v3.8+ will be able to work with it out of the box.

Currently the tests monkey-patch `asyncio` in order to verify that
this works. The users who are willing to do the same, will be able to
take advantage of it right now. Eventually (hopefully starting Python
3.11), the need for monkey-patching should be eliminated.

Refs:
* https://bugs.python.org/issue37179
* python/cpython#28073
* https://docs.aiohttp.org/en/stable/client_advanced.html#proxy-support
* aio-libs#6044

Resolves aio-libs#3816
Resolves aio-libs#4268

Co-Authored-By: Brian Bouterse <[email protected]>
Co-Authored-By: Jordan Borean <[email protected]>
Co-Authored-By: Sviatoslav Sydorenko <[email protected]>
webknjaz added a commit that referenced this issue Oct 5, 2021
This patch opens up the code path and adds the implementation that
allows end-users to start sending HTTPS requests through
HTTPS proxies.

The support for TLS-in-TLS (needed for this to work) in the stdlib is
kinda available since Python 3.7 but is disabled for `asyncio` with an
attribute/flag/toggle. When the upstream CPython enables it finally,
aiohttp v3.8+ will be able to work with it out of the box.

Currently the tests monkey-patch `asyncio` in order to verify that
this works. The users who are willing to do the same, will be able to
take advantage of it right now. Eventually (hopefully starting Python
3.11), the need for monkey-patching should be eliminated.

Refs:
* https://bugs.python.org/issue37179
* python/cpython#28073
* https://docs.aiohttp.org/en/stable/client_advanced.html#proxy-support
* #6044

PR #5992
Resolves #3816
Resolves #4268

Co-authored-by: Brian Bouterse <[email protected]>
Co-authored-by: Jordan Borean <[email protected]>
Co-authored-by: Sviatoslav Sydorenko <[email protected]>
webknjaz pushed a commit to webknjaz/aiohttp that referenced this issue Oct 5, 2021
This patch opens up the code path and adds the implementation that
allows end-users to start sending HTTPS requests through
HTTPS proxies.

The support for TLS-in-TLS (needed for this to work) in the stdlib is
kinda available since Python 3.7 but is disabled for `asyncio` with an
attribute/flag/toggle. When the upstream CPython enables it finally,
aiohttp v3.8+ will be able to work with it out of the box.

Currently the tests monkey-patch `asyncio` in order to verify that
this works. The users who are willing to do the same, will be able to
take advantage of it right now. Eventually (hopefully starting Python
3.11), the need for monkey-patching should be eliminated.

Refs:
* https://bugs.python.org/issue37179
* python/cpython#28073
* https://docs.aiohttp.org/en/stable/client_advanced.html#proxy-support
* aio-libs#6044

PR aio-libs#5992
Resolves aio-libs#3816
Resolves aio-libs#4268

Co-authored-by: Brian Bouterse <[email protected]>
Co-authored-by: Jordan Borean <[email protected]>
Co-authored-by: Sviatoslav Sydorenko <[email protected]>
(cherry picked from commit c29e5fb)
webknjaz pushed a commit to webknjaz/aiohttp that referenced this issue Oct 5, 2021
This patch opens up the code path and adds the implementation that
allows end-users to start sending HTTPS requests through
HTTPS proxies.

The support for TLS-in-TLS (needed for this to work) in the stdlib is
kinda available since Python 3.7 but is disabled for `asyncio` with an
attribute/flag/toggle. When the upstream CPython enables it finally,
aiohttp v3.8+ will be able to work with it out of the box.

Currently the tests monkey-patch `asyncio` in order to verify that
this works. The users who are willing to do the same, will be able to
take advantage of it right now. Eventually (hopefully starting Python
3.11), the need for monkey-patching should be eliminated.

Refs:
* https://bugs.python.org/issue37179
* python/cpython#28073
* https://docs.aiohttp.org/en/stable/client_advanced.html#proxy-support
* aio-libs#6044

PR aio-libs#5992
Resolves aio-libs#3816
Resolves aio-libs#4268

Co-authored-by: Brian Bouterse <[email protected]>
Co-authored-by: Jordan Borean <[email protected]>
Co-authored-by: Sviatoslav Sydorenko <[email protected]>
(cherry picked from commit c29e5fb)
webknjaz pushed a commit to webknjaz/aiohttp that referenced this issue Oct 11, 2021
This patch opens up the code path and adds the implementation that
allows end-users to start sending HTTPS requests through
HTTPS proxies.

The support for TLS-in-TLS (needed for this to work) in the stdlib is
kinda available since Python 3.7 but is disabled for `asyncio` with an
attribute/flag/toggle. When the upstream CPython enables it finally,
aiohttp v3.8+ will be able to work with it out of the box.

Currently the tests monkey-patch `asyncio` in order to verify that
this works. The users who are willing to do the same, will be able to
take advantage of it right now. Eventually (hopefully starting Python
3.11), the need for monkey-patching should be eliminated.

Refs:
* https://bugs.python.org/issue37179
* python/cpython#28073
* https://docs.aiohttp.org/en/stable/client_advanced.html#proxy-support
* aio-libs#6044

PR aio-libs#5992
Resolves aio-libs#3816
Resolves aio-libs#4268

Co-authored-by: Brian Bouterse <[email protected]>
Co-authored-by: Jordan Borean <[email protected]>
Co-authored-by: Sviatoslav Sydorenko <[email protected]>
(cherry picked from commit c29e5fb)
webknjaz pushed a commit to webknjaz/aiohttp that referenced this issue Oct 12, 2021
This patch opens up the code path and adds the implementation that
allows end-users to start sending HTTPS requests through
HTTPS proxies.

The support for TLS-in-TLS (needed for this to work) in the stdlib is
kinda available since Python 3.7 but is disabled for `asyncio` with an
attribute/flag/toggle. When the upstream CPython enables it finally,
aiohttp v3.8+ will be able to work with it out of the box.

Currently the tests monkey-patch `asyncio` in order to verify that
this works. The users who are willing to do the same, will be able to
take advantage of it right now. Eventually (hopefully starting Python
3.11), the need for monkey-patching should be eliminated.

Refs:
* https://bugs.python.org/issue37179
* python/cpython#28073
* https://docs.aiohttp.org/en/stable/client_advanced.html#proxy-support
* aio-libs#6044

PR aio-libs#5992
Resolves aio-libs#3816
Resolves aio-libs#4268

Co-authored-by: Brian Bouterse <[email protected]>
Co-authored-by: Jordan Borean <[email protected]>
Co-authored-by: Sviatoslav Sydorenko <[email protected]>
(cherry picked from commit c29e5fb)
webknjaz added a commit that referenced this issue Oct 12, 2021
…ent (#6049)

This patch opens up the code path and adds the implementation that
allows end-users to start sending HTTPS requests through
HTTPS proxies.

The support for TLS-in-TLS (needed for this to work) in the stdlib is
kinda available since Python 3.7 but is disabled for `asyncio` with an
attribute/flag/toggle. When the upstream CPython enables it finally,
aiohttp v3.8+ will be able to work with it out of the box.

Currently the tests monkey-patch `asyncio` in order to verify that
this works. The users who are willing to do the same, will be able to
take advantage of it right now. Eventually (hopefully starting Python
3.11), the need for monkey-patching should be eliminated.

Refs:
* bugs.python.org/issue37179
* python/cpython#28073
* docs.aiohttp.org/en/stable/client_advanced.html#proxy-support
* #6044

PR #5992
Resolves #3816
Resolves #4268

Co-authored-by: Brian Bouterse <[email protected]>
Co-authored-by: Jordan Borean <[email protected]>
Co-authored-by: Sviatoslav Sydorenko <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants