EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Signing failed (error 7681 )

Also by EldoS: MsgConnect
Cross-platform protocol-independent communication framework for building peer-to-peer and client-server applications and middleware components.
#25310
Posted: 06/14/2013 13:07:37
by Mario Calderón (Basic support level)
Joined: 04/25/2013
Posts: 16

Hello,

I am modifing ASPNet_Distributed sample of the PDFBlackBox to able to sign documents which source is not a file stored in file system, but a memory stream, so basically I have substituted FileStream by a MemoryStream.

Everything seems to run fine until it posts results to Result.aspx on the FinishSigning method. Inside the try statement there is this:

"doc.CompleteAsyncOperation(input, state, handler);"

where, in this case, MemoryStream input = new MemoryStream(signature);

however, when I get to that point I get this error message: "Signing failed (error 7681 )" which according to your documentation stands for "Buffer doesn't contain a valid PKCS#7 sequence"
#25311
Posted: 06/14/2013 13:22:31
by Eugene Mayevski (EldoS Corp.)

Most common mistake is to write something to the stream (stream pointer is at the *end* of the stream now) and pass the stream to the method that reads from the stream.

You need to set stream's pointer to the position from which the data begins, which in most cases is 0, before passing the stream to the method.


Sincerely yours
Eugene Mayevski
#25313
Posted: 06/14/2013 15:37:03
by Mario Calderón (Basic support level)
Joined: 04/25/2013
Posts: 16

Thank you very much.

I did as suggested, but the problem persists, I am still getting this exception:
Signing failed (error 7681 )

at
SBPDFSecurity.TElPDFPublicKeySecurityHandler.CompleteAsyncSign(Byte[] PreSig, TElDCAsyncState State)
at SBPDF.TElPDFDocument.CompleteAsyncOperation(Stream Stream, TElDCAsyncState AsyncState, TElPDFSecurityHandler Handler)
#25314
Posted: 06/14/2013 18:32:24
by Ken Ivanov (EldoS Corp.)

Mario,

Please re-check that 'signature' array contains exactly the bytes you'd received from TElPDFDocument on the pre-signing stage. Please note that .NET classes like StreamReader or StreamWriter are not binary-friendly so they may corrupt pre-signed documents.

If your check reveals that the 'signature' bytes are correct, please post the created pre-signed document to the Helpdesk and we will have a look into it.
#25319
Posted: 06/17/2013 10:47:31
by Mario Calderón (Basic support level)
Joined: 04/25/2013
Posts: 16

Well, I have change the DCWeb Solution so that I can perform signature from a MemoryStream instead of a FileStream, to do so, I have done this: (I am using the Applet)

On Presigner class and Page_Load method:

1. Commenting this line
FileStream input = new FileStream(signedFile, FileMode.Open, FileAccess.ReadWrite);

2. Adding these lines:
string inputFileName = Server.MapPath("../Data/sample.pdf");
int extraSpace = 1024;
MemoryStream input;
using (FileStream fs = File.OpenRead(inputFileName))
{
int capacity = extraSpace + (int)fs.Length;
input = new MemoryStream(capacity);
fs.CopyTo(input);
}
input.Position = 0;

3. And this:
signature.ExtraSpace = extraSpace;

Then, everything remains the same, and I got this:


Signing failed (error 7682 )


at SBPDFSecurity.TElPDFPublicKeySecurityHandler.CompleteAsyncSign(Byte[] PreSig, TElDCAsyncState State)
at SBPDF.TElPDFDocument.CompleteAsyncOperation(Stream Stream, TElDCAsyncState AsyncState, TElPDFSecurityHandler Handler)
at DCWeb.Result.FinishSigning(String& fileName, Byte[] signature) en C:\Users\mcalderon\Desktop\ASPNet_Distributed\Result.aspx.cs:line 31

Am I missing something?
#25320
Posted: 06/17/2013 12:59:52
by Ken Ivanov (EldoS Corp.)

Mario,

Please try to

1) Open the file in the following way:

FileStream fs = new FileStream(inputFileName, FileMode.Open);

2) Create the memory stream in the following way:

input = new MemoryStream();

If this doesn't help, could you please show us how exactly are you dealing with files on the pre-signing stage?
#25321
Posted: 06/17/2013 13:11:08
by Mario Calderón (Basic support level)
Joined: 04/25/2013
Posts: 16

Hello,

It did not work.

This is the code I have PreSigner.Page_Load event:

Code
protected virtual void Page_Load(object sender, EventArgs e)
        {
            SBUtils.Unit.SetLicenseKey("AF47...A57A");

            string signedFile = Server.MapPath("../Data/" + Session.SessionID + ".tmp");
            Cache[Session.SessionID] = signedFile;
            File.Copy(Server.MapPath("../Data/sample.pdf"), signedFile, true);

            TElDCAsyncState state;

            TElPDFDocument doc = new TElPDFDocument();
            TElPDFPublicKeySecurityHandler handler = new TElPDFPublicKeySecurityHandler();
            TElPDFSignature signature;

            //FileStream input = new FileStream(signedFile, FileMode.Open, FileAccess.ReadWrite);
            string inputFileName = signedFile;
            int extraSpace = 1024;
            MemoryStream input;
            int capacity = 0;
            using (FileStream fs = new FileStream(inputFileName, FileMode.Open)) //File.OpenRead(inputFileName))
            {
                capacity = extraSpace + (int)fs.Length;
                input = new MemoryStream(capacity);
                fs.CopyTo(input);
            }
            input.Position = 0;
            try
            {
                doc.Open(input);

                handler.SignatureType = TSBPDFPublicKeySignatureType.pstPKCS7SHA1;
                handler.HashAlgorithm = SBConstants.__Global.SB_ALGORITHM_DGST_SHA1;
                handler.CustomName = "Adobe.PPKMS";

                signature = doc.get_Signatures(doc.AddSignature());
                signature.SignatureType = SBPDF.__Global.stDocument;
                signature.Invisible = true;
                signature.Handler = handler;
                signature.SigningTime = DateTime.UtcNow;
                signature.ExtraSpace = 1024;

                state = doc.InitiateAsyncOperation();
            }
            finally
            {
                input.Close();
            }

            output = new MemoryStream();
            state.SaveToStream(output, SBDCXMLEnc.__Global.DCXMLEncoding());
        }
#25330
Posted: 06/18/2013 03:10:12
by Ken Ivanov (EldoS Corp.)

Mario,

As far as I can see you are not saving the pre-signed document (the contents of the 'input' stream after the InitiateAsyncOperation() call) anywhere. You should save it on server on the pre-signing stage and pass to the CompleteAsyncOperation() method on the finalization stage.
#25340
Posted: 06/18/2013 11:10:08
by Mario Calderón (Basic support level)
Joined: 04/25/2013
Posts: 16

Thank you!
I did as suggested, and worked.
Also by EldoS: CallbackDisk
Create virtual disks backed by memory or custom location, expose disk images as disks and more.

Reply

Statistics

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