Example #1
0
 def setUp(self):
     self.path = os.path.join(home, 'tests', 'data')
     self.dict = Dictionary(os.path.join(self.path, 'full'))
     self.packet = packet.AcctPacket(
         id=0,
         secret=six.b('secret'),
         authenticator=six.b('01234567890ABCDEF'),
         dict=self.dict)
Example #2
0
    def testVerifyAcctRequest(self):
        rawpacket = self.packet.RequestPacket()
        pkt = packet.AcctPacket(secret=six.b('secret'), packet=rawpacket)
        self.assertEqual(pkt.VerifyAcctRequest(), True)

        pkt.secret = six.b('different')
        self.assertEqual(pkt.VerifyAcctRequest(), False)
        pkt.secret = six.b('secret')

        pkt.raw_packet = six.b('X') + pkt.raw_packet[1:]
        self.assertEqual(pkt.VerifyAcctRequest(), False)
Example #3
0
    def CreateAcctPacket(self, **args):
        """Create a new accounting RADIUS packet.
        This utility function creates a new accouting RADIUS packet
        which can be used to communicate with the RADIUS server this
        client talks to. This is initializing the new packet with the
        dictionary and secret used for the client.

        :return: a new empty packet instance
        :rtype:  pyrad.packet.AcctPacket
        """
        return packet.AcctPacket(dict=self.dict, **args)
Example #4
0
 def testAcctPacketEncryptionFailure(self):
     '''Accounting Packets are not supposed to use encryption.'''
     pkt = packet.AcctPacket(dict=self.dict,
                             auto_crypt=True,
                             secret=six.b('secret'),
                             authenticator=six.b('01234567890ABCDEF'))
     with self.assertRaises(ValueError):
         # Encode
         pkt['Test-Password'] = six.u('test')
     pkt[4] = [six.b('0000')]  # Set raw password field
     with self.assertRaises(ValueError):
         # Decode
         pkt['Test-Password']
Example #5
0
 def build_acct_request(self):
     req = packet.AcctPacket(dict=self.dict,secret=self.acctsecret)
     for _row in range(self.acct_attr_table.rowCount()):
         attr_name_item = self.acct_attr_table.item(_row,0)
         attr_val_item = self.acct_attr_table.item(_row,1)
         flag_item =  self.acct_attr_table.item(_row,2)
         attr_name = attr_name_item and str(attr_name_item.text())
         attr_val = attr_val_item and str(attr_val_item.text())
         flag = flag_item and flag_item.text()
         if attr_name and attr_val and flag == '1':
             val = self.encode_attr(attr_name,attr_val)
             if val :
                 req[attr_name] = val
     return req
    def _create_request(self, alias, code):
        client = self._get_session(self._client,alias)
        secret = client['secret']
        dictionary = client['dictionary']

        if code == packet.AccessRequest:
          request = packet.AuthPacket(code=code, secret=secret,
                                      dict=dictionary)

        elif code in [packet.AccountingRequest, packet.CoARequest, packet.DisconnectRequest]:
          request = packet.AcctPacket(code=code, secret=secret,
                                      dict=dictionary)

        client['request'].register(request, str(request.id))
        return request
Example #7
0
    def sendacct(self):
        req = packet.AcctPacket(dict=self.dict,secret=self.acctsecret)
        req['User-Name'] = self.argvals.username
        req['Acct-Status-Type'] = status_vars[self.argvals.acct]

        for _key in  self.config.options("acct_attrs"):
            req[_key] = self._get_val('acct_attrs',_key)

        _attrs_key = "acct_attrs_%s"%self.argvals.acct
        for _key in  self.config.options(_attrs_key):
            req[_key] = self._get_val(_attrs_key,_key)

        if self.argvals.debug:
            attr_keys = req.keys()
            print ("send an accounting request")
            print ("Attributes: ")        
            for attr in attr_keys:
                print ( "%s: %s" % (attr, _decode_attr(self.dict,attr,req[attr][0])))            
        
        self.sock.sendto(req.RequestPacket(),(self.server,self.acctport)) 
Example #8
0
 def testRealisticUnknownAttributes(self):
     """ Test a realistic Accounting Packet from raw
     User-Name: [u'*****@*****.**']
     NAS-IP-Address: ['1.2.3.4']
     Service-Type: ['Framed-User']
     Framed-Protocol: ['NAS-Prompt-User']
     Framed-IP-Address: ['1.2.3.4']
     Acct-Status-Type: ['Interim-Update']
     Acct-Delay-Time: [0]
     Acct-Input-Octets: [1290826858]
     Acct-Output-Octets: [3551101035]
     Acct-Session-Id: [u'90dbd65a18b0a6c']
     Acct-Authentic: ['RADIUS']
     Acct-Session-Time: [769500]
     Acct-Input-Packets: [7403861]
     Acct-Output-Packets: [10928170]
     Acct-Link-Count: [1]
     Acct-Input-Gigawords: [0]
     Acct-Output-Gigawords: [2]
     Event-Timestamp: [1554155989]
     # vendor specific
     NAS-Port-Type: ['Virtual']
     (26, 594, 1): [u'UNKNOWN_PRODUCT']
     # implementation specific fields
     224: ['24P\x10\x00\x22\x96\xc9']
     228: ['\xfe\x99\xd0P']
     """
     path = os.path.join(home, 'tests', 'data')
     dictObj = Dictionary(os.path.join(path, 'realistic'))
     raw = six.b('\x04\x8e\x00\xc4\xb2\xf8z\xdb\xac\xfd9l\x9dI?E\x8c%\xe9'\
             '\xf5\x01\[email protected]\x04\x06\x01\x02\x03\x04\x06\x06'\
             '\x00\x00\x00\x02\x07\x06\x00\x00\x00\x07\x08\x06\x01\x02\x03'\
             '\x04(\x06\x00\x00\x00\x03)\x06\x00\x00\x00\x00*\x06L\xf0tj+'\
             '\x06\xd3\xa9\x80k,\x1190dbd65a18b0a6c-\x06\x00\x00\x00\x01.'\
             '\x06\x00\x0b\xbd\xdc/\x06\x00p\xf9U0\x06\x00\xa6\xc0*3\x06'\
             '\x00\x00\x00\x014\x06\x00\x00\x00\x005\x06\x00\x00\x00\x027'\
             '\x06\\\xa2\x89\xd5=\x06\x00\x00\x00\x05\x1a\x17\x00\x00\x02R'\
             '\x01\x11UNKNOWN_PRODUCT\xe0\n24P\x10\x00\x22\x96\xc9\xe4\x06'\
             '\xfe\x99\xd0P')
     pkt = packet.AcctPacket(dict=dictObj, packet=raw)
     self.assertEqual(pkt.raw_packet, raw)