1
0
mirror of https://github.com/H0llyW00dzZ/ESP8266-TOTP.git synced 2025-02-06 11:01:56 +00:00

Initial Commit

- [+] feat: add initial project files
- [+] feat(.gitignore): add .gitignore file
- [+] feat(LICENSE): add BSD 3-Clause License
- [+] feat(README.md): add project documentation
- [+] feat(platformio.ini): add PlatformIO configuration file
- [+] feat(totp.ino): add main Arduino sketch for TOTP generation
This commit is contained in:
H0llyW00dzZ 2024-10-20 22:32:37 +07:00
commit 82393d41c8
5 changed files with 153 additions and 0 deletions

5
.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch

30
LICENSE Normal file
View File

@ -0,0 +1,30 @@
BSD 3-Clause License
-----------
Copyright (c) 2024, H0llyW00dzZ / H0llyW00dz
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

38
README.md Normal file
View File

@ -0,0 +1,38 @@
# ESP8266 Arduino TOTP (Expermintal)
> [!WARNING]
> This is experimental and might not work as expected.
## Overview
This project demonstrates how to implement a Time-based One-Time Password (TOTP) generator using an ESP8266 board with Arduino. The system connects to Wi-Fi, synchronizes time using an NTP client, and generates OTPs based on a shared secret.
## Features
- Connects to Wi-Fi and synchronizes with an NTP server.
- Decodes a Base32 encoded secret for TOTP generation.
- Generates and displays a TOTP every 30 seconds.
## Usage
1. **Configure Wi-Fi Credentials**:
- Open the sketch and replace `your_SSID` and `your_PASSWORD` with your Wi-Fi credentials.
2. **Set Base32 Secret**:
- Replace `BASE32EncodedSecret` with your actual Base32 encoded secret.
3. **Upload Code**:
- Connect your ESP8266 board to your computer.
- Select the correct board and port in the Arduino IDE.
- Upload the code to the board.
4. **Monitor Output**:
- Open the Serial Monitor in Arduino IDE to view the generated OTPs.
## License
This project is licensed under the [BSD 3-Clause License](LICENSE).
## Acknowledgments
- Based on libraries and examples from the Arduino community.

20
platformio.ini Normal file
View File

@ -0,0 +1,20 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env:esp12e]
platform = espressif8266
board = esp12e
framework = arduino
lib_deps =
ESP8266WiFi
arduino-libraries/NTPClient
Hash
https://github.com/dirkx/Arduino-Base32-Decode
https://github.com/lucadentella/TOTP-Arduino

60
totp.ino Normal file
View File

@ -0,0 +1,60 @@
// Copyright (c) 2024 H0llyW00dz All rights reserved.
//
// By accessing or using this software, you agree to be bound by the terms
// of the License Agreement, which you can find at LICENSE files.
//
// Note: This is experimental IoT and might not work as expected.
#include <ESP8266WiFi.h>
#include <NTPClient.h>
#include <WiFiUdp.h>
#include <Hash.h>
#include <TOTP.h>
#include <Base32-Decode.h>
// Wi-Fi credentials
const char* ssid = "your_SSID";
const char* password = "your_PASSWORD";
// NTP client setup
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "pool.ntp.org", 0, 60000);
// Base32 encoded secret key for TOTP
const char* base32Secret = "BASE32EncodedSecret"; // Replace with your Base32 encoded secret
uint8_t decodedSecret[10]; // Adjust size based on your secret length
void setup() {
Serial.begin(115200);
// Connect to Wi-Fi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
// Initialize NTP client
timeClient.begin();
// Decode Base32 secret
int secretLength = base32decode((char*)base32Secret, decodedSecret, sizeof(decodedSecret));
if (secretLength <= 0) {
Serial.println("Error decoding Base32 secret");
while (true); // Halt execution
}
}
void loop() {
timeClient.update();
unsigned long epochTime = timeClient.getEpochTime();
// Generate TOTP
TOTP totp(decodedSecret, sizeof(decodedSecret));
String otp = totp.getCode(epochTime);
Serial.println("Current OTP: " + otp);
// Wait for 30 seconds before generating the next OTP
delay(30000);
}