本文整理汇总了Java中org.whispersystems.libaxolotl.state.PreKeyRecord类的典型用法代码示例。如果您正苦于以下问题:Java PreKeyRecord类的具体用法?Java PreKeyRecord怎么用?Java PreKeyRecord使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PreKeyRecord类属于org.whispersystems.libaxolotl.state包,在下文中一共展示了PreKeyRecord类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: publishBundles
import org.whispersystems.libaxolotl.state.PreKeyRecord; //导入依赖的package包/类
public IqPacket publishBundles(final SignedPreKeyRecord signedPreKeyRecord, final IdentityKey identityKey,
final Set<PreKeyRecord> preKeyRecords, final int deviceId) {
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);
}
开发者ID:xavierle,项目名称:messengerxmpp,代码行数:23,代码来源:IqGenerator.java
示例2: handleCommonRegistration
import org.whispersystems.libaxolotl.state.PreKeyRecord; //导入依赖的package包/类
private void handleCommonRegistration(MasterSecret masterSecret, TextSecureAccountManager accountManager, String number)
throws IOException
{
setState(new RegistrationState(RegistrationState.STATE_GENERATING_KEYS, number));
IdentityKeyPair identityKey = IdentityKeyUtil.getIdentityKeyPair(this, masterSecret);
List<PreKeyRecord> records = PreKeyUtil.generatePreKeys(this, masterSecret);
PreKeyRecord lastResort = PreKeyUtil.generateLastResortKey(this, masterSecret);
SignedPreKeyRecord signedPreKey = PreKeyUtil.generateSignedPreKey(this, masterSecret, identityKey);
accountManager.setPreKeys(identityKey.getPublicKey(),lastResort, signedPreKey, records);
setState(new RegistrationState(RegistrationState.STATE_GCM_REGISTERING, number));
String gcmRegistrationId = GoogleCloudMessaging.getInstance(this).register(GcmRefreshJob.REGISTRATION_ID);
TextSecurePreferences.setGcmRegistrationId(this, gcmRegistrationId);
accountManager.setGcmId(Optional.of(gcmRegistrationId));
DirectoryHelper.refreshDirectory(this, accountManager, number);
DirectoryRefreshListener.schedule(this);
}
开发者ID:redcracker,项目名称:TextSecure,代码行数:21,代码来源:RegistrationService.java
示例3: generatePreKeys
import org.whispersystems.libaxolotl.state.PreKeyRecord; //导入依赖的package包/类
public static List<PreKeyRecord> generatePreKeys(Context context, MasterSecret masterSecret) {
PreKeyStore preKeyStore = new TextSecurePreKeyStore(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 = Curve25519.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:redcracker,项目名称:TextSecure,代码行数:18,代码来源:PreKeyUtil.java
示例4: generateLastResortKey
import org.whispersystems.libaxolotl.state.PreKeyRecord; //导入依赖的package包/类
public static PreKeyRecord generateLastResortKey(Context context, MasterSecret masterSecret) {
PreKeyStore preKeyStore = new TextSecurePreKeyStore(context, masterSecret);
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 = Curve25519.generateKeyPair();
PreKeyRecord record = new PreKeyRecord(Medium.MAX_VALUE, keyPair);
preKeyStore.storePreKey(Medium.MAX_VALUE, record);
return record;
}
开发者ID:redcracker,项目名称:TextSecure,代码行数:20,代码来源:PreKeyUtil.java
示例5: onRun
import org.whispersystems.libaxolotl.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, masterSecret);
PreKeyRecord lastResortKeyRecord = PreKeyUtil.generateLastResortKey(context, masterSecret);
IdentityKeyPair identityKey = IdentityKeyUtil.getIdentityKeyPair(context, masterSecret);
SignedPreKeyRecord signedPreKeyRecord = PreKeyUtil.generateSignedPreKey(context, masterSecret, identityKey);
Log.w(TAG, "Registering new prekeys...");
accountManager.setPreKeys(identityKey.getPublicKey(), lastResortKeyRecord, signedPreKeyRecord, preKeyRecords);
TextSecurePreferences.setSignedPreKeyRegistered(context, true);
ApplicationContext.getInstance(context)
.getJobManager()
.add(new CleanPreKeysJob(context));
}
开发者ID:redcracker,项目名称:TextSecure,代码行数:27,代码来源:RefreshPreKeysJob.java
示例6: registerPreKeys
import org.whispersystems.libaxolotl.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",
PreKeyState.toJson(new PreKeyState(entities, lastResortEntity,
signedPreKeyEntity, identityKey)));
}
开发者ID:redcracker,项目名称:TextSecure,代码行数:27,代码来源:PushServiceSocket.java
示例7: getKey
import org.whispersystems.libaxolotl.state.PreKeyRecord; //导入依赖的package包/类
public PreKeyRecord getKey(final int id) throws SQLException {
final String query = "SELECT prekey FROM prekeystore WHERE id = ?";
try (PreparedStatement stmt = Database.ensureTableExists(this).prepareStatement(query)) {
stmt.setInt(1, id);
final ResultSet result = stmt.executeQuery();
if (result.first()) {
try {
return new PreKeyRecord(result.getBytes(1));
} catch (final IOException e) {
throw new SQLException("PreKeyTable: Value of prekey for id [" + id + "] is invalid.", e);
}
} else {
return null;
}
}
}
开发者ID:connorlanigan,项目名称:norvos,代码行数:19,代码来源:PreKeyTable.java
示例8: handleCommonRegistration
import org.whispersystems.libaxolotl.state.PreKeyRecord; //导入依赖的package包/类
private void handleCommonRegistration(MasterSecret masterSecret, TextSecureAccountManager accountManager, String number)
throws IOException
{
setState(new RegistrationState(RegistrationState.STATE_GENERATING_KEYS, number));
Recipient self = RecipientFactory.getRecipientsFromString(this, number, false).getPrimaryRecipient();
IdentityKeyPair identityKey = IdentityKeyUtil.getIdentityKeyPair(this, masterSecret);
List<PreKeyRecord> records = PreKeyUtil.generatePreKeys(this, masterSecret);
PreKeyRecord lastResort = PreKeyUtil.generateLastResortKey(this, masterSecret);
SignedPreKeyRecord signedPreKey = PreKeyUtil.generateSignedPreKey(this, masterSecret, identityKey);
accountManager.setPreKeys(identityKey.getPublicKey(),lastResort, signedPreKey, records);
setState(new RegistrationState(RegistrationState.STATE_GCM_REGISTERING, number));
String gcmRegistrationId = GoogleCloudMessaging.getInstance(this).register(GcmRefreshJob.REGISTRATION_ID);
accountManager.setGcmId(Optional.of(gcmRegistrationId));
TextSecurePreferences.setGcmRegistrationId(this, gcmRegistrationId);
TextSecurePreferences.setWebsocketRegistered(this, true);
DatabaseFactory.getIdentityDatabase(this).saveIdentity(masterSecret, self.getRecipientId(), identityKey.getPublicKey());
DirectoryHelper.refreshDirectory(this, accountManager, number);
DirectoryRefreshListener.schedule(this);
}
开发者ID:Agilitum,项目名称:TextSecureSMP,代码行数:25,代码来源:RegistrationService.java
示例9: generatePreKeys
import org.whispersystems.libaxolotl.state.PreKeyRecord; //导入依赖的package包/类
public static List<PreKeyRecord> generatePreKeys(Context context, MasterSecret masterSecret) {
PreKeyStore preKeyStore = new TextSecurePreKeyStore(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:Agilitum,项目名称:TextSecureSMP,代码行数:18,代码来源:PreKeyUtil.java
示例10: generateLastResortKey
import org.whispersystems.libaxolotl.state.PreKeyRecord; //导入依赖的package包/类
public static PreKeyRecord generateLastResortKey(Context context, MasterSecret masterSecret) {
PreKeyStore preKeyStore = new TextSecurePreKeyStore(context, masterSecret);
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:Agilitum,项目名称:TextSecureSMP,代码行数:20,代码来源:PreKeyUtil.java
示例11: createAlicePreKeyBundle
import org.whispersystems.libaxolotl.state.PreKeyRecord; //导入依赖的package包/类
private PreKeyBundle createAlicePreKeyBundle(AxolotlStore aliceStore) throws InvalidKeyException {
ECKeyPair aliceUnsignedPreKey = Curve.generateKeyPair();
int aliceUnsignedPreKeyId = new Random().nextInt(Medium.MAX_VALUE);
byte[] aliceSignature = Curve.calculateSignature(aliceStore.getIdentityKeyPair().getPrivateKey(),
aliceSignedPreKey.getPublicKey().serialize());
PreKeyBundle alicePreKeyBundle = new PreKeyBundle(1, 1,
aliceUnsignedPreKeyId, aliceUnsignedPreKey.getPublicKey(),
aliceSignedPreKeyId, aliceSignedPreKey.getPublicKey(),
aliceSignature, aliceStore.getIdentityKeyPair().getPublicKey());
aliceStore.storeSignedPreKey(aliceSignedPreKeyId, new SignedPreKeyRecord(aliceSignedPreKeyId, System.currentTimeMillis(), aliceSignedPreKey, aliceSignature));
aliceStore.storePreKey(aliceUnsignedPreKeyId, new PreKeyRecord(aliceUnsignedPreKeyId, aliceUnsignedPreKey));
return alicePreKeyBundle;
}
开发者ID:Securecom,项目名称:Securecom-Messaging,代码行数:17,代码来源:SimultaneousInitiateTests.java
示例12: createBobPreKeyBundle
import org.whispersystems.libaxolotl.state.PreKeyRecord; //导入依赖的package包/类
private PreKeyBundle createBobPreKeyBundle(AxolotlStore bobStore) throws InvalidKeyException {
ECKeyPair bobUnsignedPreKey = Curve.generateKeyPair();
int bobUnsignedPreKeyId = new Random().nextInt(Medium.MAX_VALUE);
byte[] bobSignature = Curve.calculateSignature(bobStore.getIdentityKeyPair().getPrivateKey(),
bobSignedPreKey.getPublicKey().serialize());
PreKeyBundle bobPreKeyBundle = new PreKeyBundle(1, 1,
bobUnsignedPreKeyId, bobUnsignedPreKey.getPublicKey(),
bobSignedPreKeyId, bobSignedPreKey.getPublicKey(),
bobSignature, bobStore.getIdentityKeyPair().getPublicKey());
bobStore.storeSignedPreKey(bobSignedPreKeyId, new SignedPreKeyRecord(bobSignedPreKeyId, System.currentTimeMillis(), bobSignedPreKey, bobSignature));
bobStore.storePreKey(bobUnsignedPreKeyId, new PreKeyRecord(bobUnsignedPreKeyId, bobUnsignedPreKey));
return bobPreKeyBundle;
}
开发者ID:Securecom,项目名称:Securecom-Messaging,代码行数:17,代码来源:SimultaneousInitiateTests.java
示例13: handleCommonRegistration
import org.whispersystems.libaxolotl.state.PreKeyRecord; //导入依赖的package包/类
private void handleCommonRegistration(MasterSecret masterSecret, TextSecureAccountManager accountManager, String number) throws IOException {
setState(new RegistrationState(RegistrationState.STATE_GENERATING_KEYS, number));
IdentityKeyPair identityKey = IdentityKeyUtil.getIdentityKeyPair(this, masterSecret);
List<PreKeyRecord> records = PreKeyUtil.generatePreKeys(this, masterSecret);
PreKeyRecord lastResort = PreKeyUtil.generateLastResortKey(this, masterSecret);
SignedPreKeyRecord signedPreKey = PreKeyUtil.generateSignedPreKey(this, masterSecret, identityKey);
accountManager.setPreKeys(identityKey.getPublicKey(),lastResort, signedPreKey, records);
setState(new RegistrationState(RegistrationState.STATE_GCM_REGISTERING, number));
String gcmRegistrationId = GoogleCloudMessaging.getInstance(this).register("225505072490");
TextSecurePreferences.setGcmRegistrationId(this, gcmRegistrationId);
accountManager.setGcmId(Optional.of(gcmRegistrationId));
DirectoryHelper.refreshDirectory(this, accountManager, number);
DirectoryRefreshListener.schedule(this);
}
开发者ID:Securecom,项目名称:Securecom-Messaging,代码行数:19,代码来源:RegistrationService.java
示例14: registerPreKeys
import org.whispersystems.libaxolotl.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",
PreKeyState.toJson(new PreKeyState(entities, lastResortEntity,
signedPreKeyEntity, identityKey)));
}
开发者ID:Securecom,项目名称:Securecom-Messaging,代码行数:27,代码来源:PushServiceSocket.java
示例15: storePreKey
import org.whispersystems.libaxolotl.state.PreKeyRecord; //导入依赖的package包/类
public void storePreKey(Account account, PreKeyRecord record) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(SQLiteAxolotlStore.ID, record.getId());
values.put(SQLiteAxolotlStore.KEY, Base64.encodeToString(record.serialize(), Base64.DEFAULT));
values.put(SQLiteAxolotlStore.ACCOUNT, account.getUuid());
db.insert(SQLiteAxolotlStore.PREKEY_TABLENAME, null, values);
}
开发者ID:xavierle,项目名称:messengerxmpp,代码行数:9,代码来源:DatabaseBackend.java
示例16: loadPreKey
import org.whispersystems.libaxolotl.state.PreKeyRecord; //导入依赖的package包/类
/**
* Load a local PreKeyRecord.
*
* @param preKeyId the ID of the local PreKeyRecord.
* @return the corresponding PreKeyRecord.
* @throws InvalidKeyIdException when there is no corresponding PreKeyRecord.
*/
@Override
public PreKeyRecord loadPreKey(int preKeyId) throws InvalidKeyIdException {
PreKeyRecord record = mXmppConnectionService.databaseBackend.loadPreKey(account, preKeyId);
if (record == null) {
throw new InvalidKeyIdException("No such PreKeyRecord: " + preKeyId);
}
return record;
}
开发者ID:xavierle,项目名称:messengerxmpp,代码行数:16,代码来源:SQLiteAxolotlStore.java
示例17: storePreKey
import org.whispersystems.libaxolotl.state.PreKeyRecord; //导入依赖的package包/类
/**
* Store a local PreKeyRecord.
*
* @param preKeyId the ID of the PreKeyRecord to store.
* @param record the PreKeyRecord.
*/
@Override
public void storePreKey(int preKeyId, PreKeyRecord record) {
mXmppConnectionService.databaseBackend.storePreKey(account, record);
currentPreKeyId = preKeyId;
boolean success = this.account.setKey(JSONKEY_CURRENT_PREKEY_ID, Integer.toString(preKeyId));
if (success) {
mXmppConnectionService.databaseBackend.updateAccount(account);
} else {
Log.e(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Failed to write new prekey id to the database!");
}
}
开发者ID:xavierle,项目名称:messengerxmpp,代码行数:18,代码来源:SQLiteAxolotlStore.java
示例18: loadPreKey
import org.whispersystems.libaxolotl.state.PreKeyRecord; //导入依赖的package包/类
@Override
public PreKeyRecord loadPreKey(int preKeyId) throws InvalidKeyIdException {
synchronized (FILE_LOCK) {
try {
return new PreKeyRecord(loadSerializedRecord(getPreKeyFile(preKeyId)));
} catch (IOException | InvalidMessageException e) {
Log.w(TAG, e);
throw new InvalidKeyIdException(e);
}
}
}
开发者ID:redcracker,项目名称:TextSecure,代码行数:12,代码来源:TextSecurePreKeyStore.java
示例19: storePreKey
import org.whispersystems.libaxolotl.state.PreKeyRecord; //导入依赖的package包/类
@Override
public void storePreKey(int preKeyId, PreKeyRecord record) {
synchronized (FILE_LOCK) {
try {
storeSerializedRecord(getPreKeyFile(preKeyId), record.serialize());
} catch (IOException e) {
throw new AssertionError(e);
}
}
}
开发者ID:redcracker,项目名称:TextSecure,代码行数:11,代码来源:TextSecurePreKeyStore.java
示例20: getLastResortKey
import org.whispersystems.libaxolotl.state.PreKeyRecord; //导入依赖的package包/类
public PreKeyRecord getLastResortKey() {
try {
final byte[] record = AccountDataTable.getInstance().getBinary("lastResortKey");
if (record == null) {
return null;
}
return new PreKeyRecord(record);
} catch (IOException | SQLException e) {
LOGGER.error("Last Resort key could not be fetched from database.", e);
Errors.showError(translate("unexpected_quit"));
Errors.stopApplication();
throw new UnreachableCodeException();
}
}
开发者ID:connorlanigan,项目名称:norvos,代码行数:15,代码来源:PreKeyStore.java
注:本文中的org.whispersystems.libaxolotl.state.PreKeyRecord类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论