Python socket.IPPROTO_AH属性代码示例

本文整理汇总了Python中socket.IPPROTO_AH属性的典型用法代码示例。如果您正苦于以下问题:Python socket.IPPROTO_AH属性的具体用法?Python socket.IPPROTO_AH怎么用?Python socket.IPPROTO_AH使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在模块socket的用法示例。

在下文中一共展示了socket.IPPROTO_AH属性的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: _encrypt_ah

# 需要导入模块: import socket [as 别名]
# 或者: from socket import IPPROTO_AH [as 别名]
def _encrypt_ah(self, pkt, seq_num=None):
        ah = AH(spi=self.spi, seq=seq_num or self.seq_num,
                icv=chr(0) * self.auth_algo.icv_size)
        if self.tunnel_header:
            tunnel = self.tunnel_header.copy()
            if tunnel.version == 4:
                del tunnel.proto
                del tunnel.len
                del tunnel.chksum
            else:
                del tunnel.nh
                del tunnel.plen
            pkt = tunnel.__class__(str(tunnel / pkt))
        ip_header, nh, payload = split_for_transport(pkt, socket.IPPROTO_AH)
        ah.nh = nh
        if ip_header.version == 6 and len(ah) % 8 != 0:
            # For IPv6, the total length of the header must be a multiple of
            # 8-octet units.
            ah.padding = chr(0) * (-len(ah) % 8)
        elif len(ah) % 4 != 0:
            # For IPv4, the total length of the header must be a multiple of
            # 4-octet units.
            ah.padding = chr(0) * (-len(ah) % 4)
        # RFC 4302 - Section 2.2. Payload Length
        # This 8-bit field specifies the length of AH in 32-bit words (4-byte
        # units), minus "2".
        ah.payloadlen = len(ah) / 4 - 2
        if ip_header.version == 4:
            ip_header.len = len(ip_header) + len(ah) + len(payload)
            del ip_header.chksum
            ip_header = ip_header.__class__(str(ip_header))
        else:
            ip_header.plen = len(ip_header.payload) + len(ah) + len(payload)
        signed_pkt = self.auth_algo.sign(ip_header / ah / payload, self.auth_key)
        # sequence number must always change, unless specified by the user
        if seq_num is None:
            self.seq_num += 1
        return signed_pkt 
开发者ID:theralfbrown,项目名称:smod-1,代码行数:51,代码来源:ipsec.py


示例2: _encrypt_ah

# 需要导入模块: import socket [as 别名]
# 或者: from socket import IPPROTO_AH [as 别名]
def _encrypt_ah(self, pkt, seq_num=None, esn_en=False, esn=0):
        ah = AH(spi=self.spi, seq=seq_num or self.seq_num,
                icv=b"\x00" * self.auth_algo.icv_size)
        if self.tunnel_header:
            tunnel = self.tunnel_header.copy()
            if tunnel.version == 4:
                del tunnel.proto
                del tunnel.len
                del tunnel.chksum
            else:
                del tunnel.nh
                del tunnel.plen
            pkt = tunnel.__class__(raw(tunnel / pkt))
        ip_header, nh, payload = split_for_transport(pkt, socket.IPPROTO_AH)
        ah.nh = nh
        if ip_header.version == 6 and len(ah) % 8 != 0:
            # For IPv6, the total length of the header must be a multiple of
            # 8-octet units.
            ah.padding = b"\x00" * (-len(ah) % 8)
        elif len(ah) % 4 != 0:
            # For IPv4, the total length of the header must be a multiple of
            # 4-octet units.
            ah.padding = b"\x00" * (-len(ah) % 4)
        # RFC 4302 - Section 2.2. Payload Length
        # This 8-bit field specifies the length of AH in 32-bit words (4-byte
        # units), minus "2".
        ah.payloadlen = len(ah) // 4 - 2
        if ip_header.version == 4:
            ip_header.len = len(ip_header) + len(ah) + len(payload)
            del ip_header.chksum
            ip_header = ip_header.__class__(raw(ip_header))
        else:
            ip_header.plen = len(ip_header.payload) + len(ah) + len(payload)
        signed_pkt = self.auth_algo.sign(ip_header / ah / payload,
                                         self.auth_key,
                                         esn_en=esn_en or self.esn_en,
                                         esn=esn or self.esn)
        # sequence number must always change, unless specified by the user
        if seq_num is None:
            self.seq_num += 1
        return signed_pkt 
开发者ID:secdev,项目名称:scapy,代码行数:54,代码来源:ipsec.py


示例3: _encrypt_ah

# 需要导入模块: import socket [as 别名]
# 或者: from socket import IPPROTO_AH [as 别名]
def _encrypt_ah(self, pkt, seq_num=None):
        ah = AH(spi=self.spi, seq=seq_num or self.seq_num,
                icv=chr(0) * self.auth_algo.icv_size)
        if self.tunnel_header:
            tunnel = self.tunnel_header.copy()
            if tunnel.version == 4:
                del tunnel.proto
                del tunnel.len
                del tunnel.chksum
            else:
                del tunnel.nh
                del tunnel.plen
            pkt = tunnel.__class__(bytes(tunnel / pkt))
        ip_header, nh, payload = split_for_transport(pkt, socket.IPPROTO_AH)
        ah.nh = nh
        if ip_header.version == 6 and len(ah) % 8 != 0:
            # For IPv6, the total length of the header must be a multiple of
            # 8-octet units.
            ah.padding = chr(0) * (-len(ah) % 8)
        elif len(ah) % 4 != 0:
            # For IPv4, the total length of the header must be a multiple of
            # 4-octet units.
            ah.padding = chr(0) * (-len(ah) % 4)
        # RFC 4302 - Section 2.2. Payload Length
        # This 8-bit field specifies the length of AH in 32-bit words (4-byte
        # units), minus "2".
        ah.payloadlen = len(ah) // 4 - 2
        if ip_header.version == 4:
            ip_header.len = len(ip_header) + len(ah) + len(payload)
            del ip_header.chksum
            ip_header = ip_header.__class__(bytes(ip_header))
        else:
            ip_header.plen = len(ip_header.payload) + len(ah) + len(payload)
        signed_pkt = self.auth_algo.sign(ip_header / ah / payload, self.auth_key)
        # sequence number must always change, unless specified by the user
        if seq_num is None:
            self.seq_num += 1
        return signed_pkt 
开发者ID:phaethon,项目名称:kamene,代码行数:51,代码来源:ipsec.py



注:本文中的socket.IPPROTO_AH属性示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。