File: fp-reg-decrypt

package info (click to toggle)
flashproxy 1.7-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 936 kB
  • ctags: 876
  • sloc: python: 3,708; sh: 823; makefile: 246; lisp: 15
file content (70 lines) | stat: -rwxr-xr-x 1,686 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python
"""
Forwards encrypted client registrations to a running fp-reg-decryptd.
"""

import getopt
import socket
import sys

CONNECT_ADDRESS = "127.0.0.1"
DEFAULT_CONNECT_PORT = 9003

class options(object):
    connect_port = DEFAULT_CONNECT_PORT

def usage(f = sys.stdout):
    print >> f, """\
Usage: %(progname)s
Reads a base64-encoded encrypted client registration from stdin and
feeds it to a local fp-reg-decryptd process. Returns 0 if the
registration was successful, 1 otherwise.

  -h, --help              show this help.
  -p, --port PORT         connect to PORT (default %(port)d).\
""" % {
    "progname": sys.argv[0],
    "port": DEFAULT_CONNECT_PORT,
}

def main():
    opts, args = getopt.gnu_getopt(sys.argv[1:], "hp:", [
        "help",
        "port=",
    ])
    for o, a in opts:
        if o == "-h" or o == "--help":
            usage()
            sys.exit()
        elif o == "-p" or o == "--port":
            options.connect_port = int(a)

    if len(args) != 0:
        usage(sys.stderr)
        sys.exit(1)

    addrinfo = socket.getaddrinfo(CONNECT_ADDRESS, options.connect_port, 0, socket.SOCK_STREAM, socket.IPPROTO_TCP)[0]

    s = socket.socket(addrinfo[0], addrinfo[1], addrinfo[2])
    s.connect(addrinfo[4])

    sent = 0
    while True:
        data = sys.stdin.read(1024)
        if data == "":
            mod = sent % 4
            if mod != 0:
                s.sendall((4 - mod) * "=")
            break
        s.sendall(data)
        sent += len(data)
    s.shutdown(socket.SHUT_WR)
    data = s.recv(1024)

    if data.strip() == "OK":
        sys.exit(0)
    else:
        sys.exit(1)

if __name__ == "__main__":
    main()