diff --git a/LICENSE b/LICENSE
index c4967cc..fd29243 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
MIT License
-Copyright (c) 2024 PI
+Copyright (c) 2024 PI (github.com/pi-314159)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/Makefile b/Makefile
index 1363199..a9a3f90 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,5 @@
# Author: pi-314159@GitHub
# License: MIT
-# Last Updated: 2024-06-10
CXX ?= g++
DEFAULT_FLAGS := -std=c++20 -O3 -Wall
diff --git a/README.md b/README.md
index f2220e1..8f7c335 100644
--- a/README.md
+++ b/README.md
@@ -2,19 +2,15 @@ This is a TOTP (Time-Based One-Time Password) authenticator that adheres to [RFC
## Build
-Before building, ensure that you have OpenSSL library 3.0 or higher installed and that your compiler supports C++20. By default, the executable is located in the `build` folder.
+Before building, ensure that you have OpenSSL library installed and that your compiler supports C++20. By default, the executable is located in the `build` folder.
### Windows
-If you're on Windows, you can install OpenSSL using vcpkg. Follow these steps:
+By default, Visual Studio Release build will statically link dependencies. You can install OpenSSL using vcpkg. Follow these steps:
1. Install OpenSSL using vcpkg:
```bat
- vcpkg.exe install openssl:x64-windows
- ```
- or
- ```bat
- vcpkg.exe install openssl
+ vcpkg.exe install openssl:x64-windows-static
```
2. Integrate vcpkg with Visual Studio:
diff --git a/VisualStudio/Authenticator.vcxproj b/VisualStudio/Authenticator.vcxproj
index 859251a..35b8f68 100644
--- a/VisualStudio/Authenticator.vcxproj
+++ b/VisualStudio/Authenticator.vcxproj
@@ -44,6 +44,7 @@
true
v143
Unicode
+ x64
Application
@@ -52,6 +53,7 @@
true
Unicode
Static
+ x64
@@ -81,6 +83,9 @@
$(SolutionDir)\..\tmp\
$(VC_IncludePath);$(WindowsSDK_IncludePath);$(SolutionDir)\..\src\include;
+
+ true
+
Level3
@@ -141,6 +146,7 @@
true
false
8388608
+ AdvAPI32.Lib;Crypt32.Lib;User32.Lib;WS2_32.Lib
diff --git a/src/Authenticator.cpp b/src/Authenticator.cpp
index f2f3b36..d0cd2be 100644
--- a/src/Authenticator.cpp
+++ b/src/Authenticator.cpp
@@ -1,12 +1,10 @@
// Author: pi-314159@GitHub
// License: MIT
-// Last updated: 2024-06-10
#include
#include
#include
#include
-#include
#include
#include
@@ -18,7 +16,7 @@
int main(int argc, char* argv[]) {
std::cout << "=========================== PI Authenticator ===========================\n"
- "= Last Updated: 2024-06-10 =\n"
+ "= Last Updated: 2024-06-17 =\n"
"= License: MIT =\n"
"= GitHub Repository: github.com/pi-314159/Authenticator =\n"
"========================================================================\n\n" << std::endl;
@@ -106,7 +104,7 @@ int main(int argc, char* argv[]) {
tOTPInstance.period = std::stoul(lineElement);
break;
case 3:
- tOTPInstance.alg = lineElement[0];
+ tOTPInstance.alg = lineElement;
break;
case 4:
tOTPInstance.digits = std::stoi(lineElement);
@@ -140,7 +138,7 @@ int main(int argc, char* argv[]) {
while (action[0] != 'q') {
STARTLOOP:
if (action[0] == 'g') {
- std::cout << "OTP: " << ACTIONS::GenerateTOTP(tOTPObjects[selectedOTPIndex]) << "\n" << std::endl;
+ std::cout << "OTP: " << ACTIONS::GenerateTotp(tOTPObjects[selectedOTPIndex]) << "\n" << std::endl;
}
else if (action[0] == 'l') {
if (tOTPObjectsSize > 0) {
@@ -159,15 +157,9 @@ int main(int argc, char* argv[]) {
if (tOTPObjectsSize > 1) {
tOTPObjects.erase(tOTPObjects.begin() + selectedOTPIndex);
action[0] = 'l';
- unsigned char* iV = new unsigned char[16];
- TOOLS::GenerateIV(iV);
auto toWrite = std::make_unique("OK" + TOOLS::VectorToString(tOTPObjects));
- auto encryptedContents = std::make_unique_for_overwrite();
- unsigned long long int encryptedContentsSize = 0;
- crypto->Aes(key, iV, *toWrite, *encryptedContents, encryptedContentsSize);
- fileIo->WriteBinary(*encryptedContents, iV);
- encryptedContents.reset(); toWrite.reset();
- delete[] iV;
+ fileIo->WriteBinary(*toWrite, key);
+ toWrite.reset();
}
else {
tOTPObjects.clear();
@@ -181,15 +173,9 @@ int main(int argc, char* argv[]) {
ACTIONS::Add(tOTPObjects);
action[0] = 'l';
++tOTPObjectsSize;
- unsigned char* iV = new unsigned char[16];
- TOOLS::GenerateIV(iV);
auto toWrite = std::make_unique("OK" + TOOLS::VectorToString(tOTPObjects));
- auto encryptedContents = std::make_unique_for_overwrite();
- unsigned long long int encryptedContentsSize = 0;
- crypto->Aes(key, iV, *toWrite, *encryptedContents, encryptedContentsSize);
- fileIo->WriteBinary(*encryptedContents, iV);
- encryptedContents.reset(); toWrite.reset();
- delete[] iV;
+ fileIo->WriteBinary(*toWrite, key);
+ toWrite.reset();
std::cout << "Added.\n" << std::endl;
goto STARTLOOP;
}
diff --git a/src/actions/add.cpp b/src/actions/add.cpp
index 99ebd33..eb6ef41 100644
--- a/src/actions/add.cpp
+++ b/src/actions/add.cpp
@@ -1,6 +1,5 @@
// Author: pi-314159@GitHub
// License: MIT
-// Last updated: 2024-06-10
#include
#include
@@ -12,14 +11,14 @@ namespace ACTIONS {
void Add(std::vector& tOTPObjects) {
auto str = std::make_unique_for_overwrite();
std::string inputBuffer, tag, secret;
- char alg = '1';
+ std::string alg = "sha1";
unsigned int period;
unsigned short digits;
while (inputBuffer.empty()) {
str->Input(inputBuffer, "Please enter the issuer (e.g., GitHub), then hit Enter TWICE to proceed:", true);
str->FormatInput(inputBuffer, inputBuffer);
}
- tag = inputBuffer + "::";
+ tag = inputBuffer + ":";
inputBuffer = "";
while (inputBuffer.empty()) {
str->Input(inputBuffer, "Please enter the account (e.g., user@example.com), \nthen hit Enter TWICE to proceed:", true);
@@ -44,11 +43,11 @@ namespace ACTIONS {
}
str->Input(inputBuffer, "Please select the hash algorithm:\n[1] SHA-1\n[2] SHA-256\n[3] SHA-384\n[5] SHA-512\nEnter your choice (default 1):");
if (inputBuffer == "2") {
- alg = '2';
+ alg = "sha256";
} else if (inputBuffer == "3") {
- alg = '3';
+ alg = "sha384";
} else if (inputBuffer == "5") {
- alg = '5';
+ alg = "sha512";
}
str->Input(inputBuffer, "Please enter the digits (between 6 - 10, default 6):");
if (str->FormatInput(inputBuffer, digits, '2')) {
diff --git a/src/actions/generatetotp.cpp b/src/actions/generatetotp.cpp
index 58bfe74..42053a7 100644
--- a/src/actions/generatetotp.cpp
+++ b/src/actions/generatetotp.cpp
@@ -1,9 +1,7 @@
// Author: pi-314159@GitHub
// License: MIT
-// Last updated: 2024-06-10
#include
-
#include
#include
@@ -11,7 +9,7 @@
#include
namespace ACTIONS {
- std::string GenerateTOTP(tOTP_object& tOTP) {
+ std::string GenerateTotp(tOTP_object& tOTP) {
auto secretSize = static_cast(floor(tOTP.secret.size() / 1.6));
unsigned char* decodedSecret = new unsigned char[secretSize];
TOOLS::Base32Decode(tOTP.secret, decodedSecret);
diff --git a/src/include/actions/add.h b/src/include/actions/add.h
index b64b1d8..cb0cf20 100644
--- a/src/include/actions/add.h
+++ b/src/include/actions/add.h
@@ -1,6 +1,5 @@
// Author: pi-314159@GitHub
// License: MIT
-// Last updated: 2024-06-10
#ifndef ACTIONS__ADD_H_
#define ACTIONS__ADD_H_
diff --git a/src/include/actions/generatetotp.h b/src/include/actions/generatetotp.h
index 5c3d557..374b9c9 100644
--- a/src/include/actions/generatetotp.h
+++ b/src/include/actions/generatetotp.h
@@ -1,6 +1,5 @@
// Author: pi-314159@GitHub
// License: MIT
-// Last updated: 2024-06-10
#ifndef ACTIONS__GENERATETOTP_H_
#define ACTIONS__GENERATETOTP_H_
@@ -8,7 +7,7 @@
#include
namespace ACTIONS {
- std::string GenerateTOTP(tOTP_object& tOTP);
+ std::string GenerateTotp(tOTP_object& tOTP);
}
#endif
diff --git a/src/include/tools/base32decode.h b/src/include/tools/base32decode.h
index b2ed187..b8367a4 100644
--- a/src/include/tools/base32decode.h
+++ b/src/include/tools/base32decode.h
@@ -1,6 +1,5 @@
// Author: pi-314159@GitHub
// License: MIT
-// Last updated: 2024-06-10
#ifndef TOOLS__BASE32DECODE_H_
#define TOOLS__BASE32DECODE_H_
diff --git a/src/include/tools/crypto.h b/src/include/tools/crypto.h
index 57bd393..ab0002b 100644
--- a/src/include/tools/crypto.h
+++ b/src/include/tools/crypto.h
@@ -1,6 +1,5 @@
// Author: pi-314159@GitHub
// License: MIT
-// Last updated: 2024-06-10
#ifndef TOOLS__CRYPTO_H_
#define TOOLS__CRYPTO_H_
@@ -10,7 +9,7 @@
namespace TOOLS {
class Crypto {
public:
- void CalculateHmac(char hashAlg, unsigned char* key, int& keySize, unsigned long long int msg, unsigned char* result, unsigned int* resultSize);
+ void CalculateHmac(std::string hashAlg, unsigned char* key, int& keySize, unsigned long long int msg, unsigned char* result, unsigned int* resultSize);
void Aes(unsigned char* key, unsigned char* iv, std::string& input, std::string& output, unsigned long long int& outputSize, bool encrypt = true, unsigned short int bufferSize = 1024);
};
}
diff --git a/src/include/tools/file_io.h b/src/include/tools/file_io.h
index 50be2b3..4260d79 100644
--- a/src/include/tools/file_io.h
+++ b/src/include/tools/file_io.h
@@ -1,6 +1,5 @@
// Author: pi-314159@GitHub
// License: MIT
-// Last updated: 2024-06-10
#ifndef TOOLS__FILE_IO_H_
#define TOOLS__FILE_IO_H_
@@ -15,7 +14,7 @@ namespace TOOLS {
public:
File_Io(std::unique_ptr& s);
bool ReadBinary(std::string& binaryFileContent);
- bool WriteBinary(std::string& binaryFileContent, unsigned char* iV, unsigned int iVSize = 16);
+ bool WriteBinary(std::string& binaryFileContent, unsigned char key[], unsigned int iVSize = 16);
bool DeleteFile();
};
}
diff --git a/src/include/tools/generateiv.h b/src/include/tools/generateiv.h
index 609d638..57fbcf9 100644
--- a/src/include/tools/generateiv.h
+++ b/src/include/tools/generateiv.h
@@ -1,12 +1,11 @@
// Author: pi-314159@GitHub
// License: MIT
-// Last updated: 2024-06-10
#ifndef TOOLS__GENERATEIV_H_
#define TOOLS__GENERATEIV_H_
namespace TOOLS {
- void GenerateIV(unsigned char* iV, unsigned int iVSize = 16);
+ void GenerateIv(unsigned char* iV, unsigned int iVSize = 16);
}
#endif
diff --git a/src/include/tools/string.h b/src/include/tools/string.h
index f722671..b7c05dc 100644
--- a/src/include/tools/string.h
+++ b/src/include/tools/string.h
@@ -1,6 +1,5 @@
// Author: pi-314159@GitHub
// License: MIT
-// Last updated: 2024-06-10
#ifndef TOOLS__STRING_H_
#define TOOLS__STRING_H_
diff --git a/src/include/tools/vectortostring.h b/src/include/tools/vectortostring.h
index bbd5540..33c9be6 100644
--- a/src/include/tools/vectortostring.h
+++ b/src/include/tools/vectortostring.h
@@ -1,6 +1,5 @@
// Author: pi-314159@GitHub
// License: MIT
-// Last updated: 2024-06-10
#ifndef TOOLS__VECTORTOSTRING_H_
#define TOOLS__VECTORTOSTRING_H_
diff --git a/src/include/totp.h b/src/include/totp.h
index 7ac8a51..ca20baf 100644
--- a/src/include/totp.h
+++ b/src/include/totp.h
@@ -1,6 +1,5 @@
// Author: pi-314159@GitHub
// License: MIT
-// Last updated: 2024-06-10
#ifndef TOTP_H_
#define TOTP_H_
@@ -12,7 +11,7 @@ struct tOTP_object {
std::string tag;
std::string secret;
unsigned int period;
- char alg;
+ std::string alg;
unsigned short digits;
};
diff --git a/src/tools/base32decode.cpp b/src/tools/base32decode.cpp
index cf6e031..b7be438 100644
--- a/src/tools/base32decode.cpp
+++ b/src/tools/base32decode.cpp
@@ -1,6 +1,5 @@
// Author: pi-314159@GitHub
// License: MIT
-// Last updated: 2024-06-10
#include
diff --git a/src/tools/crypto.cpp b/src/tools/crypto.cpp
index cf88ff6..31bcc04 100644
--- a/src/tools/crypto.cpp
+++ b/src/tools/crypto.cpp
@@ -1,6 +1,5 @@
// Author: pi-314159@GitHub
// License: MIT
-// Last updated: 2024-06-10
#include
@@ -10,18 +9,15 @@
#include
namespace TOOLS {
- void Crypto::CalculateHmac(char hashAlg, unsigned char* key, int& keySize, unsigned long long int msg, unsigned char* result, unsigned int* resultSize) {
+ void Crypto::CalculateHmac(std::string hashAlg, unsigned char* key, int& keySize, unsigned long long int msg, unsigned char* result, unsigned int* resultSize) {
auto hashAlgorithm = EVP_sha1();
- switch (hashAlg) {
- case '2':
+ if (hashAlg == "sha256") {
hashAlgorithm = EVP_sha256();
- break;
- case '3':
+ } else if (hashAlg == "sha384") {
hashAlgorithm = EVP_sha384();
- break;
- case '5':
+ }
+ else if (hashAlg == "sha512") {
hashAlgorithm = EVP_sha512();
- break;
}
unsigned char message[8] = {'0'};
diff --git a/src/tools/file_io.cpp b/src/tools/file_io.cpp
index 7508d4e..ebd1ef4 100644
--- a/src/tools/file_io.cpp
+++ b/src/tools/file_io.cpp
@@ -1,8 +1,9 @@
// Author: pi-314159@GitHub
// License: MIT
-// Last updated: 2024-06-10
+#include
#include
+#include
#include
#include
@@ -19,22 +20,23 @@ namespace TOOLS {
return true;
}
- bool File_Io::WriteBinary(std::string& binaryFileContent, unsigned char* iV, unsigned int iVSize) {
+ bool File_Io::WriteBinary(std::string& binaryFileContent, unsigned char key[], unsigned int iVSize) {
+ unsigned char* iV = new unsigned char[16];
+ GenerateIv(iV);
+ std::string encryptedContents;
+ unsigned long long int encryptedContentsSize = 0;
+ auto crypto = std::make_unique_for_overwrite();
+ crypto->Aes(key, iV, binaryFileContent, encryptedContents, encryptedContentsSize);
+ crypto.reset();
std::ofstream writeBinaryFileHandle(filePath, std::ios::binary);
writeBinaryFileHandle.write((char*)iV, iVSize);
- writeBinaryFileHandle.write(binaryFileContent.c_str(), binaryFileContent.size());
+ writeBinaryFileHandle.write(encryptedContents.c_str(), encryptedContentsSize);
writeBinaryFileHandle.close();
+ delete[] iV;
return true;
}
bool File_Io::DeleteFile() {
- bool ret = true;
- try {
- std::filesystem::remove(filePath);
- }
- catch (...) {
- ret = false;
- }
- return ret;
+ return std::filesystem::remove(filePath);
}
}
\ No newline at end of file
diff --git a/src/tools/generateiv.cpp b/src/tools/generateiv.cpp
index d63916b..95b0fc3 100644
--- a/src/tools/generateiv.cpp
+++ b/src/tools/generateiv.cpp
@@ -1,17 +1,16 @@
// Author: pi-314159@GitHub
// License: MIT
-// Last updated: 2024-06-10
#include
#include
namespace TOOLS {
- void GenerateIV(unsigned char* iV, unsigned int iVSize) {
+ void GenerateIv(unsigned char* iV, unsigned int iVSize) {
std::mt19937 devRandom(std::random_device{}());
- std::uniform_int_distribution<>IVrange{0, 255};
+ std::uniform_int_distribution<>iVRange{0, 255};
for (unsigned short int i = 0; i < iVSize; ++i) {
- iV[i] = IVrange(devRandom);
+ iV[i] = iVRange(devRandom);
}
return;
}
diff --git a/src/tools/string.cpp b/src/tools/string.cpp
index 5c88240..73266c8 100644
--- a/src/tools/string.cpp
+++ b/src/tools/string.cpp
@@ -1,6 +1,5 @@
// Author: pi-314159@GitHub
// License: MIT
-// Last updated: 2024-06-10
#include
diff --git a/src/tools/vectortostring.cpp b/src/tools/vectortostring.cpp
index 827dbff..eca04d2 100644
--- a/src/tools/vectortostring.cpp
+++ b/src/tools/vectortostring.cpp
@@ -1,6 +1,5 @@
// Author: pi-314159@GitHub
// License: MIT
-// Last updated: 2024-06-10
#include