@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
|
@@ -80,603 +80,586 @@ static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out,
|
|
|
80
80
|
static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
|
|
81
81
|
const ASN1_TEMPLATE *tt, int tag, int aclass);
|
|
82
82
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
if (
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
if (!buf) {
|
|
97
|
-
OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
|
|
98
|
-
return -1;
|
|
99
|
-
}
|
|
100
|
-
p = buf;
|
|
101
|
-
int len2 = ASN1_item_ex_i2d(&val, &p, it, /*tag=*/-1, /*aclass=*/0);
|
|
102
|
-
if (len2 <= 0) {
|
|
103
|
-
return len2;
|
|
104
|
-
}
|
|
105
|
-
assert(len == len2);
|
|
106
|
-
*out = buf;
|
|
107
|
-
return len;
|
|
83
|
+
// Top level i2d equivalents
|
|
84
|
+
|
|
85
|
+
int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it) {
|
|
86
|
+
if (out && !*out) {
|
|
87
|
+
unsigned char *p, *buf;
|
|
88
|
+
int len = ASN1_item_ex_i2d(&val, NULL, it, /*tag=*/-1, /*aclass=*/0);
|
|
89
|
+
if (len <= 0) {
|
|
90
|
+
return len;
|
|
91
|
+
}
|
|
92
|
+
buf = OPENSSL_malloc(len);
|
|
93
|
+
if (!buf) {
|
|
94
|
+
OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
|
|
95
|
+
return -1;
|
|
108
96
|
}
|
|
97
|
+
p = buf;
|
|
98
|
+
int len2 = ASN1_item_ex_i2d(&val, &p, it, /*tag=*/-1, /*aclass=*/0);
|
|
99
|
+
if (len2 <= 0) {
|
|
100
|
+
return len2;
|
|
101
|
+
}
|
|
102
|
+
assert(len == len2);
|
|
103
|
+
*out = buf;
|
|
104
|
+
return len;
|
|
105
|
+
}
|
|
109
106
|
|
|
110
|
-
|
|
107
|
+
return ASN1_item_ex_i2d(&val, out, it, /*tag=*/-1, /*aclass=*/0);
|
|
111
108
|
}
|
|
112
109
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
* performs the normal item handling: it can be used in external types.
|
|
116
|
-
*/
|
|
110
|
+
// Encode an item, taking care of IMPLICIT tagging (if any). This function
|
|
111
|
+
// performs the normal item handling: it can be used in external types.
|
|
117
112
|
|
|
118
113
|
int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
|
|
119
|
-
const ASN1_ITEM *it, int tag, int aclass)
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
return ret;
|
|
114
|
+
const ASN1_ITEM *it, int tag, int aclass) {
|
|
115
|
+
int ret = asn1_item_ex_i2d_opt(pval, out, it, tag, aclass, /*optional=*/0);
|
|
116
|
+
assert(ret != 0);
|
|
117
|
+
return ret;
|
|
124
118
|
}
|
|
125
119
|
|
|
126
|
-
|
|
127
|
-
|
|
120
|
+
// asn1_item_ex_i2d_opt behaves like |ASN1_item_ex_i2d| but, if |optional| is
|
|
121
|
+
// non-zero and |*pval| is omitted, it returns zero and writes no bytes.
|
|
128
122
|
int asn1_item_ex_i2d_opt(ASN1_VALUE **pval, unsigned char **out,
|
|
129
123
|
const ASN1_ITEM *it, int tag, int aclass,
|
|
130
|
-
int optional)
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
if (
|
|
144
|
-
|
|
145
|
-
return 0;
|
|
146
|
-
}
|
|
147
|
-
OPENSSL_PUT_ERROR(ASN1, ASN1_R_MISSING_VALUE);
|
|
148
|
-
return -1;
|
|
124
|
+
int optional) {
|
|
125
|
+
const ASN1_TEMPLATE *tt = NULL;
|
|
126
|
+
int i, seqcontlen, seqlen;
|
|
127
|
+
|
|
128
|
+
// Historically, |aclass| was repurposed to pass additional flags into the
|
|
129
|
+
// encoding process.
|
|
130
|
+
assert((aclass & ASN1_TFLG_TAG_CLASS) == aclass);
|
|
131
|
+
// If not overridding the tag, |aclass| is ignored and should be zero.
|
|
132
|
+
assert(tag != -1 || aclass == 0);
|
|
133
|
+
|
|
134
|
+
// All fields are pointers, except for boolean |ASN1_ITYPE_PRIMITIVE|s.
|
|
135
|
+
// Optional primitives are handled later.
|
|
136
|
+
if ((it->itype != ASN1_ITYPE_PRIMITIVE) && !*pval) {
|
|
137
|
+
if (optional) {
|
|
138
|
+
return 0;
|
|
149
139
|
}
|
|
140
|
+
OPENSSL_PUT_ERROR(ASN1, ASN1_R_MISSING_VALUE);
|
|
141
|
+
return -1;
|
|
142
|
+
}
|
|
150
143
|
|
|
151
|
-
|
|
152
|
-
|
|
144
|
+
switch (it->itype) {
|
|
153
145
|
case ASN1_ITYPE_PRIMITIVE:
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
}
|
|
159
|
-
return asn1_template_ex_i2d(pval, out, it->templates, tag, aclass);
|
|
146
|
+
if (it->templates) {
|
|
147
|
+
if (it->templates->flags & ASN1_TFLG_OPTIONAL) {
|
|
148
|
+
OPENSSL_PUT_ERROR(ASN1, ASN1_R_BAD_TEMPLATE);
|
|
149
|
+
return -1;
|
|
160
150
|
}
|
|
161
|
-
return
|
|
151
|
+
return asn1_template_ex_i2d(pval, out, it->templates, tag, aclass);
|
|
152
|
+
}
|
|
153
|
+
return asn1_i2d_ex_primitive(pval, out, it, tag, aclass, optional);
|
|
162
154
|
|
|
163
155
|
case ASN1_ITYPE_MSTRING:
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
}
|
|
172
|
-
return asn1_i2d_ex_primitive(pval, out, it, -1, 0, optional);
|
|
156
|
+
// It never makes sense for multi-strings to have implicit tagging, so
|
|
157
|
+
// if tag != -1, then this looks like an error in the template.
|
|
158
|
+
if (tag != -1) {
|
|
159
|
+
OPENSSL_PUT_ERROR(ASN1, ASN1_R_BAD_TEMPLATE);
|
|
160
|
+
return -1;
|
|
161
|
+
}
|
|
162
|
+
return asn1_i2d_ex_primitive(pval, out, it, -1, 0, optional);
|
|
173
163
|
|
|
174
164
|
case ASN1_ITYPE_CHOICE: {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
ASN1_VALUE **pchval = asn1_get_field_ptr(pval, chtt);
|
|
194
|
-
return asn1_template_ex_i2d(pchval, out, chtt, -1, 0);
|
|
165
|
+
// It never makes sense for CHOICE types to have implicit tagging, so if
|
|
166
|
+
// tag != -1, then this looks like an error in the template.
|
|
167
|
+
if (tag != -1) {
|
|
168
|
+
OPENSSL_PUT_ERROR(ASN1, ASN1_R_BAD_TEMPLATE);
|
|
169
|
+
return -1;
|
|
170
|
+
}
|
|
171
|
+
i = asn1_get_choice_selector(pval, it);
|
|
172
|
+
if (i < 0 || i >= it->tcount) {
|
|
173
|
+
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NO_MATCHING_CHOICE_TYPE);
|
|
174
|
+
return -1;
|
|
175
|
+
}
|
|
176
|
+
const ASN1_TEMPLATE *chtt = it->templates + i;
|
|
177
|
+
if (chtt->flags & ASN1_TFLG_OPTIONAL) {
|
|
178
|
+
OPENSSL_PUT_ERROR(ASN1, ASN1_R_BAD_TEMPLATE);
|
|
179
|
+
return -1;
|
|
180
|
+
}
|
|
181
|
+
ASN1_VALUE **pchval = asn1_get_field_ptr(pval, chtt);
|
|
182
|
+
return asn1_template_ex_i2d(pchval, out, chtt, -1, 0);
|
|
195
183
|
}
|
|
196
184
|
|
|
197
185
|
case ASN1_ITYPE_EXTERN: {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
186
|
+
// If new style i2d it does all the work
|
|
187
|
+
const ASN1_EXTERN_FUNCS *ef = it->funcs;
|
|
188
|
+
int ret = ef->asn1_ex_i2d(pval, out, it, tag, aclass);
|
|
189
|
+
if (ret == 0) {
|
|
190
|
+
// |asn1_ex_i2d| should never return zero. We have already checked
|
|
191
|
+
// for optional values generically, and |ASN1_ITYPE_EXTERN| fields
|
|
192
|
+
// must be pointers.
|
|
193
|
+
OPENSSL_PUT_ERROR(ASN1, ERR_R_INTERNAL_ERROR);
|
|
194
|
+
return -1;
|
|
195
|
+
}
|
|
196
|
+
return ret;
|
|
209
197
|
}
|
|
210
198
|
|
|
211
199
|
case ASN1_ITYPE_SEQUENCE: {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
200
|
+
i = asn1_enc_restore(&seqcontlen, out, pval, it);
|
|
201
|
+
// An error occurred
|
|
202
|
+
if (i < 0) {
|
|
203
|
+
return -1;
|
|
204
|
+
}
|
|
205
|
+
// We have a valid cached encoding...
|
|
206
|
+
if (i > 0) {
|
|
207
|
+
return seqcontlen;
|
|
208
|
+
}
|
|
209
|
+
// Otherwise carry on
|
|
210
|
+
seqcontlen = 0;
|
|
211
|
+
// If no IMPLICIT tagging set to SEQUENCE, UNIVERSAL
|
|
212
|
+
if (tag == -1) {
|
|
213
|
+
tag = V_ASN1_SEQUENCE;
|
|
214
|
+
aclass = V_ASN1_UNIVERSAL;
|
|
215
|
+
}
|
|
216
|
+
// First work out sequence content length
|
|
217
|
+
for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) {
|
|
218
|
+
const ASN1_TEMPLATE *seqtt;
|
|
219
|
+
ASN1_VALUE **pseqval;
|
|
220
|
+
int tmplen;
|
|
221
|
+
seqtt = asn1_do_adb(pval, tt, 1);
|
|
222
|
+
if (!seqtt) {
|
|
223
|
+
return -1;
|
|
225
224
|
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
int tmplen;
|
|
231
|
-
seqtt = asn1_do_adb(pval, tt, 1);
|
|
232
|
-
if (!seqtt)
|
|
233
|
-
return -1;
|
|
234
|
-
pseqval = asn1_get_field_ptr(pval, seqtt);
|
|
235
|
-
tmplen = asn1_template_ex_i2d(pseqval, NULL, seqtt, -1, 0);
|
|
236
|
-
if (tmplen == -1 || (tmplen > INT_MAX - seqcontlen))
|
|
237
|
-
return -1;
|
|
238
|
-
seqcontlen += tmplen;
|
|
225
|
+
pseqval = asn1_get_field_ptr(pval, seqtt);
|
|
226
|
+
tmplen = asn1_template_ex_i2d(pseqval, NULL, seqtt, -1, 0);
|
|
227
|
+
if (tmplen == -1 || (tmplen > INT_MAX - seqcontlen)) {
|
|
228
|
+
return -1;
|
|
239
229
|
}
|
|
230
|
+
seqcontlen += tmplen;
|
|
231
|
+
}
|
|
240
232
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
return seqlen;
|
|
244
|
-
/* Output SEQUENCE header */
|
|
245
|
-
ASN1_put_object(out, /*constructed=*/1, seqcontlen, tag, aclass);
|
|
246
|
-
for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) {
|
|
247
|
-
const ASN1_TEMPLATE *seqtt;
|
|
248
|
-
ASN1_VALUE **pseqval;
|
|
249
|
-
seqtt = asn1_do_adb(pval, tt, 1);
|
|
250
|
-
if (!seqtt)
|
|
251
|
-
return -1;
|
|
252
|
-
pseqval = asn1_get_field_ptr(pval, seqtt);
|
|
253
|
-
if (asn1_template_ex_i2d(pseqval, out, seqtt, -1, 0) < 0) {
|
|
254
|
-
return -1;
|
|
255
|
-
}
|
|
256
|
-
}
|
|
233
|
+
seqlen = ASN1_object_size(/*constructed=*/1, seqcontlen, tag);
|
|
234
|
+
if (!out || seqlen == -1) {
|
|
257
235
|
return seqlen;
|
|
236
|
+
}
|
|
237
|
+
// Output SEQUENCE header
|
|
238
|
+
ASN1_put_object(out, /*constructed=*/1, seqcontlen, tag, aclass);
|
|
239
|
+
for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) {
|
|
240
|
+
const ASN1_TEMPLATE *seqtt;
|
|
241
|
+
ASN1_VALUE **pseqval;
|
|
242
|
+
seqtt = asn1_do_adb(pval, tt, 1);
|
|
243
|
+
if (!seqtt) {
|
|
244
|
+
return -1;
|
|
245
|
+
}
|
|
246
|
+
pseqval = asn1_get_field_ptr(pval, seqtt);
|
|
247
|
+
if (asn1_template_ex_i2d(pseqval, out, seqtt, -1, 0) < 0) {
|
|
248
|
+
return -1;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
return seqlen;
|
|
258
252
|
}
|
|
259
253
|
|
|
260
254
|
default:
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
255
|
+
OPENSSL_PUT_ERROR(ASN1, ASN1_R_BAD_TEMPLATE);
|
|
256
|
+
return -1;
|
|
257
|
+
}
|
|
264
258
|
}
|
|
265
259
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
260
|
+
// asn1_template_ex_i2d behaves like |asn1_item_ex_i2d_opt| but uses an
|
|
261
|
+
// |ASN1_TEMPLATE| instead of an |ASN1_ITEM|. An |ASN1_TEMPLATE| wraps an
|
|
262
|
+
// |ASN1_ITEM| with modifiers such as tagging, SEQUENCE or SET, etc. Instead of
|
|
263
|
+
// taking an |optional| parameter, it uses the |ASN1_TFLG_OPTIONAL| flag.
|
|
270
264
|
static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
|
|
271
|
-
const ASN1_TEMPLATE *tt, int tag, int iclass)
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
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
|
-
|
|
265
|
+
const ASN1_TEMPLATE *tt, int tag, int iclass) {
|
|
266
|
+
int i, ret, flags, ttag, tclass;
|
|
267
|
+
size_t j;
|
|
268
|
+
flags = tt->flags;
|
|
269
|
+
|
|
270
|
+
// Historically, |iclass| was repurposed to pass additional flags into the
|
|
271
|
+
// encoding process.
|
|
272
|
+
assert((iclass & ASN1_TFLG_TAG_CLASS) == iclass);
|
|
273
|
+
// If not overridding the tag, |iclass| is ignored and should be zero.
|
|
274
|
+
assert(tag != -1 || iclass == 0);
|
|
275
|
+
|
|
276
|
+
// Work out tag and class to use: tagging may come either from the
|
|
277
|
+
// template or the arguments, not both because this would create
|
|
278
|
+
// ambiguity.
|
|
279
|
+
if (flags & ASN1_TFLG_TAG_MASK) {
|
|
280
|
+
// Error if argument and template tagging
|
|
281
|
+
if (tag != -1) {
|
|
282
|
+
OPENSSL_PUT_ERROR(ASN1, ASN1_R_BAD_TEMPLATE);
|
|
283
|
+
return -1;
|
|
284
|
+
}
|
|
285
|
+
// Get tagging from template
|
|
286
|
+
ttag = tt->tag;
|
|
287
|
+
tclass = flags & ASN1_TFLG_TAG_CLASS;
|
|
288
|
+
} else if (tag != -1) {
|
|
289
|
+
// No template tagging, get from arguments
|
|
290
|
+
ttag = tag;
|
|
291
|
+
tclass = iclass & ASN1_TFLG_TAG_CLASS;
|
|
292
|
+
} else {
|
|
293
|
+
ttag = -1;
|
|
294
|
+
tclass = 0;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
const int optional = (flags & ASN1_TFLG_OPTIONAL) != 0;
|
|
298
|
+
|
|
299
|
+
// At this point 'ttag' contains the outer tag to use, and 'tclass' is the
|
|
300
|
+
// class.
|
|
301
|
+
|
|
302
|
+
if (flags & ASN1_TFLG_SK_MASK) {
|
|
303
|
+
// SET OF, SEQUENCE OF
|
|
304
|
+
STACK_OF(ASN1_VALUE) *sk = (STACK_OF(ASN1_VALUE) *)*pval;
|
|
305
|
+
int isset, sktag, skaclass;
|
|
306
|
+
int skcontlen, sklen;
|
|
307
|
+
ASN1_VALUE *skitem;
|
|
308
|
+
|
|
309
|
+
if (!*pval) {
|
|
310
|
+
if (optional) {
|
|
311
|
+
return 0;
|
|
312
|
+
}
|
|
313
|
+
OPENSSL_PUT_ERROR(ASN1, ASN1_R_MISSING_VALUE);
|
|
314
|
+
return -1;
|
|
304
315
|
}
|
|
305
316
|
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
/* SET OF, SEQUENCE OF */
|
|
315
|
-
STACK_OF(ASN1_VALUE) *sk = (STACK_OF(ASN1_VALUE) *)*pval;
|
|
316
|
-
int isset, sktag, skaclass;
|
|
317
|
-
int skcontlen, sklen;
|
|
318
|
-
ASN1_VALUE *skitem;
|
|
319
|
-
|
|
320
|
-
if (!*pval) {
|
|
321
|
-
if (optional) {
|
|
322
|
-
return 0;
|
|
323
|
-
}
|
|
324
|
-
OPENSSL_PUT_ERROR(ASN1, ASN1_R_MISSING_VALUE);
|
|
325
|
-
return -1;
|
|
326
|
-
}
|
|
317
|
+
if (flags & ASN1_TFLG_SET_OF) {
|
|
318
|
+
isset = 1;
|
|
319
|
+
// Historically, types with both bits set were mutated when
|
|
320
|
+
// serialized to apply the sort. We no longer support this.
|
|
321
|
+
assert((flags & ASN1_TFLG_SEQUENCE_OF) == 0);
|
|
322
|
+
} else {
|
|
323
|
+
isset = 0;
|
|
324
|
+
}
|
|
327
325
|
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
326
|
+
// Work out inner tag value: if EXPLICIT or no tagging use underlying
|
|
327
|
+
// type.
|
|
328
|
+
if ((ttag != -1) && !(flags & ASN1_TFLG_EXPTAG)) {
|
|
329
|
+
sktag = ttag;
|
|
330
|
+
skaclass = tclass;
|
|
331
|
+
} else {
|
|
332
|
+
skaclass = V_ASN1_UNIVERSAL;
|
|
333
|
+
if (isset) {
|
|
334
|
+
sktag = V_ASN1_SET;
|
|
335
|
+
} else {
|
|
336
|
+
sktag = V_ASN1_SEQUENCE;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
336
339
|
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
340
|
+
// Determine total length of items
|
|
341
|
+
skcontlen = 0;
|
|
342
|
+
for (j = 0; j < sk_ASN1_VALUE_num(sk); j++) {
|
|
343
|
+
int tmplen;
|
|
344
|
+
skitem = sk_ASN1_VALUE_value(sk, j);
|
|
345
|
+
tmplen = ASN1_item_ex_i2d(&skitem, NULL, ASN1_ITEM_ptr(tt->item), -1, 0);
|
|
346
|
+
if (tmplen == -1 || (skcontlen > INT_MAX - tmplen)) {
|
|
347
|
+
return -1;
|
|
348
|
+
}
|
|
349
|
+
skcontlen += tmplen;
|
|
350
|
+
}
|
|
351
|
+
sklen = ASN1_object_size(/*constructed=*/1, skcontlen, sktag);
|
|
352
|
+
if (sklen == -1) {
|
|
353
|
+
return -1;
|
|
354
|
+
}
|
|
355
|
+
// If EXPLICIT need length of surrounding tag
|
|
356
|
+
if (flags & ASN1_TFLG_EXPTAG) {
|
|
357
|
+
ret = ASN1_object_size(/*constructed=*/1, sklen, ttag);
|
|
358
|
+
} else {
|
|
359
|
+
ret = sklen;
|
|
360
|
+
}
|
|
351
361
|
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
for (j = 0; j < sk_ASN1_VALUE_num(sk); j++) {
|
|
355
|
-
int tmplen;
|
|
356
|
-
skitem = sk_ASN1_VALUE_value(sk, j);
|
|
357
|
-
tmplen = ASN1_item_ex_i2d(&skitem, NULL, ASN1_ITEM_ptr(tt->item),
|
|
358
|
-
-1, 0);
|
|
359
|
-
if (tmplen == -1 || (skcontlen > INT_MAX - tmplen))
|
|
360
|
-
return -1;
|
|
361
|
-
skcontlen += tmplen;
|
|
362
|
-
}
|
|
363
|
-
sklen = ASN1_object_size(/*constructed=*/1, skcontlen, sktag);
|
|
364
|
-
if (sklen == -1)
|
|
365
|
-
return -1;
|
|
366
|
-
/* If EXPLICIT need length of surrounding tag */
|
|
367
|
-
if (flags & ASN1_TFLG_EXPTAG)
|
|
368
|
-
ret = ASN1_object_size(/*constructed=*/1, sklen, ttag);
|
|
369
|
-
else
|
|
370
|
-
ret = sklen;
|
|
371
|
-
|
|
372
|
-
if (!out || ret == -1)
|
|
373
|
-
return ret;
|
|
374
|
-
|
|
375
|
-
/* Now encode this lot... */
|
|
376
|
-
/* EXPLICIT tag */
|
|
377
|
-
if (flags & ASN1_TFLG_EXPTAG)
|
|
378
|
-
ASN1_put_object(out, /*constructed=*/1, sklen, ttag, tclass);
|
|
379
|
-
/* SET or SEQUENCE and IMPLICIT tag */
|
|
380
|
-
ASN1_put_object(out, /*constructed=*/1, skcontlen, sktag, skaclass);
|
|
381
|
-
/* And the stuff itself */
|
|
382
|
-
if (!asn1_set_seq_out(sk, out, skcontlen, ASN1_ITEM_ptr(tt->item),
|
|
383
|
-
isset)) {
|
|
384
|
-
return -1;
|
|
385
|
-
}
|
|
386
|
-
return ret;
|
|
362
|
+
if (!out || ret == -1) {
|
|
363
|
+
return ret;
|
|
387
364
|
}
|
|
388
365
|
|
|
366
|
+
// Now encode this lot...
|
|
367
|
+
// EXPLICIT tag
|
|
389
368
|
if (flags & ASN1_TFLG_EXPTAG) {
|
|
390
|
-
|
|
391
|
-
/* Find length of tagged item */
|
|
392
|
-
i = asn1_item_ex_i2d_opt(pval, NULL, ASN1_ITEM_ptr(tt->item), -1, 0,
|
|
393
|
-
optional);
|
|
394
|
-
if (i <= 0)
|
|
395
|
-
return i;
|
|
396
|
-
/* Find length of EXPLICIT tag */
|
|
397
|
-
ret = ASN1_object_size(/*constructed=*/1, i, ttag);
|
|
398
|
-
if (out && ret != -1) {
|
|
399
|
-
/* Output tag and item */
|
|
400
|
-
ASN1_put_object(out, /*constructed=*/1, i, ttag, tclass);
|
|
401
|
-
if (ASN1_item_ex_i2d(pval, out, ASN1_ITEM_ptr(tt->item), -1,
|
|
402
|
-
0) < 0) {
|
|
403
|
-
return -1;
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
return ret;
|
|
369
|
+
ASN1_put_object(out, /*constructed=*/1, sklen, ttag, tclass);
|
|
407
370
|
}
|
|
371
|
+
// SET or SEQUENCE and IMPLICIT tag
|
|
372
|
+
ASN1_put_object(out, /*constructed=*/1, skcontlen, sktag, skaclass);
|
|
373
|
+
// And the stuff itself
|
|
374
|
+
if (!asn1_set_seq_out(sk, out, skcontlen, ASN1_ITEM_ptr(tt->item), isset)) {
|
|
375
|
+
return -1;
|
|
376
|
+
}
|
|
377
|
+
return ret;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
if (flags & ASN1_TFLG_EXPTAG) {
|
|
381
|
+
// EXPLICIT tagging
|
|
382
|
+
// Find length of tagged item
|
|
383
|
+
i = asn1_item_ex_i2d_opt(pval, NULL, ASN1_ITEM_ptr(tt->item), -1, 0,
|
|
384
|
+
optional);
|
|
385
|
+
if (i <= 0) {
|
|
386
|
+
return i;
|
|
387
|
+
}
|
|
388
|
+
// Find length of EXPLICIT tag
|
|
389
|
+
ret = ASN1_object_size(/*constructed=*/1, i, ttag);
|
|
390
|
+
if (out && ret != -1) {
|
|
391
|
+
// Output tag and item
|
|
392
|
+
ASN1_put_object(out, /*constructed=*/1, i, ttag, tclass);
|
|
393
|
+
if (ASN1_item_ex_i2d(pval, out, ASN1_ITEM_ptr(tt->item), -1, 0) < 0) {
|
|
394
|
+
return -1;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
return ret;
|
|
398
|
+
}
|
|
408
399
|
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
400
|
+
// Either normal or IMPLICIT tagging
|
|
401
|
+
return asn1_item_ex_i2d_opt(pval, out, ASN1_ITEM_ptr(tt->item), ttag, tclass,
|
|
402
|
+
optional);
|
|
413
403
|
}
|
|
414
404
|
|
|
415
|
-
|
|
405
|
+
// Temporary structure used to hold DER encoding of items for SET OF
|
|
416
406
|
|
|
417
407
|
typedef struct {
|
|
418
|
-
|
|
419
|
-
|
|
408
|
+
unsigned char *data;
|
|
409
|
+
int length;
|
|
420
410
|
} DER_ENC;
|
|
421
411
|
|
|
422
|
-
static int der_cmp(const void *a, const void *b)
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
412
|
+
static int der_cmp(const void *a, const void *b) {
|
|
413
|
+
const DER_ENC *d1 = a, *d2 = b;
|
|
414
|
+
int cmplen, i;
|
|
415
|
+
cmplen = (d1->length < d2->length) ? d1->length : d2->length;
|
|
416
|
+
i = OPENSSL_memcmp(d1->data, d2->data, cmplen);
|
|
417
|
+
if (i) {
|
|
418
|
+
return i;
|
|
419
|
+
}
|
|
420
|
+
return d1->length - d2->length;
|
|
431
421
|
}
|
|
432
422
|
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
423
|
+
// asn1_set_seq_out writes |sk| to |out| under the i2d output convention,
|
|
424
|
+
// excluding the tag and length. It returns one on success and zero on error.
|
|
425
|
+
// |skcontlen| must be the total encoded size. If |do_sort| is non-zero, the
|
|
426
|
+
// elements are sorted for a SET OF type. Each element of |sk| has type
|
|
427
|
+
// |item|.
|
|
438
428
|
static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out,
|
|
439
|
-
int skcontlen, const ASN1_ITEM *item, int do_sort)
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
if (ASN1_item_ex_i2d(&skitem, out, item, -1, 0) < 0) {
|
|
446
|
-
return 0;
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
return 1;
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
if (sk_ASN1_VALUE_num(sk) > ((size_t)-1) / sizeof(DER_ENC)) {
|
|
453
|
-
OPENSSL_PUT_ERROR(ASN1, ERR_R_OVERFLOW);
|
|
429
|
+
int skcontlen, const ASN1_ITEM *item, int do_sort) {
|
|
430
|
+
// No need to sort if there are fewer than two items.
|
|
431
|
+
if (!do_sort || sk_ASN1_VALUE_num(sk) < 2) {
|
|
432
|
+
for (size_t i = 0; i < sk_ASN1_VALUE_num(sk); i++) {
|
|
433
|
+
ASN1_VALUE *skitem = sk_ASN1_VALUE_value(sk, i);
|
|
434
|
+
if (ASN1_item_ex_i2d(&skitem, out, item, -1, 0) < 0) {
|
|
454
435
|
return 0;
|
|
436
|
+
}
|
|
455
437
|
}
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
438
|
+
return 1;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
if (sk_ASN1_VALUE_num(sk) > ((size_t)-1) / sizeof(DER_ENC)) {
|
|
442
|
+
OPENSSL_PUT_ERROR(ASN1, ERR_R_OVERFLOW);
|
|
443
|
+
return 0;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
int ret = 0;
|
|
447
|
+
unsigned char *const buf = OPENSSL_malloc(skcontlen);
|
|
448
|
+
DER_ENC *encoded = OPENSSL_malloc(sk_ASN1_VALUE_num(sk) * sizeof(*encoded));
|
|
449
|
+
if (encoded == NULL || buf == NULL) {
|
|
450
|
+
OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
|
|
451
|
+
goto err;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
// Encode all the elements into |buf| and populate |encoded|.
|
|
455
|
+
unsigned char *p = buf;
|
|
456
|
+
for (size_t i = 0; i < sk_ASN1_VALUE_num(sk); i++) {
|
|
457
|
+
ASN1_VALUE *skitem = sk_ASN1_VALUE_value(sk, i);
|
|
458
|
+
encoded[i].data = p;
|
|
459
|
+
encoded[i].length = ASN1_item_ex_i2d(&skitem, &p, item, -1, 0);
|
|
460
|
+
if (encoded[i].length < 0) {
|
|
461
|
+
goto err;
|
|
463
462
|
}
|
|
463
|
+
assert(p - buf <= skcontlen);
|
|
464
|
+
}
|
|
464
465
|
|
|
465
|
-
|
|
466
|
-
unsigned char *p = buf;
|
|
467
|
-
for (size_t i = 0; i < sk_ASN1_VALUE_num(sk); i++) {
|
|
468
|
-
ASN1_VALUE *skitem = sk_ASN1_VALUE_value(sk, i);
|
|
469
|
-
encoded[i].data = p;
|
|
470
|
-
encoded[i].length = ASN1_item_ex_i2d(&skitem, &p, item, -1, 0);
|
|
471
|
-
if (encoded[i].length < 0) {
|
|
472
|
-
goto err;
|
|
473
|
-
}
|
|
474
|
-
assert(p - buf <= skcontlen);
|
|
475
|
-
}
|
|
466
|
+
qsort(encoded, sk_ASN1_VALUE_num(sk), sizeof(*encoded), der_cmp);
|
|
476
467
|
|
|
477
|
-
|
|
468
|
+
// Output the elements in sorted order.
|
|
469
|
+
p = *out;
|
|
470
|
+
for (size_t i = 0; i < sk_ASN1_VALUE_num(sk); i++) {
|
|
471
|
+
OPENSSL_memcpy(p, encoded[i].data, encoded[i].length);
|
|
472
|
+
p += encoded[i].length;
|
|
473
|
+
}
|
|
474
|
+
*out = p;
|
|
478
475
|
|
|
479
|
-
|
|
480
|
-
p = *out;
|
|
481
|
-
for (size_t i = 0; i < sk_ASN1_VALUE_num(sk); i++) {
|
|
482
|
-
OPENSSL_memcpy(p, encoded[i].data, encoded[i].length);
|
|
483
|
-
p += encoded[i].length;
|
|
484
|
-
}
|
|
485
|
-
*out = p;
|
|
486
|
-
|
|
487
|
-
ret = 1;
|
|
476
|
+
ret = 1;
|
|
488
477
|
|
|
489
478
|
err:
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
479
|
+
OPENSSL_free(encoded);
|
|
480
|
+
OPENSSL_free(buf);
|
|
481
|
+
return ret;
|
|
493
482
|
}
|
|
494
483
|
|
|
495
|
-
|
|
496
|
-
|
|
484
|
+
// asn1_i2d_ex_primitive behaves like |ASN1_item_ex_i2d| but |item| must be a
|
|
485
|
+
// a PRIMITIVE or MSTRING type that is not an |ASN1_ITEM_TEMPLATE|.
|
|
497
486
|
static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out,
|
|
498
487
|
const ASN1_ITEM *it, int tag, int aclass,
|
|
499
|
-
int optional)
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
if (
|
|
509
|
-
|
|
510
|
-
return 0;
|
|
511
|
-
}
|
|
512
|
-
OPENSSL_PUT_ERROR(ASN1, ASN1_R_MISSING_VALUE);
|
|
513
|
-
return -1;
|
|
488
|
+
int optional) {
|
|
489
|
+
// Get length of content octets and maybe find out the underlying type.
|
|
490
|
+
int omit;
|
|
491
|
+
int utype = it->utype;
|
|
492
|
+
int len = asn1_ex_i2c(pval, NULL, &omit, &utype, it);
|
|
493
|
+
if (len < 0) {
|
|
494
|
+
return -1;
|
|
495
|
+
}
|
|
496
|
+
if (omit) {
|
|
497
|
+
if (optional) {
|
|
498
|
+
return 0;
|
|
514
499
|
}
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
}
|
|
533
|
-
int len2 = asn1_ex_i2c(pval, *out, &omit, &utype, it);
|
|
534
|
-
if (len2 < 0) {
|
|
535
|
-
return -1;
|
|
536
|
-
}
|
|
537
|
-
assert(len == len2);
|
|
538
|
-
assert(!omit);
|
|
539
|
-
*out += len;
|
|
540
|
-
}
|
|
541
|
-
|
|
500
|
+
OPENSSL_PUT_ERROR(ASN1, ASN1_R_MISSING_VALUE);
|
|
501
|
+
return -1;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
// If SEQUENCE, SET or OTHER then header is included in pseudo content
|
|
505
|
+
// octets so don't include tag+length. We need to check here because the
|
|
506
|
+
// call to asn1_ex_i2c() could change utype.
|
|
507
|
+
int usetag =
|
|
508
|
+
utype != V_ASN1_SEQUENCE && utype != V_ASN1_SET && utype != V_ASN1_OTHER;
|
|
509
|
+
|
|
510
|
+
// If not implicitly tagged get tag from underlying type
|
|
511
|
+
if (tag == -1) {
|
|
512
|
+
tag = utype;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
// Output tag+length followed by content octets
|
|
516
|
+
if (out) {
|
|
542
517
|
if (usetag) {
|
|
543
|
-
|
|
518
|
+
ASN1_put_object(out, /*constructed=*/0, len, tag, aclass);
|
|
544
519
|
}
|
|
545
|
-
|
|
520
|
+
int len2 = asn1_ex_i2c(pval, *out, &omit, &utype, it);
|
|
521
|
+
if (len2 < 0) {
|
|
522
|
+
return -1;
|
|
523
|
+
}
|
|
524
|
+
assert(len == len2);
|
|
525
|
+
assert(!omit);
|
|
526
|
+
*out += len;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
if (usetag) {
|
|
530
|
+
return ASN1_object_size(/*constructed=*/0, len, tag);
|
|
531
|
+
}
|
|
532
|
+
return len;
|
|
546
533
|
}
|
|
547
534
|
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
535
|
+
// asn1_ex_i2c writes the |*pval| to |cout| under the i2d output convention,
|
|
536
|
+
// excluding the tag and length. It returns the number of bytes written,
|
|
537
|
+
// possibly zero, on success or -1 on error. If |*pval| should be omitted, it
|
|
538
|
+
// returns zero and sets |*out_omit| to true.
|
|
539
|
+
//
|
|
540
|
+
// If |it| is an MSTRING or ANY type, it gets the underlying type from |*pval|,
|
|
541
|
+
// which must be an |ASN1_STRING| or |ASN1_TYPE|, respectively. It then updates
|
|
542
|
+
// |*putype| with the tag number of type used, or |V_ASN1_OTHER| if it was not a
|
|
543
|
+
// universal type. If |*putype| is set to |V_ASN1_SEQUENCE|, |V_ASN1_SET|, or
|
|
544
|
+
// |V_ASN1_OTHER|, it additionally outputs the tag and length, so the caller
|
|
545
|
+
// must not do so.
|
|
546
|
+
//
|
|
547
|
+
// Otherwise, |*putype| must contain |it->utype|.
|
|
548
|
+
//
|
|
549
|
+
// WARNING: Unlike most functions in this file, |asn1_ex_i2c| can return zero
|
|
550
|
+
// without omitting the element. ASN.1 values may have empty contents.
|
|
564
551
|
static int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *out_omit,
|
|
565
|
-
int *putype, const ASN1_ITEM *it)
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
if (
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
*out_omit = 1;
|
|
586
|
-
return 0;
|
|
587
|
-
}
|
|
552
|
+
int *putype, const ASN1_ITEM *it) {
|
|
553
|
+
ASN1_BOOLEAN *tbool = NULL;
|
|
554
|
+
ASN1_STRING *strtmp;
|
|
555
|
+
ASN1_OBJECT *otmp;
|
|
556
|
+
int utype;
|
|
557
|
+
const unsigned char *cont;
|
|
558
|
+
unsigned char c;
|
|
559
|
+
int len;
|
|
560
|
+
|
|
561
|
+
// Historically, |it->funcs| for primitive types contained an
|
|
562
|
+
// |ASN1_PRIMITIVE_FUNCS| table of callbacks.
|
|
563
|
+
assert(it->funcs == NULL);
|
|
564
|
+
|
|
565
|
+
*out_omit = 0;
|
|
566
|
+
|
|
567
|
+
// Should type be omitted?
|
|
568
|
+
if ((it->itype != ASN1_ITYPE_PRIMITIVE) || (it->utype != V_ASN1_BOOLEAN)) {
|
|
569
|
+
if (!*pval) {
|
|
570
|
+
*out_omit = 1;
|
|
571
|
+
return 0;
|
|
588
572
|
}
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
if (it->itype == ASN1_ITYPE_MSTRING) {
|
|
576
|
+
// If MSTRING type set the underlying type
|
|
577
|
+
strtmp = (ASN1_STRING *)*pval;
|
|
578
|
+
utype = strtmp->type;
|
|
579
|
+
if (utype < 0 && utype != V_ASN1_OTHER) {
|
|
580
|
+
// MSTRINGs can have type -1 when default-constructed.
|
|
581
|
+
OPENSSL_PUT_ERROR(ASN1, ASN1_R_WRONG_TYPE);
|
|
582
|
+
return -1;
|
|
583
|
+
}
|
|
584
|
+
// Negative INTEGER and ENUMERATED values use |ASN1_STRING| type values
|
|
585
|
+
// that do not match their corresponding utype values. INTEGERs cannot
|
|
586
|
+
// participate in MSTRING types, but ENUMERATEDs can.
|
|
587
|
+
//
|
|
588
|
+
// TODO(davidben): Is this a bug? Although arguably one of the MSTRING
|
|
589
|
+
// types should contain more values, rather than less. See
|
|
590
|
+
// https://crbug.com/boringssl/412. But it is not possible to fit all
|
|
591
|
+
// possible ANY values into an |ASN1_STRING|, so matching the spec here
|
|
592
|
+
// is somewhat hopeless.
|
|
593
|
+
if (utype == V_ASN1_NEG_INTEGER) {
|
|
594
|
+
utype = V_ASN1_INTEGER;
|
|
595
|
+
} else if (utype == V_ASN1_NEG_ENUMERATED) {
|
|
596
|
+
utype = V_ASN1_ENUMERATED;
|
|
597
|
+
}
|
|
598
|
+
*putype = utype;
|
|
599
|
+
} else if (it->utype == V_ASN1_ANY) {
|
|
600
|
+
// If ANY set type and pointer to value
|
|
601
|
+
ASN1_TYPE *typ;
|
|
602
|
+
typ = (ASN1_TYPE *)*pval;
|
|
603
|
+
utype = typ->type;
|
|
604
|
+
if (utype < 0 && utype != V_ASN1_OTHER) {
|
|
605
|
+
// |ASN1_TYPE|s can have type -1 when default-constructed.
|
|
606
|
+
OPENSSL_PUT_ERROR(ASN1, ASN1_R_WRONG_TYPE);
|
|
607
|
+
return -1;
|
|
608
|
+
}
|
|
609
|
+
*putype = utype;
|
|
610
|
+
pval = &typ->value.asn1_value;
|
|
611
|
+
} else {
|
|
612
|
+
utype = *putype;
|
|
613
|
+
}
|
|
589
614
|
|
|
590
|
-
|
|
591
|
-
/* If MSTRING type set the underlying type */
|
|
592
|
-
strtmp = (ASN1_STRING *)*pval;
|
|
593
|
-
utype = strtmp->type;
|
|
594
|
-
if (utype < 0 && utype != V_ASN1_OTHER) {
|
|
595
|
-
/* MSTRINGs can have type -1 when default-constructed. */
|
|
596
|
-
OPENSSL_PUT_ERROR(ASN1, ASN1_R_WRONG_TYPE);
|
|
597
|
-
return -1;
|
|
598
|
-
}
|
|
599
|
-
/* Negative INTEGER and ENUMERATED values use |ASN1_STRING| type values
|
|
600
|
-
* that do not match their corresponding utype values. INTEGERs cannot
|
|
601
|
-
* participate in MSTRING types, but ENUMERATEDs can.
|
|
602
|
-
*
|
|
603
|
-
* TODO(davidben): Is this a bug? Although arguably one of the MSTRING
|
|
604
|
-
* types should contain more values, rather than less. See
|
|
605
|
-
* https://crbug.com/boringssl/412. But it is not possible to fit all
|
|
606
|
-
* possible ANY values into an |ASN1_STRING|, so matching the spec here
|
|
607
|
-
* is somewhat hopeless. */
|
|
608
|
-
if (utype == V_ASN1_NEG_INTEGER) {
|
|
609
|
-
utype = V_ASN1_INTEGER;
|
|
610
|
-
} else if (utype == V_ASN1_NEG_ENUMERATED) {
|
|
611
|
-
utype = V_ASN1_ENUMERATED;
|
|
612
|
-
}
|
|
613
|
-
*putype = utype;
|
|
614
|
-
} else if (it->utype == V_ASN1_ANY) {
|
|
615
|
-
/* If ANY set type and pointer to value */
|
|
616
|
-
ASN1_TYPE *typ;
|
|
617
|
-
typ = (ASN1_TYPE *)*pval;
|
|
618
|
-
utype = typ->type;
|
|
619
|
-
if (utype < 0 && utype != V_ASN1_OTHER) {
|
|
620
|
-
/* |ASN1_TYPE|s can have type -1 when default-constructed. */
|
|
621
|
-
OPENSSL_PUT_ERROR(ASN1, ASN1_R_WRONG_TYPE);
|
|
622
|
-
return -1;
|
|
623
|
-
}
|
|
624
|
-
*putype = utype;
|
|
625
|
-
pval = &typ->value.asn1_value;
|
|
626
|
-
} else
|
|
627
|
-
utype = *putype;
|
|
628
|
-
|
|
629
|
-
switch (utype) {
|
|
615
|
+
switch (utype) {
|
|
630
616
|
case V_ASN1_OBJECT:
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
617
|
+
otmp = (ASN1_OBJECT *)*pval;
|
|
618
|
+
cont = otmp->data;
|
|
619
|
+
len = otmp->length;
|
|
620
|
+
if (len == 0) {
|
|
621
|
+
// Some |ASN1_OBJECT|s do not have OIDs and cannot be serialized.
|
|
622
|
+
OPENSSL_PUT_ERROR(ASN1, ASN1_R_ILLEGAL_OBJECT);
|
|
623
|
+
return -1;
|
|
624
|
+
}
|
|
625
|
+
break;
|
|
640
626
|
|
|
641
627
|
case V_ASN1_NULL:
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
628
|
+
cont = NULL;
|
|
629
|
+
len = 0;
|
|
630
|
+
break;
|
|
645
631
|
|
|
646
632
|
case V_ASN1_BOOLEAN:
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
cont = &c;
|
|
664
|
-
len = 1;
|
|
665
|
-
break;
|
|
633
|
+
tbool = (ASN1_BOOLEAN *)pval;
|
|
634
|
+
if (*tbool == -1) {
|
|
635
|
+
*out_omit = 1;
|
|
636
|
+
return 0;
|
|
637
|
+
}
|
|
638
|
+
if (it->utype != V_ASN1_ANY) {
|
|
639
|
+
// Default handling if value == size field then omit
|
|
640
|
+
if ((*tbool && (it->size > 0)) || (!*tbool && !it->size)) {
|
|
641
|
+
*out_omit = 1;
|
|
642
|
+
return 0;
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
c = *tbool ? 0xff : 0x00;
|
|
646
|
+
cont = &c;
|
|
647
|
+
len = 1;
|
|
648
|
+
break;
|
|
666
649
|
|
|
667
650
|
case V_ASN1_BIT_STRING: {
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
651
|
+
int ret =
|
|
652
|
+
i2c_ASN1_BIT_STRING((ASN1_BIT_STRING *)*pval, cout ? &cout : NULL);
|
|
653
|
+
// |i2c_ASN1_BIT_STRING| returns zero on error instead of -1.
|
|
654
|
+
return ret <= 0 ? -1 : ret;
|
|
672
655
|
}
|
|
673
656
|
|
|
674
657
|
case V_ASN1_INTEGER:
|
|
675
658
|
case V_ASN1_ENUMERATED: {
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
659
|
+
// |i2c_ASN1_INTEGER| also handles ENUMERATED.
|
|
660
|
+
int ret = i2c_ASN1_INTEGER((ASN1_INTEGER *)*pval, cout ? &cout : NULL);
|
|
661
|
+
// |i2c_ASN1_INTEGER| returns zero on error instead of -1.
|
|
662
|
+
return ret <= 0 ? -1 : ret;
|
|
680
663
|
}
|
|
681
664
|
|
|
682
665
|
case V_ASN1_OCTET_STRING:
|
|
@@ -696,15 +679,15 @@ static int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *out_omit,
|
|
|
696
679
|
case V_ASN1_SEQUENCE:
|
|
697
680
|
case V_ASN1_SET:
|
|
698
681
|
default:
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
682
|
+
// All based on ASN1_STRING and handled the same
|
|
683
|
+
strtmp = (ASN1_STRING *)*pval;
|
|
684
|
+
cont = strtmp->data;
|
|
685
|
+
len = strtmp->length;
|
|
686
|
+
|
|
687
|
+
break;
|
|
688
|
+
}
|
|
689
|
+
if (cout && len) {
|
|
690
|
+
OPENSSL_memcpy(cout, cont, len);
|
|
691
|
+
}
|
|
692
|
+
return len;
|
|
710
693
|
}
|