Loading capif_backend/backoffice_service/__main__.py +17 −16 Original line number Diff line number Diff line Loading @@ -6,11 +6,13 @@ import json import requests import os # Create Flask app app = Flask(__name__) # Register blueprints (routes) app.register_blueprint(backoffice_routes) # create public/private key # create public/PRIVATE key key = PKey() key.generate_key(TYPE_RSA, 2048) Loading @@ -26,40 +28,37 @@ req.get_subject().emailAddress = 'inno@tid.es' req.set_pubkey(key) req.sign(key, 'sha256') # Get CSR csr_request = dump_certificate_request(FILETYPE_PEM, req) # Get private key private_key = dump_privatekey(FILETYPE_PEM, key) config = Config().get_config() url = f"http://{config['ca_factory']['url']}:{config['ca_factory']['port']}/v1/secret/data/ca" headers = { 'X-Vault-Token': config['ca_factory']['token'] } # Get ca.cert from vault config = Config().get_config() # get configuration from config.py url = f"http://{config['ca_factory']['url']}:{config['ca_factory']['port']}/v1/secret/data/ca" # http://vault:8200/v1/secret/data/ca headers = {'X-Vault-Token': config['ca_factory']['token']} response = requests.request("GET", url, headers=headers, verify = False) ca_cert = json.loads(response.text)["data"]["data"]["ca"] url = f"http://{config['ca_factory']['url']}:{config['ca_factory']['port']}/v1/pki_int/sign/my-ca" headers = {'X-Vault-Token': config['ca_factory']['token']} # Request Vault a CA certificate to backoffice application url = f"http://{config['ca_factory']['url']}:{config['ca_factory']['port']}/v1/pki_int/sign/my-ca" # http://vault:8200/v1/pki_int/sign/my-ca headers = {'X-Vault-Token': config['ca_factory']['token']} # token = dev-only-token data = { 'format':'pem_bundle', 'ttl': '43000h', 'csr': csr_request, 'common_name': "superadmin" } response = requests.request("POST", url, headers=headers, data=data, verify = False) backoffice_cert = json.loads(response.text)['data']['certificate'] # Save private_key private_key_file = open("./backoffice_service/certs/backoffice_vault_private_key.key", 'wb+') private_key_file.write(private_key) private_key_file.close() # Save backoffice_cert certification_file = open('./backoffice_service/certs/backoffice_vault_cert.crt', 'wb+') certification_file.write(bytes(backoffice_cert, 'utf-8')) certification_file.close() Loading @@ -68,6 +67,8 @@ certification_file.close() # launch #---------------------------------------- # the applicacions starts here in every interface and port 8080 # ssl -> contains backoffice_cert.crt and backoffice_key.key if __name__ == "__main__": app.run(debug=True, host='0.0.0.0', port=8080, ssl_context=( "/usr/src/app/backoffice_service/certs/backoffice_cert.crt", "/usr/src/app/backoffice_service/certs/backoffice_key.key")) Loading
capif_backend/backoffice_service/__main__.py +17 −16 Original line number Diff line number Diff line Loading @@ -6,11 +6,13 @@ import json import requests import os # Create Flask app app = Flask(__name__) # Register blueprints (routes) app.register_blueprint(backoffice_routes) # create public/private key # create public/PRIVATE key key = PKey() key.generate_key(TYPE_RSA, 2048) Loading @@ -26,40 +28,37 @@ req.get_subject().emailAddress = 'inno@tid.es' req.set_pubkey(key) req.sign(key, 'sha256') # Get CSR csr_request = dump_certificate_request(FILETYPE_PEM, req) # Get private key private_key = dump_privatekey(FILETYPE_PEM, key) config = Config().get_config() url = f"http://{config['ca_factory']['url']}:{config['ca_factory']['port']}/v1/secret/data/ca" headers = { 'X-Vault-Token': config['ca_factory']['token'] } # Get ca.cert from vault config = Config().get_config() # get configuration from config.py url = f"http://{config['ca_factory']['url']}:{config['ca_factory']['port']}/v1/secret/data/ca" # http://vault:8200/v1/secret/data/ca headers = {'X-Vault-Token': config['ca_factory']['token']} response = requests.request("GET", url, headers=headers, verify = False) ca_cert = json.loads(response.text)["data"]["data"]["ca"] url = f"http://{config['ca_factory']['url']}:{config['ca_factory']['port']}/v1/pki_int/sign/my-ca" headers = {'X-Vault-Token': config['ca_factory']['token']} # Request Vault a CA certificate to backoffice application url = f"http://{config['ca_factory']['url']}:{config['ca_factory']['port']}/v1/pki_int/sign/my-ca" # http://vault:8200/v1/pki_int/sign/my-ca headers = {'X-Vault-Token': config['ca_factory']['token']} # token = dev-only-token data = { 'format':'pem_bundle', 'ttl': '43000h', 'csr': csr_request, 'common_name': "superadmin" } response = requests.request("POST", url, headers=headers, data=data, verify = False) backoffice_cert = json.loads(response.text)['data']['certificate'] # Save private_key private_key_file = open("./backoffice_service/certs/backoffice_vault_private_key.key", 'wb+') private_key_file.write(private_key) private_key_file.close() # Save backoffice_cert certification_file = open('./backoffice_service/certs/backoffice_vault_cert.crt', 'wb+') certification_file.write(bytes(backoffice_cert, 'utf-8')) certification_file.close() Loading @@ -68,6 +67,8 @@ certification_file.close() # launch #---------------------------------------- # the applicacions starts here in every interface and port 8080 # ssl -> contains backoffice_cert.crt and backoffice_key.key if __name__ == "__main__": app.run(debug=True, host='0.0.0.0', port=8080, ssl_context=( "/usr/src/app/backoffice_service/certs/backoffice_cert.crt", "/usr/src/app/backoffice_service/certs/backoffice_key.key"))