File:  [LON-CAPA] / loncom / configuration / SSL.pm
Revision 1.8: download - view: text, annotated - select for diffs
Sat Dec 22 17:06:06 2018 UTC (5 years, 4 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- LON-CAPA SSL certificate status incudes issuer comparison for CA cert and
  Connections and Replication certs.

    1: # The LearningOnline Network with CAPA
    2: # Checksum installed LON-CAPA modules and some configuration files
    3: #
    4: # $Id: SSL.pm,v 1.8 2018/12/22 17:06:06 raeburn Exp $
    5: #
    6: # The LearningOnline Network with CAPA
    7: #
    8: # Copyright Michigan State University Board of Trustees
    9: #
   10: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
   11: #
   12: # LON-CAPA is free software; you can redistribute it and/or modify
   13: # it under the terms of the GNU General Public License as published by
   14: # the Free Software Foundation; either version 2 of the License, or
   15: # (at your option) any later version.
   16: #
   17: # LON-CAPA is distributed in the hope that it will be useful,
   18: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   19: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   20: # GNU General Public License for more details.
   21: #
   22: # You should have received a copy of the GNU General Public License
   23: # along with LON-CAPA; if not, write to the Free Software
   24: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   25: #
   26: # /home/httpd/html/adm/gpl.txt
   27: #
   28: # http://www.lon-capa.org/
   29: #
   30: 
   31: package LONCAPA::SSL;
   32: use strict;
   33: use lib '/home/httpd/lib/perl/';
   34: use Apache::lonlocal;
   35: use Apache::lonnet();
   36: use Apache::loncommon();
   37: use Apache::lonhtmlcommon();
   38: use DateTime;
   39: use DateTime::Format::x509;
   40: use LONCAPA; 
   41: 
   42: sub print_certstatus {
   43:     my ($servers,$target,$context) = @_;
   44:     return unless (ref($servers) eq 'HASH');
   45:     my $message;
   46:     my %lt = &Apache::lonlocal::texthash (
   47:                  'file'     => 'File',
   48:                  'avai'     => 'Available',
   49:                  'yes'      => 'Yes',
   50:                  'no'       => 'No',
   51:                  'cn'       => 'Common Name (CN)',
   52:                  'start'    => 'Valid From',
   53:                  'end'      => 'Valid To',
   54:                  'alg'      => 'Signature Algorithm',
   55:                  'size'     => 'Public Key Size',
   56:                  'status'   => 'Status',
   57:                  'email'    => 'E-mail',
   58:                  'key'      => 'Private Key',
   59:                  'host'     => 'Connections Certificate',
   60:                  'hostname' => 'Replication Certificate',
   61:                  'ca'       => 'LON-CAPA CA Certificate',
   62:                  'expired'  => 'Expired',
   63:                  'future'   => 'Future validity',
   64:                  'nokey'    => 'No key',
   65:                  'otherkey' => 'No matching key',
   66:                  'revoked'  => 'Revoked by CA',
   67:                  'wrongcn'  => 'Incorrect CN',
   68:                  'mismatch' => 'Mismatched Issuer',
   69:     );
   70:     my @files = qw(key host hostname ca);
   71:     my @fields = qw(status cn start end alg size email);
   72:     foreach my $server (sort(keys(%{$servers}))) {
   73:         my $hostname = $servers->{$server};
   74:         my ($result,$hashref) = &Apache::lonnet::get_servercerts_info($server,
   75:                                                                       $hostname,
   76:                                                                       $context);
   77:         if ($result eq 'ok' && ref($hashref) eq 'HASH') {
   78:             if ($target eq 'web') {
   79:                 $message .= "<fieldset><legend>$hostname ($server)</legend>".
   80:                             &Apache::loncommon::start_data_table().
   81:                             &Apache::loncommon::start_data_table_header_row()."\n";
   82:                 foreach my $item ('file','avai',@fields) {
   83:                     $message .= '<th>'.$lt{$item}.'</th>';
   84:                 }
   85:                 $message .= &Apache::loncommon::end_data_table_header_row()."\n";
   86:             } else {
   87:                 $message .= $server.':';
   88:             }
   89:             my %csr;
   90:             foreach my $file (@files) {
   91:                 if ($target eq 'web') {
   92:                     $message .= &Apache::loncommon::start_data_table_row()."\n".
   93:                                 '<td>'.$lt{$file}.'</td>';
   94:                 } else {
   95:                     $message .= $file.'=';
   96:                 }
   97:                 if (ref($hashref->{$file}) eq 'HASH') {
   98:                     my ($starttime,$endtime,$dateinvalid);
   99:                     if ($target eq 'web') {
  100:                         $message .= '<td>'.$lt{'yes'}.'</td>';
  101:                     } else {
  102:                         $message .= 'yes,';
  103:                     }
  104:                     unless ($file eq 'key') {
  105:                         if ($hashref->{$file}->{'end'} ne '') {
  106:                             my $dt = DateTime::Format::x509->parse_datetime($hashref->{$file}->{'end'});
  107:                             if (ref($dt)) {
  108:                                 $endtime = $dt->epoch;
  109:                                 if ($endtime < time) {
  110:                                     if ($target eq 'web') {
  111:                                         $dateinvalid = $lt{'expired'};
  112:                                     } else {
  113:                                         $dateinvalid = 'expired';
  114:                                     }
  115:                                 }
  116:                             }
  117:                         }
  118:                         if ($hashref->{$file}->{'start'} ne '') {
  119:                             my $dt = DateTime::Format::x509->parse_datetime($hashref->{$file}->{'start'});
  120:                             if (ref($dt)) {
  121:                                 $starttime = $dt->epoch;
  122:                                 if ($starttime > time) {
  123:                                     unless ($dateinvalid) {
  124:                                         if ($target eq 'web') {
  125:                                             $dateinvalid = $lt{'future'};
  126:                                         } else {
  127:                                             $dateinvalid = 'future';
  128:                                         }
  129:                                     }
  130:                                 }
  131:                             }
  132:                         }
  133:                     }
  134:                     foreach my $item (@fields) {
  135:                         my $display = $hashref->{$file}->{$item};
  136:                         if ($item eq 'status') {
  137:                             if ($file eq 'key') {
  138:                                 if ($display =~ /ok$/) {
  139:                                     if ($target eq 'web') {
  140:                                         $display = &Apache::lonhtmlcommon::confirm_success($display);
  141:                                     }
  142:                                 }
  143:                             } elsif ($file eq 'ca') {
  144:                                 if ($dateinvalid) {
  145:                                     $display = $dateinvalid;
  146:                                 } elsif ($target eq 'web') {
  147:                                     $display = &Apache::lonhtmlcommon::confirm_success($display);
  148:                                 }
  149:                             } elsif ($display =~ /^ok/) {
  150:                                 if ($dateinvalid) {
  151:                                     $display = $dateinvalid;
  152:                                 } elsif ($target eq 'web') { 
  153:                                     $display = &Apache::lonhtmlcommon::confirm_success($display);
  154:                                 }
  155:                             } elsif (($display eq 'nokey') || ($display eq 'otherkey') ||
  156:                                      ($display eq 'revoked') || ($display eq 'expired') ||
  157:                                      ($display eq 'wrongcn') || ($display eq 'mismatch')) {
  158:                                 if ($target eq 'web') {
  159:                                     $display = $lt{$display};
  160:                                 }
  161:                                 if (ref($hashref->{$file.'-csr'}) eq 'HASH') {
  162:                                     if ($hashref->{$file.'-csr'}->{$item} eq 'ok') {
  163:                                         if ($target eq 'web') {
  164:                                             $display .= '<br />'.&mt('(New request awaiting signature)');
  165:                                         }
  166:                                         $csr{$file} = 1;
  167:                                     }
  168:                                 }
  169:                             }
  170:                         } elsif ($item eq 'start') {
  171:                             if ($starttime) {
  172:                                 if ($target eq 'web') {
  173:                                     $display = &Apache::lonlocal::locallocaltime($starttime);
  174:                                 } else {
  175:                                     $display = $starttime;
  176:                                 }
  177:                             }
  178:                         } elsif ($item eq 'end') {
  179:                             if ($endtime) {
  180:                                 if ($target eq 'web') {
  181:                                     $display = &Apache::lonlocal::locallocaltime($endtime);
  182:                                 } else {
  183:                                     $display = $endtime;
  184:                                 }
  185:                             }
  186:                         }
  187:                         if ($target eq 'web') {
  188:                             $message .= "<td>$display</td>";
  189:                         } else {
  190:                             $message .= "$display,";
  191:                         }
  192:                     }
  193:                 } else {
  194:                     if ($target eq 'web') {
  195:                         $message .= '<td>'.$lt{'no'}.'</td>';
  196:                     } else {
  197:                         $message .= 'no,';
  198:                     }
  199:                     if ((($file eq 'host') || ($file eq 'hostname')) &&
  200:                         (ref($hashref->{$file.'-csr'}) eq 'HASH')) {
  201:                         if ($hashref->{$file.'-csr'}->{'status'} eq 'ok') {
  202:                             if ($target eq 'web') {
  203:                                 my $colspan = scalar(@fields);
  204:                                 $message .= '<td colspan="'.$colspan.'">'.
  205:                                             &mt('Request for [_1] awaiting signature',
  206:                                                 $lt{$file}).'</td>';
  207:                             }
  208:                             $csr{$file} = 1;
  209:                         }
  210:                     }
  211:                     foreach my $item (@fields) {
  212:                         if ($target eq 'web') {
  213:                             unless ($csr{$file}) {
  214:                                 $message .= '<td>&nbsp;</td>';
  215:                             }
  216:                         } else {
  217:                             $message .= ',';
  218:                         }
  219:                     } 
  220:                 }
  221:                 if ($target eq 'web') {
  222:                     $message .= &Apache::loncommon::end_data_table_row()."\n";
  223:                 } else {
  224:                     $message =~ s/,$//;
  225:                     $message .= '&';
  226:                 }
  227:             }
  228:             if ($target eq 'web') {
  229:                 $message .= &Apache::loncommon::end_data_table().'</fieldset>';
  230:             } else {
  231:                 if (keys(%csr)) {
  232:                     foreach my $file (keys(%csr)) {
  233:                         if (ref($hashref->{$file.'-csr'}) eq 'HASH') {
  234:                             $message .= $file.'-csr=yes,';
  235:                             foreach my $item (@fields) {
  236:                                 $message .= $hashref->{$file.'-csr'}->{$item}.',';
  237:                             }
  238:                             $message =~ s/,$//;
  239:                             $message .= '&';
  240:                         }
  241:                     }
  242:                 }
  243:                 $message =~ s/\&$//;
  244:             }
  245:             $message .= "\n";
  246:         } else {
  247:             if ($target eq 'web') {
  248:                 $message .= "$server:error\n";
  249:             } else {
  250:                 $message .= "$server:error\n";
  251:             }
  252:         }
  253:     }
  254:     return $message;
  255: }
  256: 
  257: 1;
  258: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>