Changed PGP backend from ObjectivePGP to GopenPGP

This commit is contained in:
Moritz Kuntze 2019-06-05 21:33:24 +02:00 committed by Mingshen Sun
parent 5439ad0f5b
commit 96f7c1960d
27 changed files with 647 additions and 193 deletions

View file

@ -2,7 +2,6 @@ platform :ios, '10.2'
use_frameworks! use_frameworks!
target 'passKit' do target 'passKit' do
pod 'ObjectivePGP', :git => 'https://github.com/krzyzanowskim/ObjectivePGP.git', :tag => '0.14.0'
target 'pass' do target 'pass' do
inherit! :search_paths inherit! :search_paths
end end

Binary file not shown.

View file

@ -0,0 +1,13 @@
// Objective-C API for talking to the following Go packages
//
// github.com/ZortacDev/GopenPGPWrapper/go/gopenpgpwrapper
//
// File is generated by gomobile bind. Do not edit.
#ifndef __Gopenpgpwrapper_FRAMEWORK_H__
#define __Gopenpgpwrapper_FRAMEWORK_H__
#include "Gopenpgpwrapper.objc.h"
#include "Universe.objc.h"
#endif

View file

@ -0,0 +1,29 @@
// Objective-C API for talking to github.com/ZortacDev/GopenPGPWrapper/go/gopenpgpwrapper Go package.
// gobind -lang=objc github.com/ZortacDev/GopenPGPWrapper/go/gopenpgpwrapper
//
// File is generated by gobind. Do not edit.
#ifndef __Gopenpgpwrapper_H__
#define __Gopenpgpwrapper_H__
@import Foundation;
#include "ref.h"
#include "Universe.objc.h"
@class GopenpgpwrapperKey;
@interface GopenpgpwrapperKey : NSObject <goSeqRefInterface> {
}
@property(strong, readonly) _Nonnull id _ref;
- (nonnull instancetype)initWithRef:(_Nonnull id)ref;
- (nonnull instancetype)init;
- (NSData* _Nullable)decrypt:(NSData* _Nullable)ciphertext passphrase:(NSString* _Nullable)passphrase;
- (NSData* _Nullable)encrypt:(NSData* _Nullable)plaintext armor:(BOOL)armor;
- (NSString* _Nonnull)getKeyID;
@end
FOUNDATION_EXPORT GopenpgpwrapperKey* _Nullable GopenpgpwrapperReadKey(NSData* _Nullable data);
#endif

View file

@ -0,0 +1,29 @@
// Objective-C API for talking to Go package.
// gobind -lang=objc
//
// File is generated by gobind. Do not edit.
#ifndef __Universe_H__
#define __Universe_H__
@import Foundation;
#include "ref.h"
@protocol Universeerror;
@class Universeerror;
@protocol Universeerror <NSObject>
- (NSString* _Nonnull)error;
@end
@class Universeerror;
@interface Universeerror : NSError <goSeqRefInterface, Universeerror> {
}
@property(strong, readonly) _Nonnull id _ref;
- (nonnull instancetype)initWithRef:(_Nonnull id)ref;
- (NSString* _Nonnull)error;
@end
#endif

View file

@ -0,0 +1,35 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
#ifndef __GO_REF_HDR__
#define __GO_REF_HDR__
#include <Foundation/Foundation.h>
// GoSeqRef is an object tagged with an integer for passing back and
// forth across the language boundary. A GoSeqRef may represent either
// an instance of a Go object, or an Objective-C object passed to Go.
// The explicit allocation of a GoSeqRef is used to pin a Go object
// when it is passed to Objective-C. The Go seq package maintains a
// reference to the Go object in a map keyed by the refnum along with
// a reference count. When the reference count reaches zero, the Go
// seq package will clear the corresponding entry in the map.
@interface GoSeqRef : NSObject {
}
@property(readonly) int32_t refnum;
@property(strong) id obj; // NULL when representing a Go object.
// new GoSeqRef object to proxy a Go object. The refnum must be
// provided from Go side.
- (instancetype)initWithRefnum:(int32_t)refnum obj:(id)obj;
- (int32_t)incNum;
@end
@protocol goSeqRefInterface
-(GoSeqRef*) _ref;
@end
#endif

View file

@ -0,0 +1,8 @@
framework module "Gopenpgpwrapper" {
header "ref.h"
header "Gopenpgpwrapper.objc.h"
header "Universe.objc.h"
header "Gopenpgpwrapper.h"
export *
}

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
</dict>
</plist>

Binary file not shown.

View file

@ -0,0 +1,13 @@
// Objective-C API for talking to the following Go packages
//
// github.com/ZortacDev/GopenPGPWrapper/go/gopenpgpwrapper
//
// File is generated by gomobile bind. Do not edit.
#ifndef __Gopenpgpwrapper_FRAMEWORK_H__
#define __Gopenpgpwrapper_FRAMEWORK_H__
#include "Gopenpgpwrapper.objc.h"
#include "Universe.objc.h"
#endif

View file

@ -0,0 +1,29 @@
// Objective-C API for talking to github.com/ZortacDev/GopenPGPWrapper/go/gopenpgpwrapper Go package.
// gobind -lang=objc github.com/ZortacDev/GopenPGPWrapper/go/gopenpgpwrapper
//
// File is generated by gobind. Do not edit.
#ifndef __Gopenpgpwrapper_H__
#define __Gopenpgpwrapper_H__
@import Foundation;
#include "ref.h"
#include "Universe.objc.h"
@class GopenpgpwrapperKey;
@interface GopenpgpwrapperKey : NSObject <goSeqRefInterface> {
}
@property(strong, readonly) _Nonnull id _ref;
- (nonnull instancetype)initWithRef:(_Nonnull id)ref;
- (nonnull instancetype)init;
- (NSData* _Nullable)decrypt:(NSData* _Nullable)ciphertext passphrase:(NSString* _Nullable)passphrase;
- (NSData* _Nullable)encrypt:(NSData* _Nullable)plaintext armor:(BOOL)armor;
- (NSString* _Nonnull)getKeyID;
@end
FOUNDATION_EXPORT GopenpgpwrapperKey* _Nullable GopenpgpwrapperReadKey(NSData* _Nullable data);
#endif

View file

@ -0,0 +1,29 @@
// Objective-C API for talking to Go package.
// gobind -lang=objc
//
// File is generated by gobind. Do not edit.
#ifndef __Universe_H__
#define __Universe_H__
@import Foundation;
#include "ref.h"
@protocol Universeerror;
@class Universeerror;
@protocol Universeerror <NSObject>
- (NSString* _Nonnull)error;
@end
@class Universeerror;
@interface Universeerror : NSError <goSeqRefInterface, Universeerror> {
}
@property(strong, readonly) _Nonnull id _ref;
- (nonnull instancetype)initWithRef:(_Nonnull id)ref;
- (NSString* _Nonnull)error;
@end
#endif

View file

@ -0,0 +1,35 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
#ifndef __GO_REF_HDR__
#define __GO_REF_HDR__
#include <Foundation/Foundation.h>
// GoSeqRef is an object tagged with an integer for passing back and
// forth across the language boundary. A GoSeqRef may represent either
// an instance of a Go object, or an Objective-C object passed to Go.
// The explicit allocation of a GoSeqRef is used to pin a Go object
// when it is passed to Objective-C. The Go seq package maintains a
// reference to the Go object in a map keyed by the refnum along with
// a reference count. When the reference count reaches zero, the Go
// seq package will clear the corresponding entry in the map.
@interface GoSeqRef : NSObject {
}
@property(readonly) int32_t refnum;
@property(strong) id obj; // NULL when representing a Go object.
// new GoSeqRef object to proxy a Go object. The refnum must be
// provided from Go side.
- (instancetype)initWithRefnum:(int32_t)refnum obj:(id)obj;
- (int32_t)incNum;
@end
@protocol goSeqRefInterface
-(GoSeqRef*) _ref;
@end
#endif

View file

@ -0,0 +1,8 @@
framework module "Gopenpgpwrapper" {
header "ref.h"
header "Gopenpgpwrapper.objc.h"
header "Universe.objc.h"
header "Gopenpgpwrapper.h"
export *
}

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
</dict>
</plist>

Binary file not shown.

View file

@ -0,0 +1,13 @@
// Objective-C API for talking to the following Go packages
//
// github.com/ZortacDev/GopenPGPWrapper/go/gopenpgpwrapper
//
// File is generated by gomobile bind. Do not edit.
#ifndef __Gopenpgpwrapper_FRAMEWORK_H__
#define __Gopenpgpwrapper_FRAMEWORK_H__
#include "Gopenpgpwrapper.objc.h"
#include "Universe.objc.h"
#endif

View file

@ -0,0 +1,29 @@
// Objective-C API for talking to github.com/ZortacDev/GopenPGPWrapper/go/gopenpgpwrapper Go package.
// gobind -lang=objc github.com/ZortacDev/GopenPGPWrapper/go/gopenpgpwrapper
//
// File is generated by gobind. Do not edit.
#ifndef __Gopenpgpwrapper_H__
#define __Gopenpgpwrapper_H__
@import Foundation;
#include "ref.h"
#include "Universe.objc.h"
@class GopenpgpwrapperKey;
@interface GopenpgpwrapperKey : NSObject <goSeqRefInterface> {
}
@property(strong, readonly) _Nonnull id _ref;
- (nonnull instancetype)initWithRef:(_Nonnull id)ref;
- (nonnull instancetype)init;
- (NSData* _Nullable)decrypt:(NSData* _Nullable)ciphertext passphrase:(NSString* _Nullable)passphrase;
- (NSData* _Nullable)encrypt:(NSData* _Nullable)plaintext armor:(BOOL)armor;
- (NSString* _Nonnull)getKeyID;
@end
FOUNDATION_EXPORT GopenpgpwrapperKey* _Nullable GopenpgpwrapperReadKey(NSData* _Nullable data);
#endif

View file

@ -0,0 +1,29 @@
// Objective-C API for talking to Go package.
// gobind -lang=objc
//
// File is generated by gobind. Do not edit.
#ifndef __Universe_H__
#define __Universe_H__
@import Foundation;
#include "ref.h"
@protocol Universeerror;
@class Universeerror;
@protocol Universeerror <NSObject>
- (NSString* _Nonnull)error;
@end
@class Universeerror;
@interface Universeerror : NSError <goSeqRefInterface, Universeerror> {
}
@property(strong, readonly) _Nonnull id _ref;
- (nonnull instancetype)initWithRef:(_Nonnull id)ref;
- (NSString* _Nonnull)error;
@end
#endif

View file

@ -0,0 +1,35 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
#ifndef __GO_REF_HDR__
#define __GO_REF_HDR__
#include <Foundation/Foundation.h>
// GoSeqRef is an object tagged with an integer for passing back and
// forth across the language boundary. A GoSeqRef may represent either
// an instance of a Go object, or an Objective-C object passed to Go.
// The explicit allocation of a GoSeqRef is used to pin a Go object
// when it is passed to Objective-C. The Go seq package maintains a
// reference to the Go object in a map keyed by the refnum along with
// a reference count. When the reference count reaches zero, the Go
// seq package will clear the corresponding entry in the map.
@interface GoSeqRef : NSObject {
}
@property(readonly) int32_t refnum;
@property(strong) id obj; // NULL when representing a Go object.
// new GoSeqRef object to proxy a Go object. The refnum must be
// provided from Go side.
- (instancetype)initWithRefnum:(int32_t)refnum obj:(id)obj;
- (int32_t)incNum;
@end
@protocol goSeqRefInterface
-(GoSeqRef*) _ref;
@end
#endif

View file

@ -0,0 +1,8 @@
framework module "Gopenpgpwrapper" {
header "ref.h"
header "Gopenpgpwrapper.objc.h"
header "Universe.objc.h"
header "Gopenpgpwrapper.h"
export *
}

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
</dict>
</plist>

84
go/src/gopenpgpwrapper.go Normal file
View file

@ -0,0 +1,84 @@
package gopenpgpwrapper // import "gopenpgpwrapper"
import (
"bytes"
"io"
"io/ioutil"
"github.com/ProtonMail/gopenpgp/crypto"
"github.com/ProtonMail/gopenpgp/armor"
)
type Key struct {
kr crypto.KeyRing
}
func (k *Key) GetKeyID() string {
return k.kr.FirstKeyID
}
func (k *Key) Encrypt(plaintext []byte, armor bool) []byte {
var b bytes.Buffer
var w io.WriteCloser
if armor {
wr, err := k.kr.EncryptArmored(&b, nil)
if err != nil {
return nil
}
w = wr
} else {
wr, err := k.kr.Encrypt(&b, nil, "", false)
if err != nil {
return nil
}
w = wr
}
if _, err := w.Write(plaintext); err != nil {
return nil
}
if err := w.Close(); err != nil {
return nil
}
return b.Bytes()
}
func (k Key) Decrypt(ciphertext []byte, passphrase string) []byte {
unarmored, err := armor.Unarmor(string(ciphertext))
if err != nil {
// Assume ciphertext is already in binary format
unarmored = ciphertext
}
err = k.kr.Unlock([]byte(passphrase))
if err != nil {
return nil
}
r, _, err := k.kr.Decrypt(bytes.NewReader(unarmored))
if err != nil {
return nil
}
if b, err := ioutil.ReadAll(r); err != nil {
return nil
} else {
return b
}
}
func ReadKey(data []byte) *Key {
kr, err := crypto.ReadArmoredKeyRing(bytes.NewReader(data))
if err != nil {
// Assume keyring is in binary form
kr, err = crypto.ReadKeyRing(bytes.NewReader(data))
if err != nil {
return nil
}
}
return &Key{kr: *kr}
}

View file

@ -7,6 +7,7 @@
objects = { objects = {
/* Begin PBXBuildFile section */ /* Begin PBXBuildFile section */
1154BEDD229AC00F00454075 /* Gopenpgpwrapper.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1154BEDB229AC00F00454075 /* Gopenpgpwrapper.framework */; };
18F19A67B0C07F13C17169E0 /* Pods_pass.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3A5620D17DF5E86B61761D0E /* Pods_pass.framework */; }; 18F19A67B0C07F13C17169E0 /* Pods_pass.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3A5620D17DF5E86B61761D0E /* Pods_pass.framework */; };
23B82F0228254275DBA609E7 /* Pods_passExtension.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B975797E0F0B7476CADD6A7D /* Pods_passExtension.framework */; }; 23B82F0228254275DBA609E7 /* Pods_passExtension.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B975797E0F0B7476CADD6A7D /* Pods_passExtension.framework */; };
300713C52219D54100F553AC /* AutoCellHeightUITableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 300713C42219D54100F553AC /* AutoCellHeightUITableViewController.swift */; }; 300713C52219D54100F553AC /* AutoCellHeightUITableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 300713C42219D54100F553AC /* AutoCellHeightUITableViewController.swift */; };
@ -207,6 +208,7 @@
/* End PBXCopyFilesBuildPhase section */ /* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */ /* Begin PBXFileReference section */
1154BEDB229AC00F00454075 /* Gopenpgpwrapper.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Gopenpgpwrapper.framework; path = go/dist/Gopenpgpwrapper.framework; sourceTree = "<group>"; };
300713C42219D54100F553AC /* AutoCellHeightUITableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AutoCellHeightUITableViewController.swift; sourceTree = "<group>"; }; 300713C42219D54100F553AC /* AutoCellHeightUITableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AutoCellHeightUITableViewController.swift; sourceTree = "<group>"; };
301F6462216162550071A4CE /* AdditionField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdditionField.swift; sourceTree = "<group>"; }; 301F6462216162550071A4CE /* AdditionField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdditionField.swift; sourceTree = "<group>"; };
301F6467216165290071A4CE /* ConstantsTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConstantsTest.swift; sourceTree = "<group>"; }; 301F6467216165290071A4CE /* ConstantsTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConstantsTest.swift; sourceTree = "<group>"; };
@ -373,6 +375,7 @@
isa = PBXFrameworksBuildPhase; isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
1154BEDD229AC00F00454075 /* Gopenpgpwrapper.framework in Frameworks */,
61326CDA7A73757FB68DCB04 /* Pods_passKit.framework in Frameworks */, 61326CDA7A73757FB68DCB04 /* Pods_passKit.framework in Frameworks */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
@ -413,6 +416,7 @@
files = ( files = (
A239F5902158C07D00576CBF /* AuthenticationServices.framework in Frameworks */, A239F5902158C07D00576CBF /* AuthenticationServices.framework in Frameworks */,
A260758D1EEC6F34005DB03E /* passKit.framework in Frameworks */, A260758D1EEC6F34005DB03E /* passKit.framework in Frameworks */,
1154BEDC229AC00F00454075 /* Gopenpgpwrapper.framework in Frameworks */,
DCC408C71E307DBB00F29B0E /* SVProgressHUD.framework in Frameworks */, DCC408C71E307DBB00F29B0E /* SVProgressHUD.framework in Frameworks */,
18F19A67B0C07F13C17169E0 /* Pods_pass.framework in Frameworks */, 18F19A67B0C07F13C17169E0 /* Pods_pass.framework in Frameworks */,
); );
@ -768,6 +772,7 @@
B975797E0F0B7476CADD6A7D /* Pods_passExtension.framework */, B975797E0F0B7476CADD6A7D /* Pods_passExtension.framework */,
DAB3F5541E51ADC8C6B56642 /* Pods_passKit.framework */, DAB3F5541E51ADC8C6B56642 /* Pods_passKit.framework */,
CF843B3CF7D55A4070CBA1E4 /* Pods_passKitTests.framework */, CF843B3CF7D55A4070CBA1E4 /* Pods_passKitTests.framework */,
1154BEDB229AC00F00454075 /* Gopenpgpwrapper.framework */,
); );
name = Frameworks; name = Frameworks;
sourceTree = "<group>"; sourceTree = "<group>";
@ -830,7 +835,6 @@
A260757C1EEC6F34005DB03E /* Sources */, A260757C1EEC6F34005DB03E /* Sources */,
A260757D1EEC6F34005DB03E /* Frameworks */, A260757D1EEC6F34005DB03E /* Frameworks */,
A260757E1EEC6F34005DB03E /* Resources */, A260757E1EEC6F34005DB03E /* Resources */,
6AEAED0AF4328940B21EAC44 /* [CP] Embed Pods Frameworks */,
); );
buildRules = ( buildRules = (
); );
@ -890,7 +894,6 @@
DC917BEC1E2F3659000FDF54 /* Run Script */, DC917BEC1E2F3659000FDF54 /* Run Script */,
A26700191EEC450100176B8A /* Embed App Extensions */, A26700191EEC450100176B8A /* Embed App Extensions */,
A26075921EEC6F34005DB03E /* Embed Frameworks */, A26075921EEC6F34005DB03E /* Embed Frameworks */,
7F5ED3FD24ED627DC957D425 /* [CP] Embed Pods Frameworks */,
); );
buildRules = ( buildRules = (
); );
@ -1093,26 +1096,6 @@
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/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# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/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# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
showEnvVarsInLog = 0; showEnvVarsInLog = 0;
}; };
6AEAED0AF4328940B21EAC44 /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
"${SRCROOT}/Pods/Target Support Files/Pods-passKitTests/Pods-passKitTests-frameworks.sh",
"${PODS_ROOT}/ObjectivePGP/Frameworks/ios/ObjectivePGP.framework",
"${PODS_ROOT}/ObjectivePGP/Frameworks/ios/ObjectivePGP.framework.dSYM",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/ObjectivePGP.framework",
"${DWARF_DSYM_FOLDER_PATH}/ObjectivePGP.framework.dSYM",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-passKitTests/Pods-passKitTests-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
736C6F64F90A20CB9A00B420 /* [CP] Check Pods Manifest.lock */ = { 736C6F64F90A20CB9A00B420 /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase; isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
@ -1131,26 +1114,6 @@
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/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# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/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# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
showEnvVarsInLog = 0; showEnvVarsInLog = 0;
}; };
7F5ED3FD24ED627DC957D425 /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
"${SRCROOT}/Pods/Target Support Files/Pods-pass/Pods-pass-frameworks.sh",
"${PODS_ROOT}/ObjectivePGP/Frameworks/ios/ObjectivePGP.framework",
"${PODS_ROOT}/ObjectivePGP/Frameworks/ios/ObjectivePGP.framework.dSYM",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/ObjectivePGP.framework",
"${DWARF_DSYM_FOLDER_PATH}/ObjectivePGP.framework.dSYM",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-pass/Pods-pass-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
94AA4FCF7FF3474A970BE194 /* [CP] Check Pods Manifest.lock */ = { 94AA4FCF7FF3474A970BE194 /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase; isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
@ -1502,7 +1465,10 @@
DYLIB_CURRENT_VERSION = 1; DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath"; DYLIB_INSTALL_NAME_BASE = "@rpath";
ENABLE_BITCODE = NO; ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = "$(inherited)"; FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/go/dist",
);
HEADER_SEARCH_PATHS = "$(inherited)"; HEADER_SEARCH_PATHS = "$(inherited)";
INFOPLIST_FILE = passKit/Info.plist; INFOPLIST_FILE = passKit/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
@ -1541,7 +1507,10 @@
DYLIB_CURRENT_VERSION = 1; DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath"; DYLIB_INSTALL_NAME_BASE = "@rpath";
ENABLE_BITCODE = NO; ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = "$(inherited)"; FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/go/dist",
);
HEADER_SEARCH_PATHS = "$(inherited)"; HEADER_SEARCH_PATHS = "$(inherited)";
INFOPLIST_FILE = passKit/Info.plist; INFOPLIST_FILE = passKit/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
@ -1830,7 +1799,10 @@
DEFINES_MODULE = NO; DEFINES_MODULE = NO;
DEVELOPMENT_TEAM = 4WDM8E95VU; DEVELOPMENT_TEAM = 4WDM8E95VU;
ENABLE_BITCODE = NO; ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = "$(inherited)"; FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/go/dist",
);
HEADER_SEARCH_PATHS = "$(inherited)"; HEADER_SEARCH_PATHS = "$(inherited)";
INFOPLIST_FILE = pass/Info.plist; INFOPLIST_FILE = pass/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
@ -1862,7 +1834,10 @@
DEFINES_MODULE = NO; DEFINES_MODULE = NO;
DEVELOPMENT_TEAM = 4WDM8E95VU; DEVELOPMENT_TEAM = 4WDM8E95VU;
ENABLE_BITCODE = NO; ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = "$(inherited)"; FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/go/dist",
);
HEADER_SEARCH_PATHS = "$(inherited)"; HEADER_SEARCH_PATHS = "$(inherited)";
INFOPLIST_FILE = pass/Info.plist; INFOPLIST_FILE = pass/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";

View file

@ -38,8 +38,8 @@ class SettingsTableViewController: UITableViewController, UITabBarControllerDele
SVProgressHUD.show(withStatus: "FetchingPgpKey".localize()) SVProgressHUD.show(withStatus: "FetchingPgpKey".localize())
DispatchQueue.global(qos: .userInitiated).async { [unowned self] in DispatchQueue.global(qos: .userInitiated).async { [unowned self] in
do { do {
try self.passwordStore.initPGPKey(from: SharedDefaults[.pgpPublicKeyURL]!, keyType: .public) try self.passwordStore.initPGPKey(from: SharedDefaults[.pgpPublicKeyURL]!, keyType: .PUBLIC)
try self.passwordStore.initPGPKey(from: SharedDefaults[.pgpPrivateKeyURL]!, keyType: .secret) try self.passwordStore.initPGPKey(from: SharedDefaults[.pgpPrivateKeyURL]!, keyType: .PRIVATE)
DispatchQueue.main.async { DispatchQueue.main.async {
self.pgpKeyTableViewCell.detailTextLabel?.text = self.passwordStore.pgpKeyID self.pgpKeyTableViewCell.detailTextLabel?.text = self.passwordStore.pgpKeyID
SVProgressHUD.showSuccess(withStatus: "Success".localize()) SVProgressHUD.showSuccess(withStatus: "Success".localize())
@ -68,8 +68,8 @@ class SettingsTableViewController: UITableViewController, UITabBarControllerDele
SVProgressHUD.show(withStatus: "FetchingPgpKey".localize()) SVProgressHUD.show(withStatus: "FetchingPgpKey".localize())
DispatchQueue.global(qos: .userInitiated).async { [unowned self] in DispatchQueue.global(qos: .userInitiated).async { [unowned self] in
do { do {
try self.passwordStore.initPGPKey(with: SharedDefaults[.pgpPublicKeyArmor] ?? "", keyType: .public) try self.passwordStore.initPGPKey(with: SharedDefaults[.pgpPublicKeyArmor] ?? "", keyType: .PUBLIC)
try self.passwordStore.initPGPKey(with: SharedDefaults[.pgpPrivateKeyArmor] ?? "", keyType: .secret) try self.passwordStore.initPGPKey(with: SharedDefaults[.pgpPrivateKeyArmor] ?? "", keyType: .PRIVATE)
DispatchQueue.main.async { DispatchQueue.main.async {
self.pgpKeyTableViewCell.detailTextLabel?.text = self.passwordStore.pgpKeyID self.pgpKeyTableViewCell.detailTextLabel?.text = self.passwordStore.pgpKeyID
SVProgressHUD.showSuccess(withStatus: "Success".localize()) SVProgressHUD.showSuccess(withStatus: "Success".localize())

View file

@ -9,7 +9,6 @@
#ifndef Objective_CBridgingHeader_h #ifndef Objective_CBridgingHeader_h
#define Objective_CBridgingHeader_h #define Objective_CBridgingHeader_h
#import "ObjectivePGP/ObjectivePGP.h"
#import "ObjectiveGit/ObjectiveGit.h" #import "ObjectiveGit/ObjectiveGit.h"
#endif /* Objective_CBridgingHeader_h */ #endif /* Objective_CBridgingHeader_h */

View file

@ -11,8 +11,8 @@ import CoreData
import UIKit import UIKit
import SwiftyUserDefaults import SwiftyUserDefaults
import ObjectiveGit import ObjectiveGit
import ObjectivePGP
import KeychainAccess import KeychainAccess
import Gopenpgpwrapper
public class PasswordStore { public class PasswordStore {
public static let shared = PasswordStore() public static let shared = PasswordStore()
@ -28,12 +28,19 @@ public class PasswordStore {
public var storeRepository: GTRepository? public var storeRepository: GTRepository?
public var pgpKeyID: String? public var pgpKeyID: String?
public var publicKey: Key? { public var publicKey: GopenpgpwrapperKey? {
didSet { didSet {
pgpKeyID = publicKey?.keyID.shortIdentifier if publicKey != nil {
pgpKeyID = publicKey!.getID()
} else {
pgpKeyID = nil
} }
} }
public var privateKey: Key? }
public var privateKey: GopenpgpwrapperKey?
public enum PGPKeyType {
case PUBLIC, PRIVATE
}
public var gitSignatureForNow: GTSignature { public var gitSignatureForNow: GTSignature {
get { get {
@ -43,8 +50,6 @@ public class PasswordStore {
} }
} }
public let keyring = ObjectivePGP.defaultKeyring
public var pgpKeyPassphrase: String? { public var pgpKeyPassphrase: String? {
set { set {
Utils.addPasswordToKeychain(name: "pgpKeyPassphrase", password: newValue) Utils.addPasswordToKeychain(name: "pgpKeyPassphrase", password: newValue)
@ -109,7 +114,7 @@ public class PasswordStore {
} }
public var numberOfLocalCommits: Int? { public var numberOfLocalCommits: Int? {
return (try? getLocalCommits())?.count return (try? getLocalCommits())?.flatMap { $0.count }
} }
public var lastSyncedTime: Date? { public var lastSyncedTime: Date? {
@ -121,6 +126,10 @@ public class PasswordStore {
} }
private init() { private init() {
// File migration to group
migrateIfNeeded()
backwardCompatibility()
do { do {
if fm.fileExists(atPath: storeURL.path) { if fm.fileExists(atPath: storeURL.path) {
try storeRepository = GTRepository.init(url: storeURL) try storeRepository = GTRepository.init(url: storeURL)
@ -131,6 +140,52 @@ public class PasswordStore {
} }
} }
private func migrateIfNeeded() {
// migrate happens only if the repository was cloned and pgp keys were set up using earlier versions
let needMigration = !pgpKeyExists() && !gitSSHKeyExists() && !fm.fileExists(atPath: Globals.repositoryPath) && fm.fileExists(atPath: Globals.repositoryPathLegacy)
guard needMigration == true else {
return
}
do {
// migrate Defaults
let userDefaults = UserDefaults()
for key in Defaults.dictionaryRepresentation().keys {
if SharedDefaults.value(forKey: key) == nil {
SharedDefaults.setValue(userDefaults.value(forKey: key), forKey: key)
}
}
// migrate files
try fm.createDirectory(atPath: Globals.documentPath, withIntermediateDirectories: true, attributes: nil)
try fm.createDirectory(atPath: Globals.libraryPath, withIntermediateDirectories: true, attributes: nil)
if fm.fileExists(atPath: Globals.pgpPublicKeyPathLegacy) {
try fm.moveItem(atPath: Globals.pgpPublicKeyPathLegacy, toPath: Globals.pgpPublicKeyPath)
}
if fm.fileExists(atPath: Globals.pgpPrivateKeyPathLegacy) {
try fm.moveItem(atPath: Globals.pgpPrivateKeyPathLegacy, toPath: Globals.pgpPrivateKeyPath)
}
if fm.fileExists(atPath: Globals.gitSSHPrivateKeyPathLegacy) {
try fm.moveItem(atPath: Globals.gitSSHPrivateKeyPathLegacy, toPath: Globals.gitSSHPrivateKeyPath)
}
try fm.moveItem(atPath: Globals.repositoryPathLegacy, toPath: Globals.repositoryPath)
} catch {
print("MigrationError".localize(error))
}
updatePasswordEntityCoreData()
}
private func backwardCompatibility() {
// For the newly-introduced isRememberGitCredentialPassphraseOn (20171008)
if (self.gitPassword != nil || self.gitSSHPrivateKeyPassphrase != nil) && SharedDefaults[.isRememberGitCredentialPassphraseOn] == false {
SharedDefaults[.isRememberGitCredentialPassphraseOn] = true
}
// For the renamed isRememberPGPPassphraseOn (20171008)
if self.pgpKeyPassphrase != nil && SharedDefaults[.isRememberPGPPassphraseOn] == false {
SharedDefaults[.isRememberPGPPassphraseOn] = true
}
}
enum SSHKeyType { enum SSHKeyType {
case `public`, secret case `public`, secret
} }
@ -141,19 +196,19 @@ public class PasswordStore {
} }
public func initPGPKeys() throws { public func initPGPKeys() throws {
try initPGPKey(.public) try initPGPKey(.PUBLIC)
try initPGPKey(.secret) try initPGPKey(.PRIVATE)
} }
public func initPGPKey(_ keyType: PGPKeyType) throws { public func initPGPKey(_ keyType: PGPKeyType) throws {
switch keyType { switch keyType {
case .public: case .PUBLIC:
let keyPath = Globals.pgpPublicKeyPath let keyPath = Globals.pgpPublicKeyPath
self.publicKey = importKey(from: keyPath) self.publicKey = importKey(from: keyPath)
if self.publicKey == nil { if self.publicKey == nil {
throw AppError.KeyImport throw AppError.KeyImport
} }
case .secret: case .PRIVATE:
let keyPath = Globals.pgpPrivateKeyPath let keyPath = Globals.pgpPrivateKeyPath
self.privateKey = importKey(from: keyPath) self.privateKey = importKey(from: keyPath)
if self.privateKey == nil { if self.privateKey == nil {
@ -166,7 +221,7 @@ public class PasswordStore {
public func initPGPKey(from url: URL, keyType: PGPKeyType) throws { public func initPGPKey(from url: URL, keyType: PGPKeyType) throws {
var pgpKeyLocalPath = "" var pgpKeyLocalPath = ""
if keyType == .public { if keyType == .PUBLIC {
pgpKeyLocalPath = Globals.pgpPublicKeyPath pgpKeyLocalPath = Globals.pgpPublicKeyPath
} else { } else {
pgpKeyLocalPath = Globals.pgpPrivateKeyPath pgpKeyLocalPath = Globals.pgpPrivateKeyPath
@ -178,7 +233,7 @@ public class PasswordStore {
public func initPGPKey(with armorKey: String, keyType: PGPKeyType) throws { public func initPGPKey(with armorKey: String, keyType: PGPKeyType) throws {
var pgpKeyLocalPath = "" var pgpKeyLocalPath = ""
if keyType == .public { if keyType == .PUBLIC {
pgpKeyLocalPath = Globals.pgpPublicKeyPath pgpKeyLocalPath = Globals.pgpPublicKeyPath
} else { } else {
pgpKeyLocalPath = Globals.pgpPrivateKeyPath pgpKeyLocalPath = Globals.pgpPrivateKeyPath
@ -188,20 +243,13 @@ public class PasswordStore {
} }
private func importKey(from keyPath: String) -> Key? { private func importKey(from keyPath: String) -> GopenpgpwrapperKey? {
if fm.fileExists(atPath: keyPath) { if fm.fileExists(atPath: keyPath) {
let keys = try! ObjectivePGP.readKeys(fromPath: keyPath) return GopenpgpwrapperReadKey(fm.contents(atPath: keyPath))
keyring.import(keys: keys)
if !keys.isEmpty {
return keys.first
}
} }
return nil return nil
} }
public func getPgpPrivateKey() -> Key {
return keyring.keys.filter({$0.secretKey != nil})[0]
}
public func repositoryExisted() -> Bool { public func repositoryExisted() -> Bool {
let fm = FileManager() let fm = FileManager()
@ -221,6 +269,7 @@ public class PasswordStore {
} catch { } catch {
fatalError("FailedToFetchPasswordEntities".localize(error)) fatalError("FailedToFetchPasswordEntities".localize(error))
} }
return true
} }
public func passwordEntityExisted(path: String) -> Bool { public func passwordEntityExisted(path: String) -> Bool {
@ -236,6 +285,7 @@ public class PasswordStore {
} catch { } catch {
fatalError("FailedToFetchPasswordEntities".localize(error)) fatalError("FailedToFetchPasswordEntities".localize(error))
} }
return true
} }
public func getPasswordEntity(by path: String, isDir: Bool) -> PasswordEntity? { public func getPasswordEntity(by path: String, isDir: Bool) -> PasswordEntity? {
@ -640,8 +690,6 @@ public class PasswordStore {
try deletePasswordEntities(passwordEntity: passwordEntity) try deletePasswordEntities(passwordEntity: passwordEntity)
let _ = try gitCommit(message: "RenamePassword.".localize(deletedFileURL.deletingPathExtension().path.removingPercentEncoding!, password.url.deletingPathExtension().path.removingPercentEncoding!)) let _ = try gitCommit(message: "RenamePassword.".localize(deletedFileURL.deletingPathExtension().path.removingPercentEncoding!, password.url.deletingPathExtension().path.removingPercentEncoding!))
} }
self.saveUpdated(passwordEntity: newPasswordEntity!)
NotificationCenter.default.post(name: .passwordStoreUpdated, object: nil) NotificationCenter.default.post(name: .passwordStoreUpdated, object: nil)
return newPasswordEntity return newPasswordEntity
} }
@ -779,8 +827,8 @@ public class PasswordStore {
if passphrase == nil { if passphrase == nil {
passphrase = requestPGPKeyPassphrase() passphrase = requestPGPKeyPassphrase()
} }
let decryptedData = try ObjectivePGP.decrypt(encryptedData, andVerifySignature: false, using: keyring.keys, passphraseForKey: {(_) in passphrase}) let decryptedData = privateKey?.decrypt(encryptedData, passphrase: passphrase)
let plainText = String(data: decryptedData, encoding: .utf8) ?? "" let plainText = String(data: decryptedData!, encoding: .utf8) ?? ""
guard let url = passwordEntity.getURL() else { guard let url = passwordEntity.getURL() else {
throw AppError.Decryption throw AppError.Decryption
} }
@ -788,16 +836,13 @@ public class PasswordStore {
} }
public func encrypt(password: Password) throws -> Data { public func encrypt(password: Password) throws -> Data {
guard keyring.keys.count > 0 else { guard publicKey != nil else {
throw AppError.PgpPublicKeyNotExist throw AppError.PgpPublicKeyNotExist
} }
let plainData = password.plainData let plainData = password.plainData
let encryptedData = try ObjectivePGP.encrypt(plainData, addSignature: false, using: keyring.keys, passphraseForKey: nil) let encryptedData = publicKey?.encrypt(plainData, armor: SharedDefaults[.encryptInArmored])
if SharedDefaults[.encryptInArmored] {
return Armor.armored(encryptedData, as: .message).data(using: .utf8)! return encryptedData!
} else {
return encryptedData
}
} }
public func removePGPKeys() { public func removePGPKeys() {
@ -809,7 +854,6 @@ public class PasswordStore {
SharedDefaults.remove(.pgpPrivateKeyURL) SharedDefaults.remove(.pgpPrivateKeyURL)
SharedDefaults.remove(.pgpPublicKeyURL) SharedDefaults.remove(.pgpPublicKeyURL)
Utils.removeKeychain(name: ".pgpKeyPassphrase") Utils.removeKeychain(name: ".pgpKeyPassphrase")
keyring.deleteAll()
publicKey = nil publicKey = nil
privateKey = nil privateKey = nil
} }
@ -838,17 +882,10 @@ public class PasswordStore {
} }
public func gitSSHKeyImportFromFileSharing() throws { public func gitSSHKeyImportFromFileSharing() throws {
if gitSSHKeyExists() {
try fm.removeItem(atPath: Globals.gitSSHPrivateKeyPath)
}
try fm.moveItem(atPath: Globals.iTunesFileSharingSSHPrivate, toPath: Globals.gitSSHPrivateKeyPath) try fm.moveItem(atPath: Globals.iTunesFileSharingSSHPrivate, toPath: Globals.gitSSHPrivateKeyPath)
} }
public func pgpKeyImportFromFileSharing() throws { public func pgpKeyImportFromFileSharing() throws {
if pgpKeyExists() {
try fm.removeItem(atPath: Globals.pgpPublicKeyPath)
try fm.removeItem(atPath: Globals.pgpPrivateKeyPath)
}
try fm.moveItem(atPath: Globals.iTunesFileSharingPGPPublic, toPath: Globals.pgpPublicKeyPath) try fm.moveItem(atPath: Globals.iTunesFileSharingPGPPublic, toPath: Globals.pgpPublicKeyPath)
try fm.moveItem(atPath: Globals.iTunesFileSharingPGPPrivate, toPath: Globals.pgpPrivateKeyPath) try fm.moveItem(atPath: Globals.iTunesFileSharingPGPPrivate, toPath: Globals.pgpPrivateKeyPath)
} }