Source Code/My Patch

[Openssl3] CMP freeText ๊ธฐ๋Šฅ ์ถ”๊ฐ€

JayKim๐Ÿ™‚ 2022. 8. 22. 17:30

cmp.h.in ์— ํ—ค๋” ์ถ”๊ฐ€

STACK_OF(OSSL_CMP_ITAV) *OSSL_CMP_exec_GENM_ses2(OSSL_CMP_CTX *ctx, ASN1_UTF8STRING **ppFreeText );
const ASN1_UTF8STRING* OSSL_CMP_get0_freeText( OSSL_CMP_PKIHEADER *hdr );
int OSSL_CMP_set0_freeText( OSSL_CMP_CTX *ctx, ASN1_UTF8STRING *text );
 
 
cmp_ctx.c ์†Œ์Šค ์— ์ถ”๊ฐ€
const ASN1_UTF8STRING* OSSL_CMP_get0_freeText( OSSL_CMP_PKIHEADER *hdr )
{
    if( hdr == NULL ) return NULL;


    return hdr->freeText;
}


int OSSL_CMP_set0_freeText( OSSL_CMP_CTX *ctx, ASN1_UTF8STRING *text )
{
    if( ctx == NULL ) return 0;

    if( ctx->freeText )
    {
        ASN1_UTF8STRING_free( ctx->freeText );
        ctx->freeText = NULL;
    }

    ctx->freeText = text;

    return 1;
}
 
cmp_client.c ์†Œ์Šค์— ์ถ”๊ฐ€
STACK_OF(OSSL_CMP_ITAV) *OSSL_CMP_exec_GENM_ses2(OSSL_CMP_CTX *ctx, ASN1_UTF8STRING **ppFreeText )
{
    OSSL_CMP_MSG *genm;
    OSSL_CMP_MSG *genp = NULL;
    STACK_OF(OSSL_CMP_ITAV) *rcvd_itavs = NULL;


    if (ctx == NULL) {
        ERR_raise(ERR_LIB_CMP, CMP_R_INVALID_ARGS);
        return 0;
    }
    ctx->status = -1;


    if ((genm = ossl_cmp_genm_new(ctx)) == NULL)
        goto err;


    if (!send_receive_check(ctx, genm, &genp, OSSL_CMP_PKIBODY_GENP))
        goto err;


    /* received stack of itavs not to be freed with the genp */
    rcvd_itavs = genp->body->value.genp;
    genp->body->value.genp = NULL;


    if( genp->header )
    {
        ASN1_UTF8STRING *pVal = sk_ASN1_UTF8STRING_value( genp->header->freeText, 0);
        if( pVal ) *ppFreeText = ASN1_STRING_dup( pVal );
    }


 err:


    OSSL_CMP_MSG_free(genm);
    OSSL_CMP_MSG_free(genp);


    return rcvd_itavs; /* recv_itavs == NULL indicates an error */    
}

์œˆ๋„์šฐ ์ง€์›์„ ์œ„ํ•ด์„œ๋Š”

utils/libcrypto.num ์— ํ•จ์ˆ˜๋ช…์„ ์ถ”๊ฐ€ ํ•ด ์ฃผ์–ด์•ผ ํ•œ๋‹ค.

๋ฐ˜์‘ํ˜•