finish simple "add password function"

This commit is contained in:
Bob Sun 2017-02-10 22:15:01 +08:00
parent cbbb631e08
commit b954a4dcab
No known key found for this signature in database
GPG key ID: 1F86BA2052FED3B4
13 changed files with 314 additions and 26 deletions

View file

@ -26,7 +26,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
SVProgressHUD.setMinimumSize(CGSize(width: 150, height: 100))
passcodeLockPresenter.present()
if let shortcutItem = launchOptions?[UIApplicationLaunchOptionsKey.shortcutItem] as? UIApplicationShortcutItem {
print(shortcutItem.type)
if shortcutItem.type == "me.mssun.pass.search" {
self.perform(#selector(postSearchNotification), with: nil, afterDelay: 0.4)
}

View file

@ -55,6 +55,11 @@
</view>
<navigationItem key="navigationItem" title="Password Store" id="Cio-ZG-zCS">
<barButtonItem key="backBarButtonItem" title="Back" id="New-sD-9Z1"/>
<barButtonItem key="rightBarButtonItem" systemItem="add" id="qVW-c1-xgh">
<connections>
<segue destination="fyR-Cj-h6o" kind="show" id="zhp-fK-Zwp"/>
</connections>
</barButtonItem>
</navigationItem>
<connections>
<outlet property="tableView" destination="Tn1-q5-vaJ" id="UHc-AS-gXh"/>
@ -507,14 +512,14 @@
<rect key="frame" x="0.0" y="0.0" width="414" height="51"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="PGP Key URL" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="dWi-eh-7Eq">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Public Key URL" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="dWi-eh-7Eq">
<rect key="frame" x="15" y="8" width="391" height="15"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleCaption1"/>
<color key="textColor" white="0.33333333333333331" alpha="1" colorSpace="calibratedWhite"/>
<nil key="highlightedColor"/>
</label>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" placeholder="PGP Key URL" minimumFontSize="17" clearButtonMode="whileEditing" translatesAutoresizingMaskIntoConstraints="NO" id="Rb8-zs-TGa">
<rect key="frame" x="15" y="22.666666666666664" width="391" height="20.999999999999993"/>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" placeholder="Public Key URL" minimumFontSize="17" clearButtonMode="whileEditing" translatesAutoresizingMaskIntoConstraints="NO" id="Rb8-zs-TGa">
<rect key="frame" x="15" y="23" width="391" height="21"/>
<nil key="textColor"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
<textInputTraits key="textInputTraits" autocorrectionType="no" spellCheckingType="no" keyboardType="URL"/>
@ -530,9 +535,39 @@
</constraints>
</tableViewCellContentView>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="passphraseTableViewCell" rowHeight="52" id="qrQ-bd-sV8">
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="pgpKeyURLTableViewCell" rowHeight="52" id="vpk-J8-j7t">
<rect key="frame" x="0.0" y="87" width="414" height="52"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="vpk-J8-j7t" id="1td-qT-6ts">
<rect key="frame" x="0.0" y="0.0" width="414" height="51"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Private Key URL" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Qht-RC-Yeg">
<rect key="frame" x="15" y="8" width="391" height="15"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleCaption1"/>
<color key="textColor" white="0.33333333333333331" alpha="1" colorSpace="calibratedWhite"/>
<nil key="highlightedColor"/>
</label>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" placeholder="Private Key URL" minimumFontSize="17" clearButtonMode="whileEditing" translatesAutoresizingMaskIntoConstraints="NO" id="cGJ-1g-Ztc">
<rect key="frame" x="15" y="23" width="391" height="21"/>
<nil key="textColor"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
<textInputTraits key="textInputTraits" autocorrectionType="no" spellCheckingType="no" keyboardType="URL"/>
</textField>
</subviews>
<constraints>
<constraint firstAttribute="topMargin" secondItem="Qht-RC-Yeg" secondAttribute="top" id="62r-G1-4dm"/>
<constraint firstItem="cGJ-1g-Ztc" firstAttribute="top" secondItem="Qht-RC-Yeg" secondAttribute="bottom" id="EkJ-SV-G4q"/>
<constraint firstAttribute="trailingMargin" secondItem="Qht-RC-Yeg" secondAttribute="trailing" id="G77-HF-QDd"/>
<constraint firstItem="Qht-RC-Yeg" firstAttribute="leading" secondItem="1td-qT-6ts" secondAttribute="leadingMargin" constant="7" id="Idd-V5-IDA"/>
<constraint firstAttribute="trailingMargin" secondItem="cGJ-1g-Ztc" secondAttribute="trailing" id="PCt-qz-Q4p"/>
<constraint firstItem="cGJ-1g-Ztc" firstAttribute="leading" secondItem="Qht-RC-Yeg" secondAttribute="leading" id="wih-Ox-YM5"/>
</constraints>
</tableViewCellContentView>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="passphraseTableViewCell" rowHeight="52" id="qrQ-bd-sV8">
<rect key="frame" x="0.0" y="139" width="414" height="52"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="qrQ-bd-sV8" id="7ts-YH-1tP">
<rect key="frame" x="0.0" y="0.0" width="414" height="51"/>
<autoresizingMask key="autoresizingMask"/>
@ -544,7 +579,7 @@
<nil key="highlightedColor"/>
</label>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" placeholder="Passphrase" minimumFontSize="17" clearButtonMode="whileEditing" translatesAutoresizingMaskIntoConstraints="NO" id="Nkx-gN-jNA">
<rect key="frame" x="15" y="22.666666666666664" width="391" height="20.999999999999993"/>
<rect key="frame" x="15" y="23" width="391" height="21"/>
<nil key="textColor"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
<textInputTraits key="textInputTraits" autocorrectionType="no" spellCheckingType="no" keyboardType="alphabet" keyboardAppearance="alert" secureTextEntry="YES"/>
@ -582,7 +617,8 @@
</navigationItem>
<connections>
<outlet property="pgpKeyPassphraseTextField" destination="Nkx-gN-jNA" id="ylV-LG-ibS"/>
<outlet property="pgpKeyURLTextField" destination="Rb8-zs-TGa" id="A6a-ny-iuX"/>
<outlet property="pgpPrivateKeyURLTextField" destination="cGJ-1g-Ztc" id="0K9-93-BKy"/>
<outlet property="pgpPublicKeyURLTextField" destination="Rb8-zs-TGa" id="ERy-Ui-ASZ"/>
</connections>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="hbx-RC-qg1" userLabel="First Responder" sceneMemberID="firstResponder"/>
@ -590,6 +626,38 @@
</objects>
<point key="canvasLocation" x="5638" y="3511"/>
</scene>
<!--Add Password-->
<scene sceneID="738-Zk-wRb">
<objects>
<tableViewController id="FgE-RV-izf" customClass="AddPasswordTableViewController" customModule="pass" customModuleProvider="target" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="static" style="grouped" separatorStyle="default" rowHeight="44" sectionHeaderHeight="18" sectionFooterHeight="18" id="xyq-V7-x1G">
<rect key="frame" x="0.0" y="0.0" width="414" height="736"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" cocoaTouchSystemColor="groupTableViewBackgroundColor"/>
<sections/>
<connections>
<outlet property="dataSource" destination="FgE-RV-izf" id="Dis-iC-JWi"/>
<outlet property="delegate" destination="FgE-RV-izf" id="DyH-cS-8or"/>
</connections>
</tableView>
<navigationItem key="navigationItem" title="Add Password" id="KOg-Gn-Buk">
<barButtonItem key="leftBarButtonItem" systemItem="cancel" id="hWX-Dx-Xxi">
<connections>
<segue destination="rRf-7l-IGe" kind="unwind" unwindAction="cancelAddPasswordWithSegue:" id="G4F-ci-BmD"/>
</connections>
</barButtonItem>
<barButtonItem key="rightBarButtonItem" systemItem="save" id="FtF-nT-zRJ">
<connections>
<segue destination="rRf-7l-IGe" kind="unwind" unwindAction="saveAddPasswordWithSegue:" id="eVU-Kz-JU0"/>
</connections>
</barButtonItem>
</navigationItem>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="6R0-BP-wo8" userLabel="First Responder" sceneMemberID="firstResponder"/>
<exit id="rRf-7l-IGe" userLabel="Exit" sceneMemberID="exit"/>
</objects>
<point key="canvasLocation" x="4869.5652173913049" y="268.20652173913044"/>
</scene>
<!--Password Detail Table View Controller-->
<scene sceneID="9wY-d0-fB1">
<objects>
@ -607,7 +675,7 @@
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="9sC-44-OKL" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="3961" y="993"/>
<point key="canvasLocation" x="3961" y="982"/>
</scene>
<!--Password-->
<scene sceneID="ACd-rk-Zf3">
@ -990,6 +1058,24 @@
</objects>
<point key="canvasLocation" x="5638" y="6273"/>
</scene>
<!--Navigation Controller-->
<scene sceneID="zfZ-pX-bff">
<objects>
<navigationController automaticallyAdjustsScrollViewInsets="NO" id="fyR-Cj-h6o" sceneMemberID="viewController">
<toolbarItems/>
<navigationBar key="navigationBar" contentMode="scaleToFill" id="jtR-Sj-1XE">
<rect key="frame" x="0.0" y="0.0" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<nil name="viewControllers"/>
<connections>
<segue destination="FgE-RV-izf" kind="relationship" relationship="rootViewController" id="yEo-bX-uA0"/>
</connections>
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="Zq0-iH-LGe" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="3962.3188405797105" y="268.20652173913044"/>
</scene>
</scenes>
<resources>
<image name="Lock" width="25" height="25"/>

View file

@ -0,0 +1,51 @@
//
// AddPasswordTableViewController.swift
// pass
//
// Created by Mingshen Sun on 10/2/2017.
// Copyright © 2017 Bob Sun. All rights reserved.
//
import UIKit
class AddPasswordTableViewController: UITableViewController {
let tableTitles = ["name", "password"]
var password: Password?
override func viewDidLoad() {
super.viewDidLoad()
tableView.register(UINib(nibName: "TextFieldTableViewCell", bundle: nil), forCellReuseIdentifier: "textFieldCell")
tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 52
tableView.allowsSelection = false
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return tableTitles.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "textFieldCell", for: indexPath) as! TextFieldTableViewCell
cell.titleLabel.text = tableTitles[indexPath.row]
return cell
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let name = getCellForName(name: "name")!.contentTextField.text ?? ""
let passwordText = getCellForName(name: "password")!.contentTextField.text ?? ""
// let additions = getCellForName(name: "additions")!.contentTextField.text ?? ""
// let additionSplit = additions.characters.split(separator: ":").map(String.init)
// print(additionSplit)
// let additionField = AdditionField(title: additionSplit[0], content: additionSplit[1])
password = Password(name: name, username: "", password: passwordText, additions: [])
}
func getCellAt(row: Int) -> TextFieldTableViewCell? {
return tableView.cellForRow(at: IndexPath(row: row, section: 0)) as? TextFieldTableViewCell
}
func getCellForName(name: String) -> TextFieldTableViewCell? {
let index = tableTitles.index(of: name)!
return getCellAt(row: Int(index))
}
}

View file

@ -11,18 +11,21 @@ import SwiftyUserDefaults
class PGPKeySettingTableViewController: UITableViewController {
@IBOutlet weak var pgpKeyURLTextField: UITextField!
@IBOutlet weak var pgpPublicKeyURLTextField: UITextField!
@IBOutlet weak var pgpPrivateKeyURLTextField: UITextField!
@IBOutlet weak var pgpKeyPassphraseTextField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
pgpKeyURLTextField.text = Defaults[.pgpKeyURL]?.absoluteString
pgpPublicKeyURLTextField.text = Defaults[.pgpPublicKeyURL]?.absoluteString
pgpPrivateKeyURLTextField.text = Defaults[.pgpPrivateKeyURL]?.absoluteString
pgpKeyPassphraseTextField.text = Defaults[.pgpKeyPassphrase]
}
override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool {
if identifier == "savePGPKeySegue" {
if URL(string: pgpKeyURLTextField.text!)!.scheme! == "http" {
if URL(string: pgpPublicKeyURLTextField.text!)!.scheme! == "http" &&
URL(string: pgpPrivateKeyURLTextField.text!)!.scheme! == "http" {
let alertMessage = "HTTP connection is not supported."
let alert = UIAlertController(title: "Cannot Save Settings", message: alertMessage, preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))

View file

@ -27,6 +27,15 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
@IBOutlet weak var tableView: UITableView!
@IBAction func cancelAddPassword(segue: UIStoryboardSegue) {
}
@IBAction func saveAddPassword(segue: UIStoryboardSegue) {
if let controller = segue.source as? AddPasswordTableViewController {
PasswordStore.shared.add(password: controller.password!)
NotificationCenter.default.post(Notification(name: Notification.Name("passwordUpdated")))
}
}
func syncPasswords() {
SVProgressHUD.setDefaultMaskType(.black)
SVProgressHUD.setDefaultStyle(.light)

View file

@ -26,9 +26,11 @@ class SettingsTableViewController: UITableViewController {
@IBAction func save(segue: UIStoryboardSegue) {
if let controller = segue.source as? PGPKeySettingTableViewController {
if Defaults[.pgpKeyURL] != URL(string: controller.pgpKeyURLTextField.text!) ||
if Defaults[.pgpPrivateKeyURL] != URL(string: controller.pgpPrivateKeyURLTextField.text!) ||
Defaults[.pgpPublicKeyURL] != URL(string: controller.pgpPublicKeyURLTextField.text!) ||
Defaults[.pgpKeyPassphrase] != controller.pgpKeyPassphraseTextField.text! {
Defaults[.pgpKeyURL] = URL(string: controller.pgpKeyURLTextField.text!)
Defaults[.pgpPrivateKeyURL] = URL(string: controller.pgpPrivateKeyURLTextField.text!)
Defaults[.pgpPublicKeyURL] = URL(string: controller.pgpPublicKeyURLTextField.text!)
Defaults[.pgpKeyPassphrase] = controller.pgpKeyPassphraseTextField.text!
SVProgressHUD.setDefaultMaskType(.black)
@ -36,7 +38,10 @@ class SettingsTableViewController: UITableViewController {
SVProgressHUD.show(withStatus: "Fetching PGP Key")
DispatchQueue.global(qos: .userInitiated).async { [unowned self] in
do {
try PasswordStore.shared.initPGP(pgpKeyURL: Defaults[.pgpKeyURL]!, pgpKeyLocalPath: Globals.secringPath)
try PasswordStore.shared.initPGP(pgpPublicKeyURL: Defaults[.pgpPublicKeyURL]!,
pgpPublicKeyLocalPath: Globals.pgpPublicKeyPath,
pgpPrivateKeyURL: Defaults[.pgpPrivateKeyURL]!,
pgpPrivateKeyLocalPath: Globals.pgpPrivateKeyPath)
DispatchQueue.main.async {
self.pgpKeyTableViewCell.detailTextLabel?.text = Defaults[.pgpKeyID]
SVProgressHUD.showSuccess(withStatus: "Success. Remember to remove the key from the server.")

View file

@ -10,7 +10,9 @@ import Foundation
import SwiftyUserDefaults
extension DefaultsKeys {
static let pgpKeyURL = DefaultsKey<URL?>("pgpKeyURL")
// static let pgpKeyURL = DefaultsKey<URL?>("pgpKeyURL")
static let pgpPublicKeyURL = DefaultsKey<URL?>("pgpPublicKeyURL")
static let pgpPrivateKeyURL = DefaultsKey<URL?>("pgpPrivateKeyURL")
static let pgpKeyPassphrase = DefaultsKey<String>("pgpKeyPassphrase")
static let pgpKeyID = DefaultsKey<String>("pgpKeyID")
@ -31,7 +33,8 @@ extension DefaultsKeys {
extension Utils {
static func eraseAllUserDefaults() {
Defaults.remove(.pgpKeyURL)
Defaults.remove(.pgpPublicKeyURL)
Defaults.remove(.pgpPrivateKeyURL)
Defaults.remove(.pgpKeyPassphrase)
Defaults.remove(.pgpKeyID)

View file

@ -10,9 +10,13 @@ import Foundation
class Globals {
static let documentPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0];
static let secringPath = "\(documentPath)/secring.gpg"
static let pgpPublicKeyPath = "\(documentPath)/gpg_key.pub"
static let pgpPrivateKeyPath = "\(documentPath)/gpg_key"
static let sshPublicKeyURL = URL(fileURLWithPath: "\(documentPath)/ssh_key.pub")
static let sshPrivateKeyURL = URL(fileURLWithPath: "\(documentPath)/ssh_key")
static let repositoryPath = "\(documentPath)/password-store"
static var passcodeConfiguration = PasscodeLockConfiguration()
static let version = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as! String
private init() { }

View file

@ -49,7 +49,7 @@ class Password {
extension PasswordEntity {
func decrypt() throws -> Password? {
var password: Password?
let encryptedDataPath = URL(fileURLWithPath: "\(Globals.documentPath)/\(rawPath!)")
let encryptedDataPath = URL(fileURLWithPath: "\(Globals.repositoryPath)/\(rawPath!)")
let encryptedData = try Data(contentsOf: encryptedDataPath)
let decryptedData = try PasswordStore.shared.pgp.decryptData(encryptedData, passphrase: Defaults[.pgpKeyPassphrase])
let plain = String(data: decryptedData, encoding: .ascii) ?? ""
@ -82,4 +82,15 @@ extension PasswordEntity {
password = Password(name: name!, username: username, password: decrypted_password, additions: decrypted_addtions)
return password
}
func encrypt(password: Password) throws -> Data {
name = password.name
rawPath = ""
let plainPassword = password.password
// let plainAdditions = password.additions.map { "\($0.title): \($0.content)" }.joined(separator: "\n")
let plainData = "\(plainPassword)\n".data(using: .ascii)!
let pgp = PasswordStore.shared.pgp
let encryptedData = try pgp.encryptData(plainData, usingPublicKey: pgp.getKeysOf(.public)[0], armored: false)
return encryptedData
}
}

View file

@ -58,7 +58,9 @@ class PasswordStore {
print(error)
}
if Defaults[.pgpKeyID] != "" {
pgp.importKeys(fromFile: Globals.secringPath, allowDuplicates: false)
pgp.importKeys(fromFile: Globals.pgpPublicKeyPath, allowDuplicates: false)
pgp.importKeys(fromFile: Globals.pgpPrivateKeyPath, allowDuplicates: false)
}
if Defaults[.gitRepositoryAuthenticationMethod] == "Password" {
gitCredential = GitCredential(credential: GitCredential.Credential.http(userName: Defaults[.gitRepositoryUsername], password: Defaults[.gitRepositoryPassword]))
@ -70,11 +72,17 @@ class PasswordStore {
}
func initPGP(pgpKeyURL: URL, pgpKeyLocalPath: String) throws {
let pgpData = try Data(contentsOf: pgpKeyURL)
try pgpData.write(to: URL(fileURLWithPath: pgpKeyLocalPath), options: .atomic)
pgp.importKeys(fromFile: pgpKeyLocalPath, allowDuplicates: false)
let key = pgp.keys[0]
func initPGP(pgpPublicKeyURL: URL, pgpPublicKeyLocalPath: String, pgpPrivateKeyURL: URL, pgpPrivateKeyLocalPath: String) throws {
let pgpPublicData = try Data(contentsOf: pgpPublicKeyURL)
try pgpPublicData.write(to: URL(fileURLWithPath: pgpPublicKeyLocalPath), options: .atomic)
let pgpPrivateData = try Data(contentsOf: pgpPrivateKeyURL)
try pgpPrivateData.write(to: URL(fileURLWithPath: pgpPrivateKeyLocalPath), options: .atomic)
pgp.importKeys(fromFile: pgpPublicKeyLocalPath, allowDuplicates: false)
pgp.importKeys(fromFile: pgpPrivateKeyLocalPath, allowDuplicates: false)
let key = pgp.getKeysOf(.public)[0]
Defaults[.pgpKeyID] = key.keyID!.shortKeyString
if let gpgUser = key.users[0] as? PGPUser {
Defaults[.pgpKeyUserID] = gpgUser.userID
@ -130,7 +138,7 @@ class PasswordStore {
let passwordEntity = PasswordEntity(context: context)
let endIndex = url.lastPathComponent.index(url.lastPathComponent.endIndex, offsetBy: -4)
passwordEntity.name = url.lastPathComponent.substring(to: endIndex)
passwordEntity.rawPath = "password-store/\(url.path)"
passwordEntity.rawPath = "\(url.path)"
let items = url.path.characters.split(separator: "/").map(String.init)
for i in 0 ..< items.count - 1 {
let passwordCategoryEntity = PasswordCategoryEntity(context: context)
@ -173,6 +181,23 @@ class PasswordStore {
func updateRemoteRepo() {
}
func commitChange() {
}
func add(password: Password) {
let passwordEntity = NSEntityDescription.insertNewObject(forEntityName: "PasswordEntity", into: context) as! PasswordEntity
do {
let encryptedData = try passwordEntity.encrypt(password: password)
let saveURL = storeURL.appendingPathComponent("\(password.name).gpg")
try encryptedData.write(to: saveURL)
passwordEntity.rawPath = "\(password.name).gpg"
try context.save()
} catch {
print(error)
}
}
func deleteCoreData(entityName: String) {
let deleteFetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: entityName)
let deleteRequest = NSBatchDeleteRequest(fetchRequest: deleteFetchRequest)
@ -186,7 +211,8 @@ class PasswordStore {
func erase() {
Utils.removeFileIfExists(at: storeURL)
Utils.removeFileIfExists(atPath: Globals.secringPath)
Utils.removeFileIfExists(atPath: Globals.pgpPublicKeyPath)
Utils.removeFileIfExists(atPath: Globals.pgpPrivateKeyPath)
Utils.removeFileIfExists(at: Globals.sshPrivateKeyURL)
Utils.removeFileIfExists(at: Globals.sshPublicKeyURL)

View file

@ -0,0 +1,27 @@
//
// TextFieldTableViewCell.swift
// pass
//
// Created by Mingshen Sun on 10/2/2017.
// Copyright © 2017 Bob Sun. All rights reserved.
//
import UIKit
class TextFieldTableViewCell: UITableViewCell {
@IBOutlet weak var titleLabel: UILabel!
@IBOutlet weak var contentTextField: UITextField!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}

View file

@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="11762" systemVersion="16D32" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" rowHeight="56" id="KGk-i7-Jjw" customClass="TextFieldTableViewCell" customModule="pass" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="320" height="56"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM">
<rect key="frame" x="0.0" y="0.0" width="320" height="55.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" verticalCompressionResistancePriority="751" text="title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="HPC-rQ-39b">
<rect key="frame" x="15" y="8" width="297" height="15"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleCaption1"/>
<color key="textColor" red="0.0" green="0.47843137250000001" blue="1" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="8Ky-UZ-sLu">
<rect key="frame" x="15" y="26" width="297" height="21.5"/>
<nil key="textColor"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
<textInputTraits key="textInputTraits" autocorrectionType="no" spellCheckingType="no" returnKeyType="next"/>
</textField>
</subviews>
<constraints>
<constraint firstAttribute="bottomMargin" secondItem="8Ky-UZ-sLu" secondAttribute="bottom" id="11n-KG-zy6"/>
<constraint firstItem="8Ky-UZ-sLu" firstAttribute="trailing" secondItem="HPC-rQ-39b" secondAttribute="trailing" id="42z-vE-AsJ"/>
<constraint firstItem="8Ky-UZ-sLu" firstAttribute="leading" secondItem="HPC-rQ-39b" secondAttribute="leading" id="8F6-w6-BDY"/>
<constraint firstAttribute="trailingMargin" secondItem="HPC-rQ-39b" secondAttribute="trailing" id="Ayv-Bg-JxT"/>
<constraint firstItem="HPC-rQ-39b" firstAttribute="top" secondItem="H2p-sc-9uM" secondAttribute="topMargin" id="JN2-lI-0ZY"/>
<constraint firstItem="8Ky-UZ-sLu" firstAttribute="top" secondItem="HPC-rQ-39b" secondAttribute="bottom" constant="3" id="Pqs-gm-93j"/>
<constraint firstItem="HPC-rQ-39b" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leadingMargin" constant="7" id="vfA-M9-FEp"/>
</constraints>
</tableViewCellContentView>
<connections>
<outlet property="contentTextField" destination="8Ky-UZ-sLu" id="pdS-Nl-e9s"/>
<outlet property="titleLabel" destination="HPC-rQ-39b" id="yPo-dZ-cth"/>
</connections>
<point key="canvasLocation" x="34" y="60"/>
</tableViewCell>
</objects>
</document>