Safelayer Secure Communications
 
 
Search
Home arrow SOAP Axis arrow CMS/PKCS#7 Signature Verification


TeleTrust Innovation Price

Innovation Award
for TrustedX 2007

The European ICT Price. Nominee

for TrustedX 2007

Safelayer Labs
 
Try

Axis examples

CMS/PKCS#7 Signature Verification Print E-mail
21 January 2008

The objective of this example is to validate the document signature produced in the CMS/PKCS#7 Signature Generation.

To try this example, you must download the file called sampleAxis6.zip and follow the instructions in Configuration of the Environment.

The downloaded file already contains a signature to be used for verification, but, if you wish, you can replace this file with the one generated in the CMS/PKCS#7 Signature Generation example, to check the validity of the generated signature.

To perform a signature verification request, you must use a VerifyRequest object which will contain the request for the destination host, just as we saw in the X.509 Certificate Validation example. And as we are dealing with a CMS signature, the profile is CMS/PKCS#7.

VerifyRequest vr = new VerifyRequest();
vr.setProfile(new URI(PROF_VERIF_CMS));

Given that the signature to be verified is detached, the request must include the data for both the signed file and the signature.
The binary encoded signature data are inserted in the request in a SignatureObject object. In addition to the data, it is also stated that the format of the inserted signature is CMS.

SignatureObject sobj = new SignatureObject();
Base64Signature b64sig = new Base64Signature();
b64sig.setType(new URI(TYPE_CMS));
b64sig.set_value(Util.readBinaryFile(path_in + signname));
sobj.setBase64Signature(b64sig);
vr.setSignatureObject(sobj);

The data of the signed file are inserted in the request as InputDocuments, and they are encoded in Base64 inside a Document object.

InputDocuments idoc = new InputDocuments();
Document doc = new Document();
Base64Data b64data = new Base64Data();
b64data.set_value(Util.readBinaryFile(path_in + filename));
doc.setBase64Data(b64data);
idoc.setDocument(doc);
vr.setInputDocuments(idoc);

Once all the data have been entered in the request, the verify() operation is invoked; this operation sends the request to the host and collects the response in a VerifyResponse object.

VerifyResponse vrs = bindingDsv.verify(vr);

Execution of this example will generate a response such as the one seen below.

** RESPONSE **
---------------------
Major: urn:oasis:names:tc:dss:1.0:resultmajor:Success
Minor: urn:oasis:names:tc:dss:1.0:resultminor:ValidSignature_OnAllDocuments
DN: CN=trustedx, OU=Demo, O=TrustedX, C=ES
Issuer Trust Level: 0
Issuer Trust Label: Administration