One of the projects I’ve been working on has been to improve aspects of the Ubuntu One Developer Documentation web site. While there are still some layout problems we are working on, it is now in a state where it is a lot easier for us to update.
I have been working on updating our authentication/authorisation documentation and revising some of the file storage documentation (the API used by the mobile Ubuntu One clients). To help verify that the documentation was useful, I wrote a small program to exercise those APIs. The result is u1ftp: a program that exposes a user’s files via an FTP daemon running on localhost. In conjunction with the OS file manager or a dedicated FTP client, this can be used to conveniently access your files on a system without the full Ubuntu One client installed.
You can download the program from:
To make it easy to run on as many systems as possible, I packaged it up as a runnable zip file so can be run directly by the Python interpreter. As well as a Python interpreter, you will need the following installed to run it:
- On Linux systems, either the gnomekeyring extension (if you are using a GNOME derived desktop), or PyKDE4 (if you have a KDE derived desktop).
- On Windows, you will need pywin32.
- On MacOS X, you shouldn’t need any additional modules.
These could not be included in the zip file because they are extension modules rather than pure Python.
Once you’ve downloaded the program, you can run it with the following command:
This will start the FTP server listening at ftp://localhost:2121/. Pointing a file manager at that URL should prompt you to log in, where you can use your standard Ubuntu One credentials and start browsing your files. It will verify the credentials against the Ubuntu SSO service and issue an OAuth token that it stores in the keyring. The OAuth token is then used to authenticate requests to the file storage REST API.
While I expect this program to be useful on its own, it was also intended to act as an example of how the Ubuntu One API can be used. One way to browse the source is to simply unzip the package and poke around. Alternatively, you can check out the source directly from Launchpad:
bzr branch lp:u1ftp
If you come up with an interesting extension to u1ftp, feel free to upload your changes as a branch on Launchpad.
I’ve been playing with OAuth a bit lately. The OAuth specification fulfills a role that some people saw as a failing of OpenID: programmatic access to websites and authenticated web services. The expectation that OpenID would handle these cases seems a bit misguided since the two uses cases are quite different:
- OpenID is designed on the principle of letting arbitrary OpenID providers talk to arbitrary relying parties and vice versa.
- OpenID is intentionally vague about how the provider authenticates the user. The only restriction is that the authentication must be able to fit into a web browsing session between the user and provider.
While these are quite useful features for a decentralised user authentication scheme, the requirements for web service authentication are quite different:
- There is a tighter coupling between the service provider and client. A client designed to talk to a photo sharing service won’t have much luck if you point it at a micro-blogging service.
- Involving a web browser session in the authentication process for individual web service request is not a workable solution: the client might be designed to run offline for instance.
While the idea of a universal web services client is not achievable, there are areas of commonality between different the services: gaining authorisation from the user and authenticating individual requests. This is the area that OAuth targets.
While it has different applications, it is possible to compare some of the choices made in the protocol:
- The secrets for request and access tokens are sent to the client in the clear. So at a minimum, a service provider’s request token URL and access token URL should be served over SSL. OpenID nominally avoids this by using Diffie-Hellman Key Exchange to avoid evesdropping, but ended up needing it to avoid man in the middle attacks. So sending them in the clear is probably a more honest approach.
- Actual web service methods can be authenticated over plain HTTP in a fairly secure means using the HMAC-SHA1 or RSA-SHA1 signature methods. Although if you’re using SSL anyway, the PLAINTEXT authentication method is probably not any worse than HMAC-SHA1.
- The authentication protocol supports both web applications and desktop applications. Though any security gained through consumer secrets is invalidated for desktop applications, since anyone with a copy of the application will necessarily have access to the secrets. A few other points follow on from this:
- The RSA-SHA1 signature method is not appropriate for use by desktop applications. The signature is based only on information available in the web service request and the RSA key associated with the consumer, and the private key will need to be distributed as part of the application. So if an attacker discovers an access token (not access token secret), they can authenticate.
- The other two authentication methods — HMAC-SHA1 and PLAINTEXT — depend on an access token secret. Along with the access token, this is essentially a proxy for the user name and password, so should be protected as such (e.g. via the GNOME keyring). It still sounds better than storing passwords directly, since the token won’t give access to unrelated sites the user happened to use the same password on, and can be revoked independently of changing the password.
- While the OpenID folks found a need for a formal extension mechanism for version 2.0 of that protocol, nothing like that seems to have been added to OAuth. There are now a number of proposed extensions for OAuth, so it probably would have been a good idea. Perhaps it isn’t as big a deal, due to tigher coupling of service providers and consumers, but I could imagine it being useful as the two parties evolve over time.
So the standard seems decent enough, and better than trying to design such a system yourself. Like OpenID, it’ll probably take until the second release of the specification for some of the ambiguities to be taken care of and for wider adoption.
From the Python programmer point of view, things could be better. The library available from the OAuth site seems quite immature and lacks support for a few aspects of the protocol. It looks okay for simpler uses, but may be difficult to extend for use in more complicated projects.