[LON-CAPA-cvs] cvs: loncom / lonssl.pm
foxr
lon-capa-cvs@mail.lon-capa.org
Fri, 28 May 2004 09:37:03 -0000
foxr Fri May 28 05:37:03 2004 EDT
Modified files:
/loncom lonssl.pm
Log:
- Accept arguments according to loncapa coding standard
- Retabinate.
Index: loncom/lonssl.pm
diff -u loncom/lonssl.pm:1.5 loncom/lonssl.pm:1.6
--- loncom/lonssl.pm:1.5 Thu May 27 06:26:19 2004
+++ loncom/lonssl.pm Fri May 28 05:37:03 2004
@@ -1,5 +1,5 @@
#
-# $Id: lonssl.pm,v 1.5 2004/05/27 10:26:19 foxr Exp $
+# $Id: lonssl.pm,v 1.6 2004/05/28 09:37:03 foxr Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -23,7 +23,7 @@
#
# http://www.lon-capa.org/
#
-
+package lonssl;
# lonssl.pm
# This file contains common functions used by lond and lonc when
# negotiating the exchange of the session encryption key via an
@@ -33,8 +33,9 @@
use strict;
-# CPAN modules:
+# CPAN/Standard modules:
+use English;
use IO::Socket::INET;
use IO::Socket::SSL;
@@ -75,23 +76,24 @@
# IO::Socket::SSL
sub PromoteClientSocket {
- my $PlaintextSocket = shift;
- my $CACert = shift;
- my $MyCert = shift;
- my $KeyFile = shift;
-
+ my ($PlaintextSocket,
+ $CACert,
+ $MyCert,
+ $KeyFile) = @ARG;
+
+
# To create the ssl socket we need to duplicate the existing
# socket. Otherwise closing the ssl socket will close the plaintext socket
# too:
-
+
open (DUPLICATE, "+>$PlaintextSocket");
-
+
my $client = IO::Socket::SSL->new_from_fd(fileno(DUPLICATE),
SSL_user_cert => 1,
SSL_key_file => $KeyFile,
SSL_cert_file => $MyCert,
SSL_ca_fie => $$CACert);
-
+
return $client; # Undef if the client negotiation fails.
}
@@ -112,10 +114,11 @@
# - undef on failure. Reason for failure can be interrogated from
# IO::Socket::SSL
sub PromoteServerSocket {
- my $PlaintextSocket = shift;
- my $CACert = shift;
- my $MyCert = shift;
- my $KeyFile = shift;
+ my ($PlaintextSocket,
+ $CACert,
+ $MyCert,
+ $KeyFile) = @ARG;
+
# To create the ssl socket we need to duplicate the existing
@@ -163,12 +166,12 @@
# the certificate authority. The second element of the list is the name
# of the owner of the certificate.
sub GetPeerCertificate {
- my $SSLSocket = shift;
-
- my $CertOwner = $SSLSocket->peer_certificate("owner");
- my $CertCA = $SSLSocket->peer_certificate("authority");
-
- return \($CertCA, $CertOwner);
+ my $SSLSocket = shift;
+
+ my $CertOwner = $SSLSocket->peer_certificate("owner");
+ my $CertCA = $SSLSocket->peer_certificate("authority");
+
+ return \($CertCA, $CertOwner);
}
#----------------------------------------------------------------------------
#
@@ -182,31 +185,31 @@
#
sub CertificateFile {
- # I need some perl variables from the configuration file for this:
-
- my $CertificateDir = $perlvar->{lonCertificateDirectory};
- my $CaFilename = $perlvar->{lonnetCertificateAuthority};
- my $CertFilename = $perlvar->{lonnetCertificate};
-
- # Ensure the existence of these variables:
-
- if((!$CertificateDir) || (!$CaFilename) || (!$CertFilename)) {
- return undef;
- }
-
- # Build the actual filenames and check for their existence and
- # readability.
-
- my $CaFilename = $CertificateDir.$pathsep.$CaFilename;
- my $CertFilename = $CertificateDir.$pathsep.$CertFilename;
-
- if((! -r $CaFilename) || (! -r $CertFilename)) {
- return undef;
- }
-
- # Everything works fine!!
-
- return \($CaFilename, $CertFilename);
+ # I need some perl variables from the configuration file for this:
+
+ my $CertificateDir = $perlvar->{lonCertificateDirectory};
+ my $CaFilename = $perlvar->{lonnetCertificateAuthority};
+ my $CertFilename = $perlvar->{lonnetCertificate};
+
+ # Ensure the existence of these variables:
+
+ if((!$CertificateDir) || (!$CaFilename) || (!$CertFilename)) {
+ return undef;
+ }
+
+ # Build the actual filenames and check for their existence and
+ # readability.
+
+ my $CaFilename = $CertificateDir.$pathsep.$CaFilename;
+ my $CertFilename = $CertificateDir.$pathsep.$CertFilename;
+
+ if((! -r $CaFilename) || (! -r $CertFilename)) {
+ return undef;
+ }
+
+ # Everything works fine!!
+
+ return \($CaFilename, $CertFilename);
}
#------------------------------------------------------------------------
@@ -220,26 +223,26 @@
#
sub KeyFile {
- # I need some perl variables from the configuration file for this:
-
- my $CertificateDir = $perlvar->{lonCertificateDirectory};
- my $KeyFilename = $perlvar->{lonnetPrivateKey};
-
- # Ensure the variables exist:
-
- if((!$CertificateDir) || (!$KeyFilename)) {
- return undef;
- }
-
- # Build the actual filename and ensure that it not only exists but
- # is also readable:
-
- my $KeyFilename = $CertificateDir.$pathsep.$KeyFilename;
- if(! (-r $KeyFilename)) {
- return undef;
- }
-
- return $KeyFilename;
+ # I need some perl variables from the configuration file for this:
+
+ my $CertificateDir = $perlvar->{lonCertificateDirectory};
+ my $KeyFilename = $perlvar->{lonnetPrivateKey};
+
+ # Ensure the variables exist:
+
+ if((!$CertificateDir) || (!$KeyFilename)) {
+ return undef;
+ }
+
+ # Build the actual filename and ensure that it not only exists but
+ # is also readable:
+
+ my $KeyFilename = $CertificateDir.$pathsep.$KeyFilename;
+ if(! (-r $KeyFilename)) {
+ return undef;
+ }
+
+ return $KeyFilename;
}
1;