当前位置: 首页>>代码示例>>Java>>正文


Java PreKeyRecord类代码示例

本文整理汇总了Java中org.whispersystems.libsignal.state.PreKeyRecord的典型用法代码示例。如果您正苦于以下问题:Java PreKeyRecord类的具体用法?Java PreKeyRecord怎么用?Java PreKeyRecord使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


PreKeyRecord类属于org.whispersystems.libsignal.state包,在下文中一共展示了PreKeyRecord类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: generatePreKeys

import org.whispersystems.libsignal.state.PreKeyRecord; //导入依赖的package包/类
private List<PreKeyRecord> generatePreKeys() {
    List<PreKeyRecord> records = new LinkedList<>();

    int preKeyIdOffset = localIdentity.getPreKeyIdOffset();

    for (int i = 0; i < PREKEY_BATCH_SIZE; i++) {
        int preKeyId = (preKeyIdOffset + i) % Medium.MAX_VALUE;
        ECKeyPair keyPair = Curve.generateKeyPair();
        PreKeyRecord record = new PreKeyRecord(preKeyId, keyPair);

        signalProtocolStore.storePreKey(preKeyId, record);
        records.add(record);
    }

    preKeyIdOffset = (preKeyIdOffset + PREKEY_BATCH_SIZE + 1) % Medium.MAX_VALUE;
    localIdentity.setPreKeyIdOffset(preKeyIdOffset);
    this.storage.getLocalIdentityStore().saveLocalIdentity(localIdentity);

    return records;
}
 
开发者ID:toshiapp,项目名称:toshi-headless-client,代码行数:21,代码来源:Manager.java

示例2: getOrGenerateLastResortPreKey

import org.whispersystems.libsignal.state.PreKeyRecord; //导入依赖的package包/类
private PreKeyRecord getOrGenerateLastResortPreKey() {
    if (signalProtocolStore.containsPreKey(Medium.MAX_VALUE)) {
        try {
            return signalProtocolStore.loadPreKey(Medium.MAX_VALUE);
        } catch (InvalidKeyIdException e) {
            signalProtocolStore.removePreKey(Medium.MAX_VALUE);
        }
    }

    ECKeyPair keyPair = Curve.generateKeyPair();
    PreKeyRecord record = new PreKeyRecord(Medium.MAX_VALUE, keyPair);

    signalProtocolStore.storePreKey(Medium.MAX_VALUE, record);

    return record;
}
 
开发者ID:toshiapp,项目名称:toshi-headless-client,代码行数:17,代码来源:Manager.java

示例3: generatePreKeys

import org.whispersystems.libsignal.state.PreKeyRecord; //导入依赖的package包/类
public static List<PreKeyRecord> generatePreKeys(Context context) {
  PreKeyStore        preKeyStore    = new TextSecurePreKeyStore(context);
  List<PreKeyRecord> records        = new LinkedList<>();
  int                preKeyIdOffset = getNextPreKeyId(context);

  for (int i=0;i<BATCH_SIZE;i++) {
    int          preKeyId = (preKeyIdOffset + i) % Medium.MAX_VALUE;
    ECKeyPair    keyPair  = Curve.generateKeyPair();
    PreKeyRecord record   = new PreKeyRecord(preKeyId, keyPair);

    preKeyStore.storePreKey(preKeyId, record);
    records.add(record);
  }

  setNextPreKeyId(context, (preKeyIdOffset + BATCH_SIZE + 1) % Medium.MAX_VALUE);
  return records;
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:18,代码来源:PreKeyUtil.java

示例4: generateLastResortKey

import org.whispersystems.libsignal.state.PreKeyRecord; //导入依赖的package包/类
public static PreKeyRecord generateLastResortKey(Context context) {
  PreKeyStore preKeyStore = new TextSecurePreKeyStore(context);

  if (preKeyStore.containsPreKey(Medium.MAX_VALUE)) {
    try {
      return preKeyStore.loadPreKey(Medium.MAX_VALUE);
    } catch (InvalidKeyIdException e) {
      Log.w("PreKeyUtil", e);
      preKeyStore.removePreKey(Medium.MAX_VALUE);
    }
  }

  ECKeyPair    keyPair = Curve.generateKeyPair();
  PreKeyRecord record  = new PreKeyRecord(Medium.MAX_VALUE, keyPair);

  preKeyStore.storePreKey(Medium.MAX_VALUE, record);

  return record;
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:20,代码来源:PreKeyUtil.java

示例5: registerPreKeys

import org.whispersystems.libsignal.state.PreKeyRecord; //导入依赖的package包/类
public void registerPreKeys(IdentityKey identityKey,
                            PreKeyRecord lastResortKey,
                            SignedPreKeyRecord signedPreKey,
                            List<PreKeyRecord> records)
    throws IOException
{
  List<PreKeyEntity> entities = new LinkedList<>();

  for (PreKeyRecord record : records) {
    PreKeyEntity entity = new PreKeyEntity(record.getId(),
                                           record.getKeyPair().getPublicKey());

    entities.add(entity);
  }

  PreKeyEntity lastResortEntity = new PreKeyEntity(lastResortKey.getId(),
                                                   lastResortKey.getKeyPair().getPublicKey());

  SignedPreKeyEntity signedPreKeyEntity = new SignedPreKeyEntity(signedPreKey.getId(),
                                                                 signedPreKey.getKeyPair().getPublicKey(),
                                                                 signedPreKey.getSignature());

  makeRequest(String.format(PREKEY_PATH, ""), "PUT",
              JsonUtil.toJson(new PreKeyState(entities, lastResortEntity,
                                              signedPreKeyEntity, identityKey)));
}
 
开发者ID:XecureIT,项目名称:PeSanKita-lib,代码行数:27,代码来源:PushServiceSocket.java

示例6: handleCommonRegistration

import org.whispersystems.libsignal.state.PreKeyRecord; //导入依赖的package包/类
private void handleCommonRegistration(SignalServiceAccountManager accountManager, String number, String password, String signalingKey, boolean supportsGcm)
    throws IOException
{
  setState(new RegistrationState(RegistrationState.STATE_GENERATING_KEYS, number));
  Recipient          self         = RecipientFactory.getRecipientsFromString(this, number, false).getPrimaryRecipient();
  IdentityKeyPair    identityKey  = IdentityKeyUtil.getIdentityKeyPair(this);
  List<PreKeyRecord> records      = PreKeyUtil.generatePreKeys(this);
  SignedPreKeyRecord signedPreKey = PreKeyUtil.generateSignedPreKey(this, identityKey, true);
  accountManager.setPreKeys(identityKey.getPublicKey(), signedPreKey, records);

  setState(new RegistrationState(RegistrationState.STATE_GCM_REGISTERING, number));

  TextSecurePreferences.setWebsocketRegistered(this, true);

  DatabaseFactory.getIdentityDatabase(this).saveIdentity(self.getRecipientId(), identityKey.getPublicKey(), IdentityDatabase.VerifiedStatus.VERIFIED, true, System.currentTimeMillis(), true);
  DirectoryHelper.refreshDirectory(this, accountManager, number);

  DirectoryRefreshListener.schedule(this);
  RotateSignedPreKeyListener.schedule(this);
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:21,代码来源:RegistrationService.java

示例7: onRun

import org.whispersystems.libsignal.state.PreKeyRecord; //导入依赖的package包/类
@Override
public void onRun(MasterSecret masterSecret) throws IOException {
  if (!TextSecurePreferences.isPushRegistered(context)) return;

  int availableKeys = accountManager.getPreKeysCount();

  if (availableKeys >= PREKEY_MINIMUM && TextSecurePreferences.isSignedPreKeyRegistered(context)) {
    Log.w(TAG, "Available keys sufficient: " + availableKeys);
    return;
  }

  List<PreKeyRecord> preKeyRecords       = PreKeyUtil.generatePreKeys(context);
  IdentityKeyPair    identityKey         = IdentityKeyUtil.getIdentityKeyPair(context);
  SignedPreKeyRecord signedPreKeyRecord  = PreKeyUtil.generateSignedPreKey(context, identityKey, false);

  Log.w(TAG, "Registering new prekeys...");

  accountManager.setPreKeys(identityKey.getPublicKey(), signedPreKeyRecord, preKeyRecords);

  PreKeyUtil.setActiveSignedPreKeyId(context, signedPreKeyRecord.getId());
  TextSecurePreferences.setSignedPreKeyRegistered(context, true);

  ApplicationContext.getInstance(context)
                    .getJobManager()
                    .add(new CleanPreKeysJob(context));
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:27,代码来源:RefreshPreKeysJob.java

示例8: publishBundles

import org.whispersystems.libsignal.state.PreKeyRecord; //导入依赖的package包/类
public IqPacket publishBundles(final SignedPreKeyRecord signedPreKeyRecord, final IdentityKey identityKey,
							   final Set<PreKeyRecord> preKeyRecords, final int deviceId, Bundle publishOptions) {
	final Element item = new Element("item");
	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.DEFAULT));
	final Element signedPreKeySignature = bundle.addChild("signedPreKeySignature");
	signedPreKeySignature.setContent(Base64.encodeToString(signedPreKeyRecord.getSignature(),Base64.DEFAULT));
	final Element identityKeyElement = bundle.addChild("identityKey");
	identityKeyElement.setContent(Base64.encodeToString(identityKey.serialize(), Base64.DEFAULT));

	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.DEFAULT));
	}

	return publish(AxolotlService.PEP_BUNDLES+":"+deviceId, item, publishOptions);
}
 
开发者ID:syntafin,项目名称:TenguChat,代码行数:23,代码来源:IqGenerator.java

示例9: registerKeys

import org.whispersystems.libsignal.state.PreKeyRecord; //导入依赖的package包/类
private Completable registerKeys(
        final IdentityKey identityKey,
        final PreKeyRecord lastResortKey,
        final String password,
        final int registrationId,
        final String signalingKey,
        final SignedPreKeyRecord signedPreKey,
        final List<PreKeyRecord> preKeys) {

    return this.chatInterface
            .getTimestamp()
            .subscribeOn(Schedulers.io())
            .observeOn(Schedulers.io())
            .flatMapCompletable(
                    serverTime -> registerKeysWithTimestamp(
                            serverTime.get(),
                            identityKey,
                            lastResortKey,
                            password,
                            registrationId,
                            signalingKey,
                            signedPreKey,
                            preKeys)
            );
}
 
开发者ID:toshiapp,项目名称:toshi-android-client,代码行数:26,代码来源:ChatService.java

示例10: generatePreKeys

import org.whispersystems.libsignal.state.PreKeyRecord; //导入依赖的package包/类
public static List<PreKeyRecord> generatePreKeys(Context context) {
    PreKeyStore preKeyStore    = new SignalPreKeyStore();
    List<PreKeyRecord> records        = new LinkedList<>();
    int                preKeyIdOffset = getNextPreKeyId(context);

    for (int i=0;i<BATCH_SIZE;i++) {
        int          preKeyId = (preKeyIdOffset + i) % Medium.MAX_VALUE;
        ECKeyPair    keyPair  = Curve.generateKeyPair();
        PreKeyRecord record   = new PreKeyRecord(preKeyId, keyPair);

        preKeyStore.storePreKey(preKeyId, record);
        records.add(record);
    }

    setNextPreKeyId(context, (preKeyIdOffset + BATCH_SIZE + 1) % Medium.MAX_VALUE);
    return records;
}
 
开发者ID:toshiapp,项目名称:toshi-android-client,代码行数:18,代码来源:PreKeyUtil.java

示例11: generateLastResortKey

import org.whispersystems.libsignal.state.PreKeyRecord; //导入依赖的package包/类
public static PreKeyRecord generateLastResortKey(Context context) {
    PreKeyStore preKeyStore = new SignalPreKeyStore();

    if (preKeyStore.containsPreKey(Medium.MAX_VALUE)) {
        try {
            return preKeyStore.loadPreKey(Medium.MAX_VALUE);
        } catch (InvalidKeyIdException e) {
            LogUtil.w("PreKeyUtil", e.toString());
            preKeyStore.removePreKey(Medium.MAX_VALUE);
        }
    }

    ECKeyPair    keyPair = Curve.generateKeyPair();
    PreKeyRecord record  = new PreKeyRecord(Medium.MAX_VALUE, keyPair);

    preKeyStore.storePreKey(Medium.MAX_VALUE, record);

    return record;
}
 
开发者ID:toshiapp,项目名称:toshi-android-client,代码行数:20,代码来源:PreKeyUtil.java

示例12: getPreKey

import org.whispersystems.libsignal.state.PreKeyRecord; //导入依赖的package包/类
public PreKeyRecord getPreKey(int id) {
	try {
		if(getPreKey == null) {
			getPreKey = db.getConnection().prepareStatement("SELECT prekey FROM " + TABLE_NAME + " WHERE id = ?");
		}
		getPreKey.setInt(1, id);
		ResultSet rs = getPreKey.executeQuery();
		if(!rs.next()) {
			logger.trace("No prekey found for id {}", id);
			return null;
		}
		return new PreKeyRecord(rs.getBytes("prekey"));
	} catch(SQLException | IOException e) {
		throw new RuntimeException("Could not get existing prekeys from database!", e);
	}
}
 
开发者ID:Turakar,项目名称:Signal-JDesktop,代码行数:17,代码来源:DerbyPreKeyStore.java

示例13: generatePreKeys

import org.whispersystems.libsignal.state.PreKeyRecord; //导入依赖的package包/类
private List<PreKeyRecord> generatePreKeys() {
    List<PreKeyRecord> records = new LinkedList<>();

    for (int i = 0; i < PREKEY_BATCH_SIZE; i++) {
        int preKeyId = (preKeyIdOffset + i) % Medium.MAX_VALUE;
        ECKeyPair keyPair = Curve.generateKeyPair();
        PreKeyRecord record = new PreKeyRecord(preKeyId, keyPair);

        signalProtocolStore.storePreKey(preKeyId, record);
        records.add(record);
    }

    preKeyIdOffset = (preKeyIdOffset + PREKEY_BATCH_SIZE + 1) % Medium.MAX_VALUE;
    save();

    return records;
}
 
开发者ID:AsamK,项目名称:signal-cli,代码行数:18,代码来源:Manager.java

示例14: publishBundles

import org.whispersystems.libsignal.state.PreKeyRecord; //导入依赖的package包/类
public IqPacket publishBundles(final SignedPreKeyRecord signedPreKeyRecord, final IdentityKey identityKey,
                               final Set<PreKeyRecord> preKeyRecords, final int deviceId, Bundle publishOptions) {
    final Element item = new Element("item");
    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.DEFAULT));
    final Element signedPreKeySignature = bundle.addChild("signedPreKeySignature");
    signedPreKeySignature.setContent(Base64.encodeToString(signedPreKeyRecord.getSignature(), Base64.DEFAULT));
    final Element identityKeyElement = bundle.addChild("identityKey");
    identityKeyElement.setContent(Base64.encodeToString(identityKey.serialize(), Base64.DEFAULT));

    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.DEFAULT));
    }

    return publish(AxolotlService.PEP_BUNDLES + ":" + deviceId, item, publishOptions);
}
 
开发者ID:kriztan,项目名称:Pix-Art-Messenger,代码行数:23,代码来源:IqGenerator.java

示例15: generatePreKeys

import org.whispersystems.libsignal.state.PreKeyRecord; //导入依赖的package包/类
public static List<PreKeyRecord> generatePreKeys(Context context, MasterSecret masterSecret) {
  PreKeyStore        preKeyStore    = new SilencePreKeyStore(context, masterSecret);
  List<PreKeyRecord> records        = new LinkedList<>();
  int                preKeyIdOffset = getNextPreKeyId(context);

  for (int i=0;i<BATCH_SIZE;i++) {
    int          preKeyId = (preKeyIdOffset + i) % Medium.MAX_VALUE;
    ECKeyPair    keyPair  = Curve.generateKeyPair();
    PreKeyRecord record   = new PreKeyRecord(preKeyId, keyPair);

    preKeyStore.storePreKey(preKeyId, record);
    records.add(record);
  }

  setNextPreKeyId(context, (preKeyIdOffset + BATCH_SIZE + 1) % Medium.MAX_VALUE);
  return records;
}
 
开发者ID:SilenceIM,项目名称:Silence,代码行数:18,代码来源:PreKeyUtil.java


注:本文中的org.whispersystems.libsignal.state.PreKeyRecord类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。