name_obj = PyUnicode_FromStringAndSize(namebuf, buflen);
if (name_obj == NULL)
goto fail;
-
+
buflen = ASN1_STRING_to_UTF8(&valuebuf, value);
if (buflen < 0) {
_setSSLError(NULL, 0, __FILE__, __LINE__);
fprintf(stderr, "RDN level %d, attribute %s: %s\n",
entry->set,
PyString_AS_STRING(PyTuple_GET_ITEM(attr, 0)),
- PyString_AS_STRING(PyTuple_GET_ITEM(attr, 1)));
+ PyString_AS_STRING(PyTuple_GET_ITEM(attr, 1)));
*/
if (attr == NULL)
goto fail1;
static PyObject *
_get_peer_alt_names (X509 *certificate) {
-
+
/* this code follows the procedure outlined in
OpenSSL's crypto/x509v3/v3_prn.c:X509v3_EXT_print()
function to extract the STACK_OF(GENERAL_NAME),
X509_EXTENSION *ext = NULL;
GENERAL_NAMES *names = NULL;
GENERAL_NAME *name;
- X509V3_EXT_METHOD *method;
+ X509V3_EXT_METHOD *method;
BIO *biobuf = NULL;
char buf[2048];
char *vptr;
if (peer_alt_names == NULL)
goto fail;
}
-
+
/* now decode the altName */
ext = X509_get_ext(certificate, i);
if(!(method = X509V3_EXT_get(ext))) {
goto fail;
}
PyTuple_SET_ITEM(t, 1, v);
-
+
} else {
/* for everything else, we use the OpenSSL print form */
} else {
return peer_alt_names;
}
-
+
fail:
if (biobuf != NULL)
goto fail0;
}
Py_DECREF(issuer);
-
+
version = PyInt_FromLong(X509_get_version(certificate) + 1);
if (PyDict_SetItemString(retval, "version", version) < 0) {
Py_DECREF(version);
}
Py_DECREF(version);
}
-
+
/* get a memory buffer */
biobuf = BIO_new(BIO_s_mem());
-
+
if (verbose) {
(void) BIO_reset(biobuf);
}
Py_DECREF(peer_alt_names);
}
-
+
BIO_free(biobuf);
return retval;
retval = _decode_certificate(x, verbose);
fail0:
-
+
if (cert != NULL) BIO_free(cert);
return retval;
}
return NULL;
}
/* this is actually an immutable bytes sequence */
- retval = PyBytes_FromStringAndSize
+ retval = PyString_FromStringAndSize
((const char *) bytes_buf, len);
OPENSSL_free(bytes_buf);
return retval;
goto fail0;
PyTuple_SET_ITEM(retval, 2, v);
return retval;
-
+
fail0:
Py_DECREF(retval);
return NULL;
Py_DECREF(buf);
return NULL;
} else if (sockstate == SOCKET_HAS_BEEN_CLOSED) {
- /* should contain a zero-length string */
- if (!buf_passed) {
- PyBytes_Resize(buf, 0);
- return buf;
- } else {
- return PyInt_FromLong(0);
- }
+ count = 0;
+ goto done;
}
}
do {
(SSL_get_shutdown(self->ssl) ==
SSL_RECEIVED_SHUTDOWN))
{
- if (!buf_passed) {
- PyBytes_Resize(buf, 0);
- return buf;
- } else {
- return PyInt_FromLong(0);
- }
+ count = 0;
+ goto done;
} else {
sockstate = SOCKET_OPERATION_OK;
}
}
return PySSL_SetError(self, count, __FILE__, __LINE__);
}
+ done:
if (!buf_passed) {
- if (count != len) {
- PyBytes_Resize(buf, count);
- }
- return buf;
+ PyObject *res = PyString_FromStringAndSize(
+ PyBytes_AS_STRING(buf), count);
+ Py_DECREF(buf);
+ return res;
} else {
return PyInt_FromLong(count);
}