Skip to content

Commit

Permalink
Merge pull request #17 from VirgilSecurity/develop
Browse files Browse the repository at this point in the history
v0.7.0
  • Loading branch information
Ogerets authored May 21, 2020
2 parents 1879943 + 11ade3a commit f3e50b0
Show file tree
Hide file tree
Showing 15 changed files with 11 additions and 1,122 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ env:

matrix:
- DESTINATION="" PREFIX="" SDK="" BUILD="0" PUBLISH_CARTHAGE="YES" CARTHAGE_PLATFORM="Mac" PUBLISH_POD="YES" SWIFT_LINT="YES" PUBLISH_DOCS="YES"
- DESTINATION="OS=13.4,name=iPhone 8" PREFIX="iOS" SDK="$IOS_SDK" BUILD="2" PUBLISH_CARTHAGE="NO" CARTHAGE_PLATFORM="iOS" PUBLISH_POD="NO" SWIFT_LINT="NO" PUBLISH_DOCS="NO"
- DESTINATION="OS=13.4.1,name=iPhone 8" PREFIX="iOS" SDK="$IOS_SDK" BUILD="2" PUBLISH_CARTHAGE="NO" CARTHAGE_PLATFORM="iOS" PUBLISH_POD="NO" SWIFT_LINT="NO" PUBLISH_DOCS="NO"
- DESTINATION="arch=x86_64" PREFIX="macOS" SDK="$MACOS_SDK" BUILD="2" PUBLISH_CARTHAGE="NO" CARTHAGE_PLATFORM="Mac" PUBLISH_POD="NO" SWIFT_LINT="NO" PUBLISH_DOCS="NO"
- DESTINATION="OS=13.4,name=Apple TV 4K" PREFIX="tvOS" SDK="$TVOS_SDK" BUILD="2" PUBLISH_CARTHAGE="NO" CARTHAGE_PLATFORM="tvOS" PUBLISH_POD="NO" SWIFT_LINT="NO" PUBLISH_DOCS="NO"
- DESTINATION="OS=6.2,name=Apple Watch Series 4 - 44mm" PREFIX="watchOS" SDK="$WATCHOS_SDK" BUILD="1" PUBLISH_CARTHAGE="NO" CARTHAGE_PLATFORM="watchOS" PUBLISH_POD="NO" SWIFT_LINT="NO" PUBLISH_DOCS="NO"
Expand Down
4 changes: 2 additions & 2 deletions Cartfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
github "VirgilSecurity/virgil-cryptowrapper-x" ~> 0.14.0
github "VirgilSecurity/virgil-sdk-x" ~> 7.2.0
github "VirgilSecurity/virgil-cryptowrapper-x" ~> 0.15.2
github "VirgilSecurity/virgil-sdk-x" ~> 7.2.1
8 changes: 4 additions & 4 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
github "VirgilSecurity/virgil-crypto-c" "v0.14.0"
github "VirgilSecurity/virgil-crypto-x" "5.4.0"
github "VirgilSecurity/virgil-cryptowrapper-x" "0.14.0"
github "VirgilSecurity/virgil-sdk-x" "7.2.0"
github "VirgilSecurity/virgil-crypto-c" "v0.15.2"
github "VirgilSecurity/virgil-crypto-x" "5.5.0"
github "VirgilSecurity/virgil-cryptowrapper-x" "0.15.2"
github "VirgilSecurity/virgil-sdk-x" "7.2.1"
113 changes: 0 additions & 113 deletions Source/SecureChat/SecureChat.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,6 @@ import VirgilCrypto
/// Session storage
@objc public let sessionStorage: SessionStorage

/// Group session storage
@objc public let groupSessionStorage: GroupSessionStorage

/// Client
@objc public let client: RatchetClientProtocol

Expand Down Expand Up @@ -151,10 +148,6 @@ import VirgilCrypto
identity: context.identityCard.identity,
crypto: crypto,
identityKeyPair: identityKeyPair)
let groupSessionStorage = try FileGroupSessionStorage(appGroup: context.appGroup,
identity: context.identityCard.identity,
crypto: crypto,
identityKeyPair: identityKeyPair)
let keysRotator = KeysRotator(crypto: crypto,
identityPrivateKey: context.identityPrivateKey,
identityCardId: context.identityCard.identifier,
Expand All @@ -176,7 +169,6 @@ import VirgilCrypto
longTermKeysStorage: longTermKeysStorage,
oneTimeKeysStorage: oneTimeKeysStorage,
sessionStorage: sessionStorage,
groupSessionStorage: groupSessionStorage,
keysRotator: keysRotator,
keyPairType: keyPairType)
}
Expand All @@ -191,7 +183,6 @@ import VirgilCrypto
/// - longTermKeysStorage: long-term keys storage
/// - oneTimeKeysStorage: one-time keys storage
/// - sessionStorage: session storage
/// - groupSessionStorage: group session storage
/// - keysRotator: keys rotation
public init(crypto: VirgilCrypto,
identityPrivateKey: VirgilPrivateKey,
Expand All @@ -200,7 +191,6 @@ import VirgilCrypto
longTermKeysStorage: LongTermKeysStorage,
oneTimeKeysStorage: OneTimeKeysStorage,
sessionStorage: SessionStorage,
groupSessionStorage: GroupSessionStorage,
keysRotator: KeysRotatorProtocol,
keyPairType: KeyPairType) {
self.crypto = crypto
Expand All @@ -210,7 +200,6 @@ import VirgilCrypto
self.longTermKeysStorage = longTermKeysStorage
self.oneTimeKeysStorage = oneTimeKeysStorage
self.sessionStorage = sessionStorage
self.groupSessionStorage = groupSessionStorage
self.keysRotator = keysRotator
self.keyPairType = keyPairType

Expand Down Expand Up @@ -251,19 +240,6 @@ import VirgilCrypto
try self.sessionStorage.storeSession(session)
}

/// Stores group session
/// - Note: This method is used for storing new session as well as updating existing ones
/// after operations that change session's state (encrypt, decrypt, setParticipants, updateParticipants),
/// therefore is session already exists in storage, it will be overwritten
///
/// - Parameter session: [SecureGroupSession](x-source-tag://SecureGroupSession) to store
/// - Throws: Rethrows from `GroupSessionStorage`
@objc open func storeGroupSession(_ session: SecureGroupSession) throws {
Log.debug("Storing group session with id \(session.identifier.hexEncodedString())")

try self.groupSessionStorage.storeSession(session)
}

/// Checks for existing session with given participent in the storage
///
/// - Parameters:
Expand Down Expand Up @@ -308,16 +284,6 @@ import VirgilCrypto
try self.sessionStorage.deleteSession(participantIdentity: participantIdentity, name: nil)
}

/// Deletes group session with given identifier
///
/// - Parameter sessionId: session identifier
/// - Throws: Rethrows from SessionGroupStorage
@objc public func deleteGroupSession(sessionId: Data) throws {
Log.debug("Deleting group session with \(sessionId.hexEncodedString())")

try self.groupSessionStorage.deleteSession(identifier: sessionId)
}

/// Starts new session with given participant using his identity card
/// - Note: This operation doesn't store session to storage automatically. Use storeSession()
///
Expand Down Expand Up @@ -578,85 +544,6 @@ import VirgilCrypto
return session
}

/// Creates RatchetGroupMessage that starts new group chat
/// - Important: Session id is REQUIRED to be unique and tied to transport layer (channel id or similar)
/// - Note: Other participants should receive this message using encrypted channel
/// ([SecureSession](x-source-tag://SecureSession))
///
/// - Parameter sessionId: Session Id. Should be 32 byte.
/// - Returns: RatchetGroupMessage that should be then passed to startGroupSession()
/// - Throws:
/// - `SecureChatError.invalidSessionIdLen`
/// - Rethrows from `RatchetGroupTicket`
@objc public func startNewGroupSession(sessionId: Data) throws -> RatchetGroupMessage {
let ticket = RatchetGroupTicket()
ticket.setRng(rng: self.crypto.rng)

guard sessionId.count == RatchetCommon.sessionIdLen else {
throw SecureChatError.invalidSessionIdLen
}

try ticket.setupTicketAsNew(sessionId: sessionId)

return ticket.getTicketMessage()
}

/// Creates secure group session that was initiated by someone.
/// - Important: RatchetGroupMessage should have .groupInfo type.
/// Such messages should be sent encrypted (using [SecureSession](x-source-tag://SecureSession))
/// - Important: Session id is REQUIRED to be unique and tied to transport layer (channel id or similar)
/// - Note: This operation doesn't store session to storage automatically. Use storeGroupSession()
///
/// - Parameters:
/// - receiversCards: participant cards (excluding creating user itself)
/// - sessionId: Session Id. Should be 32 byte.
/// - ratchetMessage: ratchet group message with .groupInfo type
/// - Returns: [SecureGroupSession](x-source-tag://SecureGroupSession)
/// - Throws:
/// - `SecureChatError.invalidMessageType`
/// - `SecureChatError.invalidCardId`
/// - Rethrows from [SecureGroupSession](x-source-tag://SecureGroupSession)
@objc public func startGroupSession(with receiversCards: [Card],
sessionId: Data,
using ratchetMessage: RatchetGroupMessage) throws -> SecureGroupSession {
guard ratchetMessage.getType() == .groupInfo else {
throw SecureChatError.invalidMessageType
}

guard ratchetMessage.getSessionId() == sessionId else {
throw SecureChatError.sessionIdMismatch
}

let privateKeyData = try self.crypto.exportPrivateKey(self.identityPrivateKey)

guard let myId = Data(hexEncodedString: self.identityCard.identifier) else {
throw SecureChatError.invalidCardId
}

return try SecureGroupSession(crypto: self.crypto,
privateKeyData: privateKeyData,
myId: myId,
ratchetGroupMessage: ratchetMessage,
cards: receiversCards)
}

/// Returns existing group session
///
/// - Parameter sessionId: session identifier
/// - Returns: Stored session if found, nil otherwise
@objc public func existingGroupSession(sessionId: Data) -> SecureGroupSession? {
if let session = self.groupSessionStorage.retrieveSession(identifier: sessionId) {
Log.debug("Found existing group session with identifier: \(sessionId)")

return session
}
else {
Log.debug("Existing session with identifier: \(sessionId) was not found")

return nil
}
}

/// Removes all data corresponding to this user: sessions and keys.
///
/// - Returns: GenericOperation
Expand Down
Loading

0 comments on commit f3e50b0

Please sign in to comment.