Author Topic: eMail cert in program.  (Read 542 times)

Offline tultalk

  • Newbie
  • *
  • Posts: 2
eMail cert in program.
« on: April 23, 2018, 11:26:12 AM »
Hi:
I have two Thunderbird client accounts  One called webpass[at]xyz.us is in office. Other webmaster[at]xyz.us
is as indicated the webmaster for website. When someone (registered user) changes their password through a website interface, I am sending email to webpass containing the new password. I want to encrypt that email message. The is sent with sendmail (old v .8) as adapted by me.

The two TB email accounts use two different Ccomodo certs. I exchanged digitally signed messages and  the two accounts are working fine exchanging encrypted messages.

On my website using sendmail, I am trying to use the public key for webpass to send  an encrypted message from webmaster to  webpass.

Using TB webmaster Account Settings | Cert Manager I found the cert from webpass and identified it:
"Not Critical
E-Mail Address: webpass[at]xyz.us"

I exported that and am trying to use it to encrypt message to webpass.  I exported it (.p12) and extracted certs using OpenSSL.

My program code to encrypt the message:

sub encryptMessage {
   my ($public_key, $string) = [at]_;
   warn("public_key at line 208  '$public_key'");       
   my $key_string;
   open(my $pub, "<", \$public_key) || die "$public_key: $!";
   read($pub,$key_string,-s $pub);
   close($pub);
   my $public = Crypt::OpenSSL::RSA->new_public_key($key_string);
   encode_base64($public->encrypt($string));   
   return $string;
}

The call to the above sub is

    my $public_key = '/home/xyzus/public_html/httpsdocs/cgi-bin/perl/Mail/certs/publicCERT.pem';
    warn("public_key at line 669  '$public_key'");
    my $eMessage = encryptMessage($public_key, $mail{'Message'});   
     socket_write($CRLF, \$eMessage, "$CRLF.$CRLF")
           || return fail("send message error");
    socket_read()
        || return fail("message transmission error ($_)");
    $log .= "\nResult: $_";
    # finish
    socket_write("QUIT$CRLF")
           || return fail("send QUIT error");
    socket_read();
    close S;

    return 1;

I have tried generating public_key over and over. Nothing works.

Going back to the .p12 export for webpass, what steps to follow to assure I have the "public key" I need?



Offline tultalk

  • Newbie
  • *
  • Posts: 2
Re: eMail cert in program.
« Reply #1 on: April 24, 2018, 09:30:33 AM »
Revised perl code:

sub encryptMessage {
   my ($publickey, $string) = [at]_;
 
   my $public_key = '/home/bwmjcmus/public_html/httpsdocs/cgi-bin/lib/perl/Mail/certs/publicCERT.pem';
   open(my $fh, "+<", "$public_key") or die "Opening: $!";
   my $key_string;
   read($fh,$key_string, -s $fh);
   warn ("line 214 key_string  '$key_string'");
   close($fh);

   my $public = Crypt::OpenSSL::RSA->new_public_key($key_string);
   encode_base64($public->encrypt($string));   
   return $string;
}



Response:

unrecognized key format at /home/bwmjcmus/public_html/httpsdocs/cgi-bin/lib/perl/Mail/sendMail.pm line 226.



This is public key for target email


<!-- warning: line 214 key_string  'Bag Attributes
    friendlyName: 's COMODO CA Limited ID #2
    localKeyID: 1E 4E 8E FB F7 5E 38 10 C2 BB D4 D3 0F C0 F8 24 A8 BB 11 D9
subject=/emailAddress=webpass[at]bwmjcm.us
issuer=/C=GB/ST=Greater Manchester/L=Salford/O=COMODO CA Limited/CN=COMODO RSA Client Authentication and Secure Email CA
­­­­­BEGIN CERTIFICATE­­­­­
MIIFLTCCBBWgAwIBAgIQQHIIM+WjI1SmTfjZWQEeYTANBgkqhkiG9w0BAQsFADCB
lzELMAkGA1UEBhMCR0IxGzAZBgNVBAgTEkdyZWF0ZXIgTWFuY2hlc3RlcjEQMA4G
A1UEBxMHU2FsZm9yZDEaMBgGA1UEChMRQ09NT0RPIENBIExpbWl0ZWQxPTA7BgNV
BAMTNENPTU9ETyBSU0EgQ2xpZW50IEF1dGhlbnRpY2F0aW9uIGFuZCBTZWN1cmUg
RW1haWwgQ0EwHhcNMTgwNDE4MDAwMDAwWhcNMTkwNDE4MjM1OTU5WjAiMSAwHgYJ
KoZIhvcNAQkBFhF3ZWJwYXNzQGJ3bWpjbS51czCCASIwDQYJKoZIhvcNAQEBBQAD
ggEPADCCAQoCggEBAOYZ5HcQTtsh8NFxMjkZTdumQmL7qulSsYPStyEGiX8KJx9t
s1fN/LbZsh0wbkuvwRIUBjXLdJ6payvVRxcYyXV3XXsBMhr40vhGjjqCaEEl5fCj
SwYN4QyF77WLqJnzs6GC68ZOW5R2JJsx1gM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