Interaction logic for SettingsWindow.xaml
상속: System.Windows.Window
예제 #1
0
 public override void AssignSession(Session oS)
 {
     Clear();
     if (!CertificateInspector.HttpsDecryptionEnabledOnStartup || !CONFIG.bCaptureCONNECT || !CONFIG.bMITM_HTTPS)
     {
         _panel.Children.Add(new System.Windows.Controls.Label {
             Content = "Fiddler Cert Inspector requires enabling decryption of HTTPS traffic, and restarting Fiddler."
         });
         return;
     }
     if (!CertificateInspector.IsSupportedOperatingSystem)
     {
         _panel.Children.Add(new System.Windows.Controls.Label
         {
             Content = "Fiddler Cert Inspector requires Windows Vista or Windows Server 2008 or later."
         });
         return;
     }
     var control = new WpfCertificateControl();
     var masterModel = new CertInspectorModel();
     masterModel.UpdateBarModel = new UpdateBarModel(CertificateInspector.LatestVersion?.Item1, CertificateInspector.LatestVersion?.Item2);
     masterModel.AskUpdateBarModel = _askUpdateBarModel;
     masterModel.AskUpdateBarModel.AskRequired = !FiddlerApplication.Prefs.GetBoolPref(PreferenceNames.ASK_CHECK_FOR_UPDATES_PREF, false);
     masterModel.SettingsCommand = new RelayCommand(_ =>
     {
         var window = new SettingsWindow();
         var helper = new WindowInteropHelper(window);
         helper.Owner = FiddlerApplication.UI.Handle;
         window.ShowDialog();
     });
     masterModel.HttpSecurityModel = new HttpSecurityModel
     {
         IsNotTunnel = (oS.BitFlags & SessionFlags.IsDecryptingTunnel) != SessionFlags.IsDecryptingTunnel,
         ContentChain = new AsyncProperty<ObservableCollection<CertificateModel>>(Task.Factory.StartNew(() =>
         {
             if (!oS.bHasResponse)
             {
                 return null;
             }
             var contentChain = ChainForContent(oS.ResponseBody);
             if (contentChain == null)
             {
                 return null;
             }
             var chainItems = contentChain.ChainElements.Cast<X509ChainElement>().Select((t, i) => AssignCertificate(t, false, null, contentChain, i)).ToList();
             return new ObservableCollection<CertificateModel>(chainItems);
         }))
     };
     if (oS.isHTTPS || (oS.BitFlags & SessionFlags.IsDecryptingTunnel) == SessionFlags.IsDecryptingTunnel)
     {
         Tuple<X509Chain, X509Certificate2> cert;
         if (CertificateInspector.ServerCertificates.TryGetValue(Tuple.Create(oS.hostname, oS.port), out cert))
         {
             var pkp = oS.ResponseHeaders.Exists("public-key-pins") ? oS.ResponseHeaders["public-key-pins"] : null;
             var pkpReportOnly = oS.ResponseHeaders.Exists("public-key-pins-report-only") ? oS.ResponseHeaders["public-key-pins-report-only"] : null;
             var pinnedKeys = pkp == null && pkpReportOnly == null ? null : PublicKeyPinsParser.Parse(pkp ?? pkpReportOnly);
             var reportOnly = pkpReportOnly != null;
             var chain = cert.Item1;
             masterModel.HttpSecurityModel.CertificateChain = new AsyncProperty<ObservableCollection<CertificateModel>>(Task.Factory.StartNew(() =>
             {
                 var chainItems = chain.ChainElements.Cast<X509ChainElement>().Select((t, i) => AssignCertificate(t, reportOnly, pinnedKeys, chain, i)).ToList();
                 return new ObservableCollection<CertificateModel>(chainItems);
             }));
             masterModel.HttpSecurityModel.Hpkp = new HpkpModel
             {
                 HasHpkpHeaders = pinnedKeys != null,
                 RawHpkpHeader = pkp ?? pkpReportOnly,
                 PinDirectives =
                     pinnedKeys == null ? null
                     : new ObservableCollection<HpkpHashModel>(pinnedKeys.PinnedKeys.Select(pk => new HpkpHashModel { Algorithm = pk.Algorithm, HashBase64 = pk.FingerprintBase64 }).ToArray())
             };
         }
     }
     control.DataContext = masterModel;
     _panel.Children.Add(control);
 }
예제 #2
0
        public override void AssignSession(Session oS)
        {
            Clear();
            if (!CertificateInspector.HttpsDecryptionEnabledOnStartup || !CONFIG.bCaptureCONNECT || !CONFIG.bMITM_HTTPS)
            {
                _panel.Children.Add(new System.Windows.Controls.Label {
                    Content = "Fiddler Cert Inspector requires enabling decryption of HTTPS traffic, and restarting Fiddler."
                });
                return;
            }
            if (!CertificateInspector.IsSupportedOperatingSystem)
            {
                _panel.Children.Add(new System.Windows.Controls.Label
                {
                    Content = "Fiddler Cert Inspector requires Windows Vista or Windows Server 2008 or later."
                });
                return;
            }
            var control     = new WpfCertificateControl();
            var masterModel = new CertInspectorModel();

            masterModel.UpdateBarModel                = new UpdateBarModel(CertificateInspector.LatestVersion?.Item1, CertificateInspector.LatestVersion?.Item2);
            masterModel.AskUpdateBarModel             = _askUpdateBarModel;
            masterModel.AskUpdateBarModel.AskRequired = !FiddlerApplication.Prefs.GetBoolPref(PreferenceNames.ASK_CHECK_FOR_UPDATES_PREF, false);
            masterModel.SettingsCommand               = new RelayCommand(_ =>
            {
                var window   = new SettingsWindow();
                var helper   = new WindowInteropHelper(window);
                helper.Owner = FiddlerApplication.UI.Handle;
                window.ShowDialog();
            });
            masterModel.HttpSecurityModel = new HttpSecurityModel
            {
                IsNotTunnel  = (oS.BitFlags & SessionFlags.IsDecryptingTunnel) != SessionFlags.IsDecryptingTunnel,
                ContentChain = new AsyncProperty <ObservableCollection <CertificateModel> >(Task.Factory.StartNew(() =>
                {
                    if (!oS.bHasResponse)
                    {
                        return(null);
                    }
                    var contentChain = ChainForContent(oS.ResponseBody);
                    if (contentChain == null)
                    {
                        return(null);
                    }
                    var chainItems = contentChain.ChainElements.Cast <X509ChainElement>().Select((t, i) => AssignCertificate(t, false, null, contentChain, i)).ToList();
                    return(new ObservableCollection <CertificateModel>(chainItems));
                }))
            };
            if (oS.isHTTPS || (oS.BitFlags & SessionFlags.IsDecryptingTunnel) == SessionFlags.IsDecryptingTunnel)
            {
                Tuple <X509Chain, X509Certificate2> cert;
                if (CertificateInspector.ServerCertificates.TryGetValue(Tuple.Create(oS.hostname, oS.port), out cert))
                {
                    var pkp           = oS.ResponseHeaders.Exists("public-key-pins") ? oS.ResponseHeaders["public-key-pins"] : null;
                    var pkpReportOnly = oS.ResponseHeaders.Exists("public-key-pins-report-only") ? oS.ResponseHeaders["public-key-pins-report-only"] : null;
                    var pinnedKeys    = pkp == null && pkpReportOnly == null ? null : PublicKeyPinsParser.Parse(pkp ?? pkpReportOnly);
                    var reportOnly    = pkpReportOnly != null;
                    var chain         = cert.Item1;
                    masterModel.HttpSecurityModel.CertificateChain = new AsyncProperty <ObservableCollection <CertificateModel> >(Task.Factory.StartNew(() =>
                    {
                        var chainItems = chain.ChainElements.Cast <X509ChainElement>().Select((t, i) => AssignCertificate(t, reportOnly, pinnedKeys, chain, i)).ToList();
                        return(new ObservableCollection <CertificateModel>(chainItems));
                    }));
                    masterModel.HttpSecurityModel.Hpkp = new HpkpModel
                    {
                        HasHpkpHeaders = pinnedKeys != null,
                        RawHpkpHeader  = pkp ?? pkpReportOnly,
                        PinDirectives  =
                            pinnedKeys == null ? null
                            : new ObservableCollection <HpkpHashModel>(pinnedKeys.PinnedKeys.Select(pk => new HpkpHashModel {
                            Algorithm = pk.Algorithm, HashBase64 = pk.FingerprintBase64
                        }).ToArray())
                    };
                }
            }
            control.DataContext = masterModel;
            _panel.Children.Add(control);
        }