[ 
https://issues.apache.org/jira/browse/DIRKRB-256?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Xu Yaning updated DIRKRB-256:
-----------------------------
    Description: 
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}

  was:
In {{EncryptionTest.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()}}.
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}


> 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: Bug
>            Reporter: Xu Yaning
>            Assignee: Xu Yaning
>
> 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)

Reply via email to