Handle multiple errors on the stack

This consumes all of the error stack whenever an error occurs. Also makes the unknown-error error message a bit more useful by including the error code and OpenSSLs error string.

I expect further refactoring will be required to generate sensible error messages when e.g. decrypting keys but this is the first step in that direction.

Fixes #466.