int KSI_HttpClient_new(KSI_CTX *ctx, KSI_NetworkClient **client) { int res = KSI_UNKNOWN_ERROR; KSI_NetworkClient *tmp = NULL; KSI_HttpClient *http = NULL; if (ctx == NULL || client == NULL) { res = KSI_INVALID_ARGUMENT; goto cleanup; } res = KSI_AbstractHttpClient_new(ctx, &tmp); if (res != KSI_OK) goto cleanup; http = tmp->impl; http->sendRequest = sendRequest; tmp->performAll = performAll; res = KSI_CTX_registerGlobals(ctx, curlGlobal_init, curlGlobal_cleanup); if (res != KSI_OK) { KSI_pushError(ctx, res, NULL); goto cleanup; } *client = tmp; tmp = NULL; res = KSI_OK; cleanup: KSI_NetworkClient_free(tmp); return res; }
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; }