1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
from pysnmp.entity import config
from pyasn1.compat.octets import null
class CommunityData:
mpModel = 1 # Default is SMIv2
securityModel = mpModel + 1
securityLevel = 'noAuthNoPriv'
contextName = null
tag = null
def __init__(self, securityName, communityName=None, mpModel=None,
contextEngineId=None, contextName=None, tag=None):
self.securityName = securityName
self.communityName = communityName
if mpModel is not None:
self.mpModel = mpModel
self.securityModel = mpModel + 1
self.contextEngineId = contextEngineId
if contextName is not None:
self.contextName = contextName
if tag is not None:
self.tag = tag
# Autogenerate securityName if not specified
if communityName is None:
self.communityName = securityName
self.securityName = 's%s' % hash(
( securityName, self.mpModel,
self.contextEngineId, self.contextName, self.tag )
)
def __repr__(self):
return '%s("%s", <COMMUNITY>, %r, %r, %r, %r)' % (
self.__class__.__name__,
self.securityName,
self.mpModel,
self.contextEngineId,
self.contextName,
self.tag
)
def __hash__(self): return hash(self.securityName)
def __eq__(self, other): return self.securityName == other
def __ne__(self, other): return self.securityName != other
def __lt__(self, other): return self.securityName < other
def __le__(self, other): return self.securityName <= other
def __gt__(self, other): return self.securityName > other
def __ge__(self, other): return self.securityName >= other
class UsmUserData:
authKey = privKey = None
authProtocol = config.usmNoAuthProtocol
privProtocol = config.usmNoPrivProtocol
securityLevel = 'noAuthNoPriv'
securityModel = 3
mpModel = 3
contextName = null
def __init__(self, securityName,
authKey=None, privKey=None,
authProtocol=None, privProtocol=None,
contextEngineId=None, contextName=None):
self.securityName = securityName
if authKey is not None:
self.authKey = authKey
if authProtocol is None:
self.authProtocol = config.usmHMACMD5AuthProtocol
else:
self.authProtocol = authProtocol
if self.securityLevel != 'authPriv':
self.securityLevel = 'authNoPriv'
if privKey is not None:
self.privKey = privKey
if self.authProtocol == config.usmNoAuthProtocol:
raise error.PySnmpError('Privacy implies authenticity')
self.securityLevel = 'authPriv'
if privProtocol is None:
self.privProtocol = config.usmDESPrivProtocol
else:
self.privProtocol = privProtocol
self.contextEngineId = contextEngineId
if contextName is not None:
self.contextName = contextName
def __repr__(self):
return '%s("%s", <AUTHKEY>, <PRIVKEY>, %r, %r, %r, %r)' % (
self.__class__.__name__,
self.securityName,
self.authProtocol,
self.privProtocol,
self.contextEngineId,
self.contextName
)
def __hash__(self): return hash(self.securityName)
def __eq__(self, other): return self.securityName == other
def __ne__(self, other): return self.securityName != other
def __lt__(self, other): return self.securityName < other
def __le__(self, other): return self.securityName <= other
def __gt__(self, other): return self.securityName > other
def __ge__(self, other): return self.securityName >= other
|