not working

not_working
kirbylife 2023-03-30 17:28:34 -06:00
parent 90d3e4b4e9
commit 8ff28c8299
5 changed files with 112 additions and 24 deletions

84
Cargo.lock generated
View File

@ -12,7 +12,7 @@ dependencies = [
"avr-hal-generic", "avr-hal-generic",
"cfg-if 1.0.0", "cfg-if 1.0.0",
"embedded-hal", "embedded-hal",
"ufmt", "ufmt 0.1.2",
"void", "void",
] ]
@ -25,6 +25,12 @@ dependencies = [
"avr-hal-generic", "avr-hal-generic",
] ]
[[package]]
name = "autocfg"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]] [[package]]
name = "avr-device" name = "avr-device"
version = "0.5.0" version = "0.5.0"
@ -60,7 +66,7 @@ dependencies = [
"nb 0.1.3", "nb 0.1.3",
"paste", "paste",
"rustversion", "rustversion",
"ufmt", "ufmt 0.1.2",
"void", "void",
] ]
@ -88,6 +94,26 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "chrono"
version = "0.4.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e3c5919066adf22df73762e50cffcde3a758f2a848b113b586d1f86728b673b"
dependencies = [
"num-integer",
"num-traits",
]
[[package]]
name = "ds323x"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "057e63d03a3beb83d3c9b7a19b799c60e203b0c53f1bbec6a715804907f73a2b"
dependencies = [
"embedded-hal",
"rtcc",
]
[[package]] [[package]]
name = "embedded-hal" name = "embedded-hal"
version = "0.2.7" version = "0.2.7"
@ -119,6 +145,25 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8d5439c4ad607c3c23abf66de8c8bf57ba8adcd1f129e699851a6e43935d339d" checksum = "8d5439c4ad607c3c23abf66de8c8bf57ba8adcd1f129e699851a6e43935d339d"
[[package]]
name = "num-integer"
version = "0.1.45"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9"
dependencies = [
"autocfg",
"num-traits",
]
[[package]]
name = "num-traits"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd"
dependencies = [
"autocfg",
]
[[package]] [[package]]
name = "panic-halt" name = "panic-halt"
version = "0.2.0" version = "0.2.0"
@ -155,6 +200,15 @@ dependencies = [
"proc-macro2", "proc-macro2",
] ]
[[package]]
name = "rtcc"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3623619ce77c09a7d87cf7c61c5c887b9c7dee8805f66af6c4aa5824be4d9930"
dependencies = [
"chrono",
]
[[package]] [[package]]
name = "rustversion" name = "rustversion"
version = "1.0.12" version = "1.0.12"
@ -167,8 +221,11 @@ version = "0.1.0"
dependencies = [ dependencies = [
"arduino-hal", "arduino-hal",
"binascii", "binascii",
"chrono",
"ds323x",
"panic-halt", "panic-halt",
"sha1_smol", "sha1_smol",
"ufmt 0.2.0",
] ]
[[package]] [[package]]
@ -195,7 +252,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "31d3c0c63312dfc9d8e5c71114d617018a19f6058674003c0da29ee8d8036cdd" checksum = "31d3c0c63312dfc9d8e5c71114d617018a19f6058674003c0da29ee8d8036cdd"
dependencies = [ dependencies = [
"proc-macro-hack", "proc-macro-hack",
"ufmt-macros", "ufmt-macros 0.2.0",
"ufmt-write",
]
[[package]]
name = "ufmt"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a64846ec02b57e9108d6469d98d1648782ad6bb150a95a9baac26900bbeab9d"
dependencies = [
"ufmt-macros 0.3.0",
"ufmt-write", "ufmt-write",
] ]
@ -211,6 +278,17 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "ufmt-macros"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d337d3be617449165cb4633c8dece429afd83f84051024079f97ad32a9663716"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "ufmt-write" name = "ufmt-write"
version = "0.1.0" version = "0.1.0"

View File

@ -8,10 +8,13 @@ arduino-hal = { git = "https://github.com/rahix/avr-hal", features = ["arduino-
panic-halt = "0.2.0" panic-halt = "0.2.0"
sha1_smol = "1.0.0" sha1_smol = "1.0.0"
binascii = { version = "0.1", default-features = false, features = ["decode"] } binascii = { version = "0.1", default-features = false, features = ["decode"] }
chrono = { version = "0.4.24", default-features = false }
ds323x = "0.5.0"
ufmt = "0.2.0"
[profile.release] [profile.release]
lto = true lto = true
panic = "abort" panic = "abort"
strip = true strip = true
opt-level = "z" opt-level = "z"
codegen-units = 1 codegen-units = 1

5
README.md 100644
View File

@ -0,0 +1,5 @@
# RustyToken
## Converts any Arduino into a TOTP keys
You can build a TOTP Key with an Arduino

View File

@ -1 +1 @@
cargo build -Z build-std=core --target avr-atmega328p.json --release cargo build -Z build-std-features=panic_immediate_abort -Z build-std=core --target avr-atmega328p.json --release

View File

@ -3,15 +3,15 @@
mod crypto; mod crypto;
use arduino_hal::hal::usart::BaudrateArduinoExt; use arduino_hal::default_serial;
use arduino_hal::prelude::*; use arduino_hal::delay_ms;
use arduino_hal::{delay_ms, Usart};
use crypto::hmac_sha1; use crypto::hmac_sha1;
use ds323x::DateTimeAccess;
use panic_halt as _; use panic_halt as _;
const INTERVAL: u64 = 30; const INTERVAL: i64 = 30;
const SECRET_KEY_MAX_LEN: u8 = 32; const SECRET_KEY_MAX_LEN: usize = 32;
fn process_secret<'a>(secret: &str, output: &mut [u8]) -> usize { fn process_secret<'a>(secret: &str, output: &mut [u8]) -> usize {
// RFC 6238 Doesn't specify a max length for the secret keys, So I chose 32 // RFC 6238 Doesn't specify a max length for the secret keys, So I chose 32
@ -39,7 +39,7 @@ fn process_secret<'a>(secret: &str, output: &mut [u8]) -> usize {
decoded.len() decoded.len()
} }
fn generate_otp_token(private_key: &str, actual_time: u64) -> u32 { fn generate_otp_token(private_key: &str, actual_time: i64) -> u32 {
let mut output = [0u8; 50]; let mut output = [0u8; 50];
let private_key_len = process_secret(private_key, &mut output); let private_key_len = process_secret(private_key, &mut output);
@ -72,22 +72,24 @@ fn main() -> ! {
let pins = arduino_hal::pins!(dp); let pins = arduino_hal::pins!(dp);
let mut led = pins.d13.into_output(); let mut led = pins.d13.into_output();
let mut serial = Usart::new( let mut serial = default_serial!(dp, pins, 9600);
dp.USART0, let i2c = arduino_hal::I2c::new(
pins.d0, dp.TWI,
pins.d1.into_output(), pins.a4.into_pull_up_input(),
BaudrateArduinoExt::into_baudrate(9600), pins.a5.into_pull_up_input(),
50000,
); );
let mut rtc = ds323x::Ds323x::new_ds3231(i2c);
// let token = generate_otp_token("holaaaaamundo", 1680155315); let timestamp = rtc.datetime().unwrap().timestamp();
let token = generate_otp_token("FS7J22EHLLSOGKUVJKV2XE7FTIX24JAJ", 1680155315); let timestamp = 0;
let mut output = [0u8; 6];
token_to_bytes(token, &mut output);
for b in output { ufmt::uwriteln!(&mut serial, "timestamp: {}", timestamp).unwrap();
serial.write_byte(b);
} // let token = generate_otp_token("holaaaaamundo", timestamp.try_into().unwrap());
serial.write_byte('\n' as u8); let token = generate_otp_token("aaaaaaaa", timestamp);
ufmt::uwriteln!(&mut serial, "token: {}", token).unwrap();
loop { loop {
led.toggle(); led.toggle();