clipdrop

module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 26, 2026 License: Apache-2.0

README

Clipdrop

Zero-cloud, end-to-end encrypted, peer-to-peer clipboard and screenshot synchronization between macOS and Windows over local Wi-Fi.


Tech Stack & Core Libraries

Release v1.0.0 Production Ready Go macOS Windows mTLS 1.3 PAKE mDNS Zeroconf slog


Highlights

  • Zero Cloud & Zero Telemetry: Direct P2P transfer over local subnet; no accounts, no relays, no third parties.
  • Mutual TLS 1.3 & Pinned Fingerprints: Custom CA-less trust model. Unpaired peers are dropped at the TLS handshake.
  • PAKE Out-of-Band Pairing: 2-minute time-limited pairing code using Password-Authenticated Key Exchange with AES-GCM credential exchange.
  • Smart Echo Loop Prevention: Content hashing (SHA-256) and receiver origin tracking guarantee zero ping-pong copy loops.
  • Screenshot-First Design: Instant PNG validation, size checks, and sub-2-second sync across platforms.

System Architecture

flowchart TB
    subgraph macOS["macOS (Darwin)"]
        subgraph MacPlatform["Platform Layer"]
            MacClip["Clipboard Watcher (cgo / Cocoa)"]
            MacStore["Config & Key Store (~/Library/.../clipdrop)"]
        end
        subgraph MacEngine["Core Engine"]
            MacDedupe["Dedupe & Echo Filter"]
            MacPolicy["Size / MIME / PNG Validator"]
        end
        subgraph MacNet["Networking & Discovery"]
            MacDiscovery["mDNS Browse & Announce"]
            MacServer["mTLS 1.3 Server (:47820)"]
            MacClient["mTLS 1.3 Client"]
        end
    end

    subgraph LocalNetwork["Local Wi-Fi Network"]
        MDNS["mDNS Multicast (_clipdrop._tcp)"]
        MTLS["Mutual TLS 1.3 Encrypted Channel"]
    end

    subgraph Windows["Windows (x86_64)"]
        subgraph WinNet["Networking & Discovery"]
            WinDiscovery["mDNS Browse & Announce"]
            WinServer["mTLS 1.3 Server (:47820)"]
            WinClient["mTLS 1.3 Client"]
        end
        subgraph WinEngine["Core Engine"]
            WinDedupe["Dedupe & Echo Filter"]
            WinPolicy["Size / MIME / PNG Validator"]
        end
        subgraph WinPlatform["Platform Layer"]
            WinClip["Clipboard Watcher (Win32 API)"]
            WinStore["Config & Key Store (%AppData%/clipdrop)"]
        end
    end

    MacClip --> MacDedupe
    MacDedupe --> MacPolicy
    MacPolicy --> MacClient
    MacClient --> MTLS
    MTLS --> WinServer
    WinServer --> WinPolicy
    WinPolicy --> WinDedupe
    WinDedupe --> WinClip

    WinClip --> WinDedupe
    WinDedupe --> WinPolicy
    WinPolicy --> WinClient
    WinClient --> MTLS
    MTLS --> MacServer
    MacServer --> MacPolicy
    MacPolicy --> MacDedupe
    MacDedupe --> MacClip

    MacDiscovery <--> MDNS
    WinDiscovery <--> MDNS

Pairing Protocol (PAKE + Credential Exchange)

Before normal synchronization begins, devices establish trust using a temporary pairing listener and Password-Authenticated Key Exchange (PAKE).

sequenceDiagram
    autonumber
    actor HostUser as Host (e.g. Mac)
    participant Host as Host Engine
    participant TempServer as Temp Pairing Listener
    participant Joiner as Joiner Engine
    actor JoinUser as Joiner (e.g. Windows)

    HostUser->>Host: clipdrop pair
    Host->>TempServer: Spawn ephemeral listener (2-min expiry)
    Host->>Host: Generate code (e.g. 4821-hawk-moon)
    Host-->>HostUser: Display pairing code
    Host->>Host: Broadcast mDNS "_clipdrop._tcp" (status=pairing)

    JoinUser->>Joiner: clipdrop pair join
    JoinUser->>Joiner: Enter code: 4821-hawk-moon
    Joiner->>Joiner: Discover Host via mDNS / --addr
    Joiner->>TempServer: Initiate PAKE handshake (over TLS)

    Note over Host,Joiner: schollz/pake v3 Key Exchange
    Joiner<<->>TempServer: Exchange PAKE Points (derived from pairing code)
    Host->>Host: Compute shared session key
    Joiner->>Joiner: Compute shared session key

    Note over Host,Joiner: Identity Exchange (AES-GCM encrypted via session key)
    Joiner->>TempServer: Encrypted payload (Cert Fingerprint, Name, OS)
    TempServer->>Joiner: Encrypted payload (Cert Fingerprint, Name, OS)

    Host->>Host: Save Joiner to trusted_devices.json (0600)
    Joiner->>Joiner: Save Host to trusted_devices.json (0600)
    Host->>TempServer: Shutdown ephemeral listener
    Host-->>HostUser: "Paired with Windows-Laptop"
    Joiner-->>JoinUser: "Paired with MacBook-Pro"

Sync Protocol & Echo Prevention

The sync engine follows an Offer / Upload sequence with strict hash recording to prevent infinite feedback loops.

sequenceDiagram
    autonumber
    participant SourceClip as Device A: Clipboard
    participant EngineA as Device A: Engine
    participant TransportA as Device A: Client
    participant TransportB as Device B: Server
    participant EngineB as Device B: Engine
    participant DestClip as Device B: Clipboard

    SourceClip->>EngineA: Clipboard change event
    EngineA->>EngineA: Read data & compute SHA-256 (HashX)
    EngineA->>EngineA: Check: HashX == LastReceivedHash? (Prevent Echo)

    EngineA->>TransportA: Transmit Offer
    TransportA->>TransportB: POST /v1/offer {id, kind, size, sha256, mime}

    EngineB->>EngineB: Check duplicate: HashX == CurrentLocalHash?
    alt Duplicate or Too Large
        TransportB-->>TransportA: 200 OK {"action": "skip", "reason": "duplicate"}
    else Ready to receive
        TransportB-->>TransportA: 200 OK {"action": "send"}
        TransportA->>TransportB: PUT /v1/items/{id} (Raw Bytes, Header: X-Sha256)
        TransportB->>EngineB: Verify payload size & SHA-256
        EngineB->>EngineB: Validate PNG header/dimensions (for images)
        EngineB->>EngineB: Record HashX as LastReceivedHash
        EngineB->>DestClip: Write content to OS Clipboard
        EngineB->>EngineB: Archive in received/ (keep newest 20)
        TransportB-->>TransportA: 200 OK {"status": "applied"}
    end

Engine State & Decision Machine

stateDiagram-v2
    [*] --> Idle

    Idle --> Detecting: Clipboard Event
    Detecting --> Inspecting: Read Content (Text / Image)

    Inspecting --> Suppressed: Hash equals LastReceivedHash (Echo)
    Inspecting --> Suppressed: Size exceeds limit (Image > 25MB, Text > 1MB)
    Inspecting --> Suppressed: Flag restricted (--images-only / --no-text)
    Suppressed --> Idle: Discard

    Inspecting --> ResolvingPeers: Valid New Content
    ResolvingPeers --> Idle: No peers online (Drop)

    ResolvingPeers --> Offering: Peer Found (mDNS / LastAddress)
    Offering --> Idle: Peer returned "skip"
    Offering --> Uploading: Peer returned "send"

    Uploading --> Idle: Transfer Complete & Confirmed

Security & Identity Architecture

flowchart LR
    subgraph Gen["Identity Initialization (First Run)"]
        GenKey["crypto/ecdsa: P-256 Keypair"]
        GenCert["crypto/x509: Self-Signed Cert"]
        GenFP["SHA-256 Cert Fingerprint = Device ID"]
        FileStore[("Config Dir (0600)\n- key.pem\n- cert.pem\n- trusted_devices.json")]

        GenKey --> GenCert --> GenFP --> FileStore
    end

    subgraph Handshake["mTLS 1.3 Connection Handshake"]
        ClientHello["Peer connects"]
        CertVerify{"Is Peer Cert Fingerprint\nin trusted_devices.json?"}
        Allow["Allow Handshake & Sync"]
        Drop["Reject & Terminate Connection"]

        ClientHello --> CertVerify
        CertVerify -- Yes --> Allow
        CertVerify -- No --> Drop
    end

Project Structure

flowchart TD
    Root["clipdrop/"]
    Cmd["cmd/clipdrop/ (Entry Point & CLI Dispatch)"]

    App["app/ (Component wiring & lifecycle)"]
    Config["config/ (Paths, defaults, env)"]
    Identity["identity/ (ECDSA keys, certs, fingerprint)"]
    Platform["platform/ (clipboard darwin/windows/fake, screenshots)"]
    Imaging["imaging/ (PNG validation & dimensions)"]
    Engine["engine/ (Event loops, dedupe, echo filter)"]
    Netx["netx/"]
    NetxDisc["discovery/ (mDNS zeroconf)"]
    NetxPair["pairing/ (PAKE listener & exchange)"]
    NetxTrans["transport/ (mTLS HTTP server & client)"]
    Store["store/ (trusted_devices.json, received/ retention)"]
    Doctor["doctor/ (Health, firewall, and permission diagnostics)"]
    Docs["docs/ (SPEC, protocol, troubleshooting)"]

    Root --> Cmd
    Root --> App
    Root --> Config
    Root --> Identity
    Root --> Platform
    Root --> Imaging
    Root --> Engine
    Root --> Netx
    Netx --> NetxDisc
    Netx --> NetxPair
    Netx --> NetxTrans
    Root --> Store
    Root --> Doctor
    Root --> Docs

Quickstart (7 Steps)

  1. Prerequisites: Install Go 1.22+ on both your Mac and Windows laptops and ensure both devices are on the same local Wi-Fi network (with Windows Wi-Fi profile set to Private).
  2. Build on macOS:
    git clone https://github.com/Rahul-8283/clipdrop.git && cd clipdrop
    make build
    
  3. Build on Windows (PowerShell):
    git clone https://github.com/Rahul-8283/clipdrop.git; cd clipdrop
    go build -o clipdrop.exe ./cmd/clipdrop
    
  4. Allow Windows Firewall & Private Wi-Fi (Windows Admin PowerShell): If Windows → Mac works but Mac → Windows is blocked, ensure your Wi-Fi profile is Private and allow clipdrop.exe on port 47820:
    Get-NetConnectionProfile | Set-NetConnectionProfile -NetworkCategory Private
    New-NetFirewallRule -DisplayName "Clipdrop" -Direction Inbound -Program "$PWD\clipdrop.exe" -Action Allow
    
  5. Pair Devices Once: Run ./clipdrop pair on your Mac to display a 2-minute pairing code, then run .\clipdrop.exe pair join on Windows and enter the code.
  6. Start Syncing: Run ./clipdrop run on Mac (add --watch-screenshots for Cmd+Shift+4 files, or --peer <windows-ip>:47820 if mDNS multicast is filtered on campus/office Wi-Fi) and .\clipdrop.exe run on Windows. Copy any text or screenshot (Cmd+Ctrl+Shift+4 / Win+Shift+S) and paste immediately on the other machine!
  7. Verify Anytime: Run ./clipdrop doctor (or .\clipdrop.exe doctor) to check permissions, firewall rules, port 47820, and peer reachability, and run go test -race ./... for the full test suite.

Documentation

  • System Specification — Architecture, mTLS 1.3 pinning, PAKE security invariants, and concurrency model.
  • Wire Protocol — REST endpoints (/v1/ping, /v1/offer, /v1/items/{id}), JSON schemas, and HTTP status codes.
  • Troubleshooting Runbook — Resolving Wi-Fi client isolation, Windows Firewall rules, and macOS permissions.

CLI Commands & Usage

Command Description
clipdrop pair Host side: Generate a single-use pairing code and open temporary pairing listener (2-min limit).
clipdrop pair join Joiner side: Input pairing code, discover host over mDNS, and complete PAKE trust exchange.
clipdrop run Start the sync daemon in the foreground. Clean exit with Ctrl+C.
clipdrop devices List all paired and trusted devices with fingerprint and last-seen timestamps.
clipdrop unpair <name> Revoke trust for a device and invalidate future mTLS connections.
clipdrop doctor Run diagnostics: port availability, permissions, identity files, mDNS multicast, peer pings.
clipdrop version Print current build version and protocol specification.
Common Flags for clipdrop run
  • --images-only : Disable text clipboard synchronization.
  • --no-text : Synonym for image-exclusive synchronization.
  • --port <number> : Custom mTLS listening port (default: 47820).
  • --peer <ip:port> : Manual fallback address if mDNS multicast is blocked on the network.
  • --watch-screenshots : Watch the macOS screenshot directory (Cmd+Shift+4 saved files) and auto-sync new captures.
  • --verbose : Enable detailed log/slog debug tracing.

License

This project is licensed under the MIT License.

Directories

Path Synopsis
Package app wires application components together and manages the process lifecycle including OS signal handling and graceful shutdown.
Package app wires application components together and manages the process lifecycle including OS signal handling and graceful shutdown.
cmd
clipdrop command
Package config provides runtime configuration, OS-compliant config directory management, and permission enforcement for Clipdrop.
Package config provides runtime configuration, OS-compliant config directory management, and permission enforcement for Clipdrop.
Package doctor provides operational health diagnostics, environment checks, and automated troubleshooting capabilities for Clipdrop.
Package doctor provides operational health diagnostics, environment checks, and automated troubleshooting capabilities for Clipdrop.
Package engine implements the local synchronization pipeline, content hashing, echo loop suppression, and deduplication policies.
Package engine implements the local synchronization pipeline, content hashing, echo loop suppression, and deduplication policies.
Package identity handles local cryptographic key generation, self-signed X.509 certificate creation, device fingerprinting, and secure persistence.
Package identity handles local cryptographic key generation, self-signed X.509 certificate creation, device fingerprinting, and secure persistence.
Package imaging provides high-performance validation and dimension inspection for raw image byte streams without full raster decoding.
Package imaging provides high-performance validation and dimension inspection for raw image byte streams without full raster decoding.
netx
pairing
Package pairing implements out-of-band device pairing using human-readable phonetic codes, PAKE cryptographic key agreement, and encrypted credential exchange.
Package pairing implements out-of-band device pairing using human-readable phonetic codes, PAKE cryptographic key agreement, and encrypted credential exchange.
transport
Package transport defines the peer-to-peer communication protocol, cryptographic mTLS configuration, and network transfer primitives.
Package transport defines the peer-to-peer communication protocol, cryptographic mTLS configuration, and network transfer primitives.
platform
clipboard
Package clipboard defines the platform-agnostic clipboard abstraction, content types, and standard errors for Clipdrop.
Package clipboard defines the platform-agnostic clipboard abstraction, content types, and standard errors for Clipdrop.
Package store manages trusted peer device records and provides atomic, thread-safe persistence for the trusted_devices.json state file.
Package store manages trusted peer device records and provides atomic, thread-safe persistence for the trusted_devices.json state file.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL