Skip to content

Commit

Permalink
Merge pull request #27 from lnls-sirius/dev
Browse files Browse the repository at this point in the history
Update Ldap-api communication
  • Loading branch information
RafaelLyra8 authored Sep 21, 2023
2 parents 82c2f1f + d86981e commit a8876a7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 27 deletions.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
18 changes: 9 additions & 9 deletions front_end/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 23 additions & 17 deletions front_end/src/data-access/Ldap_auth/index.ts
Original file line number Diff line number Diff line change
@@ -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<iterations; it++){
const it_pos = 150 * it;
const substr: string = value.substring(it_pos, it_pos+150);
const encrypted_result = cipher.encrypt(substr);
if(encrypted_result){
value_enc = encrypted_result;
value_enc.push(encrypted_result);
}
}else{
value_enc = value;
}
encrypted_data[key] = value_enc;
})

return encrypted_data
}

Expand All @@ -31,14 +34,17 @@ function decrypt_response(response_data: string): DictStr {
default_key_size: "2048"
});
cipher.setPrivateKey(private_key);
Object.entries(response_data).map(([key, value]: any)=>{
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
}
Expand All @@ -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, {
Expand Down

0 comments on commit a8876a7

Please sign in to comment.