473,396 Members | 1,864 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Perl Expect and openssl

Hi,

I've been wrestling with this for a few days and I'm not sure what I'm doing wrong. I'm writing a script that will eventually sign several certificate signing requests (CSRs) using openssl. But for now, I can't get it to sign a single one.

Here are the beginning and the signing portions of the script as they are now. Instead of using an argument to input the passphrase, I'm defining it in a variable and have it printed out to prove that perl is getting the passphrase OK.

************************************************** ***


Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2.  
  3. use Expect;
  4. use IO::Socket;
  5. use strict;
  6. use warnings;
  7.  
  8. my $pass = "pa\$\$sphrase\n";
  9. print "$pass";
  10.  
  11. ############################
  12. # on to the signing.....
  13. ############################
  14.  
  15. print "\nAttempting to sign $csr to $crt...\n\n";
  16.  
  17. my $sign_command = system ("openssl x509 -CA CA.crt -CAkey CA.key -req -CAserial CA.srl -req -in $csr -out $crt -days 1825");
  18.  
  19. my $enter = ("Enter pass phrase for CA.key:");
  20.  
  21. my $exp = new Expect;
  22.  
  23. $exp->debug(2);
  24. $exp->raw_pty(0);
  25. $exp->spawn($sign_command)
  26.     or die "Cannot spawn sign_command.\n";
  27.  
  28. $exp->match("$enter");
  29. $exp->send ("$pass\r");
  30. $exp->soft_close();
  31.  
  32. print "\n$csr successfully signed into $crt\n";   
But this is as far as the script goes when run:

Expand|Select|Wrap|Line Numbers
  1. pa$$phrase
  2.  
  3. Attempting to sign good.csr to good.crt...
  4.  
  5. Signature ok
  6. subject=/C=US/ST=State/O=MyCompany LLC/CN=internal.domain.company.com
  7. Getting CA Private Key
  8. Enter pass phrase for CA_NSO.key:


...and that's as far as it gets. Either the $exp->match isn't right or $exp->send isn't really sending. Debug isn't telling me anything and sticking in print statements between the $exp statements doesn't print anything because it's in the middle of an openssl session (at least that's what I think). Is there a way that I can narrow down if expect is seeing match or not sending the passphrase?

Thanks,
-Sean
Dec 6 '07 #1
0 1606

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: User1001 | last post by:
I have been trying to enable/use specific OpenSSL extensions that I use in generating certificates manually, via PHP5 + php5-openssl module/extension. Filling out the "configargs" array with...
3
by: nanard | last post by:
Hi,Bonjour, I m running FreeBSD 4.10 STABLE and using Apache 1.3.x and PHP4. Today, i updated php4 from Ports Tree and there was lot of change. Indeed, no more php4-something package... only...
0
by: Kirt Loki Dankmyer | last post by:
So, I download the latest "stable" tar for perl (5.8.7) and try to compile it on the Solaris 8 (SPARC) box that I administrate. I try all sorts of different switches, but I can't get it to compile....
17
by: cpptutor2000 | last post by:
Could some C guru please help me? I have a simple piece of code as: #include <stdio.h> #include <stdlib.h> #include <openssl/rand.h> int main(){ unsigned char temp; RAND_bytes(temp, 4);
1
by: laredotornado | last post by:
Hello, I downloaded PHP 4.4.4 and am trying to install for Apache 2 on Fedora Core 5. However when trying to configure with openssl, I get this error, configure: error: Cannot find...
1
by: graphman | last post by:
I have a perl script that I'm calling using php's shell_exec that uses an expect module to go to another system to pull tiff files. The php perl combination works great when I launch from the...
4
by: Patrick | last post by:
Hello, I'm currently trying the OpenSSL Library, but I got some problems. I want to create a server and client application that communicate through the OpenSSL API, but this code doesn't work. I...
2
by: vermarajeev | last post by:
Hi guys, I have written code to encrypt and decrypt files using perl script. Please help me to port below code to crypto++ library. //ENCRYPTION my $cipher = Crypt::CBC->new( -cipher =>...
5
by: Chuck Anderson | last post by:
I run Apache 2.0.55, and Php (both 4.4.1 and 5.2.5) on my home PC (Windows XP). One of the scripts that I run daily needs to access a secure URL (https://..............). When I am running Php4,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.