Loading apps/cms.c +27 −0 Original line number Diff line number Diff line Loading @@ -86,6 +86,7 @@ static int smime_cb(int ok, X509_STORE_CTX *ctx); #define SMIME_DIGEST_CREATE (10 | SMIME_OP) #define SMIME_UNCOMPRESS (11 | SMIME_IP) #define SMIME_COMPRESS (12 | SMIME_OP) #define SMIME_ENCRYPTED_DECRYPT (13 | SMIME_IP) int MAIN(int, char **); Loading Loading @@ -121,6 +122,8 @@ int MAIN(int argc, char **argv) #ifndef OPENSSL_NO_ENGINE char *engine=NULL; #endif unsigned char *secret_key = NULL; size_t secret_keylen; X509_VERIFY_PARAM *vpm = NULL; Loading Loading @@ -164,6 +167,8 @@ int MAIN(int argc, char **argv) operation = SMIME_COMPRESS; else if (!strcmp (*args, "-uncompress")) operation = SMIME_UNCOMPRESS; else if (!strcmp (*args, "-EncrypedData_decrypt")) operation = SMIME_ENCRYPTED_DECRYPT; #ifndef OPENSSL_NO_DES else if (!strcmp (*args, "-des3")) cipher = EVP_des_ede3_cbc(); Loading Loading @@ -233,6 +238,20 @@ int MAIN(int argc, char **argv) flags |= CMS_NOOLDMIMETYPE; else if (!strcmp (*args, "-crlfeol")) flags |= CMS_CRLFEOL; else if (!strcmp(*args,"-secretkey")) { long ltmp; if (!args[1]) goto argerr; args++; secret_key = string_to_hex(*args, <mp); if (!secret_key) { BIO_printf(bio_err, "Invalid key %s\n", *args); goto argerr; } secret_keylen = (size_t)ltmp; } else if (!strcmp(*args,"-rand")) { if (!args[1]) Loading Loading @@ -810,6 +829,12 @@ int MAIN(int argc, char **argv) goto end; } } else if (operation == SMIME_ENCRYPTED_DECRYPT) { if (!CMS_EncryptedData_decrypt(cms, secret_key, secret_keylen, indata, out, flags)) goto end; } else if (operation == SMIME_VERIFY) { if (CMS_verify(cms, other, store, indata, out, flags) > 0) Loading Loading @@ -878,6 +903,8 @@ end: sk_free(sksigners); if (skkeys) sk_free(skkeys); if (secret_key) OPENSSL_free(secret_key); X509_STORE_free(store); X509_free(cert); X509_free(recip); Loading crypto/cms/cms.h +10 −0 Original line number Diff line number Diff line Loading @@ -138,6 +138,13 @@ int CMS_digest_verify(CMS_ContentInfo *cms, BIO *dcont, BIO *out, CMS_ContentInfo *CMS_digest_create(BIO *in, const EVP_MD *md, unsigned int flags); int CMS_EncryptedData_decrypt(CMS_ContentInfo *cms, const unsigned char *key, size_t keylen, BIO *dcont, BIO *out, unsigned int flags); int CMS_EncryptedData_set1_key(BIO *b, CMS_ContentInfo *cms, const unsigned char *key, size_t keylen); int CMS_verify(CMS_ContentInfo *cms, STACK_OF(X509) *certs, X509_STORE *store, BIO *dcont, BIO *out, unsigned int flags); Loading Loading @@ -255,6 +262,8 @@ void ERR_load_CMS_strings(void); #define CMS_F_CMS_DIGESTEDDATA_DO_FINAL 112 #define CMS_F_CMS_DIGEST_VERIFY 113 #define CMS_F_CMS_ENCRYPTEDCONTENT_TO_BIO 138 #define CMS_F_CMS_ENCRYPTEDDATA_DECRYPT 140 #define CMS_F_CMS_ENCRYPTED_DATA_DECRYPT 139 #define CMS_F_CMS_ENVELOPED_DATA_INIT 114 #define CMS_F_CMS_FINAL 115 #define CMS_F_CMS_GET0_CERTIFICATE_CHOICES 116 Loading Loading @@ -315,6 +324,7 @@ void ERR_load_CMS_strings(void); #define CMS_R_TYPE_NOT_COMPRESSED_DATA 128 #define CMS_R_TYPE_NOT_DATA 129 #define CMS_R_TYPE_NOT_DIGESTED_DATA 130 #define CMS_R_TYPE_NOT_ENCRYPTED_DATA 142 #define CMS_R_UNABLE_TO_FINALIZE_CONTEXT 131 #define CMS_R_UNKNOWN_CIPHER 141 #define CMS_R_UNKNOWN_DIGEST_ALGORIHM 132 Loading crypto/cms/cms_enc.c +12 −11 Original line number Diff line number Diff line Loading @@ -132,18 +132,11 @@ int cms_bio_to_EncryptedContent(CMS_EncryptedContentInfo *ec, /* Return BIO based on EncryptedContentInfo and key */ BIO *cms_EncryptedContent_to_bio(CMS_EncryptedContentInfo *ec, int cms_EncryptedContent_to_bio(BIO *b, CMS_EncryptedContentInfo *ec, const unsigned char *key, int keylen) { BIO *b; EVP_CIPHER_CTX *ctx; const EVP_CIPHER *ciph; b = BIO_new(BIO_f_cipher()); if (!b) { CMSerr(CMS_F_CMS_ENCRYPTEDCONTENT_TO_BIO, ERR_R_MALLOC_FAILURE); return NULL; } BIO_get_cipher_ctx(b, &ctx); ciph = EVP_get_cipherbyobj(ec->contentEncryptionAlgorithm->algorithm); Loading Loading @@ -187,10 +180,18 @@ BIO *cms_EncryptedContent_to_bio(CMS_EncryptedContentInfo *ec, CMS_R_CIPHER_PARAMETER_INITIALISATION_ERROR); goto err; } return b; return 1; err: BIO_free(b); return NULL; return 0; } int CMS_EncryptedData_set1_key(BIO *b, CMS_ContentInfo *cms, const unsigned char *key, size_t keylen) { CMS_EncryptedContentInfo *ec; if (OBJ_obj2nid(cms->contentType) != NID_pkcs7_encrypted) return 0; ec = cms->d.encryptedData->encryptedContentInfo; return cms_EncryptedContent_to_bio(b, ec, key, keylen); } crypto/cms/cms_err.c +3 −0 Original line number Diff line number Diff line Loading @@ -87,6 +87,8 @@ static ERR_STRING_DATA CMS_str_functs[]= {ERR_FUNC(CMS_F_CMS_DIGESTEDDATA_DO_FINAL), "CMS_DIGESTEDDATA_DO_FINAL"}, {ERR_FUNC(CMS_F_CMS_DIGEST_VERIFY), "CMS_digest_verify"}, {ERR_FUNC(CMS_F_CMS_ENCRYPTEDCONTENT_TO_BIO), "CMS_ENCRYPTEDCONTENT_TO_BIO"}, {ERR_FUNC(CMS_F_CMS_ENCRYPTEDDATA_DECRYPT), "CMS_EncryptedData_decrypt"}, {ERR_FUNC(CMS_F_CMS_ENCRYPTED_DATA_DECRYPT), "CMS_ENCRYPTED_DATA_DECRYPT"}, {ERR_FUNC(CMS_F_CMS_ENVELOPED_DATA_INIT), "CMS_ENVELOPED_DATA_INIT"}, {ERR_FUNC(CMS_F_CMS_FINAL), "CMS_final"}, {ERR_FUNC(CMS_F_CMS_GET0_CERTIFICATE_CHOICES), "CMS_GET0_CERTIFICATE_CHOICES"}, Loading Loading @@ -150,6 +152,7 @@ static ERR_STRING_DATA CMS_str_reasons[]= {ERR_REASON(CMS_R_TYPE_NOT_COMPRESSED_DATA),"type not compressed data"}, {ERR_REASON(CMS_R_TYPE_NOT_DATA) ,"type not data"}, {ERR_REASON(CMS_R_TYPE_NOT_DIGESTED_DATA),"type not digested data"}, {ERR_REASON(CMS_R_TYPE_NOT_ENCRYPTED_DATA),"type not encrypted data"}, {ERR_REASON(CMS_R_UNABLE_TO_FINALIZE_CONTEXT),"unable to finalize context"}, {ERR_REASON(CMS_R_UNKNOWN_CIPHER) ,"unknown cipher"}, {ERR_REASON(CMS_R_UNKNOWN_DIGEST_ALGORIHM),"unknown digest algorihm"}, Loading crypto/cms/cms_lcl.h +6 −0 Original line number Diff line number Diff line Loading @@ -412,6 +412,12 @@ BIO *cms_DigestAlgorithm_init_bio(X509_ALGOR *digestAlgorithm); int cms_DigestAlgorithm_find_ctx(EVP_MD_CTX *mctx, BIO *chain, X509_ALGOR *mdalg); int cms_bio_to_EncryptedContent(CMS_EncryptedContentInfo *ec, const unsigned char *key, int keylen, BIO *b); int cms_EncryptedContent_to_bio(BIO *b, CMS_EncryptedContentInfo *ec, const unsigned char *key, int keylen); #ifdef __cplusplus } #endif Loading Loading
apps/cms.c +27 −0 Original line number Diff line number Diff line Loading @@ -86,6 +86,7 @@ static int smime_cb(int ok, X509_STORE_CTX *ctx); #define SMIME_DIGEST_CREATE (10 | SMIME_OP) #define SMIME_UNCOMPRESS (11 | SMIME_IP) #define SMIME_COMPRESS (12 | SMIME_OP) #define SMIME_ENCRYPTED_DECRYPT (13 | SMIME_IP) int MAIN(int, char **); Loading Loading @@ -121,6 +122,8 @@ int MAIN(int argc, char **argv) #ifndef OPENSSL_NO_ENGINE char *engine=NULL; #endif unsigned char *secret_key = NULL; size_t secret_keylen; X509_VERIFY_PARAM *vpm = NULL; Loading Loading @@ -164,6 +167,8 @@ int MAIN(int argc, char **argv) operation = SMIME_COMPRESS; else if (!strcmp (*args, "-uncompress")) operation = SMIME_UNCOMPRESS; else if (!strcmp (*args, "-EncrypedData_decrypt")) operation = SMIME_ENCRYPTED_DECRYPT; #ifndef OPENSSL_NO_DES else if (!strcmp (*args, "-des3")) cipher = EVP_des_ede3_cbc(); Loading Loading @@ -233,6 +238,20 @@ int MAIN(int argc, char **argv) flags |= CMS_NOOLDMIMETYPE; else if (!strcmp (*args, "-crlfeol")) flags |= CMS_CRLFEOL; else if (!strcmp(*args,"-secretkey")) { long ltmp; if (!args[1]) goto argerr; args++; secret_key = string_to_hex(*args, <mp); if (!secret_key) { BIO_printf(bio_err, "Invalid key %s\n", *args); goto argerr; } secret_keylen = (size_t)ltmp; } else if (!strcmp(*args,"-rand")) { if (!args[1]) Loading Loading @@ -810,6 +829,12 @@ int MAIN(int argc, char **argv) goto end; } } else if (operation == SMIME_ENCRYPTED_DECRYPT) { if (!CMS_EncryptedData_decrypt(cms, secret_key, secret_keylen, indata, out, flags)) goto end; } else if (operation == SMIME_VERIFY) { if (CMS_verify(cms, other, store, indata, out, flags) > 0) Loading Loading @@ -878,6 +903,8 @@ end: sk_free(sksigners); if (skkeys) sk_free(skkeys); if (secret_key) OPENSSL_free(secret_key); X509_STORE_free(store); X509_free(cert); X509_free(recip); Loading
crypto/cms/cms.h +10 −0 Original line number Diff line number Diff line Loading @@ -138,6 +138,13 @@ int CMS_digest_verify(CMS_ContentInfo *cms, BIO *dcont, BIO *out, CMS_ContentInfo *CMS_digest_create(BIO *in, const EVP_MD *md, unsigned int flags); int CMS_EncryptedData_decrypt(CMS_ContentInfo *cms, const unsigned char *key, size_t keylen, BIO *dcont, BIO *out, unsigned int flags); int CMS_EncryptedData_set1_key(BIO *b, CMS_ContentInfo *cms, const unsigned char *key, size_t keylen); int CMS_verify(CMS_ContentInfo *cms, STACK_OF(X509) *certs, X509_STORE *store, BIO *dcont, BIO *out, unsigned int flags); Loading Loading @@ -255,6 +262,8 @@ void ERR_load_CMS_strings(void); #define CMS_F_CMS_DIGESTEDDATA_DO_FINAL 112 #define CMS_F_CMS_DIGEST_VERIFY 113 #define CMS_F_CMS_ENCRYPTEDCONTENT_TO_BIO 138 #define CMS_F_CMS_ENCRYPTEDDATA_DECRYPT 140 #define CMS_F_CMS_ENCRYPTED_DATA_DECRYPT 139 #define CMS_F_CMS_ENVELOPED_DATA_INIT 114 #define CMS_F_CMS_FINAL 115 #define CMS_F_CMS_GET0_CERTIFICATE_CHOICES 116 Loading Loading @@ -315,6 +324,7 @@ void ERR_load_CMS_strings(void); #define CMS_R_TYPE_NOT_COMPRESSED_DATA 128 #define CMS_R_TYPE_NOT_DATA 129 #define CMS_R_TYPE_NOT_DIGESTED_DATA 130 #define CMS_R_TYPE_NOT_ENCRYPTED_DATA 142 #define CMS_R_UNABLE_TO_FINALIZE_CONTEXT 131 #define CMS_R_UNKNOWN_CIPHER 141 #define CMS_R_UNKNOWN_DIGEST_ALGORIHM 132 Loading
crypto/cms/cms_enc.c +12 −11 Original line number Diff line number Diff line Loading @@ -132,18 +132,11 @@ int cms_bio_to_EncryptedContent(CMS_EncryptedContentInfo *ec, /* Return BIO based on EncryptedContentInfo and key */ BIO *cms_EncryptedContent_to_bio(CMS_EncryptedContentInfo *ec, int cms_EncryptedContent_to_bio(BIO *b, CMS_EncryptedContentInfo *ec, const unsigned char *key, int keylen) { BIO *b; EVP_CIPHER_CTX *ctx; const EVP_CIPHER *ciph; b = BIO_new(BIO_f_cipher()); if (!b) { CMSerr(CMS_F_CMS_ENCRYPTEDCONTENT_TO_BIO, ERR_R_MALLOC_FAILURE); return NULL; } BIO_get_cipher_ctx(b, &ctx); ciph = EVP_get_cipherbyobj(ec->contentEncryptionAlgorithm->algorithm); Loading Loading @@ -187,10 +180,18 @@ BIO *cms_EncryptedContent_to_bio(CMS_EncryptedContentInfo *ec, CMS_R_CIPHER_PARAMETER_INITIALISATION_ERROR); goto err; } return b; return 1; err: BIO_free(b); return NULL; return 0; } int CMS_EncryptedData_set1_key(BIO *b, CMS_ContentInfo *cms, const unsigned char *key, size_t keylen) { CMS_EncryptedContentInfo *ec; if (OBJ_obj2nid(cms->contentType) != NID_pkcs7_encrypted) return 0; ec = cms->d.encryptedData->encryptedContentInfo; return cms_EncryptedContent_to_bio(b, ec, key, keylen); }
crypto/cms/cms_err.c +3 −0 Original line number Diff line number Diff line Loading @@ -87,6 +87,8 @@ static ERR_STRING_DATA CMS_str_functs[]= {ERR_FUNC(CMS_F_CMS_DIGESTEDDATA_DO_FINAL), "CMS_DIGESTEDDATA_DO_FINAL"}, {ERR_FUNC(CMS_F_CMS_DIGEST_VERIFY), "CMS_digest_verify"}, {ERR_FUNC(CMS_F_CMS_ENCRYPTEDCONTENT_TO_BIO), "CMS_ENCRYPTEDCONTENT_TO_BIO"}, {ERR_FUNC(CMS_F_CMS_ENCRYPTEDDATA_DECRYPT), "CMS_EncryptedData_decrypt"}, {ERR_FUNC(CMS_F_CMS_ENCRYPTED_DATA_DECRYPT), "CMS_ENCRYPTED_DATA_DECRYPT"}, {ERR_FUNC(CMS_F_CMS_ENVELOPED_DATA_INIT), "CMS_ENVELOPED_DATA_INIT"}, {ERR_FUNC(CMS_F_CMS_FINAL), "CMS_final"}, {ERR_FUNC(CMS_F_CMS_GET0_CERTIFICATE_CHOICES), "CMS_GET0_CERTIFICATE_CHOICES"}, Loading Loading @@ -150,6 +152,7 @@ static ERR_STRING_DATA CMS_str_reasons[]= {ERR_REASON(CMS_R_TYPE_NOT_COMPRESSED_DATA),"type not compressed data"}, {ERR_REASON(CMS_R_TYPE_NOT_DATA) ,"type not data"}, {ERR_REASON(CMS_R_TYPE_NOT_DIGESTED_DATA),"type not digested data"}, {ERR_REASON(CMS_R_TYPE_NOT_ENCRYPTED_DATA),"type not encrypted data"}, {ERR_REASON(CMS_R_UNABLE_TO_FINALIZE_CONTEXT),"unable to finalize context"}, {ERR_REASON(CMS_R_UNKNOWN_CIPHER) ,"unknown cipher"}, {ERR_REASON(CMS_R_UNKNOWN_DIGEST_ALGORIHM),"unknown digest algorihm"}, Loading
crypto/cms/cms_lcl.h +6 −0 Original line number Diff line number Diff line Loading @@ -412,6 +412,12 @@ BIO *cms_DigestAlgorithm_init_bio(X509_ALGOR *digestAlgorithm); int cms_DigestAlgorithm_find_ctx(EVP_MD_CTX *mctx, BIO *chain, X509_ALGOR *mdalg); int cms_bio_to_EncryptedContent(CMS_EncryptedContentInfo *ec, const unsigned char *key, int keylen, BIO *b); int cms_EncryptedContent_to_bio(BIO *b, CMS_EncryptedContentInfo *ec, const unsigned char *key, int keylen); #ifdef __cplusplus } #endif Loading