2 * Copyright (C) 2009 Martin Willi
3 * Hochschule fuer Technik Rapperswil
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>.
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
17 * @defgroup integrity_checker integrity_checker
21 #ifndef INTEGRITY_CHECKER_H_
22 #define INTEGRITY_CHECKER_H_
26 typedef struct integrity_checker_t integrity_checker_t
;
27 typedef struct integrity_checksum_t integrity_checksum_t
;
30 * Struct to hold a precalculated checksum, implemented in the checksum library.
32 struct integrity_checksum_t
{
33 /* name of the checksum */
35 /* size in bytes of the file on disk */
37 /* checksum of the file on disk */
39 /* size in bytes of executable segment in memory */
41 /* checksum of the executable segment in memory */
46 * Code integrity checker to detect non-malicious file manipulation.
48 * The integrity checker reads the checksums from a separate library
49 * libchecksum.so to compare the checksums.
51 struct integrity_checker_t
{
54 * Check the integrity of a file on disk.
56 * @param name name to lookup checksum
57 * @param file path to file
58 * @return TRUE if integrity tested successfully
60 bool (*check_file
)(integrity_checker_t
*this, char *name
, char *file
);
63 * Build the integrity checksum of a file on disk.
65 * @param file path to file
66 * @param len return length in bytes of file
67 * @return checksum, 0 on error
69 u_int32_t (*build_file
)(integrity_checker_t
*this, char *file
, size_t *len
);
72 * Check the integrity of the code segment in memory.
74 * @param name name to lookup checksum
75 * @param sym a symbol in the segment to check
76 * @return TRUE if integrity tested successfully
78 bool (*check_segment
)(integrity_checker_t
*this, char *name
, void *sym
);
80 * Build the integrity checksum of a code segment in memory.
82 * @param sym a symbol in the segment to check
83 * @param len return length in bytes of code segment in memory
84 * @return checksum, 0 on error
86 u_int32_t (*build_segment
)(integrity_checker_t
*this, void *sym
, size_t *len
);
89 * Check both, on disk file integrity and loaded segment.
91 * @param name name to lookup checksum
92 * @param sym a symbol to look up library and segment
93 * @return TRUE if integrity tested successfully
95 bool (*check
)(integrity_checker_t
*this, char *name
, void *sym
);
98 * Destroy a integrity_checker_t.
100 void (*destroy
)(integrity_checker_t
*this);
104 * Create a integrity_checker instance.
106 * @param checksum_library library containing checksums
108 integrity_checker_t
*integrity_checker_create(char *checksum_library
);
110 #endif /** INTEGRITY_CHECKER_H_ @}*/