directory-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kai Zheng (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (DIRKRB-256) Add a new test for encryption that input is not multiple 8 bytes
Date Thu, 14 May 2015 08:07:00 GMT

    [ https://issues.apache.org/jira/browse/DIRKRB-256?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14543356#comment-14543356
] 

Kai Zheng commented on DIRKRB-256:
----------------------------------

Thanks Yaning for the great work adding such tests! It looks pretty good to me. Review passed.

> Add a new test for encryption that input is not multiple 8 bytes
> ----------------------------------------------------------------
>
>                 Key: DIRKRB-256
>                 URL: https://issues.apache.org/jira/browse/DIRKRB-256
>             Project: Directory Kerberos
>          Issue Type: Test
>            Reporter: Xu Yaning
>            Assignee: Xu Yaning
>         Attachments: DIRKRB-256-v1.patch
>
>
> I have added a new test for encryption that input is not multiple 8 bytes. In {{NewEncryptionTest.java}},
when the input length is not multiple of 8 bytes, the encryption process will come up with
errors. there is sth wrong with {{paddingSize()}}, and I'll solve it in DIRKRB-257.
> The following code test it.
> {code}
> public class NewEncryptionTest {
>     @Test
>     public void testDes3CbcSha1() throws IOException, KrbException {
>         testEncWith(EncryptionType.DES3_CBC_SHA1);
>     }
>     /**
>      * Decryption can leave a little trailing cruft. For the current cryptosystems, this
can be up to 7 bytes.
>      * @param inData
>      * @param outData
>      * @return
>      */
>     private boolean compareResult(byte[] inData, byte[] outData) {
>         if (inData.length > outData.length || inData.length + 8 <= outData.length)
{
>             return false;
>         }
>         byte[] resultData = Arrays.copyOf(outData, inData.length);
>         if (Arrays.equals(inData, resultData)) {
>             return true;
>         } else {
>             return false;
>         }
>     }
>     private void testEncWith(EncryptionType eType) throws KrbException {
>         byte[] inData1 = "This is a test.\n".getBytes();
>         byte[] inData2 = "This is another test.\n".getBytes();
>         EncryptionKey key = EncryptionHandler.random2Key(eType);
>         EncryptedData enctryData1 = EncryptionHandler.encrypt(inData1, key, KeyUsage.AD_ITE);
>         EncryptedData enctryData2 = EncryptionHandler.encrypt(inData2, key, KeyUsage.AD_ITE);
>         byte[] outData1 = EncryptionHandler.decrypt(enctryData1, key, KeyUsage.AD_ITE);
>         byte[] outData2 = EncryptionHandler.decrypt(enctryData2, key, KeyUsage.AD_ITE);
>         if (compareResult(inData1, outData1)) {
>             System.out.println(eType + ": Success, inData1 & outData1 are the same!");
>         } else {
>             System.err.println(eType + ": Failed, inData1 & outData1 are not the
same!");
>         }
>         if (compareResult(inData2, outData2)) {
>             System.out.println(eType + ": Success, inData2 & outData2 are the same!");
>         } else {
>             System.err.println(eType + ": Failed, inData2 & outData2 are not the
same!");
>         }
>     }
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message