# Copyright © Albert Lane. All Rights Reserved. # Proprietary and Confidential — Albert Lane Proprietary Software License. # Unauthorized use, copying, modification, or distribution is prohibited. # License inquiries: https://albertlane.net import os import hashlib from flask import Flask, request, jsonify from werkzeug.utils import secure_filename app = Flask(__name__) app.config['UPLOAD_FOLDER'] = os.path.abspath('./intake_vault') app.config['MAX_CONTENT_LENGTH'] = 32 * 1024 * 1024 # 32MB limit ALLOWED_EXTENSIONS = {'pdf', 'tex', 'lane', 'proto'} os.makedirs(app.config['UPLOAD_FOLDER'], exist_ok=True) def allowed_file(filename: str) -> bool: return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS def calculate_sha256(filepath: str) -> str: hasher = hashlib.sha256() with open(filepath, 'rb') as f: while chunk := f.read(65536): hasher.update(chunk) return hasher.hexdigest() @app.route('/api/intake', methods=['POST']) def intake_endpoint(): auth_header = request.headers.get('Authorization', '') if not auth_header.startswith('Bearer '): return jsonify({"error": "Unauthorized: Bearer token required"}), 401 if 'file' not in request.files: return jsonify({"error": "Missing file boundary in request"}), 400 file = request.files['file'] if not file or file.filename == '': return jsonify({"error": "Empty filename specified"}), 400 if not allowed_file(file.filename): return jsonify({"error": f"Disallowed extension. Supported: {list(ALLOWED_EXTENSIONS)}"}), 400 safe_name = secure_filename(file.filename) destination = os.path.join(app.config['UPLOAD_FOLDER'], safe_name) file.save(destination) digest = calculate_sha256(destination) file_size = os.path.getsize(destination) # Perform magic check if artifact is a .lane binary binary_status = "unverified" if safe_name.endswith('.lane'): with open(destination, 'rb') as bf: magic = bf.read(8) if magic == b'\x3d\x2c\x1b\x9a\x8f\x3f\x00\x00': # 0x3F8F9A1B2C3D little-endian binary_status = "lane_kernel_verified" else: binary_status = "lane_magic_mismatch" return jsonify({ "status": "INGESTED", "file": safe_name, "bytes": file_size, "sha256": digest, "validation": binary_status }), 201 if __name__ == '__main__': app.run(host='0.0.0.0', port=5000)