use of org.whispersystems.signalservice.api.groupsv2.GroupsV2AuthorizationString in project Signal-Android by WhisperSystems.
the class PushServiceSocket method getGroupJoinInfo.
public GroupJoinInfo getGroupJoinInfo(Optional<byte[]> groupLinkPassword, GroupsV2AuthorizationString authorization) throws NonSuccessfulResponseCodeException, PushNetworkException, InvalidProtocolBufferException {
String passwordParam = groupLinkPassword.transform(Base64UrlSafe::encodeBytesWithoutPadding).or("");
ResponseBody response = makeStorageRequest(authorization.toString(), String.format(GROUPSV2_GROUP_JOIN, passwordParam), "GET", null, GROUPS_V2_GET_JOIN_INFO_HANDLER);
return GroupJoinInfo.parseFrom(readBodyBytes(response));
}
use of org.whispersystems.signalservice.api.groupsv2.GroupsV2AuthorizationString in project Signal-Android by WhisperSystems.
the class GroupsV2Authorization method getAuthorizationForToday.
public GroupsV2AuthorizationString getAuthorizationForToday(@NonNull ACI self, @NonNull GroupSecretParams groupSecretParams) throws IOException, VerificationFailedException {
final int today = currentTimeDays();
Map<Integer, AuthCredentialResponse> credentials = cache.read();
try {
return getAuthorization(self, groupSecretParams, credentials, today);
} catch (NoCredentialForRedemptionTimeException e) {
Log.i(TAG, "Auth out of date, will update auth and try again");
cache.clear();
} catch (VerificationFailedException e) {
Log.w(TAG, "Verification failed, will update auth and try again", e);
cache.clear();
}
Log.i(TAG, "Getting new auth credential responses");
credentials = groupsV2Api.getCredentials(today);
cache.write(credentials);
try {
return getAuthorization(self, groupSecretParams, credentials, today);
} catch (NoCredentialForRedemptionTimeException e) {
Log.w(TAG, "The credentials returned did not include the day requested");
throw new IOException("Failed to get credentials");
}
}
use of org.whispersystems.signalservice.api.groupsv2.GroupsV2AuthorizationString in project Signal-Android by signalapp.
the class GroupsV2Authorization method getAuthorizationForToday.
public GroupsV2AuthorizationString getAuthorizationForToday(@NonNull ACI self, @NonNull GroupSecretParams groupSecretParams) throws IOException, VerificationFailedException {
final int today = currentTimeDays();
Map<Integer, AuthCredentialResponse> credentials = cache.read();
try {
return getAuthorization(self, groupSecretParams, credentials, today);
} catch (NoCredentialForRedemptionTimeException e) {
Log.i(TAG, "Auth out of date, will update auth and try again");
cache.clear();
} catch (VerificationFailedException e) {
Log.w(TAG, "Verification failed, will update auth and try again", e);
cache.clear();
}
Log.i(TAG, "Getting new auth credential responses");
credentials = groupsV2Api.getCredentials(today);
cache.write(credentials);
try {
return getAuthorization(self, groupSecretParams, credentials, today);
} catch (NoCredentialForRedemptionTimeException e) {
Log.w(TAG, "The credentials returned did not include the day requested");
throw new IOException("Failed to get credentials");
}
}
use of org.whispersystems.signalservice.api.groupsv2.GroupsV2AuthorizationString in project Signal-Android by signalapp.
the class PushServiceSocket method getGroupJoinInfo.
public GroupJoinInfo getGroupJoinInfo(Optional<byte[]> groupLinkPassword, GroupsV2AuthorizationString authorization) throws NonSuccessfulResponseCodeException, PushNetworkException, InvalidProtocolBufferException {
String passwordParam = groupLinkPassword.transform(Base64UrlSafe::encodeBytesWithoutPadding).or("");
ResponseBody response = makeStorageRequest(authorization.toString(), String.format(GROUPSV2_GROUP_JOIN, passwordParam), "GET", null, GROUPS_V2_GET_JOIN_INFO_HANDLER);
return GroupJoinInfo.parseFrom(readBodyBytes(response));
}
use of org.whispersystems.signalservice.api.groupsv2.GroupsV2AuthorizationString in project Signal-Android by WhisperSystems.
the class PushServiceSocket method getGroupsV2GroupHistory.
public GroupHistory getGroupsV2GroupHistory(int fromVersion, GroupsV2AuthorizationString authorization, int highestKnownEpoch, boolean includeFirstState) throws IOException {
Response response = makeStorageRequestResponse(authorization.toString(), String.format(Locale.US, GROUPSV2_GROUP_CHANGES, fromVersion, highestKnownEpoch, includeFirstState), "GET", null, GROUPS_V2_GET_LOGS_HANDLER);
if (response.body() == null) {
throw new PushNetworkException("No body!");
}
GroupChanges groupChanges;
try (InputStream input = response.body().byteStream()) {
groupChanges = GroupChanges.parseFrom(input);
} catch (IOException e) {
throw new PushNetworkException(e);
}
if (response.code() == 206) {
String contentRangeHeader = response.header("Content-Range");
Optional<ContentRange> contentRange = ContentRange.parse(contentRangeHeader);
if (contentRange.isPresent()) {
Log.i(TAG, "Additional logs for group: " + contentRangeHeader);
return new GroupHistory(groupChanges, contentRange);
} else {
Log.w(TAG, "Unable to parse Content-Range header: " + contentRangeHeader);
throw new MalformedResponseException("Unable to parse content range header on 206");
}
}
return new GroupHistory(groupChanges, Optional.absent());
}
Aggregations