From 7b1b9b63708c7392427bcdb2bdcdd2d065902d81 Mon Sep 17 00:00:00 2001 From: Rafael Lyra Date: Thu, 21 Sep 2023 16:02:55 -0300 Subject: [PATCH 1/2] Update Ldap-api communication --- docker-compose.yml | 2 +- front_end/package-lock.json | 18 ++++----- front_end/src/data-access/Ldap_auth/index.ts | 42 +++++++++++--------- 3 files changed, 34 insertions(+), 28 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index feaaa0b..db4e81f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -19,7 +19,7 @@ services: frontend: container_name: 'rad-det' - image: 'ghcr.io/lnls-sirius/rad-det-frontend:1.2.6' + image: 'ghcr.io/lnls-sirius/rad-det-frontend:1.2.7' build: context: ./front_end ports: diff --git a/front_end/package-lock.json b/front_end/package-lock.json index 51a5032..00d0132 100644 --- a/front_end/package-lock.json +++ b/front_end/package-lock.json @@ -1,12 +1,12 @@ { "name": "rad-detectors", - "version": "1.2.1", + "version": "1.2.7", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "rad-detectors", - "version": "1.2.1", + "version": "1.2.7", "dependencies": { "@fortawesome/free-solid-svg-icons": "^6.2.1", "@fortawesome/react-fontawesome": "^0.2.0", @@ -1911,9 +1911,9 @@ "integrity": "sha512-x/rqGMdzj+fWZvCOYForTghzbtqPDZ5gPwaoNGHdgDfF2QA/XZbCBp4Moo5scrkAMPhB7z26XM/AaHuIJdgauA==" }, "node_modules/@babel/runtime": { - "version": "7.22.10", - "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.22.10.tgz", - "integrity": "sha512-21t/fkKLMZI4pqP2wlmsQAWnYW1PDyKyyUV4vCi+B25ydmdaYTKXPwCj0BzSUnZf4seIiYvSA3jcZ3gdsMFkLQ==", + "version": "7.22.15", + "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.22.15.tgz", + "integrity": "sha512-T0O+aa+4w0u06iNmapipJXMV4HoUir03hpx3/YqXXhu9xim3w+dVphjFWl1OH8NbZHw5Lbm9k45drDkgq2VNNA==", "dependencies": { "regenerator-runtime": "^0.14.0" }, @@ -8813,15 +8813,15 @@ } }, "node_modules/fraction.js": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/fraction.js/-/fraction.js-4.2.0.tgz", - "integrity": "sha512-MhLuK+2gUcnZe8ZHlaaINnQLl0xRIGRfcGk2yl8xoQAfHrSsL3rYu6FCmBdkdbhc9EPlwyGHewaRsvwRMJtAlA==", + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/fraction.js/-/fraction.js-4.3.4.tgz", + "integrity": "sha512-pwiTgt0Q7t+GHZA4yaLjObx4vXmmdcS0iSJ19o8d/goUGgItX9UZWKWNnLHehxviD8wU2IWRsnR8cD5+yOJP2Q==", "engines": { "node": "*" }, "funding": { "type": "patreon", - "url": "https://www.patreon.com/infusion" + "url": "https://github.com/sponsors/rawify" } }, "node_modules/fresh": { diff --git a/front_end/src/data-access/Ldap_auth/index.ts b/front_end/src/data-access/Ldap_auth/index.ts index eabff68..0fea328 100644 --- a/front_end/src/data-access/Ldap_auth/index.ts +++ b/front_end/src/data-access/Ldap_auth/index.ts @@ -1,27 +1,30 @@ import axios from "axios"; import { JSEncrypt } from "jsencrypt"; -import { DictStr } from "../../assets/interfaces/patterns"; +import { DictStr, DictEnumStr } from "../../assets/interfaces/patterns"; import { public_key, public_key_api, private_key } from "../../assets/keys"; import { Buffer } from "buffer"; -function encrypt_request(login_data: DictStr, public_key_api: string): DictStr { - let encrypted_data: DictStr = {}; +function encrypt_request(login_data: DictStr, public_key_api: string): DictEnumStr { + let encrypted_data: DictEnumStr = {}; let cipher = new JSEncrypt({ default_key_size: "2048" }); cipher.setPublicKey(public_key_api); Object.entries(login_data).map(([key, value]: [string, string])=>{ - let value_enc: string = ""; - if (key != "public_key"){ - const encrypted_result = cipher.encrypt(value); + let value_enc: string[] = []; + let iterations: number = Math.ceil(value.length/150); + + for(let it=0; it{ + Object.entries(response_data).map(([key, value_list]: any)=>{ let value_enc: string = ""; - const new_val = Buffer.from(value).toString('latin1'); - const encrypted_result = cipher.decrypt(new_val); - if(encrypted_result){ - value_enc = encrypted_result; - } - encrypted_data[key] = value_enc; + encrypted_data[key] = ""; + value_list.map((value: string) => { + const new_val = Buffer.from(value).toString('latin1'); + const encrypted_result = cipher.decrypt(new_val); + if(encrypted_result){ + value_enc = encrypted_result; + } + encrypted_data[key] += value_enc; + }) }) return encrypted_data } async function login_ldap(username: string, password: string, group: string): Promise { - const jsonurl:string = `${window.location.protocol}//ldap-auth-api.lnls.br/group`; + const jsonurl:string = `${window.location.protocol}//127.0.0.1:5000/group`; const login_data: DictStr = { email: username, password: password, @@ -52,7 +58,7 @@ async function login_ldap(username: string, password: string, group: string): Pr public_key: public_key } - const encrypted: DictStr = encrypt_request(login_data, public_key_api) + const encrypted: DictEnumStr = encrypt_request(login_data, public_key_api) const encrypt_string: string = JSON.stringify(encrypted) return await axios .post(jsonurl, { From d86981edd53a976efd6c8c31a7617dfe67a9b467 Mon Sep 17 00:00:00 2001 From: Rafael Lyra Date: Thu, 21 Sep 2023 16:04:40 -0300 Subject: [PATCH 2/2] Fix url direction --- front_end/src/data-access/Ldap_auth/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/front_end/src/data-access/Ldap_auth/index.ts b/front_end/src/data-access/Ldap_auth/index.ts index 0fea328..11ed7d5 100644 --- a/front_end/src/data-access/Ldap_auth/index.ts +++ b/front_end/src/data-access/Ldap_auth/index.ts @@ -50,7 +50,7 @@ function decrypt_response(response_data: string): DictStr { } async function login_ldap(username: string, password: string, group: string): Promise { - const jsonurl:string = `${window.location.protocol}//127.0.0.1:5000/group`; + const jsonurl:string = `${window.location.protocol}//ldap-auth-api.lnls.br/group`; const login_data: DictStr = { email: username, password: password,