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 =
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
40
class
Server
:
public
ccf::tls::Context
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
}
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:41
tls::Server::Server
Server(const std::shared_ptr< Cert > &cert_, bool http2=false)
Definition
server.h:46
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