本文整理汇总了Java中org.whispersystems.libaxolotl.InvalidVersionException类的典型用法代码示例。如果您正苦于以下问题:Java InvalidVersionException类的具体用法?Java InvalidVersionException怎么用?Java InvalidVersionException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
InvalidVersionException类属于org.whispersystems.libaxolotl包,在下文中一共展示了InvalidVersionException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initializeKey
import org.whispersystems.libaxolotl.InvalidVersionException; //导入依赖的package包/类
private void initializeKey()
throws InvalidKeyException, InvalidVersionException,
InvalidMessageException, LegacyMessageException
{
IncomingTextMessage message = new IncomingTextMessage(recipient.getNumber(),
recipientDeviceId,
System.currentTimeMillis(),
getIntent().getStringExtra("body"),
Optional.<TextSecureGroup>absent());
if (getIntent().getBooleanExtra("is_bundle", false)) {
this.message = new IncomingPreKeyBundleMessage(message, message.getMessageBody());
} else if (getIntent().getBooleanExtra("is_identity_update", false)) {
this.message = new IncomingIdentityUpdateMessage(message, message.getMessageBody());
} else {
this.message = new IncomingKeyExchangeMessage(message, message.getMessageBody());
}
this.identityKey = getIdentityKey(this.message);
}
示例2: getIdentityKey
import org.whispersystems.libaxolotl.InvalidVersionException; //导入依赖的package包/类
private 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()) {
boolean isPush = getIntent().getBooleanExtra("is_push", false);
if (isPush) return new PreKeyWhisperMessage(Base64.decode(message.getMessageBody())).getIdentityKey();
else return new PreKeyWhisperMessage(Base64.decodeWithoutPadding(message.getMessageBody())).getIdentityKey();
} else {
return new KeyExchangeMessage(Base64.decodeWithoutPadding(message.getMessageBody())).getIdentityKey();
}
} catch (IOException e) {
throw new AssertionError(e);
}
}
示例3: decrypt
import org.whispersystems.libaxolotl.InvalidVersionException; //导入依赖的package包/类
public IncomingEncryptedMessage decrypt(Context context, IncomingPreKeyBundleMessage message)
throws InvalidVersionException, InvalidMessageException, DuplicateMessageException,
UntrustedIdentityException, LegacyMessageException
{
try {
Recipients recipients = RecipientFactory.getRecipientsFromString(context, message.getSender(), false);
byte[] decoded = transportDetails.getDecodedMessage(message.getMessageBody().getBytes());
PreKeyWhisperMessage preKeyMessage = new PreKeyWhisperMessage(decoded);
SessionCipher sessionCipher = new SessionCipher(axolotlStore, recipients.getPrimaryRecipient().getRecipientId(), 1);
byte[] padded = sessionCipher.decrypt(preKeyMessage);
byte[] plaintext = transportDetails.getStrippedPaddingMessageBody(padded);
return new IncomingEncryptedMessage(message, new String(plaintext));
} catch (RecipientFormattingException | IOException | InvalidKeyException | InvalidKeyIdException e) {
throw new InvalidMessageException(e);
}
}
示例4: process
import org.whispersystems.libaxolotl.InvalidVersionException; //导入依赖的package包/类
public OutgoingKeyExchangeMessage process(Context context, IncomingKeyExchangeMessage message)
throws UntrustedIdentityException, StaleKeyExchangeException,
InvalidVersionException, LegacyMessageException, InvalidMessageException
{
try {
Recipient recipient = RecipientFactory.getRecipientsFromString(context, message.getSender(), false).getPrimaryRecipient();
KeyExchangeMessage exchangeMessage = new KeyExchangeMessage(transportDetails.getDecodedMessage(message.getMessageBody().getBytes()));
SessionBuilder sessionBuilder = new SessionBuilder(axolotlStore, recipient.getRecipientId(), 1);
KeyExchangeMessage response = sessionBuilder.process(exchangeMessage);
if (response != null) {
byte[] serializedResponse = transportDetails.getEncodedMessage(response.serialize());
return new OutgoingKeyExchangeMessage(recipient, new String(serializedResponse));
} else {
return null;
}
} catch (RecipientFormattingException | IOException | InvalidKeyException e) {
throw new InvalidMessageException(e);
}
}
示例5: onRun
import org.whispersystems.libaxolotl.InvalidVersionException; //导入依赖的package包/类
@Override
public void onRun() {
try {
String sessionKey = TextSecurePreferences.getSignalingKey(context);
TextSecureEnvelope envelope = new TextSecureEnvelope(data, sessionKey);
if (!isActiveNumber(context, envelope.getSource())) {
TextSecureDirectory directory = TextSecureDirectory.getInstance(context);
ContactTokenDetails contactTokenDetails = new ContactTokenDetails();
contactTokenDetails.setNumber(envelope.getSource());
directory.setNumber(contactTokenDetails, true);
}
if (envelope.isReceipt()) handleReceipt(envelope);
else handleMessage(envelope);
} catch (IOException | InvalidVersionException e) {
Log.w(TAG, e);
}
}
示例6: decrypt
import org.whispersystems.libaxolotl.InvalidVersionException; //导入依赖的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);
}
}
示例7: decrypt
import org.whispersystems.libaxolotl.InvalidVersionException; //导入依赖的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);
}
}
示例8: onCreate
import org.whispersystems.libaxolotl.InvalidVersionException; //导入依赖的package包/类
@Override
protected void onCreate(Bundle state) {
super.onCreate(state);
setContentView(R.layout.receive_key_activity);
initializeResources();
try {
initializeKey();
initializeText();
} catch (InvalidKeyException | InvalidVersionException | InvalidMessageException | LegacyMessageException ike) {
Log.w("ReceiveKeyActivity", ike);
}
initializeListeners();
}
示例9: TextSecureEnvelope
import org.whispersystems.libaxolotl.InvalidVersionException; //导入依赖的package包/类
public TextSecureEnvelope(String message, String signalingKey)
throws IOException, InvalidVersionException
{
byte[] ciphertext = Base64.decode(message);
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.signal = IncomingPushMessageSignal.parseFrom(getPlaintext(ciphertext, cipherKey));
}
示例10: handleUntrustedIdentityMessage
import org.whispersystems.libaxolotl.InvalidVersionException; //导入依赖的package包/类
private void handleUntrustedIdentityMessage(MasterSecret masterSecret, TextSecureEnvelope envelope, Optional<Long> smsMessageId) {
try {
EncryptingSmsDatabase database = DatabaseFactory.getEncryptingSmsDatabase(context);
Recipients recipients = RecipientFactory.getRecipientsFromString(context, envelope.getSource(), false);
long recipientId = recipients.getPrimaryRecipient().getRecipientId();
PreKeyWhisperMessage whisperMessage = new PreKeyWhisperMessage(envelope.getMessage());
IdentityKey identityKey = whisperMessage.getIdentityKey();
String encoded = Base64.encodeBytes(envelope.getMessage());
IncomingTextMessage textMessage = new IncomingTextMessage(envelope.getSource(), envelope.getSourceDevice(),
envelope.getTimestamp(), encoded,
Optional.<TextSecureGroup>absent());
if (!smsMessageId.isPresent()) {
IncomingPreKeyBundleMessage bundleMessage = new IncomingPreKeyBundleMessage(textMessage, encoded);
Pair<Long, Long> messageAndThreadId = database.insertMessageInbox(masterSecret, bundleMessage);
database.setMismatchedIdentity(messageAndThreadId.first, recipientId, identityKey);
MessageNotifier.updateNotification(context, masterSecret, messageAndThreadId.second);
} 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.libaxolotl.InvalidVersionException; //导入依赖的package包/类
@Override
public void onRun() {
try {
String sessionKey = TextSecurePreferences.getSignalingKey(context);
TextSecureEnvelope envelope = new TextSecureEnvelope(data, sessionKey);
handle(envelope, true);
} catch (IOException | InvalidVersionException e) {
Log.w(TAG, e);
}
}
示例12: KeyExchangeMessage
import org.whispersystems.libaxolotl.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.UNSUPPORTED_VERSION) {
throw new LegacyMessageException("Unsupported legacy version: " + this.version);
}
if (this.version > CiphertextMessage.CURRENT_VERSION) {
throw new InvalidVersionException("Unknown version: " + this.version);
}
WhisperProtos.KeyExchangeMessage message = WhisperProtos.KeyExchangeMessage.parseFrom(parts[1]);
if (!message.hasId() || !message.hasBaseKey() ||
!message.hasRatchetKey() || !message.hasIdentityKey() ||
(this.version >=3 && !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);
}
}
示例13: PreKeyWhisperMessage
import org.whispersystems.libaxolotl.InvalidVersionException; //导入依赖的package包/类
public PreKeyWhisperMessage(byte[] serialized)
throws InvalidMessageException, InvalidVersionException
{
try {
this.version = ByteUtil.highBitsToInt(serialized[0]);
if (this.version > CiphertextMessage.CURRENT_VERSION) {
throw new InvalidVersionException("Unknown version: " + this.version);
}
WhisperProtos.PreKeyWhisperMessage preKeyWhisperMessage
= WhisperProtos.PreKeyWhisperMessage.parseFrom(ByteString.copyFrom(serialized, 1,
serialized.length-1));
if ((version == 2 && !preKeyWhisperMessage.hasPreKeyId()) ||
(version == 3 && !preKeyWhisperMessage.hasSignedPreKeyId()) ||
!preKeyWhisperMessage.hasBaseKey() ||
!preKeyWhisperMessage.hasIdentityKey() ||
!preKeyWhisperMessage.hasMessage())
{
throw new InvalidMessageException("Incomplete message.");
}
this.serialized = serialized;
this.registrationId = preKeyWhisperMessage.getRegistrationId();
this.preKeyId = preKeyWhisperMessage.hasPreKeyId() ? Optional.of(preKeyWhisperMessage.getPreKeyId()) : Optional.<Integer>absent();
this.signedPreKeyId = preKeyWhisperMessage.hasSignedPreKeyId() ? preKeyWhisperMessage.getSignedPreKeyId() : -1;
this.baseKey = Curve.decodePoint(preKeyWhisperMessage.getBaseKey().toByteArray(), 0);
this.identityKey = new IdentityKey(Curve.decodePoint(preKeyWhisperMessage.getIdentityKey().toByteArray(), 0));
this.message = new WhisperMessage(preKeyWhisperMessage.getMessage().toByteArray());
} catch (InvalidProtocolBufferException | InvalidKeyException | LegacyMessageException e) {
throw new InvalidMessageException(e);
}
}
示例14: start
import org.whispersystems.libaxolotl.InvalidVersionException; //导入依赖的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();
}
示例15: testRepeatBundleMessageV3
import org.whispersystems.libaxolotl.InvalidVersionException; //导入依赖的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)));
}