summaryrefslogtreecommitdiff
path: root/pysnmp/proto/secmod/eso
diff options
context:
space:
mode:
Diffstat (limited to 'pysnmp/proto/secmod/eso')
-rw-r--r--pysnmp/proto/secmod/eso/priv/aes192.py8
-rw-r--r--pysnmp/proto/secmod/eso/priv/aes256.py8
-rw-r--r--pysnmp/proto/secmod/eso/priv/aesbase.py33
-rw-r--r--pysnmp/proto/secmod/eso/priv/des3.py43
4 files changed, 48 insertions, 44 deletions
diff --git a/pysnmp/proto/secmod/eso/priv/aes192.py b/pysnmp/proto/secmod/eso/priv/aes192.py
index 399a225b..7df0a0f5 100644
--- a/pysnmp/proto/secmod/eso/priv/aes192.py
+++ b/pysnmp/proto/secmod/eso/priv/aes192.py
@@ -14,8 +14,8 @@ class AesBlumenthal192(aesbase.AbstractAesBlumenthal):
http://tools.ietf.org/html/draft-blumenthal-aes-usm-04
"""
- serviceID = (1, 3, 6, 1, 4, 1, 9, 12, 6, 1, 1) # cusmAESCfb192PrivProtocol
- keySize = 24
+ SERVICE_ID = (1, 3, 6, 1, 4, 1, 9, 12, 6, 1, 1) # cusmAESCfb192PrivProtocol
+ KEY_SIZE = 24
class Aes192(aesbase.AbstractAesReeder):
@@ -29,5 +29,5 @@ class Aes192(aesbase.AbstractAesReeder):
Known to be used by many vendors including Cisco and others.
"""
- serviceID = (1, 3, 6, 1, 4, 1, 9, 12, 6, 1, 101) # cusmAESCfb192PrivProtocol (non-standard OID)
- keySize = 24
+ SERVICE_ID = (1, 3, 6, 1, 4, 1, 9, 12, 6, 1, 101) # cusmAESCfb192PrivProtocol (non-standard OID)
+ KEY_SIZE = 24
diff --git a/pysnmp/proto/secmod/eso/priv/aes256.py b/pysnmp/proto/secmod/eso/priv/aes256.py
index 360f26c3..94a255ff 100644
--- a/pysnmp/proto/secmod/eso/priv/aes256.py
+++ b/pysnmp/proto/secmod/eso/priv/aes256.py
@@ -12,8 +12,8 @@ class AesBlumenthal256(aesbase.AbstractAesBlumenthal):
http://tools.ietf.org/html/draft-blumenthal-aes-usm-04
"""
- serviceID = (1, 3, 6, 1, 4, 1, 9, 12, 6, 1, 2) # cusmAESCfb256PrivProtocol
- keySize = 32
+ SERVICE_ID = (1, 3, 6, 1, 4, 1, 9, 12, 6, 1, 2) # cusmAESCfb256PrivProtocol
+ KEY_SIZE = 32
class Aes256(aesbase.AbstractAesReeder):
@@ -27,5 +27,5 @@ class Aes256(aesbase.AbstractAesReeder):
Known to be used by many vendors including Cisco and others.
"""
- serviceID = (1, 3, 6, 1, 4, 1, 9, 12, 6, 1, 102) # cusmAESCfb256PrivProtocol (non-standard OID)
- keySize = 32
+ SERVICE_ID = (1, 3, 6, 1, 4, 1, 9, 12, 6, 1, 102) # cusmAESCfb256PrivProtocol (non-standard OID)
+ KEY_SIZE = 32
diff --git a/pysnmp/proto/secmod/eso/priv/aesbase.py b/pysnmp/proto/secmod/eso/priv/aesbase.py
index 676afbbb..f2527cec 100644
--- a/pysnmp/proto/secmod/eso/priv/aesbase.py
+++ b/pysnmp/proto/secmod/eso/priv/aesbase.py
@@ -13,6 +13,7 @@ from math import ceil
try:
from hashlib import md5, sha1
+
except ImportError:
import md5
import sha
@@ -22,17 +23,17 @@ except ImportError:
class AbstractAesBlumenthal(aes.Aes):
- serviceID = ()
- keySize = 0
+ SERVICE_ID = ()
+ KEY_SIZE = 0
# 3.1.2.1
def localizeKey(self, authProtocol, privKey, snmpEngineID):
- if authProtocol == hmacmd5.HmacMd5.serviceID:
+ if authProtocol == hmacmd5.HmacMd5.SERVICE_ID:
hashAlgo = md5
- elif authProtocol == hmacsha.HmacSha.serviceID:
+ elif authProtocol == hmacsha.HmacSha.SERVICE_ID:
hashAlgo = sha1
- elif authProtocol in hmacsha2.HmacSha2.hashAlgorithms:
- hashAlgo = hmacsha2.HmacSha2.hashAlgorithms[authProtocol]
+ elif authProtocol in hmacsha2.HmacSha2.HASH_ALGORITHM:
+ hashAlgo = hmacsha2.HmacSha2.HASH_ALGORITHM[authProtocol]
else:
raise error.ProtocolError(
'Unknown auth protocol %s' % (authProtocol,)
@@ -41,10 +42,10 @@ class AbstractAesBlumenthal(aes.Aes):
localPrivKey = localkey.localizeKey(privKey, snmpEngineID, hashAlgo)
# now extend this key if too short by repeating steps that includes the hashPassphrase step
- for count in range(1, int(ceil(self.keySize * 1.0 / len(localPrivKey)))):
+ for count in range(1, int(ceil(self.KEY_SIZE * 1.0 / len(localPrivKey)))):
localPrivKey += hashAlgo(localPrivKey).digest()
- return localPrivKey[:self.keySize]
+ return localPrivKey[:self.KEY_SIZE]
class AbstractAesReeder(aes.Aes):
@@ -62,17 +63,17 @@ class AbstractAesReeder(aes.Aes):
The difference between the two is that the Reeder draft does key extension by repeating
the steps in the password to key algorithm (hash phrase, then localize with SNMPEngine ID).
"""
- serviceID = ()
- keySize = 0
+ SERVICE_ID = ()
+ KEY_SIZE = 0
# 2.1 of https://tools.itef.org/pdf/draft_bluementhal-aes-usm-04.txt
def localizeKey(self, authProtocol, privKey, snmpEngineID):
- if authProtocol == hmacmd5.HmacMd5.serviceID:
+ if authProtocol == hmacmd5.HmacMd5.SERVICE_ID:
hashAlgo = md5
- elif authProtocol == hmacsha.HmacSha.serviceID:
+ elif authProtocol == hmacsha.HmacSha.SERVICE_ID:
hashAlgo = sha1
- elif authProtocol in hmacsha2.HmacSha2.hashAlgorithms:
- hashAlgo = hmacsha2.HmacSha2.hashAlgorithms[authProtocol]
+ elif authProtocol in hmacsha2.HmacSha2.HASH_ALGORITHM:
+ hashAlgo = hmacsha2.HmacSha2.HASH_ALGORITHM[authProtocol]
else:
raise error.ProtocolError(
'Unknown auth protocol %s' % (authProtocol,)
@@ -81,9 +82,9 @@ class AbstractAesReeder(aes.Aes):
localPrivKey = localkey.localizeKey(privKey, snmpEngineID, hashAlgo)
# now extend this key if too short by repeating steps that includes the hashPassphrase step
- while len(localPrivKey) < self.keySize:
+ while len(localPrivKey) < self.KEY_SIZE:
# this is the difference between reeder and bluementhal
newKey = localkey.hashPassphrase(localPrivKey, hashAlgo)
localPrivKey += localkey.localizeKey(newKey, snmpEngineID, hashAlgo)
- return localPrivKey[:self.keySize]
+ return localPrivKey[:self.KEY_SIZE]
diff --git a/pysnmp/proto/secmod/eso/priv/des3.py b/pysnmp/proto/secmod/eso/priv/des3.py
index fa6e20b9..bb3f8516 100644
--- a/pysnmp/proto/secmod/eso/priv/des3.py
+++ b/pysnmp/proto/secmod/eso/priv/des3.py
@@ -5,8 +5,10 @@
# License: http://snmplabs.com/pysnmp/license.html
#
import random
+
try:
from hashlib import md5, sha1
+
except ImportError:
import md5
import sha
@@ -39,17 +41,18 @@ class Des3(base.AbstractEncryptionService):
https://tools.ietf.org/html/draft-reeder-snmpv3-usm-3desede-00
"""
- serviceID = (1, 3, 6, 1, 6, 3, 10, 1, 2, 3) # usm3DESEDEPrivProtocol
- keySize = 32
- _localInt = random.randrange(0, 0xffffffff)
+ SERVICE_ID = (1, 3, 6, 1, 6, 3, 10, 1, 2, 3) # usm3DESEDEPrivProtocol
+ KEY_SIZE = 32
+
+ local_int = random.randrange(0, 0xffffffff)
def hashPassphrase(self, authProtocol, privKey):
- if authProtocol == hmacmd5.HmacMd5.serviceID:
+ if authProtocol == hmacmd5.HmacMd5.SERVICE_ID:
hashAlgo = md5
- elif authProtocol == hmacsha.HmacSha.serviceID:
+ elif authProtocol == hmacsha.HmacSha.SERVICE_ID:
hashAlgo = sha1
- elif authProtocol in hmacsha2.HmacSha2.hashAlgorithms:
- hashAlgo = hmacsha2.HmacSha2.hashAlgorithms[authProtocol]
+ elif authProtocol in hmacsha2.HmacSha2.HASH_ALGORITHM:
+ hashAlgo = hmacsha2.HmacSha2.HASH_ALGORITHM[authProtocol]
else:
raise error.ProtocolError(
'Unknown auth protocol %s' % (authProtocol,)
@@ -58,12 +61,12 @@ class Des3(base.AbstractEncryptionService):
# 2.1
def localizeKey(self, authProtocol, privKey, snmpEngineID):
- if authProtocol == hmacmd5.HmacMd5.serviceID:
+ if authProtocol == hmacmd5.HmacMd5.SERVICE_ID:
hashAlgo = md5
- elif authProtocol == hmacsha.HmacSha.serviceID:
+ elif authProtocol == hmacsha.HmacSha.SERVICE_ID:
hashAlgo = sha1
- elif authProtocol in hmacsha2.HmacSha2.hashAlgorithms:
- hashAlgo = hmacsha2.HmacSha2.hashAlgorithms[authProtocol]
+ elif authProtocol in hmacsha2.HmacSha2.HASH_ALGORITHM:
+ hashAlgo = hmacsha2.HmacSha2.HASH_ALGORITHM[authProtocol]
else:
raise error.ProtocolError(
'Unknown auth protocol %s' % (authProtocol,)
@@ -71,12 +74,12 @@ class Des3(base.AbstractEncryptionService):
localPrivKey = localkey.localizeKey(privKey, snmpEngineID, hashAlgo)
# now extend this key if too short by repeating steps that includes the hashPassphrase step
- while len(localPrivKey) < self.keySize:
+ while len(localPrivKey) < self.KEY_SIZE:
# this is the difference between reeder and bluementhal
newKey = localkey.hashPassphrase(localPrivKey, hashAlgo)
localPrivKey += localkey.localizeKey(newKey, snmpEngineID, hashAlgo)
- return localPrivKey[:self.keySize]
+ return localPrivKey[:self.KEY_SIZE]
# 5.1.1.1
def __getEncryptionKey(self, privKey, snmpEngineBoots):
@@ -91,15 +94,15 @@ class Des3(base.AbstractEncryptionService):
securityEngineBoots >> 16 & 0xff,
securityEngineBoots >> 8 & 0xff,
securityEngineBoots & 0xff,
- self._localInt >> 24 & 0xff,
- self._localInt >> 16 & 0xff,
- self._localInt >> 8 & 0xff,
- self._localInt & 0xff
+ self.local_int >> 24 & 0xff,
+ self.local_int >> 16 & 0xff,
+ self.local_int >> 8 & 0xff,
+ self.local_int & 0xff
]
- if self._localInt == 0xffffffff:
- self._localInt = 0
+ if self.local_int == 0xffffffff:
+ self.local_int = 0
else:
- self._localInt += 1
+ self.local_int += 1
# salt not yet hashed XXX