|
1 | | -# Practica2 |
| 1 | +# SDIS P2 Module 3: Secure RMI (SSL/TLS) & Streaming Auditing |
| 2 | + |
| 3 | +<div align="center"> |
| 4 | + |
| 5 | +  |
| 6 | +  |
| 7 | +  |
| 8 | +  |
| 9 | +  |
| 10 | +  |
| 11 | + |
| 12 | +</div> |
| 13 | + |
| 14 | +> **ABOUT THIS MODULE:** |
| 15 | +> This repository contains the final evolution (Module 3) of our Distributed Spotify architecture. It builds upon the Hybrid Streaming System from Module 2 by introducing **End-to-End Encryption (SSL/TLS)** for all RMI Control Plane communications and Callbacks. It also implements a **Persistent Auditing System** to log TCP streaming events. |
| 16 | +> |
| 17 | +> ⚠️ *Note: If you want to test the streaming architecture without generating SSL certificates, please switch to the `module-2` branch.* |
| 18 | +
|
| 19 | +--- |
| 20 | + |
| 21 | +## Architecture & Key Features |
| 22 | + |
| 23 | +* **Secure RMI (SSL/TLS):** The entire control plane (metadata fetching, playlist management, and remote triggers) is secured using `SslRMIClientSocketFactory` and `SslRMIServerSocketFactory`. |
| 24 | +* **Encrypted Callbacks:** The server securely invokes methods on the client (like launching the media player) using bi-directional SSL handshakes. |
| 25 | +* **Persistent Event Logging:** Implements a robust `Utils` logger that records stream connections, TCP client IPs, and total transmitted bytes to a physical `streams.txt` file for server auditing. |
| 26 | +* **Auto-Discovery & Preloading (Bonus):** The server dynamically scans the `mp3files/origin` and `jpgfiles/` directories on startup, automatically preloading all available media files and their respective covers without manual client population. |
| 27 | +* **Network-Ready:** The system explicitly defines the `java.rmi.server.hostname` property, preventing `BindExceptions` and allowing deployment across different physical machines on the same LAN. |
| 28 | + |
| 29 | +--- |
| 30 | + |
| 31 | +## Project Structure |
| 32 | + |
| 33 | +```text |
| 34 | +Distributed-Spotify-Java-RMI |
| 35 | + ┣ 📂 jpgfiles/ |
| 36 | + ┣ 📂 logs/ |
| 37 | + ┃ ┗ 📜 streams.txt |
| 38 | + ┣ 📂 mp3files/ |
| 39 | + ┃ ┣ 📂 destination/ |
| 40 | + ┃ ┗ 📂 origin/ |
| 41 | + ┗ 📂 src/spotify/ |
| 42 | + ┣ 📂 media/ |
| 43 | + ┃ ┣ 📜 Globals.java |
| 44 | + ┃ ┣ 📜 Media.java |
| 45 | + ┃ ┗ 📜 MediaPlayer.java |
| 46 | + ┣ 📂 rmi/ |
| 47 | + ┃ ┣ 📂 client/ |
| 48 | + ┃ ┃ ┣ 📜 SpotifyClientImpl.java |
| 49 | + ┃ ┃ ┗ 📜 SpotifyStreamingClient.java |
| 50 | + ┃ ┣ 📂 common/ |
| 51 | + ┃ ┃ ┣ 📜 ServerMessages.java |
| 52 | + ┃ ┃ ┣ 📜 Spotify.java |
| 53 | + ┃ ┃ ┣ 📜 SpotifyClient.java |
| 54 | + ┃ ┃ ┗ 📜 SpotifyServer.java |
| 55 | + ┃ ┗ 📂 server/ |
| 56 | + ┃ ┣ 📜 SpotifyLauncher.java |
| 57 | + ┃ ┗ 📜 SpotifyServerImpl.java |
| 58 | + ┣ 📂 stream/ |
| 59 | + ┃ ┣ 📜 ClientStream.java |
| 60 | + ┃ ┗ 📜 ServerStream.java |
| 61 | + ┗ 📂 utils/ |
| 62 | + ┣ 📜 ConcurrentMultiMap.java |
| 63 | + ┣ 📜 MediaDirectory.java |
| 64 | + ┗ 📜 Utils.java |
| 65 | +``` |
| 66 | + |
| 67 | +## Getting Started |
| 68 | +### 1. Generate the SSL Certificate (Mandatory) |
| 69 | +Before compiling or running, you must generate a dummy Keystore for the SSL Handshake. Open a terminal in the root directory and run: |
| 70 | + |
| 71 | +```bash |
| 72 | +keytool -genkey -noprompt -alias spotify -dname "CN=localhost" -keyalg RSA -keystore keystore.jks -storepass 123456 -keypass 123456 |
| 73 | +(Ensure the keystore.jks file is present in the execution directory for both Server and Client). |
| 74 | +``` |
| 75 | + |
| 76 | +### 2. Compilation |
| 77 | +Compile the entire project from your src directory: |
| 78 | + |
| 79 | +```bash |
| 80 | +javac spotify/common/*.java spotify/media/*.java spotify/utils/*.java spotify/server/*.java spotify/client/*.java spotify/stream/*.java |
| 81 | +``` |
| 82 | + |
| 83 | +### 3. Execution |
| 84 | +Start the Secure Server: |
| 85 | +The server will bind the secure registry and start logging to ./logs/streams.txt. |
| 86 | + |
| 87 | +```bash |
| 88 | +java spotify.server.SpotifyLauncher |
| 89 | +``` |
| 90 | + |
| 91 | +Start the Secure Client: |
| 92 | +```bash |
| 93 | +java spotify.client.SpotifyStreamingClient |
| 94 | +``` |
| 95 | + |
| 96 | +Interaction Example (Server Auditing) |
| 97 | +When a client streams a song, the server console and the logs/streams.txt file will register: |
| 98 | + |
| 99 | +```bash |
| 100 | +📝 DEBUG LOGS: Escrito registro en -> .../logs/streams.txt |
| 101 | +[2024-05-20 18:30:15] [STREAM] Streaming to: /127.0.0.1 |
| 102 | +[2024-05-20 18:30:16] [STREAM] Stream finished. Tx Bytes: 242449 |
| 103 | +``` |
| 104 | + |
| 105 | +### Authors |
| 106 | + |
| 107 | +Iván Moro Cienfuegos, David Martín Sebastián, Eric Soto San José y Héctor |
0 commit comments