Skip to content

Commit

Permalink
fixup! fix X509_PURPOSE_add() to take |sname| as primary key and hand…
Browse files Browse the repository at this point in the history
…le |id| in a backwd compat way for new purpose
  • Loading branch information
DDvO committed Dec 20, 2024
1 parent 90e18c9 commit 7c6e318
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ OpenSSL 3.5

* `X509_PURPOSE_add()` has been fixed to take as the primary purpose identifier
not the `id` but the `sname` parameter.
For its convenient use, `X509_PURPOSE_get_fresh_id()` has been added.
For its convenient use, `X509_PURPOSE_get_unused_id()` has been added.

This work was sponsored by Siemens AG.

Expand Down
2 changes: 1 addition & 1 deletion crypto/x509/v3_purp.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ int X509_PURPOSE_get_count(void)
}

/* find smallest identifier not yet taken - note there might be gaps */
int X509_PURPOSE_get_fresh_id(void)
int X509_PURPOSE_get_unused_id(void)
{
int id = X509_PURPOSE_MAX + 1;

Expand Down
12 changes: 6 additions & 6 deletions doc/man3/X509_check_purpose.pod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

X509_check_purpose,
X509_PURPOSE_get_count,
X509_PURPOSE_get_fresh_id,
X509_PURPOSE_get_unused_id,
X509_PURPOSE_get_by_sname,
X509_PURPOSE_get_by_id,
X509_PURPOSE_add,
Expand All @@ -23,7 +23,7 @@ X509_PURPOSE_set - functions related to checking the purpose of a certificate
int X509_check_purpose(X509 *x, int id, int ca);

int X509_PURPOSE_get_count(void);
int X509_PURPOSE_get_fresh_id(void);
int X509_PURPOSE_get_unused_id(void);
int X509_PURPOSE_get_by_sname(const char *sname);
int X509_PURPOSE_get_by_id(int id);
int X509_PURPOSE_add(int id, int trust, int flags,
Expand Down Expand Up @@ -64,7 +64,7 @@ keyUsage, extendedKeyUsage, and basicConstraints.

X509_PURPOSE_get_count() returns the number of currently defined purposes.

X509_PURPOSE_get_fresh_id() returns the smallest purpose id not yet used.
X509_PURPOSE_get_unused_id() returns the smallest purpose id not yet used.

X509_PURPOSE_get_by_sname() returns the index of
the purpose with the given short name or -1 if not found.
Expand All @@ -74,7 +74,7 @@ the purpose with the given id or -1 if not found.

X509_PURPOSE_add() adds or modifies a purpose entry identified by I<sname>.
Unless the id stays the same for an existing entry, I<id> must be fresh,
which can be achieved by using the result of X509_PURPOSE_get_fresh_id().
which can be achieved by using the result of X509_PURPOSE_get_unused_id().
The function also sets in the entry the trust id I<trust>, the given I<flags>,
the purpose (long) name I<name>, the short name I<sname>, the purpose checking
funktion I<ck> of type B<int (*) (const X509_PURPOSE *, const X509 *, int)>,
Expand Down Expand Up @@ -134,7 +134,7 @@ For CA checks the below integers could be returned with the following meanings:

X509_PURPOSE_get_count() returns the number of currently defined purposes.

X509_PURPOSE_get_fresh_id() returns the smallest purpose id not yet used.
X509_PURPOSE_get_unused_id() returns the smallest purpose id not yet used.

X509_PURPOSE_get_by_sname() returns the index of
the purpose with the given short name or -1 if not found.
Expand All @@ -160,7 +160,7 @@ X509_PURPOSE_set() returns 1 on success, 0 on error.

=head1 HISTORY

X509_PURPOSE_get_fresh_id() was added in OpensSL 3.5.
X509_PURPOSE_get_unused_id() was added in OpensSL 3.5.

=head1 COPYRIGHT

Expand Down
2 changes: 1 addition & 1 deletion include/openssl/x509v3.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ const GENERAL_NAMES *X509_get0_authority_issuer(X509 *x);
const ASN1_INTEGER *X509_get0_authority_serial(X509 *x);

int X509_PURPOSE_get_count(void);
int X509_PURPOSE_get_fresh_id(void);
int X509_PURPOSE_get_unused_id(void);
int X509_PURPOSE_get_by_sname(const char *sname);
int X509_PURPOSE_get_by_id(int id);
int X509_PURPOSE_add(int id, int trust, int flags,
Expand Down
2 changes: 1 addition & 1 deletion test/x509_internal_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ static int tests_X509_PURPOSE(void)
#define SN "SN_test"
#undef ARGS
#define ARGS(id, sn) id, X509_TRUST_MAX, 0, ck_purp, LN, sn, NULL
return TEST_int_gt((id = X509_PURPOSE_get_fresh_id()), X509_PURPOSE_MAX)
return TEST_int_gt((id = X509_PURPOSE_get_unused_id()), X509_PURPOSE_MAX)
&& TEST_int_eq(X509_PURPOSE_get_count() + 1, id)
&& TEST_int_eq(X509_PURPOSE_get_by_id(id), -1)
&& TEST_int_eq(X509_PURPOSE_get_by_sname(SN), -1)
Expand Down
2 changes: 1 addition & 1 deletion util/libcrypto.num
Original file line number Diff line number Diff line change
Expand Up @@ -5735,7 +5735,7 @@ EVP_PKEY_CTX_set_algor_params 5862 3_4_0 EXIST::FUNCTION:
EVP_PKEY_CTX_get_algor_params 5863 3_4_0 EXIST::FUNCTION:
EVP_PKEY_CTX_get_algor 5864 3_4_0 EXIST::FUNCTION:
EVP_get1_default_properties ? 3_5_0 EXIST::FUNCTION:
X509_PURPOSE_get_fresh_id ? 3_5_0 EXIST::FUNCTION:
X509_PURPOSE_get_unused_id ? 3_5_0 EXIST::FUNCTION:
d2i_OSSL_AUTHORITY_ATTRIBUTE_ID_SYNTAX ? 3_5_0 EXIST::FUNCTION:
i2d_OSSL_AUTHORITY_ATTRIBUTE_ID_SYNTAX ? 3_5_0 EXIST::FUNCTION:
OSSL_AUTHORITY_ATTRIBUTE_ID_SYNTAX_free ? 3_5_0 EXIST::FUNCTION:
Expand Down

0 comments on commit 7c6e318

Please sign in to comment.