Beispiel #1
0
class UserPreferences(BaseTable):

    __tablename__ = 'user_preferences'

    id = db.Column(db.Integer, primary_key=True)
    first_name = db.Column(db.String(64))
    last_name = db.Column(db.String(64))
    phone_number = db.Column(db.String(64))
    password_hint = db.Column(db.String(128))

    #language
    #timezone
    #trusted_users

    def __init__(self,
                 first_name=None,
                 last_name=None,
                 phone_number=None,
                 password_hint=None):
        self.first_name = first_name
        self.last_name = last_name
        self.phone_number = phone_number
        self.password_hint = password_hint

    def __repr__(self):
        return '<UserPreferences %r>' % (self.id)
Beispiel #2
0
class Device(BaseTable):

    __tablename__ = 'device'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(64), unique=True)
    make = db.Column(db.String(120))
    model = db.Column(db.String(120))
    client_name = db.Column(db.String(120))
    #client_version
    os_name = db.Column(db.String(120))
    #os_version
    last_auth_ip = db.Column(IPAddressType)

    #user_agent

    def __init__(self,
                 name=None,
                 make=None,
                 model=None,
                 client_name=None,
                 os_name=None,
                 user_agent=None):
        self.name = name
        self.make = make
        self.model = model
        self.client_name = client_name
        self.os_name = os_name
        self.user_agent = user_agent

    def __repr__(self):
        return '<Device %r>' % (self.name)
Beispiel #3
0
class WalletRecord(Record):

	__tablename__ = 'wallet_records'

	id = db.Column(db.Integer, db.ForeignKey('records.id'), primary_key=True)
	card_type = db.Column(db.String(128))
	card_number = db.Column(db.Integer, nullable=False)
	name_on_card = db.Column(db.String(128), nullable=False)
	expiration_date = db.Column(db.String(5), nullable=False)
	cvc_code = db.Column(db.Integer, nullable=False)
	zip_code = db.Column(db.Integer, nullable=False)

	__mapper_args__ = {'polymorphic_identity': 'wallet_records'}

	def __init__(self, name, card_number, name_on_card, expiration_date, cvc_code, zip_code, description=None, notes=None):
		self.name = name
		self.card_number = card_number
		self.name_on_card = name_on_card
		self.expiration_date = expiration_date
		self.cvc_code = cvc_code
		self.zip_code = zip_code
		self.description = description
		self.notes = notes

	def __repr__(self):
		return '<WalletRecord %r>' % self.card_name
Beispiel #4
0
class PasswordItem(BaseTable):

    __tablename__ = 'passwords'

    digest_key = db.Column(db.String(64))
    salt = db.Column(db.String(32))
    length = db.Column(db.Integer)
    #encryption
    #history
    flags = db.Column(ScalarListType())
Beispiel #5
0
class NoteRecord(Record):

	__tablename__ = 'note_records'

	id = db.Column(db.Integer, db.ForeignKey('records.id'), primary_key=True)
	note_type = db.Column(db.String(64))
	fields = db.Column(JSONType)

	__mapper_args__ = {'polymorphic_identity': 'note_records'}

	def __init__(self, name, note_type=None):
		self.name = name
		if not note_type:
			self.note_type = "Blank"
			self.fields = {}
		else:
			assert note_type in NOTE_FIELDS
			self.note_type = note_type
		try:
			self.fields = json.loads(NOTE_FIELDS[note_type])
		except Exception as e:
			print(e)

	def __repr__(self):
		return '<NoteRecord %r>' % self.name
Beispiel #6
0
class Record(BaseTable):

	__tablename__ = 'records'

	name = db.Column(db.String(128), unique=True, nullable=False)
	description = db.Column(db.String(200))
	starred = db.Column(db.Boolean, default=False)
	reprompt = db.Column(db.Boolean, default=False)
	color = db.Column(db.String(36))
	notes = db.Column(db.String(128))
	details = db.Column(JSONType())
	attachments = db.Column(ScalarListType())
	history = db.Column(ScalarListType())
	type = db.Column(db.String(50))

	__mapper_args__ = {
		'polymorphic_identity':'records',
		'polymorphic_on': type
	}

	def _get_name(self):
		return self.name
	def _get_description(self):
		return self.description
	def _get_starred(self):
		return self.starred
	def _get_reprompt(self):
		return self.reprompt
	def _get_color(self):
		return self.color
	def _get_notes(self):
		return self.notes
	def _get_flags(self):
		pass
	def _get_tags(self):
		pass
	def _get_attachments(self):
		pass
	def _get_history(self):
		pass

	def change_description(self):
		pass

	def change_color(self):
		pass
Beispiel #7
0
class User(UserMixin, BaseTable):

    __tablename__ = 'user'

    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(32), unique=True, nullable=False)
    email = db.Column(db.String(120), unique=True, nullable=False, index=True)
    password_hash = db.Column(String(128))

    #device = db.Column(db.Integer, ForeignKey('device.id'), nullable=False)
    #preferences
    #history

    def __init__(self, username, email, password):
        self.username = username
        self.email = email
        self._set_password(password)

    def _set_password(self, plaintext):
        self.password_hash = generate_password_hash(plaintext)

    def is_correct_password(self, plaintext):
        return check_password_hash(self.password_hash, plaintext)

    def get_reset_password_token(self, expires_in=600):
        return jwt.encode(
            {
                'reset_password': self.id,
                'exp': time() + expires_in
            },
            app.config['SECRET_KEY'],
            algorithm='HS256').decode('utf-8')

    @staticmethod
    def verify_reset_password_token(token):
        try:
            id = jwt.decode(token,
                            app.config['SECRET_KEY'],
                            algorithms=['HS256'])['reset_password']
        except:
            return
        return User.query.get(id)

    def __repr__(self):
        return '<User %r>' % (self.username)
Beispiel #8
0
class ServicePasswordRules(db.Model):
    service_id = db.Column(db.Integer, primary_key=True)
    symbols = db.Column(db.Boolean, default=True)
    alphabet = db.Column(db.String(32), default='')
    min_password_length = db.Column(db.Integer, default=8)
    max_password_length = db.Column(db.Integer, default=None)
    min_required_uppercase = db.Column(db.Integer, default=None)
    min_required_numbers = db.Column(db.Integer, default=None)
    min_required_special_chars = db.Column(db.Integer, default=None)
Beispiel #9
0
class FileRecord(Record):

	__tablename__ = 'file_records'

	id = db.Column(db.Integer, db.ForeignKey('records.id'), primary_key=True)
	encrypted_filename = db.Column(db.String(128))
	unencrypted_filename = db.Column(db.String(128))
	extension = db.Column(db.String(6))
	encrypted_content = db.Column(db.LargeBinary)
	file_path = db.Column(db.String(128))
	parent_id = db.Column(db.Integer, default=None)
	unencrypted_file_size = db.Column(db.Integer)

	__mapper_args__ = {'polymorphic_identity': 'file_records'}

	def __init__(self, name=None, encrypted_filename=None, unencrypted_filename=None, unencrypted_content=None, file_path=None, description=None, notes=None):
		self.name = name
		self.encrypted_filename = encrypted_filename
		self.file_path = file_path
		self.description = description
		self.notes = notes
		self.unencrypted_file_size = os.path.getsize(unencrypted_filename) if unencrypted_filename else None

		encrypt_file(in_filename=unencrypted_filename, out_filename=encrypted_filename)

	def allowed_filename(self, filename):
		return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS

	def set_extension(self, filename):
		pass

	def decrypt(self, in_filename=None, out_filename=None):
		if not in_filename:
			in_filename = self.encrypted_filename

		if not out_filename:
			out_filename = self.unencrypted_filename

		decrypt_file(in_filename, out_filename)

	def __repr__(self):
		return '<FileRecord %r>' % self.encrypted_filename
Beispiel #10
0
class Flag(db.Model):

	__tablename__ = 'flags'

	id = db.Column(db.Integer, primary_key=True, autoincrement=True)
	name = db.Column(db.String(100), unique=True, nullable=False)
	description = db.Column(db.String(200), unique=True, nullable=False)

	def __init__(self, name, description):
		self.name = name
		self.description = description

	@property
	def serialize(self):
		return {
		'id': id,
		'name': name
		}

	def __repr__(self):
		return '<Flag %r>' % self.name
Beispiel #11
0
class Service(db.Model):

    __tablename__ = 'services'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    service_name = db.Column(db.String(32), unique=True, nullable=False)
    domain_name = db.Column(db.String(32), unique=True, nullable=False)
    length = db.Column(db.Integer, default=8)
    symbols = db.Column(db.Boolean, default=True)
    alphabet = db.Column(db.String(32), default='')
    equiv_domains = db.Column(ScalarListType())

    def __init__(self, name, length=8, symbols=True, alphabet=''):
        self.name = name
        self.length = length
        self.symbols = symbols
        self.alphabet = alphabet

    def get_alphabet(self):
        if self.alphabet:
            return self.alphabet
        alpha = ('abcdefghijklmnopqrstuvwxyz'
                 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
                 '0123456789')
        if self.symbols:
            alpha += '!@#$%^&*()-_'
        return alpha

    def get_password(self, plaintext):
        return get_password_wrapper(plaintext, self.name, self.length,
                                    self.get_alphabet())

    def generate_password(self, plaintext):
        pass

    @classmethod
    def search(cls, query):
        return cls.select().where(cls.name**('%%%s%%' % query))
Beispiel #12
0
class TrustedUser(BaseTable):

    __tablename__ = 'trusted_user'

    username = db.Column(db.String(64), unique=True)
    email = db.Column(db.String(64), unique=True, nullable=False)
    first_name = db.Column(db.String(64))
    last_name = db.Column(db.String(64))
    permissions = db.Column(ScalarListType())

    def __init__(self,
                 username=None,
                 email=None,
                 first_name=None,
                 last_name=None,
                 permissions=None):
        self.username = username
        self.email = email
        self.first_name = first_name
        self.last_name = last_name
        self.permissions = permissions

    def __repr__(self):
        return '<TrustedUser %r>' % (self.username)
Beispiel #13
0
class Vault(BaseTable):
    src = db.Column(db.String(255))
    secret_key = db.Column(db.Unicode(255))
    token = db.Column(EncryptedType(db.Unicode, secret_key, AesEngine,
                                    'pkcs5'))

    def __init__(self, token=None, src='http://127.0.0.1:5000/'):
        self.src = src
        self.token = token
        #self.cert = cert
        #self.access_key
        #self.secret_key
        #self.expiration_time

    @staticmethod
    def create(filename, password):
        pass

    def write_to_file(self, filename, password):
        pass
Beispiel #14
0
class PasswordRecord(Record):

	__tablename__ = 'password_records'

	id = db.Column(db.Integer, db.ForeignKey('records.id'), primary_key=True)
	service_name = db.Column(db.String(128))
	service_url = db.Column(db.String(128))
	service_domain = db.Column(db.String(64))
	email = db.Column(db.String(128))
	username = db.Column(db.String(128))
	password = db.Column(db.String(128))

	__mapper_args__ = {'polymorphic_identity': 'password_records'}

	def __init__(self, name=None, service_name=None, service_url=None, service_domain=None, username=None, password=None, email=None, notes=None, description=None, reprompt=None):
		self.name = name
		self.service_name = service_name
		self.service_url = service_url
		self.service_domain = service_domain
		self.username = username
		self.password = password
		self.email = email
		self.description = description
		self.notes = notes
		self.reprompt = reprompt

	def _get_service_name(self):
		return self.service_name
	def _get_service_domain(self):
		return self.service_domain
	def _get_service(self):
		pass
	def _get_username(self):
		return self.username
	def _get_email(self):
		return self.email
	def set_password(self, password):
		self.password_hash = generate_password_hash(password)
	def check_password(self, password):
		return check_password_hash(self.password_hash, password)
	def delete(self):
		db.session.delete(self)
		db.session.commit()
	def save(self):
		db.session.add(self)
		db.session.commit()

	def __repr__(self):
		return '<PasswordRecord %r>' % self.name
Beispiel #15
0
class Tag(db.Model):

	__tablename__ = 'tags'

	id = db.Column(db.Integer, primary_key=True, autoincrement=True)
	name = db.Column(db.String(100), unique=True, nullable=False)
	password_record_id = db.Column(db.Integer,db.ForeignKey('password_records.id'))
	wallet_record_id = db.Column(db.Integer,db.ForeignKey('wallet_records.id'))
	file_record_id = db.Column(db.Integer,db.ForeignKey('file_records.id'))
	note_record_id = db.Column(db.Integer,db.ForeignKey('note_records.id'))

	def __init__(self, name=None):
		self.name = name

	@property
	def serialize(self):
		return {
		'id': self.id,
		'name': self.name
		}

	def __repr__(self):
		return '<Tag %r>' % self.name