Exemplo n.º 1
0
int KSI_PKITruststore_new(KSI_CTX *ctx, int setDefaults, KSI_PKITruststore **trust) {
	int res = KSI_UNKNOWN_ERROR;
	KSI_PKITruststore *tmp = NULL;
	HCERTSTORE collectionStore = NULL;
	char buf[1024];

	KSI_ERR_clearErrors(ctx);
	if (ctx == NULL || trust == NULL){
		res = KSI_INVALID_ARGUMENT;
		goto cleanup;
	}


	res = KSI_CTX_registerGlobals(ctx, cryptopapiGlobal_init, cryptopapiGlobal_cleanup);
	if (res != KSI_OK){
		KSI_pushError(ctx, res, NULL);
		goto cleanup;
	}

	//TODO: Will be removed
	/*Open certificate store as collection of other stores*/
	collectionStore = CertOpenStore(CERT_STORE_PROV_COLLECTION, PKCS_7_ASN_ENCODING | X509_ASN_ENCODING, 0, 0, NULL);
	if (collectionStore == NULL) {
		KSI_LOG_debug(ctx, "%s", getMSError(GetLastError(), buf, sizeof(buf)));
		KSI_pushError(ctx, res = KSI_CRYPTO_FAILURE, NULL);
		goto cleanup;
	}

	tmp = KSI_new(KSI_PKITruststore);
	if (tmp == NULL) {
		KSI_pushError(ctx, res = KSI_OUT_OF_MEMORY, NULL);
		goto cleanup;
	}

	tmp->ctx = ctx;
	tmp->collectionStore = collectionStore;

	*trust = tmp;
	tmp = NULL;

	res = KSI_OK;

cleanup:

	KSI_PKITruststore_free(tmp);

	return res;
}
Exemplo n.º 2
0
void KSI_CTX_free(KSI_CTX *ctx) {
	if (ctx != NULL) {
		/* Call cleanup methods. */
		globalCleanup(ctx);

		KSI_List_free(ctx->cleanupFnList);

		KSI_free(ctx->errors);

		KSI_NetworkClient_free(ctx->netProvider);
		KSI_PKITruststore_free(ctx->pkiTruststore);

		KSI_PublicationsFile_free(ctx->publicationsFile);
		KSI_free(ctx->publicationCertEmail_DEPRECATED);

		freeCertConstraintsArray(ctx->certConstraints);
		KSI_Signature_free(ctx->lastFailedSignature);

		KSI_free(ctx);
	}
}