EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Try to read office binary signed documents

Also by EldoS: CallbackDisk
Create virtual disks backed by memory or custom location, expose disk images as disks and more.
Posted: 12/12/2011 03:41:42
by NIkolai  (Basic support level)
Joined: 12/06/2011
Posts: 8

Hello, I want to thank you for the great job you have done with writing your product in java. I am trying to read an MS Word 2003 document signed with smart card or self signed certificate. Your code says that the document is signed. Then when I try do get some data from the certificate my problems begin. Here is what I am doing:

TElFileStream fileStream = new TElFileStream("D:\\testSigned_2003_selfCert.doc", "rw", true);
TElOfficeBinaryDocument officeDocument = new TElOfficeBinaryDocument();
System.out.println("Signed = true");
for (int i = 0; i < officeDocument.GetSignatureHandlerCount(); i++){
TElOfficeBinaryCustomSignatureHandler tmpSignatureHandler = officeDocument.GetSignatureHandler(i);
TElX509Certificate signerCertificate = ((TElOfficeBinaryCryptoAPISignatureHandler)tmpSignatureHandler).GetCertificate();

On the line : TElX509Certificate signerCertificate = ((TElOfficeBinaryCryptoAPISignatureHandler)tmpSignatureHandler).GetCertificate();

the code throws the exception:

java.lang.ClassCastException: SecureBlackbox.Office.TElOfficeBinaryInvalidSignatureHandler cannot be cast to SecureBlackbox.Office.TElOfficeBinaryCryptoAPISignatureHandler
at test.VaskoTest.testname(VaskoTest.java:67)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

I was looking at the C# code(because I couldn't find examples in java) to come up with this solution FOR JAVA. Can you tell me am I doing something wrong? If I recive this object TElOfficeBinaryInvalidSignatureHandler , what does this mean? That you can not read the Signature? Or I have to implement some other steps to retrieve data for the signature?
Posted: 12/12/2011 03:59:36
by Vsevolod Ievgiienko (EldoS Corp.)

Thank you for contacting us.

Could you please post here (or using Helpdesk) the document so we'll be able to reproduce the problem.
Posted: 12/12/2011 04:01:30
by Vsevolod Ievgiienko (EldoS Corp.)

BTW, try to add these lines of code before you call officeDocument.Open method:
Posted: 12/12/2011 04:02:52
by Dmytro Bogatskyy (EldoS Corp.)

If I recive this object TElOfficeBinaryInvalidSignatureHandler , what does this mean?

It means that a component failed to load a binary signature handler. Please check ErrorMessage property of TElOfficeBinaryInvalidSignatureHandler instance.

P.S. Could you please post a test document here or to helpdesk.
Posted: 12/12/2011 04:08:40
by NIkolai  (Basic support level)
Joined: 12/06/2011
Posts: 8

Thank you for your quick replies! The error message returns NULL :
String err = ((TElOfficeBinaryInvalidSignatureHandler)tmpSignatureHandler).GetErrorMessage();

I will attach the document I am trying to read in the HelpDesk, because here you don't accept .doc.
Posted: 12/12/2011 05:31:27
by NIkolai  (Basic support level)
Joined: 12/06/2011
Posts: 8

The code works fine when I added the code :

Now can I ask additional question then? How can I read the MS Word file from inputStream, not from the hardDrive, because
TElFileStream fileStream = new TElFileStream("D:\\testSigned_2003_selfCert.doc", "rw", true);

accepts the path to file as an argument?
Posted: 12/12/2011 06:04:15
by Vsevolod Ievgiienko (EldoS Corp.)

The only way for now is to read InputStream content into a buffer then write it to a temporary instance of TElFileStream and pass it to Open method. We'll add methods for InputStream processing in the future build.
Posted: 12/12/2011 06:14:00
by NIkolai  (Basic support level)
Joined: 12/06/2011
Posts: 8

Thank you for your replies.
Posted: 12/12/2011 07:45:26
by Vsevolod Ievgiienko (EldoS Corp.)

Just to clarify my last reply.

You can also read a document from InputStream this way without any temporary files:
TElMemoryStream ms = new TElMemoryStream(new InputStream(...));

TElMemoryStream is an analogue of System.IO.MemoryStream so the data will be stored in memory.
Also by EldoS: CallbackFilter
A component to monitor and control disk activity, track file and directory operations (create, read, write, rename etc.), alter file data, encrypt files, create virtual files.



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