• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java DuplicateMessageException类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.whispersystems.libaxolotl.DuplicateMessageException的典型用法代码示例。如果您正苦于以下问题:Java DuplicateMessageException类的具体用法?Java DuplicateMessageException怎么用?Java DuplicateMessageException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



DuplicateMessageException类属于org.whispersystems.libaxolotl包,在下文中一共展示了DuplicateMessageException类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: decrypt

import org.whispersystems.libaxolotl.DuplicateMessageException; //导入依赖的package包/类
public IncomingTextMessage decrypt(Context context, IncomingTextMessage message)
    throws LegacyMessageException, InvalidMessageException,
           DuplicateMessageException, NoSessionException
{
  try {
    Recipients     recipients     = RecipientFactory.getRecipientsFromString(context, message.getSender(), false);
    long           recipientId    = recipients.getPrimaryRecipient().getRecipientId();
    byte[]         decoded        = transportDetails.getDecodedMessage(message.getMessageBody().getBytes());
    WhisperMessage whisperMessage = new WhisperMessage(decoded);
    SessionCipher  sessionCipher  = new SessionCipher(axolotlStore, recipientId, 1);
    byte[]         padded         = sessionCipher.decrypt(whisperMessage);
    byte[]         plaintext      = transportDetails.getStrippedPaddingMessageBody(padded);

    if (message.isEndSession() && "TERMINATE".equals(new String(plaintext))) {
      axolotlStore.deleteSession(recipientId, 1);
    }

    return message.withMessageBody(new String(plaintext));
  } catch (RecipientFormattingException | IOException e) {
    throw new InvalidMessageException(e);
  }
}
 
开发者ID:redcracker,项目名称:TextSecure,代码行数:23,代码来源:SmsCipher.java


示例2: retrieveAndStore

import org.whispersystems.libaxolotl.DuplicateMessageException; //导入依赖的package包/类
private void retrieveAndStore(MasterSecret masterSecret, MmsRadio radio,
                              long messageId, long threadId,
                              String contentLocation, byte[] transactionId,
                              boolean radioEnabled, boolean useProxy)
    throws IOException, MmsException, ApnUnavailableException,
           DuplicateMessageException, NoSessionException,
           InvalidMessageException, LegacyMessageException
{
  Apn                   dbApn      = MmsConnection.getApn(context, radio.getApnInformation());
  Apn                   contentApn = new Apn(contentLocation, dbApn.getProxy(), Integer.toString(dbApn.getPort()), dbApn.getUsername(), dbApn.getPassword());
  IncomingMmsConnection connection = new IncomingMmsConnection(context, contentApn);
  RetrieveConf          retrieved  = connection.retrieve(radioEnabled, useProxy);

  storeRetrievedMms(masterSecret, contentLocation, messageId, threadId, retrieved);
  sendRetrievedAcknowledgement(radio, transactionId, radioEnabled, useProxy);
}
 
开发者ID:redcracker,项目名称:TextSecure,代码行数:17,代码来源:MmsDownloadJob.java


示例3: decrypt

import org.whispersystems.libaxolotl.DuplicateMessageException; //导入依赖的package包/类
public TextSecureMessage decrypt(TextSecureEnvelope envelope)
    throws InvalidVersionException, InvalidMessageException, InvalidKeyException,
           DuplicateMessageException, InvalidKeyIdException, UntrustedIdentityException,
           LegacyMessageException, NoSessionException
{
  try {
    byte[] paddedMessage;

    if (envelope.isPreKeyWhisperMessage()) {
      paddedMessage = sessionCipher.decrypt(new PreKeyWhisperMessage(envelope.getMessage()));
    } else if (envelope.isWhisperMessage()) {
      paddedMessage = sessionCipher.decrypt(new WhisperMessage(envelope.getMessage()));
    } else if (envelope.isPlaintext()) {
      paddedMessage = envelope.getMessage();
    } else {
      throw new InvalidMessageException("Unknown type: " + envelope.getType());
    }

    PushTransportDetails transportDetails = new PushTransportDetails(sessionCipher.getSessionVersion());
    PushMessageContent   content          = PushMessageContent.parseFrom(transportDetails.getStrippedPaddingMessageBody(paddedMessage));

    return createTextSecureMessage(envelope, content);
  } catch (InvalidProtocolBufferException e) {
    throw new InvalidMessageException(e);
  }
}
 
开发者ID:redcracker,项目名称:TextSecure,代码行数:27,代码来源:TextSecureCipher.java


示例4: decrypt

import org.whispersystems.libaxolotl.DuplicateMessageException; //导入依赖的package包/类
public TextSecureSMPMessage decrypt(TextSecureEnvelope envelope) throws InvalidVersionException,
	InvalidMessageException, InvalidKeyException, DuplicateMessageException, InvalidKeyIdException, UntrustedIdentityException, LegacyMessageException, NoSessionException {
	try {
		AxolotlAddress e = new AxolotlAddress(envelope.getSource(), envelope.getSourceDevice());
		SessionCipher sessionCipher = new SessionCipher(this.axolotlStore, e);
		byte[] paddedMessage;
		if(envelope.isPreKeyWhisperMessage()) {
			paddedMessage = sessionCipher.decrypt(new PreKeyWhisperMessage(envelope.getMessage()));
		} else {
			if(!envelope.isWhisperMessage()) {
				throw new InvalidMessageException("Unknown type: " + envelope.getType());
			}

			paddedMessage = sessionCipher.decrypt(new WhisperMessage(envelope.getMessage()));
		}

		PushTransportDetails transportDetails = new PushTransportDetails(sessionCipher.getSessionVersion());
		PushMessageProtos.PushMessageContent content = PushMessageProtos.PushMessageContent.parseFrom(transportDetails.getStrippedPaddingMessageBody(paddedMessage));
		return this.createTextSecureSMPMessage(envelope, content);
	} catch (InvalidProtocolBufferException var7) {
		throw new InvalidMessageException(var7);
	}
}
 
开发者ID:Agilitum,项目名称:TextSecureSMP,代码行数:24,代码来源:TextSecureSMPCipher.java


示例5: storeRetrievedMms

import org.whispersystems.libaxolotl.DuplicateMessageException; //导入依赖的package包/类
private void storeRetrievedMms(MasterSecret masterSecret, String contentLocation,
                               long messageId, long threadId, RetrieveConf retrieved)
    throws MmsException, NoSessionException, DuplicateMessageException, InvalidMessageException,
           LegacyMessageException
{
  MmsDatabase          database = DatabaseFactory.getMmsDatabase(context);
  IncomingMediaMessage message  = new IncomingMediaMessage(retrieved);

  Pair<Long, Long> messageAndThreadId;

  if (retrieved.getSubject() != null && WirePrefix.isEncryptedMmsSubject(retrieved.getSubject().getString())) {
    database.markAsLegacyVersion(messageId, threadId);
    messageAndThreadId = new Pair<>(messageId, threadId);
  } else {
    messageAndThreadId = database.insertMessageInbox(masterSecret, message,
                                                     contentLocation, threadId);
    database.delete(messageId);
  }

  MessageNotifier.updateNotification(context, masterSecret, messageAndThreadId.second);
}
 
开发者ID:Agilitum,项目名称:TextSecureSMP,代码行数:22,代码来源:MmsDownloadJob.java


示例6: decrypt

import org.whispersystems.libaxolotl.DuplicateMessageException; //导入依赖的package包/类
public byte[] decrypt(byte[] senderKeyMessageBytes)
    throws LegacyMessageException, InvalidMessageException, DuplicateMessageException
{
  synchronized (LOCK) {
    try {
      SenderKeyRecord  record           = senderKeyStore.loadSenderKey(senderKeyId);
      SenderKeyMessage senderKeyMessage = new SenderKeyMessage(senderKeyMessageBytes);
      SenderKeyState   senderKeyState   = record.getSenderKeyState(senderKeyMessage.getKeyId());

      senderKeyMessage.verifySignature(senderKeyState.getSigningKeyPublic());

      SenderMessageKey senderKey = getSenderKey(senderKeyState, senderKeyMessage.getIteration());

      byte[] plaintext = getPlainText(senderKey.getIv(), senderKey.getCipherKey(), senderKeyMessage.getCipherText());

      senderKeyStore.storeSenderKey(senderKeyId, record);

      return plaintext;
    } catch (org.whispersystems.libaxolotl.InvalidKeyException | InvalidKeyIdException e) {
      throw new InvalidMessageException(e);
    }
  }
}
 
开发者ID:Securecom,项目名称:Securecom-Messaging,代码行数:24,代码来源:GroupCipher.java


示例7: getSenderKey

import org.whispersystems.libaxolotl.DuplicateMessageException; //导入依赖的package包/类
private SenderMessageKey getSenderKey(SenderKeyState senderKeyState, int iteration)
    throws DuplicateMessageException, InvalidMessageException
{
  SenderChainKey senderChainKey = senderKeyState.getSenderChainKey();

  if (senderChainKey.getIteration() > iteration) {
    if (senderKeyState.hasSenderMessageKey(iteration)) {
      return senderKeyState.removeSenderMessageKey(iteration);
    } else {
      throw new DuplicateMessageException("Received message with old counter: " +
                                          senderChainKey.getIteration() + " , " + iteration);
    }
  }

  if (senderChainKey.getIteration() - iteration > 2000) {
    throw new InvalidMessageException("Over 2000 messages into the future!");
  }

  while (senderChainKey.getIteration() < iteration) {
    senderKeyState.addSenderMessageKey(senderChainKey.getSenderMessageKey());
    senderChainKey = senderChainKey.getNext();
  }

  senderKeyState.setSenderChainKey(senderChainKey.getNext());
  return senderChainKey.getSenderMessageKey();
}
 
开发者ID:Securecom,项目名称:Securecom-Messaging,代码行数:27,代码来源:GroupCipher.java


示例8: retrieveAndStore

import org.whispersystems.libaxolotl.DuplicateMessageException; //导入依赖的package包/类
private void retrieveAndStore(MasterSecret masterSecret, MmsRadio radio,
                              long messageId, long threadId,
                              String contentLocation, byte[] transactionId,
                              boolean radioEnabled, boolean useProxy)
    throws IOException, MmsException, ApnUnavailableException,
           DuplicateMessageException, NoSessionException,
           InvalidMessageException, LegacyMessageException
{
  Apn                   dbApn      = MmsConnection.getApn(context, radio.getApnInformation());
  Apn                   contentApn = new Apn(contentLocation, dbApn.getProxy(), Integer.toString(dbApn.getPort()));
  IncomingMmsConnection connection = new IncomingMmsConnection(context, contentApn);
  RetrieveConf          retrieved  = connection.retrieve(radioEnabled, useProxy);

  storeRetrievedMms(masterSecret, contentLocation, messageId, threadId, retrieved);
  sendRetrievedAcknowledgement(radio, transactionId, radioEnabled, useProxy);
}
 
开发者ID:Securecom,项目名称:Securecom-Messaging,代码行数:17,代码来源:MmsDownloadJob.java


示例9: storeRetrievedMms

import org.whispersystems.libaxolotl.DuplicateMessageException; //导入依赖的package包/类
private void storeRetrievedMms(MasterSecret masterSecret, String contentLocation,
                                 long messageId, long threadId, RetrieveConf retrieved)
      throws MmsException, NoSessionException, DuplicateMessageException, InvalidMessageException,
             LegacyMessageException
  {
    MmsDatabase          database = DatabaseFactory.getMmsDatabase(context);
    IncomingMediaMessage message  = new IncomingMediaMessage(retrieved);

    Pair<Long, Long> messageAndThreadId;

    if (retrieved.getSubject() != null && WirePrefix.isEncryptedMmsSubject(retrieved.getSubject().getString())) {
      MmsCipher            mmsCipher          = new MmsCipher(new TextSecureAxolotlStore(context, masterSecret));
      MultimediaMessagePdu plaintextPdu       = mmsCipher.decrypt(context, retrieved);
      RetrieveConf         plaintextRetrieved = new RetrieveConf(plaintextPdu.getPduHeaders(), plaintextPdu.getBody());
      IncomingMediaMessage plaintextMessage   = new IncomingMediaMessage(plaintextRetrieved);

      messageAndThreadId = database.insertSecureDecryptedMessageInbox(masterSecret, plaintextMessage,
                                                                      threadId);

//      if (masterSecret != null)
//        DecryptingQueue.scheduleDecryption(context, masterSecret, messageAndThreadId.first,
//                                           messageAndThreadId.second, retrieved);

    } else {
      messageAndThreadId = database.insertMessageInbox(masterSecret, message,
                                                       contentLocation, threadId);
    }

    database.delete(messageId);
    MessageNotifier.updateNotification(context, masterSecret, messageAndThreadId.second);
  }
 
开发者ID:redcracker,项目名称:TextSecure,代码行数:32,代码来源:MmsDownloadJob.java


示例10: handleSecureMessage

import org.whispersystems.libaxolotl.DuplicateMessageException; //导入依赖的package包/类
private void handleSecureMessage(MasterSecret masterSecret, long messageId, IncomingTextMessage message)
    throws NoSessionException, DuplicateMessageException,
    InvalidMessageException, LegacyMessageException
{
  EncryptingSmsDatabase database  = DatabaseFactory.getEncryptingSmsDatabase(context);
  SmsCipher             cipher    = new SmsCipher(new TextSecureAxolotlStore(context, masterSecret));
  IncomingTextMessage   plaintext = cipher.decrypt(context, message);

  database.updateMessageBody(masterSecret, messageId, plaintext.getMessageBody());
}
 
开发者ID:redcracker,项目名称:TextSecure,代码行数:11,代码来源:SmsDecryptJob.java


示例11: testBasicSessionV2

import org.whispersystems.libaxolotl.DuplicateMessageException; //导入依赖的package包/类
public void testBasicSessionV2()
    throws InvalidKeyException, DuplicateMessageException,
    LegacyMessageException, InvalidMessageException, NoSuchAlgorithmException, NoSessionException
{
  SessionRecord aliceSessionRecord = new SessionRecord();
  SessionRecord bobSessionRecord   = new SessionRecord();

  initializeSessionsV2(aliceSessionRecord.getSessionState(), bobSessionRecord.getSessionState());
  runInteraction(aliceSessionRecord, bobSessionRecord);
}
 
开发者ID:Securecom,项目名称:Securecom-Messaging,代码行数:11,代码来源:SessionCipherTest.java


示例12: testBasicSessionV3

import org.whispersystems.libaxolotl.DuplicateMessageException; //导入依赖的package包/类
public void testBasicSessionV3()
    throws InvalidKeyException, DuplicateMessageException,
    LegacyMessageException, InvalidMessageException, NoSuchAlgorithmException, NoSessionException
{
  SessionRecord aliceSessionRecord = new SessionRecord();
  SessionRecord bobSessionRecord   = new SessionRecord();

  initializeSessionsV3(aliceSessionRecord.getSessionState(), bobSessionRecord.getSessionState());
  runInteraction(aliceSessionRecord, bobSessionRecord);
}
 
开发者ID:Securecom,项目名称:Securecom-Messaging,代码行数:11,代码来源:SessionCipherTest.java


示例13: testBasicEncryptDecrypt

import org.whispersystems.libaxolotl.DuplicateMessageException; //导入依赖的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, "groupWithBobInIt");
  GroupCipher bobGroupCipher   = new GroupCipher(bobStore, "groupWithBobInIt::aliceUserName");

  byte[]    aliceSenderKey        = KeyHelper.generateSenderKey();
  ECKeyPair aliceSenderSigningKey = KeyHelper.generateSenderSigningKey();
  int       aliceSenderKeyId      = KeyHelper.generateSenderKeyId();

  SenderKeyDistributionMessage aliceDistributionMessage =
      aliceSessionBuilder.process("groupWithBobInIt", aliceSenderKeyId, 0,
                                  aliceSenderKey, aliceSenderSigningKey);

  bobSessionBuilder.process("groupWithBobInIt::aliceUserName", aliceDistributionMessage);

  byte[] ciphertextFromAlice = aliceGroupCipher.encrypt("smert ze smert".getBytes());
  byte[] plaintextFromAlice  = bobGroupCipher.decrypt(ciphertextFromAlice);

  assertTrue(new String(plaintextFromAlice).equals("smert ze smert"));
}
 
开发者ID:Securecom,项目名称:Securecom-Messaging,代码行数:28,代码来源:GroupCipherTest.java


示例14: testOutOfOrder

import org.whispersystems.libaxolotl.DuplicateMessageException; //导入依赖的package包/类
public void testOutOfOrder()
    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, "groupWithBobInIt");
  GroupCipher bobGroupCipher   = new GroupCipher(bobStore, "groupWithBobInIt::aliceUserName");

  byte[]    aliceSenderKey        = KeyHelper.generateSenderKey();
  ECKeyPair aliceSenderSigningKey = KeyHelper.generateSenderSigningKey();
  int       aliceSenderKeyId      = KeyHelper.generateSenderKeyId();

  SenderKeyDistributionMessage aliceDistributionMessage =
      aliceSessionBuilder.process("groupWithBobInIt", aliceSenderKeyId, 0,
                                  aliceSenderKey, aliceSenderSigningKey);

  bobSessionBuilder.process("groupWithBobInIt::aliceUserName", aliceDistributionMessage);


  ArrayList<byte[]> ciphertexts = new ArrayList<>(100);

  for (int i=0;i<100;i++) {
    ciphertexts.add(aliceGroupCipher.encrypt("up the punks".getBytes()));
  }

  while (ciphertexts.size() > 0) {
    int    index      = randomInt() % ciphertexts.size();
    byte[] ciphertext = ciphertexts.remove(index);
    byte[] plaintext  = bobGroupCipher.decrypt(ciphertext);

    assertTrue(new String(plaintext).equals("up the punks"));
  }
}
 
开发者ID:Securecom,项目名称:Securecom-Messaging,代码行数:38,代码来源:GroupCipherTest.java


示例15: testSimultaneousKeyExchange

import org.whispersystems.libaxolotl.DuplicateMessageException; //导入依赖的package包/类
public void testSimultaneousKeyExchange()
    throws InvalidKeyException, DuplicateMessageException, LegacyMessageException, InvalidMessageException, UntrustedIdentityException, StaleKeyExchangeException, NoSessionException {
  AxolotlStore   aliceStore          = new InMemoryAxolotlStore();
  SessionBuilder aliceSessionBuilder = new SessionBuilder(aliceStore, BOB_RECIPIENT_ID, 1);

  AxolotlStore   bobStore          = new InMemoryAxolotlStore();
  SessionBuilder bobSessionBuilder = new SessionBuilder(bobStore, ALICE_RECIPIENT_ID, 1);

  KeyExchangeMessage aliceKeyExchange = aliceSessionBuilder.process();
  KeyExchangeMessage bobKeyExchange   = bobSessionBuilder.process();

  assertTrue(aliceKeyExchange != null);
  assertTrue(bobKeyExchange != null);

  KeyExchangeMessage aliceResponse = aliceSessionBuilder.process(bobKeyExchange);
  KeyExchangeMessage bobResponse   = bobSessionBuilder.process(aliceKeyExchange);

  assertTrue(aliceResponse != null);
  assertTrue(bobResponse != null);

  KeyExchangeMessage aliceAck = aliceSessionBuilder.process(bobResponse);
  KeyExchangeMessage bobAck   = bobSessionBuilder.process(aliceResponse);

  assertTrue(aliceAck == null);
  assertTrue(bobAck == null);

  runInteraction(aliceStore, bobStore);
}
 
开发者ID:Securecom,项目名称:Securecom-Messaging,代码行数:29,代码来源:SessionBuilderTest.java


示例16: start

import org.whispersystems.libaxolotl.DuplicateMessageException; //导入依赖的package包/类
/**
 * Starts the Decrypter. It will automatically decrypt messages from the
 * queue and fire a {@link MessageReceivedEvent} after decrypting each one.
 */
synchronized public static void start() {
	if (thread != null && thread.isAlive()) {
		throw new IllegalStateException("MessageDecrypter is already running!");
	}

	task = new Task<Void>() {
		@Override
		protected Void call() {
			while (!isCancelled()) {
				TextSecureEnvelope envelope = null;
				try {
					envelope = queue.take();
					final TextSecureCipher cipher = new TextSecureCipher(envelope.getSourceAddress(),
							AxolotlStore.getInstance());
					final TextSecureContent content = cipher.decrypt(envelope);

					if (content.getDataMessage().isPresent()) {
						final TextSecureDataMessage message = content.getDataMessage().get();

						if (message.isEndSession()) {
							handleEndSessionMessage(envelope, message);
						} else if (message.isGroupUpdate()) {
							handleGroupMessage(envelope, message);
						} else if (message.getAttachments().isPresent()) {
							handleMediaMessage(envelope, message);
						} else {
							handleTextMessage(envelope, message);
						}
					} else {
						handleSyncMessage(content.getSyncMessage().get());
					}
				} catch (final InterruptedException e) {
					continue;
				} catch (InvalidVersionException | InvalidMessageException | InvalidKeyException
						| DuplicateMessageException | InvalidKeyIdException | NoSessionException
						| LegacyMessageException e) {
					handleInvalidMessage(envelope);
				} catch (final UntrustedIdentityException e) {
					handleUntrustedMessage(envelope);
				}
			}
			return null;
		}

	};
	thread = new Thread(task);
	thread.start();
}
 
开发者ID:connorlanigan,项目名称:norvos,代码行数:53,代码来源:MessageDecrypter.java


示例17: testBasicRatchet

import org.whispersystems.libaxolotl.DuplicateMessageException; //导入依赖的package包/类
public void testBasicRatchet()
    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, "groupWithBobInIt");
  GroupCipher bobGroupCipher   = new GroupCipher(bobStore, "groupWithBobInIt::aliceUserName");

  byte[]    aliceSenderKey        = KeyHelper.generateSenderKey();
  ECKeyPair aliceSenderSigningKey = KeyHelper.generateSenderSigningKey();
  int       aliceSenderKeyId      = KeyHelper.generateSenderKeyId();

  SenderKeyDistributionMessage aliceDistributionMessage =
      aliceSessionBuilder.process("groupWithBobInIt", aliceSenderKeyId, 0,
                                  aliceSenderKey, aliceSenderSigningKey);

  bobSessionBuilder.process("groupWithBobInIt::aliceUserName", aliceDistributionMessage);

  byte[] ciphertextFromAlice  = aliceGroupCipher.encrypt("smert ze smert".getBytes());
  byte[] ciphertextFromAlice2 = aliceGroupCipher.encrypt("smert ze smert2".getBytes());
  byte[] ciphertextFromAlice3 = aliceGroupCipher.encrypt("smert ze smert3".getBytes());

  byte[] plaintextFromAlice   = bobGroupCipher.decrypt(ciphertextFromAlice);

  try {
    bobGroupCipher.decrypt(ciphertextFromAlice);
    throw new AssertionError("Should have ratcheted forward!");
  } catch (DuplicateMessageException dme) {
    // good
  }

  byte[] plaintextFromAlice2  = bobGroupCipher.decrypt(ciphertextFromAlice2);
  byte[] plaintextFromAlice3  = bobGroupCipher.decrypt(ciphertextFromAlice3);

  assertTrue(new String(plaintextFromAlice).equals("smert ze smert"));
  assertTrue(new String(plaintextFromAlice2).equals("smert ze smert2"));
  assertTrue(new String(plaintextFromAlice3).equals("smert ze smert3"));
}
 
开发者ID:Securecom,项目名称:Securecom-Messaging,代码行数:43,代码来源:GroupCipherTest.java


示例18: testRepeatBundleMessageV3

import org.whispersystems.libaxolotl.DuplicateMessageException; //导入依赖的package包/类
public void testRepeatBundleMessageV3() throws InvalidKeyException, UntrustedIdentityException, InvalidVersionException, InvalidMessageException, InvalidKeyIdException, DuplicateMessageException, LegacyMessageException, NoSessionException {
  AxolotlStore   aliceStore          = new InMemoryAxolotlStore();
  SessionBuilder aliceSessionBuilder = new SessionBuilder(aliceStore, BOB_RECIPIENT_ID, 1);

  AxolotlStore bobStore = new InMemoryAxolotlStore();

  ECKeyPair bobPreKeyPair            = Curve.generateKeyPair();
  ECKeyPair bobSignedPreKeyPair      = Curve.generateKeyPair();
  byte[]    bobSignedPreKeySignature = Curve.calculateSignature(bobStore.getIdentityKeyPair().getPrivateKey(),
                                                                bobSignedPreKeyPair.getPublicKey().serialize());

  PreKeyBundle bobPreKey = new PreKeyBundle(bobStore.getLocalRegistrationId(), 1,
                                            31337, bobPreKeyPair.getPublicKey(),
                                            22, bobSignedPreKeyPair.getPublicKey(), bobSignedPreKeySignature,
                                            bobStore.getIdentityKeyPair().getPublicKey());

  bobStore.storePreKey(31337, new PreKeyRecord(bobPreKey.getPreKeyId(), bobPreKeyPair));
  bobStore.storeSignedPreKey(22, new SignedPreKeyRecord(22, System.currentTimeMillis(), bobSignedPreKeyPair, bobSignedPreKeySignature));

  aliceSessionBuilder.process(bobPreKey);

  String            originalMessage    = "L'homme est condamné à être libre";
  SessionCipher     aliceSessionCipher = new SessionCipher(aliceStore, BOB_RECIPIENT_ID, 1);
  CiphertextMessage outgoingMessageOne = aliceSessionCipher.encrypt(originalMessage.getBytes());
  CiphertextMessage outgoingMessageTwo = aliceSessionCipher.encrypt(originalMessage.getBytes());

  assertTrue(outgoingMessageOne.getType() == CiphertextMessage.PREKEY_TYPE);
  assertTrue(outgoingMessageTwo.getType() == CiphertextMessage.PREKEY_TYPE);

  PreKeyWhisperMessage incomingMessage = new PreKeyWhisperMessage(outgoingMessageOne.serialize());

  SessionCipher bobSessionCipher = new SessionCipher(bobStore, ALICE_RECIPIENT_ID, 1);

  byte[]        plaintext        = bobSessionCipher.decrypt(incomingMessage);
  assertTrue(originalMessage.equals(new String(plaintext)));

  CiphertextMessage bobOutgoingMessage = bobSessionCipher.encrypt(originalMessage.getBytes());

  byte[] alicePlaintext = aliceSessionCipher.decrypt(new WhisperMessage(bobOutgoingMessage.serialize()));
  assertTrue(originalMessage.equals(new String(alicePlaintext)));

  // The test

  PreKeyWhisperMessage incomingMessageTwo = new PreKeyWhisperMessage(outgoingMessageTwo.serialize());

  plaintext = bobSessionCipher.decrypt(new PreKeyWhisperMessage(incomingMessageTwo.serialize()));
  assertTrue(originalMessage.equals(new String(plaintext)));

  bobOutgoingMessage = bobSessionCipher.encrypt(originalMessage.getBytes());
  alicePlaintext = aliceSessionCipher.decrypt(new WhisperMessage(bobOutgoingMessage.serialize()));
  assertTrue(originalMessage.equals(new String(alicePlaintext)));

}
 
开发者ID:Securecom,项目名称:Securecom-Messaging,代码行数:54,代码来源:SessionBuilderTest.java


示例19: testBadMessageBundle

import org.whispersystems.libaxolotl.DuplicateMessageException; //导入依赖的package包/类
public void testBadMessageBundle() throws InvalidKeyException, UntrustedIdentityException, InvalidVersionException, InvalidMessageException, DuplicateMessageException, LegacyMessageException, InvalidKeyIdException {
  AxolotlStore   aliceStore          = new InMemoryAxolotlStore();
  SessionBuilder aliceSessionBuilder = new SessionBuilder(aliceStore, BOB_RECIPIENT_ID, 1);

  AxolotlStore bobStore = new InMemoryAxolotlStore();

  ECKeyPair bobPreKeyPair            = Curve.generateKeyPair();
  ECKeyPair bobSignedPreKeyPair      = Curve.generateKeyPair();
  byte[]    bobSignedPreKeySignature = Curve.calculateSignature(bobStore.getIdentityKeyPair().getPrivateKey(),
                                                                bobSignedPreKeyPair.getPublicKey().serialize());

  PreKeyBundle bobPreKey = new PreKeyBundle(bobStore.getLocalRegistrationId(), 1,
                                            31337, bobPreKeyPair.getPublicKey(),
                                            22, bobSignedPreKeyPair.getPublicKey(), bobSignedPreKeySignature,
                                            bobStore.getIdentityKeyPair().getPublicKey());

  bobStore.storePreKey(31337, new PreKeyRecord(bobPreKey.getPreKeyId(), bobPreKeyPair));
  bobStore.storeSignedPreKey(22, new SignedPreKeyRecord(22, System.currentTimeMillis(), bobSignedPreKeyPair, bobSignedPreKeySignature));

  aliceSessionBuilder.process(bobPreKey);

  String            originalMessage    = "L'homme est condamné à être libre";
  SessionCipher     aliceSessionCipher = new SessionCipher(aliceStore, BOB_RECIPIENT_ID, 1);
  CiphertextMessage outgoingMessageOne = aliceSessionCipher.encrypt(originalMessage.getBytes());

  assertTrue(outgoingMessageOne.getType() == CiphertextMessage.PREKEY_TYPE);

  byte[] goodMessage = outgoingMessageOne.serialize();
  byte[] badMessage  = new byte[goodMessage.length];
  System.arraycopy(goodMessage, 0, badMessage, 0, badMessage.length);

  badMessage[badMessage.length-10] ^= 0x01;

  PreKeyWhisperMessage incomingMessage  = new PreKeyWhisperMessage(badMessage);
  SessionCipher        bobSessionCipher = new SessionCipher(bobStore, ALICE_RECIPIENT_ID, 1);

  byte[] plaintext = new byte[0];

  try {
    plaintext = bobSessionCipher.decrypt(incomingMessage);
    throw new AssertionError("Decrypt should have failed!");
  } catch (InvalidMessageException e) {
    // good.
  }

  assertTrue(bobStore.containsPreKey(31337));

  plaintext = bobSessionCipher.decrypt(new PreKeyWhisperMessage(goodMessage));

  assertTrue(originalMessage.equals(new String(plaintext)));
  assertTrue(!bobStore.containsPreKey(31337));
}
 
开发者ID:Securecom,项目名称:Securecom-Messaging,代码行数:53,代码来源:SessionBuilderTest.java


示例20: testSimultaneousInitiateLostMessage

import org.whispersystems.libaxolotl.DuplicateMessageException; //导入依赖的package包/类
public void testSimultaneousInitiateLostMessage()
      throws InvalidKeyException, UntrustedIdentityException, InvalidVersionException,
      InvalidMessageException, DuplicateMessageException, LegacyMessageException,
      InvalidKeyIdException, NoSessionException
  {
    AxolotlStore aliceStore = new InMemoryAxolotlStore();
    AxolotlStore bobStore   = new InMemoryAxolotlStore();

    PreKeyBundle alicePreKeyBundle = createAlicePreKeyBundle(aliceStore);
    PreKeyBundle bobPreKeyBundle = createBobPreKeyBundle(bobStore);

    SessionBuilder aliceSessionBuilder = new SessionBuilder(aliceStore, BOB_RECIPENT_ID, 1);
    SessionBuilder bobSessionBuilder   = new SessionBuilder(bobStore, ALICE_RECIPIENT_ID, 1);

    SessionCipher aliceSessionCipher = new SessionCipher(aliceStore, BOB_RECIPENT_ID, 1);
    SessionCipher bobSessionCipher = new SessionCipher(bobStore, ALICE_RECIPIENT_ID, 1);

    aliceSessionBuilder.process(bobPreKeyBundle);
    bobSessionBuilder.process(alicePreKeyBundle);

    CiphertextMessage messageForBob   = aliceSessionCipher.encrypt("hey there".getBytes());
    CiphertextMessage messageForAlice = bobSessionCipher.encrypt("sample message".getBytes());

    assertTrue(messageForBob.getType() == CiphertextMessage.PREKEY_TYPE);
    assertTrue(messageForAlice.getType() == CiphertextMessage.PREKEY_TYPE);

    assertFalse(isSessionIdEqual(aliceStore, bobStore));

    byte[] alicePlaintext = aliceSessionCipher.decrypt(new PreKeyWhisperMessage(messageForAlice.serialize()));
    byte[] bobPlaintext   = bobSessionCipher.decrypt(new PreKeyWhisperMessage(messageForBob.serialize()));

    assertTrue(new String(alicePlaintext).equals("sample message"));
    assertTrue(new String(bobPlaintext).equals("hey there"));

    assertTrue(aliceStore.loadSession(BOB_RECIPENT_ID, 1).getSessionState().getSessionVersion() == 3);
    assertTrue(bobStore.loadSession(ALICE_RECIPIENT_ID, 1).getSessionState().getSessionVersion() == 3);

    assertFalse(isSessionIdEqual(aliceStore, bobStore));

    CiphertextMessage aliceResponse = aliceSessionCipher.encrypt("second message".getBytes());

    assertTrue(aliceResponse.getType() == CiphertextMessage.WHISPER_TYPE);

//    byte[] responsePlaintext = bobSessionCipher.decrypt(new WhisperMessage(aliceResponse.serialize()));
//
//    assertTrue(new String(responsePlaintext).equals("second message"));
//    assertTrue(isSessionIdEqual(aliceStore, bobStore));
    assertFalse(isSessionIdEqual(aliceStore, bobStore));

    CiphertextMessage finalMessage = bobSessionCipher.encrypt("third message".getBytes());

    assertTrue(finalMessage.getType() == CiphertextMessage.WHISPER_TYPE);

    byte[] finalPlaintext = aliceSessionCipher.decrypt(new WhisperMessage(finalMessage.serialize()));

    assertTrue(new String(finalPlaintext).equals("third message"));
    assertTrue(isSessionIdEqual(aliceStore, bobStore));
  }
 
开发者ID:Securecom,项目名称:Securecom-Messaging,代码行数:59,代码来源:SimultaneousInitiateTests.java



注:本文中的org.whispersystems.libaxolotl.DuplicateMessageException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java PartitionNode类代码示例发布时间:2022-05-23
下一篇:
Java OptimizedErode类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap