Refactor for older python and add nac generator (#35)

This commit is contained in:
SpaceSaver 2023-10-23 11:02:04 -04:00 committed by GitHub
parent 35020e2a4a
commit 76f35fc6a8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 26 deletions

6
generatenac.py Normal file
View file

@ -0,0 +1,6 @@
from base64 import b64encode
import emulated.nac
vd = emulated.nac.generate_validation_data()
vd = b64encode(vd).decode()
print(vd)

View file

@ -1,5 +1,6 @@
import plistlib import plistlib
from base64 import b64decode from base64 import b64decode
from typing import Union
import requests import requests
@ -14,7 +15,12 @@ import logging
logger = logging.getLogger("ids") logger = logging.getLogger("ids")
class IDSIdentity: class IDSIdentity:
def __init__(self, signing_key: str | None = None, encryption_key: str | None = None, signing_public_key: str | None = None, encryption_public_key: str | None = None): def __init__(
self,
signing_key: Union[str, None] = None,
encryption_key: Union[str, None] = None,
signing_public_key: Union[str, None] = None,
encryption_public_key: Union[str, None] = None):
if signing_key is not None: if signing_key is not None:
self.signing_key = signing_key self.signing_key = signing_key
self.signing_public_key = serialize_key(parse_key(signing_key).public_key()) self.signing_public_key = serialize_key(parse_key(signing_key).public_key())

View file

@ -9,6 +9,7 @@ import gzip
import logging import logging
import plistlib import plistlib
import random import random
from typing import Union
import uuid import uuid
from dataclasses import dataclass, field from dataclasses import dataclass, field
from hashlib import sha1, sha256 from hashlib import sha1, sha256
@ -45,11 +46,11 @@ class AttachmentFile:
@dataclass @dataclass
class MMCSFile(AttachmentFile): class MMCSFile(AttachmentFile):
url: str | None = None url: Union[str, None] = None
size: int | None = None size: Union[int, None] = None
owner: str | None = None owner: Union[str, None] = None
signature: bytes | None = None signature: Union[bytes, None] = None
decryption_key: bytes | None = None decryption_key: Union[bytes, None] = None
def data(self) -> bytes: def data(self) -> bytes:
import requests import requests
@ -107,17 +108,16 @@ class Attachment:
versions.append(MMCSFile()) versions.append(MMCSFile())
val = attrs[attribute_name] val = attrs[attribute_name]
match attribute_name: if attribute_name == "mmcs-url":
case "mmcs-url": versions[index].url = val
versions[index].url = val elif attribute_name == "mmcs-owner":
case "mmcs-owner": versions[index].owner = val
versions[index].owner = val elif attribute_name == "mmcs-signature-hex":
case "mmcs-signature-hex": versions[index].signature = base64.b16decode(val)
versions[index].signature = base64.b16decode(val) elif attribute_name == "file-size":
case "file-size": versions[index].size = int(val)
versions[index].size = int(val) elif attribute_name == "decryption-key":
case "decryption-key": versions[index].decryption_key = base64.b16decode(val)[1:]
versions[index].decryption_key = base64.b16decode(val)[1:]
self.versions = versions self.versions = versions
@ -131,25 +131,25 @@ class iMessage:
text: str = "" text: str = ""
"""Plain text of message, always required, may be an empty string""" """Plain text of message, always required, may be an empty string"""
xml: str | None = None xml: Union[str, None] = None
"""XML portion of message, may be None""" """XML portion of message, may be None"""
participants: list[str] = field(default_factory=list) participants: list[str] = field(default_factory=list)
"""List of participants in the message, including the sender""" """List of participants in the message, including the sender"""
sender: str | None = None sender: Union[str, None] = None
"""Sender of the message""" """Sender of the message"""
id: uuid.UUID | None = None id: Union[uuid.UUID, None] = None
"""ID of the message, will be randomly generated if not provided""" """ID of the message, will be randomly generated if not provided"""
group_id: uuid.UUID | None = None group_id: Union[uuid.UUID, None] = None
"""Group ID of the message, will be randomly generated if not provided""" """Group ID of the message, will be randomly generated if not provided"""
body: BalloonBody | None = None body: Union[BalloonBody, None] = None
"""BalloonBody, may be None""" """BalloonBody, may be None"""
effect: str | None = None effect: Union[str, None] = None
"""iMessage effect sent with this message, may be None""" """iMessage effect sent with this message, may be None"""
_compressed: bool = True _compressed: bool = True
"""Internal property representing whether the message should be compressed""" """Internal property representing whether the message should be compressed"""
_raw: dict | None = None _raw: Union[dict, None] = None
"""Internal property representing the original raw message, may be None""" """Internal property representing the original raw message, may be None"""
def attachments(self) -> list[Attachment]: def attachments(self) -> list[Attachment]:
@ -183,7 +183,7 @@ class iMessage:
return True return True
def from_raw(message: bytes, sender: str | None = None) -> "iMessage": def from_raw(message: bytes, sender: Union[str, None] = None) -> "iMessage":
"""Create an `iMessage` from raw message bytes""" """Create an `iMessage` from raw message bytes"""
compressed = False compressed = False
try: try:
@ -420,7 +420,7 @@ class iMessageUser:
except: except:
return False return False
def receive(self) -> iMessage | None: def receive(self) -> Union[iMessage, None]:
""" """
Will return the next iMessage in the queue, or None if there are no messages Will return the next iMessage in the queue, or None if there are no messages
""" """