Get ZAP credentials for a specific target. Args: target_host: Target host/IP to look up Returns: Dict with credentials or None if not found
(self, target_host: str)
| 2488 | """, (target_host, auth_type, login_url, username, password_encoded, |
| 2489 | login_request_data, username_field, password_field, http_realm, notes, |
| 2490 | bearer_token_encoded, api_key_encoded, api_key_header, cookie_value_encoded)) |
| 2491 | |
| 2492 | conn.commit() |
| 2493 | logger.info(f"Saved ZAP credentials for target: {target_host}") |
| 2494 | return True |
| 2495 | |
| 2496 | except Exception as e: |
| 2497 | logger.error(f"Failed to save ZAP credentials for {target_host}: {e}") |
| 2498 | return False |
| 2499 | |
| 2500 | def get_zap_credentials(self, target_host: str) -> Optional[Dict[str, Any]]: |
| 2501 | """ |
| 2502 | Get ZAP credentials for a specific target. |
| 2503 | |
| 2504 | Args: |
| 2505 | target_host: Target host/IP to look up |
| 2506 | |
| 2507 | Returns: |
| 2508 | Dict with credentials or None if not found |
| 2509 | """ |
| 2510 | import base64 |
| 2511 | |
| 2512 | try: |
| 2513 | # Normalize target host |
| 2514 | target_host = self._normalize_target_host(target_host) |
| 2515 | |
| 2516 | with self.get_connection() as conn: |
| 2517 | cursor = conn.cursor() |
| 2518 | cursor.execute(""" |
| 2519 | SELECT * FROM zap_target_credentials WHERE target_host = ? |
| 2520 | """, (target_host,)) |
| 2521 | |
| 2522 | row = cursor.fetchone() |
| 2523 | if row: |
| 2524 | result = dict(row) |
| 2525 | |
| 2526 | # Decode password |
| 2527 | if result.get('password_encrypted'): |
| 2528 | try: |
| 2529 | result['password'] = base64.b64decode( |
| 2530 | result['password_encrypted'].encode('utf-8') |
| 2531 | ).decode('utf-8') |
| 2532 | except Exception: |
| 2533 | result['password'] = None |
| 2534 | else: |
| 2535 | result['password'] = None |
| 2536 | if 'password_encrypted' in result: |
| 2537 | del result['password_encrypted'] |
| 2538 | |
| 2539 | # Decode bearer token |
| 2540 | if result.get('bearer_token_encrypted'): |
| 2541 | try: |
| 2542 | result['bearer_token'] = base64.b64decode( |
| 2543 | result['bearer_token_encrypted'].encode('utf-8') |
| 2544 | ).decode('utf-8') |
| 2545 | except Exception: |
| 2546 | result['bearer_token'] = None |
| 2547 | else: |
no test coverage detected