Skip to content

Commit

Permalink
[PLAT-951] Release 4.2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Rhea committed Apr 6, 2022
1 parent acf0dc7 commit 4dd1525
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 28 deletions.
6 changes: 3 additions & 3 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion E3db.podspec
Original file line number Diff line number Diff line change
@@ -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'

Expand Down
20 changes: 17 additions & 3 deletions E3db/Classes/Crypto.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
42 changes: 25 additions & 17 deletions Example/E3db-Example/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13178.6" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="vXZ-lx-hvc">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="20037" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="vXZ-lx-hvc">
<device id="retina5_9" orientation="portrait" appearance="light"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13156.2"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="20020"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand All @@ -18,17 +16,17 @@
<viewControllerLayoutGuide type="bottom" id="2fi-mo-0CV"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="kh9-bI-dsS">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="812"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Tozny E3DB" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="UE9-4F-0Vt">
<rect key="frame" x="16" y="40" width="343" height="36"/>
<rect key="frame" x="16" y="64" width="343" height="36"/>
<fontDescription key="fontDescription" type="system" weight="light" pointSize="30"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="xAa-ty-FOl">
<rect key="frame" x="23" y="265" width="328" height="45"/>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="xAa-ty-FOl">
<rect key="frame" x="23" y="376" width="329" height="45"/>
<color key="backgroundColor" red="0.22745098039215686" green="0.31372549019607843" blue="0.41960784313725491" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="height" constant="45" id="YW7-3q-CDq"/>
Expand All @@ -40,10 +38,10 @@
</connections>
</button>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="IKW-a9-3bw">
<rect key="frame" x="16" y="154" width="343" height="103"/>
<rect key="frame" x="16" y="178" width="343" height="190"/>
<subviews>
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" textAlignment="natural" translatesAutoresizingMaskIntoConstraints="NO" id="gaZ-12-jU2">
<rect key="frame" x="8" y="50" width="327" height="45"/>
<rect key="frame" x="8" y="50" width="327" height="132"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
Expand All @@ -59,29 +57,39 @@
</constraints>
</view>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Enter a Secret Message..." textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="7s0-Fl-g2C">
<rect key="frame" x="16" y="162" width="343" height="22"/>
<rect key="frame" x="16" y="186" width="343" height="22"/>
<fontDescription key="fontDescription" type="system" pointSize="18"/>
<color key="textColor" red="1" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="mNV-Jk-14s">
<rect key="frame" x="23" y="318" width="328" height="33"/>
<rect key="frame" x="23" y="429" width="329" height="33"/>
<constraints>
<constraint firstAttribute="height" constant="33" id="kip-qG-3k5"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="0wX-yb-nje">
<rect key="frame" x="23" y="359" width="328" height="45"/>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="0wX-yb-nje">
<rect key="frame" x="23" y="470" width="329" height="45"/>
<color key="backgroundColor" red="0.2274509804" green="0.31372549020000001" blue="0.41960784309999999" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="tintColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<state key="normal" title="Read Latest"/>
<connections>
<action selector="read" destination="vXZ-lx-hvc" eventType="touchUpInside" id="aEK-4r-nxt"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="9sA-RH-trl">
<rect key="frame" x="23" y="571" width="329" height="45"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" red="0.2274509804" green="0.31372549020000001" blue="0.41960784309999999" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="tintColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<state key="normal" title="DocumentWrite"/>
<connections>
<action selector="encryptDocument" destination="vXZ-lx-hvc" eventType="touchUpInside" id="PCT-Ma-sQs"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" red="0.80000000000000004" green="0.85882352941176465" blue="0.86274509803921573" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
Expand Down Expand Up @@ -115,7 +123,7 @@
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="x5A-6p-PRh" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="32.799999999999997" y="36.431784107946029"/>
<point key="canvasLocation" x="-1927" y="74"/>
</scene>
</scenes>
</document>
43 changes: 42 additions & 1 deletion Example/E3db-Example/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -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)
Expand Down

0 comments on commit 4dd1525

Please sign in to comment.