use libstrongswan hasher
This commit is contained in:
@@ -36,16 +36,14 @@
|
|||||||
|
|
||||||
#include <trousers/tss.h>
|
#include <trousers/tss.h>
|
||||||
#include <trousers/trousers.h>
|
#include <trousers/trousers.h>
|
||||||
#include <openssl/sha.h>
|
|
||||||
|
|
||||||
|
|
||||||
/* IMC definitions */
|
/* IMC definitions */
|
||||||
|
|
||||||
static const char imc_name[] = "Attestation";
|
static const char imc_name[] = "Attestation";
|
||||||
|
|
||||||
#define IMC_VENDOR_ID PEN_TCG
|
#define IMC_VENDOR_ID PEN_TCG
|
||||||
#define IMC_SUBTYPE PA_SUBTYPE_TCG_PTS
|
#define IMC_SUBTYPE PA_SUBTYPE_TCG_PTS
|
||||||
#define IMC_ATTESTATION_MAX_FILE_SIZE 32768
|
#define IMC_ATTESTATION_BUF_SIZE 32768
|
||||||
|
|
||||||
static imc_agent_t *imc_attestation;
|
static imc_agent_t *imc_attestation;
|
||||||
|
|
||||||
@@ -163,78 +161,48 @@ static TSS_RESULT get_tpm_version_info(BYTE *tpm_version_info)
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Hash Measurement of a file
|
* Get Hash Measurement of a file
|
||||||
* Uses openssl's sha.h
|
|
||||||
*/
|
*/
|
||||||
static TNC_Result hash_file(char *path, unsigned char *out)
|
static TNC_Result hash_file(char *path, unsigned char *out)
|
||||||
{
|
{
|
||||||
BYTE *buffer;
|
BYTE buffer[IMC_ATTESTATION_BUF_SIZE];
|
||||||
FILE *file;
|
FILE *file;
|
||||||
int bytesRead = 0;
|
int bytes_read;
|
||||||
|
hasher_t *hasher;
|
||||||
|
hash_algorithm_t hash_alg;
|
||||||
|
|
||||||
file = fopen(path, "rb");
|
/* Create a hasher */
|
||||||
if (!file) {
|
hash_alg = tcg_pts_meas_to_hash_algorithm(selected_algorithm);
|
||||||
DBG1(DBG_IMC,"File can not be opened %s\n", path);
|
hasher = lib->crypto->create_hasher(lib->crypto, hash_alg);
|
||||||
|
if (!hasher)
|
||||||
|
{
|
||||||
|
DBG1(DBG_IMC, "hasher %N not available", hash_algorithm_names, hash_alg);
|
||||||
return TNC_RESULT_FATAL;
|
return TNC_RESULT_FATAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer = malloc(IMC_ATTESTATION_MAX_FILE_SIZE);
|
file = fopen(path, "rb");
|
||||||
if(!buffer)
|
if (!file)
|
||||||
{
|
{
|
||||||
DBG1(DBG_IMC,"Buffer couldn't be allocated memory");
|
DBG1(DBG_IMC,"file '%s' can not be opened", path);
|
||||||
goto fatal;
|
hasher->destroy(hasher);
|
||||||
|
return TNC_RESULT_FATAL;
|
||||||
}
|
}
|
||||||
|
while (TRUE)
|
||||||
switch(selected_algorithm)
|
|
||||||
{
|
{
|
||||||
case PTS_MEAS_ALGO_SHA1:
|
bytes_read = fread(buffer, 1, sizeof(buffer), file);
|
||||||
|
if (bytes_read > 0)
|
||||||
{
|
{
|
||||||
SHA_CTX sha1;
|
hasher->get_hash(hasher, chunk_create(buffer, bytes_read), NULL);
|
||||||
SHA1_Init(&sha1);
|
|
||||||
|
|
||||||
while((bytesRead = fread(buffer, 1, IMC_ATTESTATION_MAX_FILE_SIZE, file)))
|
|
||||||
{
|
|
||||||
SHA1_Update(&sha1, buffer, bytesRead);
|
|
||||||
}
|
|
||||||
SHA1_Final(out, &sha1);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
case PTS_MEAS_ALGO_SHA256:
|
else
|
||||||
{
|
{
|
||||||
SHA256_CTX sha256;
|
hasher->get_hash(hasher, chunk_empty, out);
|
||||||
SHA256_Init(&sha256);
|
|
||||||
|
|
||||||
while((bytesRead = fread(buffer, 1, IMC_ATTESTATION_MAX_FILE_SIZE, file)))
|
|
||||||
{
|
|
||||||
SHA256_Update(&sha256, buffer, bytesRead);
|
|
||||||
}
|
|
||||||
SHA256_Final(out, &sha256);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PTS_MEAS_ALGO_SHA384:
|
|
||||||
/*{
|
|
||||||
SHA384_CTX sha384;
|
|
||||||
SHA384_Init(&sha384);
|
|
||||||
|
|
||||||
while((bytesRead = fread(buffer, 1, IMC_ATTESTATION_MAX_FILE_SIZE, file)))
|
|
||||||
{
|
|
||||||
SHA384_Update(&sha384, buffer, bytesRead);
|
|
||||||
}
|
|
||||||
SHA384_Final(out, &sha384);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
default:
|
|
||||||
DBG1(DBG_IMC,"Unsupported Selected Hashing Algorithm \n");
|
|
||||||
return TNC_RESULT_FATAL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(file);
|
fclose(file);
|
||||||
free(buffer);
|
hasher->destroy(hasher);
|
||||||
|
|
||||||
return TNC_RESULT_SUCCESS;
|
return TNC_RESULT_SUCCESS;
|
||||||
|
|
||||||
fatal:
|
|
||||||
fclose(file);
|
|
||||||
return TNC_RESULT_FATAL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static TNC_Result send_message(TNC_ConnectionID connection_id)
|
static TNC_Result send_message(TNC_ConnectionID connection_id)
|
||||||
|
|||||||
Reference in New Issue
Block a user