Skip to content

Commit

Permalink
add initial support for Signal message sending
Browse files Browse the repository at this point in the history
  • Loading branch information
n8fr8 committed Nov 1, 2017
1 parent 1e0871f commit 68db8d6
Show file tree
Hide file tree
Showing 7 changed files with 219 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
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
20 changes: 19 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,28 @@ repositories {
maven { url 'https://jitpack.io' }
}

allprojects {
project.ext {
// these are common variables used in */build.gradle
version_number="0.0.13"
group_info="haven"
signal_version="2.3.0"
}
}


android {
compileSdkVersion 25
buildToolsVersion '26.0.2'

packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}

defaultConfig {
Expand All @@ -35,6 +50,8 @@ android {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
multiDexEnabled true

}

buildTypes {
Expand All @@ -47,11 +64,12 @@ android {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}

}

dependencies {


compile project(':external:libsignal-service-java:java')
compile 'com.android.support:support-v4:25.4.0'
compile 'com.github.satyan:sugar:1.5'
compile 'com.android.support:appcompat-v7:25.4.0'
Expand Down
1 change: 1 addition & 0 deletions external/libsignal-service-java
Submodule libsignal-service-java added at 70a0b2
2 changes: 2 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include ':external:libsignal-service-java:java'

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package info.guardianproject.phoneypot;

import android.app.Application;
import android.support.multidex.MultiDexApplication;

import com.facebook.drawee.backends.pipeline.Fresco;
import com.orm.SugarApp;
Expand All @@ -10,7 +11,7 @@
* Created by n8fr8 on 8/9/17.
*/

public class PhoneyPotApp extends Application {
public class PhoneyPotApp extends MultiDexApplication {

@Override
public void onCreate() {
Expand Down
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) {

}
}
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());
}
}

0 comments on commit 68db8d6

Please sign in to comment.