account.setProfileKey(KeyUtils.createProfileKey());
account.save();
}
+ // Store profile keys only in profile store
+ for (ContactInfo contact : account.getContactStore().getContacts()) {
+ String profileKeyString = contact.profileKey;
+ if (profileKeyString == null) {
+ continue;
+ }
+ final ProfileKey profileKey;
+ try {
+ profileKey = new ProfileKey(Base64.decode(profileKeyString));
+ } catch (InvalidInputException | IOException e) {
+ continue;
+ }
+ contact.profileKey = null;
+ account.getProfileStore().storeProfileKey(contact.getAddress(), profileKey);
+ }
}
public void checkAccountState() throws IOException {
}
private byte[] getTargetUnidentifiedAccessKey(SignalServiceAddress recipient) {
- ContactInfo contact = account.getContactStore().getContact(recipient);
- if (contact == null || contact.profileKey == null) {
+ ProfileKey theirProfileKey = account.getProfileStore().getProfileKey(recipient);
+ if (theirProfileKey == null) {
return null;
}
- ProfileKey theirProfileKey;
- try {
- theirProfileKey = new ProfileKey(Base64.decode(contact.profileKey));
- } catch (InvalidInputException | IOException e) {
- throw new AssertionError(e);
- }
SignalProfile targetProfile;
try {
targetProfile = getRecipientProfile(recipient, Optional.absent(), theirProfileKey);
}
}
if (message.getProfileKey().isPresent() && message.getProfileKey().get().length == 32) {
+ final ProfileKey profileKey;
+ try {
+ profileKey = new ProfileKey(message.getProfileKey().get());
+ } catch (InvalidInputException e) {
+ throw new AssertionError(e);
+ }
if (source.matches(account.getSelfAddress())) {
- try {
- this.account.setProfileKey(new ProfileKey(message.getProfileKey().get()));
- } catch (InvalidInputException ignored) {
- }
- ContactInfo contact = account.getContactStore().getContact(source);
- if (contact != null) {
- contact.profileKey = Base64.encodeBytes(message.getProfileKey().get());
- account.getContactStore().updateContact(contact);
- }
- } else {
- ContactInfo contact = account.getContactStore().getContact(source);
- if (contact == null) {
- contact = new ContactInfo(source);
- }
- contact.profileKey = Base64.encodeBytes(message.getProfileKey().get());
- account.getContactStore().updateContact(contact);
+ this.account.setProfileKey(profileKey);
}
+ this.account.getProfileStore().storeProfileKey(source, profileKey);
}
if (message.getPreviews().isPresent()) {
final List<SignalServiceDataMessage.Preview> previews = message.getPreviews().get();
contact.color = c.getColor().get();
}
if (c.getProfileKey().isPresent()) {
- contact.profileKey = Base64.encodeBytes(c.getProfileKey().get().serialize());
+ account.getProfileStore().storeProfileKey(address, c.getProfileKey().get());
}
if (c.getVerified().isPresent()) {
final VerifiedMessage verifiedMessage = c.getVerified().get();
verifiedMessage = new VerifiedMessage(record.getAddress(), currentIdentity.getIdentityKey(), currentIdentity.getTrustLevel().toVerifiedState(), currentIdentity.getDateAdded().getTime());
}
- ProfileKey profileKey = null;
- try {
- profileKey = record.profileKey == null ? null : new ProfileKey(Base64.decode(record.profileKey));
- } catch (InvalidInputException ignored) {
- }
+ ProfileKey profileKey = account.getProfileStore().getProfileKey(record.getAddress());
out.write(new DeviceContact(record.getAddress(), Optional.fromNullable(record.name),
createContactAvatarAttachment(record.number), Optional.fromNullable(record.color),
Optional.fromNullable(verifiedMessage), Optional.fromNullable(profileKey), record.blocked,
import java.io.IOException;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
import java.util.UUID;
return null;
}
+ public ProfileKey getProfileKey(SignalServiceAddress serviceAddress) {
+ for (SignalProfileEntry entry : profiles) {
+ if (entry.getServiceAddress().matches(serviceAddress)) {
+ return entry.getProfileKey();
+ }
+ }
+ return null;
+ }
+
public void updateProfile(SignalServiceAddress serviceAddress, ProfileKey profileKey, long now, SignalProfile profile) {
SignalProfileEntry newEntry = new SignalProfileEntry(serviceAddress, profileKey, now, profile);
for (int i = 0; i < profiles.size(); i++) {
profiles.add(newEntry);
}
+ public void storeProfileKey(SignalServiceAddress serviceAddress, ProfileKey profileKey) {
+ SignalProfileEntry newEntry = new SignalProfileEntry(serviceAddress, profileKey, 0, null);
+ for (int i = 0; i < profiles.size(); i++) {
+ if (profiles.get(i).getServiceAddress().matches(serviceAddress)) {
+ if (!profiles.get(i).getProfileKey().equals(profileKey)) {
+ profiles.set(i, newEntry);
+ }
+ return;
+ }
+ }
+
+ profiles.add(newEntry);
+ }
+
public static class ProfileStoreDeserializer extends JsonDeserializer<List<SignalProfileEntry>> {
@Override