private void addCertificate(final Element x509DataDom, final X509Certificate x509Certificate) { final byte[] encoded = DSSUtils.getEncoded(x509Certificate); final String base64Encoded = DSSUtils.base64Encode(encoded); // <ds:X509Certificate>...</ds:X509Certificate> DSSXMLUtils.addTextElement(documentDom, x509DataDom, XMLNS, DS_X509_CERTIFICATE, base64Encoded); }
@Override public String toString() { return "CertificateRef[issuerName=" + issuerName + ",issuerSerial=" + issuerSerial + ",digest=" + DSSUtils.encodeHexString(digestValue) + "]"; } }
/** * @param digestAlgorithm the digest algorithm to set */ public void setDigestAlgorithm(final DigestAlgorithm digestAlgorithm) { this.digestAlgorithm = digestAlgorithm; if (this.digestAlgorithm != null && this.encryptionAlgorithm != null) { signatureAlgorithm = SignatureAlgorithm.getAlgorithm(this.encryptionAlgorithm, this.digestAlgorithm); } }
/** * This method loads a certificate from a base 64 encoded String * * @param base64Encoded * @return */ public static X509Certificate loadCertificateFromBase64EncodedString(final String base64Encoded) { final byte[] bytes = DSSUtils.base64Decode(base64Encoded); return loadCertificate(bytes); }
public String toString() { return "TimestampParameters{" + ", digestAlgorithm=" + digestAlgorithm.getName() + ", canonicalizationMethod=" + canonicalizationMethod + "}"; } }
/** * Creates dss document that retains the data in memory * * @param inputStream input stream representing the document * @param name the file name if the data originates from a file * @param mimeType the mime type of the file if the data originates from a file * @throws IOException */ public InMemoryDocument(final InputStream inputStream, final String name, final MimeType mimeType) throws DSSException { this(DSSUtils.toByteArray(inputStream), name, mimeType); }
/** * This method returns an {@code InputStream} which needs to be closed, based on {@code FileInputStream}. * * @param filePath The path to the file to read * @return an {@code InputStream} materialized by a {@code FileInputStream} representing the contents of the file * @throws DSSException */ public static InputStream toInputStream(final String filePath) throws DSSException { final File file = getFile(filePath); final InputStream inputStream = toInputStream(file); return inputStream; }
@Override public InputStream openStream() throws DSSException { final InputStream inputStream = DSSUtils.toInputStream(file); return inputStream; }
/** * This method writes raw {@link org.w3c.dom.Node} (without blanks) to the outputStream. * * @param node * @param out */ public static void printRawDocument(final Node node, final OutputStream out) { trimWhitespace(node); printDocument(node, out, true); }
private void addRoles(final List<String> signerRoles, final Element rolesDom, final String roleType) { for (final String signerRole : signerRoles) { final Element roleDom = DSSXMLUtils.addElement(documentDom, rolesDom, XAdES, roleType); DSSXMLUtils.setTextNode(documentDom, roleDom, signerRole); } }
/** * This method returns the list of ds:Object elements for the current signature element. * * @return */ public NodeList getObjects() { return DSSXMLUtils.getNodeList(signatureElement, xPathQueryHolder.XPATH_OBJECT); }
/** * Checks the presence of SigAndRefsTimeStamp segment in the signature, what is the proof -X profile existence * * @return true if the -X extension is present */ public boolean hasXProfile() { boolean signAndRefs = DSSXMLUtils.count(signatureElement, xPathQueryHolder.XPATH_COUNT_SIG_AND_REFS_TIMESTAMP) > 0; return signAndRefs; }
/** * This method writes formatted {@link org.w3c.dom.Node} to the outputStream. * * @param node * @param out */ public static void printDocument(final Node node, final OutputStream out) { printDocument(node, out, false); }
/** * This constructor allows to instantiate the validation context with the given date expressed as year, month and day. * * @param year the value used to set the YEAR calendar field. * @param month the month. Month value is 1-based. e.g., 1 for January. * @param day the value used to set the DAY_OF_MONTH calendar field. */ public CustomDateProcessExecutor(int year, int month, int day) { currentTime = DSSUtils.getUtcDate(year, month - 1, day); } }
/** * This method registers the default transforms. */ private static void registerDefaultTransforms() { registerTransform(Transforms.TRANSFORM_BASE64_DECODE); registerTransform(Transforms.TRANSFORM_ENVELOPED_SIGNATURE); registerTransform(Transforms.TRANSFORM_XPATH); registerTransform(Transforms.TRANSFORM_XPATH2FILTER); registerTransform(Transforms.TRANSFORM_XPOINTER); registerTransform(Transforms.TRANSFORM_XSLT); }
/** * This method registers the default canonicalizers. */ private static void registerDefaultCanonicalizers() { registerCanonicalizer(Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS); registerCanonicalizer(Canonicalizer.ALGO_ID_C14N_EXCL_OMIT_COMMENTS); registerCanonicalizer(Canonicalizer.ALGO_ID_C14N11_OMIT_COMMENTS); registerCanonicalizer(Canonicalizer.ALGO_ID_C14N_PHYSICAL); registerCanonicalizer(Canonicalizer.ALGO_ID_C14N_WITH_COMMENTS); registerCanonicalizer(Canonicalizer.ALGO_ID_C14N_EXCL_WITH_COMMENTS); registerCanonicalizer(Canonicalizer.ALGO_ID_C14N11_WITH_COMMENTS); }
/** * Converts an array of bytes into an array of characters representing the hexadecimal values of each byte in order. * The returned array will be double the length of the passed array, as it takes two characters to represent any * given byte. * * @param data a byte[] to convert to Hex characters * @return A char[] containing hexadecimal characters */ public static char[] encodeHex(byte[] data) { return encodeHex(data, true); }
public List<String> getPolicyIdentifiers() { if (policyIdentifiers == null) { policyIdentifiers = DSSUtils.getPolicyIdentifiers(x509Certificate); } return policyIdentifiers; }
/** * Creates dss document that retains the data in memory * * @param inputStream input stream representing the document * @throws DSSException */ public InMemoryDocument(final InputStream inputStream) throws DSSException { this(DSSUtils.toByteArray(inputStream), null, null); }
/** * Checks the presence of CertificateValues and RevocationValues segments in the signature, what is the proof -A profile existence * * @return true if -A extension is present */ public boolean hasAProfile() { final boolean archiveTimestamp = DSSXMLUtils.count(signatureElement, xPathQueryHolder.XPATH_COUNT_ARCHIVE_TIMESTAMP) > 0; final boolean archiveTimestamp141 = DSSXMLUtils.count(signatureElement, xPathQueryHolder.XPATH_COUNT_ARCHIVE_TIMESTAMP_141) > 0; final boolean archiveTimestampV2 = DSSXMLUtils.count(signatureElement, xPathQueryHolder.XPATH_COUNT_ARCHIVE_TIMESTAMP_V2) > 0; return archiveTimestamp || archiveTimestamp141 || archiveTimestampV2; }