summaryrefslogtreecommitdiff
path: root/pysnmp/proto/secmod
diff options
context:
space:
mode:
Diffstat (limited to 'pysnmp/proto/secmod')
-rw-r--r--pysnmp/proto/secmod/base.py2
-rw-r--r--pysnmp/proto/secmod/eso/priv/aesbase.py22
-rw-r--r--pysnmp/proto/secmod/eso/priv/des3.py19
-rw-r--r--pysnmp/proto/secmod/rfc2576.py10
-rw-r--r--pysnmp/proto/secmod/rfc3414/auth/base.py3
-rw-r--r--pysnmp/proto/secmod/rfc3414/auth/hmacmd5.py14
-rw-r--r--pysnmp/proto/secmod/rfc3414/auth/hmacsha.py13
-rw-r--r--pysnmp/proto/secmod/rfc3414/auth/noauth.py3
-rw-r--r--pysnmp/proto/secmod/rfc3414/localkey.py17
-rw-r--r--pysnmp/proto/secmod/rfc3414/priv/des.py18
-rw-r--r--pysnmp/proto/secmod/rfc3414/priv/nopriv.py3
-rw-r--r--pysnmp/proto/secmod/rfc3414/service.py33
-rw-r--r--pysnmp/proto/secmod/rfc3826/priv/aes.py18
-rw-r--r--pysnmp/proto/secmod/rfc7860/auth/hmacsha2.py6
14 files changed, 82 insertions, 99 deletions
diff --git a/pysnmp/proto/secmod/base.py b/pysnmp/proto/secmod/base.py
index 70850bcf..0f80f255 100644
--- a/pysnmp/proto/secmod/base.py
+++ b/pysnmp/proto/secmod/base.py
@@ -4,8 +4,8 @@
# Copyright (c) 2005-2019, Ilya Etingof <etingof@gmail.com>
# License: http://snmplabs.com/pysnmp/license.html
#
-from pysnmp.proto.secmod import cache
from pysnmp.proto import error
+from pysnmp.proto.secmod import cache
class AbstractSecurityModel(object):
diff --git a/pysnmp/proto/secmod/eso/priv/aesbase.py b/pysnmp/proto/secmod/eso/priv/aesbase.py
index f2527cec..0c2e5d17 100644
--- a/pysnmp/proto/secmod/eso/priv/aesbase.py
+++ b/pysnmp/proto/secmod/eso/priv/aesbase.py
@@ -4,22 +4,16 @@
# Copyright (c) 2005-2019, Ilya Etingof <etingof@gmail.com>
# License: http://snmplabs.com/pysnmp/license.html
#
-from pysnmp.proto.secmod.rfc3826.priv import aes
-from pysnmp.proto.secmod.rfc3414.auth import hmacmd5, hmacsha
-from pysnmp.proto.secmod.rfc7860.auth import hmacsha2
-from pysnmp.proto.secmod.rfc3414 import localkey
-from pysnmp.proto import error
+from hashlib import md5
+from hashlib import sha1
from math import ceil
-try:
- from hashlib import md5, sha1
-
-except ImportError:
- import md5
- import sha
-
- md5 = md5.new
- sha1 = sha.new
+from pysnmp.proto import error
+from pysnmp.proto.secmod.rfc3414 import localkey
+from pysnmp.proto.secmod.rfc3414.auth import hmacmd5
+from pysnmp.proto.secmod.rfc3414.auth import hmacsha
+from pysnmp.proto.secmod.rfc3826.priv import aes
+from pysnmp.proto.secmod.rfc7860.auth import hmacsha2
class AbstractAesBlumenthal(aes.Aes):
diff --git a/pysnmp/proto/secmod/eso/priv/des3.py b/pysnmp/proto/secmod/eso/priv/des3.py
index bb3f8516..da84475b 100644
--- a/pysnmp/proto/secmod/eso/priv/des3.py
+++ b/pysnmp/proto/secmod/eso/priv/des3.py
@@ -5,16 +5,8 @@
# License: http://snmplabs.com/pysnmp/license.html
#
import random
-
-try:
- from hashlib import md5, sha1
-
-except ImportError:
- import md5
- import sha
-
- md5 = md5.new
- sha1 = sha.new
+from hashlib import md5
+from hashlib import sha1
try:
from pysnmpcrypto import des3, PysnmpCryptoError
@@ -24,12 +16,13 @@ except ImportError:
des3 = None
from pysnmp.proto.secmod.rfc3414.priv import base
-from pysnmp.proto.secmod.rfc3414.auth import hmacmd5, hmacsha
+from pysnmp.proto.secmod.rfc3414.auth import hmacmd5
+from pysnmp.proto.secmod.rfc3414.auth import hmacsha
from pysnmp.proto.secmod.rfc3414 import localkey
from pysnmp.proto.secmod.rfc7860.auth import hmacsha2
-from pysnmp.proto import errind, error
+from pysnmp.proto import errind
+from pysnmp.proto import error
from pyasn1.type import univ
-from pyasn1.compat.octets import null
random.seed()
diff --git a/pysnmp/proto/secmod/rfc2576.py b/pysnmp/proto/secmod/rfc2576.py
index 392294f9..ba11b0fe 100644
--- a/pysnmp/proto/secmod/rfc2576.py
+++ b/pysnmp/proto/secmod/rfc2576.py
@@ -4,14 +4,16 @@
# Copyright (c) 2005-2019, Ilya Etingof <etingof@gmail.com>
# License: http://snmplabs.com/pysnmp/license.html
#
-import sys
from pyasn1.codec.ber import encoder
from pyasn1.error import PyAsn1Error
+
+from pysnmp import debug
+from pysnmp.carrier.asyncore.dgram import udp
+from pysnmp.carrier.asyncore.dgram import udp6
+from pysnmp.proto import errind
+from pysnmp.proto import error
from pysnmp.proto.secmod import base
-from pysnmp.carrier.asyncore.dgram import udp, udp6
from pysnmp.smi.error import NoSuchInstanceError
-from pysnmp.proto import errind, error
-from pysnmp import debug
class SnmpV1SecurityModel(base.AbstractSecurityModel):
diff --git a/pysnmp/proto/secmod/rfc3414/auth/base.py b/pysnmp/proto/secmod/rfc3414/auth/base.py
index 1c019aea..5bb6e660 100644
--- a/pysnmp/proto/secmod/rfc3414/auth/base.py
+++ b/pysnmp/proto/secmod/rfc3414/auth/base.py
@@ -4,7 +4,8 @@
# Copyright (c) 2005-2019, Ilya Etingof <etingof@gmail.com>
# License: http://snmplabs.com/pysnmp/license.html
#
-from pysnmp.proto import errind, error
+from pysnmp.proto import errind
+from pysnmp.proto import error
class AbstractAuthenticationService(object):
diff --git a/pysnmp/proto/secmod/rfc3414/auth/hmacmd5.py b/pysnmp/proto/secmod/rfc3414/auth/hmacmd5.py
index 3ce12da2..df3db63f 100644
--- a/pysnmp/proto/secmod/rfc3414/auth/hmacmd5.py
+++ b/pysnmp/proto/secmod/rfc3414/auth/hmacmd5.py
@@ -4,18 +4,14 @@
# Copyright (c) 2005-2019, Ilya Etingof <etingof@gmail.com>
# License: http://snmplabs.com/pysnmp/license.html
#
-try:
- from hashlib import md5
-
-except ImportError:
- import md5
-
- md5 = md5.new
+from hashlib import md5
from pyasn1.type import univ
-from pysnmp.proto.secmod.rfc3414.auth import base
+
+from pysnmp.proto import errind
+from pysnmp.proto import error
from pysnmp.proto.secmod.rfc3414 import localkey
-from pysnmp.proto import errind, error
+from pysnmp.proto.secmod.rfc3414.auth import base
TWELVE_ZEROS = univ.OctetString((0,) * 12).asOctets()
FORTY_EIGHT_ZEROS = (0,) * 48
diff --git a/pysnmp/proto/secmod/rfc3414/auth/hmacsha.py b/pysnmp/proto/secmod/rfc3414/auth/hmacsha.py
index 8776f6fb..4d5498d1 100644
--- a/pysnmp/proto/secmod/rfc3414/auth/hmacsha.py
+++ b/pysnmp/proto/secmod/rfc3414/auth/hmacsha.py
@@ -4,17 +4,14 @@
# Copyright (c) 2005-2019, Ilya Etingof <etingof@gmail.com>
# License: http://snmplabs.com/pysnmp/license.html
#
-try:
- from hashlib import sha1
-except ImportError:
- import sha
-
- sha1 = sha.new
+from hashlib import sha1
from pyasn1.type import univ
-from pysnmp.proto.secmod.rfc3414.auth import base
+
+from pysnmp.proto import errind
+from pysnmp.proto import error
from pysnmp.proto.secmod.rfc3414 import localkey
-from pysnmp.proto import errind, error
+from pysnmp.proto.secmod.rfc3414.auth import base
TWELVE_ZEROS = univ.OctetString((0,) * 12).asOctets()
FORTY_FOUR_ZEROS = (0,) * 44
diff --git a/pysnmp/proto/secmod/rfc3414/auth/noauth.py b/pysnmp/proto/secmod/rfc3414/auth/noauth.py
index d97d4888..c0c8329c 100644
--- a/pysnmp/proto/secmod/rfc3414/auth/noauth.py
+++ b/pysnmp/proto/secmod/rfc3414/auth/noauth.py
@@ -4,8 +4,9 @@
# Copyright (c) 2005-2019, Ilya Etingof <etingof@gmail.com>
# License: http://snmplabs.com/pysnmp/license.html
#
+from pysnmp.proto import errind
+from pysnmp.proto import error
from pysnmp.proto.secmod.rfc3414.auth import base
-from pysnmp.proto import errind, error
class NoAuth(base.AbstractAuthenticationService):
diff --git a/pysnmp/proto/secmod/rfc3414/localkey.py b/pysnmp/proto/secmod/rfc3414/localkey.py
index 651722e4..144342fa 100644
--- a/pysnmp/proto/secmod/rfc3414/localkey.py
+++ b/pysnmp/proto/secmod/rfc3414/localkey.py
@@ -4,39 +4,34 @@
# Copyright (c) 2005-2019, Ilya Etingof <etingof@gmail.com>
# License: http://snmplabs.com/pysnmp/license.html
#
-try:
- from hashlib import md5, sha1
-
-except ImportError:
- import md5
- import sha
-
- md5 = md5.new
- sha1 = sha.new
+from hashlib import md5
+from hashlib import sha1
from pyasn1.type import univ
def hashPassphrase(passphrase, hashFunc):
passphrase = univ.OctetString(passphrase).asOctets()
- # noinspection PyDeprecation,PyCallingNonCallable
hasher = hashFunc()
ringBuffer = passphrase * (64 // len(passphrase) + 1)
- # noinspection PyTypeChecker
ringBufferLen = len(ringBuffer)
count = 0
mark = 0
+
while count < 16384:
e = mark + 64
if e < ringBufferLen:
hasher.update(ringBuffer[mark:e])
mark = e
+
else:
hasher.update(
ringBuffer[mark:ringBufferLen] + ringBuffer[0:e - ringBufferLen]
)
mark = e - ringBufferLen
+
count += 1
+
return hasher.digest()
diff --git a/pysnmp/proto/secmod/rfc3414/priv/des.py b/pysnmp/proto/secmod/rfc3414/priv/des.py
index a9a1137c..5128a662 100644
--- a/pysnmp/proto/secmod/rfc3414/priv/des.py
+++ b/pysnmp/proto/secmod/rfc3414/priv/des.py
@@ -5,16 +5,8 @@
# License: http://snmplabs.com/pysnmp/license.html
#
import random
-
-try:
- from hashlib import md5, sha1
-
-except ImportError:
- import md5
- import sha
-
- md5 = md5.new
- sha1 = sha.new
+from hashlib import md5
+from hashlib import sha1
try:
from pysnmpcrypto import des, PysnmpCryptoError
@@ -24,10 +16,12 @@ except ImportError:
des = None
from pysnmp.proto.secmod.rfc3414.priv import base
-from pysnmp.proto.secmod.rfc3414.auth import hmacmd5, hmacsha
+from pysnmp.proto.secmod.rfc3414.auth import hmacmd5
+from pysnmp.proto.secmod.rfc3414.auth import hmacsha
from pysnmp.proto.secmod.rfc3414 import localkey
from pysnmp.proto.secmod.rfc7860.auth import hmacsha2
-from pysnmp.proto import errind, error
+from pysnmp.proto import errind
+from pysnmp.proto import error
from pyasn1.type import univ
random.seed()
diff --git a/pysnmp/proto/secmod/rfc3414/priv/nopriv.py b/pysnmp/proto/secmod/rfc3414/priv/nopriv.py
index 7283e6ec..358ea33d 100644
--- a/pysnmp/proto/secmod/rfc3414/priv/nopriv.py
+++ b/pysnmp/proto/secmod/rfc3414/priv/nopriv.py
@@ -4,8 +4,9 @@
# Copyright (c) 2005-2019, Ilya Etingof <etingof@gmail.com>
# License: http://snmplabs.com/pysnmp/license.html
#
+from pysnmp.proto import errind
+from pysnmp.proto import error
from pysnmp.proto.secmod.rfc3414.priv import base
-from pysnmp.proto import errind, error
class NoPriv(base.AbstractEncryptionService):
diff --git a/pysnmp/proto/secmod/rfc3414/service.py b/pysnmp/proto/secmod/rfc3414/service.py
index a09b98ed..f9bf056b 100644
--- a/pysnmp/proto/secmod/rfc3414/service.py
+++ b/pysnmp/proto/secmod/rfc3414/service.py
@@ -5,20 +5,33 @@
# License: http://snmplabs.com/pysnmp/license.html
#
import time
-import sys
+
+from pyasn1.codec.ber import decoder
+from pyasn1.codec.ber import encoder
+from pyasn1.codec.ber import eoo
+from pyasn1.compat.octets import null
+from pyasn1.error import PyAsn1Error
+from pyasn1.type import constraint
+from pyasn1.type import namedtype
+from pyasn1.type import univ
+
+from pysnmp import debug
+from pysnmp.proto import errind
+from pysnmp.proto import error
+from pysnmp.proto import rfc1155
+from pysnmp.proto import rfc3411
from pysnmp.proto.secmod.base import AbstractSecurityModel
-from pysnmp.proto.secmod.rfc3414.auth import hmacmd5, hmacsha, noauth
-from pysnmp.proto.secmod.rfc3414.priv import des, nopriv
+from pysnmp.proto.secmod.eso.priv import aes192
+from pysnmp.proto.secmod.eso.priv import aes256
+from pysnmp.proto.secmod.eso.priv import des3
+from pysnmp.proto.secmod.rfc3414.auth import hmacmd5
+from pysnmp.proto.secmod.rfc3414.auth import hmacsha
+from pysnmp.proto.secmod.rfc3414.auth import noauth
+from pysnmp.proto.secmod.rfc3414.priv import des
+from pysnmp.proto.secmod.rfc3414.priv import nopriv
from pysnmp.proto.secmod.rfc3826.priv import aes
from pysnmp.proto.secmod.rfc7860.auth import hmacsha2
-from pysnmp.proto.secmod.eso.priv import des3, aes192, aes256
from pysnmp.smi.error import NoSuchInstanceError
-from pysnmp.proto import rfc1155, rfc3411, errind, error
-from pysnmp import debug
-from pyasn1.type import univ, namedtype, constraint
-from pyasn1.codec.ber import encoder, decoder, eoo
-from pyasn1.error import PyAsn1Error
-from pyasn1.compat.octets import null
# USM security params
diff --git a/pysnmp/proto/secmod/rfc3826/priv/aes.py b/pysnmp/proto/secmod/rfc3826/priv/aes.py
index 8a67ecc2..56f69280 100644
--- a/pysnmp/proto/secmod/rfc3826/priv/aes.py
+++ b/pysnmp/proto/secmod/rfc3826/priv/aes.py
@@ -5,16 +5,8 @@
# License: http://snmplabs.com/pysnmp/license.html
#
import random
-
-try:
- from hashlib import md5, sha1
-
-except ImportError:
- import md5
- import sha
-
- md5 = md5.new
- sha1 = sha.new
+from hashlib import md5
+from hashlib import sha1
try:
from pysnmpcrypto import aes, PysnmpCryptoError
@@ -25,10 +17,12 @@ except ImportError:
from pyasn1.type import univ
from pysnmp.proto.secmod.rfc3414.priv import base
-from pysnmp.proto.secmod.rfc3414.auth import hmacmd5, hmacsha
+from pysnmp.proto.secmod.rfc3414.auth import hmacmd5
+from pysnmp.proto.secmod.rfc3414.auth import hmacsha
from pysnmp.proto.secmod.rfc7860.auth import hmacsha2
from pysnmp.proto.secmod.rfc3414 import localkey
-from pysnmp.proto import errind, error
+from pysnmp.proto import errind
+from pysnmp.proto import error
random.seed()
diff --git a/pysnmp/proto/secmod/rfc7860/auth/hmacsha2.py b/pysnmp/proto/secmod/rfc7860/auth/hmacsha2.py
index 495f8fcd..11dd79b3 100644
--- a/pysnmp/proto/secmod/rfc7860/auth/hmacsha2.py
+++ b/pysnmp/proto/secmod/rfc7860/auth/hmacsha2.py
@@ -4,10 +4,12 @@
# Copyright (c) 2005-2018, Olivier Verriest <verri@x25.pm>
# License: http://snmplabs.com/pysnmp/license.html
#
-import sys
import hmac
try:
- from hashlib import sha224, sha256, sha384, sha512
+ from hashlib import sha224
+ from hashlib import sha256
+ from hashlib import sha384
+ from hashlib import sha512
except ImportError: