d10de5b5bbd6acd157f4f8f1aebb2d7775610fd7
[strongswan.git] / src / libstrongswan / integrity_checker.h
1 /*
2 * Copyright (C) 2009 Martin Willi
3 * Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 /**
17 * @defgroup integrity_checker integrity_checker
18 * @{ @ingroup libstrongswan
19 */
20
21 #ifndef INTEGRITY_CHECKER_H_
22 #define INTEGRITY_CHECKER_H_
23
24 #include <utils.h>
25 #include <plugins/plugin.h>
26
27 typedef struct integrity_checker_t integrity_checker_t;
28 typedef struct integrity_checksum_t integrity_checksum_t;
29
30 /**
31 * Struct to hold a precalculated checksum, implemented in the checksum library.
32 */
33 struct integrity_checksum_t {
34 /* name of the checksum */
35 char *name;
36 /* checksum of the file on disk */
37 u_int32_t file;
38 /* checksum of the executable segment in memory */
39 u_int32_t segment;
40 };
41
42 /**
43 * Code integrity checker to detect non-malicious file manipulation.
44 *
45 * The integrity checker reads the checksums from a separate library
46 * libchecksum.so to compare the checksums.
47 */
48 struct integrity_checker_t {
49
50 /**
51 * Check the integrity of a file on disk.
52 *
53 * @param name name to lookup checksum
54 * @param file path to file
55 * @return TRUE if integrity tested successfully
56 */
57 bool (*check_file)(integrity_checker_t *this, char *name, char *file);
58
59 /**
60 * Build the integrity checksum of a file on disk.
61 *
62 * @param file path to file
63 * @return checksum, 0 on error
64 */
65 u_int32_t (*build_file)(integrity_checker_t *this, char *file);
66
67 /**
68 * Check the integrity of the code segment in memory.
69 *
70 * @param name name to lookup checksum
71 * @param sym a symbol in the segment to check
72 * @return TRUE if integrity tested successfully
73 */
74 bool (*check_segment)(integrity_checker_t *this, char *name, void *sym);
75
76 /**
77 * Build the integrity checksum of a code segment in memory.
78 *
79 * @param sym a symbol in the segment to check
80 * @return checksum, 0 on error
81 */
82 u_int32_t (*build_segment)(integrity_checker_t *this, void *sym);
83
84 /**
85 * Check both, on disk file integrity and loaded segment.
86 *
87 * @param name name to lookup checksum
88 * @param sym a symbol to look up library and segment
89 * @return TRUE if integrity tested successfully
90 */
91 bool (*check)(integrity_checker_t *this, char *name, void *sym);
92
93 /**
94 * Destroy a integrity_checker_t.
95 */
96 void (*destroy)(integrity_checker_t *this);
97 };
98
99 /**
100 * Create a integrity_checker instance.
101 *
102 * @param checksum_library library containing checksums
103 */
104 integrity_checker_t *integrity_checker_create(char *checksum_library);
105
106 #endif /* INTEGRITY_CHECKER_H_ @}*/