CMS encryption/decryption from openssl broken

老子叫甜甜 提交于 2020-01-15 23:45:16

问题


So i navigated to the demos folder of openssl in

/usr/share/doc/libssl-doc/demos/cms

I compiled the test files there

gcc cms_enc.c -o enc -lssl -lcrypto
gcc cms_dec.c -o dec -lssl -lcrypto

Then i started both of them first ./enc then ./dec. Unfortunately the following error occured

140502142240416:error:0200B009:system library:fread:Bad file descriptor:bss_file.c:245:
140502142240416:error:20082002:BIO routines:FILE_READ:system lib:bss_file.c:246:
140502142240416:error:0606506D:digital envelope routines:EVP_DecryptFinal_ex:wrong final block length:evp_enc.c:532:

So that means that the CMS implementation in openSSL is broken already? i wanted to use that functionality for my own c++ program but it failed so i wanted to try if even the examples work..


回答1:


I compiled the test files there:

gcc cms_enc.c -o enc -lssl -lcrypto
gcc cms_dec.c -o dec -lssl -lcrypto
...

140502142240416:error:0200B009:system library:fread:Bad file descriptor:bss_file.c:245:

There's a typo in cms_dec.c. Scroll on down to line 50, and swap the out and the NULL. After the swap, it should look like:

/* Decrypt S/MIME message */
if (!CMS_decrypt(cms, rkey, rcert, NULL, out, 0))
    goto err;

Then recompile cms_dec.c. After the next run, there should be no error, and decout.txt should be as expected (the same as encr.txt).



来源:https://stackoverflow.com/questions/20937978/cms-encryption-decryption-from-openssl-broken

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!