How the encryption works
How Cross Copy Paste's end-to-end encryption works, for anyone writing or checking a client. There are two kinds of server:
- Cross Copy Paste Cloud, which we run: accounts with an email address and a password or a passkey, on the free or the premium plan.
- Self-hosted, which you run: no accounts, one owner secret.
Both use the same encryption and the same device API; they differ in how you sign in and in their limits. Neither ever sees a password, the secret, the content key or a clip in the clear.
Binary values are written as unpadded base64url (RFC 4648 §5) everywhere: in JSON, in setup codes and in links. Readers should also accept padding.
Labels starting ccopy v1 belong to formats unchanged since version 1 (clips
and setup codes); ccopy v2 labels belong to version 2's sign-in and key
wrapping.
Which kind of server
GET /api/status → {"mode", "setUp", "signedIn", "version"}, where mode is
"cloud" or "self-hosted". The Cloud adds what its plans give, "free" and
"premium" (each {"clipBytes", "devices"}), and Premium's "price", which
the apps' welcome and the Upgrade dialog show, and "passkeys" (whether
passkeys are on). Once signed in, it also says "email" and
"passwordChanged" (when). The apps use the Cloud unless you choose Self-hosted and give your
server's address.
Keys at a glance
Every account (and every self-hosted server, which is one account) has a random content key that encrypts clips. The server keeps it only wrapped: encrypted with a key that comes from what you know.
password ──Argon2id──┐
├─▶ unlock key ──HKDF "ccopy v2 login"──▶ sign-in key (Ed25519; the server keeps the public key)
secret (self-hosted)─┘ └─HKDF "ccopy v2 wrap"───▶ wrap key ──▶ wrapped content key (the server keeps it)
passkey's PRF output ──HKDF "ccopy v2 passkey"──▶ passkey wrap key ──▶ that passkey's wrapped content key
The unlock key
Cloud: from the password
Argon2id(password, salt, m, t, p) (RFC 9106), 32 bytes of output:
- The password is UTF-8 in Unicode NFC, so it gives the same key whichever keyboard typed it. Clients ask for at least 10 characters, with an uppercase letter, a lowercase letter and a number (symbols are allowed, not required). The server can't check: it never sees the password.
- The salt and parameters belong to the account, and the client makes them
when the account is created: 16 random bytes of salt,
m= 65536 (KiB, so 64 MiB),t= 3,p= 4. - Bounds. Clients refuse parameters below those, or above
m= 1048576,t= 10 orp= 16, so a server can't make them weaken the key or stall.
Self-hosted: the secret
The secret is the unlock key: 15 random bytes (120 bits, already too many to guess, so it isn't stretched). The browser makes it at setup and shows it as 24 Crockford base32 characters in six groups of four:
000G-40R4-0M30-E209-185G-R38E
Alphabet 0123456789ABCDEFGHJKMNPQRSTVWXYZ, most significant bit first, no
padding (120 bits are exactly 24 characters). When reading one, ignore case,
spaces and dashes, and treat O as 0 and I, L as 1.
Sign-in key and wrap key
Both come from HKDF-SHA256 (RFC 5869) with the unlock key as input key
material, salt CrossCopyPaste (UTF-8) and 32 bytes of output:
| Key | HKDF info | Used as |
|---|---|---|
| Sign-in key | ccopy v2 login |
Ed25519 private key seed (RFC 8032). The server keeps its public key. |
| Wrap key | ccopy v2 wrap |
AES-256-GCM key that wraps the content key. |
Web Crypto can't import a raw Ed25519 seed; wrap it in PKCS #8 by prefixing
the 16 bytes 302e020100300506032b657004220420.
The content key
32 random bytes, made by the client when the account is created (or the self-hosted server is set up). Only you and your devices have it. Wrapped, it's 60 bytes:
IV (12 random bytes) ‖ AES-256-GCM(wrap key, IV, content key, AAD = UTF-8 "ccopy v2 wrap")
| When | Content key | Devices |
|---|---|---|
| Changing the password | Kept, wrapped again with the new wrap key | Keep working |
| Forgot password (Cloud) | New | All removed, with every session and passkey |
| Changing the secret (self-hosted) | New | All removed, as before |
Passkeys (Cloud)
WebAuthn, with relying party ID crosscopypaste.com (so passkeys work on all
of its subdomains), user verification required and a discoverable credential,
so signing in needs no email address. The user handle is the account's ID.
Attestation isn't asked for: the server checks a passkey's signatures, not
what made it. It accepts EdDSA, ES256 and RS256 keys.
So that a passkey alone can unlock the content key, clients ask for the
PRF extension with eval.first = the UTF-8 bytes ccopy v2 passkey. The
32-byte result goes through HKDF-SHA256 (salt CrossCopyPaste, info
ccopy v2 passkey) to make that passkey's wrap key, which wraps the content key
exactly as above. The server keeps one wrapped key per passkey.
- The PRF output never leaves the device. Clients send a passkey's answer
in WebAuthn's JSON form (
RegistrationResponseJSON,AuthenticationResponseJSON) withoutclientExtensionResults. The server refuses an answer that carries PRF results. - Some authenticators only give PRF results when signing. If creating the
passkey says
prf.enabledbut has no results, the client asks the new passkey once more (navigator.credentials.getwith its own random challenge, which the server never sees) before sending it. - A passkey without PRF still signs in. The answer then has no
passkeyWrappedKey, and the client asks for the password once to unwrap the content key (the answer has the KDF and the password's wrapped key, so this needs no second sign-in).
Signing in
The same in both modes: prove you hold the sign-in key by signing a challenge.
POST /api/login/startwith{"email"}(no body when self-hosted) →{"challenge", "kdf"}. Challenges work once, for two minutes.- Cloud:
"kdf": {"type": "argon2id", "salt", "m", "t", "p"}. For an unknown address the server answers the same way, with a salt made from the address (HMAC-SHA256(server key, address), first 16 bytes), so nobody can find out who has an account. - Self-hosted:
"kdf": {"type": "secret"}.
- Cloud:
- Sign the UTF-8 bytes of
ccopy v2 login:followed by the challenge with the sign-in key. POST /api/loginwith{"challenge", "signature"}→{"wrappedKey"}and a session cookie (HttpOnly,Secure,SameSite=Strict). A wrong password or an unknown address both get401"Wrong email or password".
Apps sign in as a device. They add "device": {"name"} in step 3. The
server then adds the device (within the plan's limit) and answers
201 {"id", "name", "token", "wrappedKey"} instead of setting a cookie. The
app unwraps the content key and keeps it with the token, exactly as if it had
used a setup code; it doesn't keep the password or a session.
With a passkey: POST /api/passkey/login/start →
{"publicKey": <PublicKeyCredentialRequestOptions>} (no
allowCredentials: any of the site's passkeys), then
POST /api/passkey/login with {"credential", "device"?}. The answer is the
same as above (a cookie, or a device), plus "email", "kdf" and, if the
passkey can unlock, "passkeyWrappedKey". A passkey the server doesn't know
(removed, or its account deleted) gets 401.
Too many attempts get 429 with Retry-After.
Accounts (Cloud)
Email codes are 6 digits, work for 15 minutes and allow 5 tries.
- Create:
POST /api/signupwith{"email"}→202, always. The email has a code, or says the address already has an account.- The client makes the salt and the content key, derives the keys, and sends
POST /api/signup/finishwith{"email", "code", "kdf", "publicKey", "wrappedKey", "device"?}. The answer is the same as signing in.
- Forgot password:
POST /api/resetwith{"email"}→202, always.POST /api/reset/finishwith{"email", "code", "kdf", "publicKey", "wrappedKey", "device"?}, made like a new account. Everything encrypted with the old content key is lost (only the waiting clip), and devices, sessions and passkeys are removed. The answer is the same as signing in, and an email says the password was reset.
- Change password (signed in):
POST /api/account/passwordwith a fresh{"challenge", "signature"}from the current sign-in key (or a passkey's, below), plus the new{"kdf", "publicKey", "wrappedKey"}. Devices and sessions carry on, and an email says the password was changed (and from which app, byX-Ccopy-App). A wrong current password gets403"wrong password" (not401: the session is still good). - Passkeys (signed in):
- Add:
POST /api/passkeys/startwith a fresh proof, like changing the password ({"challenge", "signature"}or{"passkey"}), since a passkey can sign in and unlock →{"publicKey": <PublicKeyCredentialCreationOptions>}, thenPOST /api/passkeyswith{"credential", "wrappedKey"?}(the content key wrapped with the passkey's PRF key) →201 {"passkey"}. The server names it after where it's kept, from its AAGUID ("iCloud Keychain", "Google Password Manager", "Windows Hello"…), or "Security key", or "Passkey on" the system, and emails the account that a passkey was added. - List:
GET /api/passkeys→{"passkeys": [{"id", "name", "credentialId", "unlocks", "created", "lastUsed"?}], "rpId", "userId", "now"}.rpId,userIdand the credential IDs are forPublicKeyCredential.signalAllAcceptedCredentials, so password managers can tidy away removed ones. - Remove:
DELETE /api/passkeys/{id}. - Confirm with one: changing the password and deleting the account take
{"passkey": <answer>}instead of{"challenge", "signature"}, fromPOST /api/passkey/confirm/start→{"publicKey": ...}(the account's passkeys only).
- Add:
- Delete the account (signed in):
DELETE /api/accountwith a fresh{"challenge", "signature"}(or a passkey's answer); a wrong password gets403, as above.
For each account the server keeps the email address, the KDF salt and parameters, the sign-in public key and the wrapped content key; for each passkey, its credential ID, public key and wrapped content key; for each device, its name and a hash of its token; and the account's purchases.
Self-hosted: first run and the secret
The browser sends the public sign-in key, the wrapped content key and the
8-digit setup code from the server's log: POST /api/setup with
{"code", "publicKey", "wrappedKey"}. Changing the secret (POST /api/secret)
needs a fresh {"challenge", "signature"} from the current sign-in key, plus
the new publicKey and wrappedKey, and removes every device.
Plans and limits
GET /device and, once signed in, GET /api/status include:
"plan": "free", "limits": { "clipBytes": 32768, "devices": 3 }
| Plan | clipBytes |
devices |
|---|---|---|
free (Cloud) |
16384 (16 KiB) | 3 |
premium (Cloud) |
1048576 (1 MiB) | 24 |
self-hosted |
CCOPY_MAX_BYTES (1 MiB unless set) |
CCOPY_MAX_DEVICES (24 unless set; absent if 0, no limit) |
These are defaults. The Cloud's are settings its admins can change at any
time, and a self-hosted server's owner can set its own. So clients never
build them in; they use the limits the server sends.
- Clip size is the plaintext's size: the data's length minus its 16-byte
tag. A bigger clip gets
413with{"error", "limit"}. Apps check before sending and say what the limit is. - Devices: adding one past the limit gets
403with{"error", "plan", "limit"}: signing in as a device, claiming a setup code, or making one. A browser signed in to the web UI isn't a device. Devices over the limit after a refund keep working; no more can be added. When an app signs in as a device with the right password, the403also lists the account's"devices"(asGET /api/devicesdoes), so it can show which ones fill the plan.
Clips
AES-256-GCM with the content key, a fresh random 12-byte IV for every clip,
and the UTF-8 bytes ccopy v1 clip as additional authenticated data. The
plaintext is the clip's text in UTF-8. On the wire:
{ "iv": "<12 bytes>", "data": "<ciphertext with its 16-byte tag at the end>", "chars": 87 }
chars is the text's length in Unicode code points. It's optional and only
used for the device list ("↗ 87 characters").
A device sends with PUT /clip and receives with GET /clip (204 when
nothing is waiting). The server adds from (the sender's current name, or
Web browser), fromId, fromApp (the sender's X-Ccopy-App, absent for the
web UI), age (seconds since it was sent) and expiresIn (seconds left;
absent if clips don't expire). A clip that fails to decrypt was sent with a
different content key: tell the person, don't show garbage.
Devices
Each device has its own token: 32 random bytes from the server, stored there
only as a SHA-256 hash. It goes in Authorization: Bearer <token>. Devices
should also send X-Ccopy-App: <app>/<version> (android, ios, windows,
linux or macos), which the web UI shows. GET /device returns
{"id", "name", "via", "plan", "limits"}, so an app can show its name and pick
up a rename; on the Cloud it adds the account's "email", its
"deviceCount" and what "premium" gives. PATCH /device (or POST) with {"name"} renames it and
returns the same.
DELETE /device removes the device itself: an app signing out of the Cloud,
which frees its place on the plan. On the Cloud, DELETE /device/account with
a fresh {"challenge", "signature"} (from POST /api/login/start) deletes the
whole account from an app, which has no session; a wrong password gets 403.
via says how the device reaches the server: "local" when the address it
used (the request's Host) is one in a self-hosted server's own certificate
(CCOPY_HOSTS, plus localhost), so it connects directly on the home network
or a VPN; "web" for any other address, such as a Cloudflare Tunnel's. The
Cloud leaves it out: every device reaches it the same way. The apps show it as
a badge on their device icon, and the web UI's device list shows it for every
device (with the address, from the device's last request).
A setup code carries a one-time setup token, not the device's own. The
device's first request is POST /device/claim with the setup token as its
bearer token; the answer, {"id", "name", "token"}, holds the device's own
token, which it keeps from then on. As soon as the device uses its own token,
the setup token stops working, so a setup code left in a clipboard history or
a screenshot opens nothing. If the answer to a claim gets lost, claiming again
works (and replaces the token from before) until then. A setup code that isn't
used within 10 minutes lapses. A revoked device gets 401 on everything.
GET /clip?peek=1 returns the clip without counting it as received, for
status displays.
Setup codes
The web UI gives a new device everything it needs in one code, on the Cloud and self-hosted alike. It's made in the browser, because it contains the content key, and never sent to the server:
ccopy1-<base64url of the UTF-8 JSON below>
{"v":1,"u":"https://clips.example.com","t":"<token>","k":"<content key>","n":"Work laptop","e":1796000000}
| Field | |
|---|---|
v |
Version, 1. |
u |
The server's address: https:// and a host (and port), nothing else. |
t |
The device's setup token, swapped for its own on first use. |
k |
The content key, 32 bytes. |
n |
The device's name. |
e |
When the setup token lapses if unused, in Unix seconds. |
Phones get it as a QR code of https://<server>/join#<code>. The browser never
sends the part after #, and the join page hands the code to the app as
ccopy://setup#<code>. Computers paste the code into the app (or ccopy setup).
Purchases (Cloud)
Premium is one product, com.crosscopypaste.premium: a one-time purchase that
makes the account premium for good. It belongs to the account, not to a store,
so it shows on every device signed in to that account. A refund takes the
account back to free.
| Bought | How the server learns of it |
|---|---|
On the web (Windows, ccopy and the web UI open this) |
The web UI's Upgrade page opens the payment provider's checkout with the account's ID. The provider's signed webhook records the purchase, and later any refund. (The provider isn't chosen yet.) |
| App Store (iPhone and Mac: one purchase for both) | StoreKit 2, with the account's ID as appAccountToken. The app sends the signed transaction to POST /api/purchases/apple with {"transaction"}. The server checks Apple's signature chain, the bundle and product IDs and the account ID. App Store Server Notifications report refunds. |
| Google Play | Play Billing, with the account's ID as obfuscatedAccountId. The app sends POST /api/purchases/google with {"purchaseToken"}. The server checks it with the Play Developer API and acknowledges it; voided purchases are checked daily. |
Promo codes
A promo code takes a percentage off Premium. Each works once, for one
account, and may have an end date; the server keeps which account used it,
and when. Codes look like CCOPY-7K4M-Q2XP-9DHT: twelve letters and digits
without 0, O, 1, I and L. Any case works, with or without the dashes and the
CCOPY.
- Check one:
POST /api/promowith{"code"}→{"code", "percent", "price"}, the price with the code ("$0"at 100%;""if the server can't work it out). It doesn't use the code. - Get Premium:
POST /api/premiumwith{"code"}→{"plan", "limits"}, without any payment, if the code covers the whole price. One for less answers402until paying opens.
Both need to be signed in on the web. 404: the code isn't right, or was used
or has expired. 409: the account has Premium already (the code isn't used up).
429: too many tries.
Restoring a purchase on a new device needs nothing: signing in is enough. The iPhone and Mac apps also send their current entitlement again when you choose Restore Purchases.
Test vectors
Checked by server/internal/relay/protocol_test.go; each client checks the parts it uses.
Values are base64url unless marked hex.
Self-hosted
| Secret (hex) | 000102030405060708090a0b0c0d0e |
| Secret, as shown | 000G-40R4-0M30-E209-185G-R38E |
| Sign-in key seed (hex) | d9d03c2d6210decde938ddd327900333bc9049edc159be43e929763084a512d0 |
| Sign-in public key | cfgtw4MdXYDh4yXq11_wsHT1djeonaB7x0tHXef80Rg |
Signature of ccopy v2 login:test-challenge |
I6jOGwe6hP3-MMrrSb-bFb3z7d2ijI5gCgApey2wOGLnhZO8s4iP63TdVs-jl-2Hmf2-XKAJ5DMWDIiaRpW5CQ |
| Wrap key (hex) | 3574febf2a1cace9f7e6ae6b71ed58a64478de1072b6589a9ac86f0698759535 |
| Wrapped content key | AAECAwQFBgcICQoL4x1L8IdFce-Vt-YInNICE46gw3KzvCY_2Nn_4K49wqyUi66idaiicix9Wsv4qai0 |
Cloud
| Password | correct horse battery stäple (ä as U+00E4; typed as a + U+0308, it must give the same unlock key after NFC) |
| Salt (hex) | 101112131415161718191a1b1c1d1e1f, with m = 65536, t = 3, p = 4 |
| Unlock key (hex) | 0b1731ad9c7707b67cc98b17986267c8f67f415ba39e04b4610ce1cc7713f2f0 |
| Sign-in key seed (hex) | f2f0004abb5ef0a97d85c1438ecc3db4fb301023ab090ba10f0ebd940290dcd7 |
| Sign-in public key | 3UKv9tER1PLiDcjZRRzsQKh0TPPlLaVfWB7_olja9xY |
Signature of ccopy v2 login:test-challenge |
qk3yyxih2QtS_dNLU_zXgM23V5s1ocpSGCjzkpgautOjI29pqKDr-6wUtyHjLjBmqOCPTk7v9Dhl4JRX8fqFBw |
| Wrap key (hex) | 2cc0a8282b7cb7a9dbd0493900e80fcca8a7710b9042f68765348f7443a58cc4 |
| Wrapped content key | AAECAwQFBgcICQoL8iRzEmdGPo5suvqNZhih34FlzHEVYsKO2webUvSpkOJbg_Af-9EiuvDWAgyGtEDY |
Passkey
| PRF output (hex) | 404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f |
| Passkey wrap key (hex) | b07aace778cb44012bb2a93c94b3f9cbb1bf732bde227af19841e03e8a029ad4 |
| Wrapped content key | AAECAwQFBgcICQoLgTBHnuIyMAqqObX804zHxd9UYrmhBySz7wDKUHwKDkNROifiglfECAubR92mZRIg |
Content key and a clip (every wrapped key above uses IV AAECAwQFBgcICQoL)
| Content key | 39o4sOB1mM0Z42D3W8rhMJxHc5YI6ZLUw0_mg_OcgVA |
| Clip text | Hello, 世界 👋 (11 characters) |
| IV | AAECAwQFBgcICQoL |
| Data | WeCzm3KL6ov-kAiKK2slOmgyniQACCDvJXfkxio2yWov9A |