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 = (AlpnProtocols*)arg;
24
25 if (
26 SSL_select_next_proto(
27 (unsigned char**)out, outlen, protos->data, protos->size, in, inlen) !=
28 OPENSSL_NPN_NEGOTIATED)
29 {
30 return SSL_TLSEXT_ERR_NOACK;
31 }
32
33 return SSL_TLSEXT_ERR_OK;
34 }
35
37 {
38 private:
39 std::shared_ptr<Cert> cert;
40
41 public:
42 Server(const std::shared_ptr<Cert>& cert_, bool http2 = false) :
43 Context(false),
44 cert(cert_)
45 {
46 cert->use(ssl, cfg);
47
48 // Configure protocols negotiated by ALPN
49 // See https://nghttp2.org/documentation/tutorial-server.html and use of
50 // nghttp2_select_next_protocol for better example
51 if (http2)
52 {
53 static unsigned char alpn_protos_data[] = {2, 'h', '2'};
54 static AlpnProtocols alpn_protos{
55 alpn_protos_data, sizeof(alpn_protos_data)};
56 SSL_CTX_set_alpn_select_cb(cfg, alpn_select_cb, &alpn_protos);
57 }
58 else
59 {
60 static unsigned char alpn_protos_data[] = {
61 8, 'h', 't', 't', 'p', '/', '1', '.', '1'};
62 static AlpnProtocols alpn_protos{
63 alpn_protos_data, sizeof(alpn_protos_data)};
64 SSL_CTX_set_alpn_select_cb(cfg, alpn_select_cb, &alpn_protos);
65 }
66 }
67 };
68}
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:37
Server(const std::shared_ptr< Cert > &cert_, bool http2=false)
Definition server.h:42
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