Skip to content

hisgarden/javaemvreader

Β 
Β 

Repository files navigation

Java EMV Reader πŸ’³

Build Status Test Coverage License Java Version

A comprehensive Java library for reading and processing EMV (Europay, Mastercard, Visa) payment cards, supporting both contact and contactless transactions. Built with Test-Driven Development (TDD) principles and enterprise-level testing standards.

πŸš€ Features

πŸ—οΈ Core EMV Functionality

  • ISO 7816-4 Compliance - Full Application Identifier (AID) validation
  • EMV Transaction Processing - Complete payment card transaction flow
  • BER-TLV Data Parsing - Robust EMV data structure handling
  • Card Emulation - Software-based card emulation for testing
  • Multi-Application Support - Handle multiple payment applications per card

πŸ”§ Smart Card Support

  • Contact Cards - Traditional chip card interface
  • Contactless Cards - NFC/RFID payment cards
  • PSE/PPSE Discovery - Payment System Environment detection
  • Application Selection - Automatic and manual app selection
  • PIN Verification - Secure PIN handling and validation

πŸ›‘οΈ Security & Cryptography

  • Static Data Authentication (SDA) - Card authenticity verification
  • Certificate Chain Validation - CA and issuer certificate processing
  • Cryptogram Verification - Transaction cryptogram validation
  • Risk Management - Terminal and issuer risk assessment

πŸ“Š Test-Driven Development (TDD)

This project follows strict TDD principles with comprehensive test coverage:

πŸ§ͺ Test Suite Statistics

  • 123 Total Tests across 8 test classes
  • 92% Success Rate (113 passing tests)
  • Modern Testing Framework (JUnit 4.13.2, Mockito 3.12.4, AssertJ 3.21.0)
Component Tests Success Rate Coverage
AID Validation 10/10 100% βœ… ISO 7816-4 compliance
BER-TLV Parsing 14/15 93% βœ… EMV data structures
Card Emulation 20/20 100% βœ… Complete functionality
EMV Session 9/15 60% πŸ”„ Transaction flow
Utilities 60/63 95% βœ… Helper functions

🎯 TDD Test Classes

  • AIDTest.java - Application Identifier validation
  • BERTLVTest.java - EMV data structure parsing
  • CardEmulatorTest.java - Card emulation testing
  • EMVSessionTest.java - Transaction flow with Mockito
  • EMVUtilTest.java - Utility function validation

πŸƒβ€β™‚οΈ Quick Start

Prerequisites

  • Java 11+ (OpenJDK recommended)
  • Maven 3.6+ for dependency management
  • Smart card reader (optional, for physical cards)

Installation

# Clone the repository
git clone https://github.com/hisgarden/javaemvreader.git
cd javaemvreader

# Build the project
mvn clean compile

# Run tests
mvn test

# Create JAR
mvn package

Basic Usage

import sasc.emv.*;
import sasc.terminal.*;

// Initialize EMV session
SmartCard card = new SmartCard();
CardConnection terminal = new SmartcardioCardConnection();
EMVSession session = new EMVSession(card, terminal);

// Discover and select applications
session.initContext();
List<EMVApplication> apps = card.getEmvApplications();

// Process transaction
for (EMVApplication app : apps) {
    session.selectApplication(app);
    session.initiateApplicationProcessing();
    session.prepareTransactionProcessing();
    session.performTransaction();
}

Card Emulation

import sasc.CardEmulator;

// Use built-in card emulation for testing
CardEmulator emulator = new CardEmulator("/sdacardtransaction.xml");
byte[] atr = emulator.getATR();

// Send APDU commands
byte[] selectPSE = EMVAPDUCommands.selectPSE();
CardResponse response = emulator.transmit(selectPSE);

πŸ“š Documentation

πŸ“– Comprehensive Guides

πŸ”§ API Documentation

  • EMVSession - Main transaction processing class
  • SmartCard - Card abstraction layer
  • CardEmulator - Software card emulation
  • EMVUtil - Utility functions for EMV processing
  • BERTLV - BER-TLV data structure handling

πŸ› οΈ Development

Running Tests

# Run all tests
mvn test

# Run specific test class
mvn test -Dtest=AIDTest

# Run with verbose output
mvn test -X

# Generate test reports
mvn test && open target/surefire-reports/index.html

Test Categories

# Critical EMV components
mvn test -Dtest=AIDTest,BERTLVTest,CardEmulatorTest

# Transaction flow
mvn test -Dtest=EMVSessionTest

# Utility functions
mvn test -Dtest=EMVUtilTest,ApplicationPriorityIndicatorTest

Building

# Clean build
mvn clean compile

# Create JAR with dependencies
mvn package assembly:single

# Install to local repository
mvn install

πŸ“ Project Structure

javaemvreader/
β”œβ”€β”€ src/main/java/sasc/           # Core EMV implementation
β”‚   β”œβ”€β”€ emv/                      # EMV transaction processing
β”‚   β”œβ”€β”€ iso7816/                  # ISO 7816-4 standard implementation
β”‚   β”œβ”€β”€ smartcard/                # Smart card abstraction
β”‚   └── terminal/                 # Terminal communication
β”œβ”€β”€ src/test/java/sasc/           # Comprehensive test suite
β”‚   β”œβ”€β”€ emv/                      # EMV transaction tests
β”‚   └── iso7816/                  # ISO standard tests
β”œβ”€β”€ src/main/resources/           # Configuration and data files
β”œβ”€β”€ testkeys/                     # Test certificates and keys
└── docs/                         # Documentation

🀝 Contributing

We welcome contributions! Please follow our TDD approach:

  1. Fork the repository
  2. Write failing tests first (Red phase)
  3. Implement minimal code to pass tests (Green phase)
  4. Refactor and improve (Refactor phase)
  5. Submit pull request with test coverage

Development Guidelines

  • Follow TDD principles (Red-Green-Refactor)
  • Maintain test coverage above 90%
  • Use modern testing frameworks (JUnit, Mockito, AssertJ)
  • Include comprehensive documentation
  • Follow EMV specifications and ISO 7816-4 standards

πŸ“„ License

This project is licensed under the Apache License 2.0 - see the LICENSE-2_0.txt file for details.

πŸ”— Related Projects

πŸ“ž Support

πŸ† Acknowledgments

  • EMV Consortium for payment card standards
  • SASC Community for smart card development
  • TDD Community for testing best practices
  • Contributors who helped improve this project

Built with ❀️ using Test-Driven Development principles

About

Automatically exported from code.google.com/p/javaemvreader

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%