From 9a07f75bdfb740f684410b523e55de661552f664 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Mon, 28 Sep 2026 04:05:07 +0200 Subject: [PATCH] Refuse a bind the server cannot record as it refuses one authenticate turns down --- MIGRATION.md | 5 ++--- src/server.ts | 23 ++++++++++------------- src/session-options.ts | 6 ++---- 3 files changed, 14 insertions(+), 20 deletions(-) diff --git a/MIGRATION.md b/MIGRATION.md index a3a4579..256297a 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -36,9 +36,8 @@ shape is the same, connect, send, listen for delivery reports, with callbacks re Write `alert_on_message_delivery` and `broadcast_area_identifier`, the names they read back under, for `alert_on_msg_delivery` and `failed_broadcast_area_identifier`, which are gone from `tlvs` too. -- **`session.loggedIn` is gone**: read `session.boundAs !== undefined`. `boundAs` and - `peerInterfaceVersion` are read-only; a session you construct yourself records a bind with - `session.bound()`. +- **`session.loggedIn` is gone**: read `session.boundAs !== undefined`. A session you construct + yourself records a bind with `session.bound()`. - **The `error` event is `sessionError`**, and `serverError` on the server handle. - **`log`** takes any object with `debug`, `error`, `info`, `verbose` and `warn` methods instead of a `larvitutils` one, and is silent by default: [README](README.md#logging). diff --git a/src/server.ts b/src/server.ts index c069187..2b9aefe 100644 --- a/src/server.ts +++ b/src/server.ts @@ -170,18 +170,6 @@ function bindRespTlvs(session: Session, options: ServerOptions): TlvInputs | und }; } -async function acceptBind( - session: Session, - pduObj: PduObject, - bindType: BindType, - options: ServerOptions, - identity: Record, -): Promise { - const recorded = session.bound(bindType, pduObj.params.interface_version); - - await session.sendReturn(pduObj, recorded.err ? 'ESME_RBINDFAIL' : 'ESME_ROK', identity, bindRespTlvs(session, options)); -} - async function onBind( session: Session, pduObj: PduObject, @@ -198,7 +186,16 @@ async function onBind( return; } - await acceptBind(session, pduObj, bindType, options, identity); + const recorded = session.bound(bindType, pduObj.params.interface_version); + + if (recorded.err) { + session.log.info('server - bind refused', { message: recorded.err.message, systemId }); + await session.sendReturn(pduObj, 'ESME_RBINDFAIL', identity); + + return; + } + + await session.sendReturn(pduObj, 'ESME_ROK', identity, bindRespTlvs(session, options)); session.log.verbose('server - bound', { systemId }); } diff --git a/src/session-options.ts b/src/session-options.ts index dfb3325..15d8405 100644 --- a/src/session-options.ts +++ b/src/session-options.ts @@ -123,16 +123,14 @@ export const undeclaredInterfaceVersion = 0x00; export type SessionBind = { as: BindType; peerVersion: number }; -const bindTypes: readonly string[] = ['receiver', 'transceiver', 'transmitter']; - function isBindType(value: unknown): value is BindType { - return typeof value === 'string' && bindTypes.includes(value); + return typeof value === 'string' && bindTypeFromCommand(`bind_${value}`) !== undefined; } /** A bind as `Session.bound()` records it: undefined declares no version, which is pre-3.4. */ export function checkedBind(bindType: unknown, declaredVersion: unknown): Result<{ bind: SessionBind }> { if (!isBindType(bindType)) { - return { err: new Error(`bindType must be ${bindTypes.join(', ')}, got ${namedValue(bindType)}`) }; + return { err: new Error(`bindType must be receiver, transceiver or transmitter, got ${namedValue(bindType)}`) }; } if (declaredVersion === undefined) return { bind: { as: bindType, peerVersion: undeclaredInterfaceVersion } };