static size_t receiveDataFromLibCurl(void *ptr, size_t size, size_t nmemb, void *stream) { size_t bytesCount = 0; unsigned char *tmp_buffer = NULL; CurlNetHandleCtx *nc = (CurlNetHandleCtx *) stream; bytesCount = nc->len + size * nmemb; if (bytesCount > UINT_MAX) { goto cleanup; } tmp_buffer = KSI_calloc(bytesCount, 1); if (tmp_buffer == NULL) goto cleanup; memcpy(tmp_buffer, nc->raw, nc->len); memcpy(tmp_buffer + nc->len, ptr, size * nmemb); KSI_free(nc->raw); nc->raw = tmp_buffer; nc->len = bytesCount; tmp_buffer = NULL; KSI_LOG_debug(nc->ctx, "0x%x: Received %llu bytes (%llu so far)", nc, (unsigned long long) bytesCount, nc->len); bytesCount = size * nmemb; cleanup: KSI_free(tmp_buffer); return bytesCount; }
static int setStringParam(char **param, const char *val) { char *tmp = NULL; int res = KSI_UNKNOWN_ERROR; tmp = KSI_calloc(strlen(val) + 1, 1); if (tmp == NULL) { res = KSI_INVALID_ARGUMENT; goto cleanup; } memcpy(tmp, val, strlen(val) + 1); if (*param != NULL) { KSI_free(*param); } *param = tmp; tmp = NULL; res = KSI_OK; cleanup: KSI_free(tmp); return res; }
static void CurlNetHandleCtx_free(CurlNetHandleCtx *handleCtx) { if (handleCtx != NULL) { KSI_free(handleCtx->raw); if (handleCtx->httpHeaders != NULL) curl_slist_free_all(handleCtx->httpHeaders); if (handleCtx->curl != NULL) curl_easy_cleanup(handleCtx->curl); KSI_free(handleCtx); } }
static void httpClient_free(KSI_HttpClient *http) { if (http != NULL) { KSI_free(http->urlAggregator); KSI_free(http->urlExtender); KSI_free(http->urlPublication); KSI_free(http->agentName); if (http->implCtx_free != NULL) http->implCtx_free(http->implCtx); KSI_free(http); } }
static void freeCertConstraintsArray(KSI_CertConstraint *arr) { size_t i; if (arr != NULL) {; for (i = 0; arr[i].oid != NULL; i++) { KSI_free(arr[i].oid); KSI_free(arr[i].val); } KSI_free(arr); } }
void KSI_PublicationsFile_free(KSI_PublicationsFile *t) { if (t != NULL && --t->ref == 0) { KSI_PublicationsHeader_free(t->header); KSI_CertificateRecordList_free(t->certificates); KSI_PublicationRecordList_free(t->publications); KSI_PKISignature_free(t->signature); KSI_free(t->raw); if(t->ctx->freeCertConstraintsArray != NULL) { t->ctx->freeCertConstraintsArray(t->certConstraints); } KSI_free(t); } }
static void wininetNetHandleCtx_free(wininetNetHandleCtx *handleCtx) { if (handleCtx != NULL) { InternetCloseHandle(handleCtx->session_handle); InternetCloseHandle(handleCtx->request_handle); KSI_free(handleCtx); } }
int KSI_PKICertificate_serialize(KSI_PKICertificate *cert, unsigned char **raw, size_t *raw_len) { int res = KSI_UNKNOWN_ERROR; unsigned char *tmp_serialized = NULL; DWORD len = 0; if (cert == NULL || raw == NULL || raw_len == NULL){ res = KSI_INVALID_ARGUMENT; goto cleanup; } KSI_ERR_clearErrors(cert->ctx); len = cert->x509->cbCertEncoded; tmp_serialized = KSI_malloc(len); if (tmp_serialized == NULL) { KSI_pushError(cert->ctx, res = KSI_OUT_OF_MEMORY, NULL); goto cleanup; } memcpy(tmp_serialized, cert->x509->pbCertEncoded, len); *raw = tmp_serialized; *raw_len = (size_t)len; tmp_serialized = NULL; res = KSI_OK; cleanup: KSI_free(tmp_serialized); return res; }
static void testSerializePublicationsFile(CuTest *tc) { int res; KSI_PublicationsFile *pubFile = NULL; char *raw = NULL; unsigned raw_len = 0; FILE *f = NULL; int symbol = 0; unsigned i= 0; KSI_ERR_clearErrors(ctx); setFileMockResponse(tc, getFullResourcePath(TEST_PUBLICATIONS_FILE)); res = KSI_PublicationsFile_fromFile(ctx, getFullResourcePath(TEST_PUBLICATIONS_FILE), &pubFile); CuAssert(tc, "Unable to read publications file", res == KSI_OK && pubFile != NULL); res = KSI_PublicationsFile_serialize(ctx, pubFile, &raw, &raw_len); CuAssert(tc, "Unable to serialize publications file", res == KSI_OK && raw != NULL && raw_len != 0); f = fopen(getFullResourcePath(TEST_PUBLICATIONS_FILE), "rb"); CuAssert(tc, "Unable to open publications file", res == KSI_OK && f != NULL); while ((symbol = getc(f)) != EOF && i<raw_len){ CuAssert(tc, "Serialized publications file mismatch", (char)symbol == raw[i]); i++; } CuAssert(tc, "Serialized publications file length mismatch", i == raw_len); KSI_PublicationsFile_free(pubFile); KSI_free(raw); if (f) fclose(f); }
static void winhttpNetHandleCtx_free(winhttpNetHandleCtx *handleCtx) { if (handleCtx != NULL) { WinHttpCloseHandle(handleCtx->connection_handle); WinHttpCloseHandle(handleCtx->request_handle); KSI_free(handleCtx); } }
static void testgetUsedHashAlgorithmsFromSingleLegacy(CuTest *tc) { int res; KSI_MultiSignature *ms = NULL; KSI_Signature *sig = NULL; KSI_HashAlgorithm *arr = NULL; size_t arr_len; res = KSI_MultiSignature_new(ctx, &ms); CuAssert(tc, "Unable to create multi signature container.", res == KSI_OK && ms != NULL); res = KSI_Signature_fromFile(ctx, getFullResourcePath("resource/tlv/ok-legacy-sig-2014-06.gtts.ksig"), &sig); CuAssert(tc, "Unable to read signature from file.", res == KSI_OK && sig != NULL); res = KSI_MultiSignature_add(ms, sig); CuAssert(tc, "Unable to add signature to multi signature container.", res == KSI_OK); KSI_Signature_free(sig); res = KSI_MultiSignature_getUsedHashAlgorithms(ms, &arr, &arr_len); CuAssert(tc, "Function should be successful", res == KSI_OK); CuAssert(tc, "Unexpected number of hash algorithms", arr_len == 1); CuAssert(tc, "If there are used algorithms, the output pointer should not be NULL", arr != NULL); CuAssert(tc, "Unexpected hash algorithm", arr[0] == KSI_HASHALG_SHA2_256); KSI_MultiSignature_free(ms); KSI_free(arr); }
int KSI_CTX_registerGlobals(KSI_CTX *ctx, int (*initFn)(void), void (*cleanupFn)(void)) { int res = KSI_UNKNOWN_ERROR; size_t *pos = NULL; if (ctx == NULL || initFn == NULL || cleanupFn == NULL) { res = KSI_INVALID_ARGUMENT; goto cleanup; } res = KSI_List_indexOf(ctx->cleanupFnList, (void *)cleanupFn, &pos); if (res != KSI_OK) goto cleanup; /* Only run the init function if the cleanup function is not found. */ if (pos == NULL) { res = initFn(); if (res != KSI_OK) goto cleanup; res = KSI_List_append(ctx->cleanupFnList, (void *)cleanupFn); if (res != KSI_OK) goto cleanup; } res = KSI_OK; cleanup: KSI_free(pos); return res; }
int KSI_PKISignature_serialize(KSI_PKISignature *sig, unsigned char **raw, unsigned *raw_len) { int res = KSI_UNKNOWN_ERROR; unsigned char *tmp = NULL; if (sig == NULL || raw == NULL || raw_len == NULL){ res = KSI_INVALID_ARGUMENT; goto cleanup; } KSI_ERR_clearErrors(sig->ctx); tmp = KSI_malloc(sig->pkcs7.cbData); if (tmp == NULL) { KSI_pushError(sig->ctx, res = KSI_OUT_OF_MEMORY, NULL); goto cleanup; } memcpy(tmp, sig->pkcs7.pbData, sig->pkcs7.cbData); *raw = tmp; *raw_len = (unsigned)sig->pkcs7.cbData; tmp = NULL; res = KSI_OK; cleanup: KSI_free(tmp); return res; }
static void testDeleteSignatureAppendedFromFile(CuTest *tc, const char *fname) { int res; KSI_MultiSignature *ms = NULL; KSI_Signature *sig = NULL; KSI_HashAlgorithm *arr = NULL; KSI_DataHash *hsh = NULL; res = KSI_MultiSignature_new(ctx, &ms); CuAssert(tc, "Unable to create multi signature container.", res == KSI_OK && ms != NULL); res = KSI_Signature_fromFile(ctx, fname, &sig); CuAssert(tc, "Unable to read signature from file.", res == KSI_OK && sig != NULL); res = KSI_Signature_getDocumentHash(sig, &hsh); CuAssert(tc, "Unable to retrieve signed document hash from the signature.", res == KSI_OK && hsh != NULL); KSI_DataHash_ref(hsh); res = KSI_MultiSignature_add(ms, sig); CuAssert(tc, "Unable to add signature to multi signature container.", res == KSI_OK); KSI_Signature_free(sig); sig = NULL; res = KSI_MultiSignature_remove(ms, hsh); CuAssert(tc, "Unable to remove signature.", res == KSI_OK); res = KSI_MultiSignature_get(ms, hsh, &sig); CuAssert(tc, "There should not be a signature with this hash value anymore.", res == KSI_MULTISIG_NOT_FOUND && sig == NULL); /* TimeMapper list functions are not exported so we need to cast to generic list. */ CuAssert(tc, "The internal structure should be empty", KSI_List_length((KSI_List *)ms->timeList) == 0); KSI_MultiSignature_free(ms); KSI_DataHash_free(hsh); KSI_free(arr); }
static void CRYPTO_HASH_CTX_free(CRYPTO_HASH_CTX *cryptoCtxt){ if (cryptoCtxt != NULL){ if (cryptoCtxt->pt_CSP) CryptReleaseContext(cryptoCtxt->pt_CSP, 0); if (cryptoCtxt->pt_hHash) CryptDestroyHash(cryptoCtxt->pt_hHash); KSI_free(cryptoCtxt); } }
static void testSerializeSignature(CuTest *tc) { int res; unsigned char in[0x1ffff]; unsigned in_len = 0; unsigned char *out = NULL; unsigned out_len = 0; FILE *f = NULL; KSI_Signature *sig = NULL; KSI_ERR_clearErrors(ctx); f = fopen(getFullResourcePath(TEST_SIGNATURE_FILE), "rb"); CuAssert(tc, "Unable to open signature file.", f != NULL); in_len = (unsigned)fread(in, 1, sizeof(in), f); CuAssert(tc, "Nothing read from signature file.", in_len > 0); fclose(f); res = KSI_Signature_parse(ctx, in, in_len, &sig); CuAssert(tc, "Failed to parse signature", res == KSI_OK && sig != NULL); res = KSI_Signature_serialize(sig, &out, &out_len); CuAssert(tc, "Failed to serialize signature", res == KSI_OK); CuAssert(tc, "Serialized signature length mismatch", in_len == out_len); CuAssert(tc, "Serialized signature content mismatch", !memcmp(in, out, in_len)); KSI_free(out); KSI_Signature_free(sig); }
/** * KSI_PublicationData */ void KSI_PublicationData_free(KSI_PublicationData *t) { if (t != NULL && --t->ref == 0) { KSI_Integer_free(t->time); KSI_DataHash_free(t->imprint); KSI_TLV_free(t->baseTlv); KSI_free(t); } }
/** * KSI_PublicationRecord */ void KSI_PublicationRecord_free(KSI_PublicationRecord *t) { if (t != NULL && --t->ref == 0) { KSI_PublicationData_free(t->publishedData); KSI_Utf8StringList_free(t->publicationRef); KSI_Utf8StringList_free(t->repositoryUriList); KSI_free(t); } }
static int prepareRequest( KSI_NetworkClient *client, void *pdu, int (*serialize)(void *, unsigned char **, unsigned *), KSI_RequestHandle **handle, char *url, const char *desc) { int res = KSI_UNKNOWN_ERROR; KSI_HttpClient *http = (KSI_HttpClient *)client; KSI_RequestHandle *tmp = NULL; unsigned char *raw = NULL; unsigned raw_len = 0; if (client == NULL || pdu == NULL || handle == NULL) { res = KSI_INVALID_ARGUMENT; goto cleanup; } KSI_ERR_clearErrors(client->ctx); res = serialize(pdu, &raw, &raw_len); if (res != KSI_OK) { KSI_pushError(client->ctx, res, NULL); goto cleanup; } KSI_LOG_logBlob(client->ctx, KSI_LOG_DEBUG, desc, raw, raw_len); /* Create a new request handle */ res = KSI_RequestHandle_new(client->ctx, raw, raw_len, &tmp); if (res != KSI_OK) { KSI_pushError(client->ctx, res, NULL); goto cleanup; } if (http->sendRequest == NULL) { KSI_pushError(client->ctx, res = KSI_UNKNOWN_ERROR, "Send request not initialized."); goto cleanup; } res = http->sendRequest(client, tmp, url); if (res != KSI_OK) { KSI_pushError(client->ctx, res, NULL); goto cleanup; } *handle = tmp; tmp = NULL; res = KSI_OK; cleanup: KSI_RequestHandle_free(tmp); KSI_free(raw); return res; }
int KSI_CTX_setPublicationCertEmail(KSI_CTX *ctx, const char *email) { int res = KSI_UNKNOWN_ERROR; char *tmp = NULL; KSI_CertConstraint arr[] = { { KSI_CERT_EMAIL, NULL }, { NULL, NULL } }; if (ctx == NULL || email == NULL) { res = KSI_INVALID_ARGUMENT; goto cleanup; } /* The value is only read - cast is safe. */ arr[0].val = (char *) email; res = KSI_CTX_setDefaultPubFileCertConstraints(ctx, arr); if (res != KSI_OK) { KSI_pushError(ctx, res, NULL); goto cleanup; } /* Keep the value for compatibility. */ if (email != NULL && email[0] != '\0') { size_t len = strlen(email); tmp = KSI_calloc(len + 1, 1); if (tmp == NULL) { res = KSI_OUT_OF_MEMORY; goto cleanup; } memcpy(tmp, email, len + 1); } KSI_free(ctx->publicationCertEmail_DEPRECATED); ctx->publicationCertEmail_DEPRECATED = tmp; tmp = NULL; res = KSI_OK; cleanup: KSI_free(tmp); return res; }
static void testReset(CuTest *tc) { #define TEST_AGGR_RESPONSE_FILE "resource/tlv/ok-sig-2014-07-01.1-aggr_response.tlv" int res = KSI_UNKNOWN_ERROR; KSI_BlockSigner *bs = NULL; KSI_DataHash *hsh = NULL; KSI_BlockSignerHandle *h = NULL; KSI_Signature *sig = NULL; unsigned char *raw = NULL; size_t len = 0; res = KSI_CTX_setAggregator(ctx, getFullResourcePathUri(TEST_AGGR_RESPONSE_FILE), TEST_USER, TEST_PASS); CuAssert(tc, "Unable to set aggregator file URI.", res == KSI_OK); res = KSITest_DataHash_fromStr(ctx, "0111a700b0c8066c47ecba05ed37bc14dcadb238552d86c659342d1d7e87b8772d", &hsh); CuAssert(tc, "Unable to create data hash.", res == KSI_OK && hsh != NULL); res = KSI_BlockSigner_new(ctx, KSI_HASHALG_SHA1, NULL, NULL, &bs); CuAssert(tc, "Unable to create block signer instance.", res == KSI_OK && bs != NULL); /* Add the temporary leafs. */ res = KSI_BlockSigner_addLeaf(bs, hsh, 0, NULL, NULL); CuAssert(tc, "Unable to add 1st mock hash to the blocksigner.", res == KSI_OK); res = KSI_BlockSigner_addLeaf(bs, hsh, 0, NULL, NULL); CuAssert(tc, "Unable to add 2nd hash to the blocksigner.", res == KSI_OK); res = KSI_BlockSigner_addLeaf(bs, hsh, 0, NULL, NULL); CuAssert(tc, "Unable to add 3rd hash to the blocksigner.", res == KSI_OK); res = KSI_BlockSigner_reset(bs); CuAssert(tc, "Unable to reset the block signer.", res == KSI_OK); res = KSI_BlockSigner_addLeaf(bs, hsh, 0, NULL, &h); CuAssert(tc, "Unable to add actual hash to the blocksigner.", res == KSI_OK && h != NULL); res = KSI_BlockSigner_close(bs, NULL); CuAssert(tc, "Unable to close blocksigner.", res == KSI_OK); res = KSI_BlockSignerHandle_getSignature(h, &sig); CuAssert(tc, "Unable to extract signature from the blocksigner.", res == KSI_OK && sig != NULL); res = KSI_Signature_serialize(sig, &raw, &len); CuAssert(tc, "Unable to serialize signature.", res == KSI_OK && raw != NULL && len > 0); KSI_LOG_logBlob(ctx, KSI_LOG_DEBUG, "Serialized single signature from block signer.", raw, len); KSI_BlockSignerHandle_free(h); KSI_Signature_free(sig); KSI_BlockSigner_free(bs); KSI_DataHash_free(hsh); KSI_free(raw); #undef TEST_AGGR_RESPONSE_FILE }
void KSI_PKITruststore_free(KSI_PKITruststore *trust) { char buf[1024]; if (trust != NULL) { if (trust->collectionStore != NULL){ if (!CertCloseStore(trust->collectionStore, CERT_CLOSE_STORE_CHECK_FLAG)){ KSI_LOG_debug(trust->ctx, "%s", getMSError(GetLastError(), buf, sizeof(buf))); } } KSI_free(trust); } }
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); } }
KSI_HashAlgorithm KSI_getHashAlgorithmByName(const char *name) { size_t i; KSI_HashAlgorithm algo_id = KSI_HASHALG_INVALID; int alias_id; char *alias = NULL; char *upperName = NULL; if (name == NULL || !*name || strchr(name, ',') != NULL) goto cleanup; upperName = KSI_calloc(strlen(name) + 1, 1); if (upperName == NULL) goto cleanup; /* Create upper-case name */ for (i = 0; i < (int) strlen(name); i++) { if (name[i] == '_') { upperName[i] = '-'; } else { upperName[i] = (char) toupper(name[i]); } } upperName[i] = '\0'; for (i = 0; i < KSI_NUMBER_OF_KNOWN_HASHALGS; i++) { /* Skip all records without a name. */ if (KSI_hashAlgorithmInfo[i].name == NULL) continue; /* Do we have a bingo? */ if (!strcmp(upperName, KSI_hashAlgorithmInfo[i].name)) { algo_id = i; goto cleanup; } alias_id = 0; /* Loop until a null pointer or empty string. */ while ((alias = KSI_hashAlgorithmInfo[i].aliases[alias_id++]) && *alias) { if (!strcmp(upperName, alias)) { algo_id = i; goto cleanup; } } } cleanup: KSI_free(upperName); KSI_nofree(alias); return algo_id; }
int KSI_TlvTemplate_serializeObject(KSI_CTX *ctx, const void *obj, unsigned tag, int isNc, int isFwd, const KSI_TlvTemplate *tmpl, unsigned char **raw, unsigned *raw_len) { int res = KSI_UNKNOWN_ERROR; KSI_TLV *tlv = NULL; unsigned char *tmp = NULL; unsigned tmp_len = 0; KSI_ERR_clearErrors(ctx); if (ctx == NULL || obj == NULL || tmpl == NULL || raw == NULL || raw_len == NULL) { KSI_pushError(ctx, res = KSI_INVALID_ARGUMENT, NULL); goto cleanup; } /* Create TLV for the PDU object. */ res = KSI_TLV_new(ctx, KSI_TLV_PAYLOAD_TLV, tag, isFwd, isNc, &tlv); if (res != KSI_OK) { KSI_pushError(ctx, res, NULL); goto cleanup; } /* Evaluate the TLV. */ res = KSI_TlvTemplate_construct(ctx, tlv, obj, tmpl); if (res != KSI_OK) { KSI_pushError(ctx, res, NULL); goto cleanup; } KSI_LOG_logTlv(ctx, KSI_LOG_DEBUG, "Serializing object", tlv); /* Serialize the TLV. */ res = KSI_TLV_serialize(tlv, &tmp, &tmp_len); if (res != KSI_OK) { KSI_pushError(ctx, res, NULL); goto cleanup; } *raw = tmp; tmp = NULL; *raw_len = tmp_len; res = KSI_OK; cleanup: KSI_free(tmp); KSI_TLV_free(tlv); return res; }
static void testMultiSerializeSignature(CuTest *tc) { int res; KSI_MultiSignature *ms = NULL; unsigned char *buf = NULL; size_t buf_len; createMultiSignature(&ms); res = KSI_MultiSignature_serialize(ms, &buf, &buf_len); CuAssert(tc, "Unable to serialize multi signature container.", res == KSI_OK && buf_len > 0); KSI_LOG_logBlob(ctx, KSI_LOG_DEBUG, "Multi signature", buf, buf_len); KSI_MultiSignature_free(ms); KSI_free(buf); }
static int curlReceive(KSI_RequestHandle *handle) { int res = KSI_UNKNOWN_ERROR; CurlNetHandleCtx *implCtx = NULL; long httpCode; if (handle == NULL || handle->client == NULL || handle->implCtx == NULL) { res = KSI_INVALID_ARGUMENT; goto cleanup; } KSI_ERR_clearErrors(handle->ctx); implCtx = handle->implCtx; KSI_LOG_debug(handle->ctx, "Sending request."); res = curl_easy_perform(implCtx->curl); KSI_LOG_debug(handle->ctx, "Received %llu bytes.", (unsigned long long)implCtx->len); if (curl_easy_getinfo(implCtx->curl, CURLINFO_HTTP_CODE, &httpCode) == CURLE_OK) { updateStatus(handle); KSI_LOG_debug(handle->ctx, "Received HTTP error code %d. Curl error '%s'.", httpCode, implCtx->curlErr); } if (res != CURLE_OK) { KSI_pushError(handle->ctx, res = KSI_NETWORK_ERROR, implCtx->curlErr); goto cleanup; } res = KSI_RequestHandle_setResponse(handle, implCtx->raw, implCtx->len); if (res != KSI_OK) { KSI_pushError(handle->ctx, res, NULL); goto cleanup; } /* Cleanup on success.*/ KSI_free(implCtx->raw); implCtx->raw = NULL; implCtx->len = 0; handle->completed = true; res = KSI_OK; cleanup: return res; }
static void testgetUsedHashAlgorithmsFromEmpty(CuTest *tc) { int res; KSI_MultiSignature *ms = NULL; KSI_HashAlgorithm *arr = NULL; size_t arr_len; res = KSI_MultiSignature_new(ctx, &ms); CuAssert(tc, "Unable to create multi signature container.", res == KSI_OK && ms != NULL); res = KSI_MultiSignature_getUsedHashAlgorithms(ms, &arr, &arr_len); CuAssert(tc, "Function should be successful", res == KSI_OK); CuAssert(tc, "Number of used hash algorithms should be 0", arr_len == 0); CuAssert(tc, "If there are no used algorithms, the output pointer should be NULL", arr == NULL); KSI_MultiSignature_free(ms); KSI_free(arr); }
static void testSignerIdentity(CuTest *tc) { int res; const char id_expected[] = "GT :: testA :: 36-test"; KSI_Signature *sig = NULL; char *id_actual = NULL; res = KSI_Signature_fromFile(ctx, getFullResourcePath("resource/tlv/ok-sig-2014-08-01.1.ksig"), &sig); CuAssert(tc, "Unable to load signature", res == KSI_OK && sig != NULL); res = KSI_Signature_getSignerIdentity(sig, &id_actual); CuAssert(tc, "Unable to get signer identity from signature.", res == KSI_OK && id_actual != NULL); CuAssert(tc, "Unexpected signer identity", !strncmp(id_expected, id_actual, strlen(id_expected))); KSI_Signature_free(sig); KSI_free(id_actual); }
static int wininetReceive(KSI_RequestHandle *handle) { int res; KSI_CTX *ctx = NULL; wininetNetHandleCtx *wininetHandle = NULL; unsigned char *resp = NULL; unsigned resp_len = 0; if (handle == NULL) { res = KSI_INVALID_ARGUMENT; goto cleanup; } ctx = KSI_RequestHandle_getCtx(handle); KSI_ERR_clearErrors(ctx); wininetHandle = handle->implCtx; if (!HttpSendRequestA(wininetHandle->request_handle, NULL, 0, (LPVOID) handle->request, handle->request_length)) { WININET_ERROR_1(ctx, ERROR_INTERNET_CANNOT_CONNECT, KSI_NETWORK_ERROR, "WinINet: Unable to resolve host.") WININET_ERROR_m(ctx, ERROR_INTERNET_NAME_NOT_RESOLVED, KSI_NETWORK_ERROR, "WinINet: HTTP status code header not found.") WININET_ERROR_m(ctx, ERROR_INTERNET_TIMEOUT, KSI_NETWORK_SEND_TIMEOUT, NULL) WININET_ERROR_N(ctx, KSI_UNKNOWN_ERROR, "WinINet: Unable to send request.") } res = winINet_ReadFromHandle(handle, &resp, &resp_len); if (res != KSI_OK) { KSI_pushError(ctx, res, NULL); goto cleanup; } res = KSI_RequestHandle_setResponse(handle, resp, resp_len); if (res != KSI_OK) { KSI_pushError(ctx, res, NULL); goto cleanup; } res = KSI_OK; cleanup: KSI_free(resp); return res; }