Skip to content

Instantly share code, notes, and snippets.

@wandernauta
Last active August 27, 2015 13:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wandernauta/5eeb012f2039bb2fb0d0 to your computer and use it in GitHub Desktop.
Save wandernauta/5eeb012f2039bb2fb0d0 to your computer and use it in GitHub Desktop.
Authenticating Estonian ID cards using Flask and nginx
import re
from flask import Flask, request
app = Flask(__name__)
@app.route("/")
def hello():
dn = request.headers['X-Client']
fields = dict(re.findall("/([^=]*)=([^/]*)", dn))
doctype = "<!doctype html>"
title = "<title>eID test</title>"
style = "<style>body{text-align:center;font-family:sans-serif;}</style>"
content = "<h2><br><br>HEY THERE, {GN} {SN}!</h2>"
return doctype + title + style + content.format(**fields)
if __name__ == "__main__":
app.run(debug=True, port=8080)
events {}
http {
server {
listen 443 ssl;
ssl_certificate /etc/nginx/ssl/server.crt;
ssl_certificate_key /etc/nginx/ssl/server.key;
ssl_client_certificate /etc/nginx/ssl/id.crt;
ssl_verify_client on;
ssl_verify_depth 3;
location / {
proxy_pass http://localhost:8080/;
proxy_set_header X-Client $ssl_client_s_dn;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment