Ejemplo n.º 1
0
def run_test1():
    with CTClient() as c:
        # syncronous calls
        m.refresh()
        print('MsgStore opened as ' + str(m))
        print()
        hdrs = m.get_headers()
        print('MsgStore all headers : ' + str(hdrs))
        print()
        peers = m.get_peers()
        print('MsgStore found ' + str(len(peers)) + ' peers : ')
        for p in peers:
            print('    ' + str(p))
        print()
        for i in range(0,5):
            h = random.choice(hdrs)
            msg = m.get_message(h)
            print('random message retreived as ' + msg.serialize().decode())
            msg_test = m.get_message_by_id(h.Iraw())
            assert msg == msg_test
            #print('random message retreived as ' + msg_test.serialize().decode())
            print()
        Apriv = PrivateKey()
        Apriv.randomize(4)
        Apub = PublicKey.deserialize(Apriv.serialize_pubkey())
        Bpriv = PrivateKey()
        Bpriv.randomize(4)
        Bpub = PublicKey.deserialize(Apriv.serialize_pubkey())
        mtxt = 'the quick brown fox jumped over the lazy dog'
        for ver in ['0200']:
            msg = Message.encode(mtxt, Bpub, Apriv, version=ver)
            r = m.post_message(msg)
            print('message posted, server metadata' + str(r))
        print()
Ejemplo n.º 2
0
def run_test4():
    with CTClient() as c:
        # syncronous call
        m.refresh()
        print('MsgStore opened as ' + str(m))
        print()
        Apriv = PrivateKey()
        Apriv.randomize(4)
        Apub = PublicKey.deserialize(Apriv.serialize_pubkey())
        Bpriv = PrivateKey()
        Bpriv.randomize(4)
        Bpub = PublicKey.deserialize(Apriv.serialize_pubkey())
        # asynchronous calls
        for ver in ['0200']:
            mtxt = 'the quick brown fox jumped over the lazy dog'
            msgs = []
            print('Encoding messages ')
            print()
            for i in range(0,5):
                msg = Message.encode(mtxt, Bpub, Apriv, version=ver)
                msgs.append(msg)
            print('Posting messages')
            print()
            slist = []
            for msg in msgs:
                h = MessageHeader.deserialize(msg.serialize_header())
                r = yield m.post_message(msg, callback=register_message)
                print('sent async post for ' + h.serialize().decode())
                print()
                mtxt += 'the quick brown fox jumped over the lazy dog'
Ejemplo n.º 3
0
def run_test1():
    with CTClient() as c:
        # syncronous calls
        m.refresh()
        print('MsgStore opened as ' + str(m))
        print()
        hdrs = m.get_headers()
        print('MsgStore all headers : ' + str(hdrs))
        print()
        peers = m.get_peers()
        print('MsgStore found ' + str(len(peers)) + ' peers : ')
        for p in peers:
            print('    ' + str(p))
        print()
        for i in range(0, 5):
            h = random.choice(hdrs)
            msg = m.get_message(h)
            print('random message retreived as ' + msg.serialize().decode())
            msg_test = m.get_message_by_id(h.Iraw())
            assert msg == msg_test
            #print('random message retreived as ' + msg_test.serialize().decode())
            print()
        Apriv = PrivateKey()
        Apriv.randomize(4)
        Apub = PublicKey.deserialize(Apriv.serialize_pubkey())
        Bpriv = PrivateKey()
        Bpriv.randomize(4)
        Bpub = PublicKey.deserialize(Apriv.serialize_pubkey())
        mtxt = 'the quick brown fox jumped over the lazy dog'
        for ver in ['0200']:
            msg = Message.encode(mtxt, Bpub, Apriv, version=ver)
            r = m.post_message(msg)
            print('message posted, server metadata' + str(r))
        print()
Ejemplo n.º 4
0
def run_test4():
    with CTClient() as c:
        # syncronous call
        m.refresh()
        print('MsgStore opened as ' + str(m))
        print()
        Apriv = PrivateKey()
        Apriv.randomize(4)
        Apub = PublicKey.deserialize(Apriv.serialize_pubkey())
        Bpriv = PrivateKey()
        Bpriv.randomize(4)
        Bpub = PublicKey.deserialize(Apriv.serialize_pubkey())
        # asynchronous calls
        for ver in ['0200']:
            mtxt = 'the quick brown fox jumped over the lazy dog'
            msgs = []
            print('Encoding messages ')
            print()
            for i in range(0, 5):
                msg = Message.encode(mtxt, Bpub, Apriv, version=ver)
                msgs.append(msg)
            print('Posting messages')
            print()
            slist = []
            for msg in msgs:
                h = MessageHeader.deserialize(msg.serialize_header())
                r = yield m.post_message(msg, callback=register_message)
                print('sent async post for ' + h.serialize().decode())
                print()
                mtxt += 'the quick brown fox jumped over the lazy dog'
Ejemplo n.º 5
0
def run_test10():
    with CTClient() as c:
        # synchronous onion post
        m.refresh()
        m2.refresh()
        peers = m.get_peers()
        hdrs = m.get_headers()
        onions = []
        for p in peers:
            onion = MsgStore(p['host'], p['port'])
            onion.refresh()
            if onion.Pkey is not None:
                onions.append(onion)
        nonion = len(onions)
        print('found ' + str(nonion) + ' onion hosts')
        for o in onions:
            print('    ' + str(o))
            onion._sync_headers()
        Apriv = PrivateKey()
        Apriv.randomize(4)
        Apub = PublicKey.deserialize(Apriv.serialize_pubkey())
        Bpriv = PrivateKey()
        Bpriv.randomize(4)
        Bpub = PublicKey.deserialize(Apriv.serialize_pubkey())
        # asynchronous calls
        for ver in ['0200']:
            mtxt = 'the quick brown fox jumped over the lazy dog'
            msgs = []
            print('Encoding messages ')
            print()
            for i in range(0, 5):
                msg = Message.encode(mtxt, Bpub, Apriv, version=ver)
                msgs.append(msg)
            for msg in msgs:
                h = MessageHeader.deserialize(msg.serialize_header())
                orand = random.sample(onions, min(nonion - 1, 3))
                print('posting via onions')
                for o in orand:
                    print('    ' + str(o))
                print()
                r = yield orand[0].post_message(msg,
                                                nak=nak,
                                                onions=orand[1:],
                                                callback=register_message)
                # conf = m.post_message(msg, nak=nak, onions=[m, m2])
                # conf = m2.post_message(msg, nak=nak, onions=[m2])
                print('sent post for header ' + h.serialize().decode())
                print()  # msg = m.get_message(h, nak=nak, onions=[m, m2])
Ejemplo n.º 6
0
def run_test10():
    with CTClient() as c:
        # synchronous onion post
        m.refresh()
        m2.refresh()
        peers = m.get_peers()
        hdrs = m.get_headers()
        onions = []
        for p in peers:
            onion = MsgStore(p['host'], p['port'])
            onion.refresh()
            if onion.Pkey is not None:
                onions.append(onion)
        nonion = len(onions)
        print('found ' + str(nonion) + ' onion hosts')
        for o in onions:
            print('    ' + str(o))
            onion._sync_headers()
        Apriv = PrivateKey()
        Apriv.randomize(4)
        Apub = PublicKey.deserialize(Apriv.serialize_pubkey())
        Bpriv = PrivateKey()
        Bpriv.randomize(4)
        Bpub = PublicKey.deserialize(Apriv.serialize_pubkey())
        # asynchronous calls
        for ver in ['0200']:
            mtxt = 'the quick brown fox jumped over the lazy dog'
            msgs = []
            print('Encoding messages ')
            print()
            for i in range(0,5):
                msg = Message.encode(mtxt, Bpub, Apriv, version=ver)
                msgs.append(msg)
            for msg in msgs:
                h = MessageHeader.deserialize(msg.serialize_header())
                orand = random.sample(onions, min(nonion-1,3))
                print('posting via onions')
                for o in orand:
                    print('    ' + str(o))
                print()
                r = yield orand[0].post_message(msg, nak=nak, onions=orand[1:], callback=register_message)
                # conf = m.post_message(msg, nak=nak, onions=[m, m2])
                # conf = m2.post_message(msg, nak=nak, onions=[m2])
                print('sent post for header ' + h.serialize().decode())
                print()# msg = m.get_message(h, nak=nak, onions=[m, m2])
Ejemplo n.º 7
0
from ciphrtxt.message import Message
from argparse import ArgumentParser
import sys

parser = ArgumentParser(
    description=
    'read message plaintext from stdin and write encoded message to stdout')
parser.add_argument('recipient',
                    help='recipient public key (hint: starts with P0100)')
parser.add_argument('--sender',
                    default=None,
                    help='sender private key (optional, omit for anonymous)')
clargs = parser.parse_args()

f_key = None

if clargs.sender:
    f_key = PrivateKey.deserialize(clargs.sender)
    if f_key is None:
        print('Error: unable to parse sender key', file=sys.stderr)
        exit()

t_key = PublicKey.deserialize(clargs.recipient)
if t_key is None:
    print('Error: unable to parse recipient key', file=sys.stderr)
    exit()

ptext = sys.stdin.read()
msg = Message.encode(ptext, t_key, f_key)
sys.stdout.write(msg.serialize().decode())
Ejemplo n.º 8
0
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

from ciphrtxt.keys import PrivateKey
from ciphrtxt.topic import TopicKey
from ciphrtxt.message import Message

topics = [ "#ciphrtxt", "#crypto", "#privacy", "#privacz", "#security", "#securitz" ]

ptext = 'the quick brown fox jumped over the lazy dog'

pkey = PrivateKey()
pkey.randomize()

for topic in topics:
    k = TopicKey(topic)
    print('topic = ' + topic)
    print('key = ' + str(k))
    assert k is not None
    m = Message.encode(ptext, k)
    assert m is not None
    print('encoded = ' + str(m))
    assert m.decode(k)
    print('decoded = ' + m.ptxt)
    
Ejemplo n.º 9
0
test_keys = 1500
test_msgs = 1500

print('creating alice keys')
alice = PrivateKey()
alice.randomize(4)
aliceP = PublicKey.deserialize(alice.serialize_pubkey())
print('creating bob keys')
bob = PrivateKey()
bob.randomize(4)
bobP = PublicKey.deserialize(bob.serialize_pubkey())
print('keys complete')

mtxt = 'the quick brown fox jumped over the lazy dog'
msg1 = Message.encode(mtxt, bobP, alice, progress_callback=progress, version="0100")
print('message1 = ' + str(msg1))
print(' header ' + str(msg1.serialize_header()))
print(' hash ' + str(sha256(msg1.serialize_header()).hexdigest()))
msg1a = Message.deserialize(msg1.serialize())
print('message1a = ' + str(msg1a))
print(' header ' + str(msg1a.serialize_header()))
print(' hash ' + str(sha256(msg1a.serialize_header()).hexdigest()))
if msg1a.decode(bob):
    print('decoded:', msg1a.ptxt)
msg2 = Message.encode_impersonate(mtxt, aliceP, bob, progress_callback=progress, version="0100")
print('message2 = ' + str(msg2))
print(' header ' + str(msg2.serialize_header()))
print(' hash ' + str(sha256(msg2.serialize_header()).hexdigest()))
msg2a = Message.deserialize(msg2.serialize())
print('message2a = ' + str(msg2a))
test_msgs = 1500

print('creating alice keys')
alice = PrivateKey()
alice.randomize(4)
aliceP = PublicKey.deserialize(alice.serialize_pubkey())
print('creating bob keys')
bob = PrivateKey()
bob.randomize(4)
bobP = PublicKey.deserialize(bob.serialize_pubkey())
print('keys complete')

mtxt = 'the quick brown fox jumped over the lazy dog'
msg1 = Message.encode(mtxt,
                      bobP,
                      alice,
                      progress_callback=progress,
                      version="0100")
print('message1 = ' + str(msg1))
print(' header ' + str(msg1.serialize_header()))
print(' hash ' + str(sha256(msg1.serialize_header()).hexdigest()))
msg1a = Message.deserialize(msg1.serialize())
print('message1a = ' + str(msg1a))
print(' header ' + str(msg1a.serialize_header()))
print(' hash ' + str(sha256(msg1a.serialize_header()).hexdigest()))
if msg1a.decode(bob):
    print('decoded:', msg1a.ptxt)
msg2 = Message.encode_impersonate(mtxt,
                                  aliceP,
                                  bob,
                                  progress_callback=progress,
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

from ciphrtxt.keys import PrivateKey
from ciphrtxt.topic import TopicKey
from ciphrtxt.message import Message

topics = [
    "#ciphrtxt", "#crypto", "#privacy", "#privacz", "#security", "#securitz"
]

ptext = 'the quick brown fox jumped over the lazy dog'

pkey = PrivateKey()
pkey.randomize()

for topic in topics:
    k = TopicKey(topic)
    print('topic = ' + topic)
    print('key = ' + str(k))
    assert k is not None
    m = Message.encode(ptext, k)
    assert m is not None
    print('encoded = ' + str(m))
    assert m.decode(k)
    print('decoded = ' + m.ptxt)