ksgi

Форк
0
/
test-digest-auth-int.c 
165 строк · 4.3 Кб
1
/*	$Id$ */
2
/*
3
 * Copyright (c) 2018 Charles Collicutt <charles@collicutt.co.uk>
4
 *
5
 * Permission to use, copy, modify, and distribute this software for any
6
 * purpose with or without fee is hereby granted, provided that the above
7
 * copyright notice and this permission notice appear in all copies.
8
 *
9
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16
 */
17
#include "../config.h"
18

19
#include <stdarg.h>
20
#include <stdint.h>
21
#include <stdlib.h>
22
#include <string.h>
23
#include <unistd.h>
24

25
#include <curl/curl.h>
26

27
#include "../kcgi.h"
28
#include "regress.h"
29

30
static int
31
parent3(CURL *curl)
32
{
33
	struct curl_slist *list = NULL;
34
	const char *body = "PLAIN TEXT";
35
	int c;
36

37
	curl_easy_setopt(curl, CURLOPT_URL,
38
		"http://localhost:17123/plain.txt");
39
	curl_easy_setopt(curl, CURLOPT_POST, 1);
40
	curl_easy_setopt(curl, CURLOPT_POSTFIELDS, body);
41
	list = curl_slist_append(list,
42
		"Authorization: Digest username=\"admin\","
43
		"realm=\"AuthInt Example\","
44
		"nonce=\"367sj3265s5\","
45
		"uri=\"/plain.txt\","
46
		"qop=auth-int,"
47
		"nc=ffffffff,"
48
		"cnonce=\"hxk1lu63b6c7vhk\","
49
		"response=\"bc9ef2fa9891939c3fbb0a5892410c75\","
50
		"opaque=\"87aaxcval4gba36\"");
51
	list = curl_slist_append(list,
52
		"Content-Type: application/octet-stream");
53
	curl_easy_setopt(curl, CURLOPT_HTTPHEADER, list);
54
	c = curl_easy_perform(curl);
55
	curl_slist_free_all(list);
56
	return(CURLE_OK == c);
57
}
58

59
static int
60
parent2(CURL *curl)
61
{
62
	struct curl_slist *list = NULL;
63
	const char *body = "PLAIN TEXT";
64
	int c;
65

66
	curl_easy_setopt(curl, CURLOPT_URL,
67
		"http://localhost:17123/plain.txt");
68
	curl_easy_setopt(curl, CURLOPT_POST, 1);
69
	curl_easy_setopt(curl, CURLOPT_POSTFIELDS, body);
70
	list = curl_slist_append(list,
71
		"Authorization: Digest username=\"admin\","
72
		"realm=\"AuthInt Example\","
73
		"nonce=\"367sj3265s5\","
74
		"uri=\"/plain.txt\","
75
		"qop=auth-int,"
76
		"nc=000001ff,"
77
		"cnonce=\"hxk1lu63b6c7vhk\","
78
		"response=\"517a8a2617faed1847835f3ec271ca38\","
79
		"opaque=\"87aaxcval4gba36\"");
80
	list = curl_slist_append(list,
81
		"Content-Type: application/octet-stream");
82
	curl_easy_setopt(curl, CURLOPT_HTTPHEADER, list);
83
	c = curl_easy_perform(curl);
84
	curl_slist_free_all(list);
85
	return(CURLE_OK == c);
86
}
87

88
static int
89
parent1(CURL *curl)
90
{
91
	struct curl_slist *list = NULL;
92
	const char *body = "PLAIN TEXT";
93
	int c;
94

95
	curl_easy_setopt(curl, CURLOPT_URL,
96
		"http://localhost:17123/plain.txt");
97
	curl_easy_setopt(curl, CURLOPT_POST, 1);
98
	curl_easy_setopt(curl, CURLOPT_POSTFIELDS, body);
99
	list = curl_slist_append(list,
100
		"Authorization: Digest username=\"admin\","
101
		"realm=\"AuthInt Example\","
102
		"nonce=\"367sj3265s5\","
103
		"uri=\"/plain.txt\","
104
		"qop=auth-int,"
105
		"nc=00000001,"
106
		"cnonce=\"hxk1lu63b6c7vhk\","
107
		"response=\"5ab6822b9d906cc711760a7783b28dca\","
108
		"opaque=\"87aaxcval4gba36\"");
109
	list = curl_slist_append(list,
110
		"Content-Type: application/octet-stream");
111
	curl_easy_setopt(curl, CURLOPT_HTTPHEADER, list);
112
	c = curl_easy_perform(curl);
113
	curl_slist_free_all(list);
114
	return(CURLE_OK == c);
115
}
116

117
static int
118
child(void)
119
{
120
	struct kreq	 r;
121
	const char 	*page = "index";
122
	int		 rc;
123

124
	rc = 0;
125
	if (khttp_fcgi_test())
126
		return(0);
127
	if (KCGI_OK != khttp_parse(&r, NULL, 0, &page, 1, 0))
128
		return(0);
129
	if (KAUTH_DIGEST != r.rawauth.type)
130
		goto out;
131
	else if (0 == r.rawauth.authorised)
132
		goto out;
133
	else if (strcmp(r.rawauth.d.digest.user, "admin"))
134
		goto out;
135
	else if (strcmp(r.rawauth.d.digest.realm, "AuthInt Example"))
136
		goto out;
137
	else if (strcmp(r.rawauth.d.digest.uri, "/plain.txt"))
138
		goto out;
139
	else if (khttpdigest_validate(&r, "12435") <= 0)
140
		goto out;
141

142
	khttp_head(&r, kresps[KRESP_STATUS],
143
		"%s", khttps[KHTTP_200]);
144
	khttp_head(&r, kresps[KRESP_CONTENT_TYPE],
145
		"%s", kmimetypes[KMIME_TEXT_HTML]);
146
	khttp_body(&r);
147
	rc = 1;
148
out:
149
	khttp_free(&r);
150
	return(rc);
151
}
152

153
int
154
main(int argc, char *argv[])
155
{
156

157
	if ( ! regress_cgi(parent1, child))
158
		return EXIT_FAILURE;
159
	if ( ! regress_cgi(parent2, child))
160
		return EXIT_FAILURE;
161
	if ( ! regress_cgi(parent3, child))
162
		return EXIT_FAILURE;
163

164
	return EXIT_SUCCESS;
165
}
166

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.