SHT30 온습도 모니터링 시스템 전체 소스(서버 PHP, STM32 펌웨어, SQL, 테스트). 전체 코드리뷰에서 도출된 보안 하드닝 10건 반영: - 요청 서명 HMAC-SHA256 전환(펌웨어 sig.c/서버 config.php/호스트 패리티 동시) - 재전송 방어 + 기본 API_KEY fail-closed + 디바이스 문자열 정제(api/sensor_data.php) - 오프라인 SMS 중복 발송 경합 제거(cron_heartbeat.php, 원자적 선점) - CSV 수식 주입 방지(monthly_report.php), 감사로그 회전 락(retention_cleanup.php) - 브루트포스 카운터 원자화(login.php), 예시 TOTP 비밀키 무효화, 마이그레이션 멱등화 _backup/(하드코딩 실 비밀값 포함)·config.local.php·런타임 상태는 .gitignore 제외.
30 lines
1.4 KiB
C
30 lines
1.4 KiB
C
/* =============================================================================
|
|
* httpapi.h - HTTP/1.1 POST 요청 작성 및 전송 (raw-body 서명 포함)
|
|
*
|
|
* RPi 대응: sht30_monitor.py post_reading()
|
|
* 의 requests.post + 재시도. 서명은 X-Signature 헤더로 전송한다.
|
|
* ===========================================================================*/
|
|
#ifndef HTTPAPI_H
|
|
#define HTTPAPI_H
|
|
|
|
#include <stdint.h>
|
|
#include <stddef.h>
|
|
#include "transport.h"
|
|
|
|
/* POST 요청 문자열을 out 에 작성한다(본문 포함). 반환: 길이 또는 -1(버퍼 부족).
|
|
* sig_hex 는 X-Signature 헤더 값(sig_raw_body 결과). */
|
|
int http_build_post(char *out, size_t cap,
|
|
const char *host, const char *path,
|
|
const char *device_id, const char *sig_hex,
|
|
const char *body);
|
|
|
|
/* 응답 버퍼에서 HTTP 상태 코드를 파싱한다. 반환: 코드(예 200) 또는 -1. */
|
|
int http_parse_status(const uint8_t *resp, size_t len);
|
|
|
|
/* 한 번의 POST 시도: 서명 -> 요청 작성 -> connect/send/recv -> 상태 파싱 -> close.
|
|
* 반환: HTTP 상태 코드(>0) 또는 음수(전송 계층 오류). */
|
|
int api_post_once(transport_t *t, const char *host, uint16_t port,
|
|
const char *path, const char *device_id,
|
|
const char *api_key, const char *body, uint32_t timeout_ms);
|
|
|
|
#endif /* HTTPAPI_H */
|