Skip to content

Commit 94268c7

Browse files
authored
Fix #43 - Resolved compiler warnings (#44)
* Fixes #41 by removing javax.xml.bind.DatatypeConverter usage * Suppressed deprecation warning * Enabled all warnings when compiling. * Enabled actually showing warnings. * Changing commons codec dependency to test scope as it was originally intended. * Resolved javac warnings * Fixed error prone warnings * Updated changelog * Updated changelog
1 parent bc6e44a commit 94268c7

File tree

19 files changed

+91
-10
lines changed

19 files changed

+91
-10
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
55
## [4.0.5] - ?
66

77
### Fixed
8-
- [Removed use of javax.xml.bind.DatatypeConverter](https://github.com/joyent/java-http-signature/issues/41)
8+
- [Removed use of javax.xml.bind.DatatypeConverter](https://github.com/joyent/java-http-signature/issues/41)
9+
- Resolved compiler warnings.
910

1011
## [4.0.4] - 2017-10-06
1112

common/src/main/java/com/joyent/http/signature/CryptoException.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
* @since 1.0.0
1515
*/
1616
public class CryptoException extends HttpSignatureException {
17+
18+
private static final long serialVersionUID = -3558219358777167268L;
19+
1720
/**
1821
* Creates a new exception.
1922
*/

common/src/main/java/com/joyent/http/signature/HttpSignatureException.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
* @since 1.0.0
1515
*/
1616
public class HttpSignatureException extends RuntimeException {
17+
18+
private static final long serialVersionUID = 6548882825292310527L;
19+
1720
/**
1821
* Creates a new exception.
1922
*/

common/src/main/java/com/joyent/http/signature/KeyPairLoader.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.io.IOException;
2323
import java.io.InputStream;
2424
import java.io.InputStreamReader;
25+
import java.nio.charset.StandardCharsets;
2526
import java.nio.file.Files;
2627
import java.nio.file.Path;
2728
import java.security.KeyPair;
@@ -123,7 +124,7 @@ public static KeyPair getKeyPair(final Path keyPath, final char[] password) thro
123124
* @throws IOException If unable to read the private key from the string
124125
*/
125126
public static KeyPair getKeyPair(final String privateKeyContent, final char[] password) throws IOException {
126-
byte[] pKeyBytes = privateKeyContent.getBytes();
127+
byte[] pKeyBytes = privateKeyContent.getBytes(StandardCharsets.US_ASCII);
127128

128129
return getKeyPair(pKeyBytes, password);
129130
}
@@ -156,7 +157,7 @@ public static KeyPair getKeyPair(final byte[] pKeyBytes, final char[] password)
156157
*/
157158
public static KeyPair getKeyPair(final InputStream is,
158159
final char[] password) throws IOException {
159-
try (InputStreamReader isr = new InputStreamReader(is);
160+
try (InputStreamReader isr = new InputStreamReader(is, StandardCharsets.US_ASCII);
160161
BufferedReader br = new BufferedReader(isr);
161162
PEMParser pemParser = new PEMParser(br)) {
162163

common/src/main/java/com/joyent/http/signature/Signer.java

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import java.io.IOException;
1414
import java.io.InputStream;
1515
import java.io.UnsupportedEncodingException;
16+
import java.nio.charset.StandardCharsets;
1617
import java.nio.file.Path;
1718
import java.security.InvalidKeyException;
1819
import java.security.KeyPair;
@@ -329,7 +330,7 @@ public String createAuthorizationHeader(final String login,
329330
final String fingerprint = KeyFingerprinter.md5Fingerprint(keyPair);
330331

331332
return String.format(AUTHZ_HEADER, login, fingerprint, httpHeaderAlgorithm,
332-
new String(encodedSignedDate));
333+
new String(encodedSignedDate, StandardCharsets.US_ASCII));
333334
} catch (final InvalidKeyException e) {
334335
throw new CryptoException("invalid key", e);
335336
} catch (final SignatureException e) {
@@ -396,6 +397,7 @@ public byte[] sign(final String login,
396397
*
397398
* @deprecated The fingerprint is now calculated from the given key.
398399
*/
400+
@Deprecated
399401
public boolean verify(final String login,
400402
final String fingerprint,
401403
final KeyPair keyPair,
@@ -791,23 +793,32 @@ private static class RsaHelper extends SigningAlgorithmHelper {
791793
System.setProperty("native.jnagmp", Objects.toString(JNAGMP_SUPPORTED));
792794
}
793795

794-
796+
@Override
795797
public String getAlgorithm() {
796798
return "RSA";
797799
}
800+
801+
@Override
798802
public String[] getSupportedHashes() {
799803
return SUPPORTED_HASHES;
800804
}
805+
806+
@Override
801807
public String defaultHash() {
802808
return "SHA256";
803809
}
810+
811+
@Override
804812
public String[] getSupportedProviderCodes() {
805813
return SUPPORTED_PROVIDER_CODES;
806814
}
815+
816+
@Override
807817
public String defaultProviderCode() {
808818
return "native.jnagmp";
809819
}
810820

821+
@Override
811822
public String providerPrefix(final Provider provider) {
812823
if (provider != null) {
813824
return "Native";
@@ -840,18 +851,26 @@ private static class DsaHelper extends SigningAlgorithmHelper {
840851
private static final String[] SUPPORTED_HASHES = {"SHA1", "SHA256"};
841852
private static final String[] SUPPORTED_PROVIDER_CODES = {"stdlib"};
842853

854+
@Override
843855
public String getAlgorithm() {
844856
return "DSA";
845857
}
858+
@Override
846859
public String[] getSupportedHashes() {
847860
return SUPPORTED_HASHES;
848861
}
862+
863+
@Override
849864
public String defaultHash() {
850865
return "SHA256";
851866
}
867+
868+
@Override
852869
public String[] getSupportedProviderCodes() {
853870
return SUPPORTED_PROVIDER_CODES;
854871
}
872+
873+
@Override
855874
public String defaultProviderCode() {
856875
return "stdlib";
857876
}
@@ -865,18 +884,27 @@ private static class EcdsaHelper extends SigningAlgorithmHelper {
865884
private static final String[] SUPPORTED_HASHES = {"SHA256", "SHA384", "SHA512"};
866885
private static final String[] SUPPORTED_PROVIDER_CODES = {"stdlib"};
867886

887+
@Override
868888
public String getAlgorithm() {
869889
return "ECDSA";
870890
}
891+
892+
@Override
871893
public String[] getSupportedHashes() {
872894
return SUPPORTED_HASHES;
873895
}
896+
897+
@Override
874898
public String defaultHash() {
875899
return "SHA256";
876900
}
901+
902+
@Override
877903
public String[] getSupportedProviderCodes() {
878904
return SUPPORTED_PROVIDER_CODES;
879905
}
906+
907+
@Override
880908
public String defaultProviderCode() {
881909
return "stdlib";
882910
}

common/src/main/java/com/joyent/http/signature/ThreadLocalClearException.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
* @author <a href="https://github.com/dekobon">Elijah Zupancic</a>
1414
*/
1515
public class ThreadLocalClearException extends RuntimeException {
16+
17+
private static final long serialVersionUID = 4658889695319509040L;
18+
1619
/**
1720
* Constructs a new runtime exception with the specified cause and a
1821
* detail message of <tt>(cause==null ? null : cause.toString())</tt>

common/src/main/java/com/joyent/http/signature/crypto/NativeRSABlindedEngine.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public class NativeRSABlindedEngine extends RSABlindedEngine {
7373
* @param forEncryption true if we are encrypting, false otherwise.
7474
* @param param the necessary RSA key parameters.
7575
*/
76+
@Override
7677
public void init(final boolean forEncryption, final CipherParameters param) {
7778
core.init(forEncryption, param);
7879

@@ -94,6 +95,7 @@ public void init(final boolean forEncryption, final CipherParameters param) {
9495
*
9596
* @return maximum size for an input block.
9697
*/
98+
@Override
9799
public int getInputBlockSize() {
98100
return core.getInputBlockSize();
99101
}
@@ -105,6 +107,7 @@ public int getInputBlockSize() {
105107
*
106108
* @return maximum size for an output block.
107109
*/
110+
@Override
108111
public int getOutputBlockSize() {
109112
return core.getOutputBlockSize();
110113
}
@@ -118,6 +121,7 @@ public int getOutputBlockSize() {
118121
* @return the result of the RSA process.
119122
* @exception DataLengthException the input block is too large.
120123
*/
124+
@Override
121125
public byte[] processBlock(final byte[] in, final int inOff, final int inLen) {
122126
if (key == null) {
123127
throw new IllegalStateException("RSA engine not initialised");

common/src/main/java/com/joyent/http/signature/crypto/NativeRSAProvider.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
* @author <a href="https://github.com/dekobon">Elijah Zupancic</a>
1515
*/
1616
public class NativeRSAProvider extends Provider {
17+
18+
private static final long serialVersionUID = -8156926325751209127L;
19+
1720
/**
1821
* Creates an instance of a JCE provider that supports native RSA via jnagmp.
1922
*/

common/src/test/java/com/joyent/http/signature/KeyFingerprinterIntegrationCycle.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import java.io.File;
1414
import java.io.IOException;
1515
import java.io.InputStreamReader;
16+
import java.nio.charset.StandardCharsets;
1617
import java.nio.file.Files;
1718
import java.nio.file.Path;
1819
import java.nio.file.Paths;
@@ -60,7 +61,8 @@ public String readMd5Fingerprint(int iteration) throws IOException, InterruptedE
6061
if (p.waitFor() > 0) {
6162
throw new RuntimeException("check cmd failed: " + p);
6263
}
63-
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
64+
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream(),
65+
StandardCharsets.US_ASCII));
6466
String line = reader.readLine();
6567
return line.split(" ")[1];
6668
}

common/src/test/java/com/joyent/http/signature/KeyPairLoaderTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ private KeyPair generateKeyPair() throws NoSuchAlgorithmException {
9797
private byte[] serializePrivateKey(final KeyPair keyPair,
9898
final String passphrase) throws Exception {
9999
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
100-
final JcaPEMWriter jcaPEMWriter = new JcaPEMWriter(new OutputStreamWriter(baos));
100+
final JcaPEMWriter jcaPEMWriter = new JcaPEMWriter(new OutputStreamWriter(baos,
101+
StandardCharsets.US_ASCII));
101102

102103
if (passphrase != null) {
103104
final PEMEncryptor pemEncryptor = new JcePEMEncryptorBuilder("AES-128-CBC").build(passphrase.toCharArray());

0 commit comments

Comments
 (0)