def IsIdenticalFunctionTo(self, comparison_obj): if isinstance(comparison_obj, Udp): if (Util.ArePortsEqual(comparison_obj.DestPort, self.DestPort) and Util.ArePortsEqual(comparison_obj.SourcePort, self.SourcePort)): return True return False
def __init__(self, ip_protocol, attributes_list=None, valid_attributes=None, dest_port=None, source_port=None): self.ip_protocol = ip_protocol if attributes_list and len(attributes_list) > 0: # set member defaults self.dest_port = [PortNumbers.dynamic] self.source_port = [PortNumbers.dynamic] # validate input attributes invalid_items = list() if Util.InvalidAttributesPresent(attributes_list, valid_attributes, invalid_items): raise ProtocolException( '%s : %s' % (resources["protocol_attributes_invalid"], invalid_items[0])) # also check for same attributes specified multiple times if Util.DuplicateAttributesPresent(attributes_list, valid_attributes): raise ProtocolException( '%s : %s' % (resources['duplicate_protocol_attributes'], attributes_list)) # populate members from attributes try: self.PopulatePortDetails(attributes_list, valid_attributes) self.PopulateComment(attributes_list, valid_attributes) # TODO:: populate any tcp flags #if self.ip_protocol==Ipv4ProtocolNumbers.tcp: # self.PopulateTcpFlags(attributes_list,valid_attributes) except AttributeError, e: raise ProtocolException(e.message)
def PopulateComment(self, attributes_list, valid_attributes): result = list() # non empty attribute list passed in, validate.. attribute_values = Util.GetAttributeValues(attributes_list, valid_attributes) if Util.IsCommentAvailable(ProtocolAttributes.comment, attribute_values, result): self.comment = result[0]
def __init__(self, attributes_list): # set member defaults # TODO: set default icmp type = echo? self.icmp_type = None self.icmp_code = None if not attributes_list or len(attributes_list) == 0: raise AttributeError(resources['protocol_attributes_invalid']) # list of valid icmp attributes valid_attributes = [ ProtocolAttributes.icmp_type, ProtocolAttributes.icmp_code, ProtocolAttributes.comment ] # validate input attributes invalid_items = list() if Util.InvalidAttributesPresent(attributes_list, valid_attributes, invalid_items): raise ProtocolException( '%s : %s' % (resources["protocol_attributes_invalid"], invalid_items[0])) # populate members from attributes try: result = list() attribute_values = Util.GetAttributeValues(attributes_list, valid_attributes) if Util.IsIcmpTypeValueAvailable(ProtocolAttributes.icmp_type, attribute_values, result): self.icmp_type = result[0] else: # invalid raise ProtocolException("%s" % (resources["icmp_type_not_specified"])) self.PopulateComment(attributes_list, valid_attributes) # clear list result = list() if Util.IsIcmpCodeValueAvailable(ProtocolAttributes.icmp_code, attribute_values, result): self.icmp_code = result[0] except AttributeError, e: raise ProtocolException(e.message)
def PopulatePortDetails(self, attributes_list, valid_port_attributes): result = list() # non empty attribute list passed in, validate.. attribute_values = Util.GetAttributeValues(attributes_list, valid_port_attributes) if Util.IsPortValueAvailable(ProtocolAttributes.tcp_dest_port, attribute_values, result): self.dest_port = result[0] elif Util.IsPortValueAvailable(ProtocolAttributes.udp_dest_port, attribute_values, result): self.dest_port = result[0] # clear list result = list() if Util.IsPortValueAvailable(ProtocolAttributes.tcp_source_port, attribute_values, result): self.source_port = result[0] elif Util.IsPortValueAvailable(ProtocolAttributes.udp_source_port, attribute_values, result): self.source_port = result[0]
def __init__(self, attributes_list): # list of valid icmp attributes valid_attributes = [ProtocolAttributes.comment] # validate input attributes invalid_items = list() if Util.InvalidAttributesPresent(attributes_list, valid_attributes, invalid_items): raise ProtocolException( '%s : %s' % (resources["protocol_attributes_invalid"], invalid_items[0])) # populate members from attributes try: self.PopulateComment(attributes_list, valid_attributes) except AttributeError, e: raise ProtocolException(e.message)
self.PopulatePortDetails(attributes_list, valid_attributes) self.PopulateComment(attributes_list, valid_attributes) # TODO:: populate any tcp flags #if self.ip_protocol==Ipv4ProtocolNumbers.tcp: # self.PopulateTcpFlags(attributes_list,valid_attributes) except AttributeError, e: raise ProtocolException(e.message) else: # set port values self.dest_port = dest_port self.source_port = source_port # TODO:: populate any tcp flags # final check for compliance if (Util.ArePortsEqual(self.dest_port, [PortNumbers.all]) and Util.ArePortsEqual(self.source_port, [PortNumbers.all]) or Util.ArePortsEqual(self.dest_port, [PortNumbers.all]) and Util.ArePortsEqual(self.source_port, [PortNumbers.dynamic]) or Util.ArePortsEqual(self.dest_port, [PortNumbers.dynamic]) and Util.ArePortsEqual(self.source_port, [PortNumbers.all]) or Util.ArePortsEqual(self.dest_port, [PortNumbers.dynamic]) and Util.ArePortsEqual(self.source_port, [PortNumbers.dynamic])): raise ProtocolException(resources["generic_services_disallowed"]) return @property def IpProtocol(self): return self.ip_protocol