Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix develop build #312

Merged
merged 2 commits into from
Feb 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public final class CryptoStreamFactory {
private static final Logger log = LoggerFactory.getLogger(CryptoStreamFactory.class);
private static final Properties PROPS = ApacheCiphers.forceOpenSsl(new Properties());
private static final String AES_ALGORITHM = "AES/CTR/NoPadding";
private static final String OPEN_SSL_INIT_WARNING = "Unable to initialize cipher with OpenSSL, falling back to "
+ "JCE implementation - see github.com/palantir/hadoop-crypto";

private static volatile boolean fullExceptionLoggedAlready = false;

Expand Down Expand Up @@ -100,13 +102,10 @@ static OutputStream encrypt(OutputStream output, KeyMaterial keyMaterial, String

/** To avoid spamming logs with exceptions, we only log the exception once. */
private static void warningLog(IOException exception) {
String message = "Unable to initialize cipher with OpenSSL, falling back to JCE implementation "
+ "- see github.com/palantir/hadoop-crypto";

if (fullExceptionLoggedAlready) {
log.warn(message);
log.warn(OPEN_SSL_INIT_WARNING);
} else {
log.warn(message, exception);
log.warn(OPEN_SSL_INIT_WARNING, exception);
fullExceptionLoggedAlready = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static org.assertj.core.api.Assertions.assertThat;

import com.google.common.io.BaseEncoding;
import com.palantir.crypto2.keys.KeyMaterial;
import java.util.Arrays;
import java.util.LinkedHashMap;
Expand All @@ -26,7 +27,6 @@
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.spec.SecretKeySpec;
import javax.xml.bind.DatatypeConverter;
import org.junit.Test;

public final class AesCtrCipherTest extends AbstractSeekableCipherTest {
Expand Down Expand Up @@ -73,10 +73,10 @@ public void testNistDecrypt() {
}

public void testNistExample(int opmode, int blockNumber, String input, String output) {
byte[] key = DatatypeConverter.parseHexBinary(KEY);
byte[] iv = DatatypeConverter.parseHexBinary(IV);
byte[] inputBytes = DatatypeConverter.parseHexBinary(input);
byte[] outputBytes = DatatypeConverter.parseHexBinary(output);
byte[] key = hexToBinary(KEY);
byte[] iv = hexToBinary(IV);
byte[] inputBytes = hexToBinary(input);
byte[] outputBytes = hexToBinary(output);

KeyMaterial keyMaterial = KeyMaterial.of(new SecretKeySpec(key, AesCtrCipher.KEY_ALGORITHM), iv);
SeekableCipher seekableCipher = getCipher(keyMaterial);
Expand Down Expand Up @@ -133,4 +133,7 @@ public void testIvUnderflow() {
cipher.seek(100);
}

private static byte[] hexToBinary(String hex) {
return BaseEncoding.base16().lowerCase().decode(hex);
}
}