<p>I'm attempting to use an existing CAS server to authenticate login for a Perl CGI web script and am using the <a href="http://search.cpan.org/dist/AuthCAS" rel="nofollow noreferrer">AuthCAS</a> Perl module (v 1.3.1).  I can connect to the CAS server to get the service ticket but when I try to connect to validate the ticket my script returns with the following error from the <a href="http://search.cpan.org/dist/IO-Socket-SSL" rel="nofollow noreferrer">IO::Socket::SSL</a> module:</p>

<pre><code> 500 Can't connect to [CAS Server]:443 (Bad hostname '[CAS Server]') 
 ([CAS Server] substituted for real server name)
</code></pre>

<p>Symptoms/Tests:</p>

<ol>
<li>If I type the generated URL for the authentication into the web browser's location bar it returns just fine with the expected XML snippet.  So it is not a bad host name.</li>
<li>If I generate a script without using the AuthCAS module but using the IO::Socket::SSL module directly to query the CAS server for validation on the generated service ticket the Perl script will run fine from the command line but not in the browser.</li>
<li>If I add the AuthCAS module into the script in item 2, the script no longer works on the command line and still doesn't work in the browser.</li>
</ol>

<p>Here is the bare-bones script that produces the error:</p>

<pre><code>#!/usr/bin/perl
use strict;
use warnings;
use CGI;
use AuthCAS;
use CGI::Carp qw( fatalsToBrowser );

my $id = $ENV{QUERY_STRING};
my $q = new CGI;
my $target = "http://localhost/cgi-bin/testCAS.cgi";

my $cas = new AuthCAS(casUrl =&gt; 'https://cas_server/cas');

if ($id eq ""){
    my $login_url = $cas-&gt;getServerLoginURL($target);
    printf "Location: $login_url\n\n";
    exit 0;
} else {
    print $q-&gt;header();
    print "CAS TEST&lt;br&gt;\n";

    ## When coming back from the CAS server a ticket is provided in the QUERY_STRING
    print "QUERY_STRING = " . $id . "&lt;/br&gt;\n";
    ## $ST should contain the received Service Ticket
    my $ST = $q-&gt;param('ticket');
    my $user = $cas-&gt;validateST($target, $ST);  #### This is what fails

    printf "Error: %s\n", &amp;AuthCAS::get_errors() unless (defined $user);
}
</code></pre>

<p>Any ideas on where the conflict might be?</p>

<hr>

<p>The error is coming from the line directly above the snippet Cebjyre quoted namely</p>

<pre><code>$ssl_socket = new IO::Socket::SSL(%ssl_options);
</code></pre>

<p>namely the socket creation.  All of the input parameters are correct.  I had edited the module to put in debug statements and print out all the parameters just before that call and they are all fine.  Looks like I'm going to have to dive deeper into the IO::Socket::SSL module.</p>

[{'answer_id': 27602, 'author': 'Cebjyre', 'author_id': 1612, 'author_profile': 'https://Stackoverflow.com/users/1612', 'pm_score': -1, 'selected': False, 'text': '<p>Well, from the <a href="http://search.cpan.org/src/OSALAUN/AuthCAS-1.3.1/lib/AuthCAS.pm" rel="nofollow noreferrer">module source</a> it looks like that IO::Socket error is coming from get_https2</p>\n\n<pre><code>[...]\nunless ($ssl_socket) {\n    $errors = sprintf "error %s unable to connect https://%s:%s/\\n",&amp;IO::Socket::SSL::errstr,$host,$port;\n    return undef;\n}\n[...]\n</code></pre>\n\n<p>which is called by callCAS, which is called by validateST.</p>\n\n<p>One option is to temporarily edit the module file to put some debug statements in if you can, but if I had to guess, I\'d say the casUrl you are supplying isn\'t matching up to the _parse_url regex properly - maybe you have three slashes after the https?</p>\n'}, {'answer_id': 30538, 'author': 'dagorym', 'author_id': 171, 'author_profile': 'https://Stackoverflow.com/users/171', 'pm_score': 3, 'selected': True, 'text': '<p>As usually happens when I post questions like this, I found the problem.  It turns out the <a href="http://search.cpan.org/dist/Crypt-SSLeay" rel="nofollow noreferrer">Crypt::SSLeay</a> module was not installed or at least not up to date.  Of course the error messages didn\'t give me any clues.  Updating it and all the problems go away and things are working fine now.</p>\n'}]
['https://Stackoverflow.com/questions/26842', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/171/']