本文整理汇总了Java中org.whispersystems.libsignal.InvalidVersionException类的典型用法代码示例。如果您正苦于以下问题:Java InvalidVersionException类的具体用法?Java InvalidVersionException怎么用?Java InvalidVersionException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
InvalidVersionException类属于org.whispersystems.libsignal包,在下文中一共展示了InvalidVersionException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: decrypt
import org.whispersystems.libsignal.InvalidVersionException; //导入依赖的package包/类
private byte[] decrypt(SignalServiceEnvelope envelope, byte[] ciphertext)
throws InvalidVersionException, InvalidMessageException, InvalidKeyException,
DuplicateMessageException, InvalidKeyIdException, UntrustedIdentityException,
LegacyMessageException, NoSessionException
{
SignalProtocolAddress sourceAddress = new SignalProtocolAddress(envelope.getSource(), envelope.getSourceDevice());
SessionCipher sessionCipher = new SessionCipher(signalProtocolStore, sourceAddress);
byte[] paddedMessage;
if (envelope.isPreKeySignalMessage()) {
paddedMessage = sessionCipher.decrypt(new PreKeySignalMessage(ciphertext));
} else if (envelope.isSignalMessage()) {
paddedMessage = sessionCipher.decrypt(new SignalMessage(ciphertext));
} else {
throw new InvalidMessageException("Unknown type: " + envelope.getType());
}
PushTransportDetails transportDetails = new PushTransportDetails(sessionCipher.getSessionVersion());
return transportDetails.getStrippedPaddingMessageBody(paddedMessage);
}
示例2: read
import org.whispersystems.libsignal.InvalidVersionException; //导入依赖的package包/类
/**
* A blocking call that reads a message off the pipe (see {@link #read(long, java.util.concurrent.TimeUnit)}
*
* Unlike {@link #read(long, java.util.concurrent.TimeUnit)}, this method allows you
* to specify a callback that will be called before the received message is acknowledged.
* This allows you to write the received message to durable storage before acknowledging
* receipt of it to the server.
*
* @param timeout The timeout to wait for.
* @param unit The timeout time unit.
* @param callback A callback that will be called before the message receipt is
* acknowledged to the server.
* @return The message read (same as the message sent through the callback).
* @throws TimeoutException
* @throws IOException
* @throws InvalidVersionException
*/
public SignalServiceEnvelope read(long timeout, TimeUnit unit, MessagePipeCallback callback)
throws TimeoutException, IOException, InvalidVersionException
{
while (true) {
WebSocketRequestMessage request = websocket.readRequest(unit.toMillis(timeout));
WebSocketResponseMessage response = createWebSocketResponse(request);
try {
if (isSignalServiceEnvelope(request)) {
SignalServiceEnvelope envelope = new SignalServiceEnvelope(request.getBody().toByteArray(),
credentialsProvider.getSignalingKey());
callback.onMessage(envelope);
return envelope;
}
} finally {
websocket.sendResponse(response);
}
}
}
示例3: tryFetchLatestMessage
import org.whispersystems.libsignal.InvalidVersionException; //导入依赖的package包/类
@WorkerThread
private IncomingMessage tryFetchLatestMessage() throws TimeoutException {
if (this.messagePipe == null) {
this.messagePipe = messageReceiver.createMessagePipe();
}
try {
final SignalServiceEnvelope envelope = messagePipe.read(INCOMING_MESSAGE_TIMEOUT, TimeUnit.SECONDS);
return decryptIncomingSignalServiceEnvelope(envelope);
} catch (final TimeoutException ex) {
throw new TimeoutException(ex.getMessage());
} catch (final IllegalStateException | InvalidKeyException | InvalidKeyIdException | DuplicateMessageException | InvalidVersionException | LegacyMessageException | InvalidMessageException | NoSessionException | org.whispersystems.libsignal.UntrustedIdentityException | IOException e) {
LogUtil.exception(getClass(), "Error while fetching latest message", e);
}
return null;
}
示例4: handleIncomingSofaMessage
import org.whispersystems.libsignal.InvalidVersionException; //导入依赖的package包/类
private IncomingMessage handleIncomingSofaMessage(final SignalServiceEnvelope envelope) throws InvalidVersionException, InvalidMessageException, InvalidKeyException, DuplicateMessageException, InvalidKeyIdException, org.whispersystems.libsignal.UntrustedIdentityException, LegacyMessageException, NoSessionException {
final SignalServiceAddress localAddress = new SignalServiceAddress(this.wallet.getOwnerAddress());
final SignalServiceCipher cipher = new SignalServiceCipher(localAddress, this.protocolStore);
final SignalServiceContent content = cipher.decrypt(envelope);
final String messageSource = envelope.getSource();
if (isUserBlocked(messageSource)) {
LogUtil.i(getClass(), "A blocked user is trying to send a message");
return null;
}
if (content.getDataMessage().isPresent()) {
final SignalServiceDataMessage dataMessage = content.getDataMessage().get();
if (dataMessage.isGroupUpdate()) return taskGroupUpdate.run(messageSource, dataMessage);
else return taskHandleMessage.run(messageSource, dataMessage);
}
return null;
}
示例5: decrypt
import org.whispersystems.libsignal.InvalidVersionException; //导入依赖的package包/类
public IncomingEncryptedMessage decrypt(Context context, IncomingPreKeyBundleMessage message)
throws InvalidVersionException, InvalidMessageException, DuplicateMessageException,
UntrustedIdentityException, LegacyMessageException
{
try {
byte[] decoded = transportDetails.getDecodedMessage(message.getMessageBody().getBytes());
PreKeySignalMessage preKeyMessage = new PreKeySignalMessage(decoded);
SessionCipher sessionCipher = new SessionCipher(signalProtocolStore, new SignalProtocolAddress(message.getSender(), 1));
byte[] padded = sessionCipher.decrypt(preKeyMessage);
byte[] plaintext = transportDetails.getStrippedPaddingMessageBody(padded);
return new IncomingEncryptedMessage(message, new String(plaintext));
} catch (IOException | InvalidKeyException | InvalidKeyIdException e) {
throw new InvalidMessageException(e);
}
}
示例6: process
import org.whispersystems.libsignal.InvalidVersionException; //导入依赖的package包/类
public OutgoingKeyExchangeMessage process(Context context, IncomingKeyExchangeMessage message)
throws UntrustedIdentityException, StaleKeyExchangeException,
InvalidVersionException, LegacyMessageException, InvalidMessageException
{
try {
Recipients recipients = RecipientFactory.getRecipientsFromString(context, message.getSender(), false);
SignalProtocolAddress signalProtocolAddress = new SignalProtocolAddress(message.getSender(), 1);
KeyExchangeMessage exchangeMessage = new KeyExchangeMessage(transportDetails.getDecodedMessage(message.getMessageBody().getBytes()));
SessionBuilder sessionBuilder = new SessionBuilder(signalProtocolStore, signalProtocolAddress);
KeyExchangeMessage response = sessionBuilder.process(exchangeMessage);
if (response != null) {
byte[] serializedResponse = transportDetails.getEncodedMessage(response.serialize());
return new OutgoingKeyExchangeMessage(recipients, new String(serializedResponse), message.getSubscriptionId());
} else {
return null;
}
} catch (IOException | InvalidKeyException e) {
throw new InvalidMessageException(e);
}
}
示例7: ReceiveKeyDialog
import org.whispersystems.libsignal.InvalidVersionException; //导入依赖的package包/类
public ReceiveKeyDialog(@NonNull Context context,
@NonNull MasterSecret masterSecret,
@NonNull MessageRecord messageRecord)
{
super(context);
try{
final IncomingKeyExchangeMessage message = getMessage(messageRecord);
final IdentityKey identityKey = getIdentityKey(message);
if (isTrusted(masterSecret, identityKey, messageRecord.getIndividualRecipient())){
setMessage(context.getString(R.string.ReceiveKeyActivity_the_signature_on_this_key_exchange_is_trusted_but));
} else {
setUntrustedText(messageRecord, identityKey);
}
setButton(AlertDialog.BUTTON_POSITIVE, context.getString(R.string.receive_key_activity__complete), new AcceptListener(masterSecret, messageRecord, message, identityKey));
setButton(AlertDialog.BUTTON_NEGATIVE, context.getString(android.R.string.cancel), new CancelListener());
} catch (InvalidKeyException | InvalidVersionException | InvalidMessageException | LegacyMessageException e) {
throw new AssertionError(e);
}
}
示例8: getMessage
import org.whispersystems.libsignal.InvalidVersionException; //导入依赖的package包/类
private static IncomingKeyExchangeMessage getMessage(MessageRecord messageRecord)
throws InvalidKeyException, InvalidVersionException,
InvalidMessageException, LegacyMessageException
{
IncomingTextMessage message = new IncomingTextMessage(messageRecord.getIndividualRecipient().getNumber(),
messageRecord.getRecipientDeviceId(),
System.currentTimeMillis(),
messageRecord.getBody().getBody());
if (messageRecord.isBundleKeyExchange()) {
return new IncomingPreKeyBundleMessage(message, message.getMessageBody());
} else if (messageRecord.isIdentityUpdate()) {
return new IncomingIdentityUpdateMessage(message, message.getMessageBody());
} else {
return new IncomingKeyExchangeMessage(message, message.getMessageBody());
}
}
示例9: getIdentityKey
import org.whispersystems.libsignal.InvalidVersionException; //导入依赖的package包/类
private static IdentityKey getIdentityKey(IncomingKeyExchangeMessage message)
throws InvalidKeyException, InvalidVersionException,
InvalidMessageException, LegacyMessageException
{
try {
if (message.isIdentityUpdate()) {
return new IdentityKey(Base64.decodeWithoutPadding(message.getMessageBody()), 0);
} else if (message.isPreKeyBundle()) {
return new PreKeySignalMessage(Base64.decodeWithoutPadding(message.getMessageBody())).getIdentityKey();
} else {
return new KeyExchangeMessage(Base64.decodeWithoutPadding(message.getMessageBody())).getIdentityKey();
}
} catch (IOException e) {
throw new AssertionError(e);
}
}
示例10: handleUntrustedIdentityMessage
import org.whispersystems.libsignal.InvalidVersionException; //导入依赖的package包/类
private void handleUntrustedIdentityMessage(@NonNull MasterSecretUnion masterSecret,
@NonNull SignalServiceEnvelope envelope,
@NonNull Optional<Long> smsMessageId)
{
try {
EncryptingSmsDatabase database = DatabaseFactory.getEncryptingSmsDatabase(context);
Recipients recipients = RecipientFactory.getRecipientsFromString(context, envelope.getSource(), false);
long recipientId = recipients.getPrimaryRecipient().getRecipientId();
byte[] serialized = envelope.hasLegacyMessage() ? envelope.getLegacyMessage() : envelope.getContent();
PreKeySignalMessage whisperMessage = new PreKeySignalMessage(serialized);
IdentityKey identityKey = whisperMessage.getIdentityKey();
String encoded = Base64.encodeBytes(serialized);
IncomingTextMessage textMessage = new IncomingTextMessage(envelope.getSource(), envelope.getSourceDevice(),
envelope.getTimestamp(), encoded,
Optional.<SignalServiceGroup>absent(), 0);
if (!smsMessageId.isPresent()) {
IncomingPreKeyBundleMessage bundleMessage = new IncomingPreKeyBundleMessage(textMessage, encoded, envelope.hasLegacyMessage());
Optional<InsertResult> insertResult = database.insertMessageInbox(masterSecret, bundleMessage);
if (insertResult.isPresent()) {
database.setMismatchedIdentity(insertResult.get().getMessageId(), recipientId, identityKey);
MessageNotifier.updateNotification(context, masterSecret.getMasterSecret().orNull(), insertResult.get().getThreadId());
}
} else {
database.updateMessageBody(masterSecret, smsMessageId.get(), encoded);
database.markAsPreKeyBundle(smsMessageId.get());
database.setMismatchedIdentity(smsMessageId.get(), recipientId, identityKey);
}
} catch (InvalidMessageException | InvalidVersionException e) {
throw new AssertionError(e);
}
}
示例11: onRun
import org.whispersystems.libsignal.InvalidVersionException; //导入依赖的package包/类
@Override
public void onRun() {
try {
String sessionKey = TextSecurePreferences.getSignalingKey(context);
SignalServiceEnvelope envelope = new SignalServiceEnvelope(data, sessionKey);
handle(envelope, true);
} catch (IOException | InvalidVersionException e) {
Log.w(TAG, e);
}
}
示例12: SignalServiceEnvelope
import org.whispersystems.libsignal.InvalidVersionException; //导入依赖的package包/类
/**
* Construct an envelope from a serialized SignalServiceEnvelope, encrypted with a signaling key.
*
* @param ciphertext The serialized and encrypted SignalServiceEnvelope.
* @param signalingKey The signaling key.
* @throws InvalidVersionException
* @throws IOException
*/
public SignalServiceEnvelope(byte[] ciphertext, String signalingKey)
throws InvalidVersionException, IOException
{
if (ciphertext.length < VERSION_LENGTH || ciphertext[VERSION_OFFSET] != SUPPORTED_VERSION)
throw new InvalidVersionException("Unsupported version!");
SecretKeySpec cipherKey = getCipherKey(signalingKey);
SecretKeySpec macKey = getMacKey(signalingKey);
verifyMac(ciphertext, macKey);
this.envelope = Envelope.parseFrom(getPlaintext(ciphertext, cipherKey));
}
示例13: decryptIncomingSignalServiceEnvelope
import org.whispersystems.libsignal.InvalidVersionException; //导入依赖的package包/类
private IncomingMessage decryptIncomingSignalServiceEnvelope(final SignalServiceEnvelope envelope) throws InvalidVersionException, InvalidMessageException, InvalidKeyException, DuplicateMessageException, InvalidKeyIdException, org.whispersystems.libsignal.UntrustedIdentityException, LegacyMessageException, NoSessionException {
// ToDo -- When do we need to create new keys?
/* if (envelope.getType() == SignalServiceProtos.Envelope.Type.PREKEY_BUNDLE_VALUE) {
// New keys need to be registered with the server.
registerWithServer();
return;
}*/
return handleIncomingSofaMessage(envelope);
}
示例14: KeyExchangeMessage
import org.whispersystems.libsignal.InvalidVersionException; //导入依赖的package包/类
public KeyExchangeMessage(byte[] serialized)
throws InvalidMessageException, InvalidVersionException, LegacyMessageException
{
try {
byte[][] parts = ByteUtil.split(serialized, 1, serialized.length - 1);
this.version = ByteUtil.highBitsToInt(parts[0][0]);
this.supportedVersion = ByteUtil.lowBitsToInt(parts[0][0]);
if (this.version < CiphertextMessage.CURRENT_VERSION) {
throw new LegacyMessageException("Unsupported legacy version: " + this.version);
}
if (this.version > CiphertextMessage.CURRENT_VERSION) {
throw new InvalidVersionException("Unknown version: " + this.version);
}
SignalProtos.KeyExchangeMessage message = SignalProtos.KeyExchangeMessage.parseFrom(parts[1]);
if (!message.hasId() || !message.hasBaseKey() ||
!message.hasRatchetKey() || !message.hasIdentityKey() ||
!message.hasBaseKeySignature())
{
throw new InvalidMessageException("Some required fields missing!");
}
this.sequence = message.getId() >> 5;
this.flags = message.getId() & 0x1f;
this.serialized = serialized;
this.baseKey = Curve.decodePoint(message.getBaseKey().toByteArray(), 0);
this.baseKeySignature = message.getBaseKeySignature().toByteArray();
this.ratchetKey = Curve.decodePoint(message.getRatchetKey().toByteArray(), 0);
this.identityKey = new IdentityKey(message.getIdentityKey().toByteArray(), 0);
} catch (InvalidKeyException | IOException e) {
throw new InvalidMessageException(e);
}
}
示例15: processReceiving
import org.whispersystems.libsignal.InvalidVersionException; //导入依赖的package包/类
@Nullable
public byte[] processReceiving(AxolotlKey encryptedKey) throws CryptoFailedException {
byte[] plaintext;
FingerprintStatus status = getTrust();
if (!status.isCompromised()) {
try {
if (encryptedKey.prekey) {
PreKeySignalMessage preKeySignalMessage = new PreKeySignalMessage(encryptedKey.key);
Optional<Integer> optionalPreKeyId = preKeySignalMessage.getPreKeyId();
IdentityKey identityKey = preKeySignalMessage.getIdentityKey();
if (!optionalPreKeyId.isPresent()) {
throw new CryptoFailedException("PreKeyWhisperMessage did not contain a PreKeyId");
}
preKeyId = optionalPreKeyId.get();
if (this.identityKey != null && !this.identityKey.equals(identityKey)) {
throw new CryptoFailedException("Received PreKeyWhisperMessage but preexisting identity key changed.");
}
this.identityKey = identityKey;
plaintext = cipher.decrypt(preKeySignalMessage);
} else {
SignalMessage signalMessage = new SignalMessage(encryptedKey.key);
plaintext = cipher.decrypt(signalMessage);
preKeyId = null; //better safe than sorry because we use that to do special after prekey handling
}
} catch (InvalidVersionException | InvalidKeyException | LegacyMessageException | InvalidMessageException | DuplicateMessageException | NoSessionException | InvalidKeyIdException | UntrustedIdentityException e) {
if (!(e instanceof DuplicateMessageException)) {
e.printStackTrace();
}
throw new CryptoFailedException("Error decrypting WhisperMessage " + e.getClass().getSimpleName() + ": " + e.getMessage());
}
if (!status.isActive()) {
setTrust(status.toActive());
}
} else {
throw new CryptoFailedException("not encrypting omemo message from fingerprint "+getFingerprint()+" because it was marked as compromised");
}
return plaintext;
}