• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java SessionRecord类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: storeSession

import org.whispersystems.libaxolotl.state.SessionRecord; //导入依赖的package包/类
@Override
public void storeSession(long recipientId, int deviceId, SessionRecord record) {
  synchronized (FILE_LOCK) {
    try {
      MasterCipher     masterCipher = new MasterCipher(masterSecret);
      RandomAccessFile sessionFile  = new RandomAccessFile(getSessionFile(recipientId, deviceId), "rw");
      FileChannel      out          = sessionFile.getChannel();

      out.position(0);
      writeInteger(CURRENT_VERSION, out);
      writeBlob(masterCipher.encryptBytes(record.serialize()), out);
      out.truncate(out.position());

      sessionFile.close();
    } catch (IOException e) {
      throw new AssertionError(e);
    }
  }
}
 
开发者ID:redcracker,项目名称:TextSecure,代码行数:20,代码来源:TextSecureSessionStore.java


示例2: getSession

import org.whispersystems.libaxolotl.state.SessionRecord; //导入依赖的package包/类
public SessionRecord getSession(final AxolotlAddress address) throws SQLException {
	final String query = "SELECT session_record FROM session_store WHERE name = ? AND device_id = ?";

	try (PreparedStatement stmt = Database.ensureTableExists(this).prepareStatement(query)) {
		stmt.setString(1, address.getName());
		stmt.setInt(2, address.getDeviceId());
		final ResultSet result = stmt.executeQuery();
		if (result.first()) {
			return new SessionRecord(result.getBytes(1));
		}
		return null;
	} catch (final IOException e) {
		throw new SQLException(
				"SessionTable: Value of session_record for address [" + address.toString() + "] is invalid.", e);
	}
}
 
开发者ID:connorlanigan,项目名称:norvos,代码行数:17,代码来源:SessionTable.java


示例3: sessions

import org.whispersystems.libaxolotl.state.SessionRecord; //导入依赖的package包/类
@Test
public void sessions() {
	final AxolotlAddress address = new AxolotlAddress("TestName", ANY_NUMBER);
	final AxolotlAddress wrongAddress = new AxolotlAddress("WrongName", ANY_NUMBER);
	final SessionRecord session = new SessionRecord();
	final SessionRecord wrongSession = new SessionRecord();
	store.storeSession(address, session);

	assertTrue(store.containsSession(address));
	assertFalse(store.containsSession(wrongAddress));

	assertNotEquals(session, store.loadSession(address)); // returns a copy
	assertNotEquals(wrongSession, store.loadSession(address));

	store.deleteSession(address);
	assertFalse(store.containsSession(address));

	store.storeSession(address, new SessionRecord());
	store.deleteAllSessions(address.getName());
	assertFalse(store.containsSession(address));
}
 
开发者ID:connorlanigan,项目名称:norvos,代码行数:22,代码来源:AxolotlStoreTest.java


示例4: storeSession

import org.whispersystems.libaxolotl.state.SessionRecord; //导入依赖的package包/类
@Override
public void storeSession(AxolotlAddress address, SessionRecord record) {
  synchronized (FILE_LOCK) {
    try {
      MasterCipher     masterCipher = new MasterCipher(masterSecret);
      RandomAccessFile sessionFile  = new RandomAccessFile(getSessionFile(address), "rw");
      FileChannel      out          = sessionFile.getChannel();

      out.position(0);
      writeInteger(CURRENT_VERSION, out);
      writeBlob(masterCipher.encryptBytes(record.serialize()), out);
      out.truncate(out.position());

      sessionFile.close();
    } catch (IOException e) {
      throw new AssertionError(e);
    }
  }
}
 
开发者ID:Agilitum,项目名称:TextSecureSMP,代码行数:20,代码来源:TextSecureSessionStore.java


示例5: if

import org.whispersystems.libaxolotl.state.SessionRecord; //导入依赖的package包/类
/**
 * Build a new session from a received {@link org.whispersystems.libaxolotl.protocol.PreKeyWhisperMessage}.
 *
 * After a session is constructed in this way, the embedded {@link org.whispersystems.libaxolotl.protocol.WhisperMessage}
 * can be decrypted.
 *
 * @param message The received {@link org.whispersystems.libaxolotl.protocol.PreKeyWhisperMessage}.
 * @throws org.whispersystems.libaxolotl.InvalidKeyIdException when there is no local
 *                                                             {@link org.whispersystems.libaxolotl.state.PreKeyRecord}
 *                                                             that corresponds to the PreKey ID in
 *                                                             the message.
 * @throws org.whispersystems.libaxolotl.InvalidKeyException when the message is formatted incorrectly.
 * @throws org.whispersystems.libaxolotl.UntrustedIdentityException when the {@link IdentityKey} of the sender is untrusted.
 */
/*package*/ Optional<Integer> process(SessionRecord sessionRecord, PreKeyWhisperMessage message)
    throws InvalidKeyIdException, InvalidKeyException, UntrustedIdentityException
{
  int         messageVersion   = message.getMessageVersion();
  IdentityKey theirIdentityKey = message.getIdentityKey();

  Optional<Integer> unsignedPreKeyId;

  if (!identityKeyStore.isTrustedIdentity(recipientId, theirIdentityKey)) {
    throw new UntrustedIdentityException();
  }

  switch (messageVersion) {
    case 2:  unsignedPreKeyId = processV2(sessionRecord, message); break;
    case 3:  unsignedPreKeyId = processV3(sessionRecord, message); break;
    default: throw new AssertionError("Unknown version: " + messageVersion);
  }

  identityKeyStore.saveIdentity(recipientId, theirIdentityKey);
  return unsignedPreKeyId;
}
 
开发者ID:Securecom,项目名称:Securecom-Messaging,代码行数:36,代码来源:SessionBuilder.java


示例6: process

import org.whispersystems.libaxolotl.state.SessionRecord; //导入依赖的package包/类
/**
 * Initiate a new session by sending an initial KeyExchangeMessage to the recipient.
 *
 * @return the KeyExchangeMessage to deliver.
 */
public KeyExchangeMessage process() {
  synchronized (SessionCipher.SESSION_LOCK) {
    try {
      int             sequence         = KeyHelper.getRandomSequence(65534) + 1;
      int             flags            = KeyExchangeMessage.INITIATE_FLAG;
      ECKeyPair       baseKey          = Curve.generateKeyPair();
      ECKeyPair       ratchetKey       = Curve.generateKeyPair();
      IdentityKeyPair identityKey      = identityKeyStore.getIdentityKeyPair();
      byte[]          baseKeySignature = Curve.calculateSignature(identityKey.getPrivateKey(), baseKey.getPublicKey().serialize());
      SessionRecord   sessionRecord    = sessionStore.loadSession(recipientId, deviceId);

      sessionRecord.getSessionState().setPendingKeyExchange(sequence, baseKey, ratchetKey, identityKey);
      sessionStore.storeSession(recipientId, deviceId, sessionRecord);

      return new KeyExchangeMessage(2, sequence, flags, baseKey.getPublicKey(), baseKeySignature,
                                    ratchetKey.getPublicKey(), identityKey.getPublicKey());
    } catch (InvalidKeyException e) {
      throw new AssertionError(e);
    }
  }
}
 
开发者ID:Securecom,项目名称:Securecom-Messaging,代码行数:27,代码来源:SessionBuilder.java


示例7: decrypt

import org.whispersystems.libaxolotl.state.SessionRecord; //导入依赖的package包/类
/**
 * Decrypt a message.
 *
 * @param  ciphertext The {@link PreKeyWhisperMessage} to decrypt.
 * @return The plaintext.
 * @throws InvalidMessageException if the input is not valid ciphertext.
 * @throws DuplicateMessageException if the input is a message that has already been received.
 * @throws LegacyMessageException if the input is a message formatted by a protocol version that
 *                                is no longer supported.
 * @throws InvalidKeyIdException when there is no local {@link org.whispersystems.libaxolotl.state.PreKeyRecord}
 *                               that corresponds to the PreKey ID in the message.
 * @throws InvalidKeyException when the message is formatted incorrectly.
 * @throws UntrustedIdentityException when the {@link IdentityKey} of the sender is untrusted.

 */
public byte[] decrypt(PreKeyWhisperMessage ciphertext)
    throws DuplicateMessageException, LegacyMessageException, InvalidMessageException,
           InvalidKeyIdException, InvalidKeyException, UntrustedIdentityException
{
  synchronized (SESSION_LOCK) {
    SessionRecord     sessionRecord    = sessionStore.loadSession(recipientId, deviceId);
    Optional<Integer> unsignedPreKeyId = sessionBuilder.process(sessionRecord, ciphertext);
    byte[]            plaintext        = decrypt(sessionRecord, ciphertext.getWhisperMessage());

    sessionStore.storeSession(recipientId, deviceId, sessionRecord);

    if (unsignedPreKeyId.isPresent()) {
      preKeyStore.removePreKey(unsignedPreKeyId.get());
    }

    return plaintext;
  }
}
 
开发者ID:Securecom,项目名称:Securecom-Messaging,代码行数:34,代码来源:SessionCipher.java


示例8: storeSession

import org.whispersystems.libaxolotl.state.SessionRecord; //导入依赖的package包/类
public void storeSession(Account account, AxolotlAddress contact, SessionRecord session) {
	SQLiteDatabase db = this.getWritableDatabase();
	ContentValues values = new ContentValues();
	values.put(SQLiteAxolotlStore.NAME, contact.getName());
	values.put(SQLiteAxolotlStore.DEVICE_ID, contact.getDeviceId());
	values.put(SQLiteAxolotlStore.KEY, Base64.encodeToString(session.serialize(), Base64.DEFAULT));
	values.put(SQLiteAxolotlStore.ACCOUNT, account.getUuid());
	db.insert(SQLiteAxolotlStore.SESSION_TABLENAME, null, values);
}
 
开发者ID:xavierle,项目名称:messengerxmpp,代码行数:10,代码来源:DatabaseBackend.java


示例9: getRemoteIdentityKey

import org.whispersystems.libaxolotl.state.SessionRecord; //导入依赖的package包/类
private IdentityKey getRemoteIdentityKey(MasterSecret masterSecret, Recipient recipient) {
  SessionStore  sessionStore = new TextSecureSessionStore(this, masterSecret);
  SessionRecord record       = sessionStore.loadSession(recipient.getRecipientId(),
                                                        PushAddress.DEFAULT_DEVICE_ID);

  if (record == null) {
    return null;
  }

  return record.getSessionState().getRemoteIdentityKey();
}
 
开发者ID:redcracker,项目名称:TextSecure,代码行数:12,代码来源:VerifyIdentityActivity.java


示例10: hasInitiatedSession

import org.whispersystems.libaxolotl.state.SessionRecord; //导入依赖的package包/类
private static boolean hasInitiatedSession(Context context, MasterSecret masterSecret,
                                           Recipient recipient)
{
  SessionStore  sessionStore  = new TextSecureSessionStore(context, masterSecret);
  SessionRecord sessionRecord = sessionStore.loadSession(recipient.getRecipientId(), PushAddress.DEFAULT_DEVICE_ID);

  return sessionRecord.getSessionState().hasPendingKeyExchange();
}
 
开发者ID:redcracker,项目名称:TextSecure,代码行数:9,代码来源:KeyExchangeInitiator.java


示例11: loadSession

import org.whispersystems.libaxolotl.state.SessionRecord; //导入依赖的package包/类
@Override
public SessionRecord loadSession(long recipientId, int deviceId) {
  synchronized (FILE_LOCK) {
    try {
      MasterCipher cipher = new MasterCipher(masterSecret);
      FileInputStream in     = new FileInputStream(getSessionFile(recipientId, deviceId));

      int versionMarker  = readInteger(in);

      if (versionMarker > CURRENT_VERSION) {
        throw new AssertionError("Unknown version: " + versionMarker);
      }

      byte[] serialized = cipher.decryptBytes(readBlob(in));
      in.close();

      if (versionMarker == SINGLE_STATE_VERSION) {
        SessionStructure sessionStructure = SessionStructure.parseFrom(serialized);
        SessionState     sessionState     = new SessionState(sessionStructure);
        return new SessionRecord(sessionState);
      } else if (versionMarker == ARCHIVE_STATES_VERSION) {
        return new SessionRecord(serialized);
      } else {
        throw new AssertionError("Unknown version: " + versionMarker);
      }
    } catch (InvalidMessageException | IOException e) {
      Log.w(TAG, "No existing session information found.");
      return new SessionRecord();
    }
  }
}
 
开发者ID:redcracker,项目名称:TextSecure,代码行数:32,代码来源:TextSecureSessionStore.java


示例12: storeSession

import org.whispersystems.libaxolotl.state.SessionRecord; //导入依赖的package包/类
@Override
public void storeSession(final AxolotlAddress address, final SessionRecord record) {
	try {
		SessionTable.getInstance().storeSession(address, record);
	} catch (final SQLException e) {
		LOGGER.error("Session could not be stored to database.", e);
		Errors.showError(translate("unexpected_quit"));
		Errors.stopApplication();
		throw new UnreachableCodeException();
	}
}
 
开发者ID:connorlanigan,项目名称:norvos,代码行数:12,代码来源:SessionStore.java


示例13: storeSession

import org.whispersystems.libaxolotl.state.SessionRecord; //导入依赖的package包/类
public void storeSession(final AxolotlAddress address, final SessionRecord record) throws SQLException {
	final String query = "MERGE INTO session_store VALUES (?, ?, ?)";

	try (PreparedStatement stmt = Database.ensureTableExists(this).prepareStatement(query)) {
		stmt.setString(1, address.getName());
		stmt.setInt(2, address.getDeviceId());
		stmt.setBytes(3, record.serialize());

		stmt.execute();
	}
}
 
开发者ID:connorlanigan,项目名称:norvos,代码行数:12,代码来源:SessionTable.java


示例14: getRemoteIdentityKey

import org.whispersystems.libaxolotl.state.SessionRecord; //导入依赖的package包/类
private IdentityKey getRemoteIdentityKey(MasterSecret masterSecret, Recipient recipient) {
  SessionStore   sessionStore   = new TextSecureSessionStore(this, masterSecret);
  AxolotlAddress axolotlAddress = new AxolotlAddress(recipient.getNumber(), TextSecureAddress.DEFAULT_DEVICE_ID);
  SessionRecord  record         = sessionStore.loadSession(axolotlAddress);

  if (record == null) {
    return null;
  }

  return record.getSessionState().getRemoteIdentityKey();
}
 
开发者ID:Agilitum,项目名称:TextSecureSMP,代码行数:12,代码来源:VerifyIdentityActivity.java


示例15: loadSession

import org.whispersystems.libaxolotl.state.SessionRecord; //导入依赖的package包/类
@Override
public SessionRecord loadSession(AxolotlAddress address) {
  synchronized (FILE_LOCK) {
    try {
      MasterCipher    cipher = new MasterCipher(masterSecret);
      FileInputStream in     = new FileInputStream(getSessionFile(address));

      int versionMarker  = readInteger(in);

      if (versionMarker > CURRENT_VERSION) {
        throw new AssertionError("Unknown version: " + versionMarker);
      }

      byte[] serialized = cipher.decryptBytes(readBlob(in));
      in.close();

      if (versionMarker == SINGLE_STATE_VERSION) {
        SessionStructure sessionStructure = SessionStructure.parseFrom(serialized);
        SessionState     sessionState     = new SessionState(sessionStructure);
        return new SessionRecord(sessionState);
      } else if (versionMarker == ARCHIVE_STATES_VERSION) {
        return new SessionRecord(serialized);
      } else {
        throw new AssertionError("Unknown version: " + versionMarker);
      }
    } catch (InvalidMessageException | IOException e) {
      Log.w(TAG, "No existing session information found.");
      return new SessionRecord();
    }
  }
}
 
开发者ID:Agilitum,项目名称:TextSecureSMP,代码行数:32,代码来源:TextSecureSessionStore.java


示例16: processV3

import org.whispersystems.libaxolotl.state.SessionRecord; //导入依赖的package包/类
private Optional<Integer> processV3(SessionRecord sessionRecord, PreKeyWhisperMessage message)
    throws UntrustedIdentityException, InvalidKeyIdException, InvalidKeyException
{

  if (sessionRecord.hasSessionState(message.getMessageVersion(), message.getBaseKey().serialize())) {
    Log.w(TAG, "We've already setup a session for this V3 message, letting bundled message fall through...");
    return Optional.absent();
  }

  ECKeyPair ourSignedPreKey = signedPreKeyStore.loadSignedPreKey(message.getSignedPreKeyId()).getKeyPair();

  BobAxolotlParameters.Builder parameters = BobAxolotlParameters.newBuilder();

  parameters.setTheirBaseKey(message.getBaseKey())
            .setTheirIdentityKey(message.getIdentityKey())
            .setOurIdentityKey(identityKeyStore.getIdentityKeyPair())
            .setOurSignedPreKey(ourSignedPreKey)
            .setOurRatchetKey(ourSignedPreKey);

  if (message.getPreKeyId().isPresent()) {
    parameters.setOurOneTimePreKey(Optional.of(preKeyStore.loadPreKey(message.getPreKeyId().get()).getKeyPair()));
  } else {
    parameters.setOurOneTimePreKey(Optional.<ECKeyPair>absent());
  }

  if (!sessionRecord.isFresh()) sessionRecord.archiveCurrentState();

  RatchetingSession.initializeSession(sessionRecord.getSessionState(), message.getMessageVersion(), parameters.create());

  sessionRecord.getSessionState().setLocalRegistrationId(identityKeyStore.getLocalRegistrationId());
  sessionRecord.getSessionState().setRemoteRegistrationId(message.getRegistrationId());
  sessionRecord.getSessionState().setAliceBaseKey(message.getBaseKey().serialize());

  if (message.getPreKeyId().isPresent() && message.getPreKeyId().get() != Medium.MAX_VALUE) {
    return message.getPreKeyId();
  } else {
    return Optional.absent();
  }
}
 
开发者ID:Securecom,项目名称:Securecom-Messaging,代码行数:40,代码来源:SessionBuilder.java


示例17: processV2

import org.whispersystems.libaxolotl.state.SessionRecord; //导入依赖的package包/类
private Optional<Integer> processV2(SessionRecord sessionRecord, PreKeyWhisperMessage message)
    throws UntrustedIdentityException, InvalidKeyIdException, InvalidKeyException
{
  if (!message.getPreKeyId().isPresent()) {
    throw new InvalidKeyIdException("V2 message requires one time prekey id!");
  }

  if (!preKeyStore.containsPreKey(message.getPreKeyId().get()) &&
      sessionStore.containsSession(recipientId, deviceId))
  {
    Log.w(TAG, "We've already processed the prekey part of this V2 session, letting bundled message fall through...");
    return Optional.absent();
  }

  ECKeyPair ourPreKey = preKeyStore.loadPreKey(message.getPreKeyId().get()).getKeyPair();

  BobAxolotlParameters.Builder parameters = BobAxolotlParameters.newBuilder();

  parameters.setOurIdentityKey(identityKeyStore.getIdentityKeyPair())
            .setOurSignedPreKey(ourPreKey)
            .setOurRatchetKey(ourPreKey)
            .setOurOneTimePreKey(Optional.<ECKeyPair>absent())
            .setTheirIdentityKey(message.getIdentityKey())
            .setTheirBaseKey(message.getBaseKey());

  if (!sessionRecord.isFresh()) sessionRecord.archiveCurrentState();

  RatchetingSession.initializeSession(sessionRecord.getSessionState(), message.getMessageVersion(), parameters.create());

  sessionRecord.getSessionState().setLocalRegistrationId(identityKeyStore.getLocalRegistrationId());
  sessionRecord.getSessionState().setRemoteRegistrationId(message.getRegistrationId());
  sessionRecord.getSessionState().setAliceBaseKey(message.getBaseKey().serialize());

  if (message.getPreKeyId().get() != Medium.MAX_VALUE) {
    return message.getPreKeyId();
  } else {
    return Optional.absent();
  }
}
 
开发者ID:Securecom,项目名称:Securecom-Messaging,代码行数:40,代码来源:SessionBuilder.java


示例18: getSessionVersion

import org.whispersystems.libaxolotl.state.SessionRecord; //导入依赖的package包/类
public int getSessionVersion() {
  synchronized (SESSION_LOCK) {
    if (!sessionStore.containsSession(recipientId, deviceId)) {
      throw new IllegalStateException(String.format("No session for (%d, %d)!", recipientId, deviceId));
    }

    SessionRecord record = sessionStore.loadSession(recipientId, deviceId);
    return record.getSessionState().getSessionVersion();
  }
}
 
开发者ID:Securecom,项目名称:Securecom-Messaging,代码行数:11,代码来源:SessionCipher.java


示例19: testBasicSessionV2

import org.whispersystems.libaxolotl.state.SessionRecord; //导入依赖的package包/类
public void testBasicSessionV2()
    throws InvalidKeyException, DuplicateMessageException,
    LegacyMessageException, InvalidMessageException, NoSuchAlgorithmException, NoSessionException
{
  SessionRecord aliceSessionRecord = new SessionRecord();
  SessionRecord bobSessionRecord   = new SessionRecord();

  initializeSessionsV2(aliceSessionRecord.getSessionState(), bobSessionRecord.getSessionState());
  runInteraction(aliceSessionRecord, bobSessionRecord);
}
 
开发者ID:Securecom,项目名称:Securecom-Messaging,代码行数:11,代码来源:SessionCipherTest.java


示例20: testBasicSessionV3

import org.whispersystems.libaxolotl.state.SessionRecord; //导入依赖的package包/类
public void testBasicSessionV3()
    throws InvalidKeyException, DuplicateMessageException,
    LegacyMessageException, InvalidMessageException, NoSuchAlgorithmException, NoSessionException
{
  SessionRecord aliceSessionRecord = new SessionRecord();
  SessionRecord bobSessionRecord   = new SessionRecord();

  initializeSessionsV3(aliceSessionRecord.getSessionState(), bobSessionRecord.getSessionState());
  runInteraction(aliceSessionRecord, bobSessionRecord);
}
 
开发者ID:Securecom,项目名称:Securecom-Messaging,代码行数:11,代码来源:SessionCipherTest.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Action1类代码示例发布时间:2022-05-22
下一篇:
Java AndroidInfoModule类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap