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 StringMETA_INF_FOLDERstatic StringMIME_TYPEstatic StringMIME_TYPE_COMMENTstatic StringPACKAGE_ZIP
-
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>getFileNames(DSSDocument archive)Returns the file names for the given archivestatic MimeTypegetMimeType(ASiCParameters asicParameters)static MimeTypegetMimeType(DSSDocument mimeTypeDocument)static StringgetMimeTypeString(ASiCParameters asicParameters)static 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 StringgetPadNumber(int num)Transformsnumwith the pattern:"2 -> 002","10 -> 010", etc.static booleanisArchive(List<DSSDocument> docs)static booleanisArchiveContainsCorrectSignatureFileWithExtension(DSSDocument toSignDocument, String extension)static booleanisArchiveManifest(String fileName)static booleanisAsic(List<DSSDocument> documents)static booleanisASiCContainer(DSSDocument dssDocument)static booleanisASiCE(ASiCParameters asicParameters)static booleanisASiCMimeType(MimeType asicMimeType)static booleanisASiCS(ASiCParameters asicParameters)static booleanisCAdES(String entryName)static booleanisOpenDocument(DSSDocument mimeTypeDocument)static booleanisSignature(String entryName)static booleanisXAdES(String entryName)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 Detail
-
MIME_TYPE
public static final String MIME_TYPE
- See Also:
- Constant Field Values
-
MIME_TYPE_COMMENT
public static final String MIME_TYPE_COMMENT
- See Also:
- Constant Field Values
-
META_INF_FOLDER
public static final String META_INF_FOLDER
- See Also:
- Constant Field Values
-
PACKAGE_ZIP
public static final String PACKAGE_ZIP
- See Also:
- Constant Field Values
-
-
Method Detail
-
isSignature
public static boolean isSignature(String entryName)
-
getMimeTypeString
public static String getMimeTypeString(ASiCParameters asicParameters)
-
isASiCMimeType
public static boolean isASiCMimeType(MimeType asicMimeType)
-
getASiCContainerType
public static ASiCContainerType getASiCContainerType(MimeType asicMimeType)
-
isASiCE
public static boolean isASiCE(ASiCParameters asicParameters)
-
isASiCS
public static boolean isASiCS(ASiCParameters asicParameters)
-
getMimeType
public static MimeType getMimeType(ASiCParameters asicParameters)
-
isArchiveContainsCorrectSignatureFileWithExtension
public static boolean isArchiveContainsCorrectSignatureFileWithExtension(DSSDocument toSignDocument, String extension)
-
isArchive
public static boolean isArchive(List<DSSDocument> docs)
-
isASiCContainer
public static boolean isASiCContainer(DSSDocument dssDocument)
-
isXAdES
public static boolean isXAdES(String entryName)
-
isCAdES
public static boolean isCAdES(String entryName)
-
isOpenDocument
public static boolean isOpenDocument(DSSDocument mimeTypeDocument)
-
getMimeType
public static MimeType getMimeType(DSSDocument mimeTypeDocument)
-
getContainerType
public static ASiCContainerType getContainerType(DSSDocument archive, DSSDocument mimetype, String zipComment, List<DSSDocument> signedDocuments)
-
getPadNumber
public static String getPadNumber(int num)
Transformsnumwith the pattern:"2 -> 002","10 -> 010", etc.- Parameters:
num-- Returns:
String
-
isAsic
public static boolean isAsic(List<DSSDocument> documents)
-
isArchiveManifest
public static boolean isArchiveManifest(String fileName)
-
secureCopy
public static void secureCopy(InputStream is, OutputStream os, long containerSize) throws IOException
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)- Parameters:
is-InputStreamof fileos-OutputStreamwhere save file tocontainerSize- - zip container size- Throws:
IOException
-
getFileNames
public static List<String> getFileNames(DSSDocument archive)
Returns the file names for the given archive- Parameters:
archive- the archive to be analyzed- Returns:
- a list of filename
-
getNextValidEntry
public static 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 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 IOException
Returns 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
public static void closeEntry(ZipInputStream zis)
This method closes the current Zip Entry. If an error occurs, aDSSExceptionis thrown.- Parameters:
zis- theZipInputStream
-
-