Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
I routinely create self subscribed SSL certs for testing purposes. So I wrote this script to automate this process:
#!/usr/bin/perl use strict; use warnings; use IPC::Run qw(start run); my $hostname = shift @ARGV; die "Usage: make_cert HOSTNAME" unless defined $hostname; { print "CREATE THE KEY AND REQUEST:\n\n"; my @cmd = qw(openssl req -new -keyout temp.pem -out temp.csr); my @io = ('Enter PEM pass phrase:', 'test', 'Verifying password - Enter PEM pass phrase:', 'test', 'Country Name.*:', 'UK', 'State.*:', 'Warwickshire', 'Locality Name.*:', 'Kenilworth', 'Organization Name.*:', 'Iponweb Ltd', 'Organizational Unit Name.*:', '', 'Common Name.*:', $hostname, 'Email Address.*', '', 'A challenge password.*:', '', 'An optional company name.*:', ''); expect(cmd => \@cmd, io => \@io); print "\n"; } { print "REMOVE THE PASSPHRASE FROM THE KEY:\n\n"; my @cmd = qw(openssl rsa -in temp.pem -out temp.key); my @io = ('Enter PEM pass phrase:', 'test'); expect(cmd => \@cmd, io => \@io); print "\n"; } { print "CREATE THE KEY AND REQUEST:\n\n"; my @cmd = qw(openssl x509 -in temp.csr -out temp.cert -req -signke +y temp.key -days 365); my @io = (); expect(cmd => \@cmd, io => \@io); print "\n"; } { print "PREPARING FILES:\n\n"; unlink 'temp.csr'; my $cert = $hostname . '.cert'; rename 'temp.cert', $cert; my $key = $hostname . '.key'; rename 'temp.key', $key; print "$cert and $key are ready for usage\n\n"; } sub expect { my %param = @_; my @io = @{$param{io}}; my $out; my $in; my $h = start($param{cmd}, '<pty<', \$in, '>pty>', \$out); my $last_length = 0; while(1) { my $expected = shift @io; last unless defined $expected; my $input = shift @io; last unless defined $input; until($out =~ /\G.*$expected/sgc) { $h->pump; local $| = 1; print substr $out, $last_length; $last_length = length $out; } $in .= $input . "\n"; } $h->finish; print substr $out, $last_length; }

--
Ilya Martynov, ilya@iponweb.net
CTO IPonWEB (UK) Ltd
Quality Perl Programming and Unix Support UK managed @ offshore prices - http://www.iponweb.net
Personal website - http://martynov.org


In reply to SSL certificate generator by IlyaM

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others musing on the Monastery: (7)
    As of 2014-11-29 06:43 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My preferred Perl binaries come from:














      Results (203 votes), past polls