@fails-components/webtransport 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/readme.md +1 -3
- package/src/http3eventloop.cc +83 -9
- package/src/http3eventloop.h +13 -3
- package/src/http3server.cc +22 -22
- package/src/http3server.h +7 -20
- package/src/http3wtstreamvisitor.cc +31 -10
- package/src/http3wtstreamvisitor.h +38 -11
- package/src/webtransport.js +91 -23
- package/test/echoserver.js +29 -5
- package/test/testsuite.js +242 -220
- package/third_party/boringssl/src/CMakeLists.txt +2 -0
- package/third_party/boringssl/src/crypto/CMakeLists.txt +1 -0
- package/third_party/boringssl/src/crypto/asn1/a_bitstr.c +174 -177
- package/third_party/boringssl/src/crypto/asn1/a_bool.c +46 -48
- package/third_party/boringssl/src/crypto/asn1/a_d2i_fp.c +21 -23
- package/third_party/boringssl/src/crypto/asn1/a_dup.c +21 -23
- package/third_party/boringssl/src/crypto/asn1/a_gentm.c +84 -187
- package/third_party/boringssl/src/crypto/asn1/a_i2d_fp.c +19 -21
- package/third_party/boringssl/src/crypto/asn1/a_int.c +305 -329
- package/third_party/boringssl/src/crypto/asn1/a_mbstr.c +190 -195
- package/third_party/boringssl/src/crypto/asn1/a_object.c +182 -189
- package/third_party/boringssl/src/crypto/asn1/a_octet.c +6 -9
- package/third_party/boringssl/src/crypto/asn1/a_print.c +15 -16
- package/third_party/boringssl/src/crypto/asn1/a_strex.c +386 -399
- package/third_party/boringssl/src/crypto/asn1/a_strnid.c +110 -131
- package/third_party/boringssl/src/crypto/asn1/a_time.c +118 -111
- package/third_party/boringssl/src/crypto/asn1/a_type.c +59 -60
- package/third_party/boringssl/src/crypto/asn1/a_utctm.c +114 -186
- package/third_party/boringssl/src/crypto/asn1/a_utf8.c +171 -159
- package/third_party/boringssl/src/crypto/asn1/asn1_lib.c +245 -260
- package/third_party/boringssl/src/crypto/asn1/asn1_par.c +41 -40
- package/third_party/boringssl/src/crypto/asn1/asn1_test.cc +31 -0
- package/third_party/boringssl/src/crypto/asn1/asn_pack.c +31 -33
- package/third_party/boringssl/src/crypto/asn1/f_int.c +36 -33
- package/third_party/boringssl/src/crypto/asn1/f_string.c +29 -26
- package/third_party/boringssl/src/crypto/asn1/internal.h +62 -61
- package/third_party/boringssl/src/crypto/asn1/tasn_dec.c +706 -702
- package/third_party/boringssl/src/crypto/asn1/tasn_enc.c +507 -524
- package/third_party/boringssl/src/crypto/asn1/tasn_fre.c +141 -133
- package/third_party/boringssl/src/crypto/asn1/tasn_new.c +207 -199
- package/third_party/boringssl/src/crypto/asn1/tasn_typ.c +19 -22
- package/third_party/boringssl/src/crypto/asn1/tasn_utl.c +24 -24
- package/third_party/boringssl/src/crypto/asn1/time_support.c +13 -13
- package/third_party/boringssl/src/crypto/bio/connect.c +9 -3
- package/third_party/boringssl/src/crypto/bytestring/bytestring_test.cc +125 -1
- package/third_party/boringssl/src/crypto/bytestring/cbb.c +4 -7
- package/third_party/boringssl/src/crypto/bytestring/cbs.c +167 -9
- package/third_party/boringssl/src/crypto/cipher_extra/e_aesctrhmac.c +0 -2
- package/third_party/boringssl/src/crypto/cipher_extra/e_aesgcmsiv.c +23 -54
- package/third_party/boringssl/src/crypto/cipher_extra/e_chacha20poly1305.c +0 -2
- package/third_party/boringssl/src/crypto/cipher_extra/e_tls.c +0 -2
- package/third_party/boringssl/src/crypto/curve25519/curve25519.c +6 -8
- package/third_party/boringssl/src/crypto/evp/evp_ctx.c +25 -22
- package/third_party/boringssl/src/crypto/evp/internal.h +15 -9
- package/third_party/boringssl/src/crypto/evp/p_dsa_asn1.c +2 -0
- package/third_party/boringssl/src/crypto/evp/p_ec_asn1.c +2 -0
- package/third_party/boringssl/src/crypto/evp/p_ed25519.c +3 -3
- package/third_party/boringssl/src/crypto/evp/p_ed25519_asn1.c +10 -7
- package/third_party/boringssl/src/crypto/evp/p_hkdf.c +241 -0
- package/third_party/boringssl/src/crypto/evp/p_rsa_asn1.c +2 -0
- package/third_party/boringssl/src/crypto/evp/p_x25519_asn1.c +1 -0
- package/third_party/boringssl/src/crypto/fipsmodule/aes/aes_nohw.c +9 -10
- package/third_party/boringssl/src/crypto/fipsmodule/aes/key_wrap.c +2 -6
- package/third_party/boringssl/src/crypto/fipsmodule/bn/exponentiation.c +5 -11
- package/third_party/boringssl/src/crypto/fipsmodule/bn/internal.h +1 -1
- package/third_party/boringssl/src/crypto/fipsmodule/bn/prime.c +2 -0
- package/third_party/boringssl/src/crypto/fipsmodule/cipher/e_aes.c +10 -26
- package/third_party/boringssl/src/crypto/fipsmodule/cipher/e_aesccm.c +2 -3
- package/third_party/boringssl/src/crypto/fipsmodule/digestsign/digestsign.c +1 -0
- package/third_party/boringssl/src/crypto/fipsmodule/ec/p256-nistz.c +44 -43
- package/third_party/boringssl/src/crypto/fipsmodule/modes/cbc.c +5 -9
- package/third_party/boringssl/src/crypto/fipsmodule/modes/gcm.c +14 -21
- package/third_party/boringssl/src/crypto/fipsmodule/rand/ctrdrbg.c +8 -8
- package/third_party/boringssl/src/crypto/fipsmodule/rand/internal.h +1 -4
- package/third_party/boringssl/src/crypto/hkdf/hkdf_test.cc +104 -0
- package/third_party/boringssl/src/crypto/internal.h +18 -4
- package/third_party/boringssl/src/crypto/lhash/internal.h +13 -1
- package/third_party/boringssl/src/crypto/obj/obj_dat.h +4 -1
- package/third_party/boringssl/src/crypto/obj/obj_mac.num +1 -0
- package/third_party/boringssl/src/crypto/obj/objects.txt +2 -0
- package/third_party/boringssl/src/crypto/pem/pem_all.c +77 -86
- package/third_party/boringssl/src/crypto/pem/pem_info.c +221 -233
- package/third_party/boringssl/src/crypto/pem/pem_lib.c +639 -608
- package/third_party/boringssl/src/crypto/pem/pem_oth.c +17 -16
- package/third_party/boringssl/src/crypto/pem/pem_pk8.c +133 -142
- package/third_party/boringssl/src/crypto/pem/pem_pkey.c +96 -92
- package/third_party/boringssl/src/crypto/poly1305/poly1305_vec.c +12 -28
- package/third_party/boringssl/src/crypto/siphash/siphash.c +8 -11
- package/third_party/boringssl/src/crypto/siphash/siphash_test.cc +5 -7
- package/third_party/boringssl/src/crypto/stack/stack.c +33 -16
- package/third_party/boringssl/src/crypto/thread_pthread.c +0 -2
- package/third_party/boringssl/src/crypto/thread_win.c +0 -2
- package/third_party/boringssl/src/crypto/trust_token/internal.h +14 -0
- package/third_party/boringssl/src/crypto/trust_token/pmbtoken.c +127 -30
- package/third_party/boringssl/src/crypto/trust_token/trust_token.c +40 -0
- package/third_party/boringssl/src/crypto/trust_token/trust_token_test.cc +165 -0
- package/third_party/boringssl/src/crypto/trust_token/voprf.c +55 -6
- package/third_party/boringssl/src/crypto/x509/a_digest.c +23 -24
- package/third_party/boringssl/src/crypto/x509/a_sign.c +52 -55
- package/third_party/boringssl/src/crypto/x509/a_verify.c +33 -34
- package/third_party/boringssl/src/crypto/x509/algorithm.c +17 -18
- package/third_party/boringssl/src/crypto/x509/asn1_gen.c +618 -612
- package/third_party/boringssl/src/crypto/x509/by_dir.c +320 -337
- package/third_party/boringssl/src/crypto/x509/by_file.c +186 -186
- package/third_party/boringssl/src/crypto/x509/i2d_pr.c +11 -14
- package/third_party/boringssl/src/crypto/x509/internal.h +22 -22
- package/third_party/boringssl/src/crypto/x509/name_print.c +155 -150
- package/third_party/boringssl/src/crypto/x509/rsa_pss.c +27 -29
- package/third_party/boringssl/src/crypto/x509/t_crl.c +67 -70
- package/third_party/boringssl/src/crypto/x509/t_req.c +3 -5
- package/third_party/boringssl/src/crypto/x509/t_x509.c +280 -251
- package/third_party/boringssl/src/crypto/x509/t_x509a.c +52 -47
- package/third_party/boringssl/src/crypto/x509/x509.c +3 -4
- package/third_party/boringssl/src/crypto/x509/x509_att.c +234 -223
- package/third_party/boringssl/src/crypto/x509/x509_cmp.c +286 -296
- package/third_party/boringssl/src/crypto/x509/x509_d2.c +37 -32
- package/third_party/boringssl/src/crypto/x509/x509_def.c +14 -30
- package/third_party/boringssl/src/crypto/x509/x509_ext.c +55 -84
- package/third_party/boringssl/src/crypto/x509/x509_lu.c +545 -581
- package/third_party/boringssl/src/crypto/x509/x509_obj.c +131 -121
- package/third_party/boringssl/src/crypto/x509/x509_req.c +120 -139
- package/third_party/boringssl/src/crypto/x509/x509_set.c +128 -142
- package/third_party/boringssl/src/crypto/x509/x509_trs.c +185 -193
- package/third_party/boringssl/src/crypto/x509/x509_txt.c +70 -72
- package/third_party/boringssl/src/crypto/x509/x509_v3.c +172 -161
- package/third_party/boringssl/src/crypto/x509/x509_vfy.c +2041 -2053
- package/third_party/boringssl/src/crypto/x509/x509_vpm.c +441 -461
- package/third_party/boringssl/src/crypto/x509/x509cset.c +152 -170
- package/third_party/boringssl/src/crypto/x509/x509name.c +274 -260
- package/third_party/boringssl/src/crypto/x509/x509rset.c +43 -20
- package/third_party/boringssl/src/crypto/x509/x509spki.c +62 -63
- package/third_party/boringssl/src/crypto/x509/x_algor.c +64 -62
- package/third_party/boringssl/src/crypto/x509/x_all.c +103 -133
- package/third_party/boringssl/src/crypto/x509/x_attrib.c +23 -24
- package/third_party/boringssl/src/crypto/x509/x_crl.c +310 -321
- package/third_party/boringssl/src/crypto/x509/x_exten.c +6 -5
- package/third_party/boringssl/src/crypto/x509/x_info.c +31 -28
- package/third_party/boringssl/src/crypto/x509/x_name.c +361 -365
- package/third_party/boringssl/src/crypto/x509/x_pkey.c +38 -32
- package/third_party/boringssl/src/crypto/x509/x_pubkey.c +114 -117
- package/third_party/boringssl/src/crypto/x509/x_req.c +27 -29
- package/third_party/boringssl/src/crypto/x509/x_sig.c +2 -2
- package/third_party/boringssl/src/crypto/x509/x_spki.c +8 -10
- package/third_party/boringssl/src/crypto/x509/x_val.c +2 -2
- package/third_party/boringssl/src/crypto/x509/x_x509.c +212 -226
- package/third_party/boringssl/src/crypto/x509/x_x509a.c +112 -109
- package/third_party/boringssl/src/crypto/x509v3/ext_dat.h +10 -13
- package/third_party/boringssl/src/crypto/x509v3/internal.h +72 -87
- package/third_party/boringssl/src/crypto/x509v3/pcy_cache.c +184 -176
- package/third_party/boringssl/src/crypto/x509v3/pcy_data.c +58 -56
- package/third_party/boringssl/src/crypto/x509v3/pcy_lib.c +71 -70
- package/third_party/boringssl/src/crypto/x509v3/pcy_map.c +56 -58
- package/third_party/boringssl/src/crypto/x509v3/pcy_node.c +89 -91
- package/third_party/boringssl/src/crypto/x509v3/pcy_tree.c +585 -590
- package/third_party/boringssl/src/crypto/x509v3/v3_akey.c +118 -112
- package/third_party/boringssl/src/crypto/x509v3/v3_akeya.c +3 -3
- package/third_party/boringssl/src/crypto/x509v3/v3_alt.c +447 -451
- package/third_party/boringssl/src/crypto/x509v3/v3_bcons.c +44 -38
- package/third_party/boringssl/src/crypto/x509v3/v3_bitst.c +39 -43
- package/third_party/boringssl/src/crypto/x509v3/v3_conf.c +321 -320
- package/third_party/boringssl/src/crypto/x509v3/v3_cpols.c +352 -327
- package/third_party/boringssl/src/crypto/x509v3/v3_crld.c +437 -383
- package/third_party/boringssl/src/crypto/x509v3/v3_enum.c +23 -16
- package/third_party/boringssl/src/crypto/x509v3/v3_extku.c +62 -53
- package/third_party/boringssl/src/crypto/x509v3/v3_genn.c +118 -115
- package/third_party/boringssl/src/crypto/x509v3/v3_ia5.c +30 -31
- package/third_party/boringssl/src/crypto/x509v3/v3_info.c +112 -98
- package/third_party/boringssl/src/crypto/x509v3/v3_int.c +40 -15
- package/third_party/boringssl/src/crypto/x509v3/v3_lib.c +248 -252
- package/third_party/boringssl/src/crypto/x509v3/v3_ncons.c +390 -386
- package/third_party/boringssl/src/crypto/x509v3/v3_ocsp.c +45 -32
- package/third_party/boringssl/src/crypto/x509v3/v3_pci.c +206 -209
- package/third_party/boringssl/src/crypto/x509v3/v3_pcia.c +6 -8
- package/third_party/boringssl/src/crypto/x509v3/v3_pcons.c +54 -50
- package/third_party/boringssl/src/crypto/x509v3/v3_pmaps.c +66 -65
- package/third_party/boringssl/src/crypto/x509v3/v3_prn.c +144 -133
- package/third_party/boringssl/src/crypto/x509v3/v3_purp.c +695 -709
- package/third_party/boringssl/src/crypto/x509v3/v3_skey.c +75 -69
- package/third_party/boringssl/src/crypto/x509v3/v3_utl.c +1102 -1082
- package/third_party/boringssl/src/include/openssl/base.h +3 -1
- package/third_party/boringssl/src/include/openssl/bn.h +3 -0
- package/third_party/boringssl/src/include/openssl/bytestring.h +20 -0
- package/third_party/boringssl/src/include/openssl/evp.h +6 -5
- package/third_party/boringssl/src/include/openssl/kdf.h +91 -0
- package/third_party/boringssl/src/include/openssl/nid.h +4 -0
- package/third_party/boringssl/src/include/openssl/ssl.h +6 -1
- package/third_party/boringssl/src/include/openssl/stack.h +47 -32
- package/third_party/boringssl/src/include/openssl/trust_token.h +18 -3
- package/third_party/boringssl/src/include/openssl/x509.h +18 -0
- package/third_party/boringssl/src/ssl/ssl_file.cc +61 -99
- package/third_party/boringssl/src/ssl/ssl_test.cc +101 -0
- package/third_party/boringssl/src/util/doc.config +2 -1
- package/third_party/boringssl/src/util/fipstools/acvp/acvptool/subprocess/subprocess.go +8 -0
- package/third_party/googleurl/AUTHORS +16 -2
- package/third_party/googleurl/base/BUILD +1 -0
- package/third_party/googleurl/base/compiler_specific.h +16 -17
- package/third_party/googleurl/base/containers/contiguous_iterator.h +13 -9
- package/third_party/googleurl/base/containers/span.h +23 -8
- package/third_party/googleurl/base/memory/raw_ptr.h +17 -25
- package/third_party/googleurl/base/memory/raw_ptr_exclusion.h +21 -0
- package/third_party/googleurl/base/strings/escape.cc +14 -2
- package/third_party/googleurl/base/strings/safe_sprintf.h +1 -1
- package/third_party/googleurl/base/strings/string_number_conversions.cc +5 -3
- package/third_party/googleurl/base/strings/string_number_conversions_internal.h +5 -5
- package/third_party/googleurl/base/strings/string_piece.h +3 -3
- package/third_party/googleurl/base/strings/string_util.cc +4 -27
- package/third_party/googleurl/base/strings/string_util.h +43 -8
- package/third_party/googleurl/base/strings/string_util_internal.h +11 -12
- package/third_party/googleurl/base/strings/string_util_unittest.cc +33 -0
- package/third_party/googleurl/base/strings/string_util_win.cc +0 -5
- package/third_party/googleurl/base/strings/string_util_win.h +9 -1
- package/third_party/googleurl/base/strings/utf_offset_string_conversions.cc +1 -1
- package/third_party/googleurl/base/strings/utf_string_conversion_utils.cc +5 -8
- package/third_party/googleurl/base/strings/utf_string_conversion_utils.h +13 -10
- package/third_party/googleurl/base/strings/utf_string_conversions.cc +32 -25
- package/third_party/googleurl/base/template_util.h +23 -35
- package/third_party/googleurl/build/build_config.h +14 -3
- package/third_party/googleurl/copy.bara.sky +1 -1
- package/third_party/googleurl/url/gurl.cc +8 -4
- package/third_party/googleurl/url/gurl.h +1 -0
- package/third_party/googleurl/url/gurl_unittest.cc +1 -0
- package/third_party/googleurl/url/origin.h +36 -26
- package/third_party/googleurl/url/scheme_host_port.h +4 -1
- package/third_party/googleurl/url/url_canon.h +2 -1
- package/third_party/googleurl/url/url_canon_internal.cc +9 -7
- package/third_party/googleurl/url/url_canon_internal.h +16 -16
- package/third_party/googleurl/url/url_canon_stdstring.h +2 -1
- package/third_party/googleurl/url/url_util.cc +9 -8
- package/third_party/quiche/build/source_list.bzl +7 -0
- package/third_party/quiche/build/source_list.gni +7 -0
- package/third_party/quiche/build/source_list.json +7 -0
- package/third_party/quiche/quiche/common/platform/api/quiche_mem_slice.h +7 -3
- package/third_party/quiche/quiche/http2/adapter/nghttp2_adapter_test.cc +86 -2
- package/third_party/quiche/quiche/http2/adapter/oghttp2_adapter_test.cc +104 -2
- package/third_party/quiche/quiche/http2/adapter/oghttp2_session.cc +23 -0
- package/third_party/quiche/quiche/http2/adapter/oghttp2_session.h +6 -1
- package/third_party/quiche/quiche/quic/core/congestion_control/send_algorithm_test.cc +0 -16
- package/third_party/quiche/quiche/quic/core/crypto/crypto_protocol.h +1 -1
- package/third_party/quiche/quiche/quic/core/http/end_to_end_test.cc +56 -2
- package/third_party/quiche/quiche/quic/core/http/http_constants.cc +1 -0
- package/third_party/quiche/quiche/quic/core/http/http_constants.h +1 -0
- package/third_party/quiche/quiche/quic/core/http/http_encoder.cc +28 -17
- package/third_party/quiche/quiche/quic/core/http/http_encoder.h +5 -0
- package/third_party/quiche/quiche/quic/core/http/http_encoder_test.cc +26 -30
- package/third_party/quiche/quiche/quic/core/http/http_frames.h +1 -0
- package/third_party/quiche/quiche/quic/core/http/quic_server_session_base.cc +4 -4
- package/third_party/quiche/quiche/quic/core/http/quic_server_session_base_test.cc +1 -1
- package/third_party/quiche/quiche/quic/core/http/quic_spdy_client_session.cc +5 -1
- package/third_party/quiche/quiche/quic/core/http/quic_spdy_stream.cc +6 -33
- package/third_party/quiche/quiche/quic/core/http/quic_spdy_stream.h +0 -17
- package/third_party/quiche/quiche/quic/core/http/quic_spdy_stream_test.cc +5 -20
- package/third_party/quiche/quiche/quic/core/io/quic_event_loop.h +81 -0
- package/third_party/quiche/quiche/quic/core/io/quic_poll_event_loop.cc +265 -0
- package/third_party/quiche/quiche/quic/core/io/quic_poll_event_loop.h +152 -0
- package/third_party/quiche/quiche/quic/core/io/quic_poll_event_loop_test.cc +341 -0
- package/third_party/quiche/quiche/quic/core/quic_buffered_packet_store.cc +3 -1
- package/third_party/quiche/quiche/quic/core/quic_buffered_packet_store.h +7 -7
- package/third_party/quiche/quiche/quic/core/quic_buffered_packet_store_test.cc +4 -3
- package/third_party/quiche/quiche/quic/core/quic_connection.cc +69 -19
- package/third_party/quiche/quiche/quic/core/quic_connection.h +9 -3
- package/third_party/quiche/quiche/quic/core/quic_connection_id_manager.cc +29 -10
- package/third_party/quiche/quiche/quic/core/quic_connection_id_manager.h +5 -3
- package/third_party/quiche/quiche/quic/core/quic_connection_id_manager_test.cc +85 -22
- package/third_party/quiche/quiche/quic/core/quic_connection_test.cc +186 -30
- package/third_party/quiche/quiche/quic/core/quic_crypto_stream.cc +2 -1
- package/third_party/quiche/quiche/quic/core/quic_default_clock.cc +31 -0
- package/third_party/quiche/quiche/quic/core/quic_default_clock.h +34 -0
- package/third_party/quiche/quiche/quic/core/quic_default_connection_helper.h +49 -0
- package/third_party/quiche/quiche/quic/core/quic_dispatcher.cc +53 -37
- package/third_party/quiche/quiche/quic/core/quic_dispatcher.h +19 -11
- package/third_party/quiche/quiche/quic/core/quic_dispatcher_test.cc +15 -2
- package/third_party/quiche/quiche/quic/core/quic_flags_list.h +10 -4
- package/third_party/quiche/quiche/quic/core/quic_idle_network_detector.cc +2 -2
- package/third_party/quiche/quiche/quic/core/quic_idle_network_detector_test.cc +4 -4
- package/third_party/quiche/quiche/quic/core/quic_packet_creator.cc +14 -3
- package/third_party/quiche/quiche/quic/core/quic_packet_creator_test.cc +145 -2
- package/third_party/quiche/quiche/quic/core/quic_packets.cc +3 -1
- package/third_party/quiche/quiche/quic/core/quic_packets.h +4 -0
- package/third_party/quiche/quiche/quic/core/quic_sent_packet_manager.cc +13 -11
- package/third_party/quiche/quiche/quic/core/quic_sent_packet_manager.h +9 -0
- package/third_party/quiche/quiche/quic/core/quic_sent_packet_manager_test.cc +6 -0
- package/third_party/quiche/quiche/quic/core/quic_session.cc +3 -2
- package/third_party/quiche/quiche/quic/core/quic_session.h +8 -3
- package/third_party/quiche/quiche/quic/core/quic_types.cc +18 -0
- package/third_party/quiche/quiche/quic/core/quic_types.h +3 -0
- package/third_party/quiche/quiche/quic/core/tls_chlo_extractor.cc +3 -0
- package/third_party/quiche/quiche/quic/core/tls_chlo_extractor.h +10 -0
- package/third_party/quiche/quiche/quic/test_tools/mock_quic_session_visitor.h +1 -1
- package/third_party/quiche/quiche/quic/test_tools/quic_test_utils.h +1 -1
- package/third_party/quiche/quiche/quic/test_tools/server_thread.cc +3 -2
- package/third_party/quiche/quiche/quic/test_tools/simple_session_notifier.cc +7 -1
- package/third_party/quiche/quiche/quic/test_tools/simple_session_notifier.h +3 -0
- package/third_party/quiche/quiche/quic/test_tools/simulator/quic_endpoint.h +4 -2
- package/certs/ca.cnf +0 -69
- package/certs/generate_certs.sh +0 -53
- package/certs/generate_certs_leaf.sh +0 -53
- package/certs/leaf.cnf +0 -24
- package/certs/readme.txt +0 -2
- package/third_party/quiche/build/BUILD.bazel +0 -7
|
@@ -55,67 +55,62 @@
|
|
|
55
55
|
* [including the GNU Public Licence.] */
|
|
56
56
|
|
|
57
57
|
#include <openssl/asn1.h>
|
|
58
|
-
|
|
59
|
-
#include <limits.h>
|
|
60
|
-
#include <string.h>
|
|
61
|
-
|
|
62
58
|
#include <openssl/asn1t.h>
|
|
59
|
+
#include <openssl/bytestring.h>
|
|
63
60
|
#include <openssl/err.h>
|
|
64
61
|
#include <openssl/mem.h>
|
|
65
62
|
|
|
63
|
+
#include <limits.h>
|
|
64
|
+
#include <string.h>
|
|
65
|
+
|
|
66
66
|
#include "../internal.h"
|
|
67
67
|
#include "internal.h"
|
|
68
68
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
* recursive invocations of asn1_item_embed_d2i().
|
|
74
|
-
*/
|
|
69
|
+
// Constructed types with a recursive definition (such as can be found in PKCS7)
|
|
70
|
+
// could eventually exceed the stack given malicious input with excessive
|
|
71
|
+
// recursion. Therefore we limit the stack depth. This is the maximum number of
|
|
72
|
+
// recursive invocations of asn1_item_embed_d2i().
|
|
75
73
|
#define ASN1_MAX_CONSTRUCTED_NEST 30
|
|
76
74
|
|
|
77
75
|
static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass,
|
|
78
76
|
char *cst, const unsigned char **in, long len,
|
|
79
77
|
int exptag, int expclass, char opt);
|
|
80
78
|
|
|
81
|
-
static int asn1_template_ex_d2i(ASN1_VALUE **pval,
|
|
82
|
-
const
|
|
83
|
-
const ASN1_TEMPLATE *tt, char opt,
|
|
79
|
+
static int asn1_template_ex_d2i(ASN1_VALUE **pval, const unsigned char **in,
|
|
80
|
+
long len, const ASN1_TEMPLATE *tt, char opt,
|
|
84
81
|
int depth);
|
|
85
|
-
static int asn1_template_noexp_d2i(ASN1_VALUE **val,
|
|
86
|
-
const
|
|
87
|
-
const ASN1_TEMPLATE *tt, char opt,
|
|
82
|
+
static int asn1_template_noexp_d2i(ASN1_VALUE **val, const unsigned char **in,
|
|
83
|
+
long len, const ASN1_TEMPLATE *tt, char opt,
|
|
88
84
|
int depth);
|
|
89
85
|
static int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,
|
|
90
86
|
int utype, const ASN1_ITEM *it);
|
|
91
|
-
static int asn1_d2i_ex_primitive(ASN1_VALUE **pval,
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
int tag, int aclass, char opt);
|
|
87
|
+
static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, const unsigned char **in,
|
|
88
|
+
long len, const ASN1_ITEM *it, int tag,
|
|
89
|
+
int aclass, char opt);
|
|
95
90
|
static int asn1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in,
|
|
96
91
|
long len, const ASN1_ITEM *it, int tag, int aclass,
|
|
97
92
|
char opt, int depth);
|
|
98
93
|
|
|
99
|
-
|
|
94
|
+
// Table to convert tags to bit values, used for MSTRING type
|
|
100
95
|
static const unsigned long tag2bit[31] = {
|
|
101
|
-
0,
|
|
102
|
-
0,
|
|
103
|
-
0,
|
|
96
|
+
0, // (reserved)
|
|
97
|
+
0, // BOOLEAN
|
|
98
|
+
0, // INTEGER
|
|
104
99
|
B_ASN1_BIT_STRING,
|
|
105
100
|
B_ASN1_OCTET_STRING,
|
|
106
|
-
0,
|
|
107
|
-
0,
|
|
108
|
-
B_ASN1_UNKNOWN,
|
|
109
|
-
B_ASN1_UNKNOWN,
|
|
110
|
-
B_ASN1_UNKNOWN,
|
|
111
|
-
B_ASN1_UNKNOWN,
|
|
112
|
-
B_ASN1_UNKNOWN,
|
|
101
|
+
0, // NULL
|
|
102
|
+
0, // OBJECT IDENTIFIER
|
|
103
|
+
B_ASN1_UNKNOWN, // ObjectDescriptor
|
|
104
|
+
B_ASN1_UNKNOWN, // EXTERNAL
|
|
105
|
+
B_ASN1_UNKNOWN, // REAL
|
|
106
|
+
B_ASN1_UNKNOWN, // ENUMERATED
|
|
107
|
+
B_ASN1_UNKNOWN, // EMBEDDED PDV
|
|
113
108
|
B_ASN1_UTF8STRING,
|
|
114
|
-
B_ASN1_UNKNOWN,
|
|
115
|
-
B_ASN1_UNKNOWN,
|
|
116
|
-
B_ASN1_UNKNOWN,
|
|
109
|
+
B_ASN1_UNKNOWN, // RELATIVE-OID
|
|
110
|
+
B_ASN1_UNKNOWN, // TIME
|
|
111
|
+
B_ASN1_UNKNOWN, // (reserved)
|
|
117
112
|
B_ASN1_SEQUENCE,
|
|
118
|
-
0,
|
|
113
|
+
0, // SET
|
|
119
114
|
B_ASN1_NUMERICSTRING,
|
|
120
115
|
B_ASN1_PRINTABLESTRING,
|
|
121
116
|
B_ASN1_T61STRING,
|
|
@@ -127,673 +122,663 @@ static const unsigned long tag2bit[31] = {
|
|
|
127
122
|
B_ASN1_ISO64STRING,
|
|
128
123
|
B_ASN1_GENERALSTRING,
|
|
129
124
|
B_ASN1_UNIVERSALSTRING,
|
|
130
|
-
B_ASN1_UNKNOWN,
|
|
125
|
+
B_ASN1_UNKNOWN, // CHARACTER STRING
|
|
131
126
|
B_ASN1_BMPSTRING,
|
|
132
127
|
};
|
|
133
128
|
|
|
134
|
-
unsigned long ASN1_tag2bit(int tag)
|
|
135
|
-
{
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
129
|
+
unsigned long ASN1_tag2bit(int tag) {
|
|
130
|
+
if (tag < 0 || tag > 30) {
|
|
131
|
+
return 0;
|
|
132
|
+
}
|
|
133
|
+
return tag2bit[tag];
|
|
139
134
|
}
|
|
140
135
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
ASN1_VALUE *
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
return *pval;
|
|
160
|
-
return NULL;
|
|
136
|
+
// Macro to initialize and invalidate the cache
|
|
137
|
+
|
|
138
|
+
// Decode an ASN1 item, this currently behaves just like a standard 'd2i'
|
|
139
|
+
// function. 'in' points to a buffer to read the data from, in future we
|
|
140
|
+
// will have more advanced versions that can input data a piece at a time and
|
|
141
|
+
// this will simply be a special case.
|
|
142
|
+
|
|
143
|
+
ASN1_VALUE *ASN1_item_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
|
|
144
|
+
const ASN1_ITEM *it) {
|
|
145
|
+
ASN1_VALUE *ptmpval = NULL;
|
|
146
|
+
if (!pval) {
|
|
147
|
+
pval = &ptmpval;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (asn1_item_ex_d2i(pval, in, len, it, -1, 0, 0, 0) > 0) {
|
|
151
|
+
return *pval;
|
|
152
|
+
}
|
|
153
|
+
return NULL;
|
|
161
154
|
}
|
|
162
155
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
* tag mismatch return -1 to handle OPTIONAL
|
|
166
|
-
*/
|
|
156
|
+
// Decode an item, taking care of IMPLICIT tagging, if any. If 'opt' set and
|
|
157
|
+
// tag mismatch return -1 to handle OPTIONAL
|
|
167
158
|
|
|
168
159
|
static int asn1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in,
|
|
169
160
|
long len, const ASN1_ITEM *it, int tag, int aclass,
|
|
170
|
-
char opt, int depth)
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
/*
|
|
187
|
-
* Bound |len| to comfortably fit in an int. Lengths in this module often
|
|
188
|
-
* switch between int and long without overflow checks.
|
|
189
|
-
*/
|
|
190
|
-
if (len > INT_MAX/2) {
|
|
191
|
-
len = INT_MAX/2;
|
|
192
|
-
}
|
|
161
|
+
char opt, int depth) {
|
|
162
|
+
const ASN1_TEMPLATE *tt, *errtt = NULL;
|
|
163
|
+
const ASN1_EXTERN_FUNCS *ef;
|
|
164
|
+
const unsigned char *p = NULL, *q;
|
|
165
|
+
unsigned char oclass;
|
|
166
|
+
char cst, isopt;
|
|
167
|
+
int i;
|
|
168
|
+
int otag;
|
|
169
|
+
int ret = 0;
|
|
170
|
+
ASN1_VALUE **pchptr;
|
|
171
|
+
int combine = aclass & ASN1_TFLG_COMBINE;
|
|
172
|
+
aclass &= ~ASN1_TFLG_COMBINE;
|
|
173
|
+
if (!pval) {
|
|
174
|
+
return 0;
|
|
175
|
+
}
|
|
193
176
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
177
|
+
// Bound |len| to comfortably fit in an int. Lengths in this module often
|
|
178
|
+
// switch between int and long without overflow checks.
|
|
179
|
+
if (len > INT_MAX / 2) {
|
|
180
|
+
len = INT_MAX / 2;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (++depth > ASN1_MAX_CONSTRUCTED_NEST) {
|
|
184
|
+
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_TOO_DEEP);
|
|
185
|
+
goto err;
|
|
186
|
+
}
|
|
198
187
|
|
|
199
|
-
|
|
188
|
+
switch (it->itype) {
|
|
200
189
|
case ASN1_ITYPE_PRIMITIVE:
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
it->templates, opt, depth);
|
|
215
|
-
}
|
|
216
|
-
return asn1_d2i_ex_primitive(pval, in, len, it,
|
|
217
|
-
tag, aclass, opt);
|
|
218
|
-
break;
|
|
190
|
+
if (it->templates) {
|
|
191
|
+
// tagging or OPTIONAL is currently illegal on an item template
|
|
192
|
+
// because the flags can't get passed down. In practice this
|
|
193
|
+
// isn't a problem: we include the relevant flags from the item
|
|
194
|
+
// template in the template itself.
|
|
195
|
+
if ((tag != -1) || opt) {
|
|
196
|
+
OPENSSL_PUT_ERROR(ASN1, ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE);
|
|
197
|
+
goto err;
|
|
198
|
+
}
|
|
199
|
+
return asn1_template_ex_d2i(pval, in, len, it->templates, opt, depth);
|
|
200
|
+
}
|
|
201
|
+
return asn1_d2i_ex_primitive(pval, in, len, it, tag, aclass, opt);
|
|
202
|
+
break;
|
|
219
203
|
|
|
220
204
|
case ASN1_ITYPE_MSTRING:
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
goto err;
|
|
228
|
-
}
|
|
205
|
+
// It never makes sense for multi-strings to have implicit tagging, so
|
|
206
|
+
// if tag != -1, then this looks like an error in the template.
|
|
207
|
+
if (tag != -1) {
|
|
208
|
+
OPENSSL_PUT_ERROR(ASN1, ASN1_R_BAD_TEMPLATE);
|
|
209
|
+
goto err;
|
|
210
|
+
}
|
|
229
211
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
}
|
|
212
|
+
p = *in;
|
|
213
|
+
// Just read in tag and class
|
|
214
|
+
ret = asn1_check_tlen(NULL, &otag, &oclass, NULL, &p, len, -1, 0, 1);
|
|
215
|
+
if (!ret) {
|
|
216
|
+
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
|
|
217
|
+
goto err;
|
|
218
|
+
}
|
|
238
219
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
OPENSSL_PUT_ERROR(ASN1, ASN1_R_MSTRING_NOT_UNIVERSAL);
|
|
245
|
-
goto err;
|
|
220
|
+
// Must be UNIVERSAL class
|
|
221
|
+
if (oclass != V_ASN1_UNIVERSAL) {
|
|
222
|
+
// If OPTIONAL, assume this is OK
|
|
223
|
+
if (opt) {
|
|
224
|
+
return -1;
|
|
246
225
|
}
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
226
|
+
OPENSSL_PUT_ERROR(ASN1, ASN1_R_MSTRING_NOT_UNIVERSAL);
|
|
227
|
+
goto err;
|
|
228
|
+
}
|
|
229
|
+
// Check tag matches bit map
|
|
230
|
+
if (!(ASN1_tag2bit(otag) & it->utype)) {
|
|
231
|
+
// If OPTIONAL, assume this is OK
|
|
232
|
+
if (opt) {
|
|
233
|
+
return -1;
|
|
254
234
|
}
|
|
255
|
-
|
|
235
|
+
OPENSSL_PUT_ERROR(ASN1, ASN1_R_MSTRING_WRONG_TAG);
|
|
236
|
+
goto err;
|
|
237
|
+
}
|
|
238
|
+
return asn1_d2i_ex_primitive(pval, in, len, it, otag, 0, 0);
|
|
256
239
|
|
|
257
240
|
case ASN1_ITYPE_EXTERN:
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
241
|
+
// Use new style d2i
|
|
242
|
+
ef = it->funcs;
|
|
243
|
+
return ef->asn1_ex_d2i(pval, in, len, it, tag, aclass, opt, NULL);
|
|
261
244
|
|
|
262
245
|
case ASN1_ITYPE_CHOICE: {
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
if
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
}
|
|
246
|
+
// It never makes sense for CHOICE types to have implicit tagging, so if
|
|
247
|
+
// tag != -1, then this looks like an error in the template.
|
|
248
|
+
if (tag != -1) {
|
|
249
|
+
OPENSSL_PUT_ERROR(ASN1, ASN1_R_BAD_TEMPLATE);
|
|
250
|
+
goto err;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
const ASN1_AUX *aux = it->funcs;
|
|
254
|
+
ASN1_aux_cb *asn1_cb = aux != NULL ? aux->asn1_cb : NULL;
|
|
255
|
+
if (asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it, NULL)) {
|
|
256
|
+
goto auxerr;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
if (*pval) {
|
|
260
|
+
// Free up and zero CHOICE value if initialised
|
|
261
|
+
i = asn1_get_choice_selector(pval, it);
|
|
262
|
+
if ((i >= 0) && (i < it->tcount)) {
|
|
263
|
+
tt = it->templates + i;
|
|
264
|
+
pchptr = asn1_get_field_ptr(pval, tt);
|
|
265
|
+
ASN1_template_free(pchptr, tt);
|
|
266
|
+
asn1_set_choice_selector(pval, -1, it);
|
|
267
|
+
}
|
|
268
|
+
} else if (!ASN1_item_ex_new(pval, it)) {
|
|
269
|
+
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
|
|
270
|
+
goto err;
|
|
271
|
+
}
|
|
272
|
+
// CHOICE type, try each possibility in turn
|
|
273
|
+
p = *in;
|
|
274
|
+
for (i = 0, tt = it->templates; i < it->tcount; i++, tt++) {
|
|
275
|
+
pchptr = asn1_get_field_ptr(pval, tt);
|
|
276
|
+
// We mark field as OPTIONAL so its absence can be recognised.
|
|
277
|
+
ret = asn1_template_ex_d2i(pchptr, &p, len, tt, 1, depth);
|
|
278
|
+
// If field not present, try the next one
|
|
279
|
+
if (ret == -1) {
|
|
280
|
+
continue;
|
|
281
|
+
}
|
|
282
|
+
// If positive return, read OK, break loop
|
|
283
|
+
if (ret > 0) {
|
|
284
|
+
break;
|
|
285
|
+
}
|
|
286
|
+
// Otherwise must be an ASN1 parsing error
|
|
287
|
+
errtt = tt;
|
|
288
|
+
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
|
|
289
|
+
goto err;
|
|
290
|
+
}
|
|
309
291
|
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
}
|
|
318
|
-
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NO_MATCHING_CHOICE_TYPE);
|
|
319
|
-
goto err;
|
|
292
|
+
// Did we fall off the end without reading anything?
|
|
293
|
+
if (i == it->tcount) {
|
|
294
|
+
// If OPTIONAL, this is OK
|
|
295
|
+
if (opt) {
|
|
296
|
+
// Free and zero it
|
|
297
|
+
ASN1_item_ex_free(pval, it);
|
|
298
|
+
return -1;
|
|
320
299
|
}
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
300
|
+
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NO_MATCHING_CHOICE_TYPE);
|
|
301
|
+
goto err;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
asn1_set_choice_selector(pval, i, it);
|
|
305
|
+
if (asn1_cb && !asn1_cb(ASN1_OP_D2I_POST, pval, it, NULL)) {
|
|
306
|
+
goto auxerr;
|
|
307
|
+
}
|
|
308
|
+
*in = p;
|
|
309
|
+
return 1;
|
|
327
310
|
}
|
|
328
311
|
|
|
329
312
|
case ASN1_ITYPE_SEQUENCE: {
|
|
330
|
-
|
|
313
|
+
p = *in;
|
|
331
314
|
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
if (!*pval && !ASN1_item_ex_new(pval, it)) {
|
|
351
|
-
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
|
|
352
|
-
goto err;
|
|
353
|
-
}
|
|
315
|
+
// If no IMPLICIT tagging set to SEQUENCE, UNIVERSAL
|
|
316
|
+
if (tag == -1) {
|
|
317
|
+
tag = V_ASN1_SEQUENCE;
|
|
318
|
+
aclass = V_ASN1_UNIVERSAL;
|
|
319
|
+
}
|
|
320
|
+
// Get SEQUENCE length and update len, p
|
|
321
|
+
ret = asn1_check_tlen(&len, NULL, NULL, &cst, &p, len, tag, aclass, opt);
|
|
322
|
+
if (!ret) {
|
|
323
|
+
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
|
|
324
|
+
goto err;
|
|
325
|
+
} else if (ret == -1) {
|
|
326
|
+
return -1;
|
|
327
|
+
}
|
|
328
|
+
if (!cst) {
|
|
329
|
+
OPENSSL_PUT_ERROR(ASN1, ASN1_R_SEQUENCE_NOT_CONSTRUCTED);
|
|
330
|
+
goto err;
|
|
331
|
+
}
|
|
354
332
|
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
333
|
+
if (!*pval && !ASN1_item_ex_new(pval, it)) {
|
|
334
|
+
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
|
|
335
|
+
goto err;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
const ASN1_AUX *aux = it->funcs;
|
|
339
|
+
ASN1_aux_cb *asn1_cb = aux != NULL ? aux->asn1_cb : NULL;
|
|
340
|
+
if (asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it, NULL)) {
|
|
341
|
+
goto auxerr;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// Free up and zero any ADB found
|
|
345
|
+
for (i = 0, tt = it->templates; i < it->tcount; i++, tt++) {
|
|
346
|
+
if (tt->flags & ASN1_TFLG_ADB_MASK) {
|
|
347
|
+
const ASN1_TEMPLATE *seqtt;
|
|
348
|
+
ASN1_VALUE **pseqval;
|
|
349
|
+
seqtt = asn1_do_adb(pval, tt, 0);
|
|
350
|
+
if (seqtt == NULL) {
|
|
351
|
+
continue;
|
|
352
|
+
}
|
|
353
|
+
pseqval = asn1_get_field_ptr(pval, seqtt);
|
|
354
|
+
ASN1_template_free(pseqval, seqtt);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// Get each field entry
|
|
359
|
+
for (i = 0, tt = it->templates; i < it->tcount; i++, tt++) {
|
|
360
|
+
const ASN1_TEMPLATE *seqtt;
|
|
361
|
+
ASN1_VALUE **pseqval;
|
|
362
|
+
seqtt = asn1_do_adb(pval, tt, 1);
|
|
363
|
+
if (seqtt == NULL) {
|
|
364
|
+
goto err;
|
|
365
|
+
}
|
|
366
|
+
pseqval = asn1_get_field_ptr(pval, seqtt);
|
|
367
|
+
// Have we ran out of data?
|
|
368
|
+
if (!len) {
|
|
369
|
+
break;
|
|
371
370
|
}
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
/* Have we ran out of data? */
|
|
382
|
-
if (!len)
|
|
383
|
-
break;
|
|
384
|
-
q = p;
|
|
385
|
-
/*
|
|
386
|
-
* This determines the OPTIONAL flag value. The field cannot be
|
|
387
|
-
* omitted if it is the last of a SEQUENCE and there is still
|
|
388
|
-
* data to be read. This isn't strictly necessary but it
|
|
389
|
-
* increases efficiency in some cases.
|
|
390
|
-
*/
|
|
391
|
-
if (i == (it->tcount - 1))
|
|
392
|
-
isopt = 0;
|
|
393
|
-
else
|
|
394
|
-
isopt = (char)(seqtt->flags & ASN1_TFLG_OPTIONAL);
|
|
395
|
-
/*
|
|
396
|
-
* attempt to read in field, allowing each to be OPTIONAL
|
|
397
|
-
*/
|
|
398
|
-
|
|
399
|
-
ret = asn1_template_ex_d2i(pseqval, &p, len, seqtt, isopt, depth);
|
|
400
|
-
if (!ret) {
|
|
401
|
-
errtt = seqtt;
|
|
402
|
-
goto err;
|
|
403
|
-
} else if (ret == -1) {
|
|
404
|
-
/*
|
|
405
|
-
* OPTIONAL component absent. Free and zero the field.
|
|
406
|
-
*/
|
|
407
|
-
ASN1_template_free(pseqval, seqtt);
|
|
408
|
-
continue;
|
|
409
|
-
}
|
|
410
|
-
/* Update length */
|
|
411
|
-
len -= p - q;
|
|
371
|
+
q = p;
|
|
372
|
+
// This determines the OPTIONAL flag value. The field cannot be
|
|
373
|
+
// omitted if it is the last of a SEQUENCE and there is still
|
|
374
|
+
// data to be read. This isn't strictly necessary but it
|
|
375
|
+
// increases efficiency in some cases.
|
|
376
|
+
if (i == (it->tcount - 1)) {
|
|
377
|
+
isopt = 0;
|
|
378
|
+
} else {
|
|
379
|
+
isopt = (char)(seqtt->flags & ASN1_TFLG_OPTIONAL);
|
|
412
380
|
}
|
|
381
|
+
// attempt to read in field, allowing each to be OPTIONAL
|
|
413
382
|
|
|
414
|
-
|
|
415
|
-
if (
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
}
|
|
383
|
+
ret = asn1_template_ex_d2i(pseqval, &p, len, seqtt, isopt, depth);
|
|
384
|
+
if (!ret) {
|
|
385
|
+
errtt = seqtt;
|
|
386
|
+
goto err;
|
|
387
|
+
} else if (ret == -1) {
|
|
388
|
+
// OPTIONAL component absent. Free and zero the field.
|
|
389
|
+
ASN1_template_free(pseqval, seqtt);
|
|
390
|
+
continue;
|
|
391
|
+
}
|
|
392
|
+
// Update length
|
|
393
|
+
len -= p - q;
|
|
394
|
+
}
|
|
419
395
|
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
396
|
+
// Check all data read
|
|
397
|
+
if (len) {
|
|
398
|
+
OPENSSL_PUT_ERROR(ASN1, ASN1_R_SEQUENCE_LENGTH_MISMATCH);
|
|
399
|
+
goto err;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
// If we get here we've got no more data in the SEQUENCE, however we
|
|
403
|
+
// may not have read all fields so check all remaining are OPTIONAL
|
|
404
|
+
// and clear any that are.
|
|
405
|
+
for (; i < it->tcount; tt++, i++) {
|
|
406
|
+
const ASN1_TEMPLATE *seqtt;
|
|
407
|
+
seqtt = asn1_do_adb(pval, tt, 1);
|
|
408
|
+
if (seqtt == NULL) {
|
|
409
|
+
goto err;
|
|
410
|
+
}
|
|
411
|
+
if (seqtt->flags & ASN1_TFLG_OPTIONAL) {
|
|
412
|
+
ASN1_VALUE **pseqval;
|
|
413
|
+
pseqval = asn1_get_field_ptr(pval, seqtt);
|
|
414
|
+
ASN1_template_free(pseqval, seqtt);
|
|
415
|
+
} else {
|
|
416
|
+
errtt = seqtt;
|
|
417
|
+
OPENSSL_PUT_ERROR(ASN1, ASN1_R_FIELD_MISSING);
|
|
418
|
+
goto err;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
// Save encoding
|
|
422
|
+
if (!asn1_enc_save(pval, *in, p - *in, it)) {
|
|
423
|
+
goto auxerr;
|
|
424
|
+
}
|
|
425
|
+
if (asn1_cb && !asn1_cb(ASN1_OP_D2I_POST, pval, it, NULL)) {
|
|
426
|
+
goto auxerr;
|
|
427
|
+
}
|
|
428
|
+
*in = p;
|
|
429
|
+
return 1;
|
|
447
430
|
}
|
|
448
431
|
|
|
449
432
|
default:
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
433
|
+
return 0;
|
|
434
|
+
}
|
|
435
|
+
auxerr:
|
|
436
|
+
OPENSSL_PUT_ERROR(ASN1, ASN1_R_AUX_ERROR);
|
|
437
|
+
err:
|
|
438
|
+
if (combine == 0) {
|
|
439
|
+
ASN1_item_ex_free(pval, it);
|
|
440
|
+
}
|
|
441
|
+
if (errtt) {
|
|
442
|
+
ERR_add_error_data(4, "Field=", errtt->field_name, ", Type=", it->sname);
|
|
443
|
+
} else {
|
|
444
|
+
ERR_add_error_data(2, "Type=", it->sname);
|
|
445
|
+
}
|
|
446
|
+
return 0;
|
|
463
447
|
}
|
|
464
448
|
|
|
465
449
|
int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
|
|
466
|
-
const ASN1_ITEM *it,
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
return asn1_item_ex_d2i(pval, in, len, it, tag, aclass, opt, 0);
|
|
450
|
+
const ASN1_ITEM *it, int tag, int aclass, char opt,
|
|
451
|
+
ASN1_TLC *ctx) {
|
|
452
|
+
return asn1_item_ex_d2i(pval, in, len, it, tag, aclass, opt, 0);
|
|
470
453
|
}
|
|
471
454
|
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
return 0;
|
|
488
|
-
flags = tt->flags;
|
|
489
|
-
aclass = flags & ASN1_TFLG_TAG_CLASS;
|
|
455
|
+
// Templates are handled with two separate functions. One handles any
|
|
456
|
+
// EXPLICIT tag and the other handles the rest.
|
|
457
|
+
|
|
458
|
+
static int asn1_template_ex_d2i(ASN1_VALUE **val, const unsigned char **in,
|
|
459
|
+
long inlen, const ASN1_TEMPLATE *tt, char opt,
|
|
460
|
+
int depth) {
|
|
461
|
+
int flags, aclass;
|
|
462
|
+
int ret;
|
|
463
|
+
long len;
|
|
464
|
+
const unsigned char *p, *q;
|
|
465
|
+
if (!val) {
|
|
466
|
+
return 0;
|
|
467
|
+
}
|
|
468
|
+
flags = tt->flags;
|
|
469
|
+
aclass = flags & ASN1_TFLG_TAG_CLASS;
|
|
490
470
|
|
|
491
|
-
|
|
471
|
+
p = *in;
|
|
492
472
|
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
473
|
+
// Check if EXPLICIT tag expected
|
|
474
|
+
if (flags & ASN1_TFLG_EXPTAG) {
|
|
475
|
+
char cst;
|
|
476
|
+
// Need to work out amount of data available to the inner content and
|
|
477
|
+
// where it starts: so read in EXPLICIT header to get the info.
|
|
478
|
+
ret = asn1_check_tlen(&len, NULL, NULL, &cst, &p, inlen, tt->tag, aclass,
|
|
479
|
+
opt);
|
|
480
|
+
q = p;
|
|
481
|
+
if (!ret) {
|
|
482
|
+
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
|
|
483
|
+
return 0;
|
|
484
|
+
} else if (ret == -1) {
|
|
485
|
+
return -1;
|
|
486
|
+
}
|
|
487
|
+
if (!cst) {
|
|
488
|
+
OPENSSL_PUT_ERROR(ASN1, ASN1_R_EXPLICIT_TAG_NOT_CONSTRUCTED);
|
|
489
|
+
return 0;
|
|
490
|
+
}
|
|
491
|
+
// We've found the field so it can't be OPTIONAL now
|
|
492
|
+
ret = asn1_template_noexp_d2i(val, &p, len, tt, 0, depth);
|
|
493
|
+
if (!ret) {
|
|
494
|
+
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
|
|
495
|
+
return 0;
|
|
496
|
+
}
|
|
497
|
+
// We read the field in OK so update length
|
|
498
|
+
len -= p - q;
|
|
499
|
+
// Check for trailing data.
|
|
500
|
+
if (len) {
|
|
501
|
+
OPENSSL_PUT_ERROR(ASN1, ASN1_R_EXPLICIT_LENGTH_MISMATCH);
|
|
502
|
+
goto err;
|
|
503
|
+
}
|
|
504
|
+
} else {
|
|
505
|
+
return asn1_template_noexp_d2i(val, in, inlen, tt, opt, depth);
|
|
506
|
+
}
|
|
527
507
|
|
|
528
|
-
|
|
529
|
-
|
|
508
|
+
*in = p;
|
|
509
|
+
return 1;
|
|
530
510
|
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
511
|
+
err:
|
|
512
|
+
ASN1_template_free(val, tt);
|
|
513
|
+
return 0;
|
|
534
514
|
}
|
|
535
515
|
|
|
536
|
-
static int asn1_template_noexp_d2i(ASN1_VALUE **val,
|
|
537
|
-
const
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
}
|
|
516
|
+
static int asn1_template_noexp_d2i(ASN1_VALUE **val, const unsigned char **in,
|
|
517
|
+
long len, const ASN1_TEMPLATE *tt, char opt,
|
|
518
|
+
int depth) {
|
|
519
|
+
int flags, aclass;
|
|
520
|
+
int ret;
|
|
521
|
+
const unsigned char *p;
|
|
522
|
+
if (!val) {
|
|
523
|
+
return 0;
|
|
524
|
+
}
|
|
525
|
+
flags = tt->flags;
|
|
526
|
+
aclass = flags & ASN1_TFLG_TAG_CLASS;
|
|
527
|
+
|
|
528
|
+
p = *in;
|
|
529
|
+
|
|
530
|
+
if (flags & ASN1_TFLG_SK_MASK) {
|
|
531
|
+
// SET OF, SEQUENCE OF
|
|
532
|
+
int sktag, skaclass;
|
|
533
|
+
// First work out expected inner tag value
|
|
534
|
+
if (flags & ASN1_TFLG_IMPTAG) {
|
|
535
|
+
sktag = tt->tag;
|
|
536
|
+
skaclass = aclass;
|
|
537
|
+
} else {
|
|
538
|
+
skaclass = V_ASN1_UNIVERSAL;
|
|
539
|
+
if (flags & ASN1_TFLG_SET_OF) {
|
|
540
|
+
sktag = V_ASN1_SET;
|
|
541
|
+
} else {
|
|
542
|
+
sktag = V_ASN1_SEQUENCE;
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
// Get the tag
|
|
546
|
+
ret =
|
|
547
|
+
asn1_check_tlen(&len, NULL, NULL, NULL, &p, len, sktag, skaclass, opt);
|
|
548
|
+
if (!ret) {
|
|
549
|
+
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
|
|
550
|
+
return 0;
|
|
551
|
+
} else if (ret == -1) {
|
|
552
|
+
return -1;
|
|
553
|
+
}
|
|
554
|
+
if (!*val) {
|
|
555
|
+
*val = (ASN1_VALUE *)sk_ASN1_VALUE_new_null();
|
|
556
|
+
} else {
|
|
557
|
+
// We've got a valid STACK: free up any items present
|
|
558
|
+
STACK_OF(ASN1_VALUE) *sktmp = (STACK_OF(ASN1_VALUE) *)*val;
|
|
559
|
+
ASN1_VALUE *vtmp;
|
|
560
|
+
while (sk_ASN1_VALUE_num(sktmp) > 0) {
|
|
561
|
+
vtmp = sk_ASN1_VALUE_pop(sktmp);
|
|
562
|
+
ASN1_item_ex_free(&vtmp, ASN1_ITEM_ptr(tt->item));
|
|
563
|
+
}
|
|
564
|
+
}
|
|
586
565
|
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
566
|
+
if (!*val) {
|
|
567
|
+
OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
|
|
568
|
+
goto err;
|
|
569
|
+
}
|
|
591
570
|
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
}
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
571
|
+
// Read as many items as we can
|
|
572
|
+
while (len > 0) {
|
|
573
|
+
ASN1_VALUE *skfield;
|
|
574
|
+
const unsigned char *q = p;
|
|
575
|
+
skfield = NULL;
|
|
576
|
+
if (!asn1_item_ex_d2i(&skfield, &p, len, ASN1_ITEM_ptr(tt->item), -1, 0,
|
|
577
|
+
0, depth)) {
|
|
578
|
+
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
|
|
579
|
+
goto err;
|
|
580
|
+
}
|
|
581
|
+
len -= p - q;
|
|
582
|
+
if (!sk_ASN1_VALUE_push((STACK_OF(ASN1_VALUE) *)*val, skfield)) {
|
|
583
|
+
ASN1_item_ex_free(&skfield, ASN1_ITEM_ptr(tt->item));
|
|
584
|
+
OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
|
|
585
|
+
goto err;
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
} else if (flags & ASN1_TFLG_IMPTAG) {
|
|
589
|
+
// IMPLICIT tagging
|
|
590
|
+
ret = asn1_item_ex_d2i(val, &p, len, ASN1_ITEM_ptr(tt->item), tt->tag,
|
|
591
|
+
aclass, opt, depth);
|
|
592
|
+
if (!ret) {
|
|
593
|
+
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
|
|
594
|
+
goto err;
|
|
595
|
+
} else if (ret == -1) {
|
|
596
|
+
return -1;
|
|
597
|
+
}
|
|
598
|
+
} else {
|
|
599
|
+
// Nothing special
|
|
600
|
+
ret = asn1_item_ex_d2i(val, &p, len, ASN1_ITEM_ptr(tt->item), -1,
|
|
601
|
+
tt->flags & ASN1_TFLG_COMBINE, opt, depth);
|
|
602
|
+
if (!ret) {
|
|
603
|
+
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
|
|
604
|
+
goto err;
|
|
605
|
+
} else if (ret == -1) {
|
|
606
|
+
return -1;
|
|
628
607
|
}
|
|
608
|
+
}
|
|
629
609
|
|
|
630
|
-
|
|
631
|
-
|
|
610
|
+
*in = p;
|
|
611
|
+
return 1;
|
|
632
612
|
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
613
|
+
err:
|
|
614
|
+
ASN1_template_free(val, tt);
|
|
615
|
+
return 0;
|
|
636
616
|
}
|
|
637
617
|
|
|
638
|
-
static int asn1_d2i_ex_primitive(ASN1_VALUE **pval,
|
|
639
|
-
const
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
return 0;
|
|
666
|
-
}
|
|
667
|
-
if (opt) {
|
|
668
|
-
OPENSSL_PUT_ERROR(ASN1, ASN1_R_ILLEGAL_OPTIONAL_ANY);
|
|
669
|
-
return 0;
|
|
670
|
-
}
|
|
671
|
-
p = *in;
|
|
672
|
-
ret = asn1_check_tlen(NULL, &utype, &oclass, NULL,
|
|
673
|
-
&p, inlen, -1, 0, 0);
|
|
674
|
-
if (!ret) {
|
|
675
|
-
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
|
|
676
|
-
return 0;
|
|
677
|
-
}
|
|
678
|
-
if (oclass != V_ASN1_UNIVERSAL)
|
|
679
|
-
utype = V_ASN1_OTHER;
|
|
618
|
+
static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, const unsigned char **in,
|
|
619
|
+
long inlen, const ASN1_ITEM *it, int tag,
|
|
620
|
+
int aclass, char opt) {
|
|
621
|
+
int ret = 0, utype;
|
|
622
|
+
long plen;
|
|
623
|
+
char cst;
|
|
624
|
+
const unsigned char *p;
|
|
625
|
+
const unsigned char *cont = NULL;
|
|
626
|
+
long len;
|
|
627
|
+
if (!pval) {
|
|
628
|
+
OPENSSL_PUT_ERROR(ASN1, ASN1_R_ILLEGAL_NULL);
|
|
629
|
+
return 0; // Should never happen
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
if (it->itype == ASN1_ITYPE_MSTRING) {
|
|
633
|
+
utype = tag;
|
|
634
|
+
tag = -1;
|
|
635
|
+
} else {
|
|
636
|
+
utype = it->utype;
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
if (utype == V_ASN1_ANY) {
|
|
640
|
+
// If type is ANY need to figure out type from tag
|
|
641
|
+
unsigned char oclass;
|
|
642
|
+
if (tag >= 0) {
|
|
643
|
+
OPENSSL_PUT_ERROR(ASN1, ASN1_R_ILLEGAL_TAGGED_ANY);
|
|
644
|
+
return 0;
|
|
680
645
|
}
|
|
681
|
-
if (
|
|
682
|
-
|
|
683
|
-
|
|
646
|
+
if (opt) {
|
|
647
|
+
OPENSSL_PUT_ERROR(ASN1, ASN1_R_ILLEGAL_OPTIONAL_ANY);
|
|
648
|
+
return 0;
|
|
684
649
|
}
|
|
685
650
|
p = *in;
|
|
686
|
-
|
|
687
|
-
ret = asn1_check_tlen(&plen, NULL, NULL, &cst,
|
|
688
|
-
&p, inlen, tag, aclass, opt);
|
|
651
|
+
ret = asn1_check_tlen(NULL, &utype, &oclass, NULL, &p, inlen, -1, 0, 0);
|
|
689
652
|
if (!ret) {
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
}
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
653
|
+
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
|
|
654
|
+
return 0;
|
|
655
|
+
}
|
|
656
|
+
if (oclass != V_ASN1_UNIVERSAL) {
|
|
657
|
+
utype = V_ASN1_OTHER;
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
if (tag == -1) {
|
|
661
|
+
tag = utype;
|
|
662
|
+
aclass = V_ASN1_UNIVERSAL;
|
|
663
|
+
}
|
|
664
|
+
p = *in;
|
|
665
|
+
// Check header
|
|
666
|
+
ret = asn1_check_tlen(&plen, NULL, NULL, &cst, &p, inlen, tag, aclass, opt);
|
|
667
|
+
if (!ret) {
|
|
668
|
+
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
|
|
669
|
+
return 0;
|
|
670
|
+
} else if (ret == -1) {
|
|
671
|
+
return -1;
|
|
672
|
+
}
|
|
673
|
+
ret = 0;
|
|
674
|
+
// SEQUENCE, SET and "OTHER" are left in encoded form
|
|
675
|
+
if ((utype == V_ASN1_SEQUENCE) || (utype == V_ASN1_SET) ||
|
|
676
|
+
(utype == V_ASN1_OTHER)) {
|
|
677
|
+
// SEQUENCE and SET must be constructed
|
|
678
|
+
if (utype != V_ASN1_OTHER && !cst) {
|
|
679
|
+
OPENSSL_PUT_ERROR(ASN1, ASN1_R_TYPE_NOT_CONSTRUCTED);
|
|
680
|
+
return 0;
|
|
717
681
|
}
|
|
718
682
|
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
683
|
+
cont = *in;
|
|
684
|
+
len = p - cont + plen;
|
|
685
|
+
p += plen;
|
|
686
|
+
} else if (cst) {
|
|
687
|
+
// This parser historically supported BER constructed strings. We no
|
|
688
|
+
// longer do and will gradually tighten this parser into a DER
|
|
689
|
+
// parser. BER types should use |CBS_asn1_ber_to_der|.
|
|
690
|
+
OPENSSL_PUT_ERROR(ASN1, ASN1_R_TYPE_NOT_PRIMITIVE);
|
|
691
|
+
return 0;
|
|
692
|
+
} else {
|
|
693
|
+
cont = p;
|
|
694
|
+
len = plen;
|
|
695
|
+
p += plen;
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
// We now have content length and type: translate into a structure
|
|
699
|
+
if (!asn1_ex_c2i(pval, cont, len, utype, it)) {
|
|
700
|
+
goto err;
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
*in = p;
|
|
704
|
+
ret = 1;
|
|
705
|
+
err:
|
|
706
|
+
return ret;
|
|
727
707
|
}
|
|
728
708
|
|
|
729
|
-
|
|
709
|
+
// Translate ASN1 content octets into a structure
|
|
730
710
|
|
|
731
711
|
static int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,
|
|
732
|
-
int utype, const ASN1_ITEM *it)
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
if (
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
if (utype != typ->type)
|
|
755
|
-
ASN1_TYPE_set(typ, utype, NULL);
|
|
756
|
-
opval = pval;
|
|
757
|
-
pval = &typ->value.asn1_value;
|
|
712
|
+
int utype, const ASN1_ITEM *it) {
|
|
713
|
+
ASN1_VALUE **opval = NULL;
|
|
714
|
+
ASN1_STRING *stmp;
|
|
715
|
+
ASN1_TYPE *typ = NULL;
|
|
716
|
+
int ret = 0;
|
|
717
|
+
ASN1_INTEGER **tint;
|
|
718
|
+
|
|
719
|
+
// Historically, |it->funcs| for primitive types contained an
|
|
720
|
+
// |ASN1_PRIMITIVE_FUNCS| table of callbacks.
|
|
721
|
+
assert(it->funcs == NULL);
|
|
722
|
+
|
|
723
|
+
// If ANY type clear type and set pointer to internal value
|
|
724
|
+
if (it->utype == V_ASN1_ANY) {
|
|
725
|
+
if (!*pval) {
|
|
726
|
+
typ = ASN1_TYPE_new();
|
|
727
|
+
if (typ == NULL) {
|
|
728
|
+
goto err;
|
|
729
|
+
}
|
|
730
|
+
*pval = (ASN1_VALUE *)typ;
|
|
731
|
+
} else {
|
|
732
|
+
typ = (ASN1_TYPE *)*pval;
|
|
758
733
|
}
|
|
759
|
-
|
|
734
|
+
|
|
735
|
+
if (utype != typ->type) {
|
|
736
|
+
ASN1_TYPE_set(typ, utype, NULL);
|
|
737
|
+
}
|
|
738
|
+
opval = pval;
|
|
739
|
+
pval = &typ->value.asn1_value;
|
|
740
|
+
}
|
|
741
|
+
switch (utype) {
|
|
760
742
|
case V_ASN1_OBJECT:
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
743
|
+
if (!c2i_ASN1_OBJECT((ASN1_OBJECT **)pval, &cont, len)) {
|
|
744
|
+
goto err;
|
|
745
|
+
}
|
|
746
|
+
break;
|
|
764
747
|
|
|
765
748
|
case V_ASN1_NULL:
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
749
|
+
if (len) {
|
|
750
|
+
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NULL_IS_WRONG_LENGTH);
|
|
751
|
+
goto err;
|
|
752
|
+
}
|
|
753
|
+
*pval = (ASN1_VALUE *)1;
|
|
754
|
+
break;
|
|
772
755
|
|
|
773
756
|
case V_ASN1_BOOLEAN:
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
757
|
+
if (len != 1) {
|
|
758
|
+
OPENSSL_PUT_ERROR(ASN1, ASN1_R_BOOLEAN_IS_WRONG_LENGTH);
|
|
759
|
+
goto err;
|
|
760
|
+
} else {
|
|
761
|
+
ASN1_BOOLEAN *tbool;
|
|
762
|
+
tbool = (ASN1_BOOLEAN *)pval;
|
|
763
|
+
*tbool = *cont;
|
|
764
|
+
}
|
|
765
|
+
break;
|
|
783
766
|
|
|
784
767
|
case V_ASN1_BIT_STRING:
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
768
|
+
if (!c2i_ASN1_BIT_STRING((ASN1_BIT_STRING **)pval, &cont, len)) {
|
|
769
|
+
goto err;
|
|
770
|
+
}
|
|
771
|
+
break;
|
|
788
772
|
|
|
789
773
|
case V_ASN1_INTEGER:
|
|
790
774
|
case V_ASN1_ENUMERATED:
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
775
|
+
tint = (ASN1_INTEGER **)pval;
|
|
776
|
+
if (!c2i_ASN1_INTEGER(tint, &cont, len)) {
|
|
777
|
+
goto err;
|
|
778
|
+
}
|
|
779
|
+
// Fixup type to match the expected form
|
|
780
|
+
(*tint)->type = utype | ((*tint)->type & V_ASN1_NEG);
|
|
781
|
+
break;
|
|
797
782
|
|
|
798
783
|
case V_ASN1_OCTET_STRING:
|
|
799
784
|
case V_ASN1_NUMERICSTRING:
|
|
@@ -813,92 +798,111 @@ static int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,
|
|
|
813
798
|
case V_ASN1_SET:
|
|
814
799
|
case V_ASN1_SEQUENCE:
|
|
815
800
|
default:
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
801
|
+
if (utype == V_ASN1_BMPSTRING && (len & 1)) {
|
|
802
|
+
OPENSSL_PUT_ERROR(ASN1, ASN1_R_BMPSTRING_IS_WRONG_LENGTH);
|
|
803
|
+
goto err;
|
|
804
|
+
}
|
|
805
|
+
if (utype == V_ASN1_UNIVERSALSTRING && (len & 3)) {
|
|
806
|
+
OPENSSL_PUT_ERROR(ASN1, ASN1_R_UNIVERSALSTRING_IS_WRONG_LENGTH);
|
|
807
|
+
goto err;
|
|
808
|
+
}
|
|
809
|
+
if (utype == V_ASN1_UTCTIME) {
|
|
810
|
+
CBS cbs;
|
|
811
|
+
CBS_init(&cbs, cont, (size_t)len);
|
|
812
|
+
if (!CBS_parse_utc_time(&cbs, NULL, /*allow_timezone_offset=*/1)) {
|
|
813
|
+
OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_TIME_FORMAT);
|
|
814
|
+
goto err;
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
if (utype == V_ASN1_GENERALIZEDTIME) {
|
|
818
|
+
CBS cbs;
|
|
819
|
+
CBS_init(&cbs, cont, (size_t)len);
|
|
820
|
+
if (!CBS_parse_generalized_time(&cbs, NULL,
|
|
821
|
+
/*allow_timezone_offset=*/0)) {
|
|
822
|
+
OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_TIME_FORMAT);
|
|
823
|
+
goto err;
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
// All based on ASN1_STRING and handled the same
|
|
827
|
+
if (!*pval) {
|
|
828
|
+
stmp = ASN1_STRING_type_new(utype);
|
|
829
|
+
if (!stmp) {
|
|
830
|
+
OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
|
|
831
|
+
goto err;
|
|
832
|
+
}
|
|
833
|
+
*pval = (ASN1_VALUE *)stmp;
|
|
834
|
+
} else {
|
|
835
|
+
stmp = (ASN1_STRING *)*pval;
|
|
836
|
+
stmp->type = utype;
|
|
837
|
+
}
|
|
838
|
+
if (!ASN1_STRING_set(stmp, cont, len)) {
|
|
839
|
+
OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
|
|
840
|
+
ASN1_STRING_free(stmp);
|
|
841
|
+
*pval = NULL;
|
|
842
|
+
goto err;
|
|
843
|
+
}
|
|
844
|
+
break;
|
|
845
|
+
}
|
|
846
|
+
// If ASN1_ANY and NULL type fix up value
|
|
847
|
+
if (typ && (utype == V_ASN1_NULL)) {
|
|
848
|
+
typ->value.ptr = NULL;
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
ret = 1;
|
|
852
|
+
err:
|
|
853
|
+
if (!ret) {
|
|
854
|
+
ASN1_TYPE_free(typ);
|
|
855
|
+
if (opval) {
|
|
856
|
+
*opval = NULL;
|
|
854
857
|
}
|
|
855
|
-
|
|
858
|
+
}
|
|
859
|
+
return ret;
|
|
856
860
|
}
|
|
857
861
|
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
* checks the expected tag.
|
|
861
|
-
*/
|
|
862
|
+
// Check an ASN1 tag and length: a bit like ASN1_get_object but it
|
|
863
|
+
// checks the expected tag.
|
|
862
864
|
|
|
863
865
|
static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass,
|
|
864
866
|
char *cst, const unsigned char **in, long len,
|
|
865
|
-
int exptag, int expclass, char opt)
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
if (exptag
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
OPENSSL_PUT_ERROR(ASN1, ASN1_R_WRONG_TAG);
|
|
886
|
-
return 0;
|
|
887
|
-
}
|
|
867
|
+
int exptag, int expclass, char opt) {
|
|
868
|
+
int i;
|
|
869
|
+
int ptag, pclass;
|
|
870
|
+
long plen;
|
|
871
|
+
const unsigned char *p;
|
|
872
|
+
p = *in;
|
|
873
|
+
|
|
874
|
+
i = ASN1_get_object(&p, &plen, &ptag, &pclass, len);
|
|
875
|
+
if (i & 0x80) {
|
|
876
|
+
OPENSSL_PUT_ERROR(ASN1, ASN1_R_BAD_OBJECT_HEADER);
|
|
877
|
+
return 0;
|
|
878
|
+
}
|
|
879
|
+
if (exptag >= 0) {
|
|
880
|
+
if ((exptag != ptag) || (expclass != pclass)) {
|
|
881
|
+
// If type is OPTIONAL, not an error: indicate missing type.
|
|
882
|
+
if (opt) {
|
|
883
|
+
return -1;
|
|
884
|
+
}
|
|
885
|
+
OPENSSL_PUT_ERROR(ASN1, ASN1_R_WRONG_TAG);
|
|
886
|
+
return 0;
|
|
888
887
|
}
|
|
888
|
+
}
|
|
889
889
|
|
|
890
|
-
|
|
891
|
-
|
|
890
|
+
if (cst) {
|
|
891
|
+
*cst = i & V_ASN1_CONSTRUCTED;
|
|
892
|
+
}
|
|
892
893
|
|
|
893
|
-
|
|
894
|
-
|
|
894
|
+
if (olen) {
|
|
895
|
+
*olen = plen;
|
|
896
|
+
}
|
|
895
897
|
|
|
896
|
-
|
|
897
|
-
|
|
898
|
+
if (oclass) {
|
|
899
|
+
*oclass = pclass;
|
|
900
|
+
}
|
|
898
901
|
|
|
899
|
-
|
|
900
|
-
|
|
902
|
+
if (otag) {
|
|
903
|
+
*otag = ptag;
|
|
904
|
+
}
|
|
901
905
|
|
|
902
|
-
|
|
903
|
-
|
|
906
|
+
*in = p;
|
|
907
|
+
return 1;
|
|
904
908
|
}
|