You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

EnvelopedSignatureFacet.java 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* ====================================================================
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. /* ====================================================================
  16. This product contains an ASLv2 licensed version of the OOXML signer
  17. package from the eID Applet project
  18. http://code.google.com/p/eid-applet/source/browse/trunk/README.txt
  19. Copyright (C) 2008-2014 FedICT.
  20. ================================================================= */
  21. package org.apache.poi.poifs.crypt.dsig.facets;
  22. import static org.apache.poi.poifs.crypt.dsig.facets.SignatureFacetHelper.newReference;
  23. import static org.apache.poi.poifs.crypt.dsig.facets.SignatureFacetHelper.newTransform;
  24. import java.util.ArrayList;
  25. import java.util.List;
  26. import javax.xml.crypto.dsig.CanonicalizationMethod;
  27. import javax.xml.crypto.dsig.Reference;
  28. import javax.xml.crypto.dsig.Transform;
  29. import javax.xml.crypto.dsig.XMLObject;
  30. import javax.xml.crypto.dsig.XMLSignatureException;
  31. import org.apache.poi.poifs.crypt.dsig.SignatureInfo;
  32. import org.w3c.dom.Document;
  33. /**
  34. * Signature Facet implementation to create enveloped signatures.
  35. *
  36. * @author Frank Cornelis
  37. */
  38. public class EnvelopedSignatureFacet implements SignatureFacet {
  39. @Override
  40. public void preSign(SignatureInfo signatureInfo
  41. , Document document
  42. , List<Reference> references
  43. , List<XMLObject> objects)
  44. throws XMLSignatureException {
  45. List<Transform> transforms = new ArrayList<>();
  46. Transform envelopedTransform = newTransform(signatureInfo, Transform.ENVELOPED);
  47. transforms.add(envelopedTransform);
  48. Transform exclusiveTransform = newTransform(signatureInfo, CanonicalizationMethod.EXCLUSIVE);
  49. transforms.add(exclusiveTransform);
  50. Reference reference = newReference(signatureInfo, "", transforms, null, null, null);
  51. references.add(reference);
  52. }
  53. }