コード例 #1
0
def main():
    data = Data()
    data.wireDecode(TlvData)

    # Use a hard-wired secret for testing. In a real application the signer
    # ensures that the verifier knows the shared key and its keyName.
    key = Blob(bytearray([
       0,  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
    ]))

    if KeyChain.verifyDataWithHmacWithSha256(data, key):
      dump("Hard-coded data signature verification: VERIFIED")
    else:
      dump("Hard-coded data signature verification: FAILED")

    freshData = Data(Name("/ndn/abc"))
    signature = HmacWithSha256Signature()
    signature.getKeyLocator().setType(KeyLocatorType.KEYNAME)
    signature.getKeyLocator().setKeyName(Name("key1"))
    freshData.setSignature(signature)
    freshData.setContent("SUCCESS!")
    dump("Signing fresh data packet", freshData.getName().toUri())
    KeyChain.signWithHmacWithSha256(freshData, key)

    if KeyChain.verifyDataWithHmacWithSha256(freshData, key):
      dump("Freshly-signed data signature verification: VERIFIED")
    else:
      dump("Freshly-signed data signature verification: FAILED")
コード例 #2
0
def main():
    data = Data()
    data.wireDecode(TlvData)

    # Use a hard-wired secret for testing. In a real application the signer
    # ensures that the verifier knows the shared key and its keyName.
    key = Blob(
        bytearray([
            0, 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
        ]))

    if KeyChain.verifyDataWithHmacWithSha256(data, key):
        dump("Hard-coded data signature verification: VERIFIED")
    else:
        dump("Hard-coded data signature verification: FAILED")

    freshData = Data(Name("/ndn/abc"))
    signature = HmacWithSha256Signature()
    signature.getKeyLocator().setType(KeyLocatorType.KEYNAME)
    signature.getKeyLocator().setKeyName(Name("key1"))
    freshData.setSignature(signature)
    freshData.setContent("SUCCESS!")
    dump("Signing fresh data packet", freshData.getName().toUri())
    KeyChain.signWithHmacWithSha256(freshData, key)

    if KeyChain.verifyDataWithHmacWithSha256(freshData, key):
        dump("Freshly-signed data signature verification: VERIFIED")
    else:
        dump("Freshly-signed data signature verification: FAILED")
コード例 #3
0
def main():
    interest = Interest()
    interest.wireDecode(TlvInterest)

    # Use a hard-wired secret for testing. In a real application the signer
    # ensures that the verifier knows the shared key and its keyName.
    key = Blob(bytearray([
       0,  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
    ]))

    if KeyChain.verifyInterestWithHmacWithSha256(interest, key):
      dump("Hard-coded interest signature verification: VERIFIED")
    else:
      dump("Hard-coded interest signature verification: FAILED")

    freshInterest = Interest(Name("/ndn/abc"))
    freshInterest.setMustBeFresh(False)
    keyName = Name("key1")
    dump("Signing fresh interest", freshInterest.getName().toUri())
    KeyChain.signWithHmacWithSha256(freshInterest, key, keyName)

    if KeyChain.verifyInterestWithHmacWithSha256(freshInterest, key):
      dump("Freshly-signed interest signature verification: VERIFIED")
    else:
      dump("Freshly-signed interest signature verification: FAILED")
コード例 #4
0
def main():
    # Silence the warning from Interest wire encode.
    Interest.setDefaultCanBePrefix(True)

    interest = Interest()
    interest.wireDecode(TlvInterest)

    # Use a hard-wired secret for testing. In a real application the signer
    # ensures that the verifier knows the shared key and its keyName.
    key = Blob(bytearray([
       0,  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
    ]))

    if KeyChain.verifyInterestWithHmacWithSha256(interest, key):
      dump("Hard-coded interest signature verification: VERIFIED")
    else:
      dump("Hard-coded interest signature verification: FAILED")

    freshInterest = Interest(Name("/ndn/abc"))
    freshInterest.setMustBeFresh(False)
    keyName = Name("key1")
    dump("Signing fresh interest", freshInterest.getName().toUri())
    KeyChain.signWithHmacWithSha256(freshInterest, key, keyName)

    if KeyChain.verifyInterestWithHmacWithSha256(freshInterest, key):
      dump("Freshly-signed interest signature verification: VERIFIED")
    else:
      dump("Freshly-signed interest signature verification: FAILED")
コード例 #5
0
ファイル: proxy.py プロジェクト: peurpdapeurp/proxy-py
    def onInterest(self, prefix, interest, face, interestFilterId, filter):

        key = Blob(
            bytearray([
                0, 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
            ]))

        print "Got onboarding interest with name: %s" % (
            interest.getName().toUri())

        try:
            if KeyChain.verifyInterestWithHmacWithSha256(interest, key):
                dump("Onboarding interest signature verification: VERIFIED")
            else:
                dump("Onboarding interest signature verification: FAILED")
        except:
            print "Exception when attempting to verify onboarding interest signature."

        data = Data(interest.getName())
        signature = HmacWithSha256Signature()
        signature.getKeyLocator().setType(KeyLocatorType.KEYNAME)
        signature.getKeyLocator().setKeyName(Name("key1"))
        data.setSignature(signature)
        data.setContent("")
        dump("Signing onboarding response data packet", data.getName().toUri())
        KeyChain.signWithHmacWithSha256(data, key)

        deviceID = str(interest.getName().getSubName(-3, 1).toUri()[1:])
        deviceIP = str(interest.getName().getSubName(-4, 1).toUri()[1:])

        print "Device ip: %s" % (deviceIP)
        print "Device ID: %s" % (deviceID)

        routeToRegister = str(Name(deviceID))

        registerRouteWithNameAndIp(routeToRegister, deviceIP)

        thread = threading.Thread(target=run_data_fetcher, args=(deviceID))
        thread.daemon = True  # Daemonize thread
        thread.start()

        #commandRouteToRegister = "/device/command/" + deviceID

        #registerRouteWithNameAndIp(commandRouteToRegister, deviceIP)

        face.putData(data)

        with open('%s' % (deviceIDListName), 'a') as the_file:
            the_file.seek(0)
            read_file = open('%s' % (deviceIDListName), 'r')
            if deviceID not in read_file.read():
                the_file.write('%s\n' % (deviceID))
コード例 #6
0
    def onInterest(self, prefix, interest, face, interestFilterId, filter):

        print "Got interest for device ID list."

        file = open("%s" % (deviceIDListName), "r")
        deviceIDList = file.read()

        data = Data(interest.getName())
        signature = HmacWithSha256Signature()
        signature.getKeyLocator().setType(KeyLocatorType.KEYNAME)
        signature.getKeyLocator().setKeyName(Name("key1"))
        data.setSignature(signature)
        data.setContent(deviceIDList)
        dump("Signing device ID List data packet", data.getName().toUri())
        KeyChain.signWithHmacWithSha256(data, key)

        face.putData(data)
コード例 #7
0
    def onInterest(self, prefix, interest, face, interestFilterId, filter):

        print "Got interest for latest device seq num."

        deviceID = str(interest.getName().getSubName(-1, 1).toUri()[1:])
        
        file = open("../repo-ng/seq/%s.seq" % (deviceID), "r")
        deviceIDList = file.read()

        data = Data(interest.getName())
        signature = HmacWithSha256Signature()
        signature.getKeyLocator().setType(KeyLocatorType.KEYNAME)
        signature.getKeyLocator().setKeyName(Name("key1"))
        data.setSignature(signature)
        data.setContent(deviceIDList)
        dump("Signing device ID List data packet", data.getName().toUri())
        KeyChain.signWithHmacWithSha256(data, key)

        face.putData(data)
コード例 #8
0
    def _makeNotificationInterest(self):
        """
        Make and return a new Interest where the name is
        _applicationBroadcastPrefix plus the encoding of _stateVector. Also
        use _hmacKey to sign it with HmacWithSha256.

        :return: The new signed notification interest.
        :rtype: Interest
        """
        interest = Interest(self._applicationBroadcastPrefix)
        interest.setInterestLifetimeMilliseconds(
            self._notificationInterestLifetime)
        interest.getName().append(
            StateVectorSync2018.encodeStateVector(self._stateVector,
                                                  self._sortedStateVectorKeys))

        # TODO: Should we just use key name /A ?
        KeyChain.signWithHmacWithSha256(interest, self._hmacKey, Name("/A"))

        return interest
コード例 #9
0
def scanForNistSensors():

    scanner = Scanner().withDelegate(ScanDelegate())
    scanner.scan(.1)

    if foundNistSensor == 0:
        print "Didn't find any nist sensors..."
        return False

    p = Peripheral(esp32Address)
    p.setMTU(500)

    #svcList = p.getServices()
    #print "Handle   UUID                                Properties"
    #print "-------------------------------------------------------"
    #for svc in svcList:
    #      print (str(svc.uuid))
    
    #chList = p.getCharacteristics()
    #print "Handle   UUID                                Properties"
    #print "-------------------------------------------------------"
    #for ch in chList:
    #         print ("  0x"+ format(ch.getHandle(),'02X')  +"   "+str(ch.uuid) +" " + ch.propertiesToString())

    nist_service_uuid = UUID("0000ffe0-0000-1000-8000-00805f9b34fb")
    nist_characteristic_uuid = UUID("beb5483e-36e1-4688-b7f5-ea07361b26a8")

    nistService = p.getServiceByUUID(nist_service_uuid)
    #nistCharacteristic = p.getCharacteristics(nist_characteristic_uuid)[0]
    nistCharacteristic = nistService.getCharacteristics("beb5483e-36e1-4688-b7f5-ea07361b26a8")[0]

    #readBytes = bytes(p.readCharacteristic(0x2A))
    #readBytes = bytes(nistCharacteristic.read())

    #print binascii.hexlify(readBytes)

    #with open('/home/pi/Desktop/esp32-ndn-ble/src/readBytes.txt', 'a') as the_file:
    #      the_file.seek(0)
    #      the_file.truncate()
    #      the_file.write(binascii.hexlify(readBytes))

    #TlvData = Blob(readBytes)

    #data = Data()
    #data.wireDecode(TlvData)

    # Use a hard-wired secret for testing. In a real application the signer
    # ensures that the verifier knows the shared key and its keyName.
    key = Blob(bytearray([
       0,  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
    ]))

    #if KeyChain.verifyDataWithHmacWithSha256(data, key):
    #  dump("Hard-coded data signature verification: VERIFIED")
    #else:
    #  dump("Hard-coded data signature verification: FAILED")

    freshData = Data(Name("/netInfo"))
    signature = HmacWithSha256Signature()
    signature.getKeyLocator().setType(KeyLocatorType.KEYNAME)
    signature.getKeyLocator().setKeyName(Name("key1"))
    freshData.setSignature(signature)
    freshData.setContent("EdwardPi\n11111111\n192.168.4.1\n")
    dump("Signing fresh data packet", freshData.getName().toUri())
    KeyChain.signWithHmacWithSha256(freshData, key)

    if KeyChain.verifyDataWithHmacWithSha256(freshData, key):
      dump("Freshly-signed data signature verification: VERIFIED")
    else:
      dump("Freshly-signed data signature verification: FAILED")

    bytesSend = freshData.wireEncode()

    print binascii.hexlify(bytes(bytesSend))

    try:
        nistCharacteristic.write(bytes(bytesSend), True)
    except:
        print "Exception when trying to write to BLE characteristic."