Example #1
0
def ledgerx_main():
    """\
    pyledgerx application entry point.
    """
    # Parse command line arguments
    cmd = CommandLine()
    args = cmd.parse()

    if args.generate_keypair:
        # Extract both the filepath and dirpath
        filepath = args.generate_keypair
        dirpath = os.path.dirname(filepath)

        # Check if dirpath is accessible and writable
        if not os.access(dirpath, os.W_OK | os.X_OK):
            _die('cannot access or write to {0}'.format(dirpath))

        # Generate the key pair certificate file
        _out('generating new key pair')
        KeyPair.generate_certificate(filepath)
        _dir('client key pair has been successfully generated', True)

    if args.fetch_exchange_key:
        domain = args.fetch_exchange_key
        url = 'https://' + domain + settings.EXCHANGE_CERTIFICATE_ENDPOINT
        print(requests.get(url).text)
Example #2
0
    def test_keypair_generate_load_certificate(self):
        filepath = '/tmp/test_ledgerx.cert'
        keypair0 = KeyPair.generate().save_certificate(filepath)
        keypair1 = KeyPair.load_certificate(filepath)
        self.assertEqual(keypair0, keypair1)

        with open(filepath, 'rb') as fd:
            keypair1 = KeyPair.load_certificate(fd.read())
        self.assertEqual(keypair0, keypair1)
Example #3
0
 def test_keypair_io_interface(self):
     buff = io.BytesIO()
     keypair0 = KeyPair.generate().save_certificate(buff)
     keypair1 = KeyPair.load_certificate(buff.getvalue())
     self.assertEqual(keypair0, keypair1)
Example #4
0
 def test_keypair_generate(self):
     keypair = KeyPair.generate()
     self.assertIn(keypair.public, keypair)
     self.assertIn(keypair.private, keypair)
Example #5
0
def generate_session_keypairs():
    """\
    Generate a server and a client key pairs.
    """
    return (KeyPair.generate(), KeyPair.generate())