Skip to content

Commit

Permalink
v0.1.0
Browse files Browse the repository at this point in the history
Next Version
  • Loading branch information
SciLor authored Aug 4, 2023
2 parents a8bd3de + 0a7cde4 commit 5a1736e
Show file tree
Hide file tree
Showing 1,912 changed files with 37,932 additions and 774,752 deletions.
1 change: 0 additions & 1 deletion .github/workflows/publish_docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,3 @@ jobs:
labels: ${{ steps.teddycloud_meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

16 changes: 16 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
[submodule "cJSON"]
path = cJSON
url = https://github.com/DaveGamble/cJSON.git

[submodule "teddycloud_web"]
path = teddycloud_web
url = https://github.com/toniebox-reverse-engineering/teddycloud_web.git
[submodule "cyclone/common"]
path = cyclone/common
url = https://github.com/Oryx-Embedded/Common
[submodule "cyclone/cyclone_tcp"]
path = cyclone/cyclone_tcp
url = https://github.com/Oryx-Embedded/CycloneTCP.git
[submodule "cyclone/cyclone_ssl"]
path = cyclone/cyclone_ssl
url = https://github.com/Oryx-Embedded/CycloneSSL.git
[submodule "cyclone/cyclone_crypto"]
path = cyclone/cyclone_crypto
url = https://github.com/Oryx-Embedded/CycloneCrypto.git
28 changes: 1 addition & 27 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,7 @@
"C_Cpp.default.configurationProvider": "ms-vscode.makefile-tools",
"files.associations": {
"*.v": "bsv",
"stdio.h": "c",
"string.h": "c",
"pem_export.h": "c",
"types.h": "c",
"tls_cipher_suites.h": "c",
"yarrow.h": "c",
"cloud_request.h": "c",
"debug.h": "c",
"tls_adapter.h": "c",
"errno.h": "c",
"net.h": "c",
"http_server.h": "c",
"http_client.h": "c",
"error.h": "c",
"protobuf-c.h": "c",
"toniebox.pb.rtnl.pb-c.h": "c",
"stdbool.h": "c",
"handler_cloud.h": "c",
"handler_reverse.h": "c",
"settings.h": "c",
"stats.h": "c",
"returncodes.h": "c",
"tcp.h": "c",
"winsock2.h": "c",
"platform_windows.h": "c",
"fs_port.h": "c",
"os_port_config.h": "c"
"*.h": "c"
},
"C_Cpp.autocompleteAddParentheses": true,
"editor.formatOnSave": true,
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ COPY --from=buildenv \

VOLUME [ \
"/teddycloud/data/content", \
"/teddycloud/data/library", \
"/teddycloud/certs", \
"/teddycloud/config", \
]
Expand Down
97 changes: 79 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,42 @@ OBJ_DIR = obj
SRC_DIR = src
CONTRIB_DIR = contrib
INSTALL_DIR = install
PREINSTALL_DIR = install/pre
PREINSTALL_DIR = $(INSTALL_DIR)/pre
WEB_SRC_DIR = teddycloud_web
WEB_BUILD_DIR = build
WEB_DIR = data/www/web
ZIP_DIR = install/zip

EXECUTABLE = $(BIN_DIR)/teddycloud$(EXEC_EXT)
LINK_LO_FILE = $(EXECUTABLE).lo
PLATFORM ?= linux

ifeq ($(OS),Windows_NT)
build_rawDateTime:="${shell date /t} ${shell time /t}"
else
build_rawDateTime:="${shell date "+%Y-%m-%d %H:%M:%S %z"}"
endif

build_gitDirty:=${shell git diff --quiet && echo '0' || echo '1'}
build_gitDateTime:="${shell git log -1 --format=%ai}"
build_gitShortSha:=${shell git rev-parse --short HEAD}
build_gitSha:=${shell git rev-parse HEAD}
build_gitTag:=${shell git name-rev --tags --name-only $(build_gitSha)}

CFLAGS_VERSION:=-DBUILD_GIT_IS_DIRTY=${build_gitDirty} -DBUILD_GIT_DATETIME=\"${build_gitDateTime}\" -DBUILD_RAW_DATETIME=\"${build_rawDateTime}\" -DBUILD_GIT_SHORT_SHA=\"${build_gitShortSha}\" -DBUILD_GIT_SHA=\"${build_gitSha}\" -DBUILD_GIT_TAG=\"${build_gitTag}\"

build_gitTagPrefix:=$(firstword $(subst _, ,$(build_gitTag)))
ifeq ($(build_gitTagPrefix),tc)
build_version:=$(subst ${build_gitTagPrefix}_,,${build_gitTag})
CFLAGS_VERSION+=-DBUILD_VERSION=\"${build_version}\"
endif

ifeq ($(OS),Windows_NT)
SHELL = cmd.exe
ECHO = echo
MKDIR = mkdir
RM = del
RM_R = rd /S /Q
CP = copy
CP_R = xcopy /E /I
TO_TRASH = >NUL 2>NUL
Expand All @@ -27,6 +50,7 @@ else
MKDIR = mkdir -p
ECHO = echo -e
RM = rm -f
RM_R = rm -rf
CP = cp
CP_R = cp -r
TO_TRASH = >/dev/null 2>&1
Expand Down Expand Up @@ -73,19 +97,21 @@ HEADERS_linux =
INCLUDES_linux =
SOURCES_linux = \
src/platform/platform_$(PLATFORM).c \
cyclone/common/os_port_posix.c \
src/cyclone/common/os_port_posix.c \
cyclone/common/fs_port_posix.c
LFLAGS_linux =
CFLAGS_linux += -Wall -Werror
CFLAGS_linux += -ggdb -O3
#CFLAGS += -fsanitize=address -static-libasan -Og
CFLAGS_linux += -ggdb

# for now enable extensive error checking
CFLAGS_linux += -fsanitize=undefined -fsanitize=address -Og
LFLAGS_linux += -fsanitize=undefined -fsanitize=address -static-libasan

## win32 specific headers/sources
HEADERS_windows =
INCLUDES_windows =
SOURCES_windows = \
src/platform/platform_$(PLATFORM).c\
cyclone/common/os_port_windows.c \
src/cyclone/common/os_port_windows.c \
src/cyclone/common/fs_port_windows.c
LFLAGS_windows = /DEBUG:FULL
CFLAGS_windows = /DEBUG:FULL /Zi /nologo -DWIN32 /D_UNICODE
Expand All @@ -103,20 +129,25 @@ INCLUDES = \
-Icyclone/cyclone_tcp \
-Icyclone/cyclone_crypto \
-Icyclone/cyclone_crypto/pkix \
-IcJSON
-IcJSON \
-Ifat/source

SOURCES = \
$(wildcard $(SRC_DIR)/*.c) \
$(wildcard $(SRC_DIR)/proto/*.c) \
$(CYCLONE_SOURCES) \
cJSON/cJSON.c \
cJSON/cJSON_Utils.c
cJSON/cJSON_Utils.c \
fat/source/ff.c \
fat/source/ffsystem.c \
fat/source/ffunicode.c

HEADERS = \
$(wildcard include/*.h) \
$(CYCLONE_SOURCES:.c=.h) \
cJSON/cJSON.h \
cJSON/cJSON_Utils.h
cJSON/cJSON_Utils.h \
fat/source/ff.h


#
Expand Down Expand Up @@ -190,16 +221,21 @@ CYCLONE_SOURCES = \
cyclone/cyclone_crypto/encoding/oid.c \
cyclone/cyclone_crypto/pkix/pem_import.c \
cyclone/cyclone_crypto/pkix/pem_export.c \
cyclone/cyclone_crypto/pkix/pem_common.c \
cyclone/cyclone_crypto/pkix/pem_decrypt.c \
cyclone/cyclone_crypto/pkix/pkcs8_key_parse.c \
cyclone/cyclone_crypto/pkix/pkcs8_key_format.c \
cyclone/cyclone_crypto/pkix/x509_key_format.c \
cyclone/cyclone_crypto/pkix/x509_key_parse.c \
cyclone/cyclone_crypto/pkix/x509_cert_parse.c \
cyclone/cyclone_crypto/pkix/x509_cert_ext_parse.c \
cyclone/cyclone_crypto/pkix/x509_cert_validate.c \
cyclone/cyclone_crypto/pkix/x509_crl_parse.c \
cyclone/cyclone_crypto/pkix/x509_crl_validate.c \
cyclone/cyclone_crypto/pkix/x509_crl_ext_parse.c \
cyclone/cyclone_crypto/pkix/x509_common.c \
cyclone/cyclone_crypto/pkix/x509_signature.c \
cyclone/cyclone_crypto/pkix/x509_sign_verify.c \
cyclone/cyclone_crypto/pkix/x509_sign_parse.c \
cyclone/cyclone_crypto/kdf/hkdf.c \
cyclone/cyclone_crypto/rng/yarrow.c

Expand All @@ -208,16 +244,19 @@ CYCLONE_SOURCES := $(filter-out \
cyclone/common/debug.c \
cyclone/cyclone_tcp/http/http_server.c \
cyclone/cyclone_tcp/http/http_server_misc.c \
cyclone/cyclone_ssl/tls_certificate.c \
, $(CYCLONE_SOURCES))

# and add modified ones
CYCLONE_SOURCES += \
src/cyclone/common/debug.c \
src/cyclone/cyclone_tcp/http/http_server.c \
src/cyclone/cyclone_tcp/http/http_server_misc.c
src/cyclone/cyclone_tcp/http/http_server_misc.c \
src/cyclone/cyclone_ssl/tls_certificate.c

CFLAGS += -D GPL_LICENSE_TERMS_ACCEPTED
CFLAGS += -D TRACE_NOPATH_FILE
CFLAGS += ${CFLAGS_VERSION}
CFLAGS += $(INCLUDES)

THIS_MAKEFILE := $(lastword $(MAKEFILE_LIST))
Expand All @@ -236,7 +275,7 @@ PROTO_H_FILES := $(patsubst $(PROTO_DIR)/%.proto, $(PROTO_GEN_DIR)/$(PROTO_DIR)/
# Rule to build .c files from .proto files
$(PROTO_GEN_DIR)/$(PROTO_DIR)/%.pb-c.c $(PROTO_GEN_DIR)/$(PROTO_DIR)/%.pb-c.h: $(PROTO_DIR)/%.proto
$(QUIET)$(ECHO) '[${GREEN}PROTO${NC} ] ${CYAN}$<${NC}'
$(QUIET)protoc-c --c_out=$(PROTO_GEN_DIR) $< || ($(ECHO) '[ ${YELLOW}LD${NC} ] Failed: ${RED}protoc-c --c_out=$(PROTO_GEN_DIR) $<${NC}'; false)
$(QUIET)protoc-c --c_out=$(PROTO_GEN_DIR) $<

SOURCES += $(PROTO_C_FILES)
HEADERS += $(PROTO_H_FILES)
Expand Down Expand Up @@ -267,7 +306,7 @@ else
endif


all: check_dependencies build
all: check_dependencies submodules web build

build: $(EXECUTABLE)

Expand All @@ -289,6 +328,9 @@ check_dependencies:
@which faketime >/dev/null || ($(ECHO) '${YELLOW}Warning:${NC} faketime not found, required for generating certificates. Install it using:' && \
$(ECHO) ' ${CYAN}Ubuntu/Debian:${NC} sudo apt-get install faketime' && \
$(ECHO) ' ${CYAN}Alpine:${NC} apk add faketime')
@which npm >/dev/null || ($(ECHO) '${YELLOW}Warning:${NC} npm not found, required for building the teddycloud_web. Install it using:' && \
$(ECHO) ' ${CYAN}Ubuntu/Debian:${NC} sudo apt-get install npm' && \
$(ECHO) ' ${CYAN}Alpine:${NC} apk add npm')
endif

.PRECIOUS: %/
Expand All @@ -300,19 +342,19 @@ endif
$(LINK_LO_FILE): $$(dir $$@)
$(file >$@, $(OBJECTS) $(OBJ_ONLY_FILES) )

workdirs: certs/server/ certs/client/ config/ data/www/ data/content/
workdirs: certs/server/ certs/client/ config/ data/www/ data/content/ data/library/ data/www/web/
$(QUIET)$(ECHO) '[ ${YELLOW}DIRS${NC} ] ${CYAN}$@${NC}'
$(QUIET)$(CP_R) $(subst /,$(SEP),$(CONTRIB_DIR)/data/www/*) $(subst /,$(SEP),data/www/)

.SECONDEXPANSION:
$(EXECUTABLE): $(LINK_LO_FILE) $(OBJECTS) $(HEADERS) $(THIS_MAKEFILE) workdirs | $$(dir $$@)
$(QUIET)$(ECHO) '[ ${YELLOW}LINK${NC} ] ${CYAN}$@${NC}'
$(QUIET)$(LD) $(LFLAGS) $(LINK_LO_OPT) $(LINK_OUT_OPT) || ($(ECHO) '[ ${GREEN}CC${NC} ] Failed: ${RED}$(LD) $(LFLAGS) $(LINK_LO_OPT) $(LINK_OUT_OPT)${NC}'; false)
$(QUIET)$(LD) $(LFLAGS) $(LINK_LO_OPT) $(LINK_OUT_OPT)

.SECONDEXPANSION:
$(OBJ_DIR)/%$(OBJ_EXT): %.c $(HEADERS) $(THIS_MAKEFILE) | $$(dir $$@)
$(QUIET)$(ECHO) '[ ${GREEN}CC${NC} ] ${CYAN}$<${NC}'
$(QUIET)$(CC) $(CFLAGS) $(CC_IN_OPT) $< $(CC_OUT_OPT)$@ || ($(ECHO) '[ ${GREEN}CC${NC} ] Failed: ${RED}$(CC) $(CFLAGS) $(CC_IN_OPT) $< $(CC_OUT_OPT)$@${NC}'; false)
$(QUIET)$(CC) $(CFLAGS) $(CC_IN_OPT) $< $(CC_OUT_OPT)$@

clean:
$(QUIET)$(ECHO) '[${GREEN}CLEAN${NC} ] Deleting output files...'
Expand All @@ -324,16 +366,35 @@ submodules:
$(QUIET)git submodule init
$(QUIET)git submodule update

preinstall: clean build $(INSTALL_DIR)/ $(PREINSTALL_DIR)/
preinstall: clean build web_copy $(INSTALL_DIR)/ $(PREINSTALL_DIR)/
$(QUIET)$(ECHO) '[ ${GREEN}PRE${NC} ] Preinstall'
$(QUIET)$(CP) $(BIN_DIR)/* $(PREINSTALL_DIR)/
$(QUIET)$(CP_R) $(subst /,$(SEP),$(CONTRIB_DIR)/*) $(subst /,$(SEP),$(PREINSTALL_DIR)/)
$(QUIET)cd $(PREINSTALL_DIR)/ \
&& find . -name ".gitkeep" -type f -delete \
&& cd -

web_clean:
$(QUIET)$(ECHO) '[ ${GREEN}WEB${NC} ] Clean TeddyCloud React Webinterface'
$(RM_R) $(CONTRIB_DIR)/$(WEB_DIR)

web: web_clean
$(QUIET)$(ECHO) '[ ${GREEN}WEB${NC} ] Build TeddyCloud React Webinterface'
$(QUIET) $(MKDIR) $(CONTRIB_DIR)/$(WEB_DIR)/
$(QUIET)cd $(WEB_SRC_DIR) \
&& npm install \
&& npm run build \
&& $(CP_R) $(WEB_BUILD_DIR)/* ../$(CONTRIB_DIR)/$(WEB_DIR)/ \
&& cd -

web_copy:
$(QUIET)$(ECHO) '[ ${GREEN}WEB${NC} ] Copy TeddyCloud React Webinterface'
$(QUIET) $(MKDIR) $(PREINSTALL_DIR)/$(WEB_DIR)/
$(QUIET) $(CP_R) $(CONTRIB_DIR)/$(WEB_DIR)/* $(PREINSTALL_DIR)/$(WEB_DIR)/

zip: preinstall
mkdir $(ZIP_DIR)/
$(QUIET)$(ECHO) '[ ${GREEN}ZIP${NC} ] Create release zip'
$(QUIET) $(MKDIR) $(ZIP_DIR)/
cd $(PREINSTALL_DIR)/ \
&& zip -r ../../$(ZIP_DIR)/release.zip * \
&& cd -
Expand Down
31 changes: 26 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ Currently implemented are:
* Configure LED
* Configure slapping
* Customize original box sounds (ex. jingle) over the air
* Extract/Inject certitifcates on a esp32 firmware dump

## Planned
* Decode RTNL logs
* MQTT client
* Home Assistant integration (ideas welcome)
* TeddyBench integration
* Web frontend (full stack developers welcome)
* [Web frontend](https://github.com/toniebox-reverse-engineering/teddycloud_web) (full stack developers welcome)

## Preparation
### Generate certificates
Expand All @@ -31,7 +32,7 @@ This also generates the replacement CA for the toniebox ```certs/server/ca.der``
If you are using docker, this will happen automatically.

### Dump certificates of your toniebox
You'll need the ```flash:/cert/ca.der``` (Boxine CA), ```flash:/cert/client.der``` (Client Cert) and ```flash:/cert/private.der``` (Client private key). Place those files under ```/certs/*```
You'll need the ```flash:/cert/ca.der``` (Boxine CA), ```flash:/cert/client.der``` (Client Cert) and ```flash:/cert/private.der``` (Client private key). Place those files under ```/certs/client/*```
#### CC3200
You can use the [cc3200tool](https://github.com/toniebox-reverse-engineering/cc3200tool) to dump your certificates over the Tag Connect debug port of the box. If you have installed the HackieboxNG Bootloader you should already have those files in your backup.
```
Expand All @@ -41,20 +42,40 @@ python cc.py -p COM3 read_file /cert/ca.der cert/ca.der read_file /cert/private.
You'll have to manually extract it from the flash of the box with a SOP8 clamp directly from the memory or by desoldering it. Reading in-circuit can be tricky, but is possible.

#### ESP32
You can extract the flash memory either with a SOP8 clamp or via the debug port of the box.
You can extract the flash memory via the debug port of the box and the esptool. Keep your backup!
Please connect the jumper J100 (Boot) and reset the box to put it into the required mode. Connect your 3.3V UART to J103 (TxD, RxD, GND).

```
esptool.py -b 921600 read_flash 0x0 0x800000 tb.esp32.bin
mkdir certs/client/esp32
bin/teddycloud ESP32CERT extract tb.esp32.bin certs/client/esp32
mkdir certs/client/esp32-fakeca
cp certs/client/esp32/CLIENT.DER certs/client/esp32-fakeca/
cp certs/client/esp32/PRIVATE.DER certs/client/esp32-fakeca/
cp certs/server/ca.der certs/client/esp32-fakeca/CA.DER
```

### Flash the replacement CA
#### CC3200
It is recommended to flash the replacement CA to /cert/c2.der and use the hackiebox-ng bootloader with the altCA patch. This will allow you to switch between the original and your replacement certificate. If you have installed the HackieboxNG Bootloader and the Hackiebox CFW you may upload the certificate via the webinterface of the CFW.
```
python cc.py -p COM3 write_file certs/server/ca.der /cert/c2.der
```
**Beware** The ```blockCheckRemove.310``` patch is breaks the content passthrough to Boxine. Please disable it, if your are using it.
**Beware** The ```blockCheckRemove.310``` and the ```noHide.308``` patch breaks the content passthrough to Boxine. If you are using firmware 3.1.0_BF4 isn't compatible with many patches, except the alt* ones. Please disable them.

#### CC3235 / ESP32
#### CC3235
Replace the original CA within your flash dump with the replacement CA and reflash it to your box.
(no manual or tool available yet)

#### ESP32
Replace the original CA within your flash dump with esptool.

```
cp tb.esp32.bin tb.esp32.fakeca.bin
bin/teddycloud ESP32CERT inject tb.esp32.fakeca.bin certs/client/esp32-fakeca
esptool.py -b 921600 write_flash 0x0 tb.esp32.fakeca.bin
```

### DNS
#### CC3200 with altUrl patch
With a CC3200 box it is recommened to use the altUrl patch. Set the DNS entries for ```prod.revvox``` and ```rtnl.revvox``` to the TeddyCloud servers ip-address.
Expand Down
Empty file added contrib/data/library/.gitkeep
Empty file.
Loading

0 comments on commit 5a1736e

Please sign in to comment.