Esempio n. 1
0
    def get(self):
        loader = ConfigLoader(filename="database.cfg")
        config = loader.get("commitment_scheme")

        db = DBAdapter(config)
        message = MessageModel(db)

        return message.get_all(), 200
Esempio n. 2
0
    def get(self, mid):
        loader = ConfigLoader(filename="database.cfg")
        config = loader.get("commitment_scheme")

        db = DBAdapter(config)
        message = MessageModel(db)

        message_data = message.read(mid)

        return {
            'id': message_data['mid'],
            'owner': message_data['username'],
            'type': message_data['type'],
            'envelop': {
                'message': message_data['message'],
                'signature': message_data['signature']
            }
        }, 200
Esempio n. 3
0
    def post(self, mid):
        loader = ConfigLoader(filename="database.cfg")
        config = loader.get("commitment_scheme")
        json_data = request.get_json()

        db = DBAdapter(config)
        message = MessageModel(db)
        credentials = get_credentials(request)

        is_verified = False
        try:
            is_verified = message.verify(json_data["username"], mid)
        except Exception as e:
            pass

        return {
            'is_verified': is_verified
        }, 200
Esempio n. 4
0
    def post(self, mid):
        loader = ConfigLoader(filename="database.cfg")
        config = loader.get("commitment_scheme")
        json_data = request.get_json()

        db = DBAdapter(config)
        message = MessageModel(db)
        credentials = get_credentials(request)

        message_data = message.reveal(credentials["username"], mid, json_data["secret"])

        return {
            'id': message_data['mid'],
            'owner': message_data['username'],
            'envelop': {
                'message': message_data['message'],
                'signature': message_data['signature']
            }
        }, 200
Esempio n. 5
0
    def post(self):
        loader = ConfigLoader(filename="database.cfg")
        config = loader.get("commitment_scheme")

        db = DBAdapter(config)
        user = UserModel(db)
        json_data = request.get_json()
        uid = user.create(json_data["user"], json_data["password"])
        data = user.read(json_data["user"])

        return {
            'id': data['uid'],
            'username': data['username'],
            'keys': {
                'id': data['kpid'],
                'public': data['public_key'],
                'private': data['private_key']
            }
        }, 200
Esempio n. 6
0
    def wrapper(*args, **kwargs):
        if 'Authorization' not in request.headers:
            raise APIError(
                "Please provide base64 encoded user/pass in 'Authorization' header",
                BAD_REQUEST)

        credentials = get_credentials(request)

        # BAD! Can be cleaned up.
        loader = ConfigLoader(filename="database.cfg")
        config = loader.get("commitment_scheme")
        db = DBAdapter(config)
        user = UserModel(db)
        user_data = user.read(credentials["username"])
        secure_password = SecurePassword()
        treated = secure_password.treat(credentials["password"])

        if credentials and treated == user_data["password"]:
            return func(*args, **kwargs)

        raise APIError("Please provide valid credentials!", UNAUTHORIZED)