Created
May 31, 2012 20:45
-
-
Save nwg/2846124 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import struct | |
from binascii import a2b_hex, b2a_hex | |
import socket | |
import ssl | |
import time | |
import sys | |
fmt = '!IH32s' | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
s.connect(('feedback.push.apple.com', 2196)) | |
ssl = ssl.wrap_socket(s, 'push.key', 'push.cert', ssl_version=3, cert_reqs=ssl.CERT_NONE) | |
data = ssl.read(struct.calcsize(fmt)) | |
if not data: | |
print 'no data' | |
sys.exit(0) | |
while data: | |
timestamp, length, token = struct.unpack(fmt, data) | |
print 'got token: %s' % b2a_hex(token) | |
data = ssl.read(struct.calcsize(fmt)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
[ -n "$1" ] || { echo "Usage: $0 [p12]"; exit 1; } | |
openssl pkcs12 -in "$1" -nodes -nocerts -password "pass:" -out push.key | |
openssl pkcs12 -in "$1" -nodes -nokeys -password "pass:" -out push.cert |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import struct | |
from binascii import a2b_hex | |
import socket | |
import ssl | |
import time | |
payload = '{"aps":{"alert":"Broadcasting direct to apple with p12"}}' | |
tokens = [ | |
a2b_hex('SOMETOKEN'), | |
] | |
fmt = '!BH32sH%ds' % len(payload) | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
s.connect(('gateway.push.apple.com', 2195)) | |
ssl = ssl.wrap_socket(s, 'push.key', 'push.cert', ssl_version=3, cert_reqs=ssl.CERT_NONE) | |
#ssl = socket.ssl(s) | |
for token in tokens: | |
packet = struct.pack(fmt, 0, 32, token, len(payload), payload) | |
count = ssl.write(packet) | |
print 'write %d bytes' % count |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment