Been there, done that.
1)
I have not used the python client yet. I wrote my tests using requests instead.
2)
For setting up a server I edited swagger_server/__main__.py
#!/usr/bin/env python3
import connexion
from .encoder import JSONEncoder
import ssl
from pathlib import Path
from pathlib import PurePath
import os
if __name__ == '__main__':
p = Path('.')
vis_cert = list(p.glob('**/Certificate_VIS*.pem'))
if len(vis_cert) == 0:
print('Error: no Certificate_VIS*.pem found')
vis_key = list(p.glob('**/PrivateKey_VIS*.pem'))
if len(vis_key) == 0:
print('Error: no PrivateKey_VIS*.pem found')
context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
context.load_cert_chain(str(vis_cert[0]), str(vis_key[0]))
app = connexion.App(__name__, specification_dir='./swagger/')
app.app.json_encoder = JSONEncoder
app.add_api('swagger.yaml', arguments={'title': 'Voyage Information Service API facing SeaSWIM through SSC exposing interfaces to SeaSWIM stakeholders'})
app.run(host='ec2-35-157-50-165.eu-central-1.compute.amazonaws.com', port=443, ssl_context=context)
In this project we are using self signed certificates which brings up a second problem. The root cert needs to be trusted by signging itself.
#!/bin/bash
sudo mkdir -p /usr/share/ca-certificates/MCtest
sudo cp MCtest/mc-ca-chain.pem /usr/share/ca-certificates/MCtest
sudo ln -s /usr/share/ca-certificates/MCtest/mc-ca-chain.pem /usr/lib/ssl/certs/dfa402ab.0
The last symbolic links have funny names. They are hashes of the root certificate DN. If you are using real certificates you do not need this.
For the client to connect to my server I may also need a client certificate. The connection code looks like this:
from pathlib import Path
p = Path('.')
vis_cert = list(p.glob('**/Certificate_VIS*.pem'))
if len(vis_cert) == 0:
print('Error: no Certificate_VIS*.pem found')
vis_key = list(p.glob('**/PrivateKey_VIS*.pem'))
if len(vis_key) == 0:
print('Error: no PrivateKey_VIS*.pem found')
vis_trust = list(p.glob('**/mc-ca-chain.pem'))
if len(vis_trust) == 0:
print('Error: no mc-ca-chain.pem found')
vis_cert=(str(vis_cert[0]), str(vis_key[0]))
trustchain=str(vis_trust[0])
def test_VIS_001_01(self):
"""
VIS-001-1 - VIS-2: Request (get) voyage plan with chosen UVID from VIS-1
"""
sub='/voyagePlans'
parameters={
'uvid': newvoyageuvid
}
response=requests.get(url + sub, params=parameters, cert=vis_cert, verify=trustchain)
self.assert200(response, "Response body is : " + response.text)
But then you still have the problems I am asking in my question.
- I have no way to find out how to get the identity of the client certificate from swagger generated python server.
- No solution for integrating this with uwsgi as the server is created as a module.
3)
For models you can use them like this
from swagger_server.models.voyage_plan import VoyagePlan
import json
vp = VoyagePlan()
vp.route = '<route />'
payload=voyageplan
response=requests.post(url, data=payload, cert=vis_cert, verify=trustchain)