Connect to a Remote, loading metadata and optionally acquiring a token. .. note:: If no username or token are provided, they will be looked up from the keychain, \ likely saved there by Enterprise authentication. :param username: Optional username to connect with :param token: Optional
(self, username: Optional[str] = None, token: Optional[str] = None)
| 230 | return core.BNRemoteRequestAuthenticationToken(self._handle, username, password) |
| 231 | |
| 232 | def connect(self, username: Optional[str] = None, token: Optional[str] = None): |
| 233 | """ |
| 234 | Connect to a Remote, loading metadata and optionally acquiring a token. |
| 235 | |
| 236 | .. note:: If no username or token are provided, they will be looked up from the keychain, \ |
| 237 | likely saved there by Enterprise authentication. |
| 238 | |
| 239 | :param username: Optional username to connect with |
| 240 | :param token: Optional token to authenticate with |
| 241 | :raises RuntimeError: If the connection fails |
| 242 | """ |
| 243 | if not self.has_loaded_metadata: |
| 244 | self.load_metadata() |
| 245 | got_auth = False |
| 246 | if username is not None and token is not None: |
| 247 | got_auth = True |
| 248 | if not got_auth: |
| 249 | # Try logging in with defaults |
| 250 | if self.is_enterprise and enterprise.is_authenticated(): |
| 251 | username = enterprise.username() |
| 252 | token = enterprise.token() |
| 253 | if username is not None and token is not None: |
| 254 | got_auth = True |
| 255 | |
| 256 | if not got_auth: |
| 257 | # Try to load from default secrets provider |
| 258 | secrets = binaryninja.SecretsProvider[ |
| 259 | binaryninja.Settings().get_string("enterprise.secretsProvider")] |
| 260 | if secrets.has_data(self.address): |
| 261 | creds = json.loads(secrets.get_data(self.address)) |
| 262 | username = creds['username'] |
| 263 | token = creds['token'] |
| 264 | got_auth = True |
| 265 | |
| 266 | if not got_auth: |
| 267 | # Try logging in with creds in the env |
| 268 | if os.environ.get('BN_ENTERPRISE_USERNAME') is not None and \ |
| 269 | os.environ.get('BN_ENTERPRISE_PASSWORD') is not None: |
| 270 | token = self.request_authentication_token(os.environ['BN_ENTERPRISE_USERNAME'], os.environ['BN_ENTERPRISE_PASSWORD']) |
| 271 | if token is not None: |
| 272 | username = os.environ['BN_ENTERPRISE_USERNAME'] |
| 273 | got_auth = True |
| 274 | |
| 275 | if not got_auth or username is None or token is None: |
| 276 | raise RuntimeError("Cannot connect without a username or token") |
| 277 | |
| 278 | if not core.BNRemoteConnect(self._handle, username, token): |
| 279 | raise RuntimeError(util._last_error()) |
| 280 | |
| 281 | def disconnect(self): |
| 282 | """ |