Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions marznode/backends/xray/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,27 @@ def get_version(xray_path: str) -> str | None:

def get_x25519(xray_path: str, private_key: str = None) -> Dict[str, str] | None:
"""
get x25519 public key using the private key
:param xray_path:
:param private_key:
:return: x25519 publickey
Calculates the public key from the provided private key.

- Old output format ("Public key:")
- New output format ("Password:")
"""

cmd = [xray_path, "x25519"]
if private_key:
cmd.extend(["-i", private_key])
output = subprocess.check_output(cmd, stderr=subprocess.STDOUT).decode("utf-8")
match = re.match(r"Private key: (.+)\nPublic key: (.+)", output)
if match:
private, public = match.groups()

# Try New Format (v25.8.3+): Looks for "Password:" instead of Public Key
match_new = re.match(r"PrivateKey:\s*(.+)\nPassword:\s*(.+)", output)
if match_new:
private, public = match_new.groups()
return {"private_key": private, "public_key": public}

# Try Old Format (< v25.8.3): Looks for standard "Public key:"
match_old = re.match(r"Private key:\s*(.+)\nPublic key:\s*(.+)", output)
if match_old:
private, public = match_old.groups()
return {"private_key": private, "public_key": public}

return None