-
-
Notifications
You must be signed in to change notification settings - Fork 6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
// FREEBIE
- Loading branch information
Showing
12 changed files
with
183 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/org/thoughtcrime/securesms/jobs/EncryptingJobSerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package org.thoughtcrime.securesms.jobs; | ||
|
||
import android.content.Context; | ||
|
||
import org.thoughtcrime.securesms.util.ParcelUtil; | ||
import org.whispersystems.jobqueue.EncryptionKeys; | ||
import org.whispersystems.jobqueue.Job; | ||
import org.whispersystems.jobqueue.persistence.JavaJobSerializer; | ||
import org.whispersystems.jobqueue.persistence.JobSerializer; | ||
import org.whispersystems.libaxolotl.InvalidMessageException; | ||
import org.whispersystems.textsecure.crypto.MasterCipher; | ||
import org.whispersystems.textsecure.crypto.MasterSecret; | ||
|
||
import java.io.IOException; | ||
|
||
public class EncryptingJobSerializer implements JobSerializer { | ||
|
||
private final JavaJobSerializer delegate; | ||
|
||
public EncryptingJobSerializer(Context context) { | ||
this.delegate = new JavaJobSerializer(context); | ||
} | ||
|
||
@Override | ||
public String serialize(Job job) throws IOException { | ||
String plaintext = delegate.serialize(job); | ||
|
||
if (job.getEncryptionKeys() != null) { | ||
MasterSecret masterSecret = ParcelUtil.deserialize(job.getEncryptionKeys().getEncoded(), | ||
MasterSecret.CREATOR); | ||
MasterCipher masterCipher = new MasterCipher(masterSecret); | ||
|
||
return masterCipher.encryptBody(plaintext); | ||
} else { | ||
return plaintext; | ||
} | ||
} | ||
|
||
@Override | ||
public Job deserialize(EncryptionKeys keys, boolean encrypted, String serialized) throws IOException { | ||
try { | ||
String plaintext; | ||
|
||
if (encrypted) { | ||
MasterSecret masterSecret = ParcelUtil.deserialize(keys.getEncoded(), MasterSecret.CREATOR); | ||
MasterCipher masterCipher = new MasterCipher(masterSecret); | ||
plaintext = masterCipher.decryptBody(serialized); | ||
} else { | ||
plaintext = serialized; | ||
} | ||
|
||
return delegate.deserialize(keys, encrypted, plaintext); | ||
} catch (InvalidMessageException e) { | ||
throw new IOException(e); | ||
} | ||
} | ||
} |
Oops, something went wrong.