Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

[fixed] Net::XMPP in Win32 gets not-authorized, same code works 100% in Linux

by wilsond (Scribe)
on Jan 09, 2009 at 07:40 UTC ( [id://735105]=perlquestion: print w/replies, xml ) Need Help??

wilsond has asked for the wisdom of the Perl Monks concerning the following question:

Edit: Apparently Net::XMPP is deprecated. Net::XMPP2 seems to replace it. But Net::XMPP2 is deprecated too. AnyEvent::XMPP replaced it. It seems that new XMPP implementations should use AnyEvent::XMPP.


I've written some sample code to test out Net::XMPP for a cross-platform utility. It works great in Linux. It gives "not-authorized" in Windows.

Using strace, I've grabbed the names of all of the perl modules used in Linux with this script. I've tested to ensure that those modules are all installed in Linux. They all appear to be there.

When testing the code, I'm using the same identical code between Linux and Windows. There is no platform-specific code in it.

It doesn't matter if TLS is 0 or 1. It fails both ways. The XMPP server doesn't require TLS.

Any ideas? I'm lost on this one.

Here's the code:

use strict; use Authen::SASL qw(Perl); use Net::XMPP qw(Client); use Megagram::ResolveSRV; my $VERSION = '0.01'; my $xmpp = Net::XMPP::Client->new(); $xmpp->SetCallBacks(message => \&xmppHandler, presence => \&xmppHandler, iq => \&xmppHandler); my $domain = 'example.com'; my $username = 'bobthebuilder'; my $password = 'yeswecan'; sub xmppConnect { my $rsrv = Megagram::ResolveSRV->new; my @hosts = $rsrv->resolve('_xmpp-server._tcp.'.$domain); unless ($hosts[0]) { print qq($domain doesn't appear to offer XMPP service.\n); return undef; } my $status; foreach my $host (@hosts) { my $target = $host->{target}; my $port = $host->{port}; printf("Attempting to connect to %s:%s\n", $target, $port); $status = $xmpp->Connect(hostname => $target, port => $port, componentname => $domain, tls => 1); last if defined($status); } unless (defined($status)) { print qq(ERROR: XMPP service unavailable: $!\n); return undef; } $xmpp->{STREAM}->{SIDS}->{$xmpp->{SESSION}->{id}}->{hostname} = $dom +ain; my @result = $xmpp->AuthSend(username => $username, password => $password, resource => 'TestClient_'.$VERSION); unless ($result[0] eq 'ok') { print qq(ERROR: Auth failed: $result[0] - $result[1]\n); return undef; } $xmpp->RosterGet(); $xmpp->PresenceSend(status => "Testing."); $xmpp->{presence}->{"$username\@$domain"} = "Testing."; return 1; } sub xmppHandler { my ($sid, $event) = @_; my $type = $event->GetType() || $event->{TREE}->{TAG} || 'unknown'; print qq(XMPP-EVENT: $type\n); use Data::Dumper; print Dumper($event); #runModule(command => '_xmpp_'.$type, sid => $sid, event => $event); } while (1) # process loop { if ($xmpp->Connected()) { xmppConnect() if ($xmpp->Process(1) eq undef); } else { xmppConnect() or die(qq(Can't connect to XMPP.\n)); } sleep(1); }

Edit: TLS info

Edit: FIXED! Changing AuthSend to AuthIQAuth makes it work fine. This disables SASL. TLS will take care of the encryption, though. As long as this doesn't irritate the XMPP server when I lock it down, I'm good to go! Thanks everyone for your help. Here's the updated bit of code that "fixed" it:

my @result = $xmpp->AuthIQAuth(username => $username, password => $password, resource => 'TestClient_'.$VERSION);

Replies are listed 'Best First'.
Re: Net::XMPP in Win32 gets not-authorized, same code works 100% in Linux
by Corion (Patriarch) on Jan 09, 2009 at 07:49 UTC

    You're using tls => 1, which suggests to me that Net::XMPP::Client might try to load an SSL libary. Is the appropriate SSL library installed? I couldn't make out in the source which one the module will (try to) use.

    Other than that, I can imagine different line endings as the culprit. I guess you will have to take a look at the difference between the two systems with Wireshark or another network sniffer.

      I forgot to mention: It doesn't work whether it is set to TLS=1 or TLS=0. The XMPP server doesn't require it (I run the server) though I do plan to require it eventually.

      I'll try testing it with wireshark or the like and see what it comes up with. Thanks for the idea. I should have already done this.

        According to wireshark, the packets are being sent properly and such. It uses DIGEST_MD5 as the auth. It appears to be a properly formatted hash that is sent to the XMPP server, but I haven't verified it yet. More testing to go. Thanks for your input.
        I think your problem is actually with XML::Stream. See this ticket for a patch: http://rt.cpan.org/Public/Bug/Display.html?id=24817
Re: Net::XMPP in Win32 gets not-authorized, same code works 100% in Linux
by BrowserUk (Patriarch) on Jan 09, 2009 at 07:47 UTC

      In this part of the code:

      my @result = $xmpp->AuthSend(username => $username, password => $password, resource => 'TestClient_'.$VERSION); unless ($result[0] eq 'ok')

      @result should be ('ok',''), but in Windows it is ('error','not-authorized')

        Okay. The way you originally reported the error it looked like a mis-quoted user permissions error. I know nothing about XMPP, (not even what it was till I looked up the module).

        However, I did notice Net::XMPP::Debug with options for having high and low level calls logged. The output from that might give you some clues where to look.


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://735105]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (8)
As of 2024-04-19 15:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found