Beispiel #1
0
class SNMPv3Message(univ.Sequence):
    componentType = namedtype.NamedTypes(
        namedtype.NamedType('msgVersion',
                            univ.Integer().subtype(subtypeSpec=constraint.ValueRangeConstraint(0, 2147483647))),
        namedtype.NamedType('msgGlobalData', HeaderData()),
        namedtype.NamedType('msgSecurityParameters', univ.OctetString()),
        namedtype.NamedType('msgData', ScopedPduData())
    )
Beispiel #2
0
class SimplePagedResultsControlValue(univ.Sequence):
    componentType = namedtype.NamedTypes(
        namedtype.NamedType(
            'size',
            univ.Integer().subtype(
                subtypeSpec=constraint.ValueRangeConstraint(0, maxInt))),
        namedtype.NamedType('cookie', univ.OctetString()),
    )
Beispiel #3
0
class BasicConstraints(asn1_univ.Sequence):
    """Custom BasicConstraint implementation until pyasn1_modules is fixes."""
    componentType = asn1_namedtype.NamedTypes(
        asn1_namedtype.DefaultedNamedType('cA', asn1_univ.Boolean(False)),
        asn1_namedtype.OptionalNamedType(
            'pathLenConstraint',
            asn1_univ.Integer().subtype(
                subtypeSpec=asn1_constraint.ValueRangeConstraint(0, 64))))
Beispiel #4
0
class PDU(univ.Sequence):
    componentType = namedtype.NamedTypes(
        namedtype.NamedType('request-id', rfc1902.Integer32()),
        namedtype.NamedType('error-status', errorStatus),
        namedtype.NamedType('error-index',
                            univ.Integer().subtype(subtypeSpec=constraint.ValueRangeConstraint(0, max_bindings))),
        namedtype.NamedType('variable-bindings', VarBindList())
    )
Beispiel #5
0
class UsmSecurityParameters(rfc1155.TypeCoercionHackMixIn, univ.Sequence):
    componentType = namedtype.NamedTypes(
        namedtype.NamedType('msgAuthoritativeEngineID', univ.OctetString()),
        namedtype.NamedType(
            'msgAuthoritativeEngineBoots',
            univ.Integer().subtype(
                subtypeSpec=constraint.ValueRangeConstraint(0, 2147483647))),
        namedtype.NamedType(
            'msgAuthoritativeEngineTime',
            univ.Integer().subtype(
                subtypeSpec=constraint.ValueRangeConstraint(0, 2147483647))),
        namedtype.NamedType(
            'msgUserName',
            univ.OctetString().subtype(
                subtypeSpec=constraint.ValueSizeConstraint(0, 32))),
        namedtype.NamedType('msgAuthenticationParameters', univ.OctetString()),
        namedtype.NamedType('msgPrivacyParameters', univ.OctetString()))
class ExtensionAttribute(univ.Sequence):
    componentType = namedtype.NamedTypes(
        namedtype.NamedType(
            'extension-attribute-type',
            univ.Integer().subtype(subtypeSpec=constraint.ValueRangeConstraint(0, ub_extension_attributes)).subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0))),
        namedtype.NamedType(
            'extension-attribute-value',
            univ.Any().subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1)))
    )
class CMSORIforPSKOtherInfo(univ.Sequence):
    componentType = namedtype.NamedTypes(
        namedtype.NamedType('psk', univ.OctetString()),
        namedtype.NamedType(
            'keyMgmtAlgType',
            univ.Enumerated(
                namedValues=namedval.NamedValues(('keyTrans', 5), ('keyAgree',
                                                                   10)))),
        namedtype.NamedType('keyEncryptionAlgorithm',
                            rfc5652.KeyEncryptionAlgorithmIdentifier()),
        namedtype.NamedType(
            'pskLength',
            univ.Integer().subtype(
                subtypeSpec=constraint.ValueRangeConstraint(1, MAX))),
        namedtype.NamedType(
            'kdkLength',
            univ.Integer().subtype(
                subtypeSpec=constraint.ValueRangeConstraint(1, MAX))))
Beispiel #8
0
class SearchRequest(DefaultSequenceAndSetBaseMixin, univ.Sequence):
    tagSet = univ.Sequence.tagSet.tagImplicitly(
        tag.Tag(tag.tagClassApplication, tag.tagFormatConstructed, 3))
    componentType = namedtype.NamedTypes(
        namedtype.NamedType('baseObject', LDAPDN()),
        namedtype.NamedType('scope', Scope()),
        namedtype.NamedType('derefAliases', DerefAliases()),
        namedtype.NamedType(
            'sizeLimit',
            univ.Integer().subtype(
                subtypeSpec=constraint.ValueRangeConstraint(0, maxInt))),
        namedtype.NamedType(
            'timeLimit',
            univ.Integer().subtype(
                subtypeSpec=constraint.ValueRangeConstraint(0, maxInt))),
        namedtype.NamedType('typesOnly', univ.Boolean()),
        namedtype.NamedType('filter', Filter()),
        namedtype.NamedType('attributes', AttributeSelection()))
Beispiel #9
0
class HeaderData(univ.Sequence):
    componentType = namedtype.NamedTypes(
        namedtype.NamedType(
            'msgID',
            univ.Integer().subtype(
                subtypeSpec=constraint.ValueRangeConstraint(0, 2147483647))),
        namedtype.NamedType(
            'msgMaxSize',
            univ.Integer().subtype(
                subtypeSpec=constraint.ValueRangeConstraint(484, 2147483647))),
        namedtype.NamedType(
            'msgFlags',
            univ.OctetString().subtype(
                subtypeSpec=constraint.ValueSizeConstraint(1, 1))),
        namedtype.NamedType(
            'msgSecurityModel',
            univ.Integer().subtype(
                subtypeSpec=constraint.ValueRangeConstraint(1, 2147483647))))
Beispiel #10
0
class BindRequest(univ.Sequence):
    tagSet = univ.Sequence.tagSet.tagImplicitly(
        tag.Tag(tag.tagClassApplication, tag.tagFormatConstructed, 0)
    )
    componentType = namedtype.NamedTypes(
        namedtype.NamedType('version', univ.Integer().subtype(subtypeSpec=constraint.ValueRangeConstraint(1, 127))),
        namedtype.NamedType('name', LDAPDN()),
        namedtype.NamedType('authentication', AuthenticationChoice())
    )
Beispiel #11
0
class BasicConstraints(univ.Sequence):
    componentType = namedtype.NamedTypes(
        namedtype.OptionalNamedType('cA', univ.Boolean(False)),
        namedtype.OptionalNamedType(
            'pathLenConstraint',
            univ.Integer().subtype(
                subtypeSpec=constraint.ValueRangeConstraint(0, MAX))),
    )
    to_python = extension.parse_basic_constraints
Beispiel #12
0
class Scrypt_params(univ.Sequence):
    componentType = namedtype.NamedTypes(
        namedtype.NamedType('salt', univ.OctetString()),
        namedtype.NamedType(
            'costParameter',
            univ.Integer().subtype(
                subtypeSpec=constraint.ValueRangeConstraint(1, MAX))),
        namedtype.NamedType(
            'blockSize',
            univ.Integer().subtype(
                subtypeSpec=constraint.ValueRangeConstraint(1, MAX))),
        namedtype.NamedType(
            'parallelizationParameter',
            univ.Integer().subtype(
                subtypeSpec=constraint.ValueRangeConstraint(1, MAX))),
        namedtype.OptionalNamedType(
            'keyLength',
            univ.Integer().subtype(
                subtypeSpec=constraint.ValueRangeConstraint(1, MAX))))
Beispiel #13
0
class SearchRequest(univ.Sequence):
    tagSet = univ.Sequence.tagSet.tagImplicitly(
        tag.Tag(tag.tagClassApplication, tag.tagFormatConstructed, 3)
    )
    componentType = namedtype.NamedTypes(
        namedtype.NamedType('baseObject', LDAPDN()),
        namedtype.NamedType('scope', univ.Enumerated(
            namedValues=namedval.NamedValues(('baseObject', 0), ('singleLevel', 1), ('wholeSubtree', 2)))),
        namedtype.NamedType('derefAliases', univ.Enumerated(
            namedValues=namedval.NamedValues(('neverDerefAliases', 0), ('derefInSearching', 1),
                                             ('derefFindingBaseObj', 2), ('derefAlways', 3)))),
        namedtype.NamedType('sizeLimit',
                            univ.Integer().subtype(subtypeSpec=constraint.ValueRangeConstraint(0, maxInt))),
        namedtype.NamedType('timeLimit',
                            univ.Integer().subtype(subtypeSpec=constraint.ValueRangeConstraint(0, maxInt))),
        namedtype.NamedType('typesOnly', univ.Boolean()),
        namedtype.NamedType('filter', Filter()),
        namedtype.NamedType('attributes', AttributeDescriptionList())
    )
Beispiel #14
0
 def addBasicConstraints(self, basicConstraints, critical):
     cA = basicConstraints.split(',')[0]
     pathLenConstraint = basicConstraints.split(',')[1]
     basicConstraintsExtension = rfc2459.BasicConstraints()
     basicConstraintsExtension['cA'] = cA == 'cA'
     if pathLenConstraint:
         pathLenConstraintValue = \
             univ.Integer(int(pathLenConstraint)).subtype(
                 subtypeSpec=constraint.ValueRangeConstraint(0, float('inf')))
         basicConstraintsExtension['pathLenConstraint'] = pathLenConstraintValue
     self.addExtension(rfc2459.id_ce_basicConstraints, basicConstraintsExtension, critical)
Beispiel #15
0
 def addBasicConstraints(self, basicConstraints, critical):
     cA = basicConstraints.split(',')[0]
     pathLenConstraint = basicConstraints.split(',')[1]
     basicConstraintsExtension = rfc2459.BasicConstraints()
     basicConstraintsExtension.setComponentByName('cA', cA == 'cA')
     if pathLenConstraint:
         pathLenConstraintValue = \
             univ.Integer(int(pathLenConstraint)).subtype(
                 subtypeSpec=constraint.ValueRangeConstraint(0, 64))
         basicConstraintsExtension.setComponentByName('pathLenConstraint',
                                                      pathLenConstraintValue)
     self.addExtension(rfc2459.id_ce_basicConstraints, basicConstraintsExtension, critical)
Beispiel #16
0
class HashInput(univ.Sequence):
    componentType = namedtype.NamedTypes(
        namedtype.NamedType(
            'time',
            univ.OctetString().subtype(
                subtypeSpec=constraint.ValueSizeConstraint(8, 8))),
        namedtype.NamedType(
            'randomNumber',
            univ.Integer().subtype(
                subtypeSpec=constraint.ValueRangeConstraint(0, 2147483647))),
        namedtype.NamedType('userName', char.VisibleString()),
        namedtype.NamedType('passWord', univ.OctetString()))
class GvcId(univ.Sequence):
    componentType = namedtype.NamedTypes(
        namedtype.NamedType(
            'spacecraftId',
            univ.Integer().subtype(
                subtypeSpec=constraint.ValueRangeConstraint(0, 1023))),
        namedtype.NamedType(
            'versionNumber',
            univ.Integer().subtype(
                subtypeSpec=constraint.ValueRangeConstraint(0, 3))),
        namedtype.NamedType(
            'vcId',
            univ.Choice(componentType=namedtype.NamedTypes(
                namedtype.NamedType(
                    'masterChannel',
                    univ.Null().subtype(implicitTag=tag.Tag(
                        tag.tagClassContext, tag.tagFormatSimple, 0))),
                namedtype.NamedType(
                    'virtualChannel',
                    VcId().subtype(implicitTag=tag.Tag(
                        tag.tagClassContext, tag.tagFormatSimple, 1)))))))
Beispiel #18
0
class TestAndIncr(Integer, TextualConvention):
    subtypeSpec = Integer.subtypeSpec + constraint.ValueRangeConstraint(
        0, 2147483647)
    defaultValue = 0

    def smiWrite(self, name, value, idx):
        if value != self:
            raise error.InconsistentValueError(idx=idx, name=name)
        value = value + 1
        if value > 2147483646:
            value = 0
        return self.clone(value)
Beispiel #19
0
class HeaderData(univ.Sequence):
    componentType = namedtype.NamedTypes(
        namedtype.NamedType(
            'msgID',
            univ.Integer().subtype(
                subtypeSpec=constraint.ValueRangeConstraint(0, 2147483647))),
        namedtype.NamedType(
            'msgMaxSize',
            univ.Integer().subtype(
                subtypeSpec=constraint.ValueRangeConstraint(484, 2147483647))),
        namedtype.NamedType(
            'msgFlags',
            univ.OctetString().subtype(
                subtypeSpec=constraint.ValueSizeConstraint(1, 1))),
        # NOTE (etingof): constrain SNMPv3 message to only USM+ security models
        # because SNMPv1/v2c seems incompatible in pysnmp implementation, not sure
        # if it's intended by the SNMP standard at all...
        namedtype.NamedType(
            'msgSecurityModel',
            univ.Integer().subtype(
                subtypeSpec=constraint.ValueRangeConstraint(3, 2147483647))))
Beispiel #20
0
 def addBasicConstraints(self, basicConstraints, critical):
     cA = basicConstraints.split(",")[0]
     pathLenConstraint = basicConstraints.split(",")[1]
     basicConstraintsExtension = rfc2459.BasicConstraints()
     basicConstraintsExtension["cA"] = cA == "cA"
     if pathLenConstraint:
         pathLenConstraintValue = univ.Integer(int(pathLenConstraint)).subtype(
             subtypeSpec=constraint.ValueRangeConstraint(0, float("inf"))
         )
         basicConstraintsExtension["pathLenConstraint"] = pathLenConstraintValue
     self.addExtension(
         rfc2459.id_ce_basicConstraints, basicConstraintsExtension, critical
     )
Beispiel #21
0
class ISP1Credentials(univ.Sequence):
    componentType = namedtype.NamedTypes(
        namedtype.NamedType(
            'time',
            univ.OctetString().subtype(
                subtypeSpec=constraint.ValueSizeConstraint(8, 8))),
        namedtype.NamedType(
            'randomNumber',
            univ.Integer().subtype(
                subtypeSpec=constraint.ValueRangeConstraint(0, 2147483647))),
        namedtype.NamedType(
            'theProtected',
            univ.OctetString().subtype(
                subtypeSpec=constraint.ValueSizeConstraint(20, 30))))
Beispiel #22
0
class PDU(univ.Sequence):
    componentType = namedtype.NamedTypes(
        namedtype.NamedType('request-id', rfc1902.Integer32()),
        namedtype.NamedType('error-status', univ.Integer(
            namedValues=namedval.NamedValues(('noError', 0), ('tooBig', 1), ('noSuchName', 2), ('badValue', 3),
                                             ('readOnly', 4), ('genErr', 5), ('noAccess', 6), ('wrongType', 7),
                                             ('wrongLength', 8), ('wrongEncoding', 9), ('wrongValue', 10),
                                             ('noCreation', 11), ('inconsistentValue', 12), ('resourceUnavailable', 13),
                                             ('commitFailed', 14), ('undoFailed', 15), ('authorizationError', 16),
                                             ('notWritable', 17), ('inconsistentName', 18)))),
        namedtype.NamedType('error-index',
                            univ.Integer().subtype(subtypeSpec=constraint.ValueRangeConstraint(0, max_bindings))),
        namedtype.NamedType('variable-bindings', VarBindList())
    )
Beispiel #23
0
class AAControls(univ.Sequence):
    componentType = namedtype.NamedTypes(
        namedtype.OptionalNamedType('pathLenConstraint',
            univ.Integer().subtype(
                subtypeSpec=constraint.ValueRangeConstraint(0, MAX))),
        namedtype.OptionalNamedType('permittedAttrs',
            AttrSpec().subtype(implicitTag=tag.Tag(
                tag.tagClassContext, tag.tagFormatSimple, 0))),
        namedtype.OptionalNamedType('excludedAttrs',
            AttrSpec().subtype(implicitTag=tag.Tag(
                tag.tagClassContext, tag.tagFormatSimple, 1))),
        namedtype.DefaultedNamedType('permitUnSpecified',
            univ.Boolean().subtype(value=1))
    )
Beispiel #24
0
class PDUAPI(v1.PDUAPI):
    _errorStatus = rfc1905.errorStatus.clone(0)
    _errorIndex = univ.Integer(0).subtype(
        subtypeSpec=constraint.ValueRangeConstraint(0, rfc1905.max_bindings))

    def getResponse(self, reqPDU):
        rspPDU = ResponsePDU()
        self.setDefaults(rspPDU)
        self.setRequestID(rspPDU, self.getRequestID(reqPDU))
        return rspPDU

    def getVarBindTable(self, reqPDU, rspPDU):
        return [apiPDU.getVarBinds(rspPDU)]

    def getNextVarBinds(self, varBinds, errorIndex=None):
        errorIndication = None

        rspVarBinds = []

        if errorIndex:
            return errorIndication, rspVarBinds

        for idx, varBind in enumerate(varBinds):
            if varBind[1].tagSet in (rfc1905.NoSuchObject.tagSet,
                                     rfc1905.NoSuchInstance.tagSet,
                                     rfc1905.EndOfMibView.tagSet):
                continue

            rspVarBinds.append((varBind[0], null))

        return errorIndication, rspVarBinds

    def setEndOfMibError(self, pdu, errorIndex):
        varBindList = self.getVarBindList(pdu)
        varBindList[errorIndex - 1].setComponentByPosition(
            1,
            rfc1905.endOfMibView,
            verifyConstraints=False,
            matchTags=False,
            matchConstraints=False)

    def setNoSuchInstanceError(self, pdu, errorIndex):
        varBindList = self.getVarBindList(pdu)
        varBindList[errorIndex - 1].setComponentByPosition(
            1,
            rfc1905.noSuchInstance,
            verifyConstraints=False,
            matchTags=False,
            matchConstraints=False)
Beispiel #25
0
class Manifest(univ.Sequence):
    componentType = namedtype.NamedTypes(
        namedtype.DefaultedNamedType('version',
            univ.Integer().subtype(explicitTag=tag.Tag(
                tag.tagClassContext, tag.tagFormatSimple, 0)).subtype(value=0)),
        namedtype.NamedType('manifestNumber',
            univ.Integer().subtype(
                subtypeSpec=constraint.ValueRangeConstraint(0, MAX))),
        namedtype.NamedType('thisUpdate',
            useful.GeneralizedTime()),
        namedtype.NamedType('nextUpdate',
            useful.GeneralizedTime()),
        namedtype.NamedType('fileHashAlg',
            univ.ObjectIdentifier()),
        namedtype.NamedType('fileList',
            univ.SequenceOf(componentType=FileAndHash()).subtype(
                subtypeSpec=constraint.ValueSizeConstraint(0, MAX)))
    )
Beispiel #26
0
class PDUAPI(v1.PDUAPI):
    _errorStatus = rfc1905._errorStatus.clone(0)
    _errorIndex = univ.Integer(0).subtype(
        subtypeSpec=constraint.ValueRangeConstraint(0, rfc1905.max_bindings))

    def getResponse(self, reqPDU):
        rspPDU = ResponsePDU()
        self.setDefaults(rspPDU)
        self.setRequestID(rspPDU, self.getRequestID(reqPDU))
        return rspPDU

    def getVarBindTable(self, reqPDU, rspPDU):
        return [apiPDU.getVarBinds(rspPDU)]

    def setEndOfMibError(self, pdu, errorIndex):
        varBindList = self.getVarBindList(pdu)
        varBindList[errorIndex - 1].setComponentByPosition(
            1, rfc1905.endOfMibView, verifyConstraints=False)

    def setNoSuchInstanceError(self, pdu, errorIndex):
        varBindList = self.getVarBindList(pdu)
        varBindList[errorIndex - 1].setComponentByPosition(
            1, rfc1905.noSuchInstance, verifyConstraints=False)
Beispiel #27
0
class Counter64(univ.Integer):
    """Creates an instance of SNMP Counter64 class.

    :py:class:`~pysnmp.proto.rfc1902.Counter64` type represents
    a non-negative integer which monotonically increases until it reaches
    a maximum value of 18446744073709551615, when it wraps around and starts
    increasing again from zero (:RFC:`1902#section-7.1.10`).

    Parameters
    ----------
    initializer : int
        Python integer in range between 0 to 4294967295 inclusive
        or any :py:class:`~pysnmp.proto.rfc1902.Integer`-based class.

    Raises
    ------
        PyAsn1Error :
            On constraint violation or bad initializer.

    Examples
    --------
        >>> from pysnmp.proto.rfc1902 import *
        >>> Counter64(1234)
        Counter64(1234)
        >>> Counter64(1) + 1
        Counter64(2)
        >>> int(Counter64(321))
        321
        >>>

    """
    tagSet = univ.Integer.tagSet.tagImplicitly(
        tag.Tag(tag.tagClassApplication, tag.tagFormatSimple, 0x06)
    )
    subtypeSpec = univ.Integer.subtypeSpec + constraint.ValueRangeConstraint(
        0, 18446744073709551615
    )
Beispiel #28
0
class Gauge32(univ.Integer):
    """Creates an instance of SNMP Gauge32 class.

    :py:class:`~pysnmp.proto.rfc1902.Gauge32` type represents
    a non-negative integer, which may increase or decrease, but shall
    never exceed a maximum value. The maximum value can not be greater
    than 4294967295 (:RFC:`1902#section-7.1.7`).

    Parameters
    ----------
    initializer : int
        Python integer in range between 0 to 4294967295 inclusive
        or any :py:class:`~pysnmp.proto.rfc1902.Integer`-based class.

    Raises
    ------
        PyAsn1Error :
            On constraint violation or bad initializer.

    Examples
    --------
        >>> from pysnmp.proto.rfc1902 import *
        >>> Gauge32(1234)
        Gauge32(1234)
        >>> Gauge32(1) + 1
        Gauge32(2)
        >>> int(Gauge32(321))
        321
        >>>

    """
    tagSet = univ.Integer.tagSet.tagImplicitly(
        tag.Tag(tag.tagClassApplication, tag.tagFormatSimple, 0x02)
    )
    subtypeSpec = univ.Integer.subtypeSpec + constraint.ValueRangeConstraint(
        0, 4294967295
    )
Beispiel #29
0
class TimeTicks(univ.Integer):
    """Creates an instance of SNMP TimeTicks class.

    :py:class:`~pysnmp.proto.rfc1902.TimeTicks` type represents
    a non-negative integer which represents the time, modulo 4294967296,
    in hundredths of a second between two epochs (:RFC:`1902#section-7.1.8`).

    Parameters
    ----------
    initializer : int
        Python integer in range between 0 to 4294967295 inclusive
        or any :py:class:`~pysnmp.proto.rfc1902.Integer`-based class.

    Raises
    ------
        PyAsn1Error :
            On constraint violation or bad initializer.

    Examples
    --------
        >>> from pysnmp.proto.rfc1902 import *
        >>> TimeTicks(1234)
        TimeTicks(1234)
        >>> TimeTicks(1) + 1
        TimeTicks(2)
        >>> int(TimeTicks(321))
        321
        >>>

    """
    tagSet = univ.Integer.tagSet.tagImplicitly(
        tag.Tag(tag.tagClassApplication, tag.tagFormatSimple, 0x03)
    )
    subtypeSpec = univ.Integer.subtypeSpec + constraint.ValueRangeConstraint(
        0, 4294967295
    )
Beispiel #30
0
class Unsigned32(univ.Integer):
    """Creates an instance of SNMP Unsigned32 class.

    :py:class:`~pysnmp.proto.rfc1902.Unsigned32` type represents
    integer-valued information between 0 and 4294967295
    (:RFC:`1902#section-7.1.11`).

    Parameters
    ----------
    initializer : int
        Python integer in range between 0 to 4294967295 inclusive
        or any :py:class:`~pysnmp.proto.rfc1902.Integer`-based class.

    Raises
    ------
        PyAsn1Error :
            On constraint violation or bad initializer.

    Examples
    --------
        >>> from pysnmp.proto.rfc1902 import *
        >>> Unsigned32(1234)
        Unsigned32(1234)
        >>> Unsigned32(1) + 1
        Unsigned32(2)
        >>> int(Unsigned32(321))
        321
        >>>

    """
    tagSet = univ.Integer.tagSet.tagImplicitly(
        tag.Tag(tag.tagClassApplication, tag.tagFormatSimple, 0x02)
    )
    subtypeSpec = univ.Integer.subtypeSpec + constraint.ValueRangeConstraint(
        0, 4294967295
    )