Enforced strongSwan coding rules (tab, if, {)
This commit is contained in:
committed by
Andreas Steffen
parent
0f36d4815e
commit
05a1b347b2
+55
-29
@@ -213,7 +213,8 @@ 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;
|
||||||
@@ -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;
|
||||||
@@ -314,56 +316,66 @@ static bool obtain_aik(private_pts_t *this)
|
|||||||
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,24 +393,28 @@ 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;
|
||||||
}
|
}
|
||||||
@@ -405,14 +422,16 @@ static bool obtain_aik(private_pts_t *this)
|
|||||||
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);
|
||||||
}
|
}
|
||||||
@@ -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,11 +513,13 @@ 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");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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);
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
Reference in New Issue
Block a user