Skip to content

Commit

Permalink
Merge pull request #55 from VirgilSecurity/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Ogerets authored Mar 6, 2020
2 parents b5320b2 + a483c52 commit 2c88d68
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 7 deletions.
3 changes: 2 additions & 1 deletion Source/EThree.swift
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ import VirgilSDKRatchet
verifier.whitelists = [whitelist]
}

let accessTokenProvider = CachingJwtProvider { params.tokenCallback($1) }
let accessTokenProvider = CachingJwtProvider(initialJwt: params.initialJwt,
renewTokenCallback: { params.tokenCallback($1) })

let cardManagerParams = CardManagerParams(crypto: crypto,
accessTokenProvider: accessTokenProvider,
Expand Down
19 changes: 19 additions & 0 deletions Source/Models/EThreeParams.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ import VirgilCrypto
@objc public var keyRotationInterval: TimeInterval = Defaults.keyRotationInterval
/// Service urls
@objc public var serviceUrls: ServiceUrls
/// Initial Jwt
@objc public var initialJwt: Jwt? = nil

/// Service urls
@objc(VTEServiceUrls) public class ServiceUrls: NSObject {
Expand Down Expand Up @@ -144,6 +146,23 @@ import VirgilCrypto
return try PropertyListDecoder().decode(Config.self, from: data)
}
}

@objc public convenience init(initialJwt: Jwt,
tokenCallback: @escaping EThree.RenewJwtCallback,
configUrl: URL) throws {
try self.init(identity: initialJwt.identity(),
tokenCallback: tokenCallback,
configUrl: configUrl)

self.initialJwt = initialJwt
}

@objc public convenience init(initialJwt: Jwt,
tokenCallback: @escaping EThree.RenewJwtCallback) {
self.init(identity: initialJwt.identity(), tokenCallback: tokenCallback)

self.initialJwt = initialJwt
}

/// Initializer with parameters from config plist file
///
Expand Down
2 changes: 1 addition & 1 deletion Source/PublicAPI/Encryption/EThree+Streams.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ extension EThree {
/// - Throws: corresponding error
/// - Important: Requires private key in local storage
@objc open func authDecrypt(_ stream: InputStream, to outputStream: OutputStream, from user: Card? = nil) throws {
try self.decryptInternal(stream, to: outputStream, from: nil)
try self.decryptInternal(stream, to: outputStream, from: user?.publicKey)
}

/// Decrypts stream and signature and verifies signature of sender
Expand Down
2 changes: 1 addition & 1 deletion Source/Utils/ProductInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ import Foundation

internal enum ProductInfo {
internal static let name: String = "e3kit"
internal static let version: String = "2.0.0"
internal static let version: String = "2.1.0"
}
2 changes: 1 addition & 1 deletion Tests/Utils/TestUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ import VirgilSDKPythia
return jwt.stringRepresentation()
}

@objc public func getToken(identity: String, ttl: TimeInterval = 1000) -> AccessToken {
@objc public func getToken(identity: String, ttl: TimeInterval = 1000) -> Jwt {
let privateKeyData = Data(base64Encoded: self.config.ApiPrivateKey)
let keyPair = try! self.crypto.importPrivateKey(from: privateKeyData!)

Expand Down
50 changes: 49 additions & 1 deletion Tests/VTE001_PeerToPeerTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ - (void)test07_STE_41 {
}

- (void)test08_STE_71 {
XCTestExpectation *ex = [self expectationWithDescription:@"Simple encrypt decrypt with deprecated methods should success"];
XCTestExpectation *ex = [self expectationWithDescription:@"Simple encrypt decrypt with deprecated methods should succeed"];

[self.eThree registerWithCompletion:^(NSError *error) {
XCTAssert(error == nil);
Expand Down Expand Up @@ -387,4 +387,52 @@ - (void)test08_STE_71 {
}];
}

- (void)test09_STE_88 {
XCTestExpectation *ex = [self expectationWithDescription:@"Decrypt stream, encrypted and signed as data should succeed"];

[self.eThree registerWithCompletion:^(NSError *error) {
XCTAssert(error == nil);
VTEEThree *eThree1 = self.eThree;

VTEEThree *eThree2 = [self.utils setupEThreeWithStorageParams:self.keychainStorage.storageParams];
XCTAssert(eThree2 != nil);

[eThree2 registerWithCompletion:^(NSError *error) {
XCTAssert(error == nil);

[eThree1 findUserWith:eThree1.identity forceReload:false completion:^(VSSCard *card1, NSError *error) {
XCTAssert(card1 != nil && error == nil);

[eThree1 findUserWith:eThree2.identity forceReload:false completion:^(VSSCard *card2, NSError *error) {
XCTAssert(card2 != nil && error == nil);

NSError *err;
NSData *data = [self.utils.crypto generateRandomDataOfSize:10 error:&err];
XCTAssert(data != nil && err == nil);

NSData *encrypted = [eThree1 authEncryptData:data forUser:card2 error:&err];
XCTAssert(encrypted != nil && err == nil);

NSInputStream *inputStream = [[NSInputStream alloc] initWithData:encrypted];
NSOutputStream *outputStream = [[NSOutputStream alloc] initToMemory];

[eThree2 authDecrypt:inputStream to:outputStream from:card1 error:&err];
XCTAssert(err == nil);

NSData *decryptedData = [outputStream propertyForKey:NSStreamDataWrittenToMemoryStreamKey];

XCTAssert([data isEqualToData:decryptedData]);

[ex fulfill];
}];
}];
}];
}];

[self waitForExpectationsWithTimeout:timeout handler:^(NSError *error) {
if (error != nil)
XCTFail(@"Expectation failed: %@", error);
}];
}

@end
18 changes: 18 additions & 0 deletions Tests/VTE008_AdditionalTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,22 @@ class VTE008_AdditionalTests: XCTestCase {
XCTAssert(params.enableRatchet == false)
XCTAssert(params.keyRotationInterval == 3_600)
}

func test05_STE_87__init_ethree__with_initial_jwt__should_succeed() {
let utils = TestUtils()

let identity = UUID().uuidString
let initialJwt = utils.getToken(identity: identity)

let tokenCallback: EThree.RenewJwtCallback = { completion in
XCTFail()
}

let params = EThreeParams(initialJwt: initialJwt,
tokenCallback: tokenCallback)

let ethree = try! EThree(params: params)

_ = ethree.findUser(with: ethree.identity, forceReload: true)
}
}
2 changes: 1 addition & 1 deletion VirgilE3Kit.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "VirgilE3Kit"
s.version = "2.0.0"
s.version = "2.1.0"
s.swift_version = "5.1"
s.license = { :type => "BSD", :file => "LICENSE" }
s.summary = "Vigil E3Kit for Apple devices and languages"
Expand Down
2 changes: 1 addition & 1 deletion VirgilE3Kit/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>2.0.0</string>
<string>2.1.0</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
</dict>
Expand Down

0 comments on commit 2c88d68

Please sign in to comment.