|
Lines 907-919
cleanup:
Link Here
|
| 907 |
int KSI_PKITruststore_verifyRawSignature(KSI_CTX *ctx, const unsigned char *data, size_t data_len, const char *algoOid, const unsigned char *signature, size_t signature_len, const KSI_PKICertificate *certificate) { |
907 |
int KSI_PKITruststore_verifyRawSignature(KSI_CTX *ctx, const unsigned char *data, size_t data_len, const char *algoOid, const unsigned char *signature, size_t signature_len, const KSI_PKICertificate *certificate) { |
| 908 |
int res; |
908 |
int res; |
| 909 |
ASN1_OBJECT* algorithm = NULL; |
909 |
ASN1_OBJECT* algorithm = NULL; |
| 910 |
EVP_MD_CTX md_ctx; |
910 |
EVP_MD_CTX *md_ctx; |
| 911 |
X509 *x509 = NULL; |
911 |
X509 *x509 = NULL; |
| 912 |
const EVP_MD *evp_md; |
912 |
const EVP_MD *evp_md; |
| 913 |
EVP_PKEY *pubKey = NULL; |
913 |
EVP_PKEY *pubKey = NULL; |
| 914 |
|
914 |
|
| 915 |
/* Needs to be initialized before jumping to cleanup. */ |
915 |
/* Needs to be initialized before jumping to cleanup. */ |
| 916 |
EVP_MD_CTX_init(&md_ctx); |
916 |
md_ctx = EVP_MD_CTX_create(); |
| 917 |
|
917 |
|
| 918 |
KSI_ERR_clearErrors(ctx); |
918 |
KSI_ERR_clearErrors(ctx); |
| 919 |
|
919 |
|
|
Lines 956-972
int KSI_PKITruststore_verifyRawSignature
Link Here
|
| 956 |
goto cleanup; |
956 |
goto cleanup; |
| 957 |
} |
957 |
} |
| 958 |
|
958 |
|
| 959 |
if (!EVP_VerifyInit(&md_ctx, evp_md)) { |
959 |
if (!EVP_VerifyInit(md_ctx, evp_md)) { |
| 960 |
KSI_pushError(ctx, res = KSI_CRYPTO_FAILURE, NULL); |
960 |
KSI_pushError(ctx, res = KSI_CRYPTO_FAILURE, NULL); |
| 961 |
goto cleanup; |
961 |
goto cleanup; |
| 962 |
} |
962 |
} |
| 963 |
|
963 |
|
| 964 |
if (!EVP_VerifyUpdate(&md_ctx, (unsigned char *)data, data_len)) { |
964 |
if (!EVP_VerifyUpdate(md_ctx, (unsigned char *)data, data_len)) { |
| 965 |
KSI_pushError(ctx, res = KSI_CRYPTO_FAILURE, NULL); |
965 |
KSI_pushError(ctx, res = KSI_CRYPTO_FAILURE, NULL); |
| 966 |
goto cleanup; |
966 |
goto cleanup; |
| 967 |
} |
967 |
} |
| 968 |
|
968 |
|
| 969 |
res = EVP_VerifyFinal(&md_ctx, (unsigned char *)signature, (unsigned)signature_len, pubKey); |
969 |
res = EVP_VerifyFinal(md_ctx, (unsigned char *)signature, (unsigned)signature_len, pubKey); |
| 970 |
if (res < 0) { |
970 |
if (res < 0) { |
| 971 |
KSI_pushError(ctx, res = KSI_CRYPTO_FAILURE, NULL); |
971 |
KSI_pushError(ctx, res = KSI_CRYPTO_FAILURE, NULL); |
| 972 |
goto cleanup; |
972 |
goto cleanup; |
|
Lines 982-988
int KSI_PKITruststore_verifyRawSignature
Link Here
|
| 982 |
|
982 |
|
| 983 |
cleanup: |
983 |
cleanup: |
| 984 |
|
984 |
|
| 985 |
EVP_MD_CTX_cleanup(&md_ctx); |
985 |
EVP_MD_CTX_destroy(md_ctx); |
| 986 |
if (algorithm != NULL) ASN1_OBJECT_free(algorithm); |
986 |
if (algorithm != NULL) ASN1_OBJECT_free(algorithm); |
| 987 |
if (pubKey != NULL) EVP_PKEY_free(pubKey); |
987 |
if (pubKey != NULL) EVP_PKEY_free(pubKey); |
| 988 |
|
988 |
|