Exemplo n.º 1
0
        /// <summary>
        /// Decrypt the document.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void HandleDecryptDocument(object sender, EventArgs e)
        {
            var    authenticateStore = AuthenticationStore.Instance();
            var    activeDocument    = Globals.ThisAddIn.Application.ActiveDocument;
            string sidDocumentIdValue;

            if (!activeDocument.TryGetVariable(Constants.VariableName, out sidDocumentIdValue))
            {
                return;
            }

            var range  = activeDocument.Range();
            var shapes = range.InlineShapes;

            foreach (InlineShape shape in shapes)
            {
                if (shape.Type != WdInlineShapeType.wdInlineShapePicture || string.IsNullOrWhiteSpace(shape.AlternativeText))
                {
                    continue;
                }

                // DECRYPT
                var b64Encoded = shape.AlternativeText;
                var xml        = DecryptOfficeDocument(sidDocumentIdValue, authenticateStore.IdentityToken, b64Encoded);
                if (string.IsNullOrWhiteSpace(xml))
                {
                    return;
                }

                shape.Range.InsertXML(xml);
                SetEncrypted(activeDocument, "false");
                activeDocument.Save();
            }
        }
 public ProfileUserController()
 {
     ViewModel = new ProfileUserViewModel();
     ViewModel.WindowLoaded += HandleWindowLoaded;
     _store = AuthenticationStore.Instance();
     _store.Authenticated += HandleAuthenticate;
 }
 private void HandleRibbonLoad(object sender, RibbonUIEventArgs e)
 {
     DisplayLogin(true);
     _authenticationStore = AuthenticationStore.Instance();
     _officeDocumentStore = OfficeDocumentStore.Instance();
     _authenticationStore.Authenticated += HandleAuthenticate;
     AuthenticationStore.Instance().Restore();
 }
Exemplo n.º 4
0
        /// <summary>
        /// Encrypt the document.
        /// </summary>
        /// <param name="Doc"></param>
        /// <param name="Cancel"></param>
        private void HandleDocumentBeforeClose(Document Doc, ref bool Cancel)
        {
            string sidDocumentIdValue;

            if (!Doc.TryGetVariable(Constants.VariableName, out sidDocumentIdValue))
            {
                return;
            }

            string isEncryptedStr;
            bool   isEncrypted = false;

            if (Doc.TryGetVariable(Constants.IsEncryptedVariableName, out isEncryptedStr))
            {
                bool.TryParse(isEncryptedStr, out isEncrypted);
            }

            if (isEncrypted)
            {
                return;
            }

            // Encrypt the content.
            var encryptionHelper = new EncryptionHelper();
            var encryptedResult  = encryptionHelper.Encrypt(Doc, sidDocumentIdValue).Result;

            if (!string.IsNullOrWhiteSpace(AuthenticationStore.Instance().IdentityToken))
            {
                var officeDocumentStore = OfficeDocumentStore.Instance();
                officeDocumentStore.StoreDecryption(sidDocumentIdValue, new DecryptedResponse
                {
                    Password = encryptedResult.Password,
                    Salt     = encryptedResult.Salt
                });
            }

            // Insert the image.
            var range    = Doc.Range();
            var image    = ResourceHelper.GetImage("WordAccessManagementAddin.Resources.lock.png");
            var filePath = Path.GetTempPath() + Guid.NewGuid().ToString() + ".png";
            var bm       = SteganographyHelper.CreateNonIndexedImage(image);

            bm.Save(filePath);
            range.Text = string.Empty;
            var shape = range.InlineShapes.AddPicture(filePath, false, true);

            shape.AlternativeText = encryptedResult.Content;
            File.Delete(filePath);
            SetEncrypted(Doc, "true");
            Doc.Save();
        }
Exemplo n.º 5
0
 public ProtectUserController(Window window)
 {
     _window = window;
     _documentManagementFactory      = new DocumentManagementFactory();
     _identityServerUmaClientFactory = new IdentityServerUmaClientFactory();
     _identityServerClientFactory    = new IdentityServerClientFactory();
     _authenticationStore            = AuthenticationStore.Instance();
     _officeDocumentStore            = OfficeDocumentStore.Instance();
     ViewModel = new ProtectUserViewModel();
     Init();
     ViewModel.DocumentProtected         += HandleProtectDocument;
     ViewModel.SharedLinkAdded           += HandleAddSharedLink;
     ViewModel.SelectedSharedLinkRemoved += HandleRemoveSharedLink;
 }
Exemplo n.º 6
0
        /// <summary>
        /// Handle the "navigated" event of the webrowser.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void HandleNavigated(object sender, NavigationEventArgs e)
        {
            HideScriptErrors(webBrowser, true);
            DisplaySpinner(false);
            if (e.Uri == null || !e.Uri.AbsoluteUri.StartsWith(Constants.CallbackUrl))
            {
                return;
            }

            var query = e.Uri.Query;

            query = query.Replace("?", "");
            var parameters = query.Split('&').Select(r =>
            {
                var splittedParameter = r.Split('=');
                return(new KeyValuePair <string, string>(splittedParameter[0], splittedParameter[1]));
            });

            AuthenticationStore.Instance().Authenticate(parameters);
            Close();
        }
Exemplo n.º 7
0
 private void InternalStartup()
 {
     Application.DocumentBeforeClose += HandleDocumentBeforeClose;
     OfficeDocumentStore.Instance().Decrypted    += HandleDecryptDocument;
     AuthenticationStore.Instance().Disconnected += HandleDisconnect;
 }