如何以编程方式生成openssl证书时添加关键用法?

时间:2015-07-13 11:10:07

标签: c openssl

生成自签名证书但无法在c程序中添加关键用法。

我在我的代码中包含了以下功能,但缺少了一些东西..

STACK_OF( X509_EXTENSION )  *ext_list;
ASN1_OBJECT                 *obj;
X509_EXTENSION              *ext;
INT                         crit;
INT                         i;
ASN1_OCTET_STRING           *data;
INT                         n;

    //
    // Certificate Extension
    //
    cert_inf = xcert -> cert_info;

    ext_list = cert_inf -> extensions;

    n= sk_X509_EXTENSION_num ( ext_list );

    for ( i = 0; i < n; i++ )
    {
        ext = sk_X509_EXTENSION_value ( ext_list, i );

        //
        // Makes a copy of obj, frees the object subfield of ex if it is 
        // setand stuffs it with the new copy of obj instead.
        //
        ret= X509_EXTENSION_set_object ( ext, obj );
        if ( 0 == ret )
        {
            printf ( "\tERROR in X509_EXTENSION_set_object\n" );
            hResult = GetLastError ( );
            __leave;
        }// if

        //
        // Sets the critical subfield of ex if crit is nonxero, or clears 
        // it if crit is zero. 
        //
        ret= X509_EXTENSION_set_critical( ext, crit );
        if ( 0 == ret )
        {
            printf ( "\tERROR in X509_EXTENSION_set_critical\n" );
            hResult = GetLastError ( );
            __leave;
        }// if

        //
        // Sets the value subfield of ex to the ASN1_OCTET_STRING pointed
        // to by data.
        //
        ret= X509_EXTENSION_set_data( ext, data );
        if ( 0 == ret )
        {
            printf ( "\tERROR in X509_EXTENSION_set_data\n" );
            hResult = GetLastError ( );
            __leave;
        }// if

    }// for

请帮助解决这个问题...

我希望openssl证书(.cer)在详细信息字段下包含关键字..

0 个答案:

没有答案