Added option to disable certificate checking
authorpkanavos <pkanavos@gmail.com>
Mon, 2 Apr 2012 05:40:03 +0000 (08:40 +0300)
committerpkanavos <pkanavos@gmail.com>
Mon, 2 Apr 2012 05:40:03 +0000 (08:40 +0300)
12 files changed:
trunk/.gitignore
trunk/NetSparkle/NetSparkle.cs
trunk/Pithos.Client.WPF/App.xaml.cs
trunk/Pithos.Client.WPF/Configuration/PithosSettings.cs
trunk/Pithos.Client.WPF/Preferences/PreferencesView.xaml
trunk/Pithos.Client.WPF/Preferences/PreferencesViewModel.cs
trunk/Pithos.Client.WPF/Properties/Settings.Designer.cs
trunk/Pithos.Client.WPF/Properties/Settings.settings
trunk/Pithos.Client.WPF/app.config
trunk/Pithos.Core/Agents/CloudTransferAction.cs
trunk/Pithos.Network/CloudFilesClient.cs
trunk/Pithos.Network/WebExtensions.cs

index 2b67b7b..8b093f6 100644 (file)
@@ -105,3 +105,7 @@ ignore[.-]*
 svnignore[.-]*
 lint.db
 *.vs10x
+
+*.vsp
+*.ctl
+*.psess
\ No newline at end of file
index e48ebdd..b28fe5f 100644 (file)
@@ -555,9 +555,10 @@ namespace AppLimit.NetSparkle
                 UpdateSystemProfileInformation(config);
 
                 // check if update is required
-                NetSparkleAppCastItem latestVersion = null;
+                NetSparkleAppCastItem latestVersion =null;
                 bUpdateRequired = IsUpdateRequired(config, out latestVersion);
-                this.LatestVersion = latestVersion.Version??"";                
+                if (latestVersion!=null)
+                    this.LatestVersion = latestVersion.Version??"";                
                 if (!bUpdateRequired)
                     goto WaitSection;
 
index 85f41c0..86e35ce 100644 (file)
@@ -43,6 +43,7 @@ using System;
 using System.Collections.Generic;
 using System.IO;
 using System.Linq;
+using System.Net;
 using System.Reflection;
 using System.Text;
 using System.Threading;
@@ -86,6 +87,9 @@ namespace Pithos.Client.WPF
                 Settings.Default.UseDefaultProxy = true;
             }
 
+            if (Settings.Default.IgnoreCertificateErrors)
+                ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, errors) => true;
+
 
             InitializeComponent();            
         }       
index 01866a4..fa24bab 100644 (file)
@@ -248,6 +248,16 @@ namespace Pithos.Client.WPF.Configuration
             }
         }
 
+        public bool IgnoreCertificateErrors
+        {
+            get { return _settings.IgnoreCertificateErrors; }
+            set
+            {
+                _settings.IgnoreCertificateErrors = value;
+
+            }
+        }
+
         private static void SetDebugLevel()
         {
             var loggerRepository = (Hierarchy) log4net.LogManager.GetRepository();
index ebe6a29..74a7d92 100644 (file)
                         <CheckBox Content="Enable Debug Logging" Height="16" HorizontalAlignment="Left" Margin="5,10,5,5" Name="DebugLoggingEnabled" VerticalAlignment="Top"/>
                         <Button x:Name="OpenLogPath" Content="Open Log Path" HorizontalAlignment="Left" Margin="5" Style="{StaticResource ButtonStyle}" Width="Auto"/>
                         <Button x:Name="OpenLogConsole" Content="Open Log Console" HorizontalAlignment="Left" Margin="5" Style="{StaticResource ButtonStyle}" Width="Auto" Visibility="Collapsed"/>
+                        <CheckBox Content="Ignore Certificate Errors" Height="16" HorizontalAlignment="Left" Margin="5,10,5,5" Name="IgnoreCertificateErrors" VerticalAlignment="Top"/>
                         </StackPanel>
                     </GroupBox>
                 </WrapPanel>
index 88ef03c..39707cb 100644 (file)
@@ -46,6 +46,7 @@ using System.Collections.Generic;
 using System.ComponentModel.Composition;
 using System.Diagnostics;
 using System.IO;
+using System.Net;
 using System.Reflection;
 using System.Threading.Tasks;
 using System.Windows;
@@ -333,6 +334,13 @@ namespace Pithos.Client.WPF.Preferences
             }
 
             NotifyOfPropertyChange(()=>Settings);
+
+            if (IgnoreCertificateErrors)
+                ServicePointManager.ServerCertificateValidationCallback= (sender,certificate,chain,errors)=> true;
+            else
+            {
+                ServicePointManager.ServerCertificateValidationCallback = null;
+            }
         }
 
      /*   public void ChangePithosFolder()
@@ -496,6 +504,15 @@ namespace Pithos.Client.WPF.Preferences
                 NotifyOfPropertyChange(()=>DebugLoggingEnabled);
             }
         }
+
+        public bool IgnoreCertificateErrors
+        {
+            get { return Settings.IgnoreCertificateErrors; }
+            set {
+                Settings.IgnoreCertificateErrors = value;
+                NotifyOfPropertyChange(() => IgnoreCertificateErrors);
+            }
+        }
        
         #endregion
 
index e4fc7b8..3f754ec 100644 (file)
@@ -1,7 +1,7 @@
 //------------------------------------------------------------------------------
 // <auto-generated>
 //     This code was generated by a tool.
-//     Runtime Version:4.0.30319.488
+//     Runtime Version:4.0.30319.530
 //
 //     Changes to this file may cause incorrect behavior and will be lost if
 //     the code is regenerated.
@@ -374,5 +374,17 @@ namespace Pithos.Client.WPF.Properties {
                 this["DebugLoggingEnabled"] = value;
             }
         }
+        
+        [global::System.Configuration.UserScopedSettingAttribute()]
+        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+        [global::System.Configuration.DefaultSettingValueAttribute("False")]
+        public bool IgnoreCertificateErrors {
+            get {
+                return ((bool)(this["IgnoreCertificateErrors"]));
+            }
+            set {
+                this["IgnoreCertificateErrors"] = value;
+            }
+        }
     }
 }
index 2f011dc..eb7e09f 100644 (file)
@@ -95,5 +95,8 @@
     <Setting Name="DebugLoggingEnabled" Type="System.Boolean" Scope="User">
       <Value Profile="(Default)">False</Value>
     </Setting>
+    <Setting Name="IgnoreCertificateErrors" Type="System.Boolean" Scope="User">
+      <Value Profile="(Default)">False</Value>
+    </Setting>
   </Settings>
 </SettingsFile>
\ No newline at end of file
index b56069f..dda7245 100644 (file)
       <setting name="DebugLoggingEnabled" serializeAs="String">
         <value>False</value>
       </setting>
+      <setting name="IgnoreCertificateErrors" serializeAs="String">
+        <value>False</value>
+      </setting>
     </Pithos.Client.WPF.Properties.Settings>
   </userSettings>
   <startup>
index 5576df1..cb180d6 100644 (file)
@@ -99,6 +99,9 @@ namespace Pithos.Core.Agents
         public CloudAction(AccountInfo accountInfo, CloudActionType action, FileSystemInfo localFile, ObjectInfo cloudFile, FileState state, int blockSize, string algorithm)
             : this(accountInfo,action)
         {
+            if(blockSize<=0)
+                throw new ArgumentOutOfRangeException("blockSize");
+            Contract.EndContractBlock();
             LocalFile = localFile.WithProperCapitalization();
             CloudFile = cloudFile;
             FileState = state;
index d2993ce..e11b4d6 100644 (file)
@@ -1055,12 +1055,13 @@ namespace Pithos.Network
                 {
                     var ex = t.Exception.InnerException;
                     var we = ex as WebException;
+                    
                     var response = we.Response as HttpWebResponse;
                     if (response!=null && response.StatusCode==HttpStatusCode.Conflict)
                     {
                         //In case of 409 the missing parts will be in the response content                        
                         using (var stream = response.GetResponseStream())
-                        using(var reader=stream.GetLoggedReader(Log))
+                        using(var reader=stream.GetLoggedReader(Log,response.ContentLength))
                         {
                             //We used to have to cleanup the content before returning it because it contains
                             //error content after the list of hashes
index 7aed40b..66b8e6d 100644 (file)
@@ -36,15 +36,17 @@ namespace Pithos.Network
             }
         }
 
-        public static TextReader GetLoggedReader(this Stream stream,ILog log)
+        public static TextReader GetLoggedReader(this Stream stream, ILog log, long contentLength)
         {
-            TextReader reader = new StreamReader(stream);
+            var reader = new StreamReader(stream);
             if (!log.IsDebugEnabled)
                 return reader;
             
             using (reader)
             {
-                var body = reader.ReadToEnd();
+                var buffer=new char[contentLength];
+                var read=reader.Read(buffer, 0, (int)contentLength);
+                var body = new string(buffer,0,read); //reader.ReadToEnd();
                 log.DebugFormat("JSON response: {0}", body);
                 return new StringReader(body);
             }