From 20c2bec0f3c3e0b0121d50e2828d452417f0f6c5 Mon Sep 17 00:00:00 2001 From: Andreas Steffen Date: Mon, 22 Aug 2011 22:32:19 +0200 Subject: [PATCH] added pts database interface --- src/libimcv/Makefile.am | 1 + .../plugins/imv_attestation/imv_attestation.c | 15 +++- .../plugins/imv_attestation/tables.sql | 26 ++++++ src/libimcv/tcg/pts/pts_database.c | 81 +++++++++++++++++++ src/libimcv/tcg/pts/pts_database.h | 58 +++++++++++++ 5 files changed, 180 insertions(+), 1 deletion(-) create mode 100644 src/libimcv/plugins/imv_attestation/tables.sql create mode 100644 src/libimcv/tcg/pts/pts_database.c create mode 100644 src/libimcv/tcg/pts/pts_database.h diff --git a/src/libimcv/Makefile.am b/src/libimcv/Makefile.am index 8db55e22b..0791b5488 100644 --- a/src/libimcv/Makefile.am +++ b/src/libimcv/Makefile.am @@ -32,6 +32,7 @@ libimcv_la_SOURCES = \ tcg/pts/pts.h tcg/pts/pts.c \ tcg/pts/pts_error.h tcg/pts/pts_error.c \ tcg/pts/pts_proto_caps.h tcg/pts/pts_funct_comp_name.h \ + tcg/pts/pts_database.h tcg/pts/pts_database.c \ tcg/pts/pts_meas_algo.h tcg/pts/pts_meas_algo.c # CFLAGS = -Wall -Werror diff --git a/src/libimcv/plugins/imv_attestation/imv_attestation.c b/src/libimcv/plugins/imv_attestation/imv_attestation.c index 435ca6dd9..9b462141d 100644 --- a/src/libimcv/plugins/imv_attestation/imv_attestation.c +++ b/src/libimcv/plugins/imv_attestation/imv_attestation.c @@ -20,6 +20,8 @@ #include #include +#include + #include #include #include @@ -60,6 +62,11 @@ static imv_agent_t *imv_attestation; */ static pts_meas_algorithms_t supported_algorithms = 0; +/** + * PTS file measurement database + */ +static pts_database_t *pts_db; + /** * List of files and directories to measure */ @@ -89,7 +96,7 @@ TNC_Result TNC_IMV_Initialize(TNC_IMVID imv_id, TNC_Version max_version, TNC_Version *actual_version) { - char *hash_alg; + char *hash_alg, *uri; if (imv_attestation) { @@ -130,6 +137,11 @@ TNC_Result TNC_IMV_Initialize(TNC_IMVID imv_id, supported_algorithms &= ~PTS_MEAS_ALGO_SHA256; } + /* attach file measurement database */ + uri = lib->settings->get_str(lib->settings, + "libimcv.plugins.imv-attestation.database", NULL); + pts_db = pts_database_create(uri); + return TNC_RESULT_SUCCESS; } @@ -583,6 +595,7 @@ TNC_Result TNC_IMV_Terminate(TNC_IMVID imv_id) DBG1(DBG_IMV, "IMV \"%s\" has not been initialized", imv_name); return TNC_RESULT_NOT_INITIALIZED; } + DESTROY_IF(pts_db); imv_attestation->destroy(imv_attestation); imv_attestation = NULL; diff --git a/src/libimcv/plugins/imv_attestation/tables.sql b/src/libimcv/plugins/imv_attestation/tables.sql new file mode 100644 index 000000000..449d23312 --- /dev/null +++ b/src/libimcv/plugins/imv_attestation/tables.sql @@ -0,0 +1,26 @@ +/* PTS SQLite database */ + +DROP TABLE IF EXISTS files; +CREATE TABLE files ( + id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + type INTEGER NOT NULL, + path TEXT NOT NULL, +); + +DROP TABLE IF EXISTS products; +CREATE TABLE products ( + id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + name TEXT NOT NULL, +); +DROP INDEX IF EXISTS products_name; +CREATE INDEX products_name ON products ( + name +); + +DROP TABLE IF EXISTS product_file; +CREATE TABLE product_file ( + product INTEGER NOT NULL, + file INTEGER NOT NULL, + PRIMARY KEY (product, file) +); + diff --git a/src/libimcv/tcg/pts/pts_database.c b/src/libimcv/tcg/pts/pts_database.c new file mode 100644 index 000000000..916e88843 --- /dev/null +++ b/src/libimcv/tcg/pts/pts_database.c @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2011 Sansar Choinyambuu + * HSR Hochschule fuer Technik Rapperswil + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. See . + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +#include "pts_database.h" + +#include +#include + + +typedef struct private_pts_database_t private_pts_database_t; + +/** + * Private data of a pts_database_t object. + * + */ +struct private_pts_database_t { + + /** + * Public pts_database_t interface. + */ + pts_database_t public; + + /** + * database instance + */ + database_t *db; + +}; + +METHOD(pts_database_t, create_file_enumerator, enumerator_t*, + private_pts_database_t *this, char *product, char *version) +{ + enumerator_t *e = NULL; + + return e; +} + +METHOD(pts_database_t, destroy, void, + private_pts_database_t *this) +{ + this->db->destroy(this->db); + free(this); +} + +/** + * See header + */ +pts_database_t *pts_database_create(char *uri) +{ + private_pts_database_t *this; + + INIT(this, + .public = { + .create_file_enumerator = _create_file_enumerator, + .destroy = _destroy, + }, + .db = lib->db->create(lib->db, uri), + ); + + if (!this->db) + { + DBG1(DBG_TNC, "pts failed to connect to file database"); + free(this); + return NULL; + } + + return &this->public; +} + diff --git a/src/libimcv/tcg/pts/pts_database.h b/src/libimcv/tcg/pts/pts_database.h new file mode 100644 index 000000000..40d9ffaea --- /dev/null +++ b/src/libimcv/tcg/pts/pts_database.h @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2011 Andreas Steffen + * HSR Hochschule fuer Technik Rapperswil + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. See . + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +/** + * @defgroup pts_database pts_database + * @{ @ingroup pts_database + */ + +#ifndef PTS_DATABASE_H_ +#define PTS_DATABASE_H_ + +typedef struct pts_database_t pts_database_t; + +#include + +/** + * Class implementing the PTS File Measurement database + * + */ +struct pts_database_t { + + /** + * Get files to be measured by PTS + * + * @product software product (os, vpn client, etc.) + * @param version release version + * @return enumerator over all files matching a given release + */ + enumerator_t* (*create_file_enumerator)(pts_database_t *this, char *product, + char *version); + + /** + * Destroys a pts_database_t object. + */ + void (*destroy)(pts_database_t *this); + +}; + +/** + * Creates an pts_database_t object + * + * @param ur database uri + */ +pts_database_t* pts_database_create(char *uri); + +#endif /** PTS_DATABASE_H_ @}*/