Enforced strongSwan coding rules (tab, if, {)

This commit is contained in:
Sansar Choinyambuu
2011-09-08 12:08:16 +02:00
committed by Andreas Steffen
parent 0f36d4815e
commit 05a1b347b2
33 changed files with 481 additions and 449 deletions
+63 -37
View File
@@ -213,13 +213,14 @@ static TSS_RESULT makeEKCert(TSS_HCONTEXT hContext, TSS_HTPM hTPM, UINT32 *pCert
DBG1(DBG_IMC, "Error in: Tspi_Context_CloseObject"); DBG1(DBG_IMC, "Error in: Tspi_Context_CloseObject");
return result; return result;
} }
if (modulusLen != 256) { if (modulusLen != 256)
{
DBG1(DBG_IMC, "Tspi_GetAttribData modulusLen != 256"); DBG1(DBG_IMC, "Tspi_GetAttribData modulusLen != 256");
Tspi_Context_FreeMemory (hContext, modulus); Tspi_Context_FreeMemory (hContext, modulus);
return result; return result;
} }
/* TODO define fakeEKCert /* TODO define fakeEKCert
*pCertLen = sizeof(fakeEKCert); * pCertLen = sizeof(fakeEKCert);
*pCert = malloc (*pCertLen); *pCert = malloc (*pCertLen);
memcpy (*pCert, fakeEKCert, *pCertLen); memcpy (*pCert, fakeEKCert, *pCertLen);
memcpy (*pCert + 0xc6, modulus, modulusLen); memcpy (*pCert + 0xc6, modulus, modulusLen);
@@ -247,7 +248,8 @@ static X509* readPCAcert (int level)
curl_easy_setopt (hCurl, CURLOPT_URL, url); curl_easy_setopt (hCurl, CURLOPT_URL, url);
curl_easy_setopt(hCurl, CURLOPT_WRITEDATA, (BYTE **)f_tmp); curl_easy_setopt(hCurl, CURLOPT_WRITEDATA, (BYTE **)f_tmp);
if ((result = curl_easy_perform(hCurl))) { if ((result = curl_easy_perform(hCurl)))
{
DBG1(DBG_IMC, "Unable to connect to Privacy CA, curl library result code %d", result); DBG1(DBG_IMC, "Unable to connect to Privacy CA, curl library result code %d", result);
fclose(f_tmp); fclose(f_tmp);
return NULL; return NULL;
@@ -309,61 +311,71 @@ static bool obtain_aik(private_pts_t *this)
DBG3(DBG_IMC, "Retrieving PCA certificate..."); DBG3(DBG_IMC, "Retrieving PCA certificate...");
/* TPM has EK Certificate */ /* TPM has EK Certificate */
if(REALEK) if (REALEK)
{ {
level = 1; level = 1;
} }
x509 = readPCAcert (level); x509 = readPCAcert (level);
if (x509 == NULL) { if (x509 == NULL)
{
DBG1(DBG_IMC, "Error reading PCA key"); DBG1(DBG_IMC, "Error reading PCA key");
goto err; goto err;
} }
pcaKey = X509_get_pubkey(x509); pcaKey = X509_get_pubkey(x509);
rsa = EVP_PKEY_get1_RSA(pcaKey); rsa = EVP_PKEY_get1_RSA(pcaKey);
if (rsa == NULL) { if (rsa == NULL)
{
DBG1(DBG_IMC, "Error reading RSA key from PCA"); DBG1(DBG_IMC, "Error reading RSA key from PCA");
goto err; goto err;
} }
X509_free (x509); X509_free (x509);
result = Tspi_Context_Create(&hContext); result = Tspi_Context_Create(&hContext);
if (result != TSS_SUCCESS) { if (result != TSS_SUCCESS)
{
DBG1(DBG_IMC, "Error 0x%x on Tspi_Context_Create", result); DBG1(DBG_IMC, "Error 0x%x on Tspi_Context_Create", result);
goto err; goto err;
} }
result = Tspi_Context_Connect(hContext, NULL); result = Tspi_Context_Connect(hContext, NULL);
if (result != TSS_SUCCESS) { if (result != TSS_SUCCESS)
{
DBG1(DBG_IMC, "Error 0x%x on Tspi_Context_Connect", result); DBG1(DBG_IMC, "Error 0x%x on Tspi_Context_Connect", result);
goto err; goto err;
} }
result = Tspi_Context_GetTpmObject (hContext, &hTPM); result = Tspi_Context_GetTpmObject (hContext, &hTPM);
if (result != TSS_SUCCESS) { if (result != TSS_SUCCESS)
{
DBG1(DBG_IMC, "Error 0x%x on Tspi_Context_GetTpmObject", result); DBG1(DBG_IMC, "Error 0x%x on Tspi_Context_GetTpmObject", result);
goto err; goto err;
} }
result = Tspi_Context_LoadKeyByUUID(hContext, result = Tspi_Context_LoadKeyByUUID(hContext,
TSS_PS_TYPE_SYSTEM, SRK_UUID, &hSRK); TSS_PS_TYPE_SYSTEM, SRK_UUID, &hSRK);
if (result != TSS_SUCCESS) { if (result != TSS_SUCCESS)
{
DBG1(DBG_IMC, "Error 0x%x on Tspi_Context_LoadKeyByUUID for SRK", result); DBG1(DBG_IMC, "Error 0x%x on Tspi_Context_LoadKeyByUUID for SRK", result);
goto err; goto err;
} }
result = Tspi_GetPolicyObject(hSRK, TSS_POLICY_USAGE, &hSrkPolicy); result = Tspi_GetPolicyObject(hSRK, TSS_POLICY_USAGE, &hSrkPolicy);
if (result != TSS_SUCCESS) { if (result != TSS_SUCCESS)
{
DBG1(DBG_IMC, "Error 0x%x on Tspi_GetPolicyObject for SRK", result); DBG1(DBG_IMC, "Error 0x%x on Tspi_GetPolicyObject for SRK", result);
goto err; goto err;
} }
result = Tspi_Policy_SetSecret(hSrkPolicy, TSS_SECRET_MODE_SHA1, 20, secret); result = Tspi_Policy_SetSecret(hSrkPolicy, TSS_SECRET_MODE_SHA1, 20, secret);
if (result != TSS_SUCCESS) { if (result != TSS_SUCCESS)
{
DBG1(DBG_IMC, "Error 0x%x on Tspi_Policy_SetSecret for SRK", result); DBG1(DBG_IMC, "Error 0x%x on Tspi_Policy_SetSecret for SRK", result);
goto err; goto err;
} }
result = Tspi_GetPolicyObject(hTPM, TSS_POLICY_USAGE, &hTPMPolicy); result = Tspi_GetPolicyObject(hTPM, TSS_POLICY_USAGE, &hTPMPolicy);
if (result != TSS_SUCCESS) { if (result != TSS_SUCCESS)
{
DBG1(DBG_IMC, "Error 0x%x on Tspi_GetPolicyObject for TPM", result); DBG1(DBG_IMC, "Error 0x%x on Tspi_GetPolicyObject for TPM", result);
goto err; goto err;
} }
result = Tspi_Policy_SetSecret(hTPMPolicy, TSS_SECRET_MODE_SHA1, 20, secret); result = Tspi_Policy_SetSecret(hTPMPolicy, TSS_SECRET_MODE_SHA1, 20, secret);
if (result != TSS_SUCCESS) { if (result != TSS_SUCCESS)
{
DBG1(DBG_IMC, "Error 0x%x on Tspi_Policy_SetSecret for TPM", result); DBG1(DBG_IMC, "Error 0x%x on Tspi_Policy_SetSecret for TPM", result);
goto err; goto err;
} }
@@ -371,7 +383,8 @@ static bool obtain_aik(private_pts_t *this)
result = Tspi_Context_CreateObject(hContext, result = Tspi_Context_CreateObject(hContext,
TSS_OBJECT_TYPE_RSAKEY, TSS_OBJECT_TYPE_RSAKEY,
initFlags, &hIdentKey); initFlags, &hIdentKey);
if (result != TSS_SUCCESS) { if (result != TSS_SUCCESS)
{
DBG1(DBG_IMC, "Error 0x%x on Tspi_Context_CreateObject for key", result); DBG1(DBG_IMC, "Error 0x%x on Tspi_Context_CreateObject for key", result);
goto err; goto err;
} }
@@ -380,39 +393,45 @@ static bool obtain_aik(private_pts_t *this)
TSS_OBJECT_TYPE_RSAKEY, TSS_OBJECT_TYPE_RSAKEY,
TSS_KEY_TYPE_LEGACY|TSS_KEY_SIZE_2048, TSS_KEY_TYPE_LEGACY|TSS_KEY_SIZE_2048,
&hPCAKey); &hPCAKey);
if (result != TSS_SUCCESS) { if (result != TSS_SUCCESS)
DBG1(DBG_IMC, "Error 0x%x on Tspi_Context_CreateObject for PCA\n", result); {
DBG1(DBG_IMC, "Error 0x%x on Tspi_Context_CreateObject for PCA", result);
goto err; goto err;
} }
if ((size_n = BN_bn2bin(rsa->n, n)) <= 0) { if ((size_n = BN_bn2bin(rsa->n, n)) <= 0)
printf("BN_bn2bin failed\n"); {
DBG1(DBG_IMC, "BN_bn2bin failed");
goto err;; goto err;;
} }
result = Tspi_SetAttribData (hPCAKey, TSS_TSPATTRIB_RSAKEY_INFO, result = Tspi_SetAttribData (hPCAKey, TSS_TSPATTRIB_RSAKEY_INFO,
TSS_TSPATTRIB_KEYINFO_RSA_MODULUS, size_n, n); TSS_TSPATTRIB_KEYINFO_RSA_MODULUS, size_n, n);
if (result != TSS_SUCCESS) { if (result != TSS_SUCCESS)
{
DBG1(DBG_IMC, "Error 0x%x on Tspi_SetAttribData for PCA modulus", result); DBG1(DBG_IMC, "Error 0x%x on Tspi_SetAttribData for PCA modulus", result);
goto err; goto err;
} }
result = Tspi_SetAttribUint32(hPCAKey, TSS_TSPATTRIB_KEY_INFO, result = Tspi_SetAttribUint32(hPCAKey, TSS_TSPATTRIB_KEY_INFO,
TSS_TSPATTRIB_KEYINFO_ENCSCHEME, TSS_TSPATTRIB_KEYINFO_ENCSCHEME,
TSS_ES_RSAESPKCSV15); TSS_ES_RSAESPKCSV15);
if (result != TSS_SUCCESS) { if (result != TSS_SUCCESS)
{
DBG1(DBG_IMC, "Error 0x%x on Tspi_SetAttribUint32 for PCA encscheme", result); DBG1(DBG_IMC, "Error 0x%x on Tspi_SetAttribUint32 for PCA encscheme", result);
goto err; goto err;
} }
if(!REALEK) if (!REALEK)
{ {
result = makeEKCert(hContext, hTPM, &ekCertLen, &ekCert); result = makeEKCert(hContext, hTPM, &ekCertLen, &ekCert);
if (result != TSS_SUCCESS) { if (result != TSS_SUCCESS)
DBG1(DBG_IMC, "Error 0x%x on makeEKCert\n", result); {
DBG1(DBG_IMC, "Error 0x%x on makeEKCert", result);
goto err; goto err;
} }
result = Tspi_SetAttribData(hTPM, TSS_TSPATTRIB_TPM_CREDENTIAL, result = Tspi_SetAttribData(hTPM, TSS_TSPATTRIB_TPM_CREDENTIAL,
TSS_TPMATTRIB_EKCERT, ekCertLen, ekCert); TSS_TPMATTRIB_EKCERT, ekCertLen, ekCert);
if (result != TSS_SUCCESS) { if (result != TSS_SUCCESS)
{
DBG1(DBG_IMC, "Error 0x%x on SetAttribData for EKCert", result); DBG1(DBG_IMC, "Error 0x%x on SetAttribData for EKCert", result);
goto err; goto err;
} }
@@ -423,7 +442,8 @@ static bool obtain_aik(private_pts_t *this)
NULL, hIdentKey, TSS_ALG_AES, NULL, hIdentKey, TSS_ALG_AES,
&ulTCPAIdentityReqLength, &ulTCPAIdentityReqLength,
&rgbTCPAIdentityReq); &rgbTCPAIdentityReq);
if (result != TSS_SUCCESS){ if (result != TSS_SUCCESS)
{
DBG1(DBG_IMC, "Error 0x%x on Tspi_TPM_CollateIdentityRequest", result); DBG1(DBG_IMC, "Error 0x%x on Tspi_TPM_CollateIdentityRequest", result);
goto err; goto err;
} }
@@ -442,7 +462,8 @@ static bool obtain_aik(private_pts_t *this)
slist = curl_slist_append (slist, "Content-Type: application/octet-stream"); slist = curl_slist_append (slist, "Content-Type: application/octet-stream");
slist = curl_slist_append (slist, "Content-Transfer-Encoding: binary"); slist = curl_slist_append (slist, "Content-Transfer-Encoding: binary");
curl_easy_setopt (hCurl, CURLOPT_HTTPHEADER, slist); curl_easy_setopt (hCurl, CURLOPT_HTTPHEADER, slist);
if ((result = curl_easy_perform(hCurl))) { if ((result = curl_easy_perform(hCurl)))
{
DBG1(DBG_IMC, "Unable to connect to Privacy CA, curl library result code %d", result); DBG1(DBG_IMC, "Unable to connect to Privacy CA, curl library result code %d", result);
exit (result); exit (result);
} }
@@ -454,7 +475,7 @@ static bool obtain_aik(private_pts_t *this)
symBufSize = ftell(f_tmp); symBufSize = ftell(f_tmp);
symBuf = malloc(symBufSize); symBuf = malloc(symBufSize);
rewind(f_tmp); rewind(f_tmp);
if(!fread (symBuf, 1, symBufSize, f_tmp)) if (!fread (symBuf, 1, symBufSize, f_tmp))
{ {
DBG1(DBG_IMC, "Failed to read buffer"); DBG1(DBG_IMC, "Failed to read buffer");
goto err; goto err;
@@ -474,7 +495,8 @@ static bool obtain_aik(private_pts_t *this)
symBuf += asymBufSize; symBuf += asymBufSize;
result = Tspi_Key_LoadKey (hIdentKey, hSRK); result = Tspi_Key_LoadKey (hIdentKey, hSRK);
if (result != TSS_SUCCESS) { if (result != TSS_SUCCESS)
{
DBG1(DBG_IMC, "Error 0x%x on Tspi_Key_LoadKey for AIK", result); DBG1(DBG_IMC, "Error 0x%x on Tspi_Key_LoadKey for AIK", result);
goto err; goto err;
} }
@@ -482,7 +504,8 @@ static bool obtain_aik(private_pts_t *this)
result = Tspi_TPM_ActivateIdentity (hTPM, hIdentKey, asymBufSize, asymBuf, result = Tspi_TPM_ActivateIdentity (hTPM, hIdentKey, asymBufSize, asymBuf,
symBufSize, symBuf, symBufSize, symBuf,
&credBufSize, &credBuf); &credBufSize, &credBuf);
if (result != TSS_SUCCESS) { if (result != TSS_SUCCESS)
{
DBG1(DBG_IMC, "Error 0x%x on Tspi_TPM_ActivateIdentity", result); DBG1(DBG_IMC, "Error 0x%x on Tspi_TPM_ActivateIdentity", result);
goto err; goto err;
} }
@@ -490,15 +513,17 @@ static bool obtain_aik(private_pts_t *this)
/* Output credential in PEM format */ /* Output credential in PEM format */
tbuf = credBuf; tbuf = credBuf;
x509 = d2i_X509(NULL, (const BYTE **)&tbuf, credBufSize); x509 = d2i_X509(NULL, (const BYTE **)&tbuf, credBufSize);
if (x509 == NULL) { if (x509 == NULL)
{
DBG1(DBG_IMC, "Unable to parse returned credential"); DBG1(DBG_IMC, "Unable to parse returned credential");
goto err; goto err;
} }
if (tbuf-credBuf != credBufSize) { if (tbuf-credBuf != credBufSize)
{
DBG1(DBG_IMC, "Note, not all data from privacy ca was parsed correctly"); DBG1(DBG_IMC, "Note, not all data from privacy ca was parsed correctly");
} }
if(x509) if (x509)
{ {
BUF_MEM *mem_buf; BUF_MEM *mem_buf;
BIO* bp; BIO* bp;
@@ -513,7 +538,8 @@ static bool obtain_aik(private_pts_t *this)
memcpy(tmp, mem_buf, len); memcpy(tmp, mem_buf, len);
tmp[len] = '\0'; tmp[len] = '\0';
DBG3(DBG_IMC,"X509 Certificate (PEM format):\n%s\n", tmp); DBG3(DBG_IMC,"X509 Certificate (PEM format):");
DBG3(DBG_IMC,"%s", tmp);
this->aik = chunk_create(tmp, len + 1); this->aik = chunk_create(tmp, len + 1);
this->aik = chunk_clone(this->aik); this->aik = chunk_clone(this->aik);
@@ -529,14 +555,14 @@ static bool obtain_aik(private_pts_t *this)
DBG3(DBG_IMC, "Succeeded at obtaining AIK Certificate from Privacy CA!"); DBG3(DBG_IMC, "Succeeded at obtaining AIK Certificate from Privacy CA!");
return TRUE; return TRUE;
err: err:
return FALSE; return FALSE;
} }
METHOD(pts_t, get_aik, bool, METHOD(pts_t, get_aik, bool,
private_pts_t *this, chunk_t *aik, bool *is_naked_key) private_pts_t *this, chunk_t *aik, bool *is_naked_key)
{ {
if(obtain_aik(this) != TRUE ) if (obtain_aik(this) != TRUE )
{ {
return FALSE; return FALSE;
} }
@@ -722,7 +748,7 @@ static bool has_tpm(private_pts_t *this)
this->tpm_version_info = chunk_clone(this->tpm_version_info); this->tpm_version_info = chunk_clone(this->tpm_version_info);
return TRUE; return TRUE;
err: err:
DBG1(DBG_TNC, "TPM not available: tss error 0x%x", result); DBG1(DBG_TNC, "TPM not available: tss error 0x%x", result);
return FALSE; return FALSE;
} }
+1 -1
View File
@@ -32,7 +32,7 @@ typedef struct pts_database_t pts_database_t;
*/ */
struct pts_database_t { struct pts_database_t {
/** /**
* Get files to be measured by PTS * Get files to be measured by PTS
* *
* @product software product (os, vpn client, etc.) * @product software product (os, vpn client, etc.)
+8 -2
View File
@@ -116,7 +116,10 @@ METHOD(pa_tnc_attr_t, build, void,
writer = bio_writer_create(PTS_AIK_SIZE); writer = bio_writer_create(PTS_AIK_SIZE);
if(this->naked_pub_aik) flags += 128; if (this->naked_pub_aik)
{
flags += 128;
}
writer->write_uint8 (writer, flags); writer->write_uint8 (writer, flags);
writer->write_data(writer, this->aik); writer->write_data(writer, this->aik);
@@ -139,7 +142,10 @@ METHOD(pa_tnc_attr_t, process, status_t,
reader = bio_reader_create(this->value); reader = bio_reader_create(this->value);
reader->read_uint8(reader, &flags); reader->read_uint8(reader, &flags);
if((flags >> 7 ) & 1) this->naked_pub_aik = true; if ((flags >> 7 ) & 1)
{
this->naked_pub_aik = true;
}
reader->read_data (reader, this->value.len - 1, &this->aik); reader->read_data (reader, this->value.len - 1, &this->aik);
this->aik = chunk_clone(this->aik); this->aik = chunk_clone(this->aik);
@@ -187,7 +187,7 @@ METHOD(pa_tnc_attr_t, build, void,
writer->write_uint24 (writer, this->depth); writer->write_uint24 (writer, this->depth);
writer->write_uint24 (writer, this->comp_vendor_id); writer->write_uint24 (writer, this->comp_vendor_id);
if(this->family != PTS_REQ_FUNCT_COMP_FAM_BIN_ENUM) if (this->family != PTS_REQ_FUNCT_COMP_FAM_BIN_ENUM)
{ {
DBG1(DBG_TNC, "Functional Name Encoding Family is not set to 00"); DBG1(DBG_TNC, "Functional Name Encoding Family is not set to 00");
} }
@@ -256,7 +256,7 @@ METHOD(pa_tnc_attr_t, process, status_t,
/* TODO: Generate an IF-M error attribute indicating */ /* TODO: Generate an IF-M error attribute indicating */
/* TCG_PTS_INVALID_NAME_FAM */ /* TCG_PTS_INVALID_NAME_FAM */
//if(&this->comp_vendor_id==PEN_TCG && this->family != PTS_REQ_FUNCT_COMP_FAM_BIN_ENUM) //if (&this->comp_vendor_id==PEN_TCG && this->family != PTS_REQ_FUNCT_COMP_FAM_BIN_ENUM)
//{ //{
// DBG1(DBG_TNC, "Functional Name Encoding Family is not set to 00"); // DBG1(DBG_TNC, "Functional Name Encoding Family is not set to 00");
//} //}
@@ -374,7 +374,7 @@ METHOD(pa_tnc_attr_t, process, status_t,
/* TODO: Generate an IF-M error attribute indicating */ /* TODO: Generate an IF-M error attribute indicating */
/* TCG_PTS_INVALID_NAME_FAM */ /* TCG_PTS_INVALID_NAME_FAM */
//if(&this->comp_vendor_id==PEN_TCG && this->family != PTS_REQ_FUNCT_COMP_FAM_BIN_ENUM) //if (&this->comp_vendor_id==PEN_TCG && this->family != PTS_REQ_FUNCT_COMP_FAM_BIN_ENUM)
//{ //{
// DBG1(DBG_TNC, "Functional Name Encoding Family is not set to 00"); // DBG1(DBG_TNC, "Functional Name Encoding Family is not set to 00");
//} //}