private async void UnprotectAsyncBuffer_Click(object sender, RoutedEventArgs e)
        {
            string outputStr    = "";
            string plainMessage = "";

            try
            {
                if (m_protectedBuffer != null)
                {
                    BufferProtectUnprotectResult unBuffer = await DataProtectionManager.UnprotectAsync(m_protectedBuffer);

                    m_unprotectedBuffer = unBuffer.Buffer;
                    plainMessage        = CryptographicBuffer.ConvertBinaryToString(BinaryStringEncoding.Utf8,
                                                                                    m_unprotectedBuffer
                                                                                    );
                    outputStr += "\n Status: " + unBuffer.ProtectionInfo.Status;
                    outputStr += "\n Unprotected string:" + plainMessage;
                    rootPage.NotifyUser(outputStr, NotifyType.StatusMessage);
                }
                else
                {
                    rootPage.NotifyUser("Please protect a buffer to unprotect", NotifyType.ErrorMessage);
                }
            }
            catch (Exception ex)
            {
                rootPage.NotifyUser(outputStr + "\n" + ex.ToString(), NotifyType.ErrorMessage);
            }
        }
 public ConfigManager(ILogger log, DataProtectionManager protectionManager)
 {
     _logger = log;
     _configFileName = "WebDavSync.conf";
     _serializer= new JsonSerializer<ConfigDTO>();
     _protectionManager = protectionManager;
 }
示例#3
0
        private async void ProtectStreamAsync_Click(object sender, RoutedEventArgs e)
        {
            string outputStr = "";

            Byte[] byteStream = { 1, 2, 3, 4, 5 };

            InMemoryRandomAccessStream randomAccessStream = new InMemoryRandomAccessStream();
            IOutputStream outputStream = randomAccessStream.GetOutputStreamAt(0);
            var           writer       = new DataWriter(outputStream);

            writer.WriteBytes(byteStream);
            await writer.StoreAsync();

            IInputStream source = randomAccessStream.GetInputStreamAt(0);

            m_protectedStream = new InMemoryRandomAccessStream();
            IOutputStream destination = m_protectedStream.GetOutputStreamAt(0);

            await DataProtectionManager.ProtectStreamAsync(source, Scenario1.m_enterpriseId, destination);

            var reader = new DataReader(m_protectedStream.GetInputStreamAt(0));
            await reader.LoadAsync((uint)m_protectedStream.Size);

            IBuffer protectedStreamBuffer = reader.ReadBuffer((uint)m_protectedStream.Size);

            outputStr += "\n Protected Stream buffer:" + CryptographicBuffer.EncodeToHexString(protectedStreamBuffer);

            rootPage.NotifyUser(outputStr, NotifyType.StatusMessage);
        }
示例#4
0
        private async void UnprotectAsyncBuffer_Click(object sender, RoutedEventArgs e)
        {
            string outputStr = "";

            if (m_protectedStream != null)
            {
                IInputStream source = m_protectedStream.GetInputStreamAt(0);
                m_unprotectedStream = new InMemoryRandomAccessStream();
                await DataProtectionManager.UnprotectStreamAsync(source,
                                                                 m_unprotectedStream
                                                                 );

                var unprotectedReader = new DataReader(m_unprotectedStream.GetInputStreamAt(0));
                await unprotectedReader.LoadAsync((uint)m_unprotectedStream.Size);

                IBuffer unprotectedStreamBuffer = unprotectedReader.ReadBuffer((uint)m_unprotectedStream.Size);
                outputStr += "\n UnProtected Stream buffer:" +
                             CryptographicBuffer.EncodeToHexString(unprotectedStreamBuffer);

                rootPage.NotifyUser(outputStr, NotifyType.StatusMessage);
            }
            else
            {
                rootPage.NotifyUser("Please protect a stream to unprotect", NotifyType.ErrorMessage);
            }
        }
示例#5
0
        private async void ProtectedAccessSuspending(object sender, ProtectedAccessSuspendingEventArgs args)
        {
            string logFileContent = "";

            Windows.Foundation.Deferral deferal = args.GetDeferral();

            // Protect any sensitive data in Memory so that it cannot be accessed while the device is  locked
            // You should encrypt or destory any copies of sensitve data while device is going to a locked state.

            IBuffer inputBuffer = CryptographicBuffer.ConvertStringToBinary(m_SecretMessage,
                                                                            BinaryStringEncoding.Utf8);
            BufferProtectUnprotectResult procBuffer = await DataProtectionManager.ProtectAsync(inputBuffer, m_EnterpriseID);

            m_protectedBuffer = procBuffer.Buffer;

            deferal.Complete();

            m_areKeysDropped = true;

            var settings = ApplicationData.Current.LocalSettings;

            settings.Values[m_taskName] += "\nApp got DPL suspend event";

            StorageFolder localFolder = Windows.Storage.ApplicationData.Current.LocalFolder;

            StorageFile logFile = await localFolder.CreateFileAsync("SuspendLog.txt",
                                                                    CreationCollisionOption.OpenIfExists);

            logFileContent += "\r\n" + DateTime.Now + ":" + "Got DPL Protected Suspended";
            logFileContent += "\r\n" + "Protection Status:" + procBuffer.ProtectionInfo.Status;

            await FileIO.AppendTextAsync(logFile, logFileContent);
        }
示例#6
0
        private async void DoBufferWork(IBackgroundTaskInstance taskInstance)
        {
            string message            = "Hello World!";
            string unprotectedMessage = "";
            string logFileName        = "Bufferlog.txt";
            string logFileContent     = "";

            StorageFolder localFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
            StorageFile   logFile     = await localFolder.CreateFileAsync(logFileName, CreationCollisionOption.OpenIfExists);


            IBuffer inputBuffer = CryptographicBuffer.ConvertStringToBinary(message, BinaryStringEncoding.Utf8);
            BufferProtectUnprotectResult procBuffer = await DataProtectionManager.ProtectAsync(inputBuffer, m_EnterpriseID);

            logFileContent += "\r\n" + DateTime.Now + ":" + "ProtStatus:" + procBuffer.ProtectionInfo.Status + "\n";
            logFileContent += "\r\n" + "Protected Buffer:" + CryptographicBuffer.EncodeToHexString(procBuffer.Buffer).Substring(0, 5);

            // If keys are dropped under lock, unprotectBuffer will fail so don't unprotectbuffer under lock
            if (!m_areKeysDropped)
            {
                BufferProtectUnprotectResult unBuffer = await DataProtectionManager.UnprotectAsync(procBuffer.Buffer);

                unprotectedMessage = CryptographicBuffer.ConvertBinaryToString(BinaryStringEncoding.Utf8, procBuffer.Buffer);
                logFileContent    += "\n Unprotected string:" + unprotectedMessage;
                if (message != unprotectedMessage)
                {
                    throw new Exception("Original string does not match with unprotectedMessage!");
                }
            }

            await FileIO.AppendTextAsync(logFile, logFileContent);
        }
示例#7
0
        private async void ProtectedAccessResumed(object sender, ProtectedAccessResumedEventArgs args)
        {
            string logFileContent = "";

            // Keys are available so can read and write from a protected file

            m_areKeysDropped = false;

            //
            BufferProtectUnprotectResult unBuffer = await DataProtectionManager.UnprotectAsync(m_protectedBuffer);

            m_SecretMessage = CryptographicBuffer.ConvertBinaryToString(BinaryStringEncoding.Utf8,
                                                                        m_protectedBuffer
                                                                        );
            logFileContent += "\n Unprotected string:" + m_SecretMessage;

            var settings = ApplicationData.Current.LocalSettings;

            settings.Values[m_taskName] += "\nApp got DPL resumed event";

            StorageFolder localFolder =
                Windows.Storage.ApplicationData.Current.LocalFolder;

            StorageFile logFile = await localFolder.CreateFileAsync("ResumeLog.txt",
                                                                    CreationCollisionOption.OpenIfExists);

            await FileIO.AppendTextAsync(logFile, "\r\n" + DateTime.Now + ":" + "Got DPL Protected resumed");
        }
 public Configuration(ConfigDTO dto, DataProtectionManager protectionManager, bool runDebug)
 {
     RunDebug        = runDebug;
     ReoccurenceTime = dto.ReoccurenceTime;
     Local           = new ConfigLocal(dto.Local, protectionManager);
     Remote          = new ConfigRemote(dto.Remote, protectionManager);
 }
        public ConfigRemote(ConfigRemoteDTO dto, DataProtectionManager protectionManager)
        {
            _dto               = dto;
            RemoteServerPath   = dto.RemoteServerPath;
            RemoteFolderPath   = dto.RemoteFolderPath;
            _protectionManager = protectionManager;

            Credentials = new NetworkCredential(dto.UserName, _protectionManager.Unprotect(dto.SecurePassword));
        }
        private async void ProtectAsyncBuffer_Click(object sender, RoutedEventArgs e)
        {
            string  outputStr   = "\n Protecting string:" + m_protectedMessage;
            IBuffer inputBuffer = CryptographicBuffer.ConvertStringToBinary(m_protectedMessage,
                                                                            BinaryStringEncoding.Utf8);
            BufferProtectUnprotectResult procBuffer = await DataProtectionManager.ProtectAsync(inputBuffer, Scenario1.m_enterpriseId);

            m_protectedBuffer = procBuffer.Buffer;
            outputStr        += "\n Status: " + procBuffer.ProtectionInfo.Status;
            outputStr        += "\n Protected string:";
            outputStr        += CryptographicBuffer.EncodeToHexString(m_protectedBuffer).Substring(0, 20);
            rootPage.NotifyUser(outputStr, NotifyType.StatusMessage);
        }
示例#11
0
        private async void GetStreamStatus_Click(object sender, RoutedEventArgs e)
        {
            if (m_protectedStream != null)
            {
                DataProtectionInfo procStatus = await DataProtectionManager.GetStreamProtectionInfoAsync(m_protectedStream.GetInputStreamAt(0));

                string outputStr = "\n m_protectedStream protection status: " + procStatus.Status;
                rootPage.NotifyUser(outputStr, NotifyType.StatusMessage);
            }
            else
            {
                string outputStr = "\nStream is null because ProtectStream API did not run successfully";
                rootPage.NotifyUser(outputStr, NotifyType.ErrorMessage);
            }
        }
        private async void GetBuffersStatus_Click(object sender, RoutedEventArgs e)
        {
            string outputStr = "";

            if (m_protectedBuffer != null)
            {
                DataProtectionInfo procStatus = await DataProtectionManager.GetProtectionInfoAsync(m_protectedBuffer);

                outputStr += "\n protection status: " + procStatus.Status;
                rootPage.NotifyUser(outputStr, NotifyType.StatusMessage);
            }
            else
            {
                outputStr += "\n Buffer is null because Protect API did not run successfully";
                rootPage.NotifyUser(outputStr, NotifyType.ErrorMessage);
            }
        }
示例#13
0
        /// <summary>
        /// Executes a reconfiguration of the config file
        /// </summary>
        static void Reconfigure(DataProtectionManager dataProtectionManager, bool runDebug)
        {
            ILogger logger = _logManager.GetLogger(LoggerType.Default);

            ConfigManager configManager = new ConfigManager(logger, dataProtectionManager);
            Configuration config        = configManager.ReadConfig(runDebug, ReadFileOption.CreateIfNotExists);

            if (config != null)
            {
                InstallationManager helper = new InstallationManager(logger);
                configManager.Update(helper.Reconfigure(config));
            }
            else
            {
                logger.Error("Could not read the configuration! Please try again.");
                Environment.Exit(1);
            }
        }
示例#14
0
        /// <summary>
        /// Main Method, connects to webdav server and handles sync
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            //Check the given parameters
            ParameterType type = CheckParameter(args);

            //Check if the App should run in Debug Mode or not
            bool runDebug = false;

            if (type == ParameterType.Dbg ||
                type == ParameterType.Unknown ||
                type == ParameterType.Install ||
                Debugger.IsAttached)
            {
                runDebug = true;
            }
            _logManager = new LogManager(runDebug);

            DataProtectionManager dataProtectionManager = ResolveDataProtector();

            //Check Parameter
            switch (type)
            {
            case ParameterType.Install:
                Install();
                break;

            case ParameterType.Reconfigure:
                Reconfigure(dataProtectionManager, runDebug);
                break;

            case ParameterType.Unknown:
                LogUnknownParameterMessage();
                break;

            default:
                Run(type, dataProtectionManager, runDebug);
                break;
            }
        }
示例#15
0
        /// <summary>
        /// Executes the default app
        /// </summary>
        /// <param name="type"></param>
        static void Run(ParameterType type, DataProtectionManager protectionManager, bool runDebug)
        {
            ILogger logger = _logManager.GetLogger(LoggerType.Default);

            logger.Debug("----------------------------------------");
            logger.Debug("-----Synchronization client started-----");
            logger.Debug("----------------v." + Assembly.GetEntryAssembly().GetName().Version + "---------------");
            logger.Debug("----------------------------------------");

            //Get Config
            ConfigManager configManager = new ConfigManager(logger, protectionManager);
            //Read the Config -> Create Empty if non exists
            var config = configManager.ReadConfig(runDebug, ReadFileOption.CreateIfNotExists);

            if (config == null || !configManager.Validate(config))
            {
                Environment.Exit(1);
            }

            //Execute Synchronisation
            ExecuteSynchronisation(logger, config);
        }
示例#16
0
 public ConfigLocal(ConfigLocalDTO dto, DataProtectionManager protectionManager)
 {
     LocalSyncDir       = dto.LocalSyncDir;
     _protectionManager = protectionManager;
 }
示例#17
0
 public ConfigRemote(DataProtectionManager protectionManager)
 {
     Credentials        = new NetworkCredential();
     _protectionManager = protectionManager;
 }
 public Configuration(DataProtectionManager protectionManager)
 {
     Local  = new ConfigLocal(protectionManager);
     Remote = new ConfigRemote(protectionManager);
 }
示例#19
0
 public ConfigLocal(DataProtectionManager protectionManager)
 {
     _protectionManager = protectionManager;
 }