annotate common/selftest.c @ 1086:93325618ac7b

(issue117) Set verify callback to abort the handshake earlier if the certificate does not match.
author Andre Heinecke <andre.heinecke@intevation.de>
date Fri, 12 Sep 2014 13:09:02 +0200
parents edbf5e5e88f4
children a974b61a5cce
rev   line source
634
80d1a80b3e8d Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
1 #include "selftest.h"
80d1a80b3e8d Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
2 #include "binverify.h"
80d1a80b3e8d Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
3 #include "strhelp.h"
80d1a80b3e8d Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
4 #include "logging.h"
80d1a80b3e8d Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
5
80d1a80b3e8d Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
6 bool
80d1a80b3e8d Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
7 selftest()
80d1a80b3e8d Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
8 {
1081
edbf5e5e88f4 (issue118) Extend verify_binary to carry an open file
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1073
diff changeset
9 bin_verify_result res;
634
80d1a80b3e8d Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
10 #ifdef WIN32
80d1a80b3e8d Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
11 wchar_t wPath[MAX_PATH];
80d1a80b3e8d Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
12 char *utf8path = NULL;
80d1a80b3e8d Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
13
904
f89b41fa7048 Fix whitespace errors
Andre Heinecke <andre.heinecke@intevation.de>
parents: 634
diff changeset
14 if (!GetModuleFileNameW (NULL, wPath, MAX_PATH - 1))
634
80d1a80b3e8d Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
15 {
80d1a80b3e8d Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
16 PRINTLASTERROR ("Failed to obtain module file name. Path too long?");
80d1a80b3e8d Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
17 return false;
80d1a80b3e8d Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
18 }
80d1a80b3e8d Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
19
80d1a80b3e8d Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
20 /* wPath might not be 0 terminated */
80d1a80b3e8d Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
21 wPath[MAX_PATH - 1] = '\0';
80d1a80b3e8d Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
22
80d1a80b3e8d Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
23 utf8path = wchar_to_utf8 (wPath, wcsnlen(wPath, MAX_PATH));
80d1a80b3e8d Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
24
80d1a80b3e8d Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
25 if (utf8path == NULL)
80d1a80b3e8d Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
26 {
80d1a80b3e8d Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
27 ERRORPRINTF ("Failed to convert module path to utf-8");
80d1a80b3e8d Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
28 return false;
80d1a80b3e8d Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
29 }
80d1a80b3e8d Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
30
1081
edbf5e5e88f4 (issue118) Extend verify_binary to carry an open file
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1073
diff changeset
31 res = verify_binary (utf8path, strlen(utf8path));
edbf5e5e88f4 (issue118) Extend verify_binary to carry an open file
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1073
diff changeset
32 if (res.result != VerifyValid)
634
80d1a80b3e8d Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
33 {
80d1a80b3e8d Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
34 ERRORPRINTF ("Verification of the binary failed");
80d1a80b3e8d Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
35 syslog_error_printf ("Integrity check failed.");
80d1a80b3e8d Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
36 xfree(utf8path);
80d1a80b3e8d Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
37 return false;
80d1a80b3e8d Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
38 }
80d1a80b3e8d Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
39
1081
edbf5e5e88f4 (issue118) Extend verify_binary to carry an open file
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1073
diff changeset
40 fclose(res.fptr);
634
80d1a80b3e8d Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
41 xfree(utf8path);
1073
fa3f4e2370d3 Fix selftest it was broken during the move out of verify_binary
Andre Heinecke <andre.heinecke@intevation.de>
parents: 904
diff changeset
42 return true;
634
80d1a80b3e8d Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
43 #else
1081
edbf5e5e88f4 (issue118) Extend verify_binary to carry an open file
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1073
diff changeset
44 res = verify_binary ("/proc/self/exe", 14);
edbf5e5e88f4 (issue118) Extend verify_binary to carry an open file
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1073
diff changeset
45 if (res.result != VerifyValid)
634
80d1a80b3e8d Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
46 {
80d1a80b3e8d Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
47 syslog_error_printf ("Integrity check failed.");
80d1a80b3e8d Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
48 return false;
80d1a80b3e8d Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
49 }
1081
edbf5e5e88f4 (issue118) Extend verify_binary to carry an open file
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1073
diff changeset
50 fclose(res.fptr);
edbf5e5e88f4 (issue118) Extend verify_binary to carry an open file
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1073
diff changeset
51 return true;
634
80d1a80b3e8d Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
52 #endif
80d1a80b3e8d Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
53 }

http://wald.intevation.org/projects/trustbridge/