List of usage examples for org.w3c.dom Node hashCode
@HotSpotIntrinsicCandidate public native int hashCode();
From source file:Main.java
private static void reorganizeAddAttributes(Node childNode, Iterator attrs) { JsonElement reorganizedJson = REORGANIZED.get(childNode.hashCode() + EMPTY); if (reorganizedJson instanceof JsonObject) { JsonObject objectJson = (JsonObject) reorganizedJson; while (attrs.hasNext()) { Entry entry = (Entry) attrs.next(); objectJson.addProperty(entry.getKey().toString(), entry.getValue().toString().replace(EQ, EMPTY)); }/*from w w w. j av a 2 s . co m*/ } else { System.err.println("ERROR: expected object, found element or null"); } REORGANIZED.remove(childNode.hashCode() + EMPTY); }
From source file:Main.java
private static void reorganizePrimitiveToArray(Node parentNode, JsonObject upperJson, JsonObject childJson, Node childNode, JsonElement existing) { upperJson.remove(parentNode.getNodeName()); JsonArray arrayJson = new JsonArray(); arrayJson.add(existing);//from w ww . jav a 2 s . co m arrayJson.add(new JsonPrimitive(childNode.getNodeValue())); upperJson.add(parentNode.getNodeName(), arrayJson); REORGANIZED.put(parentNode.hashCode() + EMPTY, childJson); }
From source file:Main.java
private static void reorganizeObjectToArray(Node parentNode, JsonObject upperJson, JsonObject childJson, Node childNode, JsonElement existing) { upperJson.remove(parentNode.getNodeName()); JsonArray arrayJson = new JsonArray(); arrayJson.add(existing);/*from w w w. j a v a 2s . c o m*/ childJson.addProperty(childNode.getNodeName(), childNode.getNodeValue()); arrayJson.add(childJson); upperJson.add(parentNode.getNodeName(), arrayJson); REORGANIZED.put(parentNode.hashCode() + EMPTY, childJson); }
From source file:Main.java
private static void processTextNode(Node parentNode, JsonObject upperJson, JsonObject childJson, Node childNode) {//from w w w . j a va2 s. c o m if (upperJson.has(parentNode.getNodeName())) { // upper already has such an element JsonElement existing = upperJson.get(parentNode.getNodeName()); if (existing instanceof JsonArray) { // adding to the already reorganized array ((JsonArray) existing).add(new JsonPrimitive(childNode.getNodeValue())); REORGANIZED.put(parentNode.hashCode() + EMPTY, childJson); } else if (existing instanceof JsonObject) { // found it as an object, so reorganize it reorganizeObjectToArray(parentNode, upperJson, childJson, childNode, existing); } else { // found as a primitive, so reorganize it reorganizePrimitiveToArray(parentNode, upperJson, childJson, childNode, existing); } } else { // no such a node exists yet, so add it as a property to the upper element upperJson.addProperty(parentNode.getNodeName(), childNode.getNodeValue()); } // add the parent node to the added as a value list ADDED_BY_VALUE.add(parentNode); }
From source file:eu.europa.esig.dss.xades.validation.XAdESSignature.java
/** * Gathers the data to be used to calculate the hash value sent to the TSA (messageImprint). * * @param timestampToken/*w w w . java 2 s . c om*/ * {@code TimestampToken} to validate, or {@code null} when adding a new archive timestamp * @param canonicalizationMethod * @return {@code byte} array containing the canonicalized and concatenated timestamped data */ @Override public byte[] getArchiveTimestampData(final TimestampToken timestampToken, String canonicalizationMethod) { if (LOG.isTraceEnabled()) { LOG.trace("--->Get archive timestamp data:" + (timestampToken == null ? "--> CREATION" : "--> VALIDATION")); } canonicalizationMethod = timestampToken != null ? timestampToken.getCanonicalizationMethod() : canonicalizationMethod; /** * 8.2.1 Not distributed case<br> * * When xadesv141:ArchiveTimeStamp and all the unsigned properties covered by its time-stamp certificateToken have the same parent, this * property uses the Implicit mechanism for all the time-stamped data objects. The input to the computation of the digest value MUST be built * as follows: */ try { /** * 1) Initialize the final octet stream as an empty octet stream. */ final ByteArrayOutputStream buffer = new ByteArrayOutputStream(); /** * 2) Take all the ds:Reference elements in their order of appearance within ds:SignedInfo referencing whatever the signer wants to sign * including the SignedProperties element. Process each one as indicated below:<br> * - Process the retrieved ds:Reference element according to the reference processing model of XMLDSIG.<br> * - If the result is a XML node set, canonicalize it. If ds:Canonicalization is present, the algorithm indicated by this element is used. * If not, the standard canonicalization method specified by XMLDSIG is used.<br> * - Concatenate the resulting octets to the final octet stream. */ /** * The references are already calculated {@see #checkSignatureIntegrity()} */ final Set<String> referenceURIs = new HashSet<String>(); for (final Reference reference : references) { try { String uri = reference.getURI(); if (uri.startsWith("#")) { uri = uri.substring(1); } referenceURIs.add(uri); final byte[] bytes = reference.getReferencedBytes(); DSSUtils.write(bytes, buffer); } catch (XMLSignatureException e) { throw new DSSException(e); } } /** * 3) Take the following XMLDSIG elements in the order they are listed below, canonicalize each one and concatenate each resulting octet * stream to the final octet stream:<br> * - The ds:SignedInfo element.<br> * - The ds:SignatureValue element.<br> * - The ds:KeyInfo element, if present. */ writeCanonicalizedValue(xPathQueryHolder.XPATH_SIGNED_INFO, canonicalizationMethod, buffer); writeCanonicalizedValue(xPathQueryHolder.XPATH_SIGNATURE_VALUE, canonicalizationMethod, buffer); writeCanonicalizedValue(xPathQueryHolder.XPATH_KEY_INFO, canonicalizationMethod, buffer); /** * 4) Take the unsigned signature properties that appear before the current xadesv141:ArchiveTimeStamp in the order they appear within the * xades:UnsignedSignatureProperties, canonicalize each one and concatenate each resulting octet stream to the final octet stream. While * concatenating the following rules apply: */ final Element unsignedSignaturePropertiesDom = getUnsignedSignaturePropertiesDom(); if (unsignedSignaturePropertiesDom == null) { throw new NullPointerException(xPathQueryHolder.XPATH_UNSIGNED_SIGNATURE_PROPERTIES); } final NodeList unsignedProperties = unsignedSignaturePropertiesDom.getChildNodes(); for (int ii = 0; ii < unsignedProperties.getLength(); ii++) { final Node node = unsignedProperties.item(ii); if (node.getNodeType() != Node.ELEMENT_NODE) { // This can // happened when // there is a // blank line // between tags. continue; } final String localName = node.getLocalName(); // In the SD-DSS implementation when validating the signature // the framework will not add missing data. To do so the // signature must be extended. // if (localName.equals("CertificateValues")) { /* * - The xades:CertificateValues property MUST be added if it is not already present and the ds:KeyInfo element does not contain the * full set of certificates used to validate the electronic signature. */ // } else if (localName.equals("RevocationValues")) { /* * - The xades:RevocationValues property MUST be added if it is not already present and the ds:KeyInfo element does not contain the * revocation information that has to be shipped with the electronic signature */ // } else if (localName.equals("AttrAuthoritiesCertValues")) { /* * - The xades:AttrAuthoritiesCertValues property MUST be added if not already present and the following conditions are true: there * exist an attribute certificate in the signature AND a number of certificates that have been used in its validation do not appear in * CertificateValues. Its content will satisfy with the rules specified in clause 7.6.3. */ // } else if (localName.equals("AttributeRevocationValues")) { /* * - The xades:AttributeRevocationValues property MUST be added if not already present and there the following conditions are true: * there exist an attribute certificate AND some revocation data that have been used in its validation do not appear in * RevocationValues. Its content will satisfy with the rules specified in clause 7.6.4. */ // } else if (isArchiveTimestamp(localName)) { if ((timestampToken != null) && (timestampToken.getHashCode() == node.hashCode())) { break; } } else if ("TimeStampValidationData".equals(localName)) { /** * ETSI TS 101 903 V1.4.2 (2010-12) 8.1 The new XAdESv141:TimeStampValidationData element ../.. This element is specified to serve * as an optional container for validation data required for carrying a full verification of time-stamp tokens embedded within any * of the different time-stamp containers defined in the present document. ../.. 8.1.1 Use of URI attribute ../.. a new * xadesv141:TimeStampValidationData element SHALL be created containing the missing validation data information and it SHALL be * added as a child of UnsignedSignatureProperties elements immediately after the respective time-stamp certificateToken container * element. */ } byte[] canonicalizedValue; if (timestampToken == null) { // Creation of the timestamp /** * This is the work around for the name space problem: The issue was reported on: * https://issues.apache.org/jira/browse/SANTUARIO-139 and considered as close. But for me (Bob) it still does not work! */ final byte[] bytesToCanonicalize = DSSXMLUtils.serializeNode(node); canonicalizedValue = DSSXMLUtils.canonicalize(canonicalizationMethod, bytesToCanonicalize); } else { canonicalizedValue = DSSXMLUtils.canonicalizeSubtree(canonicalizationMethod, node); } if (LOG.isTraceEnabled()) { LOG.trace(localName + ": Canonicalization: " + canonicalizationMethod); LOG.trace(new String(canonicalizedValue) + "\n"); } buffer.write(canonicalizedValue); } /** * 5) Take all the ds:Object elements except the one containing xades:QualifyingProperties element. Canonicalize each one and concatenate * each resulting octet stream to the final octet stream. If ds:Canonicalization is present, the algorithm indicated by this element is * used. If not, the standard canonicalization method specified by XMLDSIG is used. */ boolean xades141 = (timestampToken == null) || !ArchiveTimestampType.XAdES.equals(timestampToken.getArchiveTimestampType()); final NodeList objects = getObjects(); for (int ii = 0; ii < objects.getLength(); ii++) { final Node node = objects.item(ii); final Node qualifyingProperties = DSSXMLUtils.getElement(node, xPathQueryHolder.XPATH__QUALIFYING_PROPERTIES); if (qualifyingProperties != null) { continue; } if (!xades141) { /** * !!! ETSI TS 101 903 V1.3.2 (2006-03) 5) Take any ds:Object element in the signature that is not referenced by any ds:Reference * within ds:SignedInfo, except that one containing the QualifyingProperties element. Canonicalize each one and concatenate each * resulting octet stream to the final octet stream. If ds:Canonicalization is present, the algorithm indicated by this element is * used. If not, the standard canonicalization method specified by XMLDSIG is used. */ final NamedNodeMap attributes = node.getAttributes(); final int length = attributes.getLength(); String id = ""; for (int jj = 0; jj < length; jj++) { final Node item = attributes.item(jj); final String nodeName = item.getNodeName(); if ("ID".equals(nodeName.toUpperCase())) { id = item.getNodeValue(); break; } } final boolean contains = referenceURIs.contains(id); if (contains) { continue; } } byte[] canonicalizedValue = DSSXMLUtils.canonicalizeSubtree(canonicalizationMethod, node); buffer.write(canonicalizedValue); } final byte[] bytes = buffer.toByteArray(); return bytes; } catch (IOException e) { throw new DSSException("Error when computing the archive data", e); } }