提交 3f3326b2 编写于 作者: A andrew

8228440: TestAESCiphers tests fail with "access denied" trying to access ArrayUtil

Summary: Move dependencies into the com.sun.crypto.provider package
Reviewed-by: shade

--HG--
rename : src/share/classes/jdk/internal/util/Preconditions.java => src/share/classes/com/sun/crypto/provider/Preconditions.java
上级 2de2f7dd
...@@ -29,8 +29,6 @@ import java.security.InvalidKeyException; ...@@ -29,8 +29,6 @@ import java.security.InvalidKeyException;
import java.security.ProviderException; import java.security.ProviderException;
import java.util.Objects; import java.util.Objects;
import sun.security.util.ArrayUtil;
/** /**
* This class represents ciphers in cipher block chaining (CBC) mode. * This class represents ciphers in cipher block chaining (CBC) mode.
* *
...@@ -144,9 +142,9 @@ class CipherBlockChaining extends FeedbackCipher { ...@@ -144,9 +142,9 @@ class CipherBlockChaining extends FeedbackCipher {
if (plainLen <= 0) { if (plainLen <= 0) {
return plainLen; return plainLen;
} }
ArrayUtil.blockSizeCheck(plainLen, blockSize); RangeUtil.blockSizeCheck(plainLen, blockSize);
ArrayUtil.nullAndBoundsCheck(plain, plainOffset, plainLen); RangeUtil.nullAndBoundsCheck(plain, plainOffset, plainLen);
ArrayUtil.nullAndBoundsCheck(cipher, cipherOffset, plainLen); RangeUtil.nullAndBoundsCheck(cipher, cipherOffset, plainLen);
return implEncrypt(plain, plainOffset, plainLen, return implEncrypt(plain, plainOffset, plainLen,
cipher, cipherOffset); cipher, cipherOffset);
} }
...@@ -194,9 +192,9 @@ class CipherBlockChaining extends FeedbackCipher { ...@@ -194,9 +192,9 @@ class CipherBlockChaining extends FeedbackCipher {
if (cipherLen <= 0) { if (cipherLen <= 0) {
return cipherLen; return cipherLen;
} }
ArrayUtil.blockSizeCheck(cipherLen, blockSize); RangeUtil.blockSizeCheck(cipherLen, blockSize);
ArrayUtil.nullAndBoundsCheck(cipher, cipherOffset, cipherLen); RangeUtil.nullAndBoundsCheck(cipher, cipherOffset, cipherLen);
ArrayUtil.nullAndBoundsCheck(plain, plainOffset, cipherLen); RangeUtil.nullAndBoundsCheck(plain, plainOffset, cipherLen);
return implDecrypt(cipher, cipherOffset, cipherLen, plain, plainOffset); return implDecrypt(cipher, cipherOffset, cipherLen, plain, plainOffset);
} }
......
...@@ -27,7 +27,6 @@ package com.sun.crypto.provider; ...@@ -27,7 +27,6 @@ package com.sun.crypto.provider;
import java.security.InvalidKeyException; import java.security.InvalidKeyException;
import java.security.ProviderException; import java.security.ProviderException;
import sun.security.util.ArrayUtil;
/** /**
* This class represents ciphers in cipher-feedback (CFB) mode. * This class represents ciphers in cipher-feedback (CFB) mode.
...@@ -150,9 +149,9 @@ final class CipherFeedback extends FeedbackCipher { ...@@ -150,9 +149,9 @@ final class CipherFeedback extends FeedbackCipher {
*/ */
int encrypt(byte[] plain, int plainOffset, int plainLen, int encrypt(byte[] plain, int plainOffset, int plainLen,
byte[] cipher, int cipherOffset) { byte[] cipher, int cipherOffset) {
ArrayUtil.blockSizeCheck(plainLen, numBytes); RangeUtil.blockSizeCheck(plainLen, numBytes);
ArrayUtil.nullAndBoundsCheck(plain, plainOffset, plainLen); RangeUtil.nullAndBoundsCheck(plain, plainOffset, plainLen);
ArrayUtil.nullAndBoundsCheck(cipher, cipherOffset, plainLen); RangeUtil.nullAndBoundsCheck(cipher, cipherOffset, plainLen);
int nShift = blockSize - numBytes; int nShift = blockSize - numBytes;
int loopCount = plainLen / numBytes; int loopCount = plainLen / numBytes;
...@@ -227,9 +226,9 @@ final class CipherFeedback extends FeedbackCipher { ...@@ -227,9 +226,9 @@ final class CipherFeedback extends FeedbackCipher {
int decrypt(byte[] cipher, int cipherOffset, int cipherLen, int decrypt(byte[] cipher, int cipherOffset, int cipherLen,
byte[] plain, int plainOffset) { byte[] plain, int plainOffset) {
ArrayUtil.blockSizeCheck(cipherLen, numBytes); RangeUtil.blockSizeCheck(cipherLen, numBytes);
ArrayUtil.nullAndBoundsCheck(cipher, cipherOffset, cipherLen); RangeUtil.nullAndBoundsCheck(cipher, cipherOffset, cipherLen);
ArrayUtil.nullAndBoundsCheck(plain, plainOffset, cipherLen); RangeUtil.nullAndBoundsCheck(plain, plainOffset, cipherLen);
int nShift = blockSize - numBytes; int nShift = blockSize - numBytes;
int loopCount = cipherLen / numBytes; int loopCount = cipherLen / numBytes;
......
...@@ -27,8 +27,6 @@ package com.sun.crypto.provider; ...@@ -27,8 +27,6 @@ package com.sun.crypto.provider;
import java.security.InvalidKeyException; import java.security.InvalidKeyException;
import sun.security.util.ArrayUtil;
/** /**
* This class represents ciphers in counter (CTR) mode. * This class represents ciphers in counter (CTR) mode.
* *
...@@ -175,8 +173,8 @@ final class CounterMode extends FeedbackCipher { ...@@ -175,8 +173,8 @@ final class CounterMode extends FeedbackCipher {
return 0; return 0;
} }
ArrayUtil.nullAndBoundsCheck(in, inOff, len); RangeUtil.nullAndBoundsCheck(in, inOff, len);
ArrayUtil.nullAndBoundsCheck(out, outOff, len); RangeUtil.nullAndBoundsCheck(out, outOff, len);
int result = len; int result = len;
while (len-- > 0) { while (len-- > 0) {
......
...@@ -27,7 +27,6 @@ package com.sun.crypto.provider; ...@@ -27,7 +27,6 @@ package com.sun.crypto.provider;
import java.security.InvalidKeyException; import java.security.InvalidKeyException;
import java.security.ProviderException; import java.security.ProviderException;
import sun.security.util.ArrayUtil;
/** /**
* This class represents ciphers in electronic codebook (ECB) mode. * This class represents ciphers in electronic codebook (ECB) mode.
...@@ -113,9 +112,9 @@ final class ElectronicCodeBook extends FeedbackCipher { ...@@ -113,9 +112,9 @@ final class ElectronicCodeBook extends FeedbackCipher {
* @return the length of the encrypted data * @return the length of the encrypted data
*/ */
int encrypt(byte[] in, int inOff, int len, byte[] out, int outOff) { int encrypt(byte[] in, int inOff, int len, byte[] out, int outOff) {
ArrayUtil.blockSizeCheck(len, blockSize); RangeUtil.blockSizeCheck(len, blockSize);
ArrayUtil.nullAndBoundsCheck(in, inOff, len); RangeUtil.nullAndBoundsCheck(in, inOff, len);
ArrayUtil.nullAndBoundsCheck(out, outOff, len); RangeUtil.nullAndBoundsCheck(out, outOff, len);
for (int i = len; i >= blockSize; i -= blockSize) { for (int i = len; i >= blockSize; i -= blockSize) {
embeddedCipher.encryptBlock(in, inOff, out, outOff); embeddedCipher.encryptBlock(in, inOff, out, outOff);
...@@ -143,9 +142,9 @@ final class ElectronicCodeBook extends FeedbackCipher { ...@@ -143,9 +142,9 @@ final class ElectronicCodeBook extends FeedbackCipher {
* @return the length of the decrypted data * @return the length of the decrypted data
*/ */
int decrypt(byte[] in, int inOff, int len, byte[] out, int outOff) { int decrypt(byte[] in, int inOff, int len, byte[] out, int outOff) {
ArrayUtil.blockSizeCheck(len, blockSize); RangeUtil.blockSizeCheck(len, blockSize);
ArrayUtil.nullAndBoundsCheck(in, inOff, len); RangeUtil.nullAndBoundsCheck(in, inOff, len);
ArrayUtil.nullAndBoundsCheck(out, outOff, len); RangeUtil.nullAndBoundsCheck(out, outOff, len);
for (int i = len; i >= blockSize; i -= blockSize) { for (int i = len; i >= blockSize; i -= blockSize) {
embeddedCipher.decryptBlock(in, inOff, out, outOff); embeddedCipher.decryptBlock(in, inOff, out, outOff);
......
...@@ -30,7 +30,6 @@ import java.io.*; ...@@ -30,7 +30,6 @@ import java.io.*;
import java.security.*; import java.security.*;
import javax.crypto.*; import javax.crypto.*;
import static com.sun.crypto.provider.AESConstants.AES_BLOCK_SIZE; import static com.sun.crypto.provider.AESConstants.AES_BLOCK_SIZE;
import sun.security.util.ArrayUtil;
/** /**
...@@ -424,12 +423,12 @@ final class GaloisCounterMode extends FeedbackCipher { ...@@ -424,12 +423,12 @@ final class GaloisCounterMode extends FeedbackCipher {
int encrypt(byte[] in, int inOfs, int len, byte[] out, int outOfs) { int encrypt(byte[] in, int inOfs, int len, byte[] out, int outOfs) {
checkDataLength(processed, len); checkDataLength(processed, len);
ArrayUtil.blockSizeCheck(len, blockSize); RangeUtil.blockSizeCheck(len, blockSize);
processAAD(); processAAD();
if (len > 0) { if (len > 0) {
ArrayUtil.nullAndBoundsCheck(in, inOfs, len); RangeUtil.nullAndBoundsCheck(in, inOfs, len);
ArrayUtil.nullAndBoundsCheck(out, outOfs, len); RangeUtil.nullAndBoundsCheck(out, outOfs, len);
gctrPAndC.update(in, inOfs, len, out, outOfs); gctrPAndC.update(in, inOfs, len, out, outOfs);
processed += len; processed += len;
...@@ -456,7 +455,7 @@ final class GaloisCounterMode extends FeedbackCipher { ...@@ -456,7 +455,7 @@ final class GaloisCounterMode extends FeedbackCipher {
("Can't fit both data and tag into one buffer"); ("Can't fit both data and tag into one buffer");
} }
try { try {
ArrayUtil.nullAndBoundsCheck(out, outOfs, RangeUtil.nullAndBoundsCheck(out, outOfs,
(len + tagLenBytes)); (len + tagLenBytes));
} catch (ArrayIndexOutOfBoundsException aiobe) { } catch (ArrayIndexOutOfBoundsException aiobe) {
throw new ShortBufferException("Output buffer too small"); throw new ShortBufferException("Output buffer too small");
...@@ -466,7 +465,7 @@ final class GaloisCounterMode extends FeedbackCipher { ...@@ -466,7 +465,7 @@ final class GaloisCounterMode extends FeedbackCipher {
processAAD(); processAAD();
if (len > 0) { if (len > 0) {
ArrayUtil.nullAndBoundsCheck(in, inOfs, len); RangeUtil.nullAndBoundsCheck(in, inOfs, len);
doLastBlock(in, inOfs, len, out, outOfs, true); doLastBlock(in, inOfs, len, out, outOfs, true);
} }
...@@ -503,14 +502,14 @@ final class GaloisCounterMode extends FeedbackCipher { ...@@ -503,14 +502,14 @@ final class GaloisCounterMode extends FeedbackCipher {
int decrypt(byte[] in, int inOfs, int len, byte[] out, int outOfs) { int decrypt(byte[] in, int inOfs, int len, byte[] out, int outOfs) {
checkDataLength(ibuffer.size(), len); checkDataLength(ibuffer.size(), len);
ArrayUtil.blockSizeCheck(len, blockSize); RangeUtil.blockSizeCheck(len, blockSize);
processAAD(); processAAD();
if (len > 0) { if (len > 0) {
// store internally until decryptFinal is called because // store internally until decryptFinal is called because
// spec mentioned that only return recovered data after tag // spec mentioned that only return recovered data after tag
// is successfully verified // is successfully verified
ArrayUtil.nullAndBoundsCheck(in, inOfs, len); RangeUtil.nullAndBoundsCheck(in, inOfs, len);
ibuffer.write(in, inOfs, len); ibuffer.write(in, inOfs, len);
} }
return 0; return 0;
...@@ -545,7 +544,7 @@ final class GaloisCounterMode extends FeedbackCipher { ...@@ -545,7 +544,7 @@ final class GaloisCounterMode extends FeedbackCipher {
checkDataLength(ibuffer.size(), (len - tagLenBytes)); checkDataLength(ibuffer.size(), (len - tagLenBytes));
try { try {
ArrayUtil.nullAndBoundsCheck(out, outOfs, RangeUtil.nullAndBoundsCheck(out, outOfs,
(ibuffer.size() + len) - tagLenBytes); (ibuffer.size() + len) - tagLenBytes);
} catch (ArrayIndexOutOfBoundsException aiobe) { } catch (ArrayIndexOutOfBoundsException aiobe) {
throw new ShortBufferException("Output buffer too small"); throw new ShortBufferException("Output buffer too small");
...@@ -553,7 +552,7 @@ final class GaloisCounterMode extends FeedbackCipher { ...@@ -553,7 +552,7 @@ final class GaloisCounterMode extends FeedbackCipher {
processAAD(); processAAD();
ArrayUtil.nullAndBoundsCheck(in, inOfs, len); RangeUtil.nullAndBoundsCheck(in, inOfs, len);
// get the trailing tag bytes from 'in' // get the trailing tag bytes from 'in'
byte[] tag = new byte[tagLenBytes]; byte[] tag = new byte[tagLenBytes];
......
...@@ -27,7 +27,6 @@ package com.sun.crypto.provider; ...@@ -27,7 +27,6 @@ package com.sun.crypto.provider;
import java.security.InvalidKeyException; import java.security.InvalidKeyException;
import java.security.ProviderException; import java.security.ProviderException;
import sun.security.util.ArrayUtil;
/** /**
* This class represents ciphers in output-feedback (OFB) mode. * This class represents ciphers in output-feedback (OFB) mode.
...@@ -149,9 +148,9 @@ final class OutputFeedback extends FeedbackCipher { ...@@ -149,9 +148,9 @@ final class OutputFeedback extends FeedbackCipher {
*/ */
int encrypt(byte[] plain, int plainOffset, int plainLen, int encrypt(byte[] plain, int plainOffset, int plainLen,
byte[] cipher, int cipherOffset) { byte[] cipher, int cipherOffset) {
ArrayUtil.blockSizeCheck(plainLen, numBytes); RangeUtil.blockSizeCheck(plainLen, numBytes);
ArrayUtil.nullAndBoundsCheck(plain, plainOffset, plainLen); RangeUtil.nullAndBoundsCheck(plain, plainOffset, plainLen);
ArrayUtil.nullAndBoundsCheck(cipher, cipherOffset, plainLen); RangeUtil.nullAndBoundsCheck(cipher, cipherOffset, plainLen);
int nShift = blockSize - numBytes; int nShift = blockSize - numBytes;
int loopCount = plainLen / numBytes; int loopCount = plainLen / numBytes;
...@@ -190,8 +189,8 @@ final class OutputFeedback extends FeedbackCipher { ...@@ -190,8 +189,8 @@ final class OutputFeedback extends FeedbackCipher {
*/ */
int encryptFinal(byte[] plain, int plainOffset, int plainLen, int encryptFinal(byte[] plain, int plainOffset, int plainLen,
byte[] cipher, int cipherOffset) { byte[] cipher, int cipherOffset) {
ArrayUtil.nullAndBoundsCheck(plain, plainOffset, plainLen); RangeUtil.nullAndBoundsCheck(plain, plainOffset, plainLen);
ArrayUtil.nullAndBoundsCheck(cipher, cipherOffset, plainLen); RangeUtil.nullAndBoundsCheck(cipher, cipherOffset, plainLen);
int oddBytes = plainLen % numBytes; int oddBytes = plainLen % numBytes;
int len = encrypt(plain, plainOffset, (plainLen - oddBytes), int len = encrypt(plain, plainOffset, (plainLen - oddBytes),
......
...@@ -27,8 +27,6 @@ package com.sun.crypto.provider; ...@@ -27,8 +27,6 @@ package com.sun.crypto.provider;
import java.security.InvalidKeyException; import java.security.InvalidKeyException;
import java.security.ProviderException; import java.security.ProviderException;
import sun.security.util.ArrayUtil;
/** /**
* This class represents ciphers in Plaintext Cipher Block Chaining (PCBC) * This class represents ciphers in Plaintext Cipher Block Chaining (PCBC)
...@@ -137,9 +135,9 @@ final class PCBC extends FeedbackCipher { ...@@ -137,9 +135,9 @@ final class PCBC extends FeedbackCipher {
int encrypt(byte[] plain, int plainOffset, int plainLen, int encrypt(byte[] plain, int plainOffset, int plainLen,
byte[] cipher, int cipherOffset) byte[] cipher, int cipherOffset)
{ {
ArrayUtil.blockSizeCheck(plainLen, blockSize); RangeUtil.blockSizeCheck(plainLen, blockSize);
ArrayUtil.nullAndBoundsCheck(plain, plainOffset, plainLen); RangeUtil.nullAndBoundsCheck(plain, plainOffset, plainLen);
ArrayUtil.nullAndBoundsCheck(cipher, cipherOffset, plainLen); RangeUtil.nullAndBoundsCheck(cipher, cipherOffset, plainLen);
int i; int i;
int endIndex = plainOffset + plainLen; int endIndex = plainOffset + plainLen;
...@@ -178,9 +176,9 @@ final class PCBC extends FeedbackCipher { ...@@ -178,9 +176,9 @@ final class PCBC extends FeedbackCipher {
int decrypt(byte[] cipher, int cipherOffset, int cipherLen, int decrypt(byte[] cipher, int cipherOffset, int cipherLen,
byte[] plain, int plainOffset) byte[] plain, int plainOffset)
{ {
ArrayUtil.blockSizeCheck(cipherLen, blockSize); RangeUtil.blockSizeCheck(cipherLen, blockSize);
ArrayUtil.nullAndBoundsCheck(cipher, cipherOffset, cipherLen); RangeUtil.nullAndBoundsCheck(cipher, cipherOffset, cipherLen);
ArrayUtil.nullAndBoundsCheck(plain, plainOffset, cipherLen); RangeUtil.nullAndBoundsCheck(plain, plainOffset, cipherLen);
int i; int i;
int endIndex = cipherOffset + cipherLen; int endIndex = cipherOffset + cipherLen;
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
* or visit www.oracle.com if you need additional information or have any * or visit www.oracle.com if you need additional information or have any
* questions. * questions.
*/ */
package jdk.internal.util; package com.sun.crypto.provider;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
......
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.crypto.provider;
import java.util.List;
import java.util.function.BiFunction;
import java.security.*;
/**
* This class holds the various utility methods for range checks.
*/
final class RangeUtil {
private static final BiFunction<String, List<Integer>,
ArrayIndexOutOfBoundsException> AIOOBE_SUPPLIER =
Preconditions.outOfBoundsExceptionFormatter
(ArrayIndexOutOfBoundsException::new);
public static void blockSizeCheck(int len, int blockSize) {
if ((len % blockSize) != 0) {
throw new ProviderException("Internal error in input buffering");
}
}
public static void nullAndBoundsCheck(byte[] array, int offset, int len) {
// NPE is thrown when array is null
Preconditions.checkFromIndexSize(offset, len, array.length, AIOOBE_SUPPLIER);
}
}
...@@ -25,34 +25,12 @@ ...@@ -25,34 +25,12 @@
package sun.security.util; package sun.security.util;
import java.util.List;
import java.util.function.BiFunction;
import java.security.*;
import jdk.internal.util.Preconditions;
/** /**
* This class holds the various utility methods for array range checks. * This class holds the various utility methods for array range checks.
*/ */
public final class ArrayUtil { public final class ArrayUtil {
private static final BiFunction<String, List<Integer>,
ArrayIndexOutOfBoundsException> AIOOBE_SUPPLIER =
Preconditions.outOfBoundsExceptionFormatter
(ArrayIndexOutOfBoundsException::new);
public static void blockSizeCheck(int len, int blockSize) {
if ((len % blockSize) != 0) {
throw new ProviderException("Internal error in input buffering");
}
}
public static void nullAndBoundsCheck(byte[] array, int offset, int len) {
// NPE is thrown when array is null
Preconditions.checkFromIndexSize(offset, len, array.length, AIOOBE_SUPPLIER);
}
private static void swap(byte[] arr, int i, int j) { private static void swap(byte[] arr, int i, int j) {
byte tmp = arr[i]; byte tmp = arr[i];
arr[i] = arr[j]; arr[i] = arr[j];
......
...@@ -23,13 +23,12 @@ ...@@ -23,13 +23,12 @@
/** /**
* @test * @test
* @summary Objects.checkIndex/jdk.internal.util.Preconditions.checkIndex tests * @summary com.sun.crypto.provider.Preconditions.checkIndex tests
* @run testng CheckIndex * @run testng CheckIndex
* @bug 8135248 8142493 8155794 * @bug 8135248 8142493 8155794
* @modules java.base/jdk.internal.util
*/ */
import jdk.internal.util.Preconditions; import com.sun.crypto.provider.Preconditions;
import org.testng.annotations.DataProvider; import org.testng.annotations.DataProvider;
import org.testng.annotations.Test; import org.testng.annotations.Test;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册