Sign a document with an external java api

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
seb
Posts: 1
Joined: Mon Feb 25, 2008 11:34 am

Sign a document with an external java api

Post by seb »

I use the java API XMLDSIG to sign a writer document ooo2.3.1 on windows/linux
so I generate the file META-INF/documentsignatures.xml in the document archive.
I' ve got two problems with this signature. (Open office says "invalid signature" when opening the signed document.)

1) the document contains entries (declared in the manifest file) with white space like "Object 1/content.xml". These entries have to be signed and so you find references in my xml element signedinfo:

Code: Select all

	<Signature xmlns="http://www.w3.org/2000/09/xmldsig#" Id="S0">
		<SignedInfo>
			<CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
			<SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
			<Reference URI="Object%201/content.xml">
				<Transforms>
					<Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
				</Transforms>
				<DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
				<DigestValue>chCYpSsrB6IHSUg/roWEfZpCyqI=</DigestValue>
			</Reference> 
                        ....
              </SignedInfo>
the signature need to have an encoded URI for the reference with %20. if not, java gives the error
Illegal character in path at index 25: ObjectReplacements/Object 1
Writer seems to not support this kind of reference. it use white space for the reference.
is it normal ?

2) we could give additional information to the signature with SignatureProperties like the date and time.
if I use xmlns="http://purl.org/dc/elements/1.1/" dublin core namespace. java API can sign the document but core validation failed on this element with id signdatetime.
Writer does not validate the document too.

Code: Select all

<Object>
			<SignatureProperties>
				<SignatureProperty Id="signdatetime" Target="#S0">
					<date xmlns="http://purl.org/dc/elements/1.1/">2008-02-25T10:08:04</date>
				</SignatureProperty>
			</SignatureProperties>
	</Object>
if I don't put this particular namespace, signature and validation are ok in java. Open office does validate the document too, but the date of the signature in the window "file>numeric signatures" gives Date: 00/00/0000 00:00:00 for this field.
Have you got any ideas on this problem of namespace ?


as an illustration I give a signed document with my java code.
there is no references to entries with white space and there is no namespace for the date.
Only this example seems to work between java api and open office signature.
Attachments
doc2.odt
signed document with my java api
(9.53 KiB) Downloaded 433 times
User avatar
Hagar Delest
Moderator
Posts: 33394
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

Re: sign a document with an external java api

Post by Hagar Delest »

I now it's an old thread but I move it to the Java forum, perhaps you'll have more luck there.
LibreOffice 25.2 on Linux Mint Debian Edition (LMDE Faye) and 24.8 portable on Windows 11.
Post Reply