aboutsummaryrefslogtreecommitdiffstats
path: root/src/libimcv/tcg/pts
diff options
context:
space:
mode:
authorAndreas Steffen <andreas.steffen@strongswan.org>2011-08-31 16:52:31 +0200
committerAndreas Steffen <andreas.steffen@strongswan.org>2011-09-08 12:08:15 +0200
commita724a71953da15e5ed7ae0d6d2101eecce415b95 (patch)
treefeca753ac2f5d810639ace477f794c2e18c39603 /src/libimcv/tcg/pts
parentf4527909f2f77c682639aa21e199c3f96d9f4095 (diff)
downloadstrongswan-a724a71953da15e5ed7ae0d6d2101eecce415b95.tar.bz2
strongswan-a724a71953da15e5ed7ae0d6d2101eecce415b95.tar.xz
first stage of file_meas refactoring
Diffstat (limited to 'src/libimcv/tcg/pts')
-rw-r--r--src/libimcv/tcg/pts/pts.c40
-rw-r--r--src/libimcv/tcg/pts/pts.h21
2 files changed, 28 insertions, 33 deletions
diff --git a/src/libimcv/tcg/pts/pts.c b/src/libimcv/tcg/pts/pts.c
index 0d0304920..5a15b3a01 100644
--- a/src/libimcv/tcg/pts/pts.c
+++ b/src/libimcv/tcg/pts/pts.c
@@ -537,7 +537,7 @@ METHOD(pts_t, set_aik, void,
}
METHOD(pts_t, hash_file, bool,
- private_pts_t *this, chunk_t path, chunk_t *out)
+ private_pts_t *this, char *pathname, chunk_t *out)
{
char buffer[PTS_BUF_SIZE];
chunk_t path_chunk;
@@ -552,16 +552,15 @@ METHOD(pts_t, hash_file, bool,
if (!hasher)
{
DBG1(DBG_IMC, "hasher %N not available", hash_algorithm_names, hash_alg);
- return false;
+ return FALSE;
}
-
- path_chunk = chunk_create_clone(malloc(path.len), path);
- file = fopen(path_chunk.ptr, "rb");
+
+ file = fopen(pathname, "rb");
if (!file)
{
- DBG1(DBG_IMC,"file '%s' can not be opened, %s", path.ptr, strerror(errno));
+ DBG1(DBG_IMC,"file '%s' can not be opened, %s", pathname, strerror(errno));
hasher->destroy(hasher);
- return false;
+ return FALSE;
}
while (TRUE)
{
@@ -580,27 +579,27 @@ METHOD(pts_t, hash_file, bool,
fclose(file);
hasher->destroy(hasher);
- return true;
+ return TRUE;
}
METHOD(pts_t, hash_directory, bool,
- private_pts_t *this, chunk_t path, linked_list_t **file_measurements)
+ private_pts_t *this, char *pathname, linked_list_t **file_measurements)
{
DIR *dir;
struct dirent *ent;
chunk_t path_chunk;
file_meas_entry_t *entry;
linked_list_t *list = *file_measurements;
+ char filename[BUF_LEN];
list = linked_list_create();
entry = malloc_thing(file_meas_entry_t);
- path_chunk = chunk_create_clone(malloc(path.len), path);
- dir = opendir(path_chunk.ptr);
+ dir = opendir(pathname);
if (dir == NULL)
{
- DBG1(DBG_IMC, "opening directory '%s' failed: %s", path.ptr, strerror(errno));
- return false;
+ DBG1(DBG_IMC, "opening directory '%s' failed: %s", pathname, strerror(errno));
+ return FALSE;
}
while ((ent = readdir(dir)))
{
@@ -608,24 +607,21 @@ METHOD(pts_t, hash_directory, bool,
{ /* skip ".", ".." and hidden files (such as ".svn") */
continue;
}
+ snprintf(filename, BUF_LEN, "%s/%s", pathname, ent->d_name);
+ entry->filename = strdup(filename);
- if(this->public.hash_file(&this->public, chunk_cat("cc", path, chunk_create(ent->d_name, strlen(ent->d_name)))
- , &entry->measurement) != true)
+ if (!hash_file(this, filename, &entry->measurement))
{
DBG1(DBG_IMC, "Hashing the given file has failed");
- return false;
+ return FALSE;
}
-
- entry->file_name_len = strlen(ent->d_name);
- entry->file_name = chunk_create(ent->d_name,strlen(ent->d_name));
-
- list->insert_last(list,entry);
+ list->insert_last(list, entry);
}
closedir(dir);
*file_measurements = list;
- return true;
+ return TRUE;
}
METHOD(pts_t, destroy, void,
diff --git a/src/libimcv/tcg/pts/pts.h b/src/libimcv/tcg/pts/pts.h
index f88effa8d..f76ee8eb1 100644
--- a/src/libimcv/tcg/pts/pts.h
+++ b/src/libimcv/tcg/pts/pts.h
@@ -36,9 +36,8 @@ typedef struct file_meas_entry_t file_meas_entry_t;
* File Measurement entry
*/
struct file_meas_entry_t {
- chunk_t measurement;
- u_int16_t file_name_len;
- chunk_t file_name;
+ char *filename;
+ chunk_t measurement;
};
/**
@@ -94,8 +93,8 @@ struct pts_t {
* Get Attestation Identity Key
*
* @param aik chunk containing a AIK naked public key or certificate
- * @param is_naked_key TRUE if AIK is naked public key, without certificate
- * @return TRUE if AIK available
+ * @param is_naked_key TRUE if AIK is naked public key, without certificate
+ * @return TRUE if AIK available
*/
bool (*get_aik)(pts_t *this, chunk_t *aik, bool *is_naked_key);
@@ -103,27 +102,27 @@ struct pts_t {
* Set Attestation Identity Key
*
* @param aik chunk containing a AIK naked public key or certificate
- * @param is_naked_key TRUE if AIK is naked public key, without certificate
+ * @param is_naked_key TRUE if AIK is naked public key, without certificate
*/
void (*set_aik)(pts_t *this, chunk_t aik, bool is_naked_key);
/**
* Hash the given file
*
- * @param path absolute path to file to be hashed
+ * @param pathname absolute path to file to be hashed
* @param out hash output value of a given file
- * @return TRUE if hashing file was successful
+ * @return TRUE if hashing file was successful
*/
- bool (*hash_file)(pts_t *this, chunk_t path, chunk_t *out);
+ bool (*hash_file)(pts_t *this, char *pathname, chunk_t *out);
/**
* Hash the given directory
*
- * @param path absolute path to directory to be hashed
+ * @param pathname absolute path to directory to be hashed
* @param file_measurements list of hash output values of files in a given folder
* @return TRUE if hashing directory was successful
*/
- bool (*hash_directory)(pts_t *this, chunk_t path, linked_list_t **file_measurements);
+ bool (*hash_directory)(pts_t *this, char *pathname, linked_list_t **file_measurements);
/**
* Destroys a pts_t object.