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 String
MANIFEST_FILENAME
static String
META_INF_FOLDER
static String
MIME_TYPE
static String
MIME_TYPE_COMMENT
static String
PACKAGE_ZIP
static String
SIGNATURE_FILENAME
static String
TIMESTAMP_FILENAME
static String
TST_EXTENSION
static String
XML_EXTENSION
static String
ZIP_ENTRY_DETACHED_FILE
-
Method Summary
Modifier and Type Method Description static void
closeEntry(ZipInputStream zis)
This method closes the current Zip Entry.static ASiCContainerType
getASiCContainerType(MimeType asicMimeType)
static ASiCContainerType
getContainerType(DSSDocument archive, DSSDocument mimetype, String zipComment, List<DSSDocument> signedDocuments)
static DSSDocument
getCurrentDocument(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 MimeType
getMimeType(ASiCParameters asicParameters)
static MimeType
getMimeType(DSSDocument mimeTypeDocument)
static String
getMimeTypeString(ASiCParameters asicParameters)
static String
getNextASiCEManifestName(String expectedManifestName, List<DSSDocument> existingManifests)
Generates an unique name for a new ASiC-E Manifest file, avoiding any name collisionstatic ZipEntry
getNextValidEntry(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 String
getPadNumber(int num)
Transformsnum
with the pattern:"2 -> 002"
,"10 -> 010"
, etc.static boolean
isArchive(List<DSSDocument> docs)
static boolean
isArchiveContainsCorrectSignatureFileWithExtension(DSSDocument container, String extension)
Checks if the container contains a signature with the expectedextension
static boolean
isArchiveContainsCorrectTimestamp(DSSDocument container)
Checks if the container contains a timestampstatic boolean
isArchiveManifest(String fileName)
static boolean
isAsic(List<DSSDocument> documents)
static boolean
isASiCE(ASiCParameters asicParameters)
static boolean
isASiCMimeType(MimeType asicMimeType)
static boolean
isASiCS(ASiCParameters asicParameters)
static boolean
isASiCSArchive(DSSDocument document)
Checks if the current document an ASiC-E ZIP specific archivestatic boolean
isASiCWithCAdES(DSSDocument archive)
static boolean
isCAdES(String entryName)
static boolean
isOpenDocument(DSSDocument mimeTypeDoc)
static boolean
isOpenDocumentMimeType(MimeType mimeType)
static boolean
isSignature(String entryName)
Verifies if theentryName
represents a signature file namestatic boolean
isTimestamp(String entryName)
Verifies if theentryName
represents a timestamp file namestatic boolean
isXAdES(String entryName)
static boolean
isZip(DSSDocument dssDocument)
static void
secureCopy(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 theentryName
represents a signature file name- Parameters:
entryName
-String
name to check- Returns:
- TRUE if the entryName represents a signature file name, FALSE otherwise
-
isTimestamp
Verifies if theentryName
represents a timestamp file name- Parameters:
entryName
-String
name 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
-DSSDocument
representing an ASiC containerextension
-String
signature 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
-DSSDocument
representing 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
Transformsnum
with 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
-InputStream
of fileos
-OutputStream
where 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
-ZipInputStream
to get next entry from- Returns:
- list of file name
String
s - 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
-String
filepath where the file is locatedzis
-ZipInputStream
of the filecontainerSize
- - long byte size of the parent container- Returns:
DSSDocument
created from the givenzis
- Throws:
IOException
- in case of ZipInputStream read error
-
closeEntry
This method closes the current Zip Entry. If an error occurs, aDSSException
is 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
-String
defines the expected name of the file without extension (e.g. "ASiCmanifest")existingManifests
- list of existingDSSDocument
manifests of the type present in the container- Returns:
String
new manifest name
-
getDSSDocumentNames
Returns a list of document names- Parameters:
documents
- list ofDSSDocument
s to get file names- Returns:
- list of
String
document names
-
isASiCSArchive
Checks if the current document an ASiC-E ZIP specific archive- Parameters:
document
-DSSDocument
to check- Returns:
- TRUE if the document if a "package.zip" archive, FALSE otherwise
-
getPackageZipContent
Returns a content of the packageZip container- Parameters:
packageZip
-DSSDocument
ZIP container to get entries from- Returns:
- list of
DSSDocument
s
-