added pts database interface

This commit is contained in:
Andreas Steffen
2011-09-08 12:08:13 +02:00
parent 97112ec23a
commit 20c2bec0f3
5 changed files with 180 additions and 1 deletions
+1
View File
@@ -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
@@ -20,6 +20,8 @@
#include <ietf/ietf_attr.h>
#include <ietf/ietf_attr_pa_tnc_error.h>
#include <tcg/pts/pts_database.h>
#include <tcg/tcg_attr.h>
#include <tcg/tcg_pts_attr_proto_caps.h>
#include <tcg/tcg_pts_attr_meas_algo.h>
@@ -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;
@@ -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)
);
+81
View File
@@ -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 <http://www.fsf.org/copyleft/gpl.txt>.
*
* 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 <debug.h>
#include <crypto/hashers/hasher.h>
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;
}
+58
View File
@@ -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 <http://www.fsf.org/copyleft/gpl.txt>.
*
* 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 <library.h>
/**
* 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_ @}*/