From 36bf40741cc4fad08f4618be070b939d9e00ce6e Mon Sep 17 00:00:00 2001 From: Bob Sun Date: Sun, 22 Jan 2017 01:42:36 +0800 Subject: [PATCH] change a lot, the structure will be stable this time --- Cartfile | 1 + Podfile | 3 + pass.xcodeproj/project.pbxproj | 97 ++++- pass/Base.lproj/Main.storyboard | 349 ++++++++++++++---- ...angeGitRepositoryTableViewController.swift | 42 --- pass/DefaultKeys.swift | 20 + .../GitServerSettingTableViewController.swift | 31 ++ pass/Globals.swift | 16 + pass/Objective-CBridgingHeader.h | 14 + pass/PGPKeySettingTableViewController.swift | 22 ++ pass/PasswordDetailViewController.swift | 43 ++- pass/PasswordStore.swift | 30 +- pass/PasswordTableViewController.swift | 53 +-- pass/SettingsTableViewController.swift | 66 ++-- 14 files changed, 579 insertions(+), 208 deletions(-) create mode 100644 Podfile delete mode 100644 pass/ChangeGitRepositoryTableViewController.swift create mode 100644 pass/DefaultKeys.swift create mode 100644 pass/GitServerSettingTableViewController.swift create mode 100644 pass/Globals.swift create mode 100644 pass/Objective-CBridgingHeader.h create mode 100644 pass/PGPKeySettingTableViewController.swift diff --git a/Cartfile b/Cartfile index 5d3a705..0cfaa64 100644 --- a/Cartfile +++ b/Cartfile @@ -1,2 +1,3 @@ github "SwiftGit2/SwiftGit2" github "SVProgressHUD/SVProgressHUD" +github "radex/SwiftyUserDefaults" diff --git a/Podfile b/Podfile new file mode 100644 index 0000000..afcb71f --- /dev/null +++ b/Podfile @@ -0,0 +1,3 @@ +target 'pass' do + pod 'ObjectivePGP' +end diff --git a/pass.xcodeproj/project.pbxproj b/pass.xcodeproj/project.pbxproj index e5c4354..e2dbef7 100644 --- a/pass.xcodeproj/project.pbxproj +++ b/pass.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 94BA784B85E071D25EE89B59 /* libPods-pass.a in Frameworks */ = {isa = PBXBuildFile; fileRef = ADCE7A5C3CCC67D7D21BB3C4 /* libPods-pass.a */; }; DC3DC8391E2F63240062A988 /* PasswordDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC3DC8381E2F63240062A988 /* PasswordDetailViewController.swift */; }; DC917BD71E2E8231000FDF54 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC917BD61E2E8231000FDF54 /* AppDelegate.swift */; }; DC917BDC1E2E8231000FDF54 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = DC917BDA1E2E8231000FDF54 /* Main.storyboard */; }; @@ -15,7 +16,11 @@ DC917BEF1E2F38C5000FDF54 /* Result.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DC917BEE1E2F38C5000FDF54 /* Result.framework */; }; DC917BF11E2F38C9000FDF54 /* SwiftGit2.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DC917BF01E2F38C9000FDF54 /* SwiftGit2.framework */; }; DC917BF31E2F3B42000FDF54 /* PasswordTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC917BF21E2F3B42000FDF54 /* PasswordTableViewController.swift */; }; - DC9C451C1E2F8CA7005845CA /* ChangeGitRepositoryTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC9C451B1E2F8CA7005845CA /* ChangeGitRepositoryTableViewController.swift */; }; + DCA049961E3357E000522E8F /* SwiftyUserDefaults.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DCA049951E3357E000522E8F /* SwiftyUserDefaults.framework */; }; + DCA049981E33586A00522E8F /* DefaultKeys.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCA049971E33586A00522E8F /* DefaultKeys.swift */; }; + DCA0499A1E335CC800522E8F /* GitServerSettingTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCA049991E335CC800522E8F /* GitServerSettingTableViewController.swift */; }; + DCA0499C1E3362F400522E8F /* PGPKeySettingTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCA0499B1E3362F400522E8F /* PGPKeySettingTableViewController.swift */; }; + DCA0499E1E33BAC100522E8F /* Globals.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCA0499D1E33BAC100522E8F /* Globals.swift */; }; DCAAF7451E2FA66800AB94BC /* SettingsTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCAAF7441E2FA66800AB94BC /* SettingsTableViewController.swift */; }; DCC277D21E30D6EA00402246 /* pass.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = DCC408C81E30BA1300F29B0E /* pass.xcdatamodeld */; }; DCC408A41E2FCC9E00F29B0E /* PasswordStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCC408A31E2FCC9E00F29B0E /* PasswordStore.swift */; }; @@ -23,7 +28,11 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 274CCFCF32444A2FF46BE7F4 /* Pods-pass.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-pass.debug.xcconfig"; path = "Pods/Target Support Files/Pods-pass/Pods-pass.debug.xcconfig"; sourceTree = ""; }; + ADCE7A5C3CCC67D7D21BB3C4 /* libPods-pass.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-pass.a"; sourceTree = BUILT_PRODUCTS_DIR; }; + AEAD6B31EAF5D061447A68CC /* Pods-pass.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-pass.release.xcconfig"; path = "Pods/Target Support Files/Pods-pass/Pods-pass.release.xcconfig"; sourceTree = ""; }; DC3DC8381E2F63240062A988 /* PasswordDetailViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PasswordDetailViewController.swift; sourceTree = ""; }; + DC4A746D1E30FBDE00E8EB18 /* Objective-CBridgingHeader.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Objective-CBridgingHeader.h"; sourceTree = ""; }; DC917BD31E2E8231000FDF54 /* pass.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = pass.app; sourceTree = BUILT_PRODUCTS_DIR; }; DC917BD61E2E8231000FDF54 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; DC917BDB1E2E8231000FDF54 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; @@ -33,7 +42,11 @@ DC917BEE1E2F38C5000FDF54 /* Result.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Result.framework; path = Carthage/Build/iOS/Result.framework; sourceTree = ""; }; DC917BF01E2F38C9000FDF54 /* SwiftGit2.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SwiftGit2.framework; path = Carthage/Build/iOS/SwiftGit2.framework; sourceTree = ""; }; DC917BF21E2F3B42000FDF54 /* PasswordTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PasswordTableViewController.swift; sourceTree = ""; }; - DC9C451B1E2F8CA7005845CA /* ChangeGitRepositoryTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChangeGitRepositoryTableViewController.swift; sourceTree = ""; }; + DCA049951E3357E000522E8F /* SwiftyUserDefaults.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SwiftyUserDefaults.framework; path = Carthage/Build/iOS/SwiftyUserDefaults.framework; sourceTree = ""; }; + DCA049971E33586A00522E8F /* DefaultKeys.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DefaultKeys.swift; sourceTree = ""; }; + DCA049991E335CC800522E8F /* GitServerSettingTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GitServerSettingTableViewController.swift; sourceTree = ""; }; + DCA0499B1E3362F400522E8F /* PGPKeySettingTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PGPKeySettingTableViewController.swift; sourceTree = ""; }; + DCA0499D1E33BAC100522E8F /* Globals.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Globals.swift; sourceTree = ""; }; DCAAF7441E2FA66800AB94BC /* SettingsTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SettingsTableViewController.swift; sourceTree = ""; }; DCC408A31E2FCC9E00F29B0E /* PasswordStore.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PasswordStore.swift; sourceTree = ""; }; DCC408C61E307DBB00F29B0E /* SVProgressHUD.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SVProgressHUD.framework; path = Carthage/Build/iOS/SVProgressHUD.framework; sourceTree = ""; }; @@ -48,18 +61,30 @@ DC917BEF1E2F38C5000FDF54 /* Result.framework in Frameworks */, DC917BF11E2F38C9000FDF54 /* SwiftGit2.framework in Frameworks */, DCC408C71E307DBB00F29B0E /* SVProgressHUD.framework in Frameworks */, + DCA049961E3357E000522E8F /* SwiftyUserDefaults.framework in Frameworks */, + 94BA784B85E071D25EE89B59 /* libPods-pass.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + A51B01737D08DB47BB58F85A /* Pods */ = { + isa = PBXGroup; + children = ( + 274CCFCF32444A2FF46BE7F4 /* Pods-pass.debug.xcconfig */, + AEAD6B31EAF5D061447A68CC /* Pods-pass.release.xcconfig */, + ); + name = Pods; + sourceTree = ""; + }; DC917BCA1E2E8231000FDF54 = { isa = PBXGroup; children = ( DC917BD51E2E8231000FDF54 /* pass */, DC917BD41E2E8231000FDF54 /* Products */, DC917BED1E2F38C4000FDF54 /* Frameworks */, + A51B01737D08DB47BB58F85A /* Pods */, ); sourceTree = ""; }; @@ -74,17 +99,21 @@ DC917BD51E2E8231000FDF54 /* pass */ = { isa = PBXGroup; children = ( + DC4A746D1E30FBDE00E8EB18 /* Objective-CBridgingHeader.h */, DC917BF21E2F3B42000FDF54 /* PasswordTableViewController.swift */, DC917BD61E2E8231000FDF54 /* AppDelegate.swift */, DC917BDA1E2E8231000FDF54 /* Main.storyboard */, + DCA0499B1E3362F400522E8F /* PGPKeySettingTableViewController.swift */, + DCA049991E335CC800522E8F /* GitServerSettingTableViewController.swift */, DCAAF7441E2FA66800AB94BC /* SettingsTableViewController.swift */, DCC408C81E30BA1300F29B0E /* pass.xcdatamodeld */, - DC9C451B1E2F8CA7005845CA /* ChangeGitRepositoryTableViewController.swift */, DC3DC8381E2F63240062A988 /* PasswordDetailViewController.swift */, DC917BDD1E2E8231000FDF54 /* Assets.xcassets */, DC917BDF1E2E8231000FDF54 /* LaunchScreen.storyboard */, DC917BE21E2E8231000FDF54 /* Info.plist */, DCC408A31E2FCC9E00F29B0E /* PasswordStore.swift */, + DCA049971E33586A00522E8F /* DefaultKeys.swift */, + DCA0499D1E33BAC100522E8F /* Globals.swift */, ); path = pass; sourceTree = ""; @@ -92,9 +121,11 @@ DC917BED1E2F38C4000FDF54 /* Frameworks */ = { isa = PBXGroup; children = ( + DCA049951E3357E000522E8F /* SwiftyUserDefaults.framework */, DCC408C61E307DBB00F29B0E /* SVProgressHUD.framework */, DC917BF01E2F38C9000FDF54 /* SwiftGit2.framework */, DC917BEE1E2F38C5000FDF54 /* Result.framework */, + ADCE7A5C3CCC67D7D21BB3C4 /* libPods-pass.a */, ); name = Frameworks; sourceTree = ""; @@ -106,10 +137,13 @@ isa = PBXNativeTarget; buildConfigurationList = DC917BE51E2E8231000FDF54 /* Build configuration list for PBXNativeTarget "pass" */; buildPhases = ( + 68560E350F5EA82DA480749C /* [CP] Check Pods Manifest.lock */, DC917BCF1E2E8231000FDF54 /* Sources */, DC917BD01E2E8231000FDF54 /* Frameworks */, DC917BD11E2E8231000FDF54 /* Resources */, DC917BEC1E2F3659000FDF54 /* ShellScript */, + 58F20B5DB8A41D610AF2145E /* [CP] Embed Pods Frameworks */, + D5AA0953A6BB441CE2390DE3 /* [CP] Copy Pods Resources */, ); buildRules = ( ); @@ -169,6 +203,51 @@ /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ + 58F20B5DB8A41D610AF2145E /* [CP] Embed Pods Frameworks */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "[CP] Embed Pods Frameworks"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-pass/Pods-pass-frameworks.sh\"\n"; + showEnvVarsInLog = 0; + }; + 68560E350F5EA82DA480749C /* [CP] Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "[CP] Check Pods Manifest.lock"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n"; + showEnvVarsInLog = 0; + }; + D5AA0953A6BB441CE2390DE3 /* [CP] Copy Pods Resources */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "[CP] Copy Pods Resources"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-pass/Pods-pass-resources.sh\"\n"; + showEnvVarsInLog = 0; + }; DC917BEC1E2F3659000FDF54 /* ShellScript */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 12; @@ -178,6 +257,7 @@ "$(SRCROOT)/Carthage/Build/iOS/SwiftGit2.framework", "$(SRCROOT)/Carthage/Build/iOS/Result.framework", "$(SRCROOT)/Carthage/Build/iOS/SVProgressHUD.framework", + "$(SRCROOT)/Carthage/Build/iOS/SwiftyUserDefaults.framework", ); outputPaths = ( ); @@ -194,11 +274,14 @@ files = ( DC917BF31E2F3B42000FDF54 /* PasswordTableViewController.swift in Sources */, DCC408A41E2FCC9E00F29B0E /* PasswordStore.swift in Sources */, + DCA0499C1E3362F400522E8F /* PGPKeySettingTableViewController.swift in Sources */, DCAAF7451E2FA66800AB94BC /* SettingsTableViewController.swift in Sources */, + DCA0499A1E335CC800522E8F /* GitServerSettingTableViewController.swift in Sources */, DCC277D21E30D6EA00402246 /* pass.xcdatamodeld in Sources */, DC917BD71E2E8231000FDF54 /* AppDelegate.swift in Sources */, + DCA049981E33586A00522E8F /* DefaultKeys.swift in Sources */, + DCA0499E1E33BAC100522E8F /* Globals.swift in Sources */, DC3DC8391E2F63240062A988 /* PasswordDetailViewController.swift in Sources */, - DC9C451C1E2F8CA7005845CA /* ChangeGitRepositoryTableViewController.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -317,8 +400,10 @@ }; DC917BE61E2E8231000FDF54 /* Debug */ = { isa = XCBuildConfiguration; + baseConfigurationReference = 274CCFCF32444A2FF46BE7F4 /* Pods-pass.debug.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEFINES_MODULE = NO; DEVELOPMENT_TEAM = 779BQYPRCF; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -328,14 +413,17 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = me.mssun.pass; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OBJC_BRIDGING_HEADER = "/Users/mssun/Code/XcodeProjects/pass/pass/Objective-CBridgingHeader.h"; SWIFT_VERSION = 3.0; }; name = Debug; }; DC917BE71E2E8231000FDF54 /* Release */ = { isa = XCBuildConfiguration; + baseConfigurationReference = AEAD6B31EAF5D061447A68CC /* Pods-pass.release.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEFINES_MODULE = NO; DEVELOPMENT_TEAM = 779BQYPRCF; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -345,6 +433,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = me.mssun.pass; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OBJC_BRIDGING_HEADER = "/Users/mssun/Code/XcodeProjects/pass/pass/Objective-CBridgingHeader.h"; SWIFT_VERSION = 3.0; }; name = Release; diff --git a/pass/Base.lproj/Main.storyboard b/pass/Base.lproj/Main.storyboard index 9e13893..8003e77 100644 --- a/pass/Base.lproj/Main.storyboard +++ b/pass/Base.lproj/Main.storyboard @@ -36,7 +36,7 @@ - + @@ -46,97 +46,150 @@ - + + + - + - - + + - + - + - - + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - + - + - + - + - - + + - - + + - + - - + + - - + + - - + + + - - + + - - - - + + + + + @@ -144,30 +197,159 @@ - - + + - - + + + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + - - + + - + @@ -181,20 +363,23 @@ - + + + - + @@ -227,49 +412,67 @@ - + - + - - + + - - + + - + - + - + - + - + - + - + - + - + - + + + + + + + + + + + + + + + + + + + diff --git a/pass/ChangeGitRepositoryTableViewController.swift b/pass/ChangeGitRepositoryTableViewController.swift deleted file mode 100644 index 653a56f..0000000 --- a/pass/ChangeGitRepositoryTableViewController.swift +++ /dev/null @@ -1,42 +0,0 @@ -// -// ChangeGitRepositoryTableViewController.swift -// pass -// -// Created by Mingshen Sun on 18/1/2017. -// Copyright © 2017 Bob Sun. All rights reserved. -// - -import UIKit -import CoreData -import SVProgressHUD - - -class ChangeGitRepositoryTableViewController: UITableViewController { - - let userDefaults = UserDefaults.standard - var gitRepositoryURL: String? - - @IBOutlet weak var gitRepositoryURLTextField: UITextField! - - override func viewDidLoad() { - super.viewDidLoad() - if let url = userDefaults.string(forKey: "gitRepositoryURL") { - gitRepositoryURLTextField.text = url - } else { - gitRepositoryURLTextField.text = "https://github.com/mssun/public-password-store.git" - } - } - override func viewDidAppear(_ animated: Bool) { - super.viewDidAppear(animated) - gitRepositoryURLTextField.becomeFirstResponder() - } - override func viewWillDisappear(_ animated: Bool) { - super.viewWillDisappear(animated) - view.endEditing(true) - } - override func prepare(for segue: UIStoryboardSegue, sender: Any?) { - if segue.identifier == "save" { - gitRepositoryURL = gitRepositoryURLTextField.text! - } - } -} diff --git a/pass/DefaultKeys.swift b/pass/DefaultKeys.swift new file mode 100644 index 0000000..cec1e51 --- /dev/null +++ b/pass/DefaultKeys.swift @@ -0,0 +1,20 @@ +// +// DefaultKeys.swift +// pass +// +// Created by Mingshen Sun on 21/1/2017. +// Copyright © 2017 Bob Sun. All rights reserved. +// + +import Foundation +import SwiftyUserDefaults + +extension DefaultsKeys { + static let pgpKeyURL = DefaultsKey("pgpKeyURL") + + static let pgpKeyPassphrase = DefaultsKey("pgpKeyPassphrase") + static let pgpKeyID = DefaultsKey("pgpKeyID") + static let pgpKeyUserID = DefaultsKey("pgpKeyUserID") + + static let gitRepositoryURL = DefaultsKey("gitRepositoryURL") +} diff --git a/pass/GitServerSettingTableViewController.swift b/pass/GitServerSettingTableViewController.swift new file mode 100644 index 0000000..f166ba0 --- /dev/null +++ b/pass/GitServerSettingTableViewController.swift @@ -0,0 +1,31 @@ +// +// GitServerSettingTableViewController.swift +// pass +// +// Created by Mingshen Sun on 21/1/2017. +// Copyright © 2017 Bob Sun. All rights reserved. +// + +import UIKit +import SwiftyUserDefaults + +class GitServerSettingTableViewController: UITableViewController { + + @IBOutlet weak var gitRepositoryURLTextField: UITextField! + + override func viewDidLoad() { + super.viewDidLoad() + if let url = Defaults[.gitRepositoryURL] { + gitRepositoryURLTextField.text = url.absoluteString + } + } + + override func viewDidAppear(_ animated: Bool) { + super.viewDidAppear(animated) + gitRepositoryURLTextField.becomeFirstResponder() + } + override func viewWillDisappear(_ animated: Bool) { + super.viewWillDisappear(animated) + view.endEditing(true) + } +} diff --git a/pass/Globals.swift b/pass/Globals.swift new file mode 100644 index 0000000..2c364f6 --- /dev/null +++ b/pass/Globals.swift @@ -0,0 +1,16 @@ +// +// Globals.swift +// pass +// +// Created by Mingshen Sun on 21/1/2017. +// Copyright © 2017 Bob Sun. All rights reserved. +// + +import Foundation + +class Globals { + static let shared = Globals() + let documentPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]; + let secringPath = "\(NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0])/secring.gpg" + private init() { } +} diff --git a/pass/Objective-CBridgingHeader.h b/pass/Objective-CBridgingHeader.h new file mode 100644 index 0000000..945da44 --- /dev/null +++ b/pass/Objective-CBridgingHeader.h @@ -0,0 +1,14 @@ +// +// Objective-CBridgingHeader.h +// pass +// +// Created by Mingshen Sun on 19/1/2017. +// Copyright © 2017 Bob Sun. All rights reserved. +// + +#ifndef Objective_CBridgingHeader_h +#define Objective_CBridgingHeader_h + +#import + +#endif /* Objective_CBridgingHeader_h */ diff --git a/pass/PGPKeySettingTableViewController.swift b/pass/PGPKeySettingTableViewController.swift new file mode 100644 index 0000000..86265ec --- /dev/null +++ b/pass/PGPKeySettingTableViewController.swift @@ -0,0 +1,22 @@ +// +// PGPKeySettingTableViewController.swift +// pass +// +// Created by Mingshen Sun on 21/1/2017. +// Copyright © 2017 Bob Sun. All rights reserved. +// + +import UIKit +import SwiftyUserDefaults + +class PGPKeySettingTableViewController: UITableViewController { + + @IBOutlet weak var pgpKeyURLTextField: UITextField! + @IBOutlet weak var pgpKeyPassphraseTextField: UITextField! + + override func viewDidLoad() { + super.viewDidLoad() + pgpKeyURLTextField.text = Defaults[.pgpKeyURL]?.absoluteString + pgpKeyPassphraseTextField.text = Defaults[.pgpKeyPassphrase] + } +} diff --git a/pass/PasswordDetailViewController.swift b/pass/PasswordDetailViewController.swift index cec80f1..ed6b38e 100644 --- a/pass/PasswordDetailViewController.swift +++ b/pass/PasswordDetailViewController.swift @@ -7,29 +7,34 @@ // import UIKit +import SwiftyUserDefaults class PasswordDetailViewController: UIViewController { + @IBOutlet weak var passwordLabel: UILabel! + var passwordEntity: PasswordEntity? + override func viewDidLoad() { super.viewDidLoad() - - // Do any additional setup after loading the view. + + let encryptedDataURL = URL(fileURLWithPath: "\(Globals.shared.documentPath)/\(passwordEntity!.rawPath!)") + let fm = FileManager.default + if fm.fileExists(atPath: encryptedDataURL.path){ + print("file exist") + } else { + print("file doesnt exist") + } + + do { + let encryptedData = try Data(contentsOf: encryptedDataURL) + let decryptedData = try PasswordStore.shared.pgp.decryptData(encryptedData, passphrase: Defaults[.pgpKeyPassphrase]) + let plain = String(data: decryptedData, encoding: .ascii) ?? "" + print(plain) + passwordLabel.text = plain + } catch let error as NSError { + print(error.debugDescription) + } + + passwordLabel.sizeToFit() } - - override func didReceiveMemoryWarning() { - super.didReceiveMemoryWarning() - // Dispose of any resources that can be recreated. - } - - - /* - // MARK: - Navigation - - // In a storyboard-based application, you will often want to do a little preparation before navigation - override func prepare(for segue: UIStoryboardSegue, sender: Any?) { - // Get the new view controller using segue.destinationViewController. - // Pass the selected object to the new view controller. - } - */ - } diff --git a/pass/PasswordStore.swift b/pass/PasswordStore.swift index b8f6c54..303c602 100644 --- a/pass/PasswordStore.swift +++ b/pass/PasswordStore.swift @@ -11,12 +11,14 @@ import SwiftGit2 import Result import CoreData import UIKit +import SwiftyUserDefaults class PasswordStore { static let shared = PasswordStore() - let storeURL = URL(fileURLWithPath: "\(NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0])/password-store") + let storeURL = URL(fileURLWithPath: "\(Globals.shared.documentPath)/password-store") var storeRepo: Repository? + let pgp: ObjectivePGP = ObjectivePGP() let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext @@ -26,9 +28,31 @@ class PasswordStore { if case .success(let r) = result { storeRepo = r } + if Defaults[.pgpKeyID] != "" { + pgp.importKeys(fromFile: Globals.shared.secringPath, allowDuplicates: false) + + } } - func cloneRemoteRepo(remoteRepoURL: URL) -> Bool{ + func initPGP(pgpKeyURL: URL, pgpKeyLocalPath: String) -> Bool { + do { + 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] + Defaults[.pgpKeyID] = key.keyID!.shortKeyString + if let gpgUser = key.users[0] as? PGPUser { + Defaults[.pgpKeyUserID] = gpgUser.userID + } + return true + } catch { + print("error") + return false + } + } + + + func cloneRemoteRepo(remoteRepoURL: URL) -> Bool { print("start cloning remote repo") let fm = FileManager.default if (storeRepo != nil) { @@ -67,7 +91,7 @@ class PasswordStore { if url.pathExtension == "gpg" { let entity = PasswordEntity(context: context) entity.name = url.lastPathComponent - entity.rawPath = url.path + entity.rawPath = "password-store/\(url.absoluteString)" } } }) diff --git a/pass/PasswordTableViewController.swift b/pass/PasswordTableViewController.swift index 4863552..ce3a771 100644 --- a/pass/PasswordTableViewController.swift +++ b/pass/PasswordTableViewController.swift @@ -12,53 +12,12 @@ import Result import SVProgressHUD class PasswordTableViewController: UITableViewController { - private var passwordNameArray = [String]() private var passwordEntities: [PasswordEntity]? - - func temporaryURL(forPurpose purpose: String) -> URL { - let globallyUniqueString = ProcessInfo.processInfo.globallyUniqueString - let path = "\(NSTemporaryDirectory())\(globallyUniqueString)_\(purpose)" - print("\(NSHomeDirectory())/vault") - return URL(fileURLWithPath: path) - } - + override func viewDidLoad() { super.viewDidLoad() passwordEntities = PasswordStore.shared.fetchPasswordEntityCoreData() NotificationCenter.default.addObserver(self, selector: #selector(PasswordTableViewController.actOnPasswordUpdatedNotification), name: NSNotification.Name(rawValue: "passwordUpdated"), object: nil) - -// SVProgressHUD.setDefaultMaskType(SVProgressHUDMaskType.black) -// SVProgressHUD.show(withStatus: "Cloning Password Repository") -// -// let remoteRepoURL = URL(string: "https://github.com/mssun/public-password-store.git") -// let localURL = self.temporaryURL(forPurpose: "public-remote-clone") -// DispatchQueue.global(qos: .userInitiated).async { -// let cloneResult = Repository.clone(from: remoteRepoURL!, to: localURL) -// if case .success(let clonedRepo) = cloneResult { -// let latestCommit: Result = clonedRepo -// .HEAD() -// .flatMap { clonedRepo.commit($0.oid) } -// print("localURL \(localURL.path)") -// if let commit = latestCommit.value { -// print("Latest Commit: \(commit.message) by \(commit.author.name)") -// } else { -// print("Could not get commit: \(latestCommit.error)") -// } -// let fd = FileManager.default -// fd.enumerator(atPath: localURL.path)?.forEach({ (e) in -// if let e = e as? String, let url = URL(string: e) { -// if url.pathExtension == "gpg" { -// self.passwordNameArray.append(url.lastPathComponent); -// } -// } -// }) -// } -// DispatchQueue.main.async { -// SVProgressHUD.dismiss() -// self.tableView.reloadData() -// } -// -// } } func actOnPasswordUpdatedNotification() { @@ -71,11 +30,19 @@ class PasswordTableViewController: UITableViewController { return passwordEntities!.count } - override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "passwordTableViewCell", for: indexPath) cell.textLabel?.text = passwordEntities![indexPath.row].name return cell } + override func prepare(for segue: UIStoryboardSegue, sender: Any?) { + if segue.identifier == "showPasswordDetail" { + if let viewController = segue.destination as? PasswordDetailViewController { + let selectedRow = tableView.indexPathForSelectedRow!.row + viewController.passwordEntity = passwordEntities![selectedRow] + } + } + } + } diff --git a/pass/SettingsTableViewController.swift b/pass/SettingsTableViewController.swift index e885b97..c462d66 100644 --- a/pass/SettingsTableViewController.swift +++ b/pass/SettingsTableViewController.swift @@ -9,49 +9,67 @@ import UIKit import SVProgressHUD import CoreData +import SwiftyUserDefaults class SettingsTableViewController: UITableViewController { - - @IBOutlet weak var gitRepositoryTableViewCell: UITableViewCell! + + @IBOutlet weak var pgpKeyTableViewCell: UITableViewCell! @IBAction func cancel(segue: UIStoryboardSegue) { } @IBAction func save(segue: UIStoryboardSegue) { - if let changeGitRepositoryTableViewController = segue.source as? ChangeGitRepositoryTableViewController { - if let gitRepositoryURL = changeGitRepositoryTableViewController.gitRepositoryURL { - if gitRepositoryTableViewCell.detailTextLabel?.text != gitRepositoryURL { - UserDefaults.standard.set(gitRepositoryURL, forKey: "gitRepositoryURL") - gitRepositoryTableViewCell.detailTextLabel?.text = gitRepositoryURL - } + if let controller = segue.source as? GitServerSettingTableViewController { + if Defaults[.gitRepositoryURL] == nil || controller.gitRepositoryURLTextField.text != Defaults[.gitRepositoryURL]!.absoluteString { + Defaults[.gitRepositoryURL] = URL(string: controller.gitRepositoryURLTextField.text!) + + SVProgressHUD.setDefaultMaskType(.black) SVProgressHUD.show(withStatus: "Cloning Remote Repository") + DispatchQueue.global(qos: .userInitiated).async { - let ret = PasswordStore.shared.cloneRemoteRepo(remoteRepoURL: URL(string: gitRepositoryURL)!) - if ret { - DispatchQueue.main.async { - SVProgressHUD.dismiss() - SVProgressHUD.setMaximumDismissTimeInterval(1) - SVProgressHUD.showSuccess(withStatus: "Success") - NotificationCenter.default.post(Notification(name: Notification.Name("passwordUpdated"))) - } - } else { - DispatchQueue.main.async { - SVProgressHUD.showError(withStatus: "Error") + let ret = PasswordStore.shared.cloneRemoteRepo(remoteRepoURL: Defaults[.gitRepositoryURL]!) + + DispatchQueue.main.async { + if ret { + SVProgressHUD.dismiss() + SVProgressHUD.setMaximumDismissTimeInterval(1) + SVProgressHUD.showSuccess(withStatus: "Success") + NotificationCenter.default.post(Notification(name: Notification.Name("passwordUpdated"))) + } else { + SVProgressHUD.showError(withStatus: "Error") } } } - } + } else if let controller = segue.source as? PGPKeySettingTableViewController { + if Defaults[.pgpKeyURL] != URL(string: controller.pgpKeyURLTextField.text!) { + Defaults[.pgpKeyURL] = URL(string: controller.pgpKeyURLTextField.text!) + Defaults[.pgpKeyPassphrase] = controller.pgpKeyPassphraseTextField.text! + + SVProgressHUD.setDefaultMaskType(.black) + SVProgressHUD.show(withStatus: "Fetching PGP Key") + DispatchQueue.global(qos: .userInitiated).async { + let ret = PasswordStore.shared.initPGP(pgpKeyURL: Defaults[.pgpKeyURL]!, pgpKeyLocalPath: Globals.shared.secringPath) + + DispatchQueue.main.async { + if ret { + SVProgressHUD.showSuccess(withStatus: "Success") + } else { + SVProgressHUD.showError(withStatus: "Error") + } + } + } + } + } - } override func viewDidLoad() { super.viewDidLoad() - if let url = UserDefaults.standard.string(forKey: "gitRepositoryURL") { - gitRepositoryTableViewCell.detailTextLabel?.text = url + if Defaults[.pgpKeyID] == "" { + pgpKeyTableViewCell.detailTextLabel?.text = "Not Set" } else { - gitRepositoryTableViewCell.detailTextLabel?.text = "Not set" + pgpKeyTableViewCell.detailTextLabel?.text = Defaults[.pgpKeyID] } } }