Package eu.europa.esig.dss.asic.common
Class ASiCUtils
java.lang.Object
eu.europa.esig.dss.asic.common.ASiCUtils
public final class ASiCUtils extends Object
-
Field Summary
Fields Modifier and Type Field Description static StringMANIFEST_FILENAMEstatic StringMETA_INF_FOLDERstatic StringMIME_TYPEstatic StringMIME_TYPE_COMMENTstatic StringPACKAGE_ZIPstatic StringSIGNATURE_FILENAMEstatic StringTIMESTAMP_FILENAMEstatic StringTST_EXTENSIONstatic StringXML_EXTENSIONstatic StringZIP_ENTRY_DETACHED_FILE -
Method Summary
Modifier and Type Method Description static voidcloseEntry(ZipInputStream zis)This method closes the current Zip Entry.static ASiCContainerTypegetASiCContainerType(MimeType asicMimeType)static ASiCContainerTypegetContainerType(DSSDocument archive, DSSDocument mimetype, String zipComment, List<DSSDocument> signedDocuments)static DSSDocumentgetCurrentDocument(String filepath, ZipInputStream zis, long containerSize)Returns file from the given ZipInputStreamstatic List<String>getDSSDocumentNames(List<DSSDocument> documents)Returns a list of document namesstatic List<String>getFileNames(DSSDocument archive)Returns the file names for the given archivestatic MimeTypegetMimeType(ASiCParameters asicParameters)static MimeTypegetMimeType(DSSDocument mimeTypeDocument)static StringgetMimeTypeString(ASiCParameters asicParameters)static StringgetNextASiCEManifestName(String expectedManifestName, List<DSSDocument> existingManifests)Generates an unique name for a new ASiC-E Manifest file, avoiding any name collisionstatic ZipEntrygetNextValidEntry(ZipInputStream zis)Returns the next entry from the given ZipInputStream by skipping corrupted or not accessible files NOTE: returns null only when the end of ZipInputStream is reachedstatic List<DSSDocument>getPackageZipContent(DSSDocument packageZip)Returns a content of the packageZip containerstatic StringgetPadNumber(int num)Transformsnumwith the pattern:"2 -> 002","10 -> 010", etc.static booleanisArchive(List<DSSDocument> docs)static booleanisArchiveContainsCorrectSignatureFileWithExtension(DSSDocument container, String extension)Checks if the container contains a signature with the expectedextensionstatic booleanisArchiveContainsCorrectTimestamp(DSSDocument container)Checks if the container contains a timestampstatic booleanisArchiveManifest(String fileName)static booleanisAsic(List<DSSDocument> documents)static booleanisASiCE(ASiCParameters asicParameters)static booleanisASiCMimeType(MimeType asicMimeType)static booleanisASiCS(ASiCParameters asicParameters)static booleanisASiCSArchive(DSSDocument document)Checks if the current document an ASiC-E ZIP specific archivestatic booleanisASiCWithCAdES(DSSDocument archive)static booleanisCAdES(String entryName)static booleanisOpenDocument(DSSDocument mimeTypeDoc)static booleanisOpenDocumentMimeType(MimeType mimeType)static booleanisSignature(String entryName)Verifies if theentryNamerepresents a signature file namestatic booleanisTimestamp(String entryName)Verifies if theentryNamerepresents a timestamp file namestatic booleanisXAdES(String entryName)static booleanisZip(DSSDocument dssDocument)static voidsecureCopy(InputStream is, OutputStream os, long containerSize)Reads and copies InputStream in a secure way, depending on the provided container size This method allows to detect "ZipBombing" (large files inside a zip container)
-
Field Details
-
MANIFEST_FILENAME
- See Also:
- Constant Field Values
-
MIME_TYPE
- See Also:
- Constant Field Values
-
MIME_TYPE_COMMENT
- See Also:
- Constant Field Values
-
META_INF_FOLDER
- See Also:
- Constant Field Values
-
PACKAGE_ZIP
- See Also:
- Constant Field Values
-
SIGNATURE_FILENAME
- See Also:
- Constant Field Values
-
TIMESTAMP_FILENAME
- See Also:
- Constant Field Values
-
TST_EXTENSION
- See Also:
- Constant Field Values
-
XML_EXTENSION
- See Also:
- Constant Field Values
-
ZIP_ENTRY_DETACHED_FILE
- See Also:
- Constant Field Values
-
-
Method Details
-
isSignature
Verifies if theentryNamerepresents a signature file name- Parameters:
entryName-Stringname to check- Returns:
- TRUE if the entryName represents a signature file name, FALSE otherwise
-
isTimestamp
Verifies if theentryNamerepresents a timestamp file name- Parameters:
entryName-Stringname to check- Returns:
- TRUE if the entryName represents a timestamp file name, FALSE otherwise
-
getMimeTypeString
-
isASiCMimeType
-
isOpenDocumentMimeType
-
getASiCContainerType
-
isASiCE
-
isASiCS
-
getMimeType
-
isArchiveContainsCorrectSignatureFileWithExtension
public static boolean isArchiveContainsCorrectSignatureFileWithExtension(DSSDocument container, String extension)Checks if the container contains a signature with the expectedextension- Parameters:
container-DSSDocumentrepresenting an ASiC containerextension-Stringsignature file extension to find- Returns:
- TRUE if the container contains the expected signature file, FALSE otherwise
-
isArchiveContainsCorrectTimestamp
Checks if the container contains a timestamp- Parameters:
container-DSSDocumentrepresenting an ASiC container- Returns:
- TRUE if the container contains the expected timestamp file, FALSE otherwise
-
isArchive
-
isZip
-
isASiCWithCAdES
-
isXAdES
-
isCAdES
-
isOpenDocument
-
getMimeType
-
getContainerType
public static ASiCContainerType getContainerType(DSSDocument archive, DSSDocument mimetype, String zipComment, List<DSSDocument> signedDocuments) -
getPadNumber
Transformsnumwith the pattern:"2 -> 002","10 -> 010", etc.- Parameters:
num-- Returns:
String
-
isAsic
-
isArchiveManifest
-
secureCopy
public static void secureCopy(InputStream is, OutputStream os, long containerSize) throws IOExceptionReads and copies InputStream in a secure way, depending on the provided container size This method allows to detect "ZipBombing" (large files inside a zip container)- Parameters:
is-InputStreamof fileos-OutputStreamwhere save file tocontainerSize- - zip container size- Throws:
IOException
-
getFileNames
Returns the file names for the given archive- Parameters:
archive- the archive to be analyzed- Returns:
- a list of filename
-
getNextValidEntry
Returns the next entry from the given ZipInputStream by skipping corrupted or not accessible files NOTE: returns null only when the end of ZipInputStream is reached- Parameters:
zis-ZipInputStreamto get next entry from- Returns:
- list of file name
Strings - Throws:
DSSException- if too much tries failed
-
getCurrentDocument
public static DSSDocument getCurrentDocument(String filepath, ZipInputStream zis, long containerSize) throws IOExceptionReturns file from the given ZipInputStream- Parameters:
filepath-Stringfilepath where the file is locatedzis-ZipInputStreamof the filecontainerSize- - long byte size of the parent container- Returns:
DSSDocumentcreated from the givenzis- Throws:
IOException- in case of ZipInputStream read error
-
closeEntry
This method closes the current Zip Entry. If an error occurs, aDSSExceptionis thrown.- Parameters:
zis- theZipInputStream
-
getNextASiCEManifestName
public static String getNextASiCEManifestName(String expectedManifestName, List<DSSDocument> existingManifests)Generates an unique name for a new ASiC-E Manifest file, avoiding any name collision- Parameters:
expectedManifestName-Stringdefines the expected name of the file without extension (e.g. "ASiCmanifest")existingManifests- list of existingDSSDocumentmanifests of the type present in the container- Returns:
Stringnew manifest name
-
getDSSDocumentNames
Returns a list of document names- Parameters:
documents- list ofDSSDocuments to get file names- Returns:
- list of
Stringdocument names
-
isASiCSArchive
Checks if the current document an ASiC-E ZIP specific archive- Parameters:
document-DSSDocumentto check- Returns:
- TRUE if the document if a "package.zip" archive, FALSE otherwise
-
getPackageZipContent
Returns a content of the packageZip container- Parameters:
packageZip-DSSDocumentZIP container to get entries from- Returns:
- list of
DSSDocuments
-