|
28 | 28 | import salt.utils.platform |
29 | 29 | import salt.utils.stringutils |
30 | 30 | import salt.utils.verify |
31 | | -from salt.exceptions import SaltDeserializationError, SaltValidationError, UnsupportedAlgorithm |
| 31 | +from salt.exceptions import ( |
| 32 | + InvalidKeyError, |
| 33 | + SaltDeserializationError, |
| 34 | + SaltValidationError, |
| 35 | + UnsupportedAlgorithm, |
| 36 | +) |
32 | 37 | from salt.utils.cache import CacheCli |
33 | 38 |
|
34 | 39 | log = logging.getLogger(__name__) |
@@ -1317,8 +1322,8 @@ async def handle_pool_publish(self, payload, _): |
1317 | 1322 |
|
1318 | 1323 | try: |
1319 | 1324 | notify_data = salt.payload.loads(data["payload"]) |
1320 | | - except Exception as e: # pylint: disable=broad-except |
1321 | | - log.error("Failed to load join-notify payload: %s", e) |
| 1325 | + except SaltDeserializationError as e: |
| 1326 | + log.error("Failed to deserialize join-notify payload: %s", e) |
1322 | 1327 | return |
1323 | 1328 |
|
1324 | 1329 | sender_id = notify_data.get("peer_id") |
@@ -1363,8 +1368,8 @@ async def handle_pool_publish(self, payload, _): |
1363 | 1368 | sender_id, |
1364 | 1369 | ) |
1365 | 1370 | return |
1366 | | - except Exception as e: # pylint: disable=broad-except |
1367 | | - log.error("Error verifying join-notify signature: %s", e) |
| 1371 | + except (OSError, InvalidKeyError) as e: |
| 1372 | + log.error("Error loading sender public key for signature verification: %s", e) |
1368 | 1373 | return |
1369 | 1374 |
|
1370 | 1375 | # Signature verified - now we can trust the notification |
@@ -1394,8 +1399,8 @@ async def handle_pool_publish(self, payload, _): |
1394 | 1399 |
|
1395 | 1400 | try: |
1396 | 1401 | payload = salt.payload.loads(data["payload"]) |
1397 | | - except Exception as e: # pylint: disable=broad-except |
1398 | | - log.error("Failed to load join-reply payload: %s", e) |
| 1402 | + except SaltDeserializationError as e: |
| 1403 | + log.error("Failed to deserialize join-reply payload: %s", e) |
1399 | 1404 | return |
1400 | 1405 |
|
1401 | 1406 | # Verify the peer_id matches who we're expecting (bootstrap peer) |
@@ -1426,8 +1431,8 @@ async def handle_pool_publish(self, payload, _): |
1426 | 1431 | data["peer_id"], |
1427 | 1432 | ) |
1428 | 1433 | return |
1429 | | - except Exception as e: # pylint: disable=broad-except |
1430 | | - log.error("Error verifying join-reply signature: %s", e) |
| 1434 | + except (OSError, InvalidKeyError) as e: |
| 1435 | + log.error("Error loading bootstrap public key for signature verification: %s", e) |
1431 | 1436 | return |
1432 | 1437 |
|
1433 | 1438 | # Verify the return token matches what we sent |
@@ -1466,7 +1471,7 @@ async def handle_pool_publish(self, payload, _): |
1466 | 1471 | # Load and validate it's a valid private key |
1467 | 1472 | cluster_key_obj = salt.crypt.PrivateKeyString(cluster_key_pem) |
1468 | 1473 |
|
1469 | | - except Exception as e: # pylint: disable=broad-except |
| 1474 | + except (OSError, InvalidKeyError, ValueError, UnicodeDecodeError) as e: |
1470 | 1475 | log.error("Error decrypting/validating cluster key: %s", e) |
1471 | 1476 | return |
1472 | 1477 |
|
|
0 commit comments