CCF
Loading...
Searching...
No Matches
src
tls
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
7
namespace
tls
8
{
9
struct
AlpnProtocols
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
36
class
Server
:
public
ccf::tls::Context
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
}
ccf::tls::Context
Definition
context.h:17
ccf::tls::Context::ssl
ccf::crypto::OpenSSL::Unique_SSL ssl
Definition
context.h:20
ccf::tls::Context::Context
Context(bool client)
Definition
context.h:23
ccf::tls::Context::cfg
ccf::crypto::OpenSSL::Unique_SSL_CTX cfg
Definition
context.h:19
tls::Server
Definition
server.h:37
tls::Server::Server
Server(const std::shared_ptr< Cert > &cert_, bool http2=false)
Definition
server.h:42
http2
Definition
http2_callbacks.h:12
tls
Definition
key_exchange.h:18
context.h
tls::AlpnProtocols
Definition
server.h:10
tls::AlpnProtocols::size
unsigned int size
Definition
server.h:12
tls::AlpnProtocols::data
const unsigned char * data
Definition
server.h:11
Generated by
1.9.8