2 * Copyright (C) 2011-2014 Andreas Steffen
3 * HSR 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
16 #include "pts_ima_bios_list.h"
18 #include <utils/debug.h>
20 #include <sys/types.h>
26 typedef struct private_pts_ima_bios_list_t private_pts_ima_bios_list_t
;
27 typedef struct bios_entry_t bios_entry_t
;
30 * Private data of a pts_ima_bios_list_t object.
33 struct private_pts_ima_bios_list_t
{
36 * Public pts_ima_bios_list_t interface.
38 pts_ima_bios_list_t
public;
41 * List of BIOS measurement entries
46 * Time when BIOS measurements were taken
53 * Linux IMA BIOS measurement entry
63 * SHA1 measurement hash
69 * Free a bios_entry_t object
71 static void free_bios_entry(bios_entry_t
*this)
73 free(this->measurement
.ptr
);
77 METHOD(pts_ima_bios_list_t
, get_time
, time_t,
78 private_pts_ima_bios_list_t
*this)
80 return this->creation_time
;
83 METHOD(pts_ima_bios_list_t
, get_count
, int,
84 private_pts_ima_bios_list_t
*this)
86 return this->list
->get_count(this->list
);
89 METHOD(pts_ima_bios_list_t
, get_next
, status_t
,
90 private_pts_ima_bios_list_t
*this, uint32_t *pcr
, chunk_t
*measurement
)
95 status
= this->list
->remove_first(this->list
, (void**)&entry
);
97 *measurement
= entry
->measurement
;
103 METHOD(pts_ima_bios_list_t
, destroy
, void,
104 private_pts_ima_bios_list_t
*this)
106 this->list
->destroy_function(this->list
, (void *)free_bios_entry
);
113 pts_ima_bios_list_t
* pts_ima_bios_list_create(char *file
)
115 private_pts_ima_bios_list_t
*this;
116 uint32_t pcr
, num
, len
;
122 fd
= open(file
, O_RDONLY
);
125 DBG1(DBG_PTS
, "opening '%s' failed: %s", file
, strerror(errno
));
129 if (fstat(fd
, &st
) == -1)
131 DBG1(DBG_PTS
, "getting statistics of '%s' failed: %s", file
,
139 .get_time
= _get_time
,
140 .get_count
= _get_count
,
141 .get_next
= _get_next
,
144 .creation_time
= st
.st_ctime
,
145 .list
= linked_list_create(),
150 res
= read(fd
, &pcr
, 4);
153 DBG2(DBG_PTS
, "loaded bios measurements '%s' (%d entries)",
154 file
, this->list
->get_count(this->list
));
156 return &this->public;
159 entry
= malloc_thing(bios_entry_t
);
161 entry
->measurement
= chunk_alloc(HASH_SIZE_SHA1
);
167 if (read(fd
, &num
, 4) != 4)
171 if (read(fd
, entry
->measurement
.ptr
, HASH_SIZE_SHA1
) != HASH_SIZE_SHA1
)
175 if (read(fd
, &len
, 4) != 4)
179 if (lseek(fd
, len
, SEEK_CUR
) == -1)
183 this->list
->insert_last(this->list
, entry
);
186 DBG1(DBG_PTS
, "loading bios measurements '%s' failed: %s", file
,
188 free_bios_entry(entry
);