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
+55 -29
View File
@@ -213,7 +213,8 @@ static TSS_RESULT makeEKCert(TSS_HCONTEXT hContext, TSS_HTPM hTPM, UINT32 *pCert
DBG1(DBG_IMC, "Error in: Tspi_Context_CloseObject");
return result;
}
if (modulusLen != 256) {
if (modulusLen != 256)
{
DBG1(DBG_IMC, "Tspi_GetAttribData modulusLen != 256");
Tspi_Context_FreeMemory (hContext, modulus);
return result;
@@ -247,7 +248,8 @@ static X509* readPCAcert (int level)
curl_easy_setopt (hCurl, CURLOPT_URL, url);
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);
fclose(f_tmp);
return NULL;
@@ -314,56 +316,66 @@ static bool obtain_aik(private_pts_t *this)
level = 1;
}
x509 = readPCAcert (level);
if (x509 == NULL) {
if (x509 == NULL)
{
DBG1(DBG_IMC, "Error reading PCA key");
goto err;
}
pcaKey = X509_get_pubkey(x509);
rsa = EVP_PKEY_get1_RSA(pcaKey);
if (rsa == NULL) {
if (rsa == NULL)
{
DBG1(DBG_IMC, "Error reading RSA key from PCA");
goto err;
}
X509_free (x509);
result = Tspi_Context_Create(&hContext);
if (result != TSS_SUCCESS) {
if (result != TSS_SUCCESS)
{
DBG1(DBG_IMC, "Error 0x%x on Tspi_Context_Create", result);
goto err;
}
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);
goto err;
}
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);
goto err;
}
result = Tspi_Context_LoadKeyByUUID(hContext,
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);
goto err;
}
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);
goto err;
}
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);
goto err;
}
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);
goto err;
}
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);
goto err;
}
@@ -371,7 +383,8 @@ static bool obtain_aik(private_pts_t *this)
result = Tspi_Context_CreateObject(hContext,
TSS_OBJECT_TYPE_RSAKEY,
initFlags, &hIdentKey);
if (result != TSS_SUCCESS) {
if (result != TSS_SUCCESS)
{
DBG1(DBG_IMC, "Error 0x%x on Tspi_Context_CreateObject for key", result);
goto err;
}
@@ -380,24 +393,28 @@ static bool obtain_aik(private_pts_t *this)
TSS_OBJECT_TYPE_RSAKEY,
TSS_KEY_TYPE_LEGACY|TSS_KEY_SIZE_2048,
&hPCAKey);
if (result != TSS_SUCCESS) {
DBG1(DBG_IMC, "Error 0x%x on Tspi_Context_CreateObject for PCA\n", result);
if (result != TSS_SUCCESS)
{
DBG1(DBG_IMC, "Error 0x%x on Tspi_Context_CreateObject for PCA", result);
goto err;
}
if ((size_n = BN_bn2bin(rsa->n, n)) <= 0) {
printf("BN_bn2bin failed\n");
if ((size_n = BN_bn2bin(rsa->n, n)) <= 0)
{
DBG1(DBG_IMC, "BN_bn2bin failed");
goto err;;
}
result = Tspi_SetAttribData (hPCAKey, TSS_TSPATTRIB_RSAKEY_INFO,
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);
goto err;
}
result = Tspi_SetAttribUint32(hPCAKey, TSS_TSPATTRIB_KEY_INFO,
TSS_TSPATTRIB_KEYINFO_ENCSCHEME,
TSS_ES_RSAESPKCSV15);
if (result != TSS_SUCCESS) {
if (result != TSS_SUCCESS)
{
DBG1(DBG_IMC, "Error 0x%x on Tspi_SetAttribUint32 for PCA encscheme", result);
goto err;
}
@@ -405,14 +422,16 @@ static bool obtain_aik(private_pts_t *this)
if (!REALEK)
{
result = makeEKCert(hContext, hTPM, &ekCertLen, &ekCert);
if (result != TSS_SUCCESS) {
DBG1(DBG_IMC, "Error 0x%x on makeEKCert\n", result);
if (result != TSS_SUCCESS)
{
DBG1(DBG_IMC, "Error 0x%x on makeEKCert", result);
goto err;
}
result = Tspi_SetAttribData(hTPM, TSS_TSPATTRIB_TPM_CREDENTIAL,
TSS_TPMATTRIB_EKCERT, ekCertLen, ekCert);
if (result != TSS_SUCCESS) {
if (result != TSS_SUCCESS)
{
DBG1(DBG_IMC, "Error 0x%x on SetAttribData for EKCert", result);
goto err;
}
@@ -423,7 +442,8 @@ static bool obtain_aik(private_pts_t *this)
NULL, hIdentKey, TSS_ALG_AES,
&ulTCPAIdentityReqLength,
&rgbTCPAIdentityReq);
if (result != TSS_SUCCESS){
if (result != TSS_SUCCESS)
{
DBG1(DBG_IMC, "Error 0x%x on Tspi_TPM_CollateIdentityRequest", result);
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-Transfer-Encoding: binary");
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);
exit (result);
}
@@ -474,7 +495,8 @@ static bool obtain_aik(private_pts_t *this)
symBuf += asymBufSize;
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);
goto err;
}
@@ -482,7 +504,8 @@ static bool obtain_aik(private_pts_t *this)
result = Tspi_TPM_ActivateIdentity (hTPM, hIdentKey, asymBufSize, asymBuf,
symBufSize, symBuf,
&credBufSize, &credBuf);
if (result != TSS_SUCCESS) {
if (result != TSS_SUCCESS)
{
DBG1(DBG_IMC, "Error 0x%x on Tspi_TPM_ActivateIdentity", result);
goto err;
}
@@ -490,11 +513,13 @@ static bool obtain_aik(private_pts_t *this)
/* Output credential in PEM format */
tbuf = credBuf;
x509 = d2i_X509(NULL, (const BYTE **)&tbuf, credBufSize);
if (x509 == NULL) {
if (x509 == NULL)
{
DBG1(DBG_IMC, "Unable to parse returned credential");
goto err;
}
if (tbuf-credBuf != credBufSize) {
if (tbuf-credBuf != credBufSize)
{
DBG1(DBG_IMC, "Note, not all data from privacy ca was parsed correctly");
}
@@ -513,7 +538,8 @@ static bool obtain_aik(private_pts_t *this)
memcpy(tmp, mem_buf, len);
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_clone(this->aik);
+8 -2
View File
@@ -116,7 +116,10 @@ METHOD(pa_tnc_attr_t, build, void,
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_data(writer, this->aik);
@@ -139,7 +142,10 @@ METHOD(pa_tnc_attr_t, process, status_t,
reader = bio_reader_create(this->value);
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);
this->aik = chunk_clone(this->aik);