Skip to content

Commit 8373c3b

Browse files
committed
cycle through the 6 predefined colors that corresponds to a different seed
1 parent 7bc4522 commit 8373c3b

File tree

10 files changed

+483
-31
lines changed

10 files changed

+483
-31
lines changed

README.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ TurtlPass Firmware provides a simple and secure way of generating passwords usin
1616

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

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

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

3333

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

4545

46+
**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:
47+
48+
1. 🟢 Green (default)
49+
2. 🟡 Yellow
50+
3. 🔴 Red
51+
4. 🔵 Blue
52+
5. ⚪ White
53+
6. 🟣 Magenta
54+
55+
4656
## 💿 Installation and getting started
4757

4858
### 1. Install the Arduino Legacy IDE (1.8.19)

generate_seed_file.sh

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,18 @@ echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
55
echo ">>> Generating Seed.cpp file"
66
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
77

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

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

28-
const char* seed PROGMEM = R"key(
29-
$SEED
33+
for i in {0..5}; do
34+
cat >> "$FILE_NAME" << EOF
35+
const char* seed$i PROGMEM = R"key(
36+
${SEEDS[$i]}
3037
)key";
3138
EOF
39+
done
3240

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

36-
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
37-
echo "$SEED"
3845
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
3946
echo ">>> Generated file: $FILE_NAME"
4047
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"

turtlpass-firmware/Kdf.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const uint8_t KDF_SIZE = 75; // 3/4 of 100 characters
66
// KDF //
77
/////////
88

9-
bool processKeyDerivation(uint8_t *output, size_t outputLength, char *input) {
9+
bool processKeyDerivation(uint8_t *output, size_t outputLength, char *input, const char* seed) {
1010
size_t inputLength = strlen(input);
1111
uint8_t *src = (uint8_t *)malloc(inputLength);
1212
memcpy(src, input, inputLength);

turtlpass-firmware/Kdf.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
#include <Arduino.h>
55
#include "SHA512.h"
66
#include "HKDF.h"
7-
#include "Seed.h"
87
#include "HexUtil.h"
98

10-
bool processKeyDerivation(uint8_t *output, size_t outputLength, char *input);
9+
bool processKeyDerivation(uint8_t *output, size_t outputLength, char *input, const char* seed);
1110
void hkdf(const uint8_t *password, size_t passwordLength, const uint8_t *salt, size_t saltLength, uint8_t *key, size_t keyLength);
1211
void hex2Password(const uint8_t *src, size_t srcLength, uint8_t *dst);
1312

turtlpass-firmware/LedState.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ unsigned long lastLedPulseUpdateMillis = MAX_LONG;
2424

2525
LedState::LedState(byte pin) {
2626
this->pin = pin;
27-
init();
2827
}
2928

3029
//////////

turtlpass-firmware/RgbLedState.cpp

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#include "RgbLedState.h"
2+
3+
// Create the neopixel with the built in definitions NUM_NEOPIXEL and PIN_NEOPIXEL
4+
Adafruit_NeoPixel neoPixel = Adafruit_NeoPixel(NUM_NEOPIXEL, PIN_NEOPIXEL, NEO_GRB + NEO_KHZ800);
5+
Led RgbLedState::led;
6+
7+
/////////////////
8+
// CONSTRUCTOR //
9+
/////////////////
10+
11+
RgbLedState::RgbLedState() {}
12+
13+
//////////
14+
// INIT //
15+
//////////
16+
17+
void RgbLedState::init() {
18+
led.red = 0;
19+
led.green = 255;
20+
led.blue = 0;
21+
led.brightness = 255; // max
22+
led.fadeAmount = 3; // step
23+
led.blinkSpeed = 60; // in ms
24+
led.pulseSpeed = 6; // in ms
25+
led.lastUpdate = 1410065407; // max long
26+
led.state = LED_ON;
27+
28+
neoPixel.begin();
29+
neoPixel.setPixelColor(0, neoPixel.Color(led.red, led.green, led.blue));
30+
neoPixel.setBrightness(led.brightness);
31+
neoPixel.show();
32+
}
33+
34+
//////////////////
35+
// UPDATE STATE //
36+
//////////////////
37+
38+
void RgbLedState::setOn() {
39+
if (led.state != LED_ON) {
40+
led.state = LED_ON;
41+
led.brightness = 255;
42+
}
43+
}
44+
45+
void RgbLedState::setOff() {
46+
if (led.state != LED_OFF) {
47+
led.state = LED_OFF;
48+
led.brightness = 0;
49+
}
50+
}
51+
52+
void RgbLedState::setPulsing() {
53+
if (led.state != LED_PULSING) {
54+
led.brightness = 0;
55+
led.fadeAmount = 3;
56+
led.state = LED_PULSING;
57+
}
58+
}
59+
60+
void RgbLedState::setBlinking() {
61+
if (led.state != LED_BLINKING) {
62+
led.state = LED_BLINKING;
63+
}
64+
}
65+
66+
void RgbLedState::setColor(int colorIndex) {
67+
if (colorIndex < 0 || colorIndex >= NUM_COLORS) {
68+
return;
69+
}
70+
led.red = colors[colorIndex][0];
71+
led.green = colors[colorIndex][1];
72+
led.blue = colors[colorIndex][2];
73+
}
74+
75+
76+
//////////
77+
// LOOP //
78+
//////////
79+
80+
void RgbLedState::loop() {
81+
switch (led.state) {
82+
case LED_OFF: {
83+
led.brightness = 0;
84+
break;
85+
}
86+
case LED_BLINKING: {
87+
if (millis() - led.lastUpdate > led.blinkSpeed) {
88+
led.brightness = (led.brightness == 0) ? 255 : 0;
89+
led.lastUpdate = millis();
90+
}
91+
break;
92+
}
93+
case LED_PULSING: {
94+
if (millis() - led.lastUpdate > led.pulseSpeed) {
95+
led.brightness += led.fadeAmount;
96+
// reverse the direction of the fading at the ends of the fade
97+
if (led.brightness <= 0 || led.brightness >= 255) {
98+
led.fadeAmount = -led.fadeAmount;
99+
}
100+
led.lastUpdate = millis();
101+
}
102+
break;
103+
}
104+
default: { //case LED_ON:
105+
led.brightness = 255;
106+
break;
107+
}
108+
}
109+
neoPixel.setPixelColor(0, neoPixel.Color(led.red * led.brightness / 255, led.green * led.brightness / 255, led.blue * led.brightness / 255));
110+
neoPixel.show();
111+
}

turtlpass-firmware/RgbLedState.h

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#ifndef RGB_LED_STATE_H
2+
#define RGB_LED_STATE_H
3+
4+
#include <Arduino.h>
5+
#include <Adafruit_NeoPixel.h>
6+
7+
enum State {
8+
LED_OFF = 0,
9+
LED_ON = 1,
10+
LED_PULSING = 2,
11+
LED_BLINKING = 3
12+
};
13+
14+
#define NUM_COLORS 6
15+
const uint8_t colors[NUM_COLORS][3] = {
16+
{0, 255, 0}, // green
17+
{255, 255, 0}, // yellow
18+
{255, 0, 0}, // red
19+
{0, 0, 255}, // blue
20+
{255, 255, 255},// white
21+
{255, 0, 255}, // magenta
22+
};
23+
24+
struct Led {
25+
uint8_t red;
26+
uint8_t green;
27+
uint8_t blue;
28+
int brightness;
29+
int fadeAmount;
30+
int blinkState;
31+
int blinkSpeed; // in ms
32+
int pulseSpeed; // in ms
33+
unsigned long lastUpdate;
34+
State state;
35+
};
36+
37+
class RgbLedState {
38+
39+
public:
40+
RgbLedState();
41+
void init();
42+
void setOn();
43+
void setOff();
44+
void setPulsing();
45+
void setBlinking();
46+
void setColor(int colorIndex);
47+
void loop();
48+
49+
private:
50+
static Led led;
51+
};
52+
53+
#endif // RGB_LED_STATE_H

0 commit comments

Comments
 (0)