898 handle private repositories for ssh

Shall fix #898.
Also includes some refactorings and specs.