Search in sources :

Example 1 with OmemoVAxolotlProvider

use of org.jivesoftware.smackx.omemo.provider.OmemoVAxolotlProvider in project Smack by igniterealtime.

the class SignalOmemoManagerTest method stanzaRecognitionTest.

@Test
public void stanzaRecognitionTest() throws Exception {
    String omemoXML = "<encrypted xmlns='eu.siacs.conversations.axolotl'><header sid='1009'><key rid='1337'>MwohBfRqBm2atj3fT0/KUDg59Cnvfpgoe/PLNIu1xgSXujEZEAAYACIwKh6TTC7VBQZcCcKnQlO+6s1GQ9DIRKH4JU7XrJ+JJnkPUwJ4VLSeOEQD7HmFbhQPTLZO0u/qlng=</key><iv>sN0amy4e2NBrlb4G/OjNIQ==</iv></header><payload>4xVUAeg4M0Mhk+5n3YG1x12Dw/cYTc0Z</payload></encrypted>";
    OmemoElement omemoElement = new OmemoVAxolotlProvider().parse(TestUtils.getParser(omemoXML));
    Message m = StanzaBuilder.buildMessage().addExtension(omemoElement).build();
    Message n = StanzaBuilder.buildMessage().build();
    assertTrue(OmemoManager.stanzaContainsOmemoElement(m));
    assertFalse(OmemoManager.stanzaContainsOmemoElement(n));
}
Also used : OmemoVAxolotlProvider(org.jivesoftware.smackx.omemo.provider.OmemoVAxolotlProvider) Message(org.jivesoftware.smack.packet.Message) OmemoElement(org.jivesoftware.smackx.omemo.element.OmemoElement) Test(org.junit.Test)

Example 2 with OmemoVAxolotlProvider

use of org.jivesoftware.smackx.omemo.provider.OmemoVAxolotlProvider in project Smack by igniterealtime.

the class OmemoVAxolotlElementTest method serializationTest.

@Test
public void serializationTest() throws Exception {
    byte[] payload = "This is payload.".getBytes(StandardCharsets.UTF_8);
    int keyId1 = 8;
    int keyId2 = 33333;
    byte[] keyData1 = "KEYDATA".getBytes(StandardCharsets.UTF_8);
    byte[] keyData2 = "DATAKEY".getBytes(StandardCharsets.UTF_8);
    int sid = 12131415;
    byte[] iv = OmemoMessageBuilder.generateIv();
    ArrayList<OmemoKeyElement> keys = new ArrayList<>();
    keys.add(new OmemoKeyElement(keyData1, keyId1));
    keys.add(new OmemoKeyElement(keyData2, keyId2, true));
    OmemoHeaderElement_VAxolotl header = new OmemoHeaderElement_VAxolotl(sid, keys, iv);
    OmemoElement_VAxolotl element = new OmemoElement_VAxolotl(header, payload);
    String expected = "<encrypted xmlns='eu.siacs.conversations.axolotl'>" + "<header sid='12131415'>" + "<key rid='8'>" + Base64.encodeToString(keyData1) + "</key>" + "<key prekey='true' rid='33333'>" + Base64.encodeToString(keyData2) + "</key>" + "<iv>" + Base64.encodeToString(iv) + "</iv>" + "</header>" + "<payload>" + Base64.encodeToString(payload) + "</payload>" + "</encrypted>";
    String actual = element.toXML().toString();
    assertEquals("Serialized xml of OmemoElement must match.", expected, actual);
    OmemoElement_VAxolotl parsed = new OmemoVAxolotlProvider().parse(TestUtils.getParser(actual));
    assertEquals("Parsed OmemoElement must equal the original.", element.toXML().toString(), parsed.toXML().toString());
}
Also used : OmemoElement_VAxolotl(org.jivesoftware.smackx.omemo.element.OmemoElement_VAxolotl) OmemoVAxolotlProvider(org.jivesoftware.smackx.omemo.provider.OmemoVAxolotlProvider) OmemoKeyElement(org.jivesoftware.smackx.omemo.element.OmemoKeyElement) OmemoHeaderElement_VAxolotl(org.jivesoftware.smackx.omemo.element.OmemoHeaderElement_VAxolotl) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

OmemoVAxolotlProvider (org.jivesoftware.smackx.omemo.provider.OmemoVAxolotlProvider)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 Message (org.jivesoftware.smack.packet.Message)1 OmemoElement (org.jivesoftware.smackx.omemo.element.OmemoElement)1 OmemoElement_VAxolotl (org.jivesoftware.smackx.omemo.element.OmemoElement_VAxolotl)1 OmemoHeaderElement_VAxolotl (org.jivesoftware.smackx.omemo.element.OmemoHeaderElement_VAxolotl)1 OmemoKeyElement (org.jivesoftware.smackx.omemo.element.OmemoKeyElement)1