Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

ButterAuth-Native-1

A secure, Native AOT-compiled licensing framework for .NET 8.0 applications with hardware binding, JWT-based authentication, and anti-tampering mechanisms.

πŸš€ Features

  • πŸ”’ Hardware Binding (HWID): Unique machine fingerprinting using system UUID, motherboard serial, and CPU ID
  • 🎫 JWT-Based Licensing: Secure token generation with configurable expiration (5 minutes to 1 year)
  • ⚑ Native AOT Compilation: Protection against decompilation and reverse engineering
  • πŸ”— P/Invoke Interoperability: Enables integration with native code and cross-language applications
  • πŸ“‘ Background License Monitoring: Real-time validation via license shadow checking and timer display
  • πŸ†“ Free Trial Management: Time-limited trials with daily usage restrictions
  • πŸ›‘οΈ Anti-Tampering: File integrity checks and automatic shutdown on license violation
  • πŸ” AES Encryption: Secure license storage with hardware-derived keys

πŸ“‹ Table of Contents

πŸ”§ Requirements

  • .NET 8.0 SDK or later
  • Windows x64 operating system
  • Visual Studio 2022 or compatible IDE (optional)

Dependencies

  • Microsoft.IdentityModel.JsonWebTokens (v8.12.1)
  • System.IdentityModel.Tokens.Jwt (v8.12.1)
  • System.Management (v9.0.7)

πŸ“¦ Installation

  1. Clone the repository:
git clone https://github.com/yourusername/ButterAuth-Native-1.git
cd ButterAuth-Native-1
  1. Restore dependencies:
dotnet restore
  1. Build the project:
dotnet build

πŸš€ Quick Start

Building the DLL

To compile the project as a Native AOT DLL:

dotnet publish -c Release -r win-x64 --self-contained /p:NativeLib=Shared

Basic Usage in C#

using System.Runtime.InteropServices;

class Program
{
    const string DllName = "ButterAuth-Native-1.dll";
    
    [DllImport(DllName, EntryPoint = "Initialize", CallingConvention = CallingConvention.Cdecl)]
    public static extern void Initialize();
    
    [DllImport(DllName, EntryPoint = "StartLicenseShadow", CallingConvention = CallingConvention.Cdecl)]
    public static extern int StartLicenseChecker(int checkIntervalSeconds);
    
    [DllImport(DllName, EntryPoint = "StopLicenseChecker", CallingConvention = CallingConvention.Cdecl)]
    public static extern byte StopLicenseChecker(int instanceId);

    static void Main(string[] args)
    {
        try
        {
            // Initialize the license system
            Initialize();
            
            // Start the license checker with 30 second intervals
            int licenseCheckerId = StartLicenseChecker(30);
            
            // Your application logic here
            Console.WriteLine("Application running with license protection...");
            
            // Application loop
            while (true)
            {
                Thread.Sleep(1000);
                // Your main application code
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine($"Error: {ex.Message}");
        }
    }
}

πŸ”§ Building the DLL

For Library (DLL) Output

# Standard Native AOT DLL build
dotnet publish -c Release -r win-x64 --self-contained /p:NativeLib=Shared

# Alternative build command
dotnet publish --configuration Release --runtime win-x64 --output ./publish

For Executable Output

# Single file executable
dotnet publish --configuration Release --runtime win-x64 --output ./publish /p:PublishSingleFile=true /p:IncludeNativeLibrariesForSelfExtract=true /p:PublishTrimmed=true

# Standard executable
dotnet publish -c Release --self-contained --runtime win-x64

πŸ“š Usage Examples

For detailed integration examples and advanced usage patterns, see docs/USAGE.md.

License Key Generation

The system includes a built-in key generator accessible through the activation menu:

[DllImport(DllName, EntryPoint = "RunKeygenUI", CallingConvention = CallingConvention.Cdecl)]
public static extern void RunKeygenUI();

// Secret key generation
[DllImport(DllName, EntryPoint = "GUNK", CallingConvention = CallingConvention.Cdecl)]
public static extern void GUNK();

License Status Monitoring

[DllImport(DllName, EntryPoint = "TimerInitialize", CallingConvention = CallingConvention.Cdecl)]
public static extern byte LicenseTimeStatus();

// Check license status
byte status = LicenseTimeStatus();
if (status == 1)
{
    Console.WriteLine("License is valid");
}

πŸ“– API Reference

Core Functions

Function Description Parameters Returns
Initialize Initializes the licensing system None void
RunKeygenUI Opens the license key generation UI None void
StartLicenseChecker Starts background license validation int checkIntervalSeconds int (instance ID)
StopLicenseChecker Stops license checker instance int instanceId byte (success/failure)
LicenseTimeStatus Gets current license status None byte (status code)

Internal Components

  • Configurations: Manages application settings and security parameters
  • Validator: Handles license validation and decryption
  • JwtGenerate: Creates JWT tokens for license management
  • LicenseShadowCheck: Background license monitoring service
  • Trial: Manages free trial functionality
  • SystemSecure: Provides cryptographic operations

βš™οΈ Configuration

The system uses a singleton configuration pattern. Key configuration options include:

  • Product Name: Application title and branding
  • JWT Security Key: For token signing and validation
  • AES Keys: Hardware-derived encryption keys
  • Trial Duration: Default 5 minutes with daily limits
  • License Check Intervals: Configurable monitoring frequency

πŸ›‘οΈ Security Features

Hardware Binding

The system creates a unique fingerprint based on:

  • System UUID
  • Motherboard serial number
  • CPU ID
  • Combined hash for maximum uniqueness

Encryption Layers

  1. AES Encryption: License files encrypted with hardware-derived keys
  2. JWT Tokens: Signed tokens with expiration and claims validation
  3. File Hiding: Trial and license files marked as hidden
  4. Integrity Checks: Automatic validation of file modifications

Anti-Tampering Mechanisms

  • Clock Manipulation Protection: Uses UTC time for all operations
  • File Integrity Monitoring: Detects license file modifications
  • Runtime Validation: Continuous background license checking
  • Automatic Shutdown: Application exit on tamper detection

πŸ†“ Trial System

Features

  • 5-minute trial sessions per day
  • Daily usage limits to prevent abuse
  • Encrypted date tracking with hardware binding
  • Seamless transition to full license

Trial Security

  • Encrypted trial data: Cannot be easily modified
  • Hardware-bound keys: Prevents file transfer between machines
  • Hidden file storage: Discourages casual tampering
  • Application exit on tampering: Immediate shutdown if trial file is corrupted

πŸ—οΈ Architecture

graph TB
    A[ButterAuth-Native-1] --> B[Config]
    A --> C[License]
    A --> D[Manager]
    A --> E[Security]
    A --> F[Transaction]
    A --> G[Main.cs]
    
    B --> B1[Configurations.cs]
    C --> C1[JWT Components]
    C --> C2[Key Generation]
    C --> C3[License Management]
    D --> D1[License Shadow Check]
    D --> D2[Title Timer]
    D --> D3[Trial System]
    E --> E1[Cryptographic Keys]
    E --> E2[Hardware ID]
    E --> E3[System Security]
    F --> F1[File Operations]
Loading

Component Responsibilities

  • Config: Singleton pattern for application settings
  • License: JWT-based license creation and validation
  • Manager: Background monitoring and trial management
  • Security: Cryptographic operations and hardware binding
  • Transaction: License file I/O operations
  • Main: Orchestration and user interface

πŸ”„ Workflow

  1. Initialization: System starts and checks for existing license
  2. Validation: If license exists, validates signature and expiration
  3. Activation Menu: If no license, presents activation options
  4. Background Monitoring: Continuous license validation while running
  5. Trial Management: Handles free trial sessions with daily limits
  6. Security Enforcement: Monitors for tampering and unauthorized access

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“‹ Development Guidelines

  • Follow C# coding standards and conventions
  • Ensure all security features are thoroughly tested
  • Document any new API functions
  • Test Native AOT compilation before submitting
  • Validate P/Invoke signatures for cross-language compatibility

πŸ› Troubleshooting

Common Issues

  1. License Validation Fails

    • Verify hardware ID hasn't changed
    • Check system clock accuracy
    • Ensure license hasn't expired
  2. DLL Loading Issues

    • Confirm target architecture (x64)
    • Verify all dependencies are available
    • Check Native AOT compilation settings
  3. Trial System Problems

    • Delete hidden trial files if corrupted
    • Verify system date accuracy
    • Check file permissions in temp directory

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ”— Related Links

πŸ“– Detailed Usage Guide

For comprehensive integration examples, advanced patterns, and multi-language support, see the USAGE.md documentation.


⚠️ Security Notice: This framework implements strong security measures, but proper implementation and deployment practices are essential. Always test thoroughly in your target environment and follow security best practices for license distribution and key management.

About

No description, website, or topics provided.

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages