当前位置: 首页>>代码示例>>Java>>正文


Java NoSessionException类代码示例

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


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

示例1: decrypt

import org.whispersystems.libsignal.NoSessionException; //导入依赖的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);
}
 
开发者ID:XecureIT,项目名称:PeSanKita-lib,代码行数:22,代码来源:SignalServiceCipher.java

示例2: tryFetchLatestMessage

import org.whispersystems.libsignal.NoSessionException; //导入依赖的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;
}
 
开发者ID:toshiapp,项目名称:toshi-android-client,代码行数:17,代码来源:SofaMessageReceiver.java

示例3: handleIncomingSofaMessage

import org.whispersystems.libsignal.NoSessionException; //导入依赖的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;
}
 
开发者ID:toshiapp,项目名称:toshi-android-client,代码行数:19,代码来源:SofaMessageReceiver.java

示例4: decrypt

import org.whispersystems.libsignal.NoSessionException; //导入依赖的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);
  }
}
 
开发者ID:SilenceIM,项目名称:Silence,代码行数:21,代码来源:SmsCipher.java

示例5: encrypt

import org.whispersystems.libsignal.NoSessionException; //导入依赖的package包/类
public OutgoingTextMessage encrypt(OutgoingTextMessage message) throws NoSessionException {
  byte[] paddedBody      = transportDetails.getPaddedMessageBody(message.getMessageBody().getBytes());
  String recipientNumber = message.getRecipients().getPrimaryRecipient().getNumber();

  if (!signalProtocolStore.containsSession(new SignalProtocolAddress(recipientNumber, 1))) {
    throw new NoSessionException("No session for: " + recipientNumber);
  }

  SessionCipher     cipher            = new SessionCipher(signalProtocolStore, new SignalProtocolAddress(recipientNumber, 1));
  CiphertextMessage ciphertextMessage = cipher.encrypt(paddedBody);
  String            encodedCiphertext = new String(transportDetails.getEncodedMessage(ciphertextMessage.serialize()));

  if (ciphertextMessage.getType() == CiphertextMessage.PREKEY_TYPE) {
    return new OutgoingPrekeyBundleMessage(message, encodedCiphertext);
  } else {
    return message.withBody(encodedCiphertext);
  }
}
 
开发者ID:SilenceIM,项目名称:Silence,代码行数:19,代码来源:SmsCipher.java

示例6: encrypt

import org.whispersystems.libsignal.NoSessionException; //导入依赖的package包/类
/**
 * Encrypt a message.
 *
 * @param paddedPlaintext The plaintext message bytes, optionally padded.
 * @return Ciphertext.
 * @throws NoSessionException
 */
public byte[] encrypt(byte[] paddedPlaintext) throws NoSessionException {
  synchronized (LOCK) {
    try {
      SenderKeyRecord  record         = senderKeyStore.loadSenderKey(senderKeyId);
      SenderKeyState   senderKeyState = record.getSenderKeyState();
      SenderMessageKey senderKey      = senderKeyState.getSenderChainKey().getSenderMessageKey();
      byte[]           ciphertext     = getCipherText(senderKey.getIv(), senderKey.getCipherKey(), paddedPlaintext);

      SenderKeyMessage senderKeyMessage = new SenderKeyMessage(senderKeyState.getKeyId(),
                                                               senderKey.getIteration(),
                                                               ciphertext,
                                                               senderKeyState.getSigningKeyPrivate());

      senderKeyState.setSenderChainKey(senderKeyState.getSenderChainKey().getNext());

      senderKeyStore.storeSenderKey(senderKeyId, record);

      return senderKeyMessage.serialize();
    } catch (InvalidKeyIdException e) {
      throw new NoSessionException(e);
    }
  }
}
 
开发者ID:signalapp,项目名称:libsignal-protocol-java,代码行数:31,代码来源:GroupCipher.java

示例7: testNoSession

import org.whispersystems.libsignal.NoSessionException; //导入依赖的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
    }
  }
 
开发者ID:signalapp,项目名称:libsignal-protocol-java,代码行数:24,代码来源:GroupCipherTest.java

示例8: testBasicEncryptDecrypt

import org.whispersystems.libsignal.NoSessionException; //导入依赖的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"));
}
 
开发者ID:signalapp,项目名称:libsignal-protocol-java,代码行数:22,代码来源:GroupCipherTest.java

示例9: testLargeMessages

import org.whispersystems.libsignal.NoSessionException; //导入依赖的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));
}
 
开发者ID:signalapp,项目名称:libsignal-protocol-java,代码行数:23,代码来源:GroupCipherTest.java

示例10: decryptIncomingSignalServiceEnvelope

import org.whispersystems.libsignal.NoSessionException; //导入依赖的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);
   }
 
开发者ID:toshiapp,项目名称:toshi-android-client,代码行数:10,代码来源:SofaMessageReceiver.java

示例11: encrypt

import org.whispersystems.libsignal.NoSessionException; //导入依赖的package包/类
public SendReq encrypt(Context context, SendReq message)
    throws NoSessionException, RecipientFormattingException, UndeliverableMessageException
{
  EncodedStringValue[] encodedRecipient = message.getTo();
  String               recipientString  = encodedRecipient[0].getString();
  byte[]               pduBytes         = new PduComposer(context, message).make();

  if (pduBytes == null) {
    throw new UndeliverableMessageException("PDU composition failed, null payload");
  }

  if (!axolotlStore.containsSession(new SignalProtocolAddress(recipientString, 1))) {
    throw new NoSessionException("No session for: " + recipientString);
  }

  SessionCipher     cipher            = new SessionCipher(axolotlStore, new SignalProtocolAddress(recipientString, 1));
  CiphertextMessage ciphertextMessage = cipher.encrypt(pduBytes);
  byte[]            encryptedPduBytes = textTransport.getEncodedMessage(ciphertextMessage.serialize());

  PduBody body         = new PduBody();
  PduPart part         = new PduPart();
  SendReq encryptedPdu = new SendReq(message.getPduHeaders(), body);

  part.setContentId((System.currentTimeMillis()+"").getBytes());
  part.setContentType(ContentType.TEXT_PLAIN.getBytes());
  part.setName((System.currentTimeMillis()+"").getBytes());
  part.setData(encryptedPduBytes);
  body.addPart(part);
  encryptedPdu.setSubject(new EncodedStringValue(WirePrefix.calculateEncryptedMmsSubject()));
  encryptedPdu.setBody(body);

  return encryptedPdu;
}
 
开发者ID:SilenceIM,项目名称:Silence,代码行数:34,代码来源:MmsCipher.java

示例12: getAsymmetricEncrypt

import org.whispersystems.libsignal.NoSessionException; //导入依赖的package包/类
private OutgoingTextMessage getAsymmetricEncrypt(MasterSecret masterSecret,
                                                 OutgoingTextMessage message)
    throws UndeliverableMessageException
{
  try {
    return new SmsCipher(new SilenceSignalProtocolStore(context, masterSecret)).encrypt(message);
  } catch (NoSessionException e) {
    throw new UndeliverableMessageException(e);
  }
}
 
开发者ID:SilenceIM,项目名称:Silence,代码行数:11,代码来源:SmsSendJob.java

示例13: handleSecureMessage

import org.whispersystems.libsignal.NoSessionException; //导入依赖的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);
}
 
开发者ID:SilenceIM,项目名称:Silence,代码行数:14,代码来源:SmsDecryptJob.java

示例14: handleXmppExchangeMessage

import org.whispersystems.libsignal.NoSessionException; //导入依赖的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);
}
 
开发者ID:SilenceIM,项目名称:Silence,代码行数:8,代码来源:SmsDecryptJob.java

示例15: processReceiving

import org.whispersystems.libsignal.NoSessionException; //导入依赖的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;
}
 
开发者ID:siacs,项目名称:Conversations,代码行数:39,代码来源:XmppAxolotlSession.java


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