本文整理汇总了Java中org.whispersystems.libsignal.LegacyMessageException类的典型用法代码示例。如果您正苦于以下问题:Java LegacyMessageException类的具体用法?Java LegacyMessageException怎么用?Java LegacyMessageException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LegacyMessageException类属于org.whispersystems.libsignal包,在下文中一共展示了LegacyMessageException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: decrypt
import org.whispersystems.libsignal.LegacyMessageException; //导入依赖的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: tryFetchLatestMessage
import org.whispersystems.libsignal.LegacyMessageException; //导入依赖的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;
}
示例3: handleIncomingSofaMessage
import org.whispersystems.libsignal.LegacyMessageException; //导入依赖的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;
}
示例4: decrypt
import org.whispersystems.libsignal.LegacyMessageException; //导入依赖的package包/类
public IncomingTextMessage decrypt(Context context, IncomingTextMessage message)
throws LegacyMessageException, InvalidMessageException,
DuplicateMessageException, NoSessionException
{
try {
byte[] decoded = transportDetails.getDecodedMessage(message.getMessageBody().getBytes());
SignalMessage signalMessage = new SignalMessage(decoded);
SessionCipher sessionCipher = new SessionCipher(signalProtocolStore, new SignalProtocolAddress(message.getSender(), 1));
byte[] padded = sessionCipher.decrypt(signalMessage);
byte[] plaintext = transportDetails.getStrippedPaddingMessageBody(padded);
if (message.isEndSession() && "TERMINATE".equals(new String(plaintext))) {
signalProtocolStore.deleteSession(new SignalProtocolAddress(message.getSender(), 1));
}
return message.withMessageBody(new String(plaintext));
} catch (IOException | IllegalArgumentException | NullPointerException e) {
throw new InvalidMessageException(e);
}
}
示例5: process
import org.whispersystems.libsignal.LegacyMessageException; //导入依赖的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);
}
}
示例6: ReceiveKeyDialog
import org.whispersystems.libsignal.LegacyMessageException; //导入依赖的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);
}
}
示例7: getMessage
import org.whispersystems.libsignal.LegacyMessageException; //导入依赖的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());
}
}
示例8: getIdentityKey
import org.whispersystems.libsignal.LegacyMessageException; //导入依赖的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);
}
}
示例9: testNoSession
import org.whispersystems.libsignal.LegacyMessageException; //导入依赖的package包/类
public void testNoSession() throws InvalidMessageException, LegacyMessageException, NoSessionException, DuplicateMessageException {
InMemorySenderKeyStore aliceStore = new InMemorySenderKeyStore();
InMemorySenderKeyStore bobStore = new InMemorySenderKeyStore();
GroupSessionBuilder aliceSessionBuilder = new GroupSessionBuilder(aliceStore);
GroupSessionBuilder bobSessionBuilder = new GroupSessionBuilder(bobStore);
GroupCipher aliceGroupCipher = new GroupCipher(aliceStore, GROUP_SENDER);
GroupCipher bobGroupCipher = new GroupCipher(bobStore, GROUP_SENDER);
SenderKeyDistributionMessage sentAliceDistributionMessage = aliceSessionBuilder.create(GROUP_SENDER);
SenderKeyDistributionMessage receivedAliceDistributionMessage = new SenderKeyDistributionMessage(sentAliceDistributionMessage.serialize());
// bobSessionBuilder.process(GROUP_SENDER, receivedAliceDistributionMessage);
byte[] ciphertextFromAlice = aliceGroupCipher.encrypt("smert ze smert".getBytes());
try {
byte[] plaintextFromAlice = bobGroupCipher.decrypt(ciphertextFromAlice);
throw new AssertionError("Should be no session!");
} catch (NoSessionException e) {
// good
}
}
示例10: testBasicEncryptDecrypt
import org.whispersystems.libsignal.LegacyMessageException; //导入依赖的package包/类
public void testBasicEncryptDecrypt()
throws LegacyMessageException, DuplicateMessageException, InvalidMessageException, NoSessionException
{
InMemorySenderKeyStore aliceStore = new InMemorySenderKeyStore();
InMemorySenderKeyStore bobStore = new InMemorySenderKeyStore();
GroupSessionBuilder aliceSessionBuilder = new GroupSessionBuilder(aliceStore);
GroupSessionBuilder bobSessionBuilder = new GroupSessionBuilder(bobStore);
GroupCipher aliceGroupCipher = new GroupCipher(aliceStore, GROUP_SENDER);
GroupCipher bobGroupCipher = new GroupCipher(bobStore, GROUP_SENDER);
SenderKeyDistributionMessage sentAliceDistributionMessage = aliceSessionBuilder.create(GROUP_SENDER);
SenderKeyDistributionMessage receivedAliceDistributionMessage = new SenderKeyDistributionMessage(sentAliceDistributionMessage.serialize());
bobSessionBuilder.process(GROUP_SENDER, receivedAliceDistributionMessage);
byte[] ciphertextFromAlice = aliceGroupCipher.encrypt("smert ze smert".getBytes());
byte[] plaintextFromAlice = bobGroupCipher.decrypt(ciphertextFromAlice);
assertTrue(new String(plaintextFromAlice).equals("smert ze smert"));
}
示例11: testLargeMessages
import org.whispersystems.libsignal.LegacyMessageException; //导入依赖的package包/类
public void testLargeMessages() throws InvalidMessageException, LegacyMessageException, NoSessionException, DuplicateMessageException {
InMemorySenderKeyStore aliceStore = new InMemorySenderKeyStore();
InMemorySenderKeyStore bobStore = new InMemorySenderKeyStore();
GroupSessionBuilder aliceSessionBuilder = new GroupSessionBuilder(aliceStore);
GroupSessionBuilder bobSessionBuilder = new GroupSessionBuilder(bobStore);
GroupCipher aliceGroupCipher = new GroupCipher(aliceStore, GROUP_SENDER);
GroupCipher bobGroupCipher = new GroupCipher(bobStore, GROUP_SENDER);
SenderKeyDistributionMessage sentAliceDistributionMessage = aliceSessionBuilder.create(GROUP_SENDER);
SenderKeyDistributionMessage receivedAliceDistributionMessage = new SenderKeyDistributionMessage(sentAliceDistributionMessage.serialize());
bobSessionBuilder.process(GROUP_SENDER, receivedAliceDistributionMessage);
byte[] plaintext = new byte[1024 * 1024];
new Random().nextBytes(plaintext);
byte[] ciphertextFromAlice = aliceGroupCipher.encrypt(plaintext);
byte[] plaintextFromAlice = bobGroupCipher.decrypt(ciphertextFromAlice);
assertTrue(Arrays.equals(plaintext, plaintextFromAlice));
}
示例12: decryptIncomingSignalServiceEnvelope
import org.whispersystems.libsignal.LegacyMessageException; //导入依赖的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);
}
示例13: KeyExchangeMessage
import org.whispersystems.libsignal.LegacyMessageException; //导入依赖的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);
}
}
示例14: handleSecureMessage
import org.whispersystems.libsignal.LegacyMessageException; //导入依赖的package包/类
private void handleSecureMessage(MasterSecret masterSecret, long messageId, long threadId,
IncomingTextMessage message)
throws NoSessionException, DuplicateMessageException,
InvalidMessageException, LegacyMessageException
{
EncryptingSmsDatabase database = DatabaseFactory.getEncryptingSmsDatabase(context);
SmsCipher cipher = new SmsCipher(new SilenceSignalProtocolStore(context, masterSecret));
IncomingTextMessage plaintext = cipher.decrypt(context, message);
database.updateMessageBody(masterSecret, messageId, plaintext.getMessageBody());
if (message.isEndSession()) SecurityEvent.broadcastSecurityUpdateEvent(context, threadId);
}
示例15: handleXmppExchangeMessage
import org.whispersystems.libsignal.LegacyMessageException; //导入依赖的package包/类
private void handleXmppExchangeMessage(MasterSecret masterSecret, long messageId, long threadId,
IncomingXmppExchangeMessage message)
throws NoSessionException, DuplicateMessageException, InvalidMessageException, LegacyMessageException
{
EncryptingSmsDatabase database = DatabaseFactory.getEncryptingSmsDatabase(context);
database.markAsXmppExchange(messageId);
}