Beispiel #1
0
    def authenticate_advanced(self): 
        
        log.debug("Authentication advanced") 

        for person in self._data: 

            cfg= self._cfg 
            cfg.request.uid = person['uid'] 
            cfg.request.demographics = ["Pi", "Pa"]
            cfg.request.biometrics = []
            
            # test data format is DD-MM-YYYY whereas what is required
            # is YYYY-MM-DD 
            dob = person['dob'] 
            dob_split = dob.split("-") 
            dob = dob_split[2] + "-" + dob_split[1] + "-" + dob_split[0]
            cfg.request['Pi'] = {
                'ms': "E",
                'name': person['name'],
                'dob': dob,
                'gender': person['gender'], 
                }
            cfg.request["Pa"] = { 
                'ms': "E",
                "landmark": person['landmark'],
                "street": person['street'], # 12 Maulana Azad Marg
                "locality": person['locality'], #"",
                "poname": person['poname'], #"",
                "vtc": person['vtc'], #"New Delhi",
                "subdist": person['subdist'], #"New Delhi",
                "district": person['district'], #"New Delhi",
                "state": person['state'], #"New delhi",
                "pincode": person['pincode'] #"110002",
                }

            # => Gather the data from the (simulated) client
            data = AuthData(cfg=cfg) 
            data.generate_client_xml() 
            exported_data = data.export_request_data() 
            
            # Create the request object and execute 
            req = AuthRequest(cfg)
            req.import_request_data(exported_data)
            req.execute()
            
            # Load the response 
            data = json.loads(req.export_response_data())
            res = AuthResponse(cfg=cfg, uid=cfg.request.uid) 
            res.load_string(data['xml'])
            
            # Find all the attributes set 
            bits = res.lookup_usage_bits()
            print "[%.3f] (%s) -> %s " % (data['latency'], bits, data['ret'])
            if data['err'] is not None and data['err'] != -1: 
                print "Err %s: %s "% ( data['err'], data['err_message'])
Beispiel #2
0
    def authenticate_basic(self): 
        
        log.debug("Authenticating") 

        for person in self._data: 
            cfg= self._cfg 
            cfg.request.uid = person['uid'] 
            cfg.request.demographics = ["Pi"]
            cfg.request.biometrics = ["FMR"]
            cfg.request['Pi'] = {
                'ms': "E",
                'name': person['name']
                }
            cfg.request["FMR"] = { 
                'bio': person['bio']
                }

            # => Gather the data from the (simulated) client
            data = AuthData(cfg=cfg) 
            data.generate_client_xml() 
            exported_data = data.export_request_data() 
            
            # Create the request object and execute 
            req = AuthRequest(cfg)
            req.import_request_data(exported_data)
            req.execute()

            # Load the response 
            data = json.loads(req.export_response_data())
            res = AuthResponse(cfg=cfg, uid=cfg.request.uid) 
            res.load_string(data['xml'])
            
            # Find all the attributes set 
            bits = res.lookup_usage_bits()
            print "[%.3f] (%s) -> %s " % (data['latency'], bits, data['ret'])
            if data['err'] is not None and data['err'] != -1: 
                print "Err %s: %s "% ( data['err'], data['err_message'])            
Beispiel #3
0
    def authenticate(self, request, cleaned_data): 
        """
        Eventually support all possible combinations and levels 
        of authentication 
        """
        # Store this object...
        self._request = request 

        if ((cleaned_data == None) or 
            (not isinstance(cleaned_data, dict))):
            raise Exception("Invalid data to authenticate")

        # cleanup and extract the aadhaar
        credentials = {} 
        for k,v in cleaned_data.iteritems():
            if k.startswith('aadhaar'):
                if k not in ["aadhaar_dob", "aadhaar_pincode"]: 
                    credentials[k] = v
                else: 
                    credentials[k] = str(v)  # authdata requires a string...

        log.debug("authenticate: storing credentials = %s " % credentials)

        aadhaar_settings = settings.AADHAAR_SETTINGS 
        if ((aadhaar_settings == None) and (not aadhaar_settings.is_valid())):
            raise Exception("Aadhaar configuration unspecified or invalid") 

        try: 
            self._aadhaar_id = credentials['aadhaar_id']
        except: 
            raise Exception("UID not specified")
        
        cfg = aadhaar_settings.get_cfg() 
        #print("cfg = %s " % cfg)

        # Issue the request 
        cfg.request.uid = self._aadhaar_id 
        self.process_credentials(cfg, credentials) 

        print("request  %s " % cfg.request)

        # => Generate the request XML and send it over the 
        # server 
        try: 
            data = AuthData(cfg=cfg) 
            data.generate_client_xml() 
            exported_data = data.export_request_data() 
            
            log.debug("Completed PidXML generation")
            log.debug("Requesting connection with UIDAI backend")

            req = AuthRequest(cfg)
            log.debug("Created authrequest object")            
            req.import_request_data(exported_data)
            req.execute()

            log.debug("Completed  authrequest. Processing response")

            # Load the response 
            data = json.loads(req.export_response_data())
            res = AuthResponse(cfg=cfg, uid=cfg.request.uid) 
            res.load_string(data['xml'])
            
            log.debug("Completed processing response") 
        
            # Find all the attributes set 
            bits = res.lookup_usage_bits()
            log.debug("[%.3f] (%s) -> %s " % (data['latency'], bits, data['ret']))
            if data['err'] is not None and data['err'] != -1: 
                log.debug("Err %s: %s "% ( data['err'], data['err_message']))
        except: 
            # For whatever the authentication failed. 
            log.debug("Exception in the call to pyAadhaarAuth library")
            traceback.print_exc() 
            log.exception("authenticate: call failed for some reason")  
            raise Exception("Authentication call failed. Internal error")
        
        try: 
            aadhaar = self.get_aadhaar() 
        except: 
            log.exception("authencate: get_aadhaar failed")

        log.debug("aadhaar object created/obtained %s " % vars(aadhaar))
                
        # Create a new AuthDetails record 
        latency = data['latency'] 
        ts = dateutil.parser.parse(unicode(data['ts']))
        authdetails = AadhaarAuthDetails(
            aadhaar=aadhaar,
            ret = data['ret'],
            latency = round(latency, 2),
            err = data['err'], 
            ts = ts, 
            txn = data['txn'],
            info = data['info'],
            code = data['code'], 
            )
        authdetails.set_response(data['xml'])
        if (not request.user.is_anonymous()):
            authdetails.user = request.user
        authdetails.save() 
        
        log.debug("authdetails object = %s " % vars(authdetails))

        if (not request.user.is_anonymous()):
            # Create an auth aummary for a given aadhaar id
            (authsummary, created) = \
                AadhaarAuthSummary.objects.get_or_create(aadhaar=aadhaar, 
                                                         user=request.user)

            # XXX Change this. May be we should rename this as last
            # verification details. 
            authsummary.verification_details=authdetails
            authsummary.verified = req.is_successful()
            if (created): 
                authsummary.first_authentication = datetime.now()
            if (req.is_successful()): 
                log.debug("Successful authentication. So updating state")
                authsummary.last_successful_authentication = datetime.now() 
                authsummary.num_successful_authentications += 1 
            else:
                log.debug("Unsuccessful authentication. So updating state")
                authsummary.last_unsuccessful_authentication = datetime.now() 
                authsummary.num_unsuccessful_authentications += 1             
            authsummary.save() 
            self._authsummary = authsummary 
            log.debug("auth summary created/updated %s " % vars(authsummary))
        
        if ((req.is_successful()) and (not request.user.is_anonymous())):
            log.debug("Successful auth. Saving aadhaar in the profile")
            profile = request.user.get_profile() 
            profile.aadhaar = aadhaar
            profile.save() 

        return (req.is_successful(), authdetails) 
Beispiel #4
0
    cmd = AuthConfig()
    cfg = cmd.update_config()

    logging.getLogger().setLevel(cfg.common.loglevel)
    logging.basicConfig()

    # This is a simple client. Force use of name
    cfg.request.demographics = ["Pi"]
    cfg.request.biometrics = []

    # => Gather the data from the (simulated) client
    data = AuthData(cfg=cfg)
    data.generate_client_xml()
    exported_data = data.export_request_data()

    # Create the request object and execute
    req = AuthRequest(cfg)
    req.import_request_data(exported_data)
    req.execute()

    # Load the response
    data = json.loads(req.export_response_data())
    res = AuthResponse(cfg=cfg, uid=cfg.request.uid)
    res.load_string(data['xml'])

    # Find all the attributes set
    bits = res.lookup_usage_bits()
    print "[%.3f] (%s) -> %s " % (data['latency'], bits, data['ret'])
    if data['err'] is not None and data['err'] != -1:
        print "Err %s: %s " % (data['err'], data['err_message'])