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


Java SignedPreKeyRecord类代码示例

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


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

示例1: generateSignedPreKey

import org.whispersystems.libsignal.state.SignedPreKeyRecord; //导入依赖的package包/类
private SignedPreKeyRecord generateSignedPreKey(IdentityKeyPair identityKeyPair) {
    try {
        ECKeyPair keyPair = Curve.generateKeyPair();
        byte[] signature = Curve.calculateSignature(identityKeyPair.getPrivateKey(), keyPair.getPublicKey().serialize());
        int nextSignedPreKeyId = localIdentity.getNextSignedPreKeyId();
        SignedPreKeyRecord record = new SignedPreKeyRecord(nextSignedPreKeyId, System.currentTimeMillis(), keyPair, signature);

        signalProtocolStore.storeSignedPreKey(nextSignedPreKeyId, record);
        nextSignedPreKeyId = (nextSignedPreKeyId + 1) % Medium.MAX_VALUE;

        localIdentity.setNextSignedPreKeyId(nextSignedPreKeyId);
        this.storage.getLocalIdentityStore().saveLocalIdentity(localIdentity);

        return record;
    } catch (InvalidKeyException e) {
        throw new AssertionError(e);
    }
}
 
开发者ID:toshiapp,项目名称:toshi-headless-client,代码行数:19,代码来源:Manager.java

示例2: generateSignedPreKey

import org.whispersystems.libsignal.state.SignedPreKeyRecord; //导入依赖的package包/类
public static SignedPreKeyRecord generateSignedPreKey(Context context, IdentityKeyPair identityKeyPair, boolean active)
{
  try {
    SignedPreKeyStore  signedPreKeyStore = new TextSecurePreKeyStore(context);
    int                signedPreKeyId    = getNextSignedPreKeyId(context);
    ECKeyPair          keyPair           = Curve.generateKeyPair();
    byte[]             signature         = Curve.calculateSignature(identityKeyPair.getPrivateKey(), keyPair.getPublicKey().serialize());
    SignedPreKeyRecord record            = new SignedPreKeyRecord(signedPreKeyId, System.currentTimeMillis(), keyPair, signature);

    signedPreKeyStore.storeSignedPreKey(signedPreKeyId, record);
    setNextSignedPreKeyId(context, (signedPreKeyId + 1) % Medium.MAX_VALUE);

    if (active) {
      setActiveSignedPreKeyId(context, signedPreKeyId);
    }

    return record;
  } catch (InvalidKeyException e) {
    throw new AssertionError(e);
  }
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:22,代码来源:PreKeyUtil.java

示例3: loadSignedPreKeys

import org.whispersystems.libsignal.state.SignedPreKeyRecord; //导入依赖的package包/类
@Override
public List<SignedPreKeyRecord> loadSignedPreKeys() {
  synchronized (FILE_LOCK) {
    File                     directory = getSignedPreKeyDirectory();
    List<SignedPreKeyRecord> results   = new LinkedList<>();

    for (File signedPreKeyFile : directory.listFiles()) {
      try {
        if (!"index.dat".equals(signedPreKeyFile.getName())) {
          results.add(new SignedPreKeyRecord(loadSerializedRecord(signedPreKeyFile)));
        }
      } catch (IOException | InvalidMessageException e) {
        Log.w(TAG, e);
      }
    }

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

示例4: onRun

import org.whispersystems.libsignal.state.SignedPreKeyRecord; //导入依赖的package包/类
@Override
public void onRun(MasterSecret masterSecret) throws IOException {
  if (TextSecurePreferences.isSignedPreKeyRegistered(context)) {
    Log.w(TAG, "Signed prekey already registered...");
    return;
  }

  if (!TextSecurePreferences.isPushRegistered(context)) {
    Log.w(TAG, "Not yet registered...");
    return;
  }

  IdentityKeyPair    identityKeyPair    = IdentityKeyUtil.getIdentityKeyPair(context);
  SignedPreKeyRecord signedPreKeyRecord = PreKeyUtil.generateSignedPreKey(context, identityKeyPair, true);

  accountManager.setSignedPreKey(signedPreKeyRecord);
  TextSecurePreferences.setSignedPreKeyRegistered(context, true);
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:19,代码来源:CreateSignedPreKeyJob.java

示例5: onRun

import org.whispersystems.libsignal.state.SignedPreKeyRecord; //导入依赖的package包/类
@Override
public void onRun(MasterSecret masterSecret) throws Exception {
  Log.w(TAG, "Rotating signed prekey...");

  IdentityKeyPair    identityKey        = IdentityKeyUtil.getIdentityKeyPair(context);
  SignedPreKeyRecord signedPreKeyRecord = PreKeyUtil.generateSignedPreKey(context, identityKey, false);

  accountManager.setSignedPreKey(signedPreKeyRecord);

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

  ApplicationContext.getInstance(context)
                    .getJobManager()
                    .add(new CleanPreKeysJob(context));
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:18,代码来源:RotateSignedPreKeyJob.java

示例6: registerPreKeys

import org.whispersystems.libsignal.state.SignedPreKeyRecord; //导入依赖的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

示例7: handleCommonRegistration

import org.whispersystems.libsignal.state.SignedPreKeyRecord; //导入依赖的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

示例8: onRun

import org.whispersystems.libsignal.state.SignedPreKeyRecord; //导入依赖的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

示例9: publishBundles

import org.whispersystems.libsignal.state.SignedPreKeyRecord; //导入依赖的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

示例10: loadSignedPreKeys

import org.whispersystems.libsignal.state.SignedPreKeyRecord; //导入依赖的package包/类
public List<SignedPreKeyRecord> loadSignedPreKeys(Account account) {
	List<SignedPreKeyRecord> prekeys = new ArrayList<>();
	SQLiteDatabase db = this.getReadableDatabase();
	String[] columns = {SQLiteAxolotlStore.KEY};
	String[] selectionArgs = {account.getUuid()};
	Cursor cursor = db.query(SQLiteAxolotlStore.SIGNED_PREKEY_TABLENAME,
			columns,
			SQLiteAxolotlStore.ACCOUNT + "=?",
			selectionArgs,
			null, null, null);

	while (cursor.moveToNext()) {
		try {
			prekeys.add(new SignedPreKeyRecord(Base64.decode(cursor.getString(cursor.getColumnIndex(SQLiteAxolotlStore.KEY)), Base64.DEFAULT)));
		} catch (IOException ignored) {
		}
	}
	cursor.close();
	return prekeys;
}
 
开发者ID:syntafin,项目名称:TenguChat,代码行数:21,代码来源:DatabaseBackend.java

示例11: registerKeys

import org.whispersystems.libsignal.state.SignedPreKeyRecord; //导入依赖的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

示例12: generateSignedPreKey

import org.whispersystems.libsignal.state.SignedPreKeyRecord; //导入依赖的package包/类
public static SignedPreKeyRecord generateSignedPreKey(Context context, IdentityKeyPair identityKeyPair, boolean active)
{
    try {
        SignedPreKeyStore signedPreKeyStore = new SignalPreKeyStore();
        int                signedPreKeyId    = getNextSignedPreKeyId(context);
        ECKeyPair keyPair           = Curve.generateKeyPair();
        byte[]             signature         = Curve.calculateSignature(identityKeyPair.getPrivateKey(), keyPair.getPublicKey().serialize());
        SignedPreKeyRecord record            = new SignedPreKeyRecord(signedPreKeyId, System.currentTimeMillis(), keyPair, signature);

        signedPreKeyStore.storeSignedPreKey(signedPreKeyId, record);
        setNextSignedPreKeyId(context, (signedPreKeyId + 1) % Medium.MAX_VALUE);

        if (active) {
            setActiveSignedPreKeyId(context, signedPreKeyId);
        }

        return record;
    } catch (InvalidKeyException e) {
        throw new AssertionError(e);
    }
}
 
开发者ID:toshiapp,项目名称:toshi-android-client,代码行数:22,代码来源:PreKeyUtil.java

示例13: loadSignedPreKeys

import org.whispersystems.libsignal.state.SignedPreKeyRecord; //导入依赖的package包/类
@Override
public List<SignedPreKeyRecord> loadSignedPreKeys() {
    synchronized (FILE_LOCK) {
        File                     directory = getSignedPreKeyDirectory();
        List<SignedPreKeyRecord> results   = new LinkedList<>();

        for (File signedPreKeyFile : directory.listFiles()) {
            try {
                results.add(new SignedPreKeyRecord(loadSerializedRecord(signedPreKeyFile)));
            } catch (IOException | InvalidMessageException e) {
                LogUtil.w(getClass(), e.getMessage());
            }
        }

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

示例14: getSignedPreKey

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

示例15: publishBundles

import org.whispersystems.libsignal.state.SignedPreKeyRecord; //导入依赖的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


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