mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
gh-141801: Use accessors for ASN1_STRING fields in libssl (GH-141802)
* gh-141801: Use accessors for ASN1_STRING fields While ASN1_STRING is currently exposed, it is better to use the accessors. See https://github.com/openssl/openssl/issues/29117 where, if the type were opaque, OpenSSL's X509 objects could be much more memory-efficient. * Update Modules/_ssl.c Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> * Update Modules/_ssl.c Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> --------- Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
This commit is contained in:
parent
5c25bc5763
commit
c41fce08a5
1 changed files with 10 additions and 8 deletions
|
|
@ -1437,14 +1437,14 @@ _get_peer_alt_names (_sslmodulestate *state, X509 *certificate) {
|
||||||
}
|
}
|
||||||
PyTuple_SET_ITEM(t, 0, v);
|
PyTuple_SET_ITEM(t, 0, v);
|
||||||
|
|
||||||
if (name->d.ip->length == 4) {
|
if (ASN1_STRING_length(name->d.ip) == 4) {
|
||||||
unsigned char *p = name->d.ip->data;
|
const unsigned char *p = ASN1_STRING_get0_data(name->d.ip);
|
||||||
v = PyUnicode_FromFormat(
|
v = PyUnicode_FromFormat(
|
||||||
"%d.%d.%d.%d",
|
"%d.%d.%d.%d",
|
||||||
p[0], p[1], p[2], p[3]
|
p[0], p[1], p[2], p[3]
|
||||||
);
|
);
|
||||||
} else if (name->d.ip->length == 16) {
|
} else if (ASN1_STRING_length(name->d.ip) == 16) {
|
||||||
unsigned char *p = name->d.ip->data;
|
const unsigned char *p = ASN1_STRING_get0_data(name->d.ip);
|
||||||
v = PyUnicode_FromFormat(
|
v = PyUnicode_FromFormat(
|
||||||
"%X:%X:%X:%X:%X:%X:%X:%X",
|
"%X:%X:%X:%X:%X:%X:%X:%X",
|
||||||
p[0] << 8 | p[1],
|
p[0] << 8 | p[1],
|
||||||
|
|
@ -1575,8 +1575,9 @@ _get_aia_uri(X509 *certificate, int nid) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
uri = ad->location->d.uniformResourceIdentifier;
|
uri = ad->location->d.uniformResourceIdentifier;
|
||||||
ostr = PyUnicode_FromStringAndSize((char *)uri->data,
|
ostr = PyUnicode_FromStringAndSize(
|
||||||
uri->length);
|
(const char *)ASN1_STRING_get0_data(uri),
|
||||||
|
ASN1_STRING_length(uri));
|
||||||
if (ostr == NULL) {
|
if (ostr == NULL) {
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
@ -1642,8 +1643,9 @@ _get_crl_dp(X509 *certificate) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
uri = gn->d.uniformResourceIdentifier;
|
uri = gn->d.uniformResourceIdentifier;
|
||||||
ouri = PyUnicode_FromStringAndSize((char *)uri->data,
|
ouri = PyUnicode_FromStringAndSize(
|
||||||
uri->length);
|
(const char *)ASN1_STRING_get0_data(uri),
|
||||||
|
ASN1_STRING_length(uri));
|
||||||
if (ouri == NULL)
|
if (ouri == NULL)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue