Пример #1
0
 def test_symmetric(self):
     for _ in range(10):
         n = randint(3, 100)
         r = randint(1, n)
         secret = urandom(32)
         frags = ssss.split(secret, n, r)
         recovered = ssss.combine(r, frags[:r])
         self.assertEqual(secret, recovered)
Пример #2
0
def post_handler(data, request):
    '''
    returns a json response with error messages etc
    '''
    emails = (['Escrower',data['escrower'],data['encypt_emails']],
        ['Buyer',data['buyer'], data['encypt_emails']],
        ['Seller',data['sender'],data['encypt_emails']]
        )
    note = ''
    if data['note']:
        note = data.get('note', u'').encode('utf8')
    result = {}
    if len(emails) == 3:
       # Test GPG.
        using_gpg = False
        for item in emails:
            recipient, use_gpg = item[1], item[2]
            if not use_gpg:
                continue
            using_gpg = True
            _, failed = gpg.encrypt('test', recipient)
            #if failed:
                #result['error'] =  'Failed to obtain public for key %s' %recipient
                #messages.error(request, 'Failed to obtain public for key %s' %recipient);
        if using_gpg:
            gpg_note = ('If GPG fails for whatever reason, one or more emails '
                    'will be sent in plain text.')
        else:
            gpg_note = ''
        # Generate a new private key, and a bitcoin address from it.
        pk, wif_pk = bitcoin.privatekey()
        addr = bitcoin.address(pk)
        # Split the private key in m parts.
        shares = ssss.split(wif_pk, 2, 3)
        # Send the shares by email
        for share, email in zip(shares, emails):
            message = "%s" %share
            result = True
            print email
            result = mailer.sharesMail([note, share, addr,
                email[0], email[1], str(int(email[2]))]
                )
        return result
Пример #3
0
def post_handler(data, request):
    '''
    returns a json response with error messages etc
    '''
    emails = (['Escrower', data['escrower'], data['encypt_emails']
               ], ['Buyer', data['buyer'], data['encypt_emails']],
              ['Seller', data['sender'], data['encypt_emails']])
    note = ''
    if data['note']:
        note = data.get('note', u'').encode('utf8')
    result = {}
    if len(emails) == 3:
        # Test GPG.
        using_gpg = False
        for item in emails:
            recipient, use_gpg = item[1], item[2]
            if not use_gpg:
                continue
            using_gpg = True
            _, failed = gpg.encrypt('test', recipient)
            #if failed:
            #result['error'] =  'Failed to obtain public for key %s' %recipient
            #messages.error(request, 'Failed to obtain public for key %s' %recipient);
        if using_gpg:
            gpg_note = ('If GPG fails for whatever reason, one or more emails '
                        'will be sent in plain text.')
        else:
            gpg_note = ''
        # Generate a new private key, and a bitcoin address from it.
        pk, wif_pk = bitcoin.privatekey()
        addr = bitcoin.address(pk)
        # Split the private key in m parts.
        shares = ssss.split(wif_pk, 2, 3)
        # Send the shares by email
        for share, email in zip(shares, emails):
            message = "%s" % share
            result = True
            print email
            result = mailer.sharesMail(
                [note, share, addr, email[0], email[1],
                 str(int(email[2]))])
        return result
Пример #4
0
            if failed:
                reply = {'error': 'Failed to obtain public for key %s' %
                        recipient}
                self.write(json.dumps(reply))
                return
        if using_gpg:
            gpg_note = ('If GPG fails for whatever reason, one or more emails '
                    'will be sent in plain text.')
        else:
            gpg_note = ''

        # Generate a new private key, and a bitcoin address from it.
        pk, wif_pk = bitcoin.privatekey()
        addr = bitcoin.address(pk)
        # Split the private key in m parts.
        shares = ssss.split(wif_pk, n, m)
        # Send the shares by email.
        for share, email in zip(shares, data['email']):
            self.sock.send_multipart([note, share, addr,
                email[0], email[1], str(int(email[2]))])

        self.write(json.dumps({'success': addr, 'note': gpg_note}))

class GPGHandler(web.RequestHandler):
    def post(self):
        if 'pubkey' not in self.request.files:
            # Invalid POST
            self.write(INVALID)
            return
        data = self.request.files['pubkey'][0]
        body = data['body'].strip()