make IMC/IMV pairs independent of libcharon
[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 /* size in bytes of the file on disk */
37 size_t file_len;
38 /* checksum of the file on disk */
39 u_int32_t file;
40 /* size in bytes of executable segment in memory */
41 size_t segment_len;
42 /* checksum of the executable segment in memory */
43 u_int32_t segment;
44 };
45
46 /**
47 * Code integrity checker to detect non-malicious file manipulation.
48 *
49 * The integrity checker reads the checksums from a separate library
50 * libchecksum.so to compare the checksums.
51 */
52 struct integrity_checker_t {
53
54 /**
55 * Check the integrity of a file on disk.
56 *
57 * @param name name to lookup checksum
58 * @param file path to file
59 * @return TRUE if integrity tested successfully
60 */
61 bool (*check_file)(integrity_checker_t *this, char *name, char *file);
62
63 /**
64 * Build the integrity checksum of a file on disk.
65 *
66 * @param file path to file
67 * @param len return length in bytes of file
68 * @return checksum, 0 on error
69 */
70 u_int32_t (*build_file)(integrity_checker_t *this, char *file, size_t *len);
71
72 /**
73 * Check the integrity of the code segment in memory.
74 *
75 * @param name name to lookup checksum
76 * @param sym a symbol in the segment to check
77 * @return TRUE if integrity tested successfully
78 */
79 bool (*check_segment)(integrity_checker_t *this, char *name, void *sym);
80 /**
81 * Build the integrity checksum of a code segment in memory.
82 *
83 * @param sym a symbol in the segment to check
84 * @param len return length in bytes of code segment in memory
85 * @return checksum, 0 on error
86 */
87 u_int32_t (*build_segment)(integrity_checker_t *this, void *sym, size_t *len);
88
89 /**
90 * Check both, on disk file integrity and loaded segment.
91 *
92 * @param name name to lookup checksum
93 * @param sym a symbol to look up library and segment
94 * @return TRUE if integrity tested successfully
95 */
96 bool (*check)(integrity_checker_t *this, char *name, void *sym);
97
98 /**
99 * Destroy a integrity_checker_t.
100 */
101 void (*destroy)(integrity_checker_t *this);
102 };
103
104 /**
105 * Create a integrity_checker instance.
106 *
107 * @param checksum_library library containing checksums
108 */
109 integrity_checker_t *integrity_checker_create(char *checksum_library);
110
111 #endif /** INTEGRITY_CHECKER_H_ @}*/