version 1.8.2.3.2.1, 2022/02/07 12:07:55
|
version 1.12, 2018/08/18 22:07:48
|
Line 37 use lib '/home/httpd/lib/perl/';
|
Line 37 use lib '/home/httpd/lib/perl/';
|
use LONCAPA; |
use LONCAPA; |
use Apache::lonnet; |
use Apache::lonnet; |
use GDBM_File; |
use GDBM_File; |
use Net::OAuth; |
use Crypt::OpenSSL::X509; |
|
use Crypt::PKCS10; |
|
|
sub dump_with_regexp { |
sub dump_with_regexp { |
my ( $tail, $clientversion ) = @_; |
my ( $tail, $clientversion ) = @_; |
Line 239 sub check_homecourses {
|
Line 240 sub check_homecourses {
|
} |
} |
} |
} |
unless (&untie_domain_hash($hashref)) { |
unless (&untie_domain_hash($hashref)) { |
&Apache::lonnet::logthis("Failed to untie tied hash for nohist_courseids.db for $domain"); |
&logthis("Failed to untie tied hash for nohist_courseids.db for $domain"); |
} |
} |
} else { |
} else { |
&Apache::lonnet::logthis("Failed to tie hash for nohist_courseids.db for $domain"); |
&logthis("Failed to tie hash for nohist_courseids.db for $domain"); |
} |
} |
} |
} |
foreach my $hashid (keys(%recent)) { |
foreach my $hashid (keys(%recent)) { |
Line 314 sub get_courseinfo_hash {
|
Line 315 sub get_courseinfo_hash {
|
}; |
}; |
if ($@) { |
if ($@) { |
if ($@ eq "timeout\n") { |
if ($@ eq "timeout\n") { |
&Apache::lonnet::logthis("<font color='blue'>WARNING courseiddump for $cnum:$cdom from $home timedout</font>"); |
&logthis("<font color='blue'>WARNING courseiddump for $cnum:$cdom from $home timedout</font>"); |
} else { |
} else { |
&Apache::lonnet::logthis("<font color='yellow'>WARNING unexpected error during eval of call for courseiddump from $home</font>"); |
&logthis("<font color='yellow'>WARNING unexpected error during eval of call for courseiddump from $home</font>"); |
} |
} |
} else { |
} else { |
if (ref($info{$cdom.'_'.$cnum}) eq 'HASH') { |
if (ref($info{$cdom.'_'.$cnum}) eq 'HASH') { |
Line 802 sub is_course {
|
Line 803 sub is_course {
|
} |
} |
&Apache::lonnet::do_cache_new('iscourse',$hashid,$iscourse,3600); |
&Apache::lonnet::do_cache_new('iscourse',$hashid,$iscourse,3600); |
unless (&untie_domain_hash($hashref)) { |
unless (&untie_domain_hash($hashref)) { |
&Apache::lonnet::logthis("Failed to untie tied hash for nohist_courseids.db for $cdom"); |
&logthis("Failed to untie tied hash for nohist_courseids.db for $cdom"); |
} |
} |
} else { |
} else { |
&Apache::lonnet::logthis("Failed to tie hash for nohist_courseids.db for $cdom"); |
&logthis("Failed to tie hash for nohist_courseids.db for $cdom"); |
} |
} |
} |
} |
return $iscourse; |
return $iscourse; |
} |
} |
|
|
sub get_dom { |
sub server_certs { |
my ($userinput) = @_; |
my ($perlvar,$lonhost,$hostname) = @_; |
my ($cmd,$udom,$namespace,$what) =split(/:/,$userinput,4); |
my %pemfiles = ( |
my $hashref = &tie_domain_hash($udom,$namespace,&GDBM_READER()) or |
key => 'lonnetPrivateKey', |
return "error: ".($!+0)." tie(GDBM) Failed while attempting $cmd"; |
host => 'lonnetCertificate', |
my $qresult=''; |
hostname => 'lonnetHostnameCertificate', |
if (ref($hashref)) { |
ca => 'lonnetCertificateAuthority', |
chomp($what); |
); |
my @queries=split(/\&/,$what); |
my (%md5hash,%expected_cn,%expired,%revoked,%wrongcn,%info,$crlfile); |
for (my $i=0;$i<=$#queries;$i++) { |
if (ref($perlvar) eq 'HASH') { |
$qresult.="$hashref->{$queries[$i]}&"; |
$expected_cn{'host'} = $lonhost; |
} |
$expected_cn{'hostname'} = 'internal-'.$hostname; |
$qresult=~s/\&$//; |
my $certsdir = $perlvar->{'lonCertificateDirectory'}; |
} |
if (-d $certsdir) { |
&untie_user_hash($hashref) or |
$crlfile = $certsdir.'/'.$perlvar->{'lonnetCertRevocationList'}; |
return "error: ".($!+0)." untie(GDBM) Failed while attempting $cmd"; |
foreach my $key (keys(%pemfiles)) { |
return $qresult; |
if ($perlvar->{$pemfiles{$key}}) { |
} |
my $file = $certsdir.'/'.$perlvar->{$pemfiles{$key}}; |
|
if (-e $file) { |
sub crslti_itemid { |
if ($key eq 'key') { |
my ($cdom,$cnum,$url,$method,$params,$loncaparev) = @_; |
if (open(PIPE,"openssl rsa -noout -in $file -check |")) { |
unless (ref($params) eq 'HASH') { |
my $check = <PIPE>; |
return; |
close(PIPE); |
} |
chomp($check); |
if (($cdom eq '') || ($cnum eq '')) { |
$info{$key}{'status'} = $check; |
return; |
} |
} |
if (open(PIPE,"openssl rsa -noout -modulus -in $file | openssl md5 |")) { |
my ($itemid,$consumer_key,$secret); |
$md5hash{$key} = <PIPE>; |
|
close(PIPE); |
if (exists($params->{'oauth_callback'})) { |
chomp($md5hash{$key}); |
$Net::OAuth::PROTOCOL_VERSION = Net::OAuth::PROTOCOL_VERSION_1_0A; |
} |
} else { |
} else { |
$Net::OAuth::PROTOCOL_VERSION = Net::OAuth::PROTOCOL_VERSION_1_0; |
if ($key eq 'ca') { |
} |
if (open(PIPE,"openssl verify -CAfile $file $file |")) { |
|
my $check = <PIPE>; |
my $consumer_key = $params->{'oauth_consumer_key'}; |
close(PIPE); |
return if ($consumer_key eq ''); |
chomp($check); |
|
if ($check eq "$file: OK") { |
my (%crslti,%crslti_by_key); |
$info{$key}{'status'} = 'ok'; |
my $hashid=$cdom.'_'.$cnum; |
} else { |
my ($result,$cached)=&Apache::lonnet::is_cached_new('courseltienc',$hashid); |
$check =~ s/^\Q$file\E\:?\s*//; |
if (defined($cached)) { |
$info{$key}{'status'} = $check; |
if (ref($result) eq 'HASH') { |
} |
%crslti = %{$result}; |
} |
} |
} else { |
} else { |
if (open(PIPE,"openssl x509 -noout -modulus -in $file | openssl md5 |")) { |
my $reply = &dump_with_regexp(join(":",($cdom,$cnum,'nohist_ltienc','','')),$loncaparev); |
$md5hash{$key} = <PIPE>; |
%crslti = %{&Apache::lonnet::unserialize($reply)}; |
close(PIPE); |
my $cachetime = 24*60*60; |
chomp($md5hash{$key}); |
&Apache::lonnet::do_cache_new('courseltienc',$hashid,\%crslti,$cachetime); |
} |
} |
} |
|
my $x509 = Crypt::OpenSSL::X509->new_from_file($file); |
return if (!keys(%crslti)); |
my @items = split(/,\s+/,$x509->subject()); |
|
foreach my $item (@items) { |
foreach my $id (keys(%crslti)) { |
my ($name,$value) = split(/=/,$item); |
if (ref($crslti{$id}) eq 'HASH') { |
if ($name eq 'CN') { |
my $key = $crslti{$id}{'key'}; |
$info{$key}{'cn'} = $value; |
if (($key ne '') && ($crslti{$id}{'secret'} ne '')) { |
} |
push(@{$crslti_by_key{$key}},$id); |
} |
} |
$info{$key}{'start'} = $x509->notBefore(); |
} |
$info{$key}{'end'} = $x509->notAfter(); |
} |
$info{$key}{'alg'} = $x509->sig_alg_name(); |
|
$info{$key}{'size'} = $x509->bit_length(); |
return if (!keys(%crslti_by_key)); |
$info{$key}{'email'} = $x509->email(); |
|
$info{$key}{'serial'} = $x509->serial(); |
if (ref($crslti_by_key{$consumer_key}) eq 'ARRAY') { |
if ($x509->checkend(0)) { |
foreach my $id (@{$crslti_by_key{$consumer_key}}) { |
$expired{$key} = 1; |
my $secret = $crslti{$id}{'secret'}; |
} |
my $request = Net::OAuth->request('request token')->from_hash($params, |
if (($key eq 'host') || ($key eq 'hostname')) { |
request_url => $url, |
if ($info{$key}{'cn'} ne $expected_cn{$key}) { |
request_method => $method, |
$wrongcn{$key} = 1; |
consumer_secret => $secret,); |
} |
if ($request->verify()) { |
if ((-e $crlfile) && ($info{$key}{'serial'} =~ /^\w+$/)) { |
$itemid = $id; |
my $serial = $info{$key}{'serial'}; |
last; |
if (open(PIPE,"openssl crl -inform PEM -text -in $crlfile | grep $serial |")) { |
} |
my $result = <PIPE>; |
} |
close(PIPE); |
} |
chomp($result); |
return $itemid; |
if ($result ne '') { |
} |
$revoked{$key} = 1; |
|
} |
sub domlti_itemid { |
} |
my ($dom,$context,$url,$method,$params,$loncaparev) = @_; |
} |
unless (ref($params) eq 'HASH') { |
} |
return; |
} |
} |
} |
if ($dom eq '') { |
if (($key eq 'host') || ($key eq 'hostname')) { |
return; |
my $csrfile = $file; |
} |
$csrfile =~ s/\.pem$/.csr/; |
my ($itemid,$consumer_key,$secret); |
if (-e $csrfile) { |
|
if (open(PIPE,"openssl req -noout -modulus -in $csrfile |openssl md5 |")) { |
if (exists($params->{'oauth_callback'})) { |
my $csrhash = <PIPE>; |
$Net::OAuth::PROTOCOL_VERSION = Net::OAuth::PROTOCOL_VERSION_1_0A; |
close(PIPE); |
} else { |
chomp($csrhash); |
$Net::OAuth::PROTOCOL_VERSION = Net::OAuth::PROTOCOL_VERSION_1_0; |
if ((!-e $file) || ($csrhash ne $md5hash{$key}) || ($expired{$key}) || |
} |
($wrongcn{$key}) || ($revoked{$key})) { |
|
Crypt::PKCS10->setAPIversion(1); |
my $consumer_key = $params->{'oauth_consumer_key'}; |
my $decoded = Crypt::PKCS10->new( $csrfile,(PEMonly => 1, readFile => 1)); |
return if ($consumer_key eq ''); |
if (ref($decoded)) { |
|
if ($decoded->commonName() eq $expected_cn{$key}) { |
my %ltienc; |
$info{$key.'-csr'}{'cn'} = $decoded->commonName(); |
my ($encresult,$enccached)=&Apache::lonnet::is_cached_new('ltienc',$dom); |
$info{$key.'-csr'}{'alg'} = $decoded->pkAlgorithm(); |
if (defined($enccached)) { |
$info{$key.'-csr'}{'email'} = $decoded->emailAddress(); |
if (ref($encresult) eq 'HASH') { |
my $params = $decoded->subjectPublicKeyParams(); |
%ltienc = %{$encresult}; |
if (ref($params) eq 'HASH') { |
} |
$info{$key.'-csr'}{'size'} = $params->{keylen}; |
} else { |
} |
my $reply = &get_dom("getdom:$dom:encconfig:lti"); |
$md5hash{$key.'-csr'} = $csrhash; |
my $ltiencref = &Apache::lonnet::thaw_unescape($reply); |
} |
if (ref($ltiencref) eq 'HASH') { |
} |
%ltienc = %{$ltiencref}; |
} |
} |
} |
my $cachetime = 24*60*60; |
} |
&Apache::lonnet::do_cache_new('ltienc',$dom,\%ltienc,$cachetime); |
} |
} |
} |
|
|
return if (!keys(%ltienc)); |
|
|
|
my %lti; |
|
if ($context eq 'deeplink') { |
|
my ($result,$cached)=&Apache::lonnet::is_cached_new('lti',$dom); |
|
if (defined($cached)) { |
|
if (ref($result) eq 'HASH') { |
|
%lti = %{$result}; |
|
} |
|
} |
|
} else { |
|
my $reply = &get_dom("getdom:$dom:configuration:lti"); |
|
my $ltiref = &Apache::lonnet::thaw_unescape($reply); |
|
if (ref($ltiref) eq 'HASH') { |
|
%lti = %{$ltiref}; |
|
} |
} |
my $cachetime = 24*60*60; |
|
&Apache::lonnet::do_cache_new('lti',$dom,\%lti,$cachetime); |
|
} |
} |
} |
} |
return if (!keys(%lti)); |
foreach my $key ('host','hostname') { |
|
if ($md5hash{$key}) { |
my %lti_by_key; |
if ($md5hash{$key} eq $md5hash{'key'}) { |
foreach my $id (keys(%ltienc)) { |
if ($revoked{$key}) { |
if (ref($ltienc{$id}) eq 'HASH') { |
$info{$key}{'status'} = 'revoked'; |
my $key = $ltienc{$id}{'key'}; |
} elsif ($expired{$key}) { |
if (($key ne '') && ($ltienc{$id}{'secret'} ne '')) { |
$info{$key}{'status'} = 'expired'; |
if ($context eq 'deeplink') { |
} elsif ($wrongcn{$key}) { |
if (ref($lti{$id}) eq 'HASH') { |
$info{$key}{'status'} = 'wrongcn'; |
if (!$lti{$id}{'requser'}) { |
|
push(@{$lti_by_key{$key}},$id); |
|
} |
|
} |
|
} else { |
} else { |
push(@{$lti_by_key{$key}},$id); |
$info{$key}{'status'} = 'ok'; |
} |
} |
|
} elsif ($info{'key'}{'status'} =~ /ok/) { |
|
$info{$key}{'status'} = 'otherkey'; |
|
} else { |
|
$info{$key}{'status'} = 'nokey'; |
} |
} |
} |
} |
} |
if ($md5hash{$key.'-csr'}) { |
return if (!keys(%lti_by_key)); |
if ($md5hash{$key.'-csr'} eq $md5hash{'key'}) { |
|
$info{$key.'-csr'}{'status'} = 'ok'; |
if (ref($lti_by_key{$consumer_key}) eq 'ARRAY') { |
} elsif ($info{'key'}{'status'} =~ /ok/) { |
foreach my $id (@{$lti_by_key{$consumer_key}}) { |
$info{$key.'-csr'}{'status'} = 'otherkey'; |
my $secret = $ltienc{$id}{'secret'}; |
} else { |
my $request = Net::OAuth->request('request token')->from_hash($params, |
$info{$key.'-csr'}{'status'} = 'nokey'; |
request_url => $url, |
|
request_method => $method, |
|
consumer_secret => $secret,); |
|
if ($request->verify()) { |
|
$itemid = $id; |
|
last; |
|
} |
} |
} |
} |
} |
} |
return $itemid; |
my $result; |
|
foreach my $key (keys(%info)) { |
|
$result .= &escape($key).'='.&Apache::lonnet::freeze_escape($info{$key}).'&'; |
|
} |
|
$result =~ s/\&$//; |
|
return $result; |
} |
} |
|
|
1; |
1; |
Line 1106 courseID -- for the course for which the
|
Line 1088 courseID -- for the course for which the
|
The contents of the inner hash, for that single item in the outer hash |
The contents of the inner hash, for that single item in the outer hash |
are returned (and cached in memcache for 10 minutes). |
are returned (and cached in memcache for 10 minutes). |
|
|
=item get_dom ( $userinput ) |
|
|
|
get_dom() will retrieve domain configuration information from a GDBM file |
|
in /home/httpd/lonUsers/$dom on the primary library server in a domain. |
|
The single argument passed is the string: $cmd:$udom:$namespace:$what |
|
where $cmd is the command historically passed to lond - i.e., getdom |
|
or egetdom, $udom is the domain, $namespace is the name of the GDBM file |
|
(encconfig or configuration), and $what is a string containing names of |
|
items to retrieve from the db file (each item name is escaped and separated |
|
from the next item name with an ampersand). The return value is either: |
|
error: followed by an error message, or a string containing the value (escaped) |
|
for each item, again separated from the next item with an ampersand. |
|
|
|
=back |
=back |
|
|