Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 43 additions & 15 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: TianShanOS Build
name: TianshanOS Build

on:
push:
Expand Down Expand Up @@ -38,6 +38,7 @@ jobs:
node-version: '22'
- run: python3 -m unittest discover -s tests/ci -p 'test_*.py'
- run: python3 tests/release/test_release.py
- run: python3 tests/release/test_security_profile.py
- run: python3 tests/release/test_serial_upgrade.py
- name: Select checks and release eligibility
id: scope
Expand All @@ -58,17 +59,26 @@ jobs:
- run: npm ci --prefix tests/prompts
- run: npm test --prefix tests/prompts
- run: python3 tests/release/test_web_minify.py
- name: Fetch matching ESP-IDF sources for browser Origin regression
run: |
export IDF_PATH="$RUNNER_TEMP/web-idf"
echo "IDF_PATH=$IDF_PATH" >> "$GITHUB_ENV"
git clone --depth 1 --branch "$IDF_VERSION" --filter=blob:none --sparse https://github.com/espressif/esp-idf.git "$IDF_PATH"
git -C "$IDF_PATH" sparse-checkout set components/esp_http_server
- name: Install Chrome for actual-page regressions
working-directory: tests/prompts
run: npx playwright install --with-deps chrome
- run: npm run test:browser --prefix tests/prompts
env:
TS_TEST_WEB_TLS: '1'
NODE_PATH: ${{ github.workspace }}/tests/prompts/node_modules
- name: Offline xterm and vendor regressions
run: npm run test:xterm --prefix tests/prompts
env:
OFFLINE_RESULTS: ${{ runner.temp }}/xterm-source

runtime-tests:
needs: changes
needs: [changes, build]
if: needs.changes.outputs.run_full == 'true'
name: Runtime and fan regression tests
runs-on: ubuntu-latest
Expand All @@ -85,11 +95,16 @@ jobs:
export IDF_PATH="$RUNNER_TEMP/runtime-idf"
echo "IDF_PATH=$IDF_PATH" >> "$GITHUB_ENV"
git clone --depth 1 --branch "$IDF_VERSION" --filter=blob:none --sparse https://github.com/espressif/esp-idf.git "$IDF_PATH"
git -C "$IDF_PATH" sparse-checkout set components/json components/mbedtls components/nvs_flash components/console components/soc components/bootloader_support components/esp_app_format components/esp_http_server components/lwip components/esp_netif
git -C "$IDF_PATH" sparse-checkout set components/json components/mbedtls components/nvs_flash components/console components/soc components/bootloader_support components/esp_app_format components/esp_http_server components/esp_https_server components/http_parser components/esp_http_client components/esp_system components/esp-tls components/tcp_transport components/spiffs components/vfs components/lwip components/esp_netif
git -C "$IDF_PATH" submodule update --init --recursive --depth 1 components/json/cJSON components/mbedtls/mbedtls
- uses: actions/setup-node@v4
with:
node-version: '22'
- name: Fetch the managed WebSocket source from this exact build
uses: actions/download-artifact@v4
with:
name: runtime-dependencies-${{ github.sha }}
path: managed_components/espressif__esp_websocket_client
- run: bash tests/runtime/run_all.sh
- run: bash tests/ws_subscriptions/run_operation_adapter.sh
- name: Current WebSocket and lifecycle regressions
Expand Down Expand Up @@ -185,6 +200,15 @@ jobs:
rm -f build/CMakeCache.txt
idf.py build

- name: Preserve the exact managed source used by runtime fixtures
uses: actions/upload-artifact@v4
with:
name: runtime-dependencies-${{ github.sha }}
path: managed_components/espressif__esp_websocket_client/
include-hidden-files: true
if-no-files-found: error
retention-days: 7

- name: Get version info
id: version
run: |
Expand Down Expand Up @@ -216,6 +240,9 @@ jobs:
if-no-files-found: error
retention-days: 7

- name: Bind security build policy to this firmware
run: python3 tools/check_release.py --seal-build build

- name: Package USB / serial partition upgrade
run: python3 tools/serial_upgrade.py package --build-dir build --output "build/tianshanos-serial-v$(cat version.txt)"

Expand All @@ -229,6 +256,8 @@ jobs:
build/partition_table/partition-table.bin
build/flasher_args.json
build/tianshanos-serial-*.zip
build/security-build.json
build/security-artifact.json
retention-days: 30

- name: Upload full build (for debugging)
Expand Down Expand Up @@ -313,26 +342,25 @@ jobs:
GH_TOKEN: ${{ github.token }}
BUILD_VERSION: ${{ needs.build.outputs.version }}
BUILD_COMMIT: ${{ needs.build.outputs.commit }}
- name: Add build identity to the Chinese release notes
- name: Normalize public firmware filename
run: |
python3 - <<'PYTHON'
import os
import json
from pathlib import Path
notes = Path('docs/releases') / (os.environ['RELEASE_TAG'] + '.md')
with notes.open('a') as output:
output.write('\n\n## 本次构建\n\n')
output.write('固件版本:`' + os.environ['BUILD_VERSION'] + '`\n\n')
output.write('源码提交:`' + os.environ['BUILD_COMMIT'] + '`\n')
root = Path('firmware')
(root / 'TianShanOS.bin').rename(root / 'TianshanOS.bin')
args = root / 'flasher_args.json'
data = json.loads(args.read_text())
data['app']['file'] = 'TianshanOS.bin'
data['flash_files'] = {address: 'TianshanOS.bin' if name == 'TianShanOS.bin' else name for address, name in data['flash_files'].items()}
args.write_text(json.dumps(data, indent=2) + '\n')
PYTHON
env:
RELEASE_TAG: ${{ steps.preflight.outputs.tag }}
BUILD_VERSION: ${{ needs.build.outputs.version }}
BUILD_COMMIT: ${{ needs.build.outputs.commit }}

- name: Create or upload the release assets
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.preflight.outputs.tag }}
name: ${{ steps.preflight.outputs.tag }}
name: TianshanOS ${{ steps.preflight.outputs.tag }}
files: |
firmware/**/*.bin
firmware/**/flasher_args.json
Expand Down
17 changes: 13 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ cmake_minimum_required(VERSION 3.16)

# ============================================================================
# 版本管理 - 使用 Python 脚本生成版本号
# 格式: MAJOR.MINOR.PATCH+HASH.TIMESTAMP
# 例如: 0.3.1+7fdcca4d.01311234
# 格式: MAJOR.MINOR.PATCH+SOURCE_ID(不包含日期/时间)
# 例如: 0.6.5+7fdcca4d
#
# 配置阶段会生成版本号,每次 fullClean 或手动 reconfigure 会更新时间戳
# ============================================================================
Expand Down Expand Up @@ -69,7 +69,7 @@ if(ROOT_PASSWORD_RESET)
set(TIANSHAN_VERSION_BUILD "")
endif()
if(NOT ROOT_PASSWORD_RESET_RUN_ID)
string(TIMESTAMP ROOT_PASSWORD_RESET_RUN_ID "%H%M%S")
string(SHA256 ROOT_PASSWORD_RESET_RUN_ID "${TIANSHAN_VERSION_DISPLAY}")
endif()
string(REGEX REPLACE "[^a-zA-Z0-9.]" "." ROOT_PASSWORD_RESET_RUN_ID "${ROOT_PASSWORD_RESET_RUN_ID}")
string(SUBSTRING "${ROOT_PASSWORD_RESET_RUN_ID}" 0 13 ROOT_PASSWORD_RESET_RUN_ID)
Expand Down Expand Up @@ -114,10 +114,19 @@ if(ROOT_PASSWORD_RESET)
endif()

# 项目定义
project(TianShanOS VERSION ${TIANSHAN_VERSION_MAJOR}.${TIANSHAN_VERSION_MINOR}.${TIANSHAN_VERSION_PATCH})
# Disabling application authorization is an explicit, separately named build.
option(TS_DEVELOPMENT_BUILD "Build development-only firmware (never release)" OFF)
if(TS_DEVELOPMENT_BUILD)
project(TianShanOS_Dev VERSION ${TIANSHAN_VERSION_MAJOR}.${TIANSHAN_VERSION_MINOR}.${TIANSHAN_VERSION_PATCH})
else()
project(TianShanOS VERSION ${TIANSHAN_VERSION_MAJOR}.${TIANSHAN_VERSION_MINOR}.${TIANSHAN_VERSION_PATCH})
endif()
include(cmake/security_profile.cmake)

if(NOT ROOT_PASSWORD_RESET)
include(cmake/json_limits.cmake)
include(cmake/httpd_admission.cmake)
include(cmake/http_transport_polling.cmake)
include(cmake/dhcps_bindings.cmake)
endif()

Expand Down
80 changes: 80 additions & 0 deletions cmake/http_transport_polling.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Nonblocking HTTP/TLS uses SDK async connection support with zero-timeout polls.
# Keep the SDK checkout immutable and fail on an unreviewed polling implementation.
idf_component_get_property(transport_lib tcp_transport COMPONENT_LIB)
idf_component_get_property(transport_dir tcp_transport COMPONENT_DIR)
idf_component_get_property(websocket_lib espressif__esp_websocket_client COMPONENT_LIB)
idf_component_get_property(websocket_dir espressif__esp_websocket_client COMPONENT_DIR)
set(polling_dir "${CMAKE_BINARY_DIR}/http_transport_polling")
set(polling_tool "${CMAKE_SOURCE_DIR}/tools/prepare_http_transport_polling.py")
execute_process(
COMMAND "${Python3_EXECUTABLE}" "${polling_tool}" --idf-dir "$ENV{IDF_PATH}" --output "${polling_dir}" --websocket-source "${websocket_dir}/esp_websocket_client.c"
RESULT_VARIABLE polling_result
ERROR_VARIABLE polling_error
)
if(NOT polling_result EQUAL 0)
message(FATAL_ERROR "HTTP nonblocking transport unavailable: ${polling_error}")
endif()
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS
"${polling_tool}" "${transport_dir}/transport_ssl.c"
"${transport_dir}/transport_ws.c" "${websocket_dir}/esp_websocket_client.c")
get_target_property(transport_sources ${transport_lib} SOURCES)
set(updated_sources "")
set(found_transport "")
foreach(source IN LISTS transport_sources)
get_filename_component(source_name "${source}" NAME)
if(source_name STREQUAL "transport_ssl.c" OR source_name STREQUAL "transport_ws.c")
list(APPEND updated_sources "${polling_dir}/${source_name}")
list(APPEND found_transport "${source_name}")
else()
list(APPEND updated_sources "${source}")
endif()
endforeach()
list(SORT found_transport)
if(NOT found_transport STREQUAL "transport_ssl.c;transport_ws.c")
message(FATAL_ERROR "Cannot replace SDK transport sources; SDK sources changed")
endif()
set_property(TARGET ${transport_lib} PROPERTY SOURCES ${updated_sources})
target_include_directories(${transport_lib} PRIVATE "${transport_dir}")
# Bound complete HTTP response headers; binary bodies use each owner's own cap.
idf_component_get_property(parser_lib http_parser COMPONENT_LIB)
target_compile_definitions(${parser_lib} PRIVATE HTTP_MAX_HEADER_SIZE=16384)

# Feed confirmed FIN to the existing HTTP parser. This preserves valid EOF
# framing while the same parser continues rejecting short CL/chunked bodies.
idf_component_get_property(client_lib esp_http_client COMPONENT_LIB)
idf_component_get_property(client_dir esp_http_client COMPONENT_DIR)
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${client_dir}/esp_http_client.c")
get_target_property(client_sources ${client_lib} SOURCES)
set(updated_sources "")
set(found FALSE)
foreach(source IN LISTS client_sources)
if(source STREQUAL "${client_dir}/esp_http_client.c" OR source STREQUAL "esp_http_client.c")
list(APPEND updated_sources "${polling_dir}/esp_http_client.c")
set(found TRUE)
else()
list(APPEND updated_sources "${source}")
endif()
endforeach()
if(NOT found)
message(FATAL_ERROR "Cannot replace SDK esp_http_client.c; SDK sources changed")
endif()
set_property(TARGET ${client_lib} PROPERTY SOURCES ${updated_sources})
target_include_directories(${client_lib} PRIVATE "${client_dir}")

# Managed dependency stays immutable, just like the shared ESP-IDF checkout.
get_target_property(websocket_sources ${websocket_lib} SOURCES)
set(updated_sources "")
set(found FALSE)
foreach(source IN LISTS websocket_sources)
if(source STREQUAL "${websocket_dir}/esp_websocket_client.c" OR source STREQUAL "esp_websocket_client.c")
list(APPEND updated_sources "${polling_dir}/esp_websocket_client.c")
set(found TRUE)
else()
list(APPEND updated_sources "${source}")
endif()
endforeach()
if(NOT found)
message(FATAL_ERROR "Cannot replace managed WebSocket client; dependency sources changed")
endif()
set_property(TARGET ${websocket_lib} PROPERTY SOURCES ${updated_sources})
target_include_directories(${websocket_lib} PRIVATE "${websocket_dir}")
28 changes: 26 additions & 2 deletions cmake/httpd_admission.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@ set(admission_tool "${CMAKE_SOURCE_DIR}/tools/prepare_httpd_admission.py")
execute_process(
COMMAND "${Python3_EXECUTABLE}" "${admission_tool}"
--idf-dir "$ENV{IDF_PATH}" --output "${admission_dir}"
--trusted-origins "${TS_HTTP_TRUSTED_ORIGINS}" --with-https
RESULT_VARIABLE admission_result
ERROR_VARIABLE admission_error
)
if(NOT admission_result EQUAL 0)
message(FATAL_ERROR "HTTPD connection protection unavailable: ${admission_error}")
endif()
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS
"${admission_tool}" "${httpd_dir}/src/httpd_sess.c" "${httpd_dir}/src/httpd_main.c")
"${admission_tool}" "${httpd_dir}/src/httpd_sess.c" "${httpd_dir}/src/httpd_main.c"
"${httpd_dir}/src/httpd_uri.c" "${httpd_dir}/src/httpd_parse.c"
"${httpd_dir}/src/httpd_txrx.c" "${httpd_dir}/src/httpd_ws.c")
get_target_property(httpd_sources ${httpd_lib} SOURCES)
foreach(name httpd_sess.c httpd_main.c)
foreach(name httpd_sess.c httpd_main.c httpd_uri.c httpd_parse.c httpd_txrx.c httpd_ws.c)
set(found FALSE)
set(updated_sources "")
foreach(source IN LISTS httpd_sources)
Expand All @@ -33,3 +36,24 @@ foreach(name httpd_sess.c httpd_main.c)
endforeach()
set_property(TARGET ${httpd_lib} PROPERTY SOURCES ${httpd_sources})
target_include_directories(${httpd_lib} PRIVATE "${httpd_dir}/src")

# The same build-local server policy owns copied TLS startup material.
idf_component_get_property(https_lib esp_https_server COMPONENT_LIB)
idf_component_get_property(https_dir esp_https_server COMPONENT_DIR)
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${https_dir}/src/https_server.c")
get_target_property(https_sources ${https_lib} SOURCES)
set(updated_https_sources "")
set(found_https FALSE)
foreach(source IN LISTS https_sources)
if(source STREQUAL "${https_dir}/src/https_server.c" OR source STREQUAL "src/https_server.c")
list(APPEND updated_https_sources "${admission_dir}/https_server.c")
set(found_https TRUE)
else()
list(APPEND updated_https_sources "${source}")
endif()
endforeach()
if(NOT found_https)
message(FATAL_ERROR "Cannot replace HTTPS startup owner; SDK component sources changed")
endif()
set_property(TARGET ${https_lib} PROPERTY SOURCES ${updated_https_sources})
target_include_directories(${https_lib} PRIVATE "${https_dir}/src")
6 changes: 6 additions & 0 deletions cmake/json_limits.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Bound recursion inside the parser, before callers can inspect a JSON tree.
# Config packs already accept at most 32 nesting levels. Apply that same bound
# to the actual shared SDK cJSON target, including WS/HTTP/PKI consumers.
# The serial-only recovery build has no application JSON ingress.
idf_component_get_property(ts_json_target json COMPONENT_LIB)
target_compile_definitions(${ts_json_target} PUBLIC CJSON_NESTING_LIMIT=32)
25 changes: 25 additions & 0 deletions cmake/security_profile.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Inspect the effective IDF configuration, not sdkconfig.defaults.
if(NOT TS_DEVELOPMENT_BUILD AND NOT ROOT_PASSWORD_RESET AND CONFIG_TS_WEBUI_ENABLE)
if(NOT CONFIG_TS_WEBUI_AUTH_REQUIRED OR NOT CONFIG_TS_SECURITY_ENABLE)
message(FATAL_ERROR "Standard WebUI firmware requires authentication and security. Use explicit TS_DEVELOPMENT_BUILD=ON only for development firmware.")
endif()
endif()
foreach(flag TS_DEVELOPMENT_BUILD ROOT_PASSWORD_RESET CONFIG_TS_WEBUI_ENABLE CONFIG_TS_WEBUI_AUTH_REQUIRED CONFIG_TS_SECURITY_ENABLE )
if(${flag})
set(profile_${flag} true)
else()
set(profile_${flag} false)
endif()
endforeach()
set(profile_json [=[{
"schema": 2,
"development": @profile_TS_DEVELOPMENT_BUILD@,
"recovery": @profile_ROOT_PASSWORD_RESET@,
"webui_enabled": @profile_CONFIG_TS_WEBUI_ENABLE@,
"auth_required": @profile_CONFIG_TS_WEBUI_AUTH_REQUIRED@,
"security_enabled": @profile_CONFIG_TS_SECURITY_ENABLE@,
"webui_tls": false
}
]=])
string(CONFIGURE "${profile_json}" configured_profile @ONLY)
file(WRITE "${CMAKE_BINARY_DIR}/security-build.json" "${configured_profile}")
4 changes: 3 additions & 1 deletion components/ts_api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ set(TS_API_SRCS
"src/ts_api_ota.c"
"src/ts_api_log.c"
"src/ts_api_automation.c"
"src/ts_api_ws_test_transport.c"
"src/ts_api_auto_config.c"
"src/ts_api_cert.c"
"src/ts_api_auth.c"
Expand All @@ -42,5 +43,6 @@ idf_component_register(
INCLUDE_DIRS "include"
EMBED_FILES ${TS_API_EMBED_FILES}
REQUIRES ts_core ts_drivers ts_led ts_net json ts_storage ts_security ts_ota ts_automation ts_cert ts_webui ts_config_pack
PRIV_REQUIRES ts_https ts_hal esp_timer esp_app_format spi_flash bootloader_support esp_wifi app_update esp_https_ota esp_http_client espressif__esp_websocket_client
PRIV_REQUIRES
ts_http_fetch ts_dns tcp_transport mbedtls ts_https ts_hal esp_timer esp_app_format spi_flash bootloader_support esp_wifi app_update esp_https_ota esp_http_client espressif__esp_websocket_client
)
16 changes: 14 additions & 2 deletions components/ts_api/include/ts_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

#include "esp_err.h"
#include "cJSON.h"
#include "ts_api_params.h"
#include "ts_api_policy.h"
#include <stdint.h>
#include <stdbool.h>

Expand Down Expand Up @@ -89,6 +91,9 @@ typedef struct {
*/
typedef esp_err_t (*ts_api_handler_t)(const cJSON *params, ts_api_result_t *result);

/** Optional external dispatch: identity is a verified C value, never a JSON field. */
typedef esp_err_t (*ts_api_session_handler_t)(const cJSON *params, uint32_t caller_session_id, ts_api_result_t *result);

/**
* @brief API endpoint definition
*/
Expand All @@ -97,8 +102,11 @@ typedef struct {
const char *description; /**< API description */
ts_api_category_t category; /**< API category */
ts_api_handler_t handler; /**< Handler function */
bool requires_auth; /**< Requires authentication */
const char *permission; /**< Required permission (optional) */
bool requires_auth; /**< Compatibility metadata; external_access is authoritative. */
const char *permission; /**< Capability metadata/invariants (optional), not role inference. */
ts_api_external_access_t external_access; /**< Explicit role; zero means internal only. */
uint8_t allowed_methods; /**< Nonzero for external roles, zero for internal only. */
ts_api_session_handler_t session_handler; /**< External session-aware path; internal call uses handler. */
} ts_api_endpoint_t;

/*===========================================================================*/
Expand Down Expand Up @@ -157,6 +165,10 @@ void ts_api_parse_query(cJSON *params, char *query);
*/
esp_err_t ts_api_call(const char *name, const cJSON *params, ts_api_result_t *result);

/* Coarse external admission from the live registry. Body-dependent resource
* checks remain in call_for_session after parsing; this lookup never allocates. */
esp_err_t ts_api_get_access(const char *name, ts_api_access_t *access);

/* Browser/session boundary. Trusted internal callers continue to use ts_api_call. */
esp_err_t ts_api_call_for_session(const char *name, const cJSON *params,
uint32_t session_id, ts_api_result_t *result);
Expand Down
Loading
Loading