Securityfixes

Fix for unclosed file descriptor and usage of system sha1 library - tested on Solaris.