org.whispersystems.signalservice.internal.push.PushTransportDetails Java Examples
The following examples show how to use
org.whispersystems.signalservice.internal.push.PushTransportDetails.
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: SignalServiceCipher.java From bcm-android with GNU General Public License v3.0 | 5 votes |
private byte[] decrypt(SignalServiceProtos.Envelope 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.getType() == Type.PREKEY_BUNDLE) { paddedMessage = sessionCipher.decrypt(new PreKeySignalMessage(ciphertext)); //纠正remote register id SessionRecord sessionRecord = signalProtocolStore.loadSession(sourceAddress); if (sessionRecord.getSessionState().getRemoteRegistrationId() == 0) { sessionRecord.getSessionState().setRemoteRegistrationId(envelope.getSourceRegistration()); signalProtocolStore.storeSession(sourceAddress, sessionRecord); } } else if (envelope.getType() == Type.CIPHERTEXT) { paddedMessage = sessionCipher.decrypt(new SignalMessage(ciphertext)); } else { throw new InvalidMessageException("Unknown type: " + envelope.getType()); } PushTransportDetails transportDetails = new PushTransportDetails(sessionCipher.getSessionVersion()); return transportDetails.getStrippedPaddingMessageBody(paddedMessage); }