Skip to content

Commit

Permalink
Merge pull request #248 from eadmaster/interpreter-additions
Browse files Browse the repository at this point in the history
added functions in the js interpreter, hash and encryption commands, ir+rf raw mode
  • Loading branch information
pr3y authored Sep 7, 2024
2 parents 5ebb4c6 + b8cab3e commit 1902fbe
Show file tree
Hide file tree
Showing 23 changed files with 1,452 additions and 280 deletions.
37 changes: 22 additions & 15 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ build_flags =
-Wl,--print-memory-usage
-Wl,--gc-sections
-DGIT_COMMIT_HASH='"Homebrew"'
-DSAFE_STACK_BUFFER_SIZE=4096
; rtl_433_ESP flags https://github.com/NorthernMan54/rtl_433_ESP/blob/main/example/OOK_Receiver/platformio.ini
;-DOOK_MODULATION=true ; False is FSK, True is OOK
;-DRF_CC1101="CC1101"
Expand Down Expand Up @@ -66,7 +67,10 @@ lib_deps =
SmartRC-CC1101-Driver-Lib=https://github.com/bmorcelli/SmartRC-CC1101-Driver-Lib/archive/refs/heads/Bruce.zip
ducktape=https://github.com/bmorcelli/duktape/releases/download/2.7.0-lite/duktape-2.7.0.zip
;https://github.com/eadmaster/rtl_433_ESP

;jackjansen/esp32_idf5_https_server_compat
tobozo/ESP32-PSRamFS
;chegewara/EspTinyUSB

[env:m5stack-cplus2]
platform = https://github.com/bmorcelli/platform-espressif32/releases/download/0.0.4/platform-espressif32.zip
board = m5stick-c
Expand Down Expand Up @@ -425,6 +429,7 @@ build_flags =
-DGROVE_SDA=2
-DGROVE_SCL=1

;Default SPI port
-DSPI_SCK_PIN=40
-DSPI_MOSI_PIN=14
-DSPI_MISO_PIN=39
Expand Down Expand Up @@ -819,6 +824,7 @@ lib_deps =
platform = https://github.com/bmorcelli/platform-espressif32/releases/download/0.0.4/platform-espressif32.zip
board = esp32-s3-devkitc-1
framework = arduino
board_build.arduino.memory_type = qio_opi ; NEEDED FOR 8MB PSRAM (N16R8)
;board_build.partitions = custom_16Mb.csv
;board_upload.flash_size = 16MB
;monitor_speed = 115200
Expand All @@ -832,7 +838,8 @@ build_flags =
-DUSB_as_HID=1
; needed for serial
-DARDUINO_USB_CDC_ON_BOOT=1

-DBOARD_HAS_PSRAM

; grove pins
; defaults from https://github.com/espressif/arduino-esp32/blob/master/variants/esp32s3/pins_arduino.h
-DGROVE_SDA=8 ; default RF TX pin
Expand Down Expand Up @@ -895,27 +902,27 @@ build_flags =

;CC1101 SPI connection pins
; best connection pins for higher speed https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/api-reference/peripherals/spi_master.html#gpio-matrix-and-io-mux
-DUSE_CC1101_VIA_SPI
-DCC1101_GDO0_PIN=9
-DCC1101_SS_PIN=SPI_SS_PIN
-DCC1101_MOSI_PIN=SPI_MOSI_PIN
-DCC1101_SCK_PIN=SPI_SCK_PIN
-DCC1101_MISO_PIN=SPI_MISO_PIN
-DUSE_CC1101_VIA_SPI
-DCC1101_GDO0_PIN=9
-DCC1101_SS_PIN=10
-DCC1101_MOSI_PIN=11
-DCC1101_SCK_PIN=12
-DCC1101_MISO_PIN=13
;-DCC1101_GDO2_PIN=14 ; optional

; connections are the same as CC1101
-DUSE_NRF24_VIA_SPI
-DNRF24_CE_PIN=6
-DNRF24_SS_PIN=7
-DNRF24_MOSI_PIN=SPI_MOSI_PIN
-DNRF24_SCK_PIN=SPI_SCK_PIN
-DNRF24_MISO_PIN=SPI_MISO_PIN
;-DUSE_NRF24_VIA_SPI
;-DNRF24_CE_PIN=6
;-DNRF24_SS_PIN=7 ; chip select
;-DNRF24_MOSI_PIN=11
;-DNRF24_SCK_PIN=12
;-DNRF24_MISO_PIN=13

-DSPI_SCK_PIN=12
-DSPI_MOSI_PIN=11
-DSPI_MISO_PIN=13
-DSPI_SS_PIN=10

lib_deps =
${common.lib_deps}

Expand Down
21 changes: 20 additions & 1 deletion src/core/VectorDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,23 @@ class Stream : public Print {
#define MESSAGE_BUTTON 'B'
#define MESSAGE_ACK 'A'

//These enumerate the text plotting alignment (reference datum point)
#define TL_DATUM 0 // Top left (default)
#define TC_DATUM 1 // Top centre
#define TR_DATUM 2 // Top right
#define ML_DATUM 3 // Middle left
#define CL_DATUM 3 // Centre left, same as above
#define MC_DATUM 4 // Middle centre
#define CC_DATUM 4 // Centre centre, same as above
#define MR_DATUM 5 // Middle right
#define CR_DATUM 5 // Centre right, same as above
#define BL_DATUM 6 // Bottom left
#define BC_DATUM 7 // Bottom centre
#define BR_DATUM 8 // Bottom right
#define L_BASELINE 9 // Left character baseline (Line the 'A' character would sit on)
#define C_BASELINE 10 // Centre character baseline
#define R_BASELINE 11 // Right character baseline

typedef uint32_t FixedPoint32;
#define TO_FP32(f) ((uint32_t)((f)*65536. + 0.5))

Expand Down Expand Up @@ -865,7 +882,9 @@ class VectorDisplayClass : public Print {
textsize = size;
textSize((FixedPoint32)size * 8 * 65536);
}


void setTextDatum(uint8_t d) { } // mockup

void setTextColor(uint16_t f, uint16_t b) {
textBackColor565(b);
textForeColor565(f);
Expand Down
2 changes: 2 additions & 0 deletions src/core/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ extern bool sdcardMounted; // inform if SD Cardis active or not

extern bool wifiConnected; // inform if wifi is active or not

extern String wifiIP;

extern bool BLEConnected; // inform if BLE is active or not

extern bool gpsConnected; // inform if GPS is active or not
Expand Down
2 changes: 1 addition & 1 deletion src/core/menu_items/RFMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

void RFMenu::optionsMenu() {
options = {
{"Scan/copy", [=]() { RCSwitch_Read_Raw(); }},
{"Scan/copy", [=]() { RCSwitch_Read(); }},
{"Custom SubGhz", [=]() { otherRFcodes(); }},
{"Spectrum", [=]() { rf_spectrum(); }}, //@IncursioHack
{"Jammer Itmt", [=]() { rf_jammerIntermittent(); }}, //@IncursioHack
Expand Down
27 changes: 27 additions & 0 deletions src/core/mykeyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,33 @@ bool checkAnyKeyPress() {
}

#ifdef CARDPUTER

bool checkNextPagePress(){
Keyboard.update();
if(Keyboard.isKeyPressed('/')) // right arrow
{
if(wakeUpScreen()){
delay(200);
return false;
}
return true;
}
return false;
}

bool checkPrevPagePress() {
Keyboard.update();
if(Keyboard.isKeyPressed(',')) // left arrow
{
if(wakeUpScreen()){
delay(200);
return false;
}
return true;
}
return false;
}

void checkShortcutPress(){
// shortctus to quickly starts apps
Keyboard.update();
Expand Down
2 changes: 2 additions & 0 deletions src/core/mykeyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ bool checkEscPress();
void checkShortcutPress();
int checkNumberShortcutPress();
char checkLetterShortcutPress();
bool checkNextPagePress();
bool checkPrevPagePress();
#endif

bool checkAnyKeyPress();
Expand Down
58 changes: 26 additions & 32 deletions src/core/passwords.cpp
Original file line number Diff line number Diff line change
@@ -1,38 +1,32 @@
#include "mbedtls/aes.h"
#include "mbedtls/md.h"
#include "mbedtls/pkcs5.h"
#include <Arduino.h>


String aes_decrypt(uint8_t* inputData, size_t fileSize, const String& password_str) {
// generate key, iv, salt
const char *password = password_str.c_str();
unsigned char key[32];
unsigned char iv[16];
unsigned char salt[8] = { /* The salt used by OpenSSL during encryption */ };

mbedtls_md_context_t md_ctx;
mbedtls_md_init(&md_ctx);
mbedtls_md_setup(&md_ctx, mbedtls_md_info_from_type(MBEDTLS_MD_SHA256), 1);

// Derive key and IV using PBKDF2
mbedtls_pkcs5_pbkdf2_hmac(&md_ctx, (unsigned char*)password, strlen(password), salt, 8, 10000, 32, key);
mbedtls_pkcs5_pbkdf2_hmac(&md_ctx, (unsigned char*)password, strlen(password), salt, 8, 10000, 16, iv);
#include <Arduino.h>
#include <MD5Builder.h>


String xorEncryptDecrypt(const String &input, const String &password) {
uint8_t md5Hash[16];

MD5Builder md5;
md5.begin();
md5.add(password);
md5.calculate();
md5.getBytes(md5Hash); // Store MD5 hash in the output array

String output = input; // Copy input to output for modification
for (size_t i = 0; i < input.length(); i++) {
output[i] = input[i] ^ md5Hash[i % 16]; // XOR each byte with the MD5 hash
}

return output;
}

mbedtls_md_free(&md_ctx);

unsigned char *outputData = new unsigned char[fileSize];
mbedtls_aes_context aes;
mbedtls_aes_init(&aes);
mbedtls_aes_setkey_dec(&aes, key, 256);

mbedtls_aes_crypt_cbc(&aes, MBEDTLS_AES_DECRYPT, fileSize, iv, inputData, outputData);

mbedtls_aes_free(&aes);

// Convert the decrypted data to a string
String decryptedText = String(outputData, fileSize);
free(outputData);
String encryptString(String& plaintext, const String& password_str) {
// TODO: add "XOR" header
return xorEncryptDecrypt(plaintext, password_str);
}

return decryptedText;
String decryptString(String& cypertext, const String& password_str) {
return xorEncryptDecrypt(cypertext, password_str);
}
6 changes: 5 additions & 1 deletion src/core/passwords.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@

String aes_decrypt(uint8_t* inputData, size_t fileSize, const String& password_str);
#include <Arduino.h>

String encryptString(String& plaintext, const String& password_str);

String decryptString(String& cypertext, const String& password_str);
Loading

0 comments on commit 1902fbe

Please sign in to comment.