A Maven extension for validating and collecting checksums of all artifacts during execution.

Overview

Maven checksum extension

This extension allows for the creation and the enforcement of checksums for any artifact that is resolved by Maven. Without such validation, a corrupted version could otherwise enable supply-chain attacks via remote code execution, if an attacker is able to replace an artifact in a Maven repository, or otherwise intercepts a download via a man-in-the-middle attack.

If a secure checksum is available for each artifact, this extension can validate each artifact against this checksum before allowing the artifact to execute any code. If a checksum does not match, this extension ends the execution process immediately to avoid any possible damage. For this purpose, this extension can generate a file which is checked into a project against which all later downloads are validated. As a side effect, this validation would also discover re-tagged versions, for example if snapshots were used.

To activate this extension, its jar file should be either placed in the Maven installation directory under lib/ext or be specified via the -Dmaven.ext.class.path= property. It should however not be specified via .mvn/extensions.xml as this would require the extension to be downloaded without any validation of the extension itself, what would defeat its purpose. (Hopefully, something similar will however become a Maven core feature at some point.)

Collecting checksums

The extension will collect any checksums of artifacts that are being resolved. Therefore, it is important to run the same goal as would be run during validation. Typically, checksum validation is required during sensitive builds, such as during a release build:

mvn release:prepare release:perform -DdryRun \
  -Dmaven.ext.class.path=maven-checksum-extension.jar \
  -Dcodes.rafael.mavenchecksumextension.file=./checksums.sha256 \
  -Dcodes.rafael.mavenchecksumextension.mode=collect

By default, this extension uses SHA-256 checksums which are easier to compute than SHA-512 checksums but still considered non-imitable. A different algorithm can be specified by setting -Dcodes.rafael.mavenchecksumextension.algorithm=<name>, but it is highly discouraged to use weak checksums such as SHA-1 or MD5.

It is possible to retain values of a previously generated file by setting -Dcodes.rafael.mavenchecksumextension.append. Changed checksums for the same artifact will be replaced in such a run.

Validating checksums

During the actual build, which usually happens on a different machine in the network, the collected checksums are now available via the file that was previously collected and which is stored in the version control system, together with the project's source code. These checksums are now enforced to ensure that any remotely altered artifact is downloaded and handed execution privilege:

mvn release:prepare release:perform \
  -Dmaven.ext.class.path=maven-checksum-extension.jar \
  -Dcodes.rafael.mavenchecksumextension.file=./checksums.sha256 \
  -Dcodes.rafael.mavenchecksumextension.mode=enforce

It is possible to ignore unknown artifacts by setting -Dcodes.rafael.mavenchecksumextension.relaxed. This is not recommended as it opens for corruption via these artifacts, but allows to accept artifacts that might not otherwise be available and are known to be trustworthy.

Recommended workflow

Of course, if a remote repository already is corrupted, the generated checksums will reflect the corrupted artifacts during creation. However, at least, if another machine builds the same project and fails checksum validation when it has a different artifact representation stored in its local cache or fetches artifacts from a different Maven repository server, the corruption of the collection run can be discovered rather easily. Ideally, checksums are however fetched from a properly patched and supervised machine. In particular, it reduces the danger of executing against shared caches in any subsequent, validating build.

Checksum collection must be repeated after each update of Maven or a project's POM as different artifact or artifact versions might be resolved. This extension enforces a stable sort order for the generated file such that artifact changes, including transitives, become visible by their checksum changes.

By default, the extension does neither collect nor enforce checksums for snapshot versions or artifacts in system scope. Set -Dcodes.rafael.mavenchecksumextension.snapshots or -Dcodes.rafael.mavenchecksumextension.locals to enable such validation.

Integrating the extension

When building on a server with a generic Maven installation, the extension will not be available. To download the extension securely, the mvnc or mvnc.cmd files in this project can be added to any project for execution. Both scripts will also validate the downloaded jar file against a SHA-256 checksum to avoid the corruption of the extension itself, prior to its execution.

The script can be executed directly from a build server script, or can be integrated by adding /bin/sh .mvn/maven-checksum/mvnc to a shell script, or CALL .mvn\maven-checksum\mvnc.cmd to a Windows batch file. This way, the extension can for example be integrated into Maven Wrapper. If doing so, guard the script execution with an if statement (or error level goto on Windows batch), to exit Maven wrapper in case of a failure. Note that a non-existing Maven extension is unfortunately ignored by Maven, what will result in your build executing without checksum verification.

You might also like...

During a machine coding round of the company, I designed the Conference Room System in a given one hour.

During a machine coding round of the company, I designed the Conference Room System in a given one hour.

DesignConferenceRoom DESIGN A CONFERENCE ROOM One of the core problems which people face at every company is the unavailability of conference rooms. S

Dec 23, 2022

The respository of a student group called 'Bombenstimmung' at the University of Wuppertal during the SWT-Praktikum 2021/22

Bomberfrau The respository of a student group called 'Bombenstimmung' at the University of Wuppertal during the SWT-Praktikum 2021/22 Installation: Vo

Jan 10, 2022

A plugin that open the GC command execution interface for third-party clients

gc-opencommand-plugin 中文 | English 一个为第三方客户端开放GC命令执行接口的插件 服务端安装 在 Release 下载 jar 放入 plugins 文件夹即可 控制台连接 首次启动时,会在 plugins 目录下生成一个 opencommand-plugin 目录

Jan 1, 2023

A simple live streaming mobile app with cool functionalities and time extension, and live chat. With a payment system integrated. Server is designed with socket.io to give you full flexibility.

A simple live streaming mobile app with cool functionalities and time extension, and live chat. With a payment system integrated. Server is designed with socket.io to give you full flexibility.

Video Live Streaming Platform Android A simple live streaming mobile app with cool functionalities and time extension, and live chat. With a payment s

Dec 16, 2022

SecureDB is an extension for Ai2 Appinventor and its distros which stores the data in the form of key and value just like TinyDB but in a more secure manner.

SecureDB is an extension for Ai2 Appinventor and its distros which stores the data in the form of key and value just like TinyDB but in a more secure manner.

SecureDB SecureDB is an extension for Ai2 Appinventor and its distros which stores data for your app in a secure format locally on user's device. Expl

Sep 24, 2022

Community extension to generate a Java client from the provided Camunda 7 OpenAPI descitpion and also warp it into Spring Boot

Camunda Engine OpenAPI REST Client Java and Spring Boot This community extension is a convenience wrapper around the generated Java client from the Ca

Dec 28, 2022

An extension for Keycloak, that enables web-based sign in with Apple and token exchange

Apple Identity Provider for Keycloak 🍎 This repository represents an extension for Keycloak, which enables Sign in with Apple for web-based applicati

Dec 29, 2022

Lattice is a powerful, lightweight business extension invoke framework. By using the Lattice framework, complex business customization can be efficiently organized and managed.

Lattice Framework Introduction Lattice is a powerful, lightweight business extension invoke framework. By using the Lattice framework, complex busines

Dec 30, 2022

JDA Commands is an extension for JDA to make commands easier and clearer to develop.

JDA Commands JDA Commands is an extension for JDA to make commands easier and clearer to develop. With the API you can easily create commands for the

Oct 14, 2022
Comments
  • Checksum validation failed with localized powershell

    Checksum validation failed with localized powershell

    Hi,

    On my machine whose language is set to french, the validation of the checksum fails because string must match "hash".

    certUtil -hashfile ".\.mvn\maven-checksun\maven-checksum-extension.jar" SHA256
    Hachage SHA256 de .\.mvn\maven-checksun\maven-checksum-extension.jar :
    3cfb53b1f9ac03a140e7f04f6083953cbcb7da3bfbedc5c9c53f9e1b5265e7d5
    CertUtil: -hashfile La commande s’est terminée correctement.
    

    Wouldn't it be more reliable to just compare only the second result line ?

    Maybe something like ('certUtil -hashfile "%checksumJarPath%" SHA256 ^| Select -Index 1')

    opened by cyrillesondag 1
Owner
Rafael Winterhalter
software consultant who likes static types
Rafael Winterhalter
📊It includes all the work done during the Java-React Bootcamp.

?? Java + React Bootcamp ?? Part 1 - Java Part 2 - React ?? Lecture Class: Youtube ?? Instructor: Engin Demirog ?? Course Materials: Kodlama.io Bootca

İlknur Sucaklı 20 Jun 21, 2022
This repository contains all the code developed during lessions of Foundations of Informatics T2.

If you're using the content of this Repostory, please consider to Watch or Star it in order to help tracking how many people are drawing on it. Founda

null 7 Nov 24, 2022
Simple Android app during a coding night. Just Learning Firebase and Android

KUI-App Simple Android app during a coding night. Just Learning Firebase and Android What we learned: Some basics of Android Basic setup of Firebase:

Kibabii University Informatics Club (KUI) 7 Aug 28, 2022
DSMovie is a full stack web and mobile application built during Spring React Week, an event organized by DevSuperior

projeto-DSMovie Sobre o projeto DSMovie é uma aplicação full stack web e mobile construída durante a Semana Spring React, evento organizado pela DevSu

Matheus Maia Alvarez 7 Apr 18, 2022
RR4J is a tool that records java execution and later allows developers to replay locally.

RR4J [Record Replay 4 Java] RR4J is a tool that records java execution and later allows developers to replay locally. The tool solves one of the chall

Kartik  kalaghatgi 18 Dec 7, 2022
This repo contains all the materials for placement as well as Practical lab codes for all subjects and notes. For students graduating in 2023

UEMK_PLACEMENT_2023 This repo contains all the materials for placement as well as Practical lab codes for all subjects and notes. For students graduat

Shambashib Majumdar 8 Mar 5, 2022
Log4j CVE-2021-44228 examples: Remote Code Execution (through LDAP, RMI, ...), Forced DNS queries, ...

Log4j CVE-2021-44228 and CVE-2021-45046 Requisites Use a vulnerable JDK, for instance JDK 1.8.0_181 Usage Malicious server The malicious server deploy

Manuel Álvarez Álvarez 5 Feb 7, 2022
Application developed during the DDD training with 6 students.

Easyorder Application developed during the DDD training with 6 students. MongoDB To start MongoDB, use docker: docker run -p 27017:27017 --name mongo

RUARO Thibault 1 Jan 21, 2022
Java controlled pub command execution

OPIUM - Operate pub interface under machine. This package allows operating pub command with Java object only and return console context. Perquisites C

Project Will Pub 1 Jan 23, 2022
Android application made during an introduction class to mobile application development.

Reflex Revolution Android application made during an introduction class to mobile application development. Contributors Hailey Savoie Carter Moore Fre

Frederic Verret 3 Aug 27, 2022