Problem authenticating if password contains a @

I’m using the iControl SDK to create a Java application that automates configuring BIG-IP.

If my admin password for BIG-IP does not contain a @, authentication to the BIG-IP host via my Java application works fine. However, if my admin password for BIG-IP contains a @ in it, I get an authentication error because it thinks everything after the @ in the password is part of the hostname since it uses the following url to connect to BIG-IP.

https://user:password@hostname:443/iControl/iControlPortal.cgi

So, if my user is admin and my password is pass@word and my hostname is bigip.company.com, the url used is:

https://admin:pass@word@bigip.company.com:443/iControl/iControlPortal.cgi

So, it incorrectly thinks the password is pass and the hostname is word@bigip.company.com (everythin after the first @ within the password)

So, I encoded the @ in the password as %40 (e.g. pass%40word) to make it url safe since a @ is a reserved character and must be encoded according to url rules. However, authentication is still failing.

This problem appears to be like the one reported at http://devcentral.f5.com/Community/GroupDetails/tabid/1082223/asg/51/afv/topic/aft/30461/aff/1/showtab/groupforums/Default.aspx34413 that was never answered.

When the admin password is pass@word and I specify the encoded version of the password (e.g. pass%40word), I get the following error:

C:\F5\iControl-10.1.0\sdk\samples\soap\java\apache\axis\LocalLB>java -cp .;%JAVA_CLASSPATH% F5ProxySetup 9.99.999.999 443 admin pass%40word

AxisFault

faultCode: {WebServices - Axis}HTTP

faultSubcode:

faultString: (401)F5 Authorization Required

faultActor:

faultNode:

faultDetail:

{}:return code: 401

“http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>

lang=“en”>

Authentication required!

Authentication required!

This server could not verify that you are authorized to access

the URL “/iControl/iControlPortal.cgi”.

You either supplied the wrong credentials (e.g., bad password), or your

browser doesn’t understand how to supply the credentials required.

In case you are allowed to request the document, please

check your user-id and password and try again.

Error 401

Wed Apr 28 14:09:13 2010

{WebServices - Axis}HttpErrorCode:401

(401)F5 Authorization Required

at org.apache.axis.transport.http.HTTPSender.readFromSocket(HTTPSender.java:744)

at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:144)

at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)

at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)

at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)

at org.apache.axis.client.AxisClient.invoke(AxisClient.java:165)

at org.apache.axis.client.Call.invokeEngine(Call.java:2784)

at org.apache.axis.client.Call.invoke(Call.java:2767)

at org.apache.axis.client.Call.invoke(Call.java:2443)

at org.apache.axis.client.Call.invoke(Call.java:2366)

at org.apache.axis.client.Call.invoke(Call.java:1812)

at iControl.LocalLBSNATBindingStub.get_list(LocalLBSNATBindingStub.java:717)

at F5ProxySetup.createSnat(F5ProxySetup.java:70)

at F5ProxySetup.main(F5ProxySetup.java:907)

I’m not sure if this one would ever be fixed… Mainly because the syntax for including the username and password in the URL isn’t actually part of the standard. It’s an extension that (IIRC) Netscape started way back when.

Possibly it would be better to cover yourself, and if there is a reserved character in the pasword (Does / and : do the same thing?) use the basic auth callback instead.

(Ahh… Actually, I’m thinking perl when I say basic auth callback. Presumably the java API has something similar)

H

Yes, other reserved characters in the password cause the same problem.

Do you have any examples for how to “use the basic auth callback” in Java? Or can you point me to any documentation on this?

Sorry, no… I don’t. I use perl for almost all of my iControl work (Where I don’t use perl, I use C).

Try searching around in the iControl codeshare section, there should be examples in there (Or do the Java examples there use the URL notation?). Failing that, manually add the authentication headers into the HTTP request.

H

I also had a thought… What happens if you escape the @ with a backslash? e.g. pass\@word?

H

Escaping the @ with a backslash results in the same error.

Posted By Hamish on 04/30/2010 01:13 AM

Sorry, no… I don’t. I use perl for almost all of my iControl work (Where I don’t use perl, I use C).

Try searching around in the iControl codeshare section, there should be examples in there (Or do the Java examples there use the URL notation?). Failing that, manually add the authentication headers into the HTTP request.

H Hamish - How would you go about manually adding the auth headers into the HTTP request?

Thanks,

-Luke

For whichever language you’re using you should be able to insert an HTTP header in the request. The format should be:

Authorization: Basic abcd

where abcd is a base64 encoding of the username:password. Here’s a wikipedia example for a user of Aladdin and a pass of open sesame:

http://en.wikipedia.org/wiki/Basic\_access\_authentication

Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==

Aaron

Have you tried the iControl library for Java? I’ve got a version that will work with JRE 1.5 and 1.6 and uses the lower level binding classes to set the username/password for the connections. There are binary and source can be found in the iControl Assembly for .Net and Java labs project.

Look in the source\iControl\Interfaces.java class for details on how to use the lower level classes for the authentication headers.

In the “test” directory in the source distribution there are some sample applications that use the Interfaces iControl wrapper class.

Let me know if this works for you.

-Joe

Aaron,

Thanks for the quick response. I’m using C creating a Windows Form app. I have a button that I’m trying to have open a “Network Map” view of a Pool.

Here is what I had originally:

web_ltmview.Url = new Uri("https://" + txt_username.Text + ":" + txt_password.Text + "@" + ltmDerived + ".prci.com/");

Working from a non-F5 related internet article, I tried this (but I’m sure I’ve got something incorrect in here, because it still doesn’t work):

string hdr = "Authorization: Basic" + Convert.ToBase64String(Encoding.ASCII.GetBytes(txt_username.Text + ":" + txt_password.Text)) + System.Environment.NewLine;
 web_ltmview.Navigate("https://" + ltmDerived + ".prci.com/", null, null, hdr);

Thanks in advance…

-Luke

Luke, are your authenticated calls iControl method requests? If so, you should use the iControl Assembly instead of hard coding them yourself. If you just want to create an authenticated request to a web page, then your route would likely work.

-Joe

Joe,

All of the calls that get status or make updates to the configuration are iControl method requests. In the Windows Form App, I have 4 buttons that trigger certain LTM GUI Network Map pages to be presented within the application. Since I’ve already prompted the user for their ID and password, I was just hoping to have the webbrowser control page refresh not require an additional credential challenge. Also, the users will be working with several LTM pairs, and I didn’t want them to have to authenticate to each one that they go to.

I do have to apologize in advance - this is my first coding endeavor, so many of my questions are very rudimentary.

When debugging, it looks like the values are indeed correct:

string hdr = "Authorization: Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes(txt_username.Text + ":" + txt_password.Text)) + "\r\n";
Value of hdr is: "Authorization: Basic bGxlaG1hbjE6 edit lYWtANzE=\r\n"

Thanks again for the help.

- Luke

Also, URL encoding the password seems to work on 10.1 and 10.2:

https://admin:123%40321@hostname/iControl/iControlPortal.cgi

This works to enter the user/pass of admin/123@321

Aaron

I think I’m about 6-8 months away from 10.x, but it is good to know that it will work a little easier in 10.1 & 10.2.

All,

So I guess I somewhat found a way ‘around’ the problem - but I don’t care - it WORKS!!

Credit is due in most part to hoolio for his comment about how url encoding works in 10.x. I thought - "Hey, why don’t I try that in my code. Eureka!

web_ltmview.Url = new Uri(
"https://" +
txt_username.Text +
":" +
System.Web.HttpUtility.UrlEncode(txt_password.Text) +
"@" +
ltmDerived +
".domain.com/" +
"tmui/Control/form?_form_holder_opener_=&handler" +
"=%2Ftmui%2Flocallb%2Fnetwork_map&handler_before=%2Ftmui%2Flocallb%2Fnetwork_map&showObjList=&showObjList_befor" +
"e=&hideObjList=&hideObjList_before=&enableObjList=partition_control&enableObjList_before=&disableObjList=&disa" +
"bleObjList_before=&form_page=%2Ftmui%2Flocallb%2Fnetwork_map.jsp&form_page_before=%2Ftmui%2Flocallb%2Fnetwork_" +
"map.jsp&error_page=%2Ftmui%2Flocallb%2Fnetwork_map.jsp&error_page_before=%2Ftmui%2Flocallb%2Fnetwork_map.jsp&s" +
"how_map=1&show_map_before=0&status_select_before=null&status_select=0&object_type_select_before=null&object_ty" +
"pe_select=&SearchString=" +
txt_serverIp.Text +
"&SearchString_before=*&irule_body_before=unchecked&Show+Summary_before=Show+Summary&Show+Map=Update+Map&Show+M" +
"ap_before=Update+Map"
);

The magic is all here:

System.Web.HttpUtility.UrlEncode(txt_password.Text)

Replaces any special char with a string that doesn’t throw an exception.

Thanks everyone (very very much) !!

-Luke

In trying to execute due diligence, I wanted to implant commented out code for webview loads for v10. So that when we made the upgrade, all I’d have to do is comment out the v9 and uncomment the v10.

It seems that I’ve run into another Auth issue. I’ve tried the existing syntax - which worked in v9:

https://username:password@hostname/uri

I don’t know all the changes in auth from v9 to v10, but I am hoping that the change in code to allow the page to load will be doable.

Thanks!

I’m still trying to figure out why you are passing passwords along in the URI when you can use the lower level classes to do it for you.

I’d recommend using the iControl library for Java that has all the compiled interface proxy code built in with a iControl.Interfaces class wrapper that handles all the self-signed cert and authentication management for you.

The generated binding stub classes are derived from the org.apache.axis.client.Stub class which has a “setPassword()” method in it that allows you to insert the authenticate headers in the request.

If you really don’t want to use the iControl library, and if so, I’d like to hear why, and you aren’t using Apache Axis for the transport library, then the next best approach would be to generate the authenticate header yourself. You’ll want to add a header named “Authorization” with the value of “Basic user:pass” with user:pass being base64 encoded. I’m not sure about the java code to do this, but with Perl, it looks like this:

eval { $SystemInfo->transport->http_request->header
(
    'Authorization' => 
        'Basic ' . MIME::Base64::encode("$sUID:$sPWD", '')
); };

I know there are ways to add HTTP headers with the java libraries so I’m sure the logic would be the same.

This method will work on all versions of LTM back to 4.5.

-Joe

-Joe

Ahhh, now I see why you aren’t using the iControl libraries, because you are trying to do a grab of the admin GUI. If so, then my approach should work with the Authentication header.

-Joe

Thanks for the replies Joe.

Yep, I’m just grabbing a view of the GUI in a web control. I’ve tried the Authentication header addition and either it doesn’t work or I’m doing something wrong (probably the latter…)

string hdr = "Authorization: Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes(txt_username.Text + ":" + txt_password.Text)) + "\r\n";
web_ltmview.Navigate("https://" + "hostname.domain.com/", null, null, hdr);

It seems like the GUI authentication works a little differently in v9 as opposed to v10, but I’m not sure how to articulate it…

Once again, sorry for all the questions.

Luke, could you provide the code for the web_ltmview object initialization. I can try to recreate it but I want to make sure I’m using the same classes as you are.

-Joe