-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
61 lines (42 loc) · 1.19 KB
/
Copy pathapp.py
File metadata and controls
61 lines (42 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# app.py
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def read_root():
return {"message": "Hello, secure world!"}
'''
OpenSSL is a widely used, open-source software library and toolkit that
implements the Secure Sockets Layer (SSL) and Transport Layer Security (TLS) protocols.
Steps to set up HTTPS:
1) openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes
2) uvicorn app:app \
--host 0.0.0.0 \
--port 8443 \
--ssl-keyfile=key.pem \
--ssl-certfile=cert.pem:
Which starts API on:
https://localhost:8443
3) Real Production Flow (Important)
In production -x509 is not used.
Instead:
Server → Generate CSR (Certificate Signing Request)
CSR → Sent to Certificate Authority
CA → Issues trusted certificate
Example CA:
1)Let's Encrypt
2)Cloudflare
3)DigiCert
Then command used as: openssl req -new -key key.pem -out mycsr.csr
CSR contains:
- Public key
- Domain name
- Organization info
Send CSR to CA.
The CA verifies:
- You control the domain
- Your organization info (for extended validation)
CA issues a certificate
- Signed by the CA
- Trusted by browsers
It can be installed on server and Browser trusts this certificate automatically.
'''