From 603a7278e2c71c9ffa43c8457ffee633ca7d26dc Mon Sep 17 00:00:00 2001 From: Hizenberg469 Date: Tue, 5 Nov 2024 22:31:48 +0530 Subject: [PATCH] Project complete --- .../backend/ValidatorClient.java | 86 +++++++++++++------ .../frontend/MainWindowController.java | 2 + 2 files changed, 63 insertions(+), 25 deletions(-) diff --git a/src/main/java/com/secure_mailer/backend/ValidatorClient.java b/src/main/java/com/secure_mailer/backend/ValidatorClient.java index 3ca8b7a..f14552f 100644 --- a/src/main/java/com/secure_mailer/backend/ValidatorClient.java +++ b/src/main/java/com/secure_mailer/backend/ValidatorClient.java @@ -17,6 +17,7 @@ import javafx.application.Platform; import javafx.scene.control.Alert; import javafx.scene.control.Alert.AlertType; import javafx.util.Duration; +import java.util.StringTokenizer; public class ValidatorClient { @@ -154,7 +155,9 @@ public class ValidatorClient { String packet = formPacket(data); //Packet ready. - packet = String.valueOf(1) + packet; +// packet = String.valueOf() + packet; + + System.out.println("Packet for authentication : "+packet); //Send the size of packet. //ps.println(packet.length()); @@ -166,36 +169,69 @@ public class ValidatorClient { String msg = br.readLine(); - //Parse the packet. - int i = 0; - String num = ""; - for(; i < msg.length() ; i++ ) { - if( msg.charAt(i) != ':' ) - num += Character.toString(msg.charAt(i)); - else - break; - } + StringTokenizer tokenizer = new StringTokenizer(msg, ":"); + this.timeStamp = tokenizer.nextToken(); + this.authCode = tokenizer.nextToken(); +// //Parse the packet. +// int i = 0; +// String num = ""; +// for(; i < msg.length() ; i++ ) { +// if( msg.charAt(i) != ':' ) +// num += Character.toString(msg.charAt(i)); +// else +// break; +// } +// +// num = num + "\0"; +// if( num.equals("420") ) { +// Platform.runLater(() -> showAlert("Error", "Email record not found on server.")); +// return false; +// } +// +// this.timeStamp = num; +// i = i + 1; +// num = ""; +// for(; i < msg.length() ; i++ ) { +// num += Character.toString(msg.charAt(i)); +// } +//// num = num + "\0"; +// this.authCode = num + "\0"; - - if( num.equals("420") ) { - Platform.runLater(() -> showAlert("Error", "Email record not found on server.")); - return false; - } - - this.timeStamp = num; - i = i + 1; - num = ""; - for(; i < msg.length() ; i++ ) { - num += Character.toString(msg.charAt(i)); - } - this.authCode = num; + System.out.println("Size of timestamp : " + this.timeStamp.length()); + this.authCode = (this.authCode).substring(0, 6); + System.out.println("Size of authCode : " + this.authCode.length()); String secretKey = SecretCodeDAO.getSecretCode(fromEmailId); - String totp = generateTOTP( secretKey, Long.parseLong(this.timeStamp)); + String totp = generateTOTP( secretKey, Long.parseLong(this.timeStamp.trim())); + System.out.println("TimeStamp : "+this.timeStamp); + System.out.println("AuthCode : "+this.authCode); + System.out.println("TOTP : "+totp); + + String temp = this.authCode; + int serverTOTP = -132; + try { + serverTOTP = Integer.parseInt(temp.trim()); + } catch (NumberFormatException e) { + System.err.println("Problem in serverTOTP"); + } + + int clientTOTP = 4324; + try { + clientTOTP = Integer.parseInt(totp.trim()); + } catch (NumberFormatException e) { + System.err.println("Problem in clientTOTP"); + } + + System.out.println("Server TOTP : "+serverTOTP); + System.out.println("Client TOTP : "+clientTOTP); + + boolean result = (serverTOTP == clientTOTP); + + System.out.println("Result : "+result); - return (totp == this.authCode); + return result; } catch(SQLException e) { diff --git a/src/main/java/com/secure_mailer/frontend/MainWindowController.java b/src/main/java/com/secure_mailer/frontend/MainWindowController.java index 6bc71e6..5ab7284 100644 --- a/src/main/java/com/secure_mailer/frontend/MainWindowController.java +++ b/src/main/java/com/secure_mailer/frontend/MainWindowController.java @@ -299,6 +299,8 @@ public class MainWindowController extends BaseController implements Initializabl emailMessage.setIsAuthenticated(isAuthenticated); + System.out.println("Is Authenticated : "+isAuthenticated); + if(emailMessage != null) { if (isAuthenticated) { emailManager.setSelectedMessage(emailMessage);