From 0f000c432212783e9b03c0ce539615e20536fd93 Mon Sep 17 00:00:00 2001 From: Alex Heneveld Date: Mon, 23 Aug 2021 10:00:35 +0100 Subject: [PATCH] remove unnecessary dependencies make it easier for downstream projects to consume --- client/pom.xml | 5 +- .../winrm4j/client/RetryingProxyHandler.java | 8 +-- .../encryption/WinrmEncryptionUtils.java | 54 ++++++++++++------- 3 files changed, 41 insertions(+), 26 deletions(-) diff --git a/client/pom.xml b/client/pom.xml index efc1db4..79e3ba3 100644 --- a/client/pom.xml +++ b/client/pom.xml @@ -54,6 +54,7 @@ cxf-rt-frontend-jaxws ${cxf.version} + ${project.groupId} winrm4j-service @@ -96,8 +98,7 @@ org.apache.httpcomponents httpclient - 4.5.13 - + ${httpcomponents.httpclient.version} org.apache.httpcomponents diff --git a/client/src/main/java/io/cloudsoft/winrm4j/client/RetryingProxyHandler.java b/client/src/main/java/io/cloudsoft/winrm4j/client/RetryingProxyHandler.java index 1d27c61..1e7897a 100644 --- a/client/src/main/java/io/cloudsoft/winrm4j/client/RetryingProxyHandler.java +++ b/client/src/main/java/io/cloudsoft/winrm4j/client/RetryingProxyHandler.java @@ -1,20 +1,16 @@ package io.cloudsoft.winrm4j.client; +import io.cloudsoft.winrm4j.client.retry.RetryDecision; +import io.cloudsoft.winrm4j.client.retry.RetryPolicy; import java.io.IOException; import java.lang.reflect.InvocationHandler; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; - import javax.xml.ws.WebServiceException; import javax.xml.ws.soap.SOAPFaultException; - -import org.apache.cxf.jaxrs.utils.ExceptionUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import io.cloudsoft.winrm4j.client.retry.RetryDecision; -import io.cloudsoft.winrm4j.client.retry.RetryPolicy; - class RetryingProxyHandler implements InvocationHandler { private static final Logger LOG = LoggerFactory.getLogger(RetryingProxyHandler.class); diff --git a/client/src/main/java/io/cloudsoft/winrm4j/client/encryption/WinrmEncryptionUtils.java b/client/src/main/java/io/cloudsoft/winrm4j/client/encryption/WinrmEncryptionUtils.java index 93a76af..c893454 100644 --- a/client/src/main/java/io/cloudsoft/winrm4j/client/encryption/WinrmEncryptionUtils.java +++ b/client/src/main/java/io/cloudsoft/winrm4j/client/encryption/WinrmEncryptionUtils.java @@ -1,14 +1,11 @@ package io.cloudsoft.winrm4j.client.encryption; -import java.io.ByteArrayOutputStream; import java.security.InvalidKeyException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; +import javax.crypto.Cipher; import javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec; -import org.bouncycastle.crypto.engines.RC4Engine; -import org.bouncycastle.crypto.io.CipherOutputStream; -import org.bouncycastle.crypto.params.KeyParameter; public class WinrmEncryptionUtils { @@ -33,23 +30,44 @@ public static CryptoHandler decryptorArc4(byte[] key) { public static CryptoHandler cryptorArc4(boolean forEncryption, byte[] key) { // engine needs to be stateful - RC4Engine engine = new RC4Engine(); - engine.init(forEncryption, new KeyParameter(key)); + try { + final Cipher rc4 = Cipher.getInstance("RC4"); + rc4.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(key, "RC4")); - return new CryptoHandler() { - @Override - public byte[] update(byte[] input) { - try { - ByteArrayOutputStream outBytes = new ByteArrayOutputStream(); - CipherOutputStream cos = new CipherOutputStream(outBytes, engine); - cos.write(input); + return new CryptoHandler() { + @Override + public byte[] update(byte[] input) { + try { + return rc4.update(input); - return outBytes.toByteArray(); - } catch (Exception e) { - throw new IllegalStateException(e); + } catch (Exception e) { + throw new IllegalStateException(e); + } } - } - }; + }; + + } catch (Exception e) { + throw new IllegalStateException(e); + } + + // using bouncycastle - but brings in unnecessary deps +// RC4Engine engine = new RC4Engine(); +// engine.init(forEncryption, new KeyParameter(key)); +// +// return new CryptoHandler() { +// @Override +// public byte[] update(byte[] input) { +// try { +// ByteArrayOutputStream outBytes = new ByteArrayOutputStream(); +// CipherOutputStream cos = new CipherOutputStream(outBytes, engine); +// cos.write(input); +// +// return outBytes.toByteArray(); +// } catch (Exception e) { +// throw new IllegalStateException(e); +// } +// } +// }; } public static byte[] hmacMd5(byte[] key, byte[] body) {