From e88a4983e67c9db681614fb4d2698d6f4465dca1 Mon Sep 17 00:00:00 2001 From: Andreas Schildbach Date: Mon, 12 Nov 2018 14:34:35 +0100 Subject: [PATCH] AbstractHafasClientInterfaceProvider: Migrate requestChecksumSalt and requestMicMacSalt to byte arrays, to make them independent of base-encoding. --- .../pte/AbstractHafasClientInterfaceProvider.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/enabler/src/de/schildbach/pte/AbstractHafasClientInterfaceProvider.java b/enabler/src/de/schildbach/pte/AbstractHafasClientInterfaceProvider.java index ee8758c5..9b171182 100644 --- a/enabler/src/de/schildbach/pte/AbstractHafasClientInterfaceProvider.java +++ b/enabler/src/de/schildbach/pte/AbstractHafasClientInterfaceProvider.java @@ -87,9 +87,9 @@ public abstract class AbstractHafasClientInterfaceProvider extends AbstractHafas @Nullable public String apiClient; @Nullable - public String requestChecksumSalt; + public byte[] requestChecksumSalt; @Nullable - public String requestMicMacSalt; + public byte[] requestMicMacSalt; private static final String SERVER_PRODUCT = "hci"; private static final HashFunction MD5 = Hashing.md5(); @@ -117,12 +117,12 @@ public abstract class AbstractHafasClientInterfaceProvider extends AbstractHafas return this; } - protected AbstractHafasClientInterfaceProvider setRequestChecksumSalt(final String requestChecksumSalt) { + protected AbstractHafasClientInterfaceProvider setRequestChecksumSalt(final byte[] requestChecksumSalt) { this.requestChecksumSalt = requestChecksumSalt; return this; } - protected AbstractHafasClientInterfaceProvider setRequestMicMacSalt(final String requestMicMacSalt) { + protected AbstractHafasClientInterfaceProvider setRequestMicMacSalt(final byte[] requestMicMacSalt) { this.requestMicMacSalt = requestMicMacSalt; return this; } @@ -660,15 +660,15 @@ public abstract class AbstractHafasClientInterfaceProvider extends AbstractHafas private HttpUrl requestUrl(final String body) { final HttpUrl.Builder url = checkNotNull(mgateEndpoint).newBuilder(); if (requestChecksumSalt != null) { - final HashCode checksum = MD5.newHasher().putString(body, Charsets.UTF_8) - .putString(requestChecksumSalt, Charsets.UTF_8).hash(); + final HashCode checksum = MD5.newHasher().putString(body, Charsets.UTF_8).putBytes(requestChecksumSalt) + .hash(); url.addQueryParameter("checksum", checksum.toString()); } if (requestMicMacSalt != null) { final HashCode mic = MD5.newHasher().putString(body, Charsets.UTF_8).hash(); url.addQueryParameter("mic", HEX.encode(mic.asBytes())); final HashCode mac = MD5.newHasher().putString(HEX.encode(mic.asBytes()), Charsets.UTF_8) - .putBytes(HEX.decode(requestMicMacSalt)).hash(); + .putBytes(requestMicMacSalt).hash(); url.addQueryParameter("mac", HEX.encode(mac.asBytes())); } return url.build();