trying to get this working

This commit is contained in:
JJTech0130 2023-09-23 19:11:19 -04:00
parent eee69e17bd
commit 54815bac70
No known key found for this signature in database
GPG key ID: 23C92EBCCF8F93D6
5 changed files with 34 additions and 16 deletions

View file

@ -42,7 +42,7 @@ except FileNotFoundError:
CONFIG = {}
# Re-register if the commit hash has changed
if CONFIG.get("commit_hash") != commit_hash:
if CONFIG.get("commit_hash") != commit_hash or True:
logging.warning("pypush commit is different, forcing re-registration...")
CONFIG["commit_hash"] = commit_hash
if "id" in CONFIG:

View file

@ -59,6 +59,7 @@ class IDSUser:
self.user_id = user_id
self.handles = handles
self.current_handle = self.handles[0]
self.ngm = encryption.NGMIdentity(self.extra.get("device_key"), self.extra.get("prekey"))
# This is a separate call so that the user can make sure the first part succeeds before asking for validation data
def register(self, validation_data: str):
@ -67,7 +68,6 @@ class IDSUser:
if they are not already set
"""
self.ngm = encryption.NGMIdentity(self.extra.get("device_key"), self.extra.get("prekey"))
self.extra["device_key"] = self.ngm.device_key
self.extra["prekey"] = self.ngm.pre_key
@ -90,8 +90,7 @@ class IDSUser:
self._id_keypair = id_keypair
def auth_and_set_encryption_from_config(self, config: dict[str, dict[str, Any]]):
if "extra" in config:
self.extra = config["extra"]
self.extra = config.get("extra", {})
auth = config.get("auth", {})
if (

View file

@ -16,17 +16,12 @@ class NGMIdentity:
self.device_key = device_key
self.pre_key = pre_key
@staticmethod
def serialize_timestamp(timestamp: float):
import struct
return struct.pack("<d", timestamp)
import time
time.time()
def sign_prekey(self):
timestamp = time.time()
to_sign = b"NGMPrekeySignature" + _helpers.compact_key(_helpers.parse_key(self.pre_key)) + struct.pack("<d", timestamp)
# Extend to the next multiple of 8
to_sign += b"\x00" * (8 - (len(to_sign) % 8))
print(to_sign)
signed = _helpers.parse_key(self.device_key).sign(to_sign, ec.ECDSA(hashes.SHA256()))
prekey_signed = ids_pb2.PublicDevicePrekey()

View file

@ -154,7 +154,7 @@ def register(
# },
"client-data": {
"supports-ack-v1": True,
"public-message-identity-key": identity.encode(),
#"public-message-identity-key": identity.encode(),
"supports-update-attachments-v1": True,
"supports-keep-receipts": True,
"supports-people-request-messages-v2": True,
@ -195,6 +195,7 @@ def register(
"supports-dq-nr": True,
"public-message-identity-ngm-version": 12.0,
"supports-audio-messaging-v2": True,
#"ngm-public-identity": ngm.generate_loggable_data()
},
"kt-loggable-data": ngm.generate_loggable_data(),
"kt-mismatch-account-flag": True,

View file

@ -156,7 +156,8 @@ class Message:
raise NotImplementedError()
def __str__(self):
raise NotImplementedError()
#raise NotImplementedError()
return self.text
@dataclass
class SMSReflectedMessage(Message):
@ -467,8 +468,10 @@ class iMessageUser:
payload = iMessageUser._parse_payload(p)
body = BytesIO(payload[0])
#print(self.user.ngm.pre_key)
rsa_body = ids._helpers.parse_key(
self.user.encryption_identity.encryption_key # type: ignore
#self.user.ngm.pre_key
).decrypt( # type: ignore
body.read(160),
padding.OAEP(
@ -516,12 +519,32 @@ class iMessageUser:
body: dict[str, Any] = await self._receive_raw(list(MESSAGE_TYPES.keys()), [t[0] for t in MESSAGE_TYPES.values()])
t: type[Message] = MESSAGE_TYPES[body["c"]][1]
if not 'E' in body:
logger.error(f"Received message with no encryption type")
logger.error(f"Message : {body}")
return Message(text="Received message with no encryption type", sender="System", participants=[], id=uuid.uuid4(), _raw=body)
if body['E'] != 'pair':
logger.error(f"Received message with unknown encryption type {body['E']}")
return Message(text="Received message with unknown encryption type", sender="System", participants=[], id=uuid.uuid4(), _raw=body)
if not 'P' in body:
logger.error(f"Received message with no payload")
logger.error(f"Message : {body}")
return Message(text="Received message with no payload", sender="System", participants=[], id=uuid.uuid4(), _raw=body)
if not await self._verify_payload(body["P"], body["sP"], body["t"]):
raise Exception("Failed to verify payload")
#raise Exception("Failed to verify payload")
logger.error(f"Failed to verify payload")
logger.error(f"Message : {body}")
return Message(text="Failed to verify payload", sender="System", participants=[], id=uuid.uuid4(), _raw=body)
logger.debug(f"Encrypted body : {body}")
try:
decrypted: bytes = self._decrypt_payload(body["P"])
except Exception as e:
logger.error(f"Failed to decrypt message : {e}")
logger.error(f"Message : {body}")
return Message(text="Failed to decrypt message", sender="System", participants=[], id=uuid.uuid4(), _raw=body)
try:
return t.from_raw(decrypted, body["sP"])