OpenVPN 3 Core Library
Loading...
Searching...
No Matches
is_openvpn_protocol.hpp
Go to the documentation of this file.
1// OpenVPN -- An application to securely tunnel IP networks
2// over a single port, with support for SSL/TLS-based
3// session authentication and key exchange,
4// packet encryption, packet authentication, and
5// packet compression.
6//
7// Copyright (C) 2012- OpenVPN Inc.
8//
9// SPDX-License-Identifier: MPL-2.0 OR AGPL-3.0-only WITH openvpn3-openssl-exception
10//
11//
12
13#ifndef OPENVPN_SSL_IS_OPENVPN_PROTOCOL_H
14#define OPENVPN_SSL_IS_OPENVPN_PROTOCOL_H
15
16#include <cstddef> // for std::size_t
17
18namespace openvpn {
19
30inline bool is_openvpn_protocol(const unsigned char *p, std::size_t len)
31{
32 static constexpr int P_CONTROL_HARD_RESET_CLIENT_V2 = 7;
33 static constexpr int P_CONTROL_HARD_RESET_CLIENT_V3 = 10;
34 static constexpr int P_OPCODE_SHIFT = 3;
35
36 if (len >= 3)
37 {
38 int plen = (p[0] << 8) | p[1];
39
40 if (p[2] == (P_CONTROL_HARD_RESET_CLIENT_V3 << P_OPCODE_SHIFT))
41 {
42 /* WKc is at least 290 byte (not including metadata):
43 *
44 * 16 bit len + 256 bit HMAC + 2048 bit Kc = 2320 bit
45 *
46 * This is increased by the normal length of client handshake +
47 * tls-crypt overhead (32)
48 *
49 * For metadata tls-crypt-v2.txt does not explicitly specify
50 * an upper limit but we also have TLS_CRYPT_V2_MAX_WKC_LEN
51 * as 1024 bytes. We err on the safe side with 255 extra overhead
52 *
53 * We don't do the 2 byte check for tls-crypt-v2 because it is very
54 * unrealistic to have only 2 bytes available.
55 */
56 return (plen >= 336 && plen < (1024 + 255));
57 }
58
59 /* For non tls-crypt2 we assume the packet length to valid between
60 * 14 and 255 */
61 return plen >= 14 && plen <= 255
62 && (p[2] == (P_CONTROL_HARD_RESET_CLIENT_V2 << P_OPCODE_SHIFT));
63 }
64
65 if (len >= 2)
66 {
67 int plen = (p[0] << 8) | p[1];
68 return plen >= 14 && plen <= 255;
69 }
70
71 return true;
72}
73
74} // namespace openvpn
75#endif
Support deferred server-side state creation when client connects.
Definition ovpncli.cpp:95
bool is_openvpn_protocol(const unsigned char *p, std::size_t len)
Given either the first 2 or 3 bytes of an initial client -> server data payload, return true if the p...