-
-
Notifications
You must be signed in to change notification settings - Fork 728
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add initial support for Signal message sending
- Loading branch information
Showing
7 changed files
with
219 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "external/libsignal-service-java"] | ||
path = external/libsignal-service-java | ||
url = https://github.com/WhisperSystems/libsignal-service-java.git |
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
Submodule libsignal-service-java
added at
70a0b2
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,2 @@ | ||
include ':external:libsignal-service-java: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
114 changes: 114 additions & 0 deletions
114
src/main/java/info/guardianproject/phoneypot/service/signal/MySignalProtocolStore.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,114 @@ | ||
package info.guardianproject.phoneypot.service.signal; | ||
|
||
import org.whispersystems.libsignal.IdentityKey; | ||
import org.whispersystems.libsignal.IdentityKeyPair; | ||
import org.whispersystems.libsignal.InvalidKeyIdException; | ||
import org.whispersystems.libsignal.SignalProtocolAddress; | ||
import org.whispersystems.libsignal.state.IdentityKeyStore; | ||
import org.whispersystems.libsignal.state.PreKeyRecord; | ||
import org.whispersystems.libsignal.state.SessionRecord; | ||
import org.whispersystems.libsignal.state.SignalProtocolStore; | ||
import org.whispersystems.libsignal.state.SignedPreKeyRecord; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Created by n8fr8 on 11/1/17. | ||
*/ | ||
|
||
public class MySignalProtocolStore implements SignalProtocolStore { | ||
@Override | ||
public IdentityKeyPair getIdentityKeyPair() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public int getLocalRegistrationId() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public boolean saveIdentity(SignalProtocolAddress address, IdentityKey identityKey) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean isTrustedIdentity(SignalProtocolAddress address, IdentityKey identityKey, Direction direction) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public PreKeyRecord loadPreKey(int preKeyId) throws InvalidKeyIdException { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void storePreKey(int preKeyId, PreKeyRecord record) { | ||
|
||
} | ||
|
||
@Override | ||
public boolean containsPreKey(int preKeyId) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public void removePreKey(int preKeyId) { | ||
|
||
} | ||
|
||
@Override | ||
public SessionRecord loadSession(SignalProtocolAddress address) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public List<Integer> getSubDeviceSessions(String name) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void storeSession(SignalProtocolAddress address, SessionRecord record) { | ||
|
||
} | ||
|
||
@Override | ||
public boolean containsSession(SignalProtocolAddress address) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public void deleteSession(SignalProtocolAddress address) { | ||
|
||
} | ||
|
||
@Override | ||
public void deleteAllSessions(String name) { | ||
|
||
} | ||
|
||
@Override | ||
public SignedPreKeyRecord loadSignedPreKey(int signedPreKeyId) throws InvalidKeyIdException { | ||
return null; | ||
} | ||
|
||
@Override | ||
public List<SignedPreKeyRecord> loadSignedPreKeys() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void storeSignedPreKey(int signedPreKeyId, SignedPreKeyRecord record) { | ||
|
||
} | ||
|
||
@Override | ||
public boolean containsSignedPreKey(int signedPreKeyId) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public void removeSignedPreKey(int signedPreKeyId) { | ||
|
||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
src/main/java/info/guardianproject/phoneypot/service/signal/SignalSender.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,78 @@ | ||
package info.guardianproject.phoneypot.service.signal; | ||
|
||
import org.whispersystems.libsignal.IdentityKeyPair; | ||
import org.whispersystems.libsignal.InvalidKeyException; | ||
import org.whispersystems.libsignal.state.PreKeyRecord; | ||
import org.whispersystems.libsignal.state.SignedPreKeyRecord; | ||
import org.whispersystems.libsignal.util.KeyHelper; | ||
import org.whispersystems.libsignal.util.guava.Optional; | ||
import org.whispersystems.signalservice.api.SignalServiceAccountManager; | ||
import org.whispersystems.signalservice.api.SignalServiceMessageSender; | ||
import org.whispersystems.signalservice.api.crypto.UntrustedIdentityException; | ||
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage; | ||
import org.whispersystems.signalservice.api.push.SignalServiceAddress; | ||
import org.whispersystems.signalservice.api.push.TrustStore; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
/** | ||
* Created by n8fr8 on 10/31/17. | ||
*/ | ||
|
||
public class SignalSender { | ||
|
||
private final String URL = "https://my.signal.server.com"; | ||
private final TrustStore TRUST_STORE = null;//new MyTrustStoreImpl(); | ||
private final String USERNAME = "+14151231234"; | ||
private final String PASSWORD = null;//generateRandomPassword(); | ||
private final String USER_AGENT = "[FILL_IN]"; | ||
|
||
private SignalServiceAccountManager accountManager; | ||
|
||
public SignalSender () | ||
{ | ||
accountManager = null; //new SignalServiceAccountManager(URL, TRUST_STORE, USERNAME, PASSWORD, USER_AGENT); | ||
|
||
|
||
} | ||
public void generateKeys () | ||
{ | ||
|
||
} | ||
|
||
public void register () throws IOException { | ||
|
||
accountManager.requestSmsVerificationCode(); | ||
} | ||
|
||
public void verify (String receivedSmsVerificationCode) throws IOException, InvalidKeyException { | ||
|
||
// accountManager.verifyAccountWithCode(receivedSmsVerificationCode, generateRandomSignalingKey(), | ||
// generateRandomInstallId(), false); | ||
|
||
int signedPreKeyId = 1; | ||
|
||
IdentityKeyPair identityKey = KeyHelper.generateIdentityKeyPair(); | ||
List<PreKeyRecord> oneTimePreKeys = KeyHelper.generatePreKeys(0, 100); | ||
SignedPreKeyRecord signedPreKeyRecord = KeyHelper.generateSignedPreKey(identityKey, signedPreKeyId); | ||
|
||
//accountManager.setGcmId(Optional.of(GoogleCloudMessaging.getInstance(this).register(REGISTRATION_ID))); | ||
accountManager.setPreKeys(identityKey.getPublicKey(), signedPreKeyRecord, oneTimePreKeys); | ||
} | ||
|
||
public void sendMessage () throws IOException, UntrustedIdentityException { | ||
SignalServiceMessageSender messageSender = null; | ||
|
||
/** | ||
new SignalServiceMessageSender(URL, TRUST_STORE, USERNAME, PASSWORD, | ||
new MySignalProtocolStore(), | ||
USER_AGENT, Optional.absent()); | ||
**/ | ||
|
||
messageSender.sendMessage(new SignalServiceAddress("+14159998888"), | ||
SignalServiceDataMessage.newBuilder() | ||
.withBody("Hello, world!") | ||
.build()); | ||
} | ||
} |