@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
|
@@ -74,696 +74,727 @@
|
|
|
74
74
|
#include "../internal.h"
|
|
75
75
|
|
|
76
76
|
|
|
77
|
-
#define MIN_LENGTH
|
|
77
|
+
#define MIN_LENGTH 4
|
|
78
78
|
|
|
79
79
|
static int load_iv(char **fromp, unsigned char *to, int num);
|
|
80
80
|
static int check_pem(const char *nm, const char *name);
|
|
81
81
|
|
|
82
|
-
void PEM_proc_type(char *buf, int type)
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
82
|
+
void PEM_proc_type(char *buf, int type) {
|
|
83
|
+
const char *str;
|
|
84
|
+
|
|
85
|
+
if (type == PEM_TYPE_ENCRYPTED) {
|
|
86
|
+
str = "ENCRYPTED";
|
|
87
|
+
} else if (type == PEM_TYPE_MIC_CLEAR) {
|
|
88
|
+
str = "MIC-CLEAR";
|
|
89
|
+
} else if (type == PEM_TYPE_MIC_ONLY) {
|
|
90
|
+
str = "MIC-ONLY";
|
|
91
|
+
} else {
|
|
92
|
+
str = "BAD-TYPE";
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
OPENSSL_strlcat(buf, "Proc-Type: 4,", PEM_BUFSIZE);
|
|
96
|
+
OPENSSL_strlcat(buf, str, PEM_BUFSIZE);
|
|
97
|
+
OPENSSL_strlcat(buf, "\n", PEM_BUFSIZE);
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
-
void PEM_dek_info(char *buf, const char *type, int len, char *str)
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
100
|
+
void PEM_dek_info(char *buf, const char *type, int len, char *str) {
|
|
101
|
+
static const unsigned char map[17] = "0123456789ABCDEF";
|
|
102
|
+
long i;
|
|
103
|
+
int j;
|
|
104
|
+
|
|
105
|
+
OPENSSL_strlcat(buf, "DEK-Info: ", PEM_BUFSIZE);
|
|
106
|
+
OPENSSL_strlcat(buf, type, PEM_BUFSIZE);
|
|
107
|
+
OPENSSL_strlcat(buf, ",", PEM_BUFSIZE);
|
|
108
|
+
j = strlen(buf);
|
|
109
|
+
if (j + (len * 2) + 1 > PEM_BUFSIZE) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
for (i = 0; i < len; i++) {
|
|
113
|
+
buf[j + i * 2] = map[(str[i] >> 4) & 0x0f];
|
|
114
|
+
buf[j + i * 2 + 1] = map[(str[i]) & 0x0f];
|
|
115
|
+
}
|
|
116
|
+
buf[j + i * 2] = '\n';
|
|
117
|
+
buf[j + i * 2 + 1] = '\0';
|
|
118
118
|
}
|
|
119
119
|
|
|
120
120
|
void *PEM_ASN1_read(d2i_of_void *d2i, const char *name, FILE *fp, void **x,
|
|
121
|
-
pem_password_cb *cb, void *u)
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
return ret;
|
|
121
|
+
pem_password_cb *cb, void *u) {
|
|
122
|
+
BIO *b = BIO_new_fp(fp, BIO_NOCLOSE);
|
|
123
|
+
if (b == NULL) {
|
|
124
|
+
OPENSSL_PUT_ERROR(PEM, ERR_R_BUF_LIB);
|
|
125
|
+
return NULL;
|
|
126
|
+
}
|
|
127
|
+
void *ret = PEM_ASN1_read_bio(d2i, name, b, x, cb, u);
|
|
128
|
+
BIO_free(b);
|
|
129
|
+
return ret;
|
|
131
130
|
}
|
|
132
131
|
|
|
133
|
-
static int check_pem(const char *nm, const char *name)
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
132
|
+
static int check_pem(const char *nm, const char *name) {
|
|
133
|
+
// Normal matching nm and name
|
|
134
|
+
if (!strcmp(nm, name)) {
|
|
135
|
+
return 1;
|
|
136
|
+
}
|
|
138
137
|
|
|
139
|
-
|
|
138
|
+
// Make PEM_STRING_EVP_PKEY match any private key
|
|
140
139
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
!strcmp(nm, PEM_STRING_DSA);
|
|
147
|
-
}
|
|
140
|
+
if (!strcmp(name, PEM_STRING_EVP_PKEY)) {
|
|
141
|
+
return !strcmp(nm, PEM_STRING_PKCS8) || !strcmp(nm, PEM_STRING_PKCS8INF) ||
|
|
142
|
+
!strcmp(nm, PEM_STRING_RSA) || !strcmp(nm, PEM_STRING_EC) ||
|
|
143
|
+
!strcmp(nm, PEM_STRING_DSA);
|
|
144
|
+
}
|
|
148
145
|
|
|
149
|
-
|
|
146
|
+
// Permit older strings
|
|
150
147
|
|
|
151
|
-
|
|
152
|
-
|
|
148
|
+
if (!strcmp(nm, PEM_STRING_X509_OLD) && !strcmp(name, PEM_STRING_X509)) {
|
|
149
|
+
return 1;
|
|
150
|
+
}
|
|
153
151
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
152
|
+
if (!strcmp(nm, PEM_STRING_X509_REQ_OLD) &&
|
|
153
|
+
!strcmp(name, PEM_STRING_X509_REQ)) {
|
|
154
|
+
return 1;
|
|
155
|
+
}
|
|
157
156
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
157
|
+
// Allow normal certs to be read as trusted certs
|
|
158
|
+
if (!strcmp(nm, PEM_STRING_X509) && !strcmp(name, PEM_STRING_X509_TRUSTED)) {
|
|
159
|
+
return 1;
|
|
160
|
+
}
|
|
162
161
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
162
|
+
if (!strcmp(nm, PEM_STRING_X509_OLD) &&
|
|
163
|
+
!strcmp(name, PEM_STRING_X509_TRUSTED)) {
|
|
164
|
+
return 1;
|
|
165
|
+
}
|
|
166
166
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
167
|
+
// Some CAs use PKCS#7 with CERTIFICATE headers
|
|
168
|
+
if (!strcmp(nm, PEM_STRING_X509) && !strcmp(name, PEM_STRING_PKCS7)) {
|
|
169
|
+
return 1;
|
|
170
|
+
}
|
|
170
171
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
172
|
+
if (!strcmp(nm, PEM_STRING_PKCS7_SIGNED) && !strcmp(name, PEM_STRING_PKCS7)) {
|
|
173
|
+
return 1;
|
|
174
|
+
}
|
|
174
175
|
|
|
175
176
|
#ifndef OPENSSL_NO_CMS
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
177
|
+
if (!strcmp(nm, PEM_STRING_X509) && !strcmp(name, PEM_STRING_CMS)) {
|
|
178
|
+
return 1;
|
|
179
|
+
}
|
|
180
|
+
// Allow CMS to be read from PKCS#7 headers
|
|
181
|
+
if (!strcmp(nm, PEM_STRING_PKCS7) && !strcmp(name, PEM_STRING_CMS)) {
|
|
182
|
+
return 1;
|
|
183
|
+
}
|
|
181
184
|
#endif
|
|
182
185
|
|
|
183
|
-
|
|
186
|
+
return 0;
|
|
184
187
|
}
|
|
185
188
|
|
|
186
|
-
static const EVP_CIPHER *cipher_by_name(const char *name)
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
}
|
|
189
|
+
static const EVP_CIPHER *cipher_by_name(const char *name) {
|
|
190
|
+
// This is similar to the (deprecated) function |EVP_get_cipherbyname|. Note
|
|
191
|
+
// the PEM code assumes that ciphers have at least 8 bytes of IV, at most 20
|
|
192
|
+
// bytes of overhead and generally behave like CBC mode.
|
|
193
|
+
if (0 == strcmp(name, SN_des_cbc)) {
|
|
194
|
+
return EVP_des_cbc();
|
|
195
|
+
} else if (0 == strcmp(name, SN_des_ede3_cbc)) {
|
|
196
|
+
return EVP_des_ede3_cbc();
|
|
197
|
+
} else if (0 == strcmp(name, SN_aes_128_cbc)) {
|
|
198
|
+
return EVP_aes_128_cbc();
|
|
199
|
+
} else if (0 == strcmp(name, SN_aes_192_cbc)) {
|
|
200
|
+
return EVP_aes_192_cbc();
|
|
201
|
+
} else if (0 == strcmp(name, SN_aes_256_cbc)) {
|
|
202
|
+
return EVP_aes_256_cbc();
|
|
203
|
+
} else {
|
|
204
|
+
return NULL;
|
|
205
|
+
}
|
|
204
206
|
}
|
|
205
207
|
|
|
206
208
|
int PEM_bytes_read_bio(unsigned char **pdata, long *plen, char **pnm,
|
|
207
209
|
const char *name, BIO *bp, pem_password_cb *cb,
|
|
208
|
-
void *u)
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
OPENSSL_free(header);
|
|
229
|
-
OPENSSL_free(data);
|
|
230
|
-
}
|
|
231
|
-
if (!PEM_get_EVP_CIPHER_INFO(header, &cipher))
|
|
232
|
-
goto err;
|
|
233
|
-
if (!PEM_do_header(&cipher, data, &len, cb, u))
|
|
234
|
-
goto err;
|
|
235
|
-
|
|
236
|
-
*pdata = data;
|
|
237
|
-
*plen = len;
|
|
238
|
-
|
|
239
|
-
if (pnm)
|
|
240
|
-
*pnm = nm;
|
|
241
|
-
|
|
242
|
-
ret = 1;
|
|
243
|
-
|
|
244
|
-
err:
|
|
245
|
-
if (!ret || !pnm)
|
|
246
|
-
OPENSSL_free(nm);
|
|
210
|
+
void *u) {
|
|
211
|
+
EVP_CIPHER_INFO cipher;
|
|
212
|
+
char *nm = NULL, *header = NULL;
|
|
213
|
+
unsigned char *data = NULL;
|
|
214
|
+
long len;
|
|
215
|
+
int ret = 0;
|
|
216
|
+
|
|
217
|
+
for (;;) {
|
|
218
|
+
if (!PEM_read_bio(bp, &nm, &header, &data, &len)) {
|
|
219
|
+
uint32_t error = ERR_peek_error();
|
|
220
|
+
if (ERR_GET_LIB(error) == ERR_LIB_PEM &&
|
|
221
|
+
ERR_GET_REASON(error) == PEM_R_NO_START_LINE) {
|
|
222
|
+
ERR_add_error_data(2, "Expecting: ", name);
|
|
223
|
+
}
|
|
224
|
+
return 0;
|
|
225
|
+
}
|
|
226
|
+
if (check_pem(nm, name)) {
|
|
227
|
+
break;
|
|
228
|
+
}
|
|
229
|
+
OPENSSL_free(nm);
|
|
247
230
|
OPENSSL_free(header);
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
231
|
+
OPENSSL_free(data);
|
|
232
|
+
}
|
|
233
|
+
if (!PEM_get_EVP_CIPHER_INFO(header, &cipher)) {
|
|
234
|
+
goto err;
|
|
235
|
+
}
|
|
236
|
+
if (!PEM_do_header(&cipher, data, &len, cb, u)) {
|
|
237
|
+
goto err;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
*pdata = data;
|
|
241
|
+
*plen = len;
|
|
242
|
+
|
|
243
|
+
if (pnm) {
|
|
244
|
+
*pnm = nm;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
ret = 1;
|
|
248
|
+
|
|
249
|
+
err:
|
|
250
|
+
if (!ret || !pnm) {
|
|
251
|
+
OPENSSL_free(nm);
|
|
252
|
+
}
|
|
253
|
+
OPENSSL_free(header);
|
|
254
|
+
if (!ret) {
|
|
255
|
+
OPENSSL_free(data);
|
|
256
|
+
}
|
|
257
|
+
return ret;
|
|
251
258
|
}
|
|
252
259
|
|
|
253
|
-
int PEM_ASN1_write(i2d_of_void *i2d, const char *name, FILE *fp,
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
return ret;
|
|
260
|
+
int PEM_ASN1_write(i2d_of_void *i2d, const char *name, FILE *fp, void *x,
|
|
261
|
+
const EVP_CIPHER *enc, unsigned char *kstr, int klen,
|
|
262
|
+
pem_password_cb *callback, void *u) {
|
|
263
|
+
BIO *b = BIO_new_fp(fp, BIO_NOCLOSE);
|
|
264
|
+
if (b == NULL) {
|
|
265
|
+
OPENSSL_PUT_ERROR(PEM, ERR_R_BUF_LIB);
|
|
266
|
+
return 0;
|
|
267
|
+
}
|
|
268
|
+
int ret = PEM_ASN1_write_bio(i2d, name, b, x, enc, kstr, klen, callback, u);
|
|
269
|
+
BIO_free(b);
|
|
270
|
+
return ret;
|
|
265
271
|
}
|
|
266
272
|
|
|
267
|
-
int PEM_ASN1_write_bio(i2d_of_void *i2d, const char *name, BIO *bp,
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
273
|
+
int PEM_ASN1_write_bio(i2d_of_void *i2d, const char *name, BIO *bp, void *x,
|
|
274
|
+
const EVP_CIPHER *enc, unsigned char *kstr, int klen,
|
|
275
|
+
pem_password_cb *callback, void *u) {
|
|
276
|
+
EVP_CIPHER_CTX ctx;
|
|
277
|
+
int dsize = 0, i, j, ret = 0;
|
|
278
|
+
unsigned char *p, *data = NULL;
|
|
279
|
+
const char *objstr = NULL;
|
|
280
|
+
char buf[PEM_BUFSIZE];
|
|
281
|
+
unsigned char key[EVP_MAX_KEY_LENGTH];
|
|
282
|
+
unsigned char iv[EVP_MAX_IV_LENGTH];
|
|
283
|
+
|
|
284
|
+
if (enc != NULL) {
|
|
285
|
+
objstr = OBJ_nid2sn(EVP_CIPHER_nid(enc));
|
|
286
|
+
if (objstr == NULL || cipher_by_name(objstr) == NULL ||
|
|
287
|
+
EVP_CIPHER_iv_length(enc) < 8) {
|
|
288
|
+
OPENSSL_PUT_ERROR(PEM, PEM_R_UNSUPPORTED_CIPHER);
|
|
289
|
+
goto err;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
if ((dsize = i2d(x, NULL)) < 0) {
|
|
294
|
+
OPENSSL_PUT_ERROR(PEM, ERR_R_ASN1_LIB);
|
|
295
|
+
dsize = 0;
|
|
296
|
+
goto err;
|
|
297
|
+
}
|
|
298
|
+
// dzise + 8 bytes are needed
|
|
299
|
+
// actually it needs the cipher block size extra...
|
|
300
|
+
data = (unsigned char *)OPENSSL_malloc((unsigned int)dsize + 20);
|
|
301
|
+
if (data == NULL) {
|
|
302
|
+
OPENSSL_PUT_ERROR(PEM, ERR_R_MALLOC_FAILURE);
|
|
303
|
+
goto err;
|
|
304
|
+
}
|
|
305
|
+
p = data;
|
|
306
|
+
i = i2d(x, &p);
|
|
307
|
+
|
|
308
|
+
if (enc != NULL) {
|
|
309
|
+
const unsigned iv_len = EVP_CIPHER_iv_length(enc);
|
|
310
|
+
|
|
311
|
+
if (kstr == NULL) {
|
|
312
|
+
klen = 0;
|
|
313
|
+
if (!callback) {
|
|
314
|
+
callback = PEM_def_callback;
|
|
315
|
+
}
|
|
316
|
+
klen = (*callback)(buf, PEM_BUFSIZE, 1, u);
|
|
317
|
+
if (klen <= 0) {
|
|
318
|
+
OPENSSL_PUT_ERROR(PEM, PEM_R_READ_KEY);
|
|
292
319
|
goto err;
|
|
320
|
+
}
|
|
321
|
+
kstr = (unsigned char *)buf;
|
|
293
322
|
}
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
323
|
+
assert(iv_len <= (int)sizeof(iv));
|
|
324
|
+
if (!RAND_bytes(iv, iv_len)) { // Generate a salt
|
|
325
|
+
goto err;
|
|
326
|
+
}
|
|
327
|
+
// The 'iv' is used as the iv and as a salt. It is NOT taken from
|
|
328
|
+
// the BytesToKey function
|
|
329
|
+
if (!EVP_BytesToKey(enc, EVP_md5(), iv, kstr, klen, 1, key, NULL)) {
|
|
330
|
+
goto err;
|
|
300
331
|
}
|
|
301
|
-
p = data;
|
|
302
|
-
i = i2d(x, &p);
|
|
303
|
-
|
|
304
|
-
if (enc != NULL) {
|
|
305
|
-
const unsigned iv_len = EVP_CIPHER_iv_length(enc);
|
|
306
|
-
|
|
307
|
-
if (kstr == NULL) {
|
|
308
|
-
klen = 0;
|
|
309
|
-
if (!callback)
|
|
310
|
-
callback = PEM_def_callback;
|
|
311
|
-
klen = (*callback) (buf, PEM_BUFSIZE, 1, u);
|
|
312
|
-
if (klen <= 0) {
|
|
313
|
-
OPENSSL_PUT_ERROR(PEM, PEM_R_READ_KEY);
|
|
314
|
-
goto err;
|
|
315
|
-
}
|
|
316
|
-
kstr = (unsigned char *)buf;
|
|
317
|
-
}
|
|
318
|
-
assert(iv_len <= (int)sizeof(iv));
|
|
319
|
-
if (!RAND_bytes(iv, iv_len)) /* Generate a salt */
|
|
320
|
-
goto err;
|
|
321
|
-
/*
|
|
322
|
-
* The 'iv' is used as the iv and as a salt. It is NOT taken from
|
|
323
|
-
* the BytesToKey function
|
|
324
|
-
*/
|
|
325
|
-
if (!EVP_BytesToKey(enc, EVP_md5(), iv, kstr, klen, 1, key, NULL))
|
|
326
|
-
goto err;
|
|
327
332
|
|
|
328
|
-
|
|
329
|
-
|
|
333
|
+
if (kstr == (unsigned char *)buf) {
|
|
334
|
+
OPENSSL_cleanse(buf, PEM_BUFSIZE);
|
|
335
|
+
}
|
|
330
336
|
|
|
331
|
-
|
|
337
|
+
assert(strlen(objstr) + 23 + 2 * iv_len + 13 <= sizeof buf);
|
|
332
338
|
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
else
|
|
345
|
-
i += j;
|
|
346
|
-
EVP_CIPHER_CTX_cleanup(&ctx);
|
|
347
|
-
if (ret == 0)
|
|
348
|
-
goto err;
|
|
339
|
+
buf[0] = '\0';
|
|
340
|
+
PEM_proc_type(buf, PEM_TYPE_ENCRYPTED);
|
|
341
|
+
PEM_dek_info(buf, objstr, iv_len, (char *)iv);
|
|
342
|
+
// k=strlen(buf);
|
|
343
|
+
|
|
344
|
+
EVP_CIPHER_CTX_init(&ctx);
|
|
345
|
+
ret = 1;
|
|
346
|
+
if (!EVP_EncryptInit_ex(&ctx, enc, NULL, key, iv) ||
|
|
347
|
+
!EVP_EncryptUpdate(&ctx, data, &j, data, i) ||
|
|
348
|
+
!EVP_EncryptFinal_ex(&ctx, &(data[j]), &i)) {
|
|
349
|
+
ret = 0;
|
|
349
350
|
} else {
|
|
350
|
-
|
|
351
|
-
buf[0] = '\0';
|
|
351
|
+
i += j;
|
|
352
352
|
}
|
|
353
|
-
|
|
354
|
-
if (
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
353
|
+
EVP_CIPHER_CTX_cleanup(&ctx);
|
|
354
|
+
if (ret == 0) {
|
|
355
|
+
goto err;
|
|
356
|
+
}
|
|
357
|
+
} else {
|
|
358
|
+
ret = 1;
|
|
359
|
+
buf[0] = '\0';
|
|
360
|
+
}
|
|
361
|
+
i = PEM_write_bio(bp, name, buf, data, i);
|
|
362
|
+
if (i <= 0) {
|
|
363
|
+
ret = 0;
|
|
364
|
+
}
|
|
365
|
+
err:
|
|
366
|
+
OPENSSL_cleanse(key, sizeof(key));
|
|
367
|
+
OPENSSL_cleanse(iv, sizeof(iv));
|
|
368
|
+
OPENSSL_cleanse((char *)&ctx, sizeof(ctx));
|
|
369
|
+
OPENSSL_cleanse(buf, PEM_BUFSIZE);
|
|
370
|
+
OPENSSL_free(data);
|
|
371
|
+
return ret;
|
|
363
372
|
}
|
|
364
373
|
|
|
365
374
|
int PEM_do_header(EVP_CIPHER_INFO *cipher, unsigned char *data, long *plen,
|
|
366
|
-
pem_password_cb *callback, void *u)
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
if (!EVP_BytesToKey(cipher->cipher, EVP_md5(), &(cipher->iv[0]),
|
|
389
|
-
(unsigned char *)buf, klen, 1, key, NULL))
|
|
390
|
-
return 0;
|
|
375
|
+
pem_password_cb *callback, void *u) {
|
|
376
|
+
int i = 0, j, o, klen;
|
|
377
|
+
long len;
|
|
378
|
+
EVP_CIPHER_CTX ctx;
|
|
379
|
+
unsigned char key[EVP_MAX_KEY_LENGTH];
|
|
380
|
+
char buf[PEM_BUFSIZE];
|
|
381
|
+
|
|
382
|
+
len = *plen;
|
|
383
|
+
|
|
384
|
+
if (cipher->cipher == NULL) {
|
|
385
|
+
return 1;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
klen = 0;
|
|
389
|
+
if (!callback) {
|
|
390
|
+
callback = PEM_def_callback;
|
|
391
|
+
}
|
|
392
|
+
klen = callback(buf, PEM_BUFSIZE, 0, u);
|
|
393
|
+
if (klen <= 0) {
|
|
394
|
+
OPENSSL_PUT_ERROR(PEM, PEM_R_BAD_PASSWORD_READ);
|
|
395
|
+
return 0;
|
|
396
|
+
}
|
|
391
397
|
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
398
|
+
if (!EVP_BytesToKey(cipher->cipher, EVP_md5(), &(cipher->iv[0]),
|
|
399
|
+
(unsigned char *)buf, klen, 1, key, NULL)) {
|
|
400
|
+
return 0;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
j = (int)len;
|
|
404
|
+
EVP_CIPHER_CTX_init(&ctx);
|
|
405
|
+
o = EVP_DecryptInit_ex(&ctx, cipher->cipher, NULL, key, &(cipher->iv[0]));
|
|
406
|
+
if (o) {
|
|
407
|
+
o = EVP_DecryptUpdate(&ctx, data, &i, data, j);
|
|
408
|
+
}
|
|
409
|
+
if (o) {
|
|
410
|
+
o = EVP_DecryptFinal_ex(&ctx, &(data[i]), &j);
|
|
411
|
+
}
|
|
412
|
+
EVP_CIPHER_CTX_cleanup(&ctx);
|
|
413
|
+
OPENSSL_cleanse((char *)buf, sizeof(buf));
|
|
414
|
+
OPENSSL_cleanse((char *)key, sizeof(key));
|
|
415
|
+
if (!o) {
|
|
416
|
+
OPENSSL_PUT_ERROR(PEM, PEM_R_BAD_DECRYPT);
|
|
417
|
+
return 0;
|
|
418
|
+
}
|
|
419
|
+
j += i;
|
|
420
|
+
*plen = j;
|
|
421
|
+
return 1;
|
|
409
422
|
}
|
|
410
423
|
|
|
411
|
-
int PEM_get_EVP_CIPHER_INFO(char *header, EVP_CIPHER_INFO *cipher)
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
424
|
+
int PEM_get_EVP_CIPHER_INFO(char *header, EVP_CIPHER_INFO *cipher) {
|
|
425
|
+
const EVP_CIPHER *enc = NULL;
|
|
426
|
+
char *p, c;
|
|
427
|
+
char **header_pp = &header;
|
|
428
|
+
|
|
429
|
+
cipher->cipher = NULL;
|
|
430
|
+
OPENSSL_memset(cipher->iv, 0, sizeof(cipher->iv));
|
|
431
|
+
if ((header == NULL) || (*header == '\0') || (*header == '\n')) {
|
|
432
|
+
return 1;
|
|
433
|
+
}
|
|
434
|
+
if (strncmp(header, "Proc-Type: ", 11) != 0) {
|
|
435
|
+
OPENSSL_PUT_ERROR(PEM, PEM_R_NOT_PROC_TYPE);
|
|
436
|
+
return 0;
|
|
437
|
+
}
|
|
438
|
+
header += 11;
|
|
439
|
+
if (*header != '4') {
|
|
440
|
+
return 0;
|
|
441
|
+
}
|
|
442
|
+
header++;
|
|
443
|
+
if (*header != ',') {
|
|
444
|
+
return 0;
|
|
445
|
+
}
|
|
446
|
+
header++;
|
|
447
|
+
if (strncmp(header, "ENCRYPTED", 9) != 0) {
|
|
448
|
+
OPENSSL_PUT_ERROR(PEM, PEM_R_NOT_ENCRYPTED);
|
|
449
|
+
return 0;
|
|
450
|
+
}
|
|
451
|
+
for (; (*header != '\n') && (*header != '\0'); header++) {
|
|
452
|
+
;
|
|
453
|
+
}
|
|
454
|
+
if (*header == '\0') {
|
|
455
|
+
OPENSSL_PUT_ERROR(PEM, PEM_R_SHORT_HEADER);
|
|
456
|
+
return 0;
|
|
457
|
+
}
|
|
458
|
+
header++;
|
|
459
|
+
if (strncmp(header, "DEK-Info: ", 10) != 0) {
|
|
460
|
+
OPENSSL_PUT_ERROR(PEM, PEM_R_NOT_DEK_INFO);
|
|
461
|
+
return 0;
|
|
462
|
+
}
|
|
463
|
+
header += 10;
|
|
447
464
|
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
header++;
|
|
465
|
+
p = header;
|
|
466
|
+
for (;;) {
|
|
467
|
+
c = *header;
|
|
468
|
+
if (!(((c >= 'A') && (c <= 'Z')) || (c == '-') ||
|
|
469
|
+
((c >= '0') && (c <= '9')))) {
|
|
470
|
+
break;
|
|
455
471
|
}
|
|
456
|
-
*header = '\0';
|
|
457
|
-
cipher->cipher = enc = cipher_by_name(p);
|
|
458
|
-
*header = c;
|
|
459
472
|
header++;
|
|
473
|
+
}
|
|
474
|
+
*header = '\0';
|
|
475
|
+
cipher->cipher = enc = cipher_by_name(p);
|
|
476
|
+
*header = c;
|
|
477
|
+
header++;
|
|
478
|
+
|
|
479
|
+
if (enc == NULL) {
|
|
480
|
+
OPENSSL_PUT_ERROR(PEM, PEM_R_UNSUPPORTED_ENCRYPTION);
|
|
481
|
+
return 0;
|
|
482
|
+
}
|
|
483
|
+
// The IV parameter must be at least 8 bytes long to be used as the salt in
|
|
484
|
+
// the KDF. (This should not happen given |cipher_by_name|.)
|
|
485
|
+
if (EVP_CIPHER_iv_length(enc) < 8) {
|
|
486
|
+
assert(0);
|
|
487
|
+
OPENSSL_PUT_ERROR(PEM, PEM_R_UNSUPPORTED_ENCRYPTION);
|
|
488
|
+
return 0;
|
|
489
|
+
}
|
|
490
|
+
if (!load_iv(header_pp, &(cipher->iv[0]), EVP_CIPHER_iv_length(enc))) {
|
|
491
|
+
return 0;
|
|
492
|
+
}
|
|
460
493
|
|
|
461
|
-
|
|
462
|
-
OPENSSL_PUT_ERROR(PEM, PEM_R_UNSUPPORTED_ENCRYPTION);
|
|
463
|
-
return (0);
|
|
464
|
-
}
|
|
465
|
-
// The IV parameter must be at least 8 bytes long to be used as the salt in
|
|
466
|
-
// the KDF. (This should not happen given |cipher_by_name|.)
|
|
467
|
-
if (EVP_CIPHER_iv_length(enc) < 8) {
|
|
468
|
-
assert(0);
|
|
469
|
-
OPENSSL_PUT_ERROR(PEM, PEM_R_UNSUPPORTED_ENCRYPTION);
|
|
470
|
-
return 0;
|
|
471
|
-
}
|
|
472
|
-
if (!load_iv(header_pp, &(cipher->iv[0]), EVP_CIPHER_iv_length(enc)))
|
|
473
|
-
return (0);
|
|
474
|
-
|
|
475
|
-
return (1);
|
|
494
|
+
return 1;
|
|
476
495
|
}
|
|
477
496
|
|
|
478
|
-
static int load_iv(char **fromp, unsigned char *to, int num)
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
}
|
|
498
|
-
from++;
|
|
499
|
-
to[i / 2] |= v << (long)((!(i & 1)) * 4);
|
|
497
|
+
static int load_iv(char **fromp, unsigned char *to, int num) {
|
|
498
|
+
int v, i;
|
|
499
|
+
char *from;
|
|
500
|
+
|
|
501
|
+
from = *fromp;
|
|
502
|
+
for (i = 0; i < num; i++) {
|
|
503
|
+
to[i] = 0;
|
|
504
|
+
}
|
|
505
|
+
num *= 2;
|
|
506
|
+
for (i = 0; i < num; i++) {
|
|
507
|
+
if ((*from >= '0') && (*from <= '9')) {
|
|
508
|
+
v = *from - '0';
|
|
509
|
+
} else if ((*from >= 'A') && (*from <= 'F')) {
|
|
510
|
+
v = *from - 'A' + 10;
|
|
511
|
+
} else if ((*from >= 'a') && (*from <= 'f')) {
|
|
512
|
+
v = *from - 'a' + 10;
|
|
513
|
+
} else {
|
|
514
|
+
OPENSSL_PUT_ERROR(PEM, PEM_R_BAD_IV_CHARS);
|
|
515
|
+
return 0;
|
|
500
516
|
}
|
|
517
|
+
from++;
|
|
518
|
+
to[i / 2] |= v << (long)((!(i & 1)) * 4);
|
|
519
|
+
}
|
|
501
520
|
|
|
502
|
-
|
|
503
|
-
|
|
521
|
+
*fromp = from;
|
|
522
|
+
return 1;
|
|
504
523
|
}
|
|
505
524
|
|
|
506
525
|
int PEM_write(FILE *fp, const char *name, const char *header,
|
|
507
|
-
const unsigned char *data, long len)
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
return (ret);
|
|
526
|
+
const unsigned char *data, long len) {
|
|
527
|
+
BIO *b = BIO_new_fp(fp, BIO_NOCLOSE);
|
|
528
|
+
if (b == NULL) {
|
|
529
|
+
OPENSSL_PUT_ERROR(PEM, ERR_R_BUF_LIB);
|
|
530
|
+
return 0;
|
|
531
|
+
}
|
|
532
|
+
int ret = PEM_write_bio(b, name, header, data, len);
|
|
533
|
+
BIO_free(b);
|
|
534
|
+
return ret;
|
|
517
535
|
}
|
|
518
536
|
|
|
519
537
|
int PEM_write_bio(BIO *bp, const char *name, const char *header,
|
|
520
|
-
const unsigned char *data, long len)
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
538
|
+
const unsigned char *data, long len) {
|
|
539
|
+
int nlen, n, i, j, outl;
|
|
540
|
+
unsigned char *buf = NULL;
|
|
541
|
+
EVP_ENCODE_CTX ctx;
|
|
542
|
+
int reason = ERR_R_BUF_LIB;
|
|
543
|
+
|
|
544
|
+
EVP_EncodeInit(&ctx);
|
|
545
|
+
nlen = strlen(name);
|
|
546
|
+
|
|
547
|
+
if ((BIO_write(bp, "-----BEGIN ", 11) != 11) ||
|
|
548
|
+
(BIO_write(bp, name, nlen) != nlen) ||
|
|
549
|
+
(BIO_write(bp, "-----\n", 6) != 6)) {
|
|
550
|
+
goto err;
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
i = strlen(header);
|
|
554
|
+
if (i > 0) {
|
|
555
|
+
if ((BIO_write(bp, header, i) != i) || (BIO_write(bp, "\n", 1) != 1)) {
|
|
556
|
+
goto err;
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
buf = OPENSSL_malloc(PEM_BUFSIZE * 8);
|
|
561
|
+
if (buf == NULL) {
|
|
562
|
+
reason = ERR_R_MALLOC_FAILURE;
|
|
563
|
+
goto err;
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
i = j = 0;
|
|
567
|
+
while (len > 0) {
|
|
568
|
+
n = (int)((len > (PEM_BUFSIZE * 5)) ? (PEM_BUFSIZE * 5) : len);
|
|
569
|
+
EVP_EncodeUpdate(&ctx, buf, &outl, &(data[j]), n);
|
|
570
|
+
if ((outl) && (BIO_write(bp, (char *)buf, outl) != outl)) {
|
|
571
|
+
goto err;
|
|
572
|
+
}
|
|
573
|
+
i += outl;
|
|
574
|
+
len -= n;
|
|
575
|
+
j += n;
|
|
576
|
+
}
|
|
577
|
+
EVP_EncodeFinal(&ctx, buf, &outl);
|
|
578
|
+
if ((outl > 0) && (BIO_write(bp, (char *)buf, outl) != outl)) {
|
|
579
|
+
goto err;
|
|
580
|
+
}
|
|
581
|
+
OPENSSL_free(buf);
|
|
582
|
+
buf = NULL;
|
|
583
|
+
if ((BIO_write(bp, "-----END ", 9) != 9) ||
|
|
584
|
+
(BIO_write(bp, name, nlen) != nlen) ||
|
|
585
|
+
(BIO_write(bp, "-----\n", 6) != 6)) {
|
|
586
|
+
goto err;
|
|
587
|
+
}
|
|
588
|
+
return i + outl;
|
|
589
|
+
err:
|
|
590
|
+
if (buf) {
|
|
560
591
|
OPENSSL_free(buf);
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
(BIO_write(bp, "-----\n", 6) != 6))
|
|
565
|
-
goto err;
|
|
566
|
-
return (i + outl);
|
|
567
|
-
err:
|
|
568
|
-
if (buf) {
|
|
569
|
-
OPENSSL_free(buf);
|
|
570
|
-
}
|
|
571
|
-
OPENSSL_PUT_ERROR(PEM, reason);
|
|
572
|
-
return (0);
|
|
592
|
+
}
|
|
593
|
+
OPENSSL_PUT_ERROR(PEM, reason);
|
|
594
|
+
return 0;
|
|
573
595
|
}
|
|
574
596
|
|
|
575
597
|
int PEM_read(FILE *fp, char **name, char **header, unsigned char **data,
|
|
576
|
-
long *len)
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
return (ret);
|
|
598
|
+
long *len) {
|
|
599
|
+
BIO *b = BIO_new_fp(fp, BIO_NOCLOSE);
|
|
600
|
+
if (b == NULL) {
|
|
601
|
+
OPENSSL_PUT_ERROR(PEM, ERR_R_BUF_LIB);
|
|
602
|
+
return 0;
|
|
603
|
+
}
|
|
604
|
+
int ret = PEM_read_bio(b, name, header, data, len);
|
|
605
|
+
BIO_free(b);
|
|
606
|
+
return ret;
|
|
586
607
|
}
|
|
587
608
|
|
|
588
609
|
int PEM_read_bio(BIO *bp, char **name, char **header, unsigned char **data,
|
|
589
|
-
long *len)
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
}
|
|
608
|
-
|
|
609
|
-
buf[254] = '\0';
|
|
610
|
-
for (;;) {
|
|
611
|
-
i = BIO_gets(bp, buf, 254);
|
|
610
|
+
long *len) {
|
|
611
|
+
EVP_ENCODE_CTX ctx;
|
|
612
|
+
int end = 0, i, k, bl = 0, hl = 0, nohead = 0;
|
|
613
|
+
char buf[256];
|
|
614
|
+
BUF_MEM *nameB;
|
|
615
|
+
BUF_MEM *headerB;
|
|
616
|
+
BUF_MEM *dataB, *tmpB;
|
|
617
|
+
|
|
618
|
+
nameB = BUF_MEM_new();
|
|
619
|
+
headerB = BUF_MEM_new();
|
|
620
|
+
dataB = BUF_MEM_new();
|
|
621
|
+
if ((nameB == NULL) || (headerB == NULL) || (dataB == NULL)) {
|
|
622
|
+
BUF_MEM_free(nameB);
|
|
623
|
+
BUF_MEM_free(headerB);
|
|
624
|
+
BUF_MEM_free(dataB);
|
|
625
|
+
OPENSSL_PUT_ERROR(PEM, ERR_R_MALLOC_FAILURE);
|
|
626
|
+
return 0;
|
|
627
|
+
}
|
|
612
628
|
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
}
|
|
629
|
+
buf[254] = '\0';
|
|
630
|
+
for (;;) {
|
|
631
|
+
i = BIO_gets(bp, buf, 254);
|
|
617
632
|
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
633
|
+
if (i <= 0) {
|
|
634
|
+
OPENSSL_PUT_ERROR(PEM, PEM_R_NO_START_LINE);
|
|
635
|
+
goto err;
|
|
636
|
+
}
|
|
622
637
|
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
if (strncmp(&(buf[11 + i - 6]), "-----\n", 6) != 0)
|
|
627
|
-
continue;
|
|
628
|
-
if (!BUF_MEM_grow(nameB, i + 9)) {
|
|
629
|
-
OPENSSL_PUT_ERROR(PEM, ERR_R_MALLOC_FAILURE);
|
|
630
|
-
goto err;
|
|
631
|
-
}
|
|
632
|
-
OPENSSL_memcpy(nameB->data, &(buf[11]), i - 6);
|
|
633
|
-
nameB->data[i - 6] = '\0';
|
|
634
|
-
break;
|
|
635
|
-
}
|
|
638
|
+
while ((i >= 0) && (buf[i] <= ' ')) {
|
|
639
|
+
i--;
|
|
636
640
|
}
|
|
637
|
-
|
|
638
|
-
|
|
641
|
+
buf[++i] = '\n';
|
|
642
|
+
buf[++i] = '\0';
|
|
643
|
+
|
|
644
|
+
if (strncmp(buf, "-----BEGIN ", 11) == 0) {
|
|
645
|
+
i = strlen(&(buf[11]));
|
|
646
|
+
|
|
647
|
+
if (strncmp(&(buf[11 + i - 6]), "-----\n", 6) != 0) {
|
|
648
|
+
continue;
|
|
649
|
+
}
|
|
650
|
+
if (!BUF_MEM_grow(nameB, i + 9)) {
|
|
639
651
|
OPENSSL_PUT_ERROR(PEM, ERR_R_MALLOC_FAILURE);
|
|
640
652
|
goto err;
|
|
641
|
-
|
|
642
|
-
|
|
653
|
+
}
|
|
654
|
+
OPENSSL_memcpy(nameB->data, &(buf[11]), i - 6);
|
|
655
|
+
nameB->data[i - 6] = '\0';
|
|
656
|
+
break;
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
hl = 0;
|
|
660
|
+
if (!BUF_MEM_grow(headerB, 256)) {
|
|
661
|
+
OPENSSL_PUT_ERROR(PEM, ERR_R_MALLOC_FAILURE);
|
|
662
|
+
goto err;
|
|
663
|
+
}
|
|
664
|
+
headerB->data[0] = '\0';
|
|
665
|
+
for (;;) {
|
|
666
|
+
i = BIO_gets(bp, buf, 254);
|
|
667
|
+
if (i <= 0) {
|
|
668
|
+
break;
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
while ((i >= 0) && (buf[i] <= ' ')) {
|
|
672
|
+
i--;
|
|
673
|
+
}
|
|
674
|
+
buf[++i] = '\n';
|
|
675
|
+
buf[++i] = '\0';
|
|
676
|
+
|
|
677
|
+
if (buf[0] == '\n') {
|
|
678
|
+
break;
|
|
679
|
+
}
|
|
680
|
+
if (!BUF_MEM_grow(headerB, hl + i + 9)) {
|
|
681
|
+
OPENSSL_PUT_ERROR(PEM, ERR_R_MALLOC_FAILURE);
|
|
682
|
+
goto err;
|
|
683
|
+
}
|
|
684
|
+
if (strncmp(buf, "-----END ", 9) == 0) {
|
|
685
|
+
nohead = 1;
|
|
686
|
+
break;
|
|
687
|
+
}
|
|
688
|
+
OPENSSL_memcpy(&(headerB->data[hl]), buf, i);
|
|
689
|
+
headerB->data[hl + i] = '\0';
|
|
690
|
+
hl += i;
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
bl = 0;
|
|
694
|
+
if (!BUF_MEM_grow(dataB, 1024)) {
|
|
695
|
+
OPENSSL_PUT_ERROR(PEM, ERR_R_MALLOC_FAILURE);
|
|
696
|
+
goto err;
|
|
697
|
+
}
|
|
698
|
+
dataB->data[0] = '\0';
|
|
699
|
+
if (!nohead) {
|
|
643
700
|
for (;;) {
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
hl += i;
|
|
666
|
-
}
|
|
667
|
-
|
|
668
|
-
bl = 0;
|
|
669
|
-
if (!BUF_MEM_grow(dataB, 1024)) {
|
|
701
|
+
i = BIO_gets(bp, buf, 254);
|
|
702
|
+
if (i <= 0) {
|
|
703
|
+
break;
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
while ((i >= 0) && (buf[i] <= ' ')) {
|
|
707
|
+
i--;
|
|
708
|
+
}
|
|
709
|
+
buf[++i] = '\n';
|
|
710
|
+
buf[++i] = '\0';
|
|
711
|
+
|
|
712
|
+
if (i != 65) {
|
|
713
|
+
end = 1;
|
|
714
|
+
}
|
|
715
|
+
if (strncmp(buf, "-----END ", 9) == 0) {
|
|
716
|
+
break;
|
|
717
|
+
}
|
|
718
|
+
if (i > 65) {
|
|
719
|
+
break;
|
|
720
|
+
}
|
|
721
|
+
if (!BUF_MEM_grow_clean(dataB, i + bl + 9)) {
|
|
670
722
|
OPENSSL_PUT_ERROR(PEM, ERR_R_MALLOC_FAILURE);
|
|
671
723
|
goto err;
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
i--;
|
|
682
|
-
buf[++i] = '\n';
|
|
683
|
-
buf[++i] = '\0';
|
|
684
|
-
|
|
685
|
-
if (i != 65)
|
|
686
|
-
end = 1;
|
|
687
|
-
if (strncmp(buf, "-----END ", 9) == 0)
|
|
688
|
-
break;
|
|
689
|
-
if (i > 65)
|
|
690
|
-
break;
|
|
691
|
-
if (!BUF_MEM_grow_clean(dataB, i + bl + 9)) {
|
|
692
|
-
OPENSSL_PUT_ERROR(PEM, ERR_R_MALLOC_FAILURE);
|
|
693
|
-
goto err;
|
|
694
|
-
}
|
|
695
|
-
OPENSSL_memcpy(&(dataB->data[bl]), buf, i);
|
|
696
|
-
dataB->data[bl + i] = '\0';
|
|
697
|
-
bl += i;
|
|
698
|
-
if (end) {
|
|
699
|
-
buf[0] = '\0';
|
|
700
|
-
i = BIO_gets(bp, buf, 254);
|
|
701
|
-
if (i <= 0)
|
|
702
|
-
break;
|
|
703
|
-
|
|
704
|
-
while ((i >= 0) && (buf[i] <= ' '))
|
|
705
|
-
i--;
|
|
706
|
-
buf[++i] = '\n';
|
|
707
|
-
buf[++i] = '\0';
|
|
708
|
-
|
|
709
|
-
break;
|
|
710
|
-
}
|
|
724
|
+
}
|
|
725
|
+
OPENSSL_memcpy(&(dataB->data[bl]), buf, i);
|
|
726
|
+
dataB->data[bl + i] = '\0';
|
|
727
|
+
bl += i;
|
|
728
|
+
if (end) {
|
|
729
|
+
buf[0] = '\0';
|
|
730
|
+
i = BIO_gets(bp, buf, 254);
|
|
731
|
+
if (i <= 0) {
|
|
732
|
+
break;
|
|
711
733
|
}
|
|
712
|
-
} else {
|
|
713
|
-
tmpB = headerB;
|
|
714
|
-
headerB = dataB;
|
|
715
|
-
dataB = tmpB;
|
|
716
|
-
bl = hl;
|
|
717
|
-
}
|
|
718
|
-
i = strlen(nameB->data);
|
|
719
|
-
if ((strncmp(buf, "-----END ", 9) != 0) ||
|
|
720
|
-
(strncmp(nameB->data, &(buf[9]), i) != 0) ||
|
|
721
|
-
(strncmp(&(buf[9 + i]), "-----\n", 6) != 0)) {
|
|
722
|
-
OPENSSL_PUT_ERROR(PEM, PEM_R_BAD_END_LINE);
|
|
723
|
-
goto err;
|
|
724
|
-
}
|
|
725
734
|
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
OPENSSL_PUT_ERROR(PEM, PEM_R_BAD_BASE64_DECODE);
|
|
732
|
-
goto err;
|
|
733
|
-
}
|
|
734
|
-
i = EVP_DecodeFinal(&ctx, (unsigned char *)&(dataB->data[bl]), &k);
|
|
735
|
-
if (i < 0) {
|
|
736
|
-
OPENSSL_PUT_ERROR(PEM, PEM_R_BAD_BASE64_DECODE);
|
|
737
|
-
goto err;
|
|
738
|
-
}
|
|
739
|
-
bl += k;
|
|
735
|
+
while ((i >= 0) && (buf[i] <= ' ')) {
|
|
736
|
+
i--;
|
|
737
|
+
}
|
|
738
|
+
buf[++i] = '\n';
|
|
739
|
+
buf[++i] = '\0';
|
|
740
740
|
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
741
|
+
break;
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
} else {
|
|
745
|
+
tmpB = headerB;
|
|
746
|
+
headerB = dataB;
|
|
747
|
+
dataB = tmpB;
|
|
748
|
+
bl = hl;
|
|
749
|
+
}
|
|
750
|
+
i = strlen(nameB->data);
|
|
751
|
+
if ((strncmp(buf, "-----END ", 9) != 0) ||
|
|
752
|
+
(strncmp(nameB->data, &(buf[9]), i) != 0) ||
|
|
753
|
+
(strncmp(&(buf[9 + i]), "-----\n", 6) != 0)) {
|
|
754
|
+
OPENSSL_PUT_ERROR(PEM, PEM_R_BAD_END_LINE);
|
|
755
|
+
goto err;
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
EVP_DecodeInit(&ctx);
|
|
759
|
+
i = EVP_DecodeUpdate(&ctx, (unsigned char *)dataB->data, &bl,
|
|
760
|
+
(unsigned char *)dataB->data, bl);
|
|
761
|
+
if (i < 0) {
|
|
762
|
+
OPENSSL_PUT_ERROR(PEM, PEM_R_BAD_BASE64_DECODE);
|
|
763
|
+
goto err;
|
|
764
|
+
}
|
|
765
|
+
i = EVP_DecodeFinal(&ctx, (unsigned char *)&(dataB->data[bl]), &k);
|
|
766
|
+
if (i < 0) {
|
|
767
|
+
OPENSSL_PUT_ERROR(PEM, PEM_R_BAD_BASE64_DECODE);
|
|
768
|
+
goto err;
|
|
769
|
+
}
|
|
770
|
+
bl += k;
|
|
771
|
+
|
|
772
|
+
if (bl == 0) {
|
|
773
|
+
goto err;
|
|
774
|
+
}
|
|
775
|
+
*name = nameB->data;
|
|
776
|
+
*header = headerB->data;
|
|
777
|
+
*data = (unsigned char *)dataB->data;
|
|
778
|
+
*len = bl;
|
|
779
|
+
OPENSSL_free(nameB);
|
|
780
|
+
OPENSSL_free(headerB);
|
|
781
|
+
OPENSSL_free(dataB);
|
|
782
|
+
return 1;
|
|
783
|
+
err:
|
|
784
|
+
BUF_MEM_free(nameB);
|
|
785
|
+
BUF_MEM_free(headerB);
|
|
786
|
+
BUF_MEM_free(dataB);
|
|
787
|
+
return 0;
|
|
756
788
|
}
|
|
757
789
|
|
|
758
|
-
int PEM_def_callback(char *buf, int size, int rwflag, void *userdata)
|
|
759
|
-
{
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
return len;
|
|
790
|
+
int PEM_def_callback(char *buf, int size, int rwflag, void *userdata) {
|
|
791
|
+
if (!buf || !userdata || size < 0) {
|
|
792
|
+
return 0;
|
|
793
|
+
}
|
|
794
|
+
size_t len = strlen((char *)userdata);
|
|
795
|
+
if (len >= (size_t)size) {
|
|
796
|
+
return 0;
|
|
797
|
+
}
|
|
798
|
+
OPENSSL_strlcpy(buf, userdata, (size_t)size);
|
|
799
|
+
return len;
|
|
769
800
|
}
|