summaryrefslogtreecommitdiff
path: root/accel-pppd/ctrl/sstp/sstp_prot.h
blob: e3c4c9c540b2abc9353f738c44473e3c74abd267 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#ifndef SSTP_PROT_H
#define SSTP_PROT_H

#include <stdint.h>

/* Constants */
#define SSTP_PORT			443
#define SSTP_HTTP_METHOD		"SSTP_DUPLEX_POST"
#define SSTP_HTTP_URI			"/sra_{BA195980-CD49-458b-9E23-C84EE0ADCD75}/"
#define SSTP_VERSION			0x10
#define SSTP_MAX_PACKET_SIZE		4095
#define SSTP_NONCE_SIZE			32
#define SSTP_HLAK_SIZE			32
#define SSTP_CMK_SEED			"SSTP inner method derived CMK"
#define SSTP_CMK_SEED_SIZE		29
#define SSTP_NEGOTIOATION_TIMEOUT	60
#define SSTP_HELLO_TIMEOUT		60
#define SSTP_ABORT_TIMEOUT_1		3
#define SSTP_ABORT_TIMEOUT_2		1
#define SSTP_DISCONNECT_TIMEOUT_1	5
#define SSTP_DISCONNECT_TIMEOUT_2	1

/* Packet Type */
enum {
	SSTP_DATA_PACKET = 0x00,
	SSTP_CTRL_PACKET = 0x01,
};

/* Message Type */
enum {
	SSTP_MSG_CALL_CONNECT_REQUEST = 0x0001,
	SSTP_MSG_CALL_CONNECT_ACK = 0x0002,
	SSTP_MSG_CALL_CONNECT_NAK = 0x0003,
	SSTP_MSG_CALL_CONNECTED = 0x0004,
	SSTP_MSG_CALL_ABORT = 0x0005,
	SSTP_MSG_CALL_DISCONNECT = 0x0006,
	SSTP_MSG_CALL_DISCONNECT_ACK = 0x0007,
	SSTP_MSG_ECHO_REQUEST = 0x0008,
	SSTP_MSG_ECHO_RESPONSE = 0x0009,
};

/* Attribute ID */
enum {
	SSTP_ATTRIB_NO_ERROR = 0x00,
	SSTP_ATTRIB_ENCAPSULATED_PROTOCOL_ID = 0x01,
	SSTP_ATTRIB_STATUS_INFO = 0x02,
	SSTP_ATTRIB_CRYPTO_BINDING = 0x03,
	SSTP_ATTRIB_CRYPTO_BINDING_REQ = 0x04,
};

/* Protocol ID */
enum {
	SSTP_ENCAPSULATED_PROTOCOL_PPP = 0x0001,
};

/* Hash Protocol Bitmask */
enum {
	CERT_HASH_PROTOCOL_SHA1 = 0x01,
	CERT_HASH_PROTOCOL_SHA256 = 0x02,
};

/* Status */
enum {
	ATTRIB_STATUS_NO_ERROR = 0x00000000,
	ATTRIB_STATUS_DUPLICATE_ATTRIBUTE = 0x00000001,
	ATTRIB_STATUS_UNRECOGNIZED_ATTRIBUTE = 0x00000002,
	ATTRIB_STATUS_INVALID_ATTRIB_VALUE_LENGTH = 0x00000003,
	ATTRIB_STATUS_VALUE_NOT_SUPPORTED = 0x00000004,
	ATTRIB_STATUS_UNACCEPTED_FRAME_RECEIVED = 0x00000005,
	ATTRIB_STATUS_RETRY_COUNT_EXCEEDED = 0x00000006,
	ATTRIB_STATUS_INVALID_FRAME_RECEIVED = 0x00000007,
	ATTRIB_STATUS_NEGOTIATION_TIMEOUT = 0x00000008,
	ATTRIB_STATUS_ATTRIB_NOT_SUPPORTED_IN_MSG = 0x00000009,
	ATTRIB_STATUS_REQUIRED_ATTRIBUTE_MISSING = 0x0000000a,
	ATTRIB_STATUS_STATUS_INFO_NOT_SUPPORTED_IN_MSG = 0x0000000b,
};

/* State */
enum {
	STATE_SERVER_CALL_DISCONNECTED = 0,
	STATE_SERVER_CONNECT_REQUEST_PENDING,
	STATE_SERVER_CALL_CONNECTED_PENDING,
	STATE_SERVER_CALL_CONNECTED,
	STATE_CALL_ABORT_IN_PROGRESS_1,
	STATE_CALL_ABORT_IN_PROGRESS_2,
	STATE_CALL_ABORT_TIMEOUT_PENDING,
	STATE_CALL_ABORT_PENDING,
	STATE_CALL_DISCONNECT_IN_PROGRESS_1,
	STATE_CALL_DISCONNECT_IN_PROGRESS_2,
	STATE_CALL_DISCONNECT_TIMEOUT_PENDING,
	STATE_CALL_DISCONNECT_ACK_PENDING,
};

/* Packets */
struct sstp_hdr {
	uint8_t version;
	uint8_t reserved;
	uint16_t length;
	uint8_t data[0];
} __attribute__((packed));

struct sstp_ctrl_hdr {
	uint8_t version;
	uint8_t reserved;
	uint16_t length;
	uint16_t message_type;
	uint16_t num_attributes;
	uint8_t data[0];
} __attribute__((packed));

struct sstp_attr_hdr {
	uint8_t reserved;
	uint8_t attribute_id;
	uint16_t length;
	uint8_t data[0];
} __attribute__((packed));

struct sstp_attrib_encapsulated_protocol {
	struct sstp_attr_hdr hdr;
	uint16_t protocol_id;
} __attribute__((packed));

struct sstp_attrib_status_info {
	struct sstp_attr_hdr hdr;
	uint8_t reserved[3];
	uint8_t attrib_id;
	uint32_t status;
	uint8_t attrib_value[0];
} __attribute__((packed));

struct sstp_attrib_crypto_binding {
	struct sstp_attr_hdr hdr;
	uint8_t reserved[3];
	uint8_t hash_protocol_bitmask;
	uint8_t nonce[SSTP_NONCE_SIZE];
	uint8_t cert_hash[32];
	uint8_t compound_mac[32];
} __attribute__((packed));

struct sstp_attrib_crypto_binding_request {
	struct sstp_attr_hdr hdr;
	uint8_t reserved[3];
	uint8_t hash_protocol_bitmask;
	uint8_t nonce[SSTP_NONCE_SIZE];
} __attribute__((packed));

#define SSTP_DATA_HDR(len) {		\
	.version = SSTP_VERSION,	\
	.reserved = SSTP_DATA_PACKET,	\
	.length = htons(len),		\
}

#define SSTP_CTRL_HDR(type, len, num) {	\
	.version = SSTP_VERSION,	\
	.reserved = SSTP_CTRL_PACKET,	\
	.length = htons(len),		\
	.message_type = htons(type),	\
	.num_attributes = htons(num)	\
}

#define SSTP_ATTR_HDR(id, len) {	\
	.attribute_id = id,		\
	.length = htons(len)		\
}

#define INIT_SSTP_DATA_HDR(hdr, len) {		\
	(hdr)->version = SSTP_VERSION;		\
	(hdr)->reserved = SSTP_DATA_PACKET;	\
	(hdr)->length = htons(len);		\
}

#define INIT_SSTP_CTRL_HDR(hdr, type, num, len) {\
	(hdr)->version = SSTP_VERSION;		\
	(hdr)->reserved = SSTP_CTRL_PACKET;	\
	(hdr)->length = htons(len);		\
	(hdr)->message_type = htons(type);	\
	(hdr)->num_attributes = htons(num);	\
}

#define INIT_SSTP_ATTR_HDR(hdr, id, len) {	\
	(hdr)->attribute_id = id;		\
	(hdr)->length = htons(len);		\
}

#endif