aio-libs / aio-libs/aiohttp

Peercert is None

Đang mở
#7,466 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
bug
Ngôn ngữ chính
Python
Star
16.5k
Fork
2.4k
Merge trung bình
17 giờ 22 phút
Pull request đã merge (30 ngày)
212

Mô tả

### 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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.