/** * * Copyright 2017 Paul Schaub * * This file is part of smack-omemo-signal. * * smack-omemo-signal is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ package org.jivesoftware.smackx.omemo.signal; import org.jivesoftware.smackx.omemo.element.OmemoBundleElement; import org.jivesoftware.smackx.omemo.exceptions.CorruptedOmemoKeyException; import org.jivesoftware.smackx.omemo.internal.OmemoDevice; import org.jivesoftware.smackx.omemo.trust.OmemoFingerprint; import org.jivesoftware.smackx.omemo.util.OmemoKeyUtil; import org.signal.libsignal.protocol.IdentityKey; import org.signal.libsignal.protocol.IdentityKeyPair; import org.signal.libsignal.protocol.InvalidKeyException; import org.signal.libsignal.protocol.InvalidMessageException; import org.signal.libsignal.protocol.ecc.Curve; import org.signal.libsignal.protocol.ecc.ECKeyPair; import org.signal.libsignal.protocol.ecc.ECPublicKey; import org.signal.libsignal.protocol.state.PreKeyBundle; import org.signal.libsignal.protocol.state.PreKeyRecord; import org.signal.libsignal.protocol.state.SessionRecord; import org.signal.libsignal.protocol.state.SignedPreKeyRecord; import org.signal.libsignal.protocol.util.Medium; import java.io.IOException; import java.util.LinkedList; import java.util.List; import java.util.TreeMap; /** * Concrete implementation of the KeyUtil for an implementation using the Signal library. * * @author Paul Schaub */ public class SignalOmemoKeyUtil extends OmemoKeyUtil { @Override public IdentityKeyPair generateOmemoIdentityKeyPair() { return IdentityKeyPair.generate(); } @Override public TreeMap generateOmemoPreKeys(int currentPreKeyId, int count) { List preKeyRecords = generatePreKeys(currentPreKeyId, count); TreeMap map = new TreeMap<>(); for (PreKeyRecord p : preKeyRecords) { map.put(p.getId(), p); } return map; } private static List generatePreKeys(int start, int count) { List results = new LinkedList<>(); start--; for (int i=0;i