From 8d4813ceb495f9b605934fe25e4818b5fdad4291 Mon Sep 17 00:00:00 2001 From: philippe44 Date: Tue, 25 Jul 2023 22:28:19 -0700 Subject: [PATCH] Bell/cspot catchup - release --- CMakeLists.txt | 1 - .../spotify/cspot/bell/main/audio-dsp/BellDSP.cpp | 4 ---- .../main/audio-dsp/include/CentralAudioBuffer.h | 3 +-- .../spotify/cspot/bell/main/io/BellHTTPServer.cpp | 6 ++++-- .../spotify/cspot/bell/main/io/HTTPClient.cpp | 10 ++++++---- .../spotify/cspot/bell/main/io/X509Bundle.cpp | 13 +++++++++++++ .../cspot/bell/main/io/include/BellHTTPServer.h | 1 + .../cspot/bell/main/io/include/HTTPClient.h | 14 +++++++------- .../cspot/bell/main/io/include/X509Bundle.h | 13 ------------- .../spotify/cspot/bell/main/utilities/Crypto.cpp | 2 ++ .../cspot/bell/main/utilities/include/Crypto.h | 3 --- .../spotify/cspot/protobuf/authentication.proto | 2 -- .../spotify/cspot/protobuf/keyexchange.proto | 2 -- components/spotify/cspot/protobuf/mercury.proto | 2 -- components/spotify/cspot/protobuf/spirc.proto | 2 -- 15 files changed, 34 insertions(+), 44 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cc4177c1..fbb11090 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -70,7 +70,6 @@ set_target_properties(recovery.elf PROPERTIES LINK_LIBRARIES "${BCA};idf::app_re # create files with size for recovery # build_size(recovery) - # build squeezelite, add app_squeezelite to the link add_executable(squeezelite.elf "CMakeLists.txt") add_dependencies(squeezelite.elf recovery.elf) diff --git a/components/spotify/cspot/bell/main/audio-dsp/BellDSP.cpp b/components/spotify/cspot/bell/main/audio-dsp/BellDSP.cpp index d6f04272..96e76483 100644 --- a/components/spotify/cspot/bell/main/audio-dsp/BellDSP.cpp +++ b/components/spotify/cspot/bell/main/audio-dsp/BellDSP.cpp @@ -52,10 +52,6 @@ size_t BellDSP::process(uint8_t* data, size_t bytes, int channels, return 0; } - size_t bytesPerSample = channels * 2; - - size_t samplesLeftInBuffer = buffer->audioBuffer->size() / bytesPerSample; - // Create a StreamInfo object to pass to the pipeline auto streamInfo = std::make_unique(); streamInfo->numChannels = channels; diff --git a/components/spotify/cspot/bell/main/audio-dsp/include/CentralAudioBuffer.h b/components/spotify/cspot/bell/main/audio-dsp/include/CentralAudioBuffer.h index d55f3ed7..bd4f7ab1 100644 --- a/components/spotify/cspot/bell/main/audio-dsp/include/CentralAudioBuffer.h +++ b/components/spotify/cspot/bell/main/audio-dsp/include/CentralAudioBuffer.h @@ -118,8 +118,7 @@ class CentralAudioBuffer { return nullptr; } - auto readBytes = - audioBuffer->read((uint8_t*)&lastReadChunk, sizeof(AudioChunk)); + audioBuffer->read((uint8_t*)&lastReadChunk, sizeof(AudioChunk)); currentSampleRate = static_cast(lastReadChunk.sampleRate); return &lastReadChunk; } diff --git a/components/spotify/cspot/bell/main/io/BellHTTPServer.cpp b/components/spotify/cspot/bell/main/io/BellHTTPServer.cpp index 2b24c82d..b01eb6c4 100644 --- a/components/spotify/cspot/bell/main/io/BellHTTPServer.cpp +++ b/components/spotify/cspot/bell/main/io/BellHTTPServer.cpp @@ -184,8 +184,10 @@ BellHTTPServer::BellHTTPServer(int serverPort) { BELL_LOG(info, "HttpServer", "Server listening on port %d", serverPort); this->serverPort = serverPort; auto port = std::to_string(this->serverPort); - const char* options[] = {"listening_ports", port.c_str(), 0}; - server = std::make_unique(options); + + civetWebOptions.push_back("listening_ports"); + civetWebOptions.push_back(port); + server = std::make_unique(civetWebOptions); } std::unique_ptr BellHTTPServer::makeJsonResponse( diff --git a/components/spotify/cspot/bell/main/io/HTTPClient.cpp b/components/spotify/cspot/bell/main/io/HTTPClient.cpp index 73c28cbc..9c607d6d 100644 --- a/components/spotify/cspot/bell/main/io/HTTPClient.cpp +++ b/components/spotify/cspot/bell/main/io/HTTPClient.cpp @@ -50,10 +50,12 @@ void HTTPClient::Response::rawRequest(const std::string& url, } socketStream << reqEnd; + // Write request body if (content.size() > 0) { - socketStream.write((const char*)content.data(), content.size()); + socketStream.write((const char*)content.data(), content.size()); } + socketStream.flush(); // Parse response @@ -123,9 +125,9 @@ void HTTPClient::Response::get(const std::string& url, Headers headers) { } void HTTPClient::Response::post(const std::string& url, Headers headers, - const std::vector& body) { - std::string method = "POST"; - return this->rawRequest(url, method, body, headers); + const std::vector& body) { + std::string method = "POST"; + return this->rawRequest(url, method, body, headers); } size_t HTTPClient::Response::contentLength() { diff --git a/components/spotify/cspot/bell/main/io/X509Bundle.cpp b/components/spotify/cspot/bell/main/io/X509Bundle.cpp index ffcdd134..351a6317 100644 --- a/components/spotify/cspot/bell/main/io/X509Bundle.cpp +++ b/components/spotify/cspot/bell/main/io/X509Bundle.cpp @@ -12,8 +12,21 @@ using namespace bell::X509Bundle; +typedef struct crt_bundle_t { + const uint8_t** crts; + uint16_t num_certs; + size_t x509_crt_bundle_len; +} crt_bundle_t; + +static std::vector bundleBytes; + +static constexpr auto TAG = "X509Bundle"; +static constexpr auto CRT_HEADER_OFFSET = 4; +static constexpr auto BUNDLE_HEADER_OFFSET = 2; + static mbedtls_x509_crt s_dummy_crt; static bool s_should_verify_certs = false; +static crt_bundle_t s_crt_bundle; #ifndef MBEDTLS_PRIVATE #define MBEDTLS_PRIVATE(member) member diff --git a/components/spotify/cspot/bell/main/io/include/BellHTTPServer.h b/components/spotify/cspot/bell/main/io/include/BellHTTPServer.h index c65a3587..bc7f78bd 100644 --- a/components/spotify/cspot/bell/main/io/include/BellHTTPServer.h +++ b/components/spotify/cspot/bell/main/io/include/BellHTTPServer.h @@ -92,6 +92,7 @@ class BellHTTPServer : public CivetHandler { private: std::unique_ptr server; + std::vector civetWebOptions; int serverPort = 8080; Router getRequestsRouter; diff --git a/components/spotify/cspot/bell/main/io/include/HTTPClient.h b/components/spotify/cspot/bell/main/io/include/HTTPClient.h index 6b86a8fa..8dc6b4b2 100644 --- a/components/spotify/cspot/bell/main/io/include/HTTPClient.h +++ b/components/spotify/cspot/bell/main/io/include/HTTPClient.h @@ -58,7 +58,7 @@ class HTTPClient { const std::vector& content, Headers& headers); void get(const std::string& url, Headers headers = {}); void post(const std::string& url, Headers headers = {}, - const std::vector& body = {}); + const std::vector& body = {}); std::string_view body(); std::vector bytes(); @@ -106,12 +106,12 @@ class HTTPClient { } static std::unique_ptr post(const std::string& url, - Headers headers = {}, - const std::vector& body = {}) { - auto response = std::make_unique(); - response->connect(url); - response->post(url, headers, body); - return response; + Headers headers = {}, + const std::vector& body = {}) { + auto response = std::make_unique(); + response->connect(url); + response->post(url, headers, body); + return response; } }; } // namespace bell diff --git a/components/spotify/cspot/bell/main/io/include/X509Bundle.h b/components/spotify/cspot/bell/main/io/include/X509Bundle.h index 118dbcdc..5148b2c6 100644 --- a/components/spotify/cspot/bell/main/io/include/X509Bundle.h +++ b/components/spotify/cspot/bell/main/io/include/X509Bundle.h @@ -9,19 +9,6 @@ namespace bell::X509Bundle { -typedef struct crt_bundle_t { - const uint8_t** crts; - uint16_t num_certs; - size_t x509_crt_bundle_len; -} crt_bundle_t; - -static crt_bundle_t s_crt_bundle; -static std::vector bundleBytes; - -static constexpr auto TAG = "X509Bundle"; -static constexpr auto CRT_HEADER_OFFSET = 4; -static constexpr auto BUNDLE_HEADER_OFFSET = 2; - int crtCheckCertificate(mbedtls_x509_crt* child, const uint8_t* pub_key_buf, size_t pub_key_len); /* This callback is called for every certificate in the chain. If the chain diff --git a/components/spotify/cspot/bell/main/utilities/Crypto.cpp b/components/spotify/cspot/bell/main/utilities/Crypto.cpp index 28c2d31d..d3126afa 100644 --- a/components/spotify/cspot/bell/main/utilities/Crypto.cpp +++ b/components/spotify/cspot/bell/main/utilities/Crypto.cpp @@ -12,6 +12,8 @@ extern "C" { #include "aes.h" // for AES_ECB_decrypt, AES_init_ctx, AES_ctx } +static unsigned char DHGenerator[1] = {2}; + CryptoMbedTLS::CryptoMbedTLS() {} CryptoMbedTLS::~CryptoMbedTLS() { diff --git a/components/spotify/cspot/bell/main/utilities/include/Crypto.h b/components/spotify/cspot/bell/main/utilities/include/Crypto.h index 503e0cca..1ea17a71 100644 --- a/components/spotify/cspot/bell/main/utilities/include/Crypto.h +++ b/components/spotify/cspot/bell/main/utilities/include/Crypto.h @@ -21,9 +21,6 @@ const static unsigned char DHPrime[] = { 0xf2, 0x5f, 0x14, 0x37, 0x4f, 0xe1, 0x35, 0x6d, 0x6d, 0x51, 0xc2, 0x45, 0xe4, 0x85, 0xb5, 0x76, 0x62, 0x5e, 0x7e, 0xc6, 0xf4, 0x4c, 0x42, 0xe9, 0xa6, 0x3a, 0x36, 0x20, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; - -static unsigned char DHGenerator[1] = {2}; - class CryptoMbedTLS { private: mbedtls_md_context_t sha1Context; diff --git a/components/spotify/cspot/protobuf/authentication.proto b/components/spotify/cspot/protobuf/authentication.proto index 543331a4..d3896147 100644 --- a/components/spotify/cspot/protobuf/authentication.proto +++ b/components/spotify/cspot/protobuf/authentication.proto @@ -1,5 +1,3 @@ -syntax = "proto2"; - enum CpuFamily { CPU_UNKNOWN = 0x0; CPU_X86 = 0x1; diff --git a/components/spotify/cspot/protobuf/keyexchange.proto b/components/spotify/cspot/protobuf/keyexchange.proto index 55cd802a..a816d1ee 100644 --- a/components/spotify/cspot/protobuf/keyexchange.proto +++ b/components/spotify/cspot/protobuf/keyexchange.proto @@ -1,5 +1,3 @@ -syntax = "proto2"; - message LoginCryptoDiffieHellmanChallenge { required bytes gs = 0xa; } diff --git a/components/spotify/cspot/protobuf/mercury.proto b/components/spotify/cspot/protobuf/mercury.proto index 60c752aa..72138948 100644 --- a/components/spotify/cspot/protobuf/mercury.proto +++ b/components/spotify/cspot/protobuf/mercury.proto @@ -1,5 +1,3 @@ -syntax = "proto2"; - message Header { optional string uri = 0x01; optional string method = 0x03; diff --git a/components/spotify/cspot/protobuf/spirc.proto b/components/spotify/cspot/protobuf/spirc.proto index 3b5448f9..5d54bd26 100644 --- a/components/spotify/cspot/protobuf/spirc.proto +++ b/components/spotify/cspot/protobuf/spirc.proto @@ -1,5 +1,3 @@ -syntax = "proto2"; - enum MessageType { kMessageTypeHello = 0x1; kMessageTypeGoodbye = 0x2;