Skip to content

Commit

Permalink
Merge pull request #19 from hadfl/check_cert
Browse files Browse the repository at this point in the history
enhancements
  • Loading branch information
citrus-it authored Mar 9, 2019
2 parents 0307d7a + 3464a85 commit d6e1abc
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 6 deletions.
1 change: 1 addition & 0 deletions PERL_MODULES
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Data::Processor
Crypt::OpenSSL::X509
8 changes: 8 additions & 0 deletions etc/pkgmgr.conf.dist
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@
"dst_repo" : "<path/URL>",
"publisher" : "extra.omnios",
"release" : "r151023"
},
"security" : {
"signing" : "yes",
"restricted" : "yes",
"src_repo" : "<path/URL>",
"dst_repo" : "<path/URL>",
"publisher" : "omnios",
"release" : "r151028"
}
}
}
14 changes: 11 additions & 3 deletions lib/PkgMgr.pm
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,11 @@ sub fetchPackages {

my $repoPath = $self->getRepoPath($config, $repo, $opts);

my @cmd = ($PKGREPO, qw(list -F json -s), $repoPath, @$fmri);
my @cert = $config->{REPOS}->{$repo}->{restricted} ne 'yes' ? ()
: ('--key', $config->{GENERAL}->{key_file},
'--cert', $config->{GENERAL}->{cert_file});

my @cmd = ($PKGREPO, qw(list -F json -s), $repoPath, @cert, @$fmri);
open my $cmd, '-|', @cmd or die "ERROR: executing '$PKGREPO': $!\n";

my ($release, $publisher) = $getReleasePublisher->($config, $repo);
Expand All @@ -124,7 +128,7 @@ sub fetchPackages {
grep { $_->{branch} =~ /^(?:$release\.\d+|\d+\.$release)$/
&& $extractPublisher->($_) eq $publisher
&& $getEpoch->($_->{timestamp}) > $epoch
} @{JSON::PP->new->decode(<$cmd>)}
} @{JSON::PP->new->decode(<$cmd> // '[]')}
];

if ($opts->{long}) {
Expand Down Expand Up @@ -241,6 +245,10 @@ sub publishPackages {
: ('--dkey', $config->{GENERAL}->{key_file},
'--dcert', $config->{GENERAL}->{cert_file});

push @cert, $config->{REPOS}->{$repo}->{restricted} ne 'yes' ? ()
: ('--key', $config->{GENERAL}->{key_file},
'--cert', $config->{GENERAL}->{cert_file});

# set timeout env variables
$ENV{PKG_CLIENT_CONNECT_TIMEOUT} = $config->{GENERAL}->{connect_timeout};
$ENV{PKG_CLIENT_LOWSPEED_TIMEOUT} = $config->{GENERAL}->{lowspeed_timeout};
Expand Down Expand Up @@ -328,7 +336,7 @@ __END__
=head1 COPYRIGHT
Copyright 2018 OmniOS Community Edition (OmniOSce) Association.
Copyright 2019 OmniOS Community Edition (OmniOSce) Association.
=head1 LICENSE
Expand Down
11 changes: 9 additions & 2 deletions lib/PkgMgr/Config.pm
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ my $SCHEMA = sub {
cert_file => {
description => 'path to certificate file',
example => '"cert_file" : "/omniosorg/ssl/certs/ooce_cert.pem"',
validator => $sv->file('<', 'Cannot open file'),
validator => $sv->x509Cert,
},
key_file => {
description => 'path to certificate key file',
Expand Down Expand Up @@ -107,6 +107,13 @@ my $SCHEMA = sub {
},
},
},
restricted => {
optional => 1,
description => 'restricted repository; authentication needed (yes/no)',
example => '"restricted" : "no"',
default => 'no',
validator => $sv->elemOf(qw(yes no)),
},
},
},
},
Expand Down Expand Up @@ -150,7 +157,7 @@ __END__
=head1 COPYRIGHT
Copyright 2017 OmniOS Community Edition (OmniOSce) Association.
Copyright 2019 OmniOS Community Edition (OmniOSce) Association.
=head1 LICENSE
Expand Down
22 changes: 21 additions & 1 deletion lib/PkgMgr/Utils.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use strict;
use warnings;

use POSIX qw(isatty);
use Crypt::OpenSSL::X509;
use Time::Seconds qw(ONE_MONTH);

my @RSYNC = qw(/usr/bin/rsync -ahh --stats --delete-after);

Expand Down Expand Up @@ -54,6 +56,24 @@ sub elemOf {
}
}

sub x509Cert {
my $self = shift;

return sub {
local $@;
my $x509 = eval {
local $SIG{__DIE__};
Crypt::OpenSSL::X509->new_from_file(shift);
};
return $@ if $@;

print STDERR "\n*** WARNING: your certificate will expire on " . $x509->notAfter . "! ***\n\n"
if $x509->checkend(ONE_MONTH);

return undef;
}
}

sub isaTTY {
my $self = shift;
return isatty(*STDIN);
Expand Down Expand Up @@ -88,7 +108,7 @@ __END__
=head1 COPYRIGHT
Copyright 2017 OmniOS Community Edition (OmniOSce) Association.
Copyright 2019 OmniOS Community Edition (OmniOSce) Association.
=head1 LICENSE
Expand Down

0 comments on commit d6e1abc

Please sign in to comment.