Package anbxj
Class AnB_Session
java.lang.Object
anbxj.AnB_Crypto_Wrapper
anbxj.AnB_Session
AnB Session: implements a protocol session supporting cryptographic
operations.
-
Field Summary
Fields inherited from class anbxj.AnB_Crypto_Wrapper
ee, ident_ks, me -
Constructor Summary
ConstructorsConstructorDescriptionAnB_Session(AnB_Crypto_Wrapper wrapper, Channel_Abstraction channel) Creates a new session using an existingAnB_Crypto_Wrapper.AnB_Session(Crypto_EncryptionEngine ee, String myAlias, Channel_Abstraction channel) Creates a new session that reuses an existing cryptographic engine and uses an already connected socket channel (e.g., from a multi-threaded server).AnB_Session(Crypto_EncryptionEngine ee, String myAlias, Channel_Settings cs, Crypto_Config config, boolean exchange_id) Creates a new session that reuses an existing cryptographic engine.AnB_Session(Crypto_EncryptionEngine ee, String myAlias, Channel_Settings cs, Crypto_Config config, boolean exchange_id, Channel_MessageSerializer serializer) Creates a new client-side session that uses Protocol Buffers serialisation and optionally exchanges identities after opening the channel.AnB_Session(Crypto_EncryptionEngine ee, String myAlias, Channel_Settings cs, Crypto_Config config, String id_Remote_alias) Creates a new session that reuses an existing cryptographic engine and automatically sets the remote identity.AnB_Session(Crypto_EncryptionEngine ee, String myAlias, Channel_Settings cs, Crypto_Config config, String id_Remote_alias, Channel_MessageSerializer serializer) Creates a new client-side session that uses Protocol Buffers serialisation and does not exchange identities.AnB_Session(Crypto_KeyStoreSettings_Map kssd, Channel_Abstraction channel, Crypto_Config config) Constructs a new AnB_Session with the specified parameters.AnB_Session(Crypto_KeyStoreSettings_Map kssd, Channel_Settings cs, boolean exchange_id, Crypto_Config config) Constructs a new AnB_Session with the specified parameters.AnB_Session(Crypto_KeyStoreSettings_Map kssd, Channel_Settings cs, AnBx_Agent id_Remote, Crypto_Config config) Constructs a new AnB_Session with the specified parameters.AnB_Session(Crypto_KeyStoreSettings_Map kssd, Channel_Settings cs, String id_Remote_alias, Crypto_Config config) Constructs a new AnB_Session with the specified parameters.AnB_Session(String myAlias, Channel_Settings cs, boolean exchange_id, Crypto_Config config) Constructs a new AnB_Session with the specified parameters.AnB_Session(String myAlias, Channel_Settings cs, String id_Remote_alias, Crypto_Config config) Constructs a new AnB_Session with the specified parameters. -
Method Summary
Modifier and TypeMethodDescriptionvoidClose()Closes the session by closing the channel and logging the closure.Gets the current channel.Returns the channel settings of the underlying communication channel.static Channel_MessageSerializerReturns the global default message serializer that is currently configured.getDesc(int step) Retrieves theChannel_ProtobufSerializer.StepDescriptorassociated with the given step.Gets the remote identity (AnBx_Agent).booleanisServer()Determines whether the current session is acting as a server.voidOpen()Opens the session by initiating the channel, exchanging IDs if required.Receive()Receives an object using the current channel.Receives the remote identity (AnBx_Agent) using the current channel.voidSends an object using the current channel.voidSend_Id()Sends the local identity (me) using the current channel.voidSets the current channel.static voidsetDefaultSerializer(Channel_MessageSerializer serializer) Sets the global default message serializer that will be used by all subsequently createdAnB_Sessionobjects.voidsetId_Remote(AnBx_Agent id_Remote) Sets the remote identity (AnBx_Agent).static voidSets the step descriptors for this session (called during setup).Methods inherited from class anbxj.AnB_Crypto_Wrapper
aliasExists, checkHmac, decrypt, decrypt, decrypt, decrypt, decrypt, decrypt, decrypt, decrypt, encrypt, encrypt, encrypt, encrypt, encrypt, encryptSymmetric, fromProtobufSealed, fromProtobufSigned, getCryptoEngine, getHmacKey, getInfo, getKeyEx_KeyPair, getKeyEx_PublicKey, getKeyEx_SecretKey, getKeyPair, getKeyStoreSettings_Map, getMyIdentity, getName, getNonce, getPublicKey, getPublicKey, getRemoteCertificate, getRemoteCertificates, getSeqNumber, getSymmetricKey, getSymmetricKey, getSymmetricKeyPBE, getTimeStamp, hmac, isLoggingExecTimeEnabled, makeDigest, makeHmac, readObject, Receive, Receive_RemoteId, Send, Send_Id, setLoggingExecTimeEnabled, sign, sign, sign, toProtobufSealed, toProtobufSigned, unsealMessage, verify, verify, verify, verify, verify, verifyMessage, verifyMessage, writeObject, xor
-
Constructor Details
-
AnB_Session
public AnB_Session(Crypto_EncryptionEngine ee, String myAlias, Channel_Settings cs, Crypto_Config config, boolean exchange_id) Creates a new session that reuses an existing cryptographic engine. The channel is initialised based on the provided channel settings. If the configuration indicates use of a keystore, the channel is set up using keystore-based credentials; otherwise alias-based setup is used.- Parameters:
ee- the shared cryptographic engine (must not be null)myAlias- the alias of the local principal (must not be null)cs- the channel settings defining the communication parametersconfig- the cryptographic configuration (used to determine keystore usage)exchange_id- if true, the session will exchange identities after opening the channel
-
AnB_Session
public AnB_Session(Crypto_EncryptionEngine ee, String myAlias, Channel_Settings cs, Crypto_Config config, String id_Remote_alias) Creates a new session that reuses an existing cryptographic engine and automatically sets the remote identity. Identity exchange is not performed.- Parameters:
ee- the shared cryptographic engine (must not be null)myAlias- the alias of the local principal (must not be null)cs- the channel settings defining the communication parametersconfig- the cryptographic configuration (used to determine keystore usage)id_Remote_alias- the alias of the remote principal (must not be null)
-
AnB_Session
Creates a new session that reuses an existing cryptographic engine and uses an already connected socket channel (e.g., from a multi-threaded server). The channel is already established; this constructor simply wraps it.- Parameters:
ee- the shared cryptographic engine (must not be null)myAlias- the alias of the local principal (must not be null)channel- the already connected channel abstraction (must not be null)
-
AnB_Session
Creates a new session using an existingAnB_Crypto_Wrapper. The wrapper already holds a cryptographic engine and the local alias. The provided channel is used directly without re-initialisation.- Parameters:
wrapper- the existing crypto wrapper (must not be null)channel- the already connected channel abstraction (must not be null)
-
AnB_Session
Constructs a new AnB_Session with the specified parameters.- Parameters:
myAlias- Alias of the principal.cs- The Channel_Settings for initialising channels.exchange_id- A boolean indicating whether to exchange ID.config- The Crypto_Config to be used.
-
AnB_Session
public AnB_Session(Crypto_KeyStoreSettings_Map kssd, Channel_Settings cs, boolean exchange_id, Crypto_Config config) Constructs a new AnB_Session with the specified parameters.- Parameters:
kssd- The Crypto_KeyStoreSettings_Map to be used.cs- The Channel_Settings for initialising channels.exchange_id- A boolean indicating whether to exchange ID.config- The Crypto_Config to be used.
-
AnB_Session
public AnB_Session(Crypto_KeyStoreSettings_Map kssd, Channel_Settings cs, AnBx_Agent id_Remote, Crypto_Config config) Constructs a new AnB_Session with the specified parameters.- Parameters:
kssd- The Crypto_KeyStoreSettings_Map to be used.cs- The Channel_Settings for initialising channels.id_Remote- The AnBx_Agent representing the remote ID.config- The Crypto_Config to be used.
-
AnB_Session
public AnB_Session(Crypto_KeyStoreSettings_Map kssd, Channel_Settings cs, String id_Remote_alias, Crypto_Config config) Constructs a new AnB_Session with the specified parameters.- Parameters:
kssd- The Crypto_KeyStoreSettings_Map to be used.cs- The Channel_Settings for initialising channels.id_Remote_alias- The alias for the remote ID.config- The Crypto_Config to be used.
-
AnB_Session
public AnB_Session(String myAlias, Channel_Settings cs, String id_Remote_alias, Crypto_Config config) Constructs a new AnB_Session with the specified parameters.- Parameters:
myAlias- Alias of the principal.cs- The Channel_Settings for initialising channels.id_Remote_alias- The alias for the remote ID.config- The Crypto_Config to be used.
-
AnB_Session
public AnB_Session(Crypto_KeyStoreSettings_Map kssd, Channel_Abstraction channel, Crypto_Config config) Constructs a new AnB_Session with the specified parameters.- Parameters:
kssd- The Crypto_KeyStoreSettings_Map to be used.channel- The already connected channel abstraction (must not be null)config- The Crypto_Config to be used.
-
AnB_Session
public AnB_Session(Crypto_EncryptionEngine ee, String myAlias, Channel_Settings cs, Crypto_Config config, String id_Remote_alias, Channel_MessageSerializer serializer) Creates a new client-side session that uses Protocol Buffers serialisation and does not exchange identities.- Parameters:
ee- the shared cryptographic enginemyAlias- the alias of the local principalcs- the channel settingsconfig- the cryptographic configurationid_Remote_alias- the alias of the remote principal (used to set the remote identity)serializer- the protocol-specific message serializer
-
AnB_Session
public AnB_Session(Crypto_EncryptionEngine ee, String myAlias, Channel_Settings cs, Crypto_Config config, boolean exchange_id, Channel_MessageSerializer serializer) Creates a new client-side session that uses Protocol Buffers serialisation and optionally exchanges identities after opening the channel.- Parameters:
ee- the shared cryptographic enginemyAlias- the alias of the local principalcs- the channel settingsconfig- the cryptographic configurationexchange_id- iftrue, identities are exchanged after openingserializer- the protocol-specific message serializer
-
-
Method Details
-
setDefaultSerializer
Sets the global default message serializer that will be used by all subsequently createdAnB_Sessionobjects.- Parameters:
serializer- the message serializer to use, ornullto revert to standard Java serialisation- See Also:
-
getDefaultSerializer
Returns the global default message serializer that is currently configured.- Returns:
- the current default serializer, or
nullif none - See Also:
-
setStepDescriptors
public static void setStepDescriptors(Map<Integer, Channel_ProtobufSerializer.StepDescriptor> descriptors) Sets the step descriptors for this session (called during setup). The same map is typically shared with theChannel_ProtobufSerializer.- Parameters:
descriptors- a map from step number to its correspondingChannel_ProtobufSerializer.StepDescriptor; must not benull- Throws:
NullPointerException- ifdescriptorsisnull- See Also:
-
Open
public void Open()Opens the session by initiating the channel, exchanging IDs if required. -
Close
public void Close()Closes the session by closing the channel and logging the closure. -
Receive
Receives an object using the current channel.- Returns:
- The received object.
-
Send
Sends an object using the current channel.- Parameters:
obj- The object to be sent.
-
Receive_RemoteId
Receives the remote identity (AnBx_Agent) using the current channel.- Returns:
- The received AnBx_Agent representing the remote identity.
-
Send_Id
public void Send_Id()Sends the local identity (me) using the current channel. -
getChannel
Gets the current channel.- Returns:
- The current channel.
-
getId_Remote
Gets the remote identity (AnBx_Agent).- Returns:
- The remote identity.
-
setChannel
Sets the current channel.- Parameters:
c- The channel to be set.
-
setId_Remote
Sets the remote identity (AnBx_Agent).- Parameters:
id_Remote- The remote identity to be set.
-
getChannelSettings
Returns the channel settings of the underlying communication channel.- Returns:
- the
Channel_Settingsobject containing the configuration (host, port, channel type, role, etc.) of this session's channel.
-
isServer
public boolean isServer()Determines whether the current session is acting as a server.- Returns:
trueif this session's channel role is SERVER,falseotherwise.
-
getDesc
Retrieves theChannel_ProtobufSerializer.StepDescriptorassociated with the given step.- Parameters:
step- the step number- Returns:
- the step descriptor, never
null - Throws:
IllegalArgumentException- if no descriptor is registered forstep
-