Skip to content
Permalink
Browse files

Clean up model and use new upstream Gruvi.

  • Loading branch information...
geertj committed May 31, 2014
1 parent c6df37d commit 82b254380b09b91abea3a61407704f6923c4c371
@@ -594,7 +594,7 @@ static PyMethodDef openssl_methods[] =
PyDoc_STRVAR(openssl_doc, "wrapped OpenSSL methods");


MOD_INITFUNC(openssl)
MOD_INITFUNC(_openssl)
{
PyObject *Pmodule, *Pdict;

@@ -603,11 +603,11 @@ MOD_INITFUNC(openssl)
if (!PyImport_ImportModule("_ssl"))
return MOD_ERROR;

INIT_MODULE(Pmodule, "openssl", openssl_doc, openssl_methods);
INIT_MODULE(Pmodule, "_openssl", openssl_doc, openssl_methods);

if ((Pdict = PyModule_GetDict(Pmodule)) == NULL)
return MOD_ERROR;
if ((openssl_Error = PyErr_NewException("openssl.Error", NULL, NULL)) == NULL)
if ((openssl_Error = PyErr_NewException("_openssl.Error", NULL, NULL)) == NULL)
return MOD_ERROR;
if (PyDict_SetItemString(Pdict, "Error", openssl_Error) == -1)
return MOD_ERROR;
@@ -44,7 +44,7 @@ def __init__(self, options):
"""The *options* argument must be the parsed command-line arguments."""
super(Backend, self).__init__(options)
self._log = logging.get_logger(self)
self._stop_event = gruvi.Signal()
self._stop_event = gruvi.Event()
self._process = None

@classmethod
@@ -65,10 +65,6 @@ def check_options(cls, options):

def run(self):
"""Initialize the backend and run its main loop."""
if not six.PY3:
import bluepass.ssl
bluepass.ssl.patch_ssl_wrap_socket()

self._log.debug('initializing backend components')

self._log.debug('initializing password generator')
@@ -81,8 +77,8 @@ def run(self):
self._log.debug('initializing model')
model = singleton(Model, store)
token = {'id': self.options.auth_token, 'expires': 0,
'rights': {'control_api': True}}
model.add_token(token)
'allow': {'control_api': True}}
model.create_token(token)

self._log.debug('initializing locator')
locator = singleton(Locator)
@@ -111,25 +107,22 @@ def run(self):
if self.options.trace:
tracename = os.path.join(self.options.data_dir, 'backend.trace')
tracefile = open(tracename, 'w')
ctrlapi.set_tracefile(tracefile)
addr = gruvi.util.paddr(self.options.listen)
ctrlapi._set_tracefile(tracefile)
addr = gruvi.paddr(self.options.listen)
ctrlapi.listen(addr)

fname = os.path.join(self.options.data_dir, 'backend.run')
addr = gruvi.util.getsockname(ctrlapi.transport)
runinfo = { 'listen': gruvi.util.saddr(addr), 'pid': os.getpid() }
addr = ctrlapi.addresses[0]
runinfo = { 'listen': gruvi.saddr(addr), 'pid': os.getpid() }
util.write_atomic(fname, json.dumps(runinfo))

self._log.debug('initializing client API')
clientapi = singleton(ClientApiServer)
clientapi.listen()
#self._log.debug('initializing client API')
#clientapi = singleton(ClientApiServer)
#clientapi.listen()

# This is where the backend runs (until stop_event is raised or CTRL-C
# is pressed).
try:
self._stop_event.wait(timeout=None, interrupt=True)
except KeyboardInterrupt:
self._log.info('CTRL-C pressed, exiting')
self._stop_event.wait()

self._log.debug('backend event loop terminated')

@@ -145,4 +138,4 @@ def run(self):

def stop(self):
"""Stop the backend."""
self._stop_event.emit()
self._stop_event.set()
@@ -8,9 +8,9 @@

from __future__ import absolute_import, print_function

import six
import base64
import binascii
from gruvi import compat

Error = binascii.Error

@@ -27,13 +27,13 @@

def encode(b):
"""Encode a string into base-64 encoding."""
if not isinstance(b, compat.binary_type):
if not isinstance(b, six.binary_type):
raise TypeError('expecting bytes')
return base64.b64encode(b).decode('ascii')

def decode(s):
"""Decode a base-64 encoded string."""
if not isinstance(s, compat.string_types):
if not isinstance(s, six.string_types):
raise TypeError('expecting string')
try:
return base64.b64decode(s)
@@ -42,7 +42,7 @@ def decode(s):

def check(s):
"""Check that `s' is a properly encoded base64 string."""
if not isinstance(s, compat.string_types):
if not isinstance(s, six.string_types):
raise TypeError('expecting string')
try:
base64.b64decode(s)
@@ -16,7 +16,7 @@
import math

from bluepass import logging, base64
from bluepass.ext.openssl import *
from bluepass._openssl import *

__all__ = []

@@ -26,7 +26,7 @@ def measure_pbkdf2_speed(prf='hmac-sha1'):
"""Measure the speed of PBKDF2 on this system."""
salt = password = '0123456789abcdef'
length = 1; count = 1000
log = logging.get_logger('measure_pbkdf2_speed()')
log = logging.get_logger()
log.debug('starting PBKDF2 speed measurement')
start = time.time()
while True:
@@ -38,8 +38,8 @@ def measure_pbkdf2_speed(prf='hmac-sha1'):
count *= 2
end = time.time()
speed = int(count / (endrun - startrun))
log.debug('PBKDF2 speed is {} iterations / second', speed)
log.debug('PBKDF2 speed measurement took {:2f}', (end - start))
log.debug('PBKDF2 speed is {:,} iterations/second', speed)
log.debug('PBKDF2 speed measurement took {:.2f} secs', (end - start))
return speed

def pbkdf2_speed(prf='hmac-sha1'):
Oops, something went wrong.

0 comments on commit 82b2543

Please sign in to comment.
You can’t perform that action at this time.