Skip to content
This repository was archived by the owner on Sep 10, 2022. It is now read-only.

security.SecureConnection

Aaron Graubert edited this page Sep 18, 2018 · 7 revisions

security.SecureConnection

The agutil.security module includes the SecureConnection class which provides a high-level interface for sending and receiving secure messages and files.

API
  • SecureConnection(address, port, password=None, rsabits=4096, timeout=3, logmethod=DummyLog) (constructor)

    Opens a new secure connection to the address specified by opening a new SecureSocket to use internally. If address is set to '' or 'listen', the SecureConnection will listen for an incoming connection on port. Otherwise, it attempts to connect to another SecureConnection on the specified port at address. password and rsabits configure the internal SecureSocket, and are used for its constructor. timeout sets the default timeout on the internal SecureSocket. logmethod specifies a logging object to use. It defaults to agutil.DummyLog (which does not log anything). logmethod may either be an agutil.Logger class, or a bound method returned by agutil.Logger.bindToSender().

  • SecureConnection.send(msg):

    Sends msg to the remote socket using RSA encryption. The RSA signature of msg is also sent. Returns a the task name used to send the msg. Use confirm() to check if the task was a success

  • SecureConnection.confirm(task, timeout=-1):

    Waits for confirmation of the task from the remote socket. If timeout is a positive number, it waits at most timeout seconds. If timeout is None, it blocks indefinitely. If timeout is -1, it uses the default timeout specified in the constructor. Returns True or False indicating success or failure of the task on the remote end. Raises a socket.Timeout exception if the timeout expires. Confirmations are sent automatically by the remote socket, but must be confirm()-ed manually. If a task fails or times out, it is the programmers responsibility to re-attempt the task, if desired.

  • SecureConnection.read(decode=True, timeout=-1):

    Waits for a message from the remote socket. If timeout is a positive number, it waits at most timeout seconds. If timeout is None, it blocks indefinitely. If timeout is -1, it uses the default timeout specified in the constructor. Returns True or False indicating success or failure of the task on the remote end. Raises a socket.Timeout exception if the timeout expires. If decode is True, the message will be decoded to a string when returned

  • SecureConnection.sendfile(filename):

    Prepares the file specified by filename to be sent and informs the remote socket that the file is available for transfer. Starts a background thread which waits for a response from the remote socket before encrypting and sending the file using AES CBC encryption. Returns a the task name used to send the file. Use confirm() to check if the task was a success.

  • SecureConnection.savefile(destination=None, timeout=-1, force=False):

    Processes the oldest pending file transfer request or waits at most timeout seconds to receive one. If timeout is a positive number, it waits at most timeout seconds. If timeout is None, it blocks indefinitely. If timeout is -1, it uses the default timeout specified in the constructor. Returns True or False indicating success or failure of the task on the remote end. Raises a socket.Timeout exception if the timeout expires. If force is not True, this method will request user confirmation before completing the transfer. Once the transfer begins, the socket must receive at least one chunk every timeout seconds or it will raise a socket.Timeout exception. destination should be the path where the file will be saved. If destination is None, the file will be saved in the current directory, using the original filename.

  • SecureConnection.shutdown(timeout=-1)

  • SecureConnection.close(timeout=-1)

    Closes the underlying socket

  • SecureConnection.flush()

    Waits for all files to finish sending

Clone this wiki locally