EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Signing problem in .NET CF

Also by EldoS: CallbackDisk
Create virtual disks backed by memory or custom location, expose disk images as disks and more.
#2537
Posted: 03/17/2007 00:48:26
by Den Tsopa (Basic support level)
Joined: 03/17/2007
Posts: 5

Hello!

I'm trying to sign a plain text message in .NET CF1/2.
I get the following result (in text.txt.pgp):
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

The password for private keys is "testtest" (without quotes).

-----BEGIN PGP SIGNATURE-----
Version: EldoS OpenPGPBlackbox (.NETCF1)

=twTO
-----END PGP SIGNATURE-----

It seems to be invalid, but pgpWriter.ClearTextSign() does not report any error.
Tell me please whats wrong.
Below is the source code:

Code
      private void SignClearText(string strInputFilename, string strOutputFilename,
         TElPGPSecretKey Key) {
         System.IO.FileStream streamInput, streamOutput;
         System.IO.FileInfo info;

         TElPGPKeyring SignKeyring = new TElPGPKeyring();
         TElPGPWriter pgpWriter = new TElPGPWriter();
         try {
            SignKeyring.AddSecretKey(Key);
            pgpWriter.Armor = true;
            pgpWriter.ArmorHeaders.Clear();
            pgpWriter.ArmorHeaders.Add("Version: EldoS OpenPGPBlackbox (.NETCF1)");
            pgpWriter.ArmorBoundary = "PGP MESSAGE";
            pgpWriter.SigningKeys = SignKeyring;
            pgpWriter.EncryptionType = TSBPGPEncryptionType.etPublicKey;
            pgpWriter.HashAlgorithm = 11; //SB_PGP_ALGORITHM_MD_SHA224;
            info = new System.IO.FileInfo(strInputFilename);
            pgpWriter.Filename = info.Name;
            pgpWriter.Timestamp = DateTime.Now;

            streamInput = new FileStream(strInputFilename, FileMode.Open);
            try {
               streamOutput = new FileStream(strOutputFilename, FileMode.Create);
               try {
                  pgpWriter.ClearTextSign(streamInput, streamOutput, 0);
                  Console.WriteLine("The file was signed successfully");
               }
               catch (Exception ex) {
                  Console.WriteLine(ex.Message);
               }
               finally {
                  streamOutput.Close();
               }
            }
            finally {
               streamInput.Close();
            }
         }
         finally {
            //SignKeyring.Dispose();
         }
      }

      private void menuItem1_Click(object sender, EventArgs e) {
         SBUtils.Unit.SetLicenseKey(SBUtils.Unit.BytesOfString("0190...773A"));
         TElPGPKeyring pgpKeyring = new TElPGPKeyring();
         pgpKeyring.Load("\\Program Files\\dkbtest\\dentsopa.pkr", "\\Program Files\\dkbtest\\dentsopa.skr", true);
         SignClearText("\\Program Files\\dkbtest\\text.txt", "\\Program Files\\dkbtest\\text.txt.pgp", pgpKeyring.get_SecretKeys(0));
      }
#2538
Posted: 03/17/2007 01:46:58
by Eugene Mayevski (EldoS Corp.)

You have not specified the password for the secret key in your code. Use TElPGPSecretKey.Passphrase property or handle OnKeyPassphrase event.


Sincerely yours
Eugene Mayevski
#2548
Posted: 03/18/2007 19:29:30
by Den Tsopa (Basic support level)
Joined: 03/17/2007
Posts: 5

Thank you!
#2549
Posted: 03/18/2007 22:21:22
by Den Tsopa (Basic support level)
Joined: 03/17/2007
Posts: 5

Hello!

I've tried to set up the passphrase as you said.
Now SignClearText() call hangs in a dead loop.
It calls pgpWriter_OnKeyPassphrase() infinite times inside that loop, displaying the same call stack each time:

Code
dkbtest.exe!dkbtest.Form1.pgpWriter_OnKeyPassphrase(object Sender = {SBPGP.TElPGPWriter}, SBPGPKeys.TElPGPCustomSecretKey Key = {SBPGPKeys.TElPGPSecretKey}, ref string Passphrase = "testtest", ref bool Cancel = false) Line 141   C#
   SecureBlackbox.PGP.dll!SBPGP.TElPGPWriter.StreamKeyPassphrase(object Sender = {SBPGPStreams.TElPGPSigningStream}, SBPGPKeys.TElPGPCustomSecretKey Key = {SBPGPKeys.TElPGPSecretKey}, ref string Passphrase = "testtest", ref bool Cancel = false) + 0x18 bytes   
   SecureBlackbox.PGP.dll!SBPGPStreams.TElPGPSigningStream.CalculateSignatures@0(SBPGPKeys.TElPGPCustomSecretKey Key = {SBPGPKeys.TElPGPSecretKey}) + 0x27 bytes   
   SecureBlackbox.PGP.dll!SBPGPStreams.TElPGPSigningStream.CalculateSignatures() + 0x69 bytes   
   SecureBlackbox.PGP.dll!SBPGPStreams.TElPGPSigningStream.NFinalize() + 0xe4 bytes   
   SecureBlackbox.PGP.dll!SBPGPStreams.TElPGPSigningStream.DataAvailable() + 0x35 bytes   
   SecureBlackbox.PGP.dll!SBPGP.TElPGPWriter.ProcessStreamSequence(System.IO.Stream SrcStream = {System.IO.FileStream}, System.IO.Stream DestStream = {System.IO.FileStream}) + 0xca bytes   
   SecureBlackbox.PGP.dll!SBPGP.TElPGPWriter.ClearTextSign(System.IO.Stream ASourceStream = {System.IO.FileStream}, System.IO.Stream ADestStream = {System.IO.FileStream}, long Count = 0) + 0x84 bytes   
   dkbtest.exe!dkbtest.Form1.SignClearText(string strInputFilename = "\\Program Files\\dkbtest\\text.txt", string strOutputFilename = "\\Program Files\\dkbtest\\text.txt.pgp", SBPGPKeys.TElPGPSecretKey Key = {SBPGPKeys.TElPGPSecretKey}) Line 121   C#


The source code:
Code
      private void SignClearText(string strInputFilename, string strOutputFilename,
         TElPGPSecretKey Key) {
         System.IO.FileStream streamInput, streamOutput;
         System.IO.FileInfo info;

         TElPGPKeyring SignKeyring = new TElPGPKeyring();
         TElPGPWriter pgpWriter = new TElPGPWriter();
         try {
            SignKeyring.AddSecretKey(Key);
            pgpWriter.Compress = false;
            pgpWriter.CompressionAlgorithm = 1;
            pgpWriter.CompressionLevel = 9;
            pgpWriter.EncryptingKeys = null;
            pgpWriter.InputIsText = false;
            pgpWriter.Protection = SBPGPConstants.TSBPGPProtectionType.ptNormal;
            pgpWriter.SignBufferingMethod = TSBPGPSignBufferingMethod.sbmRewind;
            pgpWriter.TextCompatibilityMode = true;
            pgpWriter.UseNewFeatures = true;
            pgpWriter.UseOldPackets = false;
            pgpWriter.OnKeyPassphrase += new SBPGPStreams.TSBPGPKeyPassphraseEvent(pgpWriter_OnKeyPassphrase);
            //pgpWriter.Passphrases.Add("testtest");

            pgpWriter.Armor = true;
            pgpWriter.ArmorHeaders.Clear();
            pgpWriter.ArmorHeaders.Add("Version: EldoS OpenPGPBlackbox (.NETCF1)");
            pgpWriter.ArmorBoundary = "PGP MESSAGE";
            pgpWriter.SigningKeys = SignKeyring;
            pgpWriter.EncryptionType = TSBPGPEncryptionType.etPublicKey;
            //pgpWriter.HashAlgorithm = 11; //SB_PGP_ALGORITHM_MD_SHA224;
            info = new FileInfo(strInputFilename);
            pgpWriter.Filename = info.Name;
            pgpWriter.Timestamp = DateTime.Now;

            streamInput = new FileStream(strInputFilename, FileMode.Open);
            try {
               streamOutput = new FileStream(strOutputFilename, FileMode.Create);
               try {
                  pgpWriter.ClearTextSign(streamInput, streamOutput, 0);
                  Console.WriteLine("The file was signed successfully");
               }
               catch (Exception ex) {
                  Console.WriteLine(ex.Message);
               }
               finally {
                  streamOutput.Close();
               }
            }
            finally {
               streamInput.Close();
            }
         }
         finally {
            SignKeyring.Dispose();
         }
      }

      void pgpWriter_OnKeyPassphrase(object Sender, TElPGPCustomSecretKey Key, ref string Passphrase, ref bool Cancel) {
         Cancel = false;
         Passphrase = "testtest";
      }

      private void menuItem1_Click(object sender, EventArgs e) {
         SBUtils.Unit.SetLicenseKey(SBUtils.Unit.BytesOfString("0190...773A"));
         TElPGPKeyring pgpKeyring = new TElPGPKeyring();
         pgpKeyring.Load("\\Program Files\\dkbtest\\dentsopa.pkr", "\\Program Files\\dkbtest\\dentsopa.skr", true);
         SignClearText("\\Program Files\\dkbtest\\text.txt", "\\Program Files\\dkbtest\\text.txt.pgp", pgpKeyring.get_SecretKeys(0));
      }
#2550
Posted: 03/19/2007 00:49:06
by Eugene Mayevski (EldoS Corp.)

Please check the documentation - this way will be faster for you.

The event is fired until the correct password is provided.


Sincerely yours
Eugene Mayevski
#2551
Posted: 03/19/2007 01:23:09
by Den Tsopa (Basic support level)
Joined: 03/17/2007
Posts: 5

Of course I read the documentation, just missed that point.
BTW, I tried the pgpWriter.Passphrases.Add() call
instead of using of pgpWriter.OnKeyPassphrase event
with the same result. And I think it is pretty
unexpected behavior when a library hangs in dead loop
on incorrect input data without a chance to fix the
situation.
Anyway, thank you for fast answers. It is working now.
#2552
Posted: 03/19/2007 01:35:49
by Eugene Mayevski (EldoS Corp.)

Quote
Den Tsopa wrote:
And I think it is pretty
unexpected behavior when a library hangs in dead loop
on incorrect input data without a chance to fix the
situation.


???? It's a library for developers who are expected to read the documentation. I.e. the developer has a good chance to fix the situation - RTFM :)


Sincerely yours
Eugene Mayevski
#2553
Posted: 03/19/2007 01:54:06
by Den Tsopa (Basic support level)
Joined: 03/17/2007
Posts: 5

Another question.
I need SHA256 hash algorithm to be used in signing.
But I always get "Hash: SHA224" string in test.txt.pgp file.
I tried to set different values to the ElPGPWriter.HashAlgorithm property without success.
Tell me please what's wrong?
#2555
Posted: 03/19/2007 04:46:52
by Eugene Mayevski (EldoS Corp.)

Seems to be a bug. Passing to HelpDesk.


Sincerely yours
Eugene Mayevski
Also by EldoS: CallbackDisk
Create virtual disks backed by memory or custom location, expose disk images as disks and more.

Reply

Statistics

Topic viewed 6051 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!