Revision 0e1acc13

b/trunk/Pithos.Client.WPF/App.xaml.cs
45 45
using System.Linq;
46 46
using System.Net;
47 47
using System.Reflection;
48
using System.Security.Cryptography;
48 49
using System.Text;
49 50
using System.Threading;
50 51
using System.Threading.Tasks;
......
53 54
using Pithos.Client.WPF.Configuration;
54 55
using Pithos.Client.WPF.Properties;
55 56
using Pithos.Interfaces;
57
using Pithos.Network;
56 58
using log4net.Appender;
57 59
using log4net.Core;
58 60
using log4net.Repository.Hierarchy;
......
78 80
            //var instanceMutex=new Mutex()
79 81
            InitializeLogging();
80 82

  
81
            
83
            RegisterOpenSSL();
84

  
82 85

  
83 86
            //Detect OS, if Major Version is 6+ use RestartManager
84 87
            OperatingSystem os = Environment.OSVersion;
......
110 113
            InitializeComponent();            
111 114
        }
112 115

  
116
        private static void RegisterOpenSSL()
117
        {
118

  
119
            //Try to instantiate OpenSSL and hash an empty array
120
            try
121
            {
122
                using(var testHasher=new SHA256OpenSSL())
123
                {
124
                    testHasher.ComputeHash(new byte[0]);
125
                }
126
                CryptoConfig.AddAlgorithm(typeof(SHA256OpenSSL), "SHA256");
127
                Log.InfoFormat("Registered OpenSSL hash provider");
128
            }
129
            catch (Exception exc)
130
            {
131
                Log.WarnFormat("OpenSSL instantiation failed. Falling back to CNG provider.\r\n[{0}]",exc);                
132
            }
133
            //Running on Vista + ?
134
            if (Environment.OSVersion.Version.Major >= 6)
135
            {
136
                CryptoConfig.AddAlgorithm(typeof(SHA256Cng), "SHA256");
137
                Log.InfoFormat("Registered CNG hash provider");
138
            }
139
            else
140
            {
141
                Log.WarnFormat("Running on XP. Falling back to default hash algorithm.");
142
            }
143

  
144
            
145
        }
146

  
113 147

  
114 148
/*        private static string[] platformLibraries = {"libeay32.dll","ssleay32.dll"};
115 149
        private static Assembly CustomResolve(object sender,ResolveEventArgs args)
b/trunk/Pithos.Client.WPF/Properties/Settings.Designer.cs
389 389
        
390 390
        [global::System.Configuration.ApplicationScopedSettingAttribute()]
391 391
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
392
        [global::System.Configuration.DefaultSettingValueAttribute(@"<?xml version=""1.0"" encoding=""utf-16""?>
393
<ArrayOfServerSettings xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
394
  <ServerSettings>
395
<ServerName>Pithos Production</ServerName>
396
    <ServerUri>https://pithos.okeanos.grnet.gr</ServerUri>
397
    <LoginUri>https://pithos.okeanos.grnet.gr/login</LoginUri>
398
    <LogoutUri>https://accounts.okeanos.grnet.gr/im/logout</LogoutUri>
399
  </ServerSettings>
400
  <ServerSettings>
401
<ServerName>Pithos Development</ServerName>
402
    <ServerUri>https://pithos.dev.grnet.gr</ServerUri>
403
    <LoginUri>https://pithos.dev.grnet.gr/login</LoginUri>
404
    <LogoutUri>https://pithos.dev.grnet.gr/im/logout</LogoutUri>
405
  </ServerSettings>
406
</ArrayOfServerSettings>")]
392
        [global::System.Configuration.DefaultSettingValueAttribute(@"
393
          <ArrayOfServerSettings xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
394
            <ServerSettings>
395
              <ServerName>Pithos Production</ServerName>
396
              <ServerUri>https://pithos.okeanos.grnet.gr</ServerUri>
397
              <LoginUri>https://pithos.okeanos.grnet.gr/login</LoginUri>
398
              <LogoutUri>https://accounts.okeanos.grnet.gr/im/logout</LogoutUri>
399
            </ServerSettings>
400
            <ServerSettings>
401
              <ServerName>Pithos Development</ServerName>
402
              <ServerUri>https://pithos.dev.grnet.gr</ServerUri>
403
              <LoginUri>https://pithos.dev.grnet.gr/login</LoginUri>
404
              <LogoutUri>https://pithos.dev.grnet.gr/im/logout</LogoutUri>
405
            </ServerSettings>
406
          </ArrayOfServerSettings>
407
        ")]
407 408
        public global::Pithos.Interfaces.ServersCollection Servers {
408 409
            get {
409 410
                return ((global::Pithos.Interfaces.ServersCollection)(this["Servers"]));
b/trunk/Pithos.Client.WPF/Properties/Settings.settings
99 99
      <Value Profile="(Default)">False</Value>
100 100
    </Setting>
101 101
    <Setting Name="Servers" Type="Pithos.Interfaces.ServersCollection" Scope="Application">
102
      <Value Profile="(Default)">&lt;?xml version="1.0" encoding="utf-16"?&gt;
103
&lt;ArrayOfServerSettings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
104
  &lt;ServerSettings&gt;
105
&lt;ServerName&gt;Pithos Production&lt;/ServerName&gt;
106
    &lt;ServerUri&gt;https://pithos.okeanos.grnet.gr&lt;/ServerUri&gt;
107
    &lt;LoginUri&gt;https://pithos.okeanos.grnet.gr/login&lt;/LoginUri&gt;
108
    &lt;LogoutUri&gt;https://accounts.okeanos.grnet.gr/im/logout&lt;/LogoutUri&gt;
109
  &lt;/ServerSettings&gt;
110
  &lt;ServerSettings&gt;
111
&lt;ServerName&gt;Pithos Development&lt;/ServerName&gt;
112
    &lt;ServerUri&gt;https://pithos.dev.grnet.gr&lt;/ServerUri&gt;
113
    &lt;LoginUri&gt;https://pithos.dev.grnet.gr/login&lt;/LoginUri&gt;
114
    &lt;LogoutUri&gt;https://pithos.dev.grnet.gr/im/logout&lt;/LogoutUri&gt;
115
  &lt;/ServerSettings&gt;
116
&lt;/ArrayOfServerSettings&gt;</Value>
102
      <Value Profile="(Default)">
103
          &lt;ArrayOfServerSettings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
104
            &lt;ServerSettings&gt;
105
              &lt;ServerName&gt;Pithos Production&lt;/ServerName&gt;
106
              &lt;ServerUri&gt;https://pithos.okeanos.grnet.gr&lt;/ServerUri&gt;
107
              &lt;LoginUri&gt;https://pithos.okeanos.grnet.gr/login&lt;/LoginUri&gt;
108
              &lt;LogoutUri&gt;https://accounts.okeanos.grnet.gr/im/logout&lt;/LogoutUri&gt;
109
            &lt;/ServerSettings&gt;
110
            &lt;ServerSettings&gt;
111
              &lt;ServerName&gt;Pithos Development&lt;/ServerName&gt;
112
              &lt;ServerUri&gt;https://pithos.dev.grnet.gr&lt;/ServerUri&gt;
113
              &lt;LoginUri&gt;https://pithos.dev.grnet.gr/login&lt;/LoginUri&gt;
114
              &lt;LogoutUri&gt;https://pithos.dev.grnet.gr/im/logout&lt;/LogoutUri&gt;
115
            &lt;/ServerSettings&gt;
116
          &lt;/ArrayOfServerSettings&gt;
117
        </Value>
117 118
    </Setting>
118 119
  </Settings>
119 120
</SettingsFile>
b/trunk/Pithos.Client.WPF/app.config
138 138
      </setting>
139 139
      <setting name="Servers" serializeAs="Xml">
140 140
        <value>
141
          <ArrayOfServerSettings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
142
            xmlns:xsd="http://www.w3.org/2001/XMLSchema">
141
          <ArrayOfServerSettings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
143 142
            <ServerSettings>
144 143
              <ServerName>Pithos Production</ServerName>
145 144
              <ServerUri>https://pithos.okeanos.grnet.gr</ServerUri>
......
172 171
      </filter>
173 172
    </appender>
174 173
    <appender name="DumpFileAppender" type="log4net.Appender.RollingFileAppender">
175
      <file type="log4net.Util.PatternString"  value="%env{LOCALAPPDATA}\GRNET\PITHOS\errorlog.xml" />
174
      <file type="log4net.Util.PatternString" value="%env{LOCALAPPDATA}\GRNET\PITHOS\errorlog.xml" />
176 175
      <appendToFile value="false" />
177 176
      <rollingStyle value="Size" />
178 177
      <maxSizeRollBackups value="10" />
......
181 180
      <layout type="log4net.Layout.XMLLayout" />
182 181
    </appender>
183 182
    <appender name="DebugFileAppender" type="log4net.Appender.RollingFileAppender">
184
      <file type="log4net.Util.PatternString"  value="%env{LOCALAPPDATA}\GRNET\PITHOS\debuglog.xml" />
183
      <file type="log4net.Util.PatternString" value="%env{LOCALAPPDATA}\GRNET\PITHOS\debuglog.xml" />
185 184
      <appendToFile value="true" />
186 185
      <rollingStyle value="Size" />
187 186
      <maxSizeRollBackups value="10" />
......
190 189
      <layout type="log4net.Layout.XMLLayout" />
191 190
    </appender>
192 191
    <appender name="NetworkFileAppender" type="log4net.Appender.RollingFileAppender">
193
      <file type="log4net.Util.PatternString"  value="%env{LOCALAPPDATA}\GRNET\PITHOS\network.log" />
192
      <file type="log4net.Util.PatternString" value="%env{LOCALAPPDATA}\GRNET\PITHOS\network.log" />
194 193
      <appendToFile value="true" />
195 194
      <rollingStyle value="Size" />
196 195
      <maxSizeRollBackups value="10" />
b/trunk/Pithos.Core/Agents/BlockUpdater.cs
238 238
                                }
239 239
                                catch (IOException)
240 240
                                {
241
                                    if (i>=3)
241
                                    if (i>=2)
242 242
                                        throw;
243
                                    Thread.Sleep(100);
243
                                    Thread.Sleep((i+1)*300);
244 244
                                }                                
245 245
                            }
246 246
                        }
b/trunk/Pithos.Network/BlockHashAlgorithms.cs
43 43
using System.Diagnostics.Contracts;
44 44
using System.IO;
45 45
using System.Reflection;
46
using System.Security.Cryptography;
46 47
using System.ServiceModel.Channels;
47 48
using System.Threading;
48 49
using System.Threading.Tasks;
49 50
using System.Threading.Tasks.Dataflow;
50
using OpenSSL.Crypto;
51

  
51 52

  
52 53
namespace Pithos.Network
53 54
{
......
251 252
            if (size == 0)
252 253
            {
253 254
                var buf = new byte[0];
254
                using (var hasher = new MessageDigestContext(MessageDigest.CreateByName(algorithm)))
255
                {                    
256
                    hasher.Init();
257
                    hashes[0] = hasher.Digest(buf);
255
                using (var hasher = HashAlgorithm.Create(algorithm))
256
                {
257
                    hashes[0] = hasher.ComputeHash(buf);
258 258
                    return hashes;
259 259
                }
260 260
            }
......
264 264
            var actualHashers = parallelism > blocks ? (byte)blocks : parallelism;
265 265

  
266 266
            var buffer = new byte[actualHashers][];
267
            var hashers = new MessageDigestContext[actualHashers];
267
            var hashers = new HashAlgorithm[actualHashers];
268 268
            var bufferManager = GetBufferManager(blockSize, actualHashers);
269 269
            for (var i = 0; i < actualHashers; i++)
270 270
            {
271 271
                buffer[i] = bufferManager.TakeBuffer(blockSize);// new byte[blockSize];
272
                hashers[i] = new MessageDigestContext(MessageDigest.CreateByName(algorithm));
273
                hashers[i].Init();
272
                hashers[i] = HashAlgorithm.Create(algorithm);                
274 273
            }
275 274
            try
276 275
            {
......
307 306

  
308 307
                                                            var hasher = hashers[idx];
309 308

  
310
                                                            byte[] hash;
309
                                                            byte[] hash=hasher.ComputeHash(buffer[idx],0,lastByteIndex+1);
310
/*
311 311
                                                            if (buffer[idx].Length == lastByteIndex || lastByteIndex==-1)
312 312
                                                                hash = hasher.Digest(buffer[idx]);
313 313
                                                            else
......
316 316
                                                                Buffer.BlockCopy(buffer[idx],0,buf,0,lastByteIndex+1);
317 317
                                                                hash = hasher.Digest(buf);
318 318
                                                            }
319
*/
319 320

  
320 321
                                                            
321 322
                                                            
b/trunk/Pithos.Network/SHA1OpenSSL.cs
51 51
            }
52 52
        }
53 53
    }
54
    
55
    public class SHA256OpenSSL : SHA256
56
    {
57

  
58
        private MessageDigestContext _context;
59

  
60
        public SHA256OpenSSL()
61
        {
62
            _context = new MessageDigestContext(MessageDigest.CreateByName("SHA256"));
63
            _context.Init();
64
        }
65

  
66
        public override void Initialize()
67
        {
68
            _context.Init();
69
        }
70

  
71
        protected override void HashCore(byte[] array, int ibStart, int cbSize)
72
        {
73
            if (array.Length == cbSize)
74
                _context.Update(array);
75
            else
76
            {
77
                var block = new byte[cbSize];
78
                Buffer.BlockCopy(array, ibStart, block, 0, cbSize);
79
                _context.Update(block);
80
            }
81
        }
82

  
83
        protected override byte[] HashFinal()
84
        {
85
            return _context.DigestFinal();
86
        }
87

  
88
        protected override void Dispose(bool disposing)
89
        {
90
            base.Dispose(disposing);
91
            if (disposing)
92
            {
93
                if (_context != null)
94
                    _context.Dispose();
95
                _context = null;
96
            }
97
        }
98
    }
54 99
}

Also available in: Unified diff