Esempio n. 1
0
	def getApplicationKey(self):
		print("getting application key for "+self.appCfg.appName)
		key = Key()
		keyFile = self.appCfg.keyFile
		key.fromPEM(filename=keyFile)
		self.appKey = key
		self.key = key
Esempio n. 2
0
    def publish(key, name, last_segment, content):
        print("Generating: %s" % name)

        # Name
        co_name = Name.Name(name)

        # SignedInfo
        si = ContentObject.SignedInfo()
        si.type = ContentObject.ContentType.CCN_CONTENT_DATA
        si.finalBlockID = last_segment
        si.publisherPublicKeyDigest = key.publicKeyID
        si.keyLocator = Key.KeyLocator(key)

        # ContentObject
        co = ContentObject.ContentObject()
        co.content = content
        co.name = co_name
        co.signedInfo = si

        co.sign(key)
        return co
Esempio n. 3
0
private_pem2 = os.path.join(root, 'private2.pem')
public_pem2 = os.path.join(root, 'public2.pem')

def rm_files(*list):
	for file in list:
		if os.path.exists(file):
			os.remove(file)

rm_files(private_pem1, public_pem1, private_pem2, public_pem2)

k = CCN.getDefaultKey()

k.privateToPEM(filename=private_pem1)
k.publicToPEM(filename=public_pem1)

k2 = Key()
k2.fromPEM(filename=private_pem1)

k2.privateToPEM(filename=private_pem2)
k2.publicToPEM(filename=public_pem2)

assert(filecmp.cmp(private_pem1, private_pem2))
assert(filecmp.cmp(public_pem1, public_pem2))
print(b64encode(k.publicKeyID))
print(b64encode(k2.publicKeyID))
assert(k.publicKeyID == k2.publicKeyID)

del(k2)
rm_files(private_pem2, public_pem2)

k2 = Key()
Esempio n. 4
0
from pyccn import CCN, Name, Interest, ContentObject, Key

k = Key()
k.generateRSA(1024)
del k
Esempio n. 5
0
from pyccn import CCN,Name,Interest,ContentObject,Key

k = Key()
k.generateRSA(1024)
del k
Esempio n. 6
0

def rm_files(*list):
    for file in list:
        if os.path.exists(file):
            os.remove(file)


rm_files(private_pem1, public_pem1, private_pem2, public_pem2)

k = CCN.getDefaultKey()

k.privateToPEM(filename=private_pem1)
k.publicToPEM(filename=public_pem1)

k2 = Key()
k2.fromPEM(filename=private_pem1)

k2.privateToPEM(filename=private_pem2)
k2.publicToPEM(filename=public_pem2)

assert (filecmp.cmp(private_pem1, private_pem2))
assert (filecmp.cmp(public_pem1, public_pem2))
print(b64encode(k.publicKeyID))
print(b64encode(k2.publicKeyID))
assert (k.publicKeyID == k2.publicKeyID)

del (k2)
rm_files(private_pem2, public_pem2)

k2 = Key()
Esempio n. 7
0
 def getApplicationKey(self):
     key = Key()
     keyFile = self.appCfg.keyFile
     key.fromPEM(filename=keyFile)
     self.appKey = key
Esempio n. 8
0
import os, filecmp
from base64 import b64encode, b64decode
from pyccn import Key, _pyccn, CCN

k = CCN.getDefaultKey()

private1_der = k.privateToDER()
public1_der = k.publicToDER()

k2 = Key()
k2.fromDER(private=private1_der)

private2_der = k2.privateToDER()
public2_der = k2.publicToDER()

assert(private1_der == private2_der)
assert(public1_der == public2_der)
assert(k.publicKeyID == k2.publicKeyID)

del(k2)

k2 = Key()
k2.fromDER(public=public1_der)

try:
	private2_der = k2.privateToDER()
except:
	pass
else:
	raise AssertionError("This should fail - this is not a private key")