breadcast/breadcast-caststream-sys/vendor/openscreen/util/crypto/openssl_util.cc
Breadway 8c745d18e0
Some checks failed
dev release / build (push) Failing after 12s
Implement Cast Streaming mirroring, DLNA casting, daemon+GUI, and breadd integration
Builds out the full v1 scope: a vendored+patched openscreen subset for
low-latency Cast Streaming (Mirroring receiver 0F5096E8) alongside the
existing Cast V2/HLS and new DLNA/AVTransport casting paths, breadcastd's
Idle/Casting state machine with a private IPC socket, the breadcast GTK4
popup as a thin IPC client, and bread.cast.*/bread.command.cast.* breadd
integration (device discovery, start/stop, mirroring lifecycle events).
Also adds bakery/systemd/Forgejo CI packaging.

Validated end-to-end against a real Chromecast/Google TV: negotiated
Cast Streaming session, live pipeline playback, and daemon+GUI click-to-cast/
stop through the actual popup.
2026-08-03 09:07:21 +08:00

62 lines
1.9 KiB
C++

// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "util/crypto/openssl_util.h"
#include <openssl/crypto.h>
#include <openssl/err.h>
#include <stddef.h>
#include <stdint.h>
#include <sstream>
#include <string>
#include <string_view>
#include <utility>
#include "util/osp_logging.h"
namespace openscreen {
namespace {
// Callback routine for OpenSSL to print error messages. `str` is a
// nullptr-terminated string of length `len` containing diagnostic information
// such as the library, function and reason for the error, the file and line
// where the error originated, plus potentially any context-specific
// information about the error. `context` contains a pointer to user-supplied
// data, which is currently unused.
// If this callback returns a value <= 0, OpenSSL will stop processing the
// error queue and return, otherwise it will continue calling this function
// until all errors have been removed from the queue.
int OpenSSLErrorCallback(const char* str, size_t len, void* context) {
OSP_DVLOG << "\t" << std::string_view(str, len);
return 1;
}
} // namespace
void EnsureOpenSSLInit() {
// LOCAL PATCH (breadcast): upstream calls OPENSSL_init_ssl() here, but
// this vendored subset never touches libssl (no TLS -- see
// ../../../PATCHES.md), so this just does the general libcrypto init
// instead. Safe to call repeatedly; OpenSSL 3.x makes this optional
// anyway, but frame_crypto.cc's key setup wants it done up front.
OPENSSL_init_crypto(0, nullptr);
}
void ClearOpenSSLERRStack(const Location& location) {
if (OSP_DCHECK_IS_ON()) {
uint32_t error_num = ERR_peek_error();
if (error_num == 0) {
return;
}
OSP_DVLOG << "OpenSSL ERR_get_error stack from " << location;
ERR_print_errors_cb(&OpenSSLErrorCallback, nullptr);
} else {
ERR_clear_error();
}
}
} // namespace openscreen