We'd like to try to use it fo our project www.openca.org
Look at it and at the mailing list if you're interested in security and
digital signature problems and developing.
Thanks
Andrea
-----Messaggio originale-----
Da: Sebastian Akerman <[EMAIL PROTECTED]>
A: [EMAIL PROTECTED] <[EMAIL PROTECTED]>
Data: luned� 3 maggio 1999 19.43
Oggetto: S/MIME support in openssl-0.9.2b
>I've been trying to get the PKCS#7 stuff in openssl-0.9.2b work
>with S/MIME emails to/from Netscape Messenger and MS Outlook.
>After some research in the openssl code and by analyzing the
>pkcs7 encodings from Messenger and Outlook I have concluded that
>the following changes (or at least some of them) are necessary.
>Please correct me if I'm wrong about any of this. With these changes
>S/MIME messages can be decoded/verified and encoded for use with
>Messenger and Outlook (I haven't managed to make signatures
>verify in Outlook yet ... still something missing?).
>
>I have done the following, rows added/changed are marked with
>a + and function context is shown as **** function_decl
>(patches and example program follows as attachments):
>
>crypt/objects/objects.h:
>
> #define SN_rc2_40_cbc "RC2-40-CBC"
> #define LN_rc2_40_cbc "rc2-40-cbc"
> #define NID_rc2_40_cbc 98
>+ /* OID added, sak */
>+ #define OBJ_rc2_40_cbc OBJ_rsadsi,3L,2L
>...
>
>+ /* NID_rc2_64_cbc added by sak */
>+ #define SN_rc2_64_cbc "RC2-64-CBC"
>+ #define LN_rc2_64_cbc "rc2-64-cbc"
>+ #define NID_rc2_64_cbc 143
>+ /* OID added, sak */
>+ #define OBJ_rc2_64_cbc OBJ_rsadsi,3L,2L
>
>Comments: No OBJ defined for 40 bit rc2. Same as for 128 bit but needs to
be
> there for encoding.
>
>crypt/evp/m_sha1.c:
>
> static EVP_MD sha1_md=
> {
> NID_sha1,
>+ NID_rsaEncryption, /* Had to change this from sha1WithRSAEncryption, sak
*/
> SHA_DIGEST_LENGTH,
> SHA1_Init,
> SHA1_Update,
> SHA1_Final,
> EVP_PKEY_RSA_method,
> SHA_CBLOCK,
> sizeof(EVP_MD *)+sizeof(SHA_CTX),
> };
>
>Comments: Bad encryption algorithm in sha1 struct.
>
>
>crypt/evp/bio_enc.c: **** static int enc_read(b,out,outl)
>
> /* Should be continue next time we are called? */
> if (!BIO_should_retry(b->next_bio))
> {
> ctx->cont=i;
> i=EVP_CipherFinal(&(ctx->cipher),
> (unsigned char *)ctx->buf,
> &(ctx->buf_len));
> ctx->ok=i;
> ctx->buf_off=0;
>
>+ /* Last block copy needed. sak */
>+ i=outl<ctx->buf_len ? outl:ctx->buf_len;
>+ memcpy(out,ctx->buf,i);
>+ outl-=i;
>+ out+=i;
>+ ret+=i;
> }
>Comments: I frequently loose data at the end when decrypting. May be a
padding problem but this
>hack fixes it for now. This would cause a lot of other problems for other
applications so I'm most
>likely doing something wrong.
>
>crypt/evp/e_cbc_r2.c:
>
> static EVP_CIPHER r2_64_cbc_cipher=
> {
>+ NID_rc2_64_cbc, /* NID_rc2_40_cbc, sak */
> 8,8 /* 64 bit */,8,
> rc2_cbc_init_key,
> rc2_cbc_cipher,
> NULL,
> sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+
> sizeof((((EVP_CIPHER_CTX *)NULL)->c.rc2_ks)),
> rc2_set_asn1_type_and_iv,
> rc2_get_asn1_type_and_iv,
> };
>
>... **** static EVP_CIPHER *rc2_magic_to_meth(i)
>
> static int rc2_meth_to_magic(e)
> EVP_CIPHER *e;
> {
> int i;
>
> i=EVP_CIPHER_key_length(e);
>+ if (i == 16) return(RC2_128_MAGIC); /* i == 128 sak */
>+ else if (i == 8) return(RC2_64_MAGIC); /* i == 64 sak */
>+ else if (i == 5) return(RC2_40_MAGIC); /* i == 40 sak */
> else return(0);
> }
>
>Comments: Bad NID for 64 bit rc2 (had to hitch with 40 bit previously). The
magic
>number matching failed, should be bytes not bits.
>
>
>crypt/pkcs7/pk7_doit.c: **** BIO *PKCS7_dataInit(p7,bio)
>
>+ #if 0
> os=ASN1_OCTET_STRING_new();
> ASN1_OCTET_STRING_set(os,iv,ivlen);
> /* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX this needs to change */
> if (xalg->parameter == NULL)
> xalg->parameter=ASN1_TYPE_new();
> ASN1_TYPE_set(xalg->parameter,V_ASN1_OCTET_STRING,
> (char *)os);
>+ #endif
>
>...
>
> for (i=0; i<sk_num(rsk); i++)
> {
> ri=(PKCS7_RECIP_INFO *)sk_value(rsk,i);
> pkey=X509_get_pubkey(ri->cert);
> jj=EVP_PKEY_encrypt(tmp,key,keylen,pkey);
> EVP_PKEY_free(pkey);
> if (jj <= 0)
> {
> PKCS7err(PKCS7_F_PKCS7_DATAINIT,ERR_R_EVP_LIB);
> Free(tmp);
> goto err;
> }
> ASN1_OCTET_STRING_set(ri->enc_key,tmp,jj);
> }
> Free(tmp);
>
>+ /* Need to set the algorithm parameter using context. sak */
> BIO_set_cipher(btmp,evp_cipher,key,iv,1);
>+ if (ivlen > 0) {
>+ BIO_get_cipher_ctx(btmp, &evp_ctx);
>+ evp_cipher->set_asn1_parameters(evp_ctx,xalg->parameter);
>+ }
>
>... **** BIO *PKCS7_dataDecode(p7,pkey,in_bio,xs)
>
> evp_ctx=NULL;
> BIO_get_cipher_ctx(etmp,&evp_ctx);
> EVP_CipherInit(evp_ctx,evp_cipher,NULL,NULL,0);
>+ /* Added support for non RC2 ciphers, sak */
>+ if (evp_cipher->get_asn1_parameters != NULL &&
>+ evp_cipher->get_asn1_parameters(evp_ctx,enc_alg->parameter) < 0)
> return(NULL);
>
>... **** int PKCS7_dataFinal(p7,bio)
>
> /* Add content type, sak */
> PKCS7_add_signed_attribute(si,
> NID_pkcs9_contentType,
> V_ASN1_OBJECT,(char *)OBJ_nid2obj(NID_pkcs7_data));
>
> /* Add signing time */
> sign_time=X509_gmtime_adj(NULL,0);
> PKCS7_add_signed_attribute(si,
> NID_pkcs9_signingTime,
> V_ASN1_UTCTIME,(char *)sign_time);
>
>Coments: Bad decoding of RC2 parameter, it now decodes the magic
>number and patches the cipher correctly (I hope?). Added a pkcs7
>content type object to signed attributes.
>
>
>The smime.c program demonstrates how to create a signed and
>enveloped S/MIME message using the pkcs7 stuff. I only need to
>figure out why Outlook wont recognize the signature.
>
>Hope this is of use for someone.
>
>Sebastian Akerman
>Parallel Consulting Group Int
>
>
______________________________________________________________________
OpenSSL Project http://www.openssl.org
Development Mailing List [EMAIL PROTECTED]
Automated List Manager [EMAIL PROTECTED]