Flutter Engine
The Flutter Engine
security_context.h
Go to the documentation of this file.
1// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
4
5#ifndef RUNTIME_BIN_SECURITY_CONTEXT_H_
6#define RUNTIME_BIN_SECURITY_CONTEXT_H_
7
8#include <openssl/ssl.h>
9#include <openssl/x509.h>
10
11#include "bin/lockers.h"
13#include "bin/socket.h"
14
15namespace dart {
16namespace bin {
17
18// Forward declaration
19class SSLFilter;
20
21typedef void (*TrustEvaluateHandlerFunc)(Dart_Port dest_port_id,
23
24class SSLCertContext : public ReferenceCounted<SSLCertContext> {
25 public:
26 static const intptr_t kApproximateSize;
27 static constexpr int kSecurityContextNativeFieldIndex = 0;
28 static constexpr int kX509NativeFieldIndex = 0;
29
30 explicit SSLCertContext(SSL_CTX* context)
32 context_(context),
33 alpn_protocol_string_(nullptr),
34 trust_builtin_(false),
35 allow_tls_renegotiation_(false) {}
36
38 SSL_CTX_free(context_);
39 free(alpn_protocol_string_);
40 }
41
42 static int CertificateCallback(int preverify_ok, X509_STORE_CTX* store_ctx);
43 static void KeyLogCallback(const SSL* ssl, const char* line);
44
47 intptr_t index);
48 static void SetAlpnProtocolList(Dart_Handle protocols_handle,
49 SSL* ssl,
51 bool is_server);
52
53 static const char* root_certs_file() { return root_certs_file_; }
54 static void set_root_certs_file(const char* root_certs_file) {
55 root_certs_file_ = root_certs_file;
56 }
57 static const char* root_certs_cache() { return root_certs_cache_; }
58 static void set_root_certs_cache(const char* root_certs_cache) {
59 root_certs_cache_ = root_certs_cache;
60 }
61
63 const char* password);
64
65 void SetClientAuthoritiesBytes(Dart_Handle client_authorities_bytes,
66 const char* password);
67
68 int UseCertificateChainBytes(Dart_Handle cert_chain_bytes,
69 const char* password);
70
72
73 SSL_CTX* context() const { return context_; }
74
75 uint8_t* alpn_protocol_string() const { return alpn_protocol_string_; }
76
77 void set_alpn_protocol_string(uint8_t* protocol_string) {
78 if (alpn_protocol_string_ != nullptr) {
79 free(alpn_protocol_string_);
80 }
81 alpn_protocol_string_ = protocol_string;
82 }
83
84 bool trust_builtin() const { return trust_builtin_; }
85
86 void set_allow_tls_renegotiation(bool allow) {
87 allow_tls_renegotiation_ = allow;
88 }
89 bool allow_tls_renegotiation() const { return allow_tls_renegotiation_; }
90
91 void set_trust_builtin(bool trust_builtin) { trust_builtin_ = trust_builtin; }
92
93 void RegisterCallbacks(SSL* ssl);
95
96 static bool long_ssl_cert_evaluation() { return long_ssl_cert_evaluation_; }
98 long_ssl_cert_evaluation_ = long_ssl_cert_evaluation;
99 }
100
102 return bypass_trusting_system_roots_;
103 }
106 bypass_trusting_system_roots_ = bypass_trusting_system_roots;
107 }
108
109 private:
110 void AddCompiledInCerts();
111 void LoadRootCertFile(const char* file);
112 void LoadRootCertCache(const char* cache);
113
114 static const char* root_certs_file_;
115 static const char* root_certs_cache_;
116
117 SSL_CTX* context_;
118 uint8_t* alpn_protocol_string_;
119
120 bool trust_builtin_;
121 bool allow_tls_renegotiation_;
122 static bool long_ssl_cert_evaluation_;
123 static bool bypass_trusting_system_roots_;
124
125 DISALLOW_COPY_AND_ASSIGN(SSLCertContext);
126};
127
128class X509Helper : public AllStatic {
129 public:
137 static Dart_Handle WrappedX509Certificate(X509* certificate);
138};
139
140} // namespace bin
141} // namespace dart
142
143#endif // RUNTIME_BIN_SECURITY_CONTEXT_H_
static void KeyLogCallback(const SSL *ssl, const char *line)
static SSLCertContext * GetSecurityContext(Dart_NativeArguments args)
void RegisterCallbacks(SSL *ssl)
SSL_CTX * context() const
static void set_long_ssl_cert_evaluation(bool long_ssl_cert_evaluation)
static constexpr int kX509NativeFieldIndex
void SetClientAuthoritiesBytes(Dart_Handle client_authorities_bytes, const char *password)
static const char * root_certs_file()
static void set_bypass_trusting_system_roots(bool bypass_trusting_system_roots)
static int CertificateCallback(int preverify_ok, X509_STORE_CTX *store_ctx)
static void set_root_certs_file(const char *root_certs_file)
static const char * GetPasswordArgument(Dart_NativeArguments args, intptr_t index)
static void set_root_certs_cache(const char *root_certs_cache)
uint8_t * alpn_protocol_string() const
bool allow_tls_renegotiation() const
TrustEvaluateHandlerFunc GetTrustEvaluateHandler() const
static const intptr_t kApproximateSize
void set_allow_tls_renegotiation(bool allow)
static const char * root_certs_cache()
static bool long_ssl_cert_evaluation()
void set_trust_builtin(bool trust_builtin)
int UseCertificateChainBytes(Dart_Handle cert_chain_bytes, const char *password)
void set_alpn_protocol_string(uint8_t *protocol_string)
static void SetAlpnProtocolList(Dart_Handle protocols_handle, SSL *ssl, SSLCertContext *context, bool is_server)
void SetTrustedCertificatesBytes(Dart_Handle cert_bytes, const char *password)
SSLCertContext(SSL_CTX *context)
static constexpr int kSecurityContextNativeFieldIndex
static bool bypass_trusting_system_roots()
static Dart_Handle GetSha1(Dart_NativeArguments args)
static Dart_Handle GetDer(Dart_NativeArguments args)
static Dart_Handle GetStartValidity(Dart_NativeArguments args)
static Dart_Handle WrappedX509Certificate(X509 *certificate)
static Dart_Handle GetIssuer(Dart_NativeArguments args)
static Dart_Handle GetPem(Dart_NativeArguments args)
static Dart_Handle GetEndValidity(Dart_NativeArguments args)
static Dart_Handle GetSubject(Dart_NativeArguments args)
int64_t Dart_Port
Definition: dart_api.h:1525
struct _Dart_Handle * Dart_Handle
Definition: dart_api.h:258
struct _Dart_NativeArguments * Dart_NativeArguments
Definition: dart_api.h:3019
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
Win32Message message
void(* TrustEvaluateHandlerFunc)(Dart_Port dest_port_id, Dart_CObject *message)
Definition: dart_vm.cc:33
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace Enable an endless trace buffer The default is a ring buffer This is useful when very old events need to viewed For during application launch Memory usage will continue to grow indefinitely however Start app with an specific route defined on the framework flutter assets Path to the Flutter assets directory enable service port Allow the VM service to fallback to automatic port selection if binding to a specified port fails trace Trace early application lifecycle Automatically switches to an endless trace buffer trace skia Filters out all Skia trace event categories except those that are specified in this comma separated list dump skp on shader Automatically dump the skp that triggers new shader compilations This is useful for writing custom ShaderWarmUp to reduce jank By this is not enabled to reduce the overhead purge persistent cache
Definition: switches.h:191