public override async Task StoreKeyValuePairs(KeyPair[] keypairs) { var keychain = GetKeychainContainer(DefaultKeychainName, true); var successfullKeyPairs = new List<KeyPair>(); var failedKeyPairs = new List<KeyPair>(); if (keychain != null) { foreach (var entry in keypairs) { try { if (keychain.Values.ContainsKey(entry.Key)) { keychain.Values.Remove(entry.Key); keychain.Values.Add(entry.Key, entry.Value); successfullKeyPairs.Add(entry); } else { keychain.Values.Add(entry.Key, entry.Value); successfullKeyPairs.Add(entry); } } catch (Exception) { failedKeyPairs.Add(entry); } } } var jsonResultString = JsonConvert.SerializeObject(new object[] { successfullKeyPairs, failedKeyPairs }); WindowsPhoneUtils.Log("StoreKeyValuePair: " + jsonResultString); WindowsPhoneUtils.InvokeCallback(StoreKeyValueCallback, WindowsPhoneUtils.CALLBACKID, jsonResultString); }
public override void StoreKeyValuePairs(KeyPair[] keypairs) { throw new NotImplementedException(); }
public override void GetStoredKeyValuePairs(KeyPair[] KeyNames) { throw new NotImplementedException(); }
public override void GetStoredKeyValuePairs (KeyPair[] keynames) { UIApplication.SharedApplication.InvokeOnMainThread (delegate { string sAccessGroup = KeyChainAccessGroup; List<KeyPair> foundKeyPairs = new List<KeyPair>(); foreach(KeyPair key in keynames){ SecRecord srSearchCriteria = new SecRecord (SecKind.GenericPassword){ Account = key.Key }; if (sAccessGroup != null) srSearchCriteria.AccessGroup = sAccessGroup; SecStatusCode keyResult; SecRecord srFoundKey = SecKeyChain.QueryAsRecord (srSearchCriteria, out keyResult); if (keyResult == SecStatusCode.Success) { if(srFoundKey!=null){ KeyPair found = SecRecordToKeyPair(srFoundKey); //SystemLogger.Log(SystemLogger.Module.PLATFORM,"GetStoredKeyValuePairs - Found: "+found.Value); if(key.Encryption){ found.Value = Decrypt(found.Value); //SystemLogger.Log(SystemLogger.Module.PLATFORM,"GetStoredKeyValuePairs - Decrypt: "+found.Value); } foundKeyPairs.Add(found); } } } SystemLogger.Log(SystemLogger.Module.PLATFORM,"GetStoredKeyValuePairs - Found: " + foundKeyPairs.Count); IPhoneUtils.GetInstance().FireUnityJavascriptEvent("Appverse.Security.OnKeyValuePairsFound", foundKeyPairs); }); }
public override void GetStoredKeyValuePair (KeyPair keyname) { GetStoredKeyValuePairs (new KeyPair[] { keyname }); }
public abstract Task GetStoredKeyValuePairs(KeyPair[] keyNames);
public override void StoreKeyValuePairs(KeyPair[] keypairs) { string sAccessGroup = KeyChainAccessGroup; List<KeyPair> successfullKeyPairs = new List<KeyPair>(); List<KeyPair> failedKeyPairs = new List<KeyPair>(); foreach (KeyPair kp in keypairs) { SecRecord srNewEntry = new SecRecord (SecKind.GenericPassword){ Account = kp.Key, Generic = NSData.FromString(kp.Key), ValueData = NSData.FromString(kp.Value) }; if (sAccessGroup != null) srNewEntry.AccessGroup = sAccessGroup; if (this.GetPasscodeProtectedKeys ().Contains (kp.Key)) { if (UIDevice.CurrentDevice.CheckSystemVersion (8, 0)) { SystemLogger.Log (SystemLogger.Module.PLATFORM, "StoreKeyValuePairs - Passcode protection applied to this keychain item (as configured in security-config.xml)"); srNewEntry.AccessControl = new SecAccessControl (SecAccessible.WhenPasscodeSetThisDeviceOnly, SecAccessControlCreateFlags.UserPresence); } else { SystemLogger.Log (SystemLogger.Module.PLATFORM, "StoreKeyValuePairs - Passcode protection is requested for this keychain item, but protection couldn't be applied due to device is iOS<8"); } } SecStatusCode code = SecKeyChain.Add (srNewEntry); if (code == SecStatusCode.DuplicateItem) { SecRecord srDeleteExistingEntry = new SecRecord (SecKind.GenericPassword){ Account = kp.Key }; if (sAccessGroup != null) srDeleteExistingEntry.AccessGroup = sAccessGroup; code = SecKeyChain.Remove (srDeleteExistingEntry); if (code == SecStatusCode.Success) SecKeyChain.Add (srNewEntry); } if (code == SecStatusCode.Success){ successfullKeyPairs.Add (kp); } else { failedKeyPairs.Add(kp); } } SystemLogger.Log(SystemLogger.Module.PLATFORM,"StoreKeyValuePairs - Success: " + successfullKeyPairs.Count + ", Failed: " + failedKeyPairs.Count); UIApplication.SharedApplication.InvokeOnMainThread (delegate { IPhoneUtils.GetInstance().FireUnityJavascriptEvent("Appverse.OnKeyValuePairsStoreCompleted", new object[]{successfullKeyPairs, failedKeyPairs}); }); }
public abstract void GetStoredKeyValuePairs(KeyPair[] KeyNames);
public abstract Task StoreKeyValuePair(KeyPair keypair);
public abstract void StoreKeyValuePairs(KeyPair[] keypairs);
public abstract void GetStoredKeyValuePair(KeyPair KeyName);
public abstract void StoreKeyValuePair(KeyPair keypair);
public override async Task GetStoredKeyValuePairs(KeyPair[] keyNames) { var keychain = GetKeychainContainer(DefaultKeychainName, false); var foundKeyPairs = new List<KeyPair>(); if (keychain != null) { foundKeyPairs.AddRange(from kp in keyNames where keychain.Values.ContainsKey(kp.Key) select new KeyPair { Key = kp.Key, Value = keychain.Values[kp.Key].ToString() }); } var jsonResultString = JsonConvert.SerializeObject(foundKeyPairs.ToArray()); WindowsPhoneUtils.Log("GetStoredKeyValuePairs: " + jsonResultString); await WindowsPhoneUtils.InvokeCallback(GetKeyValueCallback, WindowsPhoneUtils.CALLBACKID, jsonResultString); }
public override async Task GetStoredKeyValuePair(KeyPair keyName) { GetStoredKeyValuePairs(new[] { keyName }); }
public override void StoreKeyValuePairs(KeyPair[] keypairs) { string sAccessGroup = KeyChainAccessGroup; List<KeyPair> successfullKeyPairs = new List<KeyPair>(); List<KeyPair> failedKeyPairs = new List<KeyPair>(); foreach (KeyPair kp in keypairs) { SecRecord srNewEntry = new SecRecord (SecKind.GenericPassword){ Account = kp.Key, Generic = NSData.FromString(kp.Key), ValueData = NSData.FromString(kp.Value) }; if (sAccessGroup != null) srNewEntry.AccessGroup = sAccessGroup; SecStatusCode code = SecKeyChain.Add (srNewEntry); if (code == SecStatusCode.DuplicateItem) { SecRecord srDeleteExistingEntry = new SecRecord (SecKind.GenericPassword){ Account = kp.Key }; if (sAccessGroup != null) srDeleteExistingEntry.AccessGroup = sAccessGroup; code = SecKeyChain.Remove (srDeleteExistingEntry); if (code == SecStatusCode.Success) SecKeyChain.Add (srNewEntry); } if (code == SecStatusCode.Success){ successfullKeyPairs.Add (kp); } else { failedKeyPairs.Add(kp); } } SystemLogger.Log(SystemLogger.Module.PLATFORM,"StoreKeyValuePairs - Success: " + successfullKeyPairs.Count + ", Failed: " + failedKeyPairs.Count); UIApplication.SharedApplication.InvokeOnMainThread (delegate { IPhoneUtils.GetInstance().FireUnityJavascriptEvent("Unity.OnKeyValuePairsStoreCompleted", new object[]{successfullKeyPairs, failedKeyPairs}); }); }
public abstract Task StoreKeyValuePairs(KeyPair[] keypairs);
public override void StoreKeyValuePair(KeyPair keypair) { StoreKeyValuePairs (new KeyPair[] { keypair }); }
public abstract Task GetStoredKeyValuePair(KeyPair keyName);
private KeyPair SecRecordToKeyPair(SecRecord entry) { if (entry != null) { KeyPair returnKeyPair = new KeyPair (); returnKeyPair.Key = entry.Account; returnKeyPair.Value = (string)NSString.FromData(entry.ValueData, NSStringEncoding.UTF8); return returnKeyPair; } return null; }
public override async Task StoreKeyValuePair(KeyPair keypair) { StoreKeyValuePairs(new[] { keypair }); }