Implements comprehensive privacy and anonymity features including Tor hidden service support, location obfuscation, and anonymous registration. Privacy Features: - Anonymous plant registration with zero personal information - Location privacy levels: exact, fuzzy, city, country, hidden - Pseudonymous identities and wallet addresses - Privacy settings component with real-time Tor status - Encrypted anonymous contact generation Tor Integration: - SOCKS proxy support for Tor connections - Hidden service (.onion) configuration - Tor connection detection and status API - Docker Compose setup for easy Tor deployment - Automatic privacy warnings when not using Tor Location Obfuscation: - Fuzzy location: ±1-5km random offset - City level: ~10km grid - Country level: ~100km grid - Hidden: complete location privacy - Haversine-based distance calculations preserved Anonymous Registration: - /plants/register-anonymous endpoint - Privacy-first UI with Tor status banner - Anonymous IDs and wallet addresses - Optional pseudonym support - Encryption key support for enhanced security Infrastructure: - Tor service integration (lib/services/tor.ts) - Privacy utilities (lib/privacy/anonymity.ts) - PrivacySettings React component - Tor status API endpoint - Docker and docker-compose configurations - Example Tor configuration (torrc.example) Documentation: - Comprehensive TOR_SETUP.md guide - Installation instructions for Linux/macOS/Windows - Privacy best practices - Troubleshooting guide - Security considerations - Updated README with Tor features Dependencies: - Added socks-proxy-agent for Tor proxy support This enables: - Privacy-conscious growers to share anonymously - Protection of exact home locations - Censorship-resistant plant sharing - Community building without identity disclosure - Compliance with privacy regulations All privacy features are optional and configurable. Users can choose their desired privacy level.
70 lines
2 KiB
TypeScript
70 lines
2 KiB
TypeScript
/**
|
|
* API Route: Check Tor status
|
|
* GET /api/privacy/tor-status
|
|
*/
|
|
|
|
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
import { getTorService } from '../../../lib/services/tor';
|
|
|
|
export default async function handler(
|
|
req: NextApiRequest,
|
|
res: NextApiResponse
|
|
) {
|
|
if (req.method !== 'GET') {
|
|
return res.status(405).json({ error: 'Method not allowed' });
|
|
}
|
|
|
|
try {
|
|
const torService = getTorService();
|
|
|
|
// Check if Tor is enabled in configuration
|
|
const isEnabled = process.env.TOR_ENABLED === 'true';
|
|
|
|
// Check if request came through Tor
|
|
const isTorConnection = torService.isRequestFromTor(req.headers);
|
|
|
|
let isAvailable = false;
|
|
let circuitInfo = null;
|
|
let onionAddress = null;
|
|
|
|
if (isEnabled) {
|
|
// Check if Tor daemon is available
|
|
try {
|
|
isAvailable = await torService.isAvailable();
|
|
|
|
if (isAvailable) {
|
|
circuitInfo = await torService.getCircuitInfo();
|
|
onionAddress = torService.getOnionAddress();
|
|
}
|
|
} catch (error) {
|
|
console.error('Error checking Tor availability:', error);
|
|
}
|
|
}
|
|
|
|
res.status(200).json({
|
|
success: true,
|
|
tor: {
|
|
enabled: isEnabled,
|
|
available: isAvailable,
|
|
connectionThroughTor: isTorConnection,
|
|
onionAddress: onionAddress,
|
|
circuit: circuitInfo,
|
|
},
|
|
privacy: {
|
|
recommendTor: !isTorConnection,
|
|
privacyLevel: isTorConnection ? 'high' : 'standard',
|
|
ip: isTorConnection ? 'Hidden via Tor' : 'Visible',
|
|
},
|
|
recommendations: isTorConnection
|
|
? ['Your connection is private via Tor', 'Anonymous plant registration available']
|
|
: [
|
|
'For maximum privacy, access via Tor Browser',
|
|
'Download Tor from https://www.torproject.org',
|
|
`Or connect to our onion service: ${onionAddress || 'Not available'}`,
|
|
],
|
|
});
|
|
} catch (error: any) {
|
|
console.error('Error checking Tor status:', error);
|
|
res.status(500).json({ error: error.message || 'Internal server error' });
|
|
}
|
|
}
|