Parse::SNI - parse Server Name Indication from TLS handshake
use Parse::SNI; use IO::Socket; my $srv = IO::Socket::INET->new( LocalAddr => 'localhost', LocalPort => 443, Listen => 1 ) or die $@; while ( my $cli = $srv->accept() ) { $cli->sysread( my $buf, 4096 ) or next; my $sni = parse_sni($buf); }
Tries to parse SNI from the passed data string, which should contain complete initial TLS handshake record from the client. On success returns SNI string in scalar context and (SNI string, start position of SNI in $data) in list context. On error dies with human readable message. One of the usefull error message to parse is /Incomplete TLS record: expected \d+ bytes, got \d+/. This may occure when u didn't read all of initial handshake from the client. You should catch it, read remaining message from the client and try again.
(SNI string, start position of SNI in $data)
/Incomplete TLS record: expected \d+ bytes, got \d+/
This function exported by default.
sniproxy
Copyright Oleg G <oleg@cpan.org>.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Parse::SNI, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Parse::SNI
CPAN shell
perl -MCPAN -e shell install Parse::SNI
For more information on module installation, please visit the detailed CPAN module installation guide.