Skip to content

Commit

Permalink
Merge pull request #13 from breakid/token_error_handling
Browse files Browse the repository at this point in the history
Handled expiration date parsing exception
  • Loading branch information
chrismaddalena authored Jun 13, 2023
2 parents 1ce1f31 + 2fba564 commit 343e48c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [3.0.2] - 13 June 2023

### Fixed

* Handled an exception caused by `_check_token()` trying to parse the expiration date from a token that never expires

## [3.0.1] - 17 May 2023

### Changed
Expand Down
8 changes: 6 additions & 2 deletions sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,11 @@ async def _execute_query(self, query: DocumentNode, variable_values: dict = None
async def _check_token(self) -> None:
"""Send a `whoami` query to Ghostwriter to check authentication and token expiration."""
whoami = await self._execute_query(self.whoami_query)
expiry = datetime.fromisoformat(whoami["whoami"]["expires"])
try:
expiry = datetime.fromisoformat(whoami["whoami"]["expires"])
except Exception:
expiry = whoami["whoami"]["expires"]

await mythic.send_event_log_message(
mythic=self.mythic_instance,
message=f"Mythic Sync has successfully authenticated to Ghostwriter. Your configured token expires at: {expiry}",
Expand All @@ -299,7 +303,7 @@ async def _check_token(self) -> None:

# Check if the token will expire within 24 hours
now = datetime.now(timezone.utc)
if expiry - now < timedelta(hours=24):
if isinstance(expiry, datetime) and expiry - now < timedelta(hours=24):
mythic_sync_log.debug(f"The provided Ghostwriter API token expires in less than 24 hours ({expiry})!")
await mythic.send_event_log_message(
mythic=self.mythic_instance,
Expand Down

0 comments on commit 343e48c

Please sign in to comment.