[osmosis-dev] [PATCH] --upload-xml-change does not send correct credentials

Guillaume Rischard openstreetmap at stereo.lu
Tue Apr 19 12:44:01 BST 2011


Hi everyone,

The --upload-xml-change feature can't log into the API server. The problem seems to come from the conversion of the username:password to Base64.

When running

osmosis -v 9 --rxc file="yourOsmChange.osm" --upload-xml-change user=you password=secret

, instead of uploading the changes, osmosis sends an incorrect username:password string and receives a 401 Authentication required error.

When comparing osmosis and wget tcpdumps, I see that the http credentials they send are different. Wget's credentials string base64-decodes back to my username:password, while osmosis's string doesn't at all.

The problem comes from the base64 conversion that is being done by the apache common codecs library. httpCon.setRequestProperty() expects a String, but gets a byte[] back from encodeBase64. This patch calls encodeBase64String which returns a String instead.

I wonder whether there's something I'm missing. How could it even work in the first place? I haven't been able to compile osmosis (the unit tests fail without a database), but encodeBase64String produces right-looking credentials for me in test code.

What do you think?

Cheers,

Guillaume

Index: xml/src/org/openstreetmap/osmosis/xml/v0_6/XmlChangeUploader.java
===================================================================
--- xml/src/org/openstreetmap/osmosis/xml/v0_6/XmlChangeUploader.java	(revision 25864)
+++ xml/src/org/openstreetmap/osmosis/xml/v0_6/XmlChangeUploader.java	(working copy)
@@ -125,7 +125,7 @@
            // we do not use Authenticator.setDefault()
            // here to stay thread-safe.
            httpCon.setRequestProperty("Authorization", "Basic "
-                    + Base64.encodeBase64(
+                    + Base64.encodeBase64String(
                            (this.myUserName + ":"
                           + this.myPassword).getBytes("UTF8")));

@@ -207,7 +207,7 @@

        // we do not use Authenticator.setDefault() here to stay thread-safe.
        httpCon.setRequestProperty("Authorization", "Basic "
-                + Base64.encodeBase64(
+                + Base64.encodeBase64String(
                        (this.myUserName + ":"
                       + this.myPassword).getBytes("UTF8")));

@@ -251,7 +251,7 @@

        // we do not use Authenticator.setDefault() here to stay thread-safe.
        httpCon.setRequestProperty("Authorization", "Basic "
-                + Base64.encodeBase64(
+                + Base64.encodeBase64String(
                        (this.myUserName + ":"
                       + this.myPassword).getBytes("UTF8")));





More information about the osmosis-dev mailing list