Skip to content

Commit

Permalink
Gracefully handle asyncio timeout & other minor updates (#16)
Browse files Browse the repository at this point in the history
* added SUPPORT document

* Handle asyncio timeout exception gracefully

* fixed no_implicit_optional (PEP484)
  • Loading branch information
fvigo authored Jan 10, 2025
1 parent ecf16e1 commit ee2e6bc
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7, 3.8]
python-version: [3.11]

steps:
- uses: actions/checkout@v2
Expand Down
15 changes: 15 additions & 0 deletions SUPPORT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Community Supported

The software and templates in the repo are released under an as-is, best effort,
support policy. This software should be seen as community supported and Palo
Alto Networks will contribute our expertise as and when possible. We do not
provide technical support or help in using or troubleshooting the components of
the project through our normal support options such as Palo Alto Networks
support teams, or ASC (Authorized Support Centers) partners and backline support
options. The underlying product used (the VM-Series firewall) by the scripts or
templates are still supported, but the support is only for the product
functionality and not for help in deploying or using the template or script
itself. Unless explicitly tagged, all projects or work posted in our GitHub
repository (at https://github.com/PaloAltoNetworks) or sites other than our
official Downloads page on https://support.paloaltonetworks.com are provided
under the best effort policy.
7 changes: 4 additions & 3 deletions jarm/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from contextlib import suppress
from datetime import datetime, timezone
import logging
from typing import Optional

try:
from jarm.constants import DEFAULT_TIMEOUT
Expand All @@ -21,9 +22,9 @@
def _scan(
target: str,
address_family: int = 0,
proxy: str = None,
proxy_auth: str = None,
proxy_insecure: bool = None,
proxy: Optional[str] = None,
proxy_auth: Optional[str] = None,
proxy_insecure: Optional[bool] = None,
concurrency: int = 2,
timeout: int = DEFAULT_TIMEOUT,
suppress: bool = False,
Expand Down
6 changes: 5 additions & 1 deletion jarm/connection/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,9 @@ async def jarm_connect(
conn_target["connect_port"] = connection_port
conn_target["address_family"] = target_family
fut = Connection.jarm_data(conn_target, data)
output = await asyncio.wait_for(fut, timeout=timeout)
output = b""
try:
output = await asyncio.wait_for(fut, timeout=timeout)
except asyncio.TimeoutError as e:
pass
return (check, output)
4 changes: 3 additions & 1 deletion jarm/packet/packet.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ class Packet:
)
EC_POINT_FORMATS: bytes = b"\x00\x0b\x00\x02\x01\x00"
SESSION_TICKET: bytes = b"\x00\x23\x00\x00"
SIGNATURE_ALGORITHMS: bytes = b"\x00\x0d\x00\x14\x00\x12\x04\x03\x08\x04\x04\x01\x05\x03\x08\x05\x05\x01\x08\x06\x06\x01\x02\x01"
SIGNATURE_ALGORITHMS: bytes = (
b"\x00\x0d\x00\x14\x00\x12\x04\x03\x08\x04\x04\x01\x05\x03\x08\x05\x05\x01\x08\x06\x06\x01\x02\x01"
)
PSK_KEY_EXCHANGE_MODES: bytes = b"\x00\x2d\x00\x02\x01\x01"
SUB_TLS_1_2_SUPPORT: List[bytes] = [b"\x03\x01", b"\x03\x02", b"\x03\x03"]
TLS_1_3_SUPPORT: List[bytes] = [b"\x03\x01", b"\x03\x02", b"\x03\x03", b"\x03\x04"]
Expand Down
6 changes: 3 additions & 3 deletions jarm/proxy/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ async def handle_proxy(
reader: asyncio.StreamReader,
writer: asyncio.StreamWriter,
target_str: str,
auth: str = None,
username: str = None,
password: str = None,
auth: Optional[str] = None,
username: Optional[str] = None,
password: Optional[str] = None,
headers: Dict[str, str] = {},
):
headers = Proxy.get_http_headers()
Expand Down
8 changes: 4 additions & 4 deletions jarm/scanner/scanner.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from collections import namedtuple
import logging
import asyncio
from typing import List, Any
from typing import Optional, List, Any
import warnings

from jarm.constants import TOTAL_FAILURE, FAILED_PACKET, ERROR_INC_1, ERROR_INC_2
Expand Down Expand Up @@ -38,9 +38,9 @@ async def scan_async(
dest_port: int,
timeout: int = 20,
address_family=Connection.AddressFamily.AF_ANY,
proxy: str = None,
proxy_auth: str = None,
proxy_insecure: bool = None,
proxy: Optional[str] = None,
proxy_auth: Optional[str] = None,
proxy_insecure: Optional[bool] = None,
concurrency: int = 2,
suppress: bool = False,
):
Expand Down

0 comments on commit ee2e6bc

Please sign in to comment.