diff --git a/aws/src/lambdas/calcHash/calcHash.zip b/aws/src/lambdas/calcHash/calcHash.zip deleted file mode 100644 index 2487586..0000000 Binary files a/aws/src/lambdas/calcHash/calcHash.zip and /dev/null differ diff --git a/aws/src/lambdas/calcHash/index.js b/aws/src/lambdas/calcHash/index.js index 3af8044..e1876ae 100644 --- a/aws/src/lambdas/calcHash/index.js +++ b/aws/src/lambdas/calcHash/index.js @@ -3,9 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -const argon2 = require('argon2'); +const argon2_1 = __importDefault(require("argon2")); const handler = async (event) => { - const httpMethod = event.requestContext.http.method; + console.log('Received event:', JSON.stringify(event, null)); + const httpMethod = event.requestContext.httpMethod; if (httpMethod === 'OPTIONS') { return { statusCode: 200, @@ -18,26 +19,11 @@ const handler = async (event) => { }; } try { - const raw = event.body; - - // Parse JSON if input is a JSON object or read raw text - let textToHash; - try { - const parsed = JSON.parse(raw); - if (parsed && typeof parsed.textToHash === 'string') { - textToHash = parsed.textToHash; - } else { - textToHash = typeof parsed === 'string' ? parsed : raw; - } - } catch { - textToHash = raw; - } - - console.log("Data to Hash: ", textToHash); + const dataToHash = typeof event.body === 'string' ? event.body : JSON.stringify(event.body, null, 2); const slt = Buffer.from('my-static-salt', 'utf8'); - const hashValue = await argon2.hash(textToHash, { + const hashValue = await argon2_1.default.hash(dataToHash, { salt: slt, - type: argon2.argon2id, + type: argon2_1.default.argon2id, timeCost: 2, // Number of iterations. memoryCost: 65536, // Memory in KiB. hashLength: 32, // Length of the resulting hash. @@ -66,4 +52,4 @@ const handler = async (event) => { }; } }; -module.exports = { handler }; \ No newline at end of file +module.exports = { handler }; diff --git a/aws/src/lambdas/calcHash/index.ts b/aws/src/lambdas/calcHash/index.ts index d5aa69d..3b87bf8 100644 --- a/aws/src/lambdas/calcHash/index.ts +++ b/aws/src/lambdas/calcHash/index.ts @@ -1,9 +1,9 @@ -import { APIGatewayEvent, Context } from "aws-lambda"; -import { APIGatewayProxyEventV2, APIGatewayProxyResultV2 } from 'aws-lambda'; +import { APIGatewayProxyResultV2, APIGatewayEvent } from 'aws-lambda'; import argon2 from 'argon2' -const handler = async (event: APIGatewayProxyEventV2): Promise => { - const httpMethod = event.requestContext.http.method; +const handler = async (event: APIGatewayEvent): Promise => { + console.log('Received event:', JSON.stringify(event, null)); + const httpMethod = event.requestContext.httpMethod; if (httpMethod === 'OPTIONS') { return { statusCode: 200, diff --git a/aws/src/lambdas/calcHash/package.json b/aws/src/lambdas/calcHash/package.json index a4384d8..cf39310 100644 --- a/aws/src/lambdas/calcHash/package.json +++ b/aws/src/lambdas/calcHash/package.json @@ -1,4 +1,9 @@ { + "scripts": { + "build": "npx tsc", + "zip": "(zip calcHash.zip index.js node_modules || powershell Compress-Archive -Path index.js, node_modules -DestinationPath calcHash.zip)", + "move": "(mv calcHash.zip ../../terraform || powershell Move-Item calcHash.zip ../../terraform)" + }, "devDependencies": { "@types/aws-lambda": "^8.10.147", "@types/node": "^22.13.13", diff --git a/aws/src/lambdas/calcHash/tsconfig.json b/aws/src/lambdas/calcHash/tsconfig.json index 9db674e..c40e4a5 100644 --- a/aws/src/lambdas/calcHash/tsconfig.json +++ b/aws/src/lambdas/calcHash/tsconfig.json @@ -4,7 +4,6 @@ "module": "CommonJS", "lib": ["ES2020"], "moduleResolution": "Node", - "outDir": "build", "rootDir": "./", "strict": true, "esModuleInterop": true diff --git a/aws/src/lambdas/getSecurityQues/getSecurityQues.zip b/aws/src/lambdas/getSecurityQues/getSecurityQues.zip deleted file mode 100644 index c2db39d..0000000 Binary files a/aws/src/lambdas/getSecurityQues/getSecurityQues.zip and /dev/null differ diff --git a/aws/src/lambdas/getSecurityQues/package.json b/aws/src/lambdas/getSecurityQues/package.json index de3c724..59066a9 100644 --- a/aws/src/lambdas/getSecurityQues/package.json +++ b/aws/src/lambdas/getSecurityQues/package.json @@ -1,4 +1,9 @@ { + "scripts": { + "build": "npx tsc", + "zip": "(zip getSecurityQues.zip index.js node_modules || powershell Compress-Archive -Path index.js, node_modules -DestinationPath getSecurityQues.zip)", + "move": "(mv getSecurityQues.zip ../../terraform || powershell Move-Item getSecurityQues.zip ../../terraform)" + }, "devDependencies": { "@types/aws-lambda": "^8.10.147", "typescript": "^5.7.3" diff --git a/aws/src/lambdas/getUserInfo/index.js b/aws/src/lambdas/getUserInfo/index.js new file mode 100644 index 0000000..6023baf --- /dev/null +++ b/aws/src/lambdas/getUserInfo/index.js @@ -0,0 +1,54 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.handler = void 0; +const promise_1 = require("mysql2/promise"); +const dbConfig = { + host: process.env.DB_HOST, + user: process.env.DB_USER, + password: process.env.DB_PASS, + database: process.env.DB_NAME, +}; +const handler = async (event) => { + try { + console.log("Incoming event:", JSON.stringify(event, null, 2)); + let request_body; + if (event.body) { + request_body = JSON.parse(event.body); + } + else { + console.log("No body found"); + return { + statusCode: 400, + body: JSON.stringify({ message: "No body found" }), + }; + } + const { UUID } = request_body; + console.log("Parsed UUID:", UUID); + try { + const connection = await (0, promise_1.createConnection)(dbConfig); + const [rows] = await connection.execute('SELECT enc_email, enc_name, enc_phone_num FROM users WHERE uuid = ?', [UUID]); + await connection.end(); + return { + statusCode: 200, + body: JSON.stringify(rows), + }; + } + catch (error) { + console.error("Database error:", error); + return { + statusCode: 500, + body: JSON.stringify({ message: "Database connection failed", error: error }), + }; + } + } + catch (error) { + console.error("Unhandled error in handler:", error); + return { + statusCode: 500, + body: JSON.stringify({ + message: "Internal Server Error" + }), + }; + } +}; +exports.handler = handler; diff --git a/aws/src/lambdas/getUserInfo/index.mjs b/aws/src/lambdas/getUserInfo/index.ts similarity index 83% rename from aws/src/lambdas/getUserInfo/index.mjs rename to aws/src/lambdas/getUserInfo/index.ts index b7adf3e..0738091 100644 --- a/aws/src/lambdas/getUserInfo/index.mjs +++ b/aws/src/lambdas/getUserInfo/index.ts @@ -1,4 +1,5 @@ -import mysql from 'mysql2/promise'; +import { APIGatewayEvent } from "aws-lambda"; +import { createConnection } from 'mysql2/promise'; const dbConfig = { host: process.env.DB_HOST, @@ -7,7 +8,7 @@ const dbConfig = { database: process.env.DB_NAME, }; -export const handler = async (event) => { +export const handler = async (event: APIGatewayEvent) => { try { console.log("Incoming event:", JSON.stringify(event, null, 2)); @@ -27,7 +28,7 @@ export const handler = async (event) => { console.log("Parsed UUID:", UUID); try { - const connection = await mysql.createConnection(dbConfig); + const connection = await createConnection(dbConfig); const [rows] = await connection.execute('SELECT enc_email, enc_name, enc_phone_num FROM users WHERE uuid = ?', [UUID]); await connection.end(); @@ -40,7 +41,7 @@ export const handler = async (event) => { console.error("Database error:", error); return { statusCode: 500, - body: JSON.stringify({ message: "Database connection failed", error: error.message }), + body: JSON.stringify({ message: "Database connection failed", error: error }), }; } } catch (error) { diff --git a/aws/src/lambdas/getUserInfo/package.json b/aws/src/lambdas/getUserInfo/package.json index 0886e55..a7c4f13 100644 --- a/aws/src/lambdas/getUserInfo/package.json +++ b/aws/src/lambdas/getUserInfo/package.json @@ -1,16 +1,14 @@ { - "name": "getuserinfo", - "version": "1.0.0", - "main": "index.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "build": "npx tsc", + "zip": "(zip getUserInfo.zip index.js node_modules || powershell Compress-Archive -Path index.js, node_modules -DestinationPath getUserInfo.zip)", + "move": "(mv getUserInfo.zip ../../terraform || powershell Move-Item getUserInfo.zip ../../terraform)" + }, + "devDependencies": { + "@types/aws-lambda": "^8.10.147", + "typescript": "^5.7.3" }, - "keywords": [], - "author": "", - "license": "ISC", - "description": "", "dependencies": { - "mysql2": "^3.14.0" + "mysql2": "^3.13.0" } - } - \ No newline at end of file +} diff --git a/aws/src/lambdas/login/tsconfig.json b/aws/src/lambdas/getUserInfo/tsconfig.json similarity index 89% rename from aws/src/lambdas/login/tsconfig.json rename to aws/src/lambdas/getUserInfo/tsconfig.json index 9db674e..c40e4a5 100644 --- a/aws/src/lambdas/login/tsconfig.json +++ b/aws/src/lambdas/getUserInfo/tsconfig.json @@ -4,7 +4,6 @@ "module": "CommonJS", "lib": ["ES2020"], "moduleResolution": "Node", - "outDir": "build", "rootDir": "./", "strict": true, "esModuleInterop": true diff --git a/aws/src/lambdas/insertDomainName/index.js b/aws/src/lambdas/insertDomainName/index.js new file mode 100644 index 0000000..2c42358 --- /dev/null +++ b/aws/src/lambdas/insertDomainName/index.js @@ -0,0 +1,60 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.handler = void 0; +const promise_1 = require("mysql2/promise"); +const dbConfig = { + host: process.env.DB_HOST, + user: process.env.DB_USER, + password: process.env.DB_PASS, + database: process.env.DB_NAME, +}; +const handler = async (event) => { + console.log("Incoming event:", JSON.stringify(event, null, 2)); + let request_body; + if (event.body) { + request_body = JSON.parse(event.body); + } + else { + console.log("No body found"); + return { + statusCode: 400, + body: JSON.stringify({ message: "No body found" }), + }; + } + const { UUID, domain } = request_body; + try { + const connection = await (0, promise_1.createConnection)(dbConfig); + const [rows] = await connection.execute('SELECT 1 FROM users WHERE uuid = ? LIMIT 1', [UUID]); + const uuidExists = rows.length > 0; + if (!uuidExists) { + await connection.end(); + return { + statusCode: 400, + body: JSON.stringify({ message: "UUID does not exist" }), + }; + } + try { + const [result] = await connection.execute('INSERT INTO user_websites (uuid, domain_id) VALUES (?, ?)', [UUID, domain]); + console.log('Insert successful:', result); + return { + statusCode: 200, + body: JSON.stringify("Domain Name added to Database"), + }; + } + catch (error) { + console.error('Failed to insert into user_websites:', error); + return { + statusCode: 401, + body: JSON.stringify({ message: "Failed to insert domain" }), + }; + } + } + catch (error) { + console.error("Database error:", error); + return { + statusCode: 500, + body: JSON.stringify({ message: "Database connection failed", error: error }), + }; + } +}; +exports.handler = handler; diff --git a/aws/src/lambdas/insertDomainName/index.mjs b/aws/src/lambdas/insertDomainName/index.ts similarity index 79% rename from aws/src/lambdas/insertDomainName/index.mjs rename to aws/src/lambdas/insertDomainName/index.ts index 19281b3..bc75d90 100644 --- a/aws/src/lambdas/insertDomainName/index.mjs +++ b/aws/src/lambdas/insertDomainName/index.ts @@ -1,4 +1,5 @@ -import mysql from 'mysql2/promise'; +import { APIGatewayEvent } from "aws-lambda"; +import { createConnection, RowDataPacket } from 'mysql2/promise'; const dbConfig = { host: process.env.DB_HOST, @@ -7,7 +8,7 @@ const dbConfig = { database: process.env.DB_NAME, }; -export const handler = async (event) => { +export const handler = async (event: APIGatewayEvent) => { console.log("Incoming event:", JSON.stringify(event, null, 2)); let request_body; @@ -24,8 +25,8 @@ export const handler = async (event) => { const { UUID, domain } = request_body; try { - const connection = await mysql.createConnection(dbConfig); - const [rows] = await connection.execute('SELECT 1 FROM users WHERE uuid = ? LIMIT 1', [UUID]); + const connection = await createConnection(dbConfig); + const [rows] = await connection.execute('SELECT 1 FROM users WHERE uuid = ? LIMIT 1', [UUID]); const uuidExists = rows.length > 0; if (!uuidExists) { await connection.end(); @@ -57,7 +58,7 @@ export const handler = async (event) => { console.error("Database error:", error); return { statusCode: 500, - body: JSON.stringify({ message: "Database connection failed", error: error.message }), + body: JSON.stringify({ message: "Database connection failed", error: error }), }; } }; diff --git a/aws/src/lambdas/insertDomainName/package.json b/aws/src/lambdas/insertDomainName/package.json index 71e0784..ad17a9f 100644 --- a/aws/src/lambdas/insertDomainName/package.json +++ b/aws/src/lambdas/insertDomainName/package.json @@ -1,16 +1,15 @@ { - "name": "my-lambda", - "version": "1.0.0", - "main": "index.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "build": "npx tsc", + "zip": "(zip insertDomainName.zip index.js node_modules || powershell Compress-Archive -Path index.js, node_modules -DestinationPath insertDomainName.zip)", + "move": "(mv insertDomainName.zip ../../terraform || powershell Move-Item insertDomainName.zip ../../terraform)" + }, + "devDependencies": { + "@types/aws-lambda": "^8.10.147", + "typescript": "^5.7.3" }, - "keywords": [], - "author": "", - "license": "ISC", - "description": "", "dependencies": { - "mysql2": "^3.14.0" + "mysql2": "^3.13.0" } } \ No newline at end of file diff --git a/aws/src/lambdas/insertDomainName/tsconfig.json b/aws/src/lambdas/insertDomainName/tsconfig.json new file mode 100644 index 0000000..c40e4a5 --- /dev/null +++ b/aws/src/lambdas/insertDomainName/tsconfig.json @@ -0,0 +1,11 @@ +{ + "compilerOptions": { + "target": "ES2020", + "module": "CommonJS", + "lib": ["ES2020"], + "moduleResolution": "Node", + "rootDir": "./", + "strict": true, + "esModuleInterop": true + } +} \ No newline at end of file diff --git a/aws/src/lambdas/insertSecurityQues/package.json b/aws/src/lambdas/insertSecurityQues/package.json index e6254dd..93e6f90 100644 --- a/aws/src/lambdas/insertSecurityQues/package.json +++ b/aws/src/lambdas/insertSecurityQues/package.json @@ -1,7 +1,7 @@ { "scripts": { "build": "npx tsc", - "zip": "(rm insertSecurityQues.zip || powershell Remove-Item insertSecurityQues.zip) && (zip insertSecurityQues.zip index.js node_modules || powershell Compress-Archive -Path index.js, node_modules -DestinationPath insertSecurityQues.zip)", + "zip": "(zip insertSecurityQues.zip index.js node_modules || powershell Compress-Archive -Path index.js, node_modules -DestinationPath insertSecurityQues.zip)", "move": "(mv insertSecurityQues.zip ../../terraform || powershell Move-Item insertSecurityQues.zip ../../terraform)" }, "devDependencies": { diff --git a/aws/src/lambdas/login/index.ts b/aws/src/lambdas/login/index.ts deleted file mode 100644 index a4f8454..0000000 --- a/aws/src/lambdas/login/index.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { APIGatewayEvent } from "aws-lambda"; - -const handler = async (event: APIGatewayEvent) => { - console.log("Event: ", JSON.stringify(event, null, 2)); - return { - statusCode: 200, - body: JSON.stringify({ - message: "Hello from signup lambda!" - }), - } -}; - -module.exports = { handler }; \ No newline at end of file diff --git a/aws/src/lambdas/login/login.zip b/aws/src/lambdas/login/login.zip deleted file mode 100644 index 0ff82fa..0000000 Binary files a/aws/src/lambdas/login/login.zip and /dev/null differ diff --git a/aws/src/lambdas/login/package.json b/aws/src/lambdas/login/package.json deleted file mode 100644 index a9576d8..0000000 --- a/aws/src/lambdas/login/package.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "devDependencies": { - "@types/aws-lambda": "^8.10.147", - "typescript": "^5.7.3" - }, - "dependencies": { - "cookie": "^1.0.2" - } -} diff --git a/aws/src/lambdas/signup/index.js b/aws/src/lambdas/signup/index.js index 2f02f03..9c0bc04 100644 --- a/aws/src/lambdas/signup/index.js +++ b/aws/src/lambdas/signup/index.js @@ -1,83 +1,66 @@ -const mysql = require('mysql2'); - +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const mysql2_1 = require("mysql2"); const dbConfig = { - host: process.env.DB_HOST, - user: process.env.DB_USER, - password: process.env.DB_PASS, - database: process.env.DB_NAME, + host: process.env.DB_HOST, + user: process.env.DB_USER, + password: process.env.DB_PASS, + database: process.env.DB_NAME, }; - module.exports.handler = async (event) => { - const httpMethod = event.requestContext.http.method; - if (httpMethod === 'OPTIONS') { - return { - statusCode: 200, - headers: { - 'Access-Control-Allow-Origin': '*', - 'Access-Control-Allow-Methods': 'GET,POST,PUT,DELETE,OPTIONS', - 'Access-Control-Allow-Headers': 'Content-Type,Authorization' - }, - body: '' - }; - } - console.log("Event: ", JSON.stringify(event, null, 2)); - - let request_body; - if (event.body) { - request_body = JSON.parse(event.body); - } else { - console.log("No body found"); - return { - statusCode: 400, - body: JSON.stringify({ message: "No body found" }), - }; - } - - const { uuid, enc_uuid, enc_name, email, enc_phone, enc_answers } = request_body; - const time_creation = new Date().toISOString(); - - let connection; - - try { - connection = mysql.createConnection(dbConfig).promise(); - - const [existing] = await connection.execute( - 'SELECT uuid FROM users WHERE enc_email = ?', - [email] - ); - - if (existing.length > 0) { - return { - statusCode: 200, - body: JSON.stringify({ message: "User already signed up." }), - }; + const httpMethod = event.requestContext.http.method; + if (httpMethod === 'OPTIONS') { + return { + statusCode: 200, + headers: { + 'Access-Control-Allow-Origin': '*', + 'Access-Control-Allow-Methods': 'GET,POST,PUT,DELETE,OPTIONS', + 'Access-Control-Allow-Headers': 'Content-Type,Authorization' + }, + body: '' + }; } - - await connection.execute( - 'INSERT INTO users (uuid, enc_uuid, enc_name, enc_email, enc_phone_num, enc_time_creation) VALUES (?, ?, ?, ?, ?, ?)', - [uuid, enc_uuid, enc_name, email, enc_phone, time_creation] - ); - - await connection.execute( - 'INSERT INTO sec_questions (uuid, enc_uuid, enc_question1, enc_question2, enc_question3, enc_question4, enc_question5, enc_question6, enc_question7, enc_question8, enc_question9, enc_question10) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', - [uuid, enc_uuid, ...enc_answers] - ); - - return { - statusCode: 200, - body: JSON.stringify({ message: "User and security questions inserted successfully!" }), - }; - - } catch (error) { - console.error("Database error:", error); - return { - statusCode: 500, - body: JSON.stringify({ message: "Database operation failed", error: error.message }), - }; - - } finally { - if (connection) { - await connection.end(); + console.log("Event: ", JSON.stringify(event, null, 2)); + let request_body; + if (event.body) { + request_body = JSON.parse(event.body); + } + else { + console.log("No body found"); + return { + statusCode: 400, + body: JSON.stringify({ message: "No body found" }), + }; + } + const { uuid, enc_uuid, enc_name, email, enc_phone, enc_answers } = request_body; + const time_creation = new Date().toISOString(); + let connection; + try { + connection = (0, mysql2_1.createConnection)(dbConfig).promise(); + const [existing] = await connection.execute('SELECT uuid FROM users WHERE enc_email = ?', [email]); + if (existing.length > 0) { + return { + statusCode: 200, + body: JSON.stringify({ message: "User already signed up." }), + }; + } + await connection.execute('INSERT INTO users (uuid, enc_uuid, enc_name, enc_email, enc_phone_num, enc_time_creation) VALUES (?, ?, ?, ?, ?, ?)', [uuid, enc_uuid, enc_name, email, enc_phone, time_creation]); + await connection.execute('INSERT INTO sec_questions (uuid, enc_uuid, enc_question1, enc_question2, enc_question3, enc_question4, enc_question5, enc_question6, enc_question7, enc_question8, enc_question9, enc_question10) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', [uuid, enc_uuid, ...enc_answers]); + return { + statusCode: 200, + body: JSON.stringify({ message: "User and security questions inserted successfully!" }), + }; + } + catch (error) { + console.error("Database error:", error); + return { + statusCode: 500, + body: JSON.stringify({ message: "Database operation failed", error: error }), + }; + } + finally { + if (connection) { + await connection.end(); + } } - } }; diff --git a/aws/src/lambdas/signup/index.ts b/aws/src/lambdas/signup/index.ts new file mode 100644 index 0000000..aa666ec --- /dev/null +++ b/aws/src/lambdas/signup/index.ts @@ -0,0 +1,84 @@ +import { APIGatewayProxyEventV2 } from 'aws-lambda'; +import { createConnection, RowDataPacket } from 'mysql2'; + +const dbConfig = { + host: process.env.DB_HOST, + user: process.env.DB_USER, + password: process.env.DB_PASS, + database: process.env.DB_NAME, +}; + +module.exports.handler = async (event: APIGatewayProxyEventV2) => { + const httpMethod = event.requestContext.http.method; + if (httpMethod === 'OPTIONS') { + return { + statusCode: 200, + headers: { + 'Access-Control-Allow-Origin': '*', + 'Access-Control-Allow-Methods': 'GET,POST,PUT,DELETE,OPTIONS', + 'Access-Control-Allow-Headers': 'Content-Type,Authorization' + }, + body: '' + }; + } + console.log("Event: ", JSON.stringify(event, null, 2)); + + let request_body; + if (event.body) { + request_body = JSON.parse(event.body); + } else { + console.log("No body found"); + return { + statusCode: 400, + body: JSON.stringify({ message: "No body found" }), + }; + } + + const { uuid, enc_uuid, enc_name, email, enc_phone, enc_answers } = request_body; + const time_creation = new Date().toISOString(); + + let connection; + + try { + connection = createConnection(dbConfig).promise(); + + const [existing] = await connection.execute( + 'SELECT uuid FROM users WHERE enc_email = ?', + [email] + ); + + if (existing.length > 0) { + return { + statusCode: 200, + body: JSON.stringify({ message: "User already signed up." }), + }; + } + + await connection.execute( + 'INSERT INTO users (uuid, enc_uuid, enc_name, enc_email, enc_phone_num, enc_time_creation) VALUES (?, ?, ?, ?, ?, ?)', + [uuid, enc_uuid, enc_name, email, enc_phone, time_creation] + ); + + await connection.execute( + 'INSERT INTO sec_questions (uuid, enc_uuid, enc_question1, enc_question2, enc_question3, enc_question4, enc_question5, enc_question6, enc_question7, enc_question8, enc_question9, enc_question10) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', + [uuid, enc_uuid, ...enc_answers] + ); + + return { + statusCode: 200, + body: JSON.stringify({ message: "User and security questions inserted successfully!" }), + }; + + } catch (error) { + console.error("Database error:", error); + return { + statusCode: 500, + body: JSON.stringify({ message: "Database operation failed", error: error }), + }; + + } finally { + if (connection) { + await connection.end(); + } + } +}; diff --git a/aws/src/lambdas/signup/package.json b/aws/src/lambdas/signup/package.json index 9d41263..8a1bf97 100644 --- a/aws/src/lambdas/signup/package.json +++ b/aws/src/lambdas/signup/package.json @@ -1,16 +1,15 @@ { - "name": "lambda", - "version": "1.0.0", - "main": "index.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "build": "npx tsc", + "zip": "(zip signup.zip index.js node_modules || powershell Compress-Archive -Path index.js, node_modules -DestinationPath signup.zip)", + "move": "(mv signup.zip ../../terraform || powershell Move-Item signup.zip ../../terraform)" + }, + "devDependencies": { + "@types/aws-lambda": "^8.10.147", + "typescript": "^5.7.3" }, - "keywords": [], - "author": "", - "license": "ISC", - "description": "", "dependencies": { - "mysql2": "^3.14.0" + "mysql2": "^3.13.0" } } \ No newline at end of file diff --git a/aws/src/lambdas/signup/tsconfig.json b/aws/src/lambdas/signup/tsconfig.json new file mode 100644 index 0000000..c40e4a5 --- /dev/null +++ b/aws/src/lambdas/signup/tsconfig.json @@ -0,0 +1,11 @@ +{ + "compilerOptions": { + "target": "ES2020", + "module": "CommonJS", + "lib": ["ES2020"], + "moduleResolution": "Node", + "rootDir": "./", + "strict": true, + "esModuleInterop": true + } +} \ No newline at end of file diff --git a/aws/src/terraform/api_gateway.tf b/aws/src/terraform/api_gateway.tf index 9e40ed4..dd92036 100644 --- a/aws/src/terraform/api_gateway.tf +++ b/aws/src/terraform/api_gateway.tf @@ -3,6 +3,14 @@ resource "aws_apigatewayv2_api" "http_api" { protocol_type = "HTTP" description = "HTTP API Gateway for HashPass endpoints" fail_on_warnings = true + + cors_configuration { + allow_origins = ["*"] + allow_methods = ["OPTIONS", "POST"] + allow_headers = ["content-type", "authorization"] + max_age = 3600 + allow_credentials = false + } } resource "aws_apigatewayv2_integration" "signup_integration" { @@ -26,24 +34,63 @@ resource "aws_apigatewayv2_integration" "insertSecurityQues_integration" { integration_method = "POST" } +resource "aws_apigatewayv2_integration" "insertDomainName_integration" { + api_id = aws_apigatewayv2_api.http_api.id + integration_type = "AWS_PROXY" + integration_uri = aws_lambda_function.insertDomainName_lambda.invoke_arn + integration_method = "POST" +} + +resource "aws_apigatewayv2_integration" "getUserInfo_integration" { + api_id = aws_apigatewayv2_api.http_api.id + integration_type = "AWS_PROXY" + integration_uri = aws_lambda_function.getUserInfo_lambda.invoke_arn + integration_method = "POST" +} + +resource "aws_apigatewayv2_integration" "calchash_integration" { + api_id = aws_apigatewayv2_api.http_api.id + integration_type = "AWS_PROXY" + integration_uri = aws_lambda_function.calcHash_lambda.invoke_arn + integration_method = "POST" +} + resource "aws_apigatewayv2_route" "signup" { api_id = aws_apigatewayv2_api.http_api.id - route_key = "POST /user/signup" + route_key = "POST /signup" target = "integrations/${aws_apigatewayv2_integration.signup_integration.id}" } resource "aws_apigatewayv2_route" "getQuestions" { api_id = aws_apigatewayv2_api.http_api.id - route_key = "POST /user/getQuestions" + route_key = "POST /getQuestions" target = "integrations/${aws_apigatewayv2_integration.getSecurityQues_integration.id}" } resource "aws_apigatewayv2_route" "insertQuestions" { api_id = aws_apigatewayv2_api.http_api.id - route_key = "POST /user/insertQuestions" + route_key = "POST /insertQuestions" target = "integrations/${aws_apigatewayv2_integration.insertSecurityQues_integration.id}" } +resource "aws_apigatewayv2_route" "insertDomainName" { + api_id = aws_apigatewayv2_api.http_api.id + route_key = "POST /insertDomainName" + target = "integrations/${aws_apigatewayv2_integration.insertDomainName_integration.id}" +} + +resource "aws_apigatewayv2_route" "getUserInfo" { + api_id = aws_apigatewayv2_api.http_api.id + route_key = "POST /getUserInfo" + target = "integrations/${aws_apigatewayv2_integration.getUserInfo_integration.id}" +} + +resource "aws_apigatewayv2_route" "calculateHash" { + api_id = aws_apigatewayv2_api.http_api.id + route_key = "POST /calcHash" + target = "integrations/${aws_apigatewayv2_integration.calchash_integration.id}" +} + resource "aws_lambda_permission" "apigw-lambda" { statement_id = "AllowExecutionFromAPIGateway" action = "lambda:InvokeFunction" @@ -64,63 +111,30 @@ resource "aws_lambda_permission" "apigw-lambda_insertQues" { statement_id = "AllowExecutionFromAPIGateway" action = "lambda:InvokeFunction" function_name = aws_lambda_function.insertSecurityQues_lambda.function_name - principal = "apigateway.amazonaws.com" - source_arn = "arn:aws:execute-api:${var.AWS_REGION}:${var.AWS_ACCOUNT_ID}:${aws_apigatewayv2_api.http_api.id}/*" -} - -resource "aws_apigatewayv2_route" "user_logout" { - api_id = aws_apigatewayv2_api.http_api.id - route_key = "POST /user/logout" -} - -resource "aws_apigatewayv2_route" "user_update" { - api_id = aws_apigatewayv2_api.http_api.id - route_key = "POST /user/update" -} - -resource "aws_apigatewayv2_route" "user_delete" { - api_id = aws_apigatewayv2_api.http_api.id - route_key = "POST /user/delete" -} - -resource "aws_apigatewayv2_route" "hash_addpass" { - api_id = aws_apigatewayv2_api.http_api.id - route_key = "POST /hash/addpass" -} - -resource "aws_apigatewayv2_route" "hash_getpass" { - api_id = aws_apigatewayv2_api.http_api.id - route_key = "POST /hash/getpass" -} - -resource "aws_apigatewayv2_route" "hash_updatepass" { - api_id = aws_apigatewayv2_api.http_api.id - route_key = "POST /hash/updatepass" -} - -resource "aws_apigatewayv2_route" "hash_deletepass" { - api_id = aws_apigatewayv2_api.http_api.id - route_key = "POST /hash/deletepass" + principal = "apigateway.amazonaws.com" + source_arn = "arn:aws:execute-api:${var.AWS_REGION}:${var.AWS_ACCOUNT_ID}:${aws_apigatewayv2_api.http_api.id}/*" } -resource "aws_apigatewayv2_route" "calculate_hash" { - api_id = aws_apigatewayv2_api.http_api.id - route_key = "POST /hash/calc_hash" - target = "integrations/${aws_apigatewayv2_integration.calchash_integration.id}" +resource "aws_lambda_permission" "apigw-lambda_hash" { + statement_id = "AllowExecutionFromAPIGateway" + action = "lambda:InvokeFunction" + function_name = aws_lambda_function.calcHash_lambda.function_name + principal = "apigateway.amazonaws.com" + source_arn = "arn:aws:execute-api:${var.AWS_REGION}:${var.AWS_ACCOUNT_ID}:${aws_apigatewayv2_api.http_api.id}/*" } -resource "aws_apigatewayv2_integration" "calchash_integration" { - api_id = aws_apigatewayv2_api.http_api.id - integration_type = "AWS_PROXY" - integration_uri = aws_lambda_function.calc_hash_lambda.invoke_arn - integration_method = "POST" +resource "aws_lambda_permission" "apigw-lambda_insertDomainName" { + statement_id = "AllowExecutionFromAPIGateway" + action = "lambda:InvokeFunction" + function_name = aws_lambda_function.insertDomainName_lambda.function_name + principal = "apigateway.amazonaws.com" + source_arn = "arn:aws:execute-api:${var.AWS_REGION}:${var.AWS_ACCOUNT_ID}:${aws_apigatewayv2_api.http_api.id}/*" } - -resource "aws_lambda_permission" "apigw-lambda_hash" { +resource "aws_lambda_permission" "apigw-lambda_getUserInfo" { statement_id = "AllowExecutionFromAPIGateway" action = "lambda:InvokeFunction" - function_name = aws_lambda_function.calc_hash_lambda.function_name + function_name = aws_lambda_function.getUserInfo_lambda.function_name principal = "apigateway.amazonaws.com" source_arn = "arn:aws:execute-api:${var.AWS_REGION}:${var.AWS_ACCOUNT_ID}:${aws_apigatewayv2_api.http_api.id}/*" } \ No newline at end of file diff --git a/aws/src/terraform/backendState.tf b/aws/src/terraform/backendState.tf new file mode 100644 index 0000000..cc3df7a --- /dev/null +++ b/aws/src/terraform/backendState.tf @@ -0,0 +1,9 @@ +terraform { + backend "s3" { + bucket = "terraform-state-bucket-343218205322" + key = "terraform.tfstate" + region = "us-east-1" + dynamodb_table = "terraform-states-lock" + encrypt = true + } +} \ No newline at end of file diff --git a/aws/src/terraform/login.tf b/aws/src/terraform/calcHash.tf similarity index 57% rename from aws/src/terraform/login.tf rename to aws/src/terraform/calcHash.tf index 241db14..c497dad 100644 --- a/aws/src/terraform/login.tf +++ b/aws/src/terraform/calcHash.tf @@ -1,10 +1,11 @@ -resource "aws_lambda_function" "login_lambda" { - filename = "${path.cwd}/login.zip" - function_name = "login" +resource "aws_lambda_function" "calcHash_lambda" { + filename = "${path.cwd}/calcHash.zip" + function_name = "calcHash" role = aws_iam_role.iam_role.arn - handler = "login/index.handler" + handler = "calcHash/index.handler" runtime = "nodejs22.x" - source_code_hash = filebase64sha256("${path.cwd}/login.zip") + timeout = 29 + source_code_hash = filebase64sha256("${path.cwd}/calcHash.zip") vpc_config { subnet_ids = ["subnet-08f7876b20ec2648d"] diff --git a/aws/src/terraform/calcHash.zip b/aws/src/terraform/calcHash.zip index 2487586..af2801e 100644 Binary files a/aws/src/terraform/calcHash.zip and b/aws/src/terraform/calcHash.zip differ diff --git a/aws/src/terraform/calc_hash.tf b/aws/src/terraform/calc_hash.tf deleted file mode 100644 index fa6bfac..0000000 --- a/aws/src/terraform/calc_hash.tf +++ /dev/null @@ -1,8 +0,0 @@ -resource "aws_lambda_function" "calc_hash_lambda" { - filename = "${path.cwd}/calcHash.zip" - function_name = "calc_hash" - role = aws_iam_role.iam_role2.arn - handler = "calc_hash/index.handler" - runtime = "nodejs22.x" - source_code_hash = filebase64sha256("${path.cwd}/calcHash.zip") -} \ No newline at end of file diff --git a/aws/src/terraform/getSecurityQues.zip b/aws/src/terraform/getSecurityQues.zip index f0ad6e5..c344402 100644 Binary files a/aws/src/terraform/getSecurityQues.zip and b/aws/src/terraform/getSecurityQues.zip differ diff --git a/aws/src/terraform/getUserInfo.tf b/aws/src/terraform/getUserInfo.tf new file mode 100644 index 0000000..9917542 --- /dev/null +++ b/aws/src/terraform/getUserInfo.tf @@ -0,0 +1,23 @@ +resource "aws_lambda_function" "getUserInfo_lambda" { + filename = "${path.cwd}/getUserInfo.zip" + function_name = "getUserInfo" + role = aws_iam_role.iam_role.arn + handler = "getUserInfo/index.handler" + runtime = "nodejs22.x" + timeout = 29 + source_code_hash = filebase64sha256("${path.cwd}/getUserInfo.zip") + + vpc_config { + subnet_ids = ["subnet-08f7876b20ec2648d"] + security_group_ids = ["sg-097af9b3d4b9cc7a3"] + } + + environment { + variables = { + DB_HOST = var.db_host + DB_USER = var.db_user + DB_PASS = var.db_pass + DB_NAME = var.db_name + } + } +} \ No newline at end of file diff --git a/aws/src/lambdas/insertSecurityQues/insertSecurityQues.zip b/aws/src/terraform/getUserInfo.zip similarity index 66% rename from aws/src/lambdas/insertSecurityQues/insertSecurityQues.zip rename to aws/src/terraform/getUserInfo.zip index edd0484..c17e29b 100644 Binary files a/aws/src/lambdas/insertSecurityQues/insertSecurityQues.zip and b/aws/src/terraform/getUserInfo.zip differ diff --git a/aws/src/terraform/iam-policy.tf b/aws/src/terraform/iam-policy.tf index bdf6d92..14846ce 100644 --- a/aws/src/terraform/iam-policy.tf +++ b/aws/src/terraform/iam-policy.tf @@ -1,6 +1,6 @@ resource "aws_iam_role_policy" "iam-policy" { name = "cloudwatch-policy" - role = aws_iam_role.iam_role2.id + role = aws_iam_role.iam_role.id policy = file("${path.module}/iam-policy.json") depends_on = [aws_iam_role.iam_role] diff --git a/aws/src/terraform/iam-role.tf b/aws/src/terraform/iam-role.tf index 623caab..0478f50 100644 --- a/aws/src/terraform/iam-role.tf +++ b/aws/src/terraform/iam-role.tf @@ -13,7 +13,7 @@ data "aws_iam_policy_document" "assume_role" { } } -resource "aws_iam_role" "iam_role2" { - name = "iam_role_for_lambda2" +resource "aws_iam_role" "iam_role" { + name = "iam_role_for_lambda" assume_role_policy = data.aws_iam_policy_document.assume_role.json } \ No newline at end of file diff --git a/aws/src/terraform/insertDomainName.tf b/aws/src/terraform/insertDomainName.tf new file mode 100644 index 0000000..103bb66 --- /dev/null +++ b/aws/src/terraform/insertDomainName.tf @@ -0,0 +1,23 @@ +resource "aws_lambda_function" "insertDomainName_lambda" { + filename = "${path.cwd}/insertDomainName.zip" + function_name = "insertDomainName" + role = aws_iam_role.iam_role.arn + handler = "insertDomainName/index.handler" + runtime = "nodejs22.x" + timeout = 29 + source_code_hash = filebase64sha256("${path.cwd}/insertDomainName.zip") + + vpc_config { + subnet_ids = ["subnet-08f7876b20ec2648d"] + security_group_ids = ["sg-097af9b3d4b9cc7a3"] + } + + environment { + variables = { + DB_HOST = var.db_host + DB_USER = var.db_user + DB_PASS = var.db_pass + DB_NAME = var.db_name + } + } +} \ No newline at end of file diff --git a/aws/src/terraform/insertDomainName.zip b/aws/src/terraform/insertDomainName.zip new file mode 100644 index 0000000..2d655f1 Binary files /dev/null and b/aws/src/terraform/insertDomainName.zip differ diff --git a/aws/src/terraform/insertSecurityQues.zip b/aws/src/terraform/insertSecurityQues.zip index 1d9d6d0..0d1b4ae 100644 Binary files a/aws/src/terraform/insertSecurityQues.zip and b/aws/src/terraform/insertSecurityQues.zip differ diff --git a/aws/src/terraform/login.zip b/aws/src/terraform/login.zip deleted file mode 100644 index 0ff82fa..0000000 Binary files a/aws/src/terraform/login.zip and /dev/null differ diff --git a/aws/src/terraform/signup.tf b/aws/src/terraform/signup.tf index 0fc3108..07da617 100644 --- a/aws/src/terraform/signup.tf +++ b/aws/src/terraform/signup.tf @@ -4,6 +4,7 @@ resource "aws_lambda_function" "signup_lambda" { role = aws_iam_role.iam_role.arn handler = "signup/index.handler" runtime = "nodejs22.x" + timeout = 29 source_code_hash = filebase64sha256("${path.cwd}/signup.zip") vpc_config { diff --git a/aws/src/terraform/signup.zip b/aws/src/terraform/signup.zip index 9a093ce..01067c3 100644 Binary files a/aws/src/terraform/signup.zip and b/aws/src/terraform/signup.zip differ diff --git a/aws/src/terraform/variables.tf b/aws/src/terraform/variables.tf index b5c154a..6e5b203 100644 --- a/aws/src/terraform/variables.tf +++ b/aws/src/terraform/variables.tf @@ -1,6 +1,6 @@ variable "release_version" { - default = "0.1.0" - type = string + default = "0.1.0" + type = string } variable "AWS_REGION" { diff --git a/extension/src/hashpass/app/security_components/tools/hashing_tool.tsx b/extension/src/hashpass/app/security_components/tools/hashing_tool.tsx index 3012532..38909e0 100644 --- a/extension/src/hashpass/app/security_components/tools/hashing_tool.tsx +++ b/extension/src/hashpass/app/security_components/tools/hashing_tool.tsx @@ -1,6 +1,6 @@ export const hashText = async (text: string): Promise => { try { - const response = await fetch('https://oawbglgv44.execute-api.us-east-1.amazonaws.com/dev/calc_hash', { + const response = await fetch('https://8fy84busdk.execute-api.us-east-1.amazonaws.com/API/calcHash', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ textToHash: text }),