コード例 #1
0
ファイル: keys.py プロジェクト: pombredanne/Dust
 def loadKeypair(self, filename):
   f=open(filename, 'r')
   pair=yaml.load(f.read())
   f.close()
   pubkey=decode(pair[0])
   privkey=decode(pair[1])
   self.keypair=Keypair(Key(privkey, False), Key(pubkey, False))
コード例 #2
0
 def loadKeypair(self, filename):
   f=open(filename, 'r')
   pair=yaml.load(f.read())
   f.close()
   pubkey=decode(pair[0])
   privkey=decode(pair[1])
   self.keypair=Keypair(Key(privkey, False), Key(pubkey, False))
コード例 #3
0
ファイル: dustmailHandler.py プロジェクト: blanu/Dust
  def sendMessage(self, message):
    print('sendMessage '+str(message))

    onion=OnionPacket()
    onion.decodeOnionPacket(self.router.keys.getKeypair(), decode(message))
    frm=encode(onion.sender)
    to=encode(onion.receiver)

    print('frm: '+str(frm))
    print('to: '+str(to))

    if not os.path.exists(self.maildir+'/'+to):
      os.mkdir(self.maildir+'/'+to)

    filename=None
    while not filename or os.path.exists(filename):
      filename=self.makeName(frm, to)
    f=open(filename, 'w')
    f.write(message)
    f.close()

    notifyPrefs=YamlMap('config/dustmail-notify.yaml')
    try:
      mailAddr=notifyPrefs[to]

      addressBook=YamlMap('config/dustmail-addressbook.yaml')
      frmName=self.nameForPubkey(addressBook, frm)
      if not frmName:
        frmName=frm

      notifier=Notifier('*****@*****.**')
      notifier.notify(mailAddr, 'New DustMail Message', "You have a DustMail message from "+frmName+".")
    except KeyError:
      print('No notification set')
コード例 #4
0
ファイル: reader.py プロジェクト: blanu/Dust
  def addInvite(self):
    pf=input("Load invite from Paste or File [P/f]? ")
    if pf=='f':
      filename=input("Load invite from filename: ").strip()
      f=open(filename, 'rb')
      data=f.read()
      f.close()
    else:
      data=decode(input("Past invite: "))

    passwd=input("Decrypt invite with password: "******"Name for this endpoint: ")
    try:
      entry=self.book[name]
    except:
      entry={}
    entry['pubkey']=encode(packet.pubkey)
    entry['tracker']=encodeAddress((invite.ip, invite.port))
    self.book[name]=entry

    self.commandDone.set()

    return entry
    def addInvite(self):
        pf = input("Load invite from Paste or File [P/f]? ")
        if pf == 'f':
            filename = input("Load invite from filename: ").strip()
            f = open(filename, 'rb')
            data = f.read()
            f.close()
        else:
            data = decode(input("Past invite: "))

        passwd = input("Decrypt invite with password: "******"Name for this endpoint: ")
        try:
            entry = self.book[name]
        except:
            entry = {}
        entry['pubkey'] = encode(packet.pubkey)
        entry['tracker'] = encodeAddress((invite.ip, invite.port))
        self.book[name] = entry

        self.commandDone.set()

        return entry
コード例 #6
0
ファイル: reader.py プロジェクト: blanu/Dust
  def foundPeer(self, endkey, peer):
    destkey=decode(peer[0])
    addr=peer[1]

    if self.reader.keys.isKnown(addr) or self.reader.keys.outgoingInvites.getInviteForHost(False, decodeAddress(addr)):
      self.sendMessage(decodeAddress(addr))
    else:
      self.reader.trackback.setPutInviteForPeerCallback(addr, self.foundInvite)
      self.tracker.getInviteForPeer(addr)
  def putInviteForPeer(self, addr, invite):
    print('putInviteForPeer!!! '+str(addr)+' '+str(invite))
    i=InviteMessage()
    i.decodeInviteMessage(decode(invite))
    self.keys.outgoingInvites.addInvite(i)
    if self.keys.outgoingFilename:
      self.keys.saveOutgoingInvites(self.keys.outgoingFilename, self.keys.invitePassword)

    callback=self.callbacks[addr]
    callback(addr, i)
  def foundPeer(self, endkey, peer):
    print('foundPeer!!! '+str(endkey)+' '+str(peer))
    destkey=decode(peer[0])
    addr=peer[1]

    if keys.isKnown(addr) or self.keys.outgoingInvites.getInviteForHost(False, decodeAddress(addr)):
      self.sendMessage(decodeAddress(addr))
    else:
      trackback.setPutInviteForPeerCallback(addr, self.foundInvite)
      tracker.getInviteForPeer(addr)
コード例 #9
0
  def loadKnownHosts(self, filename):
    self.knownHostsFile=filename
    self.knownHosts={}
    if os.path.exists(self.knownHostsFile):
      f=open(filename, 'r')
      hosts=yaml.load(f.read())
      f.close()

      for address, pubkey in hosts.items():
        self.knownHosts[address]=Key(decode(pubkey), False)
コード例 #10
0
ファイル: test-dustmail.py プロジェクト: blanu/Dust
 def foundPeer(self, endkey, peer):
   print('foundPeer!!! '+str(endkey)+' '+str(peer))
   destkey=decode(peer[0])
   addr=peer[1]
   data=self.msg.encode('ascii')
   sessionKey=keypair.createSession(Key(destkey, False))
   print('session '+str(sessionKey.bytes))
   packet=DataPacket()
   packet.createDataPacket(sessionKey.bytes, data, keys.entropy)
   self.dustmail.sendMessage(encode(self.keypair.public.bytes), encode(destkey), encode(packet.packet))
コード例 #11
0
ファイル: keys.py プロジェクト: pombredanne/Dust
  def loadKnownHosts(self, filename):
    self.knownHostsFile=filename
    self.knownHosts={}
    if os.path.exists(self.knownHostsFile):
      f=open(filename, 'r')
      hosts=yaml.load(f.read())
      f.close()

      for address, pubkey in hosts.items():
        self.knownHosts[address]=Key(decode(pubkey), False)
コード例 #12
0
ファイル: trackbackHandler.py プロジェクト: rallen71366/Dust
    def putInviteForPeer(self, addr, invite):
        print("putInviteForPeer!!! " + str(addr) + " " + str(invite))
        i = InviteMessage()
        i.decodeInviteMessage(decode(invite))
        self.keys.outgoingInvites.addInvite(i)
        if self.keys.outgoingFilename:
            self.keys.saveOutgoingInvites(self.keys.outgoingFilename, self.keys.invitePassword)

        callback = self.callbacks[addr]
        callback(addr, i)
コード例 #13
0
ファイル: test-dustmail.py プロジェクト: optionalg/Dust
 def foundPeer(self, endkey, peer):
     print('foundPeer!!! ' + str(endkey) + ' ' + str(peer))
     destkey = decode(peer[0])
     addr = peer[1]
     data = self.msg.encode('ascii')
     sessionKey = keypair.createSession(Key(destkey, False))
     print('session ' + str(sessionKey.bytes))
     packet = DataPacket()
     packet.createDataPacket(sessionKey.bytes, data, keys.entropy)
     self.dustmail.sendMessage(encode(self.keypair.public.bytes),
                               encode(destkey), encode(packet.packet))
    def foundPeer(self, endkey, peer):
        destkey = decode(peer[0])
        addr = peer[1]

        if self.reader.keys.isKnown(
                addr) or self.reader.keys.outgoingInvites.getInviteForHost(
                    False, decodeAddress(addr)):
            self.sendMessage(decodeAddress(addr))
        else:
            self.reader.trackback.setPutInviteForPeerCallback(
                addr, self.foundInvite)
            self.tracker.getInviteForPeer(addr)
コード例 #15
0
ファイル: reader.py プロジェクト: blanu/Dust
  def __init__(self, reader, name, msg):
    self.reader=reader
    self.name=name
    self.msg=msg

    destAddress=self.reader.book[self.name]['tracker']
    dest, outport, v6=decodeAddress(destAddress)
    recipient=self.reader.book[self.name]['pubkey']
    self.endkey=decode(recipient)

    self.reader.trackback.setPutPeerForEndpointCallback(recipient, self.foundPeer)
    self.tracker=TrackerClient(self.reader.router, addr=(dest, outport))
    self.tracker.getPeerForEndpoint(recipient)
    def __init__(self, reader, name, msg):
        self.reader = reader
        self.name = name
        self.msg = msg

        destAddress = self.reader.book[self.name]['tracker']
        dest, outport, v6 = decodeAddress(destAddress)
        recipient = self.reader.book[self.name]['pubkey']
        self.endkey = decode(recipient)

        self.reader.trackback.setPutPeerForEndpointCallback(
            recipient, self.foundPeer)
        self.tracker = TrackerClient(self.reader.router, addr=(dest, outport))
        self.tracker.getPeerForEndpoint(recipient)
コード例 #17
0
ファイル: reader.py プロジェクト: blanu/Dust
  def displayMessage(self, fname):
    f=open(fname, 'r')
    msg=f.read()
    f.close()

    data=decode(msg)

    onion=OnionPacket()
    #print(onion)
    try:
      onion.decodeOnionPacket(self.endpoint, data)
    except:
      traceback.print_exc()
    #print(onion)
    print(onion.data.decode('ascii'))
    def displayMessage(self, fname):
        f = open(fname, 'r')
        msg = f.read()
        f.close()

        data = decode(msg)

        onion = OnionPacket()
        #print(onion)
        try:
            onion.decodeOnionPacket(self.endpoint, data)
        except:
            traceback.print_exc()
        #print(onion)
        print(onion.data.decode('ascii'))
    def load(self, filename, password):
        try:
            f = open(filename, 'r')
        except:
            print('No such file', filename)
            return

        for line in f.readlines():
            data = decode(line.strip())
            packet = InvitePacket()
            packet.decodeInvitePacket(password, data)
            if packet.checkMac():
                self.addInvite(packet.invite)
            else:
                print('Mac check failed, possible a wrong password?')

        f.close()
コード例 #20
0
ファイル: invite.py プロジェクト: blanu/Dust
  def load(self, filename, password):
    try:
      f=open(filename, 'r')
    except:
      print('No such file', filename)
      return

    for line in f.readlines():
      data=decode(line.strip())
      packet=InvitePacket()
      packet.decodeInvitePacket(password, data)
      if packet.checkMac():
        self.addInvite(packet.invite)
      else:
        print('Mac check failed, possible a wrong password?')

    f.close()
    def sendMessage(self, message):
        print('sendMessage ' + str(message))

        onion = OnionPacket()
        onion.decodeOnionPacket(self.router.keys.getKeypair(), decode(message))
        frm = encode(onion.sender)
        to = encode(onion.receiver)

        print('frm: ' + str(frm))
        print('to: ' + str(to))

        if not os.path.exists(self.maildir + '/' + to):
            os.mkdir(self.maildir + '/' + to)

        filename = None
        while not filename or os.path.exists(filename):
            filename = self.makeName(frm, to)
        f = open(filename, 'w')
        f.write(message)
        f.close()

        notifyPrefs = YamlMap('config/dustmail-notify.yaml')
        try:
            mailAddr = notifyPrefs[to]

            addressBook = YamlMap('config/dustmail-addressbook.yaml')
            frmName = self.nameForPubkey(addressBook, frm)
            if not frmName:
                frmName = frm

            notifier = Notifier('*****@*****.**')
            notifier.notify(
                mailAddr, 'New DustMail Message',
                "You have a DustMail message from " + frmName + ".")
        except KeyError:
            print('No notification set')
コード例 #22
0
ファイル: test-curve.py プロジェクト: blanu/Dust
from dust.crypto.curve import Keypair, Key
from dust.core.util import encode, decode

keypair=Keypair(Key(decode('48ef7b8c0c6343b332a02862335c11e0cd2b38f0d7d6a3647a7f8f2661d1c946'), False), Key(decode('43aafb64bc96460f3928f6068b2a01aa87bac16da6dc034b4525d1837e9cb85e'), False))
session=keypair.createSessionBytes(decode('77516be967ad1a68632a3c8b08c9e032d23ff5b764a7fe49461b9c12b2da0c32'))
print(encode(session))

コード例 #23
0
from dust.crypto.keys import KeyManager
from dust.core.data_packet import DataPacket
from dust.core.util import encode, decode

keys=KeyManager()
#psk=keys.entropy.getBytes(32)

psk=decode("5475e69147a1463ef65116ccd8b3d732ead5ce8b5c9b0e61eb4c218fe6165013")

packet=DataPacket()
packet.createDataPacket(psk, b"test #3", keys.entropy)
print('packet:', packet)
print('packetData:', encode(packet.packet))

print('------------------------')

p2=DataPacket()
p2.decodeDataPacket(psk, packet.packet)
print(p2)
print('checkMac:', p2.checkMac())
print('checkTimestamp:', p2.checkTimestamp())
  def putTrackerInvite(self, invite):
    print('putTrackerInvite: '+str(invite))

    callback=self.callbacks['tracker']
    print('callback: '+str(callback))
    callback(decode(invite))
コード例 #25
0
ファイル: add.py プロジェクト: blanu/Dust
keys=KeyManager()
keys.setInvitePassword(passwd)
keys.loadKnownHosts('config/knownhosts.yaml')
keys.loadKeypair('config/id.yaml')
keys.loadIncomingInvites('config/incoming_invites.ip')
keys.loadOutgoingInvites('config/outgoing_invites.ip')
endpoint=keys.loadEndpoint(os.path.expanduser('~/.dust/endpoint.yaml'))

pf=input("Load invite from Paste or File [P/f]? ")
if pf=='f':
  filename=input("Load invite from filename: ").strip()
  f=open(filename, 'rb')
  data=f.read()
  f.close()
else:
  data=decode(input("Past invite: "))

passwd=input("Decrypt invite with password: "******"pubkey: "+encode(packet.pubkey))
print("invite: "+encode(packet.invite))
invite=InviteMessage()
invite.decodeInviteMessage(packet.invite)
keys.addInvite(invite)

name=input("Name for this endpoint: ")
book=YamlMap('config/dustmail-addressbook.yaml')
try:
  entry=book[name]
except:
keys = KeyManager()
keys.setInvitePassword(passwd)
keys.loadKnownHosts('config/knownhosts.yaml')
keys.loadKeypair('config/id.yaml')
keys.loadIncomingInvites('config/incoming_invites.ip')
keys.loadOutgoingInvites('config/outgoing_invites.ip')
endpoint = keys.loadEndpoint(os.path.expanduser('~/.dust/endpoint.yaml'))

pf = input("Load invite from Paste or File [P/f]? ")
if pf == 'f':
    filename = input("Load invite from filename: ").strip()
    f = open(filename, 'rb')
    data = f.read()
    f.close()
else:
    data = decode(input("Past invite: "))

passwd = input("Decrypt invite with password: "******"pubkey: " + encode(packet.pubkey))
print("invite: " + encode(packet.invite))
invite = InviteMessage()
invite.decodeInviteMessage(packet.invite)
keys.addInvite(invite)

name = input("Name for this endpoint: ")
book = YamlMap('config/dustmail-addressbook.yaml')
try:
    entry = book[name]
except:
コード例 #27
0
ファイル: trackbackHandler.py プロジェクト: rallen71366/Dust
    def putTrackerInvite(self, invite):
        print("putTrackerInvite: " + str(invite))

        callback = self.callbacks["tracker"]
        print("callback: " + str(callback))
        callback(decode(invite))
print('Host: '+str(host))

keys=KeyManager()
keys.setInvitePassword(passwd)
keys.loadKnownHosts('config/knownhosts.yaml')
keys.loadKeypair('config/id.yaml')
keys.loadIncomingInvites('config/incoming_invites.ip')
keys.loadOutgoingInvites('config/outgoing_invites.ip')

endpoint=keys.loadEndpoint(os.path.expanduser('~/.dust/endpoint.yaml'))

keypair=keys.getKeypair()
pubkey=keypair.public
pubkeyhex=encode(pubkey.bytes)

endkey=decode(recipient)

class PendingMessage:
  def __init__(self, keys, router, tracker, trackback, keypair, endkey, msg):
    self.keys=keys
    self.router=router
    self.keypair=keypair
    self.endkey=endkey
    self.msg=msg
    trackback.setPutPeerForEndpointCallback(encode(endkey), self.foundPeer)
    tracker.getPeerForEndpoint(encode(endkey))

  def foundPeer(self, endkey, peer):
    print('foundPeer!!! '+str(endkey)+' '+str(peer))
    destkey=decode(peer[0])
    addr=peer[1]
コード例 #29
0
from dust.crypto.curve import Keypair, Key
from dust.core.util import encode, decode

keypair = Keypair(
    Key(
        decode(
            '48ef7b8c0c6343b332a02862335c11e0cd2b38f0d7d6a3647a7f8f2661d1c946'
        ), False),
    Key(
        decode(
            '43aafb64bc96460f3928f6068b2a01aa87bac16da6dc034b4525d1837e9cb85e'
        ), False))
session = keypair.createSessionBytes(
    decode('77516be967ad1a68632a3c8b08c9e032d23ff5b764a7fe49461b9c12b2da0c32'))
print(encode(session))