mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-19 16:59:51 +00:00
AbstractHafasMobileProvider: Implement request body mic (message integrity code) and mac (message authentication code).
This commit is contained in:
parent
c410fcda65
commit
9fbd1f1864
1 changed files with 16 additions and 0 deletions
|
@ -48,6 +48,7 @@ import com.google.common.base.Joiner;
|
|||
import com.google.common.hash.HashCode;
|
||||
import com.google.common.hash.HashFunction;
|
||||
import com.google.common.hash.Hashing;
|
||||
import com.google.common.io.BaseEncoding;
|
||||
|
||||
import de.schildbach.pte.dto.Departure;
|
||||
import de.schildbach.pte.dto.Fare;
|
||||
|
@ -84,8 +85,11 @@ public abstract class AbstractHafasMobileProvider extends AbstractHafasProvider
|
|||
public String apiClient;
|
||||
@Nullable
|
||||
public String requestChecksumSalt;
|
||||
@Nullable
|
||||
public String requestMicMacSalt;
|
||||
|
||||
private static final HashFunction MD5 = Hashing.md5();
|
||||
private static final BaseEncoding HEX = BaseEncoding.base16().lowerCase();
|
||||
|
||||
public AbstractHafasMobileProvider(final NetworkId network, final HttpUrl apiBase, final Product[] productsMap) {
|
||||
super(network, productsMap);
|
||||
|
@ -113,6 +117,11 @@ public abstract class AbstractHafasMobileProvider extends AbstractHafasProvider
|
|||
return this;
|
||||
}
|
||||
|
||||
protected AbstractHafasMobileProvider setRequestMicMacSalt(final String requestMicMacSalt) {
|
||||
this.requestMicMacSalt = requestMicMacSalt;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NearbyLocationsResult queryNearbyLocations(final EnumSet<LocationType> types, final Location location,
|
||||
final int maxDistance, final int maxLocations) throws IOException {
|
||||
|
@ -617,6 +626,13 @@ public abstract class AbstractHafasMobileProvider extends AbstractHafasProvider
|
|||
.putString(requestChecksumSalt, Charsets.UTF_8).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();
|
||||
url.addQueryParameter("mac", HEX.encode(mac.asBytes()));
|
||||
}
|
||||
return url.build();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue