Browse Source

OMEMO: converse.js compatibility

omemo_converse
Paul Schaub 7 months ago
parent
commit
9f86eda532
No known key found for this signature in database GPG Key ID: 62BEE9264BF17311
3 changed files with 19 additions and 14 deletions
  1. +4
    -0
      smack-core/src/main/java/org/jivesoftware/smack/util/StringUtils.java
  2. +2
    -2
      smack-omemo/src/main/java/org/jivesoftware/smackx/omemo/element/OmemoBundleElement.java
  3. +13
    -12
      smack-omemo/src/main/java/org/jivesoftware/smackx/omemo/provider/OmemoBundleVAxolotlProvider.java

+ 4
- 0
smack-core/src/main/java/org/jivesoftware/smack/util/StringUtils.java View File

@@ -222,6 +222,10 @@ public class StringUtils {
return out;
}

public static String removeNewLines(String s) {
return s.trim().replaceAll("\n", "");
}

/**
* Hashes a String using the SHA-1 algorithm and returns the result as a
* String of hexadecimal numbers. This method is synchronized to avoid


+ 2
- 2
smack-omemo/src/main/java/org/jivesoftware/smackx/omemo/element/OmemoBundleElement.java View File

@@ -60,8 +60,8 @@ public abstract class OmemoBundleElement implements ExtensionElement {
* @param preKeysB64 HashMap of base64 encoded preKeys
*/
public OmemoBundleElement(int signedPreKeyId, String signedPreKeyB64, String signedPreKeySigB64, String identityKeyB64, HashMap<Integer, String> preKeysB64) {
if (signedPreKeyId <= 0) {
throw new IllegalArgumentException("signedPreKeyId MUST be greater than 0.");
if (signedPreKeyId < 0) {
throw new IllegalArgumentException("signedPreKeyId MUST be greater than or equal to 0.");
}
this.signedPreKeyId = signedPreKeyId;
this.signedPreKeyB64 = StringUtils.requireNotNullNorEmpty(signedPreKeyB64, "signedPreKeyB64 MUST NOT be null nor empty.");


+ 13
- 12
smack-omemo/src/main/java/org/jivesoftware/smackx/omemo/provider/OmemoBundleVAxolotlProvider.java View File

@@ -30,6 +30,7 @@ import java.util.HashMap;

import org.jivesoftware.smack.packet.XmlEnvironment;
import org.jivesoftware.smack.provider.ExtensionElementProvider;
import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smack.xml.XmlPullParser;
import org.jivesoftware.smack.xml.XmlPullParserException;

@@ -59,39 +60,39 @@ public class OmemoBundleVAxolotlProvider extends ExtensionElementProvider<OmemoB
case START_ELEMENT:
final int attributeCount = parser.getAttributeCount();
// <signedPreKeyPublic>
if (name.equals(SIGNED_PRE_KEY_PUB)) {
if (SIGNED_PRE_KEY_PUB.equals(name)) {
for (int i = 0; i < attributeCount; i++) {
if (parser.getAttributeName(i).equals(SIGNED_PRE_KEY_ID)) {
if (SIGNED_PRE_KEY_ID.equals(parser.getAttributeName(i))) {
int id = Integer.parseInt(parser.getAttributeValue(i));
signedPreKey = parser.nextText();
signedPreKey = StringUtils.removeNewLines(parser.nextText());
signedPreKeyId = id;
}
}
}
// <bundleGetSignedPreKeySignature>
else if (name.equals(SIGNED_PRE_KEY_SIG)) {
signedPreKeySignature = parser.nextText();
else if (SIGNED_PRE_KEY_SIG.equals(name)) {
signedPreKeySignature = StringUtils.removeNewLines(parser.nextText());
}
// <deserializeIdentityKey>
else if (name.equals(IDENTITY_KEY)) {
identityKey = parser.nextText();
else if (IDENTITY_KEY.equals(name)) {
identityKey = StringUtils.removeNewLines(parser.nextText());
}
// <deserializeECPublicKeys>
else if (name.equals(PRE_KEYS)) {
else if (PRE_KEYS.equals(name)) {
inPreKeys = true;
}
// <preKeyPublic preKeyId='424242'>
else if (inPreKeys && name.equals(PRE_KEY_PUB)) {
else if (inPreKeys && PRE_KEY_PUB.equals(name)) {
for (int i = 0; i < attributeCount; i++) {
if (parser.getAttributeName(i).equals(PRE_KEY_ID)) {
if (PRE_KEY_ID.equals(parser.getAttributeName(i))) {
preKeys.put(Integer.parseInt(parser.getAttributeValue(i)),
parser.nextText());
StringUtils.removeNewLines(parser.nextText()));
}
}
}
break;
case END_ELEMENT:
if (name.equals(BUNDLE)) {
if (BUNDLE.equals(name)) {
stop = true;
}
break;


Loading…
Cancel
Save