certificates ala communigate, RT#7515
authorivan <ivan>
Mon, 8 Nov 2010 00:01:58 +0000 (00:01 +0000)
committerivan <ivan>
Mon, 8 Nov 2010 00:01:58 +0000 (00:01 +0000)
FS/FS/svc_cert.pm
httemplate/edit/process/svc_cert.cgi
httemplate/edit/svc_cert/import_cacert.html [new file with mode: 0644]
httemplate/view/svc_cert.cgi

index 36e7582..b77ff52 100644 (file)
@@ -335,10 +335,13 @@ sub generate_selfsigned {
 #notAfter=Nov  6 05:07:42 2012 GMT
 #serial=B1DBF1A799EF207B
 
 #notAfter=Nov  6 05:07:42 2012 GMT
 #serial=B1DBF1A799EF207B
 
-sub check_certificate {
-  my $self = shift;
+sub check_certificate { shift->check_x509('certificate'); }
+sub check_cacert      { shift->check_x509('cacert');      }
+
+sub check_x509 {
+  my( $self, $field ) = ( shift, shift );
 
 
-  my $in = $self->certificate;
+  my $in = $self->$field;
   run( [qw( openssl x509 -noout -subject -issuer -dates -serial )],
        '<'=>\$in,
        '>pipe'=>\*OUT, '2>'=>'/dev/null'
   run( [qw( openssl x509 -noout -subject -issuer -dates -serial )],
        '<'=>\$in,
        '>pipe'=>\*OUT, '2>'=>'/dev/null'
index a8dc0ca..0e6037e 100644 (file)
@@ -66,6 +66,14 @@ if ( $cgi->param('privatekey') eq '_generate' ) { #generate
   $new->certificate( $cgi->param('certificate') );
   $new->$_( $old->$_ ) for grep $old->$_, qw( recnum common_name organization organization_unit city state country cert_contact );
 
   $new->certificate( $cgi->param('certificate') );
   $new->$_( $old->$_ ) for grep $old->$_, qw( recnum common_name organization organization_unit city state country cert_contact );
 
+} elsif ( $cgi->param('cacert') ) {
+
+  $popup = 'view';
+  $title = 'Certificate authority chain imported';
+
+  $new->cacert( $cgi->param('cacert') );
+  $new->$_( $old->$_ ) for grep $old->$_, qw( recnum common_name organization organization_unit city state country cert_contact );
+
 }
 
 my $error = '';
 }
 
 my $error = '';
diff --git a/httemplate/edit/svc_cert/import_cacert.html b/httemplate/edit/svc_cert/import_cacert.html
new file mode 100644 (file)
index 0000000..bc6f4e7
--- /dev/null
@@ -0,0 +1,22 @@
+<% include('/elements/header-popup.html', 'Import certificate authority chain' ) %>
+
+<% include('/elements/error.html') %>
+
+<FORM NAME="ImportKeyForm" ACTION="<% $p %>process/svc_cert.cgi" METHOD="POST">
+
+<INPUT TYPE="hidden" NAME="svcnum" VALUE="<% $svcnum %>">
+
+<TEXTAREA NAME="cacert" COLS=64 ROWS=15 STYLE="font-family:monospace"></TEXTAREA>
+
+<BR><BR>
+<INPUT TYPE="submit" VALUE="Import">
+
+</FORM>
+</BODY>
+</HTML>
+<%init>
+
+$cgi->param('svcnum') =~ /^(\d*)$/ or die 'illegal svcnum';
+my $svcnum = $1;
+
+</%init>
index 28a269b..48494d2 100644 (file)
@@ -83,8 +83,9 @@ my @fields = (
                     "<TD>$hash{notBefore} - $hash{notAfter}</TD></TR>".
                 '</TABLE>';
 
                     "<TD>$hash{notBefore} - $hash{notAfter}</TD></TR>".
                 '</TABLE>';
 
+        my $svcnum = $svc_cert->svcnum;
+
         if ( $hash{'selfsigned'} ) {
         if ( $hash{'selfsigned'} ) {
-          my $svcnum = $svc_cert->svcnum;
           $out .= qq(<BR> <A HREF="${p}misc/svc_cert-generate.html?action=generate_selfsigned;svcnum=$svcnum">Re-generate self-signed</A>).
                   ' &nbsp; '.
                   include('/elements/popup_link.html', {
           $out .= qq(<BR> <A HREF="${p}misc/svc_cert-generate.html?action=generate_selfsigned;svcnum=$svcnum">Re-generate self-signed</A>).
                   ' &nbsp; '.
                   include('/elements/popup_link.html', {
@@ -113,6 +114,70 @@ my @fields = (
       }
     },
   },
       }
     },
   },
+  { 'field'=>'cacert',
+    'value'=> sub {
+      my $svc_cert = shift;
+      if ( $svc_cert->cacert ) {
+
+        my %hash = $svc_cert->check_cacert;
+
+        tie my %w, 'Tie::IxHash',
+          'subject' => 'Issued to',
+          'issuer'  => 'Issued by',
+        ;
+
+        my $out = '<TABLE><TR><TD>';
+
+        foreach my $w ( keys %w ) {
+
+          $out .= include('/elements/table-grid.html'). #'<TABLE>'.
+                  '<TR><TH COLSPAN=2 BGCOLOR="#cccccc" ALIGN="center">'.
+                  $w{$w}. '</TH></TR>';
+
+          my $col = $svc_cert->subj_col;
+
+          my $subj = $hash{$w};
+          foreach my $key (keys %$col) { #( keys %$subj ) {
+            $out .= "<TR><TD>". $labels{$col->{$key}}.  "</TD>".
+                        "<TD>". $subj->{$key}. "</TD></TR>";
+          }
+
+          $out .= '</TABLE></TD><TD>';
+        }
+        $out .= '</TD></TR></TABLE>';
+
+        $out .= '<TABLE>'.
+                '<TR><TH ALIGN="right">Serial number</TH>'.
+                    "<TD>$hash{serial}</TD></TR>".
+                '<TR><TH ALIGN="right">Valid</TH>'.
+                    "<TD>$hash{notBefore} - $hash{notAfter}</TD></TR>".
+                '</TABLE>';
+
+        $out .= '<PRE><FONT STYLE="font-family:monospace">'.
+                $svc_cert->certificate.
+                '</FONT><PRE>';
+
+        $out;
+
+      } else {
+
+        my $svcnum = $svc_cert->svcnum;
+
+        include('/elements/popup_link.html', {
+          'action'      => $p."edit/svc_cert/import_cacert.html".
+                           "?svcnum=$svcnum",
+          'label'       => 'Import certificate authority chain',#link
+          'actionlabel' => 'Import certificate authority chain',#title
+          #opt
+          'width'       => '544',
+          'height'      => '368',
+          #'color'       => '#ff0000',
+        }). '&nbsp;(optional)'.
+        '<BR>';
+
+      }
+    },
+  },
 );
 
 </%init>
 );
 
 </%init>