def rsa_set_d(rsa, value): """Set the private-key component "d" of a RSA object.""" bn = _m2lib.BN_mpi2bn(value, len(value), None) if not bn: raise RSA.RSAError("invalid private key data") rsa_p = ctypes.cast(ctypes.c_void_p(int(rsa)), ctypes.POINTER(_RSA)) if rsa_p.contents.d: _m2lib.BN_free(rsa_p.contents.d) rsa_p.contents.d = bn
def GetPublicKey(self): try: bio = BIO.MemoryBuffer(self._value) rsa = RSA.load_pub_key_bio(bio) if rsa.check_key() != 1: raise RSA.RSAError("RSA.check_key() did not succeed.") return rsa except RSA.RSAError as e: raise type_info.TypeValueError("Public key invalid: %s" % e)
def _set_x509(self, ucert, ukey): default_proxy_location = _get_default_proxy() # User certificate and key locations if ucert and not ukey: ukey = ucert elif not ucert: if 'X509_USER_PROXY' in os.environ: ukey = ucert = os.environ['X509_USER_PROXY'] elif os.path.exists(default_proxy_location): ukey = ucert = default_proxy_location elif 'X509_USER_CERT' in os.environ: ucert = os.environ['X509_USER_CERT'] ukey = os.environ.get('X509_USER_KEY', ucert) elif os.path.exists( '/etc/grid-security/hostcert.pem') and os.path.exists( '/etc/grid-security/hostkey.pem'): ucert = '/etc/grid-security/hostcert.pem' ukey = '/etc/grid-security/hostkey.pem' if ucert and ukey: self.x509_list = _get_x509_list(ucert) self.x509 = self.x509_list[0] not_after = self.x509.get_not_after() try: not_after = not_after.get_time() except: # Ugly hack for Python 2.4 import time not_after = datetime.fromtimestamp(time.mktime( time.strptime(str(not_after), "%b %d %H:%M:%S %Y %Z")), tz=UTC) if not_after < datetime.now(UTC): raise Exception("Proxy expired!") try: self.rsa_key = RSA.load_key(ukey, self._read_passwd_from_stdin) except RSA.RSAError, e: raise RSA.RSAError("Could not load %s: %s" % (ukey, str(e))) except Exception, e: raise Exception("Could not load %s: %s" % (ukey, str(e)))