Python pyasn1.type.univ.ObjectIdentifier() Examples
The following are 30
code examples of pyasn1.type.univ.ObjectIdentifier().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pyasn1.type.univ
, or try the search function
.
Example #1
Source File: mibvar.py From scalyr-agent-2 with Apache License 2.0 | 6 votes |
def oidToMibName(mibView, oid): if not isinstance(oid, tuple): oid = tuple(univ.ObjectIdentifier(oid)) _oid, label, suffix = mibView.getNodeNameByOid(oid) modName, symName, __suffix = mibView.getNodeLocation(_oid) mibNode, = mibView.mibBuilder.importSymbols( modName, symName ) if hasattr(mibNode, 'createTest'): # table column __modName, __symName, __s = mibView.getNodeLocation(_oid[:-1]) rowNode, = mibView.mibBuilder.importSymbols(__modName, __symName) return (symName, modName), rowNode.getIndicesFromInstId(suffix) elif not suffix: # scalar return (symName, modName), suffix elif suffix == (0,): # scalar return (symName, modName), __scalarSuffix else: raise NoSuchObjectError( str='No MIB registered that defines %s object, closest known parent is %s (%s::%s)' % (univ.ObjectIdentifier(oid), univ.ObjectIdentifier(mibNode.name), modName, symName) ) # Value
Example #2
Source File: test_rfc3279.py From pyasn1-modules with BSD 2-Clause "Simplified" License | 6 votes |
def testDerCodec(self): substrate = pem.readBase64fromText(self.ec_cert_pem_text) asn1Object, rest = der_decoder(substrate, asn1Spec=self.asn1Spec) self.assertFalse(rest) self.assertTrue(asn1Object.prettyPrint()) self.assertEqual(substrate, der_encoder(asn1Object)) spki_a = asn1Object['tbsCertificate']['subjectPublicKeyInfo']['algorithm'] self.assertEqual(rfc3279.id_ecPublicKey, spki_a['algorithm']) spki_a_p, rest = der_decoder( spki_a['parameters'], asn1Spec=rfc3279.EcpkParameters()) self.assertFalse(rest) self.assertTrue(spki_a_p.prettyPrint()) self.assertEqual(spki_a['parameters'], der_encoder(spki_a_p)) self.assertEqual(univ.ObjectIdentifier('1.3.132.0.34'), spki_a_p['namedCurve'])
Example #3
Source File: key.py From bash-lambda-layer with MIT License | 6 votes |
def load_pkcs1_openssl_der(cls, keyfile): """Loads a PKCS#1 DER-encoded public key file from OpenSSL. :param keyfile: contents of a DER-encoded file that contains the public key, from OpenSSL. :return: a PublicKey object """ from rsa.asn1 import OpenSSLPubKey from pyasn1.codec.der import decoder from pyasn1.type import univ (keyinfo, _) = decoder.decode(keyfile, asn1Spec=OpenSSLPubKey()) if keyinfo['header']['oid'] != univ.ObjectIdentifier('1.2.840.113549.1.1.1'): raise TypeError("This is not a DER-encoded OpenSSL-compatible public key") return cls._load_pkcs1_der(keyinfo['key'][1:])
Example #4
Source File: test_rfc7030.py From pyasn1-modules with BSD 2-Clause "Simplified" License | 6 votes |
def testOpenTypes(self): openTypesMap = rfc5652.cmsAttributesMap.copy() for at in self.the_attrTypes: openTypesMap.update({at: univ.ObjectIdentifier()}) substrate = pem.readBase64fromText(self.pem_text) asn1Object, rest = der_decoder( substrate, asn1Spec=self.asn1Spec, openTypes=openTypesMap, decodeOpenTypes=True) self.assertFalse(rest) self.assertTrue(asn1Object.prettyPrint()) self.assertEqual(substrate, der_encoder(asn1Object)) for attr_or_oid in asn1Object: if attr_or_oid.getName() == 'attribute': valString = attr_or_oid['attribute']['attrValues'][0].prettyPrint() if attr_or_oid['attribute']['attrType'] == self.the_attrTypes[0]: self.assertEqual(self.the_attrVals[0], valString) if attr_or_oid['attribute']['attrType'] == self.the_attrTypes[1]: self.assertEqual(self.the_attrVals[1], valString)
Example #5
Source File: key.py From aqua-monitor with GNU Lesser General Public License v3.0 | 6 votes |
def load_pkcs1_openssl_der(cls, keyfile): """Loads a PKCS#1 DER-encoded public key file from OpenSSL. :param keyfile: contents of a DER-encoded file that contains the public key, from OpenSSL. :return: a PublicKey object """ from rsa.asn1 import OpenSSLPubKey from pyasn1.codec.der import decoder from pyasn1.type import univ (keyinfo, _) = decoder.decode(keyfile, asn1Spec=OpenSSLPubKey()) if keyinfo['header']['oid'] != univ.ObjectIdentifier('1.2.840.113549.1.1.1'): raise TypeError("This is not a DER-encoded OpenSSL-compatible public key") return cls._load_pkcs1_der(keyinfo['key'][1:])
Example #6
Source File: key.py From baidupan_shell with GNU General Public License v2.0 | 6 votes |
def load_pkcs1_openssl_der(cls, keyfile): '''Loads a PKCS#1 DER-encoded public key file from OpenSSL. @param keyfile: contents of a DER-encoded file that contains the public key, from OpenSSL. @return: a PublicKey object ''' from rsa.asn1 import OpenSSLPubKey from pyasn1.codec.der import decoder from pyasn1.type import univ (keyinfo, _) = decoder.decode(keyfile, asn1Spec=OpenSSLPubKey()) if keyinfo['header']['oid'] != univ.ObjectIdentifier('1.2.840.113549.1.1.1'): raise TypeError("This is not a DER-encoded OpenSSL-compatible public key") return cls._load_pkcs1_der(keyinfo['key'][1:])
Example #7
Source File: test_rfc5958.py From pyasn1-modules with BSD 2-Clause "Simplified" License | 6 votes |
def testOpenTypes(self): substrate = pem.readBase64fromText(self.asymmetric_key_pkg_pem_text) asn1Object, rest = der_decoder( substrate, asn1Spec=self.asn1Spec, decodeOpenTypes=True) self.assertFalse(rest) self.assertTrue(asn1Object.prettyPrint()) self.assertEqual(substrate, der_encoder(asn1Object)) self.assertIn( rfc5958.id_ct_KP_aKeyPackage, rfc5652.cmsContentTypesMap) oneKey = asn1Object['content'][0] self.assertEqual( rfc8410.id_Ed25519, oneKey['privateKeyAlgorithm']['algorithm']) pkcs_9_at_friendlyName = univ.ObjectIdentifier('1.2.840.113549.1.9.9.20') self.assertEqual( pkcs_9_at_friendlyName, oneKey['attributes'][0]['attrType'])
Example #8
Source File: securityblob.py From addon with GNU General Public License v3.0 | 6 votes |
def generateNegotiateSecurityBlob(ntlm_data): mech_token = univ.OctetString(ntlm_data).subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 2)) mech_types = MechTypeList().subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0)) mech_types.setComponentByPosition(0, univ.ObjectIdentifier('1.3.6.1.4.1.311.2.2.10')) n = NegTokenInit().subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0)) n.setComponentByName('mechTypes', mech_types) n.setComponentByName('mechToken', mech_token) nt = NegotiationToken() nt.setComponentByName('negTokenInit', n) ct = ContextToken() ct.setComponentByName('thisMech', univ.ObjectIdentifier('1.3.6.1.5.5.2')) ct.setComponentByName('innerContextToken', nt) return encoder.encode(ct)
Example #9
Source File: key.py From xbmc-addons-chinese with GNU General Public License v2.0 | 6 votes |
def load_pkcs1_openssl_der(cls, keyfile): """Loads a PKCS#1 DER-encoded public key file from OpenSSL. :param keyfile: contents of a DER-encoded file that contains the public key, from OpenSSL. :return: a PublicKey object """ from rsa.asn1 import OpenSSLPubKey from pyasn1.codec.der import decoder from pyasn1.type import univ (keyinfo, _) = decoder.decode(keyfile, asn1Spec=OpenSSLPubKey()) if keyinfo['header']['oid'] != univ.ObjectIdentifier('1.2.840.113549.1.1.1'): raise TypeError("This is not a DER-encoded OpenSSL-compatible public key") return cls._load_pkcs1_der(keyinfo['key'][1:])
Example #10
Source File: key.py From xbmc-addons-chinese with GNU General Public License v2.0 | 6 votes |
def load_pkcs1_openssl_der(cls, keyfile): """Loads a PKCS#1 DER-encoded public key file from OpenSSL. :param keyfile: contents of a DER-encoded file that contains the public key, from OpenSSL. :return: a PublicKey object """ from rsa.asn1 import OpenSSLPubKey from pyasn1.codec.der import decoder from pyasn1.type import univ (keyinfo, _) = decoder.decode(keyfile, asn1Spec=OpenSSLPubKey()) if keyinfo['header']['oid'] != univ.ObjectIdentifier('1.2.840.113549.1.1.1'): raise TypeError("This is not a DER-encoded OpenSSL-compatible public key") return cls._load_pkcs1_der(keyinfo['key'][1:])
Example #11
Source File: sign_pythonrsa.py From luci-py with Apache License 2.0 | 6 votes |
def _load_rsa_private_key(pem): """PEM encoded PKCS#8 private key -> rsa.PrivateKey.""" # ADB uses private RSA keys in pkcs#8 format. 'rsa' library doesn't support # them natively. Do some ASN unwrapping to extract naked RSA key # (in der-encoded form). See https://www.ietf.org/rfc/rfc2313.txt. # Also http://superuser.com/a/606266. try: der = rsa.pem.load_pem(pem, 'PRIVATE KEY') keyinfo, _ = decoder.decode(der) if keyinfo[1][0] != univ.ObjectIdentifier( '1.2.840.113549.1.1.1'): # pragma: no cover raise ValueError('Not a DER-encoded OpenSSL private RSA key') private_key_der = keyinfo[2].asOctets() except IndexError: # pragma: no cover raise ValueError('Not a DER-encoded OpenSSL private RSA key') return rsa.PrivateKey.load_pkcs1(private_key_der, format='DER')
Example #12
Source File: oauth.py From luci-py with Apache License 2.0 | 6 votes |
def _parse_private_key(pem): """PEM encoded OpenSSL private RSA key -> rsa.PrivateKey.""" # Cloud console generates OpenSSL compatible private RSA keys. 'rsa' library # doesn't support them natively. Do some ASN unwrapping to extract naked # RSA key (in der-encoded form). See https://www.ietf.org/rfc/rfc2313.txt. try: der = rsa.pem.load_pem(pem, 'PRIVATE KEY') keyinfo, _ = decoder.decode(der) if keyinfo[1][0] != univ.ObjectIdentifier('1.2.840.113549.1.1.1'): raise BadServiceAccountCredentials( 'Not a DER-encoded OpenSSL private RSA key') private_key_der = keyinfo[2].asOctets() except IndexError: raise BadServiceAccountCredentials( 'Not a DER-encoded OpenSSL private RSA key') return rsa.PrivateKey.load_pkcs1(private_key_der, format='DER')
Example #13
Source File: rfc8103.py From learn_python3_spider with MIT License | 5 votes |
def _OID(*components): output = [] for x in tuple(components): if isinstance(x, univ.ObjectIdentifier): output.extend(list(x)) else: output.append(int(x)) return univ.ObjectIdentifier(output)
Example #14
Source File: dump.py From snmpsim with BSD 2-Clause "Simplified" License | 5 votes |
def format_oid(self, oid): return univ.ObjectIdentifier(oid).prettyPrint()
Example #15
Source File: mibvar.py From scalyr-agent-2 with Apache License 2.0 | 5 votes |
def mibNameToOid(mibView, name): if isinstance(name[0], tuple): f = lambda x='',y='': (x,y) modName, symName = f(*name[0]) if modName: # load module if needed mibView.mibBuilder.loadModules(modName) else: mibView.mibBuilder.loadModules() # load all (slow) if symName: oid, label, suffix = mibView.getNodeNameByDesc(symName, modName) else: oid, label, suffix = mibView.getFirstNodeName(modName) suffix = name[1:] modName, symName, _s = mibView.getNodeLocation(oid) mibNode, = mibView.mibBuilder.importSymbols( modName, symName ) if hasattr(mibNode, 'createTest'): # table column XXX modName, symName, _s = mibView.getNodeLocation(oid[:-1]) rowNode, = mibView.mibBuilder.importSymbols(modName, symName) return oid, rowNode.getInstIdFromIndices(*suffix) else: # scalar or incomplete spec return oid, suffix elif not isinstance(name, tuple): name = tuple(univ.ObjectIdentifier(name)) oid, label, suffix = mibView.getNodeNameByOid(name) return oid, suffix
Example #16
Source File: rfc4055.py From learn_python3_spider with MIT License | 5 votes |
def _OID(*components): output = [] for x in tuple(components): if isinstance(x, univ.ObjectIdentifier): output.extend(list(x)) else: output.append(int(x)) return univ.ObjectIdentifier(output)
Example #17
Source File: rfc6402.py From learn_python3_spider with MIT License | 5 votes |
def _buildOid(*components): output = [] for x in tuple(components): if isinstance(x, univ.ObjectIdentifier): output.extend(list(x)) else: output.append(int(x)) return univ.ObjectIdentifier(output) # Since CMS Attributes and CMC Controls both use 'attrType', one map is used
Example #18
Source File: rfc3281.py From luci-py with Apache License 2.0 | 5 votes |
def _buildOid(*components): output = [] for x in tuple(components): if isinstance(x, univ.ObjectIdentifier): output.extend(list(x)) else: output.append(int(x)) return univ.ObjectIdentifier(output)
Example #19
Source File: rfc3281.py From learn_python3_spider with MIT License | 5 votes |
def _buildOid(*components): output = [] for x in tuple(components): if isinstance(x, univ.ObjectIdentifier): output.extend(list(x)) else: output.append(int(x)) return univ.ObjectIdentifier(output)
Example #20
Source File: cmd2rec.py From snmpsim with BSD 2-Clause "Simplified" License | 5 votes |
def _parse_mib_object(arg, last=False): if '::' in arg: return ObjectIdentity(*arg.split('::', 1), last=last) else: return univ.ObjectIdentifier(arg)
Example #21
Source File: rfc5934.py From learn_python3_spider with MIT License | 5 votes |
def _OID(*components): output = [] for x in tuple(components): if isinstance(x, univ.ObjectIdentifier): output.extend(list(x)) else: output.append(int(x)) return univ.ObjectIdentifier(output) # Imports from RFC 2985
Example #22
Source File: rfc5280.py From learn_python3_spider with MIT License | 5 votes |
def _buildOid(*components): output = [] for x in tuple(components): if isinstance(x, univ.ObjectIdentifier): output.extend(list(x)) else: output.append(int(x)) return univ.ObjectIdentifier(output)
Example #23
Source File: rfc2985.py From learn_python3_spider with MIT License | 5 votes |
def _OID(*components): output = [] for x in tuple(components): if isinstance(x, univ.ObjectIdentifier): output.extend(list(x)) else: output.append(int(x)) return univ.ObjectIdentifier(output)
Example #24
Source File: rfc7292.py From learn_python3_spider with MIT License | 5 votes |
def _OID(*components): output = [] for x in tuple(components): if isinstance(x, univ.ObjectIdentifier): output.extend(list(x)) else: output.append(int(x)) return univ.ObjectIdentifier(output) # Initialize the maps used in PKCS#12
Example #25
Source File: rfc5084.py From learn_python3_spider with MIT License | 5 votes |
def _OID(*components): output = [] for x in tuple(components): if isinstance(x, univ.ObjectIdentifier): output.extend(list(x)) else: output.append(int(x)) return univ.ObjectIdentifier(output)
Example #26
Source File: rfc4211.py From learn_python3_spider with MIT License | 5 votes |
def _buildOid(*components): output = [] for x in tuple(components): if isinstance(x, univ.ObjectIdentifier): output.extend(list(x)) else: output.append(int(x)) return univ.ObjectIdentifier(output)
Example #27
Source File: rfc3279.py From learn_python3_spider with MIT License | 5 votes |
def _OID(*components): output = [] for x in tuple(components): if isinstance(x, univ.ObjectIdentifier): output.extend(list(x)) else: output.append(int(x)) return univ.ObjectIdentifier(output)
Example #28
Source File: rfc8018.py From learn_python3_spider with MIT License | 5 votes |
def _OID(*components): output = [] for x in tuple(components): if isinstance(x, univ.ObjectIdentifier): output.extend(list(x)) else: output.append(int(x)) return univ.ObjectIdentifier(output) # Import from RFC 3565
Example #29
Source File: rfc5990.py From learn_python3_spider with MIT License | 5 votes |
def _OID(*components): output = [] for x in tuple(components): if isinstance(x, univ.ObjectIdentifier): output.extend(list(x)) else: output.append(int(x)) return univ.ObjectIdentifier(output) # Imports from RFC 5280
Example #30
Source File: rfc6031.py From learn_python3_spider with MIT License | 5 votes |
def _OID(*components): output = [] for x in tuple(components): if isinstance(x, univ.ObjectIdentifier): output.extend(list(x)) else: output.append(int(x)) return univ.ObjectIdentifier(output)