Example #1
0
    def test_05(self, llc):
        """Undeliverable resource"""

        payload = ''.join([chr(x) for x in range(122 - 29)])
        record = nfc.ndef.Record("application/octet-stream", "1", payload)
        ndef_message_sent = nfc.ndef.Message(record)

        max_ndef_msg_recv_size = len(str(ndef_message_sent)) - 1
        snep = nfc.snep.SnepClient(llc, max_ndef_msg_recv_size)
        try:
            info("connect to {0}".format(validation_server))
            snep.connect(validation_server)
        except nfc.llcp.ConnectRefused:
            raise TestFail("could not connect to validation server")

        try:
            info("put {0} octets ndef message".format(
                len(str(ndef_message_sent))))
            snep.put(ndef_message_sent)

            info("request ndef message back with max acceptable lenght " +
                 str(max_ndef_msg_recv_size))
            identifier = nfc.ndef.Record("application/octet-stream", "1", "")
            try:
                ndef_message = snep.get(nfc.ndef.Message(identifier))
            except nfc.snep.SnepError as e:
                if e.errno != nfc.snep.ExcessData:
                    raise TestFail("received unexpected response code")
                info("received 'excess data' response as expected")
            else:
                raise TestFail("received unexpected message from server")
        finally:
            info("disconnect from {0}".format(validation_server))
            snep.close()
Example #2
0
    def test_07(self, llc):
        """Default server limits"""

        payload = ''.join([chr(x % 256) for x in range(1024 - 32)])
        record = nfc.ndef.Record("application/octet-stream", "1", payload)
        ndef_message = nfc.ndef.Message(record)

        snep = nfc.snep.SnepClient(llc)
        try:
            info("connect to {0}".format("urn:nfc:sn:snep"))
            snep.connect("urn:nfc:sn:snep")
        except nfc.llcp.ConnectRefused:
            raise TestFail("could not connect to default server")

        try:
            info("put {0} octets ndef message".format(len(str(ndef_message))))
            snep.put(ndef_message)

            identifier = nfc.ndef.Record("application/octet-stream", "1", "")
            info("request ndef message " + repr(identifier))
            try:
                ndef_message = snep.get(nfc.ndef.Message(identifier))
            except nfc.snep.SnepError as e:
                if e.errno != nfc.snep.NotImplemented:
                    raise TestFail("received unexpected response code")
                info("received 'not implemented' response as expected")
            else:
                raise TestFail("received unexpected message from server")
        finally:
            info("disconnect from server")
            snep.close()
Example #3
0
    def test_05(self, llc):
        """Undeliverable resource"""

        payload = ''.join([chr(x) for x in range(122-29)])
        record = nfc.ndef.Record("application/octet-stream", "1", payload)
        ndef_message_sent = nfc.ndef.Message(record)

        max_ndef_msg_recv_size = len(str(ndef_message_sent)) - 1
        snep = nfc.snep.SnepClient(llc, max_ndef_msg_recv_size)
        try:
            info("connect to {0}".format(validation_server))
            snep.connect(validation_server)
        except nfc.llcp.ConnectRefused:
            raise TestError("could not connect to validation server")

        try:
            info("put {0} octets ndef message".format(
                    len(str(ndef_message_sent))))
            snep.put(ndef_message_sent)

            info("request ndef message back with max acceptable lenght " +
                 str(max_ndef_msg_recv_size))
            identifier = nfc.ndef.Record("application/octet-stream", "1", "")
            try:
                ndef_message = snep.get(nfc.ndef.Message(identifier))
            except nfc.snep.SnepError as e:
                if e.errno != nfc.snep.ExcessData:
                    raise TestError("received unexpected response code")
                info("received 'excess data' response as expected")
            else:
                raise TestError("received unexpected message from server")
        finally:
            info("disconnect from {0}".format(validation_server))
            snep.close()
Example #4
0
    def test_07(self, llc):
        """Default server limits"""

        payload = ''.join([chr(x%256) for x in range(1024-32)])
        record = nfc.ndef.Record("application/octet-stream", "1", payload)
        ndef_message = nfc.ndef.Message(record)

        snep = nfc.snep.SnepClient(llc)
        try:
            info("connect to {0}".format("urn:nfc:sn:snep"))
            snep.connect("urn:nfc:sn:snep")
        except nfc.llcp.ConnectRefused:
            raise TestError("could not connect to default server")

        try:
            info("put {0} octets ndef message".format(len(str(ndef_message))))
            snep.put(ndef_message)

            identifier = nfc.ndef.Record("application/octet-stream", "1", "")
            info("request ndef message " + repr(identifier))
            try:
                ndef_message = snep.get(nfc.ndef.Message(identifier))
            except nfc.snep.SnepError as e:
                if e.errno != nfc.snep.NotImplemented:
                    raise TestError("received unexpected response code")
                info("received 'not implemented' response as expected")
            else:
                raise TestError("received unexpected message from server")
        finally:
            info("disconnect from server")
            snep.close()
Example #5
0
def test_02():
    info("Test 2: unfragmented message exchange", prefix="")
    ndef_message_sent = list()
    ndef_message_rcvd = list()

    payload = ''.join([chr(x) for x in range(122-29)])
    record = nfc.ndef.Record(("application/octet-stream", "1", payload))
    ndef_message_sent.append(nfc.ndef.Message(record).tostring())

    snep = nfc.snep.SnepClient(max_ndef_msg_recv_size=1024)
    try:
        info("connect to {0}".format(validation_server))
        snep.connect(validation_server)
    except nfc.llcp.ConnectRefused:
        raise TestError("could not connect to validation server")

    try:
        info("put short ndef message")
        snep.put(ndef_message_sent[0])

        info("get short ndef message")
        identifier = nfc.ndef.Record(("application/octet-stream", "1", ""))
        ndef_message = snep.get(nfc.ndef.Message(identifier).tostring())
        ndef_message_rcvd.append(ndef_message)

        for i in range(len(ndef_message_sent)):
            if not ndef_message_rcvd == ndef_message_sent:
                raise TestError("rcvd ndef message {0} differs".format(i))
            else:
                info("rcvd ndef message {0} is correct".format(i))
    except Exception as e:
        TestError("exception: " + str(e))
    finally:
        info("disconnect from {0}".format(validation_server))
        snep.close()
Example #6
0
def test_07():
    info("Test 7: default server limits", prefix="")

    payload = ''.join([chr(x%256) for x in range(1024-32)])
    record = nfc.ndef.Record(("application/octet-stream", "1", payload))
    ndef_message = nfc.ndef.Message(record).tostring()
    
    snep = nfc.snep.SnepClient()
    try:
        info("connect to {0}".format("urn:nfc:sn:snep"))
        snep.connect("urn:nfc:sn:snep")
    except nfc.llcp.ConnectRefused:
        raise TestError("could not connect to validation server")

    try:
        info("put {0} octets ndef message".format(len(ndef_message)))
        snep.put(ndef_message)

        identifier = nfc.ndef.Record(("application/octet-stream", "1", ""))
        info("request ndef message " + str(identifier))
        try:
            ndef_message = snep.get(nfc.ndef.Message(identifier).tostring())
        except nfc.snep.SnepError as e:
            if e.errno == nfc.snep.NotImplemented: return # PASS
            raise TestError("received unexpected response code")
        else:
            raise TestError("received unexpected message from server")
    except Exception:
        raise
    finally:
        snep.close()
Example #7
0
def test_05():
    info("Test 5: undeliverable resource", prefix="")

    payload = ''.join([chr(x) for x in range(122-29)])
    record = nfc.ndef.Record(("application/octet-stream", "1", payload))
    ndef_message_sent = nfc.ndef.Message(record).tostring()

    max_ndef_msg_recv_size = len(ndef_message_sent) - 1
    snep = nfc.snep.SnepClient(max_ndef_msg_recv_size)
    try:
        info("connect to {0}".format(validation_server))
        snep.connect(validation_server)
    except nfc.llcp.ConnectRefused:
        raise TestError("could not connect to validation server")

    try:
        info("put {0} octets ndef message".format(len(ndef_message_sent)))
        snep.put(ndef_message_sent)

        info("request ndef message back with max acceptable lenght of " +
             str(max_ndef_msg_recv_size))
        identifier = nfc.ndef.Record(("application/octet-stream", "1", ""))
        try:
            ndef_message = snep.get(nfc.ndef.Message(identifier).tostring())
        except nfc.snep.SnepError as e:
            if e.errno == nfc.snep.ExcessData: return # PASS
            raise TestError("received unexpected response code")
        else:
            raise TestError("received unexpected message from server")
    except Exception:
        raise
    finally:
        info("disconnect from {0}".format(validation_server))
        snep.close()
Example #8
0
    def test_00(self, llc):
        """Read NDEF data to send from file 'beam.ndef'"""

        try:
            data = open("beam.ndef", "rb").read()
        except IOError:
            return
        ndef = nfc.ndef.Message(data)

        snep = nfc.snep.SnepClient(llc, max_ndef_msg_recv_size=1024)
        snep.put(ndef)
        snep.close()
Example #9
0
    def test_00(self, llc):
        """Read NDEF data to send from file 'beam.ndef'"""
        
        try:
            data = open("beam.ndef", "rb").read()
        except IOError:
            return
        ndef = nfc.ndef.Message(data)

        snep = nfc.snep.SnepClient(llc, max_ndef_msg_recv_size=1024)
        snep.put(ndef)
        snep.close()
Example #10
0
def send_ndef_message(llc):
    aar = nfc.ndef.Record('urn:nfc:ext:android.com:pkg', '', 'vs.in.de.uni_ulm.mreuter.login')

    md = hashlib.sha256()
    md.update("*****@*****.**")
    digest = md.digest()
    jointhash = base64.b64encode(digest)

   # action = nfc.ndef.Record('application/vnd.vs.in.de.uni_ulm.mreuter.login', '', 'process')
    data = nfc.ndef.Record('application/vnd.vs.in.de.uni_ulm.mreuter.login', 'update', jointhash)
    #data = nfc.ndef.TextRecord(jointhash);
    snep = nfc.snep.SnepClient(llc)
    snep.put(nfc.ndef.Message(data))
Example #11
0
    def test_04(self, llc):
        """Multiple ndef messages"""

        ndef_message_sent = list()
        ndef_message_rcvd = list()

        payload = ''.join([chr(x % 256) for x in range(50)])
        record = nfc.ndef.Record("application/octet-stream", "1", payload)
        ndef_message_sent.append(nfc.ndef.Message(record))
        record = nfc.ndef.Record("application/octet-stream", "2", payload)
        ndef_message_sent.append(nfc.ndef.Message(record))

        snep = nfc.snep.SnepClient(llc, max_ndef_msg_recv_size=10000)
        try:
            info("connect to {0}".format(validation_server))
            snep.connect(validation_server)
        except nfc.llcp.ConnectRefused:
            raise TestFail("could not connect to validation server")

        try:
            info("put 1st ndef message")
            snep.put(ndef_message_sent[0])

            info("put 2nd ndef message")
            snep.put(ndef_message_sent[1])

            info("get 1st ndef message")
            identifier = nfc.ndef.Record("application/octet-stream", "1", "")
            ndef_message = snep.get(nfc.ndef.Message(identifier))
            ndef_message_rcvd.append(ndef_message)

            info("get 2nd ndef message")
            identifier = nfc.ndef.Record("application/octet-stream", "2", "")
            ndef_message = snep.get(nfc.ndef.Message(identifier))
            ndef_message_rcvd.append(ndef_message)

            for i in range(len(ndef_message_sent)):
                if not ndef_message_rcvd == ndef_message_sent:
                    info("rcvd ndef message {0} differs".format(i))
                    raise TestFail("rcvd ndef message {0} differs".format(i))
                else:
                    info("rcvd ndef message {0} is correct".format(i))
        except Exception as e:
            raise TestFail("exception " + str(e))
        finally:
            info("disconnect from {0}".format(validation_server))
            snep.close()
Example #12
0
    def test_04(self, llc):
        """Multiple ndef messages"""
        
        ndef_message_sent = list()
        ndef_message_rcvd = list()

        payload = ''.join([chr(x%256) for x in range(50)])
        record = nfc.ndef.Record("application/octet-stream", "1", payload)
        ndef_message_sent.append(nfc.ndef.Message(record))
        record = nfc.ndef.Record("application/octet-stream", "2", payload)
        ndef_message_sent.append(nfc.ndef.Message(record))

        snep = nfc.snep.SnepClient(llc, max_ndef_msg_recv_size=10000)    
        try:
            info("connect to {0}".format(validation_server))
            snep.connect(validation_server)
        except nfc.llcp.ConnectRefused:
            raise TestError("could not connect to validation server")

        try:
            info("put 1st ndef message")
            snep.put(ndef_message_sent[0])

            info("put 2nd ndef message")
            snep.put(ndef_message_sent[1])

            info("get 1st ndef message")
            identifier = nfc.ndef.Record("application/octet-stream", "1", "")
            ndef_message = snep.get(nfc.ndef.Message(identifier))
            ndef_message_rcvd.append(ndef_message)

            info("get 2nd ndef message")
            identifier = nfc.ndef.Record("application/octet-stream", "2", "")
            ndef_message = snep.get(nfc.ndef.Message(identifier))
            ndef_message_rcvd.append(ndef_message)

            for i in range(len(ndef_message_sent)):
                if not ndef_message_rcvd == ndef_message_sent:
                    info("rcvd ndef message {0} differs".format(i))
                    raise TestError("rcvd ndef message {0} differs".format(i))
                else:
                    info("rcvd ndef message {0} is correct".format(i))
        except Exception as e:
            raise TestError("exception " + str(e))
        finally:
            info("disconnect from {0}".format(validation_server))
            snep.close()
Example #13
0
 def send_ndef_message(self, llc):
     snep = nfc.snep.SnepClient(llc)
     text = nfc.ndef.TextRecord(json.dumps(self.invoice_container))
     aar = nfc.ndef.Record('urn:nfc:ext:android.com:pkg',
                           data='com.ryuta46.nemnfcinvoice')
     snep.put(nfc.ndef.Message(text, aar))
Example #14
0
 def run(self):
     sp = nfc.ndef.SmartPosterRecord(self.btc_uri)
     snep = nfc.snep.SnepClient(self.llc)
     snep.put(nfc.ndef.Message(sp))
 def run(self):
     sp = nfc.ndef.SmartPosterRecord(self.btc_uri)
     snep = nfc.snep.SnepClient(self.llc)
     snep.put(nfc.ndef.Message(sp))