コード例 #1
0
    def process_step2(self, request, response):
        logger.debug("entrou no process step2")

        from coapthon.messages.response import Response
        assert (isinstance(response, Response))
        response.payload = "Response changed through PUT"
        response.code = defines.Codes.CHANGED.number

        response.content_type = defines.Content_types["application/json"]
        response.mid = request.mid
        defines.acknowledged = True
        #inicio autenticacao

        a = JsonAdapter.convertToDict(request.payload)

        print(a)
        #busca pelo auth_code
        entry = Step2PropostaResource.step2_queries[a["auth_code"]]

        result = "-1"

        if (entry != None) and (entry.query_result == a["query_response"]):
            print("resposta válida a query")
            result = "ok"
            #todo: passar para enum
            authEntry = AuthWorkFlowEntry(a["auth_code"], "authenticated", 0)
            AuthInspectorResource.auth_workflow[a["auth_code"]] = authEntry

        print(AuthInspectorResource.auth_workflow)

        response.payload = FactorTwoReturn(result).toJSON()

        return self, response
コード例 #2
0
 def fromJSON(payload):
     a = JsonAdapter.convertToDict(payload)
     result = AuthWorkFlowEntry()
     result.auth_code = a["auth_code"]
     result.level = a["level"]
     result.reputation = a["reputation"]
     return result
コード例 #3
0
def cb_post_login(response):
    """ Callback do post de login.
     
        Processa a resposta do login e submete o segundo passo da autenticação multifator
    """
    global client
    global auth_code
    global e
    logger.debug("dentro do callback do post do passo1")
    logger.debug("response dentro do callback do post do passo1:", response)
    a = JsonAdapter.convertToDict(response.payload)
    print(a)
    query = a["query"]

    if (query != 1):
        auth_code = a["auth_code"]
        resultado = QueryHelper.processQuery(
            query, DBClientDevices.db[indice]["uuid"])
        logger.debug("dentro do callback do post do passo1 - resultado query:",
                     resultado)
        query_result = CoapMessageStepTwo(str(resultado, "utf-8"),
                                          a["auth_code"])
        #todo: consertar isso para funcionar com o mesmo client
        client2 = HelperClient(server=(HOST, PORT))
        client2.post("step2", query_result.toJSON(), cb_post_passo2, 10)
    else:
        print("dentro do callback do post do passo1 - sem segundo fator")
        logger.debug("sinalizando para thread continuar...")
        e.set()
コード例 #4
0
ファイル: device.py プロジェクト: wesleybez/mfa_iot_lpwan
 def fromJSON(payload):
     a = JsonAdapter.convertToDict(payload)
     result = CoapDevice()
     result.uuid = a["uuid"]
     result.modelo = a["modelo"]
     result.fabricante = a["fabricante"]
     result.nro_serie = a["nro_serie"]
     return result
コード例 #5
0
    def render_POST_advanced(self, request, response):
        self.payload = request.payload
        logger.debug("entrou no post advanced")
        print("payload:", request.payload)
        data = request.payload
        #todo passar para json
        a = JsonAdapter.convertToDict(data)
        print("a:", a)

        return self.process_login(request, response)
コード例 #6
0
def cb_post_passo2(response):
    """ Callback do post de step2.
     
        Processa a resposta do passo2
    """
    logger.debug("dentro do callback do post do passo2")
    logger.debug("response dentro do callback do post do passo2:", response)
    a = JsonAdapter.convertToDict(response.payload)
    logger.debug(a)
    logger.debug("sinalizando para thread continuar...")
    e.set()
コード例 #7
0
 def process_post_login(self,response):
     """ funcao de callback do post de autenticação passo 1 """
     logger.debug ("dentro do callback do put do passo1")
     print("response:",response)
     a = JsonAdapter.convertToDict(response.payload)
     print(a)
     query=a["query"]
 
     if(query!=1):
         resultado = QueryHelper.processQuery(query, DBClientDevices.db[id]["uuid"])
         print("resultado query:", resultado)        
         query_result= CoapMessageStepTwo(str(resultado,"utf-8"),a["auth_code"])
         self.client.post("login", query_result.toJSON(), self.process_post_step2, 10)
     else :
         print("sem segundo fator")
コード例 #8
0
def cb_post(response):
    logger.debug("dentro do callback do post do register")
    #print("response:",response)
    #print("response.payload:",response.payload)

    #ja registrado
    if response.payload == "-1":
        print("ja registrado")
        return None

    if response is not None:
        print(response.pretty_print())
        retorno = RegisterReturn("", "", "")

        a = JsonAdapter.convertToDict(response.payload)
        """
        s1=response.payload[1:(len(response.payload)-1)]
        s1 = s1.strip()
        print(s1)
        campos = s1.split(",")
        a = dict()
        for s in campos :
            #print(s)
            l = s.strip().split(":")
            l[1]=l[1].strip()
            a[l[0][1:(len(l[0])-1)]]=l[1][1:(len(l[1])-1)]
            #print(l[0])
            #print(l[1]) 
        
        #print(a)
        """
        #erro ao converter de json para object
        #retorno = retorno.fromJSON(response.payload)

        #print(retorno)
        #dispositivo vazio
        print(dispositivo)
        DBClientDevices.add("", a["user"], a["passwd"], a["timestamp"],
                            dispositivo)
コード例 #9
0
    def render_POST(self, request):
        logger.debug("entrou no render_POST")
        res = BasicPropostaResource()
        res.location_query = request.uri_query
        res.payload = request.payload

        logger.debug("payload:", request.payload)
        a = JsonAdapter.convertToDict(request.payload)
        logger.debug("dict a:", a)

        if (a["auth_code"] in AuthInspectorResource.auth_workflow):
            logger.debug("codigo aceito")
            BasicPropostaResource.queue.append(a["data"])
        else:
            logger.error("codigo rejeitado - auth_code inexistente")
            return res

        logger.debug(BasicPropostaResource.queue)

        array = np.array(BasicPropostaResource.queue, dtype='i')

        self.mean = np.mean(array)
        self.dp = np.std(array)
        diferenca = abs(float(str(self.mean.astype(float))) - int(a["data"]))
        gtStd = abs(float(str(self.mean.astype(float))) -
                    int(a["data"])) > self.dp
        logger.debug("\n\nmean:", self.mean)
        logger.debug("std :", self.dp)
        logger.debug("mean diff:", diferenca)
        logger.debug("gt std:", gtStd)
        if gtStd and len(BasicPropostaResource.queue) > 50:
            logger.error("greater than standard deviantion:")
            logger.error(a["data"])
            logger.error(self.dp)
            logger.error(self.mean)
            logger.error(a["auth_code"])

        return res
コード例 #10
0
 def fromJSON(self, payload):
     a = JsonAdapter.convertToDict(payload)
     self.passwd = a["passwd"]
     self.timestamp = a["timestamp"]
     self.user = a["user"]
コード例 #11
0
 def process_post_step2(self,response):
     """ funcao de callback do post de autenticação passo 1 """
     logger.debug ("dentro do callback do put do passo2")
     print("response:",response)
     a = JsonAdapter.convertToDict(response.payload)
     print(a)
コード例 #12
0
 def fromJSON(self, payload):
     a = JsonAdapter.convertToDict(payload)
     self.result = a["result"]
コード例 #13
0
 def fromJSON(self, payload):
     a = JsonAdapter.convertToDict(payload)
     self.auth_code = a["auth_code"]
     self.query = a["query"]
コード例 #14
0
    def process_login(self, request, response):
        logger.debug("entrou no process login")
        user = request.payload

        from coapthon.messages.response import Response
        assert (isinstance(response, Response))
        #response.payload = "Response changed through PUT"
        response.code = defines.Codes.CHANGED.number

        response.content_type = defines.Content_types["application/json"]
        response.mid = request.mid
        defines.acknowledged = True
        #inicio autenticacao

        auser = JsonAdapter.convertToDict(user)
        reg = DBRegister.getByUser(auser["login"])

        authenticated = False

        if reg != -1:
            par_user = auser["login"]
            par_password = auser["password"]

            print("indice:", reg)
            print("request user:"******"request senha:", par_password)
            print("db user:"******"user"])
            print("db senha:", reg["passwd"])

            if par_user == reg["user"] and par_password == reg["passwd"]:
                resultado = "" + time.strftime('%Y%m%d%H%M%S')
                logger.debug("autenticado")
                authenticated = True
            else:
                resultado = "-1"
                logger.debug("senha errada")
        else:
            resultado = "-1"
            logger.debug("nao autenticado")
            logger.debug("nao achou usuario")
            #response.code = "403"#defines.Codes.FORBIDDEN
        #fim autenticacao

        query = "-1"
        if authenticated:
            #[0]-informacao
            #[1]-inicio
            #[2]-fim
            #[3]-inverter
            #[4]-rotacionar
            query = "1;0;2;1;1"

            device = CoapDevice.fromCSV(reg["register_data"])

            queryResponse = str(QueryHelper.processQuery(query, device.uuid),
                                "utf-8")

            entry = FactorTwoEntry(resultado, queryResponse)
            Step2PropostaResource.step2_queries[resultado] = entry
            authEntry = AuthWorkFlowEntry(resultado, "compatibility", 0)
            AuthInspectorResource.auth_workflow[resultado] = authEntry

        retorno = FactorOneReturn(resultado, query).toJSON()

        #aqui calcula o

        logger.debug(retorno)
        response.payload = retorno

        logger.debug("codigos de autenticacao ativos:")
        print(Step2PropostaResource.step2_queries)
        logger.debug("niveis de autenticacao e reputacao:")
        print(AuthInspectorResource.auth_workflow)

        print("request:", request)
        print("response:", response)

        return self, response
コード例 #15
0
 def fromJSON(payload):
     a = JsonAdapter.convertToDict(payload)
     result = FactorTwoEntry()
     result.auth_code = a["auth_code"]
     result.query_result = a["query_result"]
     return result