in main/AppCredential.c [157:202]
STATUS createCredential(PAppCredential pAppCredential)
{
STATUS retStatus = STATUS_SUCCESS;
PCHAR pAccessKey, pSecretKey, pSessionToken;
PCHAR pIotCoreCredentialEndPoint, pIotCoreCert, pIotCorePrivateKey, pIotCoreRoleAlias, pIotCoreThingName;
PCHAR pEcsToken, pEcsCredentialFullUri;
CHK(pAppCredential != NULL, STATUS_APP_CREDENTIAL_NULL_ARG);
pAppCredential->credentialType = APP_CREDENTIAL_TYPE_NA;
pAppCredential->pCredentialProvider = NULL;
pAppCredential->generateCertLock = INVALID_MUTEX_VALUE;
pAppCredential->generatedCertificates = NULL;
CHK_STATUS((searchSslCert(pAppCredential)));
if (((pAccessKey = GETENV(ACCESS_KEY_ENV_VAR)) != NULL) && ((pSecretKey = GETENV(SECRET_KEY_ENV_VAR)) != NULL)) {
pSessionToken = GETENV(SESSION_TOKEN_ENV_VAR);
CHK(createStaticCredentialProvider(pAccessKey, 0, pSecretKey, 0, pSessionToken, 0, MAX_UINT64, &pAppCredential->pCredentialProvider) ==
STATUS_SUCCESS,
STATUS_APP_CREDENTIAL_ALLOCATE_STATIC);
pAppCredential->credentialType = APP_CREDENTIAL_TYPE_STATIC;
} else if (((pIotCoreThingName = GETENV(APP_IOT_CORE_THING_NAME)) != NULL) &&
((pIotCoreCredentialEndPoint = GETENV(APP_IOT_CORE_CREDENTIAL_ENDPOINT)) != NULL) && ((pIotCoreCert = GETENV(APP_IOT_CORE_CERT))) &&
((pIotCorePrivateKey = GETENV(APP_IOT_CORE_PRIVATE_KEY)) != NULL) && ((pIotCoreRoleAlias = GETENV(APP_IOT_CORE_ROLE_ALIAS)) != NULL)) {
CHK(createIotCredentialProvider(pIotCoreCredentialEndPoint, pIotCoreCert, pIotCorePrivateKey, pAppCredential->pCaCertPath,
pIotCoreRoleAlias, pIotCoreThingName, &pAppCredential->pCredentialProvider) == STATUS_SUCCESS,
STATUS_APP_CREDENTIAL_ALLOCATE_IOT);
pAppCredential->credentialType = APP_CREDENTIAL_TYPE_IOT_CERT;
} else {
CHK(FALSE, STATUS_APP_CREDENTIAL_ALLOCATE_NA);
}
pAppCredential->generateCertLock = MUTEX_CREATE(FALSE);
CHK(IS_VALID_MUTEX_VALUE(pAppCredential->generateCertLock), STATUS_APP_CREDENTIAL_INVALID_MUTEX);
CHK(stackQueueCreate(&pAppCredential->generatedCertificates) == STATUS_SUCCESS, STATUS_APP_CREDENTIAL_PREGENERATED_CERT_QUEUE);
CleanUp:
if (STATUS_FAILED(retStatus)) {
if (pAppCredential != NULL) {
destroyCredential(pAppCredential);
}
}
return retStatus;
}