美文网首页工作生活
X509_STORE 与 X509_STORE_CTX的用法区别

X509_STORE 与 X509_STORE_CTX的用法区别

作者: 阿群1986 | 来源:发表于2019-07-03 10:38 被阅读0次

    https://stackoverflow.com/questions/16291809/programmatically-verify-certificate-chain-using-openssl-api

    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 */
    }
    
    image.png

    相关文章

      网友评论

        本文标题:X509_STORE 与 X509_STORE_CTX的用法区别

        本文链接:https://www.haomeiwen.com/subject/fqzfhctx.html