diff --git a/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/TCGEventLog.java b/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/TCGEventLog.java index ff5bdd2f..409b1182 100644 --- a/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/TCGEventLog.java +++ b/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/TCGEventLog.java @@ -256,7 +256,16 @@ public final class TCGEventLog { } return pcrs; } - + + /** + * Returns a flag which is set if the event log follows the "Crypto Agile" Format Type. + * A false implies the type is SHA1 format. + * @return true if log follows the Crypto Agile format. + */ + public boolean isCryptoAgile() { + return bCryptoAgile; + } + /** * Returns a list of event found in the Event Log. * @return an arraylist of event. diff --git a/build.gradle b/build.gradle index 763fbd69..f3ed7e76 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,6 @@ -//import java.util.concurrent.TimeUnit -// +import java.util.concurrent.TimeUnit +import org.gradle.api.tasks.Copy + plugins { // Apply the application plugin to add support for building a CLI application in Java. id 'application' @@ -8,6 +9,35 @@ plugins { // id "nebula.ospackage" version "9.1.1" } +// Global checkstyle file + ext.checkstyleConfigFile = new File(rootDir, "/config/checkstyle/sun_checks.xml") + +dependencies { + repositories { + // Use Maven Central for resolving dependencies. + mavenCentral() + } +} + +def projectVersion = rootProject.file('VERSION').text.trim() + +def buildTime = { -> + Date latestdate = new Date(); + def time = latestdate.getTime(); + long seconds = TimeUnit.MILLISECONDS.toSeconds(time); + return seconds; +} + +def gitHash = { -> + def gitProcess = 'git rev-parse --short HEAD'.execute(); + gitProcess.waitFor(); + def shortHash = gitProcess.text.trim(); + def gitHash = shortHash.substring(0, shortHash.length() - 2); + return gitHash; +} + +project.ext["packageVersion"] = "${projectVersion}.${buildTime}.${gitHash}.el8" + //subprojects { // //} diff --git a/settings.gradle b/settings.gradle index dcd004a9..4fee8f57 100644 --- a/settings.gradle +++ b/settings.gradle @@ -2,8 +2,9 @@ rootProject.name = 'HIRS' include 'HIRS_Utils', 'HIRS_AttestationCA', - 'HIRS_AttestationCAPortal' - + 'HIRS_AttestationCAPortal', + ':tools:tcg_eventlog_tool' + dependencyResolutionManagement { versionCatalogs { libs { @@ -11,6 +12,7 @@ dependencyResolutionManagement { version('jackson', '2.14.2') library('commons-codec', 'commons-codec:commons-codec:1.15') library('commons-lang3', 'org.apache.commons:commons-lang3:3.12.0') + library('commons_io', 'commons-io:commons-io:2.11.0') library('bouncycastle', 'org.bouncycastle:bcmail-jdk15on:1.70') library('guava', 'com.google.guava:guava:31.1-jre') library('minimal-json', 'com.eclipsesource.minimal-json:minimal-json:0.9.5') @@ -19,6 +21,7 @@ dependencyResolutionManagement { library('jakarta-xml', 'jakarta.xml.bind:jakarta.xml.bind-api:4.0.0') library('jackson-core', 'com.fasterxml.jackson.core', 'jackson-core').versionRef('jackson') library('jackson-databind', 'com.fasterxml.jackson.core', 'jackson-databind').versionRef('jackson') + library('jcommander', 'com.beust:jcommander:1.82') library('pci', 'com.github.marandus:pci-ids:0.3') // library('spring-datajpa', 'org.springframework.boot', 'spring-boot-starter-data-jpa').version('springboot') // library('spring-datajpa', 'org.springframework.boot', 'spring-boot-starter-web').version('springboot') @@ -26,4 +29,4 @@ dependencyResolutionManagement { library('lombok', 'org.projectlombok:lombok:1.18.26') } } -} \ No newline at end of file +} diff --git a/tools/tcg_eventlog_tool/build.gradle b/tools/tcg_eventlog_tool/build.gradle index ddfbc110..24661ca0 100644 --- a/tools/tcg_eventlog_tool/build.gradle +++ b/tools/tcg_eventlog_tool/build.gradle @@ -1,122 +1,119 @@ -apply plugin: 'java' -apply plugin: 'findbugs' -apply plugin: 'checkstyle' -apply plugin: 'nebula.ospackage' +import java.util.concurrent.TimeUnit +plugins { + id "java" +// id "findbugs" +// id "checkstyle" + id "nebula.ospackage" version "9.1.1" +} version = '1.0' +java { + toolchain { + languageVersion = JavaLanguageVersion.of(17) + } +} + repositories { mavenCentral() } dependencies { - compile project(':HIRS_Utils') - compile libs.jcommander - compile libs.commons_io - compileOnly libs.checkstyle - compileOnly libs.findbugs - testCompile libs.testng + implementation project(':HIRS_Utils') + implementation libs.jcommander + implementation libs.commons.io +// implementation libs.checkstyle +// implementation libs.findbugs +// testCompile libs.testng } ext.configDir = new File(projectDir, 'config') -ext.checkstyleConfigDir = "$configDir/checkstyle" -checkstyle { - toolVersion = '5.7' - configFile = checkstyleConfigFile - configProperties.put('basedir', checkstyleConfigDir) - ignoreFailures = false - showViolations = true -} +//ext.checkstyleConfigDir = "$configDir/checkstyle" +//ext.findbugsConfigDir = "$configDir/findbugs" -ext.findbugsConfigDir = "$configDir/findbugs" +//checkstyle { +// toolVersion = '5.7' +// configFile = checkstyleConfigFile +// configProperties.put('basedir', checkstyleConfigDir) +// ignoreFailures = false +// showViolations = true +//} -findbugs { - toolVersion = '3.0.0' - ignoreFailures = false - effort = 'max' -} + +//findbugs { +// toolVersion = '3.0.0' +// ignoreFailures = false +// effort = 'max' +//} jar { + exclude 'META-INF/*.SF', 'META-INF/*.DSA', 'META-INF/*.RSA', 'META-INF/*.MF' manifest { - attributes("Main-Class": "hirs.tcg_eventlog.Main", - "Class-Path": configurations.runtime.files.collect { "lib/$it.name" }.join(' ') - ) - } - from(configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }) {} - exclude 'META-INF/*.RSA', 'META-INF/*.SF', 'META-INF/*.DSA' -} - -uploadArchives { - repositories { - flatDir { - dirs "${buildDir}" - } - } -} - -buildscript { - repositories { - mavenCentral() - } - dependencies { - classpath 'com.netflix.nebula:gradle-ospackage-plugin:4.9.3' + attributes( + "Main-Class": "hirs.tcg_eventlog.Main", + 'Class-Path': configurations.runtimeClasspath.files.collect { it.getName() }.join(' ') + ) } + // from(configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }) {} + // exclude 'META-INF/*.RSA', 'META-INF/*.SF', 'META-INF/*.DSA' } +// Get version from main project gradle +def packVersion = properties.get("packageVersion"); +//println "packageVersion is ${projVersion}" // Produce packages ospackage { - def gitCommitHash = 'git rev-parse --verify --short HEAD'.execute().text.trim() - packageName = 'tcg_eventlog_tool' + packageName = 'tcg-eventlog-tool' os = LINUX - arch = X86_64 - version = '2.1.0' - release = gitCommitHash + arch = NOARCH + version = "$packVersion" + release = '1' - into '/opt/hirs/eventlog' user 'root' fileMode = 0755 - from(jar.outputs.files) { - into 'lib' + into ('/opt/hirs/eventlog/lib') { + from jar.outputs.files + from 'lib' + from 'configurations.runtimeClasspath' } - from('lib') { - into 'lib' - } - from(configurations.runtime) { - into 'lib' - } - from('scripts') { + into ('/opt/hirs/eventlog/scripts') { + from ('scripts') { exclude { - FileTreeElement details -> - details.file.name.endsWith('.bat') + FileTreeElement details -> + details.file.name.endsWith('.bat') } - into 'scripts' + } } - from('docs') { - exclude { - FileTreeElement details -> - details.file.name.endsWith('.odt') + into ('/opt/hirs/eventlog/docs') { + from ('docs') { + exclude { + FileTreeElement details -> + details.file.name.endsWith('.odt') + } } - into 'docs' } - from('./') { - include { - FileTreeElement details -> - details.file.name.endsWith('.md') - } - into './' - link("/usr/bin/elt", "/opt/hirs/eventlog/scripts/eventlog.sh", 0x755) - } - - into('/tmp/') { - fileMode 0664 + // Copy vendor-table into /tmp to avoid conflict with the ACA + into('/tmp/elt/default-properties') { from ('../../HIRS_Utils/src/main/resources/vendor-table.json') { - addParentDirs true - createDirectoryEntry true + fileMode 0664 + addParentDirs = true } } - postInstall file('scripts/vendor-table.sh') + // place elt link in system path to enable command line access + link("/usr/local/bin/elt", "/opt/hirs/eventlog/scripts/eventlog.sh", 0x755) + + // PostInstall + // Copy files from /opt/elt/default-properties/ to avoid conflicts with the ACA + postInstall "cp /tmp/elt/default-properties/vendor-table.json /opt/hirs/default-properties/." + postInstall "rm -rf /tmp/elt" + + // Uninstall + // copy files to where package manager exspects them and remove project files + preUninstall "mkdir -p /tmp/elt/default-properties" + preUninstall "cp /opt/hirs/default-properties/vendor-table.json /tmp/elt/default-properties/." + postUninstall "rm -rf /tmp/elt" buildRpm { arch = X86_64 diff --git a/tools/tcg_eventlog_tool/src/main/java/hirs/tcg_eventlog/Main.java b/tools/tcg_eventlog_tool/src/main/java/hirs/tcg_eventlog/Main.java index 10fa4a0a..e5864bd3 100644 --- a/tools/tcg_eventlog_tool/src/main/java/hirs/tcg_eventlog/Main.java +++ b/tools/tcg_eventlog_tool/src/main/java/hirs/tcg_eventlog/Main.java @@ -11,8 +11,8 @@ import java.security.cert.CertificateException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import hirs.tpm.eventlog.TCGEventLog; -import hirs.tpm.eventlog.TpmPcrEvent; +import hirs.utils.tpm.eventlog.TCGEventLog; +import hirs.utils.tpm.eventlog.TpmPcrEvent; import hirs.utils.HexUtils; /**