@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
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
|
|
77
77
|
|
|
78
78
|
static char *strip_spaces(char *name);
|
|
79
|
-
static int sk_strcmp(const
|
|
79
|
+
static int sk_strcmp(const char **a, const char **b);
|
|
80
80
|
static STACK_OF(OPENSSL_STRING) *get_email(X509_NAME *name,
|
|
81
81
|
GENERAL_NAMES *gens);
|
|
82
82
|
static void str_free(OPENSSL_STRING str);
|
|
@@ -87,1307 +87,1327 @@ static int ipv6_from_asc(unsigned char v6[16], const char *in);
|
|
|
87
87
|
static int ipv6_cb(const char *elem, int len, void *usr);
|
|
88
88
|
static int ipv6_hex(unsigned char *out, const char *in, int inlen);
|
|
89
89
|
|
|
90
|
-
|
|
90
|
+
// Add a CONF_VALUE name value pair to stack
|
|
91
91
|
|
|
92
92
|
static int x509V3_add_len_value(const char *name, const char *value,
|
|
93
93
|
size_t value_len, int omit_value,
|
|
94
|
-
STACK_OF(CONF_VALUE) **extlist)
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
tvalue = OPENSSL_strndup(value, value_len);
|
|
108
|
-
if (tvalue == NULL) {
|
|
109
|
-
goto malloc_err;
|
|
110
|
-
}
|
|
94
|
+
STACK_OF(CONF_VALUE) **extlist) {
|
|
95
|
+
CONF_VALUE *vtmp = NULL;
|
|
96
|
+
char *tname = NULL, *tvalue = NULL;
|
|
97
|
+
int extlist_was_null = *extlist == NULL;
|
|
98
|
+
if (name && !(tname = OPENSSL_strdup(name))) {
|
|
99
|
+
goto malloc_err;
|
|
100
|
+
}
|
|
101
|
+
if (!omit_value) {
|
|
102
|
+
// |CONF_VALUE| cannot represent strings with NULs.
|
|
103
|
+
if (OPENSSL_memchr(value, 0, value_len)) {
|
|
104
|
+
OPENSSL_PUT_ERROR(X509V3, X509V3_R_INVALID_VALUE);
|
|
105
|
+
goto err;
|
|
111
106
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
goto malloc_err;
|
|
116
|
-
vtmp->section = NULL;
|
|
117
|
-
vtmp->name = tname;
|
|
118
|
-
vtmp->value = tvalue;
|
|
119
|
-
if (!sk_CONF_VALUE_push(*extlist, vtmp))
|
|
120
|
-
goto malloc_err;
|
|
121
|
-
return 1;
|
|
122
|
-
malloc_err:
|
|
123
|
-
OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
|
|
124
|
-
err:
|
|
125
|
-
if (extlist_was_null) {
|
|
126
|
-
sk_CONF_VALUE_free(*extlist);
|
|
127
|
-
*extlist = NULL;
|
|
107
|
+
tvalue = OPENSSL_strndup(value, value_len);
|
|
108
|
+
if (tvalue == NULL) {
|
|
109
|
+
goto malloc_err;
|
|
128
110
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
111
|
+
}
|
|
112
|
+
if (!(vtmp = CONF_VALUE_new())) {
|
|
113
|
+
goto malloc_err;
|
|
114
|
+
}
|
|
115
|
+
if (!*extlist && !(*extlist = sk_CONF_VALUE_new_null())) {
|
|
116
|
+
goto malloc_err;
|
|
117
|
+
}
|
|
118
|
+
vtmp->section = NULL;
|
|
119
|
+
vtmp->name = tname;
|
|
120
|
+
vtmp->value = tvalue;
|
|
121
|
+
if (!sk_CONF_VALUE_push(*extlist, vtmp)) {
|
|
122
|
+
goto malloc_err;
|
|
123
|
+
}
|
|
124
|
+
return 1;
|
|
125
|
+
malloc_err:
|
|
126
|
+
OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
|
|
127
|
+
err:
|
|
128
|
+
if (extlist_was_null) {
|
|
129
|
+
sk_CONF_VALUE_free(*extlist);
|
|
130
|
+
*extlist = NULL;
|
|
131
|
+
}
|
|
132
|
+
OPENSSL_free(vtmp);
|
|
133
|
+
OPENSSL_free(tname);
|
|
134
|
+
OPENSSL_free(tvalue);
|
|
135
|
+
return 0;
|
|
133
136
|
}
|
|
134
137
|
|
|
135
138
|
int X509V3_add_value(const char *name, const char *value,
|
|
136
|
-
STACK_OF(CONF_VALUE) **extlist)
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
/*omit_value=*/value == NULL, extlist);
|
|
139
|
+
STACK_OF(CONF_VALUE) **extlist) {
|
|
140
|
+
return x509V3_add_len_value(name, value, value != NULL ? strlen(value) : 0,
|
|
141
|
+
/*omit_value=*/value == NULL, extlist);
|
|
140
142
|
}
|
|
141
143
|
|
|
142
144
|
int X509V3_add_value_uchar(const char *name, const unsigned char *value,
|
|
143
|
-
STACK_OF(CONF_VALUE) **extlist)
|
|
144
|
-
|
|
145
|
-
return X509V3_add_value(name, (const char *)value, extlist);
|
|
145
|
+
STACK_OF(CONF_VALUE) **extlist) {
|
|
146
|
+
return X509V3_add_value(name, (const char *)value, extlist);
|
|
146
147
|
}
|
|
147
148
|
|
|
148
149
|
int x509V3_add_value_asn1_string(const char *name, const ASN1_STRING *value,
|
|
149
|
-
STACK_OF(CONF_VALUE) **extlist)
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
/*omit_value=*/0, extlist);
|
|
150
|
+
STACK_OF(CONF_VALUE) **extlist) {
|
|
151
|
+
return x509V3_add_len_value(name, (const char *)value->data, value->length,
|
|
152
|
+
/*omit_value=*/0, extlist);
|
|
153
153
|
}
|
|
154
154
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
void X509V3_conf_free(CONF_VALUE *conf)
|
|
158
|
-
{
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
155
|
+
// Free function for STACK_OF(CONF_VALUE)
|
|
156
|
+
|
|
157
|
+
void X509V3_conf_free(CONF_VALUE *conf) {
|
|
158
|
+
if (!conf) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
if (conf->name) {
|
|
162
|
+
OPENSSL_free(conf->name);
|
|
163
|
+
}
|
|
164
|
+
if (conf->value) {
|
|
165
|
+
OPENSSL_free(conf->value);
|
|
166
|
+
}
|
|
167
|
+
if (conf->section) {
|
|
168
|
+
OPENSSL_free(conf->section);
|
|
169
|
+
}
|
|
170
|
+
OPENSSL_free(conf);
|
|
168
171
|
}
|
|
169
172
|
|
|
170
173
|
int X509V3_add_value_bool(const char *name, int asn1_bool,
|
|
171
|
-
STACK_OF(CONF_VALUE) **extlist)
|
|
172
|
-
{
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
174
|
+
STACK_OF(CONF_VALUE) **extlist) {
|
|
175
|
+
if (asn1_bool) {
|
|
176
|
+
return X509V3_add_value(name, "TRUE", extlist);
|
|
177
|
+
}
|
|
178
|
+
return X509V3_add_value(name, "FALSE", extlist);
|
|
176
179
|
}
|
|
177
180
|
|
|
178
181
|
int X509V3_add_value_bool_nf(const char *name, int asn1_bool,
|
|
179
|
-
STACK_OF(CONF_VALUE) **extlist)
|
|
180
|
-
{
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
182
|
+
STACK_OF(CONF_VALUE) **extlist) {
|
|
183
|
+
if (asn1_bool) {
|
|
184
|
+
return X509V3_add_value(name, "TRUE", extlist);
|
|
185
|
+
}
|
|
186
|
+
return 1;
|
|
184
187
|
}
|
|
185
188
|
|
|
186
|
-
static char *bignum_to_string(const BIGNUM *bn)
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
size_t len;
|
|
190
|
-
|
|
191
|
-
/*
|
|
192
|
-
* Display large numbers in hex and small numbers in decimal. Converting to
|
|
193
|
-
* decimal takes quadratic time and is no more useful than hex for large
|
|
194
|
-
* numbers.
|
|
195
|
-
*/
|
|
196
|
-
if (BN_num_bits(bn) < 32) {
|
|
197
|
-
return BN_bn2dec(bn);
|
|
198
|
-
}
|
|
189
|
+
static char *bignum_to_string(const BIGNUM *bn) {
|
|
190
|
+
char *tmp, *ret;
|
|
191
|
+
size_t len;
|
|
199
192
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
193
|
+
// Display large numbers in hex and small numbers in decimal. Converting to
|
|
194
|
+
// decimal takes quadratic time and is no more useful than hex for large
|
|
195
|
+
// numbers.
|
|
196
|
+
if (BN_num_bits(bn) < 32) {
|
|
197
|
+
return BN_bn2dec(bn);
|
|
198
|
+
}
|
|
204
199
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
OPENSSL_free(tmp);
|
|
210
|
-
return NULL;
|
|
211
|
-
}
|
|
200
|
+
tmp = BN_bn2hex(bn);
|
|
201
|
+
if (tmp == NULL) {
|
|
202
|
+
return NULL;
|
|
203
|
+
}
|
|
212
204
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
} else {
|
|
218
|
-
OPENSSL_strlcpy(ret, "0x", len);
|
|
219
|
-
OPENSSL_strlcat(ret, tmp, len);
|
|
220
|
-
}
|
|
205
|
+
len = strlen(tmp) + 3;
|
|
206
|
+
ret = OPENSSL_malloc(len);
|
|
207
|
+
if (ret == NULL) {
|
|
208
|
+
OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
|
|
221
209
|
OPENSSL_free(tmp);
|
|
222
|
-
return
|
|
210
|
+
return NULL;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// Prepend "0x", but place it after the "-" if negative.
|
|
214
|
+
if (tmp[0] == '-') {
|
|
215
|
+
OPENSSL_strlcpy(ret, "-0x", len);
|
|
216
|
+
OPENSSL_strlcat(ret, tmp + 1, len);
|
|
217
|
+
} else {
|
|
218
|
+
OPENSSL_strlcpy(ret, "0x", len);
|
|
219
|
+
OPENSSL_strlcat(ret, tmp, len);
|
|
220
|
+
}
|
|
221
|
+
OPENSSL_free(tmp);
|
|
222
|
+
return ret;
|
|
223
223
|
}
|
|
224
224
|
|
|
225
225
|
char *i2s_ASN1_ENUMERATED(const X509V3_EXT_METHOD *method,
|
|
226
|
-
const ASN1_ENUMERATED *a)
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
226
|
+
const ASN1_ENUMERATED *a) {
|
|
227
|
+
BIGNUM *bntmp = NULL;
|
|
228
|
+
char *strtmp = NULL;
|
|
229
|
+
if (!a) {
|
|
230
|
+
return NULL;
|
|
231
|
+
}
|
|
232
|
+
if (!(bntmp = ASN1_ENUMERATED_to_BN(a, NULL)) ||
|
|
233
|
+
!(strtmp = bignum_to_string(bntmp))) {
|
|
234
|
+
OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
|
|
235
|
+
}
|
|
236
|
+
BN_free(bntmp);
|
|
237
|
+
return strtmp;
|
|
237
238
|
}
|
|
238
239
|
|
|
239
|
-
char *i2s_ASN1_INTEGER(const X509V3_EXT_METHOD *method, const ASN1_INTEGER *a)
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
240
|
+
char *i2s_ASN1_INTEGER(const X509V3_EXT_METHOD *method, const ASN1_INTEGER *a) {
|
|
241
|
+
BIGNUM *bntmp = NULL;
|
|
242
|
+
char *strtmp = NULL;
|
|
243
|
+
if (!a) {
|
|
244
|
+
return NULL;
|
|
245
|
+
}
|
|
246
|
+
if (!(bntmp = ASN1_INTEGER_to_BN(a, NULL)) ||
|
|
247
|
+
!(strtmp = bignum_to_string(bntmp))) {
|
|
248
|
+
OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
|
|
249
|
+
}
|
|
250
|
+
BN_free(bntmp);
|
|
251
|
+
return strtmp;
|
|
250
252
|
}
|
|
251
253
|
|
|
252
254
|
ASN1_INTEGER *s2i_ASN1_INTEGER(const X509V3_EXT_METHOD *method,
|
|
253
|
-
const char *value)
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
255
|
+
const char *value) {
|
|
256
|
+
BIGNUM *bn = NULL;
|
|
257
|
+
ASN1_INTEGER *aint;
|
|
258
|
+
int isneg, ishex;
|
|
259
|
+
int ret;
|
|
260
|
+
if (!value) {
|
|
261
|
+
OPENSSL_PUT_ERROR(X509V3, X509V3_R_INVALID_NULL_VALUE);
|
|
262
|
+
return 0;
|
|
263
|
+
}
|
|
264
|
+
bn = BN_new();
|
|
265
|
+
if (value[0] == '-') {
|
|
266
|
+
value++;
|
|
267
|
+
isneg = 1;
|
|
268
|
+
} else {
|
|
269
|
+
isneg = 0;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
if (value[0] == '0' && ((value[1] == 'x') || (value[1] == 'X'))) {
|
|
273
|
+
value += 2;
|
|
274
|
+
ishex = 1;
|
|
275
|
+
} else {
|
|
276
|
+
ishex = 0;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
if (ishex) {
|
|
280
|
+
ret = BN_hex2bn(&bn, value);
|
|
281
|
+
} else {
|
|
282
|
+
ret = BN_dec2bn(&bn, value);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
if (!ret || value[ret]) {
|
|
286
|
+
BN_free(bn);
|
|
287
|
+
OPENSSL_PUT_ERROR(X509V3, X509V3_R_BN_DEC2BN_ERROR);
|
|
288
|
+
return 0;
|
|
289
|
+
}
|
|
286
290
|
|
|
287
|
-
|
|
288
|
-
|
|
291
|
+
if (isneg && BN_is_zero(bn)) {
|
|
292
|
+
isneg = 0;
|
|
293
|
+
}
|
|
289
294
|
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
295
|
+
aint = BN_to_ASN1_INTEGER(bn, NULL);
|
|
296
|
+
BN_free(bn);
|
|
297
|
+
if (!aint) {
|
|
298
|
+
OPENSSL_PUT_ERROR(X509V3, X509V3_R_BN_TO_ASN1_INTEGER_ERROR);
|
|
299
|
+
return 0;
|
|
300
|
+
}
|
|
301
|
+
if (isneg) {
|
|
302
|
+
aint->type |= V_ASN1_NEG;
|
|
303
|
+
}
|
|
304
|
+
return aint;
|
|
299
305
|
}
|
|
300
306
|
|
|
301
307
|
int X509V3_add_value_int(const char *name, const ASN1_INTEGER *aint,
|
|
302
|
-
STACK_OF(CONF_VALUE) **extlist)
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
return 0;
|
|
310
|
-
ret = X509V3_add_value(name, strtmp, extlist);
|
|
311
|
-
OPENSSL_free(strtmp);
|
|
312
|
-
return ret;
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
int X509V3_get_value_bool(const CONF_VALUE *value, int *asn1_bool)
|
|
316
|
-
{
|
|
317
|
-
char *btmp;
|
|
318
|
-
if (!(btmp = value->value))
|
|
319
|
-
goto err;
|
|
320
|
-
if (!strcmp(btmp, "TRUE") || !strcmp(btmp, "true")
|
|
321
|
-
|| !strcmp(btmp, "Y") || !strcmp(btmp, "y")
|
|
322
|
-
|| !strcmp(btmp, "YES") || !strcmp(btmp, "yes")) {
|
|
323
|
-
*asn1_bool = 0xff;
|
|
324
|
-
return 1;
|
|
325
|
-
} else if (!strcmp(btmp, "FALSE") || !strcmp(btmp, "false")
|
|
326
|
-
|| !strcmp(btmp, "N") || !strcmp(btmp, "n")
|
|
327
|
-
|| !strcmp(btmp, "NO") || !strcmp(btmp, "no")) {
|
|
328
|
-
*asn1_bool = 0;
|
|
329
|
-
return 1;
|
|
330
|
-
}
|
|
331
|
-
err:
|
|
332
|
-
OPENSSL_PUT_ERROR(X509V3, X509V3_R_INVALID_BOOLEAN_STRING);
|
|
333
|
-
X509V3_conf_err(value);
|
|
308
|
+
STACK_OF(CONF_VALUE) **extlist) {
|
|
309
|
+
char *strtmp;
|
|
310
|
+
int ret;
|
|
311
|
+
if (!aint) {
|
|
312
|
+
return 1;
|
|
313
|
+
}
|
|
314
|
+
if (!(strtmp = i2s_ASN1_INTEGER(NULL, aint))) {
|
|
334
315
|
return 0;
|
|
316
|
+
}
|
|
317
|
+
ret = X509V3_add_value(name, strtmp, extlist);
|
|
318
|
+
OPENSSL_free(strtmp);
|
|
319
|
+
return ret;
|
|
335
320
|
}
|
|
336
321
|
|
|
337
|
-
int
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
*
|
|
322
|
+
int X509V3_get_value_bool(const CONF_VALUE *value, int *asn1_bool) {
|
|
323
|
+
char *btmp;
|
|
324
|
+
if (!(btmp = value->value)) {
|
|
325
|
+
goto err;
|
|
326
|
+
}
|
|
327
|
+
if (!strcmp(btmp, "TRUE") || !strcmp(btmp, "true") || !strcmp(btmp, "Y") ||
|
|
328
|
+
!strcmp(btmp, "y") || !strcmp(btmp, "YES") || !strcmp(btmp, "yes")) {
|
|
329
|
+
*asn1_bool = 0xff;
|
|
345
330
|
return 1;
|
|
331
|
+
} else if (!strcmp(btmp, "FALSE") || !strcmp(btmp, "false") ||
|
|
332
|
+
!strcmp(btmp, "N") || !strcmp(btmp, "n") || !strcmp(btmp, "NO") ||
|
|
333
|
+
!strcmp(btmp, "no")) {
|
|
334
|
+
*asn1_bool = 0;
|
|
335
|
+
return 1;
|
|
336
|
+
}
|
|
337
|
+
err:
|
|
338
|
+
OPENSSL_PUT_ERROR(X509V3, X509V3_R_INVALID_BOOLEAN_STRING);
|
|
339
|
+
X509V3_conf_err(value);
|
|
340
|
+
return 0;
|
|
346
341
|
}
|
|
347
342
|
|
|
348
|
-
|
|
349
|
-
|
|
343
|
+
int X509V3_get_value_int(const CONF_VALUE *value, ASN1_INTEGER **aint) {
|
|
344
|
+
ASN1_INTEGER *itmp;
|
|
345
|
+
if (!(itmp = s2i_ASN1_INTEGER(NULL, value->value))) {
|
|
346
|
+
X509V3_conf_err(value);
|
|
347
|
+
return 0;
|
|
348
|
+
}
|
|
349
|
+
*aint = itmp;
|
|
350
|
+
return 1;
|
|
351
|
+
}
|
|
350
352
|
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
*/
|
|
353
|
+
#define HDR_NAME 1
|
|
354
|
+
#define HDR_VALUE 2
|
|
354
355
|
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
q = p + 1;
|
|
356
|
+
// #define DEBUG
|
|
357
|
+
|
|
358
|
+
STACK_OF(CONF_VALUE) *X509V3_parse_list(const char *line) {
|
|
359
|
+
char *p, *q, c;
|
|
360
|
+
char *ntmp, *vtmp;
|
|
361
|
+
STACK_OF(CONF_VALUE) *values = NULL;
|
|
362
|
+
char *linebuf;
|
|
363
|
+
int state;
|
|
364
|
+
// We are going to modify the line so copy it first
|
|
365
|
+
linebuf = OPENSSL_strdup(line);
|
|
366
|
+
if (linebuf == NULL) {
|
|
367
|
+
OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
|
|
368
|
+
goto err;
|
|
369
|
+
}
|
|
370
|
+
state = HDR_NAME;
|
|
371
|
+
ntmp = NULL;
|
|
372
|
+
// Go through all characters
|
|
373
|
+
for (p = linebuf, q = linebuf; (c = *p) && (c != '\r') && (c != '\n'); p++) {
|
|
374
|
+
switch (state) {
|
|
375
|
+
case HDR_NAME:
|
|
376
|
+
if (c == ':') {
|
|
377
|
+
state = HDR_VALUE;
|
|
378
|
+
*p = 0;
|
|
379
|
+
ntmp = strip_spaces(q);
|
|
380
|
+
if (!ntmp) {
|
|
381
|
+
OPENSSL_PUT_ERROR(X509V3, X509V3_R_INVALID_NULL_NAME);
|
|
382
|
+
goto err;
|
|
383
|
+
}
|
|
384
|
+
q = p + 1;
|
|
385
|
+
} else if (c == ',') {
|
|
386
|
+
*p = 0;
|
|
387
|
+
ntmp = strip_spaces(q);
|
|
388
|
+
q = p + 1;
|
|
389
389
|
#if 0
|
|
390
390
|
printf("%s\n", ntmp);
|
|
391
391
|
#endif
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
392
|
+
if (!ntmp) {
|
|
393
|
+
OPENSSL_PUT_ERROR(X509V3, X509V3_R_INVALID_NULL_NAME);
|
|
394
|
+
goto err;
|
|
395
|
+
}
|
|
396
|
+
X509V3_add_value(ntmp, NULL, &values);
|
|
397
|
+
}
|
|
398
|
+
break;
|
|
399
|
+
|
|
400
|
+
case HDR_VALUE:
|
|
401
|
+
if (c == ',') {
|
|
402
|
+
state = HDR_NAME;
|
|
403
|
+
*p = 0;
|
|
404
|
+
vtmp = strip_spaces(q);
|
|
405
405
|
#if 0
|
|
406
406
|
printf("%s\n", ntmp);
|
|
407
407
|
#endif
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
}
|
|
416
|
-
|
|
408
|
+
if (!vtmp) {
|
|
409
|
+
OPENSSL_PUT_ERROR(X509V3, X509V3_R_INVALID_NULL_VALUE);
|
|
410
|
+
goto err;
|
|
411
|
+
}
|
|
412
|
+
X509V3_add_value(ntmp, vtmp, &values);
|
|
413
|
+
ntmp = NULL;
|
|
414
|
+
q = p + 1;
|
|
417
415
|
}
|
|
418
416
|
}
|
|
417
|
+
}
|
|
419
418
|
|
|
420
|
-
|
|
421
|
-
|
|
419
|
+
if (state == HDR_VALUE) {
|
|
420
|
+
vtmp = strip_spaces(q);
|
|
422
421
|
#if 0
|
|
423
422
|
printf("%s=%s\n", ntmp, vtmp);
|
|
424
423
|
#endif
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
424
|
+
if (!vtmp) {
|
|
425
|
+
OPENSSL_PUT_ERROR(X509V3, X509V3_R_INVALID_NULL_VALUE);
|
|
426
|
+
goto err;
|
|
427
|
+
}
|
|
428
|
+
X509V3_add_value(ntmp, vtmp, &values);
|
|
429
|
+
} else {
|
|
430
|
+
ntmp = strip_spaces(q);
|
|
432
431
|
#if 0
|
|
433
432
|
printf("%s\n", ntmp);
|
|
434
433
|
#endif
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
}
|
|
439
|
-
X509V3_add_value(ntmp, NULL, &values);
|
|
434
|
+
if (!ntmp) {
|
|
435
|
+
OPENSSL_PUT_ERROR(X509V3, X509V3_R_INVALID_NULL_NAME);
|
|
436
|
+
goto err;
|
|
440
437
|
}
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
OPENSSL_free(linebuf);
|
|
446
|
-
sk_CONF_VALUE_pop_free(values, X509V3_conf_free);
|
|
447
|
-
return NULL;
|
|
438
|
+
X509V3_add_value(ntmp, NULL, &values);
|
|
439
|
+
}
|
|
440
|
+
OPENSSL_free(linebuf);
|
|
441
|
+
return values;
|
|
448
442
|
|
|
443
|
+
err:
|
|
444
|
+
OPENSSL_free(linebuf);
|
|
445
|
+
sk_CONF_VALUE_pop_free(values, X509V3_conf_free);
|
|
446
|
+
return NULL;
|
|
449
447
|
}
|
|
450
448
|
|
|
451
|
-
|
|
452
|
-
static char *strip_spaces(char *name)
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
449
|
+
// Delete leading and trailing spaces from a string
|
|
450
|
+
static char *strip_spaces(char *name) {
|
|
451
|
+
char *p, *q;
|
|
452
|
+
// Skip over leading spaces
|
|
453
|
+
p = name;
|
|
454
|
+
while (*p && isspace((unsigned char)*p)) {
|
|
455
|
+
p++;
|
|
456
|
+
}
|
|
457
|
+
if (!*p) {
|
|
458
|
+
return NULL;
|
|
459
|
+
}
|
|
460
|
+
q = p + strlen(p) - 1;
|
|
461
|
+
while ((q != p) && isspace((unsigned char)*q)) {
|
|
462
|
+
q--;
|
|
463
|
+
}
|
|
464
|
+
if (p != q) {
|
|
465
|
+
q[1] = 0;
|
|
466
|
+
}
|
|
467
|
+
if (!*p) {
|
|
468
|
+
return NULL;
|
|
469
|
+
}
|
|
470
|
+
return p;
|
|
469
471
|
}
|
|
470
472
|
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
char *x509v3_bytes_to_hex(const uint8_t *in, size_t len)
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
goto err;
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
uint8_t *ret;
|
|
488
|
-
size_t unused_len;
|
|
489
|
-
if (!CBB_add_u8(&cbb, 0) ||
|
|
490
|
-
!CBB_finish(&cbb, &ret, &unused_len)) {
|
|
491
|
-
goto err;
|
|
473
|
+
// hex string utilities
|
|
474
|
+
|
|
475
|
+
char *x509v3_bytes_to_hex(const uint8_t *in, size_t len) {
|
|
476
|
+
CBB cbb;
|
|
477
|
+
if (!CBB_init(&cbb, len * 3 + 1)) {
|
|
478
|
+
goto err;
|
|
479
|
+
}
|
|
480
|
+
for (size_t i = 0; i < len; i++) {
|
|
481
|
+
static const char hex[] = "0123456789ABCDEF";
|
|
482
|
+
if ((i > 0 && !CBB_add_u8(&cbb, ':')) ||
|
|
483
|
+
!CBB_add_u8(&cbb, hex[in[i] >> 4]) ||
|
|
484
|
+
!CBB_add_u8(&cbb, hex[in[i] & 0xf])) {
|
|
485
|
+
goto err;
|
|
492
486
|
}
|
|
487
|
+
}
|
|
488
|
+
uint8_t *ret;
|
|
489
|
+
size_t unused_len;
|
|
490
|
+
if (!CBB_add_u8(&cbb, 0) || !CBB_finish(&cbb, &ret, &unused_len)) {
|
|
491
|
+
goto err;
|
|
492
|
+
}
|
|
493
493
|
|
|
494
|
-
|
|
494
|
+
return (char *)ret;
|
|
495
495
|
|
|
496
496
|
err:
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
497
|
+
OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
|
|
498
|
+
CBB_cleanup(&cbb);
|
|
499
|
+
return NULL;
|
|
500
500
|
}
|
|
501
501
|
|
|
502
|
-
unsigned char *x509v3_hex_to_bytes(const char *str, long *len)
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
502
|
+
unsigned char *x509v3_hex_to_bytes(const char *str, long *len) {
|
|
503
|
+
unsigned char *hexbuf, *q;
|
|
504
|
+
unsigned char ch, cl, *p;
|
|
505
|
+
if (!str) {
|
|
506
|
+
OPENSSL_PUT_ERROR(X509V3, X509V3_R_INVALID_NULL_ARGUMENT);
|
|
507
|
+
return NULL;
|
|
508
|
+
}
|
|
509
|
+
if (!(hexbuf = OPENSSL_malloc(strlen(str) >> 1))) {
|
|
510
|
+
goto err;
|
|
511
|
+
}
|
|
512
|
+
for (p = (unsigned char *)str, q = hexbuf; *p;) {
|
|
513
|
+
ch = *p++;
|
|
514
|
+
if (ch == ':') {
|
|
515
|
+
continue;
|
|
516
|
+
}
|
|
517
|
+
cl = *p++;
|
|
518
|
+
if (!cl) {
|
|
519
|
+
OPENSSL_PUT_ERROR(X509V3, X509V3_R_ODD_NUMBER_OF_DIGITS);
|
|
520
|
+
OPENSSL_free(hexbuf);
|
|
521
|
+
return NULL;
|
|
509
522
|
}
|
|
510
|
-
if (!(hexbuf = OPENSSL_malloc(strlen(str) >> 1)))
|
|
511
|
-
goto err;
|
|
512
|
-
for (p = (unsigned char *)str, q = hexbuf; *p;) {
|
|
513
|
-
ch = *p++;
|
|
514
|
-
if (ch == ':')
|
|
515
|
-
continue;
|
|
516
|
-
cl = *p++;
|
|
517
|
-
if (!cl) {
|
|
518
|
-
OPENSSL_PUT_ERROR(X509V3, X509V3_R_ODD_NUMBER_OF_DIGITS);
|
|
519
|
-
OPENSSL_free(hexbuf);
|
|
520
|
-
return NULL;
|
|
521
|
-
}
|
|
522
523
|
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
if ((cl >= '0') && (cl <= '9'))
|
|
533
|
-
cl -= '0';
|
|
534
|
-
else if ((cl >= 'a') && (cl <= 'f'))
|
|
535
|
-
cl -= 'a' - 10;
|
|
536
|
-
else if ((cl >= 'A') && (cl <= 'F'))
|
|
537
|
-
cl -= 'A' - 10;
|
|
538
|
-
else
|
|
539
|
-
goto badhex;
|
|
540
|
-
|
|
541
|
-
*q++ = (ch << 4) | cl;
|
|
524
|
+
if ((ch >= '0') && (ch <= '9')) {
|
|
525
|
+
ch -= '0';
|
|
526
|
+
} else if ((ch >= 'a') && (ch <= 'f')) {
|
|
527
|
+
ch -= 'a' - 10;
|
|
528
|
+
} else if ((ch >= 'A') && (ch <= 'F')) {
|
|
529
|
+
ch -= 'A' - 10;
|
|
530
|
+
} else {
|
|
531
|
+
goto badhex;
|
|
542
532
|
}
|
|
543
533
|
|
|
544
|
-
if (
|
|
545
|
-
|
|
534
|
+
if ((cl >= '0') && (cl <= '9')) {
|
|
535
|
+
cl -= '0';
|
|
536
|
+
} else if ((cl >= 'a') && (cl <= 'f')) {
|
|
537
|
+
cl -= 'a' - 10;
|
|
538
|
+
} else if ((cl >= 'A') && (cl <= 'F')) {
|
|
539
|
+
cl -= 'A' - 10;
|
|
540
|
+
} else {
|
|
541
|
+
goto badhex;
|
|
542
|
+
}
|
|
546
543
|
|
|
547
|
-
|
|
544
|
+
*q++ = (ch << 4) | cl;
|
|
545
|
+
}
|
|
548
546
|
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
|
|
553
|
-
return NULL;
|
|
547
|
+
if (len) {
|
|
548
|
+
*len = q - hexbuf;
|
|
549
|
+
}
|
|
554
550
|
|
|
555
|
-
|
|
556
|
-
OPENSSL_free(hexbuf);
|
|
557
|
-
OPENSSL_PUT_ERROR(X509V3, X509V3_R_ILLEGAL_HEX_DIGIT);
|
|
558
|
-
return NULL;
|
|
551
|
+
return hexbuf;
|
|
559
552
|
|
|
553
|
+
err:
|
|
554
|
+
if (hexbuf) {
|
|
555
|
+
OPENSSL_free(hexbuf);
|
|
556
|
+
}
|
|
557
|
+
OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
|
|
558
|
+
return NULL;
|
|
559
|
+
|
|
560
|
+
badhex:
|
|
561
|
+
OPENSSL_free(hexbuf);
|
|
562
|
+
OPENSSL_PUT_ERROR(X509V3, X509V3_R_ILLEGAL_HEX_DIGIT);
|
|
563
|
+
return NULL;
|
|
560
564
|
}
|
|
561
565
|
|
|
562
|
-
int x509v3_name_cmp(const char *name, const char *cmp)
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
566
|
+
int x509v3_name_cmp(const char *name, const char *cmp) {
|
|
567
|
+
int len, ret;
|
|
568
|
+
char c;
|
|
569
|
+
len = strlen(cmp);
|
|
570
|
+
if ((ret = strncmp(name, cmp, len))) {
|
|
571
|
+
return ret;
|
|
572
|
+
}
|
|
573
|
+
c = name[len];
|
|
574
|
+
if (!c || (c == '.')) {
|
|
575
|
+
return 0;
|
|
576
|
+
}
|
|
577
|
+
return 1;
|
|
573
578
|
}
|
|
574
579
|
|
|
575
|
-
static int sk_strcmp(const
|
|
576
|
-
{
|
|
577
|
-
return strcmp(*a, *b);
|
|
578
|
-
}
|
|
580
|
+
static int sk_strcmp(const char **a, const char **b) { return strcmp(*a, *b); }
|
|
579
581
|
|
|
580
|
-
STACK_OF(OPENSSL_STRING) *X509_get1_email(X509 *x)
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
STACK_OF(OPENSSL_STRING) *ret;
|
|
582
|
+
STACK_OF(OPENSSL_STRING) *X509_get1_email(X509 *x) {
|
|
583
|
+
GENERAL_NAMES *gens;
|
|
584
|
+
STACK_OF(OPENSSL_STRING) *ret;
|
|
584
585
|
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
586
|
+
gens = X509_get_ext_d2i(x, NID_subject_alt_name, NULL, NULL);
|
|
587
|
+
ret = get_email(X509_get_subject_name(x), gens);
|
|
588
|
+
sk_GENERAL_NAME_pop_free(gens, GENERAL_NAME_free);
|
|
589
|
+
return ret;
|
|
589
590
|
}
|
|
590
591
|
|
|
591
|
-
STACK_OF(OPENSSL_STRING) *X509_get1_ocsp(X509 *x)
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
size_t i;
|
|
592
|
+
STACK_OF(OPENSSL_STRING) *X509_get1_ocsp(X509 *x) {
|
|
593
|
+
AUTHORITY_INFO_ACCESS *info;
|
|
594
|
+
STACK_OF(OPENSSL_STRING) *ret = NULL;
|
|
595
|
+
size_t i;
|
|
596
596
|
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
}
|
|
597
|
+
info = X509_get_ext_d2i(x, NID_info_access, NULL, NULL);
|
|
598
|
+
if (!info) {
|
|
599
|
+
return NULL;
|
|
600
|
+
}
|
|
601
|
+
for (i = 0; i < sk_ACCESS_DESCRIPTION_num(info); i++) {
|
|
602
|
+
ACCESS_DESCRIPTION *ad = sk_ACCESS_DESCRIPTION_value(info, i);
|
|
603
|
+
if (OBJ_obj2nid(ad->method) == NID_ad_OCSP) {
|
|
604
|
+
if (ad->location->type == GEN_URI) {
|
|
605
|
+
if (!append_ia5(&ret, ad->location->d.uniformResourceIdentifier)) {
|
|
606
|
+
break;
|
|
608
607
|
}
|
|
608
|
+
}
|
|
609
609
|
}
|
|
610
|
-
|
|
611
|
-
|
|
610
|
+
}
|
|
611
|
+
AUTHORITY_INFO_ACCESS_free(info);
|
|
612
|
+
return ret;
|
|
612
613
|
}
|
|
613
614
|
|
|
614
|
-
STACK_OF(OPENSSL_STRING) *X509_REQ_get1_email(X509_REQ *x)
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
return ret;
|
|
615
|
+
STACK_OF(OPENSSL_STRING) *X509_REQ_get1_email(X509_REQ *x) {
|
|
616
|
+
GENERAL_NAMES *gens;
|
|
617
|
+
STACK_OF(X509_EXTENSION) *exts;
|
|
618
|
+
STACK_OF(OPENSSL_STRING) *ret;
|
|
619
|
+
|
|
620
|
+
exts = X509_REQ_get_extensions(x);
|
|
621
|
+
gens = X509V3_get_d2i(exts, NID_subject_alt_name, NULL, NULL);
|
|
622
|
+
ret = get_email(X509_REQ_get_subject_name(x), gens);
|
|
623
|
+
sk_GENERAL_NAME_pop_free(gens, GENERAL_NAME_free);
|
|
624
|
+
sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free);
|
|
625
|
+
return ret;
|
|
626
626
|
}
|
|
627
627
|
|
|
628
628
|
static STACK_OF(OPENSSL_STRING) *get_email(X509_NAME *name,
|
|
629
|
-
GENERAL_NAMES *gens)
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
return NULL;
|
|
629
|
+
GENERAL_NAMES *gens) {
|
|
630
|
+
STACK_OF(OPENSSL_STRING) *ret = NULL;
|
|
631
|
+
X509_NAME_ENTRY *ne;
|
|
632
|
+
ASN1_IA5STRING *email;
|
|
633
|
+
GENERAL_NAME *gen;
|
|
634
|
+
int i;
|
|
635
|
+
size_t j;
|
|
636
|
+
// Now add any email address(es) to STACK
|
|
637
|
+
i = -1;
|
|
638
|
+
// First supplied X509_NAME
|
|
639
|
+
while ((i = X509_NAME_get_index_by_NID(name, NID_pkcs9_emailAddress, i)) >=
|
|
640
|
+
0) {
|
|
641
|
+
ne = X509_NAME_get_entry(name, i);
|
|
642
|
+
email = X509_NAME_ENTRY_get_data(ne);
|
|
643
|
+
if (!append_ia5(&ret, email)) {
|
|
644
|
+
return NULL;
|
|
646
645
|
}
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
return NULL;
|
|
646
|
+
}
|
|
647
|
+
for (j = 0; j < sk_GENERAL_NAME_num(gens); j++) {
|
|
648
|
+
gen = sk_GENERAL_NAME_value(gens, j);
|
|
649
|
+
if (gen->type != GEN_EMAIL) {
|
|
650
|
+
continue;
|
|
653
651
|
}
|
|
654
|
-
|
|
652
|
+
if (!append_ia5(&ret, gen->d.ia5)) {
|
|
653
|
+
return NULL;
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
return ret;
|
|
655
657
|
}
|
|
656
658
|
|
|
657
|
-
static void str_free(OPENSSL_STRING str)
|
|
658
|
-
{
|
|
659
|
-
OPENSSL_free(str);
|
|
660
|
-
}
|
|
659
|
+
static void str_free(OPENSSL_STRING str) { OPENSSL_free(str); }
|
|
661
660
|
|
|
662
|
-
static int append_ia5(STACK_OF(OPENSSL_STRING) **sk, ASN1_IA5STRING *email)
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
}
|
|
661
|
+
static int append_ia5(STACK_OF(OPENSSL_STRING) **sk, ASN1_IA5STRING *email) {
|
|
662
|
+
// First some sanity checks
|
|
663
|
+
if (email->type != V_ASN1_IA5STRING) {
|
|
664
|
+
return 1;
|
|
665
|
+
}
|
|
666
|
+
if (email->data == NULL || email->length == 0) {
|
|
667
|
+
return 1;
|
|
668
|
+
}
|
|
669
|
+
// |OPENSSL_STRING| cannot represent strings with embedded NULs. Do not
|
|
670
|
+
// report them as outputs.
|
|
671
|
+
if (OPENSSL_memchr(email->data, 0, email->length) != NULL) {
|
|
672
|
+
return 1;
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
char *emtmp = NULL;
|
|
676
|
+
if (!*sk) {
|
|
677
|
+
*sk = sk_OPENSSL_STRING_new(sk_strcmp);
|
|
678
|
+
}
|
|
679
|
+
if (!*sk) {
|
|
680
|
+
goto err;
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
emtmp = OPENSSL_strndup((char *)email->data, email->length);
|
|
684
|
+
if (emtmp == NULL) {
|
|
685
|
+
goto err;
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
// Don't add duplicates
|
|
689
|
+
sk_OPENSSL_STRING_sort(*sk);
|
|
690
|
+
if (sk_OPENSSL_STRING_find(*sk, NULL, emtmp)) {
|
|
691
|
+
OPENSSL_free(emtmp);
|
|
694
692
|
return 1;
|
|
693
|
+
}
|
|
694
|
+
if (!sk_OPENSSL_STRING_push(*sk, emtmp)) {
|
|
695
|
+
goto err;
|
|
696
|
+
}
|
|
697
|
+
return 1;
|
|
695
698
|
|
|
696
699
|
err:
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
700
|
+
// TODO(davidben): Fix the error-handling in this file. It currently relies
|
|
701
|
+
// on |append_ia5| leaving |*sk| at NULL on error.
|
|
702
|
+
OPENSSL_free(emtmp);
|
|
703
|
+
X509_email_free(*sk);
|
|
704
|
+
*sk = NULL;
|
|
705
|
+
return 0;
|
|
703
706
|
}
|
|
704
707
|
|
|
705
|
-
void X509_email_free(STACK_OF(OPENSSL_STRING) *sk)
|
|
706
|
-
|
|
707
|
-
sk_OPENSSL_STRING_pop_free(sk, str_free);
|
|
708
|
+
void X509_email_free(STACK_OF(OPENSSL_STRING) *sk) {
|
|
709
|
+
sk_OPENSSL_STRING_pop_free(sk, str_free);
|
|
708
710
|
}
|
|
709
711
|
|
|
710
|
-
typedef int (*equal_fn)
|
|
711
|
-
|
|
712
|
-
|
|
712
|
+
typedef int (*equal_fn)(const unsigned char *pattern, size_t pattern_len,
|
|
713
|
+
const unsigned char *subject, size_t subject_len,
|
|
714
|
+
unsigned int flags);
|
|
713
715
|
|
|
714
|
-
|
|
716
|
+
// Compare while ASCII ignoring case.
|
|
715
717
|
static int equal_nocase(const unsigned char *pattern, size_t pattern_len,
|
|
716
718
|
const unsigned char *subject, size_t subject_len,
|
|
717
|
-
unsigned int flags)
|
|
718
|
-
{
|
|
719
|
-
|
|
719
|
+
unsigned int flags) {
|
|
720
|
+
if (pattern_len != subject_len) {
|
|
721
|
+
return 0;
|
|
722
|
+
}
|
|
723
|
+
while (pattern_len) {
|
|
724
|
+
unsigned char l = *pattern;
|
|
725
|
+
unsigned char r = *subject;
|
|
726
|
+
// The pattern must not contain NUL characters.
|
|
727
|
+
if (l == 0) {
|
|
728
|
+
return 0;
|
|
729
|
+
}
|
|
730
|
+
if (l != r) {
|
|
731
|
+
if ('A' <= l && l <= 'Z') {
|
|
732
|
+
l = (l - 'A') + 'a';
|
|
733
|
+
}
|
|
734
|
+
if ('A' <= r && r <= 'Z') {
|
|
735
|
+
r = (r - 'A') + 'a';
|
|
736
|
+
}
|
|
737
|
+
if (l != r) {
|
|
720
738
|
return 0;
|
|
721
|
-
|
|
722
|
-
unsigned char l = *pattern;
|
|
723
|
-
unsigned char r = *subject;
|
|
724
|
-
/* The pattern must not contain NUL characters. */
|
|
725
|
-
if (l == 0)
|
|
726
|
-
return 0;
|
|
727
|
-
if (l != r) {
|
|
728
|
-
if ('A' <= l && l <= 'Z')
|
|
729
|
-
l = (l - 'A') + 'a';
|
|
730
|
-
if ('A' <= r && r <= 'Z')
|
|
731
|
-
r = (r - 'A') + 'a';
|
|
732
|
-
if (l != r)
|
|
733
|
-
return 0;
|
|
734
|
-
}
|
|
735
|
-
++pattern;
|
|
736
|
-
++subject;
|
|
737
|
-
--pattern_len;
|
|
739
|
+
}
|
|
738
740
|
}
|
|
739
|
-
|
|
741
|
+
++pattern;
|
|
742
|
+
++subject;
|
|
743
|
+
--pattern_len;
|
|
744
|
+
}
|
|
745
|
+
return 1;
|
|
740
746
|
}
|
|
741
747
|
|
|
742
|
-
|
|
748
|
+
// Compare using OPENSSL_memcmp.
|
|
743
749
|
static int equal_case(const unsigned char *pattern, size_t pattern_len,
|
|
744
750
|
const unsigned char *subject, size_t subject_len,
|
|
745
|
-
unsigned int flags)
|
|
746
|
-
{
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
751
|
+
unsigned int flags) {
|
|
752
|
+
if (pattern_len != subject_len) {
|
|
753
|
+
return 0;
|
|
754
|
+
}
|
|
755
|
+
return !OPENSSL_memcmp(pattern, subject, pattern_len);
|
|
750
756
|
}
|
|
751
757
|
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
* case-insensitive manner.
|
|
755
|
-
*/
|
|
758
|
+
// RFC 5280, section 7.5, requires that only the domain is compared in a
|
|
759
|
+
// case-insensitive manner.
|
|
756
760
|
static int equal_email(const unsigned char *a, size_t a_len,
|
|
757
761
|
const unsigned char *b, size_t b_len,
|
|
758
|
-
unsigned int unused_flags)
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
+
unsigned int unused_flags) {
|
|
763
|
+
size_t i = a_len;
|
|
764
|
+
if (a_len != b_len) {
|
|
765
|
+
return 0;
|
|
766
|
+
}
|
|
767
|
+
// We search backwards for the '@' character, so that we do not have to
|
|
768
|
+
// deal with quoted local-parts. The domain part is compared in a
|
|
769
|
+
// case-insensitive manner.
|
|
770
|
+
while (i > 0) {
|
|
771
|
+
--i;
|
|
772
|
+
if (a[i] == '@' || b[i] == '@') {
|
|
773
|
+
if (!equal_nocase(a + i, a_len - i, b + i, a_len - i, 0)) {
|
|
762
774
|
return 0;
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
* deal with quoted local-parts. The domain part is compared in a
|
|
766
|
-
* case-insensitive manner.
|
|
767
|
-
*/
|
|
768
|
-
while (i > 0) {
|
|
769
|
-
--i;
|
|
770
|
-
if (a[i] == '@' || b[i] == '@') {
|
|
771
|
-
if (!equal_nocase(a + i, a_len - i, b + i, a_len - i, 0))
|
|
772
|
-
return 0;
|
|
773
|
-
break;
|
|
774
|
-
}
|
|
775
|
+
}
|
|
776
|
+
break;
|
|
775
777
|
}
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
778
|
+
}
|
|
779
|
+
if (i == 0) {
|
|
780
|
+
i = a_len;
|
|
781
|
+
}
|
|
782
|
+
return equal_case(a, i, b, i, 0);
|
|
779
783
|
}
|
|
780
784
|
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
* characters in-between are valid.
|
|
784
|
-
*/
|
|
785
|
+
// Compare the prefix and suffix with the subject, and check that the
|
|
786
|
+
// characters in-between are valid.
|
|
785
787
|
static int wildcard_match(const unsigned char *prefix, size_t prefix_len,
|
|
786
788
|
const unsigned char *suffix, size_t suffix_len,
|
|
787
789
|
const unsigned char *subject, size_t subject_len,
|
|
788
|
-
unsigned int flags)
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
allow_idna = 1;
|
|
790
|
+
unsigned int flags) {
|
|
791
|
+
const unsigned char *wildcard_start;
|
|
792
|
+
const unsigned char *wildcard_end;
|
|
793
|
+
const unsigned char *p;
|
|
794
|
+
int allow_idna = 0;
|
|
795
|
+
|
|
796
|
+
if (subject_len < prefix_len + suffix_len) {
|
|
797
|
+
return 0;
|
|
798
|
+
}
|
|
799
|
+
if (!equal_nocase(prefix, prefix_len, subject, prefix_len, flags)) {
|
|
800
|
+
return 0;
|
|
801
|
+
}
|
|
802
|
+
wildcard_start = subject + prefix_len;
|
|
803
|
+
wildcard_end = subject + (subject_len - suffix_len);
|
|
804
|
+
if (!equal_nocase(wildcard_end, suffix_len, suffix, suffix_len, flags)) {
|
|
805
|
+
return 0;
|
|
806
|
+
}
|
|
807
|
+
// If the wildcard makes up the entire first label, it must match at
|
|
808
|
+
// least one character.
|
|
809
|
+
if (prefix_len == 0 && *suffix == '.') {
|
|
810
|
+
if (wildcard_start == wildcard_end) {
|
|
811
|
+
return 0;
|
|
811
812
|
}
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
* Check that the part matched by the wildcard contains only
|
|
822
|
-
* permitted characters and only matches a single label.
|
|
823
|
-
*/
|
|
824
|
-
for (p = wildcard_start; p != wildcard_end; ++p)
|
|
825
|
-
if (!(('0' <= *p && *p <= '9') ||
|
|
826
|
-
('A' <= *p && *p <= 'Z') ||
|
|
827
|
-
('a' <= *p && *p <= 'z') ||
|
|
828
|
-
*p == '-'))
|
|
829
|
-
return 0;
|
|
813
|
+
allow_idna = 1;
|
|
814
|
+
}
|
|
815
|
+
// IDNA labels cannot match partial wildcards
|
|
816
|
+
if (!allow_idna && subject_len >= 4 &&
|
|
817
|
+
OPENSSL_strncasecmp((char *)subject, "xn--", 4) == 0) {
|
|
818
|
+
return 0;
|
|
819
|
+
}
|
|
820
|
+
// The wildcard may match a literal '*'
|
|
821
|
+
if (wildcard_end == wildcard_start + 1 && *wildcard_start == '*') {
|
|
830
822
|
return 1;
|
|
823
|
+
}
|
|
824
|
+
// Check that the part matched by the wildcard contains only
|
|
825
|
+
// permitted characters and only matches a single label.
|
|
826
|
+
for (p = wildcard_start; p != wildcard_end; ++p) {
|
|
827
|
+
if (!(('0' <= *p && *p <= '9') || ('A' <= *p && *p <= 'Z') ||
|
|
828
|
+
('a' <= *p && *p <= 'z') || *p == '-')) {
|
|
829
|
+
return 0;
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
return 1;
|
|
831
833
|
}
|
|
832
834
|
|
|
833
|
-
#define LABEL_START
|
|
834
|
-
#define LABEL_END
|
|
835
|
-
#define LABEL_HYPHEN
|
|
836
|
-
#define LABEL_IDNA
|
|
835
|
+
#define LABEL_START (1 << 0)
|
|
836
|
+
#define LABEL_END (1 << 1)
|
|
837
|
+
#define LABEL_HYPHEN (1 << 2)
|
|
838
|
+
#define LABEL_IDNA (1 << 3)
|
|
837
839
|
|
|
838
840
|
static const unsigned char *valid_star(const unsigned char *p, size_t len,
|
|
839
|
-
unsigned int flags)
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
} else
|
|
884
|
-
return NULL;
|
|
841
|
+
unsigned int flags) {
|
|
842
|
+
const unsigned char *star = 0;
|
|
843
|
+
size_t i;
|
|
844
|
+
int state = LABEL_START;
|
|
845
|
+
int dots = 0;
|
|
846
|
+
for (i = 0; i < len; ++i) {
|
|
847
|
+
// Locate first and only legal wildcard, either at the start
|
|
848
|
+
// or end of a non-IDNA first and not final label.
|
|
849
|
+
if (p[i] == '*') {
|
|
850
|
+
int atstart = (state & LABEL_START);
|
|
851
|
+
int atend = (i == len - 1 || p[i + 1] == '.');
|
|
852
|
+
// At most one wildcard per pattern.
|
|
853
|
+
// No wildcards in IDNA labels.
|
|
854
|
+
// No wildcards after the first label.
|
|
855
|
+
if (star != NULL || (state & LABEL_IDNA) != 0 || dots) {
|
|
856
|
+
return NULL;
|
|
857
|
+
}
|
|
858
|
+
// Only full-label '*.example.com' wildcards.
|
|
859
|
+
if (!atstart || !atend) {
|
|
860
|
+
return NULL;
|
|
861
|
+
}
|
|
862
|
+
star = &p[i];
|
|
863
|
+
state &= ~LABEL_START;
|
|
864
|
+
} else if (('a' <= p[i] && p[i] <= 'z') || ('A' <= p[i] && p[i] <= 'Z') ||
|
|
865
|
+
('0' <= p[i] && p[i] <= '9')) {
|
|
866
|
+
if ((state & LABEL_START) != 0 && len - i >= 4 &&
|
|
867
|
+
OPENSSL_strncasecmp((char *)&p[i], "xn--", 4) == 0) {
|
|
868
|
+
state |= LABEL_IDNA;
|
|
869
|
+
}
|
|
870
|
+
state &= ~(LABEL_HYPHEN | LABEL_START);
|
|
871
|
+
} else if (p[i] == '.') {
|
|
872
|
+
if ((state & (LABEL_HYPHEN | LABEL_START)) != 0) {
|
|
873
|
+
return NULL;
|
|
874
|
+
}
|
|
875
|
+
state = LABEL_START;
|
|
876
|
+
++dots;
|
|
877
|
+
} else if (p[i] == '-') {
|
|
878
|
+
// no domain/subdomain starts with '-'
|
|
879
|
+
if ((state & LABEL_START) != 0) {
|
|
880
|
+
return NULL;
|
|
881
|
+
}
|
|
882
|
+
state |= LABEL_HYPHEN;
|
|
883
|
+
} else {
|
|
884
|
+
return NULL;
|
|
885
885
|
}
|
|
886
|
+
}
|
|
886
887
|
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
return star;
|
|
888
|
+
// The final label must not end in a hyphen or ".", and
|
|
889
|
+
// there must be at least two dots after the star.
|
|
890
|
+
if ((state & (LABEL_START | LABEL_HYPHEN)) != 0 || dots < 2) {
|
|
891
|
+
return NULL;
|
|
892
|
+
}
|
|
893
|
+
return star;
|
|
894
894
|
}
|
|
895
895
|
|
|
896
|
-
|
|
896
|
+
// Compare using wildcards.
|
|
897
897
|
static int equal_wildcard(const unsigned char *pattern, size_t pattern_len,
|
|
898
898
|
const unsigned char *subject, size_t subject_len,
|
|
899
|
-
unsigned int flags)
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
star + 1, (pattern + pattern_len) - star - 1,
|
|
914
|
-
subject, subject_len, flags);
|
|
899
|
+
unsigned int flags) {
|
|
900
|
+
const unsigned char *star = NULL;
|
|
901
|
+
|
|
902
|
+
// Subject names starting with '.' can only match a wildcard pattern
|
|
903
|
+
// via a subject sub-domain pattern suffix match.
|
|
904
|
+
if (!(subject_len > 1 && subject[0] == '.')) {
|
|
905
|
+
star = valid_star(pattern, pattern_len, flags);
|
|
906
|
+
}
|
|
907
|
+
if (star == NULL) {
|
|
908
|
+
return equal_nocase(pattern, pattern_len, subject, subject_len, flags);
|
|
909
|
+
}
|
|
910
|
+
return wildcard_match(pattern, star - pattern, star + 1,
|
|
911
|
+
(pattern + pattern_len) - star - 1, subject,
|
|
912
|
+
subject_len, flags);
|
|
915
913
|
}
|
|
916
914
|
|
|
917
915
|
int x509v3_looks_like_dns_name(const unsigned char *in, size_t len) {
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
916
|
+
// This function is used as a heuristic for whether a common name is a
|
|
917
|
+
// hostname to be matched, or merely a decorative name to describe the
|
|
918
|
+
// subject. This heuristic must be applied to both name constraints and the
|
|
919
|
+
// common name fallback, so it must be loose enough to accept hostname
|
|
920
|
+
// common names, and tight enough to reject decorative common names.
|
|
921
|
+
|
|
922
|
+
if (len > 0 && in[len - 1] == '.') {
|
|
923
|
+
len--;
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
// Wildcards are allowed in front.
|
|
927
|
+
if (len >= 2 && in[0] == '*' && in[1] == '.') {
|
|
928
|
+
in += 2;
|
|
929
|
+
len -= 2;
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
if (len == 0) {
|
|
933
|
+
return 0;
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
size_t label_start = 0;
|
|
937
|
+
for (size_t i = 0; i < len; i++) {
|
|
938
|
+
unsigned char c = in[i];
|
|
939
|
+
if ((c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') ||
|
|
940
|
+
(c >= 'A' && c <= 'Z') || (c == '-' && i > label_start) ||
|
|
941
|
+
// These are not valid characters in hostnames, but commonly found
|
|
942
|
+
// in deployments outside the Web PKI.
|
|
943
|
+
c == '_' || c == ':') {
|
|
944
|
+
continue;
|
|
932
945
|
}
|
|
933
946
|
|
|
934
|
-
|
|
935
|
-
|
|
947
|
+
// Labels must not be empty.
|
|
948
|
+
if (c == '.' && i > label_start && i < len - 1) {
|
|
949
|
+
label_start = i + 1;
|
|
950
|
+
continue;
|
|
936
951
|
}
|
|
937
952
|
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
unsigned char c = in[i];
|
|
941
|
-
if ((c >= 'a' && c <= 'z') ||
|
|
942
|
-
(c >= '0' && c <= '9') ||
|
|
943
|
-
(c >= 'A' && c <= 'Z') ||
|
|
944
|
-
(c == '-' && i > label_start) ||
|
|
945
|
-
/* These are not valid characters in hostnames, but commonly found
|
|
946
|
-
* in deployments outside the Web PKI. */
|
|
947
|
-
c == '_' ||
|
|
948
|
-
c == ':') {
|
|
949
|
-
continue;
|
|
950
|
-
}
|
|
951
|
-
|
|
952
|
-
/* Labels must not be empty. */
|
|
953
|
-
if (c == '.' && i > label_start && i < len - 1) {
|
|
954
|
-
label_start = i + 1;
|
|
955
|
-
continue;
|
|
956
|
-
}
|
|
957
|
-
|
|
958
|
-
return 0;
|
|
959
|
-
}
|
|
953
|
+
return 0;
|
|
954
|
+
}
|
|
960
955
|
|
|
961
|
-
|
|
956
|
+
return 1;
|
|
962
957
|
}
|
|
963
958
|
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
* to UTF8.
|
|
968
|
-
*/
|
|
959
|
+
// Compare an ASN1_STRING to a supplied string. If they match return 1. If
|
|
960
|
+
// cmp_type > 0 only compare if string matches the type, otherwise convert it
|
|
961
|
+
// to UTF8.
|
|
969
962
|
|
|
970
963
|
static int do_check_string(ASN1_STRING *a, int cmp_type, equal_fn equal,
|
|
971
964
|
unsigned int flags, int check_type, const char *b,
|
|
972
|
-
size_t blen, char **peername)
|
|
973
|
-
|
|
974
|
-
int rv = 0;
|
|
965
|
+
size_t blen, char **peername) {
|
|
966
|
+
int rv = 0;
|
|
975
967
|
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
968
|
+
if (!a->data || !a->length) {
|
|
969
|
+
return 0;
|
|
970
|
+
}
|
|
971
|
+
if (cmp_type > 0) {
|
|
972
|
+
if (cmp_type != a->type) {
|
|
973
|
+
return 0;
|
|
974
|
+
}
|
|
975
|
+
if (cmp_type == V_ASN1_IA5STRING) {
|
|
976
|
+
rv = equal(a->data, a->length, (unsigned char *)b, blen, flags);
|
|
977
|
+
} else if (a->length == (int)blen && !OPENSSL_memcmp(a->data, b, blen)) {
|
|
978
|
+
rv = 1;
|
|
979
|
+
}
|
|
980
|
+
if (rv > 0 && peername) {
|
|
981
|
+
*peername = OPENSSL_strndup((char *)a->data, a->length);
|
|
982
|
+
}
|
|
983
|
+
} else {
|
|
984
|
+
int astrlen;
|
|
985
|
+
unsigned char *astr;
|
|
986
|
+
astrlen = ASN1_STRING_to_UTF8(&astr, a);
|
|
987
|
+
if (astrlen < 0) {
|
|
988
|
+
return -1;
|
|
989
|
+
}
|
|
990
|
+
// We check the common name against DNS name constraints if it passes
|
|
991
|
+
// |x509v3_looks_like_dns_name|. Thus we must not consider common names
|
|
992
|
+
// for DNS fallbacks if they fail this check.
|
|
993
|
+
if (check_type == GEN_DNS && !x509v3_looks_like_dns_name(astr, astrlen)) {
|
|
994
|
+
rv = 0;
|
|
987
995
|
} else {
|
|
988
|
-
|
|
989
|
-
unsigned char *astr;
|
|
990
|
-
astrlen = ASN1_STRING_to_UTF8(&astr, a);
|
|
991
|
-
if (astrlen < 0)
|
|
992
|
-
return -1;
|
|
993
|
-
/*
|
|
994
|
-
* We check the common name against DNS name constraints if it passes
|
|
995
|
-
* |x509v3_looks_like_dns_name|. Thus we must not consider common names
|
|
996
|
-
* for DNS fallbacks if they fail this check.
|
|
997
|
-
*/
|
|
998
|
-
if (check_type == GEN_DNS &&
|
|
999
|
-
!x509v3_looks_like_dns_name(astr, astrlen)) {
|
|
1000
|
-
rv = 0;
|
|
1001
|
-
} else {
|
|
1002
|
-
rv = equal(astr, astrlen, (unsigned char *)b, blen, flags);
|
|
1003
|
-
}
|
|
1004
|
-
if (rv > 0 && peername)
|
|
1005
|
-
*peername = OPENSSL_strndup((char *)astr, astrlen);
|
|
1006
|
-
OPENSSL_free(astr);
|
|
996
|
+
rv = equal(astr, astrlen, (unsigned char *)b, blen, flags);
|
|
1007
997
|
}
|
|
1008
|
-
|
|
998
|
+
if (rv > 0 && peername) {
|
|
999
|
+
*peername = OPENSSL_strndup((char *)astr, astrlen);
|
|
1000
|
+
}
|
|
1001
|
+
OPENSSL_free(astr);
|
|
1002
|
+
}
|
|
1003
|
+
return rv;
|
|
1009
1004
|
}
|
|
1010
1005
|
|
|
1011
1006
|
static int do_x509_check(X509 *x, const char *chk, size_t chklen,
|
|
1012
|
-
unsigned int flags, int check_type, char **peername)
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
equal = equal_nocase;
|
|
1032
|
-
else
|
|
1033
|
-
equal = equal_wildcard;
|
|
1007
|
+
unsigned int flags, int check_type, char **peername) {
|
|
1008
|
+
GENERAL_NAMES *gens = NULL;
|
|
1009
|
+
X509_NAME *name = NULL;
|
|
1010
|
+
size_t i;
|
|
1011
|
+
int j;
|
|
1012
|
+
int cnid = NID_undef;
|
|
1013
|
+
int alt_type;
|
|
1014
|
+
int rv = 0;
|
|
1015
|
+
equal_fn equal;
|
|
1016
|
+
|
|
1017
|
+
if (check_type == GEN_EMAIL) {
|
|
1018
|
+
cnid = NID_pkcs9_emailAddress;
|
|
1019
|
+
alt_type = V_ASN1_IA5STRING;
|
|
1020
|
+
equal = equal_email;
|
|
1021
|
+
} else if (check_type == GEN_DNS) {
|
|
1022
|
+
cnid = NID_commonName;
|
|
1023
|
+
alt_type = V_ASN1_IA5STRING;
|
|
1024
|
+
if (flags & X509_CHECK_FLAG_NO_WILDCARDS) {
|
|
1025
|
+
equal = equal_nocase;
|
|
1034
1026
|
} else {
|
|
1035
|
-
|
|
1036
|
-
equal = equal_case;
|
|
1027
|
+
equal = equal_wildcard;
|
|
1037
1028
|
}
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1029
|
+
} else {
|
|
1030
|
+
alt_type = V_ASN1_OCTET_STRING;
|
|
1031
|
+
equal = equal_case;
|
|
1032
|
+
}
|
|
1033
|
+
|
|
1034
|
+
gens = X509_get_ext_d2i(x, NID_subject_alt_name, NULL, NULL);
|
|
1035
|
+
if (gens) {
|
|
1036
|
+
for (i = 0; i < sk_GENERAL_NAME_num(gens); i++) {
|
|
1037
|
+
GENERAL_NAME *gen;
|
|
1038
|
+
ASN1_STRING *cstr;
|
|
1039
|
+
gen = sk_GENERAL_NAME_value(gens, i);
|
|
1040
|
+
if (gen->type != check_type) {
|
|
1041
|
+
continue;
|
|
1042
|
+
}
|
|
1043
|
+
if (check_type == GEN_EMAIL) {
|
|
1044
|
+
cstr = gen->d.rfc822Name;
|
|
1045
|
+
} else if (check_type == GEN_DNS) {
|
|
1046
|
+
cstr = gen->d.dNSName;
|
|
1047
|
+
} else {
|
|
1048
|
+
cstr = gen->d.iPAddress;
|
|
1049
|
+
}
|
|
1050
|
+
// Positive on success, negative on error!
|
|
1051
|
+
if ((rv = do_check_string(cstr, alt_type, equal, flags, check_type, chk,
|
|
1052
|
+
chklen, peername)) != 0) {
|
|
1053
|
+
break;
|
|
1054
|
+
}
|
|
1060
1055
|
}
|
|
1056
|
+
GENERAL_NAMES_free(gens);
|
|
1057
|
+
return rv;
|
|
1058
|
+
}
|
|
1061
1059
|
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1060
|
+
// We're done if CN-ID is not pertinent
|
|
1061
|
+
if (cnid == NID_undef || (flags & X509_CHECK_FLAG_NEVER_CHECK_SUBJECT)) {
|
|
1062
|
+
return 0;
|
|
1063
|
+
}
|
|
1065
1064
|
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1065
|
+
j = -1;
|
|
1066
|
+
name = X509_get_subject_name(x);
|
|
1067
|
+
while ((j = X509_NAME_get_index_by_NID(name, cnid, j)) >= 0) {
|
|
1068
|
+
X509_NAME_ENTRY *ne;
|
|
1069
|
+
ASN1_STRING *str;
|
|
1070
|
+
ne = X509_NAME_get_entry(name, j);
|
|
1071
|
+
str = X509_NAME_ENTRY_get_data(ne);
|
|
1072
|
+
// Positive on success, negative on error!
|
|
1073
|
+
if ((rv = do_check_string(str, -1, equal, flags, check_type, chk, chklen,
|
|
1074
|
+
peername)) != 0) {
|
|
1075
|
+
return rv;
|
|
1077
1076
|
}
|
|
1078
|
-
|
|
1077
|
+
}
|
|
1078
|
+
return 0;
|
|
1079
1079
|
}
|
|
1080
1080
|
|
|
1081
|
-
int X509_check_host(X509 *x, const char *chk, size_t chklen,
|
|
1082
|
-
|
|
1083
|
-
{
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1081
|
+
int X509_check_host(X509 *x, const char *chk, size_t chklen, unsigned int flags,
|
|
1082
|
+
char **peername) {
|
|
1083
|
+
if (chk == NULL) {
|
|
1084
|
+
return -2;
|
|
1085
|
+
}
|
|
1086
|
+
if (OPENSSL_memchr(chk, '\0', chklen)) {
|
|
1087
|
+
return -2;
|
|
1088
|
+
}
|
|
1089
|
+
return do_x509_check(x, chk, chklen, flags, GEN_DNS, peername);
|
|
1089
1090
|
}
|
|
1090
1091
|
|
|
1091
1092
|
int X509_check_email(X509 *x, const char *chk, size_t chklen,
|
|
1092
|
-
unsigned int flags)
|
|
1093
|
-
{
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1093
|
+
unsigned int flags) {
|
|
1094
|
+
if (chk == NULL) {
|
|
1095
|
+
return -2;
|
|
1096
|
+
}
|
|
1097
|
+
if (OPENSSL_memchr(chk, '\0', chklen)) {
|
|
1098
|
+
return -2;
|
|
1099
|
+
}
|
|
1100
|
+
return do_x509_check(x, chk, chklen, flags, GEN_EMAIL, NULL);
|
|
1099
1101
|
}
|
|
1100
1102
|
|
|
1101
1103
|
int X509_check_ip(X509 *x, const unsigned char *chk, size_t chklen,
|
|
1102
|
-
unsigned int flags)
|
|
1103
|
-
{
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1104
|
+
unsigned int flags) {
|
|
1105
|
+
if (chk == NULL) {
|
|
1106
|
+
return -2;
|
|
1107
|
+
}
|
|
1108
|
+
return do_x509_check(x, (char *)chk, chklen, flags, GEN_IPADD, NULL);
|
|
1107
1109
|
}
|
|
1108
1110
|
|
|
1109
|
-
int X509_check_ip_asc(X509 *x, const char *ipasc, unsigned int flags)
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1111
|
+
int X509_check_ip_asc(X509 *x, const char *ipasc, unsigned int flags) {
|
|
1112
|
+
unsigned char ipout[16];
|
|
1113
|
+
size_t iplen;
|
|
1114
|
+
|
|
1115
|
+
if (ipasc == NULL) {
|
|
1116
|
+
return -2;
|
|
1117
|
+
}
|
|
1118
|
+
iplen = (size_t)x509v3_a2i_ipadd(ipout, ipasc);
|
|
1119
|
+
if (iplen == 0) {
|
|
1120
|
+
return -2;
|
|
1121
|
+
}
|
|
1122
|
+
return do_x509_check(x, (char *)ipout, iplen, flags, GEN_IPADD, NULL);
|
|
1120
1123
|
}
|
|
1121
1124
|
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
* with RFC 3280.
|
|
1125
|
-
*/
|
|
1125
|
+
// Convert IP addresses both IPv4 and IPv6 into an OCTET STRING compatible
|
|
1126
|
+
// with RFC 3280.
|
|
1126
1127
|
|
|
1127
|
-
ASN1_OCTET_STRING *a2i_IPADDRESS(const char *ipasc)
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
int iplen;
|
|
1128
|
+
ASN1_OCTET_STRING *a2i_IPADDRESS(const char *ipasc) {
|
|
1129
|
+
unsigned char ipout[16];
|
|
1130
|
+
ASN1_OCTET_STRING *ret;
|
|
1131
|
+
int iplen;
|
|
1132
1132
|
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1133
|
+
iplen = x509v3_a2i_ipadd(ipout, ipasc);
|
|
1134
|
+
if (!iplen) {
|
|
1135
|
+
return NULL;
|
|
1136
|
+
}
|
|
1136
1137
|
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1138
|
+
ret = ASN1_OCTET_STRING_new();
|
|
1139
|
+
if (!ret) {
|
|
1140
|
+
return NULL;
|
|
1141
|
+
}
|
|
1142
|
+
if (!ASN1_OCTET_STRING_set(ret, ipout, iplen)) {
|
|
1143
|
+
ASN1_OCTET_STRING_free(ret);
|
|
1144
|
+
return NULL;
|
|
1145
|
+
}
|
|
1146
|
+
return ret;
|
|
1145
1147
|
}
|
|
1146
1148
|
|
|
1147
|
-
ASN1_OCTET_STRING *a2i_IPADDRESS_NC(const char *ipasc)
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1149
|
+
ASN1_OCTET_STRING *a2i_IPADDRESS_NC(const char *ipasc) {
|
|
1150
|
+
ASN1_OCTET_STRING *ret = NULL;
|
|
1151
|
+
unsigned char ipout[32];
|
|
1152
|
+
char *iptmp = NULL, *p;
|
|
1153
|
+
int iplen1, iplen2;
|
|
1154
|
+
p = strchr(ipasc, '/');
|
|
1155
|
+
if (!p) {
|
|
1156
|
+
return NULL;
|
|
1157
|
+
}
|
|
1158
|
+
iptmp = OPENSSL_strdup(ipasc);
|
|
1159
|
+
if (!iptmp) {
|
|
1160
|
+
return NULL;
|
|
1161
|
+
}
|
|
1162
|
+
p = iptmp + (p - ipasc);
|
|
1163
|
+
*p++ = 0;
|
|
1161
1164
|
|
|
1162
|
-
|
|
1165
|
+
iplen1 = x509v3_a2i_ipadd(ipout, iptmp);
|
|
1163
1166
|
|
|
1164
|
-
|
|
1165
|
-
|
|
1167
|
+
if (!iplen1) {
|
|
1168
|
+
goto err;
|
|
1169
|
+
}
|
|
1166
1170
|
|
|
1167
|
-
|
|
1171
|
+
iplen2 = x509v3_a2i_ipadd(ipout + iplen1, p);
|
|
1168
1172
|
|
|
1169
|
-
|
|
1170
|
-
|
|
1173
|
+
OPENSSL_free(iptmp);
|
|
1174
|
+
iptmp = NULL;
|
|
1171
1175
|
|
|
1172
|
-
|
|
1173
|
-
|
|
1176
|
+
if (!iplen2 || (iplen1 != iplen2)) {
|
|
1177
|
+
goto err;
|
|
1178
|
+
}
|
|
1174
1179
|
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
+
ret = ASN1_OCTET_STRING_new();
|
|
1181
|
+
if (!ret) {
|
|
1182
|
+
goto err;
|
|
1183
|
+
}
|
|
1184
|
+
if (!ASN1_OCTET_STRING_set(ret, ipout, iplen1 + iplen2)) {
|
|
1185
|
+
goto err;
|
|
1186
|
+
}
|
|
1180
1187
|
|
|
1181
|
-
|
|
1188
|
+
return ret;
|
|
1182
1189
|
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1190
|
+
err:
|
|
1191
|
+
if (iptmp) {
|
|
1192
|
+
OPENSSL_free(iptmp);
|
|
1193
|
+
}
|
|
1194
|
+
if (ret) {
|
|
1195
|
+
ASN1_OCTET_STRING_free(ret);
|
|
1196
|
+
}
|
|
1197
|
+
return NULL;
|
|
1189
1198
|
}
|
|
1190
1199
|
|
|
1191
|
-
int x509v3_a2i_ipadd(unsigned char ipout[16], const char *ipasc)
|
|
1192
|
-
|
|
1193
|
-
/* If string contains a ':' assume IPv6 */
|
|
1200
|
+
int x509v3_a2i_ipadd(unsigned char ipout[16], const char *ipasc) {
|
|
1201
|
+
// If string contains a ':' assume IPv6
|
|
1194
1202
|
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
return 16;
|
|
1199
|
-
} else {
|
|
1200
|
-
if (!ipv4_from_asc(ipout, ipasc))
|
|
1201
|
-
return 0;
|
|
1202
|
-
return 4;
|
|
1203
|
+
if (strchr(ipasc, ':')) {
|
|
1204
|
+
if (!ipv6_from_asc(ipout, ipasc)) {
|
|
1205
|
+
return 0;
|
|
1203
1206
|
}
|
|
1207
|
+
return 16;
|
|
1208
|
+
} else {
|
|
1209
|
+
if (!ipv4_from_asc(ipout, ipasc)) {
|
|
1210
|
+
return 0;
|
|
1211
|
+
}
|
|
1212
|
+
return 4;
|
|
1213
|
+
}
|
|
1204
1214
|
}
|
|
1205
1215
|
|
|
1206
|
-
static int ipv4_from_asc(unsigned char v4[4], const char *in)
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1216
|
+
static int ipv4_from_asc(unsigned char v4[4], const char *in) {
|
|
1217
|
+
int a0, a1, a2, a3;
|
|
1218
|
+
if (sscanf(in, "%d.%d.%d.%d", &a0, &a1, &a2, &a3) != 4) {
|
|
1219
|
+
return 0;
|
|
1220
|
+
}
|
|
1221
|
+
if ((a0 < 0) || (a0 > 255) || (a1 < 0) || (a1 > 255) || (a2 < 0) ||
|
|
1222
|
+
(a2 > 255) || (a3 < 0) || (a3 > 255)) {
|
|
1223
|
+
return 0;
|
|
1224
|
+
}
|
|
1225
|
+
v4[0] = a0;
|
|
1226
|
+
v4[1] = a1;
|
|
1227
|
+
v4[2] = a2;
|
|
1228
|
+
v4[3] = a3;
|
|
1229
|
+
return 1;
|
|
1219
1230
|
}
|
|
1220
1231
|
|
|
1221
1232
|
typedef struct {
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1233
|
+
// Temporary store for IPV6 output
|
|
1234
|
+
unsigned char tmp[16];
|
|
1235
|
+
// Total number of bytes in tmp
|
|
1236
|
+
int total;
|
|
1237
|
+
// The position of a zero (corresponding to '::')
|
|
1238
|
+
int zero_pos;
|
|
1239
|
+
// Number of zeroes
|
|
1240
|
+
int zero_cnt;
|
|
1230
1241
|
} IPV6_STAT;
|
|
1231
1242
|
|
|
1232
|
-
static int ipv6_from_asc(unsigned char v6[16], const char *in)
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
if (!CONF_parse_list(in, ':', 0, ipv6_cb, &v6stat))
|
|
1244
|
-
return 0;
|
|
1243
|
+
static int ipv6_from_asc(unsigned char v6[16], const char *in) {
|
|
1244
|
+
IPV6_STAT v6stat;
|
|
1245
|
+
v6stat.total = 0;
|
|
1246
|
+
v6stat.zero_pos = -1;
|
|
1247
|
+
v6stat.zero_cnt = 0;
|
|
1248
|
+
// Treat the IPv6 representation as a list of values separated by ':'.
|
|
1249
|
+
// The presence of a '::' will parse as one, two or three zero length
|
|
1250
|
+
// elements.
|
|
1251
|
+
if (!CONF_parse_list(in, ':', 0, ipv6_cb, &v6stat)) {
|
|
1252
|
+
return 0;
|
|
1253
|
+
}
|
|
1245
1254
|
|
|
1246
|
-
|
|
1255
|
+
// Now for some sanity checks
|
|
1247
1256
|
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
} else {
|
|
1253
|
-
/* If '::' must have less than 16 bytes */
|
|
1254
|
-
if (v6stat.total == 16)
|
|
1255
|
-
return 0;
|
|
1256
|
-
/* More than three zeroes is an error */
|
|
1257
|
-
if (v6stat.zero_cnt > 3)
|
|
1258
|
-
return 0;
|
|
1259
|
-
/* Can only have three zeroes if nothing else present */
|
|
1260
|
-
else if (v6stat.zero_cnt == 3) {
|
|
1261
|
-
if (v6stat.total > 0)
|
|
1262
|
-
return 0;
|
|
1263
|
-
}
|
|
1264
|
-
/* Can only have two zeroes if at start or end */
|
|
1265
|
-
else if (v6stat.zero_cnt == 2) {
|
|
1266
|
-
if ((v6stat.zero_pos != 0)
|
|
1267
|
-
&& (v6stat.zero_pos != v6stat.total))
|
|
1268
|
-
return 0;
|
|
1269
|
-
} else
|
|
1270
|
-
/* Can only have one zero if *not* start or end */
|
|
1271
|
-
{
|
|
1272
|
-
if ((v6stat.zero_pos == 0)
|
|
1273
|
-
|| (v6stat.zero_pos == v6stat.total))
|
|
1274
|
-
return 0;
|
|
1275
|
-
}
|
|
1257
|
+
if (v6stat.zero_pos == -1) {
|
|
1258
|
+
// If no '::' must have exactly 16 bytes
|
|
1259
|
+
if (v6stat.total != 16) {
|
|
1260
|
+
return 0;
|
|
1276
1261
|
}
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1262
|
+
} else {
|
|
1263
|
+
// If '::' must have less than 16 bytes
|
|
1264
|
+
if (v6stat.total == 16) {
|
|
1265
|
+
return 0;
|
|
1266
|
+
}
|
|
1267
|
+
// More than three zeroes is an error
|
|
1268
|
+
if (v6stat.zero_cnt > 3) {
|
|
1269
|
+
return 0;
|
|
1270
|
+
}
|
|
1271
|
+
// Can only have three zeroes if nothing else present
|
|
1272
|
+
else if (v6stat.zero_cnt == 3) {
|
|
1273
|
+
if (v6stat.total > 0) {
|
|
1274
|
+
return 0;
|
|
1275
|
+
}
|
|
1276
|
+
}
|
|
1277
|
+
// Can only have two zeroes if at start or end
|
|
1278
|
+
else if (v6stat.zero_cnt == 2) {
|
|
1279
|
+
if ((v6stat.zero_pos != 0) && (v6stat.zero_pos != v6stat.total)) {
|
|
1280
|
+
return 0;
|
|
1281
|
+
}
|
|
1290
1282
|
} else
|
|
1291
|
-
|
|
1283
|
+
// Can only have one zero if *not* start or end
|
|
1284
|
+
{
|
|
1285
|
+
if ((v6stat.zero_pos == 0) || (v6stat.zero_pos == v6stat.total)) {
|
|
1286
|
+
return 0;
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
1289
|
+
}
|
|
1290
|
+
|
|
1291
|
+
// Format result
|
|
1292
|
+
|
|
1293
|
+
if (v6stat.zero_pos >= 0) {
|
|
1294
|
+
// Copy initial part
|
|
1295
|
+
OPENSSL_memcpy(v6, v6stat.tmp, v6stat.zero_pos);
|
|
1296
|
+
// Zero middle
|
|
1297
|
+
OPENSSL_memset(v6 + v6stat.zero_pos, 0, 16 - v6stat.total);
|
|
1298
|
+
// Copy final part
|
|
1299
|
+
if (v6stat.total != v6stat.zero_pos) {
|
|
1300
|
+
OPENSSL_memcpy(v6 + v6stat.zero_pos + 16 - v6stat.total,
|
|
1301
|
+
v6stat.tmp + v6stat.zero_pos,
|
|
1302
|
+
v6stat.total - v6stat.zero_pos);
|
|
1303
|
+
}
|
|
1304
|
+
} else {
|
|
1305
|
+
OPENSSL_memcpy(v6, v6stat.tmp, 16);
|
|
1306
|
+
}
|
|
1292
1307
|
|
|
1293
|
-
|
|
1308
|
+
return 1;
|
|
1294
1309
|
}
|
|
1295
1310
|
|
|
1296
|
-
static int ipv6_cb(const char *elem, int len, void *usr)
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1311
|
+
static int ipv6_cb(const char *elem, int len, void *usr) {
|
|
1312
|
+
IPV6_STAT *s = usr;
|
|
1313
|
+
// Error if 16 bytes written
|
|
1314
|
+
if (s->total == 16) {
|
|
1315
|
+
return 0;
|
|
1316
|
+
}
|
|
1317
|
+
if (len == 0) {
|
|
1318
|
+
// Zero length element, corresponds to '::'
|
|
1319
|
+
if (s->zero_pos == -1) {
|
|
1320
|
+
s->zero_pos = s->total;
|
|
1321
|
+
}
|
|
1322
|
+
// If we've already got a :: its an error
|
|
1323
|
+
else if (s->zero_pos != s->total) {
|
|
1324
|
+
return 0;
|
|
1325
|
+
}
|
|
1326
|
+
s->zero_cnt++;
|
|
1327
|
+
} else {
|
|
1328
|
+
// If more than 4 characters could be final a.b.c.d form
|
|
1329
|
+
if (len > 4) {
|
|
1330
|
+
// Need at least 4 bytes left
|
|
1331
|
+
if (s->total > 12) {
|
|
1332
|
+
return 0;
|
|
1333
|
+
}
|
|
1334
|
+
// Must be end of string
|
|
1335
|
+
if (elem[len]) {
|
|
1336
|
+
return 0;
|
|
1337
|
+
}
|
|
1338
|
+
if (!ipv4_from_asc(s->tmp + s->total, elem)) {
|
|
1301
1339
|
return 0;
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
if (s->zero_pos == -1)
|
|
1305
|
-
s->zero_pos = s->total;
|
|
1306
|
-
/* If we've already got a :: its an error */
|
|
1307
|
-
else if (s->zero_pos != s->total)
|
|
1308
|
-
return 0;
|
|
1309
|
-
s->zero_cnt++;
|
|
1340
|
+
}
|
|
1341
|
+
s->total += 4;
|
|
1310
1342
|
} else {
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
return 0;
|
|
1316
|
-
/* Must be end of string */
|
|
1317
|
-
if (elem[len])
|
|
1318
|
-
return 0;
|
|
1319
|
-
if (!ipv4_from_asc(s->tmp + s->total, elem))
|
|
1320
|
-
return 0;
|
|
1321
|
-
s->total += 4;
|
|
1322
|
-
} else {
|
|
1323
|
-
if (!ipv6_hex(s->tmp + s->total, elem, len))
|
|
1324
|
-
return 0;
|
|
1325
|
-
s->total += 2;
|
|
1326
|
-
}
|
|
1343
|
+
if (!ipv6_hex(s->tmp + s->total, elem, len)) {
|
|
1344
|
+
return 0;
|
|
1345
|
+
}
|
|
1346
|
+
s->total += 2;
|
|
1327
1347
|
}
|
|
1328
|
-
|
|
1348
|
+
}
|
|
1349
|
+
return 1;
|
|
1329
1350
|
}
|
|
1330
1351
|
|
|
1331
|
-
|
|
1332
|
-
* Convert a string of up to 4 hex digits into the corresponding IPv6 form.
|
|
1333
|
-
*/
|
|
1352
|
+
// Convert a string of up to 4 hex digits into the corresponding IPv6 form.
|
|
1334
1353
|
|
|
1335
|
-
static int ipv6_hex(unsigned char *out, const char *in, int inlen)
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1354
|
+
static int ipv6_hex(unsigned char *out, const char *in, int inlen) {
|
|
1355
|
+
unsigned char c;
|
|
1356
|
+
unsigned int num = 0;
|
|
1357
|
+
if (inlen > 4) {
|
|
1358
|
+
return 0;
|
|
1359
|
+
}
|
|
1360
|
+
while (inlen--) {
|
|
1361
|
+
c = *in++;
|
|
1362
|
+
num <<= 4;
|
|
1363
|
+
if ((c >= '0') && (c <= '9')) {
|
|
1364
|
+
num |= c - '0';
|
|
1365
|
+
} else if ((c >= 'A') && (c <= 'F')) {
|
|
1366
|
+
num |= c - 'A' + 10;
|
|
1367
|
+
} else if ((c >= 'a') && (c <= 'f')) {
|
|
1368
|
+
num |= c - 'a' + 10;
|
|
1369
|
+
} else {
|
|
1370
|
+
return 0;
|
|
1352
1371
|
}
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1372
|
+
}
|
|
1373
|
+
out[0] = num >> 8;
|
|
1374
|
+
out[1] = num & 0xff;
|
|
1375
|
+
return 1;
|
|
1356
1376
|
}
|
|
1357
1377
|
|
|
1358
|
-
int X509V3_NAME_from_section(X509_NAME *nm, STACK_OF
|
|
1359
|
-
unsigned long chtype)
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
}
|
|
1381
|
-
if (*type == '+') {
|
|
1382
|
-
mval = -1;
|
|
1383
|
-
type++;
|
|
1384
|
-
} else
|
|
1385
|
-
mval = 0;
|
|
1386
|
-
if (!X509_NAME_add_entry_by_txt(nm, type, chtype,
|
|
1387
|
-
(unsigned char *)v->value, -1, -1,
|
|
1388
|
-
mval))
|
|
1389
|
-
return 0;
|
|
1390
|
-
|
|
1378
|
+
int X509V3_NAME_from_section(X509_NAME *nm, STACK_OF(CONF_VALUE) *dn_sk,
|
|
1379
|
+
unsigned long chtype) {
|
|
1380
|
+
CONF_VALUE *v;
|
|
1381
|
+
int mval;
|
|
1382
|
+
size_t i;
|
|
1383
|
+
char *p, *type;
|
|
1384
|
+
if (!nm) {
|
|
1385
|
+
return 0;
|
|
1386
|
+
}
|
|
1387
|
+
|
|
1388
|
+
for (i = 0; i < sk_CONF_VALUE_num(dn_sk); i++) {
|
|
1389
|
+
v = sk_CONF_VALUE_value(dn_sk, i);
|
|
1390
|
+
type = v->name;
|
|
1391
|
+
// Skip past any leading X. X: X, etc to allow for multiple instances
|
|
1392
|
+
for (p = type; *p; p++) {
|
|
1393
|
+
if ((*p == ':') || (*p == ',') || (*p == '.')) {
|
|
1394
|
+
p++;
|
|
1395
|
+
if (*p) {
|
|
1396
|
+
type = p;
|
|
1397
|
+
}
|
|
1398
|
+
break;
|
|
1399
|
+
}
|
|
1391
1400
|
}
|
|
1392
|
-
|
|
1401
|
+
if (*type == '+') {
|
|
1402
|
+
mval = -1;
|
|
1403
|
+
type++;
|
|
1404
|
+
} else {
|
|
1405
|
+
mval = 0;
|
|
1406
|
+
}
|
|
1407
|
+
if (!X509_NAME_add_entry_by_txt(nm, type, chtype, (unsigned char *)v->value,
|
|
1408
|
+
-1, -1, mval)) {
|
|
1409
|
+
return 0;
|
|
1410
|
+
}
|
|
1411
|
+
}
|
|
1412
|
+
return 1;
|
|
1393
1413
|
}
|