Reformat code to use tabs
This really sucks to do it like this. Sorry. :(
This commit is contained in:
parent
065519d3f3
commit
299bbdf27f
File diff suppressed because it is too large
Load diff
|
@ -21,164 +21,164 @@ import eu.siacs.conversations.entities.Contact;
|
|||
import eu.siacs.conversations.xml.Element;
|
||||
|
||||
public class XmppAxolotlMessage {
|
||||
private byte[] innerKey;
|
||||
private byte[] ciphertext;
|
||||
private byte[] iv;
|
||||
private final Set<XmppAxolotlMessageHeader> headers;
|
||||
private final Contact contact;
|
||||
private final int sourceDeviceId;
|
||||
private byte[] innerKey;
|
||||
private byte[] ciphertext;
|
||||
private byte[] iv;
|
||||
private final Set<XmppAxolotlMessageHeader> headers;
|
||||
private final Contact contact;
|
||||
private final int sourceDeviceId;
|
||||
|
||||
public static class XmppAxolotlMessageHeader {
|
||||
private final int recipientDeviceId;
|
||||
private final byte[] content;
|
||||
public static class XmppAxolotlMessageHeader {
|
||||
private final int recipientDeviceId;
|
||||
private final byte[] content;
|
||||
|
||||
public XmppAxolotlMessageHeader(int deviceId, byte[] content) {
|
||||
this.recipientDeviceId = deviceId;
|
||||
this.content = content;
|
||||
}
|
||||
public XmppAxolotlMessageHeader(int deviceId, byte[] content) {
|
||||
this.recipientDeviceId = deviceId;
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public XmppAxolotlMessageHeader(Element header) {
|
||||
if("header".equals(header.getName())) {
|
||||
this.recipientDeviceId = Integer.parseInt(header.getAttribute("rid"));
|
||||
this.content = Base64.decode(header.getContent(),Base64.DEFAULT);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Argument not a <header> Element!");
|
||||
}
|
||||
}
|
||||
public XmppAxolotlMessageHeader(Element header) {
|
||||
if("header".equals(header.getName())) {
|
||||
this.recipientDeviceId = Integer.parseInt(header.getAttribute("rid"));
|
||||
this.content = Base64.decode(header.getContent(),Base64.DEFAULT);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Argument not a <header> Element!");
|
||||
}
|
||||
}
|
||||
|
||||
public int getRecipientDeviceId() {
|
||||
return recipientDeviceId;
|
||||
}
|
||||
public int getRecipientDeviceId() {
|
||||
return recipientDeviceId;
|
||||
}
|
||||
|
||||
public byte[] getContents() {
|
||||
return content;
|
||||
}
|
||||
public byte[] getContents() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public Element toXml() {
|
||||
Element headerElement = new Element("header");
|
||||
// TODO: generate XML
|
||||
headerElement.setAttribute("rid", getRecipientDeviceId());
|
||||
headerElement.setContent(Base64.encodeToString(getContents(), Base64.DEFAULT));
|
||||
return headerElement;
|
||||
}
|
||||
}
|
||||
public Element toXml() {
|
||||
Element headerElement = new Element("header");
|
||||
// TODO: generate XML
|
||||
headerElement.setAttribute("rid", getRecipientDeviceId());
|
||||
headerElement.setContent(Base64.encodeToString(getContents(), Base64.DEFAULT));
|
||||
return headerElement;
|
||||
}
|
||||
}
|
||||
|
||||
public static class XmppAxolotlPlaintextMessage {
|
||||
private final AxolotlService.XmppAxolotlSession session;
|
||||
private final String plaintext;
|
||||
public static class XmppAxolotlPlaintextMessage {
|
||||
private final AxolotlService.XmppAxolotlSession session;
|
||||
private final String plaintext;
|
||||
|
||||
public XmppAxolotlPlaintextMessage(AxolotlService.XmppAxolotlSession session, String plaintext) {
|
||||
this.session = session;
|
||||
this.plaintext = plaintext;
|
||||
}
|
||||
public XmppAxolotlPlaintextMessage(AxolotlService.XmppAxolotlSession session, String plaintext) {
|
||||
this.session = session;
|
||||
this.plaintext = plaintext;
|
||||
}
|
||||
|
||||
public String getPlaintext() {
|
||||
return plaintext;
|
||||
}
|
||||
}
|
||||
public String getPlaintext() {
|
||||
return plaintext;
|
||||
}
|
||||
}
|
||||
|
||||
public XmppAxolotlMessage(Contact contact, Element axolotlMessage) {
|
||||
this.contact = contact;
|
||||
this.sourceDeviceId = Integer.parseInt(axolotlMessage.getAttribute("id"));
|
||||
this.headers = new HashSet<>();
|
||||
for(Element child:axolotlMessage.getChildren()) {
|
||||
switch(child.getName()) {
|
||||
case "header":
|
||||
headers.add(new XmppAxolotlMessageHeader(child));
|
||||
break;
|
||||
case "message":
|
||||
iv = Base64.decode(child.getAttribute("iv"),Base64.DEFAULT);
|
||||
ciphertext = Base64.decode(child.getContent(),Base64.DEFAULT);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
public XmppAxolotlMessage(Contact contact, Element axolotlMessage) {
|
||||
this.contact = contact;
|
||||
this.sourceDeviceId = Integer.parseInt(axolotlMessage.getAttribute("id"));
|
||||
this.headers = new HashSet<>();
|
||||
for(Element child:axolotlMessage.getChildren()) {
|
||||
switch(child.getName()) {
|
||||
case "header":
|
||||
headers.add(new XmppAxolotlMessageHeader(child));
|
||||
break;
|
||||
case "message":
|
||||
iv = Base64.decode(child.getAttribute("iv"),Base64.DEFAULT);
|
||||
ciphertext = Base64.decode(child.getContent(),Base64.DEFAULT);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public XmppAxolotlMessage(Contact contact, int sourceDeviceId, String plaintext) {
|
||||
this.contact = contact;
|
||||
this.sourceDeviceId = sourceDeviceId;
|
||||
this.headers = new HashSet<>();
|
||||
this.encrypt(plaintext);
|
||||
}
|
||||
public XmppAxolotlMessage(Contact contact, int sourceDeviceId, String plaintext) {
|
||||
this.contact = contact;
|
||||
this.sourceDeviceId = sourceDeviceId;
|
||||
this.headers = new HashSet<>();
|
||||
this.encrypt(plaintext);
|
||||
}
|
||||
|
||||
private void encrypt(String plaintext) {
|
||||
try {
|
||||
KeyGenerator generator = KeyGenerator.getInstance("AES");
|
||||
generator.init(128);
|
||||
SecretKey secretKey = generator.generateKey();
|
||||
Cipher cipher = Cipher.getInstance("AES/CTR/NoPadding");
|
||||
cipher.init(Cipher.ENCRYPT_MODE, secretKey);
|
||||
this.innerKey = secretKey.getEncoded();
|
||||
this.iv = cipher.getIV();
|
||||
this.ciphertext = cipher.doFinal(plaintext.getBytes());
|
||||
} catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException
|
||||
| IllegalBlockSizeException | BadPaddingException e) {
|
||||
private void encrypt(String plaintext) {
|
||||
try {
|
||||
KeyGenerator generator = KeyGenerator.getInstance("AES");
|
||||
generator.init(128);
|
||||
SecretKey secretKey = generator.generateKey();
|
||||
Cipher cipher = Cipher.getInstance("AES/CTR/NoPadding");
|
||||
cipher.init(Cipher.ENCRYPT_MODE, secretKey);
|
||||
this.innerKey = secretKey.getEncoded();
|
||||
this.iv = cipher.getIV();
|
||||
this.ciphertext = cipher.doFinal(plaintext.getBytes());
|
||||
} catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException
|
||||
| IllegalBlockSizeException | BadPaddingException e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Contact getContact() {
|
||||
return this.contact;
|
||||
}
|
||||
public Contact getContact() {
|
||||
return this.contact;
|
||||
}
|
||||
|
||||
public int getSenderDeviceId() {
|
||||
return sourceDeviceId;
|
||||
}
|
||||
public int getSenderDeviceId() {
|
||||
return sourceDeviceId;
|
||||
}
|
||||
|
||||
public byte[] getCiphertext() {
|
||||
return ciphertext;
|
||||
}
|
||||
public byte[] getCiphertext() {
|
||||
return ciphertext;
|
||||
}
|
||||
|
||||
public Set<XmppAxolotlMessageHeader> getHeaders() {
|
||||
return headers;
|
||||
}
|
||||
public Set<XmppAxolotlMessageHeader> getHeaders() {
|
||||
return headers;
|
||||
}
|
||||
|
||||
public void addHeader(XmppAxolotlMessageHeader header) {
|
||||
headers.add(header);
|
||||
}
|
||||
public void addHeader(XmppAxolotlMessageHeader header) {
|
||||
headers.add(header);
|
||||
}
|
||||
|
||||
public byte[] getInnerKey(){
|
||||
return innerKey;
|
||||
}
|
||||
public byte[] getInnerKey(){
|
||||
return innerKey;
|
||||
}
|
||||
|
||||
public byte[] getIV() {
|
||||
return this.iv;
|
||||
}
|
||||
public byte[] getIV() {
|
||||
return this.iv;
|
||||
}
|
||||
|
||||
public Element toXml() {
|
||||
// TODO: generate outer XML, add in header XML
|
||||
Element message= new Element("axolotl_message", AxolotlService.PEP_PREFIX);
|
||||
message.setAttribute("id", sourceDeviceId);
|
||||
for(XmppAxolotlMessageHeader header: headers) {
|
||||
message.addChild(header.toXml());
|
||||
}
|
||||
Element payload = message.addChild("message");
|
||||
payload.setAttribute("iv",Base64.encodeToString(iv, Base64.DEFAULT));
|
||||
payload.setContent(Base64.encodeToString(ciphertext,Base64.DEFAULT));
|
||||
return message;
|
||||
}
|
||||
public Element toXml() {
|
||||
// TODO: generate outer XML, add in header XML
|
||||
Element message= new Element("axolotl_message", AxolotlService.PEP_PREFIX);
|
||||
message.setAttribute("id", sourceDeviceId);
|
||||
for(XmppAxolotlMessageHeader header: headers) {
|
||||
message.addChild(header.toXml());
|
||||
}
|
||||
Element payload = message.addChild("message");
|
||||
payload.setAttribute("iv",Base64.encodeToString(iv, Base64.DEFAULT));
|
||||
payload.setContent(Base64.encodeToString(ciphertext,Base64.DEFAULT));
|
||||
return message;
|
||||
}
|
||||
|
||||
|
||||
public XmppAxolotlPlaintextMessage decrypt(AxolotlService.XmppAxolotlSession session, byte[] key) {
|
||||
XmppAxolotlPlaintextMessage plaintextMessage = null;
|
||||
try {
|
||||
public XmppAxolotlPlaintextMessage decrypt(AxolotlService.XmppAxolotlSession session, byte[] key) {
|
||||
XmppAxolotlPlaintextMessage plaintextMessage = null;
|
||||
try {
|
||||
|
||||
Cipher cipher = Cipher.getInstance("AES/CTR/NoPadding");
|
||||
SecretKeySpec keySpec = new SecretKeySpec(key, "AES");
|
||||
IvParameterSpec ivSpec = new IvParameterSpec(iv);
|
||||
Cipher cipher = Cipher.getInstance("AES/CTR/NoPadding");
|
||||
SecretKeySpec keySpec = new SecretKeySpec(key, "AES");
|
||||
IvParameterSpec ivSpec = new IvParameterSpec(iv);
|
||||
|
||||
cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec);
|
||||
cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec);
|
||||
|
||||
String plaintext = new String(cipher.doFinal(ciphertext));
|
||||
plaintextMessage = new XmppAxolotlPlaintextMessage(session, plaintext);
|
||||
String plaintext = new String(cipher.doFinal(ciphertext));
|
||||
plaintextMessage = new XmppAxolotlPlaintextMessage(session, plaintext);
|
||||
|
||||
} catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException
|
||||
| InvalidAlgorithmParameterException | IllegalBlockSizeException
|
||||
| BadPaddingException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
return plaintextMessage;
|
||||
}
|
||||
} catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException
|
||||
| InvalidAlgorithmParameterException | IllegalBlockSizeException
|
||||
| BadPaddingException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
return plaintextMessage;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -310,7 +310,7 @@ public class Contact implements ListItem, Blockable {
|
|||
synchronized (this.keys) {
|
||||
if (getOtrFingerprints().contains(print)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
try {
|
||||
JSONArray fingerprints;
|
||||
if (!this.keys.has("otr_fingerprints")) {
|
||||
|
@ -392,12 +392,12 @@ public class Contact implements ListItem, Blockable {
|
|||
public boolean addAxolotlIdentityKey(IdentityKey identityKey) {
|
||||
synchronized (this.keys) {
|
||||
if(!getAxolotlIdentityKeys().contains(identityKey)) {
|
||||
JSONArray keysList;
|
||||
try {
|
||||
keysList = this.keys.getJSONArray("axolotl_identity_key");
|
||||
} catch (JSONException e) {
|
||||
keysList = new JSONArray();
|
||||
}
|
||||
JSONArray keysList;
|
||||
try {
|
||||
keysList = this.keys.getJSONArray("axolotl_identity_key");
|
||||
} catch (JSONException e) {
|
||||
keysList = new JSONArray();
|
||||
}
|
||||
|
||||
keysList.put(Base64.encodeToString(identityKey.serialize(), Base64.DEFAULT));
|
||||
try {
|
||||
|
@ -406,10 +406,10 @@ public class Contact implements ListItem, Blockable {
|
|||
Log.e(Config.LOGTAG, "Error adding Identity Key to Contact " + this.getJid() + ": " + e.getMessage());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -147,16 +147,16 @@ public class IqGenerator extends AbstractGenerator {
|
|||
return packet;
|
||||
}
|
||||
|
||||
public IqPacket publishDeviceIds(final List<Integer> ids) {
|
||||
final Element item = new Element("item");
|
||||
final Element list = item.addChild("list", AxolotlService.PEP_PREFIX);
|
||||
for(Integer id:ids) {
|
||||
final Element device = new Element("device");
|
||||
device.setAttribute("id", id);
|
||||
list.addChild(device);
|
||||
}
|
||||
return publish(AxolotlService.PEP_DEVICE_LIST, item);
|
||||
}
|
||||
public IqPacket publishDeviceIds(final List<Integer> ids) {
|
||||
final Element item = new Element("item");
|
||||
final Element list = item.addChild("list", AxolotlService.PEP_PREFIX);
|
||||
for(Integer id:ids) {
|
||||
final Element device = new Element("device");
|
||||
device.setAttribute("id", id);
|
||||
list.addChild(device);
|
||||
}
|
||||
return publish(AxolotlService.PEP_DEVICE_LIST, item);
|
||||
}
|
||||
|
||||
public IqPacket publishBundle(final SignedPreKeyRecord signedPreKeyRecord, IdentityKey identityKey, final int deviceId) {
|
||||
final Element item = new Element("item");
|
||||
|
@ -173,17 +173,17 @@ public class IqGenerator extends AbstractGenerator {
|
|||
return publish(AxolotlService.PEP_BUNDLE+":"+deviceId, item);
|
||||
}
|
||||
|
||||
public IqPacket publishPreKeys(final List<PreKeyRecord> prekeyList, final int deviceId) {
|
||||
final Element item = new Element("item");
|
||||
final Element prekeys = item.addChild("prekeys", AxolotlService.PEP_PREFIX);
|
||||
for(PreKeyRecord preKeyRecord:prekeyList) {
|
||||
final Element prekey = prekeys.addChild("preKeyPublic");
|
||||
public IqPacket publishPreKeys(final List<PreKeyRecord> prekeyList, final int deviceId) {
|
||||
final Element item = new Element("item");
|
||||
final Element prekeys = item.addChild("prekeys", AxolotlService.PEP_PREFIX);
|
||||
for(PreKeyRecord preKeyRecord:prekeyList) {
|
||||
final Element prekey = prekeys.addChild("preKeyPublic");
|
||||
prekey.setAttribute("preKeyId", preKeyRecord.getId());
|
||||
prekey.setContent(Base64.encodeToString(preKeyRecord.getKeyPair().getPublicKey().serialize(), Base64.DEFAULT));
|
||||
}
|
||||
prekey.setContent(Base64.encodeToString(preKeyRecord.getKeyPair().getPublicKey().serialize(), Base64.DEFAULT));
|
||||
}
|
||||
|
||||
return publish(AxolotlService.PEP_PREKEYS+":"+deviceId, item);
|
||||
}
|
||||
}
|
||||
|
||||
public IqPacket queryMessageArchiveManagement(final MessageArchiveService.Query mam) {
|
||||
final IqPacket packet = new IqPacket(IqPacket.TYPE.SET);
|
||||
|
|
|
@ -66,19 +66,19 @@ public class MessageGenerator extends AbstractGenerator {
|
|||
delay.setAttribute("stamp", mDateFormat.format(date));
|
||||
}
|
||||
|
||||
public MessagePacket generateAxolotlChat(Message message) throws NoSessionsCreatedException{
|
||||
return generateAxolotlChat(message, false);
|
||||
}
|
||||
public MessagePacket generateAxolotlChat(Message message) throws NoSessionsCreatedException{
|
||||
return generateAxolotlChat(message, false);
|
||||
}
|
||||
|
||||
public MessagePacket generateAxolotlChat(Message message, boolean addDelay) throws NoSessionsCreatedException{
|
||||
MessagePacket packet = preparePacket(message, addDelay);
|
||||
AxolotlService service = message.getConversation().getAccount().getAxolotlService();
|
||||
Log.d(Config.LOGTAG, "Submitting message to axolotl service for send processing...");
|
||||
XmppAxolotlMessage axolotlMessage = service.processSending(message.getContact(),
|
||||
message.getBody());
|
||||
packet.setAxolotlMessage(axolotlMessage.toXml());
|
||||
return packet;
|
||||
}
|
||||
MessagePacket packet = preparePacket(message, addDelay);
|
||||
AxolotlService service = message.getConversation().getAccount().getAxolotlService();
|
||||
Log.d(Config.LOGTAG, "Submitting message to axolotl service for send processing...");
|
||||
XmppAxolotlMessage axolotlMessage = service.processSending(message.getContact(),
|
||||
message.getBody());
|
||||
packet.setAxolotlMessage(axolotlMessage.toXml());
|
||||
return packet;
|
||||
}
|
||||
|
||||
public MessagePacket generateOtrChat(Message message) {
|
||||
return generateOtrChat(message, false);
|
||||
|
|
|
@ -70,7 +70,7 @@ public class IqParser extends AbstractParser implements OnIqPacketReceived {
|
|||
|
||||
public String avatarData(final IqPacket packet) {
|
||||
final Element pubsub = packet.findChild("pubsub",
|
||||
"http://jabber.org/protocol/pubsub");
|
||||
"http://jabber.org/protocol/pubsub");
|
||||
if (pubsub == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -165,19 +165,19 @@ public class IqParser extends AbstractParser implements OnIqPacketReceived {
|
|||
|
||||
public Map<Integer, ECPublicKey> preKeyPublics(final IqPacket packet) {
|
||||
Map<Integer, ECPublicKey> preKeyRecords = new HashMap<>();
|
||||
Element prekeysItem = getItem(packet);
|
||||
if (prekeysItem == null) {
|
||||
Log.d(Config.LOGTAG, "Couldn't find <item> in preKeyPublic IQ packet: " + packet);
|
||||
return null;
|
||||
}
|
||||
final Element prekeysElement = prekeysItem.findChild("prekeys");
|
||||
if(prekeysElement == null) {
|
||||
Log.d(Config.LOGTAG, "Couldn't find <prekeys> in preKeyPublic IQ packet: " + packet);
|
||||
return null;
|
||||
}
|
||||
Element prekeysItem = getItem(packet);
|
||||
if (prekeysItem == null) {
|
||||
Log.d(Config.LOGTAG, "Couldn't find <item> in preKeyPublic IQ packet: " + packet);
|
||||
return null;
|
||||
}
|
||||
final Element prekeysElement = prekeysItem.findChild("prekeys");
|
||||
if(prekeysElement == null) {
|
||||
Log.d(Config.LOGTAG, "Couldn't find <prekeys> in preKeyPublic IQ packet: " + packet);
|
||||
return null;
|
||||
}
|
||||
for(Element preKeyPublicElement : prekeysElement.getChildren()) {
|
||||
if(!preKeyPublicElement.getName().equals("preKeyPublic")){
|
||||
Log.d(Config.LOGTAG, "Encountered unexpected tag in prekeys list: " + preKeyPublicElement);
|
||||
Log.d(Config.LOGTAG, "Encountered unexpected tag in prekeys list: " + preKeyPublicElement);
|
||||
continue;
|
||||
}
|
||||
Integer preKeyId = Integer.valueOf(preKeyPublicElement.getAttribute("preKeyId"));
|
||||
|
@ -192,37 +192,37 @@ public class IqParser extends AbstractParser implements OnIqPacketReceived {
|
|||
return preKeyRecords;
|
||||
}
|
||||
|
||||
public PreKeyBundle bundle(final IqPacket bundle) {
|
||||
Element bundleItem = getItem(bundle);
|
||||
if(bundleItem == null) {
|
||||
return null;
|
||||
}
|
||||
final Element bundleElement = bundleItem.findChild("bundle");
|
||||
if(bundleElement == null) {
|
||||
return null;
|
||||
}
|
||||
ECPublicKey signedPreKeyPublic = signedPreKeyPublic(bundleElement);
|
||||
Integer signedPreKeyId = signedPreKeyId(bundleElement);
|
||||
byte[] signedPreKeySignature = signedPreKeySignature(bundleElement);
|
||||
IdentityKey identityKey = identityKey(bundleElement);
|
||||
if(signedPreKeyPublic == null || identityKey == null) {
|
||||
return null;
|
||||
}
|
||||
public PreKeyBundle bundle(final IqPacket bundle) {
|
||||
Element bundleItem = getItem(bundle);
|
||||
if(bundleItem == null) {
|
||||
return null;
|
||||
}
|
||||
final Element bundleElement = bundleItem.findChild("bundle");
|
||||
if(bundleElement == null) {
|
||||
return null;
|
||||
}
|
||||
ECPublicKey signedPreKeyPublic = signedPreKeyPublic(bundleElement);
|
||||
Integer signedPreKeyId = signedPreKeyId(bundleElement);
|
||||
byte[] signedPreKeySignature = signedPreKeySignature(bundleElement);
|
||||
IdentityKey identityKey = identityKey(bundleElement);
|
||||
if(signedPreKeyPublic == null || identityKey == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new PreKeyBundle(0, 0, 0, null,
|
||||
signedPreKeyId, signedPreKeyPublic, signedPreKeySignature, identityKey);
|
||||
}
|
||||
return new PreKeyBundle(0, 0, 0, null,
|
||||
signedPreKeyId, signedPreKeyPublic, signedPreKeySignature, identityKey);
|
||||
}
|
||||
|
||||
public List<PreKeyBundle> preKeys(final IqPacket preKeys) {
|
||||
List<PreKeyBundle> bundles = new ArrayList<>();
|
||||
Map<Integer, ECPublicKey> preKeyPublics = preKeyPublics(preKeys);
|
||||
if ( preKeyPublics != null) {
|
||||
for (Integer preKeyId : preKeyPublics.keySet()) {
|
||||
ECPublicKey preKeyPublic = preKeyPublics.get(preKeyId);
|
||||
bundles.add(new PreKeyBundle(0, 0, preKeyId, preKeyPublic,
|
||||
0, null, null, null));
|
||||
}
|
||||
}
|
||||
if ( preKeyPublics != null) {
|
||||
for (Integer preKeyId : preKeyPublics.keySet()) {
|
||||
ECPublicKey preKeyPublic = preKeyPublics.get(preKeyId);
|
||||
bundles.add(new PreKeyBundle(0, 0, preKeyId, preKeyPublic,
|
||||
0, null, null, null));
|
||||
}
|
||||
}
|
||||
|
||||
return bundles;
|
||||
}
|
||||
|
|
|
@ -98,17 +98,17 @@ public class MessageParser extends AbstractParser implements
|
|||
}
|
||||
}
|
||||
|
||||
private Message parseAxolotlChat(Element axolotlMessage, Jid from, String id, Conversation conversation) {
|
||||
Message finishedMessage = null;
|
||||
AxolotlService service = conversation.getAccount().getAxolotlService();
|
||||
XmppAxolotlMessage xmppAxolotlMessage = new XmppAxolotlMessage(conversation.getContact(), axolotlMessage);
|
||||
XmppAxolotlMessage.XmppAxolotlPlaintextMessage plaintextMessage = service.processReceiving(xmppAxolotlMessage);
|
||||
if(plaintextMessage != null) {
|
||||
finishedMessage = new Message(conversation, plaintextMessage.getPlaintext(), Message.ENCRYPTION_AXOLOTL, Message.STATUS_RECEIVED);
|
||||
}
|
||||
private Message parseAxolotlChat(Element axolotlMessage, Jid from, String id, Conversation conversation) {
|
||||
Message finishedMessage = null;
|
||||
AxolotlService service = conversation.getAccount().getAxolotlService();
|
||||
XmppAxolotlMessage xmppAxolotlMessage = new XmppAxolotlMessage(conversation.getContact(), axolotlMessage);
|
||||
XmppAxolotlMessage.XmppAxolotlPlaintextMessage plaintextMessage = service.processReceiving(xmppAxolotlMessage);
|
||||
if(plaintextMessage != null) {
|
||||
finishedMessage = new Message(conversation, plaintextMessage.getPlaintext(), Message.ENCRYPTION_AXOLOTL, Message.STATUS_RECEIVED);
|
||||
}
|
||||
|
||||
return finishedMessage;
|
||||
}
|
||||
return finishedMessage;
|
||||
}
|
||||
|
||||
private class Invite {
|
||||
Jid jid;
|
||||
|
@ -187,17 +187,17 @@ public class MessageParser extends AbstractParser implements
|
|||
mXmppConnectionService.updateAccountUi();
|
||||
}
|
||||
} else if (AxolotlService.PEP_DEVICE_LIST.equals(node)) {
|
||||
Log.d(Config.LOGTAG, "Received PEP device list update from "+ from + ", processing...");
|
||||
Element item = items.findChild("item");
|
||||
Log.d(Config.LOGTAG, "Received PEP device list update from "+ from + ", processing...");
|
||||
Element item = items.findChild("item");
|
||||
List<Integer> deviceIds = mXmppConnectionService.getIqParser().deviceIds(item);
|
||||
AxolotlService axolotlService = account.getAxolotlService();
|
||||
if(account.getJid().toBareJid().equals(from)) {
|
||||
} else {
|
||||
Contact contact = account.getRoster().getContact(from);
|
||||
for (Integer deviceId : deviceIds) {
|
||||
axolotlService.fetchBundleIfNeeded(contact, deviceId);
|
||||
}
|
||||
}
|
||||
AxolotlService axolotlService = account.getAxolotlService();
|
||||
if(account.getJid().toBareJid().equals(from)) {
|
||||
} else {
|
||||
Contact contact = account.getRoster().getContact(from);
|
||||
for (Integer deviceId : deviceIds) {
|
||||
axolotlService.fetchBundleIfNeeded(contact, deviceId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -262,7 +262,7 @@ public class MessageParser extends AbstractParser implements
|
|||
final String body = packet.getBody();
|
||||
final Element mucUserElement = packet.findChild("x","http://jabber.org/protocol/muc#user");
|
||||
final String pgpEncrypted = packet.findChildContent("x", "jabber:x:encrypted");
|
||||
final Element axolotlEncrypted = packet.findChild("axolotl_message", AxolotlService.PEP_PREFIX);
|
||||
final Element axolotlEncrypted = packet.findChild("axolotl_message", AxolotlService.PEP_PREFIX);
|
||||
int status;
|
||||
final Jid counterpart;
|
||||
final Jid to = packet.getTo();
|
||||
|
@ -324,13 +324,13 @@ public class MessageParser extends AbstractParser implements
|
|||
message = new Message(conversation, body, Message.ENCRYPTION_NONE, status);
|
||||
}
|
||||
} else if (pgpEncrypted != null) {
|
||||
message = new Message(conversation, pgpEncrypted, Message.ENCRYPTION_PGP, status);
|
||||
} else if (axolotlEncrypted != null) {
|
||||
message = parseAxolotlChat(axolotlEncrypted, from, remoteMsgId, conversation);
|
||||
if (message == null) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
message = new Message(conversation, pgpEncrypted, Message.ENCRYPTION_PGP, status);
|
||||
} else if (axolotlEncrypted != null) {
|
||||
message = parseAxolotlChat(axolotlEncrypted, from, remoteMsgId, conversation);
|
||||
if (message == null) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
message = new Message(conversation, body, Message.ENCRYPTION_NONE, status);
|
||||
}
|
||||
message.setCounterpart(counterpart);
|
||||
|
|
|
@ -42,7 +42,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
|
|||
+ Contact.JID + " TEXT," + Contact.KEYS + " TEXT,"
|
||||
+ Contact.PHOTOURI + " TEXT," + Contact.OPTIONS + " NUMBER,"
|
||||
+ Contact.SYSTEMACCOUNT + " NUMBER, " + Contact.AVATAR + " TEXT, "
|
||||
+ Contact.LAST_PRESENCE + " TEXT, " + Contact.LAST_TIME + " NUMBER, "
|
||||
+ Contact.LAST_PRESENCE + " TEXT, " + Contact.LAST_TIME + " NUMBER, "
|
||||
+ Contact.GROUPS + " TEXT, FOREIGN KEY(" + Contact.ACCOUNT + ") REFERENCES "
|
||||
+ Account.TABLENAME + "(" + Account.UUID
|
||||
+ ") ON DELETE CASCADE, UNIQUE(" + Contact.ACCOUNT + ", "
|
||||
|
@ -75,14 +75,14 @@ public class DatabaseBackend extends SQLiteOpenHelper {
|
|||
private static String CREATE_SESSIONS_STATEMENT = "CREATE TABLE "
|
||||
+ AxolotlService.SQLiteAxolotlStore.SESSION_TABLENAME + "("
|
||||
+ AxolotlService.SQLiteAxolotlStore.ACCOUNT + " TEXT, "
|
||||
+ AxolotlService.SQLiteAxolotlStore.NAME + " TEXT, "
|
||||
+ AxolotlService.SQLiteAxolotlStore.DEVICE_ID + " INTEGER, "
|
||||
+ AxolotlService.SQLiteAxolotlStore.NAME + " TEXT, "
|
||||
+ AxolotlService.SQLiteAxolotlStore.DEVICE_ID + " INTEGER, "
|
||||
+ AxolotlService.SQLiteAxolotlStore.TRUSTED + " INTEGER, "
|
||||
+ AxolotlService.SQLiteAxolotlStore.KEY + " TEXT, FOREIGN KEY("
|
||||
+ AxolotlService.SQLiteAxolotlStore.ACCOUNT
|
||||
+ AxolotlService.SQLiteAxolotlStore.KEY + " TEXT, FOREIGN KEY("
|
||||
+ AxolotlService.SQLiteAxolotlStore.ACCOUNT
|
||||
+ ") REFERENCES " + Account.TABLENAME + "(" + Account.UUID + ") ON DELETE CASCADE, "
|
||||
+ "UNIQUE( " + AxolotlService.SQLiteAxolotlStore.ACCOUNT + ", "
|
||||
+ AxolotlService.SQLiteAxolotlStore.NAME + ", "
|
||||
+ "UNIQUE( " + AxolotlService.SQLiteAxolotlStore.ACCOUNT + ", "
|
||||
+ AxolotlService.SQLiteAxolotlStore.NAME + ", "
|
||||
+ AxolotlService.SQLiteAxolotlStore.DEVICE_ID
|
||||
+ ") ON CONFLICT REPLACE"
|
||||
+");";
|
||||
|
@ -157,12 +157,12 @@ public class DatabaseBackend extends SQLiteOpenHelper {
|
|||
db.execSQL("ALTER TABLE " + Conversation.TABLENAME + " ADD COLUMN "
|
||||
+ Conversation.ATTRIBUTES + " TEXT");
|
||||
}
|
||||
if (oldVersion < 9 && newVersion >= 9) {
|
||||
db.execSQL("ALTER TABLE " + Contact.TABLENAME + " ADD COLUMN "
|
||||
+ Contact.LAST_TIME + " NUMBER");
|
||||
db.execSQL("ALTER TABLE " + Contact.TABLENAME + " ADD COLUMN "
|
||||
+ Contact.LAST_PRESENCE + " TEXT");
|
||||
}
|
||||
if (oldVersion < 9 && newVersion >= 9) {
|
||||
db.execSQL("ALTER TABLE " + Contact.TABLENAME + " ADD COLUMN "
|
||||
+ Contact.LAST_TIME + " NUMBER");
|
||||
db.execSQL("ALTER TABLE " + Contact.TABLENAME + " ADD COLUMN "
|
||||
+ Contact.LAST_PRESENCE + " TEXT");
|
||||
}
|
||||
if (oldVersion < 10 && newVersion >= 10) {
|
||||
db.execSQL("ALTER TABLE " + Message.TABLENAME + " ADD COLUMN "
|
||||
+ Message.RELATIVE_FILE_PATH + " TEXT");
|
||||
|
@ -557,7 +557,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
|
|||
|
||||
public SessionRecord loadSession(Account account, AxolotlAddress contact) {
|
||||
SessionRecord session = null;
|
||||
Cursor cursor = getCursorForSession(account, contact);
|
||||
Cursor cursor = getCursorForSession(account, contact);
|
||||
if(cursor.getCount() != 0) {
|
||||
cursor.moveToFirst();
|
||||
try {
|
||||
|
@ -565,8 +565,8 @@ public class DatabaseBackend extends SQLiteOpenHelper {
|
|||
} catch (IOException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
cursor.close();
|
||||
}
|
||||
cursor.close();
|
||||
return session;
|
||||
}
|
||||
|
||||
|
@ -635,7 +635,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
|
|||
Cursor cursor = getCursorForSession(account, contact);
|
||||
if(cursor.getCount() != 0) {
|
||||
cursor.moveToFirst();
|
||||
trusted = cursor.getInt(cursor.getColumnIndex(
|
||||
trusted = cursor.getInt(cursor.getColumnIndex(
|
||||
AxolotlService.SQLiteAxolotlStore.TRUSTED)) > 0;
|
||||
}
|
||||
cursor.close();
|
||||
|
|
|
@ -274,9 +274,9 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
|
|||
}
|
||||
}
|
||||
syncDirtyContacts(account);
|
||||
account.getAxolotlService().publishOwnDeviceIdIfNeeded();
|
||||
account.getAxolotlService().publishBundleIfNeeded();
|
||||
account.getAxolotlService().publishPreKeysIfNeeded();
|
||||
account.getAxolotlService().publishOwnDeviceIdIfNeeded();
|
||||
account.getAxolotlService().publishBundleIfNeeded();
|
||||
account.getAxolotlService().publishPreKeysIfNeeded();
|
||||
|
||||
scheduleWakeUpCall(Config.PING_MAX_INTERVAL, account.getUuid().hashCode());
|
||||
} else if (account.getStatus() == Account.State.OFFLINE) {
|
||||
|
|
|
@ -752,16 +752,16 @@ public class ConversationActivity extends XmppActivity
|
|||
}
|
||||
break;
|
||||
case R.id.encryption_choice_axolotl:
|
||||
Log.d(Config.LOGTAG, "Trying to enable axolotl...");
|
||||
Log.d(Config.LOGTAG, "Trying to enable axolotl...");
|
||||
if(conversation.getAccount().getAxolotlService().isContactAxolotlCapable(conversation.getContact())) {
|
||||
Log.d(Config.LOGTAG, "Enabled axolotl for Contact " + conversation.getContact().getJid() );
|
||||
Log.d(Config.LOGTAG, "Enabled axolotl for Contact " + conversation.getContact().getJid() );
|
||||
conversation.setNextEncryption(Message.ENCRYPTION_AXOLOTL);
|
||||
item.setChecked(true);
|
||||
} else {
|
||||
Log.d(Config.LOGTAG, "Contact " + conversation.getContact().getJid() + " not axolotl capable!");
|
||||
Log.d(Config.LOGTAG, "Contact " + conversation.getContact().getJid() + " not axolotl capable!");
|
||||
showAxolotlNoSessionsDialog();
|
||||
}
|
||||
break;
|
||||
break;
|
||||
default:
|
||||
conversation.setNextEncryption(Message.ENCRYPTION_NONE);
|
||||
break;
|
||||
|
@ -794,7 +794,7 @@ public class ConversationActivity extends XmppActivity
|
|||
pgp.setChecked(true);
|
||||
break;
|
||||
case Message.ENCRYPTION_AXOLOTL:
|
||||
Log.d(Config.LOGTAG, "Axolotl confirmed. Setting menu item checked!");
|
||||
Log.d(Config.LOGTAG, "Axolotl confirmed. Setting menu item checked!");
|
||||
popup.getMenu().findItem(R.id.encryption_choice_axolotl)
|
||||
.setChecked(true);
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue