SecureChat
@objc(VSRSecureChat)
open class SecureChat : NSObject
SecureChat. Class for rotating keys, starting and responding to conversation
-
Identity private key
Declaration
Swift
@objc public let identityPrivateKey: VirgilPrivateKey -
Crypto
Declaration
Swift
@objc public let crypto: VirgilCrypto -
Long-term keys storage
Declaration
Swift
@objc public let longTermKeysStorage: LongTermKeysStorage -
One-time keys storage
Declaration
Swift
@objc public let oneTimeKeysStorage: OneTimeKeysStorage -
Session storage
Declaration
Swift
@objc public let sessionStorage: SessionStorage -
Client
Declaration
Swift
@objc public let client: RatchetClientProtocol -
Undocumented
Declaration
Swift
@objc public let identityCard: Card -
Default session name (if nil is passed)
Declaration
Swift
@objc public static let defaultSessionName: String -
Initializer
Throws
- Rethrows from
KeychainLongTermKeysStorage
Declaration
Swift
@objc public convenience init(context: SecureChatContext) throwsParameters
context - Rethrows from
-
init(crypto:identityPrivateKey: identityCard: client: longTermKeysStorage: oneTimeKeysStorage: sessionStorage: keysRotator: keyPairType: ) Initializer
Declaration
Swift
public init(crypto: VirgilCrypto, identityPrivateKey: VirgilPrivateKey, identityCard: Card, client: RatchetClientProtocol, longTermKeysStorage: LongTermKeysStorage, oneTimeKeysStorage: OneTimeKeysStorage, sessionStorage: SessionStorage, keysRotator: KeysRotatorProtocol, keyPairType: KeyPairType)Parameters
cryptoVirgilCrypto instance
identityPrivateKeyidentity private key
identityCardIdentity card
clientclient
longTermKeysStoragelong-term keys storage
oneTimeKeysStorageone-time keys storage
sessionStoragesession storage
keysRotatorkeys rotation
-
Rotates keys
Rotation process:
- Retrieve all one-time keys
- Delete one-time keys that were marked as orphaned more than orphanedOneTimeKeyTtl seconds ago
- Retrieve all long-term keys
- Delete long-term keys that were marked as outdated more than outdatedLongTermKeyTtl seconds ago
- Check that all relevant long-term and one-time keys are in the cloud (still persistent in the cloud and were not used)
- Mark used one-time keys as used
- Decide on long-term key roration
- Generate needed number of one-time keys
Upload keys to the cloud
Declaration
Swift
public func rotateKeys() -> GenericOperation<RotationLog>Return Value
GenericOperation
-
Stores session
Note
This method is used for storing new session as well as updating existing ones after operations that change session’s state (encrypt and decrypt), therefore is session already exists in storage, it will be overwritten
Throws
Rethrows from
SessionStorageDeclaration
Swift
@objc open func storeSession(_ session: SecureSession) throwsParameters
sessionSecureSession to store
-
Checks for existing session with given participent in the storage
Declaration
Swift
@objc open func existingSession(withParticipantIdentity participantIdentity: String, name: String? = nil) -> SecureSession?Parameters
participantIdentityparticipant identity
namesession name
Return Value
SecureSession if exists
-
Deletes session with given participant identity
Throws
Rethrows from SessionStorageDeclaration
Swift
@objc public func deleteSession(withParticipantIdentity participantIdentity: String, name: String? = nil) throwsParameters
participantIdentityparticipant identity
nameSession name
-
Deletes session with given participant identity
Throws
Rethrows from SessionStorageDeclaration
Swift
@objc public func deleteAllSessions(withParticipantIdentity participantIdentity: String) throwsParameters
participantIdentityparticipant identity
-
Starts new session with given participant using his identity card
Note
This operation doesn’t store session to storage automatically. Use storeSession()
Throws
Throws:
SecureChatError.sessionAlreadyExistsif session already exists. Try geting existing session or removing itSecureChatError.wrongIdentityPublicKeyCryptoPublicKey is not VirgilPublicKeySecureChatError.identityKeyDoesntMatchIdentity key in the Card and on Ratchet Cloud doesn’t matchSecureChatError.invalidLongTermKeySignatureLong-term key signature is invalid- Rethrows from
SessionStorage - Rethrows from RatchetClient
- Rethrows form SecureSession
- Rethrows form
AccessTokenProvider
Declaration
Swift
open func startNewSessionAsSender(receiverCard: Card, name: String? = nil, enablePostQuantum: Bool) -> GenericOperation<SecureSession>Parameters
receiverCardreceiver identity cards
nameSession name
enablePostQuantumenablePostQuantum
Return Value
GenericOperation with SecureSession
-
Starts multiple new sessions with given participants using their identity cards
Note
This operation doesn’t store sessions to storage automatically. Use storeSession()
Throws
Throws:
SecureChatError.sessionAlreadyExistsif session already exists. Try geting existing session or removing itSecureChatError.wrongIdentityPublicKeyCryptoPublicKey is not VirgilPublicKeySecureChatError.identityKeyDoesntMatchIdentity key in the Card and on Ratchet Cloud doesn’t matchSecureChatError.invalidLongTermKeySignatureLong-term key signature is invalid- Rethrows from
SessionStorage - Rethrows from RatchetClient
- Rethrows form SecureSession
- Rethrows form
AccessTokenProvider
Declaration
Swift
open func startMutipleNewSessionsAsSender(receiverCards: [Card], name: String? = nil, enablePostQuantum: Bool) -> GenericOperation<[SecureSession]>Parameters
receiverCardsreceivers identity cards
nameSession name
Return Value
GenericOperation with SecureSession array
-
Responds with new session with given participant using his initiation message
Note
This operation doesn’t store session to storage automatically. Use storeSession()
Throws
Throws:
SecureChatError.sessionAlreadyExistsif session already exists. Try geting existing session or removing itSecureChatError.wrongIdentityPublicKeyCryptoPublicKey is not VirgilPublicKey- Rethrows from
SessionStorage - Rethrows form SecureSession
- Rethrows form
AccessTokenProvider
Declaration
Swift
@objc public func startNewSessionAsReceiver(senderCard: Card, name: String? = nil, ratchetMessage: RatchetMessage, enablePostQuantum: Bool) throws -> SecureSessionParameters
senderCardSender identity card
namesession name (in case you want to have several sessions with same participant)
ratchetMessageRatchet initiation message (should be prekey message)
Return Value
-
Removes all data corresponding to this user: sessions and keys.
Declaration
Swift
public func reset() -> GenericOperation<Void>Return Value
GenericOperation
-
Starts new session with given participant using his identity card
Declaration
Swift
@objc func startNewSessionAsSender(receiverCard: Card, name: String? = nil, enablePostQuantum: Bool, completion: @escaping (_ session: SecureSession?, _ error: Error?) -> Void)Parameters
receiverCardreceiver identity cards
nameSession name
enablePostQuantumenablePostQuantum
completioncompletion handler
sessioncreated SecureSession
errorcorresponding error
-
Starts multiple new sessions with given participants using their identity cards
Declaration
Swift
@objc func startMultipleNewSessionsAsSender(receiverCards: [Card], name: String? = nil, enablePostQuantum: Bool, completion: @escaping (_ sessions: [SecureSession]?, _ error: Error?) -> Void)Parameters
receiverCardsreceivers identity cards
nameSession name
enablePostQuantumenablePostQuantum
completioncompletion handler
sessionsarray with created SecureSessions
errorcorresponding error
-
Rotates keys. See rotateKeys() -> GenericOperation
for details Declaration
Swift
@objc func rotateKeys(completion: @escaping (_ rotationLog: RotationLog?, _ error: Error?) -> Void)Parameters
completioncompletion handler
rotationLogrepresents the result of rotateKeys operation
errorcorresponding error
-
Removes all data corresponding to this user: sessions and keys.
Declaration
Swift
@objc func reset(completion: @escaping (_ error: Error?) -> Void)Parameters
completioncompletion handler
errorcorresponding error
SecureChat Class Reference