EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Try to read office binary signed documents

Also by EldoS: Solid File System
A virtual file system that offers a feature-rich storage for application documents and data with built-in compression and encryption.
#18435
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();
officeDocument.Open(fileStream);
if(officeDocument.GetIsSigned()){
System.out.println("Signed = true");
System.out.println(officeDocument.GetSignatureHandlerCount());
for (int i = 0; i < officeDocument.GetSignatureHandlerCount(); i++){
TElOfficeBinaryCustomSignatureHandler tmpSignatureHandler = officeDocument.GetSignatureHandler(i);
TElX509Certificate signerCertificate = ((TElOfficeBinaryCryptoAPISignatureHandler)tmpSignatureHandler).GetCertificate();
}
}
officeDocument.Flush();
officeDocument.Close();

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?
#18439
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.
#18440
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:
Code
SBOffice.Initialize();
SBOfficeSecurity.Initialize();
#18441
Posted: 12/12/2011 04:02:52
by Dmytro Bogatskyy (EldoS Corp.)

Quote
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.
#18442
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();
System.out.println(err);

I will attach the document I am trying to read in the HelpDesk, because here you don't accept .doc.
#18445
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 :
SBOffice.Initialize();
SBOfficeSecurity.Initialize();

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?
#18446
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.
#18447
Posted: 12/12/2011 06:14:00
by NIkolai  (Basic support level)
Joined: 12/06/2011
Posts: 8

Thank you for your replies.
#18448
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:
Code
TElMemoryStream ms = new TElMemoryStream(new InputStream(...));
officeDocument.Open(ms);


TElMemoryStream is an analogue of System.IO.MemoryStream so the data will be stored in memory.
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 1815 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!