Beispiel #1
0
def setup_app():
    servers = {
        "api": setup_api_app,
        "dashboard": setup_dashboard_app,
    }
    server_type = config_name.split("_")[0]
    app = servers[server_type]()

    rset = app.config["REDIS_SETTIGNS"]["session"]
    r = redis.Redis(host=rset["host"], port=rset["port"], db=rset["db"])
    app.session_interface = RedisSessionInterface(redis=r)

    sentry.init_app(app, logging=True, level=logging.ERROR)
    init_logging(app, server_type)
    return app
def create_app(mode = "production"):
	global app
	app = Flask("application")
	app.session_interface = RedisSessionInterface()

	global app_run_args
	app_run_args = {'port': 5000, 'host': '127.0.0.1'}

	if mode == "production":
		app.debug = False
	elif mode == "dev":
		app.debug = True
	else:
		logging.error("Did not recognize mode '%s'" % mode)

	import application.route
Beispiel #3
0
class PublicKeyStorage:
    def __init__(self, redis):
        self.redis = redis

    def fetch_user_pem(self, username):
        return self.redis.get('user:{}:public_key'.format(username))

    def store_user_pem(self, username, public_key_pem):
        self.redis.set('user:{}:public_key'.format(username), public_key_pem)


app = Flask(__name__)
app.config.from_pyfile('config.py')
redis = Redis(**app.config['REDIS_CONFIG'])
app.extensions['public_keys'] = PublicKeyStorage(redis)
app.session_interface = RedisSessionInterface(redis)
app.debug = True

app.register_blueprint(signature_login_poc)


@app.after_request
def add_csp(response):
    response.headers['Content-Security-Policy'] = app.config['CSP_HEADER']
    return response


@app.route('/')
def main():
    return render_template('main.html')
from Crypto.Hash import SHA256
from random import randint

import binascii, os, json
import yaml, requests

from redis_session import RedisSessionInterface

# Load and parse config file
config = yaml.load(file('config.yaml', 'r'))
encrypt = config['encrypt']

app = Flask(__name__, static_url_path='/static')
app.config['recaptcha'] = config['recaptcha']
app.debug = config['debug']
app.session_interface = RedisSessionInterface(config['redis'])


def aesEncrypt(text, secKey):
    pad = 16 - len(text) % 16
    text = text + pad * chr(pad)
    encryptor = AES.new(secKey, 1)
    cipherText = encryptor.encrypt(text)
    cipherText = binascii.b2a_hex(cipherText).upper()
    return cipherText


def encrypted_request(jsonDict):
    jsonStr = json.dumps(jsonDict, separators=(",", ":"))
    encText = aesEncrypt(jsonStr, secretKey)
    data = {
Beispiel #5
0
# Stream module to keep track of current streams
from streams import Streams

# Configuration settings
import settings

# Main Flask app
app = Flask(__name__)

# List of stream stored in Streams class
active_streams = Streams()

# Store session info in redis db
redis = Redis(settings.REDIS_SERVER)
app.session_interface = RedisSessionInterface(redis=redis,
                                              domain=settings.DOMAIN)


def valid_session():
    """ Retrieve session info from redis based upon stored cookie session id
        and then check if the OAuth info has expired.  If it is still valid
        then let user in since the presence of this OAuth key implies that
        the user has successfully logged in at some point. """
    if session is None or session.get('oauth_token', None) is None:
        app.logger.debug('INVALID Session: {}'.format(session))
        return False
    else:
        app.logger.debug('VALID Session: {}'.format(session))

        # it appears we have a valid session, but check if it has expired.....
        now = datetime.datetime.now().timestamp()