I need to write a script that builds up an SSL connection to a server using a public key received by other means and not directly from the server. If I am not mistaken IO::Socket::SSL in the following code expects the private key of the client and not the public key of the server.
$socket = IO::Socket::SSL->new ( PeerAddr => $ip, PeerPort => $port, Proto => 'tcp', SSL_version => 'SSLv3', SSL_use_cert => 1, SSL_key_file => 'client-key.pem', SSL_cert_file => 'client-cert.pem', );
Is there a way to supply the public key instead of receiving it from the server after some hand shaking?

Update

The solution is simple. After reading up more on SSL I had to convince my bosses that what they want is not that server does not send the public key, neither to put the private key of the server on the client as well (yes, this too came up) but to make sure the client will check the certificate. Once this was done the code is simple:
my $socket = IO::Socket::SSL->new ( PeerAddr => $ip, PeerPort => $port, SSL_ca_file => $cert_file, Proto => 'tcp', SSL_version => 'SSLv3', SSL_verify_mode => 1, ); print $socket ? "OK\n" : "FAILED\n";
Where the $cert_file is the selfsigned certificate. The only minor issue I faced after this is to get the cert file of the server I was actually talking to (and not that of the desktop of the developer...) but this is really only a minor issue.

In reply to Using SSL with fixed public key by szabgab

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.