-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypedefs.hpp
244 lines (233 loc) · 9.94 KB
/
typedefs.hpp
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
#pragma once
constexpr size_t MAX_HEADER_LEN = 4096;
constexpr size_t default_req_buffer_sz_minus1 = 4*4096-1;
constexpr size_t filestreaming__block_sz = 1024 * 1024 * 10;
constexpr size_t filestreaming__stream_block_sz = 1024 * 1024;
constexpr size_t filestreaming__max_response_header_sz = 4321; // TODO: Establish actual value - this is an (over)estimate
static_assert(filestreaming__block_sz >= filestreaming__stream_block_sz, "filestreaming__block_sz must be >= filestreaming__stream_block_sz");
constexpr size_t server_buf_sz = (HASH1_max_file_and_header_sz > (filestreaming__block_sz+filestreaming__max_response_header_sz)) ? HASH1_max_file_and_header_sz : (filestreaming__block_sz+filestreaming__max_response_header_sz);
class HTTPResponseHandler;
class NonHTTPRequestHandler;
constexpr size_t n_extra_data_longs = 0;
constexpr time_t timer_interval = 10;
constexpr unsigned timeout_in_timer_intervals = 360;
typedef compsky::server::Server<MAX_HEADER_LEN, default_req_buffer_sz_minus1, HTTPResponseHandler, NonHTTPRequestHandler, n_extra_data_longs, timer_interval, timeout_in_timer_intervals> Server;
#define SECURITY_HEADERS_EXCLUDING_CSP \
"Referrer-Policy: no-referrer\r\n" /* HEADER__SECURITY__NO_REFERRER */ \
"Strict-Transport-Security: max-age=31536000\r\n" /* preload list is centralised (hstspreload.org) for all major browsers, so avoid "; preload" */ \
"X-Content-Type-Options: nosniff\r\n" /* HEADER__SECURITY__NOSNIFF */ \
"X-Frame-Options: SAMEORIGIN\r\n" /* or DENY HEADER__SECURITY__NO_FOREIGN_IFRAME */ \
"X-Permitted-Cross-Domain-Policies: none\r\n" /* Controls whether Flash and Adobe Acrobat are allowed to load content from a different domain. */ \
"X-XSS-Protection: 1; mode=block\r\n" /* HEADER__SECURITY__XSS */ \
/* "Feature-Policy: geolocation 'none'; camera 'none'; microphone 'none'\r\n" // HEADER__SECURITY__FEATURE_POLICY */ \
/* TODO: "Expect-CT: max-age=86400, enforce\r\n" (expect a valid Signed Certificate Timestamp (SCT) for each certificate in the certificate chain, forcing any SSL certificate forgery to leave a 'paper trail' of logs AFAIK) */ \
/* NOTE: HPKP header has been deprecated, but it looked good */
namespace _r {
constexpr static const std::string_view not_found =
HEADER__RETURN_CODE__NOT_FOUND
"Content-Length: 9\r\n"
"Content-Security-Policy: default-src 'none'\r\n" // HEADER__SECURITY__CSP__NONE
"Content-Type: text/plain\r\n"
SECURITY_HEADERS_EXCLUDING_CSP
"\r\n"
"Not Found"
;
constexpr static const std::string_view server_error =
HEADER__RETURN_CODE__SERVER_ERR
"Connection: keep-alive\r\n"
"Content-Length: 12\r\n"
"Content-Security-Policy: default-src 'none'\r\n" // HEADER__SECURITY__CSP__NONE
"Content-Type: text/plain\r\n"
SECURITY_HEADERS_EXCLUDING_CSP
"\r\n"
"Server error"
;
constexpr static const std::string_view wrong_hostname =
HEADER__RETURN_CODE__NOT_AUTHORISED
"Content-Length: 10\r\n"
"Content-Security-Policy: default-src 'none'\r\n" // HEADER__SECURITY__CSP__NONE
"Content-Type: text/plain\r\n"
SECURITY_HEADERS_EXCLUDING_CSP
"\r\n"
"Wrong host"
;
constexpr static const std::string_view suspected_robot =
HEADER__RETURN_CODE__NOT_AUTHORISED
"Content-Length: 15\r\n"
"Content-Security-Policy: default-src 'none'\r\n" // HEADER__SECURITY__CSP__NONE
"Content-Type: text/plain\r\n"
SECURITY_HEADERS_EXCLUDING_CSP
"\r\n"
"Suspected robot"
;
constexpr static const std::string_view user_login_url_already_used =
HEADER__RETURN_CODE__OK
"Content-Length: 288\r\n"
"Content-Security-Policy: default-src 'none'; style-src 'sha256-wrWloy50fEZAc/HT+n6+g5BH2EMxYik8NzH3gR6Ge3Y='\r\n" // HEADER__SECURITY__CSP__NONE
"Content-Type: text/html; charset=UTF-8\r\n" \
SECURITY_HEADERS_EXCLUDING_CSP
"\r\n"
"<!DOCTYPE html>"
"<html>"
"<head>"
"<style integrity=\"sha256-wrWloy50fEZAc/HT+n6+g5BH2EMxYik8NzH3gR6Ge3Y=\">"
"body{color:white;background:black;}"
"</style>"
"</head>"
"<body>"
"<h1>This user login was already used or has expired</h1>"
"<p>Please request a new link by contacting the website owner</p>"
"</body>"
"</html>"
;
constexpr static const std::string_view not_logged_in__dont_set_fuck_header =
HEADER__RETURN_CODE__OK
"Content-Length: 364\r\n"
"Content-Security-Policy: default-src 'none'; style-src 'sha256-wrWloy50fEZAc/HT+n6+g5BH2EMxYik8NzH3gR6Ge3Y='\r\n" // HEADER__SECURITY__CSP__NONE
"Content-Type: text/html; charset=UTF-8\r\n" \
SECURITY_HEADERS_EXCLUDING_CSP
"\r\n"
"<!DOCTYPE html>"
"<html>"
"<head>"
"<style integrity=\"sha256-wrWloy50fEZAc/HT+n6+g5BH2EMxYik8NzH3gR6Ge3Y=\">"
"body{color:white;background:black;}"
"</style>"
"</head>"
"<body>"
"<h1>Not logged in</h1>"
"<p>Please request a login link by contacting the website owner</p>"
"<p>You also look like a robot, so maybe use a different browser or device, because you might be blocked.</p>"
"</body>"
"</html>"
;
constexpr static const std::string_view cant_register_user_due_to_lack_of_fuck_cookie =
HEADER__RETURN_CODE__OK
"Content-Length: 936\r\n"
"Content-Security-Policy: default-src 'none'; style-src 'sha256-wrWloy50fEZAc/HT+n6+g5BH2EMxYik8NzH3gR6Ge3Y='; img-src 'i.imgur.com'\r\n" // HEADER__SECURITY__CSP__NONE
"Content-Type: text/html; charset=UTF-8\r\n" \
SECURITY_HEADERS_EXCLUDING_CSP
"\r\n"
"<!DOCTYPE html>"
"<html>"
"<head>"
"<style integrity=\"sha256-wrWloy50fEZAc/HT+n6+g5BH2EMxYik8NzH3gR6Ge3Y=\">"
"body{color:white;background:black;}"
"</style>"
"</head>"
"<body>"
"<h1>You are attempting to register on an unrecognised device</h1>"
"<img src=\"https://i.imgur.com/9dlLLM1.gif\"></img>"
"<p>Apologies if you are human, but <a href=\"https://support.google.com/mail/thread/16878288/gmail-is-opening-and-caching-urls-within-emails-without-user-intervention-how-and-why?hl=en\">some email services such as GMail and Hotmail automatically visit any URLs in emails</a> and this would break account registrations without this mitigation.</p>"
"<p>You must use the same device to register an account as the device you requested the account with. You can still have multiple devices, but each would register their own account.</p>"
"<p>I could instead block Google's IP addresses, but then they'd mark my website as 'malicious'! So it has to be this way.</p>"
"</body>"
"</html>"
;
constexpr static const std::string_view wiki_page_not_found =
HEADER__RETURN_CODE__NOT_FOUND
"Connection: keep-alive\r\n"
"Content-Length: 122\r\n"
"Content-Security-Policy: default-src 'none'; style-src 'self'; img-src 'self'\r\n" // HEADER__SECURITY__CSP__NONE
"Content-Type: text/html; charset=UTF-8\r\n"
SECURITY_HEADERS_EXCLUDING_CSP
"\r\n"
"Page not found, probably because the title contains special characters which I haven't bothered to code into my parser yet"
;
constexpr static const std::string_view wiki_page_error =
HEADER__RETURN_CODE__NOT_FOUND
"Connection: keep-alive\r\n"
"Content-Length: 55\r\n"
"Content-Security-Policy: default-src 'none'\r\n"
"Content-Type: text/plain\r\n"
SECURITY_HEADERS_EXCLUDING_CSP
"\r\n"
"Page exists but cannot be displayed due to software bug"
;
constexpr static const std::string_view ratelimited =
HEADER__RETURN_CODE__NOT_AUTHORISED
"Content-Length: 88\r\n"
"Content-Security-Policy: default-src 'none'\r\n" // HEADER__SECURITY__CSP__NONE
"Content-Type: text/plain\r\n"
SECURITY_HEADERS_EXCLUDING_CSP
"\r\n"
"Your user account has issued too many requests, please wait an hour before trying again."
;
#ifdef DISABLE_SERVER_AFTER_HOURS
constexpr static const std::string_view server_out_of_hours_response__pre =
"HTTP/1.1 503 Service Unavailable\r\n"
// "Connection: keep-alive\r\n" // HEADER__CONNECTION_KEEP_ALIVE
"Content-Length: 272\r\n"
"Content-Security-Policy: default-src 'none'; style-src 'sha256-wrWloy50fEZAc/HT+n6+g5BH2EMxYik8NzH3gR6Ge3Y='\r\n" // HEADER__SECURITY__CSP__NONE
"Content-Type: text/html; charset=UTF-8\r\n" \
SECURITY_HEADERS_EXCLUDING_CSP
"\r\n"
"<!DOCTYPE html>"
"<html>"
"<head>"
"<style integrity=\"sha256-wrWloy50fEZAc/HT+n6+g5BH2EMxYik8NzH3gR6Ge3Y=\">"
"body{color:white;background:black;}"
"</style>"
"</head>"
"<body>"
"<h1>Out of hours</h1>"
"<p>Website is sleeping</p>"
"<p>Come back between "
;
constexpr static const std::string_view server_out_of_hours_response__example_of_middle_content = "06:00-24:00 or 00:00-01:00";
constexpr static const std::string_view server_out_of_hours_response__post =
" (GMT)</p>"
"</body>"
"</html>"
;
static
char server_out_of_hours_response__buf[server_out_of_hours_response__pre.size() + server_out_of_hours_response__example_of_middle_content.size() + server_out_of_hours_response__post.size()];
static constexpr std::string_view server_out_of_hours_response(server_out_of_hours_response__buf, server_out_of_hours_response__pre.size() + server_out_of_hours_response__example_of_middle_content.size() + server_out_of_hours_response__post.size());
#else
static constexpr std::string_view server_out_of_hours_response(nullptr,0);
#endif
} // namespace _r
namespace response_enum {
enum {
NOT_FOUND,
SERVER_ERROR,
WRONG_HOSTNAME,
SUSPECTED_ROBOT,
USER_LOGIN_URL_ALREADY_USED,
NOT_LOGGED_IN__DONT_SET_FUCK_HEADER,
CANT_REGISTER_USER_DUE_TO_LACK_OF_FUCK_COOKIE,
WIKI_PAGE_NOT_FOUND,
WIKI_PAGE_ERROR,
SERVER_OUT_OF_HOURS,
RATELIMITED,
SENDING_FROM_CUSTOM_STRVIEW,
N
};
}
constexpr static const std::string_view all_response_names[12] = {
"_r::not_found",
"_r::server_error",
"_r::wrong_hostname",
"_r::suspected_robot",
"_r::user_login_url_already_used",
"_r::not_logged_in__dont_set_fuck_header",
"_r::cant_register_user_due_to_lack_of_fuck_cookie",
"_r::wiki_page_not_found",
"_r::wiki_page_error",
"_r::server_out_of_hours_response",
"_r::ratelimited",
"using_server_buf", // NOTE: Always has to be at end
};
constexpr static const std::string_view all_responses[11] = {
_r::not_found,
_r::server_error,
_r::wrong_hostname,
_r::suspected_robot,
_r::user_login_url_already_used,
_r::not_logged_in__dont_set_fuck_header,
_r::cant_register_user_due_to_lack_of_fuck_cookie,
_r::wiki_page_not_found,
_r::wiki_page_error,
_r::server_out_of_hours_response,
_r::ratelimited,
};