2011-04-15 9 views

Respuesta

24

Con la herramienta de línea de comandos, asumiendo el mensaje S/MIME en sí está en el archivo message:

openssl smime -verify -in message -noverify -signer cert.pem -out textdata 

Esto escribe el certificado del firmante (como incrustado en el blob firma) en cert.pem, y el texto del mensaje datos en el archivo textdata.

Como alternativa, puede guardar el blob de firma como un archivo independiente (es solo un tipo de archivo adjunto, por lo que cualquier aplicación de correo o biblioteca debería poder hacerlo.) Suponiendo que dicho blob está en un archivo llamado smime.p7s, utilice:.

openssl pkcs7 -in smime.p7s -inform DER -print_certs 

que imprima todos los certificados que están incrustados en el PKCS # 7 firma Tenga en cuenta que puede haber varias: el certificado del firmante sí mismo, y todos los certificados adicionales que el firmante de la correspondiente autorización para incluir (por ejemplo, certificados CA intermedios que pueden ayudar a validar su certificado).

+0

¿Cómo puedo verificar y extraer datos de gran pkcs7 chamuscado envuelva? ¿Hay alguna opción en openssl para que pueda procesar el fragmento en lugar de no cargar todo el archivo? – Ashish

10

O r simplemente:

cat message.eml | openssl smime -pk7out | openssl pkcs7 -print_certs > senders-cert.pem 
+1

Estaba buscando una forma de obtener información de certificados sin crear archivos (solo tuberías y filtros), y esto es todo. Como no estoy interesado en el certificado en sí, hago el último comando 'openssl pkcs7 -print_certs -noout' – Liam

1

Si está escribiendo en C/C++, este fragmento de código ayudaría

//...assuming you have valid pkcs7, st1, m_store etc...... 

    verifyResult = PKCS7_verify(pkcs7, st1, m_store, content, out, flags); 
    if(verifyResult != 1) { 
     goto exit_free; 
    } 

    //Obtain the signers of this message. Certificates from st1 as well as any found included 
    //in the message will be returned. 
    signers = PKCS7_get0_signers(pkcs7, st1, flags); 
    if (!save_certs(env, signerFilePath, signers)) { 
     //Error log 
    } 

//This method will write the signer certificates into a file provided 
int save_certs(JNIEnv *env, jstring signerFilePath, STACK_OF(X509) *signers) 
{ 
    int result = 0; 
    int i; 
    BIO *tmp; 
    int num_certificates = 0; 

    if (signerFilePath == NULL) { 
     return 0; 
    } 

    const char *signerfile = (const char *)env->GetStringUTFChars(signerFilePath, 0); 
    tmp = BIO_new_file(signerfile, "w"); 
    if (!tmp) { 
     //error. return 
    } 
    num_certificates = sk_X509_num(signers); 
    for(i = 0; i < num_certificates; i++) { 
     PEM_write_bio_X509(tmp, sk_X509_value(signers, i)); 
    } 
    result = 1; 

    exit_free: 
    BIO_free(tmp); 
    if (signerfile) { 
     env->ReleaseStringUTFChars(signerFilePath, signerfile); 
     signerfile = 0; 
    } 
    return result; 
} 
Cuestiones relacionadas