Skip to content

morinaltin/information-security-gr4

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

24 Commits
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

University Logo

University of Prishtina

Faculty of Computer and Electrical Engineering

Computer and Software Engineering - Masters Programme

Course: โ€œInformation Securityโ€

Professor: Dr. techn. Blerim Rexha , PhD Mรซrgim Hoti

Students (Gr. 4):

  • Altin Morina
  • Endri Binaku

ElGamal Authentication System

A cryptographic authentication system that implements passwordless authentication using ElGamal digital signatures and a challenge-response protocol. This project demonstrates how to build a secure authentication system without transmitting passwords during login.

๐ŸŽฏ Overview

This C# application provides a complete authentication framework where users authenticate by proving possession of a private key through digital signatures. Instead of sending passwords, users sign server-generated challenges, providing strong cryptographic authentication.

โœจ Features

  • ElGamal Digital Signatures: Full implementation of ElGamal signature generation and verification
  • Challenge-Response Protocol: Time-limited challenges prevent replay attacks
  • Passwordless Authentication: No password transmission during login
  • Session Management: Secure session token generation and validation
  • Configurable Security: Adjustable key sizes and challenge TTL
  • Thread-Safe Operations: All storage and authentication operations are thread-safe
  • Key Serialization: Support for exporting/importing public keys in JSON format

๐Ÿ—๏ธ Architecture

Core Components

  1. ElGamal Cryptography (ElGamalKeyGeneration.cs, ElGamalSignature.cs)

    • Prime number generation using Miller-Rabin primality test
    • ElGamal key pair generation (public/private keys)
    • Message signing and signature verification
    • SHA-256 hashing for message digest
  2. Authentication Service (AuthenticationService.cs)

    • User registration with public key storage
    • Challenge generation with expiration
    • Signature verification and authentication
    • Session token management
  3. Client Library (AuthenticationClient.cs)

    • Simplified API for registration and login
    • Automatic key pair management
    • Challenge signing automation
  4. Storage Layer (InMemoryUserStorage.cs)

    • In-memory user storage (can be extended to database)
    • Thread-safe user operations

๐Ÿ“‹ Prerequisites

  • .NET 9.0 SDK or later
  • Windows, Linux, or macOS

๐Ÿš€ Installation

  1. Clone the repository:
git clone <repository-url>
cd auth_elgamal
  1. Restore dependencies:
dotnet restore
  1. Build the project:
dotnet build
  1. Run the demo:
dotnet run --project auth_elgamal

๐Ÿ’ป Usage

Basic Example

using auth_elgamal;
using auth_elgamal.Client;
using auth_elgamal.Services;
using auth_elgamal.Storage;

// Setup
var storage = new InMemoryUserStorage();
var settings = new AuthSettings 
{ 
    ChallengeTtl = TimeSpan.FromMinutes(2), 
    DefaultKeySizeBits = 512 
};
var service = new AuthenticationService(storage, settings);
var client = new AuthenticationClient(service);

// Register a new user
var register = client.Register("alice", "password123", 512);
Console.WriteLine($"Register: {register.Success} - {register.Message}");

// Login
var login = client.Login("alice");
Console.WriteLine($"Login: {login.Success} - {login.Message}");

if (login.Success)
{
    var token = client.GetSessionToken();
    Console.WriteLine($"Session token: {token}");
    
    // Validate session
    bool isValid = service.IsValidSession(token!);
    string? username = service.GetUsernameFromSession(token!);
    Console.WriteLine($"Session valid: {isValid}, User: {username}");
}

Advanced Configuration

var settings = new AuthSettings
{
    ChallengeTtl = TimeSpan.FromMinutes(5),  // Challenge expiration time
    DefaultKeySizeBits = 2048                // Key size in bits (512, 1024, 2048, etc.)
};

var service = new AuthenticationService(storage, settings, new ConsoleAuthLogger());

๐Ÿ” Authentication Flow

1. Registration

Client                          Server
  |                               |
  |-- Generate ElGamal Key Pair --|
  |                               |
  |-- Register(username,        -->|
  |    password, publicKey)        |
  |                               |-- Store user with:
  |                               |   - Username
  |                               |   - Password hash (SHA-256)
  |                               |   - Public key
  |<-- Registration Response -----|
  |                               |

2. Login (Challenge-Response)

Client                          Server
  |                               |
  |-- Request Challenge(username) -->|
  |                               |-- Generate random challenge
  |                               |-- Store challenge with TTL
  |<-- Challenge (message, id) ---|
  |                               |
  |-- Sign challenge with         |
  |   private key                 |
  |                               |
  |-- Authenticate(username,     -->|
  |    challengeId, signature)     |
  |                               |-- Verify signature using
  |                               |   stored public key
  |                               |-- Check challenge expiration
  |<-- Auth Response +            |
  |    Session Token -------------|
  |                               |

3. Session Validation

Client                          Server
  |                               |
  |-- Validate Session(token) ---->|
  |                               |-- Check token exists
  |                               |-- Return username
  |<-- Session Status +           |
  |    Username ------------------|
  |                               |

๐Ÿ”’ Security Features

  • Cryptographic Authentication: Uses ElGamal digital signatures (asymmetric cryptography)
  • Challenge-Response Protocol: Prevents replay attacks with time-limited challenges
  • No Password Transmission: Passwords are only used during registration, never sent during login
  • Secure Hashing: SHA-256 for password hashing and message digest
  • Thread Safety: All operations are protected with locks
  • Configurable TTL: Challenge expiration prevents stale authentication attempts

๐Ÿ“ Project Structure

auth_elgamal/
โ”œโ”€โ”€ Client/
โ”‚   โ””โ”€โ”€ AuthenticationClient.cs      # High-level client API
โ”œโ”€โ”€ Models/
โ”‚   โ”œโ”€โ”€ AuthModels.cs                # Authentication request/response models
โ”‚   โ”œโ”€โ”€ RegistrationModels.cs        # Registration models
โ”‚   โ”œโ”€โ”€ User.cs                      # User entity
โ”‚   โ””โ”€โ”€ ErrorCodes.cs                # Error code enumerations
โ”œโ”€โ”€ Services/
โ”‚   โ”œโ”€โ”€ AuthenticationService.cs     # Core authentication logic
โ”‚   โ”œโ”€โ”€ AuthSettings.cs              # Configuration settings
โ”‚   โ””โ”€โ”€ Logging.cs                   # Logging interface
โ”œโ”€โ”€ Storage/
โ”‚   โ”œโ”€โ”€ IUserStorage.cs              # Storage interface
โ”‚   โ””โ”€โ”€ InMemoryUserStorage.cs      # In-memory implementation
โ”œโ”€โ”€ ElGamalKeyGeneration.cs          # Key pair generation
โ”œโ”€โ”€ ElGamalSignature.cs              # Signing and verification
โ”œโ”€โ”€ KeySerialization.cs              # Key export/import utilities
โ””โ”€โ”€ Program.cs                        # Demo application

๐Ÿ”ง Technical Details

ElGamal Signature Scheme

The implementation follows the standard ElGamal signature algorithm:

  1. Key Generation:

    • Generate large prime p
    • Find generator g of the multiplicative group
    • Choose private key x randomly
    • Compute public key y = g^x mod p
  2. Signing:

    • Hash message to get h
    • Choose random k coprime to p-1
    • Compute r = g^k mod p
    • Compute s = (h - x*r) * k^(-1) mod (p-1)
    • Signature is (r, s)
  3. Verification:

    • Hash message to get h
    • Verify: g^h โ‰ก y^r * r^s (mod p)

Key Sizes

  • 512 bits: Fast, suitable for development/testing
  • 1024 bits: Moderate security
  • 2048 bits: Recommended for production (slower key generation)

๐Ÿงช Testing

The project includes a demo in Program.cs that demonstrates:

  • User registration
  • Challenge generation
  • Authentication flow
  • Session management

Run the demo:

dotnet run --project auth_elgamal

๐Ÿ“ Notes

  • This is an educational project demonstrating cryptographic authentication
  • The in-memory storage is for demonstration; production systems should use persistent storage
  • Key generation can be slow for large key sizes (2048+ bits)
  • The current implementation uses a fixed generator (g=2) for simplicity

๐Ÿ”ฎ Future Enhancements

  • Database-backed user storage
  • Key rotation support
  • Multi-factor authentication
  • API endpoints (REST/GraphQL)
  • Key recovery mechanisms
  • Rate limiting for challenges
  • Audit logging

๐Ÿ“š References

๐Ÿ“„ License

This project is for educational purposes as part of an information security course.


Note: This implementation is for educational demonstration. For production use, consider using established cryptographic libraries and security best practices.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages