Refactoring to tpm_tss_quote_info object
This commit is contained in:
+74
-128
@@ -622,14 +622,13 @@ METHOD(pts_t, extend_pcr, bool,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
METHOD(pts_t, quote_tpm, bool,
|
||||
private_pts_t *this, bool use_quote2, bool use_version_info,
|
||||
chunk_t *pcr_comp, chunk_t *quote_sig)
|
||||
METHOD(pts_t, quote, bool,
|
||||
private_pts_t *this, tpm_quote_mode_t *quote_mode,
|
||||
tpm_tss_quote_info_t **quote_info, chunk_t *quote_sig)
|
||||
{
|
||||
chunk_t pcr_value;
|
||||
chunk_t pcr_value, pcr_computed;
|
||||
uint32_t pcr, pcr_sel = 0;
|
||||
enumerator_t *enumerator;
|
||||
tpm_quote_mode_t quote_mode;
|
||||
|
||||
/* select PCRs */
|
||||
DBG2(DBG_PTS, "PCR values hashed into PCR Composite:");
|
||||
@@ -638,7 +637,9 @@ METHOD(pts_t, quote_tpm, bool,
|
||||
{
|
||||
if (this->tpm->read_pcr(this->tpm, pcr, &pcr_value, HASH_SHA1))
|
||||
{
|
||||
DBG2(DBG_PTS, "PCR %2d %#B", pcr, &pcr_value);
|
||||
pcr_computed = this->pcrs->get(this->pcrs, pcr);
|
||||
DBG2(DBG_PTS, "PCR %2d %#B %s", pcr, &pcr_value,
|
||||
chunk_equals(pcr_value, pcr_computed) ? "ok" : "differs");
|
||||
chunk_free(&pcr_value);
|
||||
};
|
||||
|
||||
@@ -647,36 +648,16 @@ METHOD(pts_t, quote_tpm, bool,
|
||||
}
|
||||
enumerator->destroy(enumerator);
|
||||
|
||||
quote_mode = use_quote2 ? (use_version_info ? TPM_QUOTE2_VERSION_INFO :
|
||||
TPM_QUOTE2) : TPM_QUOTE;
|
||||
|
||||
/* TPM Quote */
|
||||
return this->tpm->quote(this->tpm, this->aik_handle, pcr_sel, HASH_SHA1,
|
||||
this->secret, quote_mode, pcr_comp, quote_sig);
|
||||
this->secret, quote_mode, quote_info, quote_sig);
|
||||
}
|
||||
|
||||
/**
|
||||
* TPM_QUOTE_INFO structure:
|
||||
* 4 bytes of version
|
||||
* 4 bytes 'Q' 'U' 'O' 'T'
|
||||
* 20 byte SHA1 of TCPA_PCR_COMPOSITE
|
||||
* 20 byte nonce
|
||||
*
|
||||
* TPM_QUOTE_INFO2 structure:
|
||||
* 2 bytes Tag 0x0036 TPM_Tag_Quote_info2
|
||||
* 4 bytes 'Q' 'U' 'T' '2'
|
||||
* 20 bytes nonce
|
||||
* 26 bytes PCR_INFO_SHORT
|
||||
*/
|
||||
|
||||
METHOD(pts_t, get_quote_info, bool,
|
||||
private_pts_t *this, bool use_quote2, bool use_version_info,
|
||||
pts_meas_algorithms_t comp_hash_algo,
|
||||
chunk_t *out_pcr_comp, chunk_t *out_quote_info)
|
||||
METHOD(pts_t, get_quote, bool,
|
||||
private_pts_t *this, tpm_tss_quote_info_t *quote_info, chunk_t *quoted)
|
||||
{
|
||||
chunk_t selection, pcr_comp, hash_pcr_comp;
|
||||
bio_writer_t *writer;
|
||||
hasher_t *hasher;
|
||||
tpm_tss_pcr_composite_t *pcr_composite;
|
||||
bool success;
|
||||
|
||||
if (!this->pcrs->get_count(this->pcrs))
|
||||
{
|
||||
@@ -690,111 +671,33 @@ METHOD(pts_t, get_quote_info, bool,
|
||||
"unable to construct TPM Quote Info");
|
||||
return FALSE;
|
||||
}
|
||||
if (use_quote2 && use_version_info && !this->tpm_version_info.ptr)
|
||||
if (quote_info->get_quote_mode(quote_info) == TPM_QUOTE2_VERSION_INFO)
|
||||
{
|
||||
DBG1(DBG_PTS, "TPM Version Information unavailable, ",
|
||||
"unable to construct TPM Quote Info2");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
pcr_comp = this->pcrs->get_composite(this->pcrs);
|
||||
|
||||
|
||||
/* Output the TPM_PCR_COMPOSITE expected from IMC */
|
||||
if (comp_hash_algo)
|
||||
{
|
||||
hash_algorithm_t algo;
|
||||
|
||||
algo = pts_meas_algo_to_hash(comp_hash_algo);
|
||||
hasher = lib->crypto->create_hasher(lib->crypto, algo);
|
||||
|
||||
/* Hash the PCR Composite Structure */
|
||||
if (!hasher || !hasher->allocate_hash(hasher, pcr_comp, out_pcr_comp))
|
||||
if (!this->tpm_version_info.ptr)
|
||||
{
|
||||
DESTROY_IF(hasher);
|
||||
free(pcr_comp.ptr);
|
||||
DBG1(DBG_PTS, "TPM Version Information unavailable, ",
|
||||
"unable to construct TPM Quote Info2");
|
||||
return FALSE;
|
||||
}
|
||||
DBG3(DBG_PTS, "constructed PCR Composite hash: %#B", out_pcr_comp);
|
||||
hasher->destroy(hasher);
|
||||
}
|
||||
else
|
||||
{
|
||||
*out_pcr_comp = chunk_clone(pcr_comp);
|
||||
quote_info->set_version_info(quote_info, this->tpm_version_info);
|
||||
}
|
||||
pcr_composite = this->pcrs->get_composite(this->pcrs);
|
||||
|
||||
/* SHA1 hash of PCR Composite to construct TPM_QUOTE_INFO */
|
||||
hasher = lib->crypto->create_hasher(lib->crypto, HASH_SHA1);
|
||||
if (!hasher || !hasher->allocate_hash(hasher, pcr_comp, &hash_pcr_comp))
|
||||
{
|
||||
DESTROY_IF(hasher);
|
||||
chunk_free(out_pcr_comp);
|
||||
free(pcr_comp.ptr);
|
||||
return FALSE;
|
||||
}
|
||||
hasher->destroy(hasher);
|
||||
success = quote_info->get_quote(quote_info, this->secret,
|
||||
pcr_composite, quoted);
|
||||
chunk_free(&pcr_composite->pcr_select);
|
||||
chunk_free(&pcr_composite->pcr_composite);
|
||||
free(pcr_composite);
|
||||
|
||||
/* Construct TPM_QUOTE_INFO/TPM_QUOTE_INFO2 structure */
|
||||
writer = bio_writer_create(TPM_QUOTE_INFO_LEN);
|
||||
|
||||
if (use_quote2)
|
||||
{
|
||||
/* TPM Structure Tag */
|
||||
writer->write_uint16(writer, TPM_TAG_QUOTE_INFO2);
|
||||
|
||||
/* Magic QUT2 value */
|
||||
writer->write_data(writer, chunk_create("QUT2", 4));
|
||||
|
||||
/* Secret assessment value 20 bytes (nonce) */
|
||||
writer->write_data(writer, this->secret);
|
||||
|
||||
/* PCR selection */
|
||||
selection.ptr = pcr_comp.ptr;
|
||||
selection.len = 2 + this->pcrs->get_selection_size(this->pcrs);
|
||||
writer->write_data(writer, selection);
|
||||
|
||||
/* TPM Locality Selection */
|
||||
writer->write_uint8(writer, TPM_LOC_ZERO);
|
||||
|
||||
/* PCR Composite Hash */
|
||||
writer->write_data(writer, hash_pcr_comp);
|
||||
|
||||
if (use_version_info)
|
||||
{
|
||||
/* TPM version Info */
|
||||
writer->write_data(writer, this->tpm_version_info);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Version number */
|
||||
writer->write_data(writer, chunk_from_chars(1, 1, 0, 0));
|
||||
|
||||
/* Magic QUOT value */
|
||||
writer->write_data(writer, chunk_create("QUOT", 4));
|
||||
|
||||
/* PCR Composite Hash */
|
||||
writer->write_data(writer, hash_pcr_comp);
|
||||
|
||||
/* Secret assessment value 20 bytes (nonce) */
|
||||
writer->write_data(writer, this->secret);
|
||||
}
|
||||
|
||||
/* TPM Quote Info */
|
||||
*out_quote_info = writer->extract_buf(writer);
|
||||
DBG3(DBG_PTS, "constructed TPM Quote Info: %B", out_quote_info);
|
||||
|
||||
writer->destroy(writer);
|
||||
free(pcr_comp.ptr);
|
||||
free(hash_pcr_comp.ptr);
|
||||
|
||||
return TRUE;
|
||||
return success;
|
||||
}
|
||||
|
||||
METHOD(pts_t, verify_quote_signature, bool,
|
||||
private_pts_t *this, chunk_t data, chunk_t signature)
|
||||
private_pts_t *this, hash_algorithm_t digest_alg, chunk_t digest,
|
||||
chunk_t signature)
|
||||
{
|
||||
public_key_t *aik_pubkey;
|
||||
signature_scheme_t scheme;
|
||||
|
||||
aik_pubkey = this->aik_cert->get_public_key(this->aik_cert);
|
||||
if (!aik_pubkey)
|
||||
@@ -803,8 +706,51 @@ METHOD(pts_t, verify_quote_signature, bool,
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!aik_pubkey->verify(aik_pubkey, SIGN_RSA_EMSA_PKCS1_SHA1,
|
||||
data, signature))
|
||||
/* Determine signing scheme */
|
||||
switch (aik_pubkey->get_type(aik_pubkey))
|
||||
{
|
||||
case KEY_RSA:
|
||||
switch (digest_alg)
|
||||
{
|
||||
case HASH_SHA1:
|
||||
scheme = SIGN_RSA_EMSA_PKCS1_SHA1;
|
||||
break;
|
||||
case HASH_SHA256:
|
||||
scheme = SIGN_RSA_EMSA_PKCS1_SHA256;
|
||||
break;
|
||||
case HASH_SHA384:
|
||||
scheme = SIGN_RSA_EMSA_PKCS1_SHA384;
|
||||
break;
|
||||
case HASH_SHA512:
|
||||
scheme = SIGN_RSA_EMSA_PKCS1_SHA512;
|
||||
break;
|
||||
default:
|
||||
scheme = SIGN_UNKNOWN;
|
||||
}
|
||||
break;
|
||||
case KEY_ECDSA:
|
||||
switch (digest_alg)
|
||||
{
|
||||
case HASH_SHA256:
|
||||
scheme = SIGN_ECDSA_256;
|
||||
break;
|
||||
case HASH_SHA384:
|
||||
scheme = SIGN_ECDSA_384;
|
||||
break;
|
||||
case HASH_SHA512:
|
||||
scheme = SIGN_ECDSA_521;
|
||||
break;
|
||||
default:
|
||||
scheme = SIGN_UNKNOWN;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
DBG1(DBG_PTS, "%N AIK key type not supported", key_type_names,
|
||||
aik_pubkey->get_type(aik_pubkey));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!aik_pubkey->verify(aik_pubkey, scheme, digest, signature))
|
||||
{
|
||||
DBG1(DBG_PTS, "signature verification failed for TPM Quote Info");
|
||||
DESTROY_IF(aik_pubkey);
|
||||
@@ -873,9 +819,9 @@ pts_t *pts_create(bool is_imc)
|
||||
.get_metadata = _get_metadata,
|
||||
.read_pcr = _read_pcr,
|
||||
.extend_pcr = _extend_pcr,
|
||||
.quote_tpm = _quote_tpm,
|
||||
.quote = _quote,
|
||||
.get_pcrs = _get_pcrs,
|
||||
.get_quote_info = _get_quote_info,
|
||||
.get_quote = _get_quote,
|
||||
.verify_quote_signature = _verify_quote_signature,
|
||||
.destroy = _destroy,
|
||||
},
|
||||
|
||||
+18
-26
@@ -32,9 +32,10 @@ typedef struct pts_t pts_t;
|
||||
#include "pts_dh_group.h"
|
||||
#include "pts_pcr.h"
|
||||
#include "pts_req_func_comp_evid.h"
|
||||
#include "pts_simple_evid_final.h"
|
||||
#include "components/pts_comp_func_name.h"
|
||||
|
||||
#include <tpm_tss_quote_info.h>
|
||||
|
||||
#include <library.h>
|
||||
#include <collections/linked_list.h>
|
||||
|
||||
@@ -70,11 +71,6 @@ typedef struct pts_t pts_t;
|
||||
*/
|
||||
#define ASSESSMENT_SECRET_LEN 20
|
||||
|
||||
/**
|
||||
* Length of the TPM_QUOTE_INFO structure, TPM Spec 1.2
|
||||
*/
|
||||
#define TPM_QUOTE_INFO_LEN 48
|
||||
|
||||
/**
|
||||
* Hashing algorithm used by tboot and trustedGRUB
|
||||
*/
|
||||
@@ -262,15 +258,13 @@ struct pts_t {
|
||||
* Quote over PCR's
|
||||
* Expects owner and SRK secret to be WELL_KNOWN_SECRET and no password set for AIK
|
||||
*
|
||||
* @param use_quote2 Version of the Quote function to be used
|
||||
* @param use_version_info Version info is concatenated to TPM_QUOTE_INFO2
|
||||
* @param pcr_comp Chunk to save PCR composite structure
|
||||
* @param quote_sig Chunk to save quote operation output
|
||||
* without external data (anti-replay protection)
|
||||
* @return FALSE in case of TSS error, TRUE otherwise
|
||||
* @param quote_mode type of Quote signature
|
||||
* @param quote_info returns various info covered by Quote signature
|
||||
* @param quote_sig returns Quote signature
|
||||
* @return FALSE in case of Quote error, TRUE otherwise
|
||||
*/
|
||||
bool (*quote_tpm)(pts_t *this, bool use_quote2, bool use_version_info,
|
||||
chunk_t *pcr_comp, chunk_t *quote_sig);
|
||||
bool (*quote)(pts_t *this, tpm_quote_mode_t *quote_mode,
|
||||
tpm_tss_quote_info_t **quote_info, chunk_t *quote_sig);
|
||||
|
||||
/**
|
||||
* Get the shadow PCR set
|
||||
@@ -279,28 +273,26 @@ struct pts_t {
|
||||
*/
|
||||
pts_pcr_t* (*get_pcrs)(pts_t *this);
|
||||
|
||||
/**
|
||||
* Constructs and returns TPM Quote Info structure expected from IMC
|
||||
/**
|
||||
* Computes digest of the constructed TPM Quote Info structure
|
||||
*
|
||||
* @param use_quote2 Version of the TPM_QUOTE_INFO to be constructed
|
||||
* @param use_version_info Version info is concatenated to TPM_QUOTE_INFO2
|
||||
* @param comp_hash_algo Composite Hash Algorithm
|
||||
* @param pcr_comp Output variable to store PCR Composite
|
||||
* @param quote_info Output variable to store TPM Quote Info
|
||||
* @param quote_info TPM Quote Info as received from IMC
|
||||
* @param quoted Encoding of TPM Quote Info
|
||||
* @return FALSE in case of any error, TRUE otherwise
|
||||
*/
|
||||
bool (*get_quote_info)(pts_t *this, bool use_quote2, bool use_version_info,
|
||||
pts_meas_algorithms_t comp_hash_algo,
|
||||
chunk_t *pcr_comp, chunk_t *quote_info);
|
||||
bool (*get_quote)(pts_t *this, tpm_tss_quote_info_t *quote_info,
|
||||
chunk_t *quoted);
|
||||
|
||||
/**
|
||||
* Constructs and returns PCR Quote Digest structure expected from IMC
|
||||
*
|
||||
* @param data Calculated TPM Quote Digest
|
||||
* @param digest_alg Hash algorithm used for TPM Quote Digest
|
||||
* @param digest Calculated TPM Quote Digest
|
||||
* @param signature TPM Quote Signature received from IMC
|
||||
* @return FALSE if signature is not verified
|
||||
*/
|
||||
bool (*verify_quote_signature)(pts_t *this, chunk_t data, chunk_t signature);
|
||||
bool (*verify_quote_signature)(pts_t *this, hash_algorithm_t digest_alg,
|
||||
chunk_t digest, chunk_t signature);
|
||||
|
||||
/**
|
||||
* Destroys a pts_t object.
|
||||
|
||||
@@ -155,6 +155,24 @@ hash_algorithm_t pts_meas_algo_to_hash(pts_meas_algorithms_t algorithm)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Described in header.
|
||||
*/
|
||||
pts_meas_algorithms_t pts_meas_algo_from_hash(hash_algorithm_t algorithm)
|
||||
{
|
||||
switch (algorithm)
|
||||
{
|
||||
case HASH_SHA1:
|
||||
return PTS_MEAS_ALGO_SHA1;
|
||||
case HASH_SHA256:
|
||||
return PTS_MEAS_ALGO_SHA256;
|
||||
case HASH_SHA384:
|
||||
return PTS_MEAS_ALGO_SHA384;
|
||||
default:
|
||||
return PTS_MEAS_ALGO_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Described in header.
|
||||
*/
|
||||
|
||||
@@ -95,6 +95,14 @@ pts_meas_algorithms_t pts_meas_algo_select(pts_meas_algorithms_t supported_algos
|
||||
*/
|
||||
hash_algorithm_t pts_meas_algo_to_hash(pts_meas_algorithms_t algorithm);
|
||||
|
||||
/**
|
||||
* Convert hash_algorithm_t to pts_meas_algorithms_t
|
||||
*
|
||||
* @param algorithm PTS measurement algorithm type
|
||||
* @return libstrongswan hash algorithm type
|
||||
*/
|
||||
pts_meas_algorithms_t pts_meas_algo_from_hash(hash_algorithm_t algorithm);
|
||||
|
||||
/**
|
||||
* Return the hash size of a pts_meas_algorithm
|
||||
*
|
||||
|
||||
+10
-12
@@ -200,10 +200,10 @@ METHOD(pts_pcr_t, extend, chunk_t,
|
||||
return this->pcrs[pcr];
|
||||
}
|
||||
|
||||
METHOD(pts_pcr_t, get_composite, chunk_t,
|
||||
METHOD(pts_pcr_t, get_composite, tpm_tss_pcr_composite_t*,
|
||||
private_pts_pcr_t *this)
|
||||
{
|
||||
chunk_t composite;
|
||||
tpm_tss_pcr_composite_t *pcr_composite;
|
||||
enumerator_t *enumerator;
|
||||
uint16_t selection_size;
|
||||
uint32_t pcr_field_size, pcr;
|
||||
@@ -212,14 +212,13 @@ METHOD(pts_pcr_t, get_composite, chunk_t,
|
||||
selection_size = get_selection_size(this);
|
||||
pcr_field_size = this->pcr_count * PTS_PCR_LEN;
|
||||
|
||||
composite = chunk_alloc(2 + selection_size + 4 + pcr_field_size);
|
||||
pos = composite.ptr;
|
||||
htoun16(pos, selection_size);
|
||||
pos += 2;
|
||||
memcpy(pos, this->pcr_select, selection_size);
|
||||
pos += selection_size;
|
||||
htoun32(pos, pcr_field_size);
|
||||
pos += 4;
|
||||
INIT(pcr_composite,
|
||||
.pcr_select = chunk_alloc(selection_size),
|
||||
.pcr_composite = chunk_alloc(pcr_field_size),
|
||||
);
|
||||
|
||||
memcpy(pcr_composite->pcr_select.ptr, this->pcr_select, selection_size);
|
||||
pos = pcr_composite->pcr_composite.ptr;
|
||||
|
||||
enumerator = create_enumerator(this);
|
||||
while (enumerator->enumerate(enumerator, &pcr))
|
||||
@@ -229,8 +228,7 @@ METHOD(pts_pcr_t, get_composite, chunk_t,
|
||||
}
|
||||
enumerator->destroy(enumerator);
|
||||
|
||||
DBG3(DBG_PTS, "constructed PCR Composite: %B", &composite);
|
||||
return composite;
|
||||
return pcr_composite;
|
||||
}
|
||||
|
||||
METHOD(pts_pcr_t, destroy, void,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2012 Andreas Steffen
|
||||
* Copyright (C) 2012-2016 Andreas Steffen
|
||||
* HSR Hochschule fuer Technik Rapperswil
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
@@ -25,6 +25,8 @@ typedef struct pts_pcr_t pts_pcr_t;
|
||||
|
||||
#include <library.h>
|
||||
|
||||
#include <tpm_tss_quote_info.h>
|
||||
|
||||
/**
|
||||
* Maximum number of PCR's of TPM, TPM Spec 1.2
|
||||
*/
|
||||
@@ -100,7 +102,7 @@ struct pts_pcr_t {
|
||||
*
|
||||
* @return PCR Composite object (must be freed)
|
||||
*/
|
||||
chunk_t (*get_composite)(pts_pcr_t *this);
|
||||
tpm_tss_pcr_composite_t* (*get_composite)(pts_pcr_t *this);
|
||||
|
||||
/**
|
||||
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup pts_simple_evid_final pts_rsimple_evid_final
|
||||
* @{ @ingroup pts
|
||||
*/
|
||||
|
||||
#ifndef PTS_SIMPLE_EVID_FINAL_H_
|
||||
#define PTS_SIMPLE_EVID_FINAL_H_
|
||||
|
||||
typedef enum pts_simple_evid_final_flag_t pts_simple_evid_final_flag_t;
|
||||
|
||||
#include <library.h>
|
||||
|
||||
/**
|
||||
* PTS Simple Evidence Final Flags
|
||||
*/
|
||||
enum pts_simple_evid_final_flag_t {
|
||||
/** TPM PCR Composite and TPM Quote Signature not included */
|
||||
PTS_SIMPLE_EVID_FINAL_NO = 0x00,
|
||||
/** TPM PCR Composite and TPM Quote Signature included
|
||||
* using TPM_QUOTE_INFO */
|
||||
PTS_SIMPLE_EVID_FINAL_QUOTE_INFO = 0x40,
|
||||
/** TPM PCR Composite and TPM Quote Signature included
|
||||
* using TPM_QUOTE_INFO2, TPM_CAP_VERSION_INFO not appended */
|
||||
PTS_SIMPLE_EVID_FINAL_QUOTE_INFO2 = 0x80,
|
||||
/** TPM PCR Composite and TPM Quote Signature included
|
||||
* using TPM_QUOTE_INFO2, TPM_CAP_VERSION_INFO appended */
|
||||
PTS_SIMPLE_EVID_FINAL_QUOTE_INFO2_CAP_VER = 0xC0,
|
||||
/** Evidence Signature included */
|
||||
PTS_SIMPLE_EVID_FINAL_EVID_SIG = 0x20,
|
||||
};
|
||||
|
||||
#endif /** PTS_SIMPLE_EVID_FINAL_H_ @}*/
|
||||
Reference in New Issue
Block a user