Class ASiCUtils

java.lang.Object
eu.europa.esig.dss.asic.common.ASiCUtils

public final class ASiCUtils extends Object
Contains utils for working with ASiC containers
  • Field Details

    • MANIFEST_FILENAME

      public static final String MANIFEST_FILENAME
      The manifest name
      See Also:
    • ASIC_MANIFEST_FILENAME

      public static final String ASIC_MANIFEST_FILENAME
      The ASiC Manifest name
      See Also:
    • ASIC_ARCHIVE_MANIFEST_FILENAME

      public static final String ASIC_ARCHIVE_MANIFEST_FILENAME
      The ASiC Archive Manifest name
      See Also:
    • ASIC_XAdES_MANIFEST_FILENAME

      public static final String ASIC_XAdES_MANIFEST_FILENAME
      The ASiC-E with XAdES Manifest name
      See Also:
    • MIME_TYPE

      public static final String MIME_TYPE
      The mimetype filename
      See Also:
    • MIME_TYPE_COMMENT

      public static final String MIME_TYPE_COMMENT
      The mimetype comment
      See Also:
    • META_INF_FOLDER

      public static final String META_INF_FOLDER
      The META-INF folder
      See Also:
    • PACKAGE_ZIP

      public static final String PACKAGE_ZIP
      The "package.zip" filename
      See Also:
    • SIGNATURE_FILENAME

      public static final String SIGNATURE_FILENAME
      The signature filename
      See Also:
    • SIGNATURES_FILENAME

      public static final String SIGNATURES_FILENAME
      The signature filename
      See Also:
    • TIMESTAMP_FILENAME

      public static final String TIMESTAMP_FILENAME
      The timestamp filename
      See Also:
    • CADES_SIGNATURE_EXTENSION

      public static final String CADES_SIGNATURE_EXTENSION
      The signature file extension
      See Also:
    • TST_EXTENSION

      public static final String TST_EXTENSION
      The timestamp file extension
      See Also:
    • XML_EXTENSION

      public static final String XML_EXTENSION
      The XML file extension
      See Also:
    • SIGNATURES_XML

      public static final String SIGNATURES_XML
      The ASiC-S with XAdES signature document name (META-INF/signatures.xml)
      See Also:
    • OPEN_DOCUMENT_SIGNATURES

      public static final String OPEN_DOCUMENT_SIGNATURES
      The ASiC-E with XAdES for OpenDocument signature file name (META-INF/documentsignatures.xml)
      See Also:
    • ASICE_METAINF_MANIFEST

      public static final String ASICE_METAINF_MANIFEST
      The default XML manifest filename (META-INF/manifest.xml)
      See Also:
    • ASICE_METAINF_XADES_SIGNATURE

      public static final String ASICE_METAINF_XADES_SIGNATURE
      The default signature filename for ASiC-E with XAdES container
      See Also:
    • ASICE_METAINF_CADES_SIGNATURE

      public static final String ASICE_METAINF_CADES_SIGNATURE
      The default signature filename for ASiC-E with CAdES container
      See Also:
    • ASICE_METAINF_CADES_TIMESTAMP

      public static final String ASICE_METAINF_CADES_TIMESTAMP
      The default timestamp filename for ASiC-E with CAdES container
      See Also:
    • ASICE_METAINF_CADES_MANIFEST

      public static final String ASICE_METAINF_CADES_MANIFEST
      The default ASIC manifest filename for ASiC-E with CAdES container
      See Also:
    • ASICE_METAINF_CADES_ARCHIVE_MANIFEST

      public static final String ASICE_METAINF_CADES_ARCHIVE_MANIFEST
      The default ASIC archive manifest filename for ASiC-E with CAdES container
      See Also:
    • SIGNATURE_P7S

      public static final String SIGNATURE_P7S
      The ASiC-S with CAdES signature document name (META-INF/signature.p7s)
      See Also:
    • TIMESTAMP_TST

      public static final String TIMESTAMP_TST
      The ASiC-S with CAdES timestamp document name (META-INF/timestamp.tst)
      See Also:
  • Method Details

    • isSignature

      public static boolean isSignature(String entryName)
      Verifies if the entryName represents a signature file name
      Parameters:
      entryName - String name to check
      Returns:
      TRUE if the entryName represents a signature file name, FALSE otherwise
    • isTimestamp

      public static boolean isTimestamp(String entryName)
      Verifies if the entryName represents a timestamp file name
      Parameters:
      entryName - String name to check
      Returns:
      TRUE if the entryName represents a timestamp file name, FALSE otherwise
    • getMimeTypeString

      public static String getMimeTypeString(ASiCParameters asicParameters)
      Returns the target MimeType string
      Parameters:
      asicParameters - ASiCParameters
      Returns:
      String MimeType
    • getZipComment

      public static String getZipComment(ASiCParameters asicParameters)
      Returns a ZIP Comment String according to the given parameters
      Parameters:
      asicParameters - ASiCParameters
      Returns:
      String zip comment
    • getZipComment

      public static String getZipComment(MimeType mimeType)
      Returns a ZIP Comment String from the provided MimeType
      Parameters:
      mimeType - MimeType
      Returns:
      String zip comment
    • getZipComment

      public static String getZipComment(String mimeTypeString)
      Returns a ZIP Comment String from the provided mimeTypeString
      Parameters:
      mimeTypeString - String
      Returns:
      String zip comment
    • isASiCMimeType

      public static boolean isASiCMimeType(MimeType mimeType)
      Checks if the given MimeType is ASiC MimeType
      Parameters:
      mimeType - MimeType to check
      Returns:
      TRUE if the given MimeType is ASiC MimeType, FALSE otherwise
    • isOpenDocumentMimeType

      public static boolean isOpenDocumentMimeType(MimeType mimeType)
      Checks if the given MimeType is OpenDocument MimeType
      Parameters:
      mimeType - MimeType to check
      Returns:
      TRUE if the given MimeType is OpenDocument MimeType, FALSE otherwise
    • getASiCContainerType

      public static ASiCContainerType getASiCContainerType(MimeType asicMimeType)
      Returns related ASiCContainerType for the given asicMimeType
      Parameters:
      asicMimeType - MimeType to get ASiCContainerType for
      Returns:
      ASiCContainerType
    • isASiCE

      public static boolean isASiCE(ASiCParameters asicParameters)
      Checks if the parameters are configured for ASiCE creation
      Parameters:
      asicParameters - ASiCParameters
      Returns:
      TRUE if parameters are configured for ASiCE, FALSE otherwise
    • isASiCS

      public static boolean isASiCS(ASiCParameters asicParameters)
      Checks if the parameters are configured for ASiCS creation
      Parameters:
      asicParameters - ASiCParameters
      Returns:
      TRUE if parameters are configured for ASiCS, FALSE otherwise
    • getMimeType

      public static MimeType getMimeType(ASiCParameters asicParameters)
      Returns a relevant MimeType for the provided parameters
      Parameters:
      asicParameters - ASiCParameters
      Returns:
      MimeType
    • filesContainCorrectSignatureFileWithExtension

      public static boolean filesContainCorrectSignatureFileWithExtension(List<String> filenames, String extension)
      Checks if the list of filenames contains a signature with the expected extension
      Parameters:
      filenames - a list of file names
      extension - String signature file extension to find
      Returns:
      TRUE if the list of filename contains the expected signature file, FALSE otherwise
    • filesContainSignatures

      public static boolean filesContainSignatures(List<String> filenames)
      Checks if the list of filenames contains a signature(s)
      Parameters:
      filenames - a list of file names
      Returns:
      TRUE if the list of filename contains a signature file(s)
    • isAsicFileContent

      public static boolean isAsicFileContent(List<String> filenames)
      Checks if the list of filenames represents an ASiC container content
      Parameters:
      filenames - a list of String file names
      Returns:
      TRUE if the list of filenames represents an ASiC container content, FALSE otherwise
    • filesContainTimestamps

      public static boolean filesContainTimestamps(List<String> filenames)
      Checks if the list of filenames contains a timestamp
      Parameters:
      filenames - a list of filenames to check
      Returns:
      TRUE if the list of filenames contains the expected timestamp file, FALSE otherwise
    • isZip

      public static boolean isZip(DSSDocument document)
      Checks if the document is a ZIP container
      Parameters:
      document - DSSDocument to check
      Returns:
      TRUE if the DSSDocument is a ZIP container, FALSE otherwise
    • isZip

      public static boolean isZip(InputStream is)
      Checks if the given InputStream contains a ZIP container
      Parameters:
      is - InputStream to check
      Returns:
      TRUE if the InputStream is a ZIP container, FALSE otherwise
    • isASiCWithXAdES

      public static boolean isASiCWithXAdES(List<String> filenames)
      Checks if the extracted filenames represent an ASiC with XAdES content
      Parameters:
      filenames - a list of String file names to check
      Returns:
      TRUE if the filenames represent an ASiC with XAdES content, FALSE otherwise
    • isASiCWithCAdES

      public static boolean isASiCWithCAdES(List<String> filenames)
      Checks if the extracted filenames represent an ASiC with CAdES content
      Parameters:
      filenames - a list of String file names to check
      Returns:
      TRUE if the filenames represent an ASiC with CAdES content, FALSE otherwise
    • isXAdES

      public static boolean isXAdES(String entryName)
      Checks if the entryName is a relevant XAdES signature
      Parameters:
      entryName - String to check
      Returns:
      TRUE if the entryName is a relevant XAdES signature, FALSE otherwise
    • isCAdES

      public static boolean isCAdES(String entryName)
      Checks if the entryName is a relevant CAdES signature
      Parameters:
      entryName - String to check
      Returns:
      TRUE if the entryName is a relevant CAdES signature, FALSE otherwise
    • isContainerOpenDocument

      public static boolean isContainerOpenDocument(DSSDocument archiveContainer)
      Checks if the archive represents an OpenDocument
      Parameters:
      archiveContainer - DSSDocument an archive to verify
      Returns:
      TRUE if the archive contains an OpenDocument mimetype, FALSE otherwise
    • isOpenDocument

      public static boolean isOpenDocument(DSSDocument mimeTypeDoc)
      Checks if the mimeType document defines an OpenDocument
      Parameters:
      mimeTypeDoc - DSSDocument mimetype file extracted from an ASiC container
      Returns:
      TRUE if the mimeTypeDoc file defines an OpenDocument, FALSE otherwise
    • areFilesContainMimetype

      public static boolean areFilesContainMimetype(List<String> filenames)
      Checks if the list of filenames contains a mimetype file
      Parameters:
      filenames - a list of filenames to check
      Returns:
      TRUE if the list of filenames contains a mimetype file, FALSE otherwise
    • isMimetype

      public static boolean isMimetype(String entryName)
      Checks if the given name is a "mimetype"
      Parameters:
      entryName - String document name
      Returns:
      TRUE if the name is a "mimetype", FALSE otherwise
    • getMimeType

      public static MimeType getMimeType(DSSDocument mimeTypeDocument)
      Extracts and returns MimeType from the document
      Parameters:
      mimeTypeDocument - DSSDocument to get a MimeType of
      Returns:
      MimeType
    • isASiCSContainer

      public static boolean isASiCSContainer(DSSDocument container)
      This method verifies whether the given container is of ASiC-S format type
      Parameters:
      container - DSSDocument to verify
      Returns:
      TRUE if the container is of ASiC-S type, FALSE otherwise
    • isASiCEContainer

      public static boolean isASiCEContainer(DSSDocument container)
      This method verifies whether the given container is of ASiC-E format type
      Parameters:
      container - DSSDocument to verify
      Returns:
      TRUE if the container is of ASiC-E type, FALSE otherwise
    • getContainerType

      public static ASiCContainerType getContainerType(DSSDocument archiveContainer)
      This method verifies type of the provided container document
      Parameters:
      archiveContainer - DSSDocument to verify
      Returns:
      ASiCContainerType
    • isASiCSContainer

      public static boolean isASiCSContainer(ASiCContent asicContent)
      This method verifies whether the given ASiCContent is of ASiC-S format type
      Parameters:
      asicContent - ASiCContent to verify
      Returns:
      TRUE if the ASiC Content is of ASiC-S type, FALSE otherwise
    • isASiCEContainer

      public static boolean isASiCEContainer(ASiCContent asicContent)
      This method verifies whether the given ASiCContent is of ASiC-E format type
      Parameters:
      asicContent - ASiCContent to verify
      Returns:
      TRUE if the ASiC Content is of ASiC-E type, FALSE otherwise
    • getContainerType

      public static ASiCContainerType getContainerType(ASiCContent asicContent)
      Returns container type
      Parameters:
      asicContent - ASiCContent
      Returns:
      ASiCContainerType
    • isManifest

      public static boolean isManifest(String fileName)
      Checks if the fileName matches to a Manifest name standard
      Parameters:
      fileName - String to check
      Returns:
      TRUE if the given name matches Manifest filename, FALSE otherwise
    • isArchiveManifest

      public static boolean isArchiveManifest(String fileName)
      Checks if the fileName matches to an Archive Manifest name standard
      Parameters:
      fileName - String to check
      Returns:
      TRUE if the given name matches ASiC Archive Manifest filename, FALSE otherwise
    • coversSignature

      public static boolean coversSignature(ManifestFile manifestFile)
      Checks if the manifestFile covers a signature
      Parameters:
      manifestFile - ManifestFile
      Returns:
      TRUE if manifest entries contain a signature, FALSE otherwise
    • addOrReplaceDocument

      public static void addOrReplaceDocument(List<DSSDocument> documentList, DSSDocument newDocument)
      This method searches for a document in a documentList with a name of newDocumentVersion and replaces the found entry with the updated version or adds the document to the given list if no such entry has been found
      Parameters:
      documentList - a list of DSSDocuments
      newDocument - DSSDocument to add
    • ensureMimeTypeAndZipComment

      public static ASiCContent ensureMimeTypeAndZipComment(ASiCContent asicContent, ASiCParameters asicParameters)
      This method is used to ensure the mimetype file and zip-comment are present within the given ASiCContent. If the entry is not defined, a new value if created from ASiCParameters.
      Parameters:
      asicContent - ASiCContent to ensure a valid structure in
      asicParameters - ASiCParameters to use to create missing entries
      Returns:
      ASiCContent
    • getRootLevelSignedDocuments

      public static List<DSSDocument> getRootLevelSignedDocuments(ASiCContent asicContent)
      This method retrieves signed document from a root level of the container (used for ASiC-E container)
      Parameters:
      asicContent - ASiCContent representing the container structure
      Returns:
      a list of DSSDocuments
    • getRootLevelDocuments

      public static List<DSSDocument> getRootLevelDocuments(List<DSSDocument> documents)
      This method returns root-level documents across the provided list of documents
      Parameters:
      documents - list of DSSDocument to get root-level documents from
      Returns:
      list of DSSDocuments
    • getZipComment

      public static String getZipComment(DSSDocument archiveContainer)
      Returns a zip comment String from the ASiC container
      Parameters:
      archiveContainer - DSSDocument representing an Archive container
      Returns:
      String zip comment
    • toSimpleManifestEntries

      public static List<ManifestEntry> toSimpleManifestEntries(List<DSSDocument> documents)
      Transforms a list of given documents to a list of "simple" (only basic information) manifest entries
      Parameters:
      documents - list of DSSDocuments
      Returns:
      list of ManifestEntrys