Merge pull request 'master' (#2) from master into release/1.0
All checks were successful
Locusworks Team/crypto/pipeline/head This commit looks good

Reviewed-on: #2
This commit is contained in:
2021-09-14 23:02:45 -05:00
22 changed files with 228 additions and 91 deletions

49
pom.xml
View File

@ -21,7 +21,7 @@
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<license-maven-plugin.version>3.0</license-maven-plugin.version>
<license-maven-plugin.version>4.1</license-maven-plugin.version>
<nexus.repo>https://nexus.locusworks.net</nexus.repo>
</properties>
@ -30,7 +30,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
<version>3.0.0-M5</version>
<configuration>
<forkMode>always</forkMode>
</configuration>
@ -38,22 +38,20 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<version>3.8.1</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
<failOnError>true</failOnError>
<compilerArgs>
<arg>-Xlint:all</arg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.owasp</groupId>
<artifactId>dependency-check-maven</artifactId>
<version>5.2.2</version>
<configuration>
<skipProvidedScope>true</skipProvidedScope>
<skipTestScope>true</skipTestScope>
<failOnError>false</failOnError>
<versionCheckEnabled>true</versionCheckEnabled>
</configuration>
<version>6.3.1</version>
<executions>
<execution>
<goals>
@ -67,13 +65,14 @@
<artifactId>license-maven-plugin</artifactId>
<version>${license-maven-plugin.version}</version>
<configuration>
<quiet>false</quiet>
<header>${basedir}/licenses/LICENSE.template</header>
<strictCheck>true</strictCheck>
<useDefaultExcludes>true</useDefaultExcludes>
<includes>
<include>**/*.java</include>
</includes>
<licenseSets>
<licenseSet>
<header>${project.baseUri}/licenses/LICENSE.template</header>
<includes>
<include>**/*.java</include>
</includes>
</licenseSet>
</licenseSets>
</configuration>
<dependencies>
<!-- this dependency allows ${license.git.copyrightLastYear} in the
@ -90,25 +89,27 @@
<dependencies>
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.8.0</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
<version>2.11.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-codec/commons-codec -->
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.14</version>
<version>1.15</version>
</dependency>
@ -116,14 +117,14 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>28.1-jre</version>
<version>30.1.1-jre</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.9</version>
<version>3.12.0</version>
</dependency>
</dependencies>

View File

@ -1,4 +1,4 @@
/**
/*
*
* Project: Crypto, File: AES.java
*

View File

@ -1,4 +1,4 @@
/**
/*
*
* Project: Crypto, File: AESKey.java
*

View File

@ -1,4 +1,4 @@
/**
/*
*
* Project: Crypto, File: AESKeySpec.java
*

View File

@ -1,4 +1,4 @@
/**
/*
*
* Project: Crypto, File: EncryptionKeyFactory.java
*

View File

@ -1,4 +1,4 @@
/**
/*
*
* Project: Crypto, File: HashSalt.java
*

View File

@ -1,4 +1,4 @@
/**
/*
*
* Project: Crypto, File: KeyFile.java
*

View File

@ -1,4 +1,4 @@
/**
/*
*
* Project: Crypto, File: RSA.java
*

View File

@ -1,4 +1,4 @@
/**
/*
*
* Project: Crypto, File: SSHEncodedKeySpec.java
*

View File

@ -1,3 +1,30 @@
/*
*
* Project: Crypto, File: ConfigurationCallback.java
*
* Copyright 2019 Locusworks LLC.
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
* any means and imposes fines up to $25,000 for violation. No part of this material
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
* modified, duplicated, adapted or translated into another program language in any
* form or by any means, electronic, mechanical, photocopying, recording, or
* otherwise, without the prior written permission from Locusworks. Locusworks
* affirms that Crypto(R) software and data is subject to United States
* Government Purpose Rights. Contact Locusworks, 1313 Lawnview Drive
* Forney TX 75126, (802) 488-0438, for commercial licensing opportunities.
*
* IN NO EVENT SHALL LOCUSWORKS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
* INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF LOCUSWORKS HAS BEEN
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. NO RESPONSIBILITY IS ASSUMED BY
* LOCUSWORKS FOR ITS USE, OR FOR ANY INFRINGEMENTS OF PATENTS OR OTHER RIGHTS OF
* THIRD PARTIES RESULTING FROM ITS USE. LOCUSWORKS SPECIFICALLY DISCLAIMS ANY
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND
* ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
* IS". LOCUSWORKS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
* ENHANCEMENTS, OR MODIFICATIONS.
*/
package net.locusworks.crypto.configuration;
@FunctionalInterface

View File

@ -1,3 +1,30 @@
/*
*
* Project: Crypto, File: ConfigurationManager.java
*
* Copyright 2019 Locusworks LLC.
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
* any means and imposes fines up to $25,000 for violation. No part of this material
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
* modified, duplicated, adapted or translated into another program language in any
* form or by any means, electronic, mechanical, photocopying, recording, or
* otherwise, without the prior written permission from Locusworks. Locusworks
* affirms that Crypto(R) software and data is subject to United States
* Government Purpose Rights. Contact Locusworks, 1313 Lawnview Drive
* Forney TX 75126, (802) 488-0438, for commercial licensing opportunities.
*
* IN NO EVENT SHALL LOCUSWORKS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
* INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF LOCUSWORKS HAS BEEN
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. NO RESPONSIBILITY IS ASSUMED BY
* LOCUSWORKS FOR ITS USE, OR FOR ANY INFRINGEMENTS OF PATENTS OR OTHER RIGHTS OF
* THIRD PARTIES RESULTING FROM ITS USE. LOCUSWORKS SPECIFICALLY DISCLAIMS ANY
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND
* ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
* IS". LOCUSWORKS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
* ENHANCEMENTS, OR MODIFICATIONS.
*/
package net.locusworks.crypto.configuration;
import java.io.IOException;

View File

@ -1,3 +1,30 @@
/*
*
* Project: Crypto, File: PersistableRequest.java
*
* Copyright 2019 Locusworks LLC.
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
* any means and imposes fines up to $25,000 for violation. No part of this material
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
* modified, duplicated, adapted or translated into another program language in any
* form or by any means, electronic, mechanical, photocopying, recording, or
* otherwise, without the prior written permission from Locusworks. Locusworks
* affirms that Crypto(R) software and data is subject to United States
* Government Purpose Rights. Contact Locusworks, 1313 Lawnview Drive
* Forney TX 75126, (802) 488-0438, for commercial licensing opportunities.
*
* IN NO EVENT SHALL LOCUSWORKS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
* INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF LOCUSWORKS HAS BEEN
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. NO RESPONSIBILITY IS ASSUMED BY
* LOCUSWORKS FOR ITS USE, OR FOR ANY INFRINGEMENTS OF PATENTS OR OTHER RIGHTS OF
* THIRD PARTIES RESULTING FROM ITS USE. LOCUSWORKS SPECIFICALLY DISCLAIMS ANY
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND
* ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
* IS". LOCUSWORKS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
* ENHANCEMENTS, OR MODIFICATIONS.
*/
package net.locusworks.crypto.configuration;
public interface PersistableRequest {

View File

@ -1,3 +1,30 @@
/*
*
* Project: Crypto, File: PropertiesManager.java
*
* Copyright 2019 Locusworks LLC.
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
* any means and imposes fines up to $25,000 for violation. No part of this material
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
* modified, duplicated, adapted or translated into another program language in any
* form or by any means, electronic, mechanical, photocopying, recording, or
* otherwise, without the prior written permission from Locusworks. Locusworks
* affirms that Crypto(R) software and data is subject to United States
* Government Purpose Rights. Contact Locusworks, 1313 Lawnview Drive
* Forney TX 75126, (802) 488-0438, for commercial licensing opportunities.
*
* IN NO EVENT SHALL LOCUSWORKS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
* INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF LOCUSWORKS HAS BEEN
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. NO RESPONSIBILITY IS ASSUMED BY
* LOCUSWORKS FOR ITS USE, OR FOR ANY INFRINGEMENTS OF PATENTS OR OTHER RIGHTS OF
* THIRD PARTIES RESULTING FROM ITS USE. LOCUSWORKS SPECIFICALLY DISCLAIMS ANY
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND
* ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
* IS". LOCUSWORKS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
* ENHANCEMENTS, OR MODIFICATIONS.
*/
package net.locusworks.crypto.configuration;
import java.io.BufferedReader;

View File

@ -1,4 +1,4 @@
/**
/*
*
* Project: Crypto, File: package-info.java
*

View File

@ -1,4 +1,4 @@
/**
/*
*
* Project: Crypto, File: DataOutputStreamHelper.java
*

View File

@ -1,4 +1,4 @@
/**
/*
*
* Project: Crypto, File: HashUtils.java
*

View File

@ -1,4 +1,4 @@
/**
/*
*
* Project: Crypto, File: RandomString.java
*

View File

@ -1,4 +1,4 @@
/**
/*
*
* Project: Crypto, File: AESEncryptionTest.java
*
@ -28,8 +28,8 @@
package net.locusworks.crypto.tests;
import org.apache.commons.lang3.StringUtils;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
import net.locusworks.crypto.AES;
@ -39,10 +39,10 @@ public class AESEncryptionTest {
public void testEncryption() {
try {
String encrypted = AES.createInstance().encrypt("hello world");
Assert.assertTrue(String.format("Encrypted String is not blank? :%s", encrypted), !StringUtils.isBlank(encrypted));
assertTrue(StringUtils.isNotBlank(encrypted), String.format("Encrypted String is not blank? :%s", encrypted));
} catch (Exception ex) {
ex.printStackTrace(System.err);
Assert.fail();
fail();
}
}
@ -52,16 +52,18 @@ public class AESEncryptionTest {
try {
AES aes = AES.createInstance();
String encrypted = aes.encrypt(testString);
Assert.assertTrue(String.format("Encrypted String is not blank? :%s", encrypted), !StringUtils.isBlank(encrypted));
assertTrue(StringUtils.isNotBlank(encrypted), String.format("Encrypted String is not blank? :%s", encrypted));
String decrypted = aes.decrypt(encrypted);
Assert.assertTrue(String.format("Decrypted String is not blank? :%s", decrypted), !StringUtils.isBlank(encrypted));
Assert.assertTrue("Test String and Original String the same? :%s", testString.equals(decrypted));
assertTrue(StringUtils.isNotBlank(encrypted), String.format("Decrypted String is not blank? :%s", decrypted));
boolean same = testString.equals(decrypted);
assertTrue(same, String.format("Test String and Original String the same? :%s", same));
} catch (Exception ex) {
ex.printStackTrace(System.err);
Assert.fail();
fail();
}
}

View File

@ -1,4 +1,4 @@
/**
/*
*
* Project: Crypto, File: HashSaltTest.java
*
@ -28,35 +28,35 @@
package net.locusworks.crypto.tests;
import org.apache.commons.lang3.StringUtils;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
import net.locusworks.crypto.HashSalt;
public class HashSaltTest {
private static String samplePassword="Hello World";
@Test
public void testEncryption() {
try {
String hashSalt = HashSalt.createHash(samplePassword);
Assert.assertTrue(String.format("Encrypted String is not blank? :%s", hashSalt), !StringUtils.isBlank(hashSalt));
} catch(Exception ex) {
Assert.fail();
}
}
@Test
public void testDecryption() {
try {
String hashSalt = HashSalt.createHash(samplePassword);
boolean decrypted = HashSalt.validatePassword(samplePassword, hashSalt);
Assert.assertTrue("Test String and Original String the same? :%s", decrypted);
} catch(Exception ex) {
Assert.fail();
}
}
private static String samplePassword="Hello World";
@Test
public void testEncryption() {
try {
String hashSalt = HashSalt.createHash(samplePassword);
assertTrue(StringUtils.isNotBlank(hashSalt), String.format("Encrypted String is not blank? :%s", hashSalt));
} catch(Exception ex) {
fail();
}
}
@Test
public void testDecryption() {
try {
String hashSalt = HashSalt.createHash(samplePassword);
boolean decrypted = HashSalt.validatePassword(samplePassword, hashSalt);
assertTrue(decrypted, String.format("Test String and Original String the same? :%s", decrypted));
} catch(Exception ex) {
fail();
}
}
}

View File

@ -1,4 +1,4 @@
/**
/*
*
* Project: Crypto, File: HashUtilsTest.java
*
@ -27,38 +27,38 @@
*/
package net.locusworks.crypto.tests;
import static org.junit.Assert.*;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
import org.apache.commons.codec.digest.DigestUtils;
import org.junit.Test;
import net.locusworks.crypto.utils.HashUtils;
public class HashUtilsTest {
private static final String TEST_STRING = "Hello World";
@Test
public void testMD5() throws Exception {
String digestUtilsMD5 = DigestUtils.md5Hex(TEST_STRING.getBytes());
String hashUtilsMD5 = HashUtils.hash("MD5", TEST_STRING);
assertTrue(digestUtilsMD5.equals(hashUtilsMD5));
}
@Test
public void testSHA1() throws Exception {
String digestUtilsMD5 = DigestUtils.sha1Hex(TEST_STRING.getBytes());
String hashUtilsMD5 = HashUtils.hash("SHA-1", TEST_STRING);
assertTrue(digestUtilsMD5.equals(hashUtilsMD5));
}
@Test
public void testSHA512() throws Exception {
String digestUtilsMD5 = DigestUtils.sha512Hex(TEST_STRING.getBytes());
String hashUtilsMD5 = HashUtils.hash("SHA-512", TEST_STRING);
assertTrue(digestUtilsMD5.equals(hashUtilsMD5));
}

View File

@ -1,6 +1,35 @@
/*
*
* Project: Crypto, File: PropertiesManagerTest.java
*
* Copyright 2019 Locusworks LLC.
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
* any means and imposes fines up to $25,000 for violation. No part of this material
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
* modified, duplicated, adapted or translated into another program language in any
* form or by any means, electronic, mechanical, photocopying, recording, or
* otherwise, without the prior written permission from Locusworks. Locusworks
* affirms that Crypto(R) software and data is subject to United States
* Government Purpose Rights. Contact Locusworks, 1313 Lawnview Drive
* Forney TX 75126, (802) 488-0438, for commercial licensing opportunities.
*
* IN NO EVENT SHALL LOCUSWORKS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
* INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF LOCUSWORKS HAS BEEN
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. NO RESPONSIBILITY IS ASSUMED BY
* LOCUSWORKS FOR ITS USE, OR FOR ANY INFRINGEMENTS OF PATENTS OR OTHER RIGHTS OF
* THIRD PARTIES RESULTING FROM ITS USE. LOCUSWORKS SPECIFICALLY DISCLAIMS ANY
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND
* ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
* IS". LOCUSWORKS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
* ENHANCEMENTS, OR MODIFICATIONS.
*/
package net.locusworks.crypto.tests;
import static org.junit.Assert.*;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
import java.io.File;
import java.io.IOException;
@ -8,8 +37,6 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Properties;
import org.junit.AfterClass;
import org.junit.Test;
import net.locusworks.crypto.configuration.PropertiesManager;
@ -51,7 +78,7 @@ public class PropertiesManagerTest {
}
}
@AfterClass
@AfterAll
public static void removeSavedProps() {
File tmp = new File(TMP_PROPS);
if (tmp.exists()) {

View File

@ -1,4 +1,4 @@
/**
/*
*
* Project: Crypto, File: RandomStringTest.java
*
@ -27,9 +27,8 @@
*/
package net.locusworks.crypto.tests;
import static org.junit.Assert.*;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
import net.locusworks.crypto.utils.RandomString;
@ -41,7 +40,7 @@ public class RandomStringTest {
assertTrue(RandomString.getBytes(length).length == length);
}
}
@Test
public void testStaticString() {
for (Integer length = 3; length < 50; length++) {