{"record":{"id":"50db919fa589e641","repo":"jumpserver/jumpserver","slug":"sp-id-is-6-bits","errorCode":null,"errorMessage":"sp_id is 6 bits","messagePattern":"sp_id is 6 bits","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"apps/common/sdk/sms/cmpp2.py","lineNumber":44,"sourceCode":"    def __init__(self):\n        self.command_id = ''\n        self.body = b''\n        self.length = 0\n\n    def get_header(self, sequence_id):\n        length = struct.pack('!L', 12 + self.length)\n        command_id = struct.pack('!L', self.command_id)\n        sequence_id = struct.pack('!L', sequence_id)\n        return length + command_id + sequence_id\n\n    def get_message(self, sequence_id):\n        return self.get_header(sequence_id) + self.body\n\n\nclass CMPPConnectRequestInstance(CMPPBaseRequestInstance):\n    def __init__(self, sp_id, sp_secret):\n        if len(sp_id) != 6:\n            raise ValueError(_(\"sp_id is 6 bits\"))\n\n        super().__init__()\n\n        source_addr = sp_id.encode('utf-8')\n        sp_secret = sp_secret.encode('utf-8')\n        version = struct.pack('!B', 0x02)\n        timestamp = struct.pack('!L', int(self.get_now()))\n        authenticator_source = source_addr + 9 * b'\\x00' + sp_secret + self.get_now().encode('utf-8')\n        auth_source_md5 = hashlib.md5(authenticator_source).digest()\n        self.body = source_addr + auth_source_md5 + version + timestamp\n        self.length = len(self.body)\n        self.command_id = CMPP_CONNECT\n\n    @staticmethod\n    def get_now():\n        return time.strftime('%m%d%H%M%S', time.localtime(time.time()))\n\n","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/jumpserver/jumpserver/blob/6ec464fabd61b95912d539455a3a5f15f5c59fe0/apps/common/sdk/sms/cmpp2.py#L26-L62","documentation":"ValueError('sp_id is 6 bits') raised in CMPPConnectRequestInstance.__init__ when the SP identifier provided to the CMPP2.0 SMS gateway is not exactly 6 characters, because the CMPP 2.0 protocol encodes source_addr as a fixed 6-byte field.","triggerScenarios":"Constructing a CMPPClient (or CMPP2SMS during send) with an sp_id shorter or longer than 6 characters, e.g. a 5-char test ID or one with trailing whitespace included in length.","commonSituations":"ISP-provided SP ID entered with whitespace/newline from config files; wrong credential field mapped (using src_id or enterprise code instead of the 6-digit SP ID); typo when transcribing from the ISP's onboarding document.","solutions":["Set sp_id to exactly the 6-character SP identifier issued by your CMPP gateway provider","Strip whitespace: sp_id = sp_id.strip() before passing it","Double-check you are using sp_id, not src_id or service_id, for this field"],"exampleFix":"# before\nclient = CMPP2SMS(**{'SP_ID': '12345 '})  # 6 chars incl. space? verify\n\n# after\nsp_id = settings.CMPP2_SP_ID.strip()\nassert len(sp_id) == 6, 'SP ID must be exactly 6 characters'","handlingStrategy":"validation","validationCode":"sp_id = settings.CMPP2_SP_ID.strip()\nif len(sp_id) != 6:\n    raise ValueError(f'sp_id must be 6 chars, got {len(sp_id)}')","typeGuard":"def is_valid_sp_id(sp_id: str) -> bool:\n    return isinstance(sp_id, str) and len(sp_id.strip()) == 6","tryCatchPattern":null,"preventionTips":["Strip config values at load time","Document the 6-char constraint next to the CMPP2_SP_ID setting","Fail fast at startup on invalid config, not at send time"],"tags":["cmpp","sms-gateway","config-validation","protocol"],"backgroundTag":"cmpp-config-validation","analyzedSha":"6ec464fabd61b95912d539455a3a5f15f5c59fe0","analyzedAt":"2026-08-28T11:33:00.925Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}