Commit d1f9a329 authored by Karsten Loesing's avatar Karsten Loesing
Browse files

Replace JAXB with Apache Commons Codec dependency.

The reason is that JAXB won't be part of standard Java 9 anymore, and
the only reason why we used it was to get rid of Apache Commons Codec
as dependency, three years ago. Now it makes sense to just go back to
Apache Commons Codec in preparation of upgrading to Java 9.

Partially reverts 1734d166.

Fixes #25444.
parent feabf88f
# Changes in version 2.5.0 - 2018-??-??
* Medium changes
- Go back to using Apache Commons Codec as base64 and hexadecimal
codec rather than using JAXB which won't be available anymore
after upgrading from Java 8 to 9. Applications must provide
Apache Commons Codec 1.10 as dependency.
# Changes in version 2.4.0 - 2018-05-23 # Changes in version 2.4.0 - 2018-05-23
* Medium changes * Medium changes
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
<property name="jarpatternprop" value="empty" /> <property name="jarpatternprop" value="empty" />
<patternset id="runtime" > <patternset id="runtime" >
<include name="commons-codec-1.10.jar"/>
<include name="commons-compress-1.13.jar"/> <include name="commons-compress-1.13.jar"/>
<include name="jackson-annotations-2.8.6.jar"/> <include name="jackson-annotations-2.8.6.jar"/>
<include name="jackson-core-2.8.6.jar"/> <include name="jackson-core-2.8.6.jar"/>
......
...@@ -6,6 +6,9 @@ package org.torproject.descriptor.impl; ...@@ -6,6 +6,9 @@ package org.torproject.descriptor.impl;
import org.torproject.descriptor.Descriptor; import org.torproject.descriptor.Descriptor;
import org.torproject.descriptor.DescriptorParseException; import org.torproject.descriptor.DescriptorParseException;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.binary.Hex;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.File; import java.io.File;
import java.io.InputStreamReader; import java.io.InputStreamReader;
...@@ -19,8 +22,6 @@ import java.util.Map; ...@@ -19,8 +22,6 @@ import java.util.Map;
import java.util.Scanner; import java.util.Scanner;
import java.util.Set; import java.util.Set;
import javax.xml.bind.DatatypeConverter;
public abstract class DescriptorImpl implements Descriptor { public abstract class DescriptorImpl implements Descriptor {
public static final String NL = "\n"; public static final String NL = "\n";
...@@ -383,7 +384,7 @@ public abstract class DescriptorImpl implements Descriptor { ...@@ -383,7 +384,7 @@ public abstract class DescriptorImpl implements Descriptor {
end = ascii.indexOf(endToken) + endToken.length(); end = ascii.indexOf(endToken) + endToken.length();
} }
if (start >= 0 && end >= 0 && end > start) { if (start >= 0 && end >= 0 && end > start) {
this.digestSha1Hex = DatatypeConverter.printHexBinary( this.digestSha1Hex = Hex.encodeHexString(
messageDigest("SHA-1", start, end)).toLowerCase(); messageDigest("SHA-1", start, end)).toLowerCase();
} }
} }
...@@ -426,7 +427,7 @@ public abstract class DescriptorImpl implements Descriptor { ...@@ -426,7 +427,7 @@ public abstract class DescriptorImpl implements Descriptor {
end = ascii.indexOf(endToken) + endToken.length(); end = ascii.indexOf(endToken) + endToken.length();
} }
if (start >= 0 && end >= 0 && end > start) { if (start >= 0 && end >= 0 && end > start) {
this.digestSha256Base64 = DatatypeConverter.printBase64Binary( this.digestSha256Base64 = Base64.encodeBase64String(
messageDigest("SHA-256", start, end)).replaceAll("=", ""); messageDigest("SHA-256", start, end)).replaceAll("=", "");
} }
} }
......
...@@ -5,6 +5,9 @@ package org.torproject.descriptor.impl; ...@@ -5,6 +5,9 @@ package org.torproject.descriptor.impl;
import org.torproject.descriptor.DescriptorParseException; import org.torproject.descriptor.DescriptorParseException;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.binary.Hex;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
...@@ -19,8 +22,6 @@ import java.util.TreeMap; ...@@ -19,8 +22,6 @@ import java.util.TreeMap;
import java.util.TreeSet; import java.util.TreeSet;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import javax.xml.bind.DatatypeConverter;
/** /**
* Parse helper for descriptor contents. * Parse helper for descriptor contents.
* *
...@@ -302,8 +303,7 @@ public class ParseHelper { ...@@ -302,8 +303,7 @@ public class ParseHelper {
+ "' in line '" + line + "' is not a valid base64-encoded " + "' in line '" + line + "' is not a valid base64-encoded "
+ "20-byte value."); + "20-byte value.");
} }
return DatatypeConverter.printHexBinary( return Hex.encodeHexString(Base64.decodeBase64(base64String + "="))
DatatypeConverter.parseBase64Binary(base64String + "="))
.toUpperCase(); .toUpperCase();
} }
...@@ -322,8 +322,7 @@ public class ParseHelper { ...@@ -322,8 +322,7 @@ public class ParseHelper {
+ "' in line '" + line + "' is not a valid base64-encoded " + "' in line '" + line + "' is not a valid base64-encoded "
+ "32-byte value."); + "32-byte value.");
} }
return DatatypeConverter.printHexBinary( return Hex.encodeHexString(Base64.decodeBase64(base64String + "="))
DatatypeConverter.parseBase64Binary(base64String + "="))
.toUpperCase(); .toUpperCase();
} }
...@@ -457,8 +456,7 @@ public class ParseHelper { ...@@ -457,8 +456,7 @@ public class ParseHelper {
.substring(beginEd25519CertLine.length(), .substring(beginEd25519CertLine.length(),
identityEd25519CryptoBlock.length() identityEd25519CryptoBlock.length()
- endEd25519CertLine.length()).replaceAll("=", ""); - endEd25519CertLine.length()).replaceAll("=", "");
byte[] identityEd25519 = DatatypeConverter.parseBase64Binary( byte[] identityEd25519 = Base64.decodeBase64(identityEd25519Base64);
identityEd25519Base64);
if (identityEd25519.length < 40) { if (identityEd25519.length < 40) {
throw new DescriptorParseException("Invalid length of " throw new DescriptorParseException("Invalid length of "
+ "identity-ed25519 (in bytes): " + identityEd25519.length); + "identity-ed25519 (in bytes): " + identityEd25519.length);
...@@ -494,8 +492,8 @@ public class ParseHelper { ...@@ -494,8 +492,8 @@ public class ParseHelper {
byte[] masterKeyEd25519 = new byte[32]; byte[] masterKeyEd25519 = new byte[32];
System.arraycopy(identityEd25519, extensionStart + 4, System.arraycopy(identityEd25519, extensionStart + 4,
masterKeyEd25519, 0, masterKeyEd25519.length); masterKeyEd25519, 0, masterKeyEd25519.length);
String masterKeyEd25519Base64 = DatatypeConverter String masterKeyEd25519Base64
.printBase64Binary(masterKeyEd25519).replaceAll("=", ""); = Base64.encodeBase64String(masterKeyEd25519).replaceAll("=", "");
String masterKeyEd25519Base64NoTrailingEqualSigns = String masterKeyEd25519Base64NoTrailingEqualSigns =
masterKeyEd25519Base64.replaceAll("=", ""); masterKeyEd25519Base64.replaceAll("=", "");
return masterKeyEd25519Base64NoTrailingEqualSigns; return masterKeyEd25519Base64NoTrailingEqualSigns;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment