2011-08-20 21:37:37 +00:00
|
|
|
/*
|
|
|
|
* 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.h"
|
|
|
|
|
|
|
|
#include <debug.h>
|
2011-08-21 08:38:51 +00:00
|
|
|
#include <crypto/hashers/hasher.h>
|
2011-08-20 21:37:37 +00:00
|
|
|
|
|
|
|
#include <trousers/tss.h>
|
|
|
|
#include <trousers/trousers.h>
|
|
|
|
|
2011-09-01 13:42:35 +00:00
|
|
|
#include <sys/stat.h>
|
2011-08-24 07:34:55 +00:00
|
|
|
#include <errno.h>
|
|
|
|
|
2011-09-01 13:42:35 +00:00
|
|
|
#define PTS_BUF_SIZE 4096
|
2011-08-24 07:34:55 +00:00
|
|
|
|
2011-08-20 21:37:37 +00:00
|
|
|
typedef struct private_pts_t private_pts_t;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Private data of a pts_t object.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
struct private_pts_t {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Public pts_t interface.
|
|
|
|
*/
|
|
|
|
pts_t public;
|
|
|
|
|
2011-08-21 08:38:51 +00:00
|
|
|
/**
|
|
|
|
* PTS Protocol Capabilities
|
|
|
|
*/
|
|
|
|
pts_proto_caps_flag_t proto_caps;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* PTS Measurement Algorithm
|
|
|
|
*/
|
|
|
|
pts_meas_algorithms_t algorithm;
|
|
|
|
|
2011-09-01 13:42:35 +00:00
|
|
|
/**
|
|
|
|
* Platform and OS Info
|
|
|
|
*/
|
|
|
|
char *platform_info;
|
|
|
|
|
2011-08-21 18:00:15 +00:00
|
|
|
/**
|
|
|
|
* Do we have an activated TPM
|
|
|
|
*/
|
|
|
|
bool has_tpm;
|
|
|
|
|
2011-08-20 21:37:37 +00:00
|
|
|
/**
|
|
|
|
* Contains a TPM_CAP_VERSION_INFO struct
|
|
|
|
*/
|
|
|
|
chunk_t tpm_version_info;
|
2011-09-02 07:39:11 +00:00
|
|
|
|
2011-08-26 12:16:12 +00:00
|
|
|
/**
|
2011-09-02 14:07:39 +00:00
|
|
|
* Contains a Attestation Identity Certificate
|
2011-08-26 12:16:12 +00:00
|
|
|
*/
|
2011-09-02 14:07:39 +00:00
|
|
|
certificate_t *aik_cert;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Contains a Attestation Identity Public Key
|
|
|
|
*/
|
|
|
|
public_key_t *aik_key;
|
2011-09-02 07:39:11 +00:00
|
|
|
|
2011-08-26 12:16:12 +00:00
|
|
|
/**
|
|
|
|
* True if AIK is naked public key, not a certificate
|
|
|
|
*/
|
|
|
|
bool is_naked_key;
|
2011-09-02 07:39:11 +00:00
|
|
|
|
2011-08-20 21:37:37 +00:00
|
|
|
};
|
|
|
|
|
2011-08-21 08:38:51 +00:00
|
|
|
METHOD(pts_t, get_proto_caps, pts_proto_caps_flag_t,
|
2011-09-02 07:39:11 +00:00
|
|
|
private_pts_t *this)
|
2011-08-21 08:38:51 +00:00
|
|
|
{
|
|
|
|
return this->proto_caps;
|
|
|
|
}
|
|
|
|
|
|
|
|
METHOD(pts_t, set_proto_caps, void,
|
2011-09-02 07:39:11 +00:00
|
|
|
private_pts_t *this, pts_proto_caps_flag_t flags)
|
2011-08-21 08:38:51 +00:00
|
|
|
{
|
|
|
|
this->proto_caps = flags;
|
2011-09-02 14:07:39 +00:00
|
|
|
DBG2(DBG_IMC, "supported PTS protocol capabilities: %s%s%s%s%s",
|
2011-09-02 07:39:11 +00:00
|
|
|
flags & PTS_PROTO_CAPS_C ? "C" : ".",
|
|
|
|
flags & PTS_PROTO_CAPS_V ? "V" : ".",
|
|
|
|
flags & PTS_PROTO_CAPS_D ? "D" : ".",
|
|
|
|
flags & PTS_PROTO_CAPS_T ? "T" : ".",
|
|
|
|
flags & PTS_PROTO_CAPS_X ? "X" : ".");
|
2011-08-21 08:38:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
METHOD(pts_t, get_meas_algorithm, pts_meas_algorithms_t,
|
2011-09-02 07:39:11 +00:00
|
|
|
private_pts_t *this)
|
2011-08-21 08:38:51 +00:00
|
|
|
{
|
|
|
|
return this->algorithm;
|
|
|
|
}
|
|
|
|
|
|
|
|
METHOD(pts_t, set_meas_algorithm, void,
|
2011-09-02 07:39:11 +00:00
|
|
|
private_pts_t *this, pts_meas_algorithms_t algorithm)
|
2011-08-21 08:38:51 +00:00
|
|
|
{
|
|
|
|
hash_algorithm_t hash_alg;
|
|
|
|
|
|
|
|
hash_alg = pts_meas_to_hash_algorithm(algorithm);
|
2011-09-02 14:07:39 +00:00
|
|
|
DBG2(DBG_IMC, "selected PTS measurement algorithm is %N",
|
2011-09-02 07:39:11 +00:00
|
|
|
hash_algorithm_names, hash_alg);
|
2011-08-21 08:38:51 +00:00
|
|
|
if (hash_alg != HASH_UNKNOWN)
|
|
|
|
{
|
|
|
|
this->algorithm = algorithm;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-20 21:37:37 +00:00
|
|
|
/**
|
|
|
|
* Print TPM 1.2 Version Info
|
|
|
|
*/
|
|
|
|
static void print_tpm_version_info(private_pts_t *this)
|
|
|
|
{
|
|
|
|
TPM_CAP_VERSION_INFO versionInfo;
|
|
|
|
UINT64 offset = 0;
|
|
|
|
TSS_RESULT result;
|
|
|
|
|
|
|
|
result = Trspi_UnloadBlob_CAP_VERSION_INFO(&offset,
|
2011-09-02 07:39:11 +00:00
|
|
|
this->tpm_version_info.ptr, &versionInfo);
|
2011-08-20 21:37:37 +00:00
|
|
|
if (result != TSS_SUCCESS)
|
|
|
|
{
|
2011-09-02 14:07:39 +00:00
|
|
|
DBG1(DBG_IMC, "could not parse tpm version info: tss error 0x%x",
|
2011-08-20 21:37:37 +00:00
|
|
|
result);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-09-02 14:07:39 +00:00
|
|
|
DBG2(DBG_IMC, "TPM 1.2 Version Info: Chip Version: %hhu.%hhu.%hhu.%hhu,"
|
2011-09-02 07:39:11 +00:00
|
|
|
" Spec Level: %hu, Errata Rev: %hhu, Vendor ID: %.4s",
|
|
|
|
versionInfo.version.major, versionInfo.version.minor,
|
|
|
|
versionInfo.version.revMajor, versionInfo.version.revMinor,
|
|
|
|
versionInfo.specLevel, versionInfo.errataRev,
|
|
|
|
versionInfo.tpmVendorID);
|
2011-08-20 21:37:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-01 13:42:35 +00:00
|
|
|
METHOD(pts_t, get_platform_info, char*,
|
2011-09-02 07:39:11 +00:00
|
|
|
private_pts_t *this)
|
2011-09-01 13:42:35 +00:00
|
|
|
{
|
|
|
|
return this->platform_info;
|
|
|
|
}
|
|
|
|
|
|
|
|
METHOD(pts_t, set_platform_info, void,
|
2011-09-02 07:39:11 +00:00
|
|
|
private_pts_t *this, char *info)
|
2011-09-01 13:42:35 +00:00
|
|
|
{
|
|
|
|
free(this->platform_info);
|
|
|
|
this->platform_info = strdup(info);
|
|
|
|
}
|
|
|
|
|
2011-08-20 21:37:37 +00:00
|
|
|
METHOD(pts_t, get_tpm_version_info, bool,
|
2011-09-02 07:39:11 +00:00
|
|
|
private_pts_t *this, chunk_t *info)
|
2011-08-20 21:37:37 +00:00
|
|
|
{
|
2011-08-21 18:00:15 +00:00
|
|
|
if (!this->has_tpm)
|
2011-08-20 21:37:37 +00:00
|
|
|
{
|
2011-08-21 18:00:15 +00:00
|
|
|
return FALSE;
|
2011-08-20 21:37:37 +00:00
|
|
|
}
|
|
|
|
*info = this->tpm_version_info;
|
|
|
|
print_tpm_version_info(this);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
METHOD(pts_t, set_tpm_version_info, void,
|
2011-09-02 07:39:11 +00:00
|
|
|
private_pts_t *this, chunk_t info)
|
2011-08-20 21:37:37 +00:00
|
|
|
{
|
|
|
|
this->tpm_version_info = chunk_clone(info);
|
|
|
|
print_tpm_version_info(this);
|
|
|
|
}
|
|
|
|
|
2011-08-31 13:04:05 +00:00
|
|
|
|
|
|
|
/**
|
2011-09-02 14:07:39 +00:00
|
|
|
* Obtain an AIK Certificate or public key
|
|
|
|
* If the certificate is available in give path, ignore whether key is there
|
|
|
|
* If certificate is not available take the public key at given path
|
2011-08-24 07:34:55 +00:00
|
|
|
*/
|
2011-08-31 15:36:16 +00:00
|
|
|
static bool obtain_aik(private_pts_t *this)
|
2011-08-26 12:16:12 +00:00
|
|
|
{
|
2011-09-02 14:07:39 +00:00
|
|
|
char *certificate_path;
|
|
|
|
char *key_path;
|
2011-08-31 13:04:05 +00:00
|
|
|
|
2011-09-02 14:07:39 +00:00
|
|
|
certificate_path = lib->settings->get_str(lib->settings,
|
2011-09-05 09:04:47 +00:00
|
|
|
"libimcv.plugins.imc-attestation.aikcert", NULL);
|
2011-09-02 14:07:39 +00:00
|
|
|
|
|
|
|
key_path = lib->settings->get_str(lib->settings,
|
2011-09-05 09:04:47 +00:00
|
|
|
"libimcv.plugins.imc-attestation.aikkey", NULL);
|
2011-08-31 13:04:05 +00:00
|
|
|
|
2011-09-02 14:07:39 +00:00
|
|
|
DBG2(DBG_IMC,"AIK Certificate path %s",certificate_path);
|
|
|
|
DBG2(DBG_IMC,"AIK Public Key path %s", key_path);
|
2011-08-31 13:04:05 +00:00
|
|
|
|
2011-09-02 14:07:39 +00:00
|
|
|
if(certificate_path && (this->aik_cert = lib->creds->create(lib->creds, CRED_CERTIFICATE, CERT_X509,
|
|
|
|
BUILD_FROM_FILE, certificate_path,
|
|
|
|
BUILD_END)))
|
2011-09-02 07:39:11 +00:00
|
|
|
{
|
2011-09-02 14:07:39 +00:00
|
|
|
this->is_naked_key = FALSE;
|
2011-08-31 13:04:05 +00:00
|
|
|
}
|
2011-09-02 14:07:39 +00:00
|
|
|
else if(key_path && (this->aik_key = lib->creds->create(lib->creds, CRED_PUBLIC_KEY, KEY_ANY,
|
|
|
|
BUILD_FROM_FILE, key_path,
|
|
|
|
BUILD_END)))
|
2011-09-02 07:39:11 +00:00
|
|
|
{
|
2011-09-02 14:07:39 +00:00
|
|
|
this->is_naked_key = TRUE;
|
2011-08-31 15:36:16 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-09-02 14:07:39 +00:00
|
|
|
DBG1(DBG_IMC, "Neither AIK Public Key nor AIK Certificate is available");
|
|
|
|
return FALSE;
|
2011-08-31 15:36:16 +00:00
|
|
|
}
|
2011-09-02 14:07:39 +00:00
|
|
|
|
2011-09-01 13:42:35 +00:00
|
|
|
DBG3(DBG_IMC, "Succeeded at obtaining AIK Certificate from Privacy CA!");
|
2011-08-26 12:16:12 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
METHOD(pts_t, get_aik, bool,
|
2011-09-02 14:07:39 +00:00
|
|
|
private_pts_t *this, certificate_t **aik_cert, public_key_t **aik_key, bool *is_naked_key)
|
2011-08-26 12:16:12 +00:00
|
|
|
{
|
2011-09-02 07:39:11 +00:00
|
|
|
if (obtain_aik(this) != TRUE )
|
2011-08-26 12:16:12 +00:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
2011-09-02 07:39:11 +00:00
|
|
|
|
2011-09-02 14:07:39 +00:00
|
|
|
*aik_cert = this->aik_cert;
|
|
|
|
*aik_key = this->aik_key;
|
2011-08-26 12:16:12 +00:00
|
|
|
*is_naked_key = this->is_naked_key;
|
2011-09-02 07:39:11 +00:00
|
|
|
|
2011-08-26 12:16:12 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-09-02 14:07:39 +00:00
|
|
|
METHOD(pts_t, set_aik_cert, void,
|
|
|
|
private_pts_t *this, certificate_t *aik_cert)
|
|
|
|
{
|
|
|
|
this->aik_cert = aik_cert;
|
|
|
|
this->is_naked_key = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
METHOD(pts_t, set_aik_key, void,
|
|
|
|
private_pts_t *this, public_key_t *aik_key)
|
2011-08-26 12:16:12 +00:00
|
|
|
{
|
2011-09-02 14:07:39 +00:00
|
|
|
this->aik_key = aik_key;
|
|
|
|
this->is_naked_key = TRUE;
|
2011-08-26 12:16:12 +00:00
|
|
|
}
|
2011-08-24 07:34:55 +00:00
|
|
|
|
2011-09-01 13:42:35 +00:00
|
|
|
/**
|
2011-09-02 07:39:11 +00:00
|
|
|
* Compute a hash over a file
|
2011-09-01 13:42:35 +00:00
|
|
|
*/
|
|
|
|
static bool hash_file(hasher_t *hasher, char *pathname, u_char *hash)
|
2011-08-24 07:34:55 +00:00
|
|
|
{
|
2011-09-01 13:42:35 +00:00
|
|
|
u_char buffer[PTS_BUF_SIZE];
|
2011-08-24 07:34:55 +00:00
|
|
|
FILE *file;
|
|
|
|
int bytes_read;
|
2011-08-31 14:52:31 +00:00
|
|
|
|
|
|
|
file = fopen(pathname, "rb");
|
2011-08-24 07:34:55 +00:00
|
|
|
if (!file)
|
|
|
|
{
|
2011-09-01 13:42:35 +00:00
|
|
|
DBG1(DBG_IMC," file '%s' can not be opened, %s", pathname,
|
|
|
|
strerror(errno));
|
2011-08-31 14:52:31 +00:00
|
|
|
return FALSE;
|
2011-08-24 07:34:55 +00:00
|
|
|
}
|
|
|
|
while (TRUE)
|
|
|
|
{
|
|
|
|
bytes_read = fread(buffer, 1, sizeof(buffer), file);
|
|
|
|
if (bytes_read > 0)
|
|
|
|
{
|
2011-09-01 13:42:35 +00:00
|
|
|
hasher->get_hash(hasher, chunk_create(buffer, bytes_read), NULL);
|
2011-08-24 07:34:55 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-09-01 13:42:35 +00:00
|
|
|
hasher->get_hash(hasher, chunk_empty, hash);
|
2011-08-24 07:34:55 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose(file);
|
|
|
|
|
2011-08-31 14:52:31 +00:00
|
|
|
return TRUE;
|
2011-09-02 07:39:11 +00:00
|
|
|
}
|
2011-09-01 13:42:35 +00:00
|
|
|
|
|
|
|
/**
|
2011-09-02 07:39:11 +00:00
|
|
|
* Get the relative filename of a fully qualified file pathname
|
2011-09-01 13:42:35 +00:00
|
|
|
*/
|
|
|
|
static char* get_filename(char *pathname)
|
|
|
|
{
|
|
|
|
char *pos, *filename;
|
|
|
|
|
|
|
|
pos = filename = pathname;
|
|
|
|
while (pos && *(++pos) != '\0')
|
|
|
|
{
|
|
|
|
filename = pos;
|
|
|
|
pos = strchr(filename, '/');
|
|
|
|
}
|
2011-09-02 07:39:11 +00:00
|
|
|
return filename;
|
2011-08-24 07:34:55 +00:00
|
|
|
}
|
|
|
|
|
2011-09-01 13:42:35 +00:00
|
|
|
METHOD(pts_t, do_measurements, pts_file_meas_t*,
|
2011-09-02 07:39:11 +00:00
|
|
|
private_pts_t *this, u_int16_t request_id, char *pathname, bool is_directory)
|
2011-08-24 07:34:55 +00:00
|
|
|
{
|
2011-09-01 13:42:35 +00:00
|
|
|
hasher_t *hasher;
|
|
|
|
hash_algorithm_t hash_alg;
|
|
|
|
u_char hash[HASH_SIZE_SHA384];
|
|
|
|
chunk_t measurement;
|
|
|
|
pts_file_meas_t *measurements;
|
|
|
|
|
|
|
|
/* Create a hasher */
|
|
|
|
hash_alg = pts_meas_to_hash_algorithm(this->algorithm);
|
|
|
|
hasher = lib->crypto->create_hasher(lib->crypto, hash_alg);
|
|
|
|
if (!hasher)
|
2011-08-24 07:34:55 +00:00
|
|
|
{
|
2011-09-01 13:42:35 +00:00
|
|
|
DBG1(DBG_IMC, " hasher %N not available", hash_algorithm_names, hash_alg);
|
|
|
|
return NULL;
|
2011-08-24 07:34:55 +00:00
|
|
|
}
|
2011-09-01 13:42:35 +00:00
|
|
|
|
|
|
|
/* Create a measurement object */
|
|
|
|
measurements = pts_file_meas_create(request_id);
|
|
|
|
|
|
|
|
/* Link the hash to the measurement and set the measurement length */
|
|
|
|
measurement = chunk_create(hash, hasher->get_hash_size(hasher));
|
|
|
|
|
2011-09-01 14:27:18 +00:00
|
|
|
if (is_directory)
|
2011-08-24 07:34:55 +00:00
|
|
|
{
|
2011-09-01 13:42:35 +00:00
|
|
|
enumerator_t *enumerator;
|
|
|
|
char *rel_name, *abs_name;
|
|
|
|
struct stat st;
|
|
|
|
|
|
|
|
enumerator = enumerator_create_directory(pathname);
|
|
|
|
if (!enumerator)
|
|
|
|
{
|
|
|
|
DBG1(DBG_IMC," directory '%s' can not be opened, %s", pathname,
|
|
|
|
strerror(errno));
|
|
|
|
hasher->destroy(hasher);
|
|
|
|
measurements->destroy(measurements);
|
2011-09-02 07:39:11 +00:00
|
|
|
return NULL;
|
2011-08-24 14:25:37 +00:00
|
|
|
}
|
2011-09-01 13:42:35 +00:00
|
|
|
while (enumerator->enumerate(enumerator, &rel_name, &abs_name, &st))
|
2011-08-24 07:34:55 +00:00
|
|
|
{
|
2011-09-01 14:27:18 +00:00
|
|
|
/* measure regular files only */
|
|
|
|
if (S_ISREG(st.st_mode) && *rel_name != '.')
|
2011-09-01 13:42:35 +00:00
|
|
|
{
|
|
|
|
if (!hash_file(hasher, abs_name, hash))
|
|
|
|
{
|
|
|
|
enumerator->destroy(enumerator);
|
|
|
|
hasher->destroy(hasher);
|
|
|
|
measurements->destroy(measurements);
|
2011-09-02 07:39:11 +00:00
|
|
|
return NULL;
|
2011-09-01 13:42:35 +00:00
|
|
|
}
|
2011-09-01 14:27:18 +00:00
|
|
|
DBG2(DBG_IMC, " %#B for '%s'", &measurement, rel_name);
|
2011-09-01 13:42:35 +00:00
|
|
|
measurements->add(measurements, rel_name, measurement);
|
2011-09-02 07:39:11 +00:00
|
|
|
}
|
2011-08-24 07:34:55 +00:00
|
|
|
}
|
2011-09-02 07:39:11 +00:00
|
|
|
enumerator->destroy(enumerator);
|
2011-08-24 07:34:55 +00:00
|
|
|
}
|
2011-09-01 13:42:35 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
char *filename;
|
|
|
|
|
|
|
|
if (!hash_file(hasher, pathname, hash))
|
|
|
|
{
|
|
|
|
hasher->destroy(hasher);
|
|
|
|
measurements->destroy(measurements);
|
2011-09-02 07:39:11 +00:00
|
|
|
return NULL;
|
2011-09-01 13:42:35 +00:00
|
|
|
}
|
|
|
|
filename = get_filename(pathname);
|
|
|
|
DBG2(DBG_IMC, " %#B for '%s'", &measurement, filename);
|
|
|
|
measurements->add(measurements, filename, measurement);
|
|
|
|
}
|
|
|
|
hasher->destroy(hasher);
|
|
|
|
|
|
|
|
return measurements;
|
2011-08-24 07:34:55 +00:00
|
|
|
}
|
|
|
|
|
2011-08-20 21:37:37 +00:00
|
|
|
METHOD(pts_t, destroy, void,
|
2011-09-02 07:39:11 +00:00
|
|
|
private_pts_t *this)
|
2011-08-20 21:37:37 +00:00
|
|
|
{
|
2011-09-01 13:42:35 +00:00
|
|
|
free(this->platform_info);
|
2011-08-20 21:37:37 +00:00
|
|
|
free(this->tpm_version_info.ptr);
|
|
|
|
free(this);
|
|
|
|
}
|
|
|
|
|
2011-08-21 18:00:15 +00:00
|
|
|
/**
|
|
|
|
* Check for a TPM by querying for TPM Version Info
|
|
|
|
*/
|
|
|
|
static bool has_tpm(private_pts_t *this)
|
|
|
|
{
|
|
|
|
TSS_HCONTEXT hContext;
|
|
|
|
TSS_HTPM hTPM;
|
|
|
|
TSS_RESULT result;
|
|
|
|
|
|
|
|
result = Tspi_Context_Create(&hContext);
|
|
|
|
if (result != TSS_SUCCESS)
|
|
|
|
{
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
result = Tspi_Context_Connect(hContext, NULL);
|
|
|
|
if (result != TSS_SUCCESS)
|
|
|
|
{
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
result = Tspi_Context_GetTpmObject (hContext, &hTPM);
|
|
|
|
if (result != TSS_SUCCESS)
|
|
|
|
{
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
result = Tspi_TPM_GetCapability(hTPM, TSS_TPMCAP_VERSION_VAL, 0, NULL,
|
|
|
|
&this->tpm_version_info.len,
|
|
|
|
&this->tpm_version_info.ptr);
|
|
|
|
if (result != TSS_SUCCESS)
|
|
|
|
{
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
this->tpm_version_info = chunk_clone(this->tpm_version_info);
|
|
|
|
return TRUE;
|
|
|
|
|
2011-09-02 07:39:11 +00:00
|
|
|
err:
|
2011-09-02 14:07:39 +00:00
|
|
|
DBG1(DBG_IMC, "TPM not available: tss error 0x%x", result);
|
2011-08-21 18:00:15 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-08-20 21:37:37 +00:00
|
|
|
/**
|
|
|
|
* See header
|
|
|
|
*/
|
2011-08-21 08:38:51 +00:00
|
|
|
pts_t *pts_create(bool is_imc)
|
2011-08-20 21:37:37 +00:00
|
|
|
{
|
|
|
|
private_pts_t *this;
|
|
|
|
|
|
|
|
INIT(this,
|
2011-09-02 07:39:11 +00:00
|
|
|
.public = {
|
|
|
|
.get_proto_caps = _get_proto_caps,
|
|
|
|
.set_proto_caps = _set_proto_caps,
|
|
|
|
.get_meas_algorithm = _get_meas_algorithm,
|
|
|
|
.set_meas_algorithm = _set_meas_algorithm,
|
|
|
|
.get_platform_info = _get_platform_info,
|
|
|
|
.set_platform_info = _set_platform_info,
|
|
|
|
.get_tpm_version_info = _get_tpm_version_info,
|
|
|
|
.set_tpm_version_info = _set_tpm_version_info,
|
|
|
|
.get_aik = _get_aik,
|
2011-09-02 14:07:39 +00:00
|
|
|
.set_aik_cert = _set_aik_cert,
|
|
|
|
.set_aik_key = _set_aik_key,
|
2011-09-02 07:39:11 +00:00
|
|
|
.do_measurements = _do_measurements,
|
|
|
|
.destroy = _destroy,
|
|
|
|
},
|
|
|
|
.proto_caps = PTS_PROTO_CAPS_V,
|
|
|
|
.algorithm = PTS_MEAS_ALGO_SHA256,
|
2011-08-20 21:37:37 +00:00
|
|
|
);
|
|
|
|
|
2011-08-21 18:00:15 +00:00
|
|
|
if (is_imc)
|
|
|
|
{
|
|
|
|
if (has_tpm(this))
|
|
|
|
{
|
|
|
|
this->has_tpm = TRUE;
|
|
|
|
this->proto_caps |= PTS_PROTO_CAPS_T;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2011-08-21 08:38:51 +00:00
|
|
|
{
|
2011-08-21 18:00:15 +00:00
|
|
|
this->proto_caps |= PTS_PROTO_CAPS_T | PTS_PROTO_CAPS_C;
|
2011-08-21 08:38:51 +00:00
|
|
|
}
|
|
|
|
|
2011-08-20 21:37:37 +00:00
|
|
|
return &this->public;
|
|
|
|
}
|
|
|
|
|