MCPcopy Create free account
hub / github.com/secdev/scapy / __call__

Method __call__

scapy/layers/tls/cert.py:300–359  ·  view source on GitHub ↗
(cls, key_path=None, cryptography_obj=None)

Source from the content-addressed store, hash-verified

298 """
299
300 def __call__(cls, key_path=None, cryptography_obj=None):
301 # This allows to import cryptography objects directly
302 if cryptography_obj is not None:
303 obj = type.__call__(cls)
304 obj.__class__ = cls
305 obj.frmt = "original"
306 obj.marker = "PUBLIC KEY"
307 obj.pubkey = cryptography_obj
308 return obj
309
310 if key_path is None:
311 obj = type.__call__(cls)
312 if cls is PubKey:
313 cls = PubKeyRSA
314 obj.__class__ = cls
315 obj.frmt = "original"
316 obj.fill_and_store()
317 return obj
318
319 # This deals with the rare RSA 'kx export' call.
320 if isinstance(key_path, tuple):
321 obj = type.__call__(cls)
322 obj.__class__ = PubKeyRSA
323 obj.frmt = "tuple"
324 obj.import_from_tuple(key_path)
325 return obj
326
327 # Now for the usual calls, key_path may be the path to either:
328 # _an X509_SubjectPublicKeyInfo, as processed by openssl;
329 # _an RSAPublicKey;
330 # _an ECDSAPublicKey;
331 # _an EdDSAPublicKey.
332 obj = _PKIObjMaker.__call__(cls, key_path, _MAX_KEY_SIZE)
333 try:
334 spki = X509_SubjectPublicKeyInfo(obj._der)
335 pubkey = spki.subjectPublicKey
336 if isinstance(pubkey, RSAPublicKey):
337 obj.__class__ = PubKeyRSA
338 obj.import_from_asn1pkt(pubkey)
339 elif isinstance(pubkey, ECDSAPublicKey):
340 obj.__class__ = PubKeyECDSA
341 obj.import_from_der(obj._der)
342 elif isinstance(pubkey, EdDSAPublicKey):
343 obj.__class__ = PubKeyEdDSA
344 obj.import_from_der(obj._der)
345 else:
346 raise
347 obj.marker = "PUBLIC KEY"
348 except Exception:
349 try:
350 pubkey = RSAPublicKey(obj._der)
351 obj.__class__ = PubKeyRSA
352 obj.import_from_asn1pkt(pubkey)
353 obj.marker = "RSA PUBLIC KEY"
354 except Exception:
355 # We cannot import an ECDSA public key without curve knowledge
356 if conf.debug_dissector:
357 raise

Callers

nothing calls this directly

Calls 7

RSAPublicKeyClass · 0.90
import_from_tupleMethod · 0.80
__call__Method · 0.45
fill_and_storeMethod · 0.45
import_from_asn1pktMethod · 0.45
import_from_derMethod · 0.45

Tested by

no test coverage detected