From: Rahul S <sr...@gm...> - 2006-09-02 10:08:12
|
Hi, I am new to expect. I am using expect in my program to invoke 'openssl' to encrypt/decrypt files. But it is not working. The following is the code using expect: <START> $command = Expect->spawn ("/usr/bin/openssl", 'enc', '-e', '-cast', '-out', 'file.enc'); $command->expect (10, "enter cast5-cbc encryption password:"); print $command "somepassword\r"; $command->expect (10, "Verifying - enter cast5-cbc encryption password:"); print $command "somepassword\r"; print $command "This is the text to be encrypted\r"; $command->soft_close(); <STOP> The command hangs at the 'soft_close' call. Using strace I found that 'openssl' is still reading from STDIN after I called 'soft_close'. What am I doing wrong here ? Regards, -Rahul S. |
From: Bryan B. <br...@bu...> - 2006-09-02 19:13:20
|
> Hi, > I am new to expect. I am using expect in my program to invoke > 'openssl' to encrypt/decrypt files. But it is not working. The > following is the code using expect: > > <START> > > $command = Expect->spawn ("/usr/bin/openssl", 'enc', '-e', '-cast', > '-out', 'file.enc'); > $command->expect (10, "enter cast5-cbc encryption password:"); > print $command "somepassword\r"; > $command->expect (10, "Verifying - enter cast5-cbc encryption password:"); > print $command "somepassword\r"; > > print $command "This is the text to be encrypted\r"; You havnt finished the openssl command, normally you would send a control-D to terminate the typing. Make this your next command: $command->send("\cD"); Then soft_close() should work. Bryan http://www.sourceforge.net/projects/rover |
From: Austin S. <te...@of...> - 2006-09-03 02:36:36
|
> > 'openssl' to encrypt/decrypt files. But it is not working. The > > following is the code using expect: > > > > <START> > > > > $command = Expect->spawn ("/usr/bin/openssl", 'enc', '-e', '-cast', > > '-out', 'file.enc'); > > $command->expect (10, "enter cast5-cbc encryption password:"); > > print $command "somepassword\r"; > > $command->expect (10, "Verifying - enter cast5-cbc encryption password:"); > > print $command "somepassword\r"; > > > > print $command "This is the text to be encrypted\r"; > > You havnt finished the openssl command, normally you would send a > control-D to terminate the typing. Make this your next command: > > $command->send("\cD"); > > Then soft_close() should work. soft_close should work anyway - it should close the tty and the child process should receive an eof. It's possible this is one of the platforms which closing the tty doesn't create an eof at the child. I originally wasn't aware there were such platforms. But.. even if this is the case it should still get an eof when $self->close() is run. The tty lib should make sure this is the case. Roland: do you agree? But your suggestion of sending \cD is a good one, as a workaround. Austin |
From: Roland G. <rgi...@cp...> - 2006-09-07 07:05:13
|
Hmm, I only test if the MASTER pty gets an EOF if the child closes stdout, this is the reverse case. But I could imagine that there are systems that have this problem... Another possibility that comes to mind is to send a SIGHUP to the child process. But this probably doesn't work in this case. But why not simply pass everything via the command-line? openssl offers several possibilities how the pass-phrase can be passed. No need for Expect here... Regards, Roland On 9/3/06, Austin Schutz <te...@of...> wrote: > > > 'openssl' to encrypt/decrypt files. But it is not working. The > > > following is the code using expect: > > > > > > <START> > > > > > > $command = Expect->spawn ("/usr/bin/openssl", 'enc', '-e', '-cast', > > > '-out', 'file.enc'); > > > $command->expect (10, "enter cast5-cbc encryption password:"); > > > print $command "somepassword\r"; > > > $command->expect (10, "Verifying - enter cast5-cbc encryption password:"); > > > print $command "somepassword\r"; > > > > > > print $command "This is the text to be encrypted\r"; > > > > You havnt finished the openssl command, normally you would send a > > control-D to terminate the typing. Make this your next command: > > > > $command->send("\cD"); > > > > Then soft_close() should work. > > soft_close should work anyway - it should close the tty and the > child process should receive an eof. > It's possible this is one of the platforms which closing the tty > doesn't create an eof at the child. I originally wasn't aware there were > such platforms. But.. even if this is the case it should still get an eof > when $self->close() is run. The tty lib should make sure this is the case. > Roland: do you agree? > > But your suggestion of sending \cD is a good one, as a workaround. > > Austin > > ------------------------------------------------------------------------- > Using Tomcat but need to do more? Need to support web services, security? > Get stuff done quickly with pre-integrated technology to make your job easier > Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 > _______________________________________________ > Expectperl-discuss mailing list > Exp...@li... > https://lists.sourceforge.net/lists/listinfo/expectperl-discuss > |
From: Austin S. <te...@of...> - 2006-09-07 17:30:45
|
On Thu, Sep 07, 2006 at 09:05:07AM +0200, Roland Giersig wrote: > Hmm, I only test if the MASTER pty gets an EOF if the child closes > stdout, this is the reverse case. But I could imagine that there are > systems that have this problem... > > Another possibility that comes to mind is to send a SIGHUP to the > child process. But this probably doesn't work in this case. > Well there are many cases where a child process will look for the eof. If you send it a signal you induce a race condition where data before the eof could conceivably be stuck in a buffer when the signal is received. I wonder what the system designers had in mind here. Bryan: what system is this you were using this on? Would you mind posting your perl -V output, please? > But why not simply pass everything via the command-line? openssl > offers several possibilities how the pass-phrase can be passed. No > need for Expect here... > No, not in this case. Austin |
From: Rahul S <sr...@gm...> - 2006-09-07 07:58:20
|
On 9/7/06, Roland Giersig <rgi...@cp...> wrote: > But why not simply pass everything via the command-line? openssl > offers several possibilities how the pass-phrase can be passed. No > need for Expect here... I don't want to pass the password on the commandline because it will be visible through utilities like 'ps'. Regards, -Rahul S. |
From: Roland G. <rgi...@cp...> - 2006-09-07 10:06:16
|
You can also pass it via stdin or a file (named pipe) or an environment variable etc. ... Just do a 'man openssl' and look for 'PASS PHRASE ARGUMENTS'. Hope this helps, Roland On 9/7/06, Rahul S <sr...@gm...> wrote: > On 9/7/06, Roland Giersig <rgi...@cp...> wrote: > > But why not simply pass everything via the command-line? openssl > > offers several possibilities how the pass-phrase can be passed. No > > need for Expect here... > > I don't want to pass the password on the commandline because it will > be visible through utilities like 'ps'. > > Regards, > > -Rahul S. > > ------------------------------------------------------------------------- > Using Tomcat but need to do more? Need to support web services, security? > Get stuff done quickly with pre-integrated technology to make your job easier > Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 > _______________________________________________ > Expectperl-discuss mailing list > Exp...@li... > https://lists.sourceforge.net/lists/listinfo/expectperl-discuss > |
From: Rahul S <sr...@gm...> - 2006-09-07 11:48:42
|
Passing it through stdin worked. I don't have to use expect after all :) Thanks, -Rahul S. On 9/7/06, Roland Giersig <rgi...@cp...> wrote: > You can also pass it via stdin or a file (named pipe) or an > environment variable etc. ... > > Just do a 'man openssl' and look for 'PASS PHRASE ARGUMENTS'. > > Hope this helps, Roland > > On 9/7/06, Rahul S <sr...@gm...> wrote: > > On 9/7/06, Roland Giersig <rgi...@cp...> wrote: > > > But why not simply pass everything via the command-line? openssl > > > offers several possibilities how the pass-phrase can be passed. No > > > need for Expect here... > > > > I don't want to pass the password on the commandline because it will > > be visible through utilities like 'ps'. |