/// <summary>
        /// Generates the fingerprint contributions
        /// </summary>
        /// <param name="element"> The element for which the fingerprint is being generated</param>
        /// <param name="ruleResult"> Used to determine the rule and the ruke result </param>
        /// <returns>Fingerprint contributions for the element</returns>
        internal static IDictionary <string, string> GetFingerPrintContributions(A11yElement element, RuleResult ruleResult)
        {
            Dictionary <string, string> fingerPrintContributions = new Dictionary <string, string>();
            IFingerprint scanResultFingerprint = FingerprintFactory.GetFingerPrint(element, ruleResult.Rule, ruleResult.Status);

            foreach (FingerprintContribution contribution in scanResultFingerprint.Contributions)
            {
                fingerPrintContributions.Add(contribution.Key, contribution.Value);
            }
            return(fingerPrintContributions);
        }
        public void ShouldFailGracefullyWithDatesFromBrowserWhichAreNotInRfc1123FormatByReturningValidButIncorrectFingerprint()
        {
            DateTime lastModifiedDate = new DateTime(2007, 4, 20);
            string   etagValue        = "\"some opaque value\"";

            mockRequest.SetupResult("IfModifiedSince", lastModifiedDate.ToString());
            mockRequest.SetupResult("IfNoneMatch", etagValue);
            ConditionalGetFingerprint fingerprint = new FingerprintFactory(null, null).BuildFromRequest(request);

            Assert.AreNotEqual(new ConditionalGetFingerprint(lastModifiedDate, etagValue), fingerprint);
        }
        public void ShouldBuildAFingerprintWithValuesFromRequestIfBothHeadersAreAvailable()
        {
            DateTime lastModifiedDate = new DateTime(2007, 4, 20);
            string   etagValue        = "\"some opaque value\"";

            mockRequest.SetupResult("IfModifiedSince", lastModifiedDate.ToString("r"));
            mockRequest.SetupResult("IfNoneMatch", etagValue);
            ConditionalGetFingerprint fingerprint = new FingerprintFactory(null, null).BuildFromRequest(request);

            Assert.AreEqual(new ConditionalGetFingerprint(lastModifiedDate, etagValue), fingerprint);
        }
        public void ShouldAddQuotesToStringFromVersionAssemblyProviderForFingerprintFromDate()
        {
            string      testETag            = "test e tag value";
            DateTime    testDate            = new DateTime(2007, 4, 20);
            DynamicMock mockVersionProvider = new DynamicMock(typeof(IVersionProvider));

            mockVersionProvider.SetupResult("GetVersion", testETag);

            ConditionalGetFingerprint testConditionalGetFingerprint =
                new FingerprintFactory((IVersionProvider)mockVersionProvider.MockInstance, null).BuildFromDate(testDate);


            string expectedETag = "\"" + testETag + "\"";

            Assert.AreEqual(expectedETag, testConditionalGetFingerprint.ETag);
        }
Esempio n. 5
0
 public static BillPaymentsClient Create(
     string secretKey,
     IClient client             = null,
     IObjectMapper objectMapper = null,
     IFingerprint fingerprint   = null
     )
 {
     return(new BillPaymentsClient(
                secretKey,
                new RequestMappingIntercessor(
                    client ?? ClientFactory.Create(),
                    objectMapper ?? ObjectMapperFactory.Create()
                    ),
                fingerprint ?? FingerprintFactory.Create()
                ));
 }
Esempio n. 6
0
        public void ShouldAddQuotesToStringFromVersionAssemblyProviderForFingerprintFromDate()
        {
            string   testETag            = "test e tag value";
            DateTime testDate            = new DateTime(2007, 4, 20);
            var      mockVersionProvider = new Mock <IVersionProvider>();

            mockVersionProvider.Setup(provider => provider.GetVersion()).Returns(testETag);

            ConditionalGetFingerprint testConditionalGetFingerprint =
                new FingerprintFactory((IVersionProvider)mockVersionProvider.Object, null).BuildFromDate(testDate);


            string expectedETag = "\"" + testETag + "\"";

            Assert.AreEqual(expectedETag, testConditionalGetFingerprint.ETag);
        }
        public void ShouldReturnNotAvailableIfEitherOrBothHeadersAreMissing()
        {
            mockRequest.ExpectAndReturn("IfModifiedSince", null);
            mockRequest.ExpectAndReturn("IfNoneMatch", null);
            ConditionalGetFingerprint fingerprint = new FingerprintFactory(null, null).BuildFromRequest(request);

            Assert.AreSame(ConditionalGetFingerprint.NOT_AVAILABLE, fingerprint);


            mockRequest.ExpectAndReturn("IfModifiedSince", DateTime.Now.ToString("r"));
            mockRequest.ExpectAndReturn("IfNoneMatch", null);
            fingerprint = new FingerprintFactory(null, null).BuildFromRequest(request);
            Assert.AreSame(ConditionalGetFingerprint.NOT_AVAILABLE, fingerprint);


            mockRequest.ExpectAndReturn("IfModifiedSince", null);
            mockRequest.ExpectAndReturn("IfNoneMatch", "\"opaque value in etag\"");
            fingerprint = new FingerprintFactory(null, null).BuildFromRequest(request);
            Assert.AreSame(ConditionalGetFingerprint.NOT_AVAILABLE, fingerprint);
        }
Esempio n. 8
0
        public void ShouldReturnNotAvailableIfEitherOrBothHeadersAreMissing()
        {
            mockRequest.SetupGet(_request => _request.IfModifiedSince).Returns(() => null).Verifiable();
            mockRequest.SetupGet(_request => _request.IfNoneMatch).Returns(() => null).Verifiable();
            ConditionalGetFingerprint fingerprint = new FingerprintFactory(null, null).BuildFromRequest(request);

            Assert.AreSame(ConditionalGetFingerprint.NOT_AVAILABLE, fingerprint);


            mockRequest.SetupGet(_request => _request.IfModifiedSince).Returns(DateTime.Now.ToString("r")).Verifiable();
            mockRequest.SetupGet(_request => _request.IfNoneMatch).Returns(() => null).Verifiable();
            fingerprint = new FingerprintFactory(null, null).BuildFromRequest(request);
            Assert.AreSame(ConditionalGetFingerprint.NOT_AVAILABLE, fingerprint);


            mockRequest.SetupGet(_request => _request.IfModifiedSince).Returns(() => null).Verifiable();
            mockRequest.SetupGet(_request => _request.IfNoneMatch).Returns("\"opaque value in etag\"").Verifiable();
            fingerprint = new FingerprintFactory(null, null).BuildFromRequest(request);
            Assert.AreSame(ConditionalGetFingerprint.NOT_AVAILABLE, fingerprint);
        }
Esempio n. 9
0
        /*
         * Decrypt the private key and start the app
         */
        public void ResumeApp()
        {
            //attempt to load the keys if not already loaded
            if (!m_ln.Loaded)
            {
                m_ln.LoadKeys();
            }

            //prompt the user to enter a password to decrypt the private key
            PasswordPrompt p = new PasswordPrompt()
            {
                NegativeButtonVisible = false, PositiveButtonText = "Decrypt"
            };

            p.OnPromptSaved += new Prompt.PromptClosedEventListener(() =>
            {
                if (p.Password == null || p.Password.Length == 0)
                {
                    return;
                }

                //attempt to decrypt the public key
                if (!m_ln.DecryptPrivateKey(p.Password))
                { //decryption failed, incorrect password was entered
                    NotificationFactory.ShortAlert("Password is incorrect");
                    p.Show();
                    return;
                }

                //erase the entered password
                Eraser.SecureErase(p.Password);
                p.Password = "";

                //private key decrypted, start the app normally
                StartAppFinal();
            });
            //check if fingerprint auth is enabled
            if (m_config.UseFingerprint && m_config.EncryptedPassword.Length > 1)
            {
                //prompt for fingerprint
                IFingerprint fp = FingerprintFactory.GetInstance();
                fp.InitReader();
                if (fp.IsReady())
                {
                    Application.Current.MainPage = new FingerprintPage(new EventHandler((oo, ee) =>
                    {
                        byte[] data = (byte[])oo; //page returns the decrypted password

                        //go to password entry if skipped
                        if (data == null)
                        {
                            p.Show();
                            return;
                        }

                        //decrypt the password
                        string pass = Encoding.UTF8.GetString(data);

                        //attempt to decrypt the private key
                        if (!m_ln.DecryptPrivateKey(pass))
                        { //decryption failed
                            return;
                        }

                        //erase the decrypted password
                        Eraser.SecureErase(pass);
                        p.Password = "";

                        //private key decrypted, start the app normally
                        StartAppFinal();
                    }), fp, "");
                }
            }
            else
            {
                p.Show();
            }
        }
Esempio n. 10
0
        public SettingsPage()
        {
            InitializeComponent();

            m_config = ConfigFactory.GetInstance();

            //initialize to the current settings
            chk_lock_on_suspend.IsToggled = m_config.LockOnSuspend;
            chk_save_on_suspend.IsToggled = m_config.SaveOnSuspend;
            chk_fingerprint.IsToggled     = m_config.UseFingerprint;

            //we need to handle the fingerprint enable separately
            chk_fingerprint.Toggled += new EventHandler <ToggledEventArgs>((o, e) =>
            {
                if (chk_fingerprint.IsToggled)
                {
                    IFingerprint fp = FingerprintFactory.GetInstance();
                    fp.InitReader();
                    if (fp.IsReady())
                    {
                        PasswordPrompt pmt = new PasswordPrompt()
                        {
                            IsNavPage = true, PromptTitle = "Verify your Password", PositiveButtonText = "Verify", RestorePage = true
                        };
                        pmt.OnPromptSaved += new Prompt.PromptClosedEventListener(() =>
                        {
                            if (pmt.Password == null || pmt.Password.Length == 0)
                            {
                                return;
                            }

                            //attempt to decrypt the private key, just as a verification method
                            if (!LocknoteMgr.GetInstance().DecryptPrivateKey(pmt.Password))
                            { //decryption failed, incorrect password was entered
                                NotificationFactory.ShortAlert("Password is incorrect");
                                pmt.Show(((NavigationPage)((HomeMDP)Application.Current.MainPage).Detail));
                                return;
                            }

                            //we verified the password is correct, now we can prompt the user to scan a fingerprint
                            Page back = Application.Current.MainPage;
                            Application.Current.MainPage = new FingerprintPage(new EventHandler((oo, ee) =>
                            {
                                byte[] data = (byte[])oo; //page returns the encrypted password
                                if (data != null)
                                {                         //only if was not skipped
                                  //encrypt the password and save it
                                    ConfigFactory.GetInstance().EncryptedPassword = data;
                                    ConfigFactory.GetInstance().UseFingerprint    = true;
                                    NotificationFactory.ShortAlert("Fingerprint unlock enabled");
                                }
                                else
                                {
                                    ConfigFactory.GetInstance().EncryptedPassword = new byte[] { 0 };
                                    ConfigFactory.GetInstance().UseFingerprint    = false;
                                    chk_fingerprint.IsToggled = false;
                                }
                                Application.Current.MainPage = back;
                            }), fp, pmt.Password);
                        });
                        pmt.OnPromptDismissed += new Prompt.PromptClosedEventListener(() =>
                        {
                            chk_fingerprint.IsToggled = false;
                        });
                        pmt.Show(((NavigationPage)((HomeMDP)Application.Current.MainPage).Detail));
                    }
                }
                else
                {
                    ConfigFactory.GetInstance().EncryptedPassword = new byte[] { 0 };
                    ConfigFactory.GetInstance().UseFingerprint    = false;
                }
            });

            //set the button handlers
            btn_save.Clicked += new EventHandler((o, e) =>
            {
                m_config.LockOnSuspend = chk_lock_on_suspend.IsToggled;
                m_config.SaveOnSuspend = chk_save_on_suspend.IsToggled;

                NotificationFactory.ShortAlert("Settings Saved!");
            });
            btn_change_password.Clicked += new EventHandler((o, e) =>
            {
                PasswordEntryView pep = new PasswordEntryView();
                pep.OnSave           += new EventHandler((oo, ee) =>
                {
                    LocknoteMgr.GetInstance().ReencryptPrivateKey(pep.Text);
                    ((NavigationPage)((HomeMDP)Application.Current.MainPage).Detail).PopAsync();
                    NotificationFactory.ShortAlert("Password changed");
                });
                Xamarin.Forms.ContentPage pg = new ContentPage();
                pg.Content = pep;
                ((NavigationPage)((HomeMDP)Application.Current.MainPage).Detail).PushAsync(pg);
            });
        }
Esempio n. 11
0
 /// <summary>
 /// Creates new instance of <seealso cref="FingerprintProvider"/>.
 /// </summary>
 /// <param name="fingerprintFactory"></param>
 protected FingerprintProvider(FingerprintFactory fingerprintFactory)
 {
     FingerprintFactory = fingerprintFactory;
 }
Esempio n. 12
0
        public FirstTimeSetup()
        {
            InitializeComponent();

            //create the password entry view
            PasswordEntryView pep = new PasswordEntryView();

            pep.OnSave += new EventHandler((o, e) =>
            {
                //get the public key ASN1
                SubjectPublicKeyInfo pubki = SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo(m_keypair.Public);
                //get the private key ASN1
                PrivateKeyInfo privki = PrivateKeyInfoFactory.CreatePrivateKeyInfo(m_keypair.Private);

                //encrypt the private key
                byte[] encPrivKey = Crypto.EncryptKey(privki.GetDerEncoded(), pep.Text);
                m_keypair         = null;

                //delete the old notebooks
                if (Directory.Exists(NoteManager.GetNotebookDir()))
                {
                    Directory.Delete(NoteManager.GetNotebookDir(), true);
                }

                //save the keys to file
                KeyManager.SaveKeys(encPrivKey, pubki.GetDerEncoded());

                //erase the data
                Eraser.SecureErase(encPrivKey);

                //ask if the user wants to use a fingerprint
                IFingerprint fp = FingerprintFactory.GetInstance();
                fp.InitReader();
                if (fp.IsReady())
                {
                    Application.Current.MainPage = new FingerprintPage(new EventHandler((oo, ee) =>
                    {
                        byte[] data = (byte[])oo; //page returns the encrypted password
                        if (data != null)
                        {                         //only if was not skipped
                            //encrypt the password and save it
                            ConfigFactory.GetInstance().EncryptedPassword = data;
                            ConfigFactory.GetInstance().UseFingerprint    = true;
                        }
                        else
                        {
                            ConfigFactory.GetInstance().EncryptedPassword = new byte[] { 0 };
                            ConfigFactory.GetInstance().UseFingerprint    = false;
                        }
                        //trigger the setup complete event
                        if (OnSetupComplete != null)
                        {
                            OnSetupComplete(this, new EventArgs());
                        }
                    }), fp, pep.Text);
                }
                else
                {
                    //trigger the setup complete event
                    if (OnSetupComplete != null)
                    {
                        OnSetupComplete(this, new EventArgs());
                    }
                }
            });

            //create the activity indicator layout
            StackLayout actLayout = new StackLayout()
            {
                VerticalOptions = LayoutOptions.CenterAndExpand
            };
            ActivityIndicator actInd = new ActivityIndicator();;

            actLayout.Children.Add(actInd);
            actLayout.Children.Add(new Label()
            {
                Text = "Generating key pair", TextColor = Color.DarkGray, HorizontalTextAlignment = TextAlignment.Center
            });

            TapRandomizer tapRnd = new TapRandomizer();

            tapRnd.OnRandomized += new EventHandler((o, e) =>
            {
                m_seed = tapRnd.Seed;
                //show wait animation
                actInd.IsRunning = true;
                this.Content     = actLayout;
                //generate the key pair
                Crypto.StartGenerateKeypair(m_seed, new Crypto.GenCompleteEventHandler((keypair) =>
                {
                    m_keypair = keypair;
                    //hide wait animation
                    actInd.IsRunning = false;
                    //show the password entry page
                    this.Content = pep;
                }));
            });

            this.Content = tapRnd;
        }