Skip to content

Commit bb1a585

Browse files
davidbendkostic
authored and
dkostic
committed
Const-correct X509_alias_get0 and X509_keyid_get0
All callers I found seem to be compatible with this. Using the non-const pointer isn't very useful because you cannot resize the value. Let's try const-correcting it and we'll revert if it's too annoying to fix. Update-Note: The above functions are now const-correct. Store the result in a const pointer to avoid compatibility issues. Change-Id: Id4a1c7223fbb333716906e20844bf8795118a8ea Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/65128 Commit-Queue: David Benjamin <[email protected]> Reviewed-by: Bob Beck <[email protected]> (cherry picked from commit 3ef8cbc419c3143fb3218eac1b1162515573ecb0)
1 parent 0fb94c8 commit bb1a585

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

crypto/x509/x_x509a.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ static X509_CERT_AUX *aux_get(X509 *x) {
9090
return x->aux;
9191
}
9292

93-
int X509_alias_set1(X509 *x, const unsigned char *name, ossl_ssize_t len) {
93+
int X509_alias_set1(X509 *x, const uint8_t *name, ossl_ssize_t len) {
9494
X509_CERT_AUX *aux;
9595
// TODO(davidben): Empty aliases are not meaningful in PKCS#12, and the
9696
// getters cannot quite represent them. Also erase the object if |len| is
@@ -112,7 +112,7 @@ int X509_alias_set1(X509 *x, const unsigned char *name, ossl_ssize_t len) {
112112
return ASN1_STRING_set(aux->alias, name, len);
113113
}
114114

115-
int X509_keyid_set1(X509 *x, const unsigned char *id, ossl_ssize_t len) {
115+
int X509_keyid_set1(X509 *x, const uint8_t *id, ossl_ssize_t len) {
116116
X509_CERT_AUX *aux;
117117
// TODO(davidben): Empty key IDs are not meaningful in PKCS#12, and the
118118
// getters cannot quite represent them. Also erase the object if |len| is
@@ -134,15 +134,15 @@ int X509_keyid_set1(X509 *x, const unsigned char *id, ossl_ssize_t len) {
134134
return ASN1_STRING_set(aux->keyid, id, len);
135135
}
136136

137-
unsigned char *X509_alias_get0(X509 *x, int *out_len) {
137+
const uint8_t *X509_alias_get0(const X509 *x, int *out_len) {
138138
const ASN1_UTF8STRING *alias = x->aux != NULL ? x->aux->alias : NULL;
139139
if (out_len != NULL) {
140140
*out_len = alias != NULL ? alias->length : 0;
141141
}
142142
return alias != NULL ? alias->data : NULL;
143143
}
144144

145-
unsigned char *X509_keyid_get0(X509 *x, int *out_len) {
145+
const uint8_t *X509_keyid_get0(const X509 *x, int *out_len) {
146146
const ASN1_OCTET_STRING *keyid = x->aux != NULL ? x->aux->keyid : NULL;
147147
if (out_len != NULL) {
148148
*out_len = keyid != NULL ? keyid->length : 0;

include/openssl/x509.h

+8-6
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,9 @@ OPENSSL_EXPORT int X509_set1_signature_value(X509 *x509, const uint8_t *sig,
619619
// Unlike similarly-named functions, this function does not output a single
620620
// ASN.1 element. Directly embedding the output in a larger ASN.1 structure will
621621
// not behave correctly.
622-
OPENSSL_EXPORT int i2d_X509_AUX(X509 *x509, unsigned char **outp);
622+
//
623+
// TODO(crbug.com/boringssl/407): |x509| should be const.
624+
OPENSSL_EXPORT int i2d_X509_AUX(X509 *x509, uint8_t **outp);
623625

624626
// d2i_X509_AUX parses up to |length| bytes from |*inp| as a DER-encoded X.509
625627
// Certificate (RFC 5280), followed optionally by a separate, OpenSSL-specific
@@ -632,19 +634,19 @@ OPENSSL_EXPORT int i2d_X509_AUX(X509 *x509, unsigned char **outp);
632634
// Unlike similarly-named functions, this function does not parse a single
633635
// ASN.1 element. Trying to parse data directly embedded in a larger ASN.1
634636
// structure will not behave correctly.
635-
OPENSSL_EXPORT X509 *d2i_X509_AUX(X509 **x509, const unsigned char **inp,
637+
OPENSSL_EXPORT X509 *d2i_X509_AUX(X509 **x509, const uint8_t **inp,
636638
long length);
637639

638640
// X509_alias_set1 sets |x509|'s alias to |len| bytes from |name|. If |name| is
639641
// NULL, the alias is cleared instead. Aliases are not part of the certificate
640642
// itself and will not be serialized by |i2d_X509|.
641-
OPENSSL_EXPORT int X509_alias_set1(X509 *x509, const unsigned char *name,
643+
OPENSSL_EXPORT int X509_alias_set1(X509 *x509, const uint8_t *name,
642644
ossl_ssize_t len);
643645

644646
// X509_keyid_set1 sets |x509|'s key ID to |len| bytes from |id|. If |id| is
645647
// NULL, the key ID is cleared instead. Key IDs are not part of the certificate
646648
// itself and will not be serialized by |i2d_X509|.
647-
OPENSSL_EXPORT int X509_keyid_set1(X509 *x509, const unsigned char *id,
649+
OPENSSL_EXPORT int X509_keyid_set1(X509 *x509, const uint8_t *id,
648650
ossl_ssize_t len);
649651

650652
// X509_alias_get0 looks up |x509|'s alias. If found, it sets |*out_len| to the
@@ -659,7 +661,7 @@ OPENSSL_EXPORT int X509_keyid_set1(X509 *x509, const unsigned char *id,
659661
// WARNING: In OpenSSL, this function did not set |*out_len| when the alias was
660662
// missing. Callers that target both OpenSSL and BoringSSL should set the value
661663
// to zero before calling this function.
662-
OPENSSL_EXPORT unsigned char *X509_alias_get0(X509 *x509, int *out_len);
664+
OPENSSL_EXPORT const uint8_t *X509_alias_get0(const X509 *x509, int *out_len);
663665

664666
// X509_keyid_get0 looks up |x509|'s key ID. If found, it sets |*out_len| to the
665667
// key ID's length and returns a pointer to a buffer containing the contents. If
@@ -669,7 +671,7 @@ OPENSSL_EXPORT unsigned char *X509_alias_get0(X509 *x509, int *out_len);
669671
// WARNING: In OpenSSL, this function did not set |*out_len| when the alias was
670672
// missing. Callers that target both OpenSSL and BoringSSL should set the value
671673
// to zero before calling this function.
672-
OPENSSL_EXPORT unsigned char *X509_keyid_get0(X509 *x509, int *out_len);
674+
OPENSSL_EXPORT const uint8_t *X509_keyid_get0(const X509 *x509, int *out_len);
673675

674676
// X509_add1_trust_object configures |x509| as a valid trust anchor for |obj|.
675677
// It returns one on success and zero on error. |obj| should be a certificate

0 commit comments

Comments
 (0)