Exemplo n.º 1
0
    def __init__(self, *args, **kwargs):
        super(SessionTransaction, self).__init__(*args, **kwargs)

        query = db.session.query

        if 'uuid' in kwargs:
            uuid = kwargs['uuid']
        else:
            uuid = generate_id()

        while query(SessionTransaction).get(uuid) is not None:
            uuid = generate_id()

        self.uuid = uuid

        if 'transaction_id' in kwargs:
            transaction_id = kwargs['transaction_id']
        else:
            transaction_id = generate_id()

        while query(SessionTransaction).filter_by(
                transaction_id=transaction_id).first() is not None:

            transaction_id = generate_id()

        self.transaction_id = transaction_id
Exemplo n.º 2
0
Arquivo: totp.py Projeto: kanarip/piko
    def __init__(self, *args, **kwargs):
        super(TOTPToken, self).__init__(*args, **kwargs)

        uuid = generate_id()

        if db.session.query(TOTPToken).get(uuid) is not None:
            while db.session.query(TOTPToken).get(uuid) is not None:
                uuid = generate_id()

        self.uuid = uuid
Exemplo n.º 3
0
    def __init__(self, *args, **kwargs):
        super(Entitlement, self).__init__(*args, **kwargs)

        uuid = generate_id()

        if db.session.query(Entitlement).get(uuid) is not None:
            while db.session.query(Entitlement).get(uuid) is not None:
                uuid = generate_id()

        self.uuid = uuid
Exemplo n.º 4
0
    def __init__(self, *args, **kwargs):
        super(Session, self).__init__(*args, **kwargs)

        uuid = generate_id()

        query = db.session.query

        if query(Session).filter_by(uuid=uuid).first() is not None:
            while query(Session).filter_by(uuid=uuid).first() is not None:
                uuid = generate_id()

        self.uuid = uuid
Exemplo n.º 5
0
    def __init__(self, *args, **kwargs):
        super(Person, self).__init__(*args, **kwargs)

        if 'uuid' in kwargs:
            uuid = kwargs['uuid']
        else:
            uuid = generate_id()

        while db.session.query(Person).get(uuid) is not None:
            uuid = generate_id()

        self.uuid = uuid
Exemplo n.º 6
0
    def __init__(self, *args, **kwargs):
        """
            When a group is created, assign it a unique integer ID.
        """
        super(Group, self).__init__(*args, **kwargs)

        uuid = generate_id()

        if db.session.query(Group).get(uuid) is not None:
            while db.session.query(Group).get(uuid) is not None:
                uuid = generate_id()

        self.uuid = uuid
Exemplo n.º 7
0
    def __init__(self, *args, **kwargs):
        """
            Upon creation of the customer entity, ensure that the integer ID
            assigned to it is random as well as unique without trial and error.
        """
        super(Customer, self).__init__(*args, **kwargs)

        uuid = generate_id()

        if db.session.query(Customer).get(uuid) is not None:
            while db.session.query(Customer).get(uuid) is not None:
                uuid = generate_id()

        self.uuid = uuid
Exemplo n.º 8
0
Arquivo: cert.py Projeto: kanarip/piko
    def generate_cert(self):
        """
            Generate and sign the certificate.
        """
        key = crypto.PKey()
        key.generate_key(crypto.TYPE_RSA, 4096)

        cert = crypto.X509()

        subject = cert.get_subject()
        subject.C = "CH"
        subject.ST = "Zurich"
        subject.O = "Kolab Systems AG"
        subject.OU = "Product Sales"
        subject.CN = self.system_uuid
        subject.emailAddress = "*****@*****.**"

        cert.set_pubkey(key)
        cert.set_version(2)

        start = datetime.datetime.utcnow()
        end = start + datetime.timedelta(days=365)

        cert.set_notBefore(start.strftime("%Y%m%d%H%M%SZ"))
        cert.set_notAfter(end.strftime("%Y%m%d%H%M%SZ"))

        serial_number = generate_id()
        cert.set_serial_number(serial_number)

        from .ca import sign_cert

        cert = sign_cert(cert)

        pem_cert = crypto.dump_certificate(crypto.FILETYPE_TEXT, cert)
        pem_cert += crypto.dump_certificate(crypto.FILETYPE_PEM, cert)

        pem_key = crypto.dump_privatekey(crypto.FILETYPE_PEM, key)
        pem = pem_cert + pem_key

        pem_path = os.path.join(cert_path, '%s.pem' % (self.system_uuid))

        with open(pem_path, 'w') as f:
            f.write(pem)

        _cert = Certificate(
            cn=self.system_uuid,
            certificate=pem_cert,
            private_key=pem_key
        )

        db.session.add(_cert)

        db.session.commit()

        return (cert, key)