latest changes

This commit is contained in:
JJTech0130 2023-04-06 10:38:29 -04:00
parent 8f5e64e4b1
commit e7a6cba72c
No known key found for this signature in database
GPG key ID: 23C92EBCCF8F93D6
2 changed files with 10 additions and 5 deletions

View file

@ -84,6 +84,7 @@ class Payload:
return f"{COMMANDS[self.command]}: {self.fields}" return f"{COMMANDS[self.command]}: {self.fields}"
import courier import courier
from hashlib import sha1
class APNSConnection(): class APNSConnection():
def __init__(self, token: bytes=None, private_key=None, cert=None): def __init__(self, token: bytes=None, private_key=None, cert=None):
@ -108,6 +109,13 @@ class APNSConnection():
if 3 in resp.fields.fields: if 3 in resp.fields.fields:
self.token = resp.fields.fields[3] self.token = resp.fields.fields[3]
def filter(self, topics: list[str]):
payload = Payload(9, Fields({1: self.token, 2: b"".join([sha1(topic.encode()).digest() for topic in topics])}))
self.sock.write(payload.to_bytes())
if __name__ == "__main__": if __name__ == "__main__":
import courier import courier
import base64 import base64

View file

@ -8,11 +8,8 @@ print(f"Push Token 1: {b64encode(conn1.token).decode()}")
conn2 = apns.APNSConnection() conn2 = apns.APNSConnection()
print(f"Push Token 2: {b64encode(conn2.token).decode()}") print(f"Push Token 2: {b64encode(conn2.token).decode()}")
# Create a topic filter payload with SHA1 hash of the topic conn1.filter(["com.apple.madrid"])
payload = apns.Payload(9, apns.Fields({1: conn2.token, 2: sha1(b"com.apple.madrid").digest()})) conn2.filter(["com.apple.madrid"])
# Send the payload
#conn1.sock.write(payload.to_bytes())
conn2.sock.write(payload.to_bytes())
#print(sha1(b"com.apple.madrid").digest()) #print(sha1(b"com.apple.madrid").digest())
# Send a notification # Send a notification