Skip to content

Instantly share code, notes, and snippets.

@sigmavirus24
Last active August 29, 2015 14:23
Show Gist options
  • Save sigmavirus24/8f033f99f70765d9689c to your computer and use it in GitHub Desktop.
Save sigmavirus24/8f033f99f70765d9689c to your computer and use it in GitHub Desktop.
__________________________________________________________________ TestCertificateSigningRequestBuilder.test_build_ca_request_with_dsa[backend0] __________________________________________________________________
self = <tests.test_x509.TestCertificateSigningRequestBuilder object at 0x108b45c90>, backend = <cryptography.hazmat.backends.openssl.backend.Backend object at 0x106d11250>
@pytest.mark.requires_backend_interface(interface=DSABackend)
def test_build_ca_request_with_dsa(self, backend):
private_key = DSA_KEY_2048.private_key(backend)
request = x509.CertificateSigningRequestBuilder().subject_name(
x509.Name([
x509.NameAttribute(x509.OID_COUNTRY_NAME, u'US'),
x509.NameAttribute(x509.OID_STATE_OR_PROVINCE_NAME, u'Texas'),
x509.NameAttribute(x509.OID_LOCALITY_NAME, u'Austin'),
x509.NameAttribute(x509.OID_ORGANIZATION_NAME, u'PyCA'),
x509.NameAttribute(x509.OID_COMMON_NAME, u'cryptography.io'),
])
).add_extension(
x509.BasicConstraints(ca=True, path_length=2), critical=True
).sign(
> backend, private_key, hashes.SHA1()
)
tests/test_x509.py:782:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.tox/py27/lib/python2.7/site-packages/cryptography/x509.py:1418: in sign
return backend.create_x509_csr(self, private_key, algorithm)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <cryptography.hazmat.backends.openssl.backend.Backend object at 0x106d11250>, builder = <cryptography.x509.CertificateSigningRequestBuilder object at 0x108b45fd0>
private_key = <cryptography.hazmat.backends.openssl.dsa._DSAPrivateKey object at 0x108b45d90>, algorithm = <cryptography.hazmat.primitives.hashes.SHA1 object at 0x108b45b90>
def create_x509_csr(self, builder, private_key, algorithm):
if not isinstance(algorithm, hashes.HashAlgorithm):
raise TypeError('Algorithm must be a registered hash algorithm.')
# Resolve the signature algorithm.
evp_md = self._lib.EVP_get_digestbyname(
algorithm.name.encode('ascii')
)
assert evp_md != self._ffi.NULL
# Create an empty request.
x509_req = self._lib.X509_REQ_new()
assert x509_req != self._ffi.NULL
x509_req = self._ffi.gc(x509_req, self._lib.X509_REQ_free)
# Set x509 version.
res = self._lib.X509_REQ_set_version(x509_req, x509.Version.v1.value)
assert res == 1
# Set subject name.
res = self._lib.X509_REQ_set_subject_name(
x509_req, _encode_name(self, list(builder._subject_name))
)
assert res == 1
# Set subject public key.
public_key = private_key.public_key()
res = self._lib.X509_REQ_set_pubkey(
> x509_req, public_key._evp_pkey
)
E AttributeError: '_DSAPublicKey' object has no attribute '_evp_pkey'
def test_build_ca_request_with_ec(self, backend): [163/1825]
private_key = ec.generate_private_key(ec.SECT283K1(), backend)
request = x509.CertificateSigningRequestBuilder().subject_name(
x509.Name([
x509.NameAttribute(x509.OID_COUNTRY_NAME, u'US'),
x509.NameAttribute(x509.OID_STATE_OR_PROVINCE_NAME, u'Texas'),
x509.NameAttribute(x509.OID_LOCALITY_NAME, u'Austin'),
x509.NameAttribute(x509.OID_ORGANIZATION_NAME, u'PyCA'),
x509.NameAttribute(x509.OID_COMMON_NAME, u'cryptography.io'),
])
).add_extension(
x509.BasicConstraints(ca=True, path_length=2), critical=True
).sign(
> backend, private_key, hashes.SHA1()
)
tests/test_x509.py:749:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.tox/py27/lib/python2.7/site-packages/cryptography/x509.py:1482: in sign
return backend.create_x509_csr(self, private_key, algorithm)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <cryptography.hazmat.backends.openssl.backend.Backend object at 0x1022a1790>, builder = <cryptography.x509.CertificateSigningRequestBuilder object at 0x138a69050>
private_key = <cryptography.hazmat.backends.openssl.ec._EllipticCurvePrivateKey object at 0x138a57e50>, algorithm = <cryptography.hazmat.primitives.hashes.SHA1 object at 0x138a69290>
def create_x509_csr(self, builder, private_key, algorithm):
if not isinstance(algorithm, hashes.HashAlgorithm):
raise TypeError('Algorithm must be a registered hash algorithm.')
if isinstance(private_key, _DSAPrivateKey):
raise NotImplementedError(
"Certificate signing requests aren't implemented for DSA keys."
)
# Resolve the signature algorithm.
evp_md = self._lib.EVP_get_digestbyname(
algorithm.name.encode('ascii')
)
assert evp_md != self._ffi.NULL
# Create an empty request.
x509_req = self._lib.X509_REQ_new()
assert x509_req != self._ffi.NULL
x509_req = self._ffi.gc(x509_req, self._lib.X509_REQ_free)
# Set x509 version.
res = self._lib.X509_REQ_set_version(x509_req, x509.Version.v1.value)
assert res == 1
# Set subject name.
res = self._lib.X509_REQ_set_subject_name(
x509_req, _encode_name(self, list(builder._subject_name))
)
assert res == 1
# Set subject public key.
public_key = private_key.public_key()
res = self._lib.X509_REQ_set_pubkey(
> x509_req, public_key._evp_pkey
)
E TypeError: initializer for ctype 'struct evp_pkey_st *' must be a cdata pointer, not NoneType
@sigmavirus24
Copy link
Author

{'_key_size': 2048, '_backend': <cryptography.hazmat.backends.openssl.backend.Backend object at 0x10933f250>, '_dsa_cdata': <cdata 'struct dsa_st *' 0x7fe13d3380c0>}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment