EldoS | Feel safer!

Software components for data protection, secure storage and transfer

How do I get the embedded filename?

Also by EldoS: CallbackRegistry
A component to monitor and control Windows registry access and create virtual registry keys.
#25961
Posted: 08/05/2013 13:06:54
by mark fenton (Basic support level)
Joined: 04/02/2012
Posts: 15

Trying to replicate GPG's --use-embedded-filename switch in TElPGPReader.

From the documentation it appears that this should be the default operation when the Outfile property isn't set, or am I misunderstanding that?

At any rate -- I pass an encrypted file with an arbitrary name, and need to get as output the decrypted contents with the filename that was embedded on encryption.

I'm using PowerShell with a call like:

$pgpReader.DecryptAndVerifyFile($FileName)

but the output is null.

in gnupg this would be
gpg --use-embedded-filename $FileName

Ideas appreciated.
#25963
Posted: 08/05/2013 13:55:14
by Eugene Mayevski (EldoS Corp.)

If I understand your question right, you need to handle OnCreateOutputStream event and the filename is passed there. But I don't know if the event can be handled in powershell.

On a side note, please link the license ticket to your user account. The ticket itself and the procedure of its use are specified in the registration e-mail that was sent to you upon license purchase. If you don't have the license ticket, please contact the person from which you have obtained the license key (the one in your source code) for a license ticket.

Having the account linked will let our site (and us) to recognize you as the licensed customer and provide more efficient support.


Sincerely yours
Eugene Mayevski
#26003
Posted: 08/06/2013 20:22:49
by mark fenton (Basic support level)
Joined: 04/02/2012
Posts: 15

I'll have someone look up our license ticket.

At any rate, PowerShell lets us create handlers for events, and if it comes down to it, we could call c# code within the script to handle the event, too.

The Register-ObjectEvent cmdlet lets up subscribe to an event. Where we're failing, I think, is in actually getting the call to the event right. (We crash pretty spectacularly upon event firing.)

Are there any code samples of how this event should/could be handled in C#? I didn't see any on your site.

Our latest attempt looks like this:

$RequestOutputFileAction = {
$event.sourceEventArgument.Path = "\\servername\directory\" + $event.sourceEventArgument.Filename
Write-Output $event.sourceEventArgumement.Path
}

Register-ObjectEvent -InputObject $PGPReader -EventName OnRequestOutputFile -SourceIdentifier DecryptFile -Action $RequestOutputFileAction

And the registration **appears** successful. The process just crashes and takes PowerShell down along with it when it fires the event. -- error is c00000005 -- memory out of bounds. (From the timing of things, it appears that the decryption process starts, but the session dies when the event is fired. -- without the handler, the process finishes, there's just no output because DecryptAndVerifyFile doesn't know where to write anything (unless I have explicitly set .OutputFile prior to decryption.)
#26004
Posted: 08/06/2013 23:25:51
by Eugene Mayevski (EldoS Corp.)

I was saying about OnCreateOutputStream rather than OnRequestOutputFile.

This is from the sample:

Code

        private void pgpReader_OnCreateOutputStream(object Sender, string Filename, DateTime TimeStamp, ref System.IO.Stream Stream, ref bool FreeOnExit)
        {
            if (Filename != "_CONSOLE") // skip 'for eyes only' message
            {
                Stream = new FileStream(editOutputDir.Text + Filename, FileMode.Create);
                FreeOnExit = true;
            }
        }


this.pgpReader.OnCreateOutputStream += new SBPGP.TSBPGPCreateOutputStreamEvent(this.pgpReader_OnCreateOutputStream);


Sincerely yours
Eugene Mayevski
#26053
Posted: 08/07/2013 11:21:14
by mark fenton (Basic support level)
Joined: 04/02/2012
Posts: 15

Ah -- my bad.

So if I trap and handle this event, then I can get the embedded file name.

Thanks, I'll post our code when we have it working.
Also by EldoS: BizCrypto
Components for BizTalk® and SQL Server® Integration Services that let you securely store and transfer information in your business automation solutions.

Reply

Statistics

Topic viewed 3396 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!