473,473 Members | 4,257 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to make an automated password file for perl script

4 New Member
Hi All,
Im new to perl programming and currently using a automation code written in perl by someone else.
My script uses an openssl client to perform some handshake operation using the client certificate, for the handshake to be successful it prompts for a passphrase. So I thought of keeping the passphrase in a file and at run time my ssl client should pick from the file. But I'm nt sure hw to go abt with it any suggestions guys??
Thanks.
Aug 4 '09 #1
8 3054
numberwhun
3,509 Recognized Expert Moderator Specialist
@newperluser
Its not really recommended to keep such things in a file because its a password (phrase... semantics). But, in the interest of automation, I can see the need. So, what I would do is put it into a configuration file with the following structure (just my suggestion):

Expand|Select|Wrap|Line Numbers
  1. name     value
  2.  
You can have as many name/value pairs as you like. Then, you just read in the configuration file as such:

Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use warnings;
  3.  
  4. # Open the config file into a file handle
  5. open(CFGFILE, "<test1.cfg");
  6.  
  7. # Initialize the variables you will be using in the code
  8. my $key;
  9. my $value;
  10. my %config;
  11.  
  12. # Read each line in the config file, then split each line on the
  13. # spaces and into the two variables $key and $value. Then, take
  14. # each and use it to create the entries in the hash
  15. while(<CFGFILE>)
  16. {
  17.     ($key, $value) = split(/\s+/, $_);
  18.     $config{ $key } = $value;
  19. }
  20.  
Now, you have a hash that contains key value pairs. Say you used a config file like the following:

Expand|Select|Wrap|Line Numbers
  1. sslPass     mypass
  2.  
Then you would simply reference your key in the code, where you need it, like so:

Expand|Select|Wrap|Line Numbers
  1. $config{sslPass}
  2.  
That will input the value of mypass where needed. I hope this helps you. My only other suggestion is to make sure that that configuration file is ONLY readable by the user executing the script, that way nobody else can just open it and read it without root.

If you are on windows, then the security is definitely an issue.

Regards,

Jeff
Aug 4 '09 #2
newperluser
4 New Member
Hi Jeff,

Thanks for your reply,

But even after trying out your code My code is not picking the passphrase from the file It stil prompts me for the passphrase

Expand|Select|Wrap|Line Numbers
  1.  
  2. open(CFGFILE, "<../phrase.cfg");
  3. while (<CFGFILE>)
  4. {
  5.   ($key,$value)=split(/\s+/,$_);
  6.    $config{$key}=$value;
  7. }
  8. #My client code , following which it will prompt for passphrase
  9. system("../client -cert ../pfx.pem  -host $ip_address -port $port -verbose -batch 1 >./tls/$ip_address/clientcerttest.log 2>&1");
  10.  
  11. $config{sslPass};
  12. #close(CFGFILE) or die "Could not close file";
  13.  
Can u pls point out whr im going wrong?
Aug 4 '09 #3
numberwhun
3,509 Recognized Expert Moderator Specialist
@newperluser
Well, the first thing you need to do is to please learn to use the code tags that are required to surround code you post in the forums. You can read about it here.

Unfortunately, seeing as how I didn't have any code before, I can now see what is going on and what I gave you isn't going to work. The reason: you are running a system command that is going to prompt for information. One of the few ways to plan for that event is to use something like expect. There is an Expect module in Perl, but it is quite complicated and not very easy to understand, especially if you don't know what expect is.

I guess my only question would be, is does the client you are using have an option that can be added to provide the passphrase at execution? If so, you can add it and put in the variable sequence as the pass phrase and it would be interpolated into its value. That would be the only option I see, but I don't know how the client is coded and what it is using.

If the client is written wholly in Perl, then this might be an opportunity for you to extend it to accept a pass phrase, but again, I don't know what the code is using to do all of this.

Regards,

Jeff
Aug 4 '09 #4
KevinADC
4,059 Recognized Expert Specialist
And if you are on Windows it can only work if you install cygwin as well and run in the cygwin environment. See the Expect modules documentation.
Aug 4 '09 #5
newperluser
4 New Member
I know using expect in my code is going to be really very complex. Unfortunately the client does not have an option to provide the passphrase and the client is coded in C and we dont want to make any changes to it now. So the question nw is hw can this be implemented using perl in the automation script.
Aug 5 '09 #6
numberwhun
3,509 Recognized Expert Moderator Specialist
@newperluser
Since it is a client run from the system command, the only way I can imagine is via the Expect module. I would go to the link I provided and see if you can fashion a solution.

Regards,

Jeff
Aug 5 '09 #7
newperluser
4 New Member
So this would mean I need to seperately install the expect module on every machine that I run this program on.... I run this on multiple platforms and this is going to be a time consuming thing for me :(
Aug 5 '09 #8
KevinADC
4,059 Recognized Expert Specialist
@newperluser
You might want to ask on a forum that discusses the operating system you are running, there might be an application you can use that has nothing to do with perl. But as far as perl goes, the only thing that I know of that sounds like it has a chance is Expect.
Aug 5 '09 #9

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

Similar topics

2
by: john brown | last post by:
There is a web page that I access frequently and would like to automate the authentication of the username and password. I would like to user a perl script but I'm not really sure about the steps....
4
by: Civilian_Target | last post by:
Is there any way in DB2 to automate the taking of a snapshot, for example, a function that will cause a db2 snapshot to be taken every 5 minutes and written to a uniquely named file? Am I better...
6
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
6
by: brettev | last post by:
World, I work at a university where the professors have a system to input grades for assignments and calculate final grades, which is output to an excel file. they are then required to get on a...
3
by: aj | last post by:
DB2 LUW 8.2 FP14 Red Hat AS 2.1 I am using a response file w/ db2setup to install DB2. I then want to install the latest fixpak in the same automated way. Is there any way to use a response...
3
by: uzzi | last post by:
I don't know how to make a php script to work via cron...I want to make it run daily...My server API is CGI/Fast CGI.I have hosting from godaddy and in the help section i found that i have to specify...
1
by: mohanprasadgutta | last post by:
Hi, I need help to open a password protected excel file in perl using Win32:OLE. when I tried to open file in normal way at the time of program execution it is prompting me to enter password. I am...
1
by: 3srt | last post by:
Hello. I am still relatively new to perl and have hit a few bumps along my way to finishing my program. Some background to my question: There are two files: info.html and run.cgi. A user...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.