Skip to content

Commit 374cbc4

Browse files
authored
log SHA-256 hash for product zip files (#105)
1 parent 0099daa commit 374cbc4

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

core/src/main/groovy/noe/common/utils/InstallerUtils.groovy

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ import noe.common.DefaultProperties
55
import noe.server.ServerAbstract
66
import noe.workspace.WorkspaceAbstract
77

8+
import javax.xml.bind.DatatypeConverter
9+
import java.nio.file.Files
10+
import java.nio.file.Paths
11+
import java.security.MessageDigest
12+
813
/**
914
* Shared for all utils classes, zip installation is similar
1015
* @author Bogdan Sikora <[email protected]>
@@ -95,9 +100,25 @@ class InstallerUtils {
95100
log.error("Zip file $zipSource, exist = ${zipSource.exists()}")
96101
throw new FileNotFoundException("Zip installation failed, $zipDest doesn't exits")
97102
}
103+
logSha256Hash(zipDest)
98104
JBFile.nativeUnzip(zipDest, new File(basedir))
99105
if (DefaultProperties.isRemoveZipAfterUnzip()) {
100106
JBFile.delete(zipDest)
101107
}
102108
}
109+
110+
/**
111+
* Compute SHA-256 hash for zip file
112+
* @param zipFile
113+
*/
114+
void logSha256Hash(File zipFile) throws FileNotFoundException {
115+
if (!zipFile.exists()) {
116+
throw new FileNotFoundException("Zip file ${zipFile} for computing SHA-256 doesn't exists.")
117+
}
118+
MessageDigest md = MessageDigest.getInstance("SHA-256")
119+
md.update(Files.readAllBytes(Paths.get(zipFile.getAbsolutePath())))
120+
byte[] digest = md.digest()
121+
String digestInHex = DatatypeConverter.printHexBinary(digest).toUpperCase()
122+
log.info("Zip file ${zipFile} SHA-256 hash is: ${digestInHex}")
123+
}
103124
}

0 commit comments

Comments
 (0)