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


Java SignalProtocolAddress类代码示例

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


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

示例1: isTrustedIdentity

import org.whispersystems.libsignal.SignalProtocolAddress; //导入依赖的package包/类
@Override
public boolean isTrustedIdentity(SignalProtocolAddress address, IdentityKey identityKey) {
  long    recipientId = RecipientFactory.getRecipientsFromString(context, address.getName(), true).getPrimaryRecipient().getRecipientId();
  boolean trusted     = DatabaseFactory.getIdentityDatabase(context)
                                       .isValidIdentity(recipientId, identityKey);

  if (trusted) {
    return true;
  } else if (!TextSecurePreferences.isBlockingIdentityUpdates(context)) {
    saveIdentity(address, identityKey);
    new TextSecureSessionStore(context).deleteAllSessions(address.getName());

    ApplicationContext.getInstance(context)
                      .getJobManager()
                      .add(new IdentityUpdateJob(context, recipientId));

    return true;
  } else {
    return false;
  }
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:22,代码来源:TextSecureIdentityKeyStore.java

示例2: storeSession

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

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

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

示例3: migrateSessions

import org.whispersystems.libsignal.SignalProtocolAddress; //导入依赖的package包/类
public void migrateSessions() {
  synchronized (FILE_LOCK) {
    File directory = getSessionDirectory();

    for (File session : directory.listFiles()) {
      if (session.isFile()) {
        SignalProtocolAddress address = getAddressName(session);

        if (address != null) {
          SessionRecord sessionRecord = loadSession(address);
          storeSession(address, sessionRecord);
        }
      }
    }
  }
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:17,代码来源:TextSecureSessionStore.java

示例4: getAddressName

import org.whispersystems.libsignal.SignalProtocolAddress; //导入依赖的package包/类
private @Nullable SignalProtocolAddress getAddressName(File sessionFile) {
  try {
    String[]  parts     = sessionFile.getName().split("[.]");
    Recipient recipient = RecipientFactory.getRecipientForId(context, Integer.valueOf(parts[0]), true);

    int deviceId;

    if (parts.length > 1) deviceId = Integer.parseInt(parts[1]);
    else                  deviceId = SignalServiceAddress.DEFAULT_DEVICE_ID;

    return new SignalProtocolAddress(recipient.getNumber(), deviceId);
  } catch (NumberFormatException e) {
    Log.w(TAG, e);
    return null;
  }
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:17,代码来源:TextSecureSessionStore.java

示例5: encrypt

import org.whispersystems.libsignal.SignalProtocolAddress; //导入依赖的package包/类
public OutgoingPushMessage encrypt(SignalProtocolAddress destination, byte[] unpaddedMessage, boolean legacy, boolean silent) {
  SessionCipher        sessionCipher        = new SessionCipher(signalProtocolStore, destination);
  PushTransportDetails transportDetails     = new PushTransportDetails(sessionCipher.getSessionVersion());
  CiphertextMessage    message              = sessionCipher.encrypt(transportDetails.getPaddedMessageBody(unpaddedMessage));
  int                  remoteRegistrationId = sessionCipher.getRemoteRegistrationId();
  String               body                 = Base64.encodeBytes(message.serialize());

  int type;

  switch (message.getType()) {
    case CiphertextMessage.PREKEY_TYPE:  type = Type.PREKEY_BUNDLE_VALUE; break;
    case CiphertextMessage.WHISPER_TYPE: type = Type.CIPHERTEXT_VALUE;    break;
    default: throw new AssertionError("Bad type: " + message.getType());
  }

  return new OutgoingPushMessage(type, destination.getDeviceId(), remoteRegistrationId,
                                 legacy ? body : null, legacy ? null : body, silent);
}
 
开发者ID:XecureIT,项目名称:PeSanKita-lib,代码行数:19,代码来源:SignalServiceCipher.java

示例6: decrypt

import org.whispersystems.libsignal.SignalProtocolAddress; //导入依赖的package包/类
private byte[] decrypt(SignalServiceEnvelope envelope, byte[] ciphertext)
    throws InvalidVersionException, InvalidMessageException, InvalidKeyException,
           DuplicateMessageException, InvalidKeyIdException, UntrustedIdentityException,
           LegacyMessageException, NoSessionException
{
  SignalProtocolAddress sourceAddress = new SignalProtocolAddress(envelope.getSource(), envelope.getSourceDevice());
  SessionCipher         sessionCipher = new SessionCipher(signalProtocolStore, sourceAddress);

  byte[] paddedMessage;

  if (envelope.isPreKeySignalMessage()) {
    paddedMessage = sessionCipher.decrypt(new PreKeySignalMessage(ciphertext));
  } else if (envelope.isSignalMessage()) {
    paddedMessage = sessionCipher.decrypt(new SignalMessage(ciphertext));
  } else {
    throw new InvalidMessageException("Unknown type: " + envelope.getType());
  }

  PushTransportDetails transportDetails = new PushTransportDetails(sessionCipher.getSessionVersion());
  return transportDetails.getStrippedPaddingMessageBody(paddedMessage);
}
 
开发者ID:XecureIT,项目名称:PeSanKita-lib,代码行数:22,代码来源:SignalServiceCipher.java

示例7: archiveSiblingSessions

import org.whispersystems.libsignal.SignalProtocolAddress; //导入依赖的package包/类
public static void archiveSiblingSessions(Context context, SignalProtocolAddress address) {
  SessionStore  sessionStore = new TextSecureSessionStore(context);
  List<Integer> devices      = sessionStore.getSubDeviceSessions(address.getName());
  devices.add(1);

  for (int device : devices) {
    if (device != address.getDeviceId()) {
      SignalProtocolAddress sibling = new SignalProtocolAddress(address.getName(), device);

      if (sessionStore.containsSession(sibling)) {
        SessionRecord sessionRecord = sessionStore.loadSession(sibling);
        sessionRecord.archiveCurrentState();
        sessionStore.storeSession(sibling, sessionRecord);
      }
    }
  }
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:18,代码来源:SessionUtil.java

示例8: isTrustedIdentity

import org.whispersystems.libsignal.SignalProtocolAddress; //导入依赖的package包/类
@Override
public boolean isTrustedIdentity(SignalProtocolAddress address, IdentityKey identityKey, Direction direction) {
  synchronized (LOCK) {
    IdentityDatabase identityDatabase = DatabaseFactory.getIdentityDatabase(context);
    long             recipientId      = RecipientFactory.getRecipientsFromString(context, address.getName(), true).getPrimaryRecipient().getRecipientId();
    String           ourNumber        = TextSecurePreferences.getLocalNumber(context);
    long             ourRecipientId   = RecipientFactory.getRecipientsFromString(context, ourNumber, true).getPrimaryRecipient().getRecipientId();

    if (ourRecipientId == recipientId || ourNumber.equals(address.getName())) {
      return identityKey.equals(IdentityKeyUtil.getIdentityKey(context));
    }

    switch (direction) {
      case SENDING:   return isTrustedForSending(identityKey, identityDatabase.getIdentity(recipientId));
      case RECEIVING: return true;
      default:        throw new AssertionError("Unknown direction: " + direction);
    }
  }
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:20,代码来源:TextSecureIdentityKeyStore.java

示例9: archiveAllSessions

import org.whispersystems.libsignal.SignalProtocolAddress; //导入依赖的package包/类
public void archiveAllSessions() {
  synchronized (FILE_LOCK) {
    File directory = getSessionDirectory();

    for (File session : directory.listFiles()) {
      if (session.isFile()) {
        SignalProtocolAddress address = getAddressName(session);

        if (address != null) {
          SessionRecord sessionRecord = loadSession(address);
          sessionRecord.archiveCurrentState();
          storeSession(address, sessionRecord);
        }
      }
    }
  }
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:18,代码来源:TextSecureSessionStore.java

示例10: saveIdentity

import org.whispersystems.libsignal.SignalProtocolAddress; //导入依赖的package包/类
public static void saveIdentity(Context context, String number, IdentityKey identityKey) {
  synchronized (SESSION_LOCK) {
    IdentityKeyStore      identityKeyStore = new TextSecureIdentityKeyStore(context);
    SessionStore          sessionStore     = new TextSecureSessionStore(context);
    SignalProtocolAddress address          = new SignalProtocolAddress(number, 1);

    if (identityKeyStore.saveIdentity(address, identityKey)) {
      if (sessionStore.containsSession(address)) {
        SessionRecord sessionRecord = sessionStore.loadSession(address);
        sessionRecord.archiveCurrentState();

        sessionStore.storeSession(address, sessionRecord);
      }
    }
  }
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:17,代码来源:IdentityUtil.java

示例11: getSubDeviceSessions

import org.whispersystems.libsignal.SignalProtocolAddress; //导入依赖的package包/类
private List<Integer> getSubDeviceSessions(SQLiteDatabase db, Account account, SignalProtocolAddress contact) {
	List<Integer> devices = new ArrayList<>();
	String[] columns = {SQLiteAxolotlStore.DEVICE_ID};
	String[] selectionArgs = {account.getUuid(),
			contact.getName()};
	Cursor cursor = db.query(SQLiteAxolotlStore.SESSION_TABLENAME,
			columns,
			SQLiteAxolotlStore.ACCOUNT + " = ? AND "
					+ SQLiteAxolotlStore.NAME + " = ?",
			selectionArgs,
			null, null, null);

	while (cursor.moveToNext()) {
		devices.add(cursor.getInt(
				cursor.getColumnIndex(SQLiteAxolotlStore.DEVICE_ID)));
	}

	cursor.close();
	return devices;
}
 
开发者ID:syntafin,项目名称:TenguChat,代码行数:21,代码来源:DatabaseBackend.java

示例12: putDevicesForJid

import org.whispersystems.libsignal.SignalProtocolAddress; //导入依赖的package包/类
private void putDevicesForJid(String bareJid, List<Integer> deviceIds, SQLiteAxolotlStore store) {
	for (Integer deviceId : deviceIds) {
		SignalProtocolAddress axolotlAddress = new SignalProtocolAddress(bareJid, deviceId);
		IdentityKey identityKey = store.loadSession(axolotlAddress).getSessionState().getRemoteIdentityKey();
		if(Config.X509_VERIFICATION) {
			X509Certificate certificate = store.getFingerprintCertificate(CryptoHelper.bytesToHex(identityKey.getPublicKey().serialize()));
			if (certificate != null) {
				Bundle information = CryptoHelper.extractCertificateInformation(certificate);
				try {
					final String cn = information.getString("subject_cn");
					final Jid jid = Jid.fromString(bareJid);
					Log.d(Config.LOGTAG,"setting common name for "+jid+" to "+cn);
					account.getRoster().getContact(jid).setCommonName(cn);
				} catch (final InvalidJidException ignored) {
					//ignored
				}
			}
		}
		this.put(axolotlAddress, new XmppAxolotlSession(account, store, axolotlAddress, identityKey));
	}
}
 
开发者ID:syntafin,项目名称:TenguChat,代码行数:22,代码来源:AxolotlService.java

示例13: createSessionsIfNeededActual

import org.whispersystems.libsignal.SignalProtocolAddress; //导入依赖的package包/类
private boolean createSessionsIfNeededActual(final Conversation conversation) {
	Log.i(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Creating axolotl sessions if needed...");
	boolean newSessions = false;
	Set<SignalProtocolAddress> addresses = findDevicesWithoutSession(conversation);
	for (SignalProtocolAddress address : addresses) {
		Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Processing device: " + address.toString());
		FetchStatus status = fetchStatusMap.get(address);
		if (status == null || status == FetchStatus.TIMEOUT) {
			fetchStatusMap.put(address, FetchStatus.PENDING);
			this.buildSessionFromPEP(address);
			newSessions = true;
		} else if (status == FetchStatus.PENDING) {
			newSessions = true;
		} else {
			Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Already fetching bundle for " + address.toString());
		}
	}

	return newSessions;
}
 
开发者ID:syntafin,项目名称:TenguChat,代码行数:21,代码来源:AxolotlService.java

示例14: saveIdentity

import org.whispersystems.libsignal.SignalProtocolAddress; //导入依赖的package包/类
/**
 * Save a remote client's identity key
 * <p/>
 * Store a remote client's identity key as trusted.
 *
 * @param address     The address of the remote client.
 * @param identityKey The remote client's identity key.
 * @return true on success
 */
@Override
public boolean saveIdentity(SignalProtocolAddress address, IdentityKey identityKey) {
	if (!mXmppConnectionService.databaseBackend.loadIdentityKeys(account, address.getName()).contains(identityKey)) {
		String fingerprint = CryptoHelper.bytesToHex(identityKey.getPublicKey().serialize());
		FingerprintStatus status = getFingerprintStatus(fingerprint);
		if (status == null) {
			if (mXmppConnectionService.blindTrustBeforeVerification() && !account.getAxolotlService().hasVerifiedKeys(address.getName())) {
				Log.d(Config.LOGTAG,account.getJid().toBareJid()+": blindly trusted "+fingerprint+" of "+address.getName());
				status = FingerprintStatus.createActiveTrusted();
			} else {
				status = FingerprintStatus.createActiveUndecided();
			}
		} else {
			status = status.toActive();
		}
		mXmppConnectionService.databaseBackend.storeIdentityKey(account, address.getName(), identityKey, status);
		trustCache.remove(fingerprint);
	}
	return true;
}
 
开发者ID:syntafin,项目名称:TenguChat,代码行数:30,代码来源:SQLiteAxolotlStore.java

示例15: storeSession

import org.whispersystems.libsignal.SignalProtocolAddress; //导入依赖的package包/类
@Override
public void storeSession(@NonNull final SignalProtocolAddress address, @NonNull final SessionRecord record) {
    synchronized (FILE_LOCK) {
        try {
            RandomAccessFile sessionFile  = new RandomAccessFile(getSessionFile(address), "rw");
            FileChannel      out          = sessionFile.getChannel();

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

            sessionFile.close();
        } catch (IOException e) {
            throw new AssertionError(e);
        }
    }
}
 
开发者ID:toshiapp,项目名称:toshi-android-client,代码行数:19,代码来源:SignalSessionStore.java


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