summaryrefslogtreecommitdiff
path: root/lib/libcrypto/asn1
AgeCommit message (Collapse)Author
2023-03-06ASN.1 enc: check ASN1_item_ex_i2d() consistencyTheo Buehler
The i2d API design is: call a function first with a pointer to NULL, get the length, allocate a buffer, call the function passing the buffer in. Both calls should be checked since ther are still internal allocations. At the heart of ASN.1 encoding, this idiom is used and the second call is assumed to succeed after the length was determined. This is far from guaranteed. Check that the second call returns the same length and error otherwise. ok jsing
2023-03-04Avoid infinite loop in bio_asn1 state machineTheo Buehler
If the BIO_write() in the ASN1_STATE_DATA_COPY state fails, incorrect error handling will break out of the switch without changing the state, and the infinite for loop will immediately try the same write again, which is unlikely to succeed... Clearly this code intended to break out of the loop instead. Via OpenSSL 1.1 commit 723f616df81ea05f31407f7417f49eea89bb459a ok millert
2023-01-13Prevent 1-byte out-of-bounds read in i2c_ASN1_BIT_STRINGTheo Buehler
If an ASN.1 BIT STRING a of length > 0 contains only zero bytes in a->data, this old code would end up reading from a->data[-1]. This may or may not crash. Luckily, anton observed two openssl-ruby regress test failures in the last few days, which could eventually be traced back to this (after a lot of painful digging due to coredumps not working properly). ok jsing
2023-01-01Add explicit LL suffixes to large constants to appease some compilers onMiod Vallat
32-bit platforms; NFCI ok tb@
2022-12-26Prepare to provide X509_CRL_get0_sigalg()Theo Buehler
This is an obvious omission from the OpenSSL 1.1 and OpenSSL 3 API which does not provide a way to access the tbs sigalg of a CRL. This is needed in security/pivy. From Alex Wilson ok jsing
2022-12-26spelling fixes; from paul tagliamonteJason McIntyre
i removed the arithmetics -> arithmetic changes, as i felt they were not clearly correct ok tb
2022-11-28Garbage collect the unused asn1_add_error()Theo Buehler
ok jsing
2022-11-26Make internal header file names consistentTheo Buehler
Libcrypto currently has a mess of *_lcl.h, *_locl.h, and *_local.h names used for internal headers. Move all these headers we inherited from OpenSSL to *_local.h, reserving the name *_internal.h for our own code. Similarly, move dtls_locl.h and ssl_locl.h to dtls_local and ssl_local.h. constant_time_locl.h is moved to constant_time.h since it's special. Adjust all .c files in libcrypto, libssl and regress. The diff is mechanical with the exception of tls13_quic.c, where #include <ssl_locl.h> was fixed manually. discussed with jsing, no objection bcook
2022-11-22Rename last OPENSSL_gmtime() to asn1_time_time_t_to_tm()Theo Buehler
This rename was done before commit, but one instance was missed since it was hidden behind #ifdef SMALL_TIME_T. Spotted by Android CI.
2022-11-13Expose ASN1_buf_print() in asn1.hTheo Buehler
This is needed to print the 32-byte Ed25519 keys which aren't handled as BNs.
2022-11-10Implement EVP interfaces for Ed25519 and X25519.Joel Sing
ok beck@ tb@
2022-11-10Port EVP raw key API from OpenSSL.Joel Sing
This will be needed to deal with Curve25519 based keys. ok beck@ tb@
2022-11-10Port ASN1_buf_print() from OpenSSL 1.1.Joel Sing
This is needed to print byte array based keys, such as Ed25519 and X25519. ok beck@ tb@
2022-11-09Clean up EVP_PKEY_ASN1_METHOD related tables and code.Joel Sing
Rather than messing around with an OBJ_bsearch() for a table that contains 16 entries (and a stack find for any application added methods), simply do a reverse linear scan. This maintains the application method first behaviour, while removing a chunk of code. While here rename some variables and do some style clean up. ok tb@
2022-11-09Sort EVP_PKEY_ASN1_METHOD externs.Joel Sing
2022-11-08Avoid signed integer overflow in i2c_ASN1_BIT_STRING()Theo Buehler
If the length of the bitstring is INT_MAX, adding 1 to it is undefined behavior, so error out before doing so. Based on BoringSSL eeb3333f by davidben ok beck joshua
2022-11-08Add missing $OpenBSD$Bob Beck
2022-11-08Replace the old OpenSSL julian date stuff with BoringSSL'sBob Beck
OpenSSL dealt with time conversion using a classical julian day scheme. BoringSSL got rid of it and uses only a julian style calculation for seconds since the POSIX time epoch. This changes libressl to use the seconds calculation exculusively instead of a mix of the julian day based conversions and the system time conversions to and from time_t to tm. ok tb@ jsing@
2022-10-17Unbreak ASN.1 indefinite length encoding.Joel Sing
In r1.25 of tasn_enc.c a check was added to ensure that asn1_ex_i2c() returned the same value on both calls, however in the ndef case the len variable gets changed between calls. Keep a copy of the original value to test against. Issue reported by niklas, who encountered a test failure in rust-openssl. ok miod@ tb@
2022-09-11Remove c2i_* and i2c_* from public visibilityTheo Buehler
This removes c2i_ASN1_OBJECT(), {c2i,i2c}_ASN1_BIT_STRING() and {c2i,i2c}_ASN1_INTEGER(). These are not part of the OpenSSL 1.1 API and should never have been exposed in the first place. ok jsing
2022-09-03Rewrap some lines, no functional change.Joel Sing
2022-09-03Tidy up asn1_c2i_primitive() slightly.Joel Sing
Rename some variables and consistently goto error. ok tb@
2022-09-03Avoid recycling ASN1_STRINGs when decoding ASN.1.Joel Sing
Rather than recycling an existing ASN1_STRING and changing its type, free it and allocate a replacement. This simplifies the code and potentially avoids bugs resulting from reuse. ok tb@
2022-09-03Remove duplicate prototype that just snuck in.Joel Sing
2022-09-03Ensure ASN.1 types are appropriately encoded.Joel Sing
Per X.690, some ASN.1 types must be primitive encoded, some must be constructed and some may be either. Add this data to our types table and check the encoding against this information when decoding. ok tb@
2022-09-03Provide c2i_ASN1_ENUMERATED_cbs() and call it from asn1_c2i_primitive().Joel Sing
This avoids asn1_c2i_primitive() from needing knowledge about the internals of ASN1_INTEGER and ASN1_ENUMERATED. ok tb@
2022-09-03Stop using CBIGNUM_it internal to libcrypto.Joel Sing
CBIGNUM_it is supposed to be the "clear bignum" or "secure" bignum - that is one which zeros its memory after use and ensures that the constant time flags are set... in LibreSSL we always do both of these things for BIGNUMs, so just use BIGNUM_it instead. ok tb@
2022-08-30Plug memory leak in X509_REQ_print_ex()Theo Buehler
CID 356353 ok jsing
2022-08-29Provide ASN1_R_TYPE_NOT_PRIMITIVE.Joel Sing
Needed for an upcoming change. ok tb@
2022-08-28Encode an ASN.1 INTEGER with NULL data to value of zero.Joel Sing
When an ASN1_INTEGER is created it has NULL data until a value is set - previously, an ASN1_INTEGER in this state encoded to an ASN.1 INTEGER with a value of 0, rather than being treated as an error. While code should really set values, the historical behaviour has not required this. Found the hard way by sthen@ with acme-client. ok tb@
2022-08-20Rewrite i2c_ASN1_INTEGER() using CBB/CBS.Joel Sing
This gives us cleaner and safer code, although it is worth noting that we now generate the encoding even when called with NULL as the output pointer (and then discard it, returning just the length). Resolves oss-fuzz #49963. ok tb@
2022-08-20Make it possible to signal an error from an i2c_* function.Joel Sing
In asn1_i2d_ex_primitive(), asn1_ex_i2c() returning -1 is used to indicate that the object is optional and should be skipped, while -2 is used to indicate that indefinite length encoding should be used. Any other negative value was treated as success, resulting in the out pointer being walked backwards. Avoid this by treating any negative value (aside from -1 and -2) as a failure, propagating it up the stack. Additionally, check the return value of the second asn1_ex_i2c() call to ensure that it matches the value returned by the first call. This makes sure that the length of the encoded object is correct, plus it detects the case where a failure occurs during the second call. Discussed with tb@ (who also flagged the negative value issue).
2022-08-11Remove unused variableTheo Buehler
X509_NAME_print() is documented to print things at a given indentation level. Unfortunately, this never worked since someone got some logic wrong. Part of the wrong logic was removed in a dead code removal in OpenSSL commit 92ada7cc, but the variable l was left behind, which leads to compiler warnings on some platforms. End its sad life pointlessly and incorrectly measuring column width and remove it. ok jsing
2022-08-10Avoid signed integer overflow due to unary negationTheo Buehler
The current X509_print_ex() tries too hard pretty printing negative serialNumbers (which shouldn't occur in the first place). In particular, negating LONG_MAX leads to signed overflow. Ditch the code dealing with negative serialNumbers representable as long and fall back to the long form printing. This simplifies the code and fixes oss-fuzz #49944 with/ok jsing
2022-08-10Cast int64_t to uint64_t for negatingTheo Buehler
Avoid signed integer overflow by casting an int64_t to uint64_t before negating. Same fix was applied in a_int.c -r1.44, but was forgotten to be applied to a_enum.c. ok jsing
2022-08-10Only print versions we know aboutTheo Buehler
The version field of an X.509 Certificate is an enum Version ::= INTEGER { v1(0), v2(1), v3(2) } Printing the version as l + 1 only really makes sense with 0 <= l <= 2. Otherwise print a naked l while also indicating that it is an unknown version. ok jsing
2022-07-30Use ASN1_INTEGER to encode/decode BIGNUM_it.Joel Sing
The current code simply shoves the unvalidated ASN.1 bytes into a BIGNUM on the hope that other things will detect issues (such as negative values being flipped to positive). Instead of doing this, decode and validate the ASN.1 data using ASN1_INTEGER, then convert it to a BIGNUM. Similarly, for encoding convert from BIGNUM to ASN1_INTEGER and use ASN1_INTEGER encoding. ok tb@
2022-07-30Provide and use a primitive clear function for BIGNUM_it.Joel Sing
Also tidy up bn_new() while here. ok tb@
2022-07-13Cast int64_t to uint64_t before negating.Joel Sing
Avoid undefined behaviour/integer overflow by casting an int64_t to uint64_t before negating. Fixes oss-fuzz #49043 ok tb@
2022-07-12Remove mkerr.pl remnants from LibreSSLKlemens Nanni
This script is not used at all and files are edited by hand instead. Thus remove misleading comments incl. the obsolete script/config. Feedback OK jsing tb
2022-07-09Make ASN1_{INTEGER,ENUMERATED}_get() return 0 on NULL againTheo Buehler
This is the documented behavior which got lost in the recent rewrite. Mismatch of documentation and reality pointed out by schwarze ok jsing
2022-07-07Expose new API in headers.Theo Buehler
These are mostly security-level related, but there are also ASN1_TIME and ASN_INTEGER functions here, as well as some missing accessors. ok jsing
2022-07-04The OpenSSL API is called ASN1_TIME_set_string_X509() (uppercase x)Theo Buehler
2022-07-02Use ASN1_INTEGER to parse/build (Z)LONG_itJoel Sing
Rather than having yet another (broken) ASN.1 INTEGER content builder and parser, use {c2i,i2c}_ASN1_INTEGER(). ok beck@
2022-06-30whitespace nitTheo Buehler
2022-06-29Refactor asn1 time parsing to use CBS - enforce valid times in ASN.1 parsing.Bob Beck
While we're here enforce valid days for months and leap years. Inspired by same in boringssl. ok jsing@
2022-06-28Negate unsigned then cast to signed.Joel Sing
Avoid undefined behaviour by negating the unsigned value, before casting to int64_t, rather than casting to int64_t then negating. Fixes oss-fuzz #48499 ok tb@
2022-06-27Add new time manipulation funcitons that OpenSSL has exposed thatBob Beck
the world seems to be using. Symbols.list changes and exposure to wait for minor bump ok jsing@ jca@
2022-06-27Prepare to provide EVP_PKEY_security_bits()Theo Buehler
This also provides a pkey_security_bits member to the PKEY ASN.1 methods and a corresponding setter EVP_PKEY_asn1_set_security_bits(). ok beck jsing
2022-06-26Provide and use long_{get,set}()Joel Sing
Apparently at some point a LONG_it was misaligned - provide and use long_{get,set}() so that we always memcpy() rather than doing it some times but not others. While here provide long_clear() rather than abusing and reusing long_free(). ok tb@