Esempio n. 1
0
    def test_signed_interest():
        name = '/local/ndn/prefix'
        app_param = b'\x01\x02\x03\x04'
        int_param = InterestParam()
        int_param.nonce = 0x6c211166
        interest = make_interest(name, int_param, app_param, signer=DigestSha256Signer())
        assert (interest ==
                b'\x05\x6f\x07\x36\x08\x05local\x08\x03ndn\x08\x06prefix'
                b'\x02 \x8e\x6e\x36\xd7\xea\xbc\xde\x43\x75\x61\x40\xc9\x0b\xda\x09\xd5'
                b'\x00\xd2\xa5\x77\xf2\xf5\x33\xb5\x69\xf0\x44\x1d\xf0\xa7\xf9\xe2'
                b'\x0a\x04\x6c\x21\x11\x66\x0c\x02\x0f\xa0'
                b'\x24\x04\x01\x02\x03\x04'
                b'\x2c\x03\x1b\x01\x00'
                b'\x2e \xea\xa8\xf0\x99\x08\x63\x78\x95\x1d\xe0\x5f\xf1\xde\xbb\xc1\x18'
                b'\xb5\x21\x8b\x2f\xca\xa0\xb5\x1d\x18\xfa\xbc\x29\xf5\x4d\x58\xff')

        interest = make_interest(name, int_param, signer=DigestSha256Signer())
        assert (interest ==
                b'\x05\x6b\x07\x36\x08\x05local\x08\x03ndn\x08\x06prefix'
                b'\x02 \x40\x77\xa5\x70\x49\xd8\x38\x48\xb5\x25\xa4\x23\xab\x97\x8e\x64'
                b'\x80\xf9\x6d\x5c\xa3\x8a\x80\xa5\xe2\xd6\xe2\x50\xa6\x17\xbe\x4f'
                b'\x0a\x04\x6c\x21\x11\x66\x0c\x02\x0f\xa0'
                b'\x24\x00'
                b'\x2c\x03\x1b\x01\x00'
                b'\x2e \x09\x4e\x00\x9d\x74\x59\x82\x5c\xa0\x2d\xaa\xb7\xad\x60\x48\x30'
                b'\x39\x19\xd8\x99\x80\x25\xbe\xff\xa6\xf9\x96\x79\xd6\x5e\x9f\x62')
Esempio n. 2
0
    def test_default():
        name = Name.from_str('/local/ndn/prefix')
        data = make_data(name, MetaInfo(), signer=DigestSha256Signer())
        assert (data ==
                b"\x06\x42\x07\x14\x08\x05local\x08\x03ndn\x08\x06prefix"
                b"\x14\x03\x18\x01\x00"
                b"\x16\x03\x1b\x01\x00"
                b"\x17 \x7f1\xe4\t\xc5z/\x1d\r\xdaVh8\xfd\xd9\x94"
                b"\xd8\'S\x13[\xd7\x15\xa5\x9d%^\x80\xf2\xab\xf0\xb5")

        name = Name.encode(name)
        data = make_data(name, MetaInfo(), b'01020304', signer=DigestSha256Signer())
        assert (data ==
                b'\x06L\x07\x14\x08\x05local\x08\x03ndn\x08\x06prefix'
                b'\x14\x03\x18\x01\x00'
                b'\x15\x0801020304'
                b'\x16\x03\x1b\x01\x00'
                b'\x17 \x94\xe9\xda\x91\x1a\x11\xfft\x02i:G\x0cO\xdd!'
                b'\xe0\xc7\xb6\xfd\x8f\x9cn\xc5\x93{\x93\x04\xe0\xdf\xa6S')

        name = '/local/ndn/prefix'
        meta_info = MetaInfo()
        data = make_data(name, meta_info)
        assert (data ==
                b"\x06\x1b\x07\x14\x08\x05local\x08\x03ndn\x08\x06prefix"
                b"\x14\x03\x18\x01\x00")

        name = '/E'
        meta_info = MetaInfo()
        meta_info.content_type = None
        data = make_data(name, meta_info, b'', signer=DigestSha256Signer())
        assert data == bytes.fromhex("0630 0703080145"
                                     "1400 1500 16031b0100"
                                     "1720f965ee682c6973c3cbaa7b69e4c7063680f83be93a46be2ccc98686134354b66")
Esempio n. 3
0
 def test_meta_info():
     name = '/local/ndn/prefix/37=%00'
     meta_info = MetaInfo()
     meta_info.content_type = ContentType.BLOB
     meta_info.freshness_period = 1000
     meta_info.final_block_id = Component.from_sequence_num(2)
     data = make_data(name, meta_info, signer=DigestSha256Signer())
     assert (data ==
             b"\x06\x4e\x07\x17\x08\x05local\x08\x03ndn\x08\x06prefix\x25\x01\x00"
             b"\x14\x0c\x18\x01\x00\x19\x02\x03\xe8\x1a\x03\x25\x01\x02"
             b"\x16\x03\x1b\x01\x00"
             b"\x17 \x03\xb8,\x18\xffMw\x84\x86\xa5a\x94e\xcc\xdaQ\x15\xb7\xfb\x19\xab\x9d1lw\'\xdf\xac\x03#\xcad")
Esempio n. 4
0
 def test_meta_info():
     name = '/local/ndn/prefix/37=%00'
     meta_info = MetaInfo()
     meta_info.content_type = ContentType.BLOB
     meta_info.freshness_period = 1000
     meta_info.final_block_id = Component.from_sequence_num(2)
     data = make_data(name, meta_info, signer=DigestSha256Signer())
     assert (
         data ==
         b"\x06\x4e\x07\x17\x08\x05local\x08\x03ndn\x08\x06prefix\x25\x01\x00"
         b"\x14\x0c\x18\x01\x00\x19\x02\x03\xe8\x1a\x03\x3a\x01\x02"
         b"\x16\x03\x1b\x01\x00"
         b"\x17 \x0f^\xa1\x0c\xa7\xf5Fb\xf0\x9cOT\xe0FeC\x8f92\x04\x9d\xabP\x80o\'\x94\xaa={hQ"
     )
Esempio n. 5
0
    def __init__(self, stype:SignatureType, keyName:Optional[str]=None, privKey:Optional[bytes]=None) -> None:
        self.type, self.signer, self.keyName, self.privKey = stype, None, "", b''

        if self.type != SignatureType.DIGEST_SHA256 and self.type != SignatureType.NOT_SIGNED:
            if privKey is None or privKey == b'':
                raise KeyError("Private Key has to be Defined in Signing Info with this Type.")
            if keyName is None or keyName == "":
                raise KeyError("Key Name has to be Defined in Signing Info with this Type.")
            self.keyName = keyName
            self.privKey = privKey

        if self.type == SignatureType.SHA256_WITH_ECDSA:
            self.signer = Sha256WithEcdsaSigner(Name.from_str(self.keyName), self.privKey)
        elif self.type == SignatureType.SHA256_WITH_RSA:
            self.signer = Sha256WithRsaSigner(Name.from_str(self.keyName), self.privKey)
        elif self.type == SignatureType.HMAC_WITH_SHA256:
            self.signer = HmacSha256Signer(Name.from_str(self.keyName), self.privKey)
        elif self.type == SignatureType.DIGEST_SHA256:
            self.signer = DigestSha256Signer()
Esempio n. 6
0
def on_interest(name: FormalName, param: InterestParam,
                _app_param: Optional[BinaryStr]):
    print(f'>> I: {Name.to_str(name)}, {param}')
    pub_key = bytes([
        0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86,
        0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00,
        0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xb8, 0x09, 0xa7,
        0x59, 0x82, 0x84, 0xec, 0x4f, 0x06, 0xfa, 0x1c, 0xb2, 0xe1, 0x38, 0x93,
        0x53, 0xbb, 0x7d, 0xd4, 0xac, 0x88, 0x1a, 0xf8, 0x25, 0x11, 0xe4, 0xfa,
        0x1d, 0x61, 0x24, 0x5b, 0x82, 0xca, 0xcd, 0x72, 0xce, 0xdb, 0x66, 0xb5,
        0x8d, 0x54, 0xbd, 0xfb, 0x23, 0xfd, 0xe8, 0x8e, 0xaf, 0xa7, 0xb3, 0x79,
        0xbe, 0x94, 0xb5, 0xb7, 0xba, 0x17, 0xb6, 0x05, 0xae, 0xce, 0x43, 0xbe,
        0x3b, 0xce, 0x6e, 0xea, 0x07, 0xdb, 0xbf, 0x0a, 0x7e, 0xeb, 0xbc, 0xc9,
        0x7b, 0x62, 0x3c, 0xf5, 0xe1, 0xce, 0xe1, 0xd9, 0x8d, 0x9c, 0xfe, 0x1f,
        0xc7, 0xf8, 0xfb, 0x59, 0xc0, 0x94, 0x0b, 0x2c, 0xd9, 0x7d, 0xbc, 0x96,
        0xeb, 0xb8, 0x79, 0x22, 0x8a, 0x2e, 0xa0, 0x12, 0x1d, 0x42, 0x07, 0xb6,
        0x5d, 0xdb, 0xe1, 0xf6, 0xb1, 0x5d, 0x7b, 0x1f, 0x54, 0x52, 0x1c, 0xa3,
        0x11, 0x9b, 0xf9, 0xeb, 0xbe, 0xb3, 0x95, 0xca, 0xa5, 0x87, 0x3f, 0x31,
        0x18, 0x1a, 0xc9, 0x99, 0x01, 0xec, 0xaa, 0x90, 0xfd, 0x8a, 0x36, 0x35,
        0x5e, 0x12, 0x81, 0xbe, 0x84, 0x88, 0xa1, 0x0d, 0x19, 0x2a, 0x4a, 0x66,
        0xc1, 0x59, 0x3c, 0x41, 0x83, 0x3d, 0x3d, 0xb8, 0xd4, 0xab, 0x34, 0x90,
        0x06, 0x3e, 0x1a, 0x61, 0x74, 0xbe, 0x04, 0xf5, 0x7a, 0x69, 0x1b, 0x9d,
        0x56, 0xfc, 0x83, 0xb7, 0x60, 0xc1, 0x5e, 0x9d, 0x85, 0x34, 0xfd, 0x02,
        0x1a, 0xba, 0x2c, 0x09, 0x72, 0xa7, 0x4a, 0x5e, 0x18, 0xbf, 0xc0, 0x58,
        0xa7, 0x49, 0x34, 0x46, 0x61, 0x59, 0x0e, 0xe2, 0x6e, 0x9e, 0xd2, 0xdb,
        0xfd, 0x72, 0x2f, 0x3c, 0x47, 0xcc, 0x5f, 0x99, 0x62, 0xee, 0x0d, 0xf3,
        0x1f, 0x30, 0x25, 0x20, 0x92, 0x15, 0x4b, 0x04, 0xfe, 0x15, 0x19, 0x1d,
        0xdc, 0x7e, 0x5c, 0x10, 0x21, 0x52, 0x21, 0x91, 0x54, 0x60, 0x8b, 0x92,
        0x41, 0x02, 0x03, 0x01, 0x00, 0x01
    ])
    content = pub_key
    meta_info = MetaInfo(None, 5000, b'\x08\x02\x00\x09')
    # Place the key at corresponding name
    # signer = Sha256WithRsaSigner('/edge/KEY/000', key)
    signer = DigestSha256Signer()
    app.put_data(name, content=content, freshness_period=10000, signer=signer)
    print(f'<< D: {Name.to_str(name)}')
    print(MetaInfo(freshness_period=10000))
    print(f'Content: (size: {len(content)})')
    print('')