<div>Hi,</div><div><br></div><div>Since <b>OC_Crypt::encrypt</b> and <b> OC_Crypt::decrypt</b> are used for string data I assume that there were an issue with decoded string size and rtrim was added to fix it without taking into account the file decryption case.</div>
<div>Probably it will be handy to add the <b>OC_Crypt::encryptString</b> and <b>OC_Crypt::decryptString</b> wrappers for strings and do not call <b>OC_Crypt::encrypt </b>and <b>OC_Crypt::decrypt</b> directly.</div><div>
<br></div><div>Btw, base64_encode is not a good idea since it creates significant overhead for the file size.</div><div><br></div><div>I did a quick search and found no Linux GUI tool for binary comparison so I have written the script for testing [1]. </div>
<div>It's self-explanatory, the only thing one needs to change is the lines #3-5. For sure, it is slow with large files so I don't recommend it for testing files over 1MB.</div><div><br></div><div>[1] <a href="http://owncube.com/apps/files_sharing/get.php?token=9f177ed2e197b12bc6af7bc4af588f1abf603cfc">http://owncube.com/apps/files_sharing/get.php?token=9f177ed2e197b12bc6af7bc4af588f1abf603cfc</a></div>
<div><br></div><div>---</div><div>Victor Dubiniuk</div><div><br><div class="gmail_quote">On Wed, Jun 13, 2012 at 7:05 PM, Frank Karlitschek <span dir="ltr"><<a href="mailto:frank@owncloud.org" target="_blank">frank@owncloud.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Wow.<br>
Very good catch.<br>
<br>
Now the question is why was the rtrim here in the first place. I can´t remember if this is my code from last summer ob from someone else :-)<br>
<span class="HOEnZb"><font color="#888888"><br>
<br>
Frank<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
<br>
On 13.06.2012, at 17:18, Victor Dubiniuk <<a href="mailto:victor.dubiniuk@gmail.com">victor.dubiniuk@gmail.com</a>> wrote:<br>
<br>
> My apologies for sending the incomplete message.<br>
><br>
> I used 4.0.2 to debug the encryption and found that the problem is in the OC_Crypt::decrypt - it strips all 0x00 characters at the 8KB block boundary.<br>
> Please check the encryption with the attached files. One has 32 of 0x00 inside and another one is the same but has 0x05 at the 7th position.<br>
><br>
> When I change apps/files_encryption/lib/crypt.php line #136<br>
> return rtrim($data, "\0");<br>
> to<br>
> return $data;<br>
><br>
> the file is decrypted correctly except the fact that it's last block is padded with 0x00. (Tested on *.exe ~ 7MB)<br>
><br>
> ---<br>
> Victor Dubiniuk<br>
><br>><br>
> On Wed, Jun 13, 2012 at 4:45 AM, Michael Gapczynski <<a href="mailto:mtgap@owncloud.com">mtgap@owncloud.com</a>> wrote:<br>
> On Tuesday, June 12, 2012 12:52:06 PM Klaas Freitag wrote:<br>
> > On 04.06.2012 18:33, Klaas Freitag wrote:<br>
> > > On 04.06.2012 18:13, Frank Karlitschek wrote:<br>
> > >> Hi,<br>
> > >><br>
> > >> we have a very evil bug report about corrupted files together with the<br>
> > >> encryption app.<br>
> > >><br>
> > >> <a href="http://bugs.owncloud.org/thebuggenie/owncloud/issues/oc-912" target="_blank">http://bugs.owncloud.org/thebuggenie/owncloud/issues/oc-912</a><br>
> > >> <a href="http://forum.owncloud.org/viewtopic.php?f=3&t=2726" target="_blank">http://forum.owncloud.org/viewtopic.php?f=3&t=2726</a><br>
> > >><br>
> > >> Everything works for me and I can´t find the problem<br>
> > >> Can someone help me with reproducing it?<br>
> > ><br>
> > > I can reproduce it with a Firefox on Linux and on Windows 7. I have<br>
> > > master running from this morning.<br>
> ><br>
> > Frank, do you think that<br>
> > <a href="http://bugs.owncloud.org/thebuggenie/owncloud/issues/oc-669" target="_blank">http://bugs.owncloud.org/thebuggenie/owncloud/issues/oc-669</a><br>
> > can be related to this problem? Is there a fix already for #912?<br>
> ><br>
> > Thanks,<br>
> ><br>
> > Klaas<br>
><br>
> It seems that binary data has problems going through the encryption. I did<br>
> some research and read that base64_encode()/decode() should allow binary files<br>
> to be encrypted. My attempts to encode and decode the data with base64 still<br>
> result in corrupted binary files.<br>
><br>
> <a href="http://bytes.com/topic/php/answers/8958-binary-encryption" target="_blank">http://bytes.com/topic/php/answers/8958-binary-encryption</a><br>
><br>
> <a href="http://stackoverflow.com/questions/6033972/encrypting-files-with-php-mcrypt-" target="_blank">http://stackoverflow.com/questions/6033972/encrypting-files-with-php-mcrypt-</a><br>
> is-corrupting-docx-and-other-microsoft-office<br>
><br>
> <a href="http://www.itnewb.com/tutorial/PHP-Encryption-Decryption-Using-the-MCrypt-" target="_blank">http://www.itnewb.com/tutorial/PHP-Encryption-Decryption-Using-the-MCrypt-</a><br>
> Library-libmcrypt<br>
><br>
><br>
><br>
> Michael<br>
> _______________________________________________<br>
> Owncloud mailing list<br>
> <a href="mailto:Owncloud@kde.org">Owncloud@kde.org</a><br>
> <a href="https://mail.kde.org/mailman/listinfo/owncloud" target="_blank">https://mail.kde.org/mailman/listinfo/owncloud</a><br>
><br>
><br>
> _______________________________________________<br>
> Owncloud mailing list<br>
> <a href="mailto:Owncloud@kde.org">Owncloud@kde.org</a><br>
> <a href="https://mail.kde.org/mailman/listinfo/owncloud" target="_blank">https://mail.kde.org/mailman/listinfo/owncloud</a><br>
<br>
</div></div></blockquote></div><br></div>