Java Code Examples for org.whispersystems.signalservice.internal.util.Hex#toStringCondensed()

The following examples show how to use org.whispersystems.signalservice.internal.util.Hex#toStringCondensed() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RemoteAttestationCipher.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
public static void verifyServerQuote(Quote quote, byte[] serverPublicStatic, String mrenclave)
    throws UnauthenticatedQuoteException
{
  try {
    byte[] theirServerPublicStatic = new byte[serverPublicStatic.length];
    System.arraycopy(quote.getReportData(), 0, theirServerPublicStatic, 0, theirServerPublicStatic.length);

    if (!MessageDigest.isEqual(theirServerPublicStatic, serverPublicStatic)) {
      throw new UnauthenticatedQuoteException("Response quote has unauthenticated report data!");
    }

    if (!MessageDigest.isEqual(Hex.fromStringCondensed(mrenclave), quote.getMrenclave())) {
      throw new UnauthenticatedQuoteException("The response quote has the wrong mrenclave value in it: " + Hex.toStringCondensed(quote.getMrenclave()));
    }

    if (quote.isDebugQuote()) {
      throw new UnauthenticatedQuoteException("Received quote for debuggable enclave");
    }
  } catch (IOException e) {
    throw new UnauthenticatedQuoteException(e);
  }
}
 
Example 2
Source File: PushServiceSocket.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
public ProfileAndCredential retrieveVersionedProfileAndCredential(UUID target, ProfileKey profileKey, Optional<UnidentifiedAccess> unidentifiedAccess)
    throws NonSuccessfulResponseCodeException, PushNetworkException, VerificationFailedException
{
  ProfileKeyVersion                  profileKeyIdentifier = profileKey.getProfileKeyVersion(target);
  ProfileKeyCredentialRequestContext requestContext       = clientZkProfileOperations.createProfileKeyCredentialRequestContext(random, target, profileKey);
  ProfileKeyCredentialRequest        request              = requestContext.getRequest();

  String version           = profileKeyIdentifier.serialize();
  String credentialRequest = Hex.toStringCondensed(request.serialize());
  String subPath           = String.format("%s/%s/%s", target, version, credentialRequest);

  String response = makeServiceRequest(String.format(PROFILE_PATH, subPath), "GET", null, NO_HEADERS, unidentifiedAccess);

  try {
    SignalServiceProfile signalServiceProfile = JsonUtil.fromJson(response, SignalServiceProfile.class);

    ProfileKeyCredential profileKeyCredential = signalServiceProfile.getProfileKeyCredentialResponse() != null
                                              ? clientZkProfileOperations.receiveProfileKeyCredential(requestContext, signalServiceProfile.getProfileKeyCredentialResponse())
                                              : null;

    return new ProfileAndCredential(signalServiceProfile, SignalServiceProfile.RequestType.PROFILE_AND_CREDENTIAL, Optional.fromNullable(profileKeyCredential));
  } catch (IOException e) {
    Log.w(TAG, e);
    throw new NonSuccessfulResponseCodeException("Unable to parse entity");
  }
}
 
Example 3
Source File: ContactDiscoveryCipher.java    From libsignal-service-java with GNU General Public License v3.0 6 votes vote down vote up
public void verifyServerQuote(Quote quote, byte[] serverPublicStatic, String mrenclave)
    throws UnauthenticatedQuoteException
{
  try {
    byte[] theirServerPublicStatic = new byte[serverPublicStatic.length];
    System.arraycopy(quote.getReportData(), 0, theirServerPublicStatic, 0, theirServerPublicStatic.length);

    if (!MessageDigest.isEqual(theirServerPublicStatic, serverPublicStatic)) {
      throw new UnauthenticatedQuoteException("Response quote has unauthenticated report data!");
    }

    if (!MessageDigest.isEqual(Hex.fromStringCondensed(mrenclave), quote.getMrenclave())) {
      throw new UnauthenticatedQuoteException("The response quote has the wrong mrenclave value in it: " + Hex.toStringCondensed(quote.getMrenclave()));
    }

    if (quote.isDebugQuote()) {
      throw new UnauthenticatedQuoteException("Received quote for debuggable enclave");
    }
  } catch (IOException e) {
    throw new UnauthenticatedQuoteException(e);
  }
}
 
Example 4
Source File: RemoteAttestationCipher.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
public static void verifyIasSignature(KeyStore trustStore, String certificates, String signatureBody, String signature, Quote quote)
    throws SignatureException
{
  if (certificates == null || certificates.isEmpty()) {
    throw new SignatureException("No certificates.");
  }

  try {
    SigningCertificate signingCertificate = new SigningCertificate(certificates, trustStore);
    signingCertificate.verifySignature(signatureBody, signature);

    SignatureBodyEntity signatureBodyEntity = JsonUtil.fromJson(signatureBody, SignatureBodyEntity.class);

    if (signatureBodyEntity.getVersion() != SIGNATURE_BODY_VERSION) {
      throw new SignatureException("Unexpected signed quote version " + signatureBodyEntity.getVersion());
    }

    if (!MessageDigest.isEqual(ByteUtil.trim(signatureBodyEntity.getIsvEnclaveQuoteBody(), 432), ByteUtil.trim(quote.getQuoteBytes(), 432))) {
      throw new SignatureException("Signed quote is not the same as RA quote: " + Hex.toStringCondensed(signatureBodyEntity.getIsvEnclaveQuoteBody()) + " vs " + Hex.toStringCondensed(quote.getQuoteBytes()));
    }

    if (!"OK".equals(signatureBodyEntity.getIsvEnclaveQuoteStatus())) {
      throw new SignatureException("Quote status is: " + signatureBodyEntity.getIsvEnclaveQuoteStatus());
    }

    if (Instant.from(ZonedDateTime.of(LocalDateTime.from(DateTimeFormatter.ofPattern("yyy-MM-dd'T'HH:mm:ss.SSSSSS").parse(signatureBodyEntity.getTimestamp())), ZoneId.of("UTC")))
               .plus(Period.ofDays(1))
               .isBefore(Instant.now()))
    {
      throw new SignatureException("Signature is expired");
    }

  } catch (CertificateException | CertPathValidatorException | IOException e) {
    throw new SignatureException(e);
  }
}
 
Example 5
Source File: PushServiceSocket.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
public byte[] retrieveSticker(byte[] packId, int stickerId)
    throws NonSuccessfulResponseCodeException, PushNetworkException {
  String                hexPackId = Hex.toStringCondensed(packId);
  ByteArrayOutputStream output    = new ByteArrayOutputStream();

  try {
    downloadFromCdn(output, 0, 0, String.format(Locale.US, STICKER_PATH, hexPackId, stickerId), 1024 * 1024, null);
  } catch (MissingConfigurationException e) {
    throw new AssertionError(e);
  }

  return output.toByteArray();
}
 
Example 6
Source File: PushServiceSocket.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
public byte[] retrieveStickerManifest(byte[] packId)
    throws NonSuccessfulResponseCodeException, PushNetworkException {
  String                hexPackId = Hex.toStringCondensed(packId);
  ByteArrayOutputStream output    = new ByteArrayOutputStream();

  try {
    downloadFromCdn(output, 0, 0, String.format(STICKER_MANIFEST_PATH, hexPackId), 1024 * 1024, null);
  } catch (MissingConfigurationException e) {
    throw new AssertionError(e);
  }

  return output.toByteArray();
}
 
Example 7
Source File: ContactDiscoveryCipher.java    From libsignal-service-java with GNU General Public License v3.0 5 votes vote down vote up
public void verifyIasSignature(KeyStore trustStore, String certificates, String signatureBody, String signature, Quote quote)
    throws SignatureException
{
  if (certificates == null || certificates.isEmpty()) {
    throw new SignatureException("No certificates.");
  }

  try {
    SigningCertificate signingCertificate = new SigningCertificate(certificates, trustStore);
    signingCertificate.verifySignature(signatureBody, signature);

    SignatureBodyEntity signatureBodyEntity = JsonUtil.fromJson(signatureBody, SignatureBodyEntity.class);

    if (signatureBodyEntity.getVersion() != SIGNATURE_BODY_VERSION) {
      throw new SignatureException("Unexpected signed quote version " + signatureBodyEntity.getVersion());
    }

    if (!MessageDigest.isEqual(ByteUtil.trim(signatureBodyEntity.getIsvEnclaveQuoteBody(), 432), ByteUtil.trim(quote.getQuoteBytes(), 432))) {
      throw new SignatureException("Signed quote is not the same as RA quote: " + Hex.toStringCondensed(signatureBodyEntity.getIsvEnclaveQuoteBody()) + " vs " + Hex.toStringCondensed(quote.getQuoteBytes()));
    }

    if (!"OK".equals(signatureBodyEntity.getIsvEnclaveQuoteStatus())) {
      throw new SignatureException("Quote status is: " + signatureBodyEntity.getIsvEnclaveQuoteStatus());
    }

    if (Instant.from(ZonedDateTime.of(LocalDateTime.from(DateTimeFormatter.ofPattern("yyy-MM-dd'T'HH:mm:ss.SSSSSS").parse(signatureBodyEntity.getTimestamp())), ZoneId.of("UTC")))
               .plus(Period.ofDays(1))
               .isBefore(Instant.now()))
    {
      throw new SignatureException("Signature is expired");
    }

  } catch (CertificateException | CertPathValidatorException | IOException e) {
    throw new SignatureException(e);
  }
}
 
Example 8
Source File: PushServiceSocket.java    From libsignal-service-java with GNU General Public License v3.0 5 votes vote down vote up
public byte[] retrieveSticker(byte[] packId, int stickerId)
    throws NonSuccessfulResponseCodeException, PushNetworkException
{
  String                hexPackId = Hex.toStringCondensed(packId);
  ByteArrayOutputStream output    = new ByteArrayOutputStream();

  downloadFromCdn(output, String.format(Locale.US, STICKER_PATH, hexPackId, stickerId), 1024 * 1024, null);

  return output.toByteArray();
}
 
Example 9
Source File: PushServiceSocket.java    From libsignal-service-java with GNU General Public License v3.0 5 votes vote down vote up
public byte[] retrieveStickerManifest(byte[] packId)
    throws NonSuccessfulResponseCodeException, PushNetworkException
{
  String                hexPackId = Hex.toStringCondensed(packId);
  ByteArrayOutputStream output    = new ByteArrayOutputStream();

  downloadFromCdn(output, String.format(STICKER_MANIFEST_PATH, hexPackId), 1024 * 1024, null);

  return output.toByteArray();
}
 
Example 10
Source File: MasterKey.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
public String deriveRegistrationLock() {
  return Hex.toStringCondensed(derive("Registration Lock"));
}
 
Example 11
Source File: GroupsV2AuthorizationString.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
GroupsV2AuthorizationString(GroupSecretParams groupSecretParams, AuthCredentialPresentation authCredentialPresentation) {
  String username = Hex.toStringCondensed(groupSecretParams.getPublicParams().serialize());
  String password = Hex.toStringCondensed(authCredentialPresentation.serialize());

  authString = Credentials.basic(username, password);
}
 
Example 12
Source File: PushServiceSocket.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
public void retrieveSticker(File destination, byte[] packId, int stickerId)
    throws NonSuccessfulResponseCodeException, PushNetworkException, MissingConfigurationException {
  String hexPackId = Hex.toStringCondensed(packId);
  downloadFromCdn(destination, 0, String.format(Locale.US, STICKER_PATH, hexPackId, stickerId), 1024 * 1024, null);
}
 
Example 13
Source File: PushServiceSocket.java    From libsignal-service-java with GNU General Public License v3.0 4 votes vote down vote up
public void retrieveSticker(File destination, byte[] packId, int stickerId)
    throws NonSuccessfulResponseCodeException, PushNetworkException
{
  String hexPackId = Hex.toStringCondensed(packId);
  downloadFromCdn(destination, String.format(Locale.US, STICKER_PATH, hexPackId, stickerId), 1024 * 1024, null);
}