ksgi

Форк
0
/
test-digest-auth-int-bad.c 
134 строки · 3.5 Кб
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
parent0(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=00000000,"
48
		"cnonce=\"hxk1lu63b6c7vhk\","
49
		"response=\"5ab6822b9d906cc711760a7783b28dca\","
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
parent1(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=00000001,"
77
		"cnonce=\"hxk1lu63b6c7vhk\","
78
		"response=\"f00f00f00f00f00f00760a7783b28dca\","
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
child(void)
90
{
91
	struct kreq	 r;
92
	const char 	*page = "index";
93
	int		 rc;
94

95
	rc = 0;
96
	if (khttp_fcgi_test())
97
		return(0);
98
	if (KCGI_OK != khttp_parse(&r, NULL, 0, &page, 1, 0))
99
		return(0);
100
	if (KAUTH_DIGEST != r.rawauth.type)
101
		goto out;
102
	else if (0 == r.rawauth.authorised)
103
		goto out;
104
	else if (strcmp(r.rawauth.d.digest.user, "admin"))
105
		goto out;
106
	else if (strcmp(r.rawauth.d.digest.realm, "AuthInt Example"))
107
		goto out;
108
	else if (strcmp(r.rawauth.d.digest.uri, "/plain.txt"))
109
		goto out;
110
	else if (khttpdigest_validate(&r, "12435") <= 0)
111
		goto out;
112

113
	khttp_head(&r, kresps[KRESP_STATUS],
114
		"%s", khttps[KHTTP_200]);
115
	khttp_head(&r, kresps[KRESP_CONTENT_TYPE],
116
		"%s", kmimetypes[KMIME_TEXT_HTML]);
117
	khttp_body(&r);
118
	rc = 1;
119
out:
120
	khttp_free(&r);
121
	return(rc);
122
}
123

124
int
125
main(int argc, char *argv[])
126
{
127

128
	if (regress_cgi(parent0, child))
129
		return EXIT_FAILURE;
130
	if (regress_cgi(parent1, child))
131
		return EXIT_FAILURE;
132

133
	return EXIT_SUCCESS;
134
}
135

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

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

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

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