This is a demo server. It will only work with smart-cards isseud by the Swiss Government. The aim of this demo project is to authenticate users using only their smart-card and their browser against the server without any other 3rd-party software required (except of course the smart-card drivers).
Only minor modifications are necessary for this project to work with other (i.e., non-SwissGov) smart-cards:
- Replace
<project-root>/cert/root/swissgov-root-ca1.p7bwith the issuing root X.509 certificate. - Replace
<project-root>/cert/root/swissgov-enhanced-ca02.p7bwith the issuing certificate chain. This file may also be identical to<project-root>/cert/root/swissgov-root-ca1.p7b. - Change the following lines in
<project-root>/root/server.pyif needed:- CERTIFICATE_CLIENT_ROOT_P7B : str = f'{CERTIFICATE_ROOT_DIR}/swissgov-root-ca1.p7b' + CERTIFICATE_CLIENT_ROOT_P7B : str = f'{CERTIFICATE_ROOT_DIR}/your-certificate-root.p7b' CERTIFICATE_CLIENT_ROOT_PEM : str = CERTIFICATE_CLIENT_ROOT_P7B[:-4] + '.pem' - CERTIFICATE_CLIENT_KEYCHAIN_P7B : str = f'{CERTIFICATE_ROOT_DIR}/swissgov-enhanced-ca02.p7b' + CERTIFICATE_CLIENT_KEYCHAIN_P7B : str = f'{CERTIFICATE_ROOT_DIR}/your-certificate-chain.p7b' CERTIFICATE_CLIENT_KEYCHAIN_PEM : str = CERTIFICATE_CLIENT_KEYCHAIN_P7B[:-4] + '.pem'
- Note that you can also exclusively use the
.pemformat instead of.p7b, but that would require also removing the following lines:- if not(os.path.exists(CERTIFICATE_CLIENT_ROOT_PEM)): - convert_p7b_to_pem(CERTIFICATE_CLIENT_ROOT_P7B, CERTIFICATE_CLIENT_ROOT_PEM) - - if not(os.path.exists(CERTIFICATE_CLIENT_KEYCHAIN_PEM)): - convert_p7b_to_pem(CERTIFICATE_CLIENT_KEYCHAIN_P7B, CERTIFICATE_CLIENT_KEYCHAIN_PEM)
- Install the smart-card drivers for the cards issued by the Swiss Government. You can find them on the Thales website.
- Install python.
- Run the following commands in your terminal:
git clone https://github.com/Unknown6656/SmartcardWebAuthTest pip install pyopenssl werkzeug flask mkdir cert/user mkdir cert/root
- Download the Swiss Government X.509 root certificates from https://www.bit.admin.ch/bit/en/home/themes/swiss-government-pki/certificate-service-provider-csp/rootzertifikate/swiss-government-root-ca-i.html and place them in the directory
cert/root.Swiss Government Root CA ISwiss Government Enhanced CA 01Swiss Government Enhanced CA 02
- Download all X.509 certificates of users you want to "whitelist" from the following pages. Place the user certificates in
cert/user.- https://admindir.verzeichnisse.admin.ch/ [Swiss Intranet only]
- https://staatskalender.admin.ch/ [Public]
- Run the following command in your terminal to start the webserver.
python server.py
- Navigate to
https://localhost:6996/ - Connect your smart-card issued by the Swiss Government.
- Select the smart-card certificate you want to use for the authentication:

- Enter your PIN:

- Success.

- If unsuccessful, the following message is displayed:
