version = '0.1.0'
repositories {
+ maven {
+ url "https://raw.github.com/AsamK/maven/master/releases/"
+ }
mavenCentral()
}
compile 'com.madgag.spongycastle:prov:1.53.0.0'
compile 'commons-io:commons-io:2.4'
compile 'net.sourceforge.argparse4j:argparse4j:0.5.0'
+ compile 'org.freedesktop.dbus:dbus-java:2.7.0'
}
jar {
import net.sourceforge.argparse4j.impl.Arguments;
import net.sourceforge.argparse4j.inf.*;
import org.apache.commons.io.IOUtils;
+import org.freedesktop.dbus.DBusConnection;
+import org.freedesktop.dbus.exceptions.DBusException;
import org.whispersystems.textsecure.api.crypto.UntrustedIdentityException;
import org.whispersystems.textsecure.api.messages.*;
import org.whispersystems.textsecure.api.messages.multidevice.TextSecureSyncMessage;
try {
m.receiveMessages(timeout, returnOnTimeout, new ReceiveMessageHandler(m));
} catch (IOException e) {
- System.err.println("Error while receiving message: " + e.getMessage());
+ System.err.println("Error while receiving messages: " + e.getMessage());
System.exit(3);
} catch (AssertionError e) {
- System.err.println("Failed to receive message (Assertion): " + e.getMessage());
- System.err.println(e.getStackTrace());
- System.err.println("If you use an Oracle JRE please check if you have unlimited strength crypto enabled, see README");
- System.exit(1);
+ handleAssertionError(e);
}
break;
case "quitGroup":
handleEncapsulatedExceptions(e);
}
+ break;
+ case "daemon":
+ if (!m.isRegistered()) {
+ System.err.println("User is not registered.");
+ System.exit(1);
+ }
+ try {
+ int busType;
+ if (ns.getBoolean("system")) {
+ busType = DBusConnection.SYSTEM;
+ } else {
+ busType = DBusConnection.SESSION;
+ }
+ DBusConnection conn = DBusConnection.getConnection(busType);
+ conn.requestBusName("org.asamk.TextSecure");
+ conn.exportObject("/org/asamk/TextSecure", m);
+ } catch (DBusException e) {
+ e.printStackTrace();
+ System.exit(3);
+ }
+ try {
+ m.receiveMessages(3600, false, new ReceiveMessageHandler(m));
+ } catch (IOException e) {
+ System.err.println("Error while receiving messages: " + e.getMessage());
+ System.exit(3);
+ } catch (AssertionError e) {
+ handleAssertionError(e);
+ }
+
break;
}
m.save();
.type(int.class)
.help("Number of seconds to wait for new messages (negative values disable timeout)");
+ Subparser parserDaemon = subparsers.addParser("daemon");
+ parserDaemon.addArgument("--system")
+ .action(Arguments.storeTrue())
+ .help("Use DBus system bus instead of user bus.");
+
try {
Namespace ns = parser.parseArgs(args);
if (ns.getString("username") == null) {
}
private static void handleAssertionError(AssertionError e) {
- System.err.println("Failed to send message (Assertion): " + e.getMessage());
+ System.err.println("Failed to send/receive message (Assertion): " + e.getMessage());
System.err.println(e.getStackTrace());
System.err.println("If you use an Oracle JRE please check if you have unlimited strength crypto enabled, see README");
System.exit(1);
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
-class Manager {
+class Manager implements TextSecure {
private final static String URL = "https://textsecure-service.whispersystems.org";
private final static TrustStore TRUST_STORE = new WhisperTrustStore();
return new TextSecureAttachmentStream(attachmentStream, mime, attachmentSize, null);
}
+ @Override
public void sendGroupMessage(String messageText, List<String> attachments,
byte[] groupId)
throws IOException, EncapsulatedExceptions, GroupNotFoundException, AttachmentInvalidException {
return g.groupId;
}
+ @Override
+ public void sendMessage(String message, List<String> attachments, String recipient)
+ throws EncapsulatedExceptions, AttachmentInvalidException, IOException {
+ List<String> recipients = new ArrayList<>(1);
+ recipients.add(recipient);
+ sendMessage(message, attachments, recipients);
+ }
+
public void sendMessage(String messageText, List<String> attachments,
Collection<String> recipients)
- throws IOException, EncapsulatedExceptions, GroupNotFoundException, AttachmentInvalidException {
+ throws IOException, EncapsulatedExceptions, AttachmentInvalidException {
final TextSecureDataMessage.Builder messageBuilder = TextSecureDataMessage.newBuilder().withBody(messageText);
if (attachments != null) {
messageBuilder.withAttachments(getTextSecureAttachments(attachments));
handleEndSession(recipient.getNumber());
}
}
+ save();
}
private TextSecureContent decryptMessage(TextSecureEnvelope envelope) {
}
}
}
+ save();
handler.handleMessage(envelope, content, group);
} catch (TimeoutException e) {
if (returnOnTimeout)
} catch (InvalidVersionException e) {
System.err.println("Ignoring error: " + e.getMessage());
}
- save();
}
} finally {
if (messagePipe != null)
private void setGroupInfo(GroupInfo group) {
groupStore.updateGroup(group);
}
+
+ @Override
+ public boolean isRemote() {
+ return false;
+ }
}
--- /dev/null
+package cli;
+
+import org.freedesktop.dbus.DBusInterface;
+import org.whispersystems.textsecure.api.push.exceptions.EncapsulatedExceptions;
+
+import java.io.IOException;
+import java.util.List;
+
+public interface TextSecure extends DBusInterface {
+ void sendMessage(String message, List<String> attachments, String recipient) throws EncapsulatedExceptions, AttachmentInvalidException, IOException;
+
+ void sendGroupMessage(String message, List<String> attachments, byte[] groupId) throws EncapsulatedExceptions, GroupNotFoundException, AttachmentInvalidException, IOException;
+}