GSoC’19 :: Milestone 2

The second part of Milestone 1 for my Google Summer of Code 2019’s project porting KDE Connect to Windows involves enabling the SFTP plugin that ships in the linux build.

The plugin allows you to navigate through your mobile device’s files (like you do with a file manager) ON YOUR DESKTOP! It makes use of sshfs to allow mounting the remote file system on your desktop. After that, you can use any file manager you like; heck, you can even use your terminal to have a walk through your mobile’s files. Once that is done, you can do literally anything with the mobile device’s files as you would do with the local filesystem: move files, copy them to your desktop machine, delete them, rename, anything!

How it works?

The plugin, like all other plugins, has two parts that comprise the plugin: the desktop side (could be Linux, Windows or OS X) and the mobile side (could be Android, Plasma Mobile or Sailfish OS).

Desktop Side

To start the plugin, the simplest way is to use the Browse device button from the device options.

> Send file? > >The SFTP Plugin concerns with the Browse device button only. The Send file button allows you to send one file to the connected device. It has different code and does not share functionality with Browse device.

Dev Notes: Invocation?

Clicking on the button invokes startBrowsing() function, which is the starting point for this plugin. After that, mounter object handles the connecting part of the SSHFS functionality.

Mobile side

Between the startBrowsing() function invocation and mounter object instantiation, the mobile is invoked by the desktop, to which the mobile replies with a packet containing: IP address, port, password, username and path for the desktop to connect to the mobile.

Dev Notes: Security?

To make the connection secure, the both devices save each other’s identity during the pairing phase, and no other device can then use the password and the address of the mobile device even if they are able to decrypt the already encrypted packet that carries the credentials for the SFTP plugin to the desktop.

For the interested, you can have a look at the encryption information in the app as well. All communications over KDE Connect are end-to-end encrypted.

Encryption Info shows the SHA1 fingerprint of both devices on the mobile! 😀

Getting SSHFS Working on the Windows 10

Working with KDE Connect, a free software, it is simply against the principle to opt for, or even recommend using any proprietary software for any part of the functionality that KDE Connect provides. Naturally, my mentors suggested me to find any open alternatives that could enable me use SSHFS on windows.

Attempt 01 : SSHFS-Win

As the site reads-

> SSHFS-Win is a minimal port of SSHFS to Windows. Under the hood it uses Cygwin for the POSIX environment and WinFsp for the FUSE functionality.

While the demonstrations looked promising, I could not get it to work with my test system. I tried using all the various methods as described in the documentation of the project, but sadly the solution simply was not able to connect to the device. The connection kept resetting, so it couldn’t be about the credentials either. I tried making it work for a couple days, but then I had to move on to the next one.

> NOTE: I also did try to just make a connection manually with the credentials through the GUI frontend Sirikali– same fate 🙁

Attempt 02 : Win-SSHFS

While Win-SSHFS supports Windows 10 on-paper, I was still unable to make use of Win-SSHFS, same error.

close but, not quite

Attempt 03 : SFTP Net Drive

While not exactly an attempt, I started doubting if these credentials were any good at all! I installed the trial version of SFTP Net Drive, and surprisingly, I was able to atleast get a taste of the sweet SFTP goodness on Windows!

see? not impossible!
works, but proprietary tech :/

Attempt 04 : Swish

This final attempt at getting the SSHFS bit working took most of the two weeks previously allotted to the SFTP plugin. To test whether this works or not, I tried out the latest release available at the time of testing. It works, yes.

The sad parts about Swish are-

  1. not maintained anymore
  2. uses a whole different package manager(Hunter package manager) to manage dependencies.

For the first part, since it was already working, I decided to go for Swish (hey, it works!) so we get SSHFS in. I could work on fixing any new limitations that the project faces, over time.

Now, as I went ahead with the dissection of the project’s build process, the second part started getting weirder and tougher with every turn. Not only the project uses a lot of alamaison’s own projects, the code base itself is based on MSVC 2013! There had already been a lot of changes and deprecation, now that I build with MSVC 2019.

The other ported software(with tests DISABLED) are available as my forks-

  • comet: https://github.com/brute4s99/comet
  • washer: https://github.com/brute4s99/washer
  • wtl: https://github.com/brute4s99/wtl

I also got to build Craft blueprints for a boost library as well 😀

  • boost-locale.py : https://github.com/KDE/craft-blueprints-kde/blob/brute4s99/swish/libs/boost/boost-locale/boost-locale.py

Albeit, the two weeks were wasted because the project was practically unusable to build anew with MSVC 19.

Next up, we decided to step back and look at the way the SFTP plugin worked prior to SSHFS.

The Solution

As you can tell by the code here, the prior implementation used to access the SFTP server (or mobile) using KIO. The SFTP plugin of KIO was again, not maintained for Windows.

Detour to kio-extras

The SFTP plugin is a part of kio-extras, which houses a lot of other plugins as well. These plugins increase the functionality of KIO, that may be used by applications that deal with input output protocols like SFTP et al.

The plugin’s functionality was not much difficult to navigate through; it had simple, easy to read functions for various activities one might perform when dealing with SFTP.

> Oh well, the patch to fix SFTP just got accepted and I just landed it. Neat!

Next up, patching the plugin in KDE Connect

With a few lines of code, a patch is under review at KDE invent. Apply this patch to get the button in the device menu like in the image (way) above.

After applying this patch, clicking the Browse device button will initiate the connection through the SFTP plugin of kio-extras, and that will pop up a dialog box with pre-filled password box. Just click OK and the connection will be made, after which an sftp:// URI is invoked for the system to start browsing. Sadly, windows systems do not ship with inbuilt support for sftp:// URIs. So, for this last bit, you can install any third party software that can provide you the missing functionality (eg: WinSCP is a good one!). After this, you will be able to navigate across your mobile device’s filesystem like your local drives!

you can use WinSCP or any other file manager that supports sftp:// URI handling

You can also download WinSCP from the Windows Store if you wish to donate to them along the way! The setup from the official website is completely free of charge!

As it stands, here is a demonstration of the KDE Connect’s SFTP plugin for Windows-

[youtube https://www.youtube.com/watch?v=h2bZxkGzfWQ&w=560&h=315]