Example #1
0
    def __call__(self, *args):
        logger.info('create contract')

        # any update to the data store must be in the context of an authorized profile
        profile = Profile.load(self.config, session['profile_name'],
                               session['profile_secret'])
        if profile is None:
            logger.info('missing required profile')
            return redirect(url_for('login_app'))

        form = __Import_Contract_Form__()

        if form.validate_on_submit():
            contract = Contract.import_contract(self.config,
                                                form.contract.data,
                                                form.contract_name.data)
            if contract is None:
                logger.info('failed to upload pdo')
                flash('failed to upload pdo file')
                return render_template('error.html',
                                       title='An Error Occurred',
                                       profile=profile)

            return redirect(
                url_for('contract_view_app',
                        contract_id=contract.safe_contract_id))

        else:
            logger.info('re-render; %s', form.errors)
            return render_template('contract/import.html',
                                   title='Add Contract',
                                   form=form,
                                   profile=profile)
Example #2
0
    def __call__(self, *args) :
        logger.info('contract_pick_app')

        # any update to the data store must be in the context of an authorized profile
        profile = Profile.load(self.config, session['profile_name'], session['profile_secret'])
        if profile is None :
            logger.info('missing required profile')
            return redirect(url_for('login_app'))

        contract_list = ContractList.load(self.config)
        if contract_list.count == 0 :
            return redirect(url_for('contract_import_app'))

        form = __Pick_Contract_Form__()

        choices = []
        for contract in contract_list :
            choices.append((contract.safe_contract_id, contract.name))

        form.contract_list.choices = choices

        if form.validate_on_submit() :
            contract_id = form.contract_list.data
            return redirect(url_for('contract_view_app', contract_id=contract_id))
        else :
            logger.info('ERRORS: %s', form.errors)
            return render_template('contract/pick.html', title='Pick Contract', form=form, profile=profile)
Example #3
0
    def __call__(self, *args):
        logger.info('add eservice')

        # any update to the data store must be in the context of an authorized profile
        profile = Profile.load(self.config, session.get('profile_name', ''),
                               session.get('profile_secret', ''))
        if profile is None:
            logger.info('missing required profile')
            return redirect(url_for('login_app'))

        form = __Add_Enclave_Service_Form__()

        if form.validate_on_submit():
            logger.info('add enclave submit')

            logger.info('create enclave information')
            eservice = EnclaveService.create(self.config,
                                             form.eservice_url.data,
                                             name=form.eservice_name.data)
            if eservice is None:
                logger.info('no eservice found')
                flash('failed to find the eservice')
                return render_template('error.html',
                                       title='An Error Occurred',
                                       profile=profile)

            return redirect(
                url_for('view_eservice_app', eservice_id=eservice.eservice_id))

        else:
            logger.info('re-render; %s', form.errors)
            return render_template('eservice/add.html',
                                   title='Add Enclave Service',
                                   form=form,
                                   profile=profile)
Example #4
0
    def __call__(self, *args):
        # any update to the data store must be in the context of an authorized profile
        profile = Profile.load(self.config, session['profile_name'],
                               session['profile_secret'])
        if profile is None:
            logger.info('missing required profile')
            return redirect(url_for('login_app'))

        eservice_list = EnclaveServiceList.load(self.config)
        if eservice_list.count == 0:
            return redirect(url_for('add_eservice_app'))

        form = __Pick_Enclave_Service_Form__()

        choices = []
        for eservice in eservice_list:
            choices.append((eservice.eservice_id, eservice.name))

        form.eservice_list.choices = choices

        if form.validate_on_submit():
            return redirect(
                url_for('view_eservice_app',
                        eservice_id=form.eservice_list.data))
        else:
            logger.debug('ERRORS: %s', form.errors)
            return render_template('eservice/pick.html',
                                   title='Pick EService',
                                   form=form,
                                   profile=profile)
Example #5
0
    def __call__(self, *args) :
        # any update to the data store must be in the context of an authorized profile
        profile = Profile.load(self.config, session['profile_name'], session['profile_secret'])
        if profile is None :
            logger.info('missing required profile')
            return redirect(url_for('login_app'))

        pservice_list = ProvisioningServiceList.load(self.config)
        if pservice_list.count == 0 :
            return redirect(url_for('add_pservice_app'))

        form = __Pick_Provisioning_Service_Form__()

        choices = []
        for pservice in pservice_list :
            choices.append((pservice.file_name, pservice.service_url))

        form.pservice_list.choices = choices

        if form.validate_on_submit() :
            pservice = ProvisioningService.load(self.config, form.pservice_list.data, use_raw=False)
            if pservice is None :
                logger.info('no such pservice as <%s>', form.pservice_list.data)
                flash('failed to find the pservice')
                return render_template('error.html', title='An Error Occurred', profile=profile)

            return render_template('pservice/view.html', title='View Provisioning Service', pservice=pservice, profile=profile)
        else :
            logger.info('ERRORS: %s', form.errors)
            return render_template('pservice/pick.html', title='Pick Provisioning Service', form=form, profile=profile)
Example #6
0
    def __call__(self, *args):
        logger.info('add eservice')

        # any update to the data store must be in the context of an authorized profile
        profile = Profile.load(self.config, session['profile_name'],
                               session['profile_secret'])
        if profile is None:
            logger.info('missing required profile')
            return redirect(url_for('login_app'))

        form = __Upload_Contract_Code_Form__()

        if form.validate_on_submit():
            contract_code = ContractCode.create(self.config,
                                                form.contract_code.data,
                                                form.contract_code_name.data)
            if contract_code is None:
                logger.info('failed to upload contract')
                flash('failed to upload contract')
                return render_template('error.html',
                                       title='An Error Occurred',
                                       profile=profile)

            return render_template('contract_code/view.html',
                                   title='View Contract Code',
                                   contract_code=contract_code,
                                   profile=profile)

        else:
            logger.info('re-render; %s', form.errors)
            return render_template('contract_code/add.html',
                                   title='Add Contract Code',
                                   form=form,
                                   profile=profile)
Example #7
0
    def __call__(self, *args) :
        form = __LoginForm__()
        if form.validate_on_submit() :
            profile = Profile.load(self.config, form.profile_name.data, form.password.data)
            if profile is None :
                if form.create_flag.data :
                    logger.info('loaded requested profile')
                    profile = Profile.create(self.config, form.profile_name.data, form.password.data)
                else :
                    logger.info('failed to locate requested profile')
                    return render_template('login.html', title='Login', form=form)

            # i cannot believe that this is secure, but given that
            # the user is the one who sent the password...
            session['profile_name'] = form.profile_name.data
            session['profile_secret'] = form.password.data

            return redirect(url_for('index_app'))
        else :
            return render_template('login.html', title='Login', form=form)
Example #8
0
    def __call__(self, contract_id, *args):
        logger.info('contract_view_app')

        # any update to the data store must be in the context of an authorized profile
        profile = Profile.load(self.config, session['profile_name'],
                               session['profile_secret'])
        if profile is None:
            logger.info('missing required profile')
            return redirect(url_for('login_app'))

        logger.info("selected contract id is %s", contract_id)
        contract = Contract.load(self.config, contract_id, use_raw=False)
        if contract is None:
            logger.info('no such contract')
            flash('failed to find contract')
            return render_template('error.html',
                                   title='An Error Occurred',
                                   profile=profile)

        form = __Contract_Invoke_Form__()

        if form.validate_on_submit():
            try:
                expression = form.expression.data
                response = ContractResponse.invoke_method(
                    self.config, profile, contract, expression)
            except InvocationException as e:
                logger.info('invocation failed: %s', str(e))
                return render_template('contract/invoke.html',
                                       title='Invocation Results',
                                       contract=contract,
                                       form=form,
                                       profile=profile,
                                       result=None,
                                       error=str(e))

            logger.info("response is %s", str(response))
            return render_template('contract/invoke.html',
                                   title='Invocation Results',
                                   contract=contract,
                                   form=form,
                                   profile=profile,
                                   result=response.value,
                                   error=None)
        else:
            logger.info('re-render; %s', form.errors)
            return render_template('contract/invoke.html',
                                   title='Invoke Contract Method',
                                   contract=contract,
                                   form=form,
                                   profile=profile,
                                   result=None,
                                   error=None)
Example #9
0
    def __call__(self, pservice_id, *args) :
        # any update to the data store must be in the context of an authorized profile
        profile = Profile.load(self.config, session['profile_name'], session['profile_secret'])
        if profile is None :
            logger.info('missing required profile')
            return redirect(url_for('login_app'))

        pservice = ProvisioningService.load(self.config, pservice_id, use_raw=False)
        if pservice is None :
            logger.info('no such pservice as <%s>', pservice_id)
            flash('failed to find the pservice')
            return render_template('error.html', title='An Error Occurred', profile=profile)

        return render_template('pservice/view.html', title='View Provisioning Service', pservice=pservice, profile=profile)
Example #10
0
    def __call__(self, *args):
        # any update to the data store must be in the context of an authorized profile
        profile = Profile.load(self.config, session['profile_name'],
                               session['profile_secret'])
        if profile is None:
            logger.info('missing required profile')
            return redirect(url_for('login_app'))

        code_list = ContractCodeList.load(self.config)
        if code_list.count == 0:
            return redirect(url_for('add_contract_code_app'))

        form = __Pick_Contract_Code_Form__()

        choices = []
        for ccode in code_list:
            choices.append((ccode.code_hash, ccode.name))

        form.contract_code_list.choices = choices

        if form.validate_on_submit():
            contract_code = ContractCode.load(self.config,
                                              form.contract_code_list.data,
                                              use_raw=False)
            if contract_code is None:
                logger.info('no such contract code')
                flash('failed to find contract code')
                return render_template('error.html',
                                       title='An Error Occurred',
                                       profile=profile)

            return render_template('contract_code/view.html',
                                   title='View Contract Code',
                                   contract_code=contract_code,
                                   profile=profile)
        else:
            logger.debug('ERRORS: %s', form.errors)
            return render_template('contract_code/pick.html',
                                   title='Pick Contract Code',
                                   form=form,
                                   profile=profile)
Example #11
0
    def __call__(self, *args):
        logger.info('add pservice')

        # any update to the data store must be in the context of an authorized profile
        profile = Profile.load(self.config, session['profile_name'],
                               session['profile_secret'])
        if profile is None:
            logger.info('missing required profile')
            return redirect(url_for('login_app'))

        form = __Add_Provisioning_Service_Form__()

        if form.validate_on_submit():
            logger.info('add enclave submit')

            logger.info('create enclave information')
            pservice = ProvisioningService.create(self.config,
                                                  form.pservice_url.data,
                                                  name=form.pservice_name.data)
            if pservice is None:
                logger.info('no pservice found')
                flash('failed to find the pservice')
                return render_template('error.html',
                                       title='An Error Occurred',
                                       profile=profile)

            return render_template('pservice/view.html',
                                   title='View Provisioning Service',
                                   pservice=pservice,
                                   profile=profile)

        else:
            logger.info('re-render; %s', form.errors)
            return render_template('pservice/add.html',
                                   title='Add Provisioning Service',
                                   form=form,
                                   profile=profile)
Example #12
0
    def __call__(self, code_hash, *args):
        logger.info('view contract %s', code_hash)

        # any update to the data store must be in the context of an authorized profile
        profile = Profile.load(self.config, session['profile_name'],
                               session['profile_secret'])
        if profile is None:
            logger.info('missing required profile')
            return redirect(url_for('login_app'))

        contract_code = ContractCode.load(self.config,
                                          code_hash,
                                          use_raw=False)
        if contract_code is None:
            logger.info('no such contract code')
            flash('failed to find contract code')
            return render_template('error.html',
                                   title='An Error Occurred',
                                   profile=profile)

        return render_template('contract_code/view.html',
                               title='View Contract Code',
                               contract_code=contract_code,
                               profile=profile)
Example #13
0
    def __call__(self, contract_id, *args):
        logger.info('contract_view_app')
        logger.info("selected contract id is %s", contract_id)

        # any update to the data store must be in the context of an authorized profile
        profile = Profile.load(self.config, session['profile_name'],
                               session['profile_secret'])
        if profile is None:
            logger.info('missing required profile')
            return redirect(url_for('login_app'))

        contract = Contract.load(self.config, contract_id, use_raw=False)
        if contract is None:
            logger.info('no such contract')
            flash('failed to find contract')
            return render_template('error.html',
                                   title='An Error Occurred',
                                   profile=profile)

        logger.info('render view')
        return render_template('contract/view.html',
                               title='View Contract',
                               contract=contract,
                               profile=profile)
Example #14
0
    def __call__(self, *args) :
        logger.info('create contract')

        # any update to the data store must be in the context of an authorized profile
        profile = Profile.load(self.config, session['profile_name'], session['profile_secret'])
        if profile is None :
            logger.info('missing required profile')
            return redirect(url_for('login_app'))

        form = __Create_Contract_Form__()

        # contract code
        code_list = ContractCodeList.load(self.config)
        if code_list.count == 0 :
            return redirect(url_for('add_contract_code_app'))

        form.contract_code_list.choices = []
        for ccode in code_list :
            form.contract_code_list.choices.append((ccode.code_hash, ccode.name))

        # eservice choices
        eservice_list = EnclaveServiceList.load(self.config)
        if eservice_list.count == 0 :
            return redirect(url_for('add_eservice_app'))

        form.eservice_list.choices = []
        for eservice in eservice_list :
            form.eservice_list.choices.append((eservice.eservice_id, eservice.name))

        # pservice choices
        pservice_list = ProvisioningServiceList.load(self.config)
        if pservice_list.count == 0 :
            return redirect(url_for('add_pservice_app'))

        form.pservice_list.choices = []
        for pservice in pservice_list :
            form.pservice_list.choices.append((pservice.file_name, pservice.name))

        # and now we work to process it
        if form.validate_on_submit() :
            logger.info("eservice list: %s", form.eservice_list.data)
            logger.info("pservice list: %s", form.pservice_list.data)
            logger.info("contract code: %s", form.contract_code_list.data)

            pservices = ProvisioningServiceList(self.config)
            for pservice_id in form.pservice_list.data :
                pservice_object = ProvisioningService.load(self.config, pservice_id, use_raw=False)
                if pservice_object is None :
                    logger.info('no such pservice as <%s>', pservice_id)
                    flash('failed to find the pservice: {0}'.format(pservice_id))
                    return render_template('error.html', title='An Error Occurred', profile=profile)
                pservices.add(pservice_object)

            eservices = EnclaveServiceList(self.config)
            for eservice_id in form.eservice_list.data :
                eservice_object = EnclaveService.load(self.config, eservice_id)
                if eservice_object is None :
                    logger.info('no such eservice as <%s>', eservice_id)
                    flash('failed to find the eservice: {0}'.format(eservice_id))
                    return render_template('error.html', title='An Error Occurred', profile=profile)
                eservices.add(eservice_object)

            contract_code = ContractCode.load(self.config, form.contract_code_list.data, use_raw=False)
            if contract_code is None :
                logger.info('no such contract code')
                flash('failed to find contract code')
                return render_template('error.html', title='An Error Occurred', profile=profile)

            contract_object = Create(self.config, profile, form.contract_name.data, contract_code, eservices, pservices)
            if contract_object is None :
                logger.info('failed to create the contract')
                flash('failed to create the contract')
                return render_template('error.html', title='An Error Occurred', profile=profile)

            return redirect(url_for('contract_view_app', contract_id=contract_object.safe_contract_id))

        else :
            logger.info('re-render; %s', form.errors)
            return render_template('contract/create.html', title='Create Contract', form=form, profile=profile)
Example #15
0
    def __call__(self, contract_id, *args):
        logger.info('set contract preferences')
        logger.info("selected contract id is %s", contract_id)

        # any update to the data store must be in the context of an authorized profile
        profile = Profile.load(self.config, session['profile_name'],
                               session['profile_secret'])
        if profile is None:
            logger.info('missing required profile')
            return redirect(url_for('login_app'))

        contract = Contract.load(self.config, contract_id, use_raw=False)
        if contract is None:
            logger.info('no such contract')
            flash('failed to find contract')
            return render_template('error.html',
                                   title='An Error Occurred',
                                   profile=profile)

        form = __Set_Preferences_Form__()

        eservice_list = EnclaveServiceList.load(self.config)

        form.invoke_list.choices = [('random', 'random')]
        for enclave_id in contract.provisioned_enclaves:
            eservice = eservice_list.get_by_enclave_id(enclave_id)
            form.invoke_list.choices.append(
                (eservice.eservice_id, eservice.name))

        form.update_list.choices = [('random', 'random')]
        for enclave_id in contract.provisioned_enclaves:
            eservice = eservice_list.get_by_enclave_id(enclave_id)
            form.update_list.choices.append(
                (eservice.eservice_id, eservice.name))

        if form.validate_on_submit():
            logger.info('invoke: %s', form.invoke_list.data)

            invoke_eservice = EnclaveService.load(self.config,
                                                  form.invoke_list.data)
            logger.info('invoke enclave id: %s', invoke_eservice.enclave_id)

            update_eservice = EnclaveService.load(self.config,
                                                  form.update_list.data)
            logger.info('update enclave id: %s', invoke_eservice.enclave_id)

            contract.invoke_enclave = invoke_eservice.enclave_id
            contract.update_enclave = update_eservice.enclave_id
            if form.contract_name.data:
                contract.name = form.contract_name.data
            contract.save(self.config)

            return redirect(
                url_for('contract_view_app', contract_id=contract_id))

        else:
            logger.info('incoming data for set preferences: %s',
                        form.invoke_list.data)

            form.contract_name.data = contract.name
            form.invoke_list.default = contract.invoke_enclave
            form.update_list.default = contract.update_enclave

            logger.info('re-render; %s', form.errors)
            return render_template('contract/preferences.html',
                                   title='Set Contract Preferences',
                                   contract=contract,
                                   form=form,
                                   profile=profile)