入力:opensslで完了した大きなマルチパート署名済みおよび暗号化メール(〜10MB)。大きなメールを復号化して確認するためのM2Cryptoのパフォーマンスが悪い
ファイルを復号化するのが十分に速いようです。
これらを確認するために復号化された情報を得ることは、それ以上のものです。 M2Cryptoライブラリには問題があるようです。 smime_load_pkcs7_bio
をファイルに置き換えてp7s +を書き込むと、それはsmime_load_pkcs7
と表示されます。しかし、私はディスク上の書き込み/読み取りを避けたい(今の私のボトルネックなので)。
質問: 誰かがこのパフォーマンスの問題に対していくつかの回避策または解決策を持っていますか?
のpython 2.7のコード:
from M2Crypto import SMIME, X509, BIO, m2
# read signed and encrypted file
with open("toto.p7m", "r") as p7mFile:
p7mBio = BIO.File(p7mFile)
p7m = SMIME.PKCS7(m2.pkcs7_read_bio_der(p7mBio._ptr()), 1)
s = SMIME.SMIME()
# Decrypt
s.load_key('cnt.key', 'cnt.crt', callback = lambda x : 'cnt_password.info')
p7s = s.decrypt(p7m)
print("Decryption ok (and fast).")
# Verify
p7s_bio = BIO.MemoryBuffer(p7s)
p7, data = SMIME.smime_load_pkcs7_bio(p7s_bio)
# MUCH FASTER !!!
#p7, data = SMIME.smime_load_pkcs7('toto.p7s')
print("Wow this long to load something that is in memory!")
sk = p7.get0_signers(X509.X509_Stack())
if 0 == len(sk) :
print("ERROR : No signers.")
s.set_x509_stack(sk)
st = X509.X509_Store()
st.load_info('ca.crt')
s.set_x509_store(st)
v = s.verify(p7, data)
if v:
print("Client signature verified.")
else:
print("ERROR : Signature verification FAILED.")
を生成するキー/ certsのメール
dd if=/dev/urandom of=sample1.jpg bs=1K count=743
dd if=/dev/urandom of=sample2.jpg bs=1K count=3009
dd if=/dev/urandom of=sample3.xml bs=1K count=5
dd if=/dev/urandom of=sample4.mp4 bs=1K count=2864
に行くためのテストデータを生成する
# generate control authority (key+cert)
openssl genrsa -out ca.key 2048 -passout file:ca_password.info
openssl req -x509 -new -nodes -key ca.key -passin file:ca_password.info -days 7300 -sha256 -extensions v3_ca -out ca.crt -subj "/C=XX/ST=Xxxxxx/L=XXXX/O=XXXXX/OU=XXXX/CN=XXX Xxxx XX"
openssl x509 -noout -text -in ca.crt
# generate client key + cert for CNT
openssl genrsa -out cnt.key 2048 -passout file:cnt_password.info
openssl req -new -key cnt.key -out cnt.csr -subj "/C=XX/ST=Xxxxxx/L=XXXX/O=XXXXX/OU=XXXX/CN=CNT xxxx"
echo "authorityKeyIdentifier = keyid,issuer" > cnt.ext
echo "basicConstraints = CA:FALSE" >> cnt.ext
echo "keyUsage = digitalSignature, keyEncipherment" >> cnt.ext
echo "subjectKeyIdentifier = hash" >> cnt.ext
openssl x509 -req -in cnt.csr -passin file:cnt_password.info -CA ca.crt -CAkey ca.key -CAcreateserial -out cnt.crt -days 1024 -extfile cnt.ext
openssl x509 -noout -text -in cnt.crt
# generate client key + cert for ET
openssl genrsa -out et.key 2048 -passout file:et_password.info
openssl req -new -key et.key -out et.csr -subj "/C=XX/ST=Xxxxxx/L=XXXX/O=XXXXX/OU=XXXX/CN=ET xxxx"
echo "authorityKeyIdentifier = keyid,issuer" > et.ext
echo "basicConstraints = CA:FALSE" >> et.ext
echo "keyUsage = digitalSignature, keyEncipherment" >> et.ext
echo "subjectKeyIdentifier = hash" >> et.ext
openssl x509 -req -in et.csr -passin file:et_password.info -CA ca.crt -CAkey ca.key -CAcreateserial -out et.crt -days 1024 -extfile et.ext
openssl x509 -noout -text -in et.crt
メールを作成する
メールは、Mail/mime.phpライブラリでPHPコードによって生成されます。
<?php
date_default_timezone_set('Europe/Paris');
require_once 'Mail/mime.php';
function add_fichier_2_mail(&$mime, $filename) {
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime_type=finfo_file($finfo,$filename);
finfo_close($finfo);
$mime->addAttachment($filename, $mime_type);
}
$crlf = "\n";
$mime_mif = new Mail_mime($crlf);
add_fichier_2_mail($mime_mif, "sample1.jpg");
add_fichier_2_mail($mime_mif, "sample2.jpg");
add_fichier_2_mail($mime_mif, "sample3.xml");
add_fichier_2_mail($mime_mif, "sample4.mp4");
$body = $mime_mif->get();
$hdrs=array();
$entete = $mime_mif->headers($hdrs);
unset($mime_mif);
$msg='';
foreach ($entete as $key=>$value) {
$msg.=$key.': '.$value.$crlf;
}
$msg.=$crlf.$crlf.$body;
file_put_contents("email_clear.eml",$msg);
?>
ログイン/メールがET秘密鍵によって署名され、その後、CNT公開証明書によって暗号化された電子メールに
を暗号化します。これは、次のコマンドを与える:
openssl smime -sign -binary -nodetach -certfile et.crt -signer et.crt -inkey et.key -in email_clear.eml -out email_signed.p7s
openssl smime -encrypt -outform DER -binary -des3 -in email_signed.p7s -out email_crypted_signed.p7m cnt.crt
サンプル.key/.crtと問題が再現するダミーメールを提供できますか? +ライブラリ/ python/osのバージョン – ffeast
これは非常にばかげたハックですが、 'smime_load_pkcs7'を使ってRAMディスクを作成してそれに書き込むのはどうでしょうか? –
なぜでしょうか。それは望ましい解決策ではありませんが、それは仕事をします。あなたは完全な答えでそれを詳述できますか? – TrapII