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) throws
Parameters
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
crypto
VirgilCrypto instance
identityPrivateKey
identity private key
identityCard
Identity card
client
client
longTermKeysStorage
long-term keys storage
oneTimeKeysStorage
one-time keys storage
sessionStorage
session storage
keysRotator
keys 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
SessionStorage
Declaration
Swift
@objc open func storeSession(_ session: SecureSession) throws
Parameters
session
SecureSession 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
participantIdentity
participant identity
name
session 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) throws
Parameters
participantIdentity
participant identity
name
Session name
-
Deletes session with given participant identity
Throws
Rethrows from SessionStorageDeclaration
Swift
@objc public func deleteAllSessions(withParticipantIdentity participantIdentity: String) throws
Parameters
participantIdentity
participant 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.sessionAlreadyExists
if session already exists. Try geting existing session or removing itSecureChatError.wrongIdentityPublicKeyCrypto
PublicKey is not VirgilPublicKeySecureChatError.identityKeyDoesntMatch
Identity key in the Card and on Ratchet Cloud doesn’t matchSecureChatError.invalidLongTermKeySignature
Long-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
receiverCard
receiver identity cards
name
Session name
enablePostQuantum
enablePostQuantum
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.sessionAlreadyExists
if session already exists. Try geting existing session or removing itSecureChatError.wrongIdentityPublicKeyCrypto
PublicKey is not VirgilPublicKeySecureChatError.identityKeyDoesntMatch
Identity key in the Card and on Ratchet Cloud doesn’t matchSecureChatError.invalidLongTermKeySignature
Long-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
receiverCards
receivers identity cards
name
Session 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.sessionAlreadyExists
if session already exists. Try geting existing session or removing itSecureChatError.wrongIdentityPublicKeyCrypto
PublicKey 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 -> SecureSession
Parameters
senderCard
Sender identity card
name
session name (in case you want to have several sessions with same participant)
ratchetMessage
Ratchet 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
receiverCard
receiver identity cards
name
Session name
enablePostQuantum
enablePostQuantum
completion
completion handler
session
created SecureSession
error
corresponding 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
receiverCards
receivers identity cards
name
Session name
enablePostQuantum
enablePostQuantum
completion
completion handler
sessions
array with created SecureSessions
error
corresponding error
-
Rotates keys. See rotateKeys() -> GenericOperation
for details Declaration
Swift
@objc func rotateKeys(completion: @escaping (_ rotationLog: RotationLog?, _ error: Error?) -> Void)
Parameters
completion
completion handler
rotationLog
represents the result of rotateKeys operation
error
corresponding error
-
Removes all data corresponding to this user: sessions and keys.
Declaration
Swift
@objc func reset(completion: @escaping (_ error: Error?) -> Void)
Parameters
completion
completion handler
error
corresponding error