aio-libs / aio-libs/aiohttp

Peercert is None

Offen
#7,466 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
bug
Vorherrschende Sprache
Python
Sterne
16.5k
Forks
2.4k
Ø Merge
17 Std. 22 Min.
Gemergte PRs (30 T.)
212

Beschreibung

### Describe the bug

Why `request.transport.get_extra_info("peercert") ` return None if the connection is secured and the client has his own certificate
Or how to get information about client certificate in "hello" function.

### To Reproduce

Server example:
```
import os
import ssl

async def hello(request):
cert = request.transport.get_extra_info("peercert") # return None

# I want to get client certificate properties here

return web.Response(text="Hello world")

def create_ssl_context_server():
ssl_cntx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
localhost_pem = os.path.abspath(os.environ["CERT_PATH"])
private_key = os.path.abspath(os.environ["KEY_PATH"])
ssl_cntx.load_cert_chain(
certfile=localhost_pem,
keyfile=private_key,
)
ssl_cntx.ski = cert_file_ski_validate(localhost_pem) # type: ignore
ssl_cntx.self_signed = int(self_signed) # type: ignore
return ssl_cntx

def create_app():

app = aiohttp.web.Application()
app.router.add_route("GET", "/hello", hello)

return app

if __name__ == "__main__":

ssl_context_server = create_ssl_context_server()
app = create_app()

web.run_app(app, ssl_context=ssl_context_server)`
```

Client example:
`
```
import ssl
import aiohttp
import asyncio

def client_session(url):
ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
ssl_context.load_cert_chain(
certfile="",
keyfile=""
)

session = aiohttp.ClientSession(
base_url=f"https://{url}",
connector=aiohttp.TCPConnector(ssl=ssl_context, force_close=True, enable_cleanup_closed=True),
)
return session

async def main():
session = client_session("localhost:8000")

async with session.get('/hello') as response:

if response.status == 200:
rtxt = await response.text()

print(rtxt)

if __name__ == "__main__":
asyncio.run(main())
```

### Expected behavior

I expect to get client certificate by `request.transport.get_extra_info("peercert")`

### Logs/tracebacks

```python-traceback
I use Client session because in the real project I need a secured websocket.
```

### Python Version

```console
Python 3.10.12
```

### aiohttp Version

```console
Version: 3.8.4
```

### multidict Version

```console
Version: 6.0.4
```

### yarl Version

```console
Version: 1.8.2
```

### OS

Ubuntu 20.04

### Related component

Server, Client

### Additional context

_No response_

### Code of Conduct

- [X] I agree to follow the aio-libs Code of Conduct

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.