Back out code for Single Server Keychain. Per discussion with Engineering team.
This commit is contained in:
		
							
								
								
									
										98
									
								
								CASA/micasad/cache/SecretStore.cs
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										98
									
								
								CASA/micasad/cache/SecretStore.cs
									
									
									
									
										vendored
									
									
								
							| @@ -28,7 +28,6 @@ using System.Xml; | |||||||
| using System.Xml.Serialization; | using System.Xml.Serialization; | ||||||
| using System.Security.Cryptography; | using System.Security.Cryptography; | ||||||
| using System.Text; | using System.Text; | ||||||
| using System.Diagnostics; |  | ||||||
|  |  | ||||||
| using sscs.cache; | using sscs.cache; | ||||||
| using sscs.common; | using sscs.common; | ||||||
| @@ -66,81 +65,6 @@ namespace sscs.cache | |||||||
| 	    private static string POLICY_DIRECTORY = "/home/.casa";	 | 	    private static string POLICY_DIRECTORY = "/home/.casa";	 | ||||||
| 	    private MPFileWatcher mpWatcher = null;         | 	    private MPFileWatcher mpWatcher = null;         | ||||||
|  |  | ||||||
|         private static SecretStore casaStore; |  | ||||||
|  |  | ||||||
|         static SecretStore() |  | ||||||
|         { |  | ||||||
|             if (casaStore == null) |  | ||||||
|             { |  | ||||||
|                 User casaUser; |  | ||||||
|  |  | ||||||
| #if LINUX                 |  | ||||||
|                 casaUser = new UnixUser(new UnixUserIdentifier(GetCasaServiceUID()), "/home/.casa/" + constants.ConstStrings.MICASA_SERVICE_NAME); |  | ||||||
| #else |  | ||||||
|                 // create a data directory for server secrets |  | ||||||
|                 Process proc = Process.GetCurrentProcess(); |  | ||||||
|                 string exePath = proc.MainModule.FileName; |  | ||||||
|                 exePath = exePath.Substring(0, exePath.LastIndexOf("\\")); |  | ||||||
|                 Directory.CreateDirectory(exePath + "\\data"); |  | ||||||
|  |  | ||||||
|                 // create a casa User |  | ||||||
|                 casaUser = new WinUser(new WinUserIdentifier(998, 0), exePath + "\\data");                                                                 |  | ||||||
| #endif |  | ||||||
|                 casaUser.SetUserName(constants.ConstStrings.MICASA_SERVICE_NAME); |  | ||||||
|                 casaStore = casaUser.GetSecretStore(); |  | ||||||
|                 casaStore.refCount++; |  | ||||||
|  |  | ||||||
|                 casaStore.AddKeyChain(new KeyChain(constants.ConstStrings.SSCS_SERVER_KEY_CHAIN_ID + "\0")); |  | ||||||
|                 casaStore.StartPersistenceOfServerSecretsBySystemKey(); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
| #if LINUX |  | ||||||
|         static private int GetCasaServiceUID() |  | ||||||
|         { |  | ||||||
|             Mono.Unix.UnixUserInfo uui; |  | ||||||
| 	    |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 uui = new Mono.Unix.UnixUserInfo(constants.ConstStrings.MICASA_SERVICE_NAME); |  | ||||||
|             } |  | ||||||
|             catch |  | ||||||
|             { |  | ||||||
|                 Process proc = new Process(); |  | ||||||
|  |  | ||||||
|                 ProcessStartInfo psi = new ProcessStartInfo("useradd"); |  | ||||||
|                 psi.Arguments = constants.ConstStrings.MICASA_SERVICE_NAME; |  | ||||||
|                 psi.UseShellExecute = false; |  | ||||||
|                 psi.RedirectStandardOutput = true; |  | ||||||
|  |  | ||||||
|                 proc.StartInfo = psi; |  | ||||||
|                 proc.Start(); |  | ||||||
|                 proc.WaitForExit(); |  | ||||||
|  |  | ||||||
|                 uui = new Mono.Unix.UnixUserInfo(constants.ConstStrings.MICASA_SERVICE_NAME);                |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|  |  | ||||||
| 	    if (uui != null) |  | ||||||
| 	    { |  | ||||||
| 	    	// create directory for casa |  | ||||||
| 		Mono.Unix.Native.FilePermissions permissions = Mono.Unix.Native.Syscall.umask( |  | ||||||
| 							Mono.Unix.Native.FilePermissions.S_IWGRP | |  | ||||||
| 							Mono.Unix.Native.FilePermissions.S_IWOTH); |  | ||||||
|  |  | ||||||
| 	        Directory.CreateDirectory("/home/.casa/" + constants.ConstStrings.MICASA_SERVICE_NAME); |  | ||||||
| 		 |  | ||||||
| 		// set ownership |  | ||||||
| 		Mono.Unix.Native.Syscall.chown("/home/.casa/" + constants.ConstStrings.MICASA_SERVICE_NAME, |  | ||||||
| 						(uint)uui.UserId, |  | ||||||
| 						(uint)uui.GroupId); |  | ||||||
|  |  | ||||||
| 		Mono.Unix.Native.Syscall.umask(permissions); |  | ||||||
| 	    } |  | ||||||
|  |  | ||||||
|             return (int)uui.UserId; |  | ||||||
|         } |  | ||||||
| #endif |  | ||||||
|         private DateTime createTime; |         private DateTime createTime; | ||||||
|         public DateTime CreateTime |         public DateTime CreateTime | ||||||
|         { |         { | ||||||
| @@ -816,21 +740,7 @@ namespace sscs.cache | |||||||
| 		} | 		} | ||||||
|  |  | ||||||
|         internal KeyChain GetKeyChain(string id)         |         internal KeyChain GetKeyChain(string id)         | ||||||
|          |  | ||||||
|     	{ |     	{ | ||||||
| 		  Console.WriteLine("Keychain {0}", id); |  | ||||||
|  |  | ||||||
|             // if this is the server keychain, return the casaStore controlled one. |  | ||||||
|             if (id.StartsWith(constants.ConstStrings.SSCS_SERVER_KEY_CHAIN_ID)) |  | ||||||
|             { |  | ||||||
|                 KeyChain casakc = (KeyChain)casaStore.keyChainList[id]; |  | ||||||
|                 casakc.AccessedTime = DateTime.Now; |  | ||||||
| 		Console.WriteLine("Returned casakc"); |  | ||||||
|  |  | ||||||
|                 return casakc;                |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|  |  | ||||||
|             if(keyChainList.ContainsKey(id)) |             if(keyChainList.ContainsKey(id)) | ||||||
|             { |             { | ||||||
|                CSSSLogger.DbgLog("In " + CSSSLogger.GetExecutionPath(this) + " Keychain already exists."); |                CSSSLogger.DbgLog("In " + CSSSLogger.GetExecutionPath(this) + " Keychain already exists."); | ||||||
| @@ -847,10 +757,6 @@ namespace sscs.cache | |||||||
| 		 | 		 | ||||||
| 		internal bool CheckIfKeyChainExists(string id) | 		internal bool CheckIfKeyChainExists(string id) | ||||||
|         { |         { | ||||||
|             // return true if this is the server keychain |  | ||||||
|             if (id.StartsWith(constants.ConstStrings.SSCS_SERVER_KEY_CHAIN_ID)) |  | ||||||
|                 return true; |  | ||||||
|  |  | ||||||
|             if(keyChainList.ContainsKey(id)) |             if(keyChainList.ContainsKey(id)) | ||||||
|                 return true; |                 return true; | ||||||
|             else |             else | ||||||
| @@ -864,10 +770,6 @@ namespace sscs.cache | |||||||
| 				lss.PersistStoreWithDelay(); | 				lss.PersistStoreWithDelay(); | ||||||
| 			if (slss != null) | 			if (slss != null) | ||||||
| 			    slss.PersistServerStoreWithDelay(); | 			    slss.PersistServerStoreWithDelay(); | ||||||
|  |  | ||||||
|             // persist casastore data |  | ||||||
|             if (casaStore.slss != null) |  | ||||||
|                 casaStore.slss.PersistServerStoreWithDelay(); |  | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|         /* This function would need to do any storage/cleanup required |         /* This function would need to do any storage/cleanup required | ||||||
|   | |||||||
| @@ -144,9 +144,6 @@ namespace sscs.constants | |||||||
| 		internal static string CONFIG_PERSISTENT_DIRECTORY		= "PersistentDirectory"; | 		internal static string CONFIG_PERSISTENT_DIRECTORY		= "PersistentDirectory"; | ||||||
| 		internal static string CONFIG_PERSIST_SECRETS			= "PersistSecrets"; | 		internal static string CONFIG_PERSIST_SECRETS			= "PersistSecrets"; | ||||||
| 		internal static string CONFIG_DECRYPT_USING_DESKTOP_PASS	= "DecryptUsingDesktopPassword"; | 		internal static string CONFIG_DECRYPT_USING_DESKTOP_PASS	= "DecryptUsingDesktopPassword"; | ||||||
|  |  | ||||||
|         internal static string MICASA_SERVICE_NAME = "casa-service-user"; |  | ||||||
|  |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     internal class ConstFlags |     internal class ConstFlags | ||||||
|   | |||||||
| @@ -32,20 +32,11 @@ namespace sscs.common | |||||||
| { | { | ||||||
|     internal class UnixUser : User |     internal class UnixUser : User | ||||||
|     { |     { | ||||||
|         private string m_userHome = null; |  | ||||||
|  |  | ||||||
|         internal UnixUser() |         internal UnixUser() | ||||||
|         { |         { | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         internal UnixUser(UserIdentifier unixUserId, string sUserHome) |  | ||||||
|         { |  | ||||||
|             m_userHome = sUserHome; |  | ||||||
| 	    userId = unixUserId; |  | ||||||
| 	    secretStore = new SecretStore(this); |  | ||||||
|  |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         internal UnixUser(UserIdentifier unixUserId) |         internal UnixUser(UserIdentifier unixUserId) | ||||||
|         {             |         {             | ||||||
|             userId = unixUserId; |             userId = unixUserId; | ||||||
| @@ -63,19 +54,12 @@ namespace sscs.common | |||||||
|         } |         } | ||||||
|  |  | ||||||
|         override internal string GetUserHomeDir() |         override internal string GetUserHomeDir() | ||||||
|         { |  | ||||||
|             if (m_userHome == null) |  | ||||||
|         { |         { | ||||||
|             uint uid = (uint)userId.GetUID(); |             uint uid = (uint)userId.GetUID(); | ||||||
|             Mono.Unix.UnixUserInfo uui = new Mono.Unix.UnixUserInfo(uid); |             Mono.Unix.UnixUserInfo uui = new Mono.Unix.UnixUserInfo(uid); | ||||||
|             userName = uui.UserName; |             userName = uui.UserName; | ||||||
|             return uui.HomeDirectory; |             return uui.HomeDirectory; | ||||||
|         } |         } | ||||||
|             else |  | ||||||
|             { |  | ||||||
|                 return m_userHome; |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|          |          | ||||||
|  |  | ||||||
|     } |     } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user