mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 18:40:39 +00:00
Replace Base64 class from libsignal with java.util.Base64
This commit is contained in:
parent
e6ea5d55f8
commit
9a775171b5
17 changed files with 100 additions and 96 deletions
|
@ -36,9 +36,9 @@ import org.whispersystems.signalservice.api.messages.multidevice.VerifiedMessage
|
||||||
import org.whispersystems.signalservice.api.messages.multidevice.ViewOnceOpenMessage;
|
import org.whispersystems.signalservice.api.messages.multidevice.ViewOnceOpenMessage;
|
||||||
import org.whispersystems.signalservice.api.messages.shared.SharedContact;
|
import org.whispersystems.signalservice.api.messages.shared.SharedContact;
|
||||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
||||||
import org.whispersystems.util.Base64;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.Base64;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
||||||
|
@ -244,10 +244,12 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
||||||
for (StickerPackOperationMessage m : stickerPackOperationMessages) {
|
for (StickerPackOperationMessage m : stickerPackOperationMessages) {
|
||||||
System.out.println(" - " + m.getType().toString());
|
System.out.println(" - " + m.getType().toString());
|
||||||
if (m.getPackId().isPresent()) {
|
if (m.getPackId().isPresent()) {
|
||||||
System.out.println(" packId: " + Base64.encodeBytes(m.getPackId().get()));
|
System.out.println(" packId: " + Base64.getEncoder()
|
||||||
|
.encodeToString(m.getPackId().get()));
|
||||||
}
|
}
|
||||||
if (m.getPackKey().isPresent()) {
|
if (m.getPackKey().isPresent()) {
|
||||||
System.out.println(" packKey: " + Base64.encodeBytes(m.getPackKey().get()));
|
System.out.println(" packKey: " + Base64.getEncoder()
|
||||||
|
.encodeToString(m.getPackKey().get()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -257,8 +259,8 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
||||||
System.out.println("Received message request response:");
|
System.out.println("Received message request response:");
|
||||||
System.out.println(" Type: " + requestResponseMessage.getType());
|
System.out.println(" Type: " + requestResponseMessage.getType());
|
||||||
if (requestResponseMessage.getGroupId().isPresent()) {
|
if (requestResponseMessage.getGroupId().isPresent()) {
|
||||||
System.out.println(" Group id: " + Base64.encodeBytes(requestResponseMessage.getGroupId()
|
System.out.println(" Group id: " + Base64.getEncoder()
|
||||||
.get()));
|
.encodeToString(requestResponseMessage.getGroupId().get()));
|
||||||
}
|
}
|
||||||
if (requestResponseMessage.getPerson().isPresent()) {
|
if (requestResponseMessage.getPerson().isPresent()) {
|
||||||
System.out.println(" Person: " + requestResponseMessage.getPerson()
|
System.out.println(" Person: " + requestResponseMessage.getPerson()
|
||||||
|
@ -418,8 +420,8 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
||||||
if (message.getSticker().isPresent()) {
|
if (message.getSticker().isPresent()) {
|
||||||
final SignalServiceDataMessage.Sticker sticker = message.getSticker().get();
|
final SignalServiceDataMessage.Sticker sticker = message.getSticker().get();
|
||||||
System.out.println("Sticker:");
|
System.out.println("Sticker:");
|
||||||
System.out.println(" - Pack id: " + Base64.encodeBytes(sticker.getPackId()));
|
System.out.println(" - Pack id: " + Base64.getEncoder().encodeToString(sticker.getPackId()));
|
||||||
System.out.println(" - Pack key: " + Base64.encodeBytes(sticker.getPackKey()));
|
System.out.println(" - Pack key: " + Base64.getEncoder().encodeToString(sticker.getPackKey()));
|
||||||
System.out.println(" - Sticker id: " + sticker.getStickerId());
|
System.out.println(" - Sticker id: " + sticker.getStickerId());
|
||||||
// TODO also download sticker image ??
|
// TODO also download sticker image ??
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,9 +20,9 @@ import org.freedesktop.dbus.connections.impl.DBusConnection;
|
||||||
import org.freedesktop.dbus.exceptions.DBusException;
|
import org.freedesktop.dbus.exceptions.DBusException;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.whispersystems.util.Base64;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Base64;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import static org.asamk.signal.util.ErrorUtils.handleAssertionError;
|
import static org.asamk.signal.util.ErrorUtils.handleAssertionError;
|
||||||
|
@ -81,7 +81,7 @@ public class ReceiveCommand implements ExtendedDbusCommand, LocalCommand {
|
||||||
messageReceived.getMessage()));
|
messageReceived.getMessage()));
|
||||||
if (messageReceived.getGroupId().length > 0) {
|
if (messageReceived.getGroupId().length > 0) {
|
||||||
System.out.println("Group info:");
|
System.out.println("Group info:");
|
||||||
System.out.println(" Id: " + Base64.encodeBytes(messageReceived.getGroupId()));
|
System.out.println(" Id: " + Base64.getEncoder().encodeToString(messageReceived.getGroupId()));
|
||||||
}
|
}
|
||||||
if (messageReceived.getAttachments().size() > 0) {
|
if (messageReceived.getAttachments().size() > 0) {
|
||||||
System.out.println("Attachments: ");
|
System.out.println("Attachments: ");
|
||||||
|
@ -130,7 +130,7 @@ public class ReceiveCommand implements ExtendedDbusCommand, LocalCommand {
|
||||||
syncReceived.getMessage()));
|
syncReceived.getMessage()));
|
||||||
if (syncReceived.getGroupId().length > 0) {
|
if (syncReceived.getGroupId().length > 0) {
|
||||||
System.out.println("Group info:");
|
System.out.println("Group info:");
|
||||||
System.out.println(" Id: " + Base64.encodeBytes(syncReceived.getGroupId()));
|
System.out.println(" Id: " + Base64.getEncoder().encodeToString(syncReceived.getGroupId()));
|
||||||
}
|
}
|
||||||
if (syncReceived.getAttachments().size() > 0) {
|
if (syncReceived.getAttachments().size() > 0) {
|
||||||
System.out.println("Attachments: ");
|
System.out.println("Attachments: ");
|
||||||
|
|
|
@ -7,9 +7,9 @@ import org.asamk.Signal;
|
||||||
import org.asamk.signal.manager.groups.GroupIdFormatException;
|
import org.asamk.signal.manager.groups.GroupIdFormatException;
|
||||||
import org.asamk.signal.util.Util;
|
import org.asamk.signal.util.Util;
|
||||||
import org.freedesktop.dbus.exceptions.DBusExecutionException;
|
import org.freedesktop.dbus.exceptions.DBusExecutionException;
|
||||||
import org.whispersystems.util.Base64;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Base64;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.asamk.signal.util.ErrorUtils.handleAssertionError;
|
import static org.asamk.signal.util.ErrorUtils.handleAssertionError;
|
||||||
|
@ -58,7 +58,7 @@ public class UpdateGroupCommand implements DbusCommand {
|
||||||
try {
|
try {
|
||||||
byte[] newGroupId = signal.updateGroup(groupId, groupName, groupMembers, groupAvatar);
|
byte[] newGroupId = signal.updateGroup(groupId, groupName, groupMembers, groupAvatar);
|
||||||
if (groupId.length != newGroupId.length) {
|
if (groupId.length != newGroupId.length) {
|
||||||
System.out.println("Creating new group \"" + Base64.encodeBytes(newGroupId) + "\" …");
|
System.out.println("Creating new group \"" + Base64.getEncoder().encodeToString(newGroupId) + "\" …");
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
} catch (AssertionError e) {
|
} catch (AssertionError e) {
|
||||||
|
|
|
@ -4,9 +4,9 @@ import org.asamk.signal.manager.groups.GroupUtils;
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceGroup;
|
import org.whispersystems.signalservice.api.messages.SignalServiceGroup;
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceGroupV2;
|
import org.whispersystems.signalservice.api.messages.SignalServiceGroupV2;
|
||||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
||||||
import org.whispersystems.util.Base64;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Base64;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
class JsonGroupInfo {
|
class JsonGroupInfo {
|
||||||
|
@ -17,7 +17,7 @@ class JsonGroupInfo {
|
||||||
String type;
|
String type;
|
||||||
|
|
||||||
JsonGroupInfo(SignalServiceGroup groupInfo) {
|
JsonGroupInfo(SignalServiceGroup groupInfo) {
|
||||||
this.groupId = Base64.encodeBytes(groupInfo.getGroupId());
|
this.groupId = Base64.getEncoder().encodeToString(groupInfo.getGroupId());
|
||||||
if (groupInfo.getMembers().isPresent()) {
|
if (groupInfo.getMembers().isPresent()) {
|
||||||
this.members = new ArrayList<>(groupInfo.getMembers().get().size());
|
this.members = new ArrayList<>(groupInfo.getMembers().get().size());
|
||||||
for (SignalServiceAddress address : groupInfo.getMembers().get()) {
|
for (SignalServiceAddress address : groupInfo.getMembers().get()) {
|
||||||
|
@ -36,6 +36,6 @@ class JsonGroupInfo {
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonGroupInfo(byte[] groupId) {
|
JsonGroupInfo(byte[] groupId) {
|
||||||
this.groupId = Base64.encodeBytes(groupId);
|
this.groupId = Base64.getEncoder().encodeToString(groupId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
package org.asamk.signal.json;
|
package org.asamk.signal.json;
|
||||||
|
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
|
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
|
||||||
import org.whispersystems.util.Base64;
|
|
||||||
|
import java.util.Base64;
|
||||||
|
|
||||||
public class JsonSticker {
|
public class JsonSticker {
|
||||||
|
|
||||||
|
@ -10,8 +11,8 @@ public class JsonSticker {
|
||||||
int stickerId;
|
int stickerId;
|
||||||
|
|
||||||
public JsonSticker(SignalServiceDataMessage.Sticker sticker) {
|
public JsonSticker(SignalServiceDataMessage.Sticker sticker) {
|
||||||
this.packId = Base64.encodeBytes(sticker.getPackId());
|
this.packId = Base64.getEncoder().encodeToString(sticker.getPackId());
|
||||||
this.packKey = Base64.encodeBytes(sticker.getPackKey());
|
this.packKey = Base64.getEncoder().encodeToString(sticker.getPackKey());
|
||||||
this.stickerId = sticker.getStickerId();
|
this.stickerId = sticker.getStickerId();
|
||||||
// TODO also download sticker image ??
|
// TODO also download sticker image ??
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,13 +3,12 @@ package org.asamk.signal.manager;
|
||||||
import org.whispersystems.libsignal.InvalidKeyException;
|
import org.whispersystems.libsignal.InvalidKeyException;
|
||||||
import org.whispersystems.libsignal.ecc.Curve;
|
import org.whispersystems.libsignal.ecc.Curve;
|
||||||
import org.whispersystems.libsignal.ecc.ECPublicKey;
|
import org.whispersystems.libsignal.ecc.ECPublicKey;
|
||||||
import org.whispersystems.util.Base64;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URLDecoder;
|
import java.net.URLDecoder;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.Base64;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -20,7 +19,7 @@ public class DeviceLinkInfo {
|
||||||
final String deviceIdentifier;
|
final String deviceIdentifier;
|
||||||
final ECPublicKey deviceKey;
|
final ECPublicKey deviceKey;
|
||||||
|
|
||||||
public static DeviceLinkInfo parseDeviceLinkUri(URI linkUri) throws IOException, InvalidKeyException {
|
public static DeviceLinkInfo parseDeviceLinkUri(URI linkUri) throws InvalidKeyException {
|
||||||
final String rawQuery = linkUri.getRawQuery();
|
final String rawQuery = linkUri.getRawQuery();
|
||||||
if (isEmpty(rawQuery)) {
|
if (isEmpty(rawQuery)) {
|
||||||
throw new RuntimeException("Invalid device link uri");
|
throw new RuntimeException("Invalid device link uri");
|
||||||
|
@ -34,7 +33,13 @@ public class DeviceLinkInfo {
|
||||||
throw new RuntimeException("Invalid device link uri");
|
throw new RuntimeException("Invalid device link uri");
|
||||||
}
|
}
|
||||||
|
|
||||||
ECPublicKey deviceKey = Curve.decodePoint(Base64.decode(publicKeyEncoded), 0);
|
final byte[] publicKeyBytes;
|
||||||
|
try {
|
||||||
|
publicKeyBytes = Base64.getDecoder().decode(publicKeyEncoded);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
throw new RuntimeException("Invalid device link uri", e);
|
||||||
|
}
|
||||||
|
ECPublicKey deviceKey = Curve.decodePoint(publicKeyBytes, 0);
|
||||||
|
|
||||||
return new DeviceLinkInfo(deviceIdentifier, deviceKey);
|
return new DeviceLinkInfo(deviceIdentifier, deviceKey);
|
||||||
}
|
}
|
||||||
|
@ -57,9 +62,10 @@ public class DeviceLinkInfo {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String createDeviceLinkUri() {
|
public String createDeviceLinkUri() {
|
||||||
|
final String deviceKeyString = Base64.getEncoder().encodeToString(deviceKey.serialize()).replace("=", "");
|
||||||
return "tsdevice:/?uuid="
|
return "tsdevice:/?uuid="
|
||||||
+ URLEncoder.encode(deviceIdentifier, StandardCharsets.UTF_8)
|
+ URLEncoder.encode(deviceIdentifier, StandardCharsets.UTF_8)
|
||||||
+ "&pub_key="
|
+ "&pub_key="
|
||||||
+ URLEncoder.encode(Base64.encodeBytesWithoutPadding(deviceKey.serialize()), StandardCharsets.UTF_8);
|
+ URLEncoder.encode(deviceKeyString, StandardCharsets.UTF_8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
package org.asamk.signal.manager.groups;
|
package org.asamk.signal.manager.groups;
|
||||||
|
|
||||||
import org.whispersystems.util.Base64;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Base64;
|
||||||
|
|
||||||
public abstract class GroupId {
|
public abstract class GroupId {
|
||||||
|
|
||||||
|
@ -43,7 +42,7 @@ public abstract class GroupId {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toBase64() {
|
public String toBase64() {
|
||||||
return Base64.encodeBytes(id);
|
return Base64.getEncoder().encodeToString(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -41,7 +41,6 @@ import org.whispersystems.libsignal.util.Pair;
|
||||||
import org.whispersystems.signalservice.api.crypto.UnidentifiedAccess;
|
import org.whispersystems.signalservice.api.crypto.UnidentifiedAccess;
|
||||||
import org.whispersystems.signalservice.api.kbs.MasterKey;
|
import org.whispersystems.signalservice.api.kbs.MasterKey;
|
||||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
||||||
import org.whispersystems.util.Base64;
|
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
@ -53,6 +52,7 @@ import java.nio.channels.Channels;
|
||||||
import java.nio.channels.ClosedChannelException;
|
import java.nio.channels.ClosedChannelException;
|
||||||
import java.nio.channels.FileChannel;
|
import java.nio.channels.FileChannel;
|
||||||
import java.nio.channels.FileLock;
|
import java.nio.channels.FileLock;
|
||||||
|
import java.util.Base64;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
@ -200,8 +200,8 @@ public class SignalAccount implements Closeable {
|
||||||
}
|
}
|
||||||
final ProfileKey profileKey;
|
final ProfileKey profileKey;
|
||||||
try {
|
try {
|
||||||
profileKey = new ProfileKey(Base64.decode(profileKeyString));
|
profileKey = new ProfileKey(Base64.getDecoder().decode(profileKeyString));
|
||||||
} catch (InvalidInputException | IOException e) {
|
} catch (InvalidInputException ignored) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
contact.profileKey = null;
|
contact.profileKey = null;
|
||||||
|
@ -264,7 +264,7 @@ public class SignalAccount implements Closeable {
|
||||||
JsonNode pinMasterKeyNode = rootNode.get("pinMasterKey");
|
JsonNode pinMasterKeyNode = rootNode.get("pinMasterKey");
|
||||||
pinMasterKey = pinMasterKeyNode == null || pinMasterKeyNode.isNull()
|
pinMasterKey = pinMasterKeyNode == null || pinMasterKeyNode.isNull()
|
||||||
? null
|
? null
|
||||||
: new MasterKey(Base64.decode(pinMasterKeyNode.asText()));
|
: new MasterKey(Base64.getDecoder().decode(pinMasterKeyNode.asText()));
|
||||||
if (rootNode.has("signalingKey")) {
|
if (rootNode.has("signalingKey")) {
|
||||||
signalingKey = Utils.getNotNullNode(rootNode, "signalingKey").asText();
|
signalingKey = Utils.getNotNullNode(rootNode, "signalingKey").asText();
|
||||||
}
|
}
|
||||||
|
@ -280,7 +280,8 @@ public class SignalAccount implements Closeable {
|
||||||
}
|
}
|
||||||
if (rootNode.has("profileKey")) {
|
if (rootNode.has("profileKey")) {
|
||||||
try {
|
try {
|
||||||
profileKey = new ProfileKey(Base64.decode(Utils.getNotNullNode(rootNode, "profileKey").asText()));
|
profileKey = new ProfileKey(Base64.getDecoder()
|
||||||
|
.decode(Utils.getNotNullNode(rootNode, "profileKey").asText()));
|
||||||
} catch (InvalidInputException e) {
|
} catch (InvalidInputException e) {
|
||||||
throw new IOException(
|
throw new IOException(
|
||||||
"Config file contains an invalid profileKey, needs to be base64 encoded array of 32 bytes",
|
"Config file contains an invalid profileKey, needs to be base64 encoded array of 32 bytes",
|
||||||
|
@ -395,11 +396,12 @@ public class SignalAccount implements Closeable {
|
||||||
.put("isMultiDevice", isMultiDevice)
|
.put("isMultiDevice", isMultiDevice)
|
||||||
.put("password", password)
|
.put("password", password)
|
||||||
.put("registrationLockPin", registrationLockPin)
|
.put("registrationLockPin", registrationLockPin)
|
||||||
.put("pinMasterKey", pinMasterKey == null ? null : Base64.encodeBytes(pinMasterKey.serialize()))
|
.put("pinMasterKey",
|
||||||
|
pinMasterKey == null ? null : Base64.getEncoder().encodeToString(pinMasterKey.serialize()))
|
||||||
.put("signalingKey", signalingKey)
|
.put("signalingKey", signalingKey)
|
||||||
.put("preKeyIdOffset", preKeyIdOffset)
|
.put("preKeyIdOffset", preKeyIdOffset)
|
||||||
.put("nextSignedPreKeyId", nextSignedPreKeyId)
|
.put("nextSignedPreKeyId", nextSignedPreKeyId)
|
||||||
.put("profileKey", Base64.encodeBytes(profileKey.serialize()))
|
.put("profileKey", Base64.getEncoder().encodeToString(profileKey.serialize()))
|
||||||
.put("registered", registered)
|
.put("registered", registered)
|
||||||
.putPOJO("axolotlStore", signalProtocolStore)
|
.putPOJO("axolotlStore", signalProtocolStore)
|
||||||
.putPOJO("groupStore", groupStore)
|
.putPOJO("groupStore", groupStore)
|
||||||
|
|
|
@ -23,13 +23,13 @@ import org.signal.zkgroup.InvalidInputException;
|
||||||
import org.signal.zkgroup.groups.GroupMasterKey;
|
import org.signal.zkgroup.groups.GroupMasterKey;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.whispersystems.util.Base64;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Base64;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -161,7 +161,8 @@ public class JsonGroupStore {
|
||||||
final GroupInfoV2 groupV2 = (GroupInfoV2) group;
|
final GroupInfoV2 groupV2 = (GroupInfoV2) group;
|
||||||
jgen.writeStartObject();
|
jgen.writeStartObject();
|
||||||
jgen.writeStringField("groupId", groupV2.getGroupId().toBase64());
|
jgen.writeStringField("groupId", groupV2.getGroupId().toBase64());
|
||||||
jgen.writeStringField("masterKey", Base64.encodeBytes(groupV2.getMasterKey().serialize()));
|
jgen.writeStringField("masterKey",
|
||||||
|
Base64.getEncoder().encodeToString(groupV2.getMasterKey().serialize()));
|
||||||
jgen.writeBooleanField("blocked", groupV2.isBlocked());
|
jgen.writeBooleanField("blocked", groupV2.isBlocked());
|
||||||
jgen.writeEndObject();
|
jgen.writeEndObject();
|
||||||
} else {
|
} else {
|
||||||
|
@ -186,15 +187,15 @@ public class JsonGroupStore {
|
||||||
// a v2 group
|
// a v2 group
|
||||||
GroupIdV2 groupId = GroupIdV2.fromBase64(n.get("groupId").asText());
|
GroupIdV2 groupId = GroupIdV2.fromBase64(n.get("groupId").asText());
|
||||||
try {
|
try {
|
||||||
GroupMasterKey masterKey = new GroupMasterKey(Base64.decode(n.get("masterKey").asText()));
|
GroupMasterKey masterKey = new GroupMasterKey(Base64.getDecoder()
|
||||||
|
.decode(n.get("masterKey").asText()));
|
||||||
g = new GroupInfoV2(groupId, masterKey);
|
g = new GroupInfoV2(groupId, masterKey);
|
||||||
} catch (InvalidInputException e) {
|
} catch (InvalidInputException | IllegalArgumentException e) {
|
||||||
throw new AssertionError("Invalid master key for group " + groupId.toBase64());
|
throw new AssertionError("Invalid master key for group " + groupId.toBase64());
|
||||||
}
|
}
|
||||||
g.setBlocked(n.get("blocked").asBoolean(false));
|
g.setBlocked(n.get("blocked").asBoolean(false));
|
||||||
} else {
|
} else {
|
||||||
GroupInfoV1 gv1 = jsonProcessor.treeToValue(n, GroupInfoV1.class);
|
g = jsonProcessor.treeToValue(n, GroupInfoV1.class);
|
||||||
g = gv1;
|
|
||||||
}
|
}
|
||||||
groups.put(g.getGroupId(), g);
|
groups.put(g.getGroupId(), g);
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,10 +17,10 @@ import org.signal.zkgroup.profiles.ProfileKey;
|
||||||
import org.signal.zkgroup.profiles.ProfileKeyCredential;
|
import org.signal.zkgroup.profiles.ProfileKeyCredential;
|
||||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
||||||
import org.whispersystems.signalservice.api.util.UuidUtil;
|
import org.whispersystems.signalservice.api.util.UuidUtil;
|
||||||
import org.whispersystems.util.Base64;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Base64;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@ -104,14 +104,14 @@ public class ProfileStore {
|
||||||
final SignalServiceAddress serviceAddress = new SignalServiceAddress(uuid, name);
|
final SignalServiceAddress serviceAddress = new SignalServiceAddress(uuid, name);
|
||||||
ProfileKey profileKey = null;
|
ProfileKey profileKey = null;
|
||||||
try {
|
try {
|
||||||
profileKey = new ProfileKey(Base64.decode(entry.get("profileKey").asText()));
|
profileKey = new ProfileKey(Base64.getDecoder().decode(entry.get("profileKey").asText()));
|
||||||
} catch (InvalidInputException ignored) {
|
} catch (InvalidInputException ignored) {
|
||||||
}
|
}
|
||||||
ProfileKeyCredential profileKeyCredential = null;
|
ProfileKeyCredential profileKeyCredential = null;
|
||||||
if (entry.hasNonNull("profileKeyCredential")) {
|
if (entry.hasNonNull("profileKeyCredential")) {
|
||||||
try {
|
try {
|
||||||
profileKeyCredential = new ProfileKeyCredential(Base64.decode(entry.get(
|
profileKeyCredential = new ProfileKeyCredential(Base64.getDecoder()
|
||||||
"profileKeyCredential").asText()));
|
.decode(entry.get("profileKeyCredential").asText()));
|
||||||
} catch (Throwable ignored) {
|
} catch (Throwable ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -145,12 +145,13 @@ public class ProfileStore {
|
||||||
if (address.getUuid().isPresent()) {
|
if (address.getUuid().isPresent()) {
|
||||||
json.writeStringField("uuid", address.getUuid().get().toString());
|
json.writeStringField("uuid", address.getUuid().get().toString());
|
||||||
}
|
}
|
||||||
json.writeStringField("profileKey", Base64.encodeBytes(profileEntry.getProfileKey().serialize()));
|
json.writeStringField("profileKey",
|
||||||
|
Base64.getEncoder().encodeToString(profileEntry.getProfileKey().serialize()));
|
||||||
json.writeNumberField("lastUpdateTimestamp", profileEntry.getLastUpdateTimestamp());
|
json.writeNumberField("lastUpdateTimestamp", profileEntry.getLastUpdateTimestamp());
|
||||||
json.writeObjectField("profile", profileEntry.getProfile());
|
json.writeObjectField("profile", profileEntry.getProfile());
|
||||||
if (profileEntry.getProfileKeyCredential() != null) {
|
if (profileEntry.getProfileKeyCredential() != null) {
|
||||||
json.writeStringField("profileKeyCredential",
|
json.writeStringField("profileKeyCredential",
|
||||||
Base64.encodeBytes(profileEntry.getProfileKeyCredential().serialize()));
|
Base64.getEncoder().encodeToString(profileEntry.getProfileKeyCredential().serialize()));
|
||||||
}
|
}
|
||||||
json.writeEndObject();
|
json.writeEndObject();
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,10 +19,10 @@ import org.whispersystems.libsignal.SignalProtocolAddress;
|
||||||
import org.whispersystems.libsignal.state.IdentityKeyStore;
|
import org.whispersystems.libsignal.state.IdentityKeyStore;
|
||||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
||||||
import org.whispersystems.signalservice.api.util.UuidUtil;
|
import org.whispersystems.signalservice.api.util.UuidUtil;
|
||||||
import org.whispersystems.util.Base64;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Base64;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
@ -196,7 +196,8 @@ public class JsonIdentityKeyStore implements IdentityKeyStore {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
int localRegistrationId = node.get("registrationId").asInt();
|
int localRegistrationId = node.get("registrationId").asInt();
|
||||||
IdentityKeyPair identityKeyPair = new IdentityKeyPair(Base64.decode(node.get("identityKey").asText()));
|
IdentityKeyPair identityKeyPair = new IdentityKeyPair(Base64.getDecoder()
|
||||||
|
.decode(node.get("identityKey").asText()));
|
||||||
|
|
||||||
JsonIdentityKeyStore keyStore = new JsonIdentityKeyStore(identityKeyPair, localRegistrationId);
|
JsonIdentityKeyStore keyStore = new JsonIdentityKeyStore(identityKeyPair, localRegistrationId);
|
||||||
|
|
||||||
|
@ -216,13 +217,14 @@ public class JsonIdentityKeyStore implements IdentityKeyStore {
|
||||||
? Utils.getSignalServiceAddressFromIdentifier(trustedKeyName)
|
? Utils.getSignalServiceAddressFromIdentifier(trustedKeyName)
|
||||||
: new SignalServiceAddress(uuid, trustedKeyName);
|
: new SignalServiceAddress(uuid, trustedKeyName);
|
||||||
try {
|
try {
|
||||||
IdentityKey id = new IdentityKey(Base64.decode(trustedKey.get("identityKey").asText()), 0);
|
IdentityKey id = new IdentityKey(Base64.getDecoder()
|
||||||
|
.decode(trustedKey.get("identityKey").asText()), 0);
|
||||||
TrustLevel trustLevel = trustedKey.has("trustLevel") ? TrustLevel.fromInt(trustedKey.get(
|
TrustLevel trustLevel = trustedKey.has("trustLevel") ? TrustLevel.fromInt(trustedKey.get(
|
||||||
"trustLevel").asInt()) : TrustLevel.TRUSTED_UNVERIFIED;
|
"trustLevel").asInt()) : TrustLevel.TRUSTED_UNVERIFIED;
|
||||||
Date added = trustedKey.has("addedTimestamp") ? new Date(trustedKey.get("addedTimestamp")
|
Date added = trustedKey.has("addedTimestamp") ? new Date(trustedKey.get("addedTimestamp")
|
||||||
.asLong()) : new Date();
|
.asLong()) : new Date();
|
||||||
keyStore.saveIdentity(serviceAddress, id, trustLevel, added);
|
keyStore.saveIdentity(serviceAddress, id, trustLevel, added);
|
||||||
} catch (InvalidKeyException | IOException e) {
|
} catch (InvalidKeyException e) {
|
||||||
logger.warn("Error while decoding key for {}: {}", trustedKeyName, e.getMessage());
|
logger.warn("Error while decoding key for {}: {}", trustedKeyName, e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -244,7 +246,13 @@ public class JsonIdentityKeyStore implements IdentityKeyStore {
|
||||||
json.writeStartObject();
|
json.writeStartObject();
|
||||||
json.writeNumberField("registrationId", jsonIdentityKeyStore.getLocalRegistrationId());
|
json.writeNumberField("registrationId", jsonIdentityKeyStore.getLocalRegistrationId());
|
||||||
json.writeStringField("identityKey",
|
json.writeStringField("identityKey",
|
||||||
Base64.encodeBytes(jsonIdentityKeyStore.getIdentityKeyPair().serialize()));
|
Base64.getEncoder().encodeToString(jsonIdentityKeyStore.getIdentityKeyPair().serialize()));
|
||||||
|
json.writeStringField("identityPrivateKey",
|
||||||
|
Base64.getEncoder()
|
||||||
|
.encodeToString(jsonIdentityKeyStore.getIdentityKeyPair().getPrivateKey().serialize()));
|
||||||
|
json.writeStringField("identityPublicKey",
|
||||||
|
Base64.getEncoder()
|
||||||
|
.encodeToString(jsonIdentityKeyStore.getIdentityKeyPair().getPublicKey().serialize()));
|
||||||
json.writeArrayFieldStart("trustedKeys");
|
json.writeArrayFieldStart("trustedKeys");
|
||||||
for (IdentityInfo trustedKey : jsonIdentityKeyStore.identities) {
|
for (IdentityInfo trustedKey : jsonIdentityKeyStore.identities) {
|
||||||
json.writeStartObject();
|
json.writeStartObject();
|
||||||
|
@ -254,7 +262,8 @@ public class JsonIdentityKeyStore implements IdentityKeyStore {
|
||||||
if (trustedKey.getAddress().getUuid().isPresent()) {
|
if (trustedKey.getAddress().getUuid().isPresent()) {
|
||||||
json.writeStringField("uuid", trustedKey.getAddress().getUuid().get().toString());
|
json.writeStringField("uuid", trustedKey.getAddress().getUuid().get().toString());
|
||||||
}
|
}
|
||||||
json.writeStringField("identityKey", Base64.encodeBytes(trustedKey.identityKey.serialize()));
|
json.writeStringField("identityKey",
|
||||||
|
Base64.getEncoder().encodeToString(trustedKey.identityKey.serialize()));
|
||||||
json.writeNumberField("trustLevel", trustedKey.trustLevel.ordinal());
|
json.writeNumberField("trustLevel", trustedKey.trustLevel.ordinal());
|
||||||
json.writeNumberField("addedTimestamp", trustedKey.added.getTime());
|
json.writeNumberField("addedTimestamp", trustedKey.added.getTime());
|
||||||
json.writeEndObject();
|
json.writeEndObject();
|
||||||
|
@ -263,5 +272,4 @@ public class JsonIdentityKeyStore implements IdentityKeyStore {
|
||||||
json.writeEndObject();
|
json.writeEndObject();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,9 +13,9 @@ import org.slf4j.LoggerFactory;
|
||||||
import org.whispersystems.libsignal.InvalidKeyIdException;
|
import org.whispersystems.libsignal.InvalidKeyIdException;
|
||||||
import org.whispersystems.libsignal.state.PreKeyRecord;
|
import org.whispersystems.libsignal.state.PreKeyRecord;
|
||||||
import org.whispersystems.libsignal.state.PreKeyStore;
|
import org.whispersystems.libsignal.state.PreKeyStore;
|
||||||
import org.whispersystems.util.Base64;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Base64;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -72,12 +72,9 @@ class JsonPreKeyStore implements PreKeyStore {
|
||||||
Map<Integer, byte[]> preKeyMap = new HashMap<>();
|
Map<Integer, byte[]> preKeyMap = new HashMap<>();
|
||||||
if (node.isArray()) {
|
if (node.isArray()) {
|
||||||
for (JsonNode preKey : node) {
|
for (JsonNode preKey : node) {
|
||||||
Integer preKeyId = preKey.get("id").asInt();
|
final int preKeyId = preKey.get("id").asInt();
|
||||||
try {
|
final byte[] preKeyRecord = Base64.getDecoder().decode(preKey.get("record").asText());
|
||||||
preKeyMap.put(preKeyId, Base64.decode(preKey.get("record").asText()));
|
preKeyMap.put(preKeyId, preKeyRecord);
|
||||||
} catch (IOException e) {
|
|
||||||
logger.warn("Error while decoding prekey for {}: {}", preKeyId, e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,7 +82,6 @@ class JsonPreKeyStore implements PreKeyStore {
|
||||||
keyStore.addPreKeys(preKeyMap);
|
keyStore.addPreKeys(preKeyMap);
|
||||||
|
|
||||||
return keyStore;
|
return keyStore;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,7 +95,7 @@ class JsonPreKeyStore implements PreKeyStore {
|
||||||
for (Map.Entry<Integer, byte[]> preKey : jsonPreKeyStore.store.entrySet()) {
|
for (Map.Entry<Integer, byte[]> preKey : jsonPreKeyStore.store.entrySet()) {
|
||||||
json.writeStartObject();
|
json.writeStartObject();
|
||||||
json.writeNumberField("id", preKey.getKey());
|
json.writeNumberField("id", preKey.getKey());
|
||||||
json.writeStringField("record", Base64.encodeBytes(preKey.getValue()));
|
json.writeStringField("record", Base64.getEncoder().encodeToString(preKey.getValue()));
|
||||||
json.writeEndObject();
|
json.writeEndObject();
|
||||||
}
|
}
|
||||||
json.writeEndArray();
|
json.writeEndArray();
|
||||||
|
|
|
@ -16,10 +16,10 @@ import org.whispersystems.libsignal.state.SessionRecord;
|
||||||
import org.whispersystems.libsignal.state.SessionStore;
|
import org.whispersystems.libsignal.state.SessionStore;
|
||||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
||||||
import org.whispersystems.signalservice.api.util.UuidUtil;
|
import org.whispersystems.signalservice.api.util.UuidUtil;
|
||||||
import org.whispersystems.util.Base64;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Base64;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
@ -150,13 +150,9 @@ class JsonSessionStore implements SessionStore {
|
||||||
? Utils.getSignalServiceAddressFromIdentifier(sessionName)
|
? Utils.getSignalServiceAddressFromIdentifier(sessionName)
|
||||||
: new SignalServiceAddress(uuid, sessionName);
|
: new SignalServiceAddress(uuid, sessionName);
|
||||||
final int deviceId = session.get("deviceId").asInt();
|
final int deviceId = session.get("deviceId").asInt();
|
||||||
final String record = session.get("record").asText();
|
final byte[] record = Base64.getDecoder().decode(session.get("record").asText());
|
||||||
try {
|
SessionInfo sessionInfo = new SessionInfo(serviceAddress, deviceId, record);
|
||||||
SessionInfo sessionInfo = new SessionInfo(serviceAddress, deviceId, Base64.decode(record));
|
sessionStore.sessions.add(sessionInfo);
|
||||||
sessionStore.sessions.add(sessionInfo);
|
|
||||||
} catch (IOException e) {
|
|
||||||
logger.warn("Error while decoding session for {}: {}", sessionName, e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,7 +176,7 @@ class JsonSessionStore implements SessionStore {
|
||||||
json.writeStringField("uuid", sessionInfo.address.getUuid().get().toString());
|
json.writeStringField("uuid", sessionInfo.address.getUuid().get().toString());
|
||||||
}
|
}
|
||||||
json.writeNumberField("deviceId", sessionInfo.deviceId);
|
json.writeNumberField("deviceId", sessionInfo.deviceId);
|
||||||
json.writeStringField("record", Base64.encodeBytes(sessionInfo.sessionRecord));
|
json.writeStringField("record", Base64.getEncoder().encodeToString(sessionInfo.sessionRecord));
|
||||||
json.writeEndObject();
|
json.writeEndObject();
|
||||||
}
|
}
|
||||||
json.writeEndArray();
|
json.writeEndArray();
|
||||||
|
|
|
@ -13,9 +13,9 @@ import org.slf4j.LoggerFactory;
|
||||||
import org.whispersystems.libsignal.InvalidKeyIdException;
|
import org.whispersystems.libsignal.InvalidKeyIdException;
|
||||||
import org.whispersystems.libsignal.state.SignedPreKeyRecord;
|
import org.whispersystems.libsignal.state.SignedPreKeyRecord;
|
||||||
import org.whispersystems.libsignal.state.SignedPreKeyStore;
|
import org.whispersystems.libsignal.state.SignedPreKeyStore;
|
||||||
import org.whispersystems.util.Base64;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Base64;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -89,12 +89,9 @@ class JsonSignedPreKeyStore implements SignedPreKeyStore {
|
||||||
Map<Integer, byte[]> preKeyMap = new HashMap<>();
|
Map<Integer, byte[]> preKeyMap = new HashMap<>();
|
||||||
if (node.isArray()) {
|
if (node.isArray()) {
|
||||||
for (JsonNode preKey : node) {
|
for (JsonNode preKey : node) {
|
||||||
Integer preKeyId = preKey.get("id").asInt();
|
final int preKeyId = preKey.get("id").asInt();
|
||||||
try {
|
final byte[] preKeyRecord = Base64.getDecoder().decode(preKey.get("record").asText());
|
||||||
preKeyMap.put(preKeyId, Base64.decode(preKey.get("record").asText()));
|
preKeyMap.put(preKeyId, preKeyRecord);
|
||||||
} catch (IOException e) {
|
|
||||||
logger.warn("Error while decoding prekey for {}: {}", preKeyId, e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,7 +99,6 @@ class JsonSignedPreKeyStore implements SignedPreKeyStore {
|
||||||
keyStore.addSignedPreKeys(preKeyMap);
|
keyStore.addSignedPreKeys(preKeyMap);
|
||||||
|
|
||||||
return keyStore;
|
return keyStore;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,7 +112,7 @@ class JsonSignedPreKeyStore implements SignedPreKeyStore {
|
||||||
for (Map.Entry<Integer, byte[]> signedPreKey : jsonPreKeyStore.store.entrySet()) {
|
for (Map.Entry<Integer, byte[]> signedPreKey : jsonPreKeyStore.store.entrySet()) {
|
||||||
json.writeStartObject();
|
json.writeStartObject();
|
||||||
json.writeNumberField("id", signedPreKey.getKey());
|
json.writeNumberField("id", signedPreKey.getKey());
|
||||||
json.writeStringField("record", Base64.encodeBytes(signedPreKey.getValue()));
|
json.writeStringField("record", Base64.getEncoder().encodeToString(signedPreKey.getValue()));
|
||||||
json.writeEndObject();
|
json.writeEndObject();
|
||||||
}
|
}
|
||||||
json.writeEndArray();
|
json.writeEndArray();
|
||||||
|
|
|
@ -6,22 +6,18 @@ import com.fasterxml.jackson.databind.DeserializationContext;
|
||||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import com.fasterxml.jackson.databind.JsonSerializer;
|
import com.fasterxml.jackson.databind.JsonSerializer;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||||
|
|
||||||
import org.whispersystems.util.Base64;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Base64;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class StickerStore {
|
public class StickerStore {
|
||||||
|
|
||||||
private static final ObjectMapper jsonProcessor = new ObjectMapper();
|
|
||||||
|
|
||||||
@JsonSerialize(using = StickersSerializer.class)
|
@JsonSerialize(using = StickersSerializer.class)
|
||||||
@JsonDeserialize(using = StickersDeserializer.class)
|
@JsonDeserialize(using = StickersDeserializer.class)
|
||||||
private final Map<byte[], Sticker> stickers = new HashMap<>();
|
private final Map<byte[], Sticker> stickers = new HashMap<>();
|
||||||
|
@ -44,8 +40,8 @@ public class StickerStore {
|
||||||
jgen.writeStartArray(stickers.size());
|
jgen.writeStartArray(stickers.size());
|
||||||
for (Sticker sticker : stickers) {
|
for (Sticker sticker : stickers) {
|
||||||
jgen.writeStartObject();
|
jgen.writeStartObject();
|
||||||
jgen.writeStringField("packId", Base64.encodeBytes(sticker.getPackId()));
|
jgen.writeStringField("packId", Base64.getEncoder().encodeToString(sticker.getPackId()));
|
||||||
jgen.writeStringField("packKey", Base64.encodeBytes(sticker.getPackKey()));
|
jgen.writeStringField("packKey", Base64.getEncoder().encodeToString(sticker.getPackKey()));
|
||||||
jgen.writeBooleanField("installed", sticker.isInstalled());
|
jgen.writeBooleanField("installed", sticker.isInstalled());
|
||||||
jgen.writeEndObject();
|
jgen.writeEndObject();
|
||||||
}
|
}
|
||||||
|
@ -62,8 +58,8 @@ public class StickerStore {
|
||||||
Map<byte[], Sticker> stickers = new HashMap<>();
|
Map<byte[], Sticker> stickers = new HashMap<>();
|
||||||
JsonNode node = jsonParser.getCodec().readTree(jsonParser);
|
JsonNode node = jsonParser.getCodec().readTree(jsonParser);
|
||||||
for (JsonNode n : node) {
|
for (JsonNode n : node) {
|
||||||
byte[] packId = Base64.decode(n.get("packId").asText());
|
byte[] packId = Base64.getDecoder().decode(n.get("packId").asText());
|
||||||
byte[] packKey = Base64.decode(n.get("packKey").asText());
|
byte[] packKey = Base64.getDecoder().decode(n.get("packKey").asText());
|
||||||
boolean installed = n.get("installed").asBoolean(false);
|
boolean installed = n.get("installed").asBoolean(false);
|
||||||
stickers.put(packId, new Sticker(packId, packKey, installed));
|
stickers.put(packId, new Sticker(packId, packKey, installed));
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,9 +13,9 @@ import org.whispersystems.libsignal.state.PreKeyRecord;
|
||||||
import org.whispersystems.libsignal.state.SignedPreKeyRecord;
|
import org.whispersystems.libsignal.state.SignedPreKeyRecord;
|
||||||
import org.whispersystems.libsignal.util.Medium;
|
import org.whispersystems.libsignal.util.Medium;
|
||||||
import org.whispersystems.signalservice.api.kbs.MasterKey;
|
import org.whispersystems.signalservice.api.kbs.MasterKey;
|
||||||
import org.whispersystems.util.Base64;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Base64;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class KeyUtils {
|
public class KeyUtils {
|
||||||
|
@ -82,7 +82,7 @@ public class KeyUtils {
|
||||||
|
|
||||||
private static String getSecret(int size) {
|
private static String getSecret(int size) {
|
||||||
byte[] secret = getSecretBytes(size);
|
byte[] secret = getSecretBytes(size);
|
||||||
return Base64.encodeBytes(secret);
|
return Base64.getEncoder().encodeToString(secret);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] getSecretBytes(int size) {
|
public static byte[] getSecretBytes(int size) {
|
||||||
|
|
|
@ -5,9 +5,8 @@ import org.signal.zkgroup.profiles.ProfileKey;
|
||||||
import org.whispersystems.signalservice.api.crypto.InvalidCiphertextException;
|
import org.whispersystems.signalservice.api.crypto.InvalidCiphertextException;
|
||||||
import org.whispersystems.signalservice.api.crypto.ProfileCipher;
|
import org.whispersystems.signalservice.api.crypto.ProfileCipher;
|
||||||
import org.whispersystems.signalservice.api.profiles.SignalServiceProfile;
|
import org.whispersystems.signalservice.api.profiles.SignalServiceProfile;
|
||||||
import org.whispersystems.util.Base64;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.util.Base64;
|
||||||
|
|
||||||
public class ProfileUtils {
|
public class ProfileUtils {
|
||||||
|
|
||||||
|
@ -20,17 +19,18 @@ public class ProfileUtils {
|
||||||
try {
|
try {
|
||||||
name = encryptedProfile.getName() == null
|
name = encryptedProfile.getName() == null
|
||||||
? null
|
? null
|
||||||
: new String(profileCipher.decryptName(Base64.decode(encryptedProfile.getName())));
|
: new String(profileCipher.decryptName(Base64.getDecoder().decode(encryptedProfile.getName())));
|
||||||
} catch (IOException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
name = null;
|
name = null;
|
||||||
}
|
}
|
||||||
String unidentifiedAccess;
|
String unidentifiedAccess;
|
||||||
try {
|
try {
|
||||||
unidentifiedAccess = encryptedProfile.getUnidentifiedAccess() == null
|
unidentifiedAccess = encryptedProfile.getUnidentifiedAccess() == null
|
||||||
|| !profileCipher.verifyUnidentifiedAccess(Base64.decode(encryptedProfile.getUnidentifiedAccess()))
|
|| !profileCipher.verifyUnidentifiedAccess(Base64.getDecoder()
|
||||||
|
.decode(encryptedProfile.getUnidentifiedAccess()))
|
||||||
? null
|
? null
|
||||||
: encryptedProfile.getUnidentifiedAccess();
|
: encryptedProfile.getUnidentifiedAccess();
|
||||||
} catch (IOException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
unidentifiedAccess = null;
|
unidentifiedAccess = null;
|
||||||
}
|
}
|
||||||
return new SignalProfile(encryptedProfile.getIdentityKey(),
|
return new SignalProfile(encryptedProfile.getIdentityKey(),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue