A signed payment can be altered (payee and amount) and still pass signature verification

Chiusa
#15 1 commento 0 reazioni 1 assegnatario Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

@aadiitya2007 ci sta già lavorando.

Dal 20/10/2026.

  • #17 di @tanujb03 — aperta
  • #33 di @aadiitya2007 — aperta

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
55/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
blockchain, cryptography, java
Ambito
payments, security

Direzione di ricerca

Start with the signing and verification code in the Transaction class: look at Transaction.create, the four-argument constructor, and hasValidSignature(), and check which fields the signature actually covers. Then look at Blockchain.addTransaction and isValid(). Run the Repro.java from the issue against target/classes. Done means the forged payment fails hasValidSignature(), the chain rejects it, and the existing tests still pass. Agree on the signed fields with the maintainer first.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

advanced bug

What I did

  1. Fresh checkout of main, JDK 17, Maven.
  2. mvn compile
  3. Save this as Repro.java in the project folder:
package minichain;

import java.security.KeyPair;
import java.security.KeyPairGenerator;

public class Repro {
    public static void main(String[] args) throws Exception {
        KeyPairGenerator g = KeyPairGenerator.getInstance("RSA");
        g.initialize(1024);
        KeyPair asha = g.generateKeyPair();

        Blockchain chain = new Blockchain(2);
        chain.minePending("asha");   // asha now has 50 coins

        // asha signs a payment of 120 coins to "ravi"
        Transaction signed = Transaction.create("asha", "ravi", 120, asha.getPrivate(), asha.getPublic());
        // same id, key and signature, but a different payee and amount
        Transaction forged = new Transaction(signed.id(), "asha", "ravi1", 20, signed.senderKey(), signed.signature());

        System.out.println("signed:  " + signed);
        System.out.println("forged:  " + forged);
        System.out.println("signature valid for the forged payment: " + forged.hasValidSignature());
        chain.addTransaction(forged);
        chain.minePending("m");
        System.out.println("chain valid: " + chain.isValid() + ", ravi1 has " + chain.balanceOf("ravi1") + " coins");
    }
}
  1. Compile and run it (use : instead of ; on Linux/macOS):
mkdir out && javac -cp target/classes -d out Repro.java && java -cp "target/classes;out" minichain.Repro

What I expected
The README says: "The system uses digital signatures to prevent forging transactions." (README.md, Note on Security)

A payment whose payee or amount differs from what asha signed should fail hasValidSignature().

What happened instead

signed:  asha -> ravi: 120
forged:  asha -> ravi1: 20
signature valid for the forged payment: true
chain valid: true, ravi1 has 20 coins

The id, key and signature are all public in the chain.

Environment
main @ 0e92205, JDK 17, Maven 3.9.16, Windows 11.

I'd like to work on the fix for this.

Lingua principale
Java
Stelle
0
Fork
3
Merge medio
3g 6h
PR unite (30g)
9

Preparare l'ambiente

  • Nessun Dockerfile né file Docker Compose
  • Ha un modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di techcsispit/mini-chain

Tutte le issue di techcsispit/mini-chain

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.