CCF
Loading...
Searching...
No Matches
server.h
Go to the documentation of this file.
1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the Apache 2.0 License.
3#pragma once
4
5#include "context.h"
6
7namespace tls
8{
10 {
11 const unsigned char* data;
12 unsigned int size;
13 };
14
15 static int alpn_select_cb(
16 SSL* /*ssl*/,
17 const unsigned char** out,
18 unsigned char* outlen,
19 const unsigned char* in,
20 unsigned int inlen,
21 void* arg)
22 {
23 auto* protos = static_cast<AlpnProtocols*>(arg);
24
25 if (
26 SSL_select_next_proto(
27 const_cast<unsigned char**>(out),
28 outlen,
29 protos->data,
30 protos->size,
31 in,
32 inlen) != OPENSSL_NPN_NEGOTIATED)
33 {
34 return SSL_TLSEXT_ERR_NOACK;
35 }
36
37 return SSL_TLSEXT_ERR_OK;
38 }
39
41 {
42 private:
43 std::shared_ptr<Cert> cert;
44
45 public:
46 Server(const std::shared_ptr<Cert>& cert_, bool http2 = false) :
47 Context(false),
48 cert(cert_)
49 {
50 cert->use(ssl, cfg);
51
52 // Configure protocols negotiated by ALPN
53 // See https://nghttp2.org/documentation/tutorial-server.html and use of
54 // nghttp2_select_next_protocol for better example
55 if (http2)
56 {
57 static unsigned char alpn_protos_data[] = {2, 'h', '2'};
58 static AlpnProtocols alpn_protos{
59 alpn_protos_data, sizeof(alpn_protos_data)};
60 SSL_CTX_set_alpn_select_cb(cfg, alpn_select_cb, &alpn_protos);
61 }
62 else
63 {
64 static unsigned char alpn_protos_data[] = {
65 8, 'h', 't', 't', 'p', '/', '1', '.', '1'};
66 static AlpnProtocols alpn_protos{
67 alpn_protos_data, sizeof(alpn_protos_data)};
68 SSL_CTX_set_alpn_select_cb(cfg, alpn_select_cb, &alpn_protos);
69 }
70 }
71 };
72}
Definition context.h:17
ccf::crypto::OpenSSL::Unique_SSL ssl
Definition context.h:20
Context(bool client)
Definition context.h:23
ccf::crypto::OpenSSL::Unique_SSL_CTX cfg
Definition context.h:19
Definition server.h:41
Server(const std::shared_ptr< Cert > &cert_, bool http2=false)
Definition server.h:46
Definition http2_callbacks.h:12
Definition key_exchange.h:18
Definition server.h:10
unsigned int size
Definition server.h:12
const unsigned char * data
Definition server.h:11