Java Code Examples for org.whispersystems.libsignal.protocol.CiphertextMessage#getType()
The following examples show how to use
org.whispersystems.libsignal.protocol.CiphertextMessage#getType() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SignalServiceCipher.java From bcm-android with GNU General Public License v3.0 | 6 votes |
public OutgoingPushMessage encrypt(SignalProtocolAddress destination, byte[] unpaddedMessage, PushPurpose pushPurpose) throws UntrustedIdentityException { SessionCipher sessionCipher = new SessionCipher(signalProtocolStore, destination); PushTransportDetails transportDetails = new PushTransportDetails(sessionCipher.getSessionVersion()); CiphertextMessage message = sessionCipher.encrypt(transportDetails.getPaddedMessageBody(unpaddedMessage)); int remoteRegistrationId = sessionCipher.getRemoteRegistrationId(); String body = Base64.encodeBytes(message.serialize()); int type; switch (message.getType()) { case CiphertextMessage.PREKEY_TYPE: type = Type.PREKEY_BUNDLE_VALUE; break; case CiphertextMessage.WHISPER_TYPE: type = Type.CIPHERTEXT_VALUE; break; default: throw new AssertionError("Bad type: " + message.getType()); } return new OutgoingPushMessage(type, destination.getDeviceId(), remoteRegistrationId, body, pushPurpose); }
Example 2
Source File: SmsCipher.java From Silence with GNU General Public License v3.0 | 6 votes |
public OutgoingTextMessage encrypt(OutgoingTextMessage message) throws NoSessionException, UntrustedIdentityException { 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); } }
Example 3
Source File: XmppAxolotlSession.java From Pix-Art-Messenger with GNU General Public License v3.0 | 5 votes |
@Nullable public AxolotlKey processSending(@NonNull byte[] outgoingMessage, boolean ignoreSessionTrust) { FingerprintStatus status = getTrust(); if (ignoreSessionTrust || status.isTrustedAndActive()) { try { CiphertextMessage ciphertextMessage = cipher.encrypt(outgoingMessage); return new AxolotlKey(getRemoteAddress().getDeviceId(), ciphertextMessage.serialize(), ciphertextMessage.getType() == CiphertextMessage.PREKEY_TYPE); } catch (UntrustedIdentityException e) { return null; } } else { return null; } }
Example 4
Source File: SignalOmemoRatchet.java From Smack with Apache License 2.0 | 5 votes |
@Override public CiphertextTuple doubleRatchetEncrypt(OmemoDevice recipient, byte[] messageKey) { CiphertextMessage ciphertextMessage; try { ciphertextMessage = getCipher(recipient).encrypt(messageKey); } catch (UntrustedIdentityException e) { throw new AssertionError("Signals trust management MUST be disabled."); } int type = ciphertextMessage.getType() == CiphertextMessage.PREKEY_TYPE ? OmemoElement.TYPE_OMEMO_PREKEY_MESSAGE : OmemoElement.TYPE_OMEMO_MESSAGE; return new CiphertextTuple(ciphertextMessage.serialize(), type); }
Example 5
Source File: XmppAxolotlSession.java From Conversations with GNU General Public License v3.0 | 5 votes |
@Nullable public AxolotlKey processSending(@NonNull byte[] outgoingMessage, boolean ignoreSessionTrust) { FingerprintStatus status = getTrust(); if (ignoreSessionTrust || status.isTrustedAndActive()) { try { CiphertextMessage ciphertextMessage = cipher.encrypt(outgoingMessage); return new AxolotlKey(getRemoteAddress().getDeviceId(), ciphertextMessage.serialize(),ciphertextMessage.getType() == CiphertextMessage.PREKEY_TYPE); } catch (UntrustedIdentityException e) { return null; } } else { return null; } }