5#ifndef RUNTIME_BIN_SECURE_SOCKET_UTILS_H_
6#define RUNTIME_BIN_SECURE_SOCKET_UTILS_H_
8#include <openssl/bio.h>
9#include <openssl/err.h>
10#include <openssl/pkcs12.h>
11#include <openssl/ssl.h>
12#include <openssl/x509.h>
31 const char* exception_type,
45 uint32_t last_error = ERR_peek_last_error();
46 return (ERR_GET_LIB(last_error) == ERR_LIB_PEM) &&
47 (ERR_GET_REASON(last_error) == PEM_R_NO_START_LINE);
68 uint8_t* bytes =
nullptr;
69 intptr_t bytes_len = 0;
70 bool is_typed_data =
false;
75 object, &typ,
reinterpret_cast<void**
>(&bytes), &bytes_len));
86 bytes_len_ = bytes_len;
87 bio_ = BIO_new_mem_buf(bytes, bytes_len);
89 is_typed_data_ = is_typed_data;
107 uint8_t*
data() {
return bytes_; }
117 DISALLOW_ALLOCATION();
121template <
typename T,
void (*free_func)(T*)>
127 if (obj_ !=
nullptr) {
133 const T*
get()
const {
return obj_; }
144 DISALLOW_ALLOCATION();
148template <
typename T,
typename E,
void (*func)(E*)>
154 if (obj_ !=
nullptr) {
155 OPENSSL_sk_pop_free_ex(
reinterpret_cast<OPENSSL_STACK*
>(obj_),
156 call_free_func, free_func);
161 const T*
get()
const {
return obj_; }
170 static void free_func(
void* element) { func(
reinterpret_cast<E*
>(element)); }
171 static void call_free_func(
void (*free_func)(
void*),
void* element) {
177 DISALLOW_ALLOCATION();
static Dart_Handle NewDartArgumentError(const char *message)
ScopedMemBIO(Dart_Handle object)
ScopedSSLStackType(T *obj)
static constexpr int SSL_ERROR_MESSAGE_BUFFER_SIZE
static bool IsCurrentTimeInsideCertValidDateRange(X509 *root_cert)
static void ThrowIOException(int status, const char *exception_type, const char *message, const SSL *ssl)
static uint32_t FetchErrorString(const SSL *ssl, TextBuffer *text_buffer)
static bool NoPEMStartLine()
static void CheckStatusSSL(int status, const char *type, const char *message, const SSL *ssl)
static void CheckStatus(int status, const char *type, const char *message)
struct _Dart_Handle * Dart_Handle
const bool SSL_LOG_STATUS
static Dart_Handle ThrowIfError(Dart_Handle handle)
ScopedSSLType< X509, X509_free > ScopedX509
ScopedSSLType< PKCS12, PKCS12_free > ScopedPKCS12
ScopedSSLStackType< STACK_OF(X509), X509, X509_free > ScopedX509Stack
DART_EXPORT uint8_t * Dart_ScopeAllocate(intptr_t size)
DART_EXPORT Dart_Handle Dart_TypedDataAcquireData(Dart_Handle object, Dart_TypedData_Type *type, void **data, intptr_t *len)
DART_EXPORT Dart_Handle Dart_ListGetAsBytes(Dart_Handle list, intptr_t offset, uint8_t *native_array, intptr_t length)
DART_EXPORT Dart_Handle Dart_TypedDataReleaseData(Dart_Handle object)
DART_EXPORT Dart_Handle Dart_ListLength(Dart_Handle list, intptr_t *len)
DART_EXPORT bool Dart_IsList(Dart_Handle object)
DART_EXPORT Dart_Handle Dart_ThrowException(Dart_Handle exception)
DART_EXPORT bool Dart_IsTypedData(Dart_Handle handle)