diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index 412fd82..0000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,21 +0,0 @@ -name: Trigger OpenG2P Packaging Workflow - -on: - push: - workflow_dispatch: - -jobs: - trigger-packaging: - runs-on: ubuntu-latest - steps: - - name: set variables - run: | - echo "BRANCH_NAME=$(echo ${{ github.ref }} | sed -e 's,.*/\(.*\),\1,')" >> $GITHUB_ENV - - name: Invoke workflow in another repo with inputs - uses: aurelien-baudet/workflow-dispatch@v2 - with: - token: ${{ secrets.GIT_PUSH_TOKEN }} - repo: OpenG2P/openg2p-packaging - workflow: OpenG2P Odoo Package Dockers build - input: "{\"packageName\": \"${{ env.BRANCH_NAME }}\"}" - ref: main diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 64a21c3..610b332 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -2,19 +2,16 @@ name: pre-commit on: pull_request: - branches: - - "15.0*" push: - branches: - - "15.0" - - "15.0-ocabot-*" jobs: pre-commit: runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: actions/setup-python@v2 + with: + python-version: "3.11" - name: Get python version run: echo "PY=$(python -VV | sha256sum | cut -d' ' -f1)" >> $GITHUB_ENV - uses: actions/cache@v1 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f49b9b4..b041d2e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,19 +4,20 @@ on: pull_request: branches: - "15.0*" + - "17.0*" push: branches: - "15.0*" - - "15.0-ocabot-*" + - "17.0*" env: OCA_GIT_USER_NAME: openg2p OCA_GIT_USER_EMAIL: bot@openg2p.org jobs: unreleased-deps: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 name: Detect unreleased dependencies steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - run: | for reqfile in requirements.txt test-requirements.txt ; do if [ -f ${reqfile} ] ; then @@ -29,7 +30,36 @@ jobs: fi fi done + matrix_prep: + runs-on: ubuntu-latest + outputs: + matrix: ${{ steps.set-matrix.outputs.matrix }} + steps: + - id: set-matrix + run: | + BRANCH_NAME=$(echo ${{ github.ref }} | sed -e 's,.*/\(.*\),\1,') + if [[ $BRANCH_NAME = 15.0* ]] ; then + matrix='{"include": [{ + "container": "ghcr.io/oca/oca-ci/py3.8-odoo15.0:latest", + "makepot": "true", + "name": "test with Odoo 15" + },{ + "container": "ghcr.io/oca/oca-ci/py3.8-ocb15.0:latest", + "name": "test with OCB 15" + }]}' + elif [[ $BRANCH_NAME = 17.0* ]] ; then + matrix='{"include": [{ + "container": "ghcr.io/oca/oca-ci/py3.10-odoo17.0:latest", + "makepot": "true", + "name": "test with Odoo 17" + },{ + "container": "ghcr.io/oca/oca-ci/py3.10-ocb17.0:latest", + "name": "test with OCB 17" + }]}' + fi + echo "matrix<> $GITHUB_OUTPUT test: + needs: matrix_prep runs-on: ubuntu-latest container: ${{ matrix.container }} name: ${{ matrix.name }} @@ -37,16 +67,10 @@ jobs: contents: write strategy: fail-fast: false - matrix: - include: - - container: ghcr.io/oca/oca-ci/py3.8-odoo15.0:latest - makepot: "true" - name: test with Odoo - - container: ghcr.io/oca/oca-ci/py3.8-ocb15.0:latest - name: test with OCB + matrix: ${{fromJson(needs.matrix_prep.outputs.matrix)}} services: postgres: - image: postgres:9.6 + image: postgres:12.0 env: POSTGRES_USER: odoo POSTGRES_PASSWORD: odoo @@ -54,7 +78,7 @@ jobs: ports: - 5432:5432 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: persist-credentials: false - name: Install addons and dependencies @@ -69,6 +93,7 @@ jobs: run: oca_init_test_database - name: Run tests run: oca_run_tests + - uses: codecov/codecov-action@v1 - name: Update .pot files run: oca_export_and_push_pot https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }} if: ${{ matrix.makepot == 'true' && github.event_name == 'push' && github.repository_owner == 'openg2p' }} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 111ab7a..ce9d079 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -28,12 +28,21 @@ repos: language: fail files: "\\.rej$" - repo: https://github.com/oca/maintainer-tools - rev: dfba427ba03900b69e0a7f2c65890dc48921d36a + rev: 9a170331575a265c092ee6b24b845ec508e8ef75 hooks: # update the NOT INSTALLABLE ADDONS section above - id: oca-update-pre-commit-excluded-addons - id: oca-fix-manifest-website args: ["https://openg2p.org"] + - id: oca-gen-addon-readme + args: + - --addons-dir=. + - --branch=15.0-develop + - --org-name=OpenG2P + - --repo-name=openg2p-security + - --if-source-changed + - --keep-source-digest + - id: oca-gen-external-dependencies - repo: https://github.com/myint/autoflake rev: v1.4 hooks: @@ -49,6 +58,8 @@ repos: rev: 22.3.0 hooks: - id: black + args: + - --line-length=110 - repo: https://github.com/pre-commit/mirrors-prettier rev: v2.4.1 hooks: @@ -107,12 +118,6 @@ repos: rev: 3.1.8 hooks: - id: setuptools-odoo-make-default - - id: setuptools-odoo-get-requirements - args: - - --output - - requirements.txt - - --header - - "# generated from manifests external_dependencies" - repo: https://github.com/PyCQA/flake8 rev: 3.9.2 hooks: diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c187f93..a1deaa6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,2 +1 @@ -Refer to contribution guidelines -[here](https://github.com/OpenG2P/openg2p-documentation/blob/1.0.0/community/contributing-to-openg2p.md). +Refer [Contributing to OpenG2P](https://github.com/OpenG2P/documentation/blob/master/CONTRIBUTING.md). diff --git a/README.md b/README.md index 3a8f9e6..6e9773e 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,10 @@ + +[![Pre-commit Status](https://github.com/OpenG2P/openg2p-security/actions/workflows/pre-commit.yml/badge.svg?branch=15.0-develop)](https://github.com/OpenG2P/openg2p-security/actions/workflows/pre-commit.yml?query=branch%3A15.0-develop) +[![Build Status](https://github.com/OpenG2P/openg2p-security/actions/workflows/test.yml/badge.svg?branch=15.0-develop)](https://github.com/OpenG2P/openg2p-security/actions/workflows/test.yml?query=branch%3A15.0-develop) +[![codecov](https://codecov.io/gh/OpenG2P/openg2p-security/branch/15.0-develop/graph/badge.svg)](https://codecov.io/gh/OpenG2P/openg2p-security) + + # OpenG2P Security diff --git a/g2p_encryption/README.rst b/g2p_encryption/README.rst index 9c8391a..5e48d46 100644 --- a/g2p_encryption/README.rst +++ b/g2p_encryption/README.rst @@ -2,10 +2,13 @@ G2P Encryption: Base ==================== -.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:2be24ba9e884952b98191815e8482ee2169686beba08fd5546a637202264487a + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png :target: https://odoo-community.org/page/development-status @@ -14,7 +17,7 @@ G2P Encryption: Base :target: https://github.com/OpenG2P/openg2p-security/tree/15.0-develop/g2p_encryption :alt: OpenG2P/openg2p-security -|badge1| |badge2| +|badge1| |badge2| OpenG2P Encryption: Base @@ -33,7 +36,7 @@ Bug Tracker Bugs are tracked on `GitHub Issues `_. In case of trouble, please check there if your issue has already been reported. -If you spotted it first, help us smashing it by providing a detailed and welcomed +If you spotted it first, help us to smash it by providing a detailed and welcomed `feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -46,6 +49,12 @@ Authors * OpenG2P +Contributors +~~~~~~~~~~~~ + +* Lalith Kota +* Vineela Ampili + Maintainers ~~~~~~~~~~~ diff --git a/g2p_encryption/readme/CONTRIBUTORS.rst b/g2p_encryption/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000..60fbbbf --- /dev/null +++ b/g2p_encryption/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Lalith Kota +* Vineela Ampili diff --git a/g2p_encryption/security/groups.xml b/g2p_encryption/security/groups.xml index 6a53fb3..e8a2db6 100644 --- a/g2p_encryption/security/groups.xml +++ b/g2p_encryption/security/groups.xml @@ -1,7 +1,16 @@ + + OpenG2P Security Module + User access level for the openg2p security modules + 4 + Crypto Admin - + + + + Crypto Dummy + diff --git a/g2p_encryption/static/description/index.html b/g2p_encryption/static/description/index.html index 0d6bd2f..7ec4129 100644 --- a/g2p_encryption/static/description/index.html +++ b/g2p_encryption/static/description/index.html @@ -1,4 +1,3 @@ - @@ -366,6 +365,8 @@

G2P Encryption: Base

Alpha OpenG2P/openg2p-security

OpenG2P Encryption: Base

@@ -381,7 +382,8 @@

G2P Encryption: Base

  • Bug Tracker
  • Credits
  • @@ -390,7 +392,7 @@

    G2P Encryption: Base

    Bug Tracker

    Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. -If you spotted it first, help us smashing it by providing a detailed and welcomed +If you spotted it first, help us to smash it by providing a detailed and welcomed feedback.

    Do not contact contributors directly about support or help with technical issues.

    @@ -402,8 +404,15 @@

    Authors

  • OpenG2P
  • +
    +

    Contributors

    + +
    -

    Maintainers

    +

    Maintainers

    This module is part of the OpenG2P/openg2p-security project on GitHub.

    You are welcome to contribute.

    diff --git a/g2p_encryption_keymanager/README.rst b/g2p_encryption_keymanager/README.rst index 006f844..d0a1239 100644 --- a/g2p_encryption_keymanager/README.rst +++ b/g2p_encryption_keymanager/README.rst @@ -2,10 +2,13 @@ G2P Encryption: Keymanager ========================== -.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:c5b90c4b58fa786333889d2061bb9fe6d3eb8eb89ba9384b3c37d72d094f71ad + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png :target: https://odoo-community.org/page/development-status @@ -14,7 +17,7 @@ G2P Encryption: Keymanager :target: https://github.com/OpenG2P/openg2p-security/tree/15.0-develop/g2p_encryption_keymanager :alt: OpenG2P/openg2p-security -|badge1| |badge2| +|badge1| |badge2| OpenG2P Encryption With Keymanager @@ -33,7 +36,7 @@ Bug Tracker Bugs are tracked on `GitHub Issues `_. In case of trouble, please check there if your issue has already been reported. -If you spotted it first, help us smashing it by providing a detailed and welcomed +If you spotted it first, help us to smash it by providing a detailed and welcomed `feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -46,6 +49,12 @@ Authors * OpenG2P +Contributors +~~~~~~~~~~~~ + +* Lalith Kota +* Vineela Ampili + Maintainers ~~~~~~~~~~~ diff --git a/g2p_encryption_keymanager/models/encryption_provider.py b/g2p_encryption_keymanager/models/encryption_provider.py index 31df0a1..238d75c 100644 --- a/g2p_encryption_keymanager/models/encryption_provider.py +++ b/g2p_encryption_keymanager/models/encryption_provider.py @@ -18,20 +18,14 @@ _logger = logging.getLogger(__name__) -KEYMANAGER_API_BASE_URL = os.getenv( - "KEYMANAGER_API_BASE_URL", "http://keymanager.keymanager/v1/keymanager" -) +KEYMANAGER_API_BASE_URL = os.getenv("KEYMANAGER_API_BASE_URL", "http://keymanager.keymanager/v1/keymanager") KEYMANAGER_AUTH_URL = os.getenv( "KEYMANAGER_AUTH_URL", "http://keycloak.keycloak/realms/openg2p/protocol/openid-connect/token", ) -KEYMANAGER_AUTH_CLIENT_ID = os.getenv( - "KEYMANAGER_AUTH_CLIENT_ID", "openg2p-admin-client" -) +KEYMANAGER_AUTH_CLIENT_ID = os.getenv("KEYMANAGER_AUTH_CLIENT_ID", "openg2p-admin-client") KEYMANAGER_AUTH_CLIENT_SECRET = os.getenv("KEYMANAGER_AUTH_CLIENT_SECRET", "") -KEYMANAGER_AUTH_GRANT_TYPE = os.getenv( - "KEYMANAGER_AUTH_GRANT_TYPE", "client_credentials" -) +KEYMANAGER_AUTH_GRANT_TYPE = os.getenv("KEYMANAGER_AUTH_GRANT_TYPE", "client_credentials") class KeymanagerEncryptionProvider(models.Model): @@ -47,20 +41,23 @@ def _km_random_secret(self): def km_generate_current_time(self): return f'{datetime.utcnow().isoformat(timespec = "milliseconds")}Z' - keymanager_api_base_url = fields.Char(default=KEYMANAGER_API_BASE_URL) - keymanager_auth_url = fields.Char(default=KEYMANAGER_AUTH_URL) - keymanager_auth_client_id = fields.Char(default=KEYMANAGER_AUTH_CLIENT_ID) + keymanager_api_base_url = fields.Char("Keymanager API Base URL", default=KEYMANAGER_API_BASE_URL) + keymanager_api_timeout = fields.Integer("Keymanager API Timeout", default=10) + keymanager_auth_url = fields.Char("Keymanager Auth URL", default=KEYMANAGER_AUTH_URL) + keymanager_auth_client_id = fields.Char("Keymanager Auth Client ID", default=KEYMANAGER_AUTH_CLIENT_ID) keymanager_auth_client_secret = fields.Char(default=KEYMANAGER_AUTH_CLIENT_SECRET) keymanager_auth_grant_type = fields.Char(default=KEYMANAGER_AUTH_GRANT_TYPE) keymanager_access_token = fields.Char() keymanager_access_token_expiry = fields.Datetime() - keymanager_encrypt_application_id = fields.Char(default="REGISTRATION") - keymanager_encrypt_reference_id = fields.Char(default="ENCRYPT") + keymanager_encrypt_application_id = fields.Char( + "Keymanager Encrypt Application ID", default="REGISTRATION" + ) + keymanager_encrypt_reference_id = fields.Char("Keymanager Encrypt Reference ID", default="ENCRYPT") - keymanager_sign_application_id = fields.Char(default="REGISTRATION") - keymanager_sign_reference_id = fields.Char(default="") + keymanager_sign_application_id = fields.Char("Keymanager Sign Application ID", default="ID_REPO") + keymanager_sign_reference_id = fields.Char("Keymanager Sign Reference ID", default="") keymanager_encrypt_salt = fields.Char(default=_km_random_secret) keymanager_encrypt_aad = fields.Char(default=_km_random_secret) @@ -85,7 +82,7 @@ def encrypt_data_keymanager(self, data: bytes, **kwargs) -> bytes: "aad": self.keymanager_encrypt_aad, }, } - response = requests.post(url, json=payload, headers=headers) + response = requests.post(url, json=payload, headers=headers, timeout=self.keymanager_api_timeout) _logger.debug("Keymanager Encrypt API response: %s", response.text) response.raise_for_status() if response: @@ -116,7 +113,7 @@ def decrypt_data_keymanager(self, data: bytes, **kwargs) -> bytes: "aad": self.keymanager_encrypt_aad, }, } - response = requests.post(url, json=payload, headers=headers) + response = requests.post(url, json=payload, headers=headers, timeout=self.keymanager_api_timeout) _logger.debug("Keymanager Decrypt API response: %s", response.text) response.raise_for_status() if response: @@ -159,7 +156,7 @@ def jwt_sign_keymanager( "includeCertHash": include_cert_hash, }, } - response = requests.post(url, json=payload, headers=headers) + response = requests.post(url, json=payload, headers=headers, timeout=self.keymanager_api_timeout) _logger.debug("Keymanager JWT Sign API response: %s", response.text) response.raise_for_status() if response: @@ -188,7 +185,7 @@ def jwt_verify_keymanager(self, data: str, **kwargs): "validateTrust": False, }, } - response = requests.post(url, json=payload, headers=headers) + response = requests.post(url, json=payload, headers=headers, timeout=self.keymanager_api_timeout) _logger.debug("Keymanager JWT Verify API response: %s", response.text) response.raise_for_status() if response: @@ -226,7 +223,7 @@ def get_jwks_keymanager(self, **kwargs): if self.keymanager_sign_reference_id: url += f"&referenceId={ref_id}" headers = {"Cookie": f"Authorization={access_token}"} - response = requests.get(url, headers=headers) + response = requests.get(url, headers=headers, timeout=self.keymanager_api_timeout) _logger.debug("Keymanager get Certificate API response: %s", response.text) response.raise_for_status() certs = response.json().get("response", {}).get("allCertificates", []) @@ -248,13 +245,9 @@ def km_convert_x509_pem_to_jwk(self, cert: bytes, use=None, kid=None): new.import_from_pyca(public_key) new.update( { - "x5c": [ - base64.b64encode(x509_cert.public_bytes(Encoding.DER)).decode() - ], + "x5c": [base64.b64encode(x509_cert.public_bytes(Encoding.DER)).decode()], "x5t": self.km_urlsafe_b64encode(x509_cert.fingerprint(hashes.SHA1())), - "x5t#S256": self.km_urlsafe_b64encode( - x509_cert.fingerprint(hashes.SHA256()) - ), + "x5t#S256": self.km_urlsafe_b64encode(x509_cert.fingerprint(hashes.SHA256())), } ) if kid: @@ -276,7 +269,7 @@ def km_get_access_token(self): "client_secret": self.keymanager_auth_client_secret, "grant_type": self.keymanager_auth_grant_type, } - response = requests.post(self.keymanager_auth_url, data=data) + response = requests.post(self.keymanager_auth_url, data=data, timeout=self.keymanager_api_timeout) _logger.debug("Keymanager get Certificates API response: %s", response.text) response.raise_for_status() access_token = response.json().get("access_token", None) @@ -299,6 +292,4 @@ def km_urlsafe_b64encode(self, input_data: bytes) -> str: @api.model def km_urlsafe_b64decode(self, input_data: str) -> bytes: - return base64.urlsafe_b64decode( - input_data.encode() + b"=" * (-len(input_data) % 4) - ) + return base64.urlsafe_b64decode(input_data.encode() + b"=" * (-len(input_data) % 4)) diff --git a/g2p_encryption_keymanager/readme/CONTRIBUTORS.rst b/g2p_encryption_keymanager/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000..60fbbbf --- /dev/null +++ b/g2p_encryption_keymanager/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Lalith Kota +* Vineela Ampili diff --git a/g2p_encryption_keymanager/static/description/index.html b/g2p_encryption_keymanager/static/description/index.html index eef0aa2..3425e96 100644 --- a/g2p_encryption_keymanager/static/description/index.html +++ b/g2p_encryption_keymanager/static/description/index.html @@ -1,4 +1,3 @@ - @@ -366,6 +365,8 @@

    G2P Encryption: Keymanager

    Alpha OpenG2P/openg2p-security

    OpenG2P Encryption With Keymanager

    @@ -381,7 +382,8 @@

    G2P Encryption: Keymanager

  • Bug Tracker
  • Credits
  • @@ -390,7 +392,7 @@

    G2P Encryption: Keymanager

    Bug Tracker

    Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. -If you spotted it first, help us smashing it by providing a detailed and welcomed +If you spotted it first, help us to smash it by providing a detailed and welcomed feedback.

    Do not contact contributors directly about support or help with technical issues.

    @@ -402,8 +404,15 @@

    Authors

  • OpenG2P
  • +
    +

    Contributors

    + +
    -

    Maintainers

    +

    Maintainers

    This module is part of the OpenG2P/openg2p-security project on GitHub.

    You are welcome to contribute.

    diff --git a/g2p_encryption_keymanager/views/encryption_provider.xml b/g2p_encryption_keymanager/views/encryption_provider.xml index 7e45fc8..78ca811 100644 --- a/g2p_encryption_keymanager/views/encryption_provider.xml +++ b/g2p_encryption_keymanager/views/encryption_provider.xml @@ -15,11 +15,22 @@ Part of OpenG2P. See LICENSE file for full copyright and licensing details. string="Keymanager Settings" attrs="{'invisible':[('type','!=','keymanager')]}" > - - - - - + + + + + + `_. In case of trouble, please check there if your issue has already been reported. -If you spotted it first, help us smashing it by providing a detailed and welcomed +If you spotted it first, help us to smash it by providing a detailed and welcomed `feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -46,6 +49,12 @@ Authors * OpenG2P +Contributors +~~~~~~~~~~~~ + +* Lalith Kota +* Vineela Ampili + Maintainers ~~~~~~~~~~~ diff --git a/g2p_encryption_rest_api/readme/CONTRIBUTORS.rst b/g2p_encryption_rest_api/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000..60fbbbf --- /dev/null +++ b/g2p_encryption_rest_api/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Lalith Kota +* Vineela Ampili diff --git a/g2p_encryption_rest_api/services/well_known.py b/g2p_encryption_rest_api/services/well_known.py index acb728a..d620854 100644 --- a/g2p_encryption_rest_api/services/well_known.py +++ b/g2p_encryption_rest_api/services/well_known.py @@ -34,7 +34,5 @@ def get_jwks(self): prov_jwks = prov.get_jwks() jwks.extend(prov_jwks.get("keys", []) if prov_jwks else []) except Exception: - _logger.exception( - "Unable to get JWKS from list of encryption providers" - ) + _logger.exception("Unable to get JWKS from list of encryption providers") return {"keys": jwks} diff --git a/g2p_encryption_rest_api/static/description/index.html b/g2p_encryption_rest_api/static/description/index.html index 7804e98..dd43918 100644 --- a/g2p_encryption_rest_api/static/description/index.html +++ b/g2p_encryption_rest_api/static/description/index.html @@ -1,4 +1,3 @@ - @@ -366,6 +365,8 @@

    G2P Encryption: Rest API

    Alpha OpenG2P/openg2p-security

    OpenG2P Encryption REST API

    @@ -381,7 +382,8 @@

    G2P Encryption: Rest API

  • Bug Tracker
  • Credits
  • @@ -390,7 +392,7 @@

    G2P Encryption: Rest API

    Bug Tracker

    Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. -If you spotted it first, help us smashing it by providing a detailed and welcomed +If you spotted it first, help us to smash it by providing a detailed and welcomed feedback.

    Do not contact contributors directly about support or help with technical issues.

    @@ -402,8 +404,15 @@

    Authors

  • OpenG2P
  • +
    +

    Contributors

    + +
    -

    Maintainers

    +

    Maintainers

    This module is part of the OpenG2P/openg2p-security project on GitHub.

    You are welcome to contribute.

    diff --git a/g2p_registry_encryption/README.rst b/g2p_registry_encryption/README.rst index d1fc794..0542c98 100644 --- a/g2p_registry_encryption/README.rst +++ b/g2p_registry_encryption/README.rst @@ -2,10 +2,13 @@ G2P Registry: Encryption ======================== -.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:7c716f60dee515e3e3aca70ba7e24c0c97e8669335b6f07c856ed87af7b9da01 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png :target: https://odoo-community.org/page/development-status @@ -14,7 +17,7 @@ G2P Registry: Encryption :target: https://github.com/OpenG2P/openg2p-security/tree/15.0-develop/g2p_registry_encryption :alt: OpenG2P/openg2p-security -|badge1| |badge2| +|badge1| |badge2| OpenG2P Registry Encryption @@ -33,7 +36,7 @@ Bug Tracker Bugs are tracked on `GitHub Issues `_. In case of trouble, please check there if your issue has already been reported. -If you spotted it first, help us smashing it by providing a detailed and welcomed +If you spotted it first, help us to smash it by providing a detailed and welcomed `feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -46,6 +49,12 @@ Authors * OpenG2P +Contributors +~~~~~~~~~~~~ + +* Lalith Kota +* Vineela Ampili + Maintainers ~~~~~~~~~~~ diff --git a/g2p_registry_encryption/__manifest__.py b/g2p_registry_encryption/__manifest__.py index 58cee70..5e65068 100644 --- a/g2p_registry_encryption/__manifest__.py +++ b/g2p_registry_encryption/__manifest__.py @@ -11,6 +11,7 @@ "data": [ "data/registry_encryption_provider.xml", "views/decrypted_partner.xml", + "views/encryption_provider.xml", "views/res_config_view.xml", ], "assets": { diff --git a/g2p_registry_encryption/models/encryption_provider.py b/g2p_registry_encryption/models/encryption_provider.py index c407705..a020dfc 100644 --- a/g2p_registry_encryption/models/encryption_provider.py +++ b/g2p_registry_encryption/models/encryption_provider.py @@ -1,9 +1,29 @@ -from odoo import api, models +from odoo import api, fields, models +from odoo.tools import safe_eval class RegistryEncryptionProvider(models.Model): _inherit = "g2p.encryption.provider" + registry_fields_to_enc = fields.Text( + "Registry Fields to Encrypt", + default="""[ + "name", + "family_name", + "given_name", + "addl_name", + "display_name", + "address", + "birth_place", + ]""", + ) + + registry_enc_field_placeholder = fields.Char("Registry Encrypted Field Placeholder", default="encrypted") + + def get_registry_fields_set_to_enc(self): + self.ensure_one() + return set(safe_eval.safe_eval(self.registry_fields_to_enc)) + @api.model def set_registry_provider(self, provider_id, replace=True): if provider_id and ( @@ -23,4 +43,4 @@ def get_registry_provider(self): .sudo() .get_param("g2p_registry_encryption.encryption_provider_id", None) ) - return self.browse(int(prov_id)) if prov_id else None + return self.sudo().browse(int(prov_id)) if prov_id else None diff --git a/g2p_registry_encryption/models/partner.py b/g2p_registry_encryption/models/partner.py index c51042a..dcf72c7 100644 --- a/g2p_registry_encryption/models/partner.py +++ b/g2p_registry_encryption/models/partner.py @@ -9,30 +9,19 @@ class EncryptedPartner(models.Model): encrypted_val = fields.Binary("Encrypted value", attachment=False) is_encrypted = fields.Boolean(default=False) - fields_list_to_enc = { - "name", - "family_name", - "given_name", - "addl_name", - "display_name", - "address", - "birth_place", - } - - placeholder_to_encrypted_field = "encrypted" - @api.model def gather_fields_to_be_enc_from_dict( self, fields_dict: dict, + prov, replace=True, ): to_be_enc = {} - for each in self.fields_list_to_enc: + for each in prov.get_registry_fields_set_to_enc(): if fields_dict.get(each, None): to_be_enc[each] = fields_dict[each] if replace: - fields_dict[each] = self.placeholder_to_encrypted_field + fields_dict[each] = prov.registry_enc_field_placeholder return to_be_enc def create(self, vals_list): @@ -47,10 +36,8 @@ def create(self, vals_list): prov = self.env["g2p.encryption.provider"].get_registry_provider() for vals in vals_list: if vals.get("is_registrant", False): - to_be_encrypted = self.gather_fields_to_be_enc_from_dict(vals) - vals["encrypted_val"] = prov.encrypt_data( - json.dumps(to_be_encrypted).encode() - ) + to_be_encrypted = self.gather_fields_to_be_enc_from_dict(vals, prov) + vals["encrypted_val"] = prov.encrypt_data(json.dumps(to_be_encrypted).encode()) vals["is_encrypted"] = True return super().create(vals_list) @@ -66,29 +53,26 @@ def write(self, vals): prov = self.env["g2p.encryption.provider"].get_registry_provider() encrypted_vals = self.get_encrypted_val() - for rec, (is_encrypted, encrypted_val) in zip(self, encrypted_vals): + for rec, (is_encrypted, encrypted_val) in zip(self, encrypted_vals, strict=True): if rec.is_registrant or vals.get("is_registrant", False): if not is_encrypted: - rec_values_list = rec.read(self.fields_list_to_enc)[0] + rec_values_list = rec.read(prov.get_registry_fields_set_to_enc())[0] rec_values_list.update(vals) rec_values_list["is_encrypted"] = True vals = rec_values_list else: - vals = json.loads(prov.decrypt_data(encrypted_val).decode()).update( - vals - ) + vals = json.loads(prov.decrypt_data(encrypted_val).decode()).update(vals) to_be_encrypted = self.gather_fields_to_be_enc_from_dict(vals) - vals["encrypted_val"] = prov.encrypt_data( - json.dumps(to_be_encrypted).encode() - ) + vals["encrypted_val"] = prov.encrypt_data(json.dumps(to_be_encrypted).encode()) return super().write(vals) def _read(self, fields): fields = set(fields) res = super()._read(fields) - enc_fields_set = self.fields_list_to_enc.intersection(fields) + prov = self.env["g2p.encryption.provider"].get_registry_provider() + enc_fields_set = prov.get_registry_fields_set_to_enc().intersection(fields) if not enc_fields_set: return res if len(fields) == 2 and "encrypted_val" in fields and "is_encrypted" in fields: @@ -101,26 +85,16 @@ def _read(self, fields): ) if not is_decrypt_fields: return res - prov = self.env["g2p.encryption.provider"].get_registry_provider() for record in self: is_encrypted, encrypted_val = record.get_encrypted_val()[0] if is_encrypted and encrypted_val: decrypted_vals = json.loads(prov.decrypt_data(encrypted_val).decode()) for field_name in enc_fields_set: - if ( - field_name in decrypted_vals - and field_name in record - and record[field_name] - ): - self.env.cache.set( - record, self._fields[field_name], decrypted_vals[field_name] - ) + if field_name in decrypted_vals and field_name in record and record[field_name]: + self.env.cache.set(record, self._fields[field_name], decrypted_vals[field_name]) return res def get_encrypted_val(self): ret = self.with_context(bin_size=False).read(["is_encrypted", "encrypted_val"]) - return [ - (each.get("is_encrypted", False), each.get("encrypted_val", None)) - for each in ret - ] + return [(each.get("is_encrypted", False), each.get("encrypted_val", None)) for each in ret] diff --git a/g2p_registry_encryption/models/res_config_settings.py b/g2p_registry_encryption/models/res_config_settings.py index 14df1e7..f65af55 100644 --- a/g2p_registry_encryption/models/res_config_settings.py +++ b/g2p_registry_encryption/models/res_config_settings.py @@ -8,11 +8,7 @@ class RegistryEncryptConfigSettings(models.TransientModel): "g2p.encryption.provider", config_parameter="g2p_registry_encryption.encryption_provider_id", ) - encrypt_registry = fields.Boolean( - config_parameter="g2p_registry_encryption.encrypt_registry" - ) + encrypt_registry = fields.Boolean(config_parameter="g2p_registry_encryption.encrypt_registry") # TODO: Change this to user context - decrypt_registry = fields.Boolean( - config_parameter="g2p_registry_encryption.decrypt_registry" - ) + decrypt_registry = fields.Boolean(config_parameter="g2p_registry_encryption.decrypt_registry") diff --git a/g2p_registry_encryption/readme/CONTRIBUTORS.rst b/g2p_registry_encryption/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000..60fbbbf --- /dev/null +++ b/g2p_registry_encryption/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Lalith Kota +* Vineela Ampili diff --git a/g2p_registry_encryption/static/description/index.html b/g2p_registry_encryption/static/description/index.html index b5fcd08..3bc7112 100644 --- a/g2p_registry_encryption/static/description/index.html +++ b/g2p_registry_encryption/static/description/index.html @@ -1,4 +1,3 @@ - @@ -366,6 +365,8 @@

    G2P Registry: Encryption

    Alpha OpenG2P/openg2p-security

    OpenG2P Registry Encryption

    @@ -381,7 +382,8 @@

    G2P Registry: Encryption

  • Bug Tracker
  • Credits
  • @@ -390,7 +392,7 @@

    G2P Registry: Encryption

    Bug Tracker

    Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. -If you spotted it first, help us smashing it by providing a detailed and welcomed +If you spotted it first, help us to smash it by providing a detailed and welcomed feedback.

    Do not contact contributors directly about support or help with technical issues.

    @@ -402,8 +404,15 @@

    Authors

  • OpenG2P
  • +
    +

    Contributors

    + +
    -

    Maintainers

    +

    Maintainers

    This module is part of the OpenG2P/openg2p-security project on GitHub.

    You are welcome to contribute.

    diff --git a/g2p_registry_encryption/views/encryption_provider.xml b/g2p_registry_encryption/views/encryption_provider.xml new file mode 100644 index 0000000..cc0146a --- /dev/null +++ b/g2p_registry_encryption/views/encryption_provider.xml @@ -0,0 +1,20 @@ + + + + + view_registry_encryption_provider_form + g2p.encryption.provider + + 10 + +
    + + + + +
    +
    +
    +
    diff --git a/requirements.txt b/requirements.txt index 2242a65..25566c7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ # generated from manifests external_dependencies -cryptography<37 +cryptography <37 jwcrypto python-jose