Skip to content

Commit

Permalink
Fix activatedVPNID.
Browse files Browse the repository at this point in the history
  • Loading branch information
lexrus committed Jan 20, 2015
1 parent 1fa3ae0 commit 53801f3
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 16 deletions.
2 changes: 1 addition & 1 deletion VPNOnData/VPN.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class VPN : NSManagedObject{
@NSManaged var isp: String!

var ID : String {
if let id = objectID.URIRepresentation().lastPathComponent {
if let id = objectID.URIRepresentation().absoluteString {
return id
}
return ""
Expand Down
8 changes: 6 additions & 2 deletions VPNOnData/VPNDataManager+VPN.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,12 @@ extension VPNDataManager
func VPNByIDString(ID: String) -> VPN?
{
if let URL = NSURL(string: ID) {
if let moid = self.persistentStoreCoordinator!.managedObjectIDForURIRepresentation(URL) {
return self.VPNByID(moid)
if let scheme = URL.scheme {
if scheme.lowercaseString == "x-coredata" {
if let moid = self.persistentStoreCoordinator!.managedObjectIDForURIRepresentation(URL) {
return self.VPNByID(moid)
}
}
}
}
return .None
Expand Down
10 changes: 5 additions & 5 deletions VPNOnKit/VPNKeychainWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@

@interface VPNKeychainWrapper : NSObject

+ (BOOL) setPassword:(NSString*)password forVPNID:(NSString*)VPNID;
+ (BOOL) setPassword:(NSString *)password forVPNID:(NSString *)VPNID;

+ (BOOL) setSecret:(NSString*)secret forVPNID:(NSString*)VPNID;
+ (BOOL) setSecret:(NSString*)secret forVPNID:(NSString *)VPNID;

+ (NSData*) passwordForVPNID:(NSString*)VPNID;
+ (NSData *) passwordForVPNID:(NSString *)VPNID;

+ (NSData*) secretForVPNID:(NSString*)VPNID;
+ (NSData *) secretForVPNID:(NSString *)VPNID;

+ (void)destoryKeyForVPNID:(NSString*)VPNID;
+ (void) destoryKeyForVPNID:(NSString *)VPNID;

@end

Expand Down
21 changes: 13 additions & 8 deletions VPNOnKit/VPNKeychainWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,35 @@ let kKeychainServiceName = "com.LexTang.VPNOn"
class VPNKeychainWrapper
{
class func setPassword(password: String, forVPNID VPNID: String) -> Bool {
let key = NSURL(string: VPNID)!.lastPathComponent!
KeychainWrapper.serviceName = kKeychainServiceName
KeychainWrapper.removeObjectForKey(VPNID)
return KeychainWrapper.setString(password, forKey: VPNID)
KeychainWrapper.removeObjectForKey(key)
return KeychainWrapper.setString(password, forKey: key)
}

class func setSecret(secret: String, forVPNID VPNID: String) -> Bool {
let key = NSURL(string: VPNID)!.lastPathComponent!
KeychainWrapper.serviceName = kKeychainServiceName
KeychainWrapper.removeObjectForKey("\(VPNID)psk")
return KeychainWrapper.setString(secret, forKey: "\(VPNID)psk")
KeychainWrapper.removeObjectForKey("\(key)psk")
return KeychainWrapper.setString(secret, forKey: "\(key)psk")
}

class func passwordForVPNID(VPNID: String) -> NSData? {
let key = NSURL(string: VPNID)!.lastPathComponent!
KeychainWrapper.serviceName = kKeychainServiceName
return KeychainWrapper.dataForKey(VPNID)
return KeychainWrapper.dataForKey(key)
}

class func secretForVPNID(VPNID: String) -> NSData? {
let key = NSURL(string: VPNID)!.lastPathComponent!
KeychainWrapper.serviceName = kKeychainServiceName
return KeychainWrapper.dataForKey("\(VPNID)psk")
return KeychainWrapper.dataForKey("\(key)psk")
}

class func destoryKeyForVPNID(VPNID: String) {
let key = NSURL(string: VPNID)!.lastPathComponent!
KeychainWrapper.serviceName = kKeychainServiceName
KeychainWrapper.removeObjectForKey(VPNID)
KeychainWrapper.removeObjectForKey("\(VPNID)psk")
KeychainWrapper.removeObjectForKey(key)
KeychainWrapper.removeObjectForKey("\(key)psk")
}
}

0 comments on commit 53801f3

Please sign in to comment.