(self)
| 357 | self.release() |
| 358 | |
| 359 | def acquire(self): |
| 360 | # UI builds have their own license manager |
| 361 | if binaryninja.core_ui_enabled(): |
| 362 | return |
| 363 | if not is_initialized(): |
| 364 | try: |
| 365 | initialize() |
| 366 | except: |
| 367 | # Named/computer licenses don't need this flow at all |
| 368 | if not is_floating_license(): |
| 369 | return |
| 370 | # Floating licenses though, this is an error. Probably the error |
| 371 | # for needing to set enterprise.server.url in settings.json |
| 372 | raise |
| 373 | if not is_floating_license(): |
| 374 | return |
| 375 | if not is_connected(): |
| 376 | connect() |
| 377 | got_auth = False |
| 378 | if not is_authenticated(): |
| 379 | try: |
| 380 | # Try Keychain |
| 381 | authenticate_with_method("Keychain", False) |
| 382 | got_auth = True |
| 383 | except RuntimeError: |
| 384 | pass |
| 385 | |
| 386 | if not got_auth and \ |
| 387 | os.environ.get('BN_ENTERPRISE_USERNAME') is not None and \ |
| 388 | os.environ.get('BN_ENTERPRISE_PASSWORD') is not None: |
| 389 | try: |
| 390 | authenticate_with_credentials(os.environ['BN_ENTERPRISE_USERNAME'], os.environ['BN_ENTERPRISE_PASSWORD']) |
| 391 | got_auth = True |
| 392 | except RuntimeError: |
| 393 | pass |
| 394 | |
| 395 | if not got_auth: |
| 396 | raise RuntimeError( |
| 397 | "Could not checkout a license: Not authenticated. Try one of the following: \n" |
| 398 | " - Log in and check out a license for an extended time\n" |
| 399 | " - Set BN_ENTERPRISE_USERNAME and BN_ENTERPRISE_PASSWORD environment variables\n" |
| 400 | " - Use binaryninja.enterprise.authenticate_with_credentials or authenticate_with_method in your code" |
| 401 | ) |
| 402 | |
| 403 | # Keychain auth can activate a license if we have one in the keychain |
| 404 | # If we have an expired named license, try to get a fresh floating one |
| 405 | if not is_license_still_activated() or (not is_floating_license() and binaryninja.core_expires() < gmtime()): |
| 406 | update_license(self.desired_duration) |
| 407 | self.acquired_license = True |
| 408 | |
| 409 | def release(self): |
| 410 | # UI builds have their own license manager |
no test coverage detected