Skip to content

jetpen/ssh-auth-webapp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

14 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

SSH Authentication Webapp

A secure PHP web application that provides SSH key-based authentication through a challenge-response protocol. This server-side component works in conjunction with the ssh-auth-extension Chromium browser extension to enable passwordless authentication using SSH keys.

🎯 Overview

Traditional password-based authentication has significant security and usability challenges. This webapp implements a modern approach using asymmetric cryptography (SSH keys) for user authentication, providing:

  • Decentralized Identity: Users maintain full control over their private keys
  • Universal Authentication: Works across participating web services
  • Automatic Login: Seamless authentication once configured
  • Maximum Security: Cryptographic strength of SSH key authentication
  • Privacy Protection: No external transmission of sensitive key material

✨ Features

Core Functionality

  • SSH Key Registration: Secure account creation with SSH public key storage
  • Challenge-Response Authentication: Stateless verification using cryptographic signatures
  • Session Management: Secure HTTP-only cookies with automatic expiration
  • Account Management: User profile and SSH key management interface

Security Features

  • XSS Prevention: Input sanitization and output encoding
  • CSRF Protection: Token-based form validation
  • HTTPS Enforcement: Secure transport requirements
  • Key Security: Public key only storage (private keys remain client-side)

User Experience

  • Progressive Enhancement: Graceful degradation without extension
  • Responsive Design: Mobile-friendly interface
  • Clear Feedback: Comprehensive error messages and status indicators
  • Accessibility: Screen reader compatible and keyboard navigable

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Web Browser   β”‚    β”‚   Web Server    β”‚    β”‚   MySQL DB      β”‚
β”‚                 β”‚    β”‚   (Apache/PHP)  β”‚    β”‚                 β”‚
β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” │◄──►│                 │◄──►│ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚ β”‚ssh-auth-    β”‚ β”‚    β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚    β”‚ β”‚user_accountsβ”‚ β”‚
β”‚ β”‚extension    β”‚ β”‚    β”‚ β”‚PHP App      β”‚ β”‚    β”‚ β”‚table        β”‚ β”‚
β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚    β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚    β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Authentication Flow

  1. Challenge Generation: Server creates random challenge encrypted with user's SSH public key
  2. Challenge Presentation: Encrypted challenge sent to client via web form
  3. Extension Processing: Browser extension decrypts challenge using user's private key
  4. Response Submission: Extension provides cryptographic signature for verification
  5. Verification: Server validates signature against original challenge

πŸ› οΈ Technology Stack

Backend

  • PHP: 7.4+ with OpenSSL extension
  • MySQL: 5.7+ for user account storage
  • Apache: 2.4+ with mod_php

Frontend

  • HTML5: Semantic markup and forms
  • CSS3: Responsive styling and animations
  • JavaScript (ES6+): Client-side validation and extension communication

Security

  • OpenSSL: Cryptographic operations
  • PHP Sessions: Secure session management
  • Content Security Policy: XSS prevention

πŸ“‹ Requirements

Server Requirements

  • Operating System: Linux (Ubuntu/Debian recommended)
  • Web Server: Apache 2.4+ with mod_php
  • Database: MySQL 5.7+ or MariaDB 10.3+
  • PHP: 7.4+ with required extensions:
    • mysqli
    • openssl
    • session

Browser Requirements

  • Chromium-based browsers: Chrome 88+, Edge 88+, Brave, etc.
  • ssh-auth-extension: Required for authentication functionality

Development Requirements

  • Git: Version control
  • Composer: PHP dependency management (if needed)
  • SSH Client: For deployment and testing

πŸš€ Installation

1. Clone Repository and copy to web server for testing

git clone https://github.com/jetpen/ssh-auth-webapp.git
cd ssh-auth-webapp
cd tests
bash setup_test_env.sh
# edit test_context.sh with location and credentials for accessing the web server
bash setup_test_env.sh
# login to web server and verify that the files have correct permissions

2. Database Setup

Create a MySQL database and user:

CREATE DATABASE ssh_auth_db;
CREATE USER 'ssh_auth_user'@'localhost' IDENTIFIED BY 'your_secure_password';
GRANT ALL PRIVILEGES ON ssh_auth_db.* TO 'ssh_auth_user'@'localhost';
FLUSH PRIVILEGES;

3. Configure Application

Copy includes/config-template.php to includes/config.php and edit:

define('DB_HOST', 'localhost');
define('DB_NAME', 'ssh_auth_db');
define('DB_USER', 'ssh_auth_user');
define('DB_PASS', 'your_secure_password');

4. Web Server Configuration

Configure Apache virtual host pointing to src/ directory:

<VirtualHost *:80>
    ServerName your-domain.com
    DocumentRoot /path/to/ssh-auth-webapp/src

    <Directory /path/to/ssh-auth-webapp/src>
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

5. HTTPS Setup

Configure SSL certificate (Let's Encrypt recommended):

sudo certbot --apache -d your-domain.com

6. Database Schema

Access https://your-domain.com/setup.php to create database tables by clicking the button.

πŸ“– Usage

User Registration

  1. Visit the application homepage
  2. Click "Sign Up" to create an account
  3. Provide unique username and SSH public key
  4. Account created successfully

Authentication

  1. Access protected pages (e.g., account summary)
  2. If unauthenticated, redirected to login challenge
  3. ssh-auth-extension automatically processes challenge
  4. Successful authentication redirects to intended page

SSH Key Management

  • Users generate SSH keys using standard tools (ssh-keygen)
  • Public keys uploaded during registration
  • Private keys remain securely stored client-side
  • Extension manages private key operations

πŸ§ͺ Testing

Setup of app on Remote Web Server

# Install vendor packages
composer install

# Configure test context
cp tests/test_context.sh.template tests/test_context.sh
# Edit tests/test_context.sh with your values

# Set up test environment with vendor packages
./tests/setup_test_vendor.sh

# Set up test environment with app
./tests/setup_test_app.sh

Additional steps must be taken to change user and group ownership of the files on the Web server. Also, change the permissions on the files and directories to enable the Web server to read them.

Manual Testing

  1. Unit Tests: PHP syntax validation completed
  2. Integration Tests: Manual browser testing with extension
  3. Security Tests: Input validation and XSS prevention verified

Test Scripts

  • tests/setup_test_env.sh: Remote deployment setup
  • tests/test_context.sh.template: Test configuration template

πŸ“ Project Structure

ssh-auth-webapp/
β”œβ”€β”€ src/                    # Web application source
β”‚   β”œβ”€β”€ index.php          # Landing page
β”‚   β”œβ”€β”€ signup.php         # Account creation
β”‚   β”œβ”€β”€ account.php        # Protected account page
β”‚   β”œβ”€β”€ auth.php           # Authentication handler
β”‚   β”œβ”€β”€ setup.php          # Database setup
β”‚   β”œβ”€β”€ logout.php         # Session cleanup
β”‚   β”œβ”€β”€ includes/          # PHP libraries
β”‚   β”‚   β”œβ”€β”€ config.php     # Database configuration
β”‚   β”‚   β”œβ”€β”€ functions.php  # Utility functions
β”‚   β”‚   └── auth.php       # Authentication logic
β”‚   β”œβ”€β”€ css/               # Stylesheets
β”‚   └── js/                # Client-side scripts
β”œβ”€β”€ tests/                 # Test scripts and configuration
β”œβ”€β”€ memory-bank/           # Project documentation
└── README.md             # This file

🀝 Contributing

Development Setup

  1. Fork the repository
  2. Create feature branch: git checkout -b feature/your-feature
  3. Make changes following PHP best practices
  4. Test thoroughly with ssh-auth-extension
  5. Submit pull request

Code Standards

  • PHP: PSR-12 coding standards
  • Security: OWASP guidelines compliance
  • Documentation: Comprehensive inline comments
  • Testing: Manual testing with extension required

Reporting Issues

  • Use GitHub Issues for bug reports
  • Include browser version and extension status
  • Provide steps to reproduce issues
  • Include relevant log entries

πŸ“„ License

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

πŸ”— Related Projects

⚠️ Security Considerations

Private Key Security

  • Never transmit private keys over any network
  • Client-side storage only for private keys
  • Extension custody of cryptographic operations

Server Security

  • HTTPS required for all communications
  • Secure session cookies with proper expiration
  • Input validation on all user data
  • Regular security updates for all components

Best Practices

  • Unique SSH keys per service recommended
  • Regular key rotation for enhanced security
  • Backup strategies for account recovery

πŸ“ž Support

Documentation

Community

  • Issues: Bug reports and feature requests
  • Discussions: General questions and community support

Built with ❀️ using PHP, MySQL, and modern web standards

About

PHP Web application to demonstrate authentication using a SSH key

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published