diff --git a/src/main/java/org/whispersystems/textsecuregcm/controllers/DirectoryController.java b/src/main/java/org/whispersystems/textsecuregcm/controllers/DirectoryController.java index 785803b81..696d35783 100644 --- a/src/main/java/org/whispersystems/textsecuregcm/controllers/DirectoryController.java +++ b/src/main/java/org/whispersystems/textsecuregcm/controllers/DirectoryController.java @@ -74,7 +74,7 @@ public class DirectoryController { rateLimiters.getContactsLimiter().validate(account.getNumber()); try { - Optional contact = directory.get(Base64.decodeWithoutPadding(token)); + Optional contact = directory.get(decodeToken(token)); if (contact.isPresent()) return Response.ok().entity(contact.get()).build(); else return Response.status(404).build(); @@ -100,7 +100,7 @@ public class DirectoryController { List tokens = new LinkedList<>(); for (String encodedContact : contacts.getContacts()) { - tokens.add(Base64.decodeWithoutPadding(encodedContact)); + tokens.add(decodeToken(encodedContact)); } List intersection = directory.get(tokens); @@ -110,4 +110,8 @@ public class DirectoryController { throw new WebApplicationException(Response.status(400).build()); } } + + private byte[] decodeToken(String encoded) throws IOException { + return Base64.decodeWithoutPadding(encoded.replace('-', '+').replace('_', '/')); + } }