Security and the handshake
How a retailer and your app trust each other, from the retailer's consent at install to the goodbye at uninstall. Every step below is what iVendNext and the kit's template do today; where a step does not reach yet, the page says so.
The path, step by step
- The retailer consents at install. Before anything installs, the retailer's administrator reads What it will do, written by iVendNext from your app itself, and ticks the box. The site refuses an install whose consent does not match what is being installed, and a new version asks again. The install adds any role your manifest names that the site lacks and makes a secret of its own for each till key.
- Your app gets its own user. An app with an event feed gets its own user from its install, with one narrow role; the site makes its key at the first connect for a hosted app. An app with no feed gets one integration user, with one narrow role, that the retailer's administrator makes (or chooses), and the administrator makes its key. For a fiscal reader your manifest declares, the install makes the user, without a key. Your service reads and writes only through the API, as that user, and sees only what the role allows. It never connects to the retailer's database. (The event feed recipe and the integration user recipe.)
- The retailer's site connects to your app. When a retailer installs a hosted app from the App library, from its public list or its Made for you shelf, its site sends your app its App library key, its own address, the secrets the install made and your app's user's key (for an app with an event feed, the user the install made; for one without, once the administrator has made it). Your app checks that the key was signed by iVendNext, for your app and for that site, and then keeps the retailer's secrets. This call is not signed: the key is its credential.
- Every press is signed. When a cashier presses your till key, the retailer's site signs the call with that key's secret and, to an app hosted with us, names itself in a header.
- Your app checks the signature before it reads the call. It refuses a call more than five minutes old, a call signed with another retailer's secret and a retailer it does not know, each with
401. The template does all of this (below). - Your app answers within the time. A till key has 3 seconds unless raised: up to 5 from your manifest, 10 at most on the record the retailer's System Manager keeps.
- Your app calls iVendNext back at the retailer's own address, never at an address a call names, with its user's key.
- At uninstall the site says goodbye to a hosted app it connected, from the public list or a Made for you shelf, and your app forgets the retailer and its secrets. A shelf app the site could not connect (it holds no key of its own for that site) is not told: disconnect that retailer yourself. Before it removes anything, the site saves your app's records to a private file of the retailer's; then it removes the records, fields, roles and keys the install added.
Where the connect does not reach. The site connects by itself only to an app hosted at an *.ivendnext.app address and installed from the App library: its public list, or a customer's Made for you shelf, which carries your app's own key for that customer's sites each time you publish that app to it. An app on your own server is connected by hand: you put the retailer's secret in your app's settings, and run the template for that one retailer.
The check, as the template does it
Every call is checked against the raw body before anything reads it. This is the template's own function, tools/app_template/service/app.py, unchanged:
def verified(secrets: list, headers, raw: bytes) -> bool:
ts, sig = headers.get("X-iVendNext-Timestamp") or "", headers.get("X-iVendNext-Signature") or ""
if not (ts.isascii() and ts.isdigit() and len(ts) <= 12) or abs(time.time() - int(ts)) > SKEW_S: # "²" is a digit int() refuses; a long string is never parsed
return False
for secret in secrets:
want = base64.b64encode(hmac.new(secret, ts.encode() + b"." + raw, hashlib.sha256).digest())
if hmac.compare_digest(want, sig.encode()):
return True
return False
secretsis the one retailer's secret, or, when your app serves many retailers, the secret of the retailer the call names inX-iVendNext-Site. A retailer your app does not know has no secret, so its call fails.SKEW_Sis 300 seconds. Keep your server's clock right.- The key check at connect is
check_keyintools/app_template/service/shops.py: the key's signature, its app and its site.
Write your app on the template and keep this check. A retailer's site checks only that your app is at a public HTTPS address; then it checks the answer, its time and its shape.
Rotating a secret
- A retailer's secret for your app. When the retailer's administrator changes a key's secret and presses Connect again, or reinstalls your app, the site sends your app the new secrets. Your app keeps the previous ones until the next connect, so nothing breaks while the retailer moves over. To stop a leaked secret working, the retailer connects twice.
- One retailer, run by hand. Set the new secret in the retailer's iVendNext, then set the old one as
IVN_POINT_SECRET_PREVIOUSand the new one asIVN_POINT_SECRETin your app. Both are accepted. Remove the old one after a day. - Your app's own user. The retailer's administrator presses Generate Keys again on the user (the app's own user too), and the old secret is refused at once. For a hosted app, the administrator then presses Connect again and the site sends your app the new key.
- On CitiXsys hosting, a container's own secrets are kept in our secret store, never in a file: send us the new one when you rotate. A function keeps no secret of its own; each retailer's arrive with its connect.
When your app is down
The retailer keeps selling. The cashier reads one of these, and nothing is added to the sale:
- "⟨key⟩ did not answer in time. Nothing was added to the sale." (slow)
- "⟨key⟩ could not finish. Nothing was added to the sale." (down, an error, or a bad signature)
Your reconciliation pull catches up on what happened while you were down. The till key page lists every message the cashier can read.
What a retailer can check
Each app's card in the App library says where the app sends data, whether an outside service reads and writes through its own user, and how many Desk users it needs. The retailer's administrator sees each connected app under Connected apps, with Hosted by CitiXsys beside an app we host. For the retailer's side of this story, see the library's trust page and how apps run.
See also
Host with CitiXsys or run your own · API reference · Publish your app · Reporting a security problem