Pregunta

Quería extraer la información del firmante de la imagen de código firmado de PKC#7 usando C/CPP. Quería saber la API de OpenSSL. Puedo extraer usando el castillo hinchable (cmssigneddata).

Hágame saber las API OpenSSL que puedo usar en C/CPP para extraer cada firma y información de firmantes y verificar los firmantes.

¿Hay alguna API como x509_lookup_buffer () en lugar de x509_lookup_file () ???

Gracias de antemano OpenSid

¿Fue útil?

Solución

Tuve un problema similar. Tuve que extraer el atributo FirmingTime de una firma PKCS#7. No pude encontrar la solución definitiva en Internet, pero pude recoger bits y piezas de varios lugares y llegué a esto. Tal vez hay una forma más agradable/mejor/más segura, es la primera vez que estoy haciendo esto, pero parece funcionar.

En una función tengo bytes p_pkcs7sigsize de la firma PKC#7 en un búfer que apunta por const void *p_pkcs7sig. Obtuve tiempo de firma por esto. He eliminado el manejo de errores, ¡no use este código detallado!

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 bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top