1
1
#include <stdio.h>
2
2
#include "ngx_http.c"
3
3
4
- static ngx_int_t ngx_http_hello_world (ngx_conf_t * cf );
4
+ static ngx_int_t ngx_http_js_challenge (ngx_conf_t * cf );
5
5
6
6
static char * setup1 (ngx_conf_t * cf , ngx_command_t * cmd , void * conf );
7
7
8
- static ngx_int_t ngx_http_hello_world_handler (ngx_http_request_t * r );
8
+ static ngx_int_t ngx_http_js_challenge_handler (ngx_http_request_t * r );
9
9
10
10
11
- static ngx_command_t ngx_http_hello_world_commands [] = {
11
+ static ngx_command_t ngx_http_js_challenge_commands [] = {
12
12
13
13
{ngx_string ("hello_world" ),
14
14
15
15
// NGX_CONF_TAKE1, for 1 arg etc
16
16
// NGX_CONF_FLAG for boolean
17
17
NGX_HTTP_LOC_CONF | NGX_HTTP_SRV_CONF | NGX_CONF_NOARGS ,
18
18
19
-
20
19
setup1 , /* configuration setup function */
21
20
0 , /* No offset. Only one context is supported. */
22
21
0 , /* No offset when storing the module configuration on struct. */
23
22
NULL },
24
-
25
- ngx_null_command /* command termination */
23
+ ngx_null_command
26
24
};
27
25
28
- /* The hello world string. */
29
- //static u_char ngx_hello_world[] = HELLO_WORLD;
30
-
31
- /* The module context. */
32
- static ngx_http_module_t ngx_http_hello_world_module_ctx = {
26
+ /**
27
+ * Module context
28
+ */
29
+ static ngx_http_module_t ngx_http_js_challenge_module_ctx = {
33
30
NULL , /* preconfiguration */
34
- ngx_http_hello_world , /* postconfiguration */
31
+ ngx_http_js_challenge , /* postconfiguration */
35
32
36
33
NULL , /* create main configuration */
37
34
NULL , /* init main configuration */
38
35
39
36
NULL , /* create server configuration */
40
37
NULL , /* merge server configuration */
41
38
39
+ //todo
42
40
NULL , /* create location configuration */
43
41
NULL /* merge location configuration */
44
42
};
45
43
46
44
/* Module definition. */
47
- ngx_module_t ngx_http_hello_world_module = {
45
+ ngx_module_t ngx_http_js_challenge_module = {
48
46
NGX_MODULE_V1 ,
49
- & ngx_http_hello_world_module_ctx , /* module context */
50
- ngx_http_hello_world_commands , /* module directives */
47
+ & ngx_http_js_challenge_module_ctx , /* module context */
48
+ ngx_http_js_challenge_commands , /* module directives */
51
49
NGX_HTTP_MODULE , /* module type */
52
50
NULL , /* init master */
53
51
NULL , /* init module */
@@ -60,7 +58,7 @@ ngx_module_t ngx_http_hello_world_module = {
60
58
};
61
59
62
60
__always_inline
63
- void buf2hex (const unsigned char * buf , size_t buflen , char * hex_string ) {
61
+ static void buf2hex (const unsigned char * buf , size_t buflen , char * hex_string ) {
64
62
static const char hexdig [] = "0123456789ABCDEF" ;
65
63
66
64
const unsigned char * p ;
@@ -90,7 +88,7 @@ static const u_char JS_SOLVER[] =
90
88
" document.cookie = 'res=' + c + i + ';';"
91
89
" window.location.reload();"
92
90
" break;"
93
- " }; "
91
+ " }"
94
92
" i++;"
95
93
" }"
96
94
"</script>Hello" ;
@@ -155,6 +153,7 @@ int verify_response(int32_t bucket, ngx_str_t addr, const char *secret, ngx_str_
155
153
* ^ offset 24
156
154
*/
157
155
156
+ //todo also check if the response is too large
158
157
if (response .len <= SHA1_STR_LEN ) {
159
158
return -1 ;
160
159
}
@@ -199,7 +198,7 @@ int get_cookie(ngx_http_request_t *r, ngx_str_t *name, ngx_str_t *value) {
199
198
return -1 ;
200
199
}
201
200
202
- static ngx_int_t ngx_http_hello_world_handler (ngx_http_request_t * r ) {
201
+ static ngx_int_t ngx_http_js_challenge_handler (ngx_http_request_t * r ) {
203
202
204
203
//TODO: If the bucket is less than 5sec away from the next one, accept both current and latest bucket
205
204
@@ -245,11 +244,11 @@ static ngx_int_t ngx_http_hello_world_handler(ngx_http_request_t *r) {
245
244
static char * setup1 (ngx_conf_t * cf , ngx_command_t * cmd , void * conf ) {
246
245
// ngx_http_core_loc_conf_t *clcf; /* pointer to core location configuration */
247
246
// clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);
248
- // clcf->handler = ngx_http_hello_world_handler ;
247
+ // clcf->handler = ngx_http_js_challenge_handler ;
249
248
return NGX_CONF_OK ;
250
249
}
251
250
252
- static ngx_int_t ngx_http_hello_world (ngx_conf_t * cf ) {
251
+ static ngx_int_t ngx_http_js_challenge (ngx_conf_t * cf ) {
253
252
254
253
ngx_http_handler_pt * h ;
255
254
ngx_http_core_main_conf_t * cmcf = ngx_http_conf_get_module_main_conf (cf , ngx_http_core_module );
@@ -260,7 +259,7 @@ static ngx_int_t ngx_http_hello_world(ngx_conf_t *cf) {
260
259
return NGX_ERROR ;
261
260
}
262
261
263
- * h = ngx_http_hello_world_handler ;
262
+ * h = ngx_http_js_challenge_handler ;
264
263
265
264
return NGX_OK ;
266
265
}
0 commit comments