/* * Copyright 2003 Federal Chancellery Austria * MOA-SPSS has been developed in a cooperation between BRZ, the Federal * Chancellery Austria - ICT staff unit, and Graz University of Technology. * * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by * the European Commission - subsequent versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: * http://www.osor.eu/eupl/ * * Unless required by applicable law or agreed to in writing, software * distributed under the Licence is distributed on an "AS IS" basis, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and * limitations under the Licence. * * This product combines work with different licenses. See the "NOTICE" text * file for details on the various modules and licenses. * The "NOTICE" text file is part of the distribution. Any derivative works * that you distribute must include a readable copy of the "NOTICE" text file. */ package at.gv.egovernment.moa.spss.server.service; import at.gv.egiz.asic.api.ASiC; import at.gv.egiz.asic.api.ASiCFactory; import at.gv.egiz.asic.api.ASiCFormat; import at.gv.egiz.asic.api.ASiCVerificationResult; import at.gv.egiz.asic.impl.ASiCMOAVerifier; import at.gv.egiz.asic.xmlbind.VerifyASICSignatureRequestParser; import at.gv.egiz.asic.xmlbind.VerifyASICSignatureResponseBuilder; import at.gv.egiz.asic.xmlbind.VerifyASiCRequest; import at.gv.egovernment.moa.spss.MOAApplicationException; import org.apache.axis.AxisFault; import org.w3c.dom.Element; import at.gv.egovernment.moa.spss.MOAException; import at.gv.egovernment.moa.spss.MOASystemException; import at.gv.egovernment.moa.spss.api.cmsverify.VerifyCMSSignatureRequest; import at.gv.egovernment.moa.spss.api.cmsverify.VerifyCMSSignatureResponse; import at.gv.egovernment.moa.spss.api.xmlbind.VerifyCMSSignatureRequestParser; import at.gv.egovernment.moa.spss.api.xmlbind.VerifyCMSSignatureResponseBuilder; import at.gv.egovernment.moa.spss.api.xmlbind.VerifyPDFSignatureResponseBuilder; import at.gv.egovernment.moa.spss.api.xmlbind.VerifyXMLSignatureRequestParser; import at.gv.egovernment.moa.spss.api.xmlbind.VerifyXMLSignatureResponseBuilder; import at.gv.egovernment.moa.spss.api.xmlverify.VerifyXMLSignatureRequest; import at.gv.egovernment.moa.spss.api.xmlverify.VerifyXMLSignatureResponse; import at.gv.egovernment.moa.spss.server.invoke.CMSSignatureVerificationInvoker; import at.gv.egovernment.moa.spss.server.invoke.XMLSignatureVerificationInvoker; import at.gv.egovernment.moa.spss.server.transaction.TransactionContext; import at.gv.egovernment.moa.spss.server.transaction.TransactionContextManager; import at.gv.egovernment.moaspss.logging.Logger; import at.gv.egovernment.moaspss.util.StreamUtils; import java.io.FileInputStream; import java.util.List; /** * The service endpoint for the SignatureVerification web service. * * @author Patrick Peck * @version $Id$ */ public class SignatureVerificationService { /** * Handle a VerifyPDFSignatureRequest. * * @param request The VerifyPDFSignatureRequest to work on * (contained in the 0th element of the array). * @return A VerifyPDFSignatureResponse as the only element of * the Element array. * @throws AxisFault An error occurred during handling of the message. */ public Element[] VerifyPDFSignatureRequest(Element[] request) throws AxisFault { CMSSignatureVerificationInvoker invoker = CMSSignatureVerificationInvoker.getInstance(); Element[] response = new Element[1]; try { // create a parser and builder for binding API objects to/from XML VerifyCMSSignatureRequestParser requestParser = new VerifyCMSSignatureRequestParser(); VerifyPDFSignatureResponseBuilder responseBuilder = new VerifyPDFSignatureResponseBuilder(); Element reparsedReq; VerifyCMSSignatureRequest requestObj; VerifyCMSSignatureResponse responseObj; // create a parser and builder for binding API objects to/from XML /*VerifyPDFRequestParser requestParser = new VerifyPDFRequestParser(); VerifyPDFResponseBuilder responseBuilder = new VerifyPDFResponseBuilder(); Element reparsedReq; VerifyPDFRequest requestObj; VerifyPDFResponse responseObj;*/ //since Axis (1.1 ff) has problem with namespaces we take the raw request stored by the Axishandler. TransactionContext context = TransactionContextManager.getInstance().getTransactionContext(); // validate the request reparsedReq = ServiceUtils.reparseRequest(request[0]);//context.getRequest()); // convert to API objects requestObj = requestParser.parsePDF(reparsedReq); // invoke the core logic responseObj = invoker.verifyCMSSignature(requestObj); // map back to XML response[0] = responseBuilder.build(responseObj).getDocumentElement(); // save response in transaction context.setResponse(response[0]); } catch (MOAException e) { AxisFault fault = AxisFault.makeFault(e); fault.setFaultDetail(new Element[] { e.toErrorResponse()}); Logger.debug("Anfrage zur Signaturpruefung wurde nicht erfolgreich beendet:" + System.getProperty("line.separator") + StreamUtils.getStackTraceAsString(e)); throw fault; } catch (Throwable t) { MOASystemException e = new MOASystemException("2900", null, t); AxisFault fault = AxisFault.makeFault(e); fault.setFaultDetail(new Element[] { e.toErrorResponse()}); Logger.debug("Anfrage zur Signaturpruefung wurde nicht erfolgreich beendet:" + System.getProperty("line.separator") + StreamUtils.getStackTraceAsString(e)); throw fault; } return response; } /** * Handle a VerifyPDFSignatureRequest. * * @param request The VerifyPDFSignatureRequest to work on * (contained in the 0th element of the array). * @return A VerifyPDFSignatureResponse as the only element of * the Element array. * @throws AxisFault An error occurred during handling of the message. */ public Element[] VerifyASICSignatureRequest(Element[] request) throws AxisFault { CMSSignatureVerificationInvoker invoker = CMSSignatureVerificationInvoker.getInstance(); Element[] response = new Element[1]; try { // create a parser and builder for binding API objects to/from XML VerifyASICSignatureRequestParser requestParser = new VerifyASICSignatureRequestParser(); VerifyASICSignatureResponseBuilder responseBuilder = new VerifyASICSignatureResponseBuilder(); Element reparsedReq; VerifyASiCRequest requestObj; VerifyCMSSignatureResponse responseObj; // create a parser and builder for binding API objects to/from XML //since Axis (1.1 ff) has problem with namespaces we take the raw request stored by the Axishandler. TransactionContext context = TransactionContextManager.getInstance().getTransactionContext(); // validate the request reparsedReq = ServiceUtils.reparseRequest(request[0]);//context.getRequest()); // convert to API objects requestObj = requestParser.parseASIC(reparsedReq); if(requestObj.getFormat() == null) { throw new MOAApplicationException("asic.0006", null); } ASiC aSiC = ASiCFactory.parseASiC(requestObj.getAsicInput(), requestObj.getFormat()); Logger.debug("Got ASiC " + aSiC); // invoke the core logic ASiCMOAVerifier v = new ASiCMOAVerifier(); List results = v.verify(aSiC, requestObj.getTrustProfile(), requestObj.getDate()); // map back to XML response[0] = responseBuilder.build(results).getDocumentElement(); // save response in transaction context.setResponse(response[0]); } catch (MOAException e) { AxisFault fault = AxisFault.makeFault(e); fault.setFaultDetail(new Element[] { e.toErrorResponse()}); Logger.debug("Anfrage zur Signaturpruefung wurde nicht erfolgreich beendet:" + System.getProperty("line.separator") + StreamUtils.getStackTraceAsString(e)); throw fault; } catch (Throwable t) { MOASystemException e = new MOASystemException("2900", null, t); AxisFault fault = AxisFault.makeFault(e); fault.setFaultDetail(new Element[] { e.toErrorResponse()}); Logger.debug("Anfrage zur Signaturpruefung wurde nicht erfolgreich beendet:" + System.getProperty("line.separator") + StreamUtils.getStackTraceAsString(e)); throw fault; } return response; } /** * Handle a VerifyCMSSignatureRequest. * * @param request The VerifyCMSSignatureRequest to work on * (contained in the 0th element of the array). * @return A VerifyCMSSignatureResponse as the only element of * the Element array. * @throws AxisFault An error occurred during handling of the message. */ public Element[] VerifyCMSSignatureRequest(Element[] request) throws AxisFault { CMSSignatureVerificationInvoker invoker = CMSSignatureVerificationInvoker.getInstance(); Element[] response = new Element[1]; try { // create a parser and builder for binding API objects to/from XML VerifyCMSSignatureRequestParser requestParser = new VerifyCMSSignatureRequestParser(); VerifyCMSSignatureResponseBuilder responseBuilder = new VerifyCMSSignatureResponseBuilder(); Element reparsedReq; VerifyCMSSignatureRequest requestObj; VerifyCMSSignatureResponse responseObj; //since Axis (1.1 ff) has problem with namespaces we take the raw request stored by the Axishandler. TransactionContext context = TransactionContextManager.getInstance().getTransactionContext(); // validate the request reparsedReq = ServiceUtils.reparseRequest(request[0]);//context.getRequest()); // convert to API objects requestObj = requestParser.parse(reparsedReq); // invoke the core logic responseObj = invoker.verifyCMSSignature(requestObj); // map back to XML response[0] = responseBuilder.build(responseObj).getDocumentElement(); // save response in transaction context.setResponse(response[0]); } catch (MOAException e) { AxisFault fault = AxisFault.makeFault(e); fault.setFaultDetail(new Element[] { e.toErrorResponse()}); Logger.debug("Anfrage zur Signaturpruefung wurde nicht erfolgreich beendet:" + System.getProperty("line.separator") + StreamUtils.getStackTraceAsString(e)); throw fault; } catch (Throwable t) { MOASystemException e = new MOASystemException("2900", null, t); AxisFault fault = AxisFault.makeFault(e); fault.setFaultDetail(new Element[] { e.toErrorResponse()}); Logger.debug("Anfrage zur Signaturpruefung wurde nicht erfolgreich beendet:" + System.getProperty("line.separator") + StreamUtils.getStackTraceAsString(e)); throw fault; } return response; } /** * Handle a VerifyXMLSignatureRequest. * * @param request The VerifyXMLSignatureRequest to work on * (contained in the 0th element of the array). * @return A VerifyXMLSignatureResponse as the only element of * the Element array. * @throws AxisFault An error occurred during handling of the message. */ public Element[] VerifyXMLSignatureRequest(Element[] request) throws AxisFault { XMLSignatureVerificationInvoker invoker = XMLSignatureVerificationInvoker.getInstance(); Element[] response = new Element[1]; try { // create a parser and builder for binding API objects to/from XML VerifyXMLSignatureRequestParser requestParser = new VerifyXMLSignatureRequestParser(); VerifyXMLSignatureResponseBuilder responseBuilder = new VerifyXMLSignatureResponseBuilder(); Element reparsedReq; VerifyXMLSignatureRequest requestObj; VerifyXMLSignatureResponse responseObj; //since Axis (1.1 ff) has problem with namespaces we take the raw request stored by the Axishandler. TransactionContext context = TransactionContextManager.getInstance().getTransactionContext(); // validate the request reparsedReq = ServiceUtils.reparseRequest(context.getRequest()); // convert to API objects requestObj = requestParser.parse(reparsedReq); // invoke the core logic responseObj = invoker.verifyXMLSignature(requestObj); // map back to XML response[0] = responseBuilder.build(responseObj).getDocumentElement(); // save response in transaction context.setResponse(response[0]); } catch (MOAException e) { AxisFault fault = AxisFault.makeFault(e); fault.setFaultDetail(new Element[] { e.toErrorResponse()}); Logger.debug("Anfrage zur Signaturpruefung wurde nicht erfolgreich beendet:" + System.getProperty("line.separator") + StreamUtils.getStackTraceAsString(e)); throw fault; } catch (Throwable t) { MOASystemException e = new MOASystemException("2900", null, t); AxisFault fault = AxisFault.makeFault(e); fault.setFaultDetail(new Element[] { e.toErrorResponse()}); Logger.debug("Anfrage zur Signaturpruefung wurde nicht erfolgreich beendet:" + System.getProperty("line.separator") + StreamUtils.getStackTraceAsString(e)); throw fault; } return response; } }