MCPcopy Create free account
hub / github.com/SecurityInnovation/PGPy / bind

Method bind

pgpy/pgp.py:2307–2359  ·  view source on GitHub ↗

Bind a subkey to this key. In addition to the optional keyword arguments accepted for self-signatures by :py:meth:`PGPkey.certify`, the following optional keyword arguments can be used with :py:meth:`PGPKey.bind`. :keyword crosssign: If ``False``, do not attempt a

(self, key, **prefs)

Source from the content-addressed store, hash-verified

2305
2306 @KeyAction(is_unlocked=True, is_public=False)
2307 def bind(self, key, **prefs):
2308 """
2309 Bind a subkey to this key.
2310
2311 In addition to the optional keyword arguments accepted for self-signatures by :py:meth:`PGPkey.certify`,
2312 the following optional keyword arguments can be used with :py:meth:`PGPKey.bind`.
2313
2314 :keyword crosssign: If ``False``, do not attempt a cross-signature (defaults to ``True``). Subkeys
2315 which are not capable of signing will not produce a cross-signature in any case.
2316 Setting ``crosssign`` to ``False`` is likely to produce subkeys that will be rejected
2317 by some other OpenPGP implementations.
2318 :type crosssign: ``bool``
2319 """
2320 hash_algo = prefs.pop('hash', None)
2321
2322 if self.is_primary and not key.is_primary:
2323 sig_type = SignatureType.Subkey_Binding
2324
2325 elif key.is_primary and not self.is_primary:
2326 sig_type = SignatureType.PrimaryKey_Binding
2327
2328 else: # pragma: no cover
2329 raise PGPError
2330
2331 sig = PGPSignature.new(sig_type, self.key_algorithm, hash_algo, self.fingerprint.keyid, created=prefs.pop('created', None))
2332
2333 if sig_type == SignatureType.Subkey_Binding:
2334 # signature options that only make sense in subkey binding signatures
2335 usage = prefs.pop('usage', None)
2336
2337 if usage is not None:
2338 sig._signature.subpackets.addnew('KeyFlags', hashed=True, flags=usage)
2339
2340 crosssig = None
2341 # if possible, have the subkey create a primary key binding signature
2342 if key.key_algorithm.can_sign and prefs.pop('crosssign', True):
2343 subkeyid = key.fingerprint.keyid
2344
2345 if not key.is_public:
2346 crosssig = key.bind(self)
2347
2348 elif subkeyid in self.subkeys: # pragma: no cover
2349 crosssig = self.subkeys[subkeyid].bind(self)
2350
2351 if crosssig is None:
2352 if usage is None:
2353 raise PGPError('subkey with no key usage flags (may be used for any purpose, including signing) requires a cross-signature')
2354 if KeyFlags.Sign in usage:
2355 raise PGPError('subkey marked for signing usage requires a cross-signature')
2356 else:
2357 sig._signature.subpackets.addnew('EmbeddedSignature', hashed=False, _sig=crosssig._signature)
2358
2359 return self._sign(key, sig, **prefs)
2360
2361 def is_considered_insecure(self, self_verifying=False):
2362 res = self.check_soundness(self_verifying=self_verifying)

Callers 1

add_subkeyMethod · 0.95

Calls 4

_signMethod · 0.95
PGPErrorClass · 0.85
addnewMethod · 0.80
newMethod · 0.45

Tested by

no test coverage detected