This is the mail archive of the mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: "contents altered after message signed" when sending openssl smime signed messages - SOLVED

Summary of problem:
1) "Wrong linefeeds" and 2) "extra lines" by ssmtp prevented messages signed
by openssl in with a detached signature to be seen as valid by outlook.

Re 1) Brian suggested "u2d" and "d2u" and it seems that this works (although
these programs unfortunately have no "-o" parameter to specify the output
file ==> your original input may be gone due to "in-place" replacements
before you really understand how u2d works   ;)  )

Re 2) As I chose a perl approach to solve the 2nd problem by replacing
ssmtp, I am doing the linefeed fix in that perl script now too!
As per Steve' suggestion, I first did

  perl -MCPAN -e 'install Net::SMTP'

Then I wrote the attached script - it works nicely for my sample test case,
but I certainly would need a lot more work to be fully useable:

<<openssl smime -sign -in message.txt -text -signer mycert.pem -from -to -subject "Signed message from cygwin" |

Remaining ToDo's (at least):
i) deal with multiple recipients in the To, Cc, Bcc fields
ii) I have to put CRT-ENTER after my signing password, with just "ENTER"
openssl declares my signing password to be invalid.

Hope this (maybe a little bit too long) thread is useful to other cygwin
users who might want to use openssl to sign a message. If I get improvement
suggestions for the below scripts, I am happy to make the most recent and
IMHO best version of the perl script available via a URL.

#!/usr/bin/perl -w

while ( $line=<> ) {
    $line =~ s/$/\r/ ;
    if ($lineCounter == 1 ) {
        $line=~ /From:\s([^\s]+)/ ;

    if ($sender eq "" ) {
		print STDERR "No sender specified in second line!\n";
	    # printing the warning only here because it might interfere
	    # with openssl dialogs
	    print STDERR "Warning: make sure, exim is running on $smtpHost or
specify any other smtp server that doesn't ask for auth or
TLS!\n\n/usr/bin/exim -bd -q30m\n";
	    use Net::SMTP;

	    $smtp = Net::SMTP->new($smtpHost
          # the next 3 lines are optional!
	    #		   , Hello => $fromDomain,
	    #		   Timeout => 30,
          #          Debug   => 1,


    if ($lineCounter == 0 ) {
	$line=~ /To:\s([^\s]+)/ ;
	if ($recipient eq "" ) {
		print STDERR "No recipient specified in first line!\n";
    if ($lineCounter > 1 ) {
# don't erase this line, otherwise, perl will complain about a variable been
# only once
print STDERR "Message sent from domain \"$fromDomain\"!\n";

Unsubscribe info:
Problem reports:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]