专栏中心

EEPW首页 > 专栏 > X509_STORE 与 X509_STORE_CTX的用法区别

X509_STORE 与 X509_STORE_CTX的用法区别

发布人:电子禅石 时间:2021-04-02 来源:工程师 发布文章

static int  verify_cb(int ok, X509_STORE_CTX *ctx)

{

    if (!ok)

    {

        /* check the error code and current cert*/

        X509 *currentCert = X509_STORE_CTX_get_current_cert(ctx);

        int certError = X509_STORE_CTX_get_error(ctx);

        int depth = X509_STORE_CTX_get_error_depth(ctx);

        printCert(currentCert);

        printf("Error depth %d, certError %d", depth, certError)

    }

 

    return(ok);

}

 

int verify_cert(X509 *cert, X509 *cacert)// 使用右侧的CA证书cacert校验左侧的普通证书cert

{

     int ret;

     X509_STORE *store;

     X509_STORE_CTX *ctx;

 

     store = X509_STORE_new();

     X509_STORE_set_verify_cb(store, verify_cb);

     X590_STORE_add_cert(store, cacert);

 

     ctx = X509_STORE_CTX_new();

     X509_STORE_CTX_init(ctx, store, cert, NULL);

 

     ret = X590_verify_cert(ctx);

 

     /* check for errors and clean up */

}


18

I am here just to post my answer as I found it with the above comments.

I had no certificate chain, so in the work I'm doing I only have a certificate generated by me programatically. I wanted to check the validity of it, so I created the following function, which checks the certificate against itself in other to verify the validity of it.

void check_certificate_validaty(X509* certificate)
{
    int status;
    X509_STORE_CTX *ctx;
    ctx = X509_STORE_CTX_new();
    X509_STORE *store = X509_STORE_new();

    X509_STORE_add_cert(store, certificate);

    X509_STORE_CTX_init(ctx, store, certificate, NULL);

    status = X509_verify_cert(ctx);
    if(status == 1)
    {
        printf("Certificate verified ok\n");
    }else
    {
        printf("%s\n", X509_verify_cert_error_string(ctx->error));
    }
}


专栏文章内容及配图由作者撰写发布,仅供工程师学习之用,如有侵权或者其他违规问题,请联系本站处理。 联系我们

关键词:

相关推荐

意法半导体公布2024年第四季度及全年财报和电话会议时间安排

Crucial英睿达扩大旗下内存和存储产品组合,为消费者带来崭新性能体验

数码相机的电路图

C64+ 系列DSP上Cache 的应用(第一部分)

视频 2009-10-16

【供应商亮点】OLEDWorks将展示下一代数字OLED技术

光电显示 2025-01-10

数字集成电路40系列pdf文件

ADS62C17 数据转换器

学子专区-ADALM2000实验:包络检波器

C64+ 系列DSP上Cache 的应用(第二部分)

视频 2009-10-16

音频控制电路集锦

由Arm驱动的NVIDIA Project DIGITS为数百万开发者带来高性能AI算力

想要BMS高效稳定?电流感应电阻解决方案了解下!

电工·电子基础精选电路详解

TI Zigbee 射频芯片RF4CE 以及RemoTI 开发包

视频 2009-10-16

高性能系列DSP上TCP2/VCP2协处理器

视频 2009-10-16

阿斯顿·马丁沙特阿美一级方程式赛车车队与Arm携手在全球最高技术含量的运动中促进公平性和AI创新

国产FPGA SoC芯选择,米尔安路飞龙核心板重磅发布

【供应商亮点】Aurora Innovation启用在美国蒙大拿州新建的激光雷达测试设施

搭载国产最新8nm制程SOC,米尔RK3576开发板初体验!

嵌入式系统 2025-01-11

实用机床电路图集

更多 培训课堂
更多 焦点
更多 视频

技术专区