Example #1
0
        public ExternalProviderGoogle(GXService providerService)
        {
            GoogleCredential credentials;

            using (Stream stream = KeyStream(CryptoImpl.Decrypt(providerService.Properties.Get(KEY))))
            {
                credentials = GoogleCredential.FromStream(stream).CreateScoped(StorageService.Scope.CloudPlatform);
            }

            using (Stream stream = KeyStream(CryptoImpl.Decrypt(providerService.Properties.Get(KEY))))
            {
                Signer = UrlSigner.FromServiceAccountData(stream);
            }

            Client = StorageClient.Create(credentials);

            Service = new StorageService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credentials,
                ApplicationName       = providerService.Properties.Get(APPLICATION_NAME)
            });

            Project = providerService.Properties.Get(PROJECT_ID);
            Bucket  = CryptoImpl.Decrypt(providerService.Properties.Get(BUCKET));
            Folder  = providerService.Properties.Get(FOLDER);

            CreateBucket();
            CreateFolder(Folder);
        }
Example #2
0
        static void Main(string[] args)
        {
            try
            {
                PrintHeader();

                CheckParams(args);

                Action action  = Action.Encrypt;
                string key     = string.Empty;
                string entry   = string.Empty;
                bool   reverse = false;
                foreach (string a in args)
                {
                    if (a == ENCRYPT)
                    {
                        action = Action.Encrypt;
                    }
                    else if (a == DECRYPT)
                    {
                        action = Action.Decrypt;
                    }
                    else if (a.StartsWith(KEY))
                    {
                        key = a.Substring(KEY.Length);
                    }
                    else if (a == REVERSE)
                    {
                        reverse = true;
                    }
                    else
                    {
                        entry = a;
                    }
                }

                bool   useKey = !string.IsNullOrEmpty(key);
                string result = "";
                switch (action)
                {
                case Action.Encrypt:
                    result = useKey ? CryptoImpl.Encrypt(entry, key, reverse) : CryptoImpl.Encrypt(entry, reverse);
                    break;

                case Action.Decrypt:
                    result = useKey ? CryptoImpl.Decrypt(entry, key, reverse) : CryptoImpl.Decrypt(entry, reverse);
                    break;

                default:
                    break;
                }

                Console.WriteLine(result);
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.Message);
                Usage();
            }
        }
        internal static bool GetEncryptedDataStoreProperty(string id, string name, out string ret)
        {
            string key = "Connection-" + id + name;
            string ds  = DATASTORE_SECTION + id;

            ret = "";
            string cfgBuf = string.Empty;
            bool   found  = false;
            string envPath;

            if (!connectionProperties.ContainsKey(key))
            {
                try
                {
                    if (Config.GetValueOf(ds, key, out cfgBuf))
                    {
                        found = true;
                    }
                    else if ((envPath = Environment.GetEnvironmentVariable("GXCFG")) != null)
                    {
                        if (IniGetValueOf(envPath + "\\gxcfg.ini", "Connection-" + id + name, out cfgBuf))
                        {
                            found = true;
                        }
                    }
#if !NETCORE
                    else if (IniGetValueOf(Environment.SystemDirectory + "\\gxcfg.ini", "Connection-" + id + name, out cfgBuf))
                    {
                        found = true;
                    }
#endif
                }
                catch (SecurityException ex)
                {
                    GXLogging.Warn(log, "Error in GetEncryptedDataStoreProperty", ex);
                }
                if (found)
                {
                    if (!CryptoImpl.Decrypt(ref ret, cfgBuf))
                    {
                        ret = cfgBuf;
                    }
                    if (!string.IsNullOrEmpty(ret))
                    {
                        connectionProperties[key] = ret;
                    }
                }
            }
            else
            {
                ret   = connectionProperties[key];
                found = true;
            }

            return(found);
        }
        private void SetEncryptProperty(GXProperties properties, String prop)
        {
            String value = properties.Get(prop);

            if (string.IsNullOrEmpty(value))
            {
                value = "";
            }
            value = CryptoImpl.Encrypt(value);
            properties.Set(prop, value);
        }
 public string GetAjaxEncryptionKey()
 {
     if (context.ReadSessionKey <string>(CryptoImpl.AJAX_ENCRYPTION_KEY) == null)
     {
         if (!RecoverEncryptionKey())
         {
             context.WriteSessionKey(CryptoImpl.AJAX_ENCRYPTION_KEY, CryptoImpl.GetRijndaelKey());
         }
     }
     return(context.ReadSessionKey <string>(CryptoImpl.AJAX_ENCRYPTION_KEY));
 }
Example #6
0
        private string decrypt(string cfgBuf)
        {
            string ret = string.Empty;

            try
            {
                if (!CryptoImpl.Decrypt(ref ret, cfgBuf))
                {
                    ret = cfgBuf;
                }
            }
            catch (Exception)
            {
            }
            return(ret);
        }
        public AzureStorageExternalProvider(GXService providerService)
        {
            Account = CryptoImpl.Decrypt(providerService.Properties.Get(ACCOUNT_NAME));
            Key     = CryptoImpl.Decrypt(providerService.Properties.Get(ACCESS_KEY));

            string publicContainer  = CryptoImpl.Decrypt(providerService.Properties.Get(PUBLIC_CONTAINER));
            string privateContainer = CryptoImpl.Decrypt(providerService.Properties.Get(PRIVATE_CONTAINER));

            StorageCredentials  credentials    = new StorageCredentials(Account, Key);
            CloudStorageAccount storageAccount = new CloudStorageAccount(credentials, true);

            Client = storageAccount.CreateCloudBlobClient();

            PublicContainer  = GetContainer(publicContainer, BlobContainerPublicAccessType.Blob);
            PrivateContainer = GetContainer(privateContainer, BlobContainerPublicAccessType.Off);
        }
Example #8
0
        public ExternalProviderS3(GXService providerService)
        {
            string         keyId       = CryptoImpl.Decrypt(providerService.Properties.Get(ACCESS_KEY_ID));
            string         keySecret   = CryptoImpl.Decrypt(providerService.Properties.Get(SECRET_ACCESS_KEY));
            AWSCredentials credentials = null;

            if (!string.IsNullOrEmpty(keyId) && !string.IsNullOrEmpty(keySecret))
            {
                credentials = new BasicAWSCredentials(keyId, keySecret);
            }

            var region = Amazon.RegionEndpoint.GetBySystemName(providerService.Properties.Get(REGION));

            Endpoint = providerService.Properties.Get(ENDPOINT);

            AmazonS3Config config = new AmazonS3Config()
            {
                ServiceURL     = Endpoint,
                RegionEndpoint = region
            };

#if NETCORE
            if (credentials != null)
            {
                Client = new AmazonS3ClientExtended(credentials, config);
            }
            else
            {
                Client = new AmazonS3ClientExtended(config);
            }
#else
            if (credentials != null)
            {
                Client = new AmazonS3Client(credentials, config);
            }
            else
            {
                Client = new AmazonS3Client(config);
            }
#endif
            Bucket = CryptoImpl.Decrypt(providerService.Properties.Get(BUCKET));
            Folder = providerService.Properties.Get(FOLDER);

            CreateBucket();
            CreateFolder(Folder);
        }
 private bool RecoverEncryptionKey()
 {
     if ((context.ReadSessionKey <string>(CryptoImpl.AJAX_ENCRYPTION_KEY) == null))
     {
         if (context.HttpContext != null)
         {
             String clientKey = context.HttpContext.Request.Headers[CryptoImpl.AJAX_SECURITY_TOKEN];
             if (!string.IsNullOrEmpty(clientKey))
             {
                 bool correctKey = false;
                 clientKey = CryptoImpl.DecryptRijndael(CryptoImpl.GX_AJAX_PRIVATE_IV + clientKey, CryptoImpl.GX_AJAX_PRIVATE_KEY, out correctKey);
                 if (correctKey)
                 {
                     context.WriteSessionKey(CryptoImpl.AJAX_ENCRYPTION_KEY, clientKey);
                     return(true);
                 }
             }
         }
     }
     return(false);
 }
Example #10
0
        public ExternalProviderOpenStack(GXService providerService)
        {
            var identityEndpoint = new Uri(providerService.Properties.Get("SERVER_URL"));
            var identity         = new CloudIdentityWithProject
            {
                Username    = CryptoImpl.Decrypt(providerService.Properties.Get("STORAGE_PROVIDER_USER")),
                Password    = CryptoImpl.Decrypt(providerService.Properties.Get("STORAGE_PROVIDER_PASSWORD")),
                ProjectName = providerService.Properties.Get("TENANT_NAME"),
            };

            OpenStackIdentityProvider identityProvider = new OpenStackIdentityProvider(identityEndpoint, identity);

            GetStorageEndpoint(identityProvider, identity);

            openstackFilesProvider = new CloudFilesProvider(null, "regionOne", identityProvider, null);
            publicBucketName       = CryptoImpl.Decrypt(providerService.Properties.Get("PUBLIC_BUCKET_NAME"));
            privateBucketName      = CryptoImpl.Decrypt(providerService.Properties.Get("PRIVATE_BUCKET_NAME"));
            folderName             = providerService.Properties.Get("FOLDER_NAME");
            serverUrl = providerService.Properties.Get("SERVER_URL");

            CreateBuckets();
            CreateFolder(folderName);
        }
Example #11
0
 private string encrypt(string value)
 {
     return(CryptoImpl.Encrypt(value, Crypto.GetServerKey()));
 }
Example #12
0
        public static ISessionService GetProvider()
        {
            var instance = GXServices.Instance?.Get(GXServices.SESSION_SERVICE);

            if (instance != null)
            {
                if (instance.Name.Equals(REDIS, StringComparison.OrdinalIgnoreCase))
                {
                    return(new GxRedisSession(instance.Properties.Get(SESSION_ADDRESS), CryptoImpl.Decrypt(instance.Properties.Get(SESSION_PASSWORD)), instance.Properties.Get(SESSION_INSTANCE)));
                }
                else if (instance.Name.Equals(DATABASE, StringComparison.OrdinalIgnoreCase))
                {
                    return(new GxDatabaseSession(instance.Properties.Get(SESSION_ADDRESS), CryptoImpl.Decrypt(instance.Properties.Get(SESSION_PASSWORD))
                                                 , instance.Properties.Get(SESSION_SCHEMA), instance.Properties.Get(SESSION_TABLE_NAME)));
                }
            }
            return(null);
        }