org.whispersystems.libsignal.ecc.ECPublicKey Java Examples

The following examples show how to use org.whispersystems.libsignal.ecc.ECPublicKey. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IqGenerator.java    From Pix-Art-Messenger with GNU General Public License v3.0 6 votes vote down vote up
public IqPacket publishBundles(final SignedPreKeyRecord signedPreKeyRecord, final IdentityKey identityKey,
                               final Set<PreKeyRecord> preKeyRecords, final int deviceId, Bundle publishOptions) {
    final Element item = new Element("item");
    item.setAttribute("id", "current");
    final Element bundle = item.addChild("bundle", AxolotlService.PEP_PREFIX);
    final Element signedPreKeyPublic = bundle.addChild("signedPreKeyPublic");
    signedPreKeyPublic.setAttribute("signedPreKeyId", signedPreKeyRecord.getId());
    ECPublicKey publicKey = signedPreKeyRecord.getKeyPair().getPublicKey();
    signedPreKeyPublic.setContent(Base64.encodeToString(publicKey.serialize(), Base64.NO_WRAP));
    final Element signedPreKeySignature = bundle.addChild("signedPreKeySignature");
    signedPreKeySignature.setContent(Base64.encodeToString(signedPreKeyRecord.getSignature(), Base64.NO_WRAP));
    final Element identityKeyElement = bundle.addChild("identityKey");
    identityKeyElement.setContent(Base64.encodeToString(identityKey.serialize(), Base64.NO_WRAP));

    final Element prekeys = bundle.addChild("prekeys", AxolotlService.PEP_PREFIX);
    for (PreKeyRecord preKeyRecord : preKeyRecords) {
        final Element prekey = prekeys.addChild("preKeyPublic");
        prekey.setAttribute("preKeyId", preKeyRecord.getId());
        prekey.setContent(Base64.encodeToString(preKeyRecord.getKeyPair().getPublicKey().serialize(), Base64.NO_WRAP));
    }

    return publish(AxolotlService.PEP_BUNDLES + ":" + deviceId, item, publishOptions);
}
 
Example #2
Source File: IqGenerator.java    From Conversations with GNU General Public License v3.0 6 votes vote down vote up
public IqPacket publishBundles(final SignedPreKeyRecord signedPreKeyRecord, final IdentityKey identityKey,
                               final Set<PreKeyRecord> preKeyRecords, final int deviceId, Bundle publishOptions) {
    final Element item = new Element("item");
    item.setAttribute("id", "current");
    final Element bundle = item.addChild("bundle", AxolotlService.PEP_PREFIX);
    final Element signedPreKeyPublic = bundle.addChild("signedPreKeyPublic");
    signedPreKeyPublic.setAttribute("signedPreKeyId", signedPreKeyRecord.getId());
    ECPublicKey publicKey = signedPreKeyRecord.getKeyPair().getPublicKey();
    signedPreKeyPublic.setContent(Base64.encodeToString(publicKey.serialize(), Base64.NO_WRAP));
    final Element signedPreKeySignature = bundle.addChild("signedPreKeySignature");
    signedPreKeySignature.setContent(Base64.encodeToString(signedPreKeyRecord.getSignature(), Base64.NO_WRAP));
    final Element identityKeyElement = bundle.addChild("identityKey");
    identityKeyElement.setContent(Base64.encodeToString(identityKey.serialize(), Base64.NO_WRAP));

    final Element prekeys = bundle.addChild("prekeys", AxolotlService.PEP_PREFIX);
    for (PreKeyRecord preKeyRecord : preKeyRecords) {
        final Element prekey = prekeys.addChild("preKeyPublic");
        prekey.setAttribute("preKeyId", preKeyRecord.getId());
        prekey.setContent(Base64.encodeToString(preKeyRecord.getKeyPair().getPublicKey().serialize(), Base64.NO_WRAP));
    }

    return publish(AxolotlService.PEP_BUNDLES + ":" + deviceId, item, publishOptions);
}
 
Example #3
Source File: AliceSignalProtocolParameters.java    From libsignal-protocol-java with GNU General Public License v3.0 6 votes vote down vote up
private AliceSignalProtocolParameters(IdentityKeyPair ourIdentityKey, ECKeyPair ourBaseKey,
                                      IdentityKey theirIdentityKey, ECPublicKey theirSignedPreKey,
                                      ECPublicKey theirRatchetKey, Optional<ECPublicKey> theirOneTimePreKey)
{
  this.ourIdentityKey     = ourIdentityKey;
  this.ourBaseKey         = ourBaseKey;
  this.theirIdentityKey   = theirIdentityKey;
  this.theirSignedPreKey  = theirSignedPreKey;
  this.theirRatchetKey    = theirRatchetKey;
  this.theirOneTimePreKey = theirOneTimePreKey;

  if (ourIdentityKey == null || ourBaseKey == null || theirIdentityKey == null ||
      theirSignedPreKey == null || theirRatchetKey == null || theirOneTimePreKey == null)
  {
    throw new IllegalArgumentException("Null values!");
  }
}
 
Example #4
Source File: AsymmetricMasterCipher.java    From bcm-android with GNU General Public License v3.0 6 votes vote down vote up
public byte[] encryptBytes(byte[] body) {
  try {
    ECPublicKey  theirPublic        = asymmetricMasterSecret.getDjbPublicKey();
    ECKeyPair    ourKeyPair         = Curve.generateKeyPair();
    byte[]       secret             = Curve.calculateAgreement(theirPublic, ourKeyPair.getPrivateKey());
    MasterCipher masterCipher       = getMasterCipherForSecret(secret);
    byte[]       encryptedBodyBytes = masterCipher.encryptBytes(body);

    PublicKey    ourPublicKey       = new PublicKey(31337, ourKeyPair.getPublicKey());
    byte[]       publicKeyBytes     = ourPublicKey.serialize();

    return Util.combine(publicKeyBytes, encryptedBodyBytes);
  } catch (InvalidKeyException e) {
    throw new AssertionError(e);
  }
}
 
Example #5
Source File: MasterSecretUtil.java    From bcm-android with GNU General Public License v3.0 6 votes vote down vote up
public static AsymmetricMasterSecret getAsymmetricMasterSecret(@NonNull AccountContext accountContext,
                                                               @Nullable MasterSecret masterSecret) {
    try {
        byte[] djbPublicBytes = retrieve(accountContext, ASYMMETRIC_LOCAL_PUBLIC_DJB);
        byte[] djbPrivateBytes = retrieve(accountContext, ASYMMETRIC_LOCAL_PRIVATE_DJB);

        ECPublicKey djbPublicKey = null;
        ECPrivateKey djbPrivateKey = null;

        if (djbPublicBytes != null) {
            djbPublicKey = Curve.decodePoint(djbPublicBytes, 0);
        }

        if (masterSecret != null) {
            MasterCipher masterCipher = new MasterCipher(masterSecret);

            if (djbPrivateBytes != null) {
                djbPrivateKey = masterCipher.decryptKey(djbPrivateBytes);
            }
        }

        return new AsymmetricMasterSecret(djbPublicKey, djbPrivateKey);
    } catch (InvalidKeyException | IOException ike) {
        throw new AssertionError(ike);
    }
}
 
Example #6
Source File: AsymmetricMasterCipher.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
public byte[] encryptBytes(byte[] body) {
  try {
    ECPublicKey  theirPublic        = asymmetricMasterSecret.getDjbPublicKey();
    ECKeyPair    ourKeyPair         = Curve.generateKeyPair();
    byte[]       secret             = Curve.calculateAgreement(theirPublic, ourKeyPair.getPrivateKey());
    MasterCipher masterCipher       = getMasterCipherForSecret(secret);
    byte[]       encryptedBodyBytes = masterCipher.encrypt(body);

    PublicKey    ourPublicKey       = new PublicKey(31337, ourKeyPair.getPublicKey());
    byte[]       publicKeyBytes     = ourPublicKey.serialize();

    return Util.combine(publicKeyBytes, encryptedBodyBytes);
  } catch (InvalidKeyException e) {
    throw new AssertionError(e);
  }
}
 
Example #7
Source File: MasterSecretUtil.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
public static AsymmetricMasterSecret getAsymmetricMasterSecret(@NonNull  Context context,
                                                               @Nullable MasterSecret masterSecret)
{
  try {
    byte[] djbPublicBytes   = retrieve(context, ASYMMETRIC_LOCAL_PUBLIC_DJB);
    byte[] djbPrivateBytes  = retrieve(context, ASYMMETRIC_LOCAL_PRIVATE_DJB);

    MasterCipher masterCipher  = new MasterCipher(masterSecret);
    ECPublicKey  djbPublicKey  = masterCipher.decryptPublicKey(djbPublicBytes);
    ECPrivateKey djbPrivateKey = masterCipher.decryptPrivateKey(djbPrivateBytes);

    return new AsymmetricMasterSecret(djbPublicKey, djbPrivateKey);
  } catch (InvalidKeyException ike) {
    throw new SecurityException(ike);
  }
}
 
Example #8
Source File: SignalMessage.java    From libsignal-protocol-java with GNU General Public License v3.0 6 votes vote down vote up
public SignalMessage(int messageVersion, SecretKeySpec macKey, ECPublicKey senderRatchetKey,
                     int counter, int previousCounter, byte[] ciphertext,
                     IdentityKey senderIdentityKey,
                     IdentityKey receiverIdentityKey)
{
  byte[] version = {ByteUtil.intsToByteHighAndLow(messageVersion, CURRENT_VERSION)};
  byte[] message = SignalProtos.SignalMessage.newBuilder()
                                             .setRatchetKey(ByteString.copyFrom(senderRatchetKey.serialize()))
                                             .setCounter(counter)
                                             .setPreviousCounter(previousCounter)
                                             .setCiphertext(ByteString.copyFrom(ciphertext))
                                             .build().toByteArray();

  byte[] mac     = getMac(senderIdentityKey, receiverIdentityKey, macKey, ByteUtil.combine(version, message));

  this.serialized       = ByteUtil.combine(version, message, mac);
  this.senderRatchetKey = senderRatchetKey;
  this.counter          = counter;
  this.previousCounter  = previousCounter;
  this.ciphertext       = ciphertext;
  this.messageVersion   = messageVersion;
}
 
Example #9
Source File: SessionState.java    From libsignal-protocol-java with GNU General Public License v3.0 6 votes vote down vote up
public boolean hasMessageKeys(ECPublicKey senderEphemeral, int counter) {
  Pair<Chain,Integer> chainAndIndex = getReceiverChain(senderEphemeral);
  Chain               chain         = chainAndIndex.first();

  if (chain == null) {
    return false;
  }

  List<Chain.MessageKey> messageKeyList = chain.getMessageKeysList();

  for (Chain.MessageKey messageKey : messageKeyList) {
    if (messageKey.getIndex() == counter) {
      return true;
    }
  }

  return false;
}
 
Example #10
Source File: SessionState.java    From libsignal-protocol-java with GNU General Public License v3.0 6 votes vote down vote up
public void setMessageKeys(ECPublicKey senderEphemeral, MessageKeys messageKeys) {
  Pair<Chain,Integer> chainAndIndex       = getReceiverChain(senderEphemeral);
  Chain               chain               = chainAndIndex.first();
  Chain.MessageKey    messageKeyStructure = Chain.MessageKey.newBuilder()
                                                            .setCipherKey(ByteString.copyFrom(messageKeys.getCipherKey().getEncoded()))
                                                            .setMacKey(ByteString.copyFrom(messageKeys.getMacKey().getEncoded()))
                                                            .setIndex(messageKeys.getCounter())
                                                            .setIv(ByteString.copyFrom(messageKeys.getIv().getIV()))
                                                            .build();

  Chain.Builder updatedChain = chain.toBuilder().addMessageKeys(messageKeyStructure);

  if (updatedChain.getMessageKeysCount() > MAX_MESSAGE_KEYS) {
    updatedChain.removeMessageKeys(0);
  }

  this.sessionStructure = this.sessionStructure.toBuilder()
                                               .setReceiverChains(chainAndIndex.second(),
                                                                  updatedChain.build())
                                               .build();
}
 
Example #11
Source File: SessionState.java    From libsignal-protocol-java with GNU General Public License v3.0 6 votes vote down vote up
public void addReceiverChain(ECPublicKey senderRatchetKey, ChainKey chainKey) {
  Chain.ChainKey chainKeyStructure = Chain.ChainKey.newBuilder()
                                                   .setKey(ByteString.copyFrom(chainKey.getKey()))
                                                   .setIndex(chainKey.getIndex())
                                                   .build();

  Chain chain = Chain.newBuilder()
                     .setChainKey(chainKeyStructure)
                     .setSenderRatchetKey(ByteString.copyFrom(senderRatchetKey.serialize()))
                     .build();

  this.sessionStructure = this.sessionStructure.toBuilder().addReceiverChains(chain).build();

  if (this.sessionStructure.getReceiverChainsList().size() > 5) {
    this.sessionStructure = this.sessionStructure.toBuilder()
                                                 .removeReceiverChains(0)
                                                 .build();
  }
}
 
Example #12
Source File: SenderKeyRecord.java    From libsignal-protocol-java with GNU General Public License v3.0 5 votes vote down vote up
public void addSenderKeyState(int id, int iteration, byte[] chainKey, ECPublicKey signatureKey) {
  senderKeyStates.addFirst(new SenderKeyState(id, iteration, chainKey, signatureKey));

  if (senderKeyStates.size() > MAX_STATES) {
    senderKeyStates.removeLast();
  }
}
 
Example #13
Source File: Utils.java    From signal-cli with GNU General Public License v3.0 5 votes vote down vote up
static DeviceLinkInfo parseDeviceLinkUri(URI linkUri) throws IOException, InvalidKeyException {
    Map<String, String> query = getQueryMap(linkUri.getRawQuery());
    String deviceIdentifier = query.get("uuid");
    String publicKeyEncoded = query.get("pub_key");

    if (isEmpty(deviceIdentifier) || isEmpty(publicKeyEncoded)) {
        throw new RuntimeException("Invalid device link uri");
    }

    ECPublicKey deviceKey = Curve.decodePoint(Base64.decode(publicKeyEncoded), 0);

    return new DeviceLinkInfo(deviceIdentifier, deviceKey);
}
 
Example #14
Source File: SessionState.java    From libsignal-protocol-java with GNU General Public License v3.0 5 votes vote down vote up
public void setReceiverChainKey(ECPublicKey senderEphemeral, ChainKey chainKey) {
  Pair<Chain,Integer> chainAndIndex = getReceiverChain(senderEphemeral);
  Chain               chain         = chainAndIndex.first();

  Chain.ChainKey chainKeyStructure = Chain.ChainKey.newBuilder()
                                                   .setKey(ByteString.copyFrom(chainKey.getKey()))
                                                   .setIndex(chainKey.getIndex())
                                                   .build();

  Chain updatedChain = chain.toBuilder().setChainKey(chainKeyStructure).build();

  this.sessionStructure = this.sessionStructure.toBuilder()
                                               .setReceiverChains(chainAndIndex.second(), updatedChain)
                                               .build();
}
 
Example #15
Source File: SessionState.java    From libsignal-protocol-java with GNU General Public License v3.0 5 votes vote down vote up
public ECPublicKey getSenderRatchetKey() {
  try {
    return Curve.decodePoint(sessionStructure.getSenderChain().getSenderRatchetKey().toByteArray(), 0);
  } catch (InvalidKeyException e) {
    throw new AssertionError(e);
  }
}
 
Example #16
Source File: RatchetingSession.java    From libsignal-protocol-java with GNU General Public License v3.0 5 votes vote down vote up
public static void initializeSession(SessionState sessionState, SymmetricSignalProtocolParameters parameters)
    throws InvalidKeyException
{
  if (isAlice(parameters.getOurBaseKey().getPublicKey(), parameters.getTheirBaseKey())) {
    AliceSignalProtocolParameters.Builder aliceParameters = AliceSignalProtocolParameters.newBuilder();

    aliceParameters.setOurBaseKey(parameters.getOurBaseKey())
                   .setOurIdentityKey(parameters.getOurIdentityKey())
                   .setTheirRatchetKey(parameters.getTheirRatchetKey())
                   .setTheirIdentityKey(parameters.getTheirIdentityKey())
                   .setTheirSignedPreKey(parameters.getTheirBaseKey())
                   .setTheirOneTimePreKey(Optional.<ECPublicKey>absent());

    RatchetingSession.initializeSession(sessionState, aliceParameters.create());
  } else {
    BobSignalProtocolParameters.Builder bobParameters = BobSignalProtocolParameters.newBuilder();

    bobParameters.setOurIdentityKey(parameters.getOurIdentityKey())
                 .setOurRatchetKey(parameters.getOurRatchetKey())
                 .setOurSignedPreKey(parameters.getOurBaseKey())
                 .setOurOneTimePreKey(Optional.<ECKeyPair>absent())
                 .setTheirBaseKey(parameters.getTheirBaseKey())
                 .setTheirIdentityKey(parameters.getTheirIdentityKey());

    RatchetingSession.initializeSession(sessionState, bobParameters.create());
  }
}
 
Example #17
Source File: PreKeySignalMessage.java    From libsignal-protocol-java with GNU General Public License v3.0 5 votes vote down vote up
public PreKeySignalMessage(int messageVersion, int registrationId, Optional<Integer> preKeyId,
                           int signedPreKeyId, ECPublicKey baseKey, IdentityKey identityKey,
                           SignalMessage message)
{
  this.version        = messageVersion;
  this.registrationId = registrationId;
  this.preKeyId       = preKeyId;
  this.signedPreKeyId = signedPreKeyId;
  this.baseKey        = baseKey;
  this.identityKey    = identityKey;
  this.message        = message;

  SignalProtos.PreKeySignalMessage.Builder builder =
      SignalProtos.PreKeySignalMessage.newBuilder()
                                      .setSignedPreKeyId(signedPreKeyId)
                                      .setBaseKey(ByteString.copyFrom(baseKey.serialize()))
                                      .setIdentityKey(ByteString.copyFrom(identityKey.serialize()))
                                      .setMessage(ByteString.copyFrom(message.serialize()))
                                      .setRegistrationId(registrationId);

  if (preKeyId.isPresent()) {
    builder.setPreKeyId(preKeyId.get());
  }

  byte[] versionBytes = {ByteUtil.intsToByteHighAndLow(this.version, CURRENT_VERSION)};
  byte[] messageBytes = builder.build().toByteArray();

  this.serialized = ByteUtil.combine(versionBytes, messageBytes);
}
 
Example #18
Source File: SessionState.java    From libsignal-protocol-java with GNU General Public License v3.0 5 votes vote down vote up
public ECKeyPair getSenderRatchetKeyPair() {
  ECPublicKey  publicKey  = getSenderRatchetKey();
  ECPrivateKey privateKey = Curve.decodePrivatePoint(sessionStructure.getSenderChain()
                                                                     .getSenderRatchetKeyPrivate()
                                                                     .toByteArray());

  return new ECKeyPair(publicKey, privateKey);
}
 
Example #19
Source File: Manager.java    From signal-cli with GNU General Public License v3.0 5 votes vote down vote up
private void addDevice(String deviceIdentifier, ECPublicKey deviceKey) throws IOException, InvalidKeyException {
    IdentityKeyPair identityKeyPair = getIdentityKeyPair();
    String verificationCode = accountManager.getNewDeviceVerificationCode();

    accountManager.addDevice(deviceIdentifier, deviceKey, identityKeyPair, Optional.of(account.getProfileKey().serialize()), verificationCode);
    account.setMultiDevice(true);
    account.save();
}
 
Example #20
Source File: MasterCipher.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
public ECPublicKey decryptPublicKey(byte[] key) throws InvalidKeyException {
  try {
    return Curve.decodePoint(decrypt(key, "ECPublicKey".getBytes()), 0);
  } catch (GeneralSecurityException ge) {
    throw new InvalidKeyException(ge);
  }
}
 
Example #21
Source File: SignedPreKeyRecord.java    From libsignal-protocol-java with GNU General Public License v3.0 5 votes vote down vote up
public ECKeyPair getKeyPair() {
  try {
    ECPublicKey publicKey = Curve.decodePoint(this.structure.getPublicKey().toByteArray(), 0);
    ECPrivateKey privateKey = Curve.decodePrivatePoint(this.structure.getPrivateKey().toByteArray());

    return new ECKeyPair(publicKey, privateKey);
  } catch (InvalidKeyException e) {
    throw new AssertionError(e);
  }
}
 
Example #22
Source File: SessionState.java    From libsignal-protocol-java with GNU General Public License v3.0 5 votes vote down vote up
public ChainKey getReceiverChainKey(ECPublicKey senderEphemeral) {
  Pair<Chain,Integer> receiverChainAndIndex = getReceiverChain(senderEphemeral);
  Chain               receiverChain         = receiverChainAndIndex.first();

  if (receiverChain == null) {
    return null;
  } else {
    return new ChainKey(HKDF.createFor(getSessionVersion()),
                        receiverChain.getChainKey().getKey().toByteArray(),
                        receiverChain.getChainKey().getIndex());
  }
}
 
Example #23
Source File: MasterSecretUtil.java    From Silence with GNU General Public License v3.0 5 votes vote down vote up
public static AsymmetricMasterSecret getAsymmetricMasterSecret(Context context,
                                                               MasterSecret masterSecret)
{
  try {
    byte[] djbPublicBytes   = retrieve(context, ASYMMETRIC_LOCAL_PUBLIC_DJB);
    byte[] djbPrivateBytes  = retrieve(context, ASYMMETRIC_LOCAL_PRIVATE_DJB);

    ECPublicKey  djbPublicKey  = null;
    ECPrivateKey djbPrivateKey = null;

    if (djbPublicBytes != null) {
      djbPublicKey = Curve.decodePoint(djbPublicBytes, 0);
    }

    if (masterSecret != null) {
      MasterCipher masterCipher = new MasterCipher(masterSecret);

      if (djbPrivateBytes != null) {
        djbPrivateKey = masterCipher.decryptKey(djbPrivateBytes);
      }
    }

    return new AsymmetricMasterSecret(djbPublicKey, djbPrivateKey);
  } catch (InvalidKeyException | IOException ike) {
    throw new AssertionError(ike);
  }
}
 
Example #24
Source File: Manager.java    From signald with GNU General Public License v3.0 5 votes vote down vote up
public void addDeviceLink(URI linkUri) throws IOException, InvalidKeyException {
    Map<String, String> query = getQueryMap(linkUri.getRawQuery());
    String deviceIdentifier = query.get("uuid");
    String publicKeyEncoded = query.get("pub_key");

    if (isEmpty(deviceIdentifier) || isEmpty(publicKeyEncoded)) {
        throw new RuntimeException("Invalid device link uri");
    }

    ECPublicKey deviceKey = Curve.decodePoint(Base64.decode(publicKeyEncoded), 0);

    addDevice(deviceIdentifier, deviceKey);
}
 
Example #25
Source File: Manager.java    From signald with GNU General Public License v3.0 5 votes vote down vote up
private void addDevice(String deviceIdentifier, ECPublicKey deviceKey) throws IOException, InvalidKeyException {
    IdentityKeyPair identityKeyPair = accountData.axolotlStore.identityKeyStore.getIdentityKeyPair();
    String verificationCode = accountManager.getNewDeviceVerificationCode();

    // TODO send profile key
    accountManager.addDevice(deviceIdentifier, deviceKey, identityKeyPair, Optional.<byte[]>absent(), verificationCode);
}
 
Example #26
Source File: Manager.java    From signald with GNU General Public License v3.0 5 votes vote down vote up
private static CertificateValidator getCertificateValidator() {
    try {
        ECPublicKey unidentifiedSenderTrustRoot = Curve.decodePoint(Base64.decode(BuildConfig.UNIDENTIFIED_SENDER_TRUST_ROOT), 0);
        return new CertificateValidator(unidentifiedSenderTrustRoot);
    } catch (InvalidKeyException | IOException e) {
        throw new AssertionError(e);
    }
}
 
Example #27
Source File: SignalServiceAccountManager.java    From libsignal-service-java with GNU General Public License v3.0 5 votes vote down vote up
public void addDevice(String deviceIdentifier,
                      ECPublicKey deviceKey,
                      IdentityKeyPair identityKeyPair,
                      Optional<byte[]> profileKey,
                      String code)
    throws InvalidKeyException, IOException
{
  ProvisioningCipher       cipher  = new ProvisioningCipher(deviceKey);
  ProvisionMessage.Builder message = ProvisionMessage.newBuilder()
                                                     .setIdentityKeyPublic(ByteString.copyFrom(identityKeyPair.getPublicKey().serialize()))
                                                     .setIdentityKeyPrivate(ByteString.copyFrom(identityKeyPair.getPrivateKey().serialize()))
                                                     .setProvisioningCode(code)
                                                     .setProvisioningVersion(ProvisioningVersion.CURRENT_VALUE);
  if (userE164 != null) {
    message.setNumber(userE164);
  }

  if (userUuid != null) {
    message.setUuid(userUuid.toString());
  }

  if (profileKey.isPresent()) {
    message.setProfileKey(ByteString.copyFrom(profileKey.get()));
  }

  byte[] ciphertext = cipher.encrypt(message.build());
  this.pushServiceSocket.sendProvisioningMessage(deviceIdentifier, ciphertext);
}
 
Example #28
Source File: SignalOmemoService.java    From Smack with Apache License 2.0 5 votes vote down vote up
@Override
protected SignalOmemoRatchet instantiateOmemoRatchet(
        OmemoManager manager,
        OmemoStore<IdentityKeyPair, IdentityKey, PreKeyRecord, SignedPreKeyRecord, SessionRecord,
                SignalProtocolAddress, ECPublicKey, PreKeyBundle, SessionCipher> store) {

    return new SignalOmemoRatchet(manager, getOmemoStoreBackend());
}
 
Example #29
Source File: SignalOmemoRatchet.java    From Smack with Apache License 2.0 5 votes vote down vote up
SignalOmemoRatchet(OmemoManager omemoManager,
                          OmemoStore<IdentityKeyPair, IdentityKey, PreKeyRecord, SignedPreKeyRecord,
                                         SessionRecord, SignalProtocolAddress, ECPublicKey, PreKeyBundle,
                                         SessionCipher> store) {
    super(omemoManager, store);
    this.storeConnector = new SignalOmemoStoreConnector(omemoManager, store);
}
 
Example #30
Source File: PreKeyEntity.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ECPublicKey deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    if (null != json) {
        try {
            String publicSting = json.getAsString();
            return Curve.decodePoint(Base64.decodeWithoutPadding(publicSting), 0);
        } catch (Throwable e) {
            throw new JsonParseException("unknown public key", e);
        }
    }
    return null;
}