Alon Bar-Lev has uploaded a new change for review. Change subject: pki: cleanup: favor Charset.getName() over plain string ......................................................................
pki: cleanup: favor Charset.getName() over plain string Change-Id: Id61cad58356820a73683666235d328a72582486b Signed-off-by: Alon Bar-Lev <alo...@redhat.com> --- M backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/crypt/EncryptionUtils.java M backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/hostinstall/OpenSslCAWrapper.java 2 files changed, 12 insertions(+), 11 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/92/13192/1 diff --git a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/crypt/EncryptionUtils.java b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/crypt/EncryptionUtils.java index bd94324..f683b86 100644 --- a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/crypt/EncryptionUtils.java +++ b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/crypt/EncryptionUtils.java @@ -4,8 +4,8 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; -import java.io.UnsupportedEncodingException; import java.math.BigInteger; +import java.nio.charset.Charset; import java.security.GeneralSecurityException; import java.security.InvalidKeyException; import java.security.Key; @@ -37,11 +37,11 @@ * The cert. * @return base64 encoded result. */ - private static String encrypt(String source, Certificate cert) throws GeneralSecurityException, UnsupportedEncodingException { + private static String encrypt(String source, Certificate cert) throws GeneralSecurityException { Cipher rsa = Cipher.getInstance(algo); rsa.init(Cipher.ENCRYPT_MODE, cert.getPublicKey()); return new Base64(0).encodeToString( - rsa.doFinal(source.trim().getBytes("UTF-8")) + rsa.doFinal(source.trim().getBytes(Charset.forName("UTF-8"))) ); } @@ -110,12 +110,12 @@ } private static String decrypt(String source, Key key) throws NoSuchAlgorithmException, NoSuchPaddingException, - InvalidKeyException, IllegalBlockSizeException, BadPaddingException, UnsupportedEncodingException { + InvalidKeyException, IllegalBlockSizeException, BadPaddingException { Cipher rsa = Cipher.getInstance(algo); rsa.init(Cipher.DECRYPT_MODE, key); return new String( rsa.doFinal(Base64.decodeBase64(source)), - "UTF-8" + Charset.forName("UTF-8") ); } @@ -167,7 +167,7 @@ EncryptUtilParams params = new EncryptUtilParams(keyMaterial, algorithm); cipher = Cipher.getInstance(params.algorithm); cipher.init(Cipher.ENCRYPT_MODE, params.secretKey); - encoding = cipher.doFinal(secret.getBytes("UTF-8")); + encoding = cipher.doFinal(secret.getBytes(Charset.forName("UTF-8"))); } catch (Exception e) { log.error("Error in encrypting the secret", e); } @@ -200,7 +200,7 @@ Cipher cipher = Cipher.getInstance(params.algorithm); cipher.init(Cipher.DECRYPT_MODE, params.secretKey); decode = cipher.doFinal(encoding); - return decode != null ? new String(decode, "UTF-8") : null; + return decode != null ? new String(decode, Charset.forName("UTF-8")) : null; } catch (Exception e) { log.error("Error in decrypting the secret", e); return null; @@ -217,7 +217,7 @@ private String algorithm = null; private SecretKeySpec secretKey = null; - public EncryptUtilParams(String keyMaterial, String algorithm) throws UnsupportedEncodingException { + public EncryptUtilParams(String keyMaterial, String algorithm) { if (algorithm == null || "".equals(algorithm)) { this.algorithm = "Blowfish"; } else { @@ -225,7 +225,7 @@ } if (keyMaterial == null || "".equals(keyMaterial)) { - secretKey = new SecretKeySpec("jaas is the way".getBytes("UTF-8"), this.algorithm); + secretKey = new SecretKeySpec("jaas is the way".getBytes(Charset.forName("UTF-8")), this.algorithm); } else { secretKey = new SecretKeySpec(keyMaterial.getBytes(), this.algorithm); } diff --git a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/hostinstall/OpenSslCAWrapper.java b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/hostinstall/OpenSslCAWrapper.java index 74eec2d..05cff38 100644 --- a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/hostinstall/OpenSslCAWrapper.java +++ b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/hostinstall/OpenSslCAWrapper.java @@ -8,6 +8,7 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; +import java.nio.charset.Charset; import java.security.cert.Certificate; import java.security.cert.CertificateFactory; import java.text.SimpleDateFormat; @@ -72,7 +73,7 @@ reqFileName ) ); - os.write(request.getBytes("UTF-8")); + os.write(request.getBytes(Charset.forName("UTF-8"))); } finally { if (os != null) { @@ -139,7 +140,7 @@ try { log.debug("Running Sign Certificate request script"); Process process = getRuntime().exec(command_array); - stdOutput = new BufferedReader(new InputStreamReader(process.getInputStream(), "UTF-8")); + stdOutput = new BufferedReader(new InputStreamReader(process.getInputStream(), Charset.forName("UTF-8"))); stdError = new BufferedReader(new InputStreamReader(process.getErrorStream())); int exitCode = 0; boolean completed = false; -- To view, visit http://gerrit.ovirt.org/13192 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Id61cad58356820a73683666235d328a72582486b Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Alon Bar-Lev <alo...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches