This file is indexed.

/usr/share/perl5/EBox/CGI/CA/RenewCertificate.pm is in zentyal-ca 2.3.6+quantal1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# Copyright (C) 2008-2012 eBox Technologies S.L.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2, as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

package EBox::CGI::CA::RenewCertificate;

use strict;
use warnings;

use base 'EBox::CGI::ClientBase';

use EBox::Gettext;
use EBox::Global;
# For exceptions
use Error qw(:try);
use EBox::Exceptions::DataInUse;

# Method: new
#
#       Constructor for RenewCertificate CGI
#
# Returns:
#
#       RenewCertificate - The object recently created

sub new
  {

    my $class = shift;

    my $self = $class->SUPER::new('title' => __('Certification Authority'),
				  @_);

    $self->{chain} = "CA/Index";
    bless($self, $class);

    return $self;

  }

# Process the HTTP query

sub _process
  {

    my $self = shift;

    my $ca = EBox::Global->modInstance('ca');

    if ( $self->param('cancel') ) {
      $self->setRedirect( 'CA/Index' );
      $self->setMsg( __("The certificate has NOT been renewed") );
      $self->cgi()->delete_all();
      return;
    }

    $self->_requireParam('isCACert', __('Boolean indicating Certification Authority Certificate') );
    $self->_requireParam('expireDays', __('Days to expire') );

    my $commonName = $self->unsafeParam('commonName');
    # We have to check it manually
    if ( not defined($commonName) or $commonName eq '' ) {
        throw EBox::Exceptions::DataMissing(data => __('Common Name'));
    }
    # Only valid chars minus '/' plus '*' --> security risk
    unless ( $commonName =~ m{^[\w .?&+:\-\@\*]*$} ) {
        throw EBox::Exceptions::External(__('The input contains invalid ' .
                                            'characters. All alphanumeric characters, ' .
					    'plus these non alphanumeric chars: .?&+:-@* ' .
					    'and spaces are allowed.'));
    }

    # Transform %40 in @
    $commonName =~ s/%40/@/g;
    # Transform %20 in space
    $commonName =~ s/%20/ /g;

    my $isCACert = $self->param('isCACert');
    my $expireDays = $self->param('expireDays');
    my $caPassphrase = $self->param('caPassphrase');
    $caPassphrase = undef if ( $caPassphrase eq '' );

    unless ( $expireDays > 0) {
        throw EBox::Exceptions::External(__x('Days to expire ({days}) must be '
                                             . 'a positive number',
                                             days => $expireDays));
    }

    my $retValue;
    my $retFromCatch;
    if ( defined ($self->param('renewForced')) ) {
	if ( $isCACert ) {
	  $retValue = $ca->renewCACertificate( days => $expireDays,
                                               caKeyPassword => $caPassphrase,
					       force => 'true',
					     );
	} else {
	  $retValue = $ca->renewCertificate( commonName => $commonName,
					     days       => $expireDays,
                                             caKeyPassword => $caPassphrase,
					     force      => 'true',
					   );
	}
    }
    else {
      try {
      if ( $isCACert ) {
	  $retValue = $ca->renewCACertificate( days => $expireDays,
                                               caKeyPassword => $caPassphrase,
                                               );
	} else {
	  $retValue = $ca->renewCertificate( commonName    => $commonName,
                                             caKeyPassword => $caPassphrase,
					     days          => $expireDays);
	}
      } catch EBox::Exceptions::DataInUse with {
	$self->{template} = '/ca/forceRenew.mas';
	$self->{chain} = undef;
	my $cert = $ca->getCertificateMetadata( cn => $commonName );
	my @array;
	push (@array, 'metaDataCert' => $cert);
	push (@array, 'expireDays'   => $expireDays);
        push (@array, 'caPassphrase' => $caPassphrase);
	$self->{params} = \@array;
	$retFromCatch = 1;
      };
    }

    if ( not $retFromCatch ) {
      if (not defined($retValue) ) {
	throw EBox::Exceptions::External(__('The certificate CANNOT be renewed'));
      } else {
	my $msg = __("The certificate has been renewed");
	$msg = __("The new CA certificate has been renewed") if ($isCACert);
	$self->setMsg($msg);
        $self->cgi()->delete_all();
      }
    }

  }

1;