Pergunta

Eu queria extrair as informações do assinante da imagem de código assinada do PKCS#7 usando C/CPP. Eu queria saber as API do OpenSSL. Eu sou capaz de extrair usando o castelo saltitante (cmsSignedData).

Informe -me as APIs OpenSSL que posso usar no C/CPP para extrair as informações de cada signatário e signer e verificar os signatários.

Existe alguma API como x509_lookup_buffer () em vez de x509_lookup_file () ???

Obrigado antecipadamente openSid

Foi útil?

Solução

Eu tive um problema parecido. Eu tive que extrair o atributo SigningTime de uma assinatura PKCS#7. Não consegui encontrar a solução definitiva na internet, mas pude pegar pedaços e peças de vários lugares e vim até isso. Talvez haja uma maneira mais agradável/melhor/mais segura, é a primeira vez que eu faço isso, mas parece funcionar.

Em uma função, eu tenho p_pkcs7sigsize bytes de assinatura PKCS#7 em um buffer apontando por const void *p_pkcs7sig. Eu recebi o tempo de assinatura com isso. Eu removi o manuseio de erros, não use este código detalhado!

BIO                         *v_in          = NULL;
PKCS7                       *v_p7          = NULL;
STACK_OF(PKCS7_SIGNER_INFO) *v_signerInfos = NULL;
PKCS7_SIGNER_INFO           *v_signerInfo  = NULL;
ASN1_TYPE                   *v_asn1SigningTime  = NULL;

/* make BIO for input buffer */
v_in = BIO_new_mem_buf( (void*)(uintptr_t) p_pkcs7Sig, p_pkcs7SigSize );

/* make a PKCS7 object of it */
v_p7 = d2i_PKCS7_bio( v_in, NULL);

/* get all signer infos */
v_signerInfos = PKCS7_get_signer_info( v_p7 );

/* if you need all signer infos then loop through all, 
 * count you get by k_PKCS7_SIGNER_INFO_num(v_signerInfos) 
 */

/* get the first signer info */
v_signerInfo = sk_PKCS7_SIGNER_INFO_value(v_signerInfos,0);

/* get signing time */
v_asn1SigningTime = PKCS7_get_signed_attribute( v_signerInfo, NID_pkcs9_signingTime );

/* You should got a v_asn1SigningTime->type == V_ASN1_UTCTIME, 
 * if yes then the actual value is in the string buffer at
 * v_asn1SigningTime->value.utctime->data 
 */

if ( v_in )
{
   BIO_free_all( v_in );
   v_in = NULL;
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top