Registry / auth-security / pysnmpcrypto

pysnmpcrypto

JSON →
library0.1.0pypypi✓ verified 85d ago

pysnmpcrypto provides strong cryptographic support for the PySNMP library, enhancing security for SNMPv3 operations. It integrates seamlessly with PySNMP's security framework by leveraging PyCryptodome. The current version is 0.1.0, with releases typically tied to updates in its core dependencies, PySNMP and PyCryptodome.

pip install pysnmpcrypto
INSTALL
IMPORT
SIG · PYSNMPCRYPTO
P
pysnmpcrypto
auth-securitypythonv0.1.0
Install
2.4s avg
Import
Disk
33MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.1.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 34.4MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 2.4s · import 0.000s · 35MB
33MB installed
● package 33MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

PysnmpCryptoError
from pysnmpcrypto import PysnmpCryptoError
import pysnmpcrypto.hl.api
generic_encrypt
from pysnmpcrypto import generic_encrypt
generic_decrypt
from pysnmpcrypto import generic_decrypt

This quickstart demonstrates how to enable and use strong cryptographic protocols (like SHA512 for authentication and AES256 for privacy) for SNMPv3 within PySNMP by simply importing `pysnmpcrypto.hl.api`. It sets up an SNMPv3 user with these protocols and attempts to perform a GET operation against a public test agent. For this to fully succeed, the target agent must be configured with a matching user and supported security levels.

from pysnmp.hlapi import * import pysnmpcrypto.hl.api # This import enables strong crypto support # 1. SNMP Engine and User Definition snmp_engine = SnmpEngine() # Define an SNMPv3 user with strong authentication (SHA512) and privacy (AES256). # These protocols are enabled by 'pysnmpcrypto'. # In a real scenario, 'authKey' and 'privKey' should be strong, unique values. auth_key = b'myAuthPassword123' priv_key = b'myPrivPassword456' user_data = UsmUserData( userName='testUser', authKey=auth_key, privKey=priv_key, authProtocol=usmHMACSHA512AuthProtocol, # Requires pysnmpcrypto privProtocol=usmAES256PrivProtocol # Requires pysnmpcrypto ) # 2. Target Agent Definition (using a public test server for demonstration) # Note: 'testUser' must be configured on the target agent with matching keys/protocols. target = UdpTransportTarget(('demo.snmplabs.com', 161), timeout=1, retries=0) # 3. Context Data context = ContextData() # 4. Object to query (e.g., sysDescr.0) oid = ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)) # 5. Perform the SNMP GET operation print(f"Attempting to query {oid} using SNMPv3 with SHA512/AES256 (requires pysnmpcrypto)...") error_indication, error_status, error_index, var_binds = next( getCmd(snmp_engine, user_data, target, context, oid) ) # 6. Process the response if error_indication: print(f"Error: {error_indication}") elif error_status: print(f"Error: {error_status.prettyPrint()} at {error_index and var_binds[int(error_index) - 1][0] or '?'}") else: for var_bind in var_binds: print(f"{var_bind.prettyPrint()}") # The key takeaway is that usmHMACSHA512AuthProtocol and usmAES256PrivProtocol # become available for use after 'import pysnmpcrypto.hl.api'. # A successful connection depends on the target agent supporting the user and protocols.
Debug
Known issues
gotchapysnmpcrypto is an extension for PySNMP. It requires `pysnmp` to be installed and specifically requires PySNMP version `4.4.0` or higher to function correctly and provide access to the extended cryptographic algorithms.
fix
Ensure `pip install pysnmp>=4.4.0` is performed before or alongside `pysnmpcrypto`.
affects: < 0.1.0 (implicitly, based on PySNMP requirement)
gotchaThe library depends on `pycryptodome` for its cryptographic operations. If `pycryptodome` is not installed, pysnmpcrypto will not be able to provide the strong encryption algorithms, potentially leading to errors when attempting to use protocols like SHA512 or AES256.
fix
Install the underlying cryptography library: `pip install pycryptodome`.
affects: All
gotchapysnmpcrypto primarily enhances SNMPv3 security. While PySNMP supports other SNMP versions, the strong authentication and privacy protocols provided by this library are specific to SNMPv3's User-based Security Model (USM).
fix
Ensure you are configuring your SNMP operations to use SNMPv3 and the appropriate `UsmUserData`.
affects: All
gotchaPython version compatibility: pysnmpcrypto requires Python `>=3.8` and `<4.0`. Ensure your environment matches this requirement, as PySNMP itself might have broader compatibility, but this extension is more specific.
fix
Use a Python environment within the `3.8 <= Python < 4.0` range.
affects: All
breakingAs a relatively new library (v0.1.0), future major versions might introduce breaking changes to how it integrates with PySNMP or to its exposed (albeit limited) API. Keep an eye on the GitHub repository for release notes.
fix
Refer to official release notes on the GitHub repository for migration guides when upgrading to new major versions.
affects: Future versions > 0.1.0
Upgrade
Version history
0.1.0latest on PyPI · released Sep 9, 2024
Audit
Dependencies
pysnmprequiredCore SNMP library it extends; required for all functionality. Requires version >= 4.4.0.
pycryptodomerequiredUnderlying cryptographic implementation; provides the strong algorithms.
Agent activity
10 hits · last 30 days
node
6
Amazon
3
OpenAI (training)
1
Resources
pysnmpcrypto — pip install pysnmpcrypto · libregistry