Loading capif_backend/Dockerfile +3 −0 Original line number Diff line number Diff line Loading @@ -15,6 +15,9 @@ RUN apk add jq RUN apk add curl RUN apk add redis # Copiar el script generate_certs.py COPY backoffice_service/generate_certs.py /usr/src/app/generate_certs.py COPY . /usr/src/app EXPOSE 8080 Loading capif_backend/backoffice_service/__main__.py +41 −36 Original line number Diff line number Diff line Loading @@ -69,42 +69,47 @@ csr_request = dump_certificate_request(FILETYPE_PEM, req) private_key = dump_privatekey(FILETYPE_PEM, key) # Get ca.cert from vault # config = Config().get_config() # get configuration from config.py # url = 'http://{}:{}/v1/secret/data/ca'.format(os.getenv('VAULT_HOSTNAME'), os.getenv('VAULT_PORT')) # http://vault:8200/v1/secret/data/ca # headers = {'X-Vault-Token': os.getenv('VAULT_TOKEN')} # response = requests.request("GET", url, headers=headers, verify = False) # ca_cert = json.loads(response.text)["data"]["data"]["ca"] # # print ("CA CERT URL: ", url) # # print ("VAULT_HOSTNAME", os.get_environ('VAULT_HOSTNAME')) # # print ("VAULT_PORT", os.get_environ('VAULT_PORT')) # # Request Vault a CA certificate to backoffice application # url = 'http://{}:{}/v1/pki_int/sign/my-ca'.format(os.getenv('VAULT_HOSTNAME'), os.getenv('VAULT_PORT')) # http://vault:8200/v1/pki_int/sign/my-ca # headers = {'X-Vault-Token': os.getenv('VAULT_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 ca_cert # ca_file = open('./backoffice_service/certs/ca.crt', 'wb+') # ca_file.write(bytes(ca_cert, 'utf-8')) # ca_file.close() # # 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() config = Config().get_config() # get configuration from config.py url = 'http://{}:{}/v1/secret/data/ca'.format(os.getenv('VAULT_HOSTNAME'), os.getenv('VAULT_PORT')) # http://vault:8200/v1/secret/data/ca headers = {'X-Vault-Token': os.getenv('VAULT_TOKEN')} response = requests.request("GET", url, headers=headers, verify = False) ca_cert = json.loads(response.text)["data"]["data"]["ca"] # print ("CA CERT URL: ", url) # print ("VAULT_HOSTNAME", os.get_environ('VAULT_HOSTNAME')) # print ("VAULT_PORT", os.get_environ('VAULT_PORT')) # Request Vault a CA certificate to backoffice application url = 'http://{}:{}/v1/pki_int/sign/my-ca'.format(os.getenv('VAULT_HOSTNAME'), os.getenv('VAULT_PORT')) # http://vault:8200/v1/pki_int/sign/my-ca headers = {'X-Vault-Token': os.getenv('VAULT_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'] # Ensure the certs directory exists os.makedirs('newcerts', exist_ok=True) # Save ca_cert ca_file = open('newcerts/ca_root.crt', 'wb+') ca_file.write(bytes(ca_cert, 'utf-8')) ca_file.close() # Save private_key private_key_file = open("newcerts/superadmin.key", 'wb+') private_key_file.write(private_key) private_key_file.close() # Save backoffice_cert certification_file = open('newcerts/superadmin.crt', 'wb+') certification_file.write(bytes(backoffice_cert, 'utf-8')) certification_file.close() #---------------------------------------- # launch Loading capif_backend/backoffice_service/controllers/users_controller.py +8 −8 Original line number Diff line number Diff line Loading @@ -75,14 +75,14 @@ def get_capif_num_users(): # return jsonify(message="Invalid name", object=None), 400 # return operations.get_user(name) # # GET a JSON with all users # @cross_origin() # @users_routes.route("/users", methods=["GET"]) # @jwt_required() # def get_capif_users(): # if id == "null": # return jsonify(message="Invalid id", object=None), 400 # return operations.get_users() # GET a JSON with all users @cross_origin() @users_routes.route("/users", methods=["GET"]) @jwt_required() def get_capif_users(): if id == "null": return jsonify(message="Invalid id", object=None), 400 return operations.get_users_total() # # GET users with pagination # @cross_origin() Loading capif_backend/backoffice_service/core/operations.py +84 −871 File changed.Preview size limit exceeded, changes collapsed. Show changes capif_backend/backoffice_service/generate_certs.py 0 → 100644 +80 −0 Original line number Diff line number Diff line import os import json import requests from OpenSSL.crypto import PKey, TYPE_RSA, X509Req, dump_certificate_request, dump_privatekey, FILETYPE_PEM # Configure JWT (dummy example, not used in this script) JWT_SECRET_KEY = "super-secret" # create public/PRIVATE key key = PKey() key.generate_key(TYPE_RSA, 2048) # Generate CSR req = X509Req() req.get_subject().O = 'Telefonica I+D' req.get_subject().OU = 'Innovation' req.get_subject().L = 'Madrid' req.get_subject().ST = 'Madrid' req.get_subject().C = 'ES' 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) # Get ca.cert from vault VAULT_HOSTNAME = os.getenv('VAULT_HOSTNAME') VAULT_PORT = os.getenv('VAULT_PORT') VAULT_TOKEN = os.getenv('VAULT_TOKEN') url = f'http://{VAULT_HOSTNAME}:{VAULT_PORT}/v1/secret/data/ca' headers = {'X-Vault-Token': VAULT_TOKEN} response = requests.get(url, headers=headers, verify=False) ca_cert = json.loads(response.text)["data"]["data"]["ca"] # Request Vault a CA certificate to backoffice application url = f'http://{VAULT_HOSTNAME}:{VAULT_PORT}/v1/pki_int/sign/my-ca' data = { 'format': 'pem_bundle', 'ttl': '43000h', 'csr': csr_request.decode('utf-8'), 'common_name': "superadmin" } response = requests.post(url, headers=headers, data=data, verify=False) backoffice_cert = json.loads(response.text)['data']['certificate'] # Ensure the certs directory exists os.makedirs('backoffice_service/core/newcerts', exist_ok=True) # Save ca_cert ca_file_path = 'backoffice_service/core/newcerts/ca_root.crt' with open(ca_file_path, 'wb+') as ca_file: ca_file.write(bytes(ca_cert, 'utf-8')) print(f"CA Certificate saved at: {ca_file_path}") # Save private_key private_key_file_path = "backoffice_service/core/newcerts/superadmin.key" with open(private_key_file_path, 'wb+') as private_key_file: private_key_file.write(private_key) print(f"Private Key saved at: {private_key_file_path}") # Save backoffice_cert certification_file_path = 'backoffice_service/core/newcerts/superadmin.crt' with open(certification_file_path, 'wb+') as certification_file: certification_file.write(bytes(backoffice_cert, 'utf-8')) print(f"Backoffice Certificate saved at: {certification_file_path}") # Print the contents of the saved files with open(ca_file_path, 'r') as ca_file: print(f"CA Certificate content:\n{ca_file.read()}") with open(private_key_file_path, 'r') as private_key_file: print(f"Private Key content:\n{private_key_file.read()}") with open(certification_file_path, 'r') as certification_file: print(f"Backoffice Certificate content:\n{certification_file.read()}") Loading
capif_backend/Dockerfile +3 −0 Original line number Diff line number Diff line Loading @@ -15,6 +15,9 @@ RUN apk add jq RUN apk add curl RUN apk add redis # Copiar el script generate_certs.py COPY backoffice_service/generate_certs.py /usr/src/app/generate_certs.py COPY . /usr/src/app EXPOSE 8080 Loading
capif_backend/backoffice_service/__main__.py +41 −36 Original line number Diff line number Diff line Loading @@ -69,42 +69,47 @@ csr_request = dump_certificate_request(FILETYPE_PEM, req) private_key = dump_privatekey(FILETYPE_PEM, key) # Get ca.cert from vault # config = Config().get_config() # get configuration from config.py # url = 'http://{}:{}/v1/secret/data/ca'.format(os.getenv('VAULT_HOSTNAME'), os.getenv('VAULT_PORT')) # http://vault:8200/v1/secret/data/ca # headers = {'X-Vault-Token': os.getenv('VAULT_TOKEN')} # response = requests.request("GET", url, headers=headers, verify = False) # ca_cert = json.loads(response.text)["data"]["data"]["ca"] # # print ("CA CERT URL: ", url) # # print ("VAULT_HOSTNAME", os.get_environ('VAULT_HOSTNAME')) # # print ("VAULT_PORT", os.get_environ('VAULT_PORT')) # # Request Vault a CA certificate to backoffice application # url = 'http://{}:{}/v1/pki_int/sign/my-ca'.format(os.getenv('VAULT_HOSTNAME'), os.getenv('VAULT_PORT')) # http://vault:8200/v1/pki_int/sign/my-ca # headers = {'X-Vault-Token': os.getenv('VAULT_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 ca_cert # ca_file = open('./backoffice_service/certs/ca.crt', 'wb+') # ca_file.write(bytes(ca_cert, 'utf-8')) # ca_file.close() # # 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() config = Config().get_config() # get configuration from config.py url = 'http://{}:{}/v1/secret/data/ca'.format(os.getenv('VAULT_HOSTNAME'), os.getenv('VAULT_PORT')) # http://vault:8200/v1/secret/data/ca headers = {'X-Vault-Token': os.getenv('VAULT_TOKEN')} response = requests.request("GET", url, headers=headers, verify = False) ca_cert = json.loads(response.text)["data"]["data"]["ca"] # print ("CA CERT URL: ", url) # print ("VAULT_HOSTNAME", os.get_environ('VAULT_HOSTNAME')) # print ("VAULT_PORT", os.get_environ('VAULT_PORT')) # Request Vault a CA certificate to backoffice application url = 'http://{}:{}/v1/pki_int/sign/my-ca'.format(os.getenv('VAULT_HOSTNAME'), os.getenv('VAULT_PORT')) # http://vault:8200/v1/pki_int/sign/my-ca headers = {'X-Vault-Token': os.getenv('VAULT_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'] # Ensure the certs directory exists os.makedirs('newcerts', exist_ok=True) # Save ca_cert ca_file = open('newcerts/ca_root.crt', 'wb+') ca_file.write(bytes(ca_cert, 'utf-8')) ca_file.close() # Save private_key private_key_file = open("newcerts/superadmin.key", 'wb+') private_key_file.write(private_key) private_key_file.close() # Save backoffice_cert certification_file = open('newcerts/superadmin.crt', 'wb+') certification_file.write(bytes(backoffice_cert, 'utf-8')) certification_file.close() #---------------------------------------- # launch Loading
capif_backend/backoffice_service/controllers/users_controller.py +8 −8 Original line number Diff line number Diff line Loading @@ -75,14 +75,14 @@ def get_capif_num_users(): # return jsonify(message="Invalid name", object=None), 400 # return operations.get_user(name) # # GET a JSON with all users # @cross_origin() # @users_routes.route("/users", methods=["GET"]) # @jwt_required() # def get_capif_users(): # if id == "null": # return jsonify(message="Invalid id", object=None), 400 # return operations.get_users() # GET a JSON with all users @cross_origin() @users_routes.route("/users", methods=["GET"]) @jwt_required() def get_capif_users(): if id == "null": return jsonify(message="Invalid id", object=None), 400 return operations.get_users_total() # # GET users with pagination # @cross_origin() Loading
capif_backend/backoffice_service/core/operations.py +84 −871 File changed.Preview size limit exceeded, changes collapsed. Show changes
capif_backend/backoffice_service/generate_certs.py 0 → 100644 +80 −0 Original line number Diff line number Diff line import os import json import requests from OpenSSL.crypto import PKey, TYPE_RSA, X509Req, dump_certificate_request, dump_privatekey, FILETYPE_PEM # Configure JWT (dummy example, not used in this script) JWT_SECRET_KEY = "super-secret" # create public/PRIVATE key key = PKey() key.generate_key(TYPE_RSA, 2048) # Generate CSR req = X509Req() req.get_subject().O = 'Telefonica I+D' req.get_subject().OU = 'Innovation' req.get_subject().L = 'Madrid' req.get_subject().ST = 'Madrid' req.get_subject().C = 'ES' 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) # Get ca.cert from vault VAULT_HOSTNAME = os.getenv('VAULT_HOSTNAME') VAULT_PORT = os.getenv('VAULT_PORT') VAULT_TOKEN = os.getenv('VAULT_TOKEN') url = f'http://{VAULT_HOSTNAME}:{VAULT_PORT}/v1/secret/data/ca' headers = {'X-Vault-Token': VAULT_TOKEN} response = requests.get(url, headers=headers, verify=False) ca_cert = json.loads(response.text)["data"]["data"]["ca"] # Request Vault a CA certificate to backoffice application url = f'http://{VAULT_HOSTNAME}:{VAULT_PORT}/v1/pki_int/sign/my-ca' data = { 'format': 'pem_bundle', 'ttl': '43000h', 'csr': csr_request.decode('utf-8'), 'common_name': "superadmin" } response = requests.post(url, headers=headers, data=data, verify=False) backoffice_cert = json.loads(response.text)['data']['certificate'] # Ensure the certs directory exists os.makedirs('backoffice_service/core/newcerts', exist_ok=True) # Save ca_cert ca_file_path = 'backoffice_service/core/newcerts/ca_root.crt' with open(ca_file_path, 'wb+') as ca_file: ca_file.write(bytes(ca_cert, 'utf-8')) print(f"CA Certificate saved at: {ca_file_path}") # Save private_key private_key_file_path = "backoffice_service/core/newcerts/superadmin.key" with open(private_key_file_path, 'wb+') as private_key_file: private_key_file.write(private_key) print(f"Private Key saved at: {private_key_file_path}") # Save backoffice_cert certification_file_path = 'backoffice_service/core/newcerts/superadmin.crt' with open(certification_file_path, 'wb+') as certification_file: certification_file.write(bytes(backoffice_cert, 'utf-8')) print(f"Backoffice Certificate saved at: {certification_file_path}") # Print the contents of the saved files with open(ca_file_path, 'r') as ca_file: print(f"CA Certificate content:\n{ca_file.read()}") with open(private_key_file_path, 'r') as private_key_file: print(f"Private Key content:\n{private_key_file.read()}") with open(certification_file_path, 'r') as certification_file: print(f"Backoffice Certificate content:\n{certification_file.read()}")