.NET 4.0 library fails under mono

Feb 10, 2012 at 2:32 PM
Edited Feb 10, 2012 at 2:35 PM

Due to a bug in mono 2.10.x, System.Security.Cryptography.HashAlgorithm does not have a Dispose() method.  This causes a runtime exception in SshClient's Connect() and Dispose() methods (and possibly in other places too).

I've posted this as a bug against mono (http://bugzilla.xamarin.com/show_bug.cgi?id=3375).  Xamarin can be quite slow to respond though so it might be worth considering a workaround.  The HashAlgorithm class has a Clear() method which offers equivalent functionality to Dispose().  I've tested locally that changing all calls to HashAlgorithm.Dispose() to HashAlgorithm.Clear() works under both MS and mono.

I'm happy to provide diffs but in this case, its maybe as easy to describe the changes.  The only files affected were:

Renci.SshClient\Renci.SshNet\Security\Cryptography\DsaDigitalSignature.cs

Renci.SshClient\Renci.SshNet\Session.cs

The only changes were to replace Dispose() with Clear() for HashAlgorithm members.

Coordinator
Feb 10, 2012 at 2:59 PM

Hi,

I guess I could create another version which compiles for Mono.

Or you saying that I can replace Dispose calls with Clear and it will work for both versions?

If so can you provide me with changes and I will take a look at it later.

Also, can you open it as an issue so I dont forget to look at it since it can get last with all the discussions here.

 

Thanks,

Oleg

Feb 10, 2012 at 3:03 PM

Replacing Dispose calls with Clear will work with both versions.

I'll post this as an issue.

To help me post diffs, can you let me know the format you'l like them in please?  I don't believe I have access to your source control server so I can't use it to help generate diffs.

Coordinator
Feb 10, 2012 at 3:21 PM

ok, thanks.

Well, in the past people used to submit it as a patch, so you can do that if you like or if its few files, then just tell me what and where you changed.

 

Thanks,

Oleg

Coordinator
Feb 10, 2012 at 5:42 PM

Simon,

 

Can you take a look at latest source code?

 

I just checked in the changed need to be made for mono, only the one you described earlier in the post as well as possible memory leak in HMac<T> class.

 

Thanks,

Oleg

Feb 13, 2012 at 8:59 AM
Edited Feb 13, 2012 at 8:59 AM

Hi Oleg

 

Thanks, the changes look good.  Unfortunately I missed one instance of Dispose in my OP.

Renci.SshClient\Renci.SshNet\Security\Cryptography\RsaDigitalSignature.cs:68

also needs to change to call Clear to work on mono.

 

thanks

Simon

Feb 13, 2012 at 1:02 PM

There are also a couple of calls to Dispose remaining in

Renci.SshClient\Renci.SshNet\Session.cs

(_serverMac and _clientMac are both Dispose()d in two places - around lines 1220 & 1940)

Coordinator
Feb 13, 2012 at 1:31 PM

ok, I changed those too now,

 

By the way, I just realized that silverlight does not support dispose methods too so the way we solved that is by adding Dispose extension method that calls to the Clear internally, so may be its a good idea to do something like that for all not mono supported functions. Just an idea.

 

Also, if you wanted to include mono source code project so other people could use it, feel free to let me know.

 

Thanks,

Oleg

Feb 13, 2012 at 1:59 PM

Thanks for fixing this so quickly Oleg!

The current format of the project is perfect for me so I don't need a mono source code project (and also don't have one to contribute).

Simon