Package javax.xml.crypto.dsig

Examples of javax.xml.crypto.dsig.XMLSignatureException


    protected void checkSearchValueNotNull(Input input) throws Exception { //NOPMD
        LOG.debug("Searching for output element with search value '{}' and sarch type {}", input.getOutputNodeSearch(),
                input.getOutputNodeSearchType());
        if (input.getOutputNodeSearch() == null) {
            throw new XMLSignatureException(String.format("Wrong configruation: Value is missing for output node search %s.",
                    input.getOutputNodeSearchType()));
        }
    }
View Full Code Here


        // grab the signing key
        Element signingElement = feed.getFirstChild(new QName(Common.NS_URI,
                Common.SIGN));
        if (signingElement == null) {
            throw new XMLSignatureException(
                    "Could not find signing key for feed: " + feed.getId());
        }

        // verify that the key matches the id
        PublicKey publicKey = Common.toPublicKeyFromX509(signingElement
                .getText());
        if (Common.fromFeedUrn(feed.getId()) == null
                || !Common.fromFeedUrn(feed.getId()).equals(
                        Common.toFeedId(publicKey))) {
            throw new XMLSignatureException(
                    "Signing key does not match feed id: "
                            + Common.fromFeedUrn(feed.getId()) + " : "
                            + Common.toFeedId(publicKey));
        }

        // prep the verifier
        AbderaSecurity security = new AbderaSecurity(Abdera.getInstance());
        Signature signature = security.getSignature();
        SignatureOptions options = signature.getDefaultSignatureOptions();
        options.setSigningAlgorithm("http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha1");
        options.setSignLinks(false);
        options.setPublicKey(publicKey);

        // validate, persist, and remove each entry
        List<Entry> entries = new LinkedList<Entry>();
        entries.addAll(feed.getEntries()); // make a copy
        String existingEntryXml;
        for (Entry entry : feed.getEntries()) {
            String feedId = Common.toFeedIdString(feed.getId());
            long entryId = Common.toEntryId(entry.getId());
            try {
                try {
                    existingEntryXml = persistence.readEntry(feedId, entryId);
                } catch (FileNotFoundException fnfe) {
                    existingEntryXml = null;
                }
                if (existingEntryXml != null) {
                    Entry parsed = (Entry) Abdera.getInstance().getParser()
                            .parse(new StringReader(existingEntryXml))
                            .getRoot();
                    if (entry.getUpdated().after(parsed.getUpdated())) {
                        // discard what we have in cache
                        existingEntryXml = null;
                    }
                }
            } catch (Exception e) {
                existingEntryXml = null;
                log.warn(
                        "Unexpected error parsing existing entry before validation: "
                                + entry.getId(), e);
            }
            if (existingEntryXml != null) {
                log.trace("Skipping validation for existing entry: "
                        + entry.getId());
            } else {
                if (!signature.verify(entry, options)) {
                    // failed validation
                    Element activity = entry.getExtension(new QName(
                            "http://activitystrea.ms/spec/1.0/", "verb",
                            "activity"));
                    // if not a 'deleted' entry
                    if (activity == null
                            || !"deleted".equals(activity.getText())) {
                        // TODO: should validate that the 'delete' entry that
                        // this entry mentions is mentioning this entry
                        log.warn("Could not verify signature for entry with id: "
                                + feed.getId());
                        // fail ingest
                        throw new XMLSignatureException(
                                "Could not verify signature for entry with id: "
                                        + entry.getId() + " : " + feed.getId());
                    } else {
                        log.warn("Skipping signature verification for deleted entry: "
                                + feed.getId());
                    }
                }
                try {
                    // yield a bit while validating entries
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    log.error("Should never happen: ", e);
                }
            }

            // remove from feed parent
            entry.discard();
            try {
                // see if this file already exists
                storage.readEntry(Common.toFeedIdString(feed.getId()),
                        Common.toEntryId(entry.getId()));
                // this file exists; remove from processing
                entries.remove(entry);
            } catch (FileNotFoundException e) {
                // file does not already exist: resume
            }
        }
        // setEditDetail(request, entry, key);
        // String edit = entry.getEditLinkResolvedHref().toString();

        // remove all navigation links before signing
        for (Link link : feed.getLinks()) {
            if (Link.REL_FIRST.equals(link.getRel())
                    || Link.REL_LAST.equals(link.getRel())
                    || Link.REL_CURRENT.equals(link.getRel())
                    || Link.REL_NEXT.equals(link.getRel())
                    || Link.REL_PREVIOUS.equals(link.getRel())) {
                link.discard();
            }
        }
        // remove all opensearch elements before verifying
        for (Element e : feed
                .getExtensions("http://a9.com/-/spec/opensearch/1.1/")) {
            e.discard();
        }

        // now validate feed signature sans entries
        if (!signature.verify(feed, options)) {
            log.warn("Could not verify signature for feed with id: "
                    + feed.getId());
            throw new XMLSignatureException(
                    "Could not verify signature for feed with id: "
                            + feed.getId());
        }

        // persist feed
View Full Code Here

                .newCanonicalizationMethod(signatureConfig.getCanonicalizationMethod(),
                (C14NMethodParameterSpec) null);
            signedInfo = signatureFactory.newSignedInfo(
                canonicalizationMethod, signatureMethod, references);
        } catch (GeneralSecurityException e) {
            throw new XMLSignatureException(e);
        }

        /*
         * JSR105 ds:Signature creation
         */
 
View Full Code Here

    protected Transform newTransform(String canonicalizationMethod, TransformParameterSpec paramSpec)
    throws XMLSignatureException {
        try {
            return getSignatureFactory().newTransform(canonicalizationMethod, paramSpec);
        } catch (GeneralSecurityException e) {
            throw new XMLSignatureException("unknown canonicalization method: "+canonicalizationMethod, e);
        }
    }
View Full Code Here

        XMLSignatureFactory sigFac = signatureConfig.getSignatureFactory();
        DigestMethod digestMethod;
        try {
            digestMethod = sigFac.newDigestMethod(digestMethodUri, null);
        } catch (GeneralSecurityException e) {
            throw new XMLSignatureException("unknown digest method uri: "+digestMethodUri, e);
        }

        Reference reference;
        if (digestValue == null) {
            reference = sigFac.newReference(uri, digestMethod, transforms, type, id);
View Full Code Here

            PackageRelationshipCollection prc;
            try {
                prc = new PackageRelationshipCollection(ooxml);
                prc.parseRelationshipsPart(pp);
            } catch (InvalidFormatException e) {
                throw new XMLSignatureException("Invalid relationship descriptor: "+pp.getPartName().getName(), e);
            }
           
            RelationshipTransformParameterSpec parameterSpec = new RelationshipTransformParameterSpec();
            for (PackageRelationship relationship : prc) {
                String relationshipType = relationship.getRelationshipType();
               
                /*
                 * ECMA-376 Part 2 - 3rd edition
                 * 13.2.4.16 Manifest Element
                 * "The producer shall not create a Manifest element that references any data outside of the package."
                 */
                if (TargetMode.EXTERNAL == relationship.getTargetMode()) {
                    continue;
                }

                if (!isSignedRelationship(relationshipType)) continue;

                parameterSpec.addRelationshipReference(relationship.getId());

                // TODO: find a better way ...
                String partName = baseUri + relationship.getTargetURI().toString();
                try {
                    partName = new URI(partName).normalize().getPath().replace('\\', '/');
                    LOG.log(POILogger.DEBUG, "part name: " + partName);
                } catch (URISyntaxException e) {
                    throw new XMLSignatureException(e);
                }
               
                String contentType;
                try {
                    PackagePartName relName = PackagingURIHelper.createPartName(partName);
                    PackagePart pp2 = ooxml.getPart(relName);
                    contentType = pp2.getContentType();
                } catch (InvalidFormatException e) {
                    throw new XMLSignatureException(e);
                }
               
                if (relationshipType.endsWith("customXml")
                    && !(contentType.equals("inkml+xml") || contentType.equals("text/xml"))) {
                    LOG.log(POILogger.DEBUG, "skipping customXml with content type: " + contentType);
View Full Code Here

     *
     * @see org.picketlink.identity.federation.PicketLinkLogger#signatureError(java.lang.Throwable)
     */
    @Override
    public XMLSignatureException signatureError(Throwable e) {
        return new XMLSignatureException(ErrorCodes.SIGNING_PROCESS_FAILURE, e);
    }
View Full Code Here

     *
     * @see org.picketlink.identity.federation.PicketLinkLogger#signatureInvalidError(java.lang.String, java.lang.Throwable)
     */
    @Override
    public XMLSignatureException signatureInvalidError(String message, Throwable t) {
        return new XMLSignatureException(ErrorCodes.INVALID_DIGITAL_SIGNATURE + message);
    }
View Full Code Here

        return stsUnableToDecodePasswordError;
    }

    @Override
    public final XMLSignatureException signatureInvalidError(final String message, final Throwable t) {
        XMLSignatureException result = new XMLSignatureException(String.format(((projectCode +"000009: ")+ signatureInvalidError$str()), message), t);
        StackTraceElement[] st = result.getStackTrace();
        result.setStackTrace(Arrays.copyOfRange(st, 1, st.length));
        return result;
    }
View Full Code Here

        return processingError;
    }

    @Override
    public final XMLSignatureException signatureError(final Throwable t) {
        XMLSignatureException result = new XMLSignatureException(String.format(((projectCode +"000100: ")+ signatureError$str())), t);
        StackTraceElement[] st = result.getStackTrace();
        result.setStackTrace(Arrays.copyOfRange(st, 1, st.length));
        return result;
    }
View Full Code Here

TOP

Related Classes of javax.xml.crypto.dsig.XMLSignatureException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.