Solved

module exporting/importing problem

Posted on 2006-11-15
15
241 Views
Last Modified: 2008-01-16
THis is from the apache error log when i try and  run the script.

"makerandom" is not exported by the Crypt::Random module at /usr/local/share/perl/5.6.1/Crypt/Random/Generator.pm line 12
"makerandom_itv" is not exported by the Crypt::Random module at /usr/local/share/perl/5.6.1/Crypt/Random/Generator.pm line 12
"makerandom_octet" is not exported by the Crypt::Random module at /usr/local/share/perl/5.6.1/Crypt/Random/Generator.pm line 12
[Thu Nov 16 11:52:58 2006] [error] Can't continue after import errors at /usr/local/share/perl/5.6.1/Crypt/Random/Generator.pm line 12
BEGIN failed--compilation aborted at /usr/local/share/perl/5.6.1/Crypt/Random/Generator.pm line 12.
Compilation failed in require at /usr/local/share/perl/5.6.1/Crypt/Random.pm line 18.
BEGIN failed--compilation aborted at /usr/local/share/perl/5.6.1/Crypt/Random.pm line 18.
Compilation failed in require at /usr/local/share/perl/5.6.1/Crypt/DSA.pm line 7.
BEGIN failed--compilation aborted at /usr/local/share/perl/5.6.1/Crypt/DSA.pm line 7.
Compilation failed in require at /usr/local/share/perl/5.6.1/Crypt/OpenPGP/Key/Secret/DSA.pm line 31.

its saying that the the module Crypt::Random isn't exporting makerandom... etc but i have looked at the file and it is.

from the error log i can deduce this Crypt/OpenPGP/Key/Secret/DSA.pm imports Crypt/DSA.pm, which imports Crypt/Random.pm, which imports Crypt/Random/Generator.pm, WHICH IN TURN imports Crypt/Random.pm.

So what think is happening is that Crypt/Random/Generator.pm is loaded and then tries to load Crypt/Random.pm which tries to load Crypt/Random/Generator.pm but get stuck cause its waiting for Crypt/Random.pm to load. SO it can't load or something.

I don't know perl that well so i don't know if this situation is possible but heres the twist. On another machine where all these modules are the same there is no problem!

both machines have the same @INC paths etc. I don't know what else to look for.

Any clues or leads that i could look into would be appreciated

Thanks

0
Comment
Question by:Dinky7
  • 8
  • 6
15 Comments
 
LVL 17

Expert Comment

by:mjcoyne
Comment Utility
How are you including Crypt::Random in your script?  Are you using the line:

use Crypt::Random qw( makerandom );
0
 

Author Comment

by:Dinky7
Comment Utility
Here are the headers to the modules:


package Crypt::Random::Generator;
use Crypt::Random qw(makerandom makerandom_itv makerandom_octet);
use Carp;

------------------

package Crypt::Random;
require Exporter;
use vars qw($VERSION @EXPORT_OK);
use Math::Pari qw(PARI floor Mod pari2pv pari2num lift);
use Carp;
use Data::Dumper;
use Class::Loader;
use Crypt::Random::Generator;
*import      = \&Exporter::import;

@EXPORT_OK   = qw( makerandom makerandom_itv makerandom_octet );
0
 

Author Comment

by:Dinky7
Comment Utility
by headers i mean the head of the scripts :)
0
 
LVL 17

Expert Comment

by:mjcoyne
Comment Utility
Yes, those are the headers to the modules, but how are you loading the modules in *your* script -- the one that generates the error when it runs?
0
 

Author Comment

by:Dinky7
Comment Utility
to be honest i can't give you to answer that you want because i haven't been able to find it myself (I didn't write the script i'm just trying to fix a problem *sigh*)

as i noted earlier:
Crypt/OpenPGP/Key/Secret/DSA.pm imports Crypt/DSA.pm, which imports Crypt/Random.pm, which imports Crypt/Random/Generator.pm, WHICH IN TURN imports Crypt/Random.pm.

each of these modules use 'use' or 'require' to load the modules.

in the scripts that i'm looking at i can't seem to find where it loads Crypt/OpenPGP/Key/Secret/DSA.pm to start off with.

All i can see so far is that my script loads Crypt::OpenPGP and the error occurs when a call is made to the Crypt::OpenPGP->sign method.

from there on I have tried to trace where that call goes and have not been able to find any scripts or modules that loads Crypt/OpenPGP/Key/Secret/DSA.pm (which in turn loads everything else)

Please note that all the Crypt:: modules should be independant because as i stated that on another box where all these modules are the same (the ones i've managed to trace, so i could be missing some) and it works on that box.

This doesn't seem to be very helpful lol. If theres any other information that may help you let me know.

Thanks
0
 
LVL 17

Expert Comment

by:mjcoyne
Comment Utility
Two things:

>> All i can see so far is that my script loads Crypt::OpenPGP and the error occurs when a call is made to the Crypt::OpenPGP->sign method.

What is the "my script" you're referring to in the above sentence?  These errors are being stored in Apache's log, so I assume it's a CGI script.  Before we think about blaming well-used and stable modules for the errors, I think we should look closely at the CGI script that's initiating the whole cascade.  Can we see this CGI script?

>> Please note that all the Crypt:: modules should be independant because as i stated that on another box where all these modules are the same (the ones i've managed to trace, so i could be missing some) and it works on that box.

I would definately re-install the modules on the problem machine.  Something may have been corrupted, so I would un-install the existing modules, and then re-install the latest versions.  To uninstall a module, see http://www.cpan.org/misc/cpan-faq.html#How_delete_Perl_modules.

I'd also generate a list of installed modules from the machine that works, and compare it to a list generated on a machine giving you trouble (see http://www.cpan.org/misc/cpan-faq.html#How_installed_modules).  See that you're using the same versions of all modules.
0
 

Author Comment

by:Dinky7
Comment Utility
I've copied code stubs from the main script and some parts of modules that it uses. Brief explanation is of what happens is in the main script it creates a SRS::OpenPGP object and a SRS::Communications object. SRS::Communications takes a SRS::OpnPGP object as one of its arguments.
SRS::Communications->send method is then called from the main script. this in turn calls SRS::OpenPGP->sign which then calls Crypt::OpenPGP->sign.
(These modules and scripts are the same on both machines)

I have also checked the versions of the installed modules on the working machine compared to the problem machine using the code from ur CPAN links and they are all identitcal. I'll see if it is possible to reinstall the modules

==Main Script===========================================
sub srs_send {
  my $xml = shift;
  my $sec = shift || 0;

  ## Log the XML transaction
  my $file = '';
  my $time = time;
  while ($file eq '' or -e $file) {
    $file = "/acnts/logs/xml/srs/srs-xml-$$-$time.txt";
    $time++;
    }
  open (FILE, ">$file");
  print FILE $xml;
  close FILE;

  ## We should probably validate the XML against the DTD here too

  ## Initialise Error Repository
  if (my $error = SRS::Error::Repository::initialize('SrsClient')) {
    return (undef, $error);
    }

  my $pgp = new SRS::OpenPGP(
   'secretKeyRing' => '/acnts/lib/SRS/keys/secring.gpg',
   'publicKeyRing' => '/acnts/lib/SRS/keys/pubring.gpg');

  my $sender = new SRS::Communications(
    url           => $ServerURI,
    registrar     => $RegistrarID,
    pgp           => $pgp,
    timeout       => 7000,
   );
print "1";

  my ($sendError, $xmlResponse)
   = $sender->send(requiresSecurity=>$sec, request=>$xml); #<----FAILS INSIDE THIS CALL
print "2";
  if ($sendError) {
    return (undef, $sendError->logString());
    }

===========================================
==SRS::OpenPGP module=========================================
package SRS::OpenPGP;

use strict;
use warnings;
use Carp;

use Crypt::OpenPGP;

sub new {
    my ($class, %args) = @_;

    # Create PGP Object
    my $pgp = new Crypt::OpenPGP( SecRing => $args{secretKeyRing},
                                  PubRing => $args{publicKeyRing},)
      or croak "
Cannot instantiate OpenPGP object for
  public key ring: $args{publicKeyRing}
  secret key ring: $args{secretKeyRing}
" . Crypt::OpenPGP->errstr;

    my $self = {PGP => $pgp};
    bless ($self,$class);

    $self->{DefaultSigningKey}    = $self->findSigningKey($args{uid})
      or warn "No default signing key".   ($args{uid} ? "($args{uid})" : "");
    $self->{DefaultEncryptingKey} = $self->findEncryptingKey($args{uid})
      or warn "No default encrypting key".($args{uid} ? "($args{uid})" : "");

    return $self;
}

sub sign {
    my $self = shift;
    my %params = @_;

    my $data       = $params{Data}       or croak "Data not supplied";
    my $key        = $params{Key}        || $self->{DefaultSigningKey};
    my $passphrase = $params{PassPhrase} || '';
    my $pgp        = $self->{PGP};
print "-SRS PGP 1-";


    my $signature = $pgp->sign(Data       => clean ($data), # XXX this needs more thought
                               Detach     => 1,
                               Armour     => 1,
                               Digest     => 'SHA1',
                               PassPhrase => $passphrase,
                               Key        => $key); #<---FAILS INSIDE THIS CALL
print "-SRS PGP 2-";
    carp "Signing attempt failed: ", $pgp->errstr() unless $signature;
print "-SRS PGP 3-";

   return $signature;
}


============================================
==SRS::Communications=========================================
sub send {
    my $self = shift;
    my %params = @_;

    my %postParams;
    if ($params{postParams}) {
        %postParams = %{$params{postParams}};
    }

    my $pgp = $self->{pgp};

    # Check for parameters
    unless (defined($params{request})) {
        return generateError(MISSING_MANDATORY_FIELD(), 'Request');
    }

    my $request = $params{request};
print "-SRS Comm1-";
    # Sign Request
    my $signature = $pgp->sign(Data       => $request); #<---FAILS INSIDE THIS CALL
print "-SRS Comm2-";

============================================

0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 17

Expert Comment

by:mjcoyne
Comment Utility
Where are $ServerURI and $RegistrarID defined?  They're not passed to the sub, are they global?

Try adding few debugging messages, to see where it's actually failing:

sub srs_send {
  my $xml = shift or die "Didn't get \$xml\n";
  my $sec = shift || 0;

  ## Log the XML transaction
  my $file = '';
  my $time = time;
  while ($file eq '' or -e $file) {
    $file = "/acnts/logs/xml/srs/srs-xml-$$-$time.txt" or die "Can't assign to \$file\n";
    $time++;
    }
  open (FILE, ">$file") or die "Can't open file $file: $!\n";;
  print FILE $xml;
  close FILE;

  ## We should probably validate the XML against the DTD here too

  ## Initialise Error Repository
  if (my $error = SRS::Error::Repository::initialize('SrsClient')) {
    return (undef, $error);
    }

  my $pgp = new SRS::OpenPGP(
   'secretKeyRing' => '/acnts/lib/SRS/keys/secring.gpg',
   'publicKeyRing' => '/acnts/lib/SRS/keys/pubring.gpg')
  or die "Can't assign to \$pgp\n";

  my $sender = new SRS::Communications(
    url           => $ServerURI,
    registrar     => $RegistrarID,
    pgp           => $pgp,
    timeout       => 7000,
   ) or die "Can't assign to \$sender\n";
print "1";

  my ($sendError, $xmlResponse)
   = $sender->send(requiresSecurity=>$sec, request=>$xml); #<----FAILS INSIDE THIS CALL
print "2";
  if ($sendError) {
    return (undef, $sendError->logString());
    }
} # I added this
0
 

Author Comment

by:Dinky7
Comment Utility
yes $ServerURI and $RegistrarID and global in the main script.

I have added debugging comments to the scriipts i have write access to. It fails in the SRS::OpenPGP->sign method which makes a call to Crypt::OpenPGP->sign. it does not return from the Crypt::OpenPGP->sign call but dies, according to the apache log, when somehwere down the line it trys to load the Crypt::Random module.

Corruption of the modules seems like a possiblility but I've done a diff on the modules that i can trace and they are all the same.
The include paths are exactly the same. I don't see what else could be different between the 2 servers that would cause this problem :(

Thanks for your input so far mjcoyne
0
 
LVL 17

Expert Comment

by:mjcoyne
Comment Utility
So, it dies at:

  my $pgp = new SRS::OpenPGP(
   'secretKeyRing' => '/acnts/lib/SRS/keys/secring.gpg',
   'publicKeyRing' => '/acnts/lib/SRS/keys/pubring.gpg')
  or die "Can't assign to \$pgp\n";

?

This would indicate to me, all other things being equal (e.g. putting aside for a minute the possibility of corrupt modules, and assuming that all directory stuctures are the same in name and permissions between the two servers), that there's something wrong with your secret or public (or both) keyring files on the server giving you problems.

Are the pubring.gpg and secring.gpg keyring files exactly the same size on both machines (assuming they contain the same contents)?  Are they assigned the same permissions on both machines?  Though the structure (names and order) of the directories are the same on both machines, are the permissions set for all directories and subdirectories the same?  Are both machines running the same OS?  Do the user accounts the web server and Perl run under assigned the same privileges?
0
 

Author Comment

by:Dinky7
Comment Utility
the script dies in SRS::OpenPGP
    my $signature = $pgp->sign(Data       => clean ($data), # XXX this needs more thought
                               Detach     => 1,
                               Armour     => 1,
                               Digest     => 'SHA1',
                               PassPhrase => $passphrase,
                               Key        => $key); #<---FAILS INSIDE THIS CALL

$pgp here is a Crypt::OpenPGP object. so the call to Crypt::OpenPGP->sign() is where it dies.

I copied the keyrings from the good to the problem server and it makes no difference.

The directories and keyrings have more permissions on the problem machine but the owner and user group are different. I don't know if that makes a difference.
the /etc/debian_version file are both 3.0
uname release is 2.4.27 on the problem machine and 2.4.19 on the other.
I'm not sure how to find the user accounts for the web server and perl.

If it was a permission problem wouldn't the apache log say can't access the module instead of saying the module doesn't export the functions?
0
 
LVL 17

Accepted Solution

by:
mjcoyne earned 250 total points
Comment Utility
Boy, this is a wierd one...

Could it be a Perl version problem?  I notice the errors you posted above reference a Perl 5.6.1 installation -- quite old.  Perhaps the working machine is running Perl 5.8.x?

Compare the two Perl installations by typing perl -V at the command line on both machines, see what you get.

A less likely problem is that when you copied the keyring files from one machine to the other, you used the wrong mode (ASCII vs binary or vice versa)?
0
 

Author Comment

by:Dinky7
Comment Utility
both perl versions are 5.6.1. both machines keyrings are binary files as well.

times like these make u wanna break stuff lol.
I think the answer is 'It should be working' haha.

A complete format might be the way to go but thats out of the question unfortunately
0
 

Author Comment

by:Dinky7
Comment Utility
oh well, thanks for your input mjcoyne.
I'm just gonna skip this problem until i have to fix it lol
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now