Пример #1
0
def certificate_form_validator(_: _, field: StringField) -> None:
    """
    Check if user has submitted a valid SSL certificate
    """
    if field.data:
        try:
            utils.parse_ssl_cert(field.data)
        except CertificateException as ex:
            raise ValidationError(ex.message) from ex
Пример #2
0
def server_cert_validator(value: str) -> str:
    """
    Validate the server certificate
    """
    if value:
        try:
            parse_ssl_cert(value)
        except CertificateException:
            raise ValidationError([_("Invalid certificate")])
    return value
Пример #3
0
def certificate_form_validator(  # pylint: disable=unused-argument
        form: DynamicForm, field: StringField) -> None:
    """
        Check if user has submitted a valid SSL certificate
    """
    if field.data:
        try:
            utils.parse_ssl_cert(field.data)
        except CertificateException as ex:
            raise ValidationError(ex.message)
Пример #4
0
 def _pre_add_update(self, database: Database) -> None:
     if app.config["PREVENT_UNSAFE_DB_CONNECTIONS"]:
         check_sqlalchemy_uri(database.sqlalchemy_uri)
     self.check_extra(database)
     self.check_encrypted_extra(database)
     if database.server_cert:
         utils.parse_ssl_cert(database.server_cert)
     database.set_sqlalchemy_uri(database.sqlalchemy_uri)
     security_manager.add_permission_view_menu("database_access", database.perm)
     # adding a new database we always want to force refresh schema list
     for schema in database.get_all_schema_names():
         security_manager.add_permission_view_menu(
             "schema_access", security_manager.get_schema_perm(database, schema)
         )
Пример #5
0
 def test_ssl_certificate_parse(self):
     parsed_certificate = parse_ssl_cert(ssl_certificate)
     self.assertEqual(parsed_certificate.serial_number,
                      12355228710836649848)
     self.assertRaises(CertificateException, parse_ssl_cert,
                       "abc" + ssl_certificate)