From 4dd152596f07648a9ca0b37b9860bd794ea05ec0 Mon Sep 17 00:00:00 2001 From: Matthew Rhea Date: Wed, 6 Apr 2022 11:06:03 -0700 Subject: [PATCH] [PLAT-951] Release 4.2.3 --- DEVELOPMENT.md | 6 +-- E3db.podspec | 2 +- E3db/Classes/Crypto.swift | 20 +++++++-- .../E3db-Example/Base.lproj/Main.storyboard | 42 ++++++++++-------- Example/E3db-Example/ViewController.swift | 43 ++++++++++++++++++- Example/Podfile.lock | 6 +-- 6 files changed, 91 insertions(+), 28 deletions(-) diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 1343d7d..a3ed15f 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -57,8 +57,8 @@ Before running the Example app you will want to add configuration for a valid To private let e3dbToken = "259918a1804c89f4acd10b134810442284e4b2d93776c5a7a1c8934e14113a81" ``` -## Building (Release 4.2.2) -Due to difficulties using Carthage as a package manager for the project, for release 4.2.2 the SDK has transitioned to using [Cocoapods](https://cocoapods.org/) for both the `E3db` SDK and `E3db-example` test application projects in this repository. The current build instructions for version 4.2.2 and beyond are detailed here. +## Building (Release >=4.2.2) +As of 4.2.2, the Carthage package manager is no longer supported. The SDK should be install with [Cocoapods](https://cocoapods.org/) for both the `E3db` SDK and `E3db-example` test application projects in this repository. The current build instructions for 4.2.2 and beyond are detailed here. 1. `cd e3db-swift` 2. `pod install` - The SDK dependencies are downloaded and built. @@ -76,7 +76,7 @@ pod install --repo update What happened is that `pod install` references specs in the local `~/.cocoapods/repos` directory when installing dependencies. The `--repo-update` will update these references so that the latest pod versions can be found. The above command will update the repo specs, and run `pod install`. -## Running (Release 4.2.2) +## Running (Release >=4.2.2) After following the build steps in the [Building](#Building) section, the example application can be ran to test some functionality of the SDK. 1. Open the `E3db-example.xcworkspace` file in Xcode diff --git a/E3db.podspec b/E3db.podspec index c4a716b..fdf5bac 100644 --- a/E3db.podspec +++ b/E3db.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'E3db' - s.version = '4.2.2' + s.version = '4.2.3' s.summary = 'Super Easy End-to-End Encryption' s.swift_version = '5.0' diff --git a/E3db/Classes/Crypto.swift b/E3db/Classes/Crypto.swift index 876af14..bec26a2 100644 --- a/E3db/Classes/Crypto.swift +++ b/E3db/Classes/Crypto.swift @@ -187,11 +187,25 @@ extension Crypto { extension Crypto { + /** + Signature method that signs data with the signer's secret key. The data is expected to be an object conforming to the Signable protocol, and thus + serializable to a string. The data, if when serialized is a plain string, will be encoded to utf8 bytes. If the data is already bytes, then it will attempt + to be base64Url decoded. + + - parameter doc: An object that conforms to the Signable protocol (e.g. EncryptedDocument or SignableDocument) + - parameter signingKey: The byte representation of the private signing key of the signer + */ static func signature(doc: Signable, signingKey: Sign.SecretKey) -> String? { - let message = try? Crypto.base64UrlDecoded(string: doc.serialized()) - return sodium.sign.signature(message: message!, secretKey: signingKey)?.base64UrlEncodedString() + var message: [UInt8] = Array("".utf8) + do { + message = try Crypto.base64UrlDecoded(string: doc.serialized()) + } + catch { + message = Array(doc.serialized().utf8) + } + return sodium.sign.signature(message: message, secretKey: signingKey)?.base64UrlEncodedString() } - + static func verify(doc: Signable, encodedSig: String, verifyingKey: Sign.PublicKey) -> Bool? { let message = Bytes(doc.serialized().utf8) return Bytes(base64UrlEncoded: encodedSig) diff --git a/Example/E3db-Example/Base.lproj/Main.storyboard b/Example/E3db-Example/Base.lproj/Main.storyboard index 87cbc16..99694f0 100644 --- a/Example/E3db-Example/Base.lproj/Main.storyboard +++ b/Example/E3db-Example/Base.lproj/Main.storyboard @@ -1,11 +1,9 @@ - - - - + + - - + + @@ -18,17 +16,17 @@ - + - - + - + @@ -59,13 +57,13 @@ - + @@ -115,7 +123,7 @@ - + diff --git a/Example/E3db-Example/ViewController.swift b/Example/E3db-Example/ViewController.swift index e642c3c..47f1936 100644 --- a/Example/E3db-Example/ViewController.swift +++ b/Example/E3db-Example/ViewController.swift @@ -60,7 +60,48 @@ class ViewController: UIViewController { } - + + /// Demonstrates encrypting Documents securely with E3db. + @IBAction func encryptDocument() { + guard let msg = messageView.text else { + return print("Text field contains no text") + } + + // Wrap message in RecordData type + let recordData = RecordData(cleartext: ["secret message": msg]) + + // Get EAKInfo and attempt to encrypt data to receive a Document + var encryptText = "" + var decryptText = "" + + e3db?.createWriterKey(type: "example", completion: { result in + switch result { + case .success(let eak): + // Perform encrypt operation + let encrypted = try? self.e3db?.encrypt(type: "mobility-app", data: recordData, eakInfo: eak, plain: ["sent from": "my iphone"]) + encryptText = "Encrypted document! \(String(describing: encrypted?.serialized()))" + + // Attempt to decrypt an encrypted document with the EAKInfo instance + do { + let decrypted = try self.e3db?.decrypt(encryptedDoc: encrypted!, eakInfo: eak) + decryptText = "Decrypted document! \(String(describing: decrypted))" + } + catch { + decryptText = "Failed to decrypt!" + } + + case .failure(let error): + encryptText = "An error occured attempting to encrypt a document: \(error)" + } + + // Present response + print(encryptText) + self.responseLabel.text = encryptText + + print(decryptText) + self.responseLabel.text = decryptText + }) + } /// Demonstrates writing data securely to E3db. /// The `write` operation will encrypt the secret message diff --git a/Example/Podfile.lock b/Example/Podfile.lock index e4726a5..2679fcd 100644 --- a/Example/Podfile.lock +++ b/Example/Podfile.lock @@ -1,7 +1,7 @@ PODS: - - E3db (4.2.2): - - E3db/Core (= 4.2.2) - - E3db/Core (4.2.2): + - E3db (4.2.3): + - E3db/Core (= 4.2.3) + - E3db/Core (4.2.3): - ToznyHeimdallr (~> 4.0.2) - ToznySodium (~> 0.10.0) - ToznySwish (~> 5.0.1)