Skip to content

Commit

Permalink
cycle through the 6 predefined colors that corresponds to a different…
Browse files Browse the repository at this point in the history
… seed
  • Loading branch information
ryanamaral committed Feb 3, 2023
1 parent 7bc4522 commit 8373c3b
Show file tree
Hide file tree
Showing 10 changed files with 483 additions and 31 deletions.
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ TurtlPass Firmware provides a simple and secure way of generating passwords usin

* Generates unique, secure passwords from a simple input hash
* 100 characters long, including a combination of lowercase and uppercase letters, as well as numbers
* Uses a seed stored in flash memory for added security
* Seed material stored in flash memory for added security
* Automatically types the password for you, so you don't have to
* Erases the password from memory after use, for extra peace of mind
* Easy to integrate into your existing projects with USB serial port connectivity
Expand All @@ -26,9 +26,9 @@ TurtlPass Firmware provides a simple and secure way of generating passwords usin

<img src="assets/rpi-picos.jpg" width="100%">

1. **Raspberry Pi Pico**
2. **OTG Cable**: micro-USB (male) to USB-C (male)
3. **Cover/Case** (optional)
1. **RP2040 Board**: both **Raspberry Pi Pico** and **Adafruit Trinkey QT2040** have been tested ✅
2. **USB OTG Cable / Adapter**
3. Cover/Case (optional)


## 💡 LED State
Expand All @@ -43,6 +43,16 @@ TurtlPass Firmware provides a simple and secure way of generating passwords usin
* No power input


**If your board have a RGB LED**, is possible to **switch seed** by pressing the `BOOTSEL` button on the board (in the `ON` state only). Here are the 6 available colors:

1. 🟢 Green (default)
2. 🟡 Yellow
3. 🔴 Red
4. 🔵 Blue
5. ⚪ White
6. 🟣 Magenta


## 💿 Installation and getting started

### 1. Install the Arduino Legacy IDE (1.8.19)
Expand Down
35 changes: 21 additions & 14 deletions generate_seed_file.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@ echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
echo ">>> Generating Seed.cpp file"
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"

# Generate a new private key
openssl genrsa -out seed.tmp 4096

# Skip the first and last line of the private key file
TOTAL_LINES=$(wc -l seed.tmp | awk '{print $1}')

# Store the output of the tail and head commands in the SEED variable
SEED=$(tail -n +2 seed.tmp | head -n $((TOTAL_LINES - 2)))
SEEDS=()
for i in {1..6}; do
# Generate a new private key 4096 bits
openssl genrsa -out seed.tmp 4096
# Skip the first and last line of the private key file
TOTAL_LINES=$(wc -l seed.tmp | awk '{print $1}')
# Store the output of the tail and head commands in the SEED variable
SEED=$(tail -n +2 seed.tmp | head -n $((TOTAL_LINES - 2)))
SEEDS+=( "$SEED" )
# Clean up
rm seed.tmp
done

# Create the timestamp
TIMESTAMP=$(date +"%Y%m%d%H%M%S")
Expand All @@ -24,17 +28,20 @@ touch "$FILE_NAME"
# Write the contents of the file
cat > "$FILE_NAME" << EOF
#include "Seed.h"
EOF

const char* seed PROGMEM = R"key(
$SEED
for i in {0..5}; do
cat >> "$FILE_NAME" << EOF
const char* seed$i PROGMEM = R"key(
${SEEDS[$i]}
)key";
EOF
done

# Clean up
rm seed.tmp
cat >> "$FILE_NAME" << EOF
const char* seedArray[] PROGMEM = {seed0, seed1, seed2, seed3, seed4, seed5};
EOF

echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
echo "$SEED"
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
echo ">>> Generated file: $FILE_NAME"
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
Expand Down
2 changes: 1 addition & 1 deletion turtlpass-firmware/Kdf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const uint8_t KDF_SIZE = 75; // 3/4 of 100 characters
// KDF //
/////////

bool processKeyDerivation(uint8_t *output, size_t outputLength, char *input) {
bool processKeyDerivation(uint8_t *output, size_t outputLength, char *input, const char* seed) {
size_t inputLength = strlen(input);
uint8_t *src = (uint8_t *)malloc(inputLength);
memcpy(src, input, inputLength);
Expand Down
3 changes: 1 addition & 2 deletions turtlpass-firmware/Kdf.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
#include <Arduino.h>
#include "SHA512.h"
#include "HKDF.h"
#include "Seed.h"
#include "HexUtil.h"

bool processKeyDerivation(uint8_t *output, size_t outputLength, char *input);
bool processKeyDerivation(uint8_t *output, size_t outputLength, char *input, const char* seed);
void hkdf(const uint8_t *password, size_t passwordLength, const uint8_t *salt, size_t saltLength, uint8_t *key, size_t keyLength);
void hex2Password(const uint8_t *src, size_t srcLength, uint8_t *dst);

Expand Down
1 change: 0 additions & 1 deletion turtlpass-firmware/LedState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ unsigned long lastLedPulseUpdateMillis = MAX_LONG;

LedState::LedState(byte pin) {
this->pin = pin;
init();
}

//////////
Expand Down
111 changes: 111 additions & 0 deletions turtlpass-firmware/RgbLedState.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#include "RgbLedState.h"

// Create the neopixel with the built in definitions NUM_NEOPIXEL and PIN_NEOPIXEL
Adafruit_NeoPixel neoPixel = Adafruit_NeoPixel(NUM_NEOPIXEL, PIN_NEOPIXEL, NEO_GRB + NEO_KHZ800);
Led RgbLedState::led;

/////////////////
// CONSTRUCTOR //
/////////////////

RgbLedState::RgbLedState() {}

//////////
// INIT //
//////////

void RgbLedState::init() {
led.red = 0;
led.green = 255;
led.blue = 0;
led.brightness = 255; // max
led.fadeAmount = 3; // step
led.blinkSpeed = 60; // in ms
led.pulseSpeed = 6; // in ms
led.lastUpdate = 1410065407; // max long
led.state = LED_ON;

neoPixel.begin();
neoPixel.setPixelColor(0, neoPixel.Color(led.red, led.green, led.blue));
neoPixel.setBrightness(led.brightness);
neoPixel.show();
}

//////////////////
// UPDATE STATE //
//////////////////

void RgbLedState::setOn() {
if (led.state != LED_ON) {
led.state = LED_ON;
led.brightness = 255;
}
}

void RgbLedState::setOff() {
if (led.state != LED_OFF) {
led.state = LED_OFF;
led.brightness = 0;
}
}

void RgbLedState::setPulsing() {
if (led.state != LED_PULSING) {
led.brightness = 0;
led.fadeAmount = 3;
led.state = LED_PULSING;
}
}

void RgbLedState::setBlinking() {
if (led.state != LED_BLINKING) {
led.state = LED_BLINKING;
}
}

void RgbLedState::setColor(int colorIndex) {
if (colorIndex < 0 || colorIndex >= NUM_COLORS) {
return;
}
led.red = colors[colorIndex][0];
led.green = colors[colorIndex][1];
led.blue = colors[colorIndex][2];
}


//////////
// LOOP //
//////////

void RgbLedState::loop() {
switch (led.state) {
case LED_OFF: {
led.brightness = 0;
break;
}
case LED_BLINKING: {
if (millis() - led.lastUpdate > led.blinkSpeed) {
led.brightness = (led.brightness == 0) ? 255 : 0;
led.lastUpdate = millis();
}
break;
}
case LED_PULSING: {
if (millis() - led.lastUpdate > led.pulseSpeed) {
led.brightness += led.fadeAmount;
// reverse the direction of the fading at the ends of the fade
if (led.brightness <= 0 || led.brightness >= 255) {
led.fadeAmount = -led.fadeAmount;
}
led.lastUpdate = millis();
}
break;
}
default: { //case LED_ON:
led.brightness = 255;
break;
}
}
neoPixel.setPixelColor(0, neoPixel.Color(led.red * led.brightness / 255, led.green * led.brightness / 255, led.blue * led.brightness / 255));
neoPixel.show();
}
53 changes: 53 additions & 0 deletions turtlpass-firmware/RgbLedState.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#ifndef RGB_LED_STATE_H
#define RGB_LED_STATE_H

#include <Arduino.h>
#include <Adafruit_NeoPixel.h>

enum State {
LED_OFF = 0,
LED_ON = 1,
LED_PULSING = 2,
LED_BLINKING = 3
};

#define NUM_COLORS 6
const uint8_t colors[NUM_COLORS][3] = {
{0, 255, 0}, // green
{255, 255, 0}, // yellow
{255, 0, 0}, // red
{0, 0, 255}, // blue
{255, 255, 255},// white
{255, 0, 255}, // magenta
};

struct Led {
uint8_t red;
uint8_t green;
uint8_t blue;
int brightness;
int fadeAmount;
int blinkState;
int blinkSpeed; // in ms
int pulseSpeed; // in ms
unsigned long lastUpdate;
State state;
};

class RgbLedState {

public:
RgbLedState();
void init();
void setOn();
void setOff();
void setPulsing();
void setBlinking();
void setColor(int colorIndex);
void loop();

private:
static Led led;
};

#endif // RGB_LED_STATE_H
Loading

0 comments on commit 8373c3b

Please sign in to comment.