Class Keys

All Implemented Interfaces:
it.auties.protobuf.model.ProtobufMessage, it.auties.protobuf.model.ProtobufObject

public final class Keys extends Controller<Keys> implements it.auties.protobuf.model.ProtobufMessage
This controller holds the cryptographic-related data regarding a WhatsappWeb session
  • Field Details

    • registrationId

      final Integer registrationId
      The client id
    • noiseKeyPair

      final SignalKeyPair noiseKeyPair
      The secret key pair used for buffer messages
    • ephemeralKeyPair

      final SignalKeyPair ephemeralKeyPair
      The ephemeral key pair
    • identityKeyPair

      final SignalKeyPair identityKeyPair
      The signed identity key
    • companionKeyPair

      SignalKeyPair companionKeyPair
      The companion secret key
    • signedKeyPair

      final SignalSignedKeyPair signedKeyPair
      The signed pre key
    • signedKeyIndex

      byte[] signedKeyIndex
      The signed key of the companion's device This value will be null until it gets synced by whatsapp
    • signedKeyIndexTimestamp

      Long signedKeyIndexTimestamp
      The timestampSeconds of the signed key companion's device
    • preKeys

      final List<SignalPreKeyPair> preKeys
      Whether these keys have generated pre keys assigned to them
    • fdid

      final String fdid
      The phone id for the mobile api
    • deviceId

      final byte[] deviceId
      The device id for the mobile api
    • advertisingId

      final UUID advertisingId
    • identityId

      final byte[] identityId
      The recovery token for the mobile api
    • companionIdentity

      SignedDeviceIdentity companionIdentity
      The bytes of the encoded SignedDeviceIdentityHMAC received during the auth process
    • senderKeys

      final Map<SenderKeyName,SenderKeyRecord> senderKeys
      Sender keys for signal implementation
    • appStateKeys

      final List<CompanionSyncKey> appStateKeys
      App state keys
    • sessions

      final Map<SessionAddress,Session> sessions
      Sessions map
    • hashStates

      final List<CompanionPatch> hashStates
      Hash state
    • groupsPreKeys

      final Map<Jid,SenderPreKeys> groupsPreKeys
    • registered

      boolean registered
      Whether the client was registered
    • businessCertificate

      boolean businessCertificate
      Whether the client has already sent its business certificate (mobile api only)
    • initialAppSync

      boolean initialAppSync
      Whether the client received the initial app sync (web api only)
    • writeCounter

      final AtomicLong writeCounter
      Write counter for IV
    • readCounter

      final AtomicLong readCounter
      Read counter for IV
    • writeKey

      byte[] writeKey
      Session dependent keys to write and read cyphered messages
    • readKey

      byte[] readKey
      Session dependent keys to write and read cyphered messages
  • Constructor Details

  • Method Details

    • newKeys

      public static Keys newKeys(UUID uuid, Long phoneNumber, Collection<String> alias, ClientType clientType)
    • encodedRegistrationId

      public byte[] encodedRegistrationId()
      Returns the encoded id
      Returns:
      a non-null byte array
    • clearReadWriteKey

      public void clearReadWriteKey()
      Clears the signal keys associated with this object
    • hasPreKeys

      public boolean hasPreKeys()
      Checks if the client sent pre keys to the server
      Returns:
      true if the client sent pre keys to the server
    • findSenderKeyByName

      public SenderKeyRecord findSenderKeyByName(SenderKeyName name)
      Queries the first SenderKeyRecord that matches name
      Parameters:
      name - the non-null name to search
      Returns:
      a non-null SenderKeyRecord
    • findSessionByAddress

      public Optional<Session> findSessionByAddress(SessionAddress address)
      Queries the Session that matches address
      Parameters:
      address - the non-null address to search
      Returns:
      a non-null Optional SessionRecord
    • findSignedKeyPairById

      public Optional<SignalSignedKeyPair> findSignedKeyPairById(int id)
      Queries the trusted key that matches id
      Parameters:
      id - the id to search
      Returns:
      a non-null signed key pair
      Throws:
      IllegalArgumentException - if no element can be found
    • findPreKeyById

      public Optional<SignalPreKeyPair> findPreKeyById(Integer id)
      Queries the trusted key that matches id
      Parameters:
      id - the non-null id to search
      Returns:
      a non-null pre key
    • findAppKeyById

      public Optional<AppStateSyncKey> findAppKeyById(Jid jid, byte[] id)
      Queries the app state key that matches id
      Parameters:
      jid - the non-null jid of the app key
      id - the non-null id to search
      Returns:
      a non-null Optional app state dataSync key
    • findHashStateByName

      public Optional<CompanionHashState> findHashStateByName(Jid device, PatchType patchType)
      Queries the hash state that matches name. Otherwise, creates a new one.
      Parameters:
      device - the non-null device
      patchType - the non-null name to search
      Returns:
      a non-null hash state
    • hasTrust

      public boolean hasTrust(SessionAddress address, byte[] identityKey)
      Checks whether identityKey is trusted for address
      Parameters:
      address - the non-null address
      identityKey - the nullable identity key
      Returns:
      true if any match is found
    • hasSession

      public boolean hasSession(SessionAddress address)
      Checks whether a session already whatsappOldEligible for the given address
      Parameters:
      address - the address to check
      Returns:
      true if a session for that address already whatsappOldEligible
    • putSession

      public Keys putSession(SessionAddress address, Session record)
      Adds the provided address and record to the known sessions
      Parameters:
      address - the non-null address
      record - the non-null record
      Returns:
      this
    • putState

      public Keys putState(Jid device, CompanionHashState state)
      Adds the provided hash state to the known ones
      Parameters:
      device - the non-null device
      state - the non-null hash state
      Returns:
      this
    • addAppKeys

      public Keys addAppKeys(Jid jid, Collection<AppStateSyncKey> keys)
      Adds the provided keys to the app state keys
      Parameters:
      jid - the non-null jid of the app key
      keys - the keys to add
      Returns:
      this
    • getLatestAppKey

      public AppStateSyncKey getLatestAppKey(Jid jid)
      Get any available app key
      Returns:
      a non-null app key
    • getAppKeys

      public LinkedList<AppStateSyncKey> getAppKeys(Jid jid)
      Get any available app key
      Returns:
      a non-null app key
    • addPreKey

      public Keys addPreKey(SignalPreKeyPair preKey)
      Adds the provided pre key to the pre keys
      Parameters:
      preKey - the key to add
      Returns:
      this
    • writeCounter

      public long writeCounter(boolean increment)
      Returns write counter
      Parameters:
      increment - whether the counter should be incremented after the call
      Returns:
      an unsigned long
    • readCounter

      public long readCounter(boolean increment)
      Returns read counter
      Parameters:
      increment - whether the counter should be incremented after the call
      Returns:
      an unsigned long
    • lastPreKeyId

      public int lastPreKeyId()
      Returns the id of the last available pre key
      Returns:
      an integer
    • companionIdentity

      public Keys companionIdentity(SignedDeviceIdentity companionIdentity)
      This function sets the companionIdentity field to the value of the companionIdentity parameter, serializes the object, and returns the object.
      Parameters:
      companionIdentity - The identity of the companion device.
      Returns:
      The object itself.
    • companionIdentity

      public Optional<SignedDeviceIdentity> companionIdentity()
      Returns the companion identity of this session Only available for web sessions
      Returns:
      an optional
    • preKeys

      public Collection<SignalPreKeyPair> preKeys()
      Returns all the registered pre keys
      Returns:
      a non-null collection
    • addRecipientWithPreKeys

      public void addRecipientWithPreKeys(Jid group, Jid recipient)
    • addRecipientsWithPreKeys

      public void addRecipientsWithPreKeys(Jid group, Collection<Jid> recipients)
    • hasGroupKeys

      public boolean hasGroupKeys(Jid group, Jid recipient)
    • dispose

      public void dispose()
      Description copied from class: Controller
      Disposes this object
      Specified by:
      dispose in class Controller<Keys>
    • serialize

      public void serialize(boolean async)
      Description copied from class: Controller
      Serializes this object
      Specified by:
      serialize in class Controller<Keys>
      Parameters:
      async - whether the operation should be executed asynchronously
    • registrationId

      public int registrationId()
    • noiseKeyPair

      public SignalKeyPair noiseKeyPair()
    • ephemeralKeyPair

      public SignalKeyPair ephemeralKeyPair()
    • identityKeyPair

      public SignalKeyPair identityKeyPair()
    • signedKeyPair

      public SignalSignedKeyPair signedKeyPair()
    • signedKeyIndex

      public Optional<byte[]> signedKeyIndex()
    • signedKeyIndexTimestamp

      public OptionalLong signedKeyIndexTimestamp()
    • companionKeyPair

      public SignalKeyPair companionKeyPair()
    • fdid

      public String fdid()
    • deviceId

      public byte[] deviceId()
    • advertisingId

      public UUID advertisingId()
    • identityId

      public byte[] identityId()
    • senderKeys

      public Map<SenderKeyName,SenderKeyRecord> senderKeys()
    • appStateKeys

      public List<CompanionSyncKey> appStateKeys()
    • sessions

      public Map<SessionAddress,Session> sessions()
    • hashStates

      public List<CompanionPatch> hashStates()
    • groupsPreKeys

      public Map<Jid,SenderPreKeys> groupsPreKeys()
    • registered

      public boolean registered()
    • businessCertificate

      public boolean businessCertificate()
    • initialAppSync

      public boolean initialAppSync()
    • writeCounter

      public AtomicLong writeCounter()
    • readCounter

      public AtomicLong readCounter()
    • writeKey

      public Optional<byte[]> writeKey()
    • readKey

      public Optional<byte[]> readKey()
    • setCompanionKeyPair

      public Keys setCompanionKeyPair(SignalKeyPair companionKeyPair)
    • setSignedKeyIndex

      public Keys setSignedKeyIndex(byte[] signedKeyIndex)
    • setSignedKeyIndexTimestamp

      public Keys setSignedKeyIndexTimestamp(Long signedKeyIndexTimestamp)
    • setCompanionIdentity

      public Keys setCompanionIdentity(SignedDeviceIdentity companionIdentity)
    • setRegistered

      public Keys setRegistered(boolean registered)
    • setBusinessCertificate

      public Keys setBusinessCertificate(boolean businessCertificate)
    • setInitialAppSync

      public Keys setInitialAppSync(boolean initialAppSync)
    • setWriteKey

      public Keys setWriteKey(byte[] writeKey)
    • setReadKey

      public Keys setReadKey(byte[] readKey)
    • toString

      public String toString()
      Six part keys representation
      Overrides:
      toString in class Object
      Returns:
      a string