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


Java KeyHelper类代码示例

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


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

示例1: finishConnectAsPrimary

import org.whispersystems.libsignal.util.KeyHelper; //导入依赖的package包/类
/**
 * Finish the connection and registration as primary device with the received verification code
 * @param verificationCode the verification code without the -
 * @throws IOException
 */
public void finishConnectAsPrimary(String verificationCode) throws IOException {
	if(accountManager == null) {
		throw new IllegalStateException("Cannot finish: No connection started!");
	} else if(isRegistered()) {
		throw new IllegalStateException("Already registered!");
	}
	createRegistrationId();
	accountManager.verifyAccountWithCode(verificationCode, store.getSignalingKey(), 
			store.getLocalRegistrationId(), false, true);
	IdentityKeyPair identityKeyPair = KeyHelper.generateIdentityKeyPair();
	store.setIdentityKeyPair(identityKeyPair);
	store.setLastResortPreKey(KeyHelper.generateLastResortPreKey());
	checkPreKeys(-1);
	save();
}
 
开发者ID:Turakar,项目名称:signal4j,代码行数:21,代码来源:SignalService.java

示例2: finishConnectAsSecondary

import org.whispersystems.libsignal.util.KeyHelper; //导入依赖的package包/类
/**
 * Blocking call. Call this directly after {@code startConnectAsSecondary()} and this method will wait
 * for the master device accepting this device.
 * @param deviceName a name for this device (not the user agent)
 * @param supportsSms whether this device can receive and send SMS
 * @throws IOException
 * @throws TimeoutException
 */
public void finishConnectAsSecondary(String deviceName, boolean supportsSms) throws IOException, TimeoutException {
	if(accountManager == null) {
		throw new IllegalStateException("Cannot finish: No connection started!");
	} else if(isRegistered()) {
		throw new IllegalStateException("Already registered!");
	}
	try {
		NewDeviceRegistrationReturn ret = accountManager.finishNewDeviceRegistration(tempIdentity,
				store.getSignalingKey(), supportsSms, true, store.getLocalRegistrationId(), deviceName);
		store.setDeviceId(ret.getDeviceId());
		store.setIdentityKeyPair(ret.getIdentity());
	} catch (InvalidKeyException e) {
		throw new RuntimeException("This can not happen - theoretically", e);
	}
	store.setLastResortPreKey(KeyHelper.generateLastResortPreKey());
	checkPreKeys(-1);
	save();
}
 
开发者ID:Turakar,项目名称:signal4j,代码行数:27,代码来源:SignalService.java

示例3: getQrCode

import org.whispersystems.libsignal.util.KeyHelper; //导入依赖的package包/类
public void getQrCode(Consumer<String> callback) {
	executor.submit(new Runnable() {
		@Override
		public void run() {
			try {
				logger.debug("Creating QR code for provisioning");
				temporaryPassword = SecretUtil.getSecret(18);
				temporaryIdentity = KeyHelper.generateIdentityKeyPair();
				accountManager = new SignalServiceAccountManager(SignalConstants.URL, new ResourceTrustStore(),
						null, temporaryPassword, SignalConstants.USER_AGENT);

				String uuid = accountManager.getNewDeviceUuid();
				String publicKey = Base64.encodeBytesWithoutPadding(temporaryIdentity.getPublicKey().serialize());
				String qrString = "tsdevice:/?uuid=" + URLEncoder.encode(uuid, "UTF-8") + "&pub_key="
						+ URLEncoder.encode(publicKey, "UTF-8");
				logger.debug("Content of qr code: {}", qrString);

				String qrCode = QRCode.from(qrString).file().getAbsolutePath();
				callback.accept(qrCode);
			} catch (IOException | TimeoutException e) {
				throw new RuntimeException("Networking error while creating provisioning QR code!", e);
			}
		}
	});
}
 
开发者ID:Turakar,项目名称:Signal-JDesktop,代码行数:26,代码来源:SignalAccountHelper.java

示例4: finishRegistration

import org.whispersystems.libsignal.util.KeyHelper; //导入依赖的package包/类
public void finishRegistration(String deviceName, Consumer<Void> callback) {
	executor.submit(new Runnable() {
		@Override
		public void run() {
			String temporarySignalingKey = SecretUtil.getSecret(52);
			int temporaryRegistrationId = KeyHelper.generateRegistrationId(false);
			try {
				NewDeviceRegistrationReturn ret = accountManager.finishNewDeviceRegistration(temporaryIdentity,
						temporarySignalingKey, false, true, temporaryRegistrationId, deviceName);
				logger.debug("Got response from master device for provisioning");
				Main.getInstance().getStore().getUserStore().createNewIdentity(ret.getNumber(), ret.getDeviceId(),
						temporaryPassword, temporaryRegistrationId, temporarySignalingKey, temporaryIdentity);
				callback.accept(null);
			} catch (TimeoutException | IOException | InvalidKeyException e) {
				e.printStackTrace();
				throw new RuntimeException("Could not finish device registration!", e);
			}

		}
	});
}
 
开发者ID:Turakar,项目名称:Signal-JDesktop,代码行数:22,代码来源:SignalAccountHelper.java

示例5: process

import org.whispersystems.libsignal.util.KeyHelper; //导入依赖的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(remoteAddress);

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

      return new KeyExchangeMessage(CiphertextMessage.CURRENT_VERSION,
                                    sequence, flags, baseKey.getPublicKey(), baseKeySignature,
                                    ratchetKey.getPublicKey(), identityKey.getPublicKey());
    } catch (InvalidKeyException e) {
      throw new AssertionError(e);
    }
  }
}
 
开发者ID:SilenceIM,项目名称:Silence,代码行数:28,代码来源:SessionBuilder.java

示例6: create

import org.whispersystems.libsignal.util.KeyHelper; //导入依赖的package包/类
/**
 * Construct a group session for sending messages.
 *
 * @param senderKeyName The (groupId, senderId, deviceId) tuple.  In this case, 'senderId' should be the caller.
 * @return A SenderKeyDistributionMessage that is individually distributed to each member of the group.
 */
public SenderKeyDistributionMessage create(SenderKeyName senderKeyName) {
  synchronized (GroupCipher.LOCK) {
    try {
      SenderKeyRecord senderKeyRecord = senderKeyStore.loadSenderKey(senderKeyName);

      if (senderKeyRecord.isEmpty()) {
        senderKeyRecord.setSenderKeyState(KeyHelper.generateSenderKeyId(),
                                          0,
                                          KeyHelper.generateSenderKey(),
                                          KeyHelper.generateSenderSigningKey());
        senderKeyStore.storeSenderKey(senderKeyName, senderKeyRecord);
      }

      SenderKeyState state = senderKeyRecord.getSenderKeyState();

      return new SenderKeyDistributionMessage(state.getKeyId(),
                                              state.getSenderChainKey().getIteration(),
                                              state.getSenderChainKey().getSeed(),
                                              state.getSigningKeyPublic());

    } catch (InvalidKeyIdException | InvalidKeyException e) {
      throw new AssertionError(e);
    }
  }
}
 
开发者ID:signalapp,项目名称:libsignal-protocol-java,代码行数:32,代码来源:GroupSessionBuilder.java

示例7: checkPreKeys

import org.whispersystems.libsignal.util.KeyHelper; //导入依赖的package包/类
/**
 * Ensures that there are enough prekeys available. Has to be called regularly.<br>
 * Every time somebody sends you a message, he uses one of your prekeys which you have uploaded earlier.
 * To always have one prekey available, you also upload a last resort key. You should always
 * have enough prekeys to prevent key reusing.
 * @param minimumKeys the minimum amount of keys to register. Must be below 100.
 * @throws IOException
 */
public void checkPreKeys(int minimumKeys) throws IOException {
	if(minimumKeys > PREKEYS_BATCH_SIZE) {
		throw new IllegalArgumentException("PreKeys count must be below or equal to " + PREKEYS_BATCH_SIZE);
	}
	checkRegistered();
	int preKeysCount = accountManager.getPreKeysCount();
	if(preKeysCount < minimumKeys || minimumKeys < 0) {
		try {
			// generate prekeys
			int nextPreKeyId = store.getNextPreKeyId();
			ArrayList<PreKeyRecord> preKeys = new ArrayList<>();
			for(int i = 0; i < PREKEYS_BATCH_SIZE; i++) {
				PreKeyRecord record = new PreKeyRecord(nextPreKeyId, Curve.generateKeyPair());
				store.storePreKey(record.getId(), record);
				preKeys.add(record);
				nextPreKeyId = (nextPreKeyId + 1) % MAX_PREKEY_ID;
			}
			store.setNextPreKeyId(nextPreKeyId);
			
			// generate signed prekey
			int nextSignedPreKeyId = store.getNextSignedPreKeyId();
			SignedPreKeyRecord signedPreKey = KeyHelper.generateSignedPreKey(store.getIdentityKeyPair(), nextSignedPreKeyId);
			store.storeSignedPreKey(signedPreKey.getId(), signedPreKey);
			store.setNextSignedPreKeyId((nextSignedPreKeyId + 1) % MAX_PREKEY_ID);
			
			// upload
			accountManager.setPreKeys(store.getIdentityKeyPair().getPublicKey(), store.getLastResortPreKey(), 
					signedPreKey, preKeys);
		} catch (InvalidKeyException e) {
			throw new RuntimeException("Stored identity corrupt!", e);
		}
		save();
	}
}
 
开发者ID:Turakar,项目名称:signal4j,代码行数:43,代码来源:SignalService.java

示例8: createNewIdentity

import org.whispersystems.libsignal.util.KeyHelper; //导入依赖的package包/类
public void createNewIdentity() {
    IdentityKeyPair identityKey = KeyHelper.generateIdentityKeyPair();
    int registrationId = KeyHelper.generateRegistrationId(false);
    signalProtocolStore = new JsonSignalProtocolStore(identityKey, registrationId);
    groupStore = new JsonGroupStore();
    registered = false;
    save();
}
 
开发者ID:AsamK,项目名称:signal-cli,代码行数:9,代码来源:Manager.java

示例9: handleSmsRegistrationIntent

import org.whispersystems.libsignal.util.KeyHelper; //导入依赖的package包/类
private void handleSmsRegistrationIntent(Intent intent) {
  markAsVerifying(true);

  String  number         = intent.getStringExtra(NUMBER_EXTRA);
  boolean supportsGcm    = intent.getBooleanExtra(GCM_SUPPORTED_EXTRA, true);
  int     registrationId = TextSecurePreferences.getLocalRegistrationId(this);
  boolean supportsVideo  = TextSecurePreferences.isWebrtcCallingEnabled(this) || !supportsGcm;

  if (registrationId == 0) {
    registrationId = KeyHelper.generateRegistrationId(false);
    TextSecurePreferences.setLocalRegistrationId(this, registrationId);
  }

  String password     = Util.getSecret(18);
  String signalingKey = Util.getSecret(52);

  try {
    initializeChallengeListener();

    setState(new RegistrationState(RegistrationState.STATE_CONNECTING, number));
    SignalServiceAccountManager accountManager = AccountManagerFactory.createManager(this, number, password);
    accountManager.requestSmsVerificationCode();

    setState(new RegistrationState(RegistrationState.STATE_VERIFYING, number));
    String challenge = waitForChallenge();
    accountManager.verifyAccountWithCode(challenge, signalingKey, registrationId, true, supportsVideo, !supportsGcm);

    handleCommonRegistration(accountManager, number, password, signalingKey, supportsGcm);
    markAsVerified(number, password, signalingKey);

    setState(new RegistrationState(RegistrationState.STATE_COMPLETE, number));
    broadcastComplete(true);
  } catch (ExpectationFailedException efe) {
    Log.w("RegistrationService", efe);
    setState(new RegistrationState(RegistrationState.STATE_MULTI_REGISTERED, number));
    broadcastComplete(false);
  } catch (UnsupportedOperationException uoe) {
    Log.w("RegistrationService", uoe);
    setState(new RegistrationState(RegistrationState.STATE_GCM_UNSUPPORTED, number));
    broadcastComplete(false);
  } catch (AccountVerificationTimeoutException avte) {
    Log.w("RegistrationService", avte);
    setState(new RegistrationState(RegistrationState.STATE_TIMEOUT, number, password));
    broadcastComplete(false);
  } catch (IOException e) {
    Log.w("RegistrationService", e);
    setState(new RegistrationState(RegistrationState.STATE_NETWORK_ERROR, number));
    broadcastComplete(false);
  } finally {
    shutdownChallengeListener();
  }
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:53,代码来源:RegistrationService.java

示例10: handleSmsRegistrationIntent

import org.whispersystems.libsignal.util.KeyHelper; //导入依赖的package包/类
private void handleSmsRegistrationIntent(Intent intent) {
  markAsVerifying(true);

  String  number         = intent.getStringExtra(NUMBER_EXTRA);
  boolean supportsGcm    = false;
  int     registrationId = KeyHelper.generateRegistrationId(false);
  TextSecurePreferences.setLocalRegistrationId(this, registrationId);
  SessionUtil.archiveAllSessions(this);

  try {
    String password     = Util.getSecret(18);
    String signalingKey = Util.getSecret(52);

    initializeChallengeListener();

    setState(new RegistrationState(RegistrationState.STATE_CONNECTING, number));
    SignalServiceAccountManager accountManager = AccountManagerFactory.createManager(this, number, password);
    accountManager.requestSmsVerificationCode();

    setState(new RegistrationState(RegistrationState.STATE_VERIFYING, number));
    String challenge = waitForChallenge();
    accountManager.verifyAccountWithCode(challenge, signalingKey, registrationId, !supportsGcm);

    handleCommonRegistration(accountManager, number, password, signalingKey, supportsGcm);
    markAsVerified(number, password, signalingKey);

    setState(new RegistrationState(RegistrationState.STATE_COMPLETE, number));
    broadcastComplete(true);
  } catch (ExpectationFailedException efe) {
    Log.w("RegistrationService", efe);
    setState(new RegistrationState(RegistrationState.STATE_MULTI_REGISTERED, number));
    broadcastComplete(false);
  } catch (UnsupportedOperationException uoe) {
    Log.w("RegistrationService", uoe);
    setState(new RegistrationState(RegistrationState.STATE_GCM_UNSUPPORTED, number));
    broadcastComplete(false);
  } catch (AccountVerificationTimeoutException avte) {
    Log.w("RegistrationService", avte);
    setState(new RegistrationState(RegistrationState.STATE_TIMEOUT, number));
    broadcastComplete(false);
  } catch (IOException e) {
    Log.w("RegistrationService", e);
    setState(new RegistrationState(RegistrationState.STATE_NETWORK_ERROR, number));
    broadcastComplete(false);
  } finally {
    shutdownChallengeListener();
  }
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:49,代码来源:RegistrationService.java

示例11: generateRegistrationId

import org.whispersystems.libsignal.util.KeyHelper; //导入依赖的package包/类
private static int generateRegistrationId() {
	Log.i(Config.LOGTAG, AxolotlService.LOGPREFIX + " : " + "Generating axolotl registration ID...");
	return KeyHelper.generateRegistrationId(true);
}
 
开发者ID:syntafin,项目名称:TenguChat,代码行数:5,代码来源:SQLiteAxolotlStore.java

示例12: generateIdentityKeyPair

import org.whispersystems.libsignal.util.KeyHelper; //导入依赖的package包/类
private IdentityKeyPair generateIdentityKeyPair() {
    final IdentityKeyPair ikp = KeyHelper.generateIdentityKeyPair();
    SignalPreferences.setSerializedIdentityKeyPair(ikp.serialize());
    return ikp;
}
 
开发者ID:toshiapp,项目名称:toshi-android-client,代码行数:6,代码来源:ProtocolStore.java

示例13: generateLocalRegistrationId

import org.whispersystems.libsignal.util.KeyHelper; //导入依赖的package包/类
private int generateLocalRegistrationId() {
    final int rid = KeyHelper.generateRegistrationId(false);
    SignalPreferences.setLocalRegistrationId(rid);
    return rid;
}
 
开发者ID:toshiapp,项目名称:toshi-android-client,代码行数:6,代码来源:ProtocolStore.java

示例14: generateRegistrationId

import org.whispersystems.libsignal.util.KeyHelper; //导入依赖的package包/类
private static int generateRegistrationId() {
    Log.i(Config.LOGTAG, AxolotlService.LOGPREFIX + " : " + "Generating axolotl registration ID...");
    return KeyHelper.generateRegistrationId(true);
}
 
开发者ID:kriztan,项目名称:Pix-Art-Messenger,代码行数:5,代码来源:SQLiteAxolotlStore.java

示例15: generateRegistrationId

import org.whispersystems.libsignal.util.KeyHelper; //导入依赖的package包/类
private static int generateRegistrationId() {
  return KeyHelper.generateRegistrationId(false);
}
 
开发者ID:signalapp,项目名称:libsignal-protocol-java,代码行数:4,代码来源:TestInMemorySignalProtocolStore.java


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