Cryptlib/OpenSSL: update to openssl 1.1.0e

- Delete the old openssl files and use the script to copy the new files

- Add "-DNO_SYSLOG" to CFLAGS and add crypto/include to the include path

Signed-off-by: Gary Lin <glin@suse.com>
This commit is contained in:
Gary Lin 2017-03-31 16:34:14 +08:00 committed by Peter Jones
parent 4da6ac8195
commit 0f3dfc01e2
556 changed files with 40987 additions and 57572 deletions

View File

@ -1,9 +1,9 @@
EFI_INCLUDES = -I../Include -I$(EFI_INCLUDE) -I$(EFI_INCLUDE)/$(ARCH) -I$(EFI_INCLUDE)/protocol -Icrypto/asn1 -Icrypto/evp -Icrypto/modes EFI_INCLUDES = -I../Include -I$(EFI_INCLUDE) -I$(EFI_INCLUDE)/$(ARCH) -I$(EFI_INCLUDE)/protocol -Icrypto/asn1 -Icrypto/evp -Icrypto/modes -Icrypto/include
CFLAGS = -ggdb -O0 -I. -I.. -I../Include/ -Icrypto -fno-stack-protector -fno-strict-aliasing -fpic -fshort-wchar -nostdinc \ CFLAGS = -ggdb -O0 -I. -I.. -I../Include/ -Icrypto -fno-stack-protector -fno-strict-aliasing -fpic -fshort-wchar -nostdinc \
-ffreestanding -std=gnu89 -I$(shell $(CC) -print-file-name=include) \ -ffreestanding -std=gnu89 -I$(shell $(CC) -print-file-name=include) \
-Wall $(EFI_INCLUDES) -DL_ENDIAN -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE -DOPENSSL_SMALL_FOOTPRINT -DPEDANTIC -Wall $(EFI_INCLUDES) -DL_ENDIAN -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE -DNO_SYSLOG -DOPENSSL_SMALL_FOOTPRINT -DPEDANTIC
ifeq ($(ARCH),x86_64) ifeq ($(ARCH),x86_64)
CFLAGS += -mno-mmx -mno-sse -mno-red-zone -maccumulate-outgoing-args \ CFLAGS += -mno-mmx -mno-sse -mno-red-zone -maccumulate-outgoing-args \
@ -23,410 +23,316 @@ endif
LDFLAGS = -nostdlib -znocombreloc LDFLAGS = -nostdlib -znocombreloc
TARGET = libopenssl.a TARGET = libopenssl.a
OBJS = crypto/cryptlib.o \ OBJS = crypto/bio/b_print.o \
crypto/mem.o \ crypto/aes/aes_cbc.o \
crypto/mem_clr.o \ crypto/aes/aes_cfb.o \
crypto/mem_dbg.o \ crypto/aes/aes_core.o \
crypto/cversion.o \ crypto/aes/aes_ecb.o \
crypto/ex_data.o \ crypto/aes/aes_ige.o \
crypto/aes/aes_misc.o \
crypto/aes/aes_ofb.o \
crypto/aes/aes_wrap.o \
crypto/asn1/a_bitstr.o \
crypto/asn1/a_d2i_fp.o \
crypto/asn1/a_digest.o \
crypto/asn1/a_dup.o \
crypto/asn1/a_gentm.o \
crypto/asn1/a_i2d_fp.o \
crypto/asn1/a_int.o \
crypto/asn1/a_mbstr.o \
crypto/asn1/a_object.o \
crypto/asn1/a_octet.o \
crypto/asn1/a_print.o \
crypto/asn1/a_sign.o \
crypto/asn1/a_strex.o \
crypto/asn1/a_strnid.o \
crypto/asn1/a_time.o \
crypto/asn1/a_type.o \
crypto/asn1/a_utctm.o \
crypto/asn1/a_utf8.o \
crypto/asn1/a_verify.o \
crypto/asn1/ameth_lib.o \
crypto/asn1/asn1_err.o \
crypto/asn1/asn1_gen.o \
crypto/asn1/asn1_lib.o \
crypto/asn1/asn1_par.o \
crypto/asn1/asn_mime.o \
crypto/asn1/asn_moid.o \
crypto/asn1/asn_mstbl.o \
crypto/asn1/asn_pack.o \
crypto/asn1/bio_asn1.o \
crypto/asn1/bio_ndef.o \
crypto/asn1/d2i_pr.o \
crypto/asn1/d2i_pu.o \
crypto/asn1/evp_asn1.o \
crypto/asn1/f_int.o \
crypto/asn1/f_string.o \
crypto/asn1/i2d_pr.o \
crypto/asn1/i2d_pu.o \
crypto/asn1/n_pkey.o \
crypto/asn1/nsseq.o \
crypto/asn1/p5_pbe.o \
crypto/asn1/p5_pbev2.o \
crypto/asn1/p5_scrypt.o \
crypto/asn1/p8_pkey.o \
crypto/asn1/t_bitst.o \
crypto/asn1/t_pkey.o \
crypto/asn1/t_spki.o \
crypto/asn1/tasn_dec.o \
crypto/asn1/tasn_enc.o \
crypto/asn1/tasn_fre.o \
crypto/asn1/tasn_new.o \
crypto/asn1/tasn_prn.o \
crypto/asn1/tasn_scn.o \
crypto/asn1/tasn_typ.o \
crypto/asn1/tasn_utl.o \
crypto/asn1/x_algor.o \
crypto/asn1/x_bignum.o \
crypto/asn1/x_info.o \
crypto/asn1/x_long.o \
crypto/asn1/x_pkey.o \
crypto/asn1/x_sig.o \
crypto/asn1/x_spki.o \
crypto/asn1/x_val.o \
crypto/async/arch/async_null.o \
crypto/async/arch/async_posix.o \
crypto/async/arch/async_win.o \
crypto/async/async.o \
crypto/async/async_err.o \
crypto/async/async_wait.o \
crypto/bio/b_addr.o \
crypto/bio/b_dump.o \
crypto/bio/b_sock.o \
crypto/bio/b_sock2.o \
crypto/bio/bf_buff.o \
crypto/bio/bf_lbuf.o \
crypto/bio/bf_nbio.o \
crypto/bio/bf_null.o \
crypto/bio/bio_cb.o \
crypto/bio/bio_err.o \
crypto/bio/bio_lib.o \
crypto/bio/bio_meth.o \
crypto/bio/bss_acpt.o \
crypto/bio/bss_bio.o \
crypto/bio/bss_conn.o \
crypto/bio/bss_dgram.o \
crypto/bio/bss_fd.o \
crypto/bio/bss_file.o \
crypto/bio/bss_log.o \
crypto/bio/bss_mem.o \
crypto/bio/bss_null.o \
crypto/bio/bss_sock.o \
crypto/bn/bn_add.o \
crypto/bn/bn_asm.o \
crypto/bn/bn_blind.o \
crypto/bn/bn_const.o \
crypto/bn/bn_ctx.o \
crypto/bn/bn_depr.o \
crypto/bn/bn_dh.o \
crypto/bn/bn_div.o \
crypto/bn/bn_err.o \
crypto/bn/bn_exp.o \
crypto/bn/bn_exp2.o \
crypto/bn/bn_gcd.o \
crypto/bn/bn_gf2m.o \
crypto/bn/bn_intern.o \
crypto/bn/bn_kron.o \
crypto/bn/bn_lib.o \
crypto/bn/bn_mod.o \
crypto/bn/bn_mont.o \
crypto/bn/bn_mpi.o \
crypto/bn/bn_mul.o \
crypto/bn/bn_nist.o \
crypto/bn/bn_prime.o \
crypto/bn/bn_print.o \
crypto/bn/bn_rand.o \
crypto/bn/bn_recp.o \
crypto/bn/bn_shift.o \
crypto/bn/bn_sqr.o \
crypto/bn/bn_sqrt.o \
crypto/bn/bn_srp.o \
crypto/bn/bn_word.o \
crypto/bn/bn_x931p.o \
crypto/buffer/buf_err.o \
crypto/buffer/buffer.o \
crypto/cmac/cm_ameth.o \
crypto/cmac/cm_pmeth.o \
crypto/cmac/cmac.o \
crypto/comp/c_zlib.o \
crypto/comp/comp_err.o \
crypto/comp/comp_lib.o \
crypto/conf/conf_api.o \
crypto/conf/conf_def.o \
crypto/conf/conf_err.o \
crypto/conf/conf_lib.o \
crypto/conf/conf_mall.o \
crypto/conf/conf_mod.o \
crypto/conf/conf_sap.o \
crypto/cpt_err.o \ crypto/cpt_err.o \
crypto/ebcdic.o \ crypto/cryptlib.o \
crypto/uid.o \ crypto/cversion.o \
crypto/o_time.o \ crypto/des/cbc_cksm.o \
crypto/o_str.o \
crypto/o_dir.o \
crypto/o_fips.o \
crypto/o_init.o \
crypto/fips_ers.o \
crypto/md4/md4_dgst.o \
crypto/md4/md4_one.o \
crypto/md5/md5_dgst.o \
crypto/md5/md5_one.o \
crypto/sha/sha_dgst.o \
crypto/sha/sha1dgst.o \
crypto/sha/sha_one.o \
crypto/sha/sha1_one.o \
crypto/sha/sha256.o \
crypto/sha/sha512.o \
crypto/hmac/hmac.o \
crypto/hmac/hm_ameth.o \
crypto/hmac/hm_pmeth.o \
crypto/des/set_key.o \
crypto/des/ecb_enc.o \
crypto/des/cbc_enc.o \ crypto/des/cbc_enc.o \
crypto/des/ecb3_enc.o \
crypto/des/cfb64enc.o \
crypto/des/cfb64ede.o \ crypto/des/cfb64ede.o \
crypto/des/cfb64enc.o \
crypto/des/cfb_enc.o \ crypto/des/cfb_enc.o \
crypto/des/des_enc.o \
crypto/des/ecb3_enc.o \
crypto/des/ecb_enc.o \
crypto/des/fcrypt.o \
crypto/des/fcrypt_b.o \
crypto/des/ofb64ede.o \ crypto/des/ofb64ede.o \
crypto/des/enc_read.o \
crypto/des/enc_writ.o \
crypto/des/ofb64enc.o \ crypto/des/ofb64enc.o \
crypto/des/ofb_enc.o \ crypto/des/ofb_enc.o \
crypto/des/str2key.o \
crypto/des/pcbc_enc.o \ crypto/des/pcbc_enc.o \
crypto/des/qud_cksm.o \ crypto/des/qud_cksm.o \
crypto/des/rand_key.o \ crypto/des/rand_key.o \
crypto/des/des_enc.o \
crypto/des/fcrypt_b.o \
crypto/des/fcrypt.o \
crypto/des/xcbc_enc.o \
crypto/des/rpc_enc.o \ crypto/des/rpc_enc.o \
crypto/des/cbc_cksm.o \ crypto/des/set_key.o \
crypto/des/ede_cbcm_enc.o \ crypto/des/str2key.o \
crypto/des/des_old.o \ crypto/des/xcbc_enc.o \
crypto/des/des_old2.o \ crypto/dh/dh_ameth.o \
crypto/des/read2pwd.o \ crypto/dh/dh_asn1.o \
crypto/rc4/rc4_enc.o \ crypto/dh/dh_check.o \
crypto/rc4/rc4_skey.o \ crypto/dh/dh_depr.o \
crypto/rc4/rc4_utl.o \ crypto/dh/dh_err.o \
crypto/aes/aes_misc.o \ crypto/dh/dh_gen.o \
crypto/aes/aes_ecb.o \ crypto/dh/dh_kdf.o \
crypto/aes/aes_cfb.o \ crypto/dh/dh_key.o \
crypto/aes/aes_ofb.o \ crypto/dh/dh_lib.o \
crypto/aes/aes_ctr.o \ crypto/dh/dh_meth.o \
crypto/aes/aes_ige.o \ crypto/dh/dh_pmeth.o \
crypto/aes/aes_wrap.o \ crypto/dh/dh_prn.o \
crypto/aes/aes_core.o \ crypto/dh/dh_rfc5114.o \
crypto/aes/aes_cbc.o \
crypto/modes/cbc128.o \
crypto/modes/ctr128.o \
crypto/modes/cts128.o \
crypto/modes/cfb128.o \
crypto/modes/ofb128.o \
crypto/modes/gcm128.o \
crypto/modes/ccm128.o \
crypto/modes/xts128.o \
crypto/modes/wrap128.o \
crypto/bn/bn_add.o \
crypto/bn/bn_div.o \
crypto/bn/bn_exp.o \
crypto/bn/bn_lib.o \
crypto/bn/bn_ctx.o \
crypto/bn/bn_mul.o \
crypto/bn/bn_mod.o \
crypto/bn/bn_print.o \
crypto/bn/bn_rand.o \
crypto/bn/bn_shift.o \
crypto/bn/bn_word.o \
crypto/bn/bn_blind.o \
crypto/bn/bn_kron.o \
crypto/bn/bn_sqrt.o \
crypto/bn/bn_gcd.o \
crypto/bn/bn_prime.o \
crypto/bn/bn_err.o \
crypto/bn/bn_sqr.o \
crypto/bn/bn_asm.o \
crypto/bn/bn_recp.o \
crypto/bn/bn_mont.o \
crypto/bn/bn_mpi.o \
crypto/bn/bn_exp2.o \
crypto/bn/bn_gf2m.o \
crypto/bn/bn_nist.o \
crypto/bn/bn_depr.o \
crypto/bn/bn_x931p.o \
crypto/bn/bn_const.o \
crypto/rsa/rsa_eay.o \
crypto/rsa/rsa_gen.o \
crypto/rsa/rsa_lib.o \
crypto/rsa/rsa_sign.o \
crypto/rsa/rsa_saos.o \
crypto/rsa/rsa_err.o \
crypto/rsa/rsa_pk1.o \
crypto/rsa/rsa_ssl.o \
crypto/rsa/rsa_none.o \
crypto/rsa/rsa_oaep.o \
crypto/rsa/rsa_chk.o \
crypto/rsa/rsa_null.o \
crypto/rsa/rsa_pss.o \
crypto/rsa/rsa_x931.o \
crypto/rsa/rsa_asn1.o \
crypto/rsa/rsa_depr.o \
crypto/rsa/rsa_ameth.o \
crypto/rsa/rsa_prn.o \
crypto/rsa/rsa_pmeth.o \
crypto/rsa/rsa_crpt.o \
crypto/dso/dso_dl.o \ crypto/dso/dso_dl.o \
crypto/dso/dso_dlfcn.o \ crypto/dso/dso_dlfcn.o \
crypto/dso/dso_err.o \ crypto/dso/dso_err.o \
crypto/dso/dso_lib.o \ crypto/dso/dso_lib.o \
crypto/dso/dso_null.o \
crypto/dso/dso_openssl.o \ crypto/dso/dso_openssl.o \
crypto/dso/dso_win32.o \
crypto/dso/dso_vms.o \ crypto/dso/dso_vms.o \
crypto/dso/dso_beos.o \ crypto/dso/dso_win32.o \
crypto/dh/dh_asn1.o \ crypto/ebcdic.o \
crypto/dh/dh_gen.o \
crypto/dh/dh_key.o \
crypto/dh/dh_lib.o \
crypto/dh/dh_check.o \
crypto/dh/dh_err.o \
crypto/dh/dh_depr.o \
crypto/dh/dh_ameth.o \
crypto/dh/dh_pmeth.o \
crypto/dh/dh_prn.o \
crypto/dh/dh_rfc5114.o \
crypto/buffer/buffer.o \
crypto/buffer/buf_str.o \
crypto/buffer/buf_err.o \
crypto/bio/bio_lib.o \
crypto/bio/bio_cb.o \
crypto/bio/bio_err.o \
crypto/bio/bss_mem.o \
crypto/bio/bss_null.o \
crypto/bio/bss_fd.o \
crypto/bio/bss_file.o \
crypto/bio/bss_sock.o \
crypto/bio/bss_conn.o \
crypto/bio/bf_null.o \
crypto/bio/bf_buff.o \
crypto/bio/b_dump.o \
crypto/bio/b_print.o \
crypto/bio/b_sock.o \
crypto/bio/bss_acpt.o \
crypto/bio/bf_nbio.o \
crypto/bio/bss_log.o \
crypto/bio/bss_bio.o \
crypto/bio/bss_dgram.o \
crypto/stack/stack.o \
crypto/lhash/lhash.o \
crypto/lhash/lh_stats.o \
crypto/rand/md_rand.o \
crypto/rand/randfile.o \
crypto/rand/rand_lib.o \
crypto/rand/rand_err.o \
crypto/rand/rand_unix.o \
crypto/err/err.o \ crypto/err/err.o \
crypto/err/err_all.o \ crypto/err/err_all.o \
crypto/err/err_prn.o \ crypto/err/err_prn.o \
crypto/objects/o_names.o \ crypto/evp/bio_b64.o \
crypto/objects/obj_dat.o \ crypto/evp/bio_enc.o \
crypto/objects/obj_lib.o \ crypto/evp/bio_md.o \
crypto/objects/obj_err.o \ crypto/evp/bio_ok.o \
crypto/objects/obj_xref.o \ crypto/evp/c_allc.o \
crypto/evp/encode.o \ crypto/evp/c_alld.o \
crypto/evp/cmeth_lib.o \
crypto/evp/digest.o \ crypto/evp/digest.o \
crypto/evp/evp_enc.o \
crypto/evp/evp_key.o \
crypto/evp/evp_acnf.o \
crypto/evp/evp_cnf.o \
crypto/evp/e_des.o \
crypto/evp/e_bf.o \
crypto/evp/e_idea.o \
crypto/evp/e_des3.o \
crypto/evp/e_camellia.o \
crypto/evp/e_rc4.o \
crypto/evp/e_aes.o \ crypto/evp/e_aes.o \
crypto/evp/names.o \ crypto/evp/e_aes_cbc_hmac_sha1.o \
crypto/evp/e_aes_cbc_hmac_sha256.o \
crypto/evp/e_bf.o \
crypto/evp/e_camellia.o \
crypto/evp/e_cast.o \
crypto/evp/e_chacha20_poly1305.o \
crypto/evp/e_des.o \
crypto/evp/e_des3.o \
crypto/evp/e_idea.o \
crypto/evp/e_null.o \
crypto/evp/e_old.o \
crypto/evp/e_rc2.o \
crypto/evp/e_rc4.o \
crypto/evp/e_rc4_hmac_md5.o \
crypto/evp/e_rc5.o \
crypto/evp/e_seed.o \ crypto/evp/e_seed.o \
crypto/evp/e_xcbc_d.o \ crypto/evp/e_xcbc_d.o \
crypto/evp/e_rc2.o \ crypto/evp/encode.o \
crypto/evp/e_cast.o \ crypto/evp/evp_cnf.o \
crypto/evp/e_rc5.o \ crypto/evp/evp_enc.o \
crypto/evp/m_null.o \ crypto/evp/evp_err.o \
crypto/evp/evp_key.o \
crypto/evp/evp_lib.o \
crypto/evp/evp_pbe.o \
crypto/evp/evp_pkey.o \
crypto/evp/m_md2.o \ crypto/evp/m_md2.o \
crypto/evp/m_md4.o \ crypto/evp/m_md4.o \
crypto/evp/m_md5.o \ crypto/evp/m_md5.o \
crypto/evp/m_sha.o \ crypto/evp/m_md5_sha1.o \
crypto/evp/m_sha1.o \
crypto/evp/m_wp.o \
crypto/evp/m_dss.o \
crypto/evp/m_dss1.o \
crypto/evp/m_mdc2.o \ crypto/evp/m_mdc2.o \
crypto/evp/m_null.o \
crypto/evp/m_ripemd.o \ crypto/evp/m_ripemd.o \
crypto/evp/m_ecdsa.o \ crypto/evp/m_sha1.o \
crypto/evp/m_sigver.o \
crypto/evp/m_wp.o \
crypto/evp/names.o \
crypto/evp/p5_crpt.o \
crypto/evp/p5_crpt2.o \
crypto/evp/p_dec.o \
crypto/evp/p_enc.o \
crypto/evp/p_lib.o \
crypto/evp/p_open.o \ crypto/evp/p_open.o \
crypto/evp/p_seal.o \ crypto/evp/p_seal.o \
crypto/evp/p_sign.o \ crypto/evp/p_sign.o \
crypto/evp/p_verify.o \ crypto/evp/p_verify.o \
crypto/evp/p_lib.o \
crypto/evp/p_enc.o \
crypto/evp/p_dec.o \
crypto/evp/bio_md.o \
crypto/evp/bio_b64.o \
crypto/evp/bio_enc.o \
crypto/evp/evp_err.o \
crypto/evp/e_null.o \
crypto/evp/c_all.o \
crypto/evp/c_allc.o \
crypto/evp/c_alld.o \
crypto/evp/evp_lib.o \
crypto/evp/bio_ok.o \
crypto/evp/evp_pkey.o \
crypto/evp/evp_pbe.o \
crypto/evp/p5_crpt.o \
crypto/evp/p5_crpt2.o \
crypto/evp/e_old.o \
crypto/evp/pmeth_lib.o \
crypto/evp/pmeth_fn.o \ crypto/evp/pmeth_fn.o \
crypto/evp/pmeth_gn.o \ crypto/evp/pmeth_gn.o \
crypto/evp/m_sigver.o \ crypto/evp/pmeth_lib.o \
crypto/evp/e_aes_cbc_hmac_sha1.o \ crypto/evp/scrypt.o \
crypto/evp/e_aes_cbc_hmac_sha256.o \ crypto/ex_data.o \
crypto/evp/e_rc4_hmac_md5.o \ crypto/hmac/hm_ameth.o \
crypto/asn1/a_object.o \ crypto/hmac/hm_pmeth.o \
crypto/asn1/a_bitstr.o \ crypto/hmac/hmac.o \
crypto/asn1/a_utctm.o \ crypto/init.o \
crypto/asn1/a_gentm.o \ crypto/kdf/hkdf.o \
crypto/asn1/a_time.o \ crypto/kdf/kdf_err.o \
crypto/asn1/a_int.o \ crypto/kdf/tls1_prf.o \
crypto/asn1/a_octet.o \ crypto/lhash/lh_stats.o \
crypto/asn1/a_print.o \ crypto/lhash/lhash.o \
crypto/asn1/a_type.o \ crypto/md4/md4_dgst.o \
crypto/asn1/a_set.o \ crypto/md4/md4_one.o \
crypto/asn1/a_dup.o \ crypto/md5/md5_dgst.o \
crypto/asn1/a_d2i_fp.o \ crypto/md5/md5_one.o \
crypto/asn1/a_i2d_fp.o \ crypto/mem.o \
crypto/asn1/a_enum.o \ crypto/mem_clr.o \
crypto/asn1/a_utf8.o \ crypto/mem_dbg.o \
crypto/asn1/a_sign.o \ crypto/mem_sec.o \
crypto/asn1/a_digest.o \ crypto/modes/cbc128.o \
crypto/asn1/a_verify.o \ crypto/modes/ccm128.o \
crypto/asn1/a_mbstr.o \ crypto/modes/cfb128.o \
crypto/asn1/a_strex.o \ crypto/modes/ctr128.o \
crypto/asn1/x_algor.o \ crypto/modes/cts128.o \
crypto/asn1/x_val.o \ crypto/modes/gcm128.o \
crypto/asn1/x_pubkey.o \ crypto/modes/ocb128.o \
crypto/asn1/x_sig.o \ crypto/modes/ofb128.o \
crypto/asn1/x_req.o \ crypto/modes/wrap128.o \
crypto/asn1/x_attrib.o \ crypto/modes/xts128.o \
crypto/asn1/x_bignum.o \ crypto/o_dir.o \
crypto/asn1/x_long.o \ crypto/o_fips.o \
crypto/asn1/x_name.o \ crypto/o_fopen.o \
crypto/asn1/x_x509.o \ crypto/o_init.o \
crypto/asn1/x_x509a.o \ crypto/o_str.o \
crypto/asn1/x_crl.o \ crypto/o_time.o \
crypto/asn1/x_info.o \ crypto/objects/o_names.o \
crypto/asn1/x_spki.o \ crypto/objects/obj_dat.o \
crypto/asn1/nsseq.o \ crypto/objects/obj_err.o \
crypto/asn1/x_nx509.o \ crypto/objects/obj_lib.o \
crypto/asn1/d2i_pu.o \ crypto/objects/obj_xref.o \
crypto/asn1/d2i_pr.o \ crypto/ocsp/ocsp_asn.o \
crypto/asn1/i2d_pu.o \ crypto/ocsp/ocsp_cl.o \
crypto/asn1/i2d_pr.o \ crypto/ocsp/ocsp_err.o \
crypto/asn1/t_req.o \ crypto/ocsp/ocsp_ext.o \
crypto/asn1/t_x509.o \ crypto/ocsp/ocsp_ht.o \
crypto/asn1/t_x509a.o \ crypto/ocsp/ocsp_lib.o \
crypto/asn1/t_crl.o \ crypto/ocsp/ocsp_prn.o \
crypto/asn1/t_pkey.o \ crypto/ocsp/ocsp_srv.o \
crypto/asn1/t_spki.o \ crypto/ocsp/ocsp_vfy.o \
crypto/asn1/t_bitst.o \ crypto/ocsp/v3_ocsp.o \
crypto/asn1/tasn_new.o \
crypto/asn1/tasn_fre.o \
crypto/asn1/tasn_enc.o \
crypto/asn1/tasn_dec.o \
crypto/asn1/tasn_utl.o \
crypto/asn1/tasn_typ.o \
crypto/asn1/tasn_prn.o \
crypto/asn1/ameth_lib.o \
crypto/asn1/f_int.o \
crypto/asn1/f_string.o \
crypto/asn1/n_pkey.o \
crypto/asn1/f_enum.o \
crypto/asn1/x_pkey.o \
crypto/asn1/a_bool.o \
crypto/asn1/x_exten.o \
crypto/asn1/bio_asn1.o \
crypto/asn1/bio_ndef.o \
crypto/asn1/asn_mime.o \
crypto/asn1/asn1_gen.o \
crypto/asn1/asn1_par.o \
crypto/asn1/asn1_lib.o \
crypto/asn1/asn1_err.o \
crypto/asn1/a_bytes.o \
crypto/asn1/a_strnid.o \
crypto/asn1/evp_asn1.o \
crypto/asn1/asn_pack.o \
crypto/asn1/p5_pbe.o \
crypto/asn1/p5_pbev2.o \
crypto/asn1/p8_pkey.o \
crypto/asn1/asn_moid.o \
crypto/pem/pem_sign.o \
crypto/pem/pem_seal.o \
crypto/pem/pem_info.o \
crypto/pem/pem_lib.o \
crypto/pem/pem_all.o \ crypto/pem/pem_all.o \
crypto/pem/pem_err.o \ crypto/pem/pem_err.o \
crypto/pem/pem_x509.o \ crypto/pem/pem_info.o \
crypto/pem/pem_xaux.o \ crypto/pem/pem_lib.o \
crypto/pem/pem_oth.o \ crypto/pem/pem_oth.o \
crypto/pem/pem_pk8.o \ crypto/pem/pem_pk8.o \
crypto/pem/pem_pkey.o \ crypto/pem/pem_pkey.o \
crypto/pem/pem_sign.o \
crypto/pem/pem_x509.o \
crypto/pem/pem_xaux.o \
crypto/pem/pvkfmt.o \ crypto/pem/pvkfmt.o \
crypto/x509/x509_def.o \
crypto/x509/x509_d2.o \
crypto/x509/x509_r2x.o \
crypto/x509/x509_cmp.o \
crypto/x509/x509_obj.o \
crypto/x509/x509_req.o \
crypto/x509/x509spki.o \
crypto/x509/x509_vfy.o \
crypto/x509/x509_set.o \
crypto/x509/x509cset.o \
crypto/x509/x509rset.o \
crypto/x509/x509_err.o \
crypto/x509/x509name.o \
crypto/x509/x509_v3.o \
crypto/x509/x509_ext.o \
crypto/x509/x509_att.o \
crypto/x509/x509type.o \
crypto/x509/x509_lu.o \
crypto/x509/x_all.o \
crypto/x509/x509_txt.o \
crypto/x509/x509_trs.o \
crypto/x509/x509_vpm.o \
crypto/x509v3/v3_bcons.o \
crypto/x509v3/v3_bitst.o \
crypto/x509v3/v3_conf.o \
crypto/x509v3/v3_extku.o \
crypto/x509v3/v3_ia5.o \
crypto/x509v3/v3_lib.o \
crypto/x509v3/v3_prn.o \
crypto/x509v3/v3_utl.o \
crypto/x509v3/v3err.o \
crypto/x509v3/v3_genn.o \
crypto/x509v3/v3_alt.o \
crypto/x509v3/v3_skey.o \
crypto/x509v3/v3_akey.o \
crypto/x509v3/v3_pku.o \
crypto/x509v3/v3_int.o \
crypto/x509v3/v3_enum.o \
crypto/x509v3/v3_sxnet.o \
crypto/x509v3/v3_cpols.o \
crypto/x509v3/v3_crld.o \
crypto/x509v3/v3_purp.o \
crypto/x509v3/v3_info.o \
crypto/x509v3/v3_ocsp.o \
crypto/x509v3/v3_akeya.o \
crypto/x509v3/v3_pmaps.o \
crypto/x509v3/v3_pcons.o \
crypto/x509v3/v3_ncons.o \
crypto/x509v3/v3_pcia.o \
crypto/x509v3/v3_pci.o \
crypto/x509v3/pcy_cache.o \
crypto/x509v3/pcy_node.o \
crypto/x509v3/pcy_data.o \
crypto/x509v3/pcy_map.o \
crypto/x509v3/pcy_tree.o \
crypto/x509v3/pcy_lib.o \
crypto/x509v3/v3_asid.o \
crypto/x509v3/v3_addr.o \
crypto/conf/conf_err.o \
crypto/conf/conf_lib.o \
crypto/conf/conf_api.o \
crypto/conf/conf_def.o \
crypto/conf/conf_mod.o \
crypto/conf/conf_mall.o \
crypto/conf/conf_sap.o \
crypto/txt_db/txt_db.o \
crypto/pkcs7/pk7_asn1.o \
crypto/pkcs7/pk7_lib.o \
crypto/pkcs7/pkcs7err.o \
crypto/pkcs7/pk7_doit.o \
crypto/pkcs7/pk7_smime.o \
crypto/pkcs7/pk7_attr.o \
crypto/pkcs7/pk7_mime.o \
crypto/pkcs7/bio_pk7.o \
crypto/pkcs12/p12_add.o \ crypto/pkcs12/p12_add.o \
crypto/pkcs12/p12_asn.o \ crypto/pkcs12/p12_asn.o \
crypto/pkcs12/p12_attr.o \ crypto/pkcs12/p12_attr.o \
@ -437,31 +343,133 @@ OBJS = crypto/cryptlib.o \
crypto/pkcs12/p12_key.o \ crypto/pkcs12/p12_key.o \
crypto/pkcs12/p12_kiss.o \ crypto/pkcs12/p12_kiss.o \
crypto/pkcs12/p12_mutl.o \ crypto/pkcs12/p12_mutl.o \
crypto/pkcs12/p12_utl.o \
crypto/pkcs12/p12_npas.o \ crypto/pkcs12/p12_npas.o \
crypto/pkcs12/pk12err.o \
crypto/pkcs12/p12_p8d.o \ crypto/pkcs12/p12_p8d.o \
crypto/pkcs12/p12_p8e.o \ crypto/pkcs12/p12_p8e.o \
crypto/comp/comp_lib.o \ crypto/pkcs12/p12_sbag.o \
crypto/comp/comp_err.o \ crypto/pkcs12/p12_utl.o \
crypto/comp/c_rle.o \ crypto/pkcs12/pk12err.o \
crypto/comp/c_zlib.o \ crypto/pkcs7/bio_pk7.o \
crypto/ocsp/ocsp_asn.o \ crypto/pkcs7/pk7_asn1.o \
crypto/ocsp/ocsp_ext.o \ crypto/pkcs7/pk7_attr.o \
crypto/ocsp/ocsp_ht.o \ crypto/pkcs7/pk7_doit.o \
crypto/ocsp/ocsp_lib.o \ crypto/pkcs7/pk7_lib.o \
crypto/ocsp/ocsp_cl.o \ crypto/pkcs7/pk7_mime.o \
crypto/ocsp/ocsp_srv.o \ crypto/pkcs7/pk7_smime.o \
crypto/ocsp/ocsp_prn.o \ crypto/pkcs7/pkcs7err.o \
crypto/ocsp/ocsp_vfy.o \ crypto/rand/md_rand.o \
crypto/ocsp/ocsp_err.o \ crypto/rand/rand_egd.o \
crypto/ui/ui_lib.o \ crypto/rand/rand_err.o \
crypto/ui/ui_util.o \ crypto/rand/rand_lib.o \
crypto/ui/ui_compat.o \ crypto/rand/rand_unix.o \
crypto/krb5/krb5_asn.o \ crypto/rand/rand_vms.o \
crypto/cmac/cmac.o \ crypto/rand/rand_win.o \
crypto/cmac/cm_ameth.o \ crypto/rand/randfile.o \
crypto/cmac/cm_pmeth.o \ crypto/rc4/rc4_enc.o \
crypto/rc4/rc4_skey.o \
crypto/rsa/rsa_ameth.o \
crypto/rsa/rsa_asn1.o \
crypto/rsa/rsa_chk.o \
crypto/rsa/rsa_crpt.o \
crypto/rsa/rsa_depr.o \
crypto/rsa/rsa_err.o \
crypto/rsa/rsa_gen.o \
crypto/rsa/rsa_lib.o \
crypto/rsa/rsa_meth.o \
crypto/rsa/rsa_none.o \
crypto/rsa/rsa_null.o \
crypto/rsa/rsa_oaep.o \
crypto/rsa/rsa_ossl.o \
crypto/rsa/rsa_pk1.o \
crypto/rsa/rsa_pmeth.o \
crypto/rsa/rsa_prn.o \
crypto/rsa/rsa_pss.o \
crypto/rsa/rsa_saos.o \
crypto/rsa/rsa_sign.o \
crypto/rsa/rsa_ssl.o \
crypto/rsa/rsa_x931.o \
crypto/rsa/rsa_x931g.o \
crypto/sha/sha1_one.o \
crypto/sha/sha1dgst.o \
crypto/sha/sha256.o \
crypto/sha/sha512.o \
crypto/stack/stack.o \
crypto/threads_none.o \
crypto/threads_pthread.o \
crypto/threads_win.o \
crypto/txt_db/txt_db.o \
crypto/uid.o \
crypto/x509/by_dir.o \
crypto/x509/by_file.o \
crypto/x509/t_crl.o \
crypto/x509/t_req.o \
crypto/x509/t_x509.o \
crypto/x509/x509_att.o \
crypto/x509/x509_cmp.o \
crypto/x509/x509_d2.o \
crypto/x509/x509_def.o \
crypto/x509/x509_err.o \
crypto/x509/x509_ext.o \
crypto/x509/x509_lu.o \
crypto/x509/x509_obj.o \
crypto/x509/x509_r2x.o \
crypto/x509/x509_req.o \
crypto/x509/x509_set.o \
crypto/x509/x509_trs.o \
crypto/x509/x509_txt.o \
crypto/x509/x509_v3.o \
crypto/x509/x509_vfy.o \
crypto/x509/x509_vpm.o \
crypto/x509/x509cset.o \
crypto/x509/x509name.o \
crypto/x509/x509rset.o \
crypto/x509/x509spki.o \
crypto/x509/x509type.o \
crypto/x509/x_all.o \
crypto/x509/x_attrib.o \
crypto/x509/x_crl.o \
crypto/x509/x_exten.o \
crypto/x509/x_name.o \
crypto/x509/x_pubkey.o \
crypto/x509/x_req.o \
crypto/x509/x_x509.o \
crypto/x509/x_x509a.o \
crypto/x509v3/pcy_cache.o \
crypto/x509v3/pcy_data.o \
crypto/x509v3/pcy_lib.o \
crypto/x509v3/pcy_map.o \
crypto/x509v3/pcy_node.o \
crypto/x509v3/pcy_tree.o \
crypto/x509v3/v3_addr.o \
crypto/x509v3/v3_akey.o \
crypto/x509v3/v3_akeya.o \
crypto/x509v3/v3_alt.o \
crypto/x509v3/v3_asid.o \
crypto/x509v3/v3_bcons.o \
crypto/x509v3/v3_bitst.o \
crypto/x509v3/v3_conf.o \
crypto/x509v3/v3_cpols.o \
crypto/x509v3/v3_crld.o \
crypto/x509v3/v3_enum.o \
crypto/x509v3/v3_extku.o \
crypto/x509v3/v3_genn.o \
crypto/x509v3/v3_ia5.o \
crypto/x509v3/v3_info.o \
crypto/x509v3/v3_int.o \
crypto/x509v3/v3_lib.o \
crypto/x509v3/v3_ncons.o \
crypto/x509v3/v3_pci.o \
crypto/x509v3/v3_pcia.o \
crypto/x509v3/v3_pcons.o \
crypto/x509v3/v3_pku.o \
crypto/x509v3/v3_pmaps.o \
crypto/x509v3/v3_prn.o \
crypto/x509v3/v3_purp.o \
crypto/x509v3/v3_skey.o \
crypto/x509v3/v3_sxnet.o \
crypto/x509v3/v3_tlsf.o \
crypto/x509v3/v3_utl.o \
crypto/x509v3/v3err.o
all: $(TARGET) all: $(TARGET)

View File

@ -1,2 +1,2 @@
#define PLATFORM "UEFI" #define PLATFORM "UEFI"
#define DATE "Mon Mar 8 14:17:05 PDT 2010" #define DATE "Tues Mar 21 01:23:45 PDT 2017"

View File

@ -1,3 +1,12 @@
/*
* Copyright 2004-2016 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
/* /*
* Copyright (c) 2004, Richard Levitte <richard@levitte.org> * Copyright (c) 2004, Richard Levitte <richard@levitte.org>
* All rights reserved. * All rights reserved.

View File

@ -1,52 +1,10 @@
/* crypto/aes/aes_cbc.c */ /*
/* ==================================================================== * Copyright 2002-2016 The OpenSSL Project Authors. All Rights Reserved.
* Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
*
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* openssl-core@openssl.org.
*
* 5. Products derived from this software may not be called "OpenSSL"
* nor may "OpenSSL" appear in their names without prior written
* permission of the OpenSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit (http://www.openssl.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
* *
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/ */
#include <openssl/aes.h> #include <openssl/aes.h>

View File

@ -1,52 +1,10 @@
/* crypto/aes/aes_cfb.c */ /*
/* ==================================================================== * Copyright 2002-2016 The OpenSSL Project Authors. All Rights Reserved.
* Copyright (c) 2002-2006 The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
*
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* openssl-core@openssl.org.
*
* 5. Products derived from this software may not be called "OpenSSL"
* nor may "OpenSSL" appear in their names without prior written
* permission of the OpenSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit (http://www.openssl.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
* *
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/ */
#include <openssl/aes.h> #include <openssl/aes.h>

View File

@ -1,4 +1,12 @@
/* crypto/aes/aes_core.c */ /*
* Copyright 2002-2016 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
/** /**
* rijndael-alg-fst.c * rijndael-alg-fst.c
* *
@ -28,14 +36,10 @@
/* Note: rewritten a little bit to provide error control and an OpenSSL- /* Note: rewritten a little bit to provide error control and an OpenSSL-
compatible API */ compatible API */
#ifndef AES_DEBUG
# ifndef NDEBUG
# define NDEBUG
# endif
#endif
#include <assert.h> #include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <openssl/crypto.h>
#include <openssl/aes.h> #include <openssl/aes.h>
#include "aes_locl.h" #include "aes_locl.h"
@ -625,7 +629,7 @@ static const u32 rcon[] = {
/** /**
* Expand the cipher key into the encryption key schedule. * Expand the cipher key into the encryption key schedule.
*/ */
int private_AES_set_encrypt_key(const unsigned char *userKey, const int bits, int AES_set_encrypt_key(const unsigned char *userKey, const int bits,
AES_KEY *key) AES_KEY *key)
{ {
@ -640,9 +644,9 @@ int private_AES_set_encrypt_key(const unsigned char *userKey, const int bits,
rk = key->rd_key; rk = key->rd_key;
if (bits==128) if (bits == 128)
key->rounds = 10; key->rounds = 10;
else if (bits==192) else if (bits == 192)
key->rounds = 12; key->rounds = 12;
else else
key->rounds = 14; key->rounds = 14;
@ -727,7 +731,7 @@ int private_AES_set_encrypt_key(const unsigned char *userKey, const int bits,
/** /**
* Expand the cipher key into the decryption key schedule. * Expand the cipher key into the decryption key schedule.
*/ */
int private_AES_set_decrypt_key(const unsigned char *userKey, const int bits, int AES_set_decrypt_key(const unsigned char *userKey, const int bits,
AES_KEY *key) AES_KEY *key)
{ {
@ -736,7 +740,7 @@ int private_AES_set_decrypt_key(const unsigned char *userKey, const int bits,
u32 temp; u32 temp;
/* first, start with an encryption schedule */ /* first, start with an encryption schedule */
status = private_AES_set_encrypt_key(userKey, bits, key); status = AES_set_encrypt_key(userKey, bits, key);
if (status < 0) if (status < 0)
return status; return status;
@ -1204,7 +1208,7 @@ static const u32 rcon[] = {
/** /**
* Expand the cipher key into the encryption key schedule. * Expand the cipher key into the encryption key schedule.
*/ */
int private_AES_set_encrypt_key(const unsigned char *userKey, const int bits, int AES_set_encrypt_key(const unsigned char *userKey, const int bits,
AES_KEY *key) AES_KEY *key)
{ {
u32 *rk; u32 *rk;
@ -1218,9 +1222,9 @@ int private_AES_set_encrypt_key(const unsigned char *userKey, const int bits,
rk = key->rd_key; rk = key->rd_key;
if (bits==128) if (bits == 128)
key->rounds = 10; key->rounds = 10;
else if (bits==192) else if (bits == 192)
key->rounds = 12; key->rounds = 12;
else else
key->rounds = 14; key->rounds = 14;
@ -1305,7 +1309,7 @@ int private_AES_set_encrypt_key(const unsigned char *userKey, const int bits,
/** /**
* Expand the cipher key into the decryption key schedule. * Expand the cipher key into the decryption key schedule.
*/ */
int private_AES_set_decrypt_key(const unsigned char *userKey, const int bits, int AES_set_decrypt_key(const unsigned char *userKey, const int bits,
AES_KEY *key) AES_KEY *key)
{ {
@ -1314,7 +1318,7 @@ int private_AES_set_decrypt_key(const unsigned char *userKey, const int bits,
u32 temp; u32 temp;
/* first, start with an encryption schedule */ /* first, start with an encryption schedule */
status = private_AES_set_encrypt_key(userKey, bits, key); status = AES_set_encrypt_key(userKey, bits, key);
if (status < 0) if (status < 0)
return status; return status;

View File

@ -1,63 +0,0 @@
/* crypto/aes/aes_ctr.c */
/* ====================================================================
* Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
*
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* openssl-core@openssl.org.
*
* 5. Products derived from this software may not be called "OpenSSL"
* nor may "OpenSSL" appear in their names without prior written
* permission of the OpenSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit (http://www.openssl.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*
*/
#include <openssl/aes.h>
#include <openssl/modes.h>
void AES_ctr128_encrypt(const unsigned char *in, unsigned char *out,
size_t length, const AES_KEY *key,
unsigned char ivec[AES_BLOCK_SIZE],
unsigned char ecount_buf[AES_BLOCK_SIZE],
unsigned int *num)
{
CRYPTO_ctr128_encrypt(in, out, length, key, ivec, ecount_buf, num,
(block128_f) AES_encrypt);
}

View File

@ -1,59 +1,12 @@
/* crypto/aes/aes_ecb.c */ /*
/* ==================================================================== * Copyright 2002-2016 The OpenSSL Project Authors. All Rights Reserved.
* Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
*
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* openssl-core@openssl.org.
*
* 5. Products derived from this software may not be called "OpenSSL"
* nor may "OpenSSL" appear in their names without prior written
* permission of the OpenSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit (http://www.openssl.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
* *
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/ */
#ifndef AES_DEBUG
# ifndef NDEBUG
# define NDEBUG
# endif
#endif
#include <assert.h> #include <assert.h>
#include <openssl/aes.h> #include <openssl/aes.h>

View File

@ -1,55 +1,13 @@
/* crypto/aes/aes_ige.c */ /*
/* ==================================================================== * Copyright 2006-2016 The OpenSSL Project Authors. All Rights Reserved.
* Copyright (c) 2006 The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
*
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* openssl-core@openssl.org.
*
* 5. Products derived from this software may not be called "OpenSSL"
* nor may "OpenSSL" appear in their names without prior written
* permission of the OpenSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit (http://www.openssl.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
* *
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/ */
#include "cryptlib.h" #include "internal/cryptlib.h"
#include <openssl/aes.h> #include <openssl/aes.h>
#include "aes_locl.h" #include "aes_locl.h"

View File

@ -1,63 +1,16 @@
/* crypto/aes/aes.h */ /*
/* ==================================================================== * Copyright 2002-2016 The OpenSSL Project Authors. All Rights Reserved.
* Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
*
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* openssl-core@openssl.org.
*
* 5. Products derived from this software may not be called "OpenSSL"
* nor may "OpenSSL" appear in their names without prior written
* permission of the OpenSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit (http://www.openssl.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
* *
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/ */
#ifndef HEADER_AES_LOCL_H #ifndef HEADER_AES_LOCL_H
# define HEADER_AES_LOCL_H # define HEADER_AES_LOCL_H
# include <openssl/e_os2.h> # include <openssl/e_os2.h>
# ifdef OPENSSL_NO_AES
# error AES is disabled.
# endif
# include <stdio.h> # include <stdio.h>
# include <stdlib.h> # include <stdlib.h>
# include <string.h> # include <string.h>

View File

@ -1,61 +1,16 @@
/* crypto/aes/aes_misc.c */ /*
/* ==================================================================== * Copyright 2002-2016 The OpenSSL Project Authors. All Rights Reserved.
* Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
*
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* openssl-core@openssl.org.
*
* 5. Products derived from this software may not be called "OpenSSL"
* nor may "OpenSSL" appear in their names without prior written
* permission of the OpenSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit (http://www.openssl.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
* *
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/ */
#include <openssl/opensslv.h> #include <openssl/opensslv.h>
#include <openssl/crypto.h>
#include <openssl/aes.h> #include <openssl/aes.h>
#include "aes_locl.h" #include "aes_locl.h"
const char AES_version[] = "AES" OPENSSL_VERSION_PTEXT;
const char *AES_options(void) const char *AES_options(void)
{ {
#ifdef FULL_UNROLL #ifdef FULL_UNROLL
@ -64,23 +19,3 @@ const char *AES_options(void)
return "aes(partial)"; return "aes(partial)";
#endif #endif
} }
/* FIPS wrapper functions to block low level AES calls in FIPS mode */
int AES_set_encrypt_key(const unsigned char *userKey, const int bits,
AES_KEY *key)
{
#ifdef OPENSSL_FIPS
fips_cipher_abort(AES);
#endif
return private_AES_set_encrypt_key(userKey, bits, key);
}
int AES_set_decrypt_key(const unsigned char *userKey, const int bits,
AES_KEY *key)
{
#ifdef OPENSSL_FIPS
fips_cipher_abort(AES);
#endif
return private_AES_set_decrypt_key(userKey, bits, key);
}

View File

@ -1,52 +1,10 @@
/* crypto/aes/aes_ofb.c */ /*
/* ==================================================================== * Copyright 2002-2016 The OpenSSL Project Authors. All Rights Reserved.
* Copyright (c) 2002-2006 The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
*
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* openssl-core@openssl.org.
*
* 5. Products derived from this software may not be called "OpenSSL"
* nor may "OpenSSL" appear in their names without prior written
* permission of the OpenSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit (http://www.openssl.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
* *
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/ */
#include <openssl/aes.h> #include <openssl/aes.h>

View File

@ -1,58 +1,13 @@
/* crypto/aes/aes_wrap.c */
/* /*
* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * Copyright 2008-2016 The OpenSSL Project Authors. All Rights Reserved.
* project.
*/
/* ====================================================================
* Copyright (c) 2008 The OpenSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Licensed under the OpenSSL license (the "License"). You may not use
* modification, are permitted provided that the following conditions * this file except in compliance with the License. You can obtain a copy
* are met: * in the file LICENSE in the source distribution or at
* * https://www.openssl.org/source/license.html
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
*
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* licensing@OpenSSL.org.
*
* 5. Products derived from this software may not be called "OpenSSL"
* nor may "OpenSSL" appear in their names without prior written
* permission of the OpenSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*/ */
#include "cryptlib.h" #include "internal/cryptlib.h"
#include <openssl/aes.h> #include <openssl/aes.h>
#include <openssl/modes.h> #include <openssl/modes.h>

View File

@ -1,68 +1,20 @@
/* crypto/asn1/a_bitstr.c */ /*
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
* All rights reserved.
* *
* This package is an SSL implementation written * Licensed under the OpenSSL license (the "License"). You may not use
* by Eric Young (eay@cryptsoft.com). * this file except in compliance with the License. You can obtain a copy
* The implementation was written so as to conform with Netscapes SSL. * in the file LICENSE in the source distribution or at
* * https://www.openssl.org/source/license.html
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* "This product includes cryptographic software written by
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/ */
#include <stdio.h> #include <stdio.h>
#include "cryptlib.h" #include "internal/cryptlib.h"
#include <openssl/asn1.h> #include <openssl/asn1.h>
#include "asn1_locl.h"
int ASN1_BIT_STRING_set(ASN1_BIT_STRING *x, unsigned char *d, int len) int ASN1_BIT_STRING_set(ASN1_BIT_STRING *x, unsigned char *d, int len)
{ {
return M_ASN1_BIT_STRING_set(x, d, len); return ASN1_STRING_set(x, d, len);
} }
int i2c_ASN1_BIT_STRING(ASN1_BIT_STRING *a, unsigned char **pp) int i2c_ASN1_BIT_STRING(ASN1_BIT_STRING *a, unsigned char **pp)
@ -114,10 +66,11 @@ int i2c_ASN1_BIT_STRING(ASN1_BIT_STRING *a, unsigned char **pp)
*(p++) = (unsigned char)bits; *(p++) = (unsigned char)bits;
d = a->data; d = a->data;
if (len > 0) {
memcpy(p, d, len); memcpy(p, d, len);
p += len; p += len;
if (len > 0)
p[-1] &= (0xff << bits); p[-1] &= (0xff << bits);
}
*pp = p; *pp = p;
return (ret); return (ret);
} }
@ -136,7 +89,7 @@ ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,
} }
if ((a == NULL) || ((*a) == NULL)) { if ((a == NULL) || ((*a) == NULL)) {
if ((ret = M_ASN1_BIT_STRING_new()) == NULL) if ((ret = ASN1_BIT_STRING_new()) == NULL)
return (NULL); return (NULL);
} else } else
ret = (*a); ret = (*a);
@ -155,7 +108,7 @@ ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,
ret->flags |= (ASN1_STRING_FLAG_BITS_LEFT | i); /* set */ ret->flags |= (ASN1_STRING_FLAG_BITS_LEFT | i); /* set */
if (len-- > 1) { /* using one because of the bits left byte */ if (len-- > 1) { /* using one because of the bits left byte */
s = (unsigned char *)OPENSSL_malloc((int)len); s = OPENSSL_malloc((int)len);
if (s == NULL) { if (s == NULL) {
i = ERR_R_MALLOC_FAILURE; i = ERR_R_MALLOC_FAILURE;
goto err; goto err;
@ -167,7 +120,6 @@ ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,
s = NULL; s = NULL;
ret->length = (int)len; ret->length = (int)len;
if (ret->data != NULL)
OPENSSL_free(ret->data); OPENSSL_free(ret->data);
ret->data = s; ret->data = s;
ret->type = V_ASN1_BIT_STRING; ret->type = V_ASN1_BIT_STRING;
@ -177,8 +129,8 @@ ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,
return (ret); return (ret);
err: err:
ASN1err(ASN1_F_C2I_ASN1_BIT_STRING, i); ASN1err(ASN1_F_C2I_ASN1_BIT_STRING, i);
if ((ret != NULL) && ((a == NULL) || (*a != ret))) if ((a == NULL) || (*a != ret))
M_ASN1_BIT_STRING_free(ret); ASN1_BIT_STRING_free(ret);
return (NULL); return (NULL);
} }
@ -204,11 +156,7 @@ int ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value)
if ((a->length < (w + 1)) || (a->data == NULL)) { if ((a->length < (w + 1)) || (a->data == NULL)) {
if (!value) if (!value)
return (1); /* Don't need to set */ return (1); /* Don't need to set */
if (a->data == NULL) c = OPENSSL_clear_realloc(a->data, a->length, w + 1);
c = (unsigned char *)OPENSSL_malloc(w + 1);
else
c = (unsigned char *)OPENSSL_realloc_clean(a->data,
a->length, w + 1);
if (c == NULL) { if (c == NULL) {
ASN1err(ASN1_F_ASN1_BIT_STRING_SET_BIT, ERR_R_MALLOC_FAILURE); ASN1err(ASN1_F_ASN1_BIT_STRING_SET_BIT, ERR_R_MALLOC_FAILURE);
return 0; return 0;
@ -224,7 +172,7 @@ int ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value)
return (1); return (1);
} }
int ASN1_BIT_STRING_get_bit(ASN1_BIT_STRING *a, int n) int ASN1_BIT_STRING_get_bit(const ASN1_BIT_STRING *a, int n)
{ {
int w, v; int w, v;
@ -241,8 +189,8 @@ int ASN1_BIT_STRING_get_bit(ASN1_BIT_STRING *a, int n)
* which is not specified in 'flags', 1 otherwise. * which is not specified in 'flags', 1 otherwise.
* 'len' is the length of 'flags'. * 'len' is the length of 'flags'.
*/ */
int ASN1_BIT_STRING_check(ASN1_BIT_STRING *a, int ASN1_BIT_STRING_check(const ASN1_BIT_STRING *a,
unsigned char *flags, int flags_len) const unsigned char *flags, int flags_len)
{ {
int i, ok; int i, ok;
/* Check if there is one bit set at all. */ /* Check if there is one bit set at all. */

View File

@ -1,111 +0,0 @@
/* crypto/asn1/a_bool.c */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
* This package is an SSL implementation written
* by Eric Young (eay@cryptsoft.com).
* The implementation was written so as to conform with Netscapes SSL.
*
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* "This product includes cryptographic software written by
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/
#include <stdio.h>
#include "cryptlib.h"
#include <openssl/asn1t.h>
int i2d_ASN1_BOOLEAN(int a, unsigned char **pp)
{
int r;
unsigned char *p;
r = ASN1_object_size(0, 1, V_ASN1_BOOLEAN);
if (pp == NULL)
return (r);
p = *pp;
ASN1_put_object(&p, 0, 1, V_ASN1_BOOLEAN, V_ASN1_UNIVERSAL);
*(p++) = (unsigned char)a;
*pp = p;
return (r);
}
int d2i_ASN1_BOOLEAN(int *a, const unsigned char **pp, long length)
{
int ret = -1;
const unsigned char *p;
long len;
int inf, tag, xclass;
int i = 0;
p = *pp;
inf = ASN1_get_object(&p, &len, &tag, &xclass, length);
if (inf & 0x80) {
i = ASN1_R_BAD_OBJECT_HEADER;
goto err;
}
if (tag != V_ASN1_BOOLEAN) {
i = ASN1_R_EXPECTING_A_BOOLEAN;
goto err;
}
if (len != 1) {
i = ASN1_R_BOOLEAN_IS_WRONG_LENGTH;
goto err;
}
ret = (int)*(p++);
if (a != NULL)
(*a) = ret;
*pp = p;
return (ret);
err:
ASN1err(ASN1_F_D2I_ASN1_BOOLEAN, i);
return (ret);
}

View File

@ -1,334 +0,0 @@
/* crypto/asn1/a_bytes.c */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
* This package is an SSL implementation written
* by Eric Young (eay@cryptsoft.com).
* The implementation was written so as to conform with Netscapes SSL.
*
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* "This product includes cryptographic software written by
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/
#include <stdio.h>
#include "cryptlib.h"
#include <openssl/asn1.h>
static int asn1_collate_primitive(ASN1_STRING *a, ASN1_const_CTX *c,
int depth);
static ASN1_STRING *int_d2i_ASN1_bytes(ASN1_STRING **a,
const unsigned char **pp, long length,
int Ptag, int Pclass, int depth,
int *perr);
/*
* type is a 'bitmap' of acceptable string types.
*/
ASN1_STRING *d2i_ASN1_type_bytes(ASN1_STRING **a, const unsigned char **pp,
long length, int type)
{
ASN1_STRING *ret = NULL;
const unsigned char *p;
unsigned char *s;
long len;
int inf, tag, xclass;
int i = 0;
p = *pp;
inf = ASN1_get_object(&p, &len, &tag, &xclass, length);
if (inf & 0x80)
goto err;
if (tag >= 32) {
i = ASN1_R_TAG_VALUE_TOO_HIGH;
goto err;
}
if (!(ASN1_tag2bit(tag) & type)) {
i = ASN1_R_WRONG_TYPE;
goto err;
}
/* If a bit-string, exit early */
if (tag == V_ASN1_BIT_STRING)
return (d2i_ASN1_BIT_STRING(a, pp, length));
if ((a == NULL) || ((*a) == NULL)) {
if ((ret = ASN1_STRING_new()) == NULL)
return (NULL);
} else
ret = (*a);
if (len != 0) {
s = OPENSSL_malloc((int)len + 1);
if (s == NULL) {
i = ERR_R_MALLOC_FAILURE;
goto err;
}
memcpy(s, p, (int)len);
s[len] = '\0';
p += len;
} else
s = NULL;
if (ret->data != NULL)
OPENSSL_free(ret->data);
ret->length = (int)len;
ret->data = s;
ret->type = tag;
if (a != NULL)
(*a) = ret;
*pp = p;
return (ret);
err:
ASN1err(ASN1_F_D2I_ASN1_TYPE_BYTES, i);
if ((ret != NULL) && ((a == NULL) || (*a != ret)))
ASN1_STRING_free(ret);
return (NULL);
}
int i2d_ASN1_bytes(ASN1_STRING *a, unsigned char **pp, int tag, int xclass)
{
int ret, r, constructed;
unsigned char *p;
if (a == NULL)
return (0);
if (tag == V_ASN1_BIT_STRING)
return (i2d_ASN1_BIT_STRING(a, pp));
ret = a->length;
r = ASN1_object_size(0, ret, tag);
if (pp == NULL)
return (r);
p = *pp;
if ((tag == V_ASN1_SEQUENCE) || (tag == V_ASN1_SET))
constructed = 1;
else
constructed = 0;
ASN1_put_object(&p, constructed, ret, tag, xclass);
memcpy(p, a->data, a->length);
p += a->length;
*pp = p;
return (r);
}
/*
* Maximum recursion depth of d2i_ASN1_bytes(): much more than should be
* encountered in pratice.
*/
#define ASN1_BYTES_MAXDEPTH 20
ASN1_STRING *d2i_ASN1_bytes(ASN1_STRING **a, const unsigned char **pp,
long length, int Ptag, int Pclass)
{
int err = 0;
ASN1_STRING *s = int_d2i_ASN1_bytes(a, pp, length, Ptag, Pclass, 0, &err);
if (err != 0)
ASN1err(ASN1_F_D2I_ASN1_BYTES, err);
return s;
}
static ASN1_STRING *int_d2i_ASN1_bytes(ASN1_STRING **a,
const unsigned char **pp, long length,
int Ptag, int Pclass,
int depth, int *perr)
{
ASN1_STRING *ret = NULL;
const unsigned char *p;
unsigned char *s;
long len;
int inf, tag, xclass;
if (depth > ASN1_BYTES_MAXDEPTH) {
*perr = ASN1_R_NESTED_ASN1_STRING;
return NULL;
}
if ((a == NULL) || ((*a) == NULL)) {
if ((ret = ASN1_STRING_new()) == NULL)
return (NULL);
} else
ret = (*a);
p = *pp;
inf = ASN1_get_object(&p, &len, &tag, &xclass, length);
if (inf & 0x80) {
*perr = ASN1_R_BAD_OBJECT_HEADER;
goto err;
}
if (tag != Ptag) {
*perr = ASN1_R_WRONG_TAG;
goto err;
}
if (inf & V_ASN1_CONSTRUCTED) {
ASN1_const_CTX c;
c.error = 0;
c.pp = pp;
c.p = p;
c.inf = inf;
c.slen = len;
c.tag = Ptag;
c.xclass = Pclass;
c.max = (length == 0) ? 0 : (p + length);
if (!asn1_collate_primitive(ret, &c, depth)) {
*perr = c.error;
goto err;
} else {
p = c.p;
}
} else {
if (len != 0) {
if ((ret->length < len) || (ret->data == NULL)) {
s = OPENSSL_malloc((int)len + 1);
if (s == NULL) {
*perr = ERR_R_MALLOC_FAILURE;
goto err;
}
if (ret->data != NULL)
OPENSSL_free(ret->data);
} else
s = ret->data;
memcpy(s, p, (int)len);
s[len] = '\0';
p += len;
} else {
s = NULL;
if (ret->data != NULL)
OPENSSL_free(ret->data);
}
ret->length = (int)len;
ret->data = s;
ret->type = Ptag;
}
if (a != NULL)
(*a) = ret;
*pp = p;
return (ret);
err:
if ((ret != NULL) && ((a == NULL) || (*a != ret)))
ASN1_STRING_free(ret);
return (NULL);
}
/*
* We are about to parse 0..n d2i_ASN1_bytes objects, we are to collapse them
* into the one structure that is then returned
*/
/*
* There have been a few bug fixes for this function from Paul Keogh
* <paul.keogh@sse.ie>, many thanks to him
*/
static int asn1_collate_primitive(ASN1_STRING *a, ASN1_const_CTX *c,
int depth)
{
ASN1_STRING *os = NULL;
BUF_MEM b;
int num;
b.length = 0;
b.max = 0;
b.data = NULL;
if (a == NULL) {
c->error = ERR_R_PASSED_NULL_PARAMETER;
goto err;
}
num = 0;
for (;;) {
if (c->inf & 1) {
c->eos = ASN1_const_check_infinite_end(&c->p,
(long)(c->max - c->p));
if (c->eos)
break;
} else {
if (c->slen <= 0)
break;
}
c->q = c->p;
if (int_d2i_ASN1_bytes(&os, &c->p, c->max - c->p, c->tag, c->xclass,
depth + 1, &c->error) == NULL) {
goto err;
}
if (!BUF_MEM_grow_clean(&b, num + os->length)) {
c->error = ERR_R_BUF_LIB;
goto err;
}
memcpy(&(b.data[num]), os->data, os->length);
if (!(c->inf & 1))
c->slen -= (c->p - c->q);
num += os->length;
}
if (!asn1_const_Finish(c))
goto err;
a->length = num;
if (a->data != NULL)
OPENSSL_free(a->data);
a->data = (unsigned char *)b.data;
if (os != NULL)
ASN1_STRING_free(os);
return (1);
err:
if (os != NULL)
ASN1_STRING_free(os);
if (b.data != NULL)
OPENSSL_free(b.data);
return (0);
}

View File

@ -1,71 +1,23 @@
/* crypto/asn1/a_d2i_fp.c */ /*
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
* All rights reserved.
* *
* This package is an SSL implementation written * Licensed under the OpenSSL license (the "License"). You may not use
* by Eric Young (eay@cryptsoft.com). * this file except in compliance with the License. You can obtain a copy
* The implementation was written so as to conform with Netscapes SSL. * in the file LICENSE in the source distribution or at
* * https://www.openssl.org/source/license.html
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* "This product includes cryptographic software written by
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/ */
#include <stdio.h> #include <stdio.h>
#include <limits.h> #include <limits.h>
#include "cryptlib.h" #include "internal/cryptlib.h"
#include "internal/numbers.h"
#include <openssl/buffer.h> #include <openssl/buffer.h>
#include <openssl/asn1_mac.h> #include <openssl/asn1.h>
static int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb); static int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb);
#ifndef NO_OLD_ASN1 #ifndef NO_OLD_ASN1
# ifndef OPENSSL_NO_FP_API # ifndef OPENSSL_NO_STDIO
void *ASN1_d2i_fp(void *(*xnew) (void), d2i_of_void *d2i, FILE *in, void **x) void *ASN1_d2i_fp(void *(*xnew) (void), d2i_of_void *d2i, FILE *in, void **x)
{ {
@ -97,7 +49,6 @@ void *ASN1_d2i_bio(void *(*xnew) (void), d2i_of_void *d2i, BIO *in, void **x)
p = (unsigned char *)b->data; p = (unsigned char *)b->data;
ret = d2i(x, &p, len); ret = d2i(x, &p, len);
err: err:
if (b != NULL)
BUF_MEM_free(b); BUF_MEM_free(b);
return (ret); return (ret);
} }
@ -118,12 +69,11 @@ void *ASN1_item_d2i_bio(const ASN1_ITEM *it, BIO *in, void *x)
p = (const unsigned char *)b->data; p = (const unsigned char *)b->data;
ret = ASN1_item_d2i(x, &p, len, it); ret = ASN1_item_d2i(x, &p, len, it);
err: err:
if (b != NULL)
BUF_MEM_free(b); BUF_MEM_free(b);
return (ret); return (ret);
} }
#ifndef OPENSSL_NO_FP_API #ifndef OPENSSL_NO_STDIO
void *ASN1_item_d2i_fp(const ASN1_ITEM *it, FILE *in, void *x) void *ASN1_item_d2i_fp(const ASN1_ITEM *it, FILE *in, void *x)
{ {
BIO *b; BIO *b;
@ -147,12 +97,15 @@ static int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb)
BUF_MEM *b; BUF_MEM *b;
unsigned char *p; unsigned char *p;
int i; int i;
ASN1_const_CTX c;
size_t want = HEADER_SIZE; size_t want = HEADER_SIZE;
int eos = 0; uint32_t eos = 0;
size_t off = 0; size_t off = 0;
size_t len = 0; size_t len = 0;
const unsigned char *q;
long slen;
int inf, tag, xclass;
b = BUF_MEM_new(); b = BUF_MEM_new();
if (b == NULL) { if (b == NULL) {
ASN1err(ASN1_F_ASN1_D2I_READ_BIO, ERR_R_MALLOC_FAILURE); ASN1err(ASN1_F_ASN1_D2I_READ_BIO, ERR_R_MALLOC_FAILURE);
@ -184,10 +137,9 @@ static int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb)
/* else data already loaded */ /* else data already loaded */
p = (unsigned char *)&(b->data[off]); p = (unsigned char *)&(b->data[off]);
c.p = p; q = p;
c.inf = ASN1_get_object(&(c.p), &(c.slen), &(c.tag), &(c.xclass), inf = ASN1_get_object(&q, &slen, &tag, &xclass, len - off);
len - off); if (inf & 0x80) {
if (c.inf & 0x80) {
unsigned long e; unsigned long e;
e = ERR_GET_REASON(ERR_peek_error()); e = ERR_GET_REASON(ERR_peek_error());
@ -196,27 +148,27 @@ static int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb)
else else
ERR_clear_error(); /* clear error */ ERR_clear_error(); /* clear error */
} }
i = c.p - p; /* header length */ i = q - p; /* header length */
off += i; /* end of data */ off += i; /* end of data */
if (c.inf & 1) { if (inf & 1) {
/* no data body so go round again */ /* no data body so go round again */
eos++; if (eos == UINT32_MAX) {
if (eos < 0) {
ASN1err(ASN1_F_ASN1_D2I_READ_BIO, ASN1_R_HEADER_TOO_LONG); ASN1err(ASN1_F_ASN1_D2I_READ_BIO, ASN1_R_HEADER_TOO_LONG);
goto err; goto err;
} }
eos++;
want = HEADER_SIZE; want = HEADER_SIZE;
} else if (eos && (c.slen == 0) && (c.tag == V_ASN1_EOC)) { } else if (eos && (slen == 0) && (tag == V_ASN1_EOC)) {
/* eos value, so go back and read another header */ /* eos value, so go back and read another header */
eos--; eos--;
if (eos <= 0) if (eos == 0)
break; break;
else else
want = HEADER_SIZE; want = HEADER_SIZE;
} else { } else {
/* suck in c.slen bytes of data */ /* suck in slen bytes of data */
want = c.slen; want = slen;
if (want > (len - off)) { if (want > (len - off)) {
size_t chunk_max = ASN1_CHUNK_INITIAL_SIZE; size_t chunk_max = ASN1_CHUNK_INITIAL_SIZE;
@ -258,12 +210,12 @@ static int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb)
chunk_max *= 2; chunk_max *= 2;
} }
} }
if (off + c.slen < off) { if (off + slen < off) {
ASN1err(ASN1_F_ASN1_D2I_READ_BIO, ASN1_R_TOO_LONG); ASN1err(ASN1_F_ASN1_D2I_READ_BIO, ASN1_R_TOO_LONG);
goto err; goto err;
} }
off += c.slen; off += slen;
if (eos <= 0) { if (eos == 0) {
break; break;
} else } else
want = HEADER_SIZE; want = HEADER_SIZE;
@ -278,7 +230,6 @@ static int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb)
*pb = b; *pb = b;
return off; return off;
err: err:
if (b != NULL)
BUF_MEM_free(b); BUF_MEM_free(b);
return -1; return -1;
} }

View File

@ -1,65 +1,16 @@
/* crypto/asn1/a_digest.c */ /*
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
* All rights reserved.
* *
* This package is an SSL implementation written * Licensed under the OpenSSL license (the "License"). You may not use
* by Eric Young (eay@cryptsoft.com). * this file except in compliance with the License. You can obtain a copy
* The implementation was written so as to conform with Netscapes SSL. * in the file LICENSE in the source distribution or at
* * https://www.openssl.org/source/license.html
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* "This product includes cryptographic software written by
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/ */
#include <stdio.h> #include <stdio.h>
#include <time.h> #include <time.h>
#include "cryptlib.h" #include "internal/cryptlib.h"
#ifndef NO_SYS_TYPES_H #ifndef NO_SYS_TYPES_H
# include <sys/types.h> # include <sys/types.h>
@ -79,15 +30,17 @@ int ASN1_digest(i2d_of_void *i2d, const EVP_MD *type, char *data,
unsigned char *str, *p; unsigned char *str, *p;
i = i2d(data, NULL); i = i2d(data, NULL);
if ((str = (unsigned char *)OPENSSL_malloc(i)) == NULL) { if ((str = OPENSSL_malloc(i)) == NULL) {
ASN1err(ASN1_F_ASN1_DIGEST, ERR_R_MALLOC_FAILURE); ASN1err(ASN1_F_ASN1_DIGEST, ERR_R_MALLOC_FAILURE);
return (0); return (0);
} }
p = str; p = str;
i2d(data, &p); i2d(data, &p);
if (!EVP_Digest(str, i, md, len, type, NULL)) if (!EVP_Digest(str, i, md, len, type, NULL)) {
OPENSSL_free(str);
return 0; return 0;
}
OPENSSL_free(str); OPENSSL_free(str);
return (1); return (1);
} }
@ -104,8 +57,10 @@ int ASN1_item_digest(const ASN1_ITEM *it, const EVP_MD *type, void *asn,
if (!str) if (!str)
return (0); return (0);
if (!EVP_Digest(str, i, md, len, type, NULL)) if (!EVP_Digest(str, i, md, len, type, NULL)) {
OPENSSL_free(str);
return 0; return 0;
}
OPENSSL_free(str); OPENSSL_free(str);
return (1); return (1);
} }

View File

@ -1,63 +1,14 @@
/* crypto/asn1/a_dup.c */ /*
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
* All rights reserved.
* *
* This package is an SSL implementation written * Licensed under the OpenSSL license (the "License"). You may not use
* by Eric Young (eay@cryptsoft.com). * this file except in compliance with the License. You can obtain a copy
* The implementation was written so as to conform with Netscapes SSL. * in the file LICENSE in the source distribution or at
* * https://www.openssl.org/source/license.html
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* "This product includes cryptographic software written by
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/ */
#include <stdio.h> #include <stdio.h>
#include "cryptlib.h" #include "internal/cryptlib.h"
#include <openssl/asn1.h> #include <openssl/asn1.h>
#ifndef NO_OLD_ASN1 #ifndef NO_OLD_ASN1

View File

@ -1,181 +0,0 @@
/* crypto/asn1/a_enum.c */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
* This package is an SSL implementation written
* by Eric Young (eay@cryptsoft.com).
* The implementation was written so as to conform with Netscapes SSL.
*
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* "This product includes cryptographic software written by
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/
#include <stdio.h>
#include "cryptlib.h"
#include <openssl/asn1.h>
#include <openssl/bn.h>
/*
* Code for ENUMERATED type: identical to INTEGER apart from a different tag.
* for comments on encoding see a_int.c
*/
int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v)
{
int j, k;
unsigned int i;
unsigned char buf[sizeof(long) + 1];
long d;
a->type = V_ASN1_ENUMERATED;
if (a->length < (int)(sizeof(long) + 1)) {
if (a->data != NULL)
OPENSSL_free(a->data);
if ((a->data =
(unsigned char *)OPENSSL_malloc(sizeof(long) + 1)) != NULL)
memset((char *)a->data, 0, sizeof(long) + 1);
}
if (a->data == NULL) {
ASN1err(ASN1_F_ASN1_ENUMERATED_SET, ERR_R_MALLOC_FAILURE);
return (0);
}
d = v;
if (d < 0) {
d = -d;
a->type = V_ASN1_NEG_ENUMERATED;
}
for (i = 0; i < sizeof(long); i++) {
if (d == 0)
break;
buf[i] = (int)d & 0xff;
d >>= 8;
}
j = 0;
for (k = i - 1; k >= 0; k--)
a->data[j++] = buf[k];
a->length = j;
return (1);
}
long ASN1_ENUMERATED_get(ASN1_ENUMERATED *a)
{
int neg = 0, i;
long r = 0;
if (a == NULL)
return (0L);
i = a->type;
if (i == V_ASN1_NEG_ENUMERATED)
neg = 1;
else if (i != V_ASN1_ENUMERATED)
return -1;
if (a->length > (int)sizeof(long)) {
/* hmm... a bit ugly */
return (0xffffffffL);
}
if (a->data == NULL)
return 0;
for (i = 0; i < a->length; i++) {
r <<= 8;
r |= (unsigned char)a->data[i];
}
if (neg)
r = -r;
return (r);
}
ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai)
{
ASN1_ENUMERATED *ret;
int len, j;
if (ai == NULL)
ret = M_ASN1_ENUMERATED_new();
else
ret = ai;
if (ret == NULL) {
ASN1err(ASN1_F_BN_TO_ASN1_ENUMERATED, ERR_R_NESTED_ASN1_ERROR);
goto err;
}
if (BN_is_negative(bn))
ret->type = V_ASN1_NEG_ENUMERATED;
else
ret->type = V_ASN1_ENUMERATED;
j = BN_num_bits(bn);
len = ((j == 0) ? 0 : ((j / 8) + 1));
if (ret->length < len + 4) {
unsigned char *new_data = OPENSSL_realloc(ret->data, len + 4);
if (!new_data) {
ASN1err(ASN1_F_BN_TO_ASN1_ENUMERATED, ERR_R_MALLOC_FAILURE);
goto err;
}
ret->data = new_data;
}
ret->length = BN_bn2bin(bn, ret->data);
return (ret);
err:
if (ret != ai)
M_ASN1_ENUMERATED_free(ret);
return (NULL);
}
BIGNUM *ASN1_ENUMERATED_to_BN(ASN1_ENUMERATED *ai, BIGNUM *bn)
{
BIGNUM *ret;
if ((ret = BN_bin2bn(ai->data, ai->length, bn)) == NULL)
ASN1err(ASN1_F_ASN1_ENUMERATED_TO_BN, ASN1_R_BN_LIB);
else if (ai->type == V_ASN1_NEG_ENUMERATED)
BN_set_negative(ret, 1);
return (ret);
}

View File

@ -1,123 +1,22 @@
/* crypto/asn1/a_gentm.c */ /*
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
* All rights reserved.
* *
* This package is an SSL implementation written * Licensed under the OpenSSL license (the "License"). You may not use
* by Eric Young (eay@cryptsoft.com). * this file except in compliance with the License. You can obtain a copy
* The implementation was written so as to conform with Netscapes SSL. * in the file LICENSE in the source distribution or at
* * https://www.openssl.org/source/license.html
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* "This product includes cryptographic software written by
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/ */
/* /*
* GENERALIZEDTIME implementation, written by Steve Henson. Based on UTCTIME * GENERALIZEDTIME implementation. Based on UTCTIME
*/ */
#include <stdio.h> #include <stdio.h>
#include <time.h> #include <time.h>
#include "cryptlib.h" #include "internal/cryptlib.h"
#include "o_time.h"
#include <openssl/asn1.h> #include <openssl/asn1.h>
#include "asn1_locl.h" #include "asn1_locl.h"
#if 0
int i2d_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME *a, unsigned char **pp)
{
# ifdef CHARSET_EBCDIC
/* KLUDGE! We convert to ascii before writing DER */
int len;
char tmp[24];
ASN1_STRING tmpstr = *(ASN1_STRING *)a;
len = tmpstr.length;
ebcdic2ascii(tmp, tmpstr.data, (len >= sizeof tmp) ? sizeof tmp : len);
tmpstr.data = tmp;
a = (ASN1_GENERALIZEDTIME *)&tmpstr;
# endif
return (i2d_ASN1_bytes((ASN1_STRING *)a, pp,
V_ASN1_GENERALIZEDTIME, V_ASN1_UNIVERSAL));
}
ASN1_GENERALIZEDTIME *d2i_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME **a,
unsigned char **pp,
long length)
{
ASN1_GENERALIZEDTIME *ret = NULL;
ret =
(ASN1_GENERALIZEDTIME *)d2i_ASN1_bytes((ASN1_STRING **)a, pp, length,
V_ASN1_GENERALIZEDTIME,
V_ASN1_UNIVERSAL);
if (ret == NULL) {
ASN1err(ASN1_F_D2I_ASN1_GENERALIZEDTIME, ERR_R_NESTED_ASN1_ERROR);
return (NULL);
}
# ifdef CHARSET_EBCDIC
ascii2ebcdic(ret->data, ret->data, ret->length);
# endif
if (!ASN1_GENERALIZEDTIME_check(ret)) {
ASN1err(ASN1_F_D2I_ASN1_GENERALIZEDTIME, ASN1_R_INVALID_TIME_FORMAT);
goto err;
}
return (ret);
err:
if ((ret != NULL) && ((a == NULL) || (*a != ret)))
M_ASN1_GENERALIZEDTIME_free(ret);
return (NULL);
}
#endif
int asn1_generalizedtime_to_tm(struct tm *tm, const ASN1_GENERALIZEDTIME *d) int asn1_generalizedtime_to_tm(struct tm *tm, const ASN1_GENERALIZEDTIME *d)
{ {
static const int min[9] = { 0, 0, 1, 1, 0, 0, 0, 0, 0 }; static const int min[9] = { 0, 0, 1, 1, 0, 0, 0, 0, 0 };
@ -249,8 +148,7 @@ int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, const char *str)
t.data = (unsigned char *)str; t.data = (unsigned char *)str;
if (ASN1_GENERALIZEDTIME_check(&t)) { if (ASN1_GENERALIZEDTIME_check(&t)) {
if (s != NULL) { if (s != NULL) {
if (!ASN1_STRING_set((ASN1_STRING *)s, if (!ASN1_STRING_set((ASN1_STRING *)s, str, t.length))
(unsigned char *)str, t.length))
return 0; return 0;
s->type = V_ASN1_GENERALIZEDTIME; s->type = V_ASN1_GENERALIZEDTIME;
} }
@ -273,40 +171,103 @@ ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_adj(ASN1_GENERALIZEDTIME *s,
struct tm *ts; struct tm *ts;
struct tm data; struct tm data;
size_t len = 20; size_t len = 20;
ASN1_GENERALIZEDTIME *tmps = NULL;
if (s == NULL) if (s == NULL)
s = M_ASN1_GENERALIZEDTIME_new(); tmps = ASN1_GENERALIZEDTIME_new();
if (s == NULL) else
return (NULL); tmps = s;
if (tmps == NULL)
return NULL;
ts = OPENSSL_gmtime(&t, &data); ts = OPENSSL_gmtime(&t, &data);
if (ts == NULL) if (ts == NULL)
return (NULL); goto err;
if (offset_day || offset_sec) { if (offset_day || offset_sec) {
if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec)) if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec))
return NULL; goto err;
} }
p = (char *)s->data; p = (char *)tmps->data;
if ((p == NULL) || ((size_t)s->length < len)) { if ((p == NULL) || ((size_t)tmps->length < len)) {
p = OPENSSL_malloc(len); p = OPENSSL_malloc(len);
if (p == NULL) { if (p == NULL) {
ASN1err(ASN1_F_ASN1_GENERALIZEDTIME_ADJ, ERR_R_MALLOC_FAILURE); ASN1err(ASN1_F_ASN1_GENERALIZEDTIME_ADJ, ERR_R_MALLOC_FAILURE);
return (NULL); goto err;
} }
if (s->data != NULL) OPENSSL_free(tmps->data);
OPENSSL_free(s->data); tmps->data = (unsigned char *)p;
s->data = (unsigned char *)p;
} }
BIO_snprintf(p, len, "%04d%02d%02d%02d%02d%02dZ", ts->tm_year + 1900, BIO_snprintf(p, len, "%04d%02d%02d%02d%02d%02dZ", ts->tm_year + 1900,
ts->tm_mon + 1, ts->tm_mday, ts->tm_hour, ts->tm_min, ts->tm_mon + 1, ts->tm_mday, ts->tm_hour, ts->tm_min,
ts->tm_sec); ts->tm_sec);
s->length = strlen(p); tmps->length = strlen(p);
s->type = V_ASN1_GENERALIZEDTIME; tmps->type = V_ASN1_GENERALIZEDTIME;
#ifdef CHARSET_EBCDIC_not #ifdef CHARSET_EBCDIC_not
ebcdic2ascii(s->data, s->data, s->length); ebcdic2ascii(tmps->data, tmps->data, tmps->length);
#endif #endif
return (s); return tmps;
err:
if (s == NULL)
ASN1_GENERALIZEDTIME_free(tmps);
return NULL;
}
const char *_asn1_mon[12] = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};
int ASN1_GENERALIZEDTIME_print(BIO *bp, const ASN1_GENERALIZEDTIME *tm)
{
char *v;
int gmt = 0;
int i;
int y = 0, M = 0, d = 0, h = 0, m = 0, s = 0;
char *f = NULL;
int f_len = 0;
i = tm->length;
v = (char *)tm->data;
if (i < 12)
goto err;
if (v[i - 1] == 'Z')
gmt = 1;
for (i = 0; i < 12; i++)
if ((v[i] > '9') || (v[i] < '0'))
goto err;
y = (v[0] - '0') * 1000 + (v[1] - '0') * 100
+ (v[2] - '0') * 10 + (v[3] - '0');
M = (v[4] - '0') * 10 + (v[5] - '0');
if ((M > 12) || (M < 1))
goto err;
d = (v[6] - '0') * 10 + (v[7] - '0');
h = (v[8] - '0') * 10 + (v[9] - '0');
m = (v[10] - '0') * 10 + (v[11] - '0');
if (tm->length >= 14 &&
(v[12] >= '0') && (v[12] <= '9') &&
(v[13] >= '0') && (v[13] <= '9')) {
s = (v[12] - '0') * 10 + (v[13] - '0');
/* Check for fractions of seconds. */
if (tm->length >= 15 && v[14] == '.') {
int l = tm->length;
f = &v[14]; /* The decimal point. */
f_len = 1;
while (14 + f_len < l && f[f_len] >= '0' && f[f_len] <= '9')
++f_len;
}
}
if (BIO_printf(bp, "%s %2d %02d:%02d:%02d%.*s %d%s",
_asn1_mon[M - 1], d, h, m, s, f_len, f, y,
(gmt) ? " GMT" : "") <= 0)
return (0);
else
return (1);
err:
BIO_write(bp, "Bad time value", 14);
return (0);
} }

View File

@ -1,69 +1,20 @@
/* crypto/asn1/a_i2d_fp.c */ /*
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
* All rights reserved.
* *
* This package is an SSL implementation written * Licensed under the OpenSSL license (the "License"). You may not use
* by Eric Young (eay@cryptsoft.com). * this file except in compliance with the License. You can obtain a copy
* The implementation was written so as to conform with Netscapes SSL. * in the file LICENSE in the source distribution or at
* * https://www.openssl.org/source/license.html
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* "This product includes cryptographic software written by
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/ */
#include <stdio.h> #include <stdio.h>
#include "cryptlib.h" #include "internal/cryptlib.h"
#include <openssl/buffer.h> #include <openssl/buffer.h>
#include <openssl/asn1.h> #include <openssl/asn1.h>
#ifndef NO_OLD_ASN1 #ifndef NO_OLD_ASN1
# ifndef OPENSSL_NO_FP_API # ifndef OPENSSL_NO_STDIO
int ASN1_i2d_fp(i2d_of_void *i2d, FILE *out, void *x) int ASN1_i2d_fp(i2d_of_void *i2d, FILE *out, void *x)
{ {
BIO *b; BIO *b;
@ -87,7 +38,7 @@ int ASN1_i2d_bio(i2d_of_void *i2d, BIO *out, unsigned char *x)
int i, j = 0, n, ret = 1; int i, j = 0, n, ret = 1;
n = i2d(x, NULL); n = i2d(x, NULL);
b = (char *)OPENSSL_malloc(n); b = OPENSSL_malloc(n);
if (b == NULL) { if (b == NULL) {
ASN1err(ASN1_F_ASN1_I2D_BIO, ERR_R_MALLOC_FAILURE); ASN1err(ASN1_F_ASN1_I2D_BIO, ERR_R_MALLOC_FAILURE);
return (0); return (0);
@ -113,7 +64,7 @@ int ASN1_i2d_bio(i2d_of_void *i2d, BIO *out, unsigned char *x)
#endif #endif
#ifndef OPENSSL_NO_FP_API #ifndef OPENSSL_NO_STDIO
int ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out, void *x) int ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out, void *x)
{ {
BIO *b; BIO *b;

View File

@ -1,69 +1,23 @@
/* crypto/asn1/a_int.c */ /*
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
* All rights reserved.
* *
* This package is an SSL implementation written * Licensed under the OpenSSL license (the "License"). You may not use
* by Eric Young (eay@cryptsoft.com). * this file except in compliance with the License. You can obtain a copy
* The implementation was written so as to conform with Netscapes SSL. * in the file LICENSE in the source distribution or at
* * https://www.openssl.org/source/license.html
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* "This product includes cryptographic software written by
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/ */
#include <stdio.h> #include <stdio.h>
#include "cryptlib.h" #include "internal/cryptlib.h"
#include "internal/numbers.h"
#include <limits.h>
#include <openssl/asn1.h> #include <openssl/asn1.h>
#include <openssl/bn.h> #include <openssl/bn.h>
#include "asn1_locl.h"
ASN1_INTEGER *ASN1_INTEGER_dup(const ASN1_INTEGER *x) ASN1_INTEGER *ASN1_INTEGER_dup(const ASN1_INTEGER *x)
{ {
return M_ASN1_INTEGER_dup(x); return ASN1_STRING_dup(x);
} }
int ASN1_INTEGER_cmp(const ASN1_INTEGER *x, const ASN1_INTEGER *y) int ASN1_INTEGER_cmp(const ASN1_INTEGER *x, const ASN1_INTEGER *y)
@ -87,10 +41,11 @@ int ASN1_INTEGER_cmp(const ASN1_INTEGER *x, const ASN1_INTEGER *y)
} }
/*- /*-
* This converts an ASN1 INTEGER into its content encoding. * This converts a big endian buffer and sign into its content encoding.
* This is used for INTEGER and ENUMERATED types.
* The internal representation is an ASN1_STRING whose data is a big endian * The internal representation is an ASN1_STRING whose data is a big endian
* representation of the value, ignoring the sign. The sign is determined by * representation of the value, ignoring the sign. The sign is determined by
* the type: V_ASN1_INTEGER for positive and V_ASN1_NEG_INTEGER for negative. * the type: if type & V_ASN1_NEG is true it is negative, otherwise positive.
* *
* Positive integers are no problem: they are almost the same as the DER * Positive integers are no problem: they are almost the same as the DER
* encoding, except if the first byte is >= 0x80 we need to add a zero pad. * encoding, except if the first byte is >= 0x80 we need to add a zero pad.
@ -111,19 +66,19 @@ int ASN1_INTEGER_cmp(const ASN1_INTEGER *x, const ASN1_INTEGER *y)
* followed by optional zeros isn't padded. * followed by optional zeros isn't padded.
*/ */
int i2c_ASN1_INTEGER(ASN1_INTEGER *a, unsigned char **pp) static size_t i2c_ibuf(const unsigned char *b, size_t blen, int neg,
unsigned char **pp)
{ {
int pad = 0, ret, i, neg; int pad = 0;
unsigned char *p, *n, pb = 0; size_t ret, i;
unsigned char *p, pb = 0;
const unsigned char *n;
if (a == NULL) if (b == NULL || blen == 0)
return (0);
neg = a->type & V_ASN1_NEG;
if (a->length == 0)
ret = 1; ret = 1;
else { else {
ret = a->length; ret = blen;
i = a->data[0]; i = b[0];
if (ret == 1 && i == 0) if (ret == 1 && i == 0)
neg = 0; neg = 0;
if (!neg && (i > 127)) { if (!neg && (i > 127)) {
@ -138,8 +93,8 @@ int i2c_ASN1_INTEGER(ASN1_INTEGER *a, unsigned char **pp)
* Special case: if any other bytes non zero we pad: * Special case: if any other bytes non zero we pad:
* otherwise we don't. * otherwise we don't.
*/ */
for (i = 1; i < a->length; i++) for (i = 1; i < blen; i++)
if (a->data[i]) { if (b[i]) {
pad = 1; pad = 1;
pb = 0xFF; pb = 0xFF;
break; break;
@ -149,127 +104,299 @@ int i2c_ASN1_INTEGER(ASN1_INTEGER *a, unsigned char **pp)
ret += pad; ret += pad;
} }
if (pp == NULL) if (pp == NULL)
return (ret); return ret;
p = *pp; p = *pp;
if (pad) if (pad)
*(p++) = pb; *(p++) = pb;
if (a->length == 0) if (b == NULL || blen == 0)
*(p++) = 0; *p = 0;
else if (!neg) else if (!neg)
memcpy(p, a->data, (unsigned int)a->length); memcpy(p, b, blen);
else { else {
/* Begin at the end of the encoding */ /* Begin at the end of the encoding */
n = a->data + a->length - 1; n = b + blen;
p += a->length - 1; p += blen;
i = a->length; i = blen;
/* Copy zeros to destination as long as source is zero */ /* Copy zeros to destination as long as source is zero */
while (!*n && i > 1) { while (!n[-1] && i > 1) {
*(p--) = 0; *(--p) = 0;
n--; n--;
i--; i--;
} }
/* Complement and increment next octet */ /* Complement and increment next octet */
*(p--) = ((*(n--)) ^ 0xff) + 1; *(--p) = ((*(--n)) ^ 0xff) + 1;
i--; i--;
/* Complement any octets left */ /* Complement any octets left */
for (; i > 0; i--) for (; i > 0; i--)
*(p--) = *(n--) ^ 0xff; *(--p) = *(--n) ^ 0xff;
} }
*pp += ret; *pp += ret;
return (ret); return ret;
} }
/* Convert just ASN1 INTEGER content octets to ASN1_INTEGER structure */ /*
* convert content octets into a big endian buffer. Returns the length
* of buffer or 0 on error: for malformed INTEGER. If output buffer is
* NULL just return length.
*/
static size_t c2i_ibuf(unsigned char *b, int *pneg,
const unsigned char *p, size_t plen)
{
size_t i;
int neg, pad;
/* Zero content length is illegal */
if (plen == 0) {
ASN1err(ASN1_F_C2I_IBUF, ASN1_R_ILLEGAL_ZERO_CONTENT);
return 0;
}
neg = p[0] & 0x80;
if (pneg)
*pneg = neg;
/* Handle common case where length is 1 octet separately */
if (plen == 1) {
if (b) {
if (neg)
b[0] = (p[0] ^ 0xFF) + 1;
else
b[0] = p[0];
}
return 1;
}
if (p[0] == 0 || p[0] == 0xFF)
pad = 1;
else
pad = 0;
/* reject illegal padding: first two octets MSB can't match */
if (pad && (neg == (p[1] & 0x80))) {
ASN1err(ASN1_F_C2I_IBUF, ASN1_R_ILLEGAL_PADDING);
return 0;
}
/* If positive just copy across */
if (neg == 0) {
if (b)
memcpy(b, p + pad, plen - pad);
return plen - pad;
}
if (neg && pad) {
/* check is any following octets are non zero */
for (i = 1; i < plen; i++) {
if (p[i] != 0)
break;
}
/* if all bytes are zero handle as special case */
if (i == plen) {
if (b) {
b[0] = 1;
memset(b + 1, 0, plen - 1);
}
return plen;
}
}
plen -= pad;
/* Must be negative: calculate twos complement */
if (b) {
const unsigned char *from = p + plen - 1 + pad;
unsigned char *to = b + plen;
i = plen;
while (*from == 0 && i) {
*--to = 0;
i--;
from--;
}
*--to = (*from-- ^ 0xff) + 1;
OPENSSL_assert(i != 0);
i--;
for (; i > 0; i--)
*--to = *from-- ^ 0xff;
}
return plen;
}
int i2c_ASN1_INTEGER(ASN1_INTEGER *a, unsigned char **pp)
{
return i2c_ibuf(a->data, a->length, a->type & V_ASN1_NEG, pp);
}
/* Convert big endian buffer into uint64_t, return 0 on error */
static int asn1_get_uint64(uint64_t *pr, const unsigned char *b, size_t blen)
{
size_t i;
if (blen > sizeof(*pr)) {
ASN1err(ASN1_F_ASN1_GET_UINT64, ASN1_R_TOO_LARGE);
return 0;
}
*pr = 0;
if (b == NULL)
return 0;
for (i = 0; i < blen; i++) {
*pr <<= 8;
*pr |= b[i];
}
return 1;
}
static size_t asn1_put_uint64(unsigned char *b, uint64_t r)
{
if (r >= 0x100) {
unsigned char *p;
uint64_t rtmp = r;
size_t i = 0;
/* Work out how many bytes we need */
while (rtmp) {
rtmp >>= 8;
i++;
}
/* Copy from end to beginning */
p = b + i - 1;
do {
*p-- = r & 0xFF;
r >>= 8;
} while (p >= b);
return i;
}
b[0] = (unsigned char)r;
return 1;
}
/*
* Absolute value of INT64_MIN: we can't just use -INT64_MIN as it produces
* overflow warnings.
*/
#define ABS_INT64_MIN \
((uint64_t)INT64_MAX + (uint64_t)(-(INT64_MIN + INT64_MAX)))
/* signed version of asn1_get_uint64 */
static int asn1_get_int64(int64_t *pr, const unsigned char *b, size_t blen,
int neg)
{
uint64_t r;
if (asn1_get_uint64(&r, b, blen) == 0)
return 0;
if (neg) {
if (r > ABS_INT64_MIN) {
ASN1err(ASN1_F_ASN1_GET_INT64, ASN1_R_TOO_SMALL);
return 0;
}
*pr = 0 - (uint64_t)r;
} else {
if (r > INT64_MAX) {
ASN1err(ASN1_F_ASN1_GET_INT64, ASN1_R_TOO_LARGE);
return 0;
}
*pr = (int64_t)r;
}
return 1;
}
/* Convert ASN1 INTEGER content octets to ASN1_INTEGER structure */
ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **a, const unsigned char **pp, ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **a, const unsigned char **pp,
long len) long len)
{ {
ASN1_INTEGER *ret = NULL; ASN1_INTEGER *ret = NULL;
const unsigned char *p, *pend; size_t r;
unsigned char *to, *s; int neg;
int i;
r = c2i_ibuf(NULL, NULL, *pp, len);
if (r == 0)
return NULL;
if ((a == NULL) || ((*a) == NULL)) { if ((a == NULL) || ((*a) == NULL)) {
if ((ret = M_ASN1_INTEGER_new()) == NULL) ret = ASN1_INTEGER_new();
return (NULL); if (ret == NULL)
return NULL;
ret->type = V_ASN1_INTEGER; ret->type = V_ASN1_INTEGER;
} else } else
ret = (*a); ret = *a;
p = *pp; if (ASN1_STRING_set(ret, NULL, r) == 0)
pend = p + len;
/*
* We must OPENSSL_malloc stuff, even for 0 bytes otherwise it signifies
* a missing NULL parameter.
*/
s = (unsigned char *)OPENSSL_malloc((int)len + 1);
if (s == NULL) {
i = ERR_R_MALLOC_FAILURE;
goto err; goto err;
}
to = s;
if (!len) {
/*
* Strictly speaking this is an illegal INTEGER but we tolerate it.
*/
ret->type = V_ASN1_INTEGER;
} else if (*p & 0x80) { /* a negative number */
ret->type = V_ASN1_NEG_INTEGER;
if ((*p == 0xff) && (len != 1)) {
p++;
len--;
}
i = len;
p += i - 1;
to += i - 1;
while ((!*p) && i) {
*(to--) = 0;
i--;
p--;
}
/*
* Special case: if all zeros then the number will be of the form FF
* followed by n zero bytes: this corresponds to 1 followed by n zero
* bytes. We've already written n zeros so we just append an extra
* one and set the first byte to a 1. This is treated separately
* because it is the only case where the number of bytes is larger
* than len.
*/
if (!i) {
*s = 1;
s[len] = 0;
len++;
} else {
*(to--) = (*(p--) ^ 0xff) + 1;
i--;
for (; i > 0; i--)
*(to--) = *(p--) ^ 0xff;
}
} else {
ret->type = V_ASN1_INTEGER;
if ((*p == 0) && (len != 1)) {
p++;
len--;
}
memcpy(s, p, (int)len);
}
if (ret->data != NULL) c2i_ibuf(ret->data, &neg, *pp, len);
OPENSSL_free(ret->data);
ret->data = s; if (neg)
ret->length = (int)len; ret->type |= V_ASN1_NEG;
*pp += len;
if (a != NULL) if (a != NULL)
(*a) = ret; (*a) = ret;
*pp = pend; return ret;
return (ret);
err: err:
ASN1err(ASN1_F_C2I_ASN1_INTEGER, i); ASN1err(ASN1_F_C2I_ASN1_INTEGER, ERR_R_MALLOC_FAILURE);
if ((ret != NULL) && ((a == NULL) || (*a != ret))) if ((a == NULL) || (*a != ret))
M_ASN1_INTEGER_free(ret); ASN1_INTEGER_free(ret);
return (NULL); return NULL;
}
static int asn1_string_get_int64(int64_t *pr, const ASN1_STRING *a, int itype)
{
if (a == NULL) {
ASN1err(ASN1_F_ASN1_STRING_GET_INT64, ERR_R_PASSED_NULL_PARAMETER);
return 0;
}
if ((a->type & ~V_ASN1_NEG) != itype) {
ASN1err(ASN1_F_ASN1_STRING_GET_INT64, ASN1_R_WRONG_INTEGER_TYPE);
return 0;
}
return asn1_get_int64(pr, a->data, a->length, a->type & V_ASN1_NEG);
}
static int asn1_string_set_int64(ASN1_STRING *a, int64_t r, int itype)
{
unsigned char tbuf[sizeof(r)];
size_t l;
a->type = itype;
if (r < 0) {
l = asn1_put_uint64(tbuf, -r);
a->type |= V_ASN1_NEG;
} else {
l = asn1_put_uint64(tbuf, r);
a->type &= ~V_ASN1_NEG;
}
if (l == 0)
return 0;
return ASN1_STRING_set(a, tbuf, l);
}
static int asn1_string_get_uint64(uint64_t *pr, const ASN1_STRING *a,
int itype)
{
if (a == NULL) {
ASN1err(ASN1_F_ASN1_STRING_GET_UINT64, ERR_R_PASSED_NULL_PARAMETER);
return 0;
}
if ((a->type & ~V_ASN1_NEG) != itype) {
ASN1err(ASN1_F_ASN1_STRING_GET_UINT64, ASN1_R_WRONG_INTEGER_TYPE);
return 0;
}
if (a->type & V_ASN1_NEG) {
ASN1err(ASN1_F_ASN1_STRING_GET_UINT64, ASN1_R_ILLEGAL_NEGATIVE_VALUE);
return 0;
}
return asn1_get_uint64(pr, a->data, a->length);
}
static int asn1_string_set_uint64(ASN1_STRING *a, uint64_t r, int itype)
{
unsigned char tbuf[sizeof(r)];
size_t l;
a->type = itype;
l = asn1_put_uint64(tbuf, r);
if (l == 0)
return 0;
return ASN1_STRING_set(a, tbuf, l);
} }
/* /*
@ -289,7 +416,7 @@ ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a, const unsigned char **pp,
int i; int i;
if ((a == NULL) || ((*a) == NULL)) { if ((a == NULL) || ((*a) == NULL)) {
if ((ret = M_ASN1_INTEGER_new()) == NULL) if ((ret = ASN1_INTEGER_new()) == NULL)
return (NULL); return (NULL);
ret->type = V_ASN1_INTEGER; ret->type = V_ASN1_INTEGER;
} else } else
@ -311,7 +438,7 @@ ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a, const unsigned char **pp,
* We must OPENSSL_malloc stuff, even for 0 bytes otherwise it signifies * We must OPENSSL_malloc stuff, even for 0 bytes otherwise it signifies
* a missing NULL parameter. * a missing NULL parameter.
*/ */
s = (unsigned char *)OPENSSL_malloc((int)len + 1); s = OPENSSL_malloc((int)len + 1);
if (s == NULL) { if (s == NULL) {
i = ERR_R_MALLOC_FAILURE; i = ERR_R_MALLOC_FAILURE;
goto err; goto err;
@ -326,7 +453,6 @@ ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a, const unsigned char **pp,
p += len; p += len;
} }
if (ret->data != NULL)
OPENSSL_free(ret->data); OPENSSL_free(ret->data);
ret->data = s; ret->data = s;
ret->length = (int)len; ret->length = (int)len;
@ -336,129 +462,163 @@ ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a, const unsigned char **pp,
return (ret); return (ret);
err: err:
ASN1err(ASN1_F_D2I_ASN1_UINTEGER, i); ASN1err(ASN1_F_D2I_ASN1_UINTEGER, i);
if ((ret != NULL) && ((a == NULL) || (*a != ret))) if ((a == NULL) || (*a != ret))
M_ASN1_INTEGER_free(ret); ASN1_INTEGER_free(ret);
return (NULL); return (NULL);
} }
static ASN1_STRING *bn_to_asn1_string(const BIGNUM *bn, ASN1_STRING *ai,
int atype)
{
ASN1_INTEGER *ret;
int len;
if (ai == NULL) {
ret = ASN1_STRING_type_new(atype);
} else {
ret = ai;
ret->type = atype;
}
if (ret == NULL) {
ASN1err(ASN1_F_BN_TO_ASN1_STRING, ERR_R_NESTED_ASN1_ERROR);
goto err;
}
if (BN_is_negative(bn) && !BN_is_zero(bn))
ret->type |= V_ASN1_NEG_INTEGER;
len = BN_num_bytes(bn);
if (len == 0)
len = 1;
if (ASN1_STRING_set(ret, NULL, len) == 0) {
ASN1err(ASN1_F_BN_TO_ASN1_STRING, ERR_R_MALLOC_FAILURE);
goto err;
}
/* Correct zero case */
if (BN_is_zero(bn))
ret->data[0] = 0;
else
len = BN_bn2bin(bn, ret->data);
ret->length = len;
return ret;
err:
if (ret != ai)
ASN1_INTEGER_free(ret);
return (NULL);
}
static BIGNUM *asn1_string_to_bn(const ASN1_INTEGER *ai, BIGNUM *bn,
int itype)
{
BIGNUM *ret;
if ((ai->type & ~V_ASN1_NEG) != itype) {
ASN1err(ASN1_F_ASN1_STRING_TO_BN, ASN1_R_WRONG_INTEGER_TYPE);
return NULL;
}
ret = BN_bin2bn(ai->data, ai->length, bn);
if (ret == 0) {
ASN1err(ASN1_F_ASN1_STRING_TO_BN, ASN1_R_BN_LIB);
return NULL;
}
if (ai->type & V_ASN1_NEG)
BN_set_negative(ret, 1);
return ret;
}
int ASN1_INTEGER_get_int64(int64_t *pr, const ASN1_INTEGER *a)
{
return asn1_string_get_int64(pr, a, V_ASN1_INTEGER);
}
int ASN1_INTEGER_set_int64(ASN1_INTEGER *a, int64_t r)
{
return asn1_string_set_int64(a, r, V_ASN1_INTEGER);
}
int ASN1_INTEGER_get_uint64(uint64_t *pr, const ASN1_INTEGER *a)
{
return asn1_string_get_uint64(pr, a, V_ASN1_INTEGER);
}
int ASN1_INTEGER_set_uint64(ASN1_INTEGER *a, uint64_t r)
{
return asn1_string_set_uint64(a, r, V_ASN1_INTEGER);
}
int ASN1_INTEGER_set(ASN1_INTEGER *a, long v) int ASN1_INTEGER_set(ASN1_INTEGER *a, long v)
{ {
int j, k; return ASN1_INTEGER_set_int64(a, v);
unsigned int i;
unsigned char buf[sizeof(long) + 1];
long d;
a->type = V_ASN1_INTEGER;
if (a->length < (int)(sizeof(long) + 1)) {
if (a->data != NULL)
OPENSSL_free(a->data);
if ((a->data =
(unsigned char *)OPENSSL_malloc(sizeof(long) + 1)) != NULL)
memset((char *)a->data, 0, sizeof(long) + 1);
}
if (a->data == NULL) {
ASN1err(ASN1_F_ASN1_INTEGER_SET, ERR_R_MALLOC_FAILURE);
return (0);
}
d = v;
if (d < 0) {
d = -d;
a->type = V_ASN1_NEG_INTEGER;
}
for (i = 0; i < sizeof(long); i++) {
if (d == 0)
break;
buf[i] = (int)d & 0xff;
d >>= 8;
}
j = 0;
for (k = i - 1; k >= 0; k--)
a->data[j++] = buf[k];
a->length = j;
return (1);
} }
long ASN1_INTEGER_get(const ASN1_INTEGER *a) long ASN1_INTEGER_get(const ASN1_INTEGER *a)
{ {
int neg = 0, i; int i;
long r = 0; int64_t r;
if (a == NULL) if (a == NULL)
return (0L);
i = a->type;
if (i == V_ASN1_NEG_INTEGER)
neg = 1;
else if (i != V_ASN1_INTEGER)
return -1;
if (a->length > (int)sizeof(long)) {
/* hmm... a bit ugly, return all ones */
return -1;
}
if (a->data == NULL)
return 0; return 0;
i = ASN1_INTEGER_get_int64(&r, a);
for (i = 0; i < a->length; i++) { if (i == 0)
r <<= 8; return -1;
r |= (unsigned char)a->data[i]; if (r > LONG_MAX || r < LONG_MIN)
} return -1;
if (neg) return (long)r;
r = -r;
return (r);
} }
ASN1_INTEGER *BN_to_ASN1_INTEGER(const BIGNUM *bn, ASN1_INTEGER *ai) ASN1_INTEGER *BN_to_ASN1_INTEGER(const BIGNUM *bn, ASN1_INTEGER *ai)
{ {
ASN1_INTEGER *ret; return bn_to_asn1_string(bn, ai, V_ASN1_INTEGER);
int len, j;
if (ai == NULL)
ret = M_ASN1_INTEGER_new();
else
ret = ai;
if (ret == NULL) {
ASN1err(ASN1_F_BN_TO_ASN1_INTEGER, ERR_R_NESTED_ASN1_ERROR);
goto err;
}
if (BN_is_negative(bn) && !BN_is_zero(bn))
ret->type = V_ASN1_NEG_INTEGER;
else
ret->type = V_ASN1_INTEGER;
j = BN_num_bits(bn);
len = ((j == 0) ? 0 : ((j / 8) + 1));
if (ret->length < len + 4) {
unsigned char *new_data = OPENSSL_realloc(ret->data, len + 4);
if (!new_data) {
ASN1err(ASN1_F_BN_TO_ASN1_INTEGER, ERR_R_MALLOC_FAILURE);
goto err;
}
ret->data = new_data;
}
ret->length = BN_bn2bin(bn, ret->data);
/* Correct zero case */
if (!ret->length) {
ret->data[0] = 0;
ret->length = 1;
}
return (ret);
err:
if (ret != ai)
M_ASN1_INTEGER_free(ret);
return (NULL);
} }
BIGNUM *ASN1_INTEGER_to_BN(const ASN1_INTEGER *ai, BIGNUM *bn) BIGNUM *ASN1_INTEGER_to_BN(const ASN1_INTEGER *ai, BIGNUM *bn)
{ {
BIGNUM *ret; return asn1_string_to_bn(ai, bn, V_ASN1_INTEGER);
if ((ret = BN_bin2bn(ai->data, ai->length, bn)) == NULL)
ASN1err(ASN1_F_ASN1_INTEGER_TO_BN, ASN1_R_BN_LIB);
else if (ai->type == V_ASN1_NEG_INTEGER)
BN_set_negative(ret, 1);
return (ret);
} }
IMPLEMENT_STACK_OF(ASN1_INTEGER) int ASN1_ENUMERATED_get_int64(int64_t *pr, const ASN1_ENUMERATED *a)
{
return asn1_string_get_int64(pr, a, V_ASN1_ENUMERATED);
}
IMPLEMENT_ASN1_SET_OF(ASN1_INTEGER) int ASN1_ENUMERATED_set_int64(ASN1_ENUMERATED *a, int64_t r)
{
return asn1_string_set_int64(a, r, V_ASN1_ENUMERATED);
}
int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v)
{
return ASN1_ENUMERATED_set_int64(a, v);
}
long ASN1_ENUMERATED_get(const ASN1_ENUMERATED *a)
{
int i;
int64_t r;
if (a == NULL)
return 0;
if ((a->type & ~V_ASN1_NEG) != V_ASN1_ENUMERATED)
return -1;
if (a->length > (int)sizeof(long))
return 0xffffffffL;
i = ASN1_ENUMERATED_get_int64(&r, a);
if (i == 0)
return -1;
if (r > LONG_MAX || r < LONG_MIN)
return -1;
return (long)r;
}
ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(const BIGNUM *bn, ASN1_ENUMERATED *ai)
{
return bn_to_asn1_string(bn, ai, V_ASN1_ENUMERATED);
}
BIGNUM *ASN1_ENUMERATED_to_BN(const ASN1_ENUMERATED *ai, BIGNUM *bn)
{
return asn1_string_to_bn(ai, bn, V_ASN1_ENUMERATED);
}

View File

@ -1,65 +1,15 @@
/* a_mbstr.c */
/* /*
* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved.
* 1999.
*/
/* ====================================================================
* Copyright (c) 1999 The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
*
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* licensing@OpenSSL.org.
*
* 5. Products derived from this software may not be called "OpenSSL"
* nor may "OpenSSL" appear in their names without prior written
* permission of the OpenSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*
* This product includes cryptographic software written by Eric Young
* (eay@cryptsoft.com). This product includes software written by Tim
* Hudson (tjh@cryptsoft.com).
* *
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/ */
#include <stdio.h> #include <stdio.h>
#include <ctype.h> #include <ctype.h>
#include "cryptlib.h" #include "internal/cryptlib.h"
#include <openssl/asn1.h> #include <openssl/asn1.h>
static int traverse_string(const unsigned char *p, int len, int inform, static int traverse_string(const unsigned char *p, int len, int inform,
@ -72,13 +22,14 @@ static int cpy_asc(unsigned long value, void *arg);
static int cpy_bmp(unsigned long value, void *arg); static int cpy_bmp(unsigned long value, void *arg);
static int cpy_univ(unsigned long value, void *arg); static int cpy_univ(unsigned long value, void *arg);
static int cpy_utf8(unsigned long value, void *arg); static int cpy_utf8(unsigned long value, void *arg);
static int is_numeric(unsigned long value);
static int is_printable(unsigned long value); static int is_printable(unsigned long value);
/* /*
* These functions take a string in UTF8, ASCII or multibyte form and a mask * These functions take a string in UTF8, ASCII or multibyte form and a mask
* of permissible ASN1 string types. It then works out the minimal type * of permissible ASN1 string types. It then works out the minimal type
* (using the order Printable < IA5 < T61 < BMP < Universal < UTF8) and * (using the order Numeric < Printable < IA5 < T61 < BMP < Universal < UTF8)
* creates a string of the correct type with the supplied data. Yes this is * and creates a string of the correct type with the supplied data. Yes this is
* horrible: it has to be :-( The 'ncopy' form checks minimum and maximum * horrible: it has to be :-( The 'ncopy' form checks minimum and maximum
* size limits too. * size limits too.
*/ */
@ -169,7 +120,9 @@ int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
/* Now work out output format and string type */ /* Now work out output format and string type */
outform = MBSTRING_ASC; outform = MBSTRING_ASC;
if (mask & B_ASN1_PRINTABLESTRING) if (mask & B_ASN1_NUMERICSTRING)
str_type = V_ASN1_NUMERICSTRING;
else if (mask & B_ASN1_PRINTABLESTRING)
str_type = V_ASN1_PRINTABLESTRING; str_type = V_ASN1_PRINTABLESTRING;
else if (mask & B_ASN1_IA5STRING) else if (mask & B_ASN1_IA5STRING)
str_type = V_ASN1_IA5STRING; str_type = V_ASN1_IA5STRING;
@ -190,16 +143,14 @@ int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
if (*out) { if (*out) {
free_out = 0; free_out = 0;
dest = *out; dest = *out;
if (dest->data) {
dest->length = 0;
OPENSSL_free(dest->data); OPENSSL_free(dest->data);
dest->data = NULL; dest->data = NULL;
} dest->length = 0;
dest->type = str_type; dest->type = str_type;
} else { } else {
free_out = 1; free_out = 1;
dest = ASN1_STRING_type_new(str_type); dest = ASN1_STRING_type_new(str_type);
if (!dest) { if (dest == NULL) {
ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, ERR_R_MALLOC_FAILURE); ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, ERR_R_MALLOC_FAILURE);
return -1; return -1;
} }
@ -237,7 +188,7 @@ int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
cpyfunc = cpy_utf8; cpyfunc = cpy_utf8;
break; break;
} }
if (!(p = OPENSSL_malloc(outlen + 1))) { if ((p = OPENSSL_malloc(outlen + 1)) == NULL) {
if (free_out) if (free_out)
ASN1_STRING_free(dest); ASN1_STRING_free(dest);
ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, ERR_R_MALLOC_FAILURE); ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, ERR_R_MALLOC_FAILURE);
@ -322,6 +273,8 @@ static int type_str(unsigned long value, void *arg)
{ {
unsigned long types; unsigned long types;
types = *((unsigned long *)arg); types = *((unsigned long *)arg);
if ((types & B_ASN1_NUMERICSTRING) && !is_numeric(value))
types &= ~B_ASN1_NUMERICSTRING;
if ((types & B_ASN1_PRINTABLESTRING) && !is_printable(value)) if ((types & B_ASN1_PRINTABLESTRING) && !is_printable(value))
types &= ~B_ASN1_PRINTABLESTRING; types &= ~B_ASN1_PRINTABLESTRING;
if ((types & B_ASN1_IA5STRING) && (value > 127)) if ((types & B_ASN1_IA5STRING) && (value > 127))
@ -421,3 +374,22 @@ static int is_printable(unsigned long value)
#endif /* CHARSET_EBCDIC */ #endif /* CHARSET_EBCDIC */
return 0; return 0;
} }
/* Return 1 if the character is a digit or space */
static int is_numeric(unsigned long value)
{
int ch;
if (value > 0x7f)
return 0;
ch = (int)value;
#ifndef CHARSET_EBCDIC
if (!isdigit(ch) && ch != ' ')
return 0;
#else
if (ch > os_toascii['9'])
return 0;
if (ch < os_toascii['0'] && ch != os_toascii[' '])
return 0;
#endif
return 1;
}

View File

@ -1,70 +1,23 @@
/* crypto/asn1/a_object.c */ /*
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
* All rights reserved.
* *
* This package is an SSL implementation written * Licensed under the OpenSSL license (the "License"). You may not use
* by Eric Young (eay@cryptsoft.com). * this file except in compliance with the License. You can obtain a copy
* The implementation was written so as to conform with Netscapes SSL. * in the file LICENSE in the source distribution or at
* * https://www.openssl.org/source/license.html
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* "This product includes cryptographic software written by
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/ */
#include <stdio.h> #include <stdio.h>
#include <limits.h> #include <limits.h>
#include "cryptlib.h" #include "internal/cryptlib.h"
#include <openssl/buffer.h> #include <openssl/buffer.h>
#include <openssl/asn1.h> #include <openssl/asn1.h>
#include <openssl/objects.h> #include <openssl/objects.h>
#include <openssl/bn.h> #include <openssl/bn.h>
#include "internal/asn1_int.h"
#include "asn1_locl.h"
int i2d_ASN1_OBJECT(ASN1_OBJECT *a, unsigned char **pp) int i2d_ASN1_OBJECT(const ASN1_OBJECT *a, unsigned char **pp)
{ {
unsigned char *p; unsigned char *p;
int objsize; int objsize;
@ -137,9 +90,9 @@ int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num)
} }
if (!use_bn && l >= ((ULONG_MAX - 80) / 10L)) { if (!use_bn && l >= ((ULONG_MAX - 80) / 10L)) {
use_bn = 1; use_bn = 1;
if (!bl) if (bl == NULL)
bl = BN_new(); bl = BN_new();
if (!bl || !BN_set_word(bl, l)) if (bl == NULL || !BN_set_word(bl, l))
goto err; goto err;
} }
if (use_bn) { if (use_bn) {
@ -171,7 +124,7 @@ int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num)
OPENSSL_free(tmp); OPENSSL_free(tmp);
tmpsize = blsize + 32; tmpsize = blsize + 32;
tmp = OPENSSL_malloc(tmpsize); tmp = OPENSSL_malloc(tmpsize);
if (!tmp) if (tmp == NULL)
goto err; goto err;
} }
while (blsize--) { while (blsize--) {
@ -203,23 +156,21 @@ int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num)
} }
if (tmp != ftmp) if (tmp != ftmp)
OPENSSL_free(tmp); OPENSSL_free(tmp);
if (bl)
BN_free(bl); BN_free(bl);
return (len); return (len);
err: err:
if (tmp != ftmp) if (tmp != ftmp)
OPENSSL_free(tmp); OPENSSL_free(tmp);
if (bl)
BN_free(bl); BN_free(bl);
return (0); return (0);
} }
int i2t_ASN1_OBJECT(char *buf, int buf_len, ASN1_OBJECT *a) int i2t_ASN1_OBJECT(char *buf, int buf_len, const ASN1_OBJECT *a)
{ {
return OBJ_obj2txt(buf, buf_len, a, 0); return OBJ_obj2txt(buf, buf_len, a, 0);
} }
int i2a_ASN1_OBJECT(BIO *bp, ASN1_OBJECT *a) int i2a_ASN1_OBJECT(BIO *bp, const ASN1_OBJECT *a)
{ {
char buf[80], *p = buf; char buf[80], *p = buf;
int i; int i;
@ -229,12 +180,15 @@ int i2a_ASN1_OBJECT(BIO *bp, ASN1_OBJECT *a)
i = i2t_ASN1_OBJECT(buf, sizeof buf, a); i = i2t_ASN1_OBJECT(buf, sizeof buf, a);
if (i > (int)(sizeof(buf) - 1)) { if (i > (int)(sizeof(buf) - 1)) {
p = OPENSSL_malloc(i + 1); p = OPENSSL_malloc(i + 1);
if (!p) if (p == NULL)
return -1; return -1;
i2t_ASN1_OBJECT(p, i + 1, a); i2t_ASN1_OBJECT(p, i + 1, a);
} }
if (i <= 0) if (i <= 0) {
return BIO_write(bp, "<INVALID>", 9); i = BIO_write(bp, "<INVALID>", 9);
i += BIO_dump(bp, (const char *)a->data, a->length);
return i;
}
BIO_write(bp, p, i); BIO_write(bp, p, i);
if (p != buf) if (p != buf)
OPENSSL_free(p); OPENSSL_free(p);
@ -272,7 +226,7 @@ ASN1_OBJECT *d2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp,
ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp,
long len) long len)
{ {
ASN1_OBJECT *ret = NULL; ASN1_OBJECT *ret = NULL, tobj;
const unsigned char *p; const unsigned char *p;
unsigned char *data; unsigned char *data;
int i, length; int i, length;
@ -289,6 +243,29 @@ ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp,
} }
/* Now 0 < len <= INT_MAX, so the cast is safe. */ /* Now 0 < len <= INT_MAX, so the cast is safe. */
length = (int)len; length = (int)len;
/*
* Try to lookup OID in table: these are all valid encodings so if we get
* a match we know the OID is valid.
*/
tobj.nid = NID_undef;
tobj.data = p;
tobj.length = length;
tobj.flags = 0;
i = OBJ_obj2nid(&tobj);
if (i != NID_undef) {
/*
* Return shared registered OID object: this improves efficiency
* because we don't have to return a dynamically allocated OID
* and NID lookups can use the cached value.
*/
ret = OBJ_nid2obj(i);
if (a) {
ASN1_OBJECT_free(*a);
*a = ret;
}
*pp += len;
return ret;
}
for (i = 0; i < length; i++, p++) { for (i = 0; i < length; i++, p++) {
if (*p == 0x80 && (!i || !(p[-1] & 0x80))) { if (*p == 0x80 && (!i || !(p[-1] & 0x80))) {
ASN1err(ASN1_F_C2I_ASN1_OBJECT, ASN1_R_INVALID_OBJECT_ENCODING); ASN1err(ASN1_F_C2I_ASN1_OBJECT, ASN1_R_INVALID_OBJECT_ENCODING);
@ -314,9 +291,8 @@ ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp,
/* once detached we can change it */ /* once detached we can change it */
if ((data == NULL) || (ret->length < length)) { if ((data == NULL) || (ret->length < length)) {
ret->length = 0; ret->length = 0;
if (data != NULL)
OPENSSL_free(data); OPENSSL_free(data);
data = (unsigned char *)OPENSSL_malloc(length); data = OPENSSL_malloc(length);
if (data == NULL) { if (data == NULL) {
i = ERR_R_MALLOC_FAILURE; i = ERR_R_MALLOC_FAILURE;
goto err; goto err;
@ -338,7 +314,7 @@ ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp,
return (ret); return (ret);
err: err:
ASN1err(ASN1_F_C2I_ASN1_OBJECT, i); ASN1err(ASN1_F_C2I_ASN1_OBJECT, i);
if ((ret != NULL) && ((a == NULL) || (*a != ret))) if ((a == NULL) || (*a != ret))
ASN1_OBJECT_free(ret); ASN1_OBJECT_free(ret);
return (NULL); return (NULL);
} }
@ -347,16 +323,11 @@ ASN1_OBJECT *ASN1_OBJECT_new(void)
{ {
ASN1_OBJECT *ret; ASN1_OBJECT *ret;
ret = (ASN1_OBJECT *)OPENSSL_malloc(sizeof(ASN1_OBJECT)); ret = OPENSSL_zalloc(sizeof(*ret));
if (ret == NULL) { if (ret == NULL) {
ASN1err(ASN1_F_ASN1_OBJECT_NEW, ERR_R_MALLOC_FAILURE); ASN1err(ASN1_F_ASN1_OBJECT_NEW, ERR_R_MALLOC_FAILURE);
return (NULL); return (NULL);
} }
ret->length = 0;
ret->data = NULL;
ret->nid = 0;
ret->sn = NULL;
ret->ln = NULL;
ret->flags = ASN1_OBJECT_FLAG_DYNAMIC; ret->flags = ASN1_OBJECT_FLAG_DYNAMIC;
return (ret); return (ret);
} }
@ -369,16 +340,13 @@ void ASN1_OBJECT_free(ASN1_OBJECT *a)
#ifndef CONST_STRICT /* disable purely for compile-time strict #ifndef CONST_STRICT /* disable purely for compile-time strict
* const checking. Doing this on a "real" * const checking. Doing this on a "real"
* compile will cause memory leaks */ * compile will cause memory leaks */
if (a->sn != NULL) OPENSSL_free((void*)a->sn);
OPENSSL_free((void *)a->sn); OPENSSL_free((void*)a->ln);
if (a->ln != NULL)
OPENSSL_free((void *)a->ln);
#endif #endif
a->sn = a->ln = NULL; a->sn = a->ln = NULL;
} }
if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_DATA) { if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_DATA) {
if (a->data != NULL) OPENSSL_free((void*)a->data);
OPENSSL_free((void *)a->data);
a->data = NULL; a->data = NULL;
a->length = 0; a->length = 0;
} }
@ -400,7 +368,3 @@ ASN1_OBJECT *ASN1_OBJECT_create(int nid, unsigned char *data, int len,
ASN1_OBJECT_FLAG_DYNAMIC_DATA; ASN1_OBJECT_FLAG_DYNAMIC_DATA;
return (OBJ_dup(&o)); return (OBJ_dup(&o));
} }
IMPLEMENT_STACK_OF(ASN1_OBJECT)
IMPLEMENT_ASN1_SET_OF(ASN1_OBJECT)

View File

@ -1,78 +1,29 @@
/* crypto/asn1/a_octet.c */ /*
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
* All rights reserved.
* *
* This package is an SSL implementation written * Licensed under the OpenSSL license (the "License"). You may not use
* by Eric Young (eay@cryptsoft.com). * this file except in compliance with the License. You can obtain a copy
* The implementation was written so as to conform with Netscapes SSL. * in the file LICENSE in the source distribution or at
* * https://www.openssl.org/source/license.html
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* "This product includes cryptographic software written by
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/ */
#include <stdio.h> #include <stdio.h>
#include "cryptlib.h" #include "internal/cryptlib.h"
#include <openssl/asn1.h> #include <openssl/asn1.h>
ASN1_OCTET_STRING *ASN1_OCTET_STRING_dup(const ASN1_OCTET_STRING *x) ASN1_OCTET_STRING *ASN1_OCTET_STRING_dup(const ASN1_OCTET_STRING *x)
{ {
return M_ASN1_OCTET_STRING_dup(x); return ASN1_STRING_dup(x);
} }
int ASN1_OCTET_STRING_cmp(const ASN1_OCTET_STRING *a, int ASN1_OCTET_STRING_cmp(const ASN1_OCTET_STRING *a,
const ASN1_OCTET_STRING *b) const ASN1_OCTET_STRING *b)
{ {
return M_ASN1_OCTET_STRING_cmp(a, b); return ASN1_STRING_cmp(a, b);
} }
int ASN1_OCTET_STRING_set(ASN1_OCTET_STRING *x, const unsigned char *d, int ASN1_OCTET_STRING_set(ASN1_OCTET_STRING *x, const unsigned char *d,
int len) int len)
{ {
return M_ASN1_OCTET_STRING_set(x, d, len); return ASN1_STRING_set(x, d, len);
} }

View File

@ -1,63 +1,15 @@
/* crypto/asn1/a_print.c */ /*
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
* All rights reserved.
* *
* This package is an SSL implementation written * Licensed under the OpenSSL license (the "License"). You may not use
* by Eric Young (eay@cryptsoft.com). * this file except in compliance with the License. You can obtain a copy
* The implementation was written so as to conform with Netscapes SSL. * in the file LICENSE in the source distribution or at
* * https://www.openssl.org/source/license.html
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* "This product includes cryptographic software written by
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/ */
#include <stdio.h> #include <stdio.h>
#include "cryptlib.h" #include <ctype.h>
#include "internal/cryptlib.h"
#include <openssl/asn1.h> #include <openssl/asn1.h>
int ASN1_PRINTABLE_type(const unsigned char *s, int len) int ASN1_PRINTABLE_type(const unsigned char *s, int len)
@ -76,7 +28,6 @@ int ASN1_PRINTABLE_type(const unsigned char *s, int len)
#ifndef CHARSET_EBCDIC #ifndef CHARSET_EBCDIC
if (!(((c >= 'a') && (c <= 'z')) || if (!(((c >= 'a') && (c <= 'z')) ||
((c >= 'A') && (c <= 'Z')) || ((c >= 'A') && (c <= 'Z')) ||
(c == ' ') ||
((c >= '0') && (c <= '9')) || ((c >= '0') && (c <= '9')) ||
(c == ' ') || (c == '\'') || (c == ' ') || (c == '\'') ||
(c == '(') || (c == ')') || (c == '(') || (c == ')') ||
@ -127,3 +78,32 @@ int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s)
s->type = ASN1_PRINTABLE_type(s->data, s->length); s->type = ASN1_PRINTABLE_type(s->data, s->length);
return (1); return (1);
} }
int ASN1_STRING_print(BIO *bp, const ASN1_STRING *v)
{
int i, n;
char buf[80];
const char *p;
if (v == NULL)
return (0);
n = 0;
p = (const char *)v->data;
for (i = 0; i < v->length; i++) {
if ((p[i] > '~') || ((p[i] < ' ') &&
(p[i] != '\n') && (p[i] != '\r')))
buf[n] = '.';
else
buf[n] = p[i];
n++;
if (n >= 80) {
if (BIO_write(bp, buf, n) <= 0)
return (0);
n = 0;
}
}
if (n > 0)
if (BIO_write(bp, buf, n) <= 0)
return (0);
return (1);
}

View File

@ -1,243 +0,0 @@
/* crypto/asn1/a_set.c */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
* This package is an SSL implementation written
* by Eric Young (eay@cryptsoft.com).
* The implementation was written so as to conform with Netscapes SSL.
*
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* "This product includes cryptographic software written by
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/
#include <stdio.h>
#include <limits.h>
#include "cryptlib.h"
#include <openssl/asn1_mac.h>
#ifndef NO_ASN1_OLD
typedef struct {
unsigned char *pbData;
int cbData;
} MYBLOB;
/*
* SetBlobCmp This function compares two elements of SET_OF block
*/
static int SetBlobCmp(const void *elem1, const void *elem2)
{
const MYBLOB *b1 = (const MYBLOB *)elem1;
const MYBLOB *b2 = (const MYBLOB *)elem2;
int r;
r = memcmp(b1->pbData, b2->pbData,
b1->cbData < b2->cbData ? b1->cbData : b2->cbData);
if (r != 0)
return r;
return b1->cbData - b2->cbData;
}
/*
* int is_set: if TRUE, then sort the contents (i.e. it isn't a SEQUENCE)
*/
int i2d_ASN1_SET(STACK_OF(OPENSSL_BLOCK) *a, unsigned char **pp,
i2d_of_void *i2d, int ex_tag, int ex_class, int is_set)
{
int ret = 0, r;
int i;
unsigned char *p;
unsigned char *pStart, *pTempMem;
MYBLOB *rgSetBlob;
int totSize;
if (a == NULL)
return (0);
for (i = sk_OPENSSL_BLOCK_num(a) - 1; i >= 0; i--) {
int tmplen = i2d(sk_OPENSSL_BLOCK_value(a, i), NULL);
if (tmplen > INT_MAX - ret)
return -1;
ret += i2d(sk_OPENSSL_BLOCK_value(a, i), NULL);
}
r = ASN1_object_size(1, ret, ex_tag);
if (pp == NULL || r == -1)
return (r);
p = *pp;
ASN1_put_object(&p, 1, ret, ex_tag, ex_class);
/* Modified by gp@nsj.co.jp */
/* And then again by Ben */
/* And again by Steve */
if (!is_set || (sk_OPENSSL_BLOCK_num(a) < 2)) {
for (i = 0; i < sk_OPENSSL_BLOCK_num(a); i++)
i2d(sk_OPENSSL_BLOCK_value(a, i), &p);
*pp = p;
return (r);
}
pStart = p; /* Catch the beg of Setblobs */
/* In this array we will store the SET blobs */
rgSetBlob = OPENSSL_malloc(sk_OPENSSL_BLOCK_num(a) * sizeof(MYBLOB));
if (rgSetBlob == NULL) {
ASN1err(ASN1_F_I2D_ASN1_SET, ERR_R_MALLOC_FAILURE);
return (0);
}
for (i = 0; i < sk_OPENSSL_BLOCK_num(a); i++) {
rgSetBlob[i].pbData = p; /* catch each set encode blob */
i2d(sk_OPENSSL_BLOCK_value(a, i), &p);
rgSetBlob[i].cbData = p - rgSetBlob[i].pbData; /* Length of this
* SetBlob */
}
*pp = p;
totSize = p - pStart; /* This is the total size of all set blobs */
/*
* Now we have to sort the blobs. I am using a simple algo. *Sort ptrs
* *Copy to temp-mem *Copy from temp-mem to user-mem
*/
qsort(rgSetBlob, sk_OPENSSL_BLOCK_num(a), sizeof(MYBLOB), SetBlobCmp);
if (!(pTempMem = OPENSSL_malloc(totSize))) {
ASN1err(ASN1_F_I2D_ASN1_SET, ERR_R_MALLOC_FAILURE);
return (0);
}
/* Copy to temp mem */
p = pTempMem;
for (i = 0; i < sk_OPENSSL_BLOCK_num(a); ++i) {
memcpy(p, rgSetBlob[i].pbData, rgSetBlob[i].cbData);
p += rgSetBlob[i].cbData;
}
/* Copy back to user mem*/
memcpy(pStart, pTempMem, totSize);
OPENSSL_free(pTempMem);
OPENSSL_free(rgSetBlob);
return (r);
}
STACK_OF(OPENSSL_BLOCK) *d2i_ASN1_SET(STACK_OF(OPENSSL_BLOCK) **a,
const unsigned char **pp,
long length, d2i_of_void *d2i,
void (*free_func) (OPENSSL_BLOCK),
int ex_tag, int ex_class)
{
ASN1_const_CTX c;
STACK_OF(OPENSSL_BLOCK) *ret = NULL;
if ((a == NULL) || ((*a) == NULL)) {
if ((ret = sk_OPENSSL_BLOCK_new_null()) == NULL) {
ASN1err(ASN1_F_D2I_ASN1_SET, ERR_R_MALLOC_FAILURE);
goto err;
}
} else
ret = (*a);
c.p = *pp;
c.max = (length == 0) ? 0 : (c.p + length);
c.inf = ASN1_get_object(&c.p, &c.slen, &c.tag, &c.xclass, c.max - c.p);
if (c.inf & 0x80)
goto err;
if (ex_class != c.xclass) {
ASN1err(ASN1_F_D2I_ASN1_SET, ASN1_R_BAD_CLASS);
goto err;
}
if (ex_tag != c.tag) {
ASN1err(ASN1_F_D2I_ASN1_SET, ASN1_R_BAD_TAG);
goto err;
}
if ((c.slen + c.p) > c.max) {
ASN1err(ASN1_F_D2I_ASN1_SET, ASN1_R_LENGTH_ERROR);
goto err;
}
/*
* check for infinite constructed - it can be as long as the amount of
* data passed to us
*/
if (c.inf == (V_ASN1_CONSTRUCTED + 1))
c.slen = length + *pp - c.p;
c.max = c.p + c.slen;
while (c.p < c.max) {
char *s;
if (M_ASN1_D2I_end_sequence())
break;
/*
* XXX: This was called with 4 arguments, incorrectly, it seems if
* ((s=func(NULL,&c.p,c.slen,c.max-c.p)) == NULL)
*/
if ((s = d2i(NULL, &c.p, c.slen)) == NULL) {
ASN1err(ASN1_F_D2I_ASN1_SET, ASN1_R_ERROR_PARSING_SET_ELEMENT);
asn1_add_error(*pp, (int)(c.p - *pp));
goto err;
}
if (!sk_OPENSSL_BLOCK_push(ret, s))
goto err;
}
if (a != NULL)
(*a) = ret;
*pp = c.p;
return (ret);
err:
if ((ret != NULL) && ((a == NULL) || (*a != ret))) {
if (free_func != NULL)
sk_OPENSSL_BLOCK_pop_free(ret, free_func);
else
sk_OPENSSL_BLOCK_free(ret);
}
return (NULL);
}
#endif

View File

@ -1,118 +1,16 @@
/* crypto/asn1/a_sign.c */ /*
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
* All rights reserved.
*
* This package is an SSL implementation written
* by Eric Young (eay@cryptsoft.com).
* The implementation was written so as to conform with Netscapes SSL.
*
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* "This product includes cryptographic software written by
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/
/* ====================================================================
* Copyright (c) 1998-2003 The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
*
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* openssl-core@openssl.org.
*
* 5. Products derived from this software may not be called "OpenSSL"
* nor may "OpenSSL" appear in their names without prior written
* permission of the OpenSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit (http://www.openssl.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*
* This product includes cryptographic software written by Eric Young
* (eay@cryptsoft.com). This product includes software written by Tim
* Hudson (tjh@cryptsoft.com).
* *
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/ */
#include <stdio.h> #include <stdio.h>
#include <time.h> #include <time.h>
#include "cryptlib.h" #include "internal/cryptlib.h"
#ifndef NO_SYS_TYPES_H #ifndef NO_SYS_TYPES_H
# include <sys/types.h> # include <sys/types.h>
@ -123,7 +21,8 @@
#include <openssl/x509.h> #include <openssl/x509.h>
#include <openssl/objects.h> #include <openssl/objects.h>
#include <openssl/buffer.h> #include <openssl/buffer.h>
#include "asn1_locl.h" #include "internal/asn1_int.h"
#include "internal/evp_int.h"
#ifndef NO_ASN1_OLD #ifndef NO_ASN1_OLD
@ -131,12 +30,15 @@ int ASN1_sign(i2d_of_void *i2d, X509_ALGOR *algor1, X509_ALGOR *algor2,
ASN1_BIT_STRING *signature, char *data, EVP_PKEY *pkey, ASN1_BIT_STRING *signature, char *data, EVP_PKEY *pkey,
const EVP_MD *type) const EVP_MD *type)
{ {
EVP_MD_CTX ctx; EVP_MD_CTX *ctx = EVP_MD_CTX_new();
unsigned char *p, *buf_in = NULL, *buf_out = NULL; unsigned char *p, *buf_in = NULL, *buf_out = NULL;
int i, inl = 0, outl = 0, outll = 0; int i, inl = 0, outl = 0, outll = 0;
X509_ALGOR *a; X509_ALGOR *a;
EVP_MD_CTX_init(&ctx); if (ctx == NULL) {
ASN1err(ASN1_F_ASN1_SIGN, ERR_R_MALLOC_FAILURE);
goto err;
}
for (i = 0; i < 2; i++) { for (i = 0; i < 2; i++) {
if (i == 0) if (i == 0)
a = algor1; a = algor1;
@ -171,9 +73,9 @@ int ASN1_sign(i2d_of_void *i2d, X509_ALGOR *algor1, X509_ALGOR *algor2,
} }
} }
inl = i2d(data, NULL); inl = i2d(data, NULL);
buf_in = (unsigned char *)OPENSSL_malloc((unsigned int)inl); buf_in = OPENSSL_malloc((unsigned int)inl);
outll = outl = EVP_PKEY_size(pkey); outll = outl = EVP_PKEY_size(pkey);
buf_out = (unsigned char *)OPENSSL_malloc((unsigned int)outl); buf_out = OPENSSL_malloc((unsigned int)outl);
if ((buf_in == NULL) || (buf_out == NULL)) { if ((buf_in == NULL) || (buf_out == NULL)) {
outl = 0; outl = 0;
ASN1err(ASN1_F_ASN1_SIGN, ERR_R_MALLOC_FAILURE); ASN1err(ASN1_F_ASN1_SIGN, ERR_R_MALLOC_FAILURE);
@ -182,15 +84,14 @@ int ASN1_sign(i2d_of_void *i2d, X509_ALGOR *algor1, X509_ALGOR *algor2,
p = buf_in; p = buf_in;
i2d(data, &p); i2d(data, &p);
if (!EVP_SignInit_ex(&ctx, type, NULL) if (!EVP_SignInit_ex(ctx, type, NULL)
|| !EVP_SignUpdate(&ctx, (unsigned char *)buf_in, inl) || !EVP_SignUpdate(ctx, (unsigned char *)buf_in, inl)
|| !EVP_SignFinal(&ctx, (unsigned char *)buf_out, || !EVP_SignFinal(ctx, (unsigned char *)buf_out,
(unsigned int *)&outl, pkey)) { (unsigned int *)&outl, pkey)) {
outl = 0; outl = 0;
ASN1err(ASN1_F_ASN1_SIGN, ERR_R_EVP_LIB); ASN1err(ASN1_F_ASN1_SIGN, ERR_R_EVP_LIB);
goto err; goto err;
} }
if (signature->data != NULL)
OPENSSL_free(signature->data); OPENSSL_free(signature->data);
signature->data = buf_out; signature->data = buf_out;
buf_out = NULL; buf_out = NULL;
@ -202,15 +103,9 @@ int ASN1_sign(i2d_of_void *i2d, X509_ALGOR *algor1, X509_ALGOR *algor2,
signature->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07); signature->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07);
signature->flags |= ASN1_STRING_FLAG_BITS_LEFT; signature->flags |= ASN1_STRING_FLAG_BITS_LEFT;
err: err:
EVP_MD_CTX_cleanup(&ctx); EVP_MD_CTX_free(ctx);
if (buf_in != NULL) { OPENSSL_clear_free((char *)buf_in, (unsigned int)inl);
OPENSSL_cleanse((char *)buf_in, (unsigned int)inl); OPENSSL_clear_free((char *)buf_out, outll);
OPENSSL_free(buf_in);
}
if (buf_out != NULL) {
OPENSSL_cleanse((char *)buf_out, outll);
OPENSSL_free(buf_out);
}
return (outl); return (outl);
} }
@ -220,13 +115,22 @@ int ASN1_item_sign(const ASN1_ITEM *it, X509_ALGOR *algor1,
X509_ALGOR *algor2, ASN1_BIT_STRING *signature, void *asn, X509_ALGOR *algor2, ASN1_BIT_STRING *signature, void *asn,
EVP_PKEY *pkey, const EVP_MD *type) EVP_PKEY *pkey, const EVP_MD *type)
{ {
EVP_MD_CTX ctx; int rv;
EVP_MD_CTX_init(&ctx); EVP_MD_CTX *ctx = EVP_MD_CTX_new();
if (!EVP_DigestSignInit(&ctx, NULL, type, NULL, pkey)) {
EVP_MD_CTX_cleanup(&ctx); if (ctx == NULL) {
ASN1err(ASN1_F_ASN1_ITEM_SIGN, ERR_R_MALLOC_FAILURE);
return 0; return 0;
} }
return ASN1_item_sign_ctx(it, algor1, algor2, signature, asn, &ctx); if (!EVP_DigestSignInit(ctx, NULL, type, NULL, pkey)) {
EVP_MD_CTX_free(ctx);
return 0;
}
rv = ASN1_item_sign_ctx(it, algor1, algor2, signature, asn, ctx);
EVP_MD_CTX_free(ctx);
return rv;
} }
int ASN1_item_sign_ctx(const ASN1_ITEM *it, int ASN1_item_sign_ctx(const ASN1_ITEM *it,
@ -241,11 +145,16 @@ int ASN1_item_sign_ctx(const ASN1_ITEM *it,
int rv; int rv;
type = EVP_MD_CTX_md(ctx); type = EVP_MD_CTX_md(ctx);
pkey = EVP_PKEY_CTX_get0_pkey(ctx->pctx); pkey = EVP_PKEY_CTX_get0_pkey(EVP_MD_CTX_pkey_ctx(ctx));
if (!type || !pkey) { if (type == NULL || pkey == NULL) {
ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX, ASN1_R_CONTEXT_NOT_INITIALISED); ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX, ASN1_R_CONTEXT_NOT_INITIALISED);
return 0; goto err;
}
if (pkey->ameth == NULL) {
ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX, ASN1_R_DIGEST_AND_KEY_TYPE_NOT_SUPPORTED);
goto err;
} }
if (pkey->ameth->item_sign) { if (pkey->ameth->item_sign) {
@ -267,17 +176,13 @@ int ASN1_item_sign_ctx(const ASN1_ITEM *it,
rv = 2; rv = 2;
if (rv == 2) { if (rv == 2) {
if (type->flags & EVP_MD_FLAG_PKEY_METHOD_SIGNATURE) { if (!OBJ_find_sigid_by_algs(&signid,
if (!pkey->ameth ||
!OBJ_find_sigid_by_algs(&signid,
EVP_MD_nid(type), EVP_MD_nid(type),
pkey->ameth->pkey_id)) { pkey->ameth->pkey_id)) {
ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX, ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX,
ASN1_R_DIGEST_AND_KEY_TYPE_NOT_SUPPORTED); ASN1_R_DIGEST_AND_KEY_TYPE_NOT_SUPPORTED);
return 0; goto err;
} }
} else
signid = type->pkey_type;
if (pkey->ameth->pkey_flags & ASN1_PKEY_SIGPARAM_NULL) if (pkey->ameth->pkey_flags & ASN1_PKEY_SIGPARAM_NULL)
paramtype = V_ASN1_NULL; paramtype = V_ASN1_NULL;
@ -306,7 +211,6 @@ int ASN1_item_sign_ctx(const ASN1_ITEM *it,
ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX, ERR_R_EVP_LIB); ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX, ERR_R_EVP_LIB);
goto err; goto err;
} }
if (signature->data != NULL)
OPENSSL_free(signature->data); OPENSSL_free(signature->data);
signature->data = buf_out; signature->data = buf_out;
buf_out = NULL; buf_out = NULL;
@ -318,14 +222,7 @@ int ASN1_item_sign_ctx(const ASN1_ITEM *it,
signature->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07); signature->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07);
signature->flags |= ASN1_STRING_FLAG_BITS_LEFT; signature->flags |= ASN1_STRING_FLAG_BITS_LEFT;
err: err:
EVP_MD_CTX_cleanup(ctx); OPENSSL_clear_free((char *)buf_in, (unsigned int)inl);
if (buf_in != NULL) { OPENSSL_clear_free((char *)buf_out, outll);
OPENSSL_cleanse((char *)buf_in, (unsigned int)inl);
OPENSSL_free(buf_in);
}
if (buf_out != NULL) {
OPENSSL_cleanse((char *)buf_out, outll);
OPENSSL_free(buf_out);
}
return (outl); return (outl);
} }

View File

@ -1,65 +1,16 @@
/* a_strex.c */
/* /*
* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project * Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
* 2000.
*/
/* ====================================================================
* Copyright (c) 2000 The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
*
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* licensing@OpenSSL.org.
*
* 5. Products derived from this software may not be called "OpenSSL"
* nor may "OpenSSL" appear in their names without prior written
* permission of the OpenSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*
* This product includes cryptographic software written by Eric Young
* (eay@cryptsoft.com). This product includes software written by Tim
* Hudson (tjh@cryptsoft.com).
* *
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/ */
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "cryptlib.h" #include "internal/cryptlib.h"
#include "internal/asn1_int.h"
#include <openssl/crypto.h> #include <openssl/crypto.h>
#include <openssl/x509.h> #include <openssl/x509.h>
#include <openssl/asn1.h> #include <openssl/asn1.h>
@ -75,6 +26,7 @@
#define CHARTYPE_BS_ESC (ASN1_STRFLGS_ESC_2253 | CHARTYPE_FIRST_ESC_2253 | CHARTYPE_LAST_ESC_2253) #define CHARTYPE_BS_ESC (ASN1_STRFLGS_ESC_2253 | CHARTYPE_FIRST_ESC_2253 | CHARTYPE_LAST_ESC_2253)
#define ESC_FLAGS (ASN1_STRFLGS_ESC_2253 | \ #define ESC_FLAGS (ASN1_STRFLGS_ESC_2253 | \
ASN1_STRFLGS_ESC_2254 | \
ASN1_STRFLGS_ESC_QUOTE | \ ASN1_STRFLGS_ESC_QUOTE | \
ASN1_STRFLGS_ESC_CTRL | \ ASN1_STRFLGS_ESC_CTRL | \
ASN1_STRFLGS_ESC_MSB) ASN1_STRFLGS_ESC_MSB)
@ -83,18 +35,6 @@
* Three IO functions for sending data to memory, a BIO and and a FILE * Three IO functions for sending data to memory, a BIO and and a FILE
* pointer. * pointer.
*/ */
#if 0 /* never used */
static int send_mem_chars(void *arg, const void *buf, int len)
{
unsigned char **out = arg;
if (!out)
return 1;
memcpy(*out, buf, len);
*out += len;
return 1;
}
#endif
static int send_bio_chars(void *arg, const void *buf, int len) static int send_bio_chars(void *arg, const void *buf, int len)
{ {
if (!arg) if (!arg)
@ -104,7 +44,7 @@ static int send_bio_chars(void *arg, const void *buf, int len)
return 1; return 1;
} }
#ifndef OPENSSL_NO_FP_API #ifndef OPENSSL_NO_STDIO
static int send_fp_chars(void *arg, const void *buf, int len) static int send_fp_chars(void *arg, const void *buf, int len)
{ {
if (!arg) if (!arg)
@ -126,7 +66,8 @@ typedef int char_io (void *arg, const void *buf, int len);
static int do_esc_char(unsigned long c, unsigned char flags, char *do_quotes, static int do_esc_char(unsigned long c, unsigned char flags, char *do_quotes,
char_io *io_ch, void *arg) char_io *io_ch, void *arg)
{ {
unsigned char chflgs, chtmp; unsigned short chflgs;
unsigned char chtmp;
char tmphex[HEX_SIZE(long) + 3]; char tmphex[HEX_SIZE(long) + 3];
if (c > 0xffffffffL) if (c > 0xffffffffL)
@ -163,7 +104,9 @@ static int do_esc_char(unsigned long c, unsigned char flags, char *do_quotes,
return -1; return -1;
return 2; return 2;
} }
if (chflgs & (ASN1_STRFLGS_ESC_CTRL | ASN1_STRFLGS_ESC_MSB)) { if (chflgs & (ASN1_STRFLGS_ESC_CTRL
| ASN1_STRFLGS_ESC_MSB
| ASN1_STRFLGS_ESC_2254)) {
BIO_snprintf(tmphex, 11, "\\%02X", chtmp); BIO_snprintf(tmphex, 11, "\\%02X", chtmp);
if (!io_ch(arg, tmphex, 3)) if (!io_ch(arg, tmphex, 3))
return -1; return -1;
@ -193,11 +136,12 @@ static int do_esc_char(unsigned long c, unsigned char flags, char *do_quotes,
*/ */
static int do_buf(unsigned char *buf, int buflen, static int do_buf(unsigned char *buf, int buflen,
int type, unsigned char flags, char *quotes, char_io *io_ch, int type, unsigned short flags, char *quotes, char_io *io_ch,
void *arg) void *arg)
{ {
int i, outlen, len; int i, outlen, len;
unsigned char orflags, *p, *q; unsigned short orflags;
unsigned char *p, *q;
unsigned long c; unsigned long c;
p = buf; p = buf;
q = buf + buflen; q = buf + buflen;
@ -247,7 +191,7 @@ static int do_buf(unsigned char *buf, int buflen,
* character will never be escaped on first and last. * character will never be escaped on first and last.
*/ */
len = len =
do_esc_char(utfbuf[i], (unsigned char)(flags | orflags), do_esc_char(utfbuf[i], (unsigned short)(flags | orflags),
quotes, io_ch, arg); quotes, io_ch, arg);
if (len < 0) if (len < 0)
return -1; return -1;
@ -255,7 +199,7 @@ static int do_buf(unsigned char *buf, int buflen,
} }
} else { } else {
len = len =
do_esc_char(c, (unsigned char)(flags | orflags), quotes, do_esc_char(c, (unsigned short)(flags | orflags), quotes,
io_ch, arg); io_ch, arg);
if (len < 0) if (len < 0)
return -1; return -1;
@ -294,7 +238,7 @@ static int do_hex_dump(char_io *io_ch, void *arg, unsigned char *buf,
*/ */
static int do_dump(unsigned long lflags, char_io *io_ch, void *arg, static int do_dump(unsigned long lflags, char_io *io_ch, void *arg,
ASN1_STRING *str) const ASN1_STRING *str)
{ {
/* /*
* Placing the ASN1_STRING in a temp ASN1_TYPE allows the DER encoding to * Placing the ASN1_STRING in a temp ASN1_TYPE allows the DER encoding to
@ -317,7 +261,7 @@ static int do_dump(unsigned long lflags, char_io *io_ch, void *arg,
t.value.ptr = (char *)str; t.value.ptr = (char *)str;
der_len = i2d_ASN1_TYPE(&t, NULL); der_len = i2d_ASN1_TYPE(&t, NULL);
der_buf = OPENSSL_malloc(der_len); der_buf = OPENSSL_malloc(der_len);
if (!der_buf) if (der_buf == NULL)
return -1; return -1;
p = der_buf; p = der_buf;
i2d_ASN1_TYPE(&t, &p); i2d_ASN1_TYPE(&t, &p);
@ -352,15 +296,15 @@ static const signed char tag2nbyte[] = {
*/ */
static int do_print_ex(char_io *io_ch, void *arg, unsigned long lflags, static int do_print_ex(char_io *io_ch, void *arg, unsigned long lflags,
ASN1_STRING *str) const ASN1_STRING *str)
{ {
int outlen, len; int outlen, len;
int type; int type;
char quotes; char quotes;
unsigned char flags; unsigned short flags;
quotes = 0; quotes = 0;
/* Keep a copy of escape flags */ /* Keep a copy of escape flags */
flags = (unsigned char)(lflags & ESC_FLAGS); flags = (unsigned short)(lflags & ESC_FLAGS);
type = str->type; type = str->type;
@ -444,14 +388,14 @@ static int do_indent(char_io *io_ch, void *arg, int indent)
#define FN_WIDTH_LN 25 #define FN_WIDTH_LN 25
#define FN_WIDTH_SN 10 #define FN_WIDTH_SN 10
static int do_name_ex(char_io *io_ch, void *arg, X509_NAME *n, static int do_name_ex(char_io *io_ch, void *arg, const X509_NAME *n,
int indent, unsigned long flags) int indent, unsigned long flags)
{ {
int i, prev = -1, orflags, cnt; int i, prev = -1, orflags, cnt;
int fn_opt, fn_nid; int fn_opt, fn_nid;
ASN1_OBJECT *fn; ASN1_OBJECT *fn;
ASN1_STRING *val; const ASN1_STRING *val;
X509_NAME_ENTRY *ent; const X509_NAME_ENTRY *ent;
char objtmp[80]; char objtmp[80];
const char *objbuf; const char *objbuf;
int outlen, len; int outlen, len;
@ -515,7 +459,7 @@ static int do_name_ex(char_io *io_ch, void *arg, X509_NAME *n,
else else
ent = X509_NAME_get_entry(n, i); ent = X509_NAME_get_entry(n, i);
if (prev != -1) { if (prev != -1) {
if (prev == ent->set) { if (prev == X509_NAME_ENTRY_set(ent)) {
if (!io_ch(arg, sep_mv, sep_mv_len)) if (!io_ch(arg, sep_mv, sep_mv_len))
return -1; return -1;
outlen += sep_mv_len; outlen += sep_mv_len;
@ -528,7 +472,7 @@ static int do_name_ex(char_io *io_ch, void *arg, X509_NAME *n,
outlen += indent; outlen += indent;
} }
} }
prev = ent->set; prev = X509_NAME_ENTRY_set(ent);
fn = X509_NAME_ENTRY_get_object(ent); fn = X509_NAME_ENTRY_get_object(ent);
val = X509_NAME_ENTRY_get_data(ent); val = X509_NAME_ENTRY_get_data(ent);
fn_nid = OBJ_obj2nid(fn); fn_nid = OBJ_obj2nid(fn);
@ -582,7 +526,7 @@ static int do_name_ex(char_io *io_ch, void *arg, X509_NAME *n,
/* Wrappers round the main functions */ /* Wrappers round the main functions */
int X509_NAME_print_ex(BIO *out, X509_NAME *nm, int indent, int X509_NAME_print_ex(BIO *out, const X509_NAME *nm, int indent,
unsigned long flags) unsigned long flags)
{ {
if (flags == XN_FLAG_COMPAT) if (flags == XN_FLAG_COMPAT)
@ -590,8 +534,8 @@ int X509_NAME_print_ex(BIO *out, X509_NAME *nm, int indent,
return do_name_ex(send_bio_chars, out, nm, indent, flags); return do_name_ex(send_bio_chars, out, nm, indent, flags);
} }
#ifndef OPENSSL_NO_FP_API #ifndef OPENSSL_NO_STDIO
int X509_NAME_print_ex_fp(FILE *fp, X509_NAME *nm, int indent, int X509_NAME_print_ex_fp(FILE *fp, const X509_NAME *nm, int indent,
unsigned long flags) unsigned long flags)
{ {
if (flags == XN_FLAG_COMPAT) { if (flags == XN_FLAG_COMPAT) {
@ -608,13 +552,13 @@ int X509_NAME_print_ex_fp(FILE *fp, X509_NAME *nm, int indent,
} }
#endif #endif
int ASN1_STRING_print_ex(BIO *out, ASN1_STRING *str, unsigned long flags) int ASN1_STRING_print_ex(BIO *out, const ASN1_STRING *str, unsigned long flags)
{ {
return do_print_ex(send_bio_chars, out, flags, str); return do_print_ex(send_bio_chars, out, flags, str);
} }
#ifndef OPENSSL_NO_FP_API #ifndef OPENSSL_NO_STDIO
int ASN1_STRING_print_ex_fp(FILE *fp, ASN1_STRING *str, unsigned long flags) int ASN1_STRING_print_ex_fp(FILE *fp, const ASN1_STRING *str, unsigned long flags)
{ {
return do_print_ex(send_fp_chars, fp, flags, str); return do_print_ex(send_fp_chars, fp, flags, str);
} }
@ -625,7 +569,7 @@ int ASN1_STRING_print_ex_fp(FILE *fp, ASN1_STRING *str, unsigned long flags)
* in output string or a negative error code * in output string or a negative error code
*/ */
int ASN1_STRING_to_UTF8(unsigned char **out, ASN1_STRING *in) int ASN1_STRING_to_UTF8(unsigned char **out, const ASN1_STRING *in)
{ {
ASN1_STRING stmp, *str = &stmp; ASN1_STRING stmp, *str = &stmp;
int mbflag, type, ret; int mbflag, type, ret;
@ -649,3 +593,53 @@ int ASN1_STRING_to_UTF8(unsigned char **out, ASN1_STRING *in)
*out = stmp.data; *out = stmp.data;
return stmp.length; return stmp.length;
} }
/* Return 1 if host is a valid hostname and 0 otherwise */
int asn1_valid_host(const ASN1_STRING *host)
{
int hostlen = host->length;
const unsigned char *hostptr = host->data;
int type = host->type;
int i;
char width = -1;
unsigned short chflags = 0, prevchflags;
if (type > 0 && type < 31)
width = tag2nbyte[type];
if (width == -1 || hostlen == 0)
return 0;
/* Treat UTF8String as width 1 as any MSB set is invalid */
if (width == 0)
width = 1;
for (i = 0 ; i < hostlen; i+= width) {
prevchflags = chflags;
/* Value must be <= 0x7F: check upper bytes are all zeroes */
if (width == 4) {
if (*hostptr++ != 0 || *hostptr++ != 0 || *hostptr++ != 0)
return 0;
} else if (width == 2) {
if (*hostptr++ != 0)
return 0;
}
if (*hostptr > 0x7f)
return 0;
chflags = char_type[*hostptr++];
if (!(chflags & (CHARTYPE_HOST_ANY | CHARTYPE_HOST_WILD))) {
/* Nothing else allowed at start or end of string */
if (i == 0 || i == hostlen - 1)
return 0;
/* Otherwise invalid if not dot or hyphen */
if (!(chflags & (CHARTYPE_HOST_DOT | CHARTYPE_HOST_HYPHEN)))
return 0;
/*
* If previous is dot or hyphen then illegal unless both
* are hyphens: as .- -. .. are all illegal
*/
if (prevchflags & (CHARTYPE_HOST_DOT | CHARTYPE_HOST_HYPHEN)
&& ((prevchflags & CHARTYPE_HOST_DOT)
|| (chflags & CHARTYPE_HOST_DOT)))
return 0;
}
}
return 1;
}

View File

@ -1,65 +1,15 @@
/* a_strnid.c */
/* /*
* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved.
* 1999.
*/
/* ====================================================================
* Copyright (c) 1999 The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
*
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* licensing@OpenSSL.org.
*
* 5. Products derived from this software may not be called "OpenSSL"
* nor may "OpenSSL" appear in their names without prior written
* permission of the OpenSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*
* This product includes cryptographic software written by Eric Young
* (eay@cryptsoft.com). This product includes software written by Tim
* Hudson (tjh@cryptsoft.com).
* *
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/ */
#include <stdio.h> #include <stdio.h>
#include <ctype.h> #include <ctype.h>
#include "cryptlib.h" #include "internal/cryptlib.h"
#include <openssl/asn1.h> #include <openssl/asn1.h>
#include <openssl/objects.h> #include <openssl/objects.h>
@ -100,19 +50,19 @@ int ASN1_STRING_set_default_mask_asc(const char *p)
{ {
unsigned long mask; unsigned long mask;
char *end; char *end;
if (!strncmp(p, "MASK:", 5)) { if (strncmp(p, "MASK:", 5) == 0) {
if (!p[5]) if (!p[5])
return 0; return 0;
mask = strtoul(p + 5, &end, 0); mask = strtoul(p + 5, &end, 0);
if (*end) if (*end)
return 0; return 0;
} else if (!strcmp(p, "nombstr")) } else if (strcmp(p, "nombstr") == 0)
mask = ~((unsigned long)(B_ASN1_BMPSTRING | B_ASN1_UTF8STRING)); mask = ~((unsigned long)(B_ASN1_BMPSTRING | B_ASN1_UTF8STRING));
else if (!strcmp(p, "pkix")) else if (strcmp(p, "pkix") == 0)
mask = ~((unsigned long)B_ASN1_T61STRING); mask = ~((unsigned long)B_ASN1_T61STRING);
else if (!strcmp(p, "utf8only")) else if (strcmp(p, "utf8only") == 0)
mask = B_ASN1_UTF8STRING; mask = B_ASN1_UTF8STRING;
else if (!strcmp(p, "default")) else if (strcmp(p, "default") == 0)
mask = 0xFFFFFFFFL; mask = 0xFFFFFFFFL;
else else
return 0; return 0;
@ -168,6 +118,10 @@ ASN1_STRING *ASN1_STRING_set_by_NID(ASN1_STRING **out,
#define ub_email_address 128 #define ub_email_address 128
#define ub_serial_number 64 #define ub_serial_number 64
/* From RFC4524 */
#define ub_rfc822_mailbox 256
/* This table must be kept in NID order */ /* This table must be kept in NID order */
static const ASN1_STRING_TABLE tbl_standard[] = { static const ASN1_STRING_TABLE tbl_standard[] = {
@ -192,7 +146,12 @@ static const ASN1_STRING_TABLE tbl_standard[] = {
{NID_name, 1, ub_name, DIRSTRING_TYPE, 0}, {NID_name, 1, ub_name, DIRSTRING_TYPE, 0},
{NID_dnQualifier, -1, -1, B_ASN1_PRINTABLESTRING, STABLE_NO_MASK}, {NID_dnQualifier, -1, -1, B_ASN1_PRINTABLESTRING, STABLE_NO_MASK},
{NID_domainComponent, 1, -1, B_ASN1_IA5STRING, STABLE_NO_MASK}, {NID_domainComponent, 1, -1, B_ASN1_IA5STRING, STABLE_NO_MASK},
{NID_ms_csp_name, -1, -1, B_ASN1_BMPSTRING, STABLE_NO_MASK} {NID_ms_csp_name, -1, -1, B_ASN1_BMPSTRING, STABLE_NO_MASK},
{NID_rfc822Mailbox, 1, ub_rfc822_mailbox, B_ASN1_IA5STRING,
STABLE_NO_MASK},
{NID_INN, 1, 12, B_ASN1_NUMERICSTRING, STABLE_NO_MASK},
{NID_OGRN, 1, 13, B_ASN1_NUMERICSTRING, STABLE_NO_MASK},
{NID_SNILS, 1, 11, B_ASN1_NUMERICSTRING, STABLE_NO_MASK}
}; };
static int sk_table_cmp(const ASN1_STRING_TABLE *const *a, static int sk_table_cmp(const ASN1_STRING_TABLE *const *a,
@ -213,20 +172,52 @@ IMPLEMENT_OBJ_BSEARCH_CMP_FN(ASN1_STRING_TABLE, ASN1_STRING_TABLE, table);
ASN1_STRING_TABLE *ASN1_STRING_TABLE_get(int nid) ASN1_STRING_TABLE *ASN1_STRING_TABLE_get(int nid)
{ {
int idx; int idx;
ASN1_STRING_TABLE *ttmp;
ASN1_STRING_TABLE fnd; ASN1_STRING_TABLE fnd;
fnd.nid = nid; fnd.nid = nid;
ttmp = OBJ_bsearch_table(&fnd, tbl_standard, if (stable) {
sizeof(tbl_standard) /
sizeof(ASN1_STRING_TABLE));
if (ttmp)
return ttmp;
if (!stable)
return NULL;
idx = sk_ASN1_STRING_TABLE_find(stable, &fnd); idx = sk_ASN1_STRING_TABLE_find(stable, &fnd);
if (idx < 0) if (idx >= 0)
return NULL;
return sk_ASN1_STRING_TABLE_value(stable, idx); return sk_ASN1_STRING_TABLE_value(stable, idx);
}
return OBJ_bsearch_table(&fnd, tbl_standard, OSSL_NELEM(tbl_standard));
}
/*
* Return a string table pointer which can be modified: either directly from
* table or a copy of an internal value added to the table.
*/
static ASN1_STRING_TABLE *stable_get(int nid)
{
ASN1_STRING_TABLE *tmp, *rv;
/* Always need a string table so allocate one if NULL */
if (stable == NULL) {
stable = sk_ASN1_STRING_TABLE_new(sk_table_cmp);
if (stable == NULL)
return NULL;
}
tmp = ASN1_STRING_TABLE_get(nid);
if (tmp && tmp->flags & STABLE_FLAGS_MALLOC)
return tmp;
rv = OPENSSL_zalloc(sizeof(*rv));
if (rv == NULL)
return NULL;
if (!sk_ASN1_STRING_TABLE_push(stable, rv)) {
OPENSSL_free(rv);
return NULL;
}
if (tmp) {
rv->nid = tmp->nid;
rv->minsize = tmp->minsize;
rv->maxsize = tmp->maxsize;
rv->mask = tmp->mask;
rv->flags = tmp->flags | STABLE_FLAGS_MALLOC;
} else {
rv->minsize = -1;
rv->maxsize = -1;
rv->flags = STABLE_FLAGS_MALLOC;
}
return rv;
} }
int ASN1_STRING_TABLE_add(int nid, int ASN1_STRING_TABLE_add(int nid,
@ -234,33 +225,19 @@ int ASN1_STRING_TABLE_add(int nid,
unsigned long flags) unsigned long flags)
{ {
ASN1_STRING_TABLE *tmp; ASN1_STRING_TABLE *tmp;
char new_nid = 0; tmp = stable_get(nid);
flags &= ~STABLE_FLAGS_MALLOC;
if (!stable)
stable = sk_ASN1_STRING_TABLE_new(sk_table_cmp);
if (!stable) {
ASN1err(ASN1_F_ASN1_STRING_TABLE_ADD, ERR_R_MALLOC_FAILURE);
return 0;
}
if (!(tmp = ASN1_STRING_TABLE_get(nid))) {
tmp = OPENSSL_malloc(sizeof(ASN1_STRING_TABLE));
if (!tmp) { if (!tmp) {
ASN1err(ASN1_F_ASN1_STRING_TABLE_ADD, ERR_R_MALLOC_FAILURE); ASN1err(ASN1_F_ASN1_STRING_TABLE_ADD, ERR_R_MALLOC_FAILURE);
return 0; return 0;
} }
tmp->flags = flags | STABLE_FLAGS_MALLOC; if (minsize >= 0)
tmp->nid = nid;
tmp->minsize = tmp->maxsize = -1;
new_nid = 1;
} else
tmp->flags = (tmp->flags & STABLE_FLAGS_MALLOC) | flags;
if (minsize != -1)
tmp->minsize = minsize; tmp->minsize = minsize;
if (maxsize != -1) if (maxsize >= 0)
tmp->maxsize = maxsize; tmp->maxsize = maxsize;
if (mask)
tmp->mask = mask; tmp->mask = mask;
if (new_nid) if (flags)
sk_ASN1_STRING_TABLE_push(stable, tmp); tmp->flags = STABLE_FLAGS_MALLOC | flags;
return 1; return 1;
} }
@ -281,8 +258,6 @@ static void st_free(ASN1_STRING_TABLE *tbl)
} }
IMPLEMENT_STACK_OF(ASN1_STRING_TABLE)
#ifdef STRING_TABLE_TEST #ifdef STRING_TABLE_TEST
main() main()
@ -290,8 +265,7 @@ main()
ASN1_STRING_TABLE *tmp; ASN1_STRING_TABLE *tmp;
int i, last_nid = -1; int i, last_nid = -1;
for (tmp = tbl_standard, i = 0; for (tmp = tbl_standard, i = 0; i < OSSL_NELEM(tbl_standard); i++, tmp++) {
i < sizeof(tbl_standard) / sizeof(ASN1_STRING_TABLE); i++, tmp++) {
if (tmp->nid < last_nid) { if (tmp->nid < last_nid) {
last_nid = 0; last_nid = 0;
break; break;
@ -304,8 +278,7 @@ main()
exit(0); exit(0);
} }
for (tmp = tbl_standard, i = 0; for (tmp = tbl_standard, i = 0; i < OSSL_NELEM(tbl_standard); i++, tmp++)
i < sizeof(tbl_standard) / sizeof(ASN1_STRING_TABLE); i++, tmp++)
printf("Index %d, NID %d, Name=%s\n", i, tmp->nid, printf("Index %d, NID %d, Name=%s\n", i, tmp->nid,
OBJ_nid2ln(tmp->nid)); OBJ_nid2ln(tmp->nid));

View File

@ -1,56 +1,10 @@
/* crypto/asn1/a_time.c */ /*
/* ==================================================================== * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved.
* Copyright (c) 1999 The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
*
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* licensing@OpenSSL.org.
*
* 5. Products derived from this software may not be called "OpenSSL"
* nor may "OpenSSL" appear in their names without prior written
* permission of the OpenSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*
* This product includes cryptographic software written by Eric Young
* (eay@cryptsoft.com). This product includes software written by Tim
* Hudson (tjh@cryptsoft.com).
* *
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/ */
/*- /*-
@ -58,13 +12,11 @@
* Time ::= CHOICE { * Time ::= CHOICE {
* utcTime UTCTime, * utcTime UTCTime,
* generalTime GeneralizedTime } * generalTime GeneralizedTime }
* written by Steve Henson.
*/ */
#include <stdio.h> #include <stdio.h>
#include <time.h> #include <time.h>
#include "cryptlib.h" #include "internal/cryptlib.h"
#include "o_time.h"
#include <openssl/asn1t.h> #include <openssl/asn1t.h>
#include "asn1_locl.h" #include "asn1_locl.h"
@ -72,33 +24,6 @@ IMPLEMENT_ASN1_MSTRING(ASN1_TIME, B_ASN1_TIME)
IMPLEMENT_ASN1_FUNCTIONS(ASN1_TIME) IMPLEMENT_ASN1_FUNCTIONS(ASN1_TIME)
#if 0
int i2d_ASN1_TIME(ASN1_TIME *a, unsigned char **pp)
{
# ifdef CHARSET_EBCDIC
/* KLUDGE! We convert to ascii before writing DER */
char tmp[24];
ASN1_STRING tmpstr;
if (a->type == V_ASN1_UTCTIME || a->type == V_ASN1_GENERALIZEDTIME) {
int len;
tmpstr = *(ASN1_STRING *)a;
len = tmpstr.length;
ebcdic2ascii(tmp, tmpstr.data,
(len >= sizeof tmp) ? sizeof tmp : len);
tmpstr.data = tmp;
a = (ASN1_GENERALIZEDTIME *)&tmpstr;
}
# endif
if (a->type == V_ASN1_UTCTIME || a->type == V_ASN1_GENERALIZEDTIME)
return (i2d_ASN1_bytes((ASN1_STRING *)a, pp,
a->type, V_ASN1_UNIVERSAL));
ASN1err(ASN1_F_I2D_ASN1_TIME, ASN1_R_EXPECTING_A_TIME);
return -1;
}
#endif
ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t) ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t)
{ {
return ASN1_TIME_adj(s, t, 0, 0); return ASN1_TIME_adj(s, t, 0, 0);
@ -124,7 +49,7 @@ ASN1_TIME *ASN1_TIME_adj(ASN1_TIME *s, time_t t,
return ASN1_GENERALIZEDTIME_adj(s, t, offset_day, offset_sec); return ASN1_GENERALIZEDTIME_adj(s, t, offset_day, offset_sec);
} }
int ASN1_TIME_check(ASN1_TIME *t) int ASN1_TIME_check(const ASN1_TIME *t)
{ {
if (t->type == V_ASN1_GENERALIZEDTIME) if (t->type == V_ASN1_GENERALIZEDTIME)
return ASN1_GENERALIZEDTIME_check(t); return ASN1_GENERALIZEDTIME_check(t);
@ -144,8 +69,8 @@ ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(ASN1_TIME *t,
if (!ASN1_TIME_check(t)) if (!ASN1_TIME_check(t))
return NULL; return NULL;
if (!out || !*out) { if (out == NULL || *out == NULL) {
if (!(ret = ASN1_GENERALIZEDTIME_new())) if ((ret = ASN1_GENERALIZEDTIME_new()) == NULL)
return NULL; return NULL;
if (out) if (out)
*out = ret; *out = ret;
@ -167,11 +92,11 @@ ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(ASN1_TIME *t,
str = (char *)ret->data; str = (char *)ret->data;
/* Work out the century and prepend */ /* Work out the century and prepend */
if (t->data[0] >= '5') if (t->data[0] >= '5')
BUF_strlcpy(str, "19", newlen); OPENSSL_strlcpy(str, "19", newlen);
else else
BUF_strlcpy(str, "20", newlen); OPENSSL_strlcpy(str, "20", newlen);
BUF_strlcat(str, (char *)t->data, newlen); OPENSSL_strlcat(str, (char *)t->data, newlen);
return ret; return ret;
} }
@ -226,3 +151,13 @@ int ASN1_TIME_diff(int *pday, int *psec,
return 0; return 0;
return OPENSSL_gmtime_diff(pday, psec, &tm_from, &tm_to); return OPENSSL_gmtime_diff(pday, psec, &tm_from, &tm_to);
} }
int ASN1_TIME_print(BIO *bp, const ASN1_TIME *tm)
{
if (tm->type == V_ASN1_UTCTIME)
return ASN1_UTCTIME_print(bp, tm);
if (tm->type == V_ASN1_GENERALIZEDTIME)
return ASN1_GENERALIZEDTIME_print(bp, tm);
BIO_write(bp, "Bad time value", 14);
return (0);
}

View File

@ -1,67 +1,19 @@
/* crypto/asn1/a_type.c */ /*
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
* All rights reserved.
* *
* This package is an SSL implementation written * Licensed under the OpenSSL license (the "License"). You may not use
* by Eric Young (eay@cryptsoft.com). * this file except in compliance with the License. You can obtain a copy
* The implementation was written so as to conform with Netscapes SSL. * in the file LICENSE in the source distribution or at
* * https://www.openssl.org/source/license.html
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* "This product includes cryptographic software written by
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/ */
#include <stdio.h> #include <stdio.h>
#include "cryptlib.h" #include "internal/cryptlib.h"
#include <openssl/asn1t.h> #include <openssl/asn1t.h>
#include <openssl/objects.h> #include <openssl/objects.h>
#include "asn1_locl.h"
int ASN1_TYPE_get(ASN1_TYPE *a) int ASN1_TYPE_get(const ASN1_TYPE *a)
{ {
if ((a->value.ptr != NULL) || (a->type == V_ASN1_NULL)) if ((a->value.ptr != NULL) || (a->type == V_ASN1_NULL))
return (a->type); return (a->type);
@ -73,7 +25,7 @@ void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value)
{ {
if (a->value.ptr != NULL) { if (a->value.ptr != NULL) {
ASN1_TYPE **tmp_a = &a; ASN1_TYPE **tmp_a = &a;
ASN1_primitive_free((ASN1_VALUE **)tmp_a, NULL); asn1_primitive_free((ASN1_VALUE **)tmp_a, NULL, 0);
} }
a->type = type; a->type = type;
if (type == V_ASN1_BOOLEAN) if (type == V_ASN1_BOOLEAN)
@ -103,10 +55,6 @@ int ASN1_TYPE_set1(ASN1_TYPE *a, int type, const void *value)
return 1; return 1;
} }
IMPLEMENT_STACK_OF(ASN1_TYPE)
IMPLEMENT_ASN1_SET_OF(ASN1_TYPE)
/* Returns 0 if they are equal, != 0 otherwise. */ /* Returns 0 if they are equal, != 0 otherwise. */
int ASN1_TYPE_cmp(const ASN1_TYPE *a, const ASN1_TYPE *b) int ASN1_TYPE_cmp(const ASN1_TYPE *a, const ASN1_TYPE *b)
{ {
@ -153,3 +101,34 @@ int ASN1_TYPE_cmp(const ASN1_TYPE *a, const ASN1_TYPE *b)
return result; return result;
} }
ASN1_TYPE *ASN1_TYPE_pack_sequence(const ASN1_ITEM *it, void *s, ASN1_TYPE **t)
{
ASN1_OCTET_STRING *oct;
ASN1_TYPE *rt;
oct = ASN1_item_pack(s, it, NULL);
if (oct == NULL)
return NULL;
if (t && *t) {
rt = *t;
} else {
rt = ASN1_TYPE_new();
if (rt == NULL) {
ASN1_OCTET_STRING_free(oct);
return NULL;
}
if (t)
*t = rt;
}
ASN1_TYPE_set(rt, V_ASN1_SEQUENCE, oct);
return rt;
}
void *ASN1_TYPE_unpack_sequence(const ASN1_ITEM *it, const ASN1_TYPE *t)
{
if (t == NULL || t->type != V_ASN1_SEQUENCE || t->value.sequence == NULL)
return NULL;
return ASN1_item_unpack(t->value.sequence, it);
}

View File

@ -1,115 +1,18 @@
/* crypto/asn1/a_utctm.c */ /*
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
* All rights reserved.
* *
* This package is an SSL implementation written * Licensed under the OpenSSL license (the "License"). You may not use
* by Eric Young (eay@cryptsoft.com). * this file except in compliance with the License. You can obtain a copy
* The implementation was written so as to conform with Netscapes SSL. * in the file LICENSE in the source distribution or at
* * https://www.openssl.org/source/license.html
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* "This product includes cryptographic software written by
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/ */
#include <stdio.h> #include <stdio.h>
#include <time.h> #include <time.h>
#include "cryptlib.h" #include "internal/cryptlib.h"
#include "o_time.h"
#include <openssl/asn1.h> #include <openssl/asn1.h>
#include "asn1_locl.h" #include "asn1_locl.h"
#if 0
int i2d_ASN1_UTCTIME(ASN1_UTCTIME *a, unsigned char **pp)
{
# ifndef CHARSET_EBCDIC
return (i2d_ASN1_bytes((ASN1_STRING *)a, pp,
V_ASN1_UTCTIME, V_ASN1_UNIVERSAL));
# else
/* KLUDGE! We convert to ascii before writing DER */
int len;
char tmp[24];
ASN1_STRING x = *(ASN1_STRING *)a;
len = x.length;
ebcdic2ascii(tmp, x.data, (len >= sizeof tmp) ? sizeof tmp : len);
x.data = tmp;
return i2d_ASN1_bytes(&x, pp, V_ASN1_UTCTIME, V_ASN1_UNIVERSAL);
# endif
}
ASN1_UTCTIME *d2i_ASN1_UTCTIME(ASN1_UTCTIME **a, unsigned char **pp,
long length)
{
ASN1_UTCTIME *ret = NULL;
ret = (ASN1_UTCTIME *)d2i_ASN1_bytes((ASN1_STRING **)a, pp, length,
V_ASN1_UTCTIME, V_ASN1_UNIVERSAL);
if (ret == NULL) {
ASN1err(ASN1_F_D2I_ASN1_UTCTIME, ERR_R_NESTED_ASN1_ERROR);
return (NULL);
}
# ifdef CHARSET_EBCDIC
ascii2ebcdic(ret->data, ret->data, ret->length);
# endif
if (!ASN1_UTCTIME_check(ret)) {
ASN1err(ASN1_F_D2I_ASN1_UTCTIME, ASN1_R_INVALID_TIME_FORMAT);
goto err;
}
return (ret);
err:
if ((ret != NULL) && ((a == NULL) || (*a != ret)))
M_ASN1_UTCTIME_free(ret);
return (NULL);
}
#endif
int asn1_utctime_to_tm(struct tm *tm, const ASN1_UTCTIME *d) int asn1_utctime_to_tm(struct tm *tm, const ASN1_UTCTIME *d)
{ {
static const int min[8] = { 0, 1, 1, 0, 0, 0, 0, 0 }; static const int min[8] = { 0, 1, 1, 0, 0, 0, 0, 0 };
@ -216,8 +119,7 @@ int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, const char *str)
t.data = (unsigned char *)str; t.data = (unsigned char *)str;
if (ASN1_UTCTIME_check(&t)) { if (ASN1_UTCTIME_check(&t)) {
if (s != NULL) { if (s != NULL) {
if (!ASN1_STRING_set((ASN1_STRING *)s, if (!ASN1_STRING_set((ASN1_STRING *)s, str, t.length))
(unsigned char *)str, t.length))
return 0; return 0;
s->type = V_ASN1_UTCTIME; s->type = V_ASN1_UTCTIME;
} }
@ -241,11 +143,11 @@ ASN1_UTCTIME *ASN1_UTCTIME_adj(ASN1_UTCTIME *s, time_t t,
int free_s = 0; int free_s = 0;
if (s == NULL) { if (s == NULL) {
free_s = 1; s = ASN1_UTCTIME_new();
s = M_ASN1_UTCTIME_new();
}
if (s == NULL) if (s == NULL)
goto err; goto err;
free_s = 1;
}
ts = OPENSSL_gmtime(&t, &data); ts = OPENSSL_gmtime(&t, &data);
if (ts == NULL) if (ts == NULL)
@ -266,7 +168,6 @@ ASN1_UTCTIME *ASN1_UTCTIME_adj(ASN1_UTCTIME *s, time_t t,
ASN1err(ASN1_F_ASN1_UTCTIME_ADJ, ERR_R_MALLOC_FAILURE); ASN1err(ASN1_F_ASN1_UTCTIME_ADJ, ERR_R_MALLOC_FAILURE);
goto err; goto err;
} }
if (s->data != NULL)
OPENSSL_free(s->data); OPENSSL_free(s->data);
s->data = (unsigned char *)p; s->data = (unsigned char *)p;
} }
@ -281,8 +182,8 @@ ASN1_UTCTIME *ASN1_UTCTIME_adj(ASN1_UTCTIME *s, time_t t,
#endif #endif
return (s); return (s);
err: err:
if (free_s && s) if (free_s)
M_ASN1_UTCTIME_free(s); ASN1_UTCTIME_free(s);
return NULL; return NULL;
} }
@ -311,42 +212,43 @@ int ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t)
return 0; return 0;
} }
#if 0 int ASN1_UTCTIME_print(BIO *bp, const ASN1_UTCTIME *tm)
time_t ASN1_UTCTIME_get(const ASN1_UTCTIME *s)
{ {
struct tm tm; const char *v;
int offset; int gmt = 0;
int i;
int y = 0, M = 0, d = 0, h = 0, m = 0, s = 0;
memset(&tm, '\0', sizeof tm); i = tm->length;
v = (const char *)tm->data;
# define g2(p) (((p)[0]-'0')*10+(p)[1]-'0') if (i < 10)
tm.tm_year = g2(s->data); goto err;
if (tm.tm_year < 50) if (v[i - 1] == 'Z')
tm.tm_year += 100; gmt = 1;
tm.tm_mon = g2(s->data + 2) - 1; for (i = 0; i < 10; i++)
tm.tm_mday = g2(s->data + 4); if ((v[i] > '9') || (v[i] < '0'))
tm.tm_hour = g2(s->data + 6); goto err;
tm.tm_min = g2(s->data + 8); y = (v[0] - '0') * 10 + (v[1] - '0');
tm.tm_sec = g2(s->data + 10); if (y < 50)
if (s->data[12] == 'Z') y += 100;
offset = 0; M = (v[2] - '0') * 10 + (v[3] - '0');
else { if ((M > 12) || (M < 1))
offset = g2(s->data + 13) * 60 + g2(s->data + 15); goto err;
if (s->data[12] == '-') d = (v[4] - '0') * 10 + (v[5] - '0');
offset = -offset; h = (v[6] - '0') * 10 + (v[7] - '0');
} m = (v[8] - '0') * 10 + (v[9] - '0');
# undef g2 if (tm->length >= 12 &&
(v[10] >= '0') && (v[10] <= '9') && (v[11] >= '0') && (v[11] <= '9'))
s = (v[10] - '0') * 10 + (v[11] - '0');
/* if (BIO_printf(bp, "%s %2d %02d:%02d:%02d %d%s",
* FIXME: mktime assumes the current timezone _asn1_mon[M - 1], d, h, m, s, y + 1900,
* instead of UTC, and unless we rewrite OpenSSL (gmt) ? " GMT" : "") <= 0)
* in Lisp we cannot locally change the timezone return (0);
* without possibly interfering with other parts else
* of the program. timegm, which uses UTC, is return (1);
* non-standard. err:
* Also time_t is inappropriate for general BIO_write(bp, "Bad time value", 14);
* UTC times because it may a 32 bit type. return (0);
*/
return mktime(&tm) - offset * 60;
} }
#endif

View File

@ -1,63 +1,14 @@
/* crypto/asn1/a_utf8.c */ /*
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
* All rights reserved.
* *
* This package is an SSL implementation written * Licensed under the OpenSSL license (the "License"). You may not use
* by Eric Young (eay@cryptsoft.com). * this file except in compliance with the License. You can obtain a copy
* The implementation was written so as to conform with Netscapes SSL. * in the file LICENSE in the source distribution or at
* * https://www.openssl.org/source/license.html
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* "This product includes cryptographic software written by
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/ */
#include <stdio.h> #include <stdio.h>
#include "cryptlib.h" #include "internal/cryptlib.h"
#include <openssl/asn1.h> #include <openssl/asn1.h>
/* UTF8 utilities */ /* UTF8 utilities */

View File

@ -1,66 +1,16 @@
/* crypto/asn1/a_verify.c */ /*
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
* All rights reserved.
* *
* This package is an SSL implementation written * Licensed under the OpenSSL license (the "License"). You may not use
* by Eric Young (eay@cryptsoft.com). * this file except in compliance with the License. You can obtain a copy
* The implementation was written so as to conform with Netscapes SSL. * in the file LICENSE in the source distribution or at
* * https://www.openssl.org/source/license.html
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* "This product includes cryptographic software written by
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/ */
#include <stdio.h> #include <stdio.h>
#include <time.h> #include <time.h>
#include "cryptlib.h" #include "internal/cryptlib.h"
#include "asn1_locl.h"
#ifndef NO_SYS_TYPES_H #ifndef NO_SYS_TYPES_H
# include <sys/types.h> # include <sys/types.h>
@ -71,18 +21,23 @@
#include <openssl/objects.h> #include <openssl/objects.h>
#include <openssl/buffer.h> #include <openssl/buffer.h>
#include <openssl/evp.h> #include <openssl/evp.h>
#include "internal/asn1_int.h"
#include "internal/evp_int.h"
#ifndef NO_ASN1_OLD #ifndef NO_ASN1_OLD
int ASN1_verify(i2d_of_void *i2d, X509_ALGOR *a, ASN1_BIT_STRING *signature, int ASN1_verify(i2d_of_void *i2d, X509_ALGOR *a, ASN1_BIT_STRING *signature,
char *data, EVP_PKEY *pkey) char *data, EVP_PKEY *pkey)
{ {
EVP_MD_CTX ctx; EVP_MD_CTX *ctx = EVP_MD_CTX_new();
const EVP_MD *type; const EVP_MD *type;
unsigned char *p, *buf_in = NULL; unsigned char *p, *buf_in = NULL;
int ret = -1, i, inl; int ret = -1, i, inl;
EVP_MD_CTX_init(&ctx); if (ctx == NULL) {
ASN1err(ASN1_F_ASN1_VERIFY, ERR_R_MALLOC_FAILURE);
goto err;
}
i = OBJ_obj2nid(a->algorithm); i = OBJ_obj2nid(a->algorithm);
type = EVP_get_digestbyname(OBJ_nid2sn(i)); type = EVP_get_digestbyname(OBJ_nid2sn(i));
if (type == NULL) { if (type == NULL) {
@ -104,30 +59,26 @@ int ASN1_verify(i2d_of_void *i2d, X509_ALGOR *a, ASN1_BIT_STRING *signature,
p = buf_in; p = buf_in;
i2d(data, &p); i2d(data, &p);
if (!EVP_VerifyInit_ex(&ctx, type, NULL) ret = EVP_VerifyInit_ex(ctx, type, NULL)
|| !EVP_VerifyUpdate(&ctx, (unsigned char *)buf_in, inl)) { && EVP_VerifyUpdate(ctx, (unsigned char *)buf_in, inl);
OPENSSL_clear_free(buf_in, (unsigned int)inl);
if (!ret) {
ASN1err(ASN1_F_ASN1_VERIFY, ERR_R_EVP_LIB); ASN1err(ASN1_F_ASN1_VERIFY, ERR_R_EVP_LIB);
ret = 0;
goto err; goto err;
} }
ret = -1;
OPENSSL_cleanse(buf_in, (unsigned int)inl); if (EVP_VerifyFinal(ctx, (unsigned char *)signature->data,
OPENSSL_free(buf_in);
if (EVP_VerifyFinal(&ctx, (unsigned char *)signature->data,
(unsigned int)signature->length, pkey) <= 0) { (unsigned int)signature->length, pkey) <= 0) {
ASN1err(ASN1_F_ASN1_VERIFY, ERR_R_EVP_LIB); ASN1err(ASN1_F_ASN1_VERIFY, ERR_R_EVP_LIB);
ret = 0; ret = 0;
goto err; goto err;
} }
/*
* we don't need to zero the 'ctx' because we just checked public
* information
*/
/* memset(&ctx,0,sizeof(ctx)); */
ret = 1; ret = 1;
err: err:
EVP_MD_CTX_cleanup(&ctx); EVP_MD_CTX_free(ctx);
return (ret); return (ret);
} }
@ -136,7 +87,7 @@ int ASN1_verify(i2d_of_void *i2d, X509_ALGOR *a, ASN1_BIT_STRING *signature,
int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a, int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a,
ASN1_BIT_STRING *signature, void *asn, EVP_PKEY *pkey) ASN1_BIT_STRING *signature, void *asn, EVP_PKEY *pkey)
{ {
EVP_MD_CTX ctx; EVP_MD_CTX *ctx = NULL;
unsigned char *buf_in = NULL; unsigned char *buf_in = NULL;
int ret = -1, inl; int ret = -1, inl;
@ -152,7 +103,11 @@ int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a,
return -1; return -1;
} }
EVP_MD_CTX_init(&ctx); ctx = EVP_MD_CTX_new();
if (ctx == NULL) {
ASN1err(ASN1_F_ASN1_ITEM_VERIFY, ERR_R_MALLOC_FAILURE);
goto err;
}
/* Convert signature OID into digest and public key OIDs */ /* Convert signature OID into digest and public key OIDs */
if (!OBJ_find_sigid_algs(OBJ_obj2nid(a->algorithm), &mdnid, &pknid)) { if (!OBJ_find_sigid_algs(OBJ_obj2nid(a->algorithm), &mdnid, &pknid)) {
@ -165,7 +120,7 @@ int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a,
ASN1_R_UNKNOWN_SIGNATURE_ALGORITHM); ASN1_R_UNKNOWN_SIGNATURE_ALGORITHM);
goto err; goto err;
} }
ret = pkey->ameth->item_verify(&ctx, it, asn, a, signature, pkey); ret = pkey->ameth->item_verify(ctx, it, asn, a, signature, pkey);
/* /*
* Return value of 2 means carry on, anything else means we exit * Return value of 2 means carry on, anything else means we exit
* straight away: either a fatal error of the underlying verification * straight away: either a fatal error of the underlying verification
@ -189,7 +144,7 @@ int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a,
goto err; goto err;
} }
if (!EVP_DigestVerifyInit(&ctx, NULL, type, NULL, pkey)) { if (!EVP_DigestVerifyInit(ctx, NULL, type, NULL, pkey)) {
ASN1err(ASN1_F_ASN1_ITEM_VERIFY, ERR_R_EVP_LIB); ASN1err(ASN1_F_ASN1_ITEM_VERIFY, ERR_R_EVP_LIB);
ret = 0; ret = 0;
goto err; goto err;
@ -204,28 +159,24 @@ int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a,
goto err; goto err;
} }
if (!EVP_DigestVerifyUpdate(&ctx, buf_in, inl)) { ret = EVP_DigestVerifyUpdate(ctx, buf_in, inl);
OPENSSL_clear_free(buf_in, (unsigned int)inl);
if (!ret) {
ASN1err(ASN1_F_ASN1_ITEM_VERIFY, ERR_R_EVP_LIB); ASN1err(ASN1_F_ASN1_ITEM_VERIFY, ERR_R_EVP_LIB);
ret = 0;
goto err; goto err;
} }
ret = -1;
OPENSSL_cleanse(buf_in, (unsigned int)inl); if (EVP_DigestVerifyFinal(ctx, signature->data,
OPENSSL_free(buf_in);
if (EVP_DigestVerifyFinal(&ctx, signature->data,
(size_t)signature->length) <= 0) { (size_t)signature->length) <= 0) {
ASN1err(ASN1_F_ASN1_ITEM_VERIFY, ERR_R_EVP_LIB); ASN1err(ASN1_F_ASN1_ITEM_VERIFY, ERR_R_EVP_LIB);
ret = 0; ret = 0;
goto err; goto err;
} }
/*
* we don't need to zero the 'ctx' because we just checked public
* information
*/
/* memset(&ctx,0,sizeof(ctx)); */
ret = 1; ret = 1;
err: err:
EVP_MD_CTX_cleanup(&ctx); EVP_MD_CTX_free(ctx);
return (ret); return (ret);
} }

View File

@ -1,77 +1,19 @@
/* /*
* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project * Copyright 2006-2016 The OpenSSL Project Authors. All Rights Reserved.
* 2006.
*/
/* ====================================================================
* Copyright (c) 2006 The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
*
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* licensing@OpenSSL.org.
*
* 5. Products derived from this software may not be called "OpenSSL"
* nor may "OpenSSL" appear in their names without prior written
* permission of the OpenSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*
* This product includes cryptographic software written by Eric Young
* (eay@cryptsoft.com). This product includes software written by Tim
* Hudson (tjh@cryptsoft.com).
* *
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/ */
#include <stdio.h> #include <stdio.h>
#include "cryptlib.h" #include "internal/cryptlib.h"
#include <openssl/asn1t.h> #include <openssl/asn1t.h>
#include <openssl/x509.h> #include <openssl/x509.h>
#ifndef OPENSSL_NO_ENGINE #include <openssl/engine.h>
# include <openssl/engine.h> #include "internal/asn1_int.h"
#endif #include "internal/evp_int.h"
#include "asn1_locl.h"
extern const EVP_PKEY_ASN1_METHOD rsa_asn1_meths[];
extern const EVP_PKEY_ASN1_METHOD dsa_asn1_meths[];
extern const EVP_PKEY_ASN1_METHOD dh_asn1_meth;
extern const EVP_PKEY_ASN1_METHOD dhx_asn1_meth;
extern const EVP_PKEY_ASN1_METHOD eckey_asn1_meth;
extern const EVP_PKEY_ASN1_METHOD hmac_asn1_meth;
extern const EVP_PKEY_ASN1_METHOD cmac_asn1_meth;
/* Keep this sorted in type order !! */ /* Keep this sorted in type order !! */
static const EVP_PKEY_ASN1_METHOD *standard_methods[] = { static const EVP_PKEY_ASN1_METHOD *standard_methods[] = {
@ -97,20 +39,21 @@ static const EVP_PKEY_ASN1_METHOD *standard_methods[] = {
&cmac_asn1_meth, &cmac_asn1_meth,
#endif #endif
#ifndef OPENSSL_NO_DH #ifndef OPENSSL_NO_DH
&dhx_asn1_meth &dhx_asn1_meth,
#endif
#ifndef OPENSSL_NO_EC
&ecx25519_asn1_meth
#endif #endif
}; };
typedef int sk_cmp_fn_type(const char *const *a, const char *const *b); typedef int sk_cmp_fn_type(const char *const *a, const char *const *b);
DECLARE_STACK_OF(EVP_PKEY_ASN1_METHOD)
static STACK_OF(EVP_PKEY_ASN1_METHOD) *app_methods = NULL; static STACK_OF(EVP_PKEY_ASN1_METHOD) *app_methods = NULL;
#ifdef TEST #ifdef TEST
void main() void main()
{ {
int i; int i;
for (i = 0; for (i = 0; i < OSSL_NELEM(standard_methods); i++)
i < sizeof(standard_methods) / sizeof(EVP_PKEY_ASN1_METHOD *); i++)
fprintf(stderr, "Number %d id=%d (%s)\n", i, fprintf(stderr, "Number %d id=%d (%s)\n", i,
standard_methods[i]->pkey_id, standard_methods[i]->pkey_id,
OBJ_nid2sn(standard_methods[i]->pkey_id)); OBJ_nid2sn(standard_methods[i]->pkey_id));
@ -131,7 +74,7 @@ IMPLEMENT_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_ASN1_METHOD *,
int EVP_PKEY_asn1_get_count(void) int EVP_PKEY_asn1_get_count(void)
{ {
int num = sizeof(standard_methods) / sizeof(EVP_PKEY_ASN1_METHOD *); int num = OSSL_NELEM(standard_methods);
if (app_methods) if (app_methods)
num += sk_EVP_PKEY_ASN1_METHOD_num(app_methods); num += sk_EVP_PKEY_ASN1_METHOD_num(app_methods);
return num; return num;
@ -139,7 +82,7 @@ int EVP_PKEY_asn1_get_count(void)
const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_get0(int idx) const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_get0(int idx)
{ {
int num = sizeof(standard_methods) / sizeof(EVP_PKEY_ASN1_METHOD *); int num = OSSL_NELEM(standard_methods);
if (idx < 0) if (idx < 0)
return NULL; return NULL;
if (idx < num) if (idx < num)
@ -159,8 +102,7 @@ static const EVP_PKEY_ASN1_METHOD *pkey_asn1_find(int type)
if (idx >= 0) if (idx >= 0)
return sk_EVP_PKEY_ASN1_METHOD_value(app_methods, idx); return sk_EVP_PKEY_ASN1_METHOD_value(app_methods, idx);
} }
ret = OBJ_bsearch_ameth(&t, standard_methods, sizeof(standard_methods) ret = OBJ_bsearch_ameth(&t, standard_methods, OSSL_NELEM(standard_methods));
/ sizeof(EVP_PKEY_ASN1_METHOD *));
if (!ret || !*ret) if (!ret || !*ret)
return NULL; return NULL;
return *ret; return *ret;
@ -225,8 +167,8 @@ const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find_str(ENGINE **pe,
ameth = EVP_PKEY_asn1_get0(i); ameth = EVP_PKEY_asn1_get0(i);
if (ameth->pkey_flags & ASN1_PKEY_ALIAS) if (ameth->pkey_flags & ASN1_PKEY_ALIAS)
continue; continue;
if (((int)strlen(ameth->pem_str) == len) && if (((int)strlen(ameth->pem_str) == len)
!strncasecmp(ameth->pem_str, str, len)) && (strncasecmp(ameth->pem_str, str, len) == 0))
return ameth; return ameth;
} }
return NULL; return NULL;
@ -236,7 +178,7 @@ int EVP_PKEY_asn1_add0(const EVP_PKEY_ASN1_METHOD *ameth)
{ {
if (app_methods == NULL) { if (app_methods == NULL) {
app_methods = sk_EVP_PKEY_ASN1_METHOD_new(ameth_cmp); app_methods = sk_EVP_PKEY_ASN1_METHOD_new(ameth_cmp);
if (!app_methods) if (app_methods == NULL)
return 0; return 0;
} }
if (!sk_EVP_PKEY_ASN1_METHOD_push(app_methods, ameth)) if (!sk_EVP_PKEY_ASN1_METHOD_push(app_methods, ameth))
@ -249,7 +191,7 @@ int EVP_PKEY_asn1_add_alias(int to, int from)
{ {
EVP_PKEY_ASN1_METHOD *ameth; EVP_PKEY_ASN1_METHOD *ameth;
ameth = EVP_PKEY_asn1_new(from, ASN1_PKEY_ALIAS, NULL, NULL); ameth = EVP_PKEY_asn1_new(from, ASN1_PKEY_ALIAS, NULL, NULL);
if (!ameth) if (ameth == NULL)
return 0; return 0;
ameth->pkey_base_id = to; ameth->pkey_base_id = to;
if (!EVP_PKEY_asn1_add0(ameth)) { if (!EVP_PKEY_asn1_add0(ameth)) {
@ -279,7 +221,7 @@ int EVP_PKEY_asn1_get0_info(int *ppkey_id, int *ppkey_base_id,
return 1; return 1;
} }
const EVP_PKEY_ASN1_METHOD *EVP_PKEY_get0_asn1(EVP_PKEY *pkey) const EVP_PKEY_ASN1_METHOD *EVP_PKEY_get0_asn1(const EVP_PKEY *pkey)
{ {
return pkey->ameth; return pkey->ameth;
} }
@ -287,63 +229,30 @@ const EVP_PKEY_ASN1_METHOD *EVP_PKEY_get0_asn1(EVP_PKEY *pkey)
EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_new(int id, int flags, EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_new(int id, int flags,
const char *pem_str, const char *info) const char *pem_str, const char *info)
{ {
EVP_PKEY_ASN1_METHOD *ameth; EVP_PKEY_ASN1_METHOD *ameth = OPENSSL_zalloc(sizeof(*ameth));
ameth = OPENSSL_malloc(sizeof(EVP_PKEY_ASN1_METHOD));
if (!ameth)
return NULL;
memset(ameth, 0, sizeof(EVP_PKEY_ASN1_METHOD)); if (ameth == NULL)
return NULL;
ameth->pkey_id = id; ameth->pkey_id = id;
ameth->pkey_base_id = id; ameth->pkey_base_id = id;
ameth->pkey_flags = flags | ASN1_PKEY_DYNAMIC; ameth->pkey_flags = flags | ASN1_PKEY_DYNAMIC;
if (info) { if (info) {
ameth->info = BUF_strdup(info); ameth->info = OPENSSL_strdup(info);
if (!ameth->info) if (!ameth->info)
goto err; goto err;
} else }
ameth->info = NULL;
if (pem_str) { if (pem_str) {
ameth->pem_str = BUF_strdup(pem_str); ameth->pem_str = OPENSSL_strdup(pem_str);
if (!ameth->pem_str) if (!ameth->pem_str)
goto err; goto err;
} else }
ameth->pem_str = NULL;
ameth->pub_decode = 0;
ameth->pub_encode = 0;
ameth->pub_cmp = 0;
ameth->pub_print = 0;
ameth->priv_decode = 0;
ameth->priv_encode = 0;
ameth->priv_print = 0;
ameth->old_priv_encode = 0;
ameth->old_priv_decode = 0;
ameth->item_verify = 0;
ameth->item_sign = 0;
ameth->pkey_size = 0;
ameth->pkey_bits = 0;
ameth->param_decode = 0;
ameth->param_encode = 0;
ameth->param_missing = 0;
ameth->param_copy = 0;
ameth->param_cmp = 0;
ameth->param_print = 0;
ameth->pkey_free = 0;
ameth->pkey_ctrl = 0;
return ameth; return ameth;
err: err:
EVP_PKEY_asn1_free(ameth); EVP_PKEY_asn1_free(ameth);
return NULL; return NULL;
@ -386,9 +295,7 @@ void EVP_PKEY_asn1_copy(EVP_PKEY_ASN1_METHOD *dst,
void EVP_PKEY_asn1_free(EVP_PKEY_ASN1_METHOD *ameth) void EVP_PKEY_asn1_free(EVP_PKEY_ASN1_METHOD *ameth)
{ {
if (ameth && (ameth->pkey_flags & ASN1_PKEY_DYNAMIC)) { if (ameth && (ameth->pkey_flags & ASN1_PKEY_DYNAMIC)) {
if (ameth->pem_str)
OPENSSL_free(ameth->pem_str); OPENSSL_free(ameth->pem_str);
if (ameth->info)
OPENSSL_free(ameth->info); OPENSSL_free(ameth->info);
OPENSSL_free(ameth); OPENSSL_free(ameth);
} }
@ -417,7 +324,7 @@ void EVP_PKEY_asn1_set_public(EVP_PKEY_ASN1_METHOD *ameth,
void EVP_PKEY_asn1_set_private(EVP_PKEY_ASN1_METHOD *ameth, void EVP_PKEY_asn1_set_private(EVP_PKEY_ASN1_METHOD *ameth,
int (*priv_decode) (EVP_PKEY *pk, int (*priv_decode) (EVP_PKEY *pk,
PKCS8_PRIV_KEY_INFO const PKCS8_PRIV_KEY_INFO
*p8inf), *p8inf),
int (*priv_encode) (PKCS8_PRIV_KEY_INFO *p8, int (*priv_encode) (PKCS8_PRIV_KEY_INFO *p8,
const EVP_PKEY *pk), const EVP_PKEY *pk),
@ -467,6 +374,13 @@ void EVP_PKEY_asn1_set_ctrl(EVP_PKEY_ASN1_METHOD *ameth,
ameth->pkey_ctrl = pkey_ctrl; ameth->pkey_ctrl = pkey_ctrl;
} }
void EVP_PKEY_asn1_set_security_bits(EVP_PKEY_ASN1_METHOD *ameth,
int (*pkey_security_bits) (const EVP_PKEY
*pk))
{
ameth->pkey_security_bits = pkey_security_bits;
}
void EVP_PKEY_asn1_set_item(EVP_PKEY_ASN1_METHOD *ameth, void EVP_PKEY_asn1_set_item(EVP_PKEY_ASN1_METHOD *ameth,
int (*item_verify) (EVP_MD_CTX *ctx, int (*item_verify) (EVP_MD_CTX *ctx,
const ASN1_ITEM *it, const ASN1_ITEM *it,

View File

@ -1,62 +1,11 @@
/* crypto/asn1/asn1_err.c */
/* ====================================================================
* Copyright (c) 1999-2014 The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
*
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* openssl-core@OpenSSL.org.
*
* 5. Products derived from this software may not be called "OpenSSL"
* nor may "OpenSSL" appear in their names without prior written
* permission of the OpenSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*
* This product includes cryptographic software written by Eric Young
* (eay@cryptsoft.com). This product includes software written by Tim
* Hudson (tjh@cryptsoft.com).
*
*/
/* /*
* NOTE: this file was auto generated by the mkerr.pl script: any changes * Generated by util/mkerr.pl DO NOT EDIT
* made to it will be overwritten when the script next updates this file, * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
* only reason strings will be preserved. *
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/ */
#include <stdio.h> #include <stdio.h>
@ -71,38 +20,33 @@
static ERR_STRING_DATA ASN1_str_functs[] = { static ERR_STRING_DATA ASN1_str_functs[] = {
{ERR_FUNC(ASN1_F_A2D_ASN1_OBJECT), "a2d_ASN1_OBJECT"}, {ERR_FUNC(ASN1_F_A2D_ASN1_OBJECT), "a2d_ASN1_OBJECT"},
{ERR_FUNC(ASN1_F_A2I_ASN1_ENUMERATED), "a2i_ASN1_ENUMERATED"},
{ERR_FUNC(ASN1_F_A2I_ASN1_INTEGER), "a2i_ASN1_INTEGER"}, {ERR_FUNC(ASN1_F_A2I_ASN1_INTEGER), "a2i_ASN1_INTEGER"},
{ERR_FUNC(ASN1_F_A2I_ASN1_STRING), "a2i_ASN1_STRING"}, {ERR_FUNC(ASN1_F_A2I_ASN1_STRING), "a2i_ASN1_STRING"},
{ERR_FUNC(ASN1_F_APPEND_EXP), "APPEND_EXP"}, {ERR_FUNC(ASN1_F_APPEND_EXP), "append_exp"},
{ERR_FUNC(ASN1_F_ASN1_BIT_STRING_SET_BIT), "ASN1_BIT_STRING_set_bit"}, {ERR_FUNC(ASN1_F_ASN1_BIT_STRING_SET_BIT), "ASN1_BIT_STRING_set_bit"},
{ERR_FUNC(ASN1_F_ASN1_CB), "ASN1_CB"}, {ERR_FUNC(ASN1_F_ASN1_CB), "asn1_cb"},
{ERR_FUNC(ASN1_F_ASN1_CHECK_TLEN), "ASN1_CHECK_TLEN"}, {ERR_FUNC(ASN1_F_ASN1_CHECK_TLEN), "asn1_check_tlen"},
{ERR_FUNC(ASN1_F_ASN1_COLLATE_PRIMITIVE), "ASN1_COLLATE_PRIMITIVE"}, {ERR_FUNC(ASN1_F_ASN1_COLLECT), "asn1_collect"},
{ERR_FUNC(ASN1_F_ASN1_COLLECT), "ASN1_COLLECT"}, {ERR_FUNC(ASN1_F_ASN1_D2I_EX_PRIMITIVE), "asn1_d2i_ex_primitive"},
{ERR_FUNC(ASN1_F_ASN1_D2I_EX_PRIMITIVE), "ASN1_D2I_EX_PRIMITIVE"},
{ERR_FUNC(ASN1_F_ASN1_D2I_FP), "ASN1_d2i_fp"}, {ERR_FUNC(ASN1_F_ASN1_D2I_FP), "ASN1_d2i_fp"},
{ERR_FUNC(ASN1_F_ASN1_D2I_READ_BIO), "ASN1_D2I_READ_BIO"}, {ERR_FUNC(ASN1_F_ASN1_D2I_READ_BIO), "asn1_d2i_read_bio"},
{ERR_FUNC(ASN1_F_ASN1_DIGEST), "ASN1_digest"}, {ERR_FUNC(ASN1_F_ASN1_DIGEST), "ASN1_digest"},
{ERR_FUNC(ASN1_F_ASN1_DO_ADB), "ASN1_DO_ADB"}, {ERR_FUNC(ASN1_F_ASN1_DO_ADB), "asn1_do_adb"},
{ERR_FUNC(ASN1_F_ASN1_DO_LOCK), "asn1_do_lock"},
{ERR_FUNC(ASN1_F_ASN1_DUP), "ASN1_dup"}, {ERR_FUNC(ASN1_F_ASN1_DUP), "ASN1_dup"},
{ERR_FUNC(ASN1_F_ASN1_ENUMERATED_SET), "ASN1_ENUMERATED_set"}, {ERR_FUNC(ASN1_F_ASN1_EX_C2I), "asn1_ex_c2i"},
{ERR_FUNC(ASN1_F_ASN1_ENUMERATED_TO_BN), "ASN1_ENUMERATED_to_BN"}, {ERR_FUNC(ASN1_F_ASN1_FIND_END), "asn1_find_end"},
{ERR_FUNC(ASN1_F_ASN1_EX_C2I), "ASN1_EX_C2I"},
{ERR_FUNC(ASN1_F_ASN1_FIND_END), "ASN1_FIND_END"},
{ERR_FUNC(ASN1_F_ASN1_GENERALIZEDTIME_ADJ), "ASN1_GENERALIZEDTIME_adj"}, {ERR_FUNC(ASN1_F_ASN1_GENERALIZEDTIME_ADJ), "ASN1_GENERALIZEDTIME_adj"},
{ERR_FUNC(ASN1_F_ASN1_GENERALIZEDTIME_SET), "ASN1_GENERALIZEDTIME_set"},
{ERR_FUNC(ASN1_F_ASN1_GENERATE_V3), "ASN1_generate_v3"}, {ERR_FUNC(ASN1_F_ASN1_GENERATE_V3), "ASN1_generate_v3"},
{ERR_FUNC(ASN1_F_ASN1_GET_INT64), "asn1_get_int64"},
{ERR_FUNC(ASN1_F_ASN1_GET_OBJECT), "ASN1_get_object"}, {ERR_FUNC(ASN1_F_ASN1_GET_OBJECT), "ASN1_get_object"},
{ERR_FUNC(ASN1_F_ASN1_HEADER_NEW), "ASN1_HEADER_NEW"}, {ERR_FUNC(ASN1_F_ASN1_GET_UINT64), "asn1_get_uint64"},
{ERR_FUNC(ASN1_F_ASN1_I2D_BIO), "ASN1_i2d_bio"}, {ERR_FUNC(ASN1_F_ASN1_I2D_BIO), "ASN1_i2d_bio"},
{ERR_FUNC(ASN1_F_ASN1_I2D_FP), "ASN1_i2d_fp"}, {ERR_FUNC(ASN1_F_ASN1_I2D_FP), "ASN1_i2d_fp"},
{ERR_FUNC(ASN1_F_ASN1_INTEGER_SET), "ASN1_INTEGER_set"},
{ERR_FUNC(ASN1_F_ASN1_INTEGER_TO_BN), "ASN1_INTEGER_to_BN"},
{ERR_FUNC(ASN1_F_ASN1_ITEM_D2I_FP), "ASN1_item_d2i_fp"}, {ERR_FUNC(ASN1_F_ASN1_ITEM_D2I_FP), "ASN1_item_d2i_fp"},
{ERR_FUNC(ASN1_F_ASN1_ITEM_DUP), "ASN1_item_dup"}, {ERR_FUNC(ASN1_F_ASN1_ITEM_DUP), "ASN1_item_dup"},
{ERR_FUNC(ASN1_F_ASN1_ITEM_EX_COMBINE_NEW), "ASN1_ITEM_EX_COMBINE_NEW"}, {ERR_FUNC(ASN1_F_ASN1_ITEM_EMBED_D2I), "asn1_item_embed_d2i"},
{ERR_FUNC(ASN1_F_ASN1_ITEM_EX_D2I), "ASN1_ITEM_EX_D2I"}, {ERR_FUNC(ASN1_F_ASN1_ITEM_EMBED_NEW), "asn1_item_embed_new"},
{ERR_FUNC(ASN1_F_ASN1_ITEM_I2D_BIO), "ASN1_item_i2d_bio"}, {ERR_FUNC(ASN1_F_ASN1_ITEM_I2D_BIO), "ASN1_item_i2d_bio"},
{ERR_FUNC(ASN1_F_ASN1_ITEM_I2D_FP), "ASN1_item_i2d_fp"}, {ERR_FUNC(ASN1_F_ASN1_ITEM_I2D_FP), "ASN1_item_i2d_fp"},
{ERR_FUNC(ASN1_F_ASN1_ITEM_PACK), "ASN1_item_pack"}, {ERR_FUNC(ASN1_F_ASN1_ITEM_PACK), "ASN1_item_pack"},
@ -112,85 +56,65 @@ static ERR_STRING_DATA ASN1_str_functs[] = {
{ERR_FUNC(ASN1_F_ASN1_ITEM_VERIFY), "ASN1_item_verify"}, {ERR_FUNC(ASN1_F_ASN1_ITEM_VERIFY), "ASN1_item_verify"},
{ERR_FUNC(ASN1_F_ASN1_MBSTRING_NCOPY), "ASN1_mbstring_ncopy"}, {ERR_FUNC(ASN1_F_ASN1_MBSTRING_NCOPY), "ASN1_mbstring_ncopy"},
{ERR_FUNC(ASN1_F_ASN1_OBJECT_NEW), "ASN1_OBJECT_new"}, {ERR_FUNC(ASN1_F_ASN1_OBJECT_NEW), "ASN1_OBJECT_new"},
{ERR_FUNC(ASN1_F_ASN1_OUTPUT_DATA), "ASN1_OUTPUT_DATA"}, {ERR_FUNC(ASN1_F_ASN1_OUTPUT_DATA), "asn1_output_data"},
{ERR_FUNC(ASN1_F_ASN1_PACK_STRING), "ASN1_pack_string"},
{ERR_FUNC(ASN1_F_ASN1_PCTX_NEW), "ASN1_PCTX_new"}, {ERR_FUNC(ASN1_F_ASN1_PCTX_NEW), "ASN1_PCTX_new"},
{ERR_FUNC(ASN1_F_ASN1_PKCS5_PBE_SET), "ASN1_PKCS5_PBE_SET"}, {ERR_FUNC(ASN1_F_ASN1_SCTX_NEW), "ASN1_SCTX_new"},
{ERR_FUNC(ASN1_F_ASN1_SEQ_PACK), "ASN1_seq_pack"},
{ERR_FUNC(ASN1_F_ASN1_SEQ_UNPACK), "ASN1_seq_unpack"},
{ERR_FUNC(ASN1_F_ASN1_SIGN), "ASN1_sign"}, {ERR_FUNC(ASN1_F_ASN1_SIGN), "ASN1_sign"},
{ERR_FUNC(ASN1_F_ASN1_STR2TYPE), "ASN1_STR2TYPE"}, {ERR_FUNC(ASN1_F_ASN1_STR2TYPE), "asn1_str2type"},
{ERR_FUNC(ASN1_F_ASN1_STRING_GET_INT64), "asn1_string_get_int64"},
{ERR_FUNC(ASN1_F_ASN1_STRING_GET_UINT64), "asn1_string_get_uint64"},
{ERR_FUNC(ASN1_F_ASN1_STRING_SET), "ASN1_STRING_set"}, {ERR_FUNC(ASN1_F_ASN1_STRING_SET), "ASN1_STRING_set"},
{ERR_FUNC(ASN1_F_ASN1_STRING_TABLE_ADD), "ASN1_STRING_TABLE_add"}, {ERR_FUNC(ASN1_F_ASN1_STRING_TABLE_ADD), "ASN1_STRING_TABLE_add"},
{ERR_FUNC(ASN1_F_ASN1_STRING_TO_BN), "asn1_string_to_bn"},
{ERR_FUNC(ASN1_F_ASN1_STRING_TYPE_NEW), "ASN1_STRING_type_new"}, {ERR_FUNC(ASN1_F_ASN1_STRING_TYPE_NEW), "ASN1_STRING_type_new"},
{ERR_FUNC(ASN1_F_ASN1_TEMPLATE_EX_D2I), "ASN1_TEMPLATE_EX_D2I"}, {ERR_FUNC(ASN1_F_ASN1_TEMPLATE_EX_D2I), "asn1_template_ex_d2i"},
{ERR_FUNC(ASN1_F_ASN1_TEMPLATE_NEW), "ASN1_TEMPLATE_NEW"}, {ERR_FUNC(ASN1_F_ASN1_TEMPLATE_NEW), "asn1_template_new"},
{ERR_FUNC(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I), "ASN1_TEMPLATE_NOEXP_D2I"}, {ERR_FUNC(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I), "asn1_template_noexp_d2i"},
{ERR_FUNC(ASN1_F_ASN1_TIME_ADJ), "ASN1_TIME_adj"}, {ERR_FUNC(ASN1_F_ASN1_TIME_ADJ), "ASN1_TIME_adj"},
{ERR_FUNC(ASN1_F_ASN1_TIME_SET), "ASN1_TIME_set"},
{ERR_FUNC(ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING), {ERR_FUNC(ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING),
"ASN1_TYPE_get_int_octetstring"}, "ASN1_TYPE_get_int_octetstring"},
{ERR_FUNC(ASN1_F_ASN1_TYPE_GET_OCTETSTRING), "ASN1_TYPE_get_octetstring"}, {ERR_FUNC(ASN1_F_ASN1_TYPE_GET_OCTETSTRING), "ASN1_TYPE_get_octetstring"},
{ERR_FUNC(ASN1_F_ASN1_UNPACK_STRING), "ASN1_unpack_string"},
{ERR_FUNC(ASN1_F_ASN1_UTCTIME_ADJ), "ASN1_UTCTIME_adj"}, {ERR_FUNC(ASN1_F_ASN1_UTCTIME_ADJ), "ASN1_UTCTIME_adj"},
{ERR_FUNC(ASN1_F_ASN1_UTCTIME_SET), "ASN1_UTCTIME_set"},
{ERR_FUNC(ASN1_F_ASN1_VERIFY), "ASN1_verify"}, {ERR_FUNC(ASN1_F_ASN1_VERIFY), "ASN1_verify"},
{ERR_FUNC(ASN1_F_B64_READ_ASN1), "B64_READ_ASN1"}, {ERR_FUNC(ASN1_F_B64_READ_ASN1), "b64_read_asn1"},
{ERR_FUNC(ASN1_F_B64_WRITE_ASN1), "B64_WRITE_ASN1"}, {ERR_FUNC(ASN1_F_B64_WRITE_ASN1), "B64_write_ASN1"},
{ERR_FUNC(ASN1_F_BIO_NEW_NDEF), "BIO_new_NDEF"}, {ERR_FUNC(ASN1_F_BIO_NEW_NDEF), "BIO_new_NDEF"},
{ERR_FUNC(ASN1_F_BITSTR_CB), "BITSTR_CB"}, {ERR_FUNC(ASN1_F_BITSTR_CB), "bitstr_cb"},
{ERR_FUNC(ASN1_F_BN_TO_ASN1_ENUMERATED), "BN_to_ASN1_ENUMERATED"}, {ERR_FUNC(ASN1_F_BN_TO_ASN1_STRING), "bn_to_asn1_string"},
{ERR_FUNC(ASN1_F_BN_TO_ASN1_INTEGER), "BN_to_ASN1_INTEGER"},
{ERR_FUNC(ASN1_F_C2I_ASN1_BIT_STRING), "c2i_ASN1_BIT_STRING"}, {ERR_FUNC(ASN1_F_C2I_ASN1_BIT_STRING), "c2i_ASN1_BIT_STRING"},
{ERR_FUNC(ASN1_F_C2I_ASN1_INTEGER), "c2i_ASN1_INTEGER"}, {ERR_FUNC(ASN1_F_C2I_ASN1_INTEGER), "c2i_ASN1_INTEGER"},
{ERR_FUNC(ASN1_F_C2I_ASN1_OBJECT), "c2i_ASN1_OBJECT"}, {ERR_FUNC(ASN1_F_C2I_ASN1_OBJECT), "c2i_ASN1_OBJECT"},
{ERR_FUNC(ASN1_F_COLLECT_DATA), "COLLECT_DATA"}, {ERR_FUNC(ASN1_F_C2I_IBUF), "c2i_ibuf"},
{ERR_FUNC(ASN1_F_D2I_ASN1_BIT_STRING), "D2I_ASN1_BIT_STRING"}, {ERR_FUNC(ASN1_F_COLLECT_DATA), "collect_data"},
{ERR_FUNC(ASN1_F_D2I_ASN1_BOOLEAN), "d2i_ASN1_BOOLEAN"},
{ERR_FUNC(ASN1_F_D2I_ASN1_BYTES), "d2i_ASN1_bytes"},
{ERR_FUNC(ASN1_F_D2I_ASN1_GENERALIZEDTIME), "D2I_ASN1_GENERALIZEDTIME"},
{ERR_FUNC(ASN1_F_D2I_ASN1_HEADER), "D2I_ASN1_HEADER"},
{ERR_FUNC(ASN1_F_D2I_ASN1_INTEGER), "D2I_ASN1_INTEGER"},
{ERR_FUNC(ASN1_F_D2I_ASN1_OBJECT), "d2i_ASN1_OBJECT"}, {ERR_FUNC(ASN1_F_D2I_ASN1_OBJECT), "d2i_ASN1_OBJECT"},
{ERR_FUNC(ASN1_F_D2I_ASN1_SET), "d2i_ASN1_SET"},
{ERR_FUNC(ASN1_F_D2I_ASN1_TYPE_BYTES), "d2i_ASN1_type_bytes"},
{ERR_FUNC(ASN1_F_D2I_ASN1_UINTEGER), "d2i_ASN1_UINTEGER"}, {ERR_FUNC(ASN1_F_D2I_ASN1_UINTEGER), "d2i_ASN1_UINTEGER"},
{ERR_FUNC(ASN1_F_D2I_ASN1_UTCTIME), "D2I_ASN1_UTCTIME"},
{ERR_FUNC(ASN1_F_D2I_AUTOPRIVATEKEY), "d2i_AutoPrivateKey"}, {ERR_FUNC(ASN1_F_D2I_AUTOPRIVATEKEY), "d2i_AutoPrivateKey"},
{ERR_FUNC(ASN1_F_D2I_NETSCAPE_RSA), "d2i_Netscape_RSA"},
{ERR_FUNC(ASN1_F_D2I_NETSCAPE_RSA_2), "D2I_NETSCAPE_RSA_2"},
{ERR_FUNC(ASN1_F_D2I_PRIVATEKEY), "d2i_PrivateKey"}, {ERR_FUNC(ASN1_F_D2I_PRIVATEKEY), "d2i_PrivateKey"},
{ERR_FUNC(ASN1_F_D2I_PUBLICKEY), "d2i_PublicKey"}, {ERR_FUNC(ASN1_F_D2I_PUBLICKEY), "d2i_PublicKey"},
{ERR_FUNC(ASN1_F_D2I_RSA_NET), "d2i_RSA_NET"}, {ERR_FUNC(ASN1_F_DO_TCREATE), "do_tcreate"},
{ERR_FUNC(ASN1_F_D2I_RSA_NET_2), "D2I_RSA_NET_2"},
{ERR_FUNC(ASN1_F_D2I_X509), "D2I_X509"},
{ERR_FUNC(ASN1_F_D2I_X509_CINF), "D2I_X509_CINF"},
{ERR_FUNC(ASN1_F_D2I_X509_PKEY), "d2i_X509_PKEY"},
{ERR_FUNC(ASN1_F_I2D_ASN1_BIO_STREAM), "i2d_ASN1_bio_stream"}, {ERR_FUNC(ASN1_F_I2D_ASN1_BIO_STREAM), "i2d_ASN1_bio_stream"},
{ERR_FUNC(ASN1_F_I2D_ASN1_SET), "i2d_ASN1_SET"},
{ERR_FUNC(ASN1_F_I2D_ASN1_TIME), "I2D_ASN1_TIME"},
{ERR_FUNC(ASN1_F_I2D_DSA_PUBKEY), "i2d_DSA_PUBKEY"}, {ERR_FUNC(ASN1_F_I2D_DSA_PUBKEY), "i2d_DSA_PUBKEY"},
{ERR_FUNC(ASN1_F_I2D_EC_PUBKEY), "i2d_EC_PUBKEY"}, {ERR_FUNC(ASN1_F_I2D_EC_PUBKEY), "i2d_EC_PUBKEY"},
{ERR_FUNC(ASN1_F_I2D_PRIVATEKEY), "i2d_PrivateKey"}, {ERR_FUNC(ASN1_F_I2D_PRIVATEKEY), "i2d_PrivateKey"},
{ERR_FUNC(ASN1_F_I2D_PUBLICKEY), "i2d_PublicKey"}, {ERR_FUNC(ASN1_F_I2D_PUBLICKEY), "i2d_PublicKey"},
{ERR_FUNC(ASN1_F_I2D_RSA_NET), "i2d_RSA_NET"},
{ERR_FUNC(ASN1_F_I2D_RSA_PUBKEY), "i2d_RSA_PUBKEY"}, {ERR_FUNC(ASN1_F_I2D_RSA_PUBKEY), "i2d_RSA_PUBKEY"},
{ERR_FUNC(ASN1_F_LONG_C2I), "LONG_C2I"}, {ERR_FUNC(ASN1_F_LONG_C2I), "long_c2i"},
{ERR_FUNC(ASN1_F_OID_MODULE_INIT), "OID_MODULE_INIT"}, {ERR_FUNC(ASN1_F_OID_MODULE_INIT), "oid_module_init"},
{ERR_FUNC(ASN1_F_PARSE_TAGGING), "PARSE_TAGGING"}, {ERR_FUNC(ASN1_F_PARSE_TAGGING), "parse_tagging"},
{ERR_FUNC(ASN1_F_PKCS5_PBE2_SET_IV), "PKCS5_pbe2_set_iv"}, {ERR_FUNC(ASN1_F_PKCS5_PBE2_SET_IV), "PKCS5_pbe2_set_iv"},
{ERR_FUNC(ASN1_F_PKCS5_PBE2_SET_SCRYPT), "PKCS5_pbe2_set_scrypt"},
{ERR_FUNC(ASN1_F_PKCS5_PBE_SET), "PKCS5_pbe_set"}, {ERR_FUNC(ASN1_F_PKCS5_PBE_SET), "PKCS5_pbe_set"},
{ERR_FUNC(ASN1_F_PKCS5_PBE_SET0_ALGOR), "PKCS5_pbe_set0_algor"}, {ERR_FUNC(ASN1_F_PKCS5_PBE_SET0_ALGOR), "PKCS5_pbe_set0_algor"},
{ERR_FUNC(ASN1_F_PKCS5_PBKDF2_SET), "PKCS5_pbkdf2_set"}, {ERR_FUNC(ASN1_F_PKCS5_PBKDF2_SET), "PKCS5_pbkdf2_set"},
{ERR_FUNC(ASN1_F_PKCS5_SCRYPT_SET), "pkcs5_scrypt_set"},
{ERR_FUNC(ASN1_F_SMIME_READ_ASN1), "SMIME_read_ASN1"}, {ERR_FUNC(ASN1_F_SMIME_READ_ASN1), "SMIME_read_ASN1"},
{ERR_FUNC(ASN1_F_SMIME_TEXT), "SMIME_text"}, {ERR_FUNC(ASN1_F_SMIME_TEXT), "SMIME_text"},
{ERR_FUNC(ASN1_F_X509_CINF_NEW), "X509_CINF_NEW"}, {ERR_FUNC(ASN1_F_STBL_MODULE_INIT), "stbl_module_init"},
{ERR_FUNC(ASN1_F_X509_CRL_ADD0_REVOKED), "X509_CRL_add0_revoked"}, {ERR_FUNC(ASN1_F_X509_CRL_ADD0_REVOKED), "X509_CRL_add0_revoked"},
{ERR_FUNC(ASN1_F_X509_INFO_NEW), "X509_INFO_new"}, {ERR_FUNC(ASN1_F_X509_INFO_NEW), "X509_INFO_new"},
{ERR_FUNC(ASN1_F_X509_NAME_ENCODE), "X509_NAME_ENCODE"}, {ERR_FUNC(ASN1_F_X509_NAME_ENCODE), "x509_name_encode"},
{ERR_FUNC(ASN1_F_X509_NAME_EX_D2I), "X509_NAME_EX_D2I"}, {ERR_FUNC(ASN1_F_X509_NAME_EX_D2I), "x509_name_ex_d2i"},
{ERR_FUNC(ASN1_F_X509_NAME_EX_NEW), "X509_NAME_EX_NEW"}, {ERR_FUNC(ASN1_F_X509_NAME_EX_NEW), "x509_name_ex_new"},
{ERR_FUNC(ASN1_F_X509_NEW), "X509_NEW"},
{ERR_FUNC(ASN1_F_X509_PKEY_NEW), "X509_PKEY_new"}, {ERR_FUNC(ASN1_F_X509_PKEY_NEW), "X509_PKEY_new"},
{0, NULL} {0, NULL}
}; };
@ -200,10 +124,7 @@ static ERR_STRING_DATA ASN1_str_reasons[] = {
{ERR_REASON(ASN1_R_ASN1_PARSE_ERROR), "asn1 parse error"}, {ERR_REASON(ASN1_R_ASN1_PARSE_ERROR), "asn1 parse error"},
{ERR_REASON(ASN1_R_ASN1_SIG_PARSE_ERROR), "asn1 sig parse error"}, {ERR_REASON(ASN1_R_ASN1_SIG_PARSE_ERROR), "asn1 sig parse error"},
{ERR_REASON(ASN1_R_AUX_ERROR), "aux error"}, {ERR_REASON(ASN1_R_AUX_ERROR), "aux error"},
{ERR_REASON(ASN1_R_BAD_CLASS), "bad class"},
{ERR_REASON(ASN1_R_BAD_OBJECT_HEADER), "bad object header"}, {ERR_REASON(ASN1_R_BAD_OBJECT_HEADER), "bad object header"},
{ERR_REASON(ASN1_R_BAD_PASSWORD_READ), "bad password read"},
{ERR_REASON(ASN1_R_BAD_TAG), "bad tag"},
{ERR_REASON(ASN1_R_BMPSTRING_IS_WRONG_LENGTH), {ERR_REASON(ASN1_R_BMPSTRING_IS_WRONG_LENGTH),
"bmpstring is wrong length"}, "bmpstring is wrong length"},
{ERR_REASON(ASN1_R_BN_LIB), "bn lib"}, {ERR_REASON(ASN1_R_BN_LIB), "bn lib"},
@ -214,21 +135,16 @@ static ERR_STRING_DATA ASN1_str_reasons[] = {
{ERR_REASON(ASN1_R_CONTEXT_NOT_INITIALISED), "context not initialised"}, {ERR_REASON(ASN1_R_CONTEXT_NOT_INITIALISED), "context not initialised"},
{ERR_REASON(ASN1_R_DATA_IS_WRONG), "data is wrong"}, {ERR_REASON(ASN1_R_DATA_IS_WRONG), "data is wrong"},
{ERR_REASON(ASN1_R_DECODE_ERROR), "decode error"}, {ERR_REASON(ASN1_R_DECODE_ERROR), "decode error"},
{ERR_REASON(ASN1_R_DECODING_ERROR), "decoding error"},
{ERR_REASON(ASN1_R_DEPTH_EXCEEDED), "depth exceeded"}, {ERR_REASON(ASN1_R_DEPTH_EXCEEDED), "depth exceeded"},
{ERR_REASON(ASN1_R_DIGEST_AND_KEY_TYPE_NOT_SUPPORTED), {ERR_REASON(ASN1_R_DIGEST_AND_KEY_TYPE_NOT_SUPPORTED),
"digest and key type not supported"}, "digest and key type not supported"},
{ERR_REASON(ASN1_R_ENCODE_ERROR), "encode error"}, {ERR_REASON(ASN1_R_ENCODE_ERROR), "encode error"},
{ERR_REASON(ASN1_R_ERROR_GETTING_TIME), "error getting time"}, {ERR_REASON(ASN1_R_ERROR_GETTING_TIME), "error getting time"},
{ERR_REASON(ASN1_R_ERROR_LOADING_SECTION), "error loading section"}, {ERR_REASON(ASN1_R_ERROR_LOADING_SECTION), "error loading section"},
{ERR_REASON(ASN1_R_ERROR_PARSING_SET_ELEMENT),
"error parsing set element"},
{ERR_REASON(ASN1_R_ERROR_SETTING_CIPHER_PARAMS), {ERR_REASON(ASN1_R_ERROR_SETTING_CIPHER_PARAMS),
"error setting cipher params"}, "error setting cipher params"},
{ERR_REASON(ASN1_R_EXPECTING_AN_INTEGER), "expecting an integer"}, {ERR_REASON(ASN1_R_EXPECTING_AN_INTEGER), "expecting an integer"},
{ERR_REASON(ASN1_R_EXPECTING_AN_OBJECT), "expecting an object"}, {ERR_REASON(ASN1_R_EXPECTING_AN_OBJECT), "expecting an object"},
{ERR_REASON(ASN1_R_EXPECTING_A_BOOLEAN), "expecting a boolean"},
{ERR_REASON(ASN1_R_EXPECTING_A_TIME), "expecting a time"},
{ERR_REASON(ASN1_R_EXPLICIT_LENGTH_MISMATCH), "explicit length mismatch"}, {ERR_REASON(ASN1_R_EXPLICIT_LENGTH_MISMATCH), "explicit length mismatch"},
{ERR_REASON(ASN1_R_EXPLICIT_TAG_NOT_CONSTRUCTED), {ERR_REASON(ASN1_R_EXPLICIT_TAG_NOT_CONSTRUCTED),
"explicit tag not constructed"}, "explicit tag not constructed"},
@ -242,6 +158,7 @@ static ERR_STRING_DATA ASN1_str_reasons[] = {
{ERR_REASON(ASN1_R_ILLEGAL_HEX), "illegal hex"}, {ERR_REASON(ASN1_R_ILLEGAL_HEX), "illegal hex"},
{ERR_REASON(ASN1_R_ILLEGAL_IMPLICIT_TAG), "illegal implicit tag"}, {ERR_REASON(ASN1_R_ILLEGAL_IMPLICIT_TAG), "illegal implicit tag"},
{ERR_REASON(ASN1_R_ILLEGAL_INTEGER), "illegal integer"}, {ERR_REASON(ASN1_R_ILLEGAL_INTEGER), "illegal integer"},
{ERR_REASON(ASN1_R_ILLEGAL_NEGATIVE_VALUE), "illegal negative value"},
{ERR_REASON(ASN1_R_ILLEGAL_NESTED_TAGGING), "illegal nested tagging"}, {ERR_REASON(ASN1_R_ILLEGAL_NESTED_TAGGING), "illegal nested tagging"},
{ERR_REASON(ASN1_R_ILLEGAL_NULL), "illegal null"}, {ERR_REASON(ASN1_R_ILLEGAL_NULL), "illegal null"},
{ERR_REASON(ASN1_R_ILLEGAL_NULL_VALUE), "illegal null value"}, {ERR_REASON(ASN1_R_ILLEGAL_NULL_VALUE), "illegal null value"},
@ -249,8 +166,10 @@ static ERR_STRING_DATA ASN1_str_reasons[] = {
{ERR_REASON(ASN1_R_ILLEGAL_OPTIONAL_ANY), "illegal optional any"}, {ERR_REASON(ASN1_R_ILLEGAL_OPTIONAL_ANY), "illegal optional any"},
{ERR_REASON(ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE), {ERR_REASON(ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE),
"illegal options on item template"}, "illegal options on item template"},
{ERR_REASON(ASN1_R_ILLEGAL_PADDING), "illegal padding"},
{ERR_REASON(ASN1_R_ILLEGAL_TAGGED_ANY), "illegal tagged any"}, {ERR_REASON(ASN1_R_ILLEGAL_TAGGED_ANY), "illegal tagged any"},
{ERR_REASON(ASN1_R_ILLEGAL_TIME_VALUE), "illegal time value"}, {ERR_REASON(ASN1_R_ILLEGAL_TIME_VALUE), "illegal time value"},
{ERR_REASON(ASN1_R_ILLEGAL_ZERO_CONTENT), "illegal zero content"},
{ERR_REASON(ASN1_R_INTEGER_NOT_ASCII_FORMAT), "integer not ascii format"}, {ERR_REASON(ASN1_R_INTEGER_NOT_ASCII_FORMAT), "integer not ascii format"},
{ERR_REASON(ASN1_R_INTEGER_TOO_LARGE_FOR_LONG), {ERR_REASON(ASN1_R_INTEGER_TOO_LARGE_FOR_LONG),
"integer too large for long"}, "integer too large for long"},
@ -262,13 +181,15 @@ static ERR_STRING_DATA ASN1_str_reasons[] = {
{ERR_REASON(ASN1_R_INVALID_MODIFIER), "invalid modifier"}, {ERR_REASON(ASN1_R_INVALID_MODIFIER), "invalid modifier"},
{ERR_REASON(ASN1_R_INVALID_NUMBER), "invalid number"}, {ERR_REASON(ASN1_R_INVALID_NUMBER), "invalid number"},
{ERR_REASON(ASN1_R_INVALID_OBJECT_ENCODING), "invalid object encoding"}, {ERR_REASON(ASN1_R_INVALID_OBJECT_ENCODING), "invalid object encoding"},
{ERR_REASON(ASN1_R_INVALID_SCRYPT_PARAMETERS),
"invalid scrypt parameters"},
{ERR_REASON(ASN1_R_INVALID_SEPARATOR), "invalid separator"}, {ERR_REASON(ASN1_R_INVALID_SEPARATOR), "invalid separator"},
{ERR_REASON(ASN1_R_INVALID_TIME_FORMAT), "invalid time format"}, {ERR_REASON(ASN1_R_INVALID_STRING_TABLE_VALUE),
"invalid string table value"},
{ERR_REASON(ASN1_R_INVALID_UNIVERSALSTRING_LENGTH), {ERR_REASON(ASN1_R_INVALID_UNIVERSALSTRING_LENGTH),
"invalid universalstring length"}, "invalid universalstring length"},
{ERR_REASON(ASN1_R_INVALID_UTF8STRING), "invalid utf8string"}, {ERR_REASON(ASN1_R_INVALID_UTF8STRING), "invalid utf8string"},
{ERR_REASON(ASN1_R_IV_TOO_LARGE), "iv too large"}, {ERR_REASON(ASN1_R_INVALID_VALUE), "invalid value"},
{ERR_REASON(ASN1_R_LENGTH_ERROR), "length error"},
{ERR_REASON(ASN1_R_LIST_ERROR), "list error"}, {ERR_REASON(ASN1_R_LIST_ERROR), "list error"},
{ERR_REASON(ASN1_R_MIME_NO_CONTENT_TYPE), "mime no content type"}, {ERR_REASON(ASN1_R_MIME_NO_CONTENT_TYPE), "mime no content type"},
{ERR_REASON(ASN1_R_MIME_PARSE_ERROR), "mime parse error"}, {ERR_REASON(ASN1_R_MIME_PARSE_ERROR), "mime parse error"},
@ -283,7 +204,6 @@ static ERR_STRING_DATA ASN1_str_reasons[] = {
{ERR_REASON(ASN1_R_NOT_ASCII_FORMAT), "not ascii format"}, {ERR_REASON(ASN1_R_NOT_ASCII_FORMAT), "not ascii format"},
{ERR_REASON(ASN1_R_NOT_ENOUGH_DATA), "not enough data"}, {ERR_REASON(ASN1_R_NOT_ENOUGH_DATA), "not enough data"},
{ERR_REASON(ASN1_R_NO_CONTENT_TYPE), "no content type"}, {ERR_REASON(ASN1_R_NO_CONTENT_TYPE), "no content type"},
{ERR_REASON(ASN1_R_NO_DEFAULT_DIGEST), "no default digest"},
{ERR_REASON(ASN1_R_NO_MATCHING_CHOICE_TYPE), "no matching choice type"}, {ERR_REASON(ASN1_R_NO_MATCHING_CHOICE_TYPE), "no matching choice type"},
{ERR_REASON(ASN1_R_NO_MULTIPART_BODY_FAILURE), {ERR_REASON(ASN1_R_NO_MULTIPART_BODY_FAILURE),
"no multipart body failure"}, "no multipart body failure"},
@ -292,8 +212,6 @@ static ERR_STRING_DATA ASN1_str_reasons[] = {
{ERR_REASON(ASN1_R_NULL_IS_WRONG_LENGTH), "null is wrong length"}, {ERR_REASON(ASN1_R_NULL_IS_WRONG_LENGTH), "null is wrong length"},
{ERR_REASON(ASN1_R_OBJECT_NOT_ASCII_FORMAT), "object not ascii format"}, {ERR_REASON(ASN1_R_OBJECT_NOT_ASCII_FORMAT), "object not ascii format"},
{ERR_REASON(ASN1_R_ODD_NUMBER_OF_CHARS), "odd number of chars"}, {ERR_REASON(ASN1_R_ODD_NUMBER_OF_CHARS), "odd number of chars"},
{ERR_REASON(ASN1_R_PRIVATE_KEY_HEADER_MISSING),
"private key header missing"},
{ERR_REASON(ASN1_R_SECOND_NUMBER_TOO_LARGE), "second number too large"}, {ERR_REASON(ASN1_R_SECOND_NUMBER_TOO_LARGE), "second number too large"},
{ERR_REASON(ASN1_R_SEQUENCE_LENGTH_MISMATCH), "sequence length mismatch"}, {ERR_REASON(ASN1_R_SEQUENCE_LENGTH_MISMATCH), "sequence length mismatch"},
{ERR_REASON(ASN1_R_SEQUENCE_NOT_CONSTRUCTED), "sequence not constructed"}, {ERR_REASON(ASN1_R_SEQUENCE_NOT_CONSTRUCTED), "sequence not constructed"},
@ -304,16 +222,14 @@ static ERR_STRING_DATA ASN1_str_reasons[] = {
{ERR_REASON(ASN1_R_STREAMING_NOT_SUPPORTED), "streaming not supported"}, {ERR_REASON(ASN1_R_STREAMING_NOT_SUPPORTED), "streaming not supported"},
{ERR_REASON(ASN1_R_STRING_TOO_LONG), "string too long"}, {ERR_REASON(ASN1_R_STRING_TOO_LONG), "string too long"},
{ERR_REASON(ASN1_R_STRING_TOO_SHORT), "string too short"}, {ERR_REASON(ASN1_R_STRING_TOO_SHORT), "string too short"},
{ERR_REASON(ASN1_R_TAG_VALUE_TOO_HIGH), "tag value too high"},
{ERR_REASON(ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD), {ERR_REASON(ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD),
"the asn1 object identifier is not known for this md"}, "the asn1 object identifier is not known for this md"},
{ERR_REASON(ASN1_R_TIME_NOT_ASCII_FORMAT), "time not ascii format"}, {ERR_REASON(ASN1_R_TIME_NOT_ASCII_FORMAT), "time not ascii format"},
{ERR_REASON(ASN1_R_TOO_LARGE), "too large"},
{ERR_REASON(ASN1_R_TOO_LONG), "too long"}, {ERR_REASON(ASN1_R_TOO_LONG), "too long"},
{ERR_REASON(ASN1_R_TOO_SMALL), "too small"},
{ERR_REASON(ASN1_R_TYPE_NOT_CONSTRUCTED), "type not constructed"}, {ERR_REASON(ASN1_R_TYPE_NOT_CONSTRUCTED), "type not constructed"},
{ERR_REASON(ASN1_R_TYPE_NOT_PRIMITIVE), "type not primitive"}, {ERR_REASON(ASN1_R_TYPE_NOT_PRIMITIVE), "type not primitive"},
{ERR_REASON(ASN1_R_UNABLE_TO_DECODE_RSA_KEY), "unable to decode rsa key"},
{ERR_REASON(ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY),
"unable to decode rsa private key"},
{ERR_REASON(ASN1_R_UNEXPECTED_EOC), "unexpected eoc"}, {ERR_REASON(ASN1_R_UNEXPECTED_EOC), "unexpected eoc"},
{ERR_REASON(ASN1_R_UNIVERSALSTRING_IS_WRONG_LENGTH), {ERR_REASON(ASN1_R_UNIVERSALSTRING_IS_WRONG_LENGTH),
"universalstring is wrong length"}, "universalstring is wrong length"},
@ -325,24 +241,20 @@ static ERR_STRING_DATA ASN1_str_reasons[] = {
{ERR_REASON(ASN1_R_UNKNOWN_SIGNATURE_ALGORITHM), {ERR_REASON(ASN1_R_UNKNOWN_SIGNATURE_ALGORITHM),
"unknown signature algorithm"}, "unknown signature algorithm"},
{ERR_REASON(ASN1_R_UNKNOWN_TAG), "unknown tag"}, {ERR_REASON(ASN1_R_UNKNOWN_TAG), "unknown tag"},
{ERR_REASON(ASN1_R_UNKOWN_FORMAT), "unknown format"},
{ERR_REASON(ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE), {ERR_REASON(ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE),
"unsupported any defined by type"}, "unsupported any defined by type"},
{ERR_REASON(ASN1_R_UNSUPPORTED_CIPHER), "unsupported cipher"},
{ERR_REASON(ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM),
"unsupported encryption algorithm"},
{ERR_REASON(ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE), {ERR_REASON(ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE),
"unsupported public key type"}, "unsupported public key type"},
{ERR_REASON(ASN1_R_UNSUPPORTED_TYPE), "unsupported type"}, {ERR_REASON(ASN1_R_UNSUPPORTED_TYPE), "unsupported type"},
{ERR_REASON(ASN1_R_WRONG_INTEGER_TYPE), "wrong integer type"},
{ERR_REASON(ASN1_R_WRONG_PUBLIC_KEY_TYPE), "wrong public key type"}, {ERR_REASON(ASN1_R_WRONG_PUBLIC_KEY_TYPE), "wrong public key type"},
{ERR_REASON(ASN1_R_WRONG_TAG), "wrong tag"}, {ERR_REASON(ASN1_R_WRONG_TAG), "wrong tag"},
{ERR_REASON(ASN1_R_WRONG_TYPE), "wrong type"},
{0, NULL} {0, NULL}
}; };
#endif #endif
void ERR_load_ASN1_strings(void) int ERR_load_ASN1_strings(void)
{ {
#ifndef OPENSSL_NO_ERR #ifndef OPENSSL_NO_ERR
@ -351,4 +263,5 @@ void ERR_load_ASN1_strings(void)
ERR_load_strings(0, ASN1_str_reasons); ERR_load_strings(0, ASN1_str_reasons);
} }
#endif #endif
return 1;
} }

View File

@ -1,63 +1,13 @@
/* asn1_gen.c */
/* /*
* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project * Copyright 2002-2016 The OpenSSL Project Authors. All Rights Reserved.
* 2002.
*/
/* ====================================================================
* Copyright (c) 2002 The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
*
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* licensing@OpenSSL.org.
*
* 5. Products derived from this software may not be called "OpenSSL"
* nor may "OpenSSL" appear in their names without prior written
* permission of the OpenSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*
* This product includes cryptographic software written by Eric Young
* (eay@cryptsoft.com). This product includes software written by Tim
* Hudson (tjh@cryptsoft.com).
* *
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/ */
#include "cryptlib.h" #include "internal/cryptlib.h"
#include <openssl/asn1.h> #include <openssl/asn1.h>
#include <openssl/x509v3.h> #include <openssl/x509v3.h>
@ -112,7 +62,7 @@ typedef struct {
int exp_count; int exp_count;
} tag_exp_arg; } tag_exp_arg;
static ASN1_TYPE *generate_v3(char *str, X509V3_CTX *cnf, int depth, static ASN1_TYPE *generate_v3(const char *str, X509V3_CTX *cnf, int depth,
int *perr); int *perr);
static int bitstr_cb(const char *elem, int len, void *bitstr); static int bitstr_cb(const char *elem, int len, void *bitstr);
static int asn1_cb(const char *elem, int len, void *bitstr); static int asn1_cb(const char *elem, int len, void *bitstr);
@ -125,7 +75,7 @@ static ASN1_TYPE *asn1_multi(int utype, const char *section, X509V3_CTX *cnf,
static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype); static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype);
static int asn1_str2tag(const char *tagstr, int len); static int asn1_str2tag(const char *tagstr, int len);
ASN1_TYPE *ASN1_generate_nconf(char *str, CONF *nconf) ASN1_TYPE *ASN1_generate_nconf(const char *str, CONF *nconf)
{ {
X509V3_CTX cnf; X509V3_CTX cnf;
@ -136,7 +86,7 @@ ASN1_TYPE *ASN1_generate_nconf(char *str, CONF *nconf)
return ASN1_generate_v3(str, &cnf); return ASN1_generate_v3(str, &cnf);
} }
ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf) ASN1_TYPE *ASN1_generate_v3(const char *str, X509V3_CTX *cnf)
{ {
int err = 0; int err = 0;
ASN1_TYPE *ret = generate_v3(str, cnf, 0, &err); ASN1_TYPE *ret = generate_v3(str, cnf, 0, &err);
@ -145,7 +95,7 @@ ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf)
return ret; return ret;
} }
static ASN1_TYPE *generate_v3(char *str, X509V3_CTX *cnf, int depth, static ASN1_TYPE *generate_v3(const char *str, X509V3_CTX *cnf, int depth,
int *perr) int *perr)
{ {
ASN1_TYPE *ret; ASN1_TYPE *ret;
@ -159,7 +109,7 @@ static ASN1_TYPE *generate_v3(char *str, X509V3_CTX *cnf, int depth,
unsigned char *p; unsigned char *p;
const unsigned char *cp; const unsigned char *cp;
int cpy_len; int cpy_len;
long hdr_len; long hdr_len = 0;
int hdr_constructed = 0, hdr_tag, hdr_class; int hdr_constructed = 0, hdr_tag, hdr_class;
int r; int r;
@ -243,7 +193,7 @@ static ASN1_TYPE *generate_v3(char *str, X509V3_CTX *cnf, int depth,
/* Allocate buffer for new encoding */ /* Allocate buffer for new encoding */
new_der = OPENSSL_malloc(len); new_der = OPENSSL_malloc(len);
if (!new_der) if (new_der == NULL)
goto err; goto err;
/* Generate tagged encoding */ /* Generate tagged encoding */
@ -280,9 +230,7 @@ static ASN1_TYPE *generate_v3(char *str, X509V3_CTX *cnf, int depth,
ret = d2i_ASN1_TYPE(NULL, &cp, len); ret = d2i_ASN1_TYPE(NULL, &cp, len);
err: err:
if (orig_der)
OPENSSL_free(orig_der); OPENSSL_free(orig_der);
if (new_der)
OPENSSL_free(new_der); OPENSSL_free(new_der);
return ret; return ret;
@ -377,16 +325,16 @@ static int asn1_cb(const char *elem, int len, void *bitstr)
ASN1err(ASN1_F_ASN1_CB, ASN1_R_UNKNOWN_FORMAT); ASN1err(ASN1_F_ASN1_CB, ASN1_R_UNKNOWN_FORMAT);
return -1; return -1;
} }
if (!strncmp(vstart, "ASCII", 5)) if (strncmp(vstart, "ASCII", 5) == 0)
arg->format = ASN1_GEN_FORMAT_ASCII; arg->format = ASN1_GEN_FORMAT_ASCII;
else if (!strncmp(vstart, "UTF8", 4)) else if (strncmp(vstart, "UTF8", 4) == 0)
arg->format = ASN1_GEN_FORMAT_UTF8; arg->format = ASN1_GEN_FORMAT_UTF8;
else if (!strncmp(vstart, "HEX", 3)) else if (strncmp(vstart, "HEX", 3) == 0)
arg->format = ASN1_GEN_FORMAT_HEX; arg->format = ASN1_GEN_FORMAT_HEX;
else if (!strncmp(vstart, "BITLIST", 7)) else if (strncmp(vstart, "BITLIST", 7) == 0)
arg->format = ASN1_GEN_FORMAT_BITLIST; arg->format = ASN1_GEN_FORMAT_BITLIST;
else { else {
ASN1err(ASN1_F_ASN1_CB, ASN1_R_UNKOWN_FORMAT); ASN1err(ASN1_F_ASN1_CB, ASN1_R_UNKNOWN_FORMAT);
return -1; return -1;
} }
break; break;
@ -443,7 +391,6 @@ static int parse_tagging(const char *vstart, int vlen, int *ptag, int *pclass)
ASN1err(ASN1_F_PARSE_TAGGING, ASN1_R_INVALID_MODIFIER); ASN1err(ASN1_F_PARSE_TAGGING, ASN1_R_INVALID_MODIFIER);
ERR_add_error_data(2, "Char=", erch); ERR_add_error_data(2, "Char=", erch);
return 0; return 0;
break;
} }
} else } else
@ -495,15 +442,12 @@ static ASN1_TYPE *asn1_multi(int utype, const char *section, X509V3_CTX *cnf,
if (derlen < 0) if (derlen < 0)
goto bad; goto bad;
if ((ret = ASN1_TYPE_new()) == NULL)
if (!(ret = ASN1_TYPE_new()))
goto bad; goto bad;
if ((ret->value.asn1_string = ASN1_STRING_type_new(utype)) == NULL)
if (!(ret->value.asn1_string = ASN1_STRING_type_new(utype)))
goto bad; goto bad;
ret->type = utype; ret->type = utype;
ret->value.asn1_string->data = der; ret->value.asn1_string->data = der;
ret->value.asn1_string->length = derlen; ret->value.asn1_string->length = derlen;
@ -511,12 +455,9 @@ static ASN1_TYPE *asn1_multi(int utype, const char *section, X509V3_CTX *cnf,
bad: bad:
if (der)
OPENSSL_free(der); OPENSSL_free(der);
if (sk)
sk_ASN1_TYPE_pop_free(sk, ASN1_TYPE_free); sk_ASN1_TYPE_pop_free(sk, ASN1_TYPE_free);
if (sect)
X509V3_section_free(cnf, sect); X509V3_section_free(cnf, sect);
return ret; return ret;
@ -626,8 +567,8 @@ static int asn1_str2tag(const char *tagstr, int len)
len = strlen(tagstr); len = strlen(tagstr);
tntmp = tnst; tntmp = tnst;
for (i = 0; i < sizeof(tnst) / sizeof(struct tag_name_st); i++, tntmp++) { for (i = 0; i < OSSL_NELEM(tnst); i++, tntmp++) {
if ((len == tntmp->len) && !strncmp(tntmp->strnam, tagstr, len)) if ((len == tntmp->len) && (strncmp(tntmp->strnam, tagstr, len) == 0))
return tntmp->tag; return tntmp->tag;
} }
@ -637,15 +578,12 @@ static int asn1_str2tag(const char *tagstr, int len)
static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype) static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype)
{ {
ASN1_TYPE *atmp = NULL; ASN1_TYPE *atmp = NULL;
CONF_VALUE vtmp; CONF_VALUE vtmp;
unsigned char *rdata; unsigned char *rdata;
long rdlen; long rdlen;
int no_unused = 1; int no_unused = 1;
if (!(atmp = ASN1_TYPE_new())) { if ((atmp = ASN1_TYPE_new()) == NULL) {
ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE); ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE);
return NULL; return NULL;
} }
@ -682,7 +620,8 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype)
ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_INTEGER_NOT_ASCII_FORMAT); ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_INTEGER_NOT_ASCII_FORMAT);
goto bad_form; goto bad_form;
} }
if (!(atmp->value.integer = s2i_ASN1_INTEGER(NULL, (char *)str))) { if ((atmp->value.integer
= s2i_ASN1_INTEGER(NULL, str)) == NULL) {
ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_INTEGER); ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_INTEGER);
goto bad_str; goto bad_str;
} }
@ -693,7 +632,7 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype)
ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_OBJECT_NOT_ASCII_FORMAT); ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_OBJECT_NOT_ASCII_FORMAT);
goto bad_form; goto bad_form;
} }
if (!(atmp->value.object = OBJ_txt2obj(str, 0))) { if ((atmp->value.object = OBJ_txt2obj(str, 0)) == NULL) {
ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_OBJECT); ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_OBJECT);
goto bad_str; goto bad_str;
} }
@ -705,7 +644,7 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype)
ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_TIME_NOT_ASCII_FORMAT); ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_TIME_NOT_ASCII_FORMAT);
goto bad_form; goto bad_form;
} }
if (!(atmp->value.asn1_string = ASN1_STRING_new())) { if ((atmp->value.asn1_string = ASN1_STRING_new()) == NULL) {
ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE); ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE);
goto bad_str; goto bad_str;
} }
@ -730,7 +669,6 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype)
case V_ASN1_UNIVERSALSTRING: case V_ASN1_UNIVERSALSTRING:
case V_ASN1_GENERALSTRING: case V_ASN1_GENERALSTRING:
case V_ASN1_NUMERICSTRING: case V_ASN1_NUMERICSTRING:
if (format == ASN1_GEN_FORMAT_ASCII) if (format == ASN1_GEN_FORMAT_ASCII)
format = MBSTRING_ASC; format = MBSTRING_ASC;
else if (format == ASN1_GEN_FORMAT_UTF8) else if (format == ASN1_GEN_FORMAT_UTF8)
@ -749,25 +687,20 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype)
break; break;
case V_ASN1_BIT_STRING: case V_ASN1_BIT_STRING:
case V_ASN1_OCTET_STRING: case V_ASN1_OCTET_STRING:
if ((atmp->value.asn1_string = ASN1_STRING_new()) == NULL) {
if (!(atmp->value.asn1_string = ASN1_STRING_new())) {
ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE); ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE);
goto bad_form; goto bad_form;
} }
if (format == ASN1_GEN_FORMAT_HEX) { if (format == ASN1_GEN_FORMAT_HEX) {
if ((rdata = OPENSSL_hexstr2buf(str, &rdlen)) == NULL) {
if (!(rdata = string_to_hex((char *)str, &rdlen))) {
ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_HEX); ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_HEX);
goto bad_str; goto bad_str;
} }
atmp->value.asn1_string->data = rdata; atmp->value.asn1_string->data = rdata;
atmp->value.asn1_string->length = rdlen; atmp->value.asn1_string->length = rdlen;
atmp->value.asn1_string->type = utype; atmp->value.asn1_string->type = utype;
} else if (format == ASN1_GEN_FORMAT_ASCII) } else if (format == ASN1_GEN_FORMAT_ASCII)
ASN1_STRING_set(atmp->value.asn1_string, str, -1); ASN1_STRING_set(atmp->value.asn1_string, str, -1);
else if ((format == ASN1_GEN_FORMAT_BITLIST) else if ((format == ASN1_GEN_FORMAT_BITLIST)
@ -795,7 +728,6 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype)
default: default:
ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_UNSUPPORTED_TYPE); ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_UNSUPPORTED_TYPE);
goto bad_str; goto bad_str;
break;
} }
atmp->type = utype; atmp->type = utype;
@ -829,3 +761,29 @@ static int bitstr_cb(const char *elem, int len, void *bitstr)
} }
return 1; return 1;
} }
static int mask_cb(const char *elem, int len, void *arg)
{
unsigned long *pmask = arg, tmpmask;
int tag;
if (elem == NULL)
return 0;
if ((len == 3) && (strncmp(elem, "DIR", 3) == 0)) {
*pmask |= B_ASN1_DIRECTORYSTRING;
return 1;
}
tag = asn1_str2tag(elem, len);
if (!tag || (tag & ASN1_GEN_FLAG))
return 0;
tmpmask = ASN1_tag2bit(tag);
if (!tmpmask)
return 0;
*pmask |= tmpmask;
return 1;
}
int ASN1_str2mask(const char *str, unsigned long *pmask)
{
*pmask = 0;
return CONF_parse_list(str, '|', 1, mask_cb, pmask);
}

View File

@ -1,71 +1,21 @@
/* crypto/asn1/asn1_lib.c */ /*
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
* All rights reserved.
* *
* This package is an SSL implementation written * Licensed under the OpenSSL license (the "License"). You may not use
* by Eric Young (eay@cryptsoft.com). * this file except in compliance with the License. You can obtain a copy
* The implementation was written so as to conform with Netscapes SSL. * in the file LICENSE in the source distribution or at
* * https://www.openssl.org/source/license.html
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* "This product includes cryptographic software written by
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/ */
#include <stdio.h> #include <stdio.h>
#include <limits.h> #include <limits.h>
#include "cryptlib.h" #include "internal/cryptlib.h"
#include <openssl/asn1.h> #include <openssl/asn1.h>
#include <openssl/asn1_mac.h> #include "asn1_locl.h"
static int asn1_get_length(const unsigned char **pp, int *inf, long *rl, static int asn1_get_length(const unsigned char **pp, int *inf, long *rl,
long max); long max);
static void asn1_put_length(unsigned char **pp, int length); static void asn1_put_length(unsigned char **pp, int length);
const char ASN1_version[] = "ASN.1" OPENSSL_VERSION_PTEXT;
static int _asn1_check_infinite_end(const unsigned char **p, long len) static int _asn1_check_infinite_end(const unsigned char **p, long len)
{ {
@ -137,12 +87,6 @@ int ASN1_get_object(const unsigned char **pp, long *plength, int *ptag,
if (inf && !(ret & V_ASN1_CONSTRUCTED)) if (inf && !(ret & V_ASN1_CONSTRUCTED))
goto err; goto err;
#if 0
fprintf(stderr, "p=%d + *plength=%ld > omax=%ld + *pp=%d (%d > %d)\n",
(int)p, *plength, omax, (int)*pp, (int)(p + *plength),
(int)(omax + *pp));
#endif
if (*plength > (omax - (p - *pp))) { if (*plength > (omax - (p - *pp))) {
ASN1err(ASN1_F_ASN1_GET_OBJECT, ASN1_R_TOO_LONG); ASN1err(ASN1_F_ASN1_GET_OBJECT, ASN1_R_TOO_LONG);
/* /*
@ -175,7 +119,14 @@ static int asn1_get_length(const unsigned char **pp, int *inf, long *rl,
*inf = 0; *inf = 0;
i = *p & 0x7f; i = *p & 0x7f;
if (*(p++) & 0x80) { if (*(p++) & 0x80) {
if (i > sizeof(ret) || max < (long)i) if (max < (long)i + 1)
return 0;
/* Skip leading zeroes */
while (i && *p == 0) {
p++;
i--;
}
if (i > sizeof(long))
return 0; return 0;
while (i-- > 0) { while (i-- > 0) {
ret <<= 8L; ret <<= 8L;
@ -282,57 +233,6 @@ int ASN1_object_size(int constructed, int length, int tag)
return ret + length; return ret + length;
} }
static int _asn1_Finish(ASN1_const_CTX *c)
{
if ((c->inf == (1 | V_ASN1_CONSTRUCTED)) && (!c->eos)) {
if (!ASN1_const_check_infinite_end(&c->p, c->slen)) {
c->error = ERR_R_MISSING_ASN1_EOS;
return (0);
}
}
if (((c->slen != 0) && !(c->inf & 1)) || ((c->slen < 0) && (c->inf & 1))) {
c->error = ERR_R_ASN1_LENGTH_MISMATCH;
return (0);
}
return (1);
}
int asn1_Finish(ASN1_CTX *c)
{
return _asn1_Finish((ASN1_const_CTX *)c);
}
int asn1_const_Finish(ASN1_const_CTX *c)
{
return _asn1_Finish(c);
}
int asn1_GetSequence(ASN1_const_CTX *c, long *length)
{
const unsigned char *q;
q = c->p;
c->inf = ASN1_get_object(&(c->p), &(c->slen), &(c->tag), &(c->xclass),
*length);
if (c->inf & 0x80) {
c->error = ERR_R_BAD_GET_ASN1_OBJECT_CALL;
return (0);
}
if (c->tag != V_ASN1_SEQUENCE) {
c->error = ERR_R_EXPECTING_AN_ASN1_SEQUENCE;
return (0);
}
(*length) -= (c->p - q);
if (c->max && (*length < 0)) {
c->error = ERR_R_ASN1_LENGTH_MISMATCH;
return (0);
}
if (c->inf == (1 | V_ASN1_CONSTRUCTED))
c->slen = *length;
c->eos = 0;
return (1);
}
int ASN1_STRING_copy(ASN1_STRING *dst, const ASN1_STRING *str) int ASN1_STRING_copy(ASN1_STRING *dst, const ASN1_STRING *str)
{ {
if (str == NULL) if (str == NULL)
@ -340,7 +240,9 @@ int ASN1_STRING_copy(ASN1_STRING *dst, const ASN1_STRING *str)
dst->type = str->type; dst->type = str->type;
if (!ASN1_STRING_set(dst, str->data, str->length)) if (!ASN1_STRING_set(dst, str->data, str->length))
return 0; return 0;
dst->flags = str->flags; /* Copy flags but preserve embed value */
dst->flags &= ASN1_STRING_FLAG_EMBED;
dst->flags |= str->flags & ~ASN1_STRING_FLAG_EMBED;
return 1; return 1;
} }
@ -350,7 +252,7 @@ ASN1_STRING *ASN1_STRING_dup(const ASN1_STRING *str)
if (!str) if (!str)
return NULL; return NULL;
ret = ASN1_STRING_new(); ret = ASN1_STRING_new();
if (!ret) if (ret == NULL)
return NULL; return NULL;
if (!ASN1_STRING_copy(ret, str)) { if (!ASN1_STRING_copy(ret, str)) {
ASN1_STRING_free(ret); ASN1_STRING_free(ret);
@ -372,11 +274,7 @@ int ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len)
} }
if ((str->length <= len) || (str->data == NULL)) { if ((str->length <= len) || (str->data == NULL)) {
c = str->data; c = str->data;
if (c == NULL)
str->data = OPENSSL_malloc(len + 1);
else
str->data = OPENSSL_realloc(c, len + 1); str->data = OPENSSL_realloc(c, len + 1);
if (str->data == NULL) { if (str->data == NULL) {
ASN1err(ASN1_F_ASN1_STRING_SET, ERR_R_MALLOC_FAILURE); ASN1err(ASN1_F_ASN1_STRING_SET, ERR_R_MALLOC_FAILURE);
str->data = c; str->data = c;
@ -394,7 +292,6 @@ int ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len)
void ASN1_STRING_set0(ASN1_STRING *str, void *data, int len) void ASN1_STRING_set0(ASN1_STRING *str, void *data, int len)
{ {
if (str->data)
OPENSSL_free(str->data); OPENSSL_free(str->data);
str->data = data; str->data = data;
str->length = len; str->length = len;
@ -409,30 +306,37 @@ ASN1_STRING *ASN1_STRING_type_new(int type)
{ {
ASN1_STRING *ret; ASN1_STRING *ret;
ret = (ASN1_STRING *)OPENSSL_malloc(sizeof(ASN1_STRING)); ret = OPENSSL_zalloc(sizeof(*ret));
if (ret == NULL) { if (ret == NULL) {
ASN1err(ASN1_F_ASN1_STRING_TYPE_NEW, ERR_R_MALLOC_FAILURE); ASN1err(ASN1_F_ASN1_STRING_TYPE_NEW, ERR_R_MALLOC_FAILURE);
return (NULL); return (NULL);
} }
ret->length = 0;
ret->type = type; ret->type = type;
ret->data = NULL;
ret->flags = 0;
return (ret); return (ret);
} }
void asn1_string_embed_free(ASN1_STRING *a, int embed)
{
if (a == NULL)
return;
if (!(a->flags & ASN1_STRING_FLAG_NDEF))
OPENSSL_free(a->data);
if (embed == 0)
OPENSSL_free(a);
}
void ASN1_STRING_free(ASN1_STRING *a) void ASN1_STRING_free(ASN1_STRING *a)
{ {
if (a == NULL) if (a == NULL)
return; return;
if (a->data && !(a->flags & ASN1_STRING_FLAG_NDEF)) asn1_string_embed_free(a, a->flags & ASN1_STRING_FLAG_EMBED);
OPENSSL_free(a->data);
OPENSSL_free(a);
} }
void ASN1_STRING_clear_free(ASN1_STRING *a) void ASN1_STRING_clear_free(ASN1_STRING *a)
{ {
if (a && a->data && !(a->flags & ASN1_STRING_FLAG_NDEF)) if (a == NULL)
return;
if (a->data && !(a->flags & ASN1_STRING_FLAG_NDEF))
OPENSSL_cleanse(a->data, a->length); OPENSSL_cleanse(a->data, a->length);
ASN1_STRING_free(a); ASN1_STRING_free(a);
} }
@ -452,32 +356,29 @@ int ASN1_STRING_cmp(const ASN1_STRING *a, const ASN1_STRING *b)
return (i); return (i);
} }
void asn1_add_error(const unsigned char *address, int offset)
{
char buf1[DECIMAL_SIZE(address) + 1], buf2[DECIMAL_SIZE(offset) + 1];
BIO_snprintf(buf1, sizeof buf1, "%lu", (unsigned long)address);
BIO_snprintf(buf2, sizeof buf2, "%d", offset);
ERR_add_error_data(4, "address=", buf1, " offset=", buf2);
}
int ASN1_STRING_length(const ASN1_STRING *x) int ASN1_STRING_length(const ASN1_STRING *x)
{ {
return M_ASN1_STRING_length(x); return x->length;
} }
void ASN1_STRING_length_set(ASN1_STRING *x, int len) void ASN1_STRING_length_set(ASN1_STRING *x, int len)
{ {
M_ASN1_STRING_length_set(x, len); x->length = len;
return;
} }
int ASN1_STRING_type(ASN1_STRING *x) int ASN1_STRING_type(const ASN1_STRING *x)
{ {
return M_ASN1_STRING_type(x); return x->type;
} }
const unsigned char *ASN1_STRING_get0_data(const ASN1_STRING *x)
{
return x->data;
}
# if OPENSSL_API_COMPAT < 0x10100000L
unsigned char *ASN1_STRING_data(ASN1_STRING *x) unsigned char *ASN1_STRING_data(ASN1_STRING *x)
{ {
return M_ASN1_STRING_data(x); return x->data;
} }
#endif

View File

@ -1,60 +1,10 @@
/* asn1t.h */
/* /*
* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project * Copyright 2005-2016 The OpenSSL Project Authors. All Rights Reserved.
* 2006.
*/
/* ====================================================================
* Copyright (c) 2006 The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
*
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* licensing@OpenSSL.org.
*
* 5. Products derived from this software may not be called "OpenSSL"
* nor may "OpenSSL" appear in their names without prior written
* permission of the OpenSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*
* This product includes cryptographic software written by Eric Young
* (eay@cryptsoft.com). This product includes software written by Tim
* Hudson (tjh@cryptsoft.com).
* *
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/ */
/* Internal ASN1 structures and functions: not for application use */ /* Internal ASN1 structures and functions: not for application use */
@ -62,74 +12,67 @@
int asn1_utctime_to_tm(struct tm *tm, const ASN1_UTCTIME *d); int asn1_utctime_to_tm(struct tm *tm, const ASN1_UTCTIME *d);
int asn1_generalizedtime_to_tm(struct tm *tm, const ASN1_GENERALIZEDTIME *d); int asn1_generalizedtime_to_tm(struct tm *tm, const ASN1_GENERALIZEDTIME *d);
/* ASN1 print context structure */ /* ASN1 scan context structure */
struct asn1_pctx_st { struct asn1_sctx_st {
/* The ASN1_ITEM associated with this field */
const ASN1_ITEM *it;
/* If ASN1_TEMPLATE associated with this field */
const ASN1_TEMPLATE *tt;
/* Various flags associated with field and context */
unsigned long flags; unsigned long flags;
unsigned long nm_flags; /* If SEQUENCE OF or SET OF, field index */
unsigned long cert_flags; int skidx;
unsigned long oid_flags; /* ASN1 depth of field */
unsigned long str_flags; int depth;
} /* ASN1_PCTX */ ; /* Structure and field name */
const char *sname, *fname;
/* If a primitive type the type of underlying field */
int prim_type;
/* The field value itself */
ASN1_VALUE **field;
/* Callback to pass information to */
int (*scan_cb) (ASN1_SCTX *ctx);
/* Context specific application data */
void *app_data;
} /* ASN1_SCTX */ ;
/* ASN1 public key method structure */ typedef struct mime_param_st MIME_PARAM;
DEFINE_STACK_OF(MIME_PARAM)
typedef struct mime_header_st MIME_HEADER;
DEFINE_STACK_OF(MIME_HEADER)
struct evp_pkey_asn1_method_st { /* Month values for printing out times */
int pkey_id; extern const char *_asn1_mon[12];
int pkey_base_id;
unsigned long pkey_flags;
char *pem_str;
char *info;
int (*pub_decode) (EVP_PKEY *pk, X509_PUBKEY *pub);
int (*pub_encode) (X509_PUBKEY *pub, const EVP_PKEY *pk);
int (*pub_cmp) (const EVP_PKEY *a, const EVP_PKEY *b);
int (*pub_print) (BIO *out, const EVP_PKEY *pkey, int indent,
ASN1_PCTX *pctx);
int (*priv_decode) (EVP_PKEY *pk, PKCS8_PRIV_KEY_INFO *p8inf);
int (*priv_encode) (PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pk);
int (*priv_print) (BIO *out, const EVP_PKEY *pkey, int indent,
ASN1_PCTX *pctx);
int (*pkey_size) (const EVP_PKEY *pk);
int (*pkey_bits) (const EVP_PKEY *pk);
int (*param_decode) (EVP_PKEY *pkey,
const unsigned char **pder, int derlen);
int (*param_encode) (const EVP_PKEY *pkey, unsigned char **pder);
int (*param_missing) (const EVP_PKEY *pk);
int (*param_copy) (EVP_PKEY *to, const EVP_PKEY *from);
int (*param_cmp) (const EVP_PKEY *a, const EVP_PKEY *b);
int (*param_print) (BIO *out, const EVP_PKEY *pkey, int indent,
ASN1_PCTX *pctx);
int (*sig_print) (BIO *out,
const X509_ALGOR *sigalg, const ASN1_STRING *sig,
int indent, ASN1_PCTX *pctx);
void (*pkey_free) (EVP_PKEY *pkey);
int (*pkey_ctrl) (EVP_PKEY *pkey, int op, long arg1, void *arg2);
/* Legacy functions for old PEM */
int (*old_priv_decode) (EVP_PKEY *pkey,
const unsigned char **pder, int derlen);
int (*old_priv_encode) (const EVP_PKEY *pkey, unsigned char **pder);
/* Custom ASN1 signature verification */
int (*item_verify) (EVP_MD_CTX *ctx, const ASN1_ITEM *it, void *asn,
X509_ALGOR *a, ASN1_BIT_STRING *sig, EVP_PKEY *pkey);
int (*item_sign) (EVP_MD_CTX *ctx, const ASN1_ITEM *it, void *asn,
X509_ALGOR *alg1, X509_ALGOR *alg2,
ASN1_BIT_STRING *sig);
} /* EVP_PKEY_ASN1_METHOD */ ;
/* void asn1_string_embed_free(ASN1_STRING *a, int embed);
* Method to handle CRL access. In general a CRL could be very large (several
* Mb) and can consume large amounts of resources if stored in memory by
* multiple processes. This method allows general CRL operations to be
* redirected to more efficient callbacks: for example a CRL entry database.
*/
#define X509_CRL_METHOD_DYNAMIC 1 int asn1_get_choice_selector(ASN1_VALUE **pval, const ASN1_ITEM *it);
int asn1_set_choice_selector(ASN1_VALUE **pval, int value,
const ASN1_ITEM *it);
struct x509_crl_method_st { ASN1_VALUE **asn1_get_field_ptr(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt);
int flags;
int (*crl_init) (X509_CRL *crl); const ASN1_TEMPLATE *asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt,
int (*crl_free) (X509_CRL *crl); int nullerr);
int (*crl_lookup) (X509_CRL *crl, X509_REVOKED **ret,
ASN1_INTEGER *ser, X509_NAME *issuer); int asn1_do_lock(ASN1_VALUE **pval, int op, const ASN1_ITEM *it);
int (*crl_verify) (X509_CRL *crl, EVP_PKEY *pk);
}; void asn1_enc_init(ASN1_VALUE **pval, const ASN1_ITEM *it);
void asn1_enc_free(ASN1_VALUE **pval, const ASN1_ITEM *it);
int asn1_enc_restore(int *len, unsigned char **out, ASN1_VALUE **pval,
const ASN1_ITEM *it);
int asn1_enc_save(ASN1_VALUE **pval, const unsigned char *in, int inlen,
const ASN1_ITEM *it);
void asn1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int embed);
void asn1_template_free(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt);
ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp,
long length);
int i2c_ASN1_BIT_STRING(ASN1_BIT_STRING *a, unsigned char **pp);
ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,
const unsigned char **pp, long length);
int i2c_ASN1_INTEGER(ASN1_INTEGER *a, unsigned char **pp);
ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **a, const unsigned char **pp,
long length);

View File

@ -1,63 +1,14 @@
/* crypto/asn1/asn1_par.c */ /*
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
* All rights reserved.
* *
* This package is an SSL implementation written * Licensed under the OpenSSL license (the "License"). You may not use
* by Eric Young (eay@cryptsoft.com). * this file except in compliance with the License. You can obtain a copy
* The implementation was written so as to conform with Netscapes SSL. * in the file LICENSE in the source distribution or at
* * https://www.openssl.org/source/license.html
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* "This product includes cryptographic software written by
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/ */
#include <stdio.h> #include <stdio.h>
#include "cryptlib.h" #include "internal/cryptlib.h"
#include <openssl/buffer.h> #include <openssl/buffer.h>
#include <openssl/objects.h> #include <openssl/objects.h>
#include <openssl/asn1.h> #include <openssl/asn1.h>
@ -125,28 +76,19 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length,
ASN1_OBJECT *o = NULL; ASN1_OBJECT *o = NULL;
ASN1_OCTET_STRING *os = NULL; ASN1_OCTET_STRING *os = NULL;
/* ASN1_BMPSTRING *bmp=NULL; */ /* ASN1_BMPSTRING *bmp=NULL; */
int dump_indent; int dump_indent, dump_cont = 0;
#if 0
dump_indent = indent;
#else
dump_indent = 6; /* Because we know BIO_dump_indent() */
#endif
if (depth > ASN1_PARSE_MAXDEPTH) { if (depth > ASN1_PARSE_MAXDEPTH) {
BIO_puts(bp, "BAD RECURSION DEPTH\n"); BIO_puts(bp, "BAD RECURSION DEPTH\n");
return 0; return 0;
} }
dump_indent = 6; /* Because we know BIO_dump_indent() */
p = *pp; p = *pp;
tot = p + length; tot = p + length;
op = p - 1; while (length > 0) {
while ((p < tot) && (op < p)) {
op = p; op = p;
j = ASN1_get_object(&p, &len, &tag, &xclass, length); j = ASN1_get_object(&p, &len, &tag, &xclass, length);
#ifdef LINT
j = j;
#endif
if (j & 0x80) { if (j & 0x80) {
if (BIO_write(bp, "Error in encoding\n", 18) <= 0) if (BIO_write(bp, "Error in encoding\n", 18) <= 0)
goto end; goto end;
@ -173,7 +115,7 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length,
if (!asn1_print_info(bp, tag, xclass, j, (indent) ? depth : 0)) if (!asn1_print_info(bp, tag, xclass, j, (indent) ? depth : 0))
goto end; goto end;
if (j & V_ASN1_CONSTRUCTED) { if (j & V_ASN1_CONSTRUCTED) {
const unsigned char *sp; const unsigned char *sp = p;
ep = p + len; ep = p + len;
if (BIO_write(bp, "\n", 1) <= 0) if (BIO_write(bp, "\n", 1) <= 0)
@ -184,7 +126,6 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length,
goto end; goto end;
} }
if ((j == 0x21) && (len == 0)) { if ((j == 0x21) && (len == 0)) {
sp = p;
for (;;) { for (;;) {
r = asn1_parse2(bp, &p, (long)(tot - p), r = asn1_parse2(bp, &p, (long)(tot - p),
offset + (p - *pp), depth + 1, offset + (p - *pp), depth + 1,
@ -203,7 +144,8 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length,
while (p < ep) { while (p < ep) {
sp = p; sp = p;
r = asn1_parse2(bp, &p, tmp, offset + (p - *pp), depth + 1, r = asn1_parse2(bp, &p, tmp,
offset + (p - *pp), depth + 1,
indent, dump); indent, dump);
if (r == 0) { if (r == 0) {
ret = 0; ret = 0;
@ -237,19 +179,18 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length,
goto end; goto end;
i2a_ASN1_OBJECT(bp, o); i2a_ASN1_OBJECT(bp, o);
} else { } else {
if (BIO_write(bp, ":BAD OBJECT", 11) <= 0) if (BIO_puts(bp, ":BAD OBJECT") <= 0)
goto end; goto end;
dump_cont = 1;
} }
} else if (tag == V_ASN1_BOOLEAN) { } else if (tag == V_ASN1_BOOLEAN) {
int ii; if (len != 1) {
if (BIO_puts(bp, ":BAD BOOLEAN") <= 0)
opp = op;
ii = d2i_ASN1_BOOLEAN(NULL, &opp, len + hl);
if (ii < 0) {
if (BIO_write(bp, "Bad boolean\n", 12) <= 0)
goto end; goto end;
dump_cont = 1;
} }
BIO_printf(bp, ":%d", ii); if (len > 0)
BIO_printf(bp, ":%u", p[0]);
} else if (tag == V_ASN1_BMPSTRING) { } else if (tag == V_ASN1_BMPSTRING) {
/* do the BMP thang */ /* do the BMP thang */
} else if (tag == V_ASN1_OCTET_STRING) { } else if (tag == V_ASN1_OCTET_STRING) {
@ -306,10 +247,8 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length,
nl = 1; nl = 1;
} }
} }
if (os != NULL) { ASN1_OCTET_STRING_free(os);
M_ASN1_OCTET_STRING_free(os);
os = NULL; os = NULL;
}
} else if (tag == V_ASN1_INTEGER) { } else if (tag == V_ASN1_INTEGER) {
ASN1_INTEGER *bs; ASN1_INTEGER *bs;
int i; int i;
@ -331,10 +270,11 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length,
goto end; goto end;
} }
} else { } else {
if (BIO_write(bp, "BAD INTEGER", 11) <= 0) if (BIO_puts(bp, ":BAD INTEGER") <= 0)
goto end; goto end;
dump_cont = 1;
} }
M_ASN1_INTEGER_free(bs); ASN1_INTEGER_free(bs);
} else if (tag == V_ASN1_ENUMERATED) { } else if (tag == V_ASN1_ENUMERATED) {
ASN1_ENUMERATED *bs; ASN1_ENUMERATED *bs;
int i; int i;
@ -356,10 +296,11 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length,
goto end; goto end;
} }
} else { } else {
if (BIO_write(bp, "BAD ENUMERATED", 14) <= 0) if (BIO_puts(bp, ":BAD ENUMERATED") <= 0)
goto end; goto end;
dump_cont = 1;
} }
M_ASN1_ENUMERATED_free(bs); ASN1_ENUMERATED_free(bs);
} else if (len > 0 && dump) { } else if (len > 0 && dump) {
if (!nl) { if (!nl) {
if (BIO_write(bp, "\n", 1) <= 0) if (BIO_write(bp, "\n", 1) <= 0)
@ -371,6 +312,18 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length,
goto end; goto end;
nl = 1; nl = 1;
} }
if (dump_cont) {
int i;
const unsigned char *tmp = op + hl;
if (BIO_puts(bp, ":[") <= 0)
goto end;
for (i = 0; i < len; i++) {
if (BIO_printf(bp, "%02X", tmp[i]) <= 0)
goto end;
}
if (BIO_puts(bp, "]") <= 0)
goto end;
}
if (!nl) { if (!nl) {
if (BIO_write(bp, "\n", 1) <= 0) if (BIO_write(bp, "\n", 1) <= 0)
@ -386,10 +339,8 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length,
} }
ret = 1; ret = 1;
end: end:
if (o != NULL)
ASN1_OBJECT_free(o); ASN1_OBJECT_free(o);
if (os != NULL) ASN1_OCTET_STRING_free(os);
M_ASN1_OCTET_STRING_free(os);
*pp = p; *pp = p;
return (ret); return (ret);
} }

View File

@ -1,65 +1,21 @@
/* asn_mime.c */
/* /*
* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * Copyright 2008-2016 The OpenSSL Project Authors. All Rights Reserved.
* project.
*/
/* ====================================================================
* Copyright (c) 1999-2008 The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
*
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* licensing@OpenSSL.org.
*
* 5. Products derived from this software may not be called "OpenSSL"
* nor may "OpenSSL" appear in their names without prior written
* permission of the OpenSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
* *
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/ */
#include <stdio.h> #include <stdio.h>
#include <ctype.h> #include <ctype.h>
#include "cryptlib.h" #include "internal/cryptlib.h"
#include <openssl/rand.h> #include <openssl/rand.h>
#include <openssl/x509.h> #include <openssl/x509.h>
#include <openssl/asn1.h> #include <openssl/asn1.h>
#include <openssl/asn1t.h> #include <openssl/asn1t.h>
#include "internal/evp_int.h"
#include "internal/bio.h"
#include "asn1_locl.h" #include "asn1_locl.h"
/* /*
@ -72,41 +28,35 @@
* from parameter values. Quotes are stripped off * from parameter values. Quotes are stripped off
*/ */
typedef struct { struct mime_param_st {
char *param_name; /* Param name e.g. "micalg" */ char *param_name; /* Param name e.g. "micalg" */
char *param_value; /* Param value e.g. "sha1" */ char *param_value; /* Param value e.g. "sha1" */
} MIME_PARAM; };
DECLARE_STACK_OF(MIME_PARAM) struct mime_header_st {
IMPLEMENT_STACK_OF(MIME_PARAM)
typedef struct {
char *name; /* Name of line e.g. "content-type" */ char *name; /* Name of line e.g. "content-type" */
char *value; /* Value of line e.g. "text/plain" */ char *value; /* Value of line e.g. "text/plain" */
STACK_OF(MIME_PARAM) *params; /* Zero or more parameters */ STACK_OF(MIME_PARAM) *params; /* Zero or more parameters */
} MIME_HEADER; };
DECLARE_STACK_OF(MIME_HEADER)
IMPLEMENT_STACK_OF(MIME_HEADER)
static int asn1_output_data(BIO *out, BIO *data, ASN1_VALUE *val, int flags, static int asn1_output_data(BIO *out, BIO *data, ASN1_VALUE *val, int flags,
const ASN1_ITEM *it); const ASN1_ITEM *it);
static char *strip_ends(char *name); static char *strip_ends(char *name);
static char *strip_start(char *name); static char *strip_start(char *name);
static char *strip_end(char *name); static char *strip_end(char *name);
static MIME_HEADER *mime_hdr_new(char *name, char *value); static MIME_HEADER *mime_hdr_new(const char *name, const char *value);
static int mime_hdr_addparam(MIME_HEADER *mhdr, char *name, char *value); static int mime_hdr_addparam(MIME_HEADER *mhdr, const char *name, const char *value);
static STACK_OF(MIME_HEADER) *mime_parse_hdr(BIO *bio); static STACK_OF(MIME_HEADER) *mime_parse_hdr(BIO *bio);
static int mime_hdr_cmp(const MIME_HEADER *const *a, static int mime_hdr_cmp(const MIME_HEADER *const *a,
const MIME_HEADER *const *b); const MIME_HEADER *const *b);
static int mime_param_cmp(const MIME_PARAM *const *a, static int mime_param_cmp(const MIME_PARAM *const *a,
const MIME_PARAM *const *b); const MIME_PARAM *const *b);
static void mime_param_free(MIME_PARAM *param); static void mime_param_free(MIME_PARAM *param);
static int mime_bound_check(char *line, int linelen, char *bound, int blen); static int mime_bound_check(char *line, int linelen, const char *bound, int blen);
static int multi_split(BIO *bio, char *bound, STACK_OF(BIO) **ret); static int multi_split(BIO *bio, const char *bound, STACK_OF(BIO) **ret);
static int strip_eol(char *linebuf, int *plen); static int strip_eol(char *linebuf, int *plen, int flags);
static MIME_HEADER *mime_hdr_find(STACK_OF(MIME_HEADER) *hdrs, char *name); static MIME_HEADER *mime_hdr_find(STACK_OF(MIME_HEADER) *hdrs, const char *name);
static MIME_PARAM *mime_param_find(MIME_HEADER *hdr, char *name); static MIME_PARAM *mime_param_find(MIME_HEADER *hdr, const char *name);
static void mime_hdr_free(MIME_HEADER *hdr); static void mime_hdr_free(MIME_HEADER *hdr);
#define MAX_SMLEN 1024 #define MAX_SMLEN 1024
@ -151,7 +101,7 @@ static int B64_write_ASN1(BIO *out, ASN1_VALUE *val, BIO *in, int flags,
BIO *b64; BIO *b64;
int r; int r;
b64 = BIO_new(BIO_f_base64()); b64 = BIO_new(BIO_f_base64());
if (!b64) { if (b64 == NULL) {
ASN1err(ASN1_F_B64_WRITE_ASN1, ERR_R_MALLOC_FAILURE); ASN1err(ASN1_F_B64_WRITE_ASN1, ERR_R_MALLOC_FAILURE);
return 0; return 0;
} }
@ -182,7 +132,8 @@ static ASN1_VALUE *b64_read_asn1(BIO *bio, const ASN1_ITEM *it)
{ {
BIO *b64; BIO *b64;
ASN1_VALUE *val; ASN1_VALUE *val;
if (!(b64 = BIO_new(BIO_f_base64()))) {
if ((b64 = BIO_new(BIO_f_base64())) == NULL) {
ASN1err(ASN1_F_B64_READ_ASN1, ERR_R_MALLOC_FAILURE); ASN1err(ASN1_F_B64_READ_ASN1, ERR_R_MALLOC_FAILURE);
return 0; return 0;
} }
@ -191,7 +142,7 @@ static ASN1_VALUE *b64_read_asn1(BIO *bio, const ASN1_ITEM *it)
if (!val) if (!val)
ASN1err(ASN1_F_B64_READ_ASN1, ASN1_R_DECODE_ERROR); ASN1err(ASN1_F_B64_READ_ASN1, ASN1_R_DECODE_ERROR);
(void)BIO_flush(bio); (void)BIO_flush(bio);
bio = BIO_pop(bio); BIO_pop(bio);
BIO_free(b64); BIO_free(b64);
return val; return val;
} }
@ -246,7 +197,6 @@ static int asn1_write_micalg(BIO *out, STACK_OF(X509_ALGOR) *mdalgs)
case NID_id_GostR3411_94: case NID_id_GostR3411_94:
BIO_puts(out, "gostr3411-94"); BIO_puts(out, "gostr3411-94");
goto err; goto err;
break;
default: default:
if (have_unknown) if (have_unknown)
@ -370,7 +320,7 @@ static int asn1_output_data(BIO *out, BIO *data, ASN1_VALUE *val, int flags,
int rv = 1; int rv = 1;
/* /*
* If data is not deteched or resigning then the output BIO is already * If data is not detached or resigning then the output BIO is already
* set up to finalise when it is written through. * set up to finalise when it is written through.
*/ */
if (!(flags & SMIME_DETACHED) || (flags & PKCS7_REUSE_DIGEST)) { if (!(flags & SMIME_DETACHED) || (flags & PKCS7_REUSE_DIGEST)) {
@ -430,12 +380,13 @@ ASN1_VALUE *SMIME_read_ASN1(BIO *bio, BIO **bcont, const ASN1_ITEM *it)
if (bcont) if (bcont)
*bcont = NULL; *bcont = NULL;
if (!(headers = mime_parse_hdr(bio))) { if ((headers = mime_parse_hdr(bio)) == NULL) {
ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_MIME_PARSE_ERROR); ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_MIME_PARSE_ERROR);
return NULL; return NULL;
} }
if (!(hdr = mime_hdr_find(headers, "content-type")) || !hdr->value) { if ((hdr = mime_hdr_find(headers, "content-type")) == NULL
|| hdr->value == NULL) {
sk_MIME_HEADER_pop_free(headers, mime_hdr_free); sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_NO_CONTENT_TYPE); ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_NO_CONTENT_TYPE);
return NULL; return NULL;
@ -443,7 +394,7 @@ ASN1_VALUE *SMIME_read_ASN1(BIO *bio, BIO **bcont, const ASN1_ITEM *it)
/* Handle multipart/signed */ /* Handle multipart/signed */
if (!strcmp(hdr->value, "multipart/signed")) { if (strcmp(hdr->value, "multipart/signed") == 0) {
/* Split into two parts */ /* Split into two parts */
prm = mime_param_find(hdr, "boundary"); prm = mime_param_find(hdr, "boundary");
if (!prm || !prm->param_value) { if (!prm || !prm->param_value) {
@ -462,7 +413,7 @@ ASN1_VALUE *SMIME_read_ASN1(BIO *bio, BIO **bcont, const ASN1_ITEM *it)
/* Parse the signature piece */ /* Parse the signature piece */
asnin = sk_BIO_value(parts, 1); asnin = sk_BIO_value(parts, 1);
if (!(headers = mime_parse_hdr(asnin))) { if ((headers = mime_parse_hdr(asnin)) == NULL) {
ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_MIME_SIG_PARSE_ERROR); ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_MIME_SIG_PARSE_ERROR);
sk_BIO_pop_free(parts, BIO_vfree); sk_BIO_pop_free(parts, BIO_vfree);
return NULL; return NULL;
@ -470,7 +421,8 @@ ASN1_VALUE *SMIME_read_ASN1(BIO *bio, BIO **bcont, const ASN1_ITEM *it)
/* Get content type */ /* Get content type */
if (!(hdr = mime_hdr_find(headers, "content-type")) || !hdr->value) { if ((hdr = mime_hdr_find(headers, "content-type")) == NULL
|| hdr->value == NULL) {
sk_MIME_HEADER_pop_free(headers, mime_hdr_free); sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_NO_SIG_CONTENT_TYPE); ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_NO_SIG_CONTENT_TYPE);
return NULL; return NULL;
@ -486,7 +438,7 @@ ASN1_VALUE *SMIME_read_ASN1(BIO *bio, BIO **bcont, const ASN1_ITEM *it)
} }
sk_MIME_HEADER_pop_free(headers, mime_hdr_free); sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
/* Read in ASN1 */ /* Read in ASN1 */
if (!(val = b64_read_asn1(asnin, it))) { if ((val = b64_read_asn1(asnin, it)) == NULL) {
ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_ASN1_SIG_PARSE_ERROR); ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_ASN1_SIG_PARSE_ERROR);
sk_BIO_pop_free(parts, BIO_vfree); sk_BIO_pop_free(parts, BIO_vfree);
return NULL; return NULL;
@ -513,7 +465,7 @@ ASN1_VALUE *SMIME_read_ASN1(BIO *bio, BIO **bcont, const ASN1_ITEM *it)
sk_MIME_HEADER_pop_free(headers, mime_hdr_free); sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
if (!(val = b64_read_asn1(bio, it))) { if ((val = b64_read_asn1(bio, it)) == NULL) {
ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_ASN1_PARSE_ERROR); ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_ASN1_PARSE_ERROR);
return NULL; return NULL;
} }
@ -533,21 +485,33 @@ int SMIME_crlf_copy(BIO *in, BIO *out, int flags)
* when streaming as we don't end up with one OCTET STRING per line. * when streaming as we don't end up with one OCTET STRING per line.
*/ */
bf = BIO_new(BIO_f_buffer()); bf = BIO_new(BIO_f_buffer());
if (!bf) if (bf == NULL)
return 0; return 0;
out = BIO_push(bf, out); out = BIO_push(bf, out);
if (flags & SMIME_BINARY) { if (flags & SMIME_BINARY) {
while ((len = BIO_read(in, linebuf, MAX_SMLEN)) > 0) while ((len = BIO_read(in, linebuf, MAX_SMLEN)) > 0)
BIO_write(out, linebuf, len); BIO_write(out, linebuf, len);
} else { } else {
int eolcnt = 0;
if (flags & SMIME_TEXT) if (flags & SMIME_TEXT)
BIO_printf(out, "Content-Type: text/plain\r\n\r\n"); BIO_printf(out, "Content-Type: text/plain\r\n\r\n");
while ((len = BIO_gets(in, linebuf, MAX_SMLEN)) > 0) { while ((len = BIO_gets(in, linebuf, MAX_SMLEN)) > 0) {
eol = strip_eol(linebuf, &len); eol = strip_eol(linebuf, &len, flags);
if (len) if (len) {
/* Not EOF: write out all CRLF */
if (flags & SMIME_ASCIICRLF) {
int i;
for (i = 0; i < eolcnt; i++)
BIO_write(out, "\r\n", 2);
eolcnt = 0;
}
BIO_write(out, linebuf, len); BIO_write(out, linebuf, len);
if (eol) if (eol)
BIO_write(out, "\r\n", 2); BIO_write(out, "\r\n", 2);
} else if (flags & SMIME_ASCIICRLF)
eolcnt++;
else if (eol)
BIO_write(out, "\r\n", 2);
} }
} }
(void)BIO_flush(out); (void)BIO_flush(out);
@ -564,11 +528,12 @@ int SMIME_text(BIO *in, BIO *out)
STACK_OF(MIME_HEADER) *headers; STACK_OF(MIME_HEADER) *headers;
MIME_HEADER *hdr; MIME_HEADER *hdr;
if (!(headers = mime_parse_hdr(in))) { if ((headers = mime_parse_hdr(in)) == NULL) {
ASN1err(ASN1_F_SMIME_TEXT, ASN1_R_MIME_PARSE_ERROR); ASN1err(ASN1_F_SMIME_TEXT, ASN1_R_MIME_PARSE_ERROR);
return 0; return 0;
} }
if (!(hdr = mime_hdr_find(headers, "content-type")) || !hdr->value) { if ((hdr = mime_hdr_find(headers, "content-type")) == NULL
|| hdr->value == NULL) {
ASN1err(ASN1_F_SMIME_TEXT, ASN1_R_MIME_NO_CONTENT_TYPE); ASN1err(ASN1_F_SMIME_TEXT, ASN1_R_MIME_NO_CONTENT_TYPE);
sk_MIME_HEADER_pop_free(headers, mime_hdr_free); sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
return 0; return 0;
@ -592,7 +557,7 @@ int SMIME_text(BIO *in, BIO *out)
* canonical parts in a STACK of bios * canonical parts in a STACK of bios
*/ */
static int multi_split(BIO *bio, char *bound, STACK_OF(BIO) **ret) static int multi_split(BIO *bio, const char *bound, STACK_OF(BIO) **ret)
{ {
char linebuf[MAX_SMLEN]; char linebuf[MAX_SMLEN];
int len, blen; int len, blen;
@ -607,24 +572,32 @@ static int multi_split(BIO *bio, char *bound, STACK_OF(BIO) **ret)
first = 1; first = 1;
parts = sk_BIO_new_null(); parts = sk_BIO_new_null();
*ret = parts; *ret = parts;
if (*ret == NULL)
return 0;
while ((len = BIO_gets(bio, linebuf, MAX_SMLEN)) > 0) { while ((len = BIO_gets(bio, linebuf, MAX_SMLEN)) > 0) {
state = mime_bound_check(linebuf, len, bound, blen); state = mime_bound_check(linebuf, len, bound, blen);
if (state == 1) { if (state == 1) {
first = 1; first = 1;
part++; part++;
} else if (state == 2) { } else if (state == 2) {
sk_BIO_push(parts, bpart); if (!sk_BIO_push(parts, bpart)) {
BIO_free(bpart);
return 0;
}
return 1; return 1;
} else if (part) { } else if (part) {
/* Strip CR+LF from linebuf */ /* Strip CR+LF from linebuf */
next_eol = strip_eol(linebuf, &len); next_eol = strip_eol(linebuf, &len, 0);
if (first) { if (first) {
first = 0; first = 0;
if (bpart) if (bpart)
sk_BIO_push(parts, bpart); if (!sk_BIO_push(parts, bpart)) {
BIO_free(bpart);
return 0;
}
bpart = BIO_new(BIO_s_mem()); bpart = BIO_new(BIO_s_mem());
if (bpart == NULL) if (bpart == NULL)
return 1; return 0;
BIO_set_mem_eof_return(bpart, 0); BIO_set_mem_eof_return(bpart, 0);
} else if (eol) } else if (eol)
BIO_write(bpart, "\r\n", 2); BIO_write(bpart, "\r\n", 2);
@ -633,6 +606,7 @@ static int multi_split(BIO *bio, char *bound, STACK_OF(BIO) **ret)
BIO_write(bpart, linebuf, len); BIO_write(bpart, linebuf, len);
} }
} }
BIO_free(bpart);
return 0; return 0;
} }
@ -651,12 +625,12 @@ static STACK_OF(MIME_HEADER) *mime_parse_hdr(BIO *bio)
char *p, *q, c; char *p, *q, c;
char *ntmp; char *ntmp;
char linebuf[MAX_SMLEN]; char linebuf[MAX_SMLEN];
MIME_HEADER *mhdr = NULL; MIME_HEADER *mhdr = NULL, *new_hdr = NULL;
STACK_OF(MIME_HEADER) *headers; STACK_OF(MIME_HEADER) *headers;
int len, state, save_state = 0; int len, state, save_state = 0;
headers = sk_MIME_HEADER_new(mime_hdr_cmp); headers = sk_MIME_HEADER_new(mime_hdr_cmp);
if (!headers) if (headers == NULL)
return NULL; return NULL;
while ((len = BIO_gets(bio, linebuf, MAX_SMLEN)) > 0) { while ((len = BIO_gets(bio, linebuf, MAX_SMLEN)) > 0) {
/* If whitespace at line start then continuation line */ /* If whitespace at line start then continuation line */
@ -688,8 +662,13 @@ static STACK_OF(MIME_HEADER) *mime_parse_hdr(BIO *bio)
if (c == ';') { if (c == ';') {
mime_debug("Found End Value\n"); mime_debug("Found End Value\n");
*p = 0; *p = 0;
mhdr = mime_hdr_new(ntmp, strip_ends(q)); new_hdr = mime_hdr_new(ntmp, strip_ends(q));
sk_MIME_HEADER_push(headers, mhdr); if (new_hdr == NULL)
goto err;
if (!sk_MIME_HEADER_push(headers, new_hdr))
goto err;
mhdr = new_hdr;
new_hdr = NULL;
ntmp = NULL; ntmp = NULL;
q = p + 1; q = p + 1;
state = MIME_NAME; state = MIME_NAME;
@ -740,8 +719,13 @@ static STACK_OF(MIME_HEADER) *mime_parse_hdr(BIO *bio)
} }
if (state == MIME_TYPE) { if (state == MIME_TYPE) {
mhdr = mime_hdr_new(ntmp, strip_ends(q)); new_hdr = mime_hdr_new(ntmp, strip_ends(q));
sk_MIME_HEADER_push(headers, mhdr); if (new_hdr == NULL)
goto err;
if (!sk_MIME_HEADER_push(headers, new_hdr))
goto err;
mhdr = new_hdr;
new_hdr = NULL;
} else if (state == MIME_VALUE) } else if (state == MIME_VALUE)
mime_hdr_addparam(mhdr, ntmp, strip_ends(q)); mime_hdr_addparam(mhdr, ntmp, strip_ends(q));
if (p == linebuf) if (p == linebuf)
@ -750,6 +734,10 @@ static STACK_OF(MIME_HEADER) *mime_parse_hdr(BIO *bio)
return headers; return headers;
err:
mime_hdr_free(new_hdr);
sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
return NULL;
} }
static char *strip_ends(char *name) static char *strip_ends(char *name)
@ -799,13 +787,14 @@ static char *strip_end(char *name)
return NULL; return NULL;
} }
static MIME_HEADER *mime_hdr_new(char *name, char *value) static MIME_HEADER *mime_hdr_new(const char *name, const char *value)
{ {
MIME_HEADER *mhdr; MIME_HEADER *mhdr = NULL;
char *tmpname, *tmpval, *p; char *tmpname = NULL, *tmpval = NULL, *p;
int c; int c;
if (name) { if (name) {
if (!(tmpname = BUF_strdup(name))) if ((tmpname = OPENSSL_strdup(name)) == NULL)
return NULL; return NULL;
for (p = tmpname; *p; p++) { for (p = tmpname; *p; p++) {
c = (unsigned char)*p; c = (unsigned char)*p;
@ -814,11 +803,10 @@ static MIME_HEADER *mime_hdr_new(char *name, char *value)
*p = c; *p = c;
} }
} }
} else }
tmpname = NULL;
if (value) { if (value) {
if (!(tmpval = BUF_strdup(value))) if ((tmpval = OPENSSL_strdup(value)) == NULL)
return NULL; goto err;
for (p = tmpval; *p; p++) { for (p = tmpval; *p; p++) {
c = (unsigned char)*p; c = (unsigned char)*p;
if (isupper(c)) { if (isupper(c)) {
@ -826,27 +814,32 @@ static MIME_HEADER *mime_hdr_new(char *name, char *value)
*p = c; *p = c;
} }
} }
} else }
tmpval = NULL; mhdr = OPENSSL_malloc(sizeof(*mhdr));
mhdr = (MIME_HEADER *)OPENSSL_malloc(sizeof(MIME_HEADER)); if (mhdr == NULL)
if (!mhdr) goto err;
return NULL;
mhdr->name = tmpname; mhdr->name = tmpname;
mhdr->value = tmpval; mhdr->value = tmpval;
if (!(mhdr->params = sk_MIME_PARAM_new(mime_param_cmp))) if ((mhdr->params = sk_MIME_PARAM_new(mime_param_cmp)) == NULL)
return NULL; goto err;
return mhdr; return mhdr;
err:
OPENSSL_free(tmpname);
OPENSSL_free(tmpval);
OPENSSL_free(mhdr);
return NULL;
} }
static int mime_hdr_addparam(MIME_HEADER *mhdr, char *name, char *value) static int mime_hdr_addparam(MIME_HEADER *mhdr, const char *name, const char *value)
{ {
char *tmpname, *tmpval, *p; char *tmpname = NULL, *tmpval = NULL, *p;
int c; int c;
MIME_PARAM *mparam; MIME_PARAM *mparam = NULL;
if (name) { if (name) {
tmpname = BUF_strdup(name); tmpname = OPENSSL_strdup(name);
if (!tmpname) if (!tmpname)
return 0; goto err;
for (p = tmpname; *p; p++) { for (p = tmpname; *p; p++) {
c = (unsigned char)*p; c = (unsigned char)*p;
if (isupper(c)) { if (isupper(c)) {
@ -854,22 +847,26 @@ static int mime_hdr_addparam(MIME_HEADER *mhdr, char *name, char *value)
*p = c; *p = c;
} }
} }
} else }
tmpname = NULL;
if (value) { if (value) {
tmpval = BUF_strdup(value); tmpval = OPENSSL_strdup(value);
if (!tmpval) if (!tmpval)
return 0; goto err;
} else }
tmpval = NULL;
/* Parameter values are case sensitive so leave as is */ /* Parameter values are case sensitive so leave as is */
mparam = (MIME_PARAM *)OPENSSL_malloc(sizeof(MIME_PARAM)); mparam = OPENSSL_malloc(sizeof(*mparam));
if (!mparam) if (mparam == NULL)
return 0; goto err;
mparam->param_name = tmpname; mparam->param_name = tmpname;
mparam->param_value = tmpval; mparam->param_value = tmpval;
sk_MIME_PARAM_push(mhdr->params, mparam); if (!sk_MIME_PARAM_push(mhdr->params, mparam))
goto err;
return 1; return 1;
err:
OPENSSL_free(tmpname);
OPENSSL_free(tmpval);
OPENSSL_free(mparam);
return 0;
} }
static int mime_hdr_cmp(const MIME_HEADER *const *a, static int mime_hdr_cmp(const MIME_HEADER *const *a,
@ -891,22 +888,28 @@ static int mime_param_cmp(const MIME_PARAM *const *a,
/* Find a header with a given name (if possible) */ /* Find a header with a given name (if possible) */
static MIME_HEADER *mime_hdr_find(STACK_OF(MIME_HEADER) *hdrs, char *name) static MIME_HEADER *mime_hdr_find(STACK_OF(MIME_HEADER) *hdrs, const char *name)
{ {
MIME_HEADER htmp; MIME_HEADER htmp;
int idx; int idx;
htmp.name = name;
htmp.name = (char *)name;
htmp.value = NULL;
htmp.params = NULL;
idx = sk_MIME_HEADER_find(hdrs, &htmp); idx = sk_MIME_HEADER_find(hdrs, &htmp);
if (idx < 0) if (idx < 0)
return NULL; return NULL;
return sk_MIME_HEADER_value(hdrs, idx); return sk_MIME_HEADER_value(hdrs, idx);
} }
static MIME_PARAM *mime_param_find(MIME_HEADER *hdr, char *name) static MIME_PARAM *mime_param_find(MIME_HEADER *hdr, const char *name)
{ {
MIME_PARAM param; MIME_PARAM param;
int idx; int idx;
param.param_name = name;
param.param_name = (char *)name;
param.param_value = NULL;
idx = sk_MIME_PARAM_find(hdr->params, &param); idx = sk_MIME_PARAM_find(hdr->params, &param);
if (idx < 0) if (idx < 0)
return NULL; return NULL;
@ -915,9 +918,9 @@ static MIME_PARAM *mime_param_find(MIME_HEADER *hdr, char *name)
static void mime_hdr_free(MIME_HEADER *hdr) static void mime_hdr_free(MIME_HEADER *hdr)
{ {
if (hdr->name) if (hdr == NULL)
return;
OPENSSL_free(hdr->name); OPENSSL_free(hdr->name);
if (hdr->value)
OPENSSL_free(hdr->value); OPENSSL_free(hdr->value);
if (hdr->params) if (hdr->params)
sk_MIME_PARAM_pop_free(hdr->params, mime_param_free); sk_MIME_PARAM_pop_free(hdr->params, mime_param_free);
@ -926,9 +929,7 @@ static void mime_hdr_free(MIME_HEADER *hdr)
static void mime_param_free(MIME_PARAM *param) static void mime_param_free(MIME_PARAM *param)
{ {
if (param->param_name)
OPENSSL_free(param->param_name); OPENSSL_free(param->param_name);
if (param->param_value)
OPENSSL_free(param->param_value); OPENSSL_free(param->param_value);
OPENSSL_free(param); OPENSSL_free(param);
} }
@ -939,7 +940,7 @@ static void mime_param_free(MIME_PARAM *param)
* 1 : part boundary * 1 : part boundary
* 2 : final boundary * 2 : final boundary
*/ */
static int mime_bound_check(char *line, int linelen, char *bound, int blen) static int mime_bound_check(char *line, int linelen, const char *bound, int blen)
{ {
if (linelen == -1) if (linelen == -1)
linelen = strlen(line); linelen = strlen(line);
@ -949,8 +950,9 @@ static int mime_bound_check(char *line, int linelen, char *bound, int blen)
if (blen + 2 > linelen) if (blen + 2 > linelen)
return 0; return 0;
/* Check for part boundary */ /* Check for part boundary */
if (!strncmp(line, "--", 2) && !strncmp(line + 2, bound, blen)) { if ((strncmp(line, "--", 2) == 0)
if (!strncmp(line + blen + 2, "--", 2)) && strncmp(line + 2, bound, blen) == 0) {
if (strncmp(line + blen + 2, "--", 2) == 0)
return 2; return 2;
else else
return 1; return 1;
@ -958,7 +960,7 @@ static int mime_bound_check(char *line, int linelen, char *bound, int blen)
return 0; return 0;
} }
static int strip_eol(char *linebuf, int *plen) static int strip_eol(char *linebuf, int *plen, int flags)
{ {
int len = *plen; int len = *plen;
char *p, c; char *p, c;
@ -968,6 +970,8 @@ static int strip_eol(char *linebuf, int *plen)
c = *p; c = *p;
if (c == '\n') if (c == '\n')
is_eol = 1; is_eol = 1;
else if (is_eol && flags & SMIME_ASCIICRLF && c < 33)
continue;
else if (c != '\r') else if (c != '\r')
break; break;
} }

View File

@ -1,73 +1,24 @@
/* asn_moid.c */
/* /*
* Written by Stephen Henson (steve@openssl.org) for the OpenSSL project * Copyright 2002-2016 The OpenSSL Project Authors. All Rights Reserved.
* 2001.
*/
/* ====================================================================
* Copyright (c) 2001-2004 The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
*
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* licensing@OpenSSL.org.
*
* 5. Products derived from this software may not be called "OpenSSL"
* nor may "OpenSSL" appear in their names without prior written
* permission of the OpenSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*
* This product includes cryptographic software written by Eric Young
* (eay@cryptsoft.com). This product includes software written by Tim
* Hudson (tjh@cryptsoft.com).
* *
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/ */
#include <stdio.h> #include <stdio.h>
#include <ctype.h> #include <ctype.h>
#include <openssl/crypto.h> #include <openssl/crypto.h>
#include "cryptlib.h" #include "internal/cryptlib.h"
#include <openssl/conf.h> #include <openssl/conf.h>
#include <openssl/dso.h>
#include <openssl/x509.h> #include <openssl/x509.h>
#include "internal/asn1_int.h"
#include "internal/objects.h"
/* Simple ASN1 OID module: add all objects in a given section */ /* Simple ASN1 OID module: add all objects in a given section */
static int do_create(char *value, char *name); static int do_create(const char *value, const char *name);
static int oid_module_init(CONF_IMODULE *md, const CONF *cnf) static int oid_module_init(CONF_IMODULE *md, const CONF *cnf)
{ {
@ -75,8 +26,9 @@ static int oid_module_init(CONF_IMODULE *md, const CONF *cnf)
const char *oid_section; const char *oid_section;
STACK_OF(CONF_VALUE) *sktmp; STACK_OF(CONF_VALUE) *sktmp;
CONF_VALUE *oval; CONF_VALUE *oval;
oid_section = CONF_imodule_get_value(md); oid_section = CONF_imodule_get_value(md);
if (!(sktmp = NCONF_get_section(cnf, oid_section))) { if ((sktmp = NCONF_get_section(cnf, oid_section)) == NULL) {
ASN1err(ASN1_F_OID_MODULE_INIT, ASN1_R_ERROR_LOADING_SECTION); ASN1err(ASN1_F_OID_MODULE_INIT, ASN1_R_ERROR_LOADING_SECTION);
return 0; return 0;
} }
@ -92,7 +44,6 @@ static int oid_module_init(CONF_IMODULE *md, const CONF *cnf)
static void oid_module_finish(CONF_IMODULE *md) static void oid_module_finish(CONF_IMODULE *md)
{ {
OBJ_cleanup();
} }
void ASN1_add_oid_module(void) void ASN1_add_oid_module(void)
@ -106,11 +57,12 @@ void ASN1_add_oid_module(void)
* shortname = some long name, 1.2.3.4 * shortname = some long name, 1.2.3.4
*/ */
static int do_create(char *value, char *name) static int do_create(const char *value, const char *name)
{ {
int nid; int nid;
ASN1_OBJECT *oid; ASN1_OBJECT *oid;
char *ln, *ostr, *p, *lntmp; const char *ln, *ostr, *p;
char *lntmp;
p = strrchr(value, ','); p = strrchr(value, ',');
if (!p) { if (!p) {
ln = name; ln = name;

View File

@ -0,0 +1,114 @@
/*
* Copyright 2012-2016 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
#include <stdio.h>
#include <ctype.h>
#include <openssl/crypto.h>
#include "internal/cryptlib.h"
#include <openssl/conf.h>
#include <openssl/x509v3.h>
/* Multi string module: add table entries from a given section */
static int do_tcreate(const char *value, const char *name);
static int stbl_module_init(CONF_IMODULE *md, const CONF *cnf)
{
int i;
const char *stbl_section;
STACK_OF(CONF_VALUE) *sktmp;
CONF_VALUE *mval;
stbl_section = CONF_imodule_get_value(md);
if ((sktmp = NCONF_get_section(cnf, stbl_section)) == NULL) {
ASN1err(ASN1_F_STBL_MODULE_INIT, ASN1_R_ERROR_LOADING_SECTION);
return 0;
}
for (i = 0; i < sk_CONF_VALUE_num(sktmp); i++) {
mval = sk_CONF_VALUE_value(sktmp, i);
if (!do_tcreate(mval->value, mval->name)) {
ASN1err(ASN1_F_STBL_MODULE_INIT, ASN1_R_INVALID_VALUE);
return 0;
}
}
return 1;
}
static void stbl_module_finish(CONF_IMODULE *md)
{
ASN1_STRING_TABLE_cleanup();
}
void ASN1_add_stable_module(void)
{
CONF_module_add("stbl_section", stbl_module_init, stbl_module_finish);
}
/*
* Create an table entry based on a name value pair. format is oid_name =
* n1:v1, n2:v2,... where name is "min", "max", "mask" or "flags".
*/
static int do_tcreate(const char *value, const char *name)
{
char *eptr;
int nid, i, rv = 0;
long tbl_min = -1, tbl_max = -1;
unsigned long tbl_mask = 0, tbl_flags = 0;
STACK_OF(CONF_VALUE) *lst = NULL;
CONF_VALUE *cnf = NULL;
nid = OBJ_sn2nid(name);
if (nid == NID_undef)
nid = OBJ_ln2nid(name);
if (nid == NID_undef)
goto err;
lst = X509V3_parse_list(value);
if (!lst)
goto err;
for (i = 0; i < sk_CONF_VALUE_num(lst); i++) {
cnf = sk_CONF_VALUE_value(lst, i);
if (strcmp(cnf->name, "min") == 0) {
tbl_min = strtoul(cnf->value, &eptr, 0);
if (*eptr)
goto err;
} else if (strcmp(cnf->name, "max") == 0) {
tbl_max = strtoul(cnf->value, &eptr, 0);
if (*eptr)
goto err;
} else if (strcmp(cnf->name, "mask") == 0) {
if (!ASN1_str2mask(cnf->value, &tbl_mask) || !tbl_mask)
goto err;
} else if (strcmp(cnf->name, "flags") == 0) {
if (strcmp(cnf->value, "nomask") == 0)
tbl_flags = STABLE_NO_MASK;
else if (strcmp(cnf->value, "none") == 0)
tbl_flags = STABLE_FLAGS_CLEAR;
else
goto err;
} else
goto err;
}
rv = 1;
err:
if (rv == 0) {
ASN1err(ASN1_F_DO_TCREATE, ASN1_R_INVALID_STRING_TABLE_VALUE);
if (cnf)
ERR_add_error_data(4, "field=", cnf->name,
", value=", cnf->value);
else
ERR_add_error_data(4, "name=", name, ", value=", value);
} else {
rv = ASN1_STRING_TABLE_add(nid, tbl_min, tbl_max,
tbl_mask, tbl_flags);
if (!rv)
ASN1err(ASN1_F_DO_TCREATE, ERR_R_MALLOC_FAILURE);
}
sk_CONF_VALUE_pop_free(lst, X509V3_conf_free);
return rv;
}

View File

@ -1,207 +1,62 @@
/* asn_pack.c */
/* /*
* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved.
* 1999.
*/
/* ====================================================================
* Copyright (c) 1999 The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
*
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* licensing@OpenSSL.org.
*
* 5. Products derived from this software may not be called "OpenSSL"
* nor may "OpenSSL" appear in their names without prior written
* permission of the OpenSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*
* This product includes cryptographic software written by Eric Young
* (eay@cryptsoft.com). This product includes software written by Tim
* Hudson (tjh@cryptsoft.com).
* *
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/ */
#include <stdio.h> #include <stdio.h>
#include "cryptlib.h" #include "internal/cryptlib.h"
#include <openssl/asn1.h> #include <openssl/asn1.h>
#ifndef NO_ASN1_OLD
/* ASN1 packing and unpacking functions */ /* ASN1 packing and unpacking functions */
/* Turn an ASN1 encoded SEQUENCE OF into a STACK of structures */
STACK_OF(OPENSSL_BLOCK) *ASN1_seq_unpack(const unsigned char *buf, int len,
d2i_of_void *d2i,
void (*free_func) (OPENSSL_BLOCK))
{
STACK_OF(OPENSSL_BLOCK) *sk;
const unsigned char *pbuf;
pbuf = buf;
if (!(sk = d2i_ASN1_SET(NULL, &pbuf, len, d2i, free_func,
V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL)))
ASN1err(ASN1_F_ASN1_SEQ_UNPACK, ASN1_R_DECODE_ERROR);
return sk;
}
/*
* Turn a STACK structures into an ASN1 encoded SEQUENCE OF structure in a
* OPENSSL_malloc'ed buffer
*/
unsigned char *ASN1_seq_pack(STACK_OF(OPENSSL_BLOCK) *safes, i2d_of_void *i2d,
unsigned char **buf, int *len)
{
int safelen;
unsigned char *safe, *p;
if (!(safelen = i2d_ASN1_SET(safes, NULL, i2d, V_ASN1_SEQUENCE,
V_ASN1_UNIVERSAL, IS_SEQUENCE))) {
ASN1err(ASN1_F_ASN1_SEQ_PACK, ASN1_R_ENCODE_ERROR);
return NULL;
}
if (!(safe = OPENSSL_malloc(safelen))) {
ASN1err(ASN1_F_ASN1_SEQ_PACK, ERR_R_MALLOC_FAILURE);
return NULL;
}
p = safe;
i2d_ASN1_SET(safes, &p, i2d, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL,
IS_SEQUENCE);
if (len)
*len = safelen;
if (buf)
*buf = safe;
return safe;
}
/* Extract an ASN1 object from an ASN1_STRING */
void *ASN1_unpack_string(ASN1_STRING *oct, d2i_of_void *d2i)
{
const unsigned char *p;
char *ret;
p = oct->data;
if (!(ret = d2i(NULL, &p, oct->length)))
ASN1err(ASN1_F_ASN1_UNPACK_STRING, ASN1_R_DECODE_ERROR);
return ret;
}
/* Pack an ASN1 object into an ASN1_STRING */
ASN1_STRING *ASN1_pack_string(void *obj, i2d_of_void *i2d, ASN1_STRING **oct)
{
unsigned char *p;
ASN1_STRING *octmp;
if (!oct || !*oct) {
if (!(octmp = ASN1_STRING_new())) {
ASN1err(ASN1_F_ASN1_PACK_STRING, ERR_R_MALLOC_FAILURE);
return NULL;
}
if (oct)
*oct = octmp;
} else
octmp = *oct;
if (!(octmp->length = i2d(obj, NULL))) {
ASN1err(ASN1_F_ASN1_PACK_STRING, ASN1_R_ENCODE_ERROR);
goto err;
}
if (!(p = OPENSSL_malloc(octmp->length))) {
ASN1err(ASN1_F_ASN1_PACK_STRING, ERR_R_MALLOC_FAILURE);
goto err;
}
octmp->data = p;
i2d(obj, &p);
return octmp;
err:
if (!oct || !*oct) {
ASN1_STRING_free(octmp);
if (oct)
*oct = NULL;
}
return NULL;
}
#endif
/* ASN1_ITEM versions of the above */
ASN1_STRING *ASN1_item_pack(void *obj, const ASN1_ITEM *it, ASN1_STRING **oct) ASN1_STRING *ASN1_item_pack(void *obj, const ASN1_ITEM *it, ASN1_STRING **oct)
{ {
ASN1_STRING *octmp; ASN1_STRING *octmp;
if (!oct || !*oct) { if (oct == NULL || *oct == NULL) {
if (!(octmp = ASN1_STRING_new())) { if ((octmp = ASN1_STRING_new()) == NULL) {
ASN1err(ASN1_F_ASN1_ITEM_PACK, ERR_R_MALLOC_FAILURE); ASN1err(ASN1_F_ASN1_ITEM_PACK, ERR_R_MALLOC_FAILURE);
return NULL; return NULL;
} }
if (oct) } else {
*oct = octmp;
} else
octmp = *oct; octmp = *oct;
}
if (octmp->data) {
OPENSSL_free(octmp->data); OPENSSL_free(octmp->data);
octmp->data = NULL; octmp->data = NULL;
if ((octmp->length = ASN1_item_i2d(obj, &octmp->data, it)) == 0) {
ASN1err(ASN1_F_ASN1_ITEM_PACK, ASN1_R_ENCODE_ERROR);
goto err;
}
if (octmp->data == NULL) {
ASN1err(ASN1_F_ASN1_ITEM_PACK, ERR_R_MALLOC_FAILURE);
goto err;
} }
if (!(octmp->length = ASN1_item_i2d(obj, &octmp->data, it))) { if (oct != NULL && *oct == NULL)
ASN1err(ASN1_F_ASN1_ITEM_PACK, ASN1_R_ENCODE_ERROR); *oct = octmp;
return NULL;
}
if (!octmp->data) {
ASN1err(ASN1_F_ASN1_ITEM_PACK, ERR_R_MALLOC_FAILURE);
return NULL;
}
return octmp; return octmp;
err:
if (oct == NULL || *oct == NULL)
ASN1_STRING_free(octmp);
return NULL;
} }
/* Extract an ASN1 object from an ASN1_STRING */ /* Extract an ASN1 object from an ASN1_STRING */
void *ASN1_item_unpack(ASN1_STRING *oct, const ASN1_ITEM *it) void *ASN1_item_unpack(const ASN1_STRING *oct, const ASN1_ITEM *it)
{ {
const unsigned char *p; const unsigned char *p;
void *ret; void *ret;
p = oct->data; p = oct->data;
if (!(ret = ASN1_item_d2i(NULL, &p, oct->length, it))) if ((ret = ASN1_item_d2i(NULL, &p, oct->length, it)) == NULL)
ASN1err(ASN1_F_ASN1_ITEM_UNPACK, ASN1_R_DECODE_ERROR); ASN1err(ASN1_F_ASN1_ITEM_UNPACK, ASN1_R_DECODE_ERROR);
return ret; return ret;
} }

View File

@ -1,60 +1,10 @@
/* bio_asn1.c */
/* /*
* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * Copyright 2006-2016 The OpenSSL Project Authors. All Rights Reserved.
* project.
*/
/* ====================================================================
* Copyright (c) 2006 The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
*
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* licensing@OpenSSL.org.
*
* 5. Products derived from this software may not be called "OpenSSL"
* nor may "OpenSSL" appear in their names without prior written
* permission of the OpenSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*
* This product includes cryptographic software written by Eric Young
* (eay@cryptsoft.com). This product includes software written by Tim
* Hudson (tjh@cryptsoft.com).
* *
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/ */
/* /*
@ -64,7 +14,7 @@
*/ */
#include <string.h> #include <string.h>
#include <openssl/bio.h> #include <internal/bio.h>
#include <openssl/asn1.h> #include <openssl/asn1.h>
/* Must be large enough for biggest tag+length */ /* Must be large enough for biggest tag+length */
@ -125,7 +75,7 @@ static int asn1_bio_setup_ex(BIO *b, BIO_ASN1_BUF_CTX *ctx,
asn1_bio_state_t ex_state, asn1_bio_state_t ex_state,
asn1_bio_state_t other_state); asn1_bio_state_t other_state);
static BIO_METHOD methods_asn1 = { static const BIO_METHOD methods_asn1 = {
BIO_TYPE_ASN1, BIO_TYPE_ASN1,
"asn1", "asn1",
asn1_bio_write, asn1_bio_write,
@ -138,59 +88,55 @@ static BIO_METHOD methods_asn1 = {
asn1_bio_callback_ctrl, asn1_bio_callback_ctrl,
}; };
BIO_METHOD *BIO_f_asn1(void) const BIO_METHOD *BIO_f_asn1(void)
{ {
return (&methods_asn1); return (&methods_asn1);
} }
static int asn1_bio_new(BIO *b) static int asn1_bio_new(BIO *b)
{ {
BIO_ASN1_BUF_CTX *ctx; BIO_ASN1_BUF_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx));
ctx = OPENSSL_malloc(sizeof(BIO_ASN1_BUF_CTX));
if (!ctx) if (ctx == NULL)
return 0; return 0;
if (!asn1_bio_init(ctx, DEFAULT_ASN1_BUF_SIZE)) { if (!asn1_bio_init(ctx, DEFAULT_ASN1_BUF_SIZE)) {
OPENSSL_free(ctx); OPENSSL_free(ctx);
return 0; return 0;
} }
b->init = 1; BIO_set_data(b, ctx);
b->ptr = (char *)ctx; BIO_set_init(b, 1);
b->flags = 0;
return 1; return 1;
} }
static int asn1_bio_init(BIO_ASN1_BUF_CTX *ctx, int size) static int asn1_bio_init(BIO_ASN1_BUF_CTX *ctx, int size)
{ {
ctx->buf = OPENSSL_malloc(size); ctx->buf = OPENSSL_malloc(size);
if (!ctx->buf) if (ctx->buf == NULL)
return 0; return 0;
ctx->bufsize = size; ctx->bufsize = size;
ctx->bufpos = 0;
ctx->buflen = 0;
ctx->copylen = 0;
ctx->asn1_class = V_ASN1_UNIVERSAL; ctx->asn1_class = V_ASN1_UNIVERSAL;
ctx->asn1_tag = V_ASN1_OCTET_STRING; ctx->asn1_tag = V_ASN1_OCTET_STRING;
ctx->ex_buf = NULL;
ctx->ex_len = 0;
ctx->ex_pos = 0;
ctx->state = ASN1_STATE_START; ctx->state = ASN1_STATE_START;
ctx->prefix = ctx->prefix_free = ctx->suffix = ctx->suffix_free = NULL;
ctx->ex_arg = NULL;
return 1; return 1;
} }
static int asn1_bio_free(BIO *b) static int asn1_bio_free(BIO *b)
{ {
BIO_ASN1_BUF_CTX *ctx; BIO_ASN1_BUF_CTX *ctx;
ctx = (BIO_ASN1_BUF_CTX *)b->ptr;
if (b == NULL)
return 0;
ctx = BIO_get_data(b);
if (ctx == NULL) if (ctx == NULL)
return 0; return 0;
if (ctx->buf)
OPENSSL_free(ctx->buf); OPENSSL_free(ctx->buf);
OPENSSL_free(ctx); OPENSSL_free(ctx);
b->init = 0; BIO_set_data(b, NULL);
b->ptr = NULL; BIO_set_init(b, 0);
b->flags = 0;
return 1; return 1;
} }
@ -199,10 +145,11 @@ static int asn1_bio_write(BIO *b, const char *in, int inl)
BIO_ASN1_BUF_CTX *ctx; BIO_ASN1_BUF_CTX *ctx;
int wrmax, wrlen, ret; int wrmax, wrlen, ret;
unsigned char *p; unsigned char *p;
if (!in || (inl < 0) || (b->next_bio == NULL)) BIO *next;
return 0;
ctx = (BIO_ASN1_BUF_CTX *)b->ptr; ctx = BIO_get_data(b);
if (ctx == NULL) next = BIO_next(b);
if (in == NULL || inl < 0 || ctx == NULL || next == NULL)
return 0; return 0;
wrlen = 0; wrlen = 0;
@ -240,7 +187,7 @@ static int asn1_bio_write(BIO *b, const char *in, int inl)
break; break;
case ASN1_STATE_HEADER_COPY: case ASN1_STATE_HEADER_COPY:
ret = BIO_write(b->next_bio, ctx->buf + ctx->bufpos, ctx->buflen); ret = BIO_write(next, ctx->buf + ctx->bufpos, ctx->buflen);
if (ret <= 0) if (ret <= 0)
goto done; goto done;
@ -260,7 +207,7 @@ static int asn1_bio_write(BIO *b, const char *in, int inl)
wrmax = ctx->copylen; wrmax = ctx->copylen;
else else
wrmax = inl; wrmax = inl;
ret = BIO_write(b->next_bio, in, wrmax); ret = BIO_write(next, in, wrmax);
if (ret <= 0) if (ret <= 0)
break; break;
wrlen += ret; wrlen += ret;
@ -296,10 +243,11 @@ static int asn1_bio_flush_ex(BIO *b, BIO_ASN1_BUF_CTX *ctx,
asn1_ps_func *cleanup, asn1_bio_state_t next) asn1_ps_func *cleanup, asn1_bio_state_t next)
{ {
int ret; int ret;
if (ctx->ex_len <= 0) if (ctx->ex_len <= 0)
return 1; return 1;
for (;;) { for (;;) {
ret = BIO_write(b->next_bio, ctx->ex_buf + ctx->ex_pos, ctx->ex_len); ret = BIO_write(BIO_next(b), ctx->ex_buf + ctx->ex_pos, ctx->ex_len);
if (ret <= 0) if (ret <= 0)
break; break;
ctx->ex_len -= ret; ctx->ex_len -= ret;
@ -334,9 +282,10 @@ static int asn1_bio_setup_ex(BIO *b, BIO_ASN1_BUF_CTX *ctx,
static int asn1_bio_read(BIO *b, char *in, int inl) static int asn1_bio_read(BIO *b, char *in, int inl)
{ {
if (!b->next_bio) BIO *next = BIO_next(b);
if (next == NULL)
return 0; return 0;
return BIO_read(b->next_bio, in, inl); return BIO_read(next, in, inl);
} }
static int asn1_bio_puts(BIO *b, const char *str) static int asn1_bio_puts(BIO *b, const char *str)
@ -346,16 +295,18 @@ static int asn1_bio_puts(BIO *b, const char *str)
static int asn1_bio_gets(BIO *b, char *str, int size) static int asn1_bio_gets(BIO *b, char *str, int size)
{ {
if (!b->next_bio) BIO *next = BIO_next(b);
if (next == NULL)
return 0; return 0;
return BIO_gets(b->next_bio, str, size); return BIO_gets(next, str, size);
} }
static long asn1_bio_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) static long asn1_bio_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
{ {
if (b->next_bio == NULL) BIO *next = BIO_next(b);
return (0); if (next == NULL)
return BIO_callback_ctrl(b->next_bio, cmd, fp); return 0;
return BIO_callback_ctrl(next, cmd, fp);
} }
static long asn1_bio_ctrl(BIO *b, int cmd, long arg1, void *arg2) static long asn1_bio_ctrl(BIO *b, int cmd, long arg1, void *arg2)
@ -363,9 +314,12 @@ static long asn1_bio_ctrl(BIO *b, int cmd, long arg1, void *arg2)
BIO_ASN1_BUF_CTX *ctx; BIO_ASN1_BUF_CTX *ctx;
BIO_ASN1_EX_FUNCS *ex_func; BIO_ASN1_EX_FUNCS *ex_func;
long ret = 1; long ret = 1;
ctx = (BIO_ASN1_BUF_CTX *)b->ptr; BIO *next;
ctx = BIO_get_data(b);
if (ctx == NULL) if (ctx == NULL)
return 0; return 0;
next = BIO_next(b);
switch (cmd) { switch (cmd) {
case BIO_C_SET_PREFIX: case BIO_C_SET_PREFIX:
@ -401,7 +355,7 @@ static long asn1_bio_ctrl(BIO *b, int cmd, long arg1, void *arg2)
break; break;
case BIO_CTRL_FLUSH: case BIO_CTRL_FLUSH:
if (!b->next_bio) if (next == NULL)
return 0; return 0;
/* Call post function if possible */ /* Call post function if possible */
@ -419,17 +373,16 @@ static long asn1_bio_ctrl(BIO *b, int cmd, long arg1, void *arg2)
} }
if (ctx->state == ASN1_STATE_DONE) if (ctx->state == ASN1_STATE_DONE)
return BIO_ctrl(b->next_bio, cmd, arg1, arg2); return BIO_ctrl(next, cmd, arg1, arg2);
else { else {
BIO_clear_retry_flags(b); BIO_clear_retry_flags(b);
return 0; return 0;
} }
break;
default: default:
if (!b->next_bio) if (next == NULL)
return 0; return 0;
return BIO_ctrl(b->next_bio, cmd, arg1, arg2); return BIO_ctrl(next, cmd, arg1, arg2);
} }

View File

@ -1,56 +1,10 @@
/* bio_ndef.c */
/* /*
* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * Copyright 2008-2016 The OpenSSL Project Authors. All Rights Reserved.
* project.
*/
/* ====================================================================
* Copyright (c) 2008 The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
*
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* licensing@OpenSSL.org.
*
* 5. Products derived from this software may not be called "OpenSSL"
* nor may "OpenSSL" appear in their names without prior written
* permission of the OpenSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
* *
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/ */
#include <openssl/asn1.h> #include <openssl/asn1.h>
@ -65,7 +19,7 @@
/* /*
* The usage is quite simple, initialize an ASN1 structure, get a BIO from it * The usage is quite simple, initialize an ASN1 structure, get a BIO from it
* then any data written through the BIO will end up translated to * then any data written through the BIO will end up translated to
* approptiate format on the fly. The data is streamed out and does *not* * appropriate format on the fly. The data is streamed out and does *not*
* need to be all held in memory at once. When the BIO is flushed the output * need to be all held in memory at once. When the BIO is flushed the output
* is finalized and any signatures etc written out. The BIO is a 'proper' * is finalized and any signatures etc written out. The BIO is a 'proper'
* BIO and can handle non blocking I/O correctly. The usage is simple. The * BIO and can handle non blocking I/O correctly. The usage is simple. The
@ -106,21 +60,21 @@ BIO *BIO_new_NDEF(BIO *out, ASN1_VALUE *val, const ASN1_ITEM *it)
ASN1err(ASN1_F_BIO_NEW_NDEF, ASN1_R_STREAMING_NOT_SUPPORTED); ASN1err(ASN1_F_BIO_NEW_NDEF, ASN1_R_STREAMING_NOT_SUPPORTED);
return NULL; return NULL;
} }
ndef_aux = OPENSSL_malloc(sizeof(NDEF_SUPPORT)); ndef_aux = OPENSSL_zalloc(sizeof(*ndef_aux));
asn_bio = BIO_new(BIO_f_asn1()); asn_bio = BIO_new(BIO_f_asn1());
if (ndef_aux == NULL || asn_bio == NULL)
goto err;
/* ASN1 bio needs to be next to output BIO */ /* ASN1 bio needs to be next to output BIO */
out = BIO_push(asn_bio, out); out = BIO_push(asn_bio, out);
if (out == NULL)
if (!ndef_aux || !asn_bio || !out)
goto err; goto err;
BIO_asn1_set_prefix(asn_bio, ndef_prefix, ndef_prefix_free); BIO_asn1_set_prefix(asn_bio, ndef_prefix, ndef_prefix_free);
BIO_asn1_set_suffix(asn_bio, ndef_suffix, ndef_suffix_free); BIO_asn1_set_suffix(asn_bio, ndef_suffix, ndef_suffix_free);
/* /*
* Now let callback prepend any digest, cipher etc BIOs ASN1 structure * Now let callback prepends any digest, cipher etc BIOs ASN1 structure
* needs. * needs.
*/ */
@ -136,16 +90,13 @@ BIO *BIO_new_NDEF(BIO *out, ASN1_VALUE *val, const ASN1_ITEM *it)
ndef_aux->ndef_bio = sarg.ndef_bio; ndef_aux->ndef_bio = sarg.ndef_bio;
ndef_aux->boundary = sarg.boundary; ndef_aux->boundary = sarg.boundary;
ndef_aux->out = out; ndef_aux->out = out;
ndef_aux->derbuf = NULL;
BIO_ctrl(asn_bio, BIO_C_SET_EX_ARG, 0, ndef_aux); BIO_ctrl(asn_bio, BIO_C_SET_EX_ARG, 0, ndef_aux);
return sarg.ndef_bio; return sarg.ndef_bio;
err: err:
if (asn_bio)
BIO_free(asn_bio); BIO_free(asn_bio);
if (ndef_aux)
OPENSSL_free(ndef_aux); OPENSSL_free(ndef_aux);
return NULL; return NULL;
} }
@ -163,7 +114,7 @@ static int ndef_prefix(BIO *b, unsigned char **pbuf, int *plen, void *parg)
derlen = ASN1_item_ndef_i2d(ndef_aux->val, NULL, ndef_aux->it); derlen = ASN1_item_ndef_i2d(ndef_aux->val, NULL, ndef_aux->it);
p = OPENSSL_malloc(derlen); p = OPENSSL_malloc(derlen);
if (!p) if (p == NULL)
return 0; return 0;
ndef_aux->derbuf = p; ndef_aux->derbuf = p;
@ -188,7 +139,6 @@ static int ndef_prefix_free(BIO *b, unsigned char **pbuf, int *plen,
ndef_aux = *(NDEF_SUPPORT **)parg; ndef_aux = *(NDEF_SUPPORT **)parg;
if (ndef_aux->derbuf)
OPENSSL_free(ndef_aux->derbuf); OPENSSL_free(ndef_aux->derbuf);
ndef_aux->derbuf = NULL; ndef_aux->derbuf = NULL;
@ -233,7 +183,7 @@ static int ndef_suffix(BIO *b, unsigned char **pbuf, int *plen, void *parg)
derlen = ASN1_item_ndef_i2d(ndef_aux->val, NULL, ndef_aux->it); derlen = ASN1_item_ndef_i2d(ndef_aux->val, NULL, ndef_aux->it);
p = OPENSSL_malloc(derlen); p = OPENSSL_malloc(derlen);
if (!p) if (p == NULL)
return 0; return 0;
ndef_aux->derbuf = p; ndef_aux->derbuf = p;

View File

@ -1,15 +1,34 @@
/* /*
* Auto generated with chartype.pl script. Mask of various character * WARNING: do not edit!
* properties * Generated by crypto/asn1/charmap.pl
*
* Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/ */
static const unsigned char char_type[] = { #define CHARTYPE_HOST_ANY 4096
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, #define CHARTYPE_HOST_DOT 8192
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, #define CHARTYPE_HOST_HYPHEN 16384
120, 0, 1, 40, 0, 0, 0, 16, 16, 16, 0, 25, 25, 16, 16, 16, #define CHARTYPE_HOST_WILD 32768
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 9, 9, 16, 9, 16,
0, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, /*
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 0, 1, 0, 0, 0, * Mask of various character properties
0, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, */
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 0, 0, 0, 0, 2
static const unsigned short char_type[] = {
1026, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 120, 0, 1, 40,
0, 0, 0, 16, 1040, 1040, 33792, 25, 25, 16400, 8208, 16,
4112, 4112, 4112, 4112, 4112, 4112, 4112, 4112, 4112, 4112, 16, 9,
9, 16, 9, 16, 0, 4112, 4112, 4112, 4112, 4112, 4112, 4112,
4112, 4112, 4112, 4112, 4112, 4112, 4112, 4112, 4112, 4112, 4112, 4112,
4112, 4112, 4112, 4112, 4112, 4112, 4112, 0, 1025, 0, 0, 0,
0, 4112, 4112, 4112, 4112, 4112, 4112, 4112, 4112, 4112, 4112, 4112,
4112, 4112, 4112, 4112, 4112, 4112, 4112, 4112, 4112, 4112, 4112, 4112,
4112, 4112, 4112, 0, 0, 0, 0, 2
}; };

View File

@ -1,72 +1,22 @@
/* crypto/asn1/d2i_pr.c */ /*
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
* All rights reserved.
* *
* This package is an SSL implementation written * Licensed under the OpenSSL license (the "License"). You may not use
* by Eric Young (eay@cryptsoft.com). * this file except in compliance with the License. You can obtain a copy
* The implementation was written so as to conform with Netscapes SSL. * in the file LICENSE in the source distribution or at
* * https://www.openssl.org/source/license.html
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* "This product includes cryptographic software written by
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/ */
#include <stdio.h> #include <stdio.h>
#include "cryptlib.h" #include "internal/cryptlib.h"
#include <openssl/bn.h> #include <openssl/bn.h>
#include <openssl/evp.h> #include <openssl/evp.h>
#include <openssl/objects.h> #include <openssl/objects.h>
#ifndef OPENSSL_NO_ENGINE #include <openssl/engine.h>
# include <openssl/engine.h>
#endif
#include <openssl/x509.h> #include <openssl/x509.h>
#include <openssl/asn1.h> #include <openssl/asn1.h>
#include "asn1_locl.h" #include "internal/asn1_int.h"
#include "internal/evp_int.h"
EVP_PKEY *d2i_PrivateKey(int type, EVP_PKEY **a, const unsigned char **pp, EVP_PKEY *d2i_PrivateKey(int type, EVP_PKEY **a, const unsigned char **pp,
long length) long length)
@ -82,10 +32,8 @@ EVP_PKEY *d2i_PrivateKey(int type, EVP_PKEY **a, const unsigned char **pp,
} else { } else {
ret = *a; ret = *a;
#ifndef OPENSSL_NO_ENGINE #ifndef OPENSSL_NO_ENGINE
if (ret->engine) {
ENGINE_finish(ret->engine); ENGINE_finish(ret->engine);
ret->engine = NULL; ret->engine = NULL;
}
#endif #endif
} }
@ -118,7 +66,7 @@ EVP_PKEY *d2i_PrivateKey(int type, EVP_PKEY **a, const unsigned char **pp,
(*a) = ret; (*a) = ret;
return (ret); return (ret);
err: err:
if ((ret != NULL) && ((a == NULL) || (*a != ret))) if (a == NULL || *a != ret)
EVP_PKEY_free(ret); EVP_PKEY_free(ret);
return (NULL); return (NULL);
} }

View File

@ -1,76 +1,23 @@
/* crypto/asn1/d2i_pu.c */ /*
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
* All rights reserved.
* *
* This package is an SSL implementation written * Licensed under the OpenSSL license (the "License"). You may not use
* by Eric Young (eay@cryptsoft.com). * this file except in compliance with the License. You can obtain a copy
* The implementation was written so as to conform with Netscapes SSL. * in the file LICENSE in the source distribution or at
* * https://www.openssl.org/source/license.html
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* "This product includes cryptographic software written by
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/ */
#include <stdio.h> #include <stdio.h>
#include "cryptlib.h" #include "internal/cryptlib.h"
#include <openssl/bn.h> #include <openssl/bn.h>
#include <openssl/evp.h> #include <openssl/evp.h>
#include <openssl/objects.h> #include <openssl/objects.h>
#include <openssl/asn1.h> #include <openssl/asn1.h>
#ifndef OPENSSL_NO_RSA #include <openssl/rsa.h>
# include <openssl/rsa.h> #include <openssl/dsa.h>
#endif #include <openssl/ec.h>
#ifndef OPENSSL_NO_DSA
# include <openssl/dsa.h> #include "internal/evp_int.h"
#endif
#ifndef OPENSSL_NO_EC
# include <openssl/ec.h>
#endif
EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **a, const unsigned char **pp, EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **a, const unsigned char **pp,
long length) long length)
@ -93,10 +40,7 @@ EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **a, const unsigned char **pp,
switch (EVP_PKEY_id(ret)) { switch (EVP_PKEY_id(ret)) {
#ifndef OPENSSL_NO_RSA #ifndef OPENSSL_NO_RSA
case EVP_PKEY_RSA: case EVP_PKEY_RSA:
/* TMP UGLY CAST */ if ((ret->pkey.rsa = d2i_RSAPublicKey(NULL, pp, length)) == NULL) {
if ((ret->pkey.rsa = d2i_RSAPublicKey(NULL,
(const unsigned char **)pp,
length)) == NULL) {
ASN1err(ASN1_F_D2I_PUBLICKEY, ERR_R_ASN1_LIB); ASN1err(ASN1_F_D2I_PUBLICKEY, ERR_R_ASN1_LIB);
goto err; goto err;
} }
@ -105,8 +49,7 @@ EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **a, const unsigned char **pp,
#ifndef OPENSSL_NO_DSA #ifndef OPENSSL_NO_DSA
case EVP_PKEY_DSA: case EVP_PKEY_DSA:
/* TMP UGLY CAST */ /* TMP UGLY CAST */
if (!d2i_DSAPublicKey(&(ret->pkey.dsa), if (!d2i_DSAPublicKey(&ret->pkey.dsa, pp, length)) {
(const unsigned char **)pp, length)) {
ASN1err(ASN1_F_D2I_PUBLICKEY, ERR_R_ASN1_LIB); ASN1err(ASN1_F_D2I_PUBLICKEY, ERR_R_ASN1_LIB);
goto err; goto err;
} }
@ -114,8 +57,7 @@ EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **a, const unsigned char **pp,
#endif #endif
#ifndef OPENSSL_NO_EC #ifndef OPENSSL_NO_EC
case EVP_PKEY_EC: case EVP_PKEY_EC:
if (!o2i_ECPublicKey(&(ret->pkey.ec), if (!o2i_ECPublicKey(&ret->pkey.ec, pp, length)) {
(const unsigned char **)pp, length)) {
ASN1err(ASN1_F_D2I_PUBLICKEY, ERR_R_ASN1_LIB); ASN1err(ASN1_F_D2I_PUBLICKEY, ERR_R_ASN1_LIB);
goto err; goto err;
} }
@ -130,7 +72,7 @@ EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **a, const unsigned char **pp,
(*a) = ret; (*a) = ret;
return (ret); return (ret);
err: err:
if ((ret != NULL) && ((a == NULL) || (*a != ret))) if (a == NULL || *a != ret)
EVP_PKEY_free(ret); EVP_PKEY_free(ret);
return (NULL); return (NULL);
} }

View File

@ -1,74 +1,25 @@
/* crypto/asn1/evp_asn1.c */ /*
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
* All rights reserved.
* *
* This package is an SSL implementation written * Licensed under the OpenSSL license (the "License"). You may not use
* by Eric Young (eay@cryptsoft.com). * this file except in compliance with the License. You can obtain a copy
* The implementation was written so as to conform with Netscapes SSL. * in the file LICENSE in the source distribution or at
* * https://www.openssl.org/source/license.html
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* "This product includes cryptographic software written by
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/ */
#include <stdio.h> #include <stdio.h>
#include "cryptlib.h" #include "internal/cryptlib.h"
#include <openssl/asn1.h> #include <openssl/asn1.h>
#include <openssl/asn1_mac.h> #include <openssl/asn1t.h>
int ASN1_TYPE_set_octetstring(ASN1_TYPE *a, unsigned char *data, int len) int ASN1_TYPE_set_octetstring(ASN1_TYPE *a, unsigned char *data, int len)
{ {
ASN1_STRING *os; ASN1_STRING *os;
if ((os = M_ASN1_OCTET_STRING_new()) == NULL) if ((os = ASN1_OCTET_STRING_new()) == NULL)
return (0); return (0);
if (!M_ASN1_OCTET_STRING_set(os, data, len)) { if (!ASN1_OCTET_STRING_set(os, data, len)) {
M_ASN1_OCTET_STRING_free(os); ASN1_OCTET_STRING_free(os);
return 0; return 0;
} }
ASN1_TYPE_set(a, V_ASN1_OCTET_STRING, os); ASN1_TYPE_set(a, V_ASN1_OCTET_STRING, os);
@ -76,17 +27,17 @@ int ASN1_TYPE_set_octetstring(ASN1_TYPE *a, unsigned char *data, int len)
} }
/* int max_len: for returned value */ /* int max_len: for returned value */
int ASN1_TYPE_get_octetstring(ASN1_TYPE *a, unsigned char *data, int max_len) int ASN1_TYPE_get_octetstring(const ASN1_TYPE *a, unsigned char *data, int max_len)
{ {
int ret, num; int ret, num;
unsigned char *p; const unsigned char *p;
if ((a->type != V_ASN1_OCTET_STRING) || (a->value.octet_string == NULL)) { if ((a->type != V_ASN1_OCTET_STRING) || (a->value.octet_string == NULL)) {
ASN1err(ASN1_F_ASN1_TYPE_GET_OCTETSTRING, ASN1_R_DATA_IS_WRONG); ASN1err(ASN1_F_ASN1_TYPE_GET_OCTETSTRING, ASN1_R_DATA_IS_WRONG);
return (-1); return (-1);
} }
p = M_ASN1_STRING_data(a->value.octet_string); p = ASN1_STRING_get0_data(a->value.octet_string);
ret = M_ASN1_STRING_length(a->value.octet_string); ret = ASN1_STRING_length(a->value.octet_string);
if (ret < max_len) if (ret < max_len)
num = ret; num = ret;
else else
@ -95,101 +46,70 @@ int ASN1_TYPE_get_octetstring(ASN1_TYPE *a, unsigned char *data, int max_len)
return (ret); return (ret);
} }
typedef struct {
long num;
ASN1_OCTET_STRING *oct;
} asn1_int_oct;
ASN1_SEQUENCE(asn1_int_oct) = {
ASN1_SIMPLE(asn1_int_oct, num, LONG),
ASN1_SIMPLE(asn1_int_oct, oct, ASN1_OCTET_STRING)
} static_ASN1_SEQUENCE_END(asn1_int_oct)
DECLARE_ASN1_ITEM(asn1_int_oct)
int ASN1_TYPE_set_int_octetstring(ASN1_TYPE *a, long num, unsigned char *data, int ASN1_TYPE_set_int_octetstring(ASN1_TYPE *a, long num, unsigned char *data,
int len) int len)
{ {
int n, size; asn1_int_oct atmp;
ASN1_OCTET_STRING os, *osp; ASN1_OCTET_STRING oct;
ASN1_INTEGER in;
unsigned char *p;
unsigned char buf[32]; /* when they have 256bit longs, I'll be in
* trouble */
in.data = buf;
in.length = 32;
os.data = data;
os.type = V_ASN1_OCTET_STRING;
os.length = len;
ASN1_INTEGER_set(&in, num);
n = i2d_ASN1_INTEGER(&in, NULL);
n += M_i2d_ASN1_OCTET_STRING(&os, NULL);
size = ASN1_object_size(1, n, V_ASN1_SEQUENCE); atmp.num = num;
atmp.oct = &oct;
oct.data = data;
oct.type = V_ASN1_OCTET_STRING;
oct.length = len;
oct.flags = 0;
if ((osp = ASN1_STRING_new()) == NULL) if (ASN1_TYPE_pack_sequence(ASN1_ITEM_rptr(asn1_int_oct), &atmp, &a))
return (0); return 1;
/* Grow the 'string' */ return 0;
if (!ASN1_STRING_set(osp, NULL, size)) {
ASN1_STRING_free(osp);
return (0);
}
M_ASN1_STRING_length_set(osp, size);
p = M_ASN1_STRING_data(osp);
ASN1_put_object(&p, 1, n, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL);
i2d_ASN1_INTEGER(&in, &p);
M_i2d_ASN1_OCTET_STRING(&os, &p);
ASN1_TYPE_set(a, V_ASN1_SEQUENCE, osp);
return (1);
} }
/* /*
* we return the actual length..., num may be missing, in which case, set it * we return the actual length...
* to zero
*/ */
/* int max_len: for returned value */ /* int max_len: for returned value */
int ASN1_TYPE_get_int_octetstring(ASN1_TYPE *a, long *num, int ASN1_TYPE_get_int_octetstring(const ASN1_TYPE *a, long *num,
unsigned char *data, int max_len) unsigned char *data, int max_len)
{ {
asn1_int_oct *atmp = NULL;
int ret = -1, n; int ret = -1, n;
ASN1_INTEGER *ai = NULL;
ASN1_OCTET_STRING *os = NULL;
const unsigned char *p;
long length;
ASN1_const_CTX c;
if ((a->type != V_ASN1_SEQUENCE) || (a->value.sequence == NULL)) { if ((a->type != V_ASN1_SEQUENCE) || (a->value.sequence == NULL)) {
goto err; goto err;
} }
p = M_ASN1_STRING_data(a->value.sequence);
length = M_ASN1_STRING_length(a->value.sequence);
c.pp = &p; atmp = ASN1_TYPE_unpack_sequence(ASN1_ITEM_rptr(asn1_int_oct), a);
c.p = p;
c.max = p + length;
c.error = ASN1_R_DATA_IS_WRONG;
M_ASN1_D2I_start_sequence(); if (atmp == NULL)
c.q = c.p;
if ((ai = d2i_ASN1_INTEGER(NULL, &c.p, c.slen)) == NULL)
goto err;
c.slen -= (c.p - c.q);
c.q = c.p;
if ((os = d2i_ASN1_OCTET_STRING(NULL, &c.p, c.slen)) == NULL)
goto err;
c.slen -= (c.p - c.q);
if (!M_ASN1_D2I_end_sequence())
goto err; goto err;
if (num != NULL) if (num != NULL)
*num = ASN1_INTEGER_get(ai); *num = atmp->num;
ret = M_ASN1_STRING_length(os); ret = ASN1_STRING_length(atmp->oct);
if (max_len > ret) if (max_len > ret)
n = ret; n = ret;
else else
n = max_len; n = max_len;
if (data != NULL) if (data != NULL)
memcpy(data, M_ASN1_STRING_data(os), n); memcpy(data, ASN1_STRING_get0_data(atmp->oct), n);
if (0) { if (ret == -1) {
err: err:
ASN1err(ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING, ASN1_R_DATA_IS_WRONG); ASN1err(ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING, ASN1_R_DATA_IS_WRONG);
} }
if (os != NULL) M_ASN1_free_of(atmp, asn1_int_oct);
M_ASN1_OCTET_STRING_free(os); return ret;
if (ai != NULL)
M_ASN1_INTEGER_free(ai);
return (ret);
} }

View File

@ -1,203 +0,0 @@
/* crypto/asn1/f_enum.c */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
* This package is an SSL implementation written
* by Eric Young (eay@cryptsoft.com).
* The implementation was written so as to conform with Netscapes SSL.
*
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* "This product includes cryptographic software written by
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/
#include <stdio.h>
#include "cryptlib.h"
#include <openssl/buffer.h>
#include <openssl/asn1.h>
/* Based on a_int.c: equivalent ENUMERATED functions */
int i2a_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *a)
{
int i, n = 0;
static const char *h = "0123456789ABCDEF";
char buf[2];
if (a == NULL)
return (0);
if (a->length == 0) {
if (BIO_write(bp, "00", 2) != 2)
goto err;
n = 2;
} else {
for (i = 0; i < a->length; i++) {
if ((i != 0) && (i % 35 == 0)) {
if (BIO_write(bp, "\\\n", 2) != 2)
goto err;
n += 2;
}
buf[0] = h[((unsigned char)a->data[i] >> 4) & 0x0f];
buf[1] = h[((unsigned char)a->data[i]) & 0x0f];
if (BIO_write(bp, buf, 2) != 2)
goto err;
n += 2;
}
}
return (n);
err:
return (-1);
}
int a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size)
{
int ret = 0;
int i, j, k, m, n, again, bufsize;
unsigned char *s = NULL, *sp;
unsigned char *bufp;
int num = 0, slen = 0, first = 1;
bs->type = V_ASN1_ENUMERATED;
bufsize = BIO_gets(bp, buf, size);
for (;;) {
if (bufsize < 1)
goto err_sl;
i = bufsize;
if (buf[i - 1] == '\n')
buf[--i] = '\0';
if (i == 0)
goto err_sl;
if (buf[i - 1] == '\r')
buf[--i] = '\0';
if (i == 0)
goto err_sl;
again = (buf[i - 1] == '\\');
for (j = 0; j < i; j++) {
if (!(((buf[j] >= '0') && (buf[j] <= '9')) ||
((buf[j] >= 'a') && (buf[j] <= 'f')) ||
((buf[j] >= 'A') && (buf[j] <= 'F')))) {
i = j;
break;
}
}
buf[i] = '\0';
/*
* We have now cleared all the crap off the end of the line
*/
if (i < 2)
goto err_sl;
bufp = (unsigned char *)buf;
if (first) {
first = 0;
if ((bufp[0] == '0') && (buf[1] == '0')) {
bufp += 2;
i -= 2;
}
}
k = 0;
i -= again;
if (i % 2 != 0) {
ASN1err(ASN1_F_A2I_ASN1_ENUMERATED, ASN1_R_ODD_NUMBER_OF_CHARS);
goto err;
}
i /= 2;
if (num + i > slen) {
if (s == NULL)
sp = (unsigned char *)OPENSSL_malloc((unsigned int)num +
i * 2);
else
sp = (unsigned char *)OPENSSL_realloc(s,
(unsigned int)num +
i * 2);
if (sp == NULL) {
ASN1err(ASN1_F_A2I_ASN1_ENUMERATED, ERR_R_MALLOC_FAILURE);
goto err;
}
s = sp;
slen = num + i * 2;
}
for (j = 0; j < i; j++, k += 2) {
for (n = 0; n < 2; n++) {
m = bufp[k + n];
if ((m >= '0') && (m <= '9'))
m -= '0';
else if ((m >= 'a') && (m <= 'f'))
m = m - 'a' + 10;
else if ((m >= 'A') && (m <= 'F'))
m = m - 'A' + 10;
else {
ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,
ASN1_R_NON_HEX_CHARACTERS);
goto err;
}
s[num + j] <<= 4;
s[num + j] |= m;
}
}
num += i;
if (again)
bufsize = BIO_gets(bp, buf, size);
else
break;
}
bs->length = num;
bs->data = s;
ret = 1;
err:
if (0) {
err_sl:
ASN1err(ASN1_F_A2I_ASN1_ENUMERATED, ASN1_R_SHORT_LINE);
}
if (ret != 1)
OPENSSL_free(s);
return (ret);
}

View File

@ -1,67 +1,19 @@
/* crypto/asn1/f_int.c */ /*
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
* All rights reserved.
* *
* This package is an SSL implementation written * Licensed under the OpenSSL license (the "License"). You may not use
* by Eric Young (eay@cryptsoft.com). * this file except in compliance with the License. You can obtain a copy
* The implementation was written so as to conform with Netscapes SSL. * in the file LICENSE in the source distribution or at
* * https://www.openssl.org/source/license.html
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* "This product includes cryptographic software written by
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/ */
#include <stdio.h> #include <stdio.h>
#include "cryptlib.h" #include <ctype.h>
#include "internal/cryptlib.h"
#include <openssl/buffer.h> #include <openssl/buffer.h>
#include <openssl/asn1.h> #include <openssl/asn1.h>
int i2a_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *a) int i2a_ASN1_INTEGER(BIO *bp, const ASN1_INTEGER *a)
{ {
int i, n = 0; int i, n = 0;
static const char *h = "0123456789ABCDEF"; static const char *h = "0123456789ABCDEF";
@ -101,7 +53,6 @@ int i2a_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *a)
int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size) int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size)
{ {
int ret = 0;
int i, j, k, m, n, again, bufsize; int i, j, k, m, n, again, bufsize;
unsigned char *s = NULL, *sp; unsigned char *s = NULL, *sp;
unsigned char *bufp; unsigned char *bufp;
@ -112,16 +63,16 @@ int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size)
bufsize = BIO_gets(bp, buf, size); bufsize = BIO_gets(bp, buf, size);
for (;;) { for (;;) {
if (bufsize < 1) if (bufsize < 1)
goto err_sl; goto err;
i = bufsize; i = bufsize;
if (buf[i - 1] == '\n') if (buf[i - 1] == '\n')
buf[--i] = '\0'; buf[--i] = '\0';
if (i == 0) if (i == 0)
goto err_sl; goto err;
if (buf[i - 1] == '\r') if (buf[i - 1] == '\r')
buf[--i] = '\0'; buf[--i] = '\0';
if (i == 0) if (i == 0)
goto err_sl; goto err;
again = (buf[i - 1] == '\\'); again = (buf[i - 1] == '\\');
for (j = 0; j < i; j++) { for (j = 0; j < i; j++) {
@ -147,7 +98,7 @@ int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size)
* We have now cleared all the crap off the end of the line * We have now cleared all the crap off the end of the line
*/ */
if (i < 2) if (i < 2)
goto err_sl; goto err;
bufp = (unsigned char *)buf; bufp = (unsigned char *)buf;
if (first) { if (first) {
@ -161,32 +112,24 @@ int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size)
i -= again; i -= again;
if (i % 2 != 0) { if (i % 2 != 0) {
ASN1err(ASN1_F_A2I_ASN1_INTEGER, ASN1_R_ODD_NUMBER_OF_CHARS); ASN1err(ASN1_F_A2I_ASN1_INTEGER, ASN1_R_ODD_NUMBER_OF_CHARS);
goto err; OPENSSL_free(s);
return 0;
} }
i /= 2; i /= 2;
if (num + i > slen) { if (num + i > slen) {
if (s == NULL) sp = OPENSSL_clear_realloc(s, slen, num + i * 2);
sp = (unsigned char *)OPENSSL_malloc((unsigned int)num +
i * 2);
else
sp = OPENSSL_realloc_clean(s, slen, num + i * 2);
if (sp == NULL) { if (sp == NULL) {
ASN1err(ASN1_F_A2I_ASN1_INTEGER, ERR_R_MALLOC_FAILURE); ASN1err(ASN1_F_A2I_ASN1_INTEGER, ERR_R_MALLOC_FAILURE);
goto err; OPENSSL_free(s);
return 0;
} }
s = sp; s = sp;
slen = num + i * 2; slen = num + i * 2;
} }
for (j = 0; j < i; j++, k += 2) { for (j = 0; j < i; j++, k += 2) {
for (n = 0; n < 2; n++) { for (n = 0; n < 2; n++) {
m = bufp[k + n]; m = OPENSSL_hexchar2int(bufp[k + n]);
if ((m >= '0') && (m <= '9')) if (m < 0) {
m -= '0';
else if ((m >= 'a') && (m <= 'f'))
m = m - 'a' + 10;
else if ((m >= 'A') && (m <= 'F'))
m = m - 'A' + 10;
else {
ASN1err(ASN1_F_A2I_ASN1_INTEGER, ASN1err(ASN1_F_A2I_ASN1_INTEGER,
ASN1_R_NON_HEX_CHARACTERS); ASN1_R_NON_HEX_CHARACTERS);
goto err; goto err;
@ -203,13 +146,22 @@ int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size)
} }
bs->length = num; bs->length = num;
bs->data = s; bs->data = s;
ret = 1; return 1;
err: err:
if (0) {
err_sl:
ASN1err(ASN1_F_A2I_ASN1_INTEGER, ASN1_R_SHORT_LINE); ASN1err(ASN1_F_A2I_ASN1_INTEGER, ASN1_R_SHORT_LINE);
}
if (ret != 1)
OPENSSL_free(s); OPENSSL_free(s);
return (ret); return 0;
}
int i2a_ASN1_ENUMERATED(BIO *bp, const ASN1_ENUMERATED *a)
{
return i2a_ASN1_INTEGER(bp, a);
}
int a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size)
{
int rv = a2i_ASN1_INTEGER(bp, bs, buf, size);
if (rv == 1)
bs->type = V_ASN1_INTEGER | (bs->type & V_ASN1_NEG);
return rv;
} }

View File

@ -1,67 +1,19 @@
/* crypto/asn1/f_string.c */ /*
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
* All rights reserved.
* *
* This package is an SSL implementation written * Licensed under the OpenSSL license (the "License"). You may not use
* by Eric Young (eay@cryptsoft.com). * this file except in compliance with the License. You can obtain a copy
* The implementation was written so as to conform with Netscapes SSL. * in the file LICENSE in the source distribution or at
* * https://www.openssl.org/source/license.html
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* "This product includes cryptographic software written by
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/ */
#include <stdio.h> #include <stdio.h>
#include "cryptlib.h" #include <ctype.h>
#include "internal/cryptlib.h"
#include <openssl/buffer.h> #include <openssl/buffer.h>
#include <openssl/asn1.h> #include <openssl/asn1.h>
int i2a_ASN1_STRING(BIO *bp, ASN1_STRING *a, int type) int i2a_ASN1_STRING(BIO *bp, const ASN1_STRING *a, int type)
{ {
int i, n = 0; int i, n = 0;
static const char *h = "0123456789ABCDEF"; static const char *h = "0123456789ABCDEF";
@ -95,8 +47,7 @@ int i2a_ASN1_STRING(BIO *bp, ASN1_STRING *a, int type)
int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size) int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size)
{ {
int ret = 0; int i, j, k, m, n, again, bufsize, spec_char;
int i, j, k, m, n, again, bufsize;
unsigned char *s = NULL, *sp; unsigned char *s = NULL, *sp;
unsigned char *bufp; unsigned char *bufp;
int num = 0, slen = 0, first = 1; int num = 0, slen = 0, first = 1;
@ -107,7 +58,7 @@ int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size)
if (first) if (first)
break; break;
else else
goto err_sl; goto err;
} }
first = 0; first = 0;
@ -115,27 +66,27 @@ int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size)
if (buf[i - 1] == '\n') if (buf[i - 1] == '\n')
buf[--i] = '\0'; buf[--i] = '\0';
if (i == 0) if (i == 0)
goto err_sl; goto err;
if (buf[i - 1] == '\r') if (buf[i - 1] == '\r')
buf[--i] = '\0'; buf[--i] = '\0';
if (i == 0) if (i == 0)
goto err_sl; goto err;
again = (buf[i - 1] == '\\'); again = (buf[i - 1] == '\\');
for (j = i - 1; j > 0; j--) { for (j = i - 1; j > 0; j--) {
#ifndef CHARSET_EBCDIC #ifndef CHARSET_EBCDIC
if (!(((buf[j] >= '0') && (buf[j] <= '9')) || spec_char = (!(((buf[j] >= '0') && (buf[j] <= '9')) ||
((buf[j] >= 'a') && (buf[j] <= 'f')) || ((buf[j] >= 'a') && (buf[j] <= 'f')) ||
((buf[j] >= 'A') && (buf[j] <= 'F')))) ((buf[j] >= 'A') && (buf[j] <= 'F'))));
#else #else
/* /*
* This #ifdef is not strictly necessary, since the characters * This #ifdef is not strictly necessary, since the characters
* A...F a...f 0...9 are contiguous (yes, even in EBCDIC - but * A...F a...f 0...9 are contiguous (yes, even in EBCDIC - but
* not the whole alphabet). Nevertheless, isxdigit() is faster. * not the whole alphabet). Nevertheless, isxdigit() is faster.
*/ */
if (!isxdigit(buf[j])) spec_char = (!isxdigit(buf[j]));
#endif #endif
{ if (spec_char) {
i = j; i = j;
break; break;
} }
@ -145,7 +96,7 @@ int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size)
* We have now cleared all the crap off the end of the line * We have now cleared all the crap off the end of the line
*/ */
if (i < 2) if (i < 2)
goto err_sl; goto err;
bufp = (unsigned char *)buf; bufp = (unsigned char *)buf;
@ -153,37 +104,28 @@ int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size)
i -= again; i -= again;
if (i % 2 != 0) { if (i % 2 != 0) {
ASN1err(ASN1_F_A2I_ASN1_STRING, ASN1_R_ODD_NUMBER_OF_CHARS); ASN1err(ASN1_F_A2I_ASN1_STRING, ASN1_R_ODD_NUMBER_OF_CHARS);
goto err; OPENSSL_free(s);
return 0;
} }
i /= 2; i /= 2;
if (num + i > slen) { if (num + i > slen) {
if (s == NULL) sp = OPENSSL_realloc(s, (unsigned int)num + i * 2);
sp = (unsigned char *)OPENSSL_malloc((unsigned int)num +
i * 2);
else
sp = (unsigned char *)OPENSSL_realloc(s,
(unsigned int)num +
i * 2);
if (sp == NULL) { if (sp == NULL) {
ASN1err(ASN1_F_A2I_ASN1_STRING, ERR_R_MALLOC_FAILURE); ASN1err(ASN1_F_A2I_ASN1_STRING, ERR_R_MALLOC_FAILURE);
goto err; OPENSSL_free(s);
return 0;
} }
s = sp; s = sp;
slen = num + i * 2; slen = num + i * 2;
} }
for (j = 0; j < i; j++, k += 2) { for (j = 0; j < i; j++, k += 2) {
for (n = 0; n < 2; n++) { for (n = 0; n < 2; n++) {
m = bufp[k + n]; m = OPENSSL_hexchar2int(bufp[k + n]);
if ((m >= '0') && (m <= '9')) if (m < 0) {
m -= '0';
else if ((m >= 'a') && (m <= 'f'))
m = m - 'a' + 10;
else if ((m >= 'A') && (m <= 'F'))
m = m - 'A' + 10;
else {
ASN1err(ASN1_F_A2I_ASN1_STRING, ASN1err(ASN1_F_A2I_ASN1_STRING,
ASN1_R_NON_HEX_CHARACTERS); ASN1_R_NON_HEX_CHARACTERS);
goto err; OPENSSL_free(s);
return 0;
} }
s[num + j] <<= 4; s[num + j] <<= 4;
s[num + j] |= m; s[num + j] |= m;
@ -197,13 +139,10 @@ int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size)
} }
bs->length = num; bs->length = num;
bs->data = s; bs->data = s;
ret = 1; return 1;
err: err:
if (0) {
err_sl:
ASN1err(ASN1_F_A2I_ASN1_STRING, ASN1_R_SHORT_LINE); ASN1err(ASN1_F_A2I_ASN1_STRING, ASN1_R_SHORT_LINE);
}
if (ret != 1)
OPENSSL_free(s); OPENSSL_free(s);
return (ret); return 0;
} }

View File

@ -1,66 +1,18 @@
/* crypto/asn1/i2d_pr.c */ /*
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
* All rights reserved.
* *
* This package is an SSL implementation written * Licensed under the OpenSSL license (the "License"). You may not use
* by Eric Young (eay@cryptsoft.com). * this file except in compliance with the License. You can obtain a copy
* The implementation was written so as to conform with Netscapes SSL. * in the file LICENSE in the source distribution or at
* * https://www.openssl.org/source/license.html
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* "This product includes cryptographic software written by
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/ */
#include <stdio.h> #include <stdio.h>
#include "cryptlib.h" #include "internal/cryptlib.h"
#include <openssl/evp.h> #include <openssl/evp.h>
#include <openssl/x509.h> #include <openssl/x509.h>
#include "asn1_locl.h" #include "internal/asn1_int.h"
#include "internal/evp_int.h"
int i2d_PrivateKey(EVP_PKEY *a, unsigned char **pp) int i2d_PrivateKey(EVP_PKEY *a, unsigned char **pp)
{ {

View File

@ -1,93 +1,38 @@
/* crypto/asn1/i2d_pu.c */ /*
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
* All rights reserved.
* *
* This package is an SSL implementation written * Licensed under the OpenSSL license (the "License"). You may not use
* by Eric Young (eay@cryptsoft.com). * this file except in compliance with the License. You can obtain a copy
* The implementation was written so as to conform with Netscapes SSL. * in the file LICENSE in the source distribution or at
* * https://www.openssl.org/source/license.html
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* "This product includes cryptographic software written by
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/ */
#include <stdio.h> #include <stdio.h>
#include "cryptlib.h" #include "internal/cryptlib.h"
#include <openssl/bn.h> #include <openssl/bn.h>
#include <openssl/evp.h> #include <openssl/evp.h>
#include <openssl/objects.h> #include <openssl/objects.h>
#ifndef OPENSSL_NO_RSA #include <openssl/rsa.h>
# include <openssl/rsa.h> #include <openssl/dsa.h>
#endif #include <openssl/ec.h>
#ifndef OPENSSL_NO_DSA
# include <openssl/dsa.h>
#endif
#ifndef OPENSSL_NO_EC
# include <openssl/ec.h>
#endif
int i2d_PublicKey(EVP_PKEY *a, unsigned char **pp) int i2d_PublicKey(EVP_PKEY *a, unsigned char **pp)
{ {
switch (a->type) { switch (EVP_PKEY_id(a)) {
#ifndef OPENSSL_NO_RSA #ifndef OPENSSL_NO_RSA
case EVP_PKEY_RSA: case EVP_PKEY_RSA:
return (i2d_RSAPublicKey(a->pkey.rsa, pp)); return i2d_RSAPublicKey(EVP_PKEY_get0_RSA(a), pp);
#endif #endif
#ifndef OPENSSL_NO_DSA #ifndef OPENSSL_NO_DSA
case EVP_PKEY_DSA: case EVP_PKEY_DSA:
return (i2d_DSAPublicKey(a->pkey.dsa, pp)); return i2d_DSAPublicKey(EVP_PKEY_get0_DSA(a), pp);
#endif #endif
#ifndef OPENSSL_NO_EC #ifndef OPENSSL_NO_EC
case EVP_PKEY_EC: case EVP_PKEY_EC:
return (i2o_ECPublicKey(a->pkey.ec, pp)); return i2o_ECPublicKey(EVP_PKEY_get0_EC_KEY(a), pp);
#endif #endif
default: default:
ASN1err(ASN1_F_I2D_PUBLICKEY, ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE); ASN1err(ASN1_F_I2D_PUBLICKEY, ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE);
return (-1); return -1;
} }
} }

View File

@ -1,68 +1,22 @@
/* crypto/asn1/n_pkey.c */ /*
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
* All rights reserved.
* *
* This package is an SSL implementation written * Licensed under the OpenSSL license (the "License"). You may not use
* by Eric Young (eay@cryptsoft.com). * this file except in compliance with the License. You can obtain a copy
* The implementation was written so as to conform with Netscapes SSL. * in the file LICENSE in the source distribution or at
* * https://www.openssl.org/source/license.html
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* "This product includes cryptographic software written by
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/ */
#include <stdio.h> #include "openssl/opensslconf.h"
#include "cryptlib.h" #ifdef OPENSSL_NO_RSA
#ifndef OPENSSL_NO_RSA NON_EMPTY_TRANSLATION_UNIT
#else
# include "internal/cryptlib.h"
# include <stdio.h>
# include <openssl/rsa.h> # include <openssl/rsa.h>
# include <openssl/objects.h> # include <openssl/objects.h>
# include <openssl/asn1t.h> # include <openssl/asn1t.h>
# include <openssl/asn1_mac.h>
# include <openssl/evp.h> # include <openssl/evp.h>
# include <openssl/x509.h> # include <openssl/x509.h>
@ -87,7 +41,7 @@ typedef struct netscape_encrypted_pkey_st {
ASN1_BROKEN_SEQUENCE(NETSCAPE_ENCRYPTED_PKEY) = { ASN1_BROKEN_SEQUENCE(NETSCAPE_ENCRYPTED_PKEY) = {
ASN1_SIMPLE(NETSCAPE_ENCRYPTED_PKEY, os, ASN1_OCTET_STRING), ASN1_SIMPLE(NETSCAPE_ENCRYPTED_PKEY, os, ASN1_OCTET_STRING),
ASN1_SIMPLE(NETSCAPE_ENCRYPTED_PKEY, enckey, X509_SIG) ASN1_SIMPLE(NETSCAPE_ENCRYPTED_PKEY, enckey, X509_SIG)
} ASN1_BROKEN_SEQUENCE_END(NETSCAPE_ENCRYPTED_PKEY) } static_ASN1_BROKEN_SEQUENCE_END(NETSCAPE_ENCRYPTED_PKEY)
DECLARE_ASN1_FUNCTIONS_const(NETSCAPE_ENCRYPTED_PKEY) DECLARE_ASN1_FUNCTIONS_const(NETSCAPE_ENCRYPTED_PKEY)
DECLARE_ASN1_ENCODE_FUNCTIONS_const(NETSCAPE_ENCRYPTED_PKEY,NETSCAPE_ENCRYPTED_PKEY) DECLARE_ASN1_ENCODE_FUNCTIONS_const(NETSCAPE_ENCRYPTED_PKEY,NETSCAPE_ENCRYPTED_PKEY)
@ -97,258 +51,12 @@ ASN1_SEQUENCE(NETSCAPE_PKEY) = {
ASN1_SIMPLE(NETSCAPE_PKEY, version, LONG), ASN1_SIMPLE(NETSCAPE_PKEY, version, LONG),
ASN1_SIMPLE(NETSCAPE_PKEY, algor, X509_ALGOR), ASN1_SIMPLE(NETSCAPE_PKEY, algor, X509_ALGOR),
ASN1_SIMPLE(NETSCAPE_PKEY, private_key, ASN1_OCTET_STRING) ASN1_SIMPLE(NETSCAPE_PKEY, private_key, ASN1_OCTET_STRING)
} ASN1_SEQUENCE_END(NETSCAPE_PKEY) } static_ASN1_SEQUENCE_END(NETSCAPE_PKEY)
DECLARE_ASN1_FUNCTIONS_const(NETSCAPE_PKEY) DECLARE_ASN1_FUNCTIONS_const(NETSCAPE_PKEY)
DECLARE_ASN1_ENCODE_FUNCTIONS_const(NETSCAPE_PKEY,NETSCAPE_PKEY) DECLARE_ASN1_ENCODE_FUNCTIONS_const(NETSCAPE_PKEY,NETSCAPE_PKEY)
IMPLEMENT_ASN1_FUNCTIONS_const(NETSCAPE_PKEY) IMPLEMENT_ASN1_FUNCTIONS_const(NETSCAPE_PKEY)
static RSA *d2i_RSA_NET_2(RSA **a, ASN1_OCTET_STRING *os,
int (*cb) (char *buf, int len, const char *prompt,
int verify), int sgckey);
int i2d_Netscape_RSA(const RSA *a, unsigned char **pp,
int (*cb) (char *buf, int len, const char *prompt,
int verify))
{
return i2d_RSA_NET(a, pp, cb, 0);
}
int i2d_RSA_NET(const RSA *a, unsigned char **pp,
int (*cb) (char *buf, int len, const char *prompt,
int verify), int sgckey)
{
int i, j, ret = 0;
int rsalen, pkeylen, olen;
NETSCAPE_PKEY *pkey = NULL;
NETSCAPE_ENCRYPTED_PKEY *enckey = NULL;
unsigned char buf[256], *zz;
unsigned char key[EVP_MAX_KEY_LENGTH];
EVP_CIPHER_CTX ctx;
EVP_CIPHER_CTX_init(&ctx);
if (a == NULL)
return (0);
if ((pkey = NETSCAPE_PKEY_new()) == NULL)
goto err;
if ((enckey = NETSCAPE_ENCRYPTED_PKEY_new()) == NULL)
goto err;
pkey->version = 0;
pkey->algor->algorithm = OBJ_nid2obj(NID_rsaEncryption);
if ((pkey->algor->parameter = ASN1_TYPE_new()) == NULL)
goto err;
pkey->algor->parameter->type = V_ASN1_NULL;
rsalen = i2d_RSAPrivateKey(a, NULL);
/*
* Fake some octet strings just for the initial length calculation.
*/
pkey->private_key->length = rsalen;
pkeylen = i2d_NETSCAPE_PKEY(pkey, NULL);
enckey->enckey->digest->length = pkeylen;
enckey->os->length = 11; /* "private-key" */
enckey->enckey->algor->algorithm = OBJ_nid2obj(NID_rc4);
if ((enckey->enckey->algor->parameter = ASN1_TYPE_new()) == NULL)
goto err;
enckey->enckey->algor->parameter->type = V_ASN1_NULL;
if (pp == NULL) {
olen = i2d_NETSCAPE_ENCRYPTED_PKEY(enckey, NULL);
NETSCAPE_PKEY_free(pkey);
NETSCAPE_ENCRYPTED_PKEY_free(enckey);
return olen;
}
/* Since its RC4 encrypted length is actual length */
if ((zz = (unsigned char *)OPENSSL_malloc(rsalen)) == NULL) {
ASN1err(ASN1_F_I2D_RSA_NET, ERR_R_MALLOC_FAILURE);
goto err;
}
pkey->private_key->data = zz;
/* Write out private key encoding */
i2d_RSAPrivateKey(a, &zz);
if ((zz = OPENSSL_malloc(pkeylen)) == NULL) {
ASN1err(ASN1_F_I2D_RSA_NET, ERR_R_MALLOC_FAILURE);
goto err;
}
if (!ASN1_STRING_set(enckey->os, "private-key", -1)) {
ASN1err(ASN1_F_I2D_RSA_NET, ERR_R_MALLOC_FAILURE);
goto err;
}
enckey->enckey->digest->data = zz;
i2d_NETSCAPE_PKEY(pkey, &zz);
/* Wipe the private key encoding */
OPENSSL_cleanse(pkey->private_key->data, rsalen);
if (cb == NULL)
#ifndef OPENSSL_NO_UI
cb = EVP_read_pw_string;
#else
i = 1;
else
#endif
i = cb((char *)buf, 256, "Enter Private Key password:", 1);
if (i != 0) {
ASN1err(ASN1_F_I2D_RSA_NET, ASN1_R_BAD_PASSWORD_READ);
goto err;
}
i = strlen((char *)buf);
/* If the key is used for SGC the algorithm is modified a little. */
if (sgckey) {
if (!EVP_Digest(buf, i, buf, NULL, EVP_md5(), NULL))
goto err;
memcpy(buf + 16, "SGCKEYSALT", 10);
i = 26;
}
if (!EVP_BytesToKey(EVP_rc4(), EVP_md5(), NULL, buf, i, 1, key, NULL))
goto err;
OPENSSL_cleanse(buf, 256);
/* Encrypt private key in place */
zz = enckey->enckey->digest->data;
if (!EVP_EncryptInit_ex(&ctx, EVP_rc4(), NULL, key, NULL))
goto err;
if (!EVP_EncryptUpdate(&ctx, zz, &i, zz, pkeylen))
goto err;
if (!EVP_EncryptFinal_ex(&ctx, zz + i, &j))
goto err;
ret = i2d_NETSCAPE_ENCRYPTED_PKEY(enckey, pp);
err:
EVP_CIPHER_CTX_cleanup(&ctx);
NETSCAPE_ENCRYPTED_PKEY_free(enckey);
NETSCAPE_PKEY_free(pkey);
return (ret);
}
RSA *d2i_Netscape_RSA(RSA **a, const unsigned char **pp, long length,
int (*cb) (char *buf, int len, const char *prompt,
int verify))
{
return d2i_RSA_NET(a, pp, length, cb, 0);
}
RSA *d2i_RSA_NET(RSA **a, const unsigned char **pp, long length,
int (*cb) (char *buf, int len, const char *prompt,
int verify), int sgckey)
{
RSA *ret = NULL;
const unsigned char *p;
NETSCAPE_ENCRYPTED_PKEY *enckey = NULL;
p = *pp;
enckey = d2i_NETSCAPE_ENCRYPTED_PKEY(NULL, &p, length);
if (!enckey) {
ASN1err(ASN1_F_D2I_RSA_NET, ASN1_R_DECODING_ERROR);
return NULL;
}
if ((enckey->os->length != 11) || (strncmp("private-key",
(char *)enckey->os->data,
11) != 0)) {
ASN1err(ASN1_F_D2I_RSA_NET, ASN1_R_PRIVATE_KEY_HEADER_MISSING);
NETSCAPE_ENCRYPTED_PKEY_free(enckey);
return NULL;
}
if (OBJ_obj2nid(enckey->enckey->algor->algorithm) != NID_rc4) {
ASN1err(ASN1_F_D2I_RSA_NET, ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM);
goto err;
}
if (cb == NULL)
#ifndef OPENSSL_NO_UI
cb = EVP_read_pw_string;
#else
goto err;
#endif
if ((ret = d2i_RSA_NET_2(a, enckey->enckey->digest, cb, sgckey)) == NULL)
goto err;
*pp = p;
err:
NETSCAPE_ENCRYPTED_PKEY_free(enckey);
return ret;
}
static RSA *d2i_RSA_NET_2(RSA **a, ASN1_OCTET_STRING *os,
int (*cb) (char *buf, int len, const char *prompt,
int verify), int sgckey)
{
NETSCAPE_PKEY *pkey = NULL;
RSA *ret = NULL;
int i, j;
unsigned char buf[256];
const unsigned char *zz;
unsigned char key[EVP_MAX_KEY_LENGTH];
EVP_CIPHER_CTX ctx;
EVP_CIPHER_CTX_init(&ctx);
i = cb((char *)buf, 256, "Enter Private Key password:", 0);
if (i != 0) {
ASN1err(ASN1_F_D2I_RSA_NET_2, ASN1_R_BAD_PASSWORD_READ);
goto err;
}
i = strlen((char *)buf);
if (sgckey) {
if (!EVP_Digest(buf, i, buf, NULL, EVP_md5(), NULL))
goto err;
memcpy(buf + 16, "SGCKEYSALT", 10);
i = 26;
}
if (!EVP_BytesToKey(EVP_rc4(), EVP_md5(), NULL, buf, i, 1, key, NULL))
goto err;
OPENSSL_cleanse(buf, 256);
if (!EVP_DecryptInit_ex(&ctx, EVP_rc4(), NULL, key, NULL))
goto err;
if (!EVP_DecryptUpdate(&ctx, os->data, &i, os->data, os->length))
goto err;
if (!EVP_DecryptFinal_ex(&ctx, &(os->data[i]), &j))
goto err;
os->length = i + j;
zz = os->data;
if ((pkey = d2i_NETSCAPE_PKEY(NULL, &zz, os->length)) == NULL) {
ASN1err(ASN1_F_D2I_RSA_NET_2,
ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY);
goto err;
}
zz = pkey->private_key->data;
if ((ret = d2i_RSAPrivateKey(a, &zz, pkey->private_key->length)) == NULL) {
ASN1err(ASN1_F_D2I_RSA_NET_2, ASN1_R_UNABLE_TO_DECODE_RSA_KEY);
goto err;
}
err:
EVP_CIPHER_CTX_cleanup(&ctx);
NETSCAPE_PKEY_free(pkey);
return (ret);
}
# endif /* OPENSSL_NO_RC4 */ # endif /* OPENSSL_NO_RC4 */
#else /* !OPENSSL_NO_RSA */
# if PEDANTIC
static void *dummy = &dummy;
# endif
#endif #endif

View File

@ -1,60 +1,10 @@
/* nsseq.c */
/* /*
* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved.
* 1999.
*/
/* ====================================================================
* Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
*
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* licensing@OpenSSL.org.
*
* 5. Products derived from this software may not be called "OpenSSL"
* nor may "OpenSSL" appear in their names without prior written
* permission of the OpenSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*
* This product includes cryptographic software written by Eric Young
* (eay@cryptsoft.com). This product includes software written by Tim
* Hudson (tjh@cryptsoft.com).
* *
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/ */
#include <stdio.h> #include <stdio.h>

View File

@ -1,64 +1,14 @@
/* p5_pbe.c */
/* /*
* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved.
* 1999.
*/
/* ====================================================================
* Copyright (c) 1999 The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
*
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* licensing@OpenSSL.org.
*
* 5. Products derived from this software may not be called "OpenSSL"
* nor may "OpenSSL" appear in their names without prior written
* permission of the OpenSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*
* This product includes cryptographic software written by Eric Young
* (eay@cryptsoft.com). This product includes software written by Tim
* Hudson (tjh@cryptsoft.com).
* *
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/ */
#include <stdio.h> #include <stdio.h>
#include "cryptlib.h" #include "internal/cryptlib.h"
#include <openssl/asn1t.h> #include <openssl/asn1t.h>
#include <openssl/x509.h> #include <openssl/x509.h>
#include <openssl/rand.h> #include <openssl/rand.h>
@ -79,10 +29,10 @@ int PKCS5_pbe_set0_algor(X509_ALGOR *algor, int alg, int iter,
{ {
PBEPARAM *pbe = NULL; PBEPARAM *pbe = NULL;
ASN1_STRING *pbe_str = NULL; ASN1_STRING *pbe_str = NULL;
unsigned char *sstr; unsigned char *sstr = NULL;
pbe = PBEPARAM_new(); pbe = PBEPARAM_new();
if (!pbe) { if (pbe == NULL) {
ASN1err(ASN1_F_PKCS5_PBE_SET0_ALGOR, ERR_R_MALLOC_FAILURE); ASN1err(ASN1_F_PKCS5_PBE_SET0_ALGOR, ERR_R_MALLOC_FAILURE);
goto err; goto err;
} }
@ -94,16 +44,20 @@ int PKCS5_pbe_set0_algor(X509_ALGOR *algor, int alg, int iter,
} }
if (!saltlen) if (!saltlen)
saltlen = PKCS5_SALT_LEN; saltlen = PKCS5_SALT_LEN;
if (!ASN1_STRING_set(pbe->salt, NULL, saltlen)) {
sstr = OPENSSL_malloc(saltlen);
if (sstr == NULL) {
ASN1err(ASN1_F_PKCS5_PBE_SET0_ALGOR, ERR_R_MALLOC_FAILURE); ASN1err(ASN1_F_PKCS5_PBE_SET0_ALGOR, ERR_R_MALLOC_FAILURE);
goto err; goto err;
} }
sstr = ASN1_STRING_data(pbe->salt);
if (salt) if (salt)
memcpy(sstr, salt, saltlen); memcpy(sstr, salt, saltlen);
else if (RAND_bytes(sstr, saltlen) <= 0) else if (RAND_bytes(sstr, saltlen) <= 0)
goto err; goto err;
ASN1_STRING_set0(pbe->salt, sstr, saltlen);
sstr = NULL;
if (!ASN1_item_pack(pbe, ASN1_ITEM_rptr(PBEPARAM), &pbe_str)) { if (!ASN1_item_pack(pbe, ASN1_ITEM_rptr(PBEPARAM), &pbe_str)) {
ASN1err(ASN1_F_PKCS5_PBE_SET0_ALGOR, ERR_R_MALLOC_FAILURE); ASN1err(ASN1_F_PKCS5_PBE_SET0_ALGOR, ERR_R_MALLOC_FAILURE);
goto err; goto err;
@ -116,9 +70,8 @@ int PKCS5_pbe_set0_algor(X509_ALGOR *algor, int alg, int iter,
return 1; return 1;
err: err:
if (pbe != NULL) OPENSSL_free(sstr);
PBEPARAM_free(pbe); PBEPARAM_free(pbe);
if (pbe_str != NULL)
ASN1_STRING_free(pbe_str); ASN1_STRING_free(pbe_str);
return 0; return 0;
} }
@ -130,7 +83,7 @@ X509_ALGOR *PKCS5_pbe_set(int alg, int iter,
{ {
X509_ALGOR *ret; X509_ALGOR *ret;
ret = X509_ALGOR_new(); ret = X509_ALGOR_new();
if (!ret) { if (ret == NULL) {
ASN1err(ASN1_F_PKCS5_PBE_SET, ERR_R_MALLOC_FAILURE); ASN1err(ASN1_F_PKCS5_PBE_SET, ERR_R_MALLOC_FAILURE);
return NULL; return NULL;
} }

View File

@ -1,64 +1,14 @@
/* p5_pbev2.c */
/* /*
* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved.
* 1999-2004.
*/
/* ====================================================================
* Copyright (c) 1999 The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
*
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* licensing@OpenSSL.org.
*
* 5. Products derived from this software may not be called "OpenSSL"
* nor may "OpenSSL" appear in their names without prior written
* permission of the OpenSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*
* This product includes cryptographic software written by Eric Young
* (eay@cryptsoft.com). This product includes software written by Tim
* Hudson (tjh@cryptsoft.com).
* *
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/ */
#include <stdio.h> #include <stdio.h>
#include "cryptlib.h" #include "internal/cryptlib.h"
#include <openssl/asn1t.h> #include <openssl/asn1t.h>
#include <openssl/x509.h> #include <openssl/x509.h>
#include <openssl/rand.h> #include <openssl/rand.h>
@ -93,7 +43,7 @@ X509_ALGOR *PKCS5_pbe2_set_iv(const EVP_CIPHER *cipher, int iter,
{ {
X509_ALGOR *scheme = NULL, *ret = NULL; X509_ALGOR *scheme = NULL, *ret = NULL;
int alg_nid, keylen; int alg_nid, keylen;
EVP_CIPHER_CTX ctx; EVP_CIPHER_CTX *ctx = NULL;
unsigned char iv[EVP_MAX_IV_LENGTH]; unsigned char iv[EVP_MAX_IV_LENGTH];
PBE2PARAM *pbe2 = NULL; PBE2PARAM *pbe2 = NULL;
@ -104,14 +54,13 @@ X509_ALGOR *PKCS5_pbe2_set_iv(const EVP_CIPHER *cipher, int iter,
goto err; goto err;
} }
if (!(pbe2 = PBE2PARAM_new())) if ((pbe2 = PBE2PARAM_new()) == NULL)
goto merr; goto merr;
/* Setup the AlgorithmIdentifier for the encryption scheme */ /* Setup the AlgorithmIdentifier for the encryption scheme */
scheme = pbe2->encryption; scheme = pbe2->encryption;
scheme->algorithm = OBJ_nid2obj(alg_nid); scheme->algorithm = OBJ_nid2obj(alg_nid);
if (!(scheme->parameter = ASN1_TYPE_new())) if ((scheme->parameter = ASN1_TYPE_new()) == NULL)
goto merr; goto merr;
/* Create random IV */ /* Create random IV */
@ -122,14 +71,15 @@ X509_ALGOR *PKCS5_pbe2_set_iv(const EVP_CIPHER *cipher, int iter,
goto err; goto err;
} }
EVP_CIPHER_CTX_init(&ctx); ctx = EVP_CIPHER_CTX_new();
if (ctx == NULL)
goto merr;
/* Dummy cipherinit to just setup the IV, and PRF */ /* Dummy cipherinit to just setup the IV, and PRF */
if (!EVP_CipherInit_ex(&ctx, cipher, NULL, NULL, iv, 0)) if (!EVP_CipherInit_ex(ctx, cipher, NULL, NULL, iv, 0))
goto err; goto err;
if (EVP_CIPHER_param_to_asn1(&ctx, scheme->parameter) < 0) { if (EVP_CIPHER_param_to_asn1(ctx, scheme->parameter) < 0) {
ASN1err(ASN1_F_PKCS5_PBE2_SET_IV, ASN1_R_ERROR_SETTING_CIPHER_PARAMS); ASN1err(ASN1_F_PKCS5_PBE2_SET_IV, ASN1_R_ERROR_SETTING_CIPHER_PARAMS);
EVP_CIPHER_CTX_cleanup(&ctx);
goto err; goto err;
} }
/* /*
@ -137,11 +87,12 @@ X509_ALGOR *PKCS5_pbe2_set_iv(const EVP_CIPHER *cipher, int iter,
* here: just means use default PRF. * here: just means use default PRF.
*/ */
if ((prf_nid == -1) && if ((prf_nid == -1) &&
EVP_CIPHER_CTX_ctrl(&ctx, EVP_CTRL_PBE_PRF_NID, 0, &prf_nid) <= 0) { EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_PBE_PRF_NID, 0, &prf_nid) <= 0) {
ERR_clear_error(); ERR_clear_error();
prf_nid = NID_hmacWithSHA1; prf_nid = NID_hmacWithSHA256;
} }
EVP_CIPHER_CTX_cleanup(&ctx); EVP_CIPHER_CTX_free(ctx);
ctx = NULL;
/* If its RC2 then we'd better setup the key length */ /* If its RC2 then we'd better setup the key length */
@ -161,19 +112,16 @@ X509_ALGOR *PKCS5_pbe2_set_iv(const EVP_CIPHER *cipher, int iter,
/* Now set up top level AlgorithmIdentifier */ /* Now set up top level AlgorithmIdentifier */
if (!(ret = X509_ALGOR_new())) if ((ret = X509_ALGOR_new()) == NULL)
goto merr;
if (!(ret->parameter = ASN1_TYPE_new()))
goto merr; goto merr;
ret->algorithm = OBJ_nid2obj(NID_pbes2); ret->algorithm = OBJ_nid2obj(NID_pbes2);
/* Encode PBE2PARAM into parameter */ /* Encode PBE2PARAM into parameter */
if (!ASN1_item_pack(pbe2, ASN1_ITEM_rptr(PBE2PARAM), if (!ASN1_TYPE_pack_sequence(ASN1_ITEM_rptr(PBE2PARAM), pbe2,
&ret->parameter->value.sequence)) &ret->parameter))
goto merr; goto merr;
ret->parameter->type = V_ASN1_SEQUENCE;
PBE2PARAM_free(pbe2); PBE2PARAM_free(pbe2);
pbe2 = NULL; pbe2 = NULL;
@ -184,6 +132,7 @@ X509_ALGOR *PKCS5_pbe2_set_iv(const EVP_CIPHER *cipher, int iter,
ASN1err(ASN1_F_PKCS5_PBE2_SET_IV, ERR_R_MALLOC_FAILURE); ASN1err(ASN1_F_PKCS5_PBE2_SET_IV, ERR_R_MALLOC_FAILURE);
err: err:
EVP_CIPHER_CTX_free(ctx);
PBE2PARAM_free(pbe2); PBE2PARAM_free(pbe2);
/* Note 'scheme' is freed as part of pbe2 */ /* Note 'scheme' is freed as part of pbe2 */
X509_ALGOR_free(ret); X509_ALGOR_free(ret);
@ -204,17 +153,17 @@ X509_ALGOR *PKCS5_pbkdf2_set(int iter, unsigned char *salt, int saltlen,
PBKDF2PARAM *kdf = NULL; PBKDF2PARAM *kdf = NULL;
ASN1_OCTET_STRING *osalt = NULL; ASN1_OCTET_STRING *osalt = NULL;
if (!(kdf = PBKDF2PARAM_new())) if ((kdf = PBKDF2PARAM_new()) == NULL)
goto merr; goto merr;
if (!(osalt = M_ASN1_OCTET_STRING_new())) if ((osalt = ASN1_OCTET_STRING_new()) == NULL)
goto merr; goto merr;
kdf->salt->value.octet_string = osalt; kdf->salt->value.octet_string = osalt;
kdf->salt->type = V_ASN1_OCTET_STRING; kdf->salt->type = V_ASN1_OCTET_STRING;
if (!saltlen) if (saltlen == 0)
saltlen = PKCS5_SALT_LEN; saltlen = PKCS5_SALT_LEN;
if (!(osalt->data = OPENSSL_malloc(saltlen))) if ((osalt->data = OPENSSL_malloc(saltlen)) == NULL)
goto merr; goto merr;
osalt->length = saltlen; osalt->length = saltlen;
@ -233,7 +182,7 @@ X509_ALGOR *PKCS5_pbkdf2_set(int iter, unsigned char *salt, int saltlen,
/* If have a key len set it up */ /* If have a key len set it up */
if (keylen > 0) { if (keylen > 0) {
if (!(kdf->keylength = M_ASN1_INTEGER_new())) if ((kdf->keylength = ASN1_INTEGER_new()) == NULL)
goto merr; goto merr;
if (!ASN1_INTEGER_set(kdf->keylength, keylen)) if (!ASN1_INTEGER_set(kdf->keylength, keylen))
goto merr; goto merr;
@ -242,7 +191,7 @@ X509_ALGOR *PKCS5_pbkdf2_set(int iter, unsigned char *salt, int saltlen,
/* prf can stay NULL if we are using hmacWithSHA1 */ /* prf can stay NULL if we are using hmacWithSHA1 */
if (prf_nid > 0 && prf_nid != NID_hmacWithSHA1) { if (prf_nid > 0 && prf_nid != NID_hmacWithSHA1) {
kdf->prf = X509_ALGOR_new(); kdf->prf = X509_ALGOR_new();
if (!kdf->prf) if (kdf->prf == NULL)
goto merr; goto merr;
X509_ALGOR_set0(kdf->prf, OBJ_nid2obj(prf_nid), V_ASN1_NULL, NULL); X509_ALGOR_set0(kdf->prf, OBJ_nid2obj(prf_nid), V_ASN1_NULL, NULL);
} }
@ -250,21 +199,17 @@ X509_ALGOR *PKCS5_pbkdf2_set(int iter, unsigned char *salt, int saltlen,
/* Finally setup the keyfunc structure */ /* Finally setup the keyfunc structure */
keyfunc = X509_ALGOR_new(); keyfunc = X509_ALGOR_new();
if (!keyfunc) if (keyfunc == NULL)
goto merr; goto merr;
keyfunc->algorithm = OBJ_nid2obj(NID_id_pbkdf2); keyfunc->algorithm = OBJ_nid2obj(NID_id_pbkdf2);
/* Encode PBKDF2PARAM into parameter of pbe2 */ /* Encode PBKDF2PARAM into parameter of pbe2 */
if (!(keyfunc->parameter = ASN1_TYPE_new())) if (!ASN1_TYPE_pack_sequence(ASN1_ITEM_rptr(PBKDF2PARAM), kdf,
&keyfunc->parameter))
goto merr; goto merr;
if (!ASN1_item_pack(kdf, ASN1_ITEM_rptr(PBKDF2PARAM),
&keyfunc->parameter->value.sequence))
goto merr;
keyfunc->parameter->type = V_ASN1_SEQUENCE;
PBKDF2PARAM_free(kdf); PBKDF2PARAM_free(kdf);
return keyfunc; return keyfunc;

View File

@ -0,0 +1,283 @@
/*
* Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
#include <stdio.h>
#include "internal/cryptlib.h"
#include <openssl/asn1t.h>
#include <openssl/err.h>
#include <openssl/evp.h>
#include <openssl/x509.h>
#include <openssl/rand.h>
#ifndef OPENSSL_NO_SCRYPT
/* PKCS#5 scrypt password based encryption structures */
typedef struct {
ASN1_OCTET_STRING *salt;
ASN1_INTEGER *costParameter;
ASN1_INTEGER *blockSize;
ASN1_INTEGER *parallelizationParameter;
ASN1_INTEGER *keyLength;
} SCRYPT_PARAMS;
ASN1_SEQUENCE(SCRYPT_PARAMS) = {
ASN1_SIMPLE(SCRYPT_PARAMS, salt, ASN1_OCTET_STRING),
ASN1_SIMPLE(SCRYPT_PARAMS, costParameter, ASN1_INTEGER),
ASN1_SIMPLE(SCRYPT_PARAMS, blockSize, ASN1_INTEGER),
ASN1_SIMPLE(SCRYPT_PARAMS, parallelizationParameter, ASN1_INTEGER),
ASN1_OPT(SCRYPT_PARAMS, keyLength, ASN1_INTEGER),
} static_ASN1_SEQUENCE_END(SCRYPT_PARAMS)
DECLARE_ASN1_ALLOC_FUNCTIONS(SCRYPT_PARAMS)
IMPLEMENT_ASN1_ALLOC_FUNCTIONS(SCRYPT_PARAMS)
static X509_ALGOR *pkcs5_scrypt_set(const unsigned char *salt, size_t saltlen,
size_t keylen, uint64_t N, uint64_t r,
uint64_t p);
/*
* Return an algorithm identifier for a PKCS#5 v2.0 PBE algorithm using scrypt
*/
X509_ALGOR *PKCS5_pbe2_set_scrypt(const EVP_CIPHER *cipher,
const unsigned char *salt, int saltlen,
unsigned char *aiv, uint64_t N, uint64_t r,
uint64_t p)
{
X509_ALGOR *scheme = NULL, *ret = NULL;
int alg_nid;
size_t keylen = 0;
EVP_CIPHER_CTX *ctx = NULL;
unsigned char iv[EVP_MAX_IV_LENGTH];
PBE2PARAM *pbe2 = NULL;
if (!cipher) {
ASN1err(ASN1_F_PKCS5_PBE2_SET_SCRYPT, ERR_R_PASSED_NULL_PARAMETER);
goto err;
}
if (EVP_PBE_scrypt(NULL, 0, NULL, 0, N, r, p, 0, NULL, 0) == 0) {
ASN1err(ASN1_F_PKCS5_PBE2_SET_SCRYPT,
ASN1_R_INVALID_SCRYPT_PARAMETERS);
goto err;
}
alg_nid = EVP_CIPHER_type(cipher);
if (alg_nid == NID_undef) {
ASN1err(ASN1_F_PKCS5_PBE2_SET_SCRYPT,
ASN1_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER);
goto err;
}
pbe2 = PBE2PARAM_new();
if (pbe2 == NULL)
goto merr;
/* Setup the AlgorithmIdentifier for the encryption scheme */
scheme = pbe2->encryption;
scheme->algorithm = OBJ_nid2obj(alg_nid);
scheme->parameter = ASN1_TYPE_new();
if (scheme->parameter == NULL)
goto merr;
/* Create random IV */
if (EVP_CIPHER_iv_length(cipher)) {
if (aiv)
memcpy(iv, aiv, EVP_CIPHER_iv_length(cipher));
else if (RAND_bytes(iv, EVP_CIPHER_iv_length(cipher)) < 0)
goto err;
}
ctx = EVP_CIPHER_CTX_new();
if (ctx == NULL)
goto merr;
/* Dummy cipherinit to just setup the IV */
if (EVP_CipherInit_ex(ctx, cipher, NULL, NULL, iv, 0) == 0)
goto err;
if (EVP_CIPHER_param_to_asn1(ctx, scheme->parameter) < 0) {
ASN1err(ASN1_F_PKCS5_PBE2_SET_SCRYPT,
ASN1_R_ERROR_SETTING_CIPHER_PARAMS);
goto err;
}
EVP_CIPHER_CTX_free(ctx);
ctx = NULL;
/* If its RC2 then we'd better setup the key length */
if (alg_nid == NID_rc2_cbc)
keylen = EVP_CIPHER_key_length(cipher);
/* Setup keyfunc */
X509_ALGOR_free(pbe2->keyfunc);
pbe2->keyfunc = pkcs5_scrypt_set(salt, saltlen, keylen, N, r, p);
if (pbe2->keyfunc == NULL)
goto merr;
/* Now set up top level AlgorithmIdentifier */
ret = X509_ALGOR_new();
if (ret == NULL)
goto merr;
ret->algorithm = OBJ_nid2obj(NID_pbes2);
/* Encode PBE2PARAM into parameter */
if (ASN1_TYPE_pack_sequence(ASN1_ITEM_rptr(PBE2PARAM), pbe2,
&ret->parameter) == NULL)
goto merr;
PBE2PARAM_free(pbe2);
pbe2 = NULL;
return ret;
merr:
ASN1err(ASN1_F_PKCS5_PBE2_SET_SCRYPT, ERR_R_MALLOC_FAILURE);
err:
PBE2PARAM_free(pbe2);
X509_ALGOR_free(ret);
EVP_CIPHER_CTX_free(ctx);
return NULL;
}
static X509_ALGOR *pkcs5_scrypt_set(const unsigned char *salt, size_t saltlen,
size_t keylen, uint64_t N, uint64_t r,
uint64_t p)
{
X509_ALGOR *keyfunc = NULL;
SCRYPT_PARAMS *sparam = SCRYPT_PARAMS_new();
if (sparam == NULL)
goto merr;
if (!saltlen)
saltlen = PKCS5_SALT_LEN;
/* This will either copy salt or grow the buffer */
if (ASN1_STRING_set(sparam->salt, salt, saltlen) == 0)
goto merr;
if (salt == NULL && RAND_bytes(sparam->salt->data, saltlen) <= 0)
goto err;
if (ASN1_INTEGER_set_uint64(sparam->costParameter, N) == 0)
goto merr;
if (ASN1_INTEGER_set_uint64(sparam->blockSize, r) == 0)
goto merr;
if (ASN1_INTEGER_set_uint64(sparam->parallelizationParameter, p) == 0)
goto merr;
/* If have a key len set it up */
if (keylen > 0) {
sparam->keyLength = ASN1_INTEGER_new();
if (sparam->keyLength == NULL)
goto merr;
if (ASN1_INTEGER_set_int64(sparam->keyLength, keylen) == 0)
goto merr;
}
/* Finally setup the keyfunc structure */
keyfunc = X509_ALGOR_new();
if (keyfunc == NULL)
goto merr;
keyfunc->algorithm = OBJ_nid2obj(NID_id_scrypt);
/* Encode SCRYPT_PARAMS into parameter of pbe2 */
if (ASN1_TYPE_pack_sequence(ASN1_ITEM_rptr(SCRYPT_PARAMS), sparam,
&keyfunc->parameter) == NULL)
goto merr;
SCRYPT_PARAMS_free(sparam);
return keyfunc;
merr:
ASN1err(ASN1_F_PKCS5_SCRYPT_SET, ERR_R_MALLOC_FAILURE);
err:
SCRYPT_PARAMS_free(sparam);
X509_ALGOR_free(keyfunc);
return NULL;
}
int PKCS5_v2_scrypt_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass,
int passlen, ASN1_TYPE *param,
const EVP_CIPHER *c, const EVP_MD *md, int en_de)
{
unsigned char *salt, key[EVP_MAX_KEY_LENGTH];
uint64_t p, r, N;
size_t saltlen;
size_t keylen = 0;
int rv = 0;
SCRYPT_PARAMS *sparam = NULL;
if (EVP_CIPHER_CTX_cipher(ctx) == NULL) {
EVPerr(EVP_F_PKCS5_V2_SCRYPT_KEYIVGEN, EVP_R_NO_CIPHER_SET);
goto err;
}
/* Decode parameter */
sparam = ASN1_TYPE_unpack_sequence(ASN1_ITEM_rptr(SCRYPT_PARAMS), param);
if (sparam == NULL) {
EVPerr(EVP_F_PKCS5_V2_SCRYPT_KEYIVGEN, EVP_R_DECODE_ERROR);
goto err;
}
keylen = EVP_CIPHER_CTX_key_length(ctx);
/* Now check the parameters of sparam */
if (sparam->keyLength) {
uint64_t spkeylen;
if ((ASN1_INTEGER_get_uint64(&spkeylen, sparam->keyLength) == 0)
|| (spkeylen != keylen)) {
EVPerr(EVP_F_PKCS5_V2_SCRYPT_KEYIVGEN,
EVP_R_UNSUPPORTED_KEYLENGTH);
goto err;
}
}
/* Check all parameters fit in uint64_t and are acceptable to scrypt */
if (ASN1_INTEGER_get_uint64(&N, sparam->costParameter) == 0
|| ASN1_INTEGER_get_uint64(&r, sparam->blockSize) == 0
|| ASN1_INTEGER_get_uint64(&p, sparam->parallelizationParameter) == 0
|| EVP_PBE_scrypt(NULL, 0, NULL, 0, N, r, p, 0, NULL, 0) == 0) {
EVPerr(EVP_F_PKCS5_V2_SCRYPT_KEYIVGEN,
EVP_R_ILLEGAL_SCRYPT_PARAMETERS);
goto err;
}
/* it seems that its all OK */
salt = sparam->salt->data;
saltlen = sparam->salt->length;
if (EVP_PBE_scrypt(pass, passlen, salt, saltlen, N, r, p, 0, key, keylen)
== 0)
goto err;
rv = EVP_CipherInit_ex(ctx, NULL, NULL, key, NULL, en_de);
err:
if (keylen)
OPENSSL_cleanse(key, keylen);
SCRYPT_PARAMS_free(sparam);
return rv;
}
#endif /* OPENSSL_NO_SCRYPT */

View File

@ -1,66 +1,17 @@
/* p8_pkey.c */
/* /*
* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved.
* 1999.
*/
/* ====================================================================
* Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
*
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* licensing@OpenSSL.org.
*
* 5. Products derived from this software may not be called "OpenSSL"
* nor may "OpenSSL" appear in their names without prior written
* permission of the OpenSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*
* This product includes cryptographic software written by Eric Young
* (eay@cryptsoft.com). This product includes software written by Tim
* Hudson (tjh@cryptsoft.com).
* *
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/ */
#include <stdio.h> #include <stdio.h>
#include "cryptlib.h" #include "internal/cryptlib.h"
#include <openssl/asn1t.h> #include <openssl/asn1t.h>
#include <openssl/x509.h> #include <openssl/x509.h>
#include "internal/x509_int.h"
/* Minor tweak to operation: zero private key data */ /* Minor tweak to operation: zero private key data */
static int pkey_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, static int pkey_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
@ -69,10 +20,8 @@ static int pkey_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
/* Since the structure must still be valid use ASN1_OP_FREE_PRE */ /* Since the structure must still be valid use ASN1_OP_FREE_PRE */
if (operation == ASN1_OP_FREE_PRE) { if (operation == ASN1_OP_FREE_PRE) {
PKCS8_PRIV_KEY_INFO *key = (PKCS8_PRIV_KEY_INFO *)*pval; PKCS8_PRIV_KEY_INFO *key = (PKCS8_PRIV_KEY_INFO *)*pval;
if (key->pkey && key->pkey->type == V_ASN1_OCTET_STRING if (key->pkey)
&& key->pkey->value.octet_string != NULL) OPENSSL_cleanse(key->pkey->data, key->pkey->length);
OPENSSL_cleanse(key->pkey->value.octet_string->data,
key->pkey->value.octet_string->length);
} }
return 1; return 1;
} }
@ -80,7 +29,7 @@ static int pkey_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
ASN1_SEQUENCE_cb(PKCS8_PRIV_KEY_INFO, pkey_cb) = { ASN1_SEQUENCE_cb(PKCS8_PRIV_KEY_INFO, pkey_cb) = {
ASN1_SIMPLE(PKCS8_PRIV_KEY_INFO, version, ASN1_INTEGER), ASN1_SIMPLE(PKCS8_PRIV_KEY_INFO, version, ASN1_INTEGER),
ASN1_SIMPLE(PKCS8_PRIV_KEY_INFO, pkeyalg, X509_ALGOR), ASN1_SIMPLE(PKCS8_PRIV_KEY_INFO, pkeyalg, X509_ALGOR),
ASN1_SIMPLE(PKCS8_PRIV_KEY_INFO, pkey, ASN1_ANY), ASN1_SIMPLE(PKCS8_PRIV_KEY_INFO, pkey, ASN1_OCTET_STRING),
ASN1_IMP_SET_OF_OPT(PKCS8_PRIV_KEY_INFO, attributes, X509_ATTRIBUTE, 0) ASN1_IMP_SET_OF_OPT(PKCS8_PRIV_KEY_INFO, attributes, X509_ATTRIBUTE, 0)
} ASN1_SEQUENCE_END_cb(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO) } ASN1_SEQUENCE_END_cb(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO)
@ -90,56 +39,42 @@ int PKCS8_pkey_set0(PKCS8_PRIV_KEY_INFO *priv, ASN1_OBJECT *aobj,
int version, int version,
int ptype, void *pval, unsigned char *penc, int penclen) int ptype, void *pval, unsigned char *penc, int penclen)
{ {
unsigned char **ppenc = NULL;
if (version >= 0) { if (version >= 0) {
if (!ASN1_INTEGER_set(priv->version, version)) if (!ASN1_INTEGER_set(priv->version, version))
return 0; return 0;
} }
if (penc) { if (!X509_ALGOR_set0(priv->pkeyalg, aobj, ptype, pval))
int pmtype;
ASN1_OCTET_STRING *oct;
oct = ASN1_OCTET_STRING_new();
if (!oct)
return 0; return 0;
oct->data = penc; if (penc)
ppenc = &oct->data; ASN1_STRING_set0(priv->pkey, penc, penclen);
oct->length = penclen;
if (priv->broken == PKCS8_NO_OCTET)
pmtype = V_ASN1_SEQUENCE;
else
pmtype = V_ASN1_OCTET_STRING;
ASN1_TYPE_set(priv->pkey, pmtype, oct);
}
if (!X509_ALGOR_set0(priv->pkeyalg, aobj, ptype, pval)) {
/* If call fails do not swallow 'enc' */
if (ppenc)
*ppenc = NULL;
return 0;
}
return 1; return 1;
} }
int PKCS8_pkey_get0(ASN1_OBJECT **ppkalg, int PKCS8_pkey_get0(const ASN1_OBJECT **ppkalg,
const unsigned char **pk, int *ppklen, const unsigned char **pk, int *ppklen,
X509_ALGOR **pa, PKCS8_PRIV_KEY_INFO *p8) const X509_ALGOR **pa, const PKCS8_PRIV_KEY_INFO *p8)
{ {
if (ppkalg) if (ppkalg)
*ppkalg = p8->pkeyalg->algorithm; *ppkalg = p8->pkeyalg->algorithm;
if (p8->pkey->type == V_ASN1_OCTET_STRING) {
p8->broken = PKCS8_OK;
if (pk) { if (pk) {
*pk = p8->pkey->value.octet_string->data; *pk = ASN1_STRING_get0_data(p8->pkey);
*ppklen = p8->pkey->value.octet_string->length; *ppklen = ASN1_STRING_length(p8->pkey);
} }
} else if (p8->pkey->type == V_ASN1_SEQUENCE) {
p8->broken = PKCS8_NO_OCTET;
if (pk) {
*pk = p8->pkey->value.sequence->data;
*ppklen = p8->pkey->value.sequence->length;
}
} else
return 0;
if (pa) if (pa)
*pa = p8->pkeyalg; *pa = p8->pkeyalg;
return 1; return 1;
} }
const STACK_OF(X509_ATTRIBUTE) *
PKCS8_pkey_get0_attrs(const PKCS8_PRIV_KEY_INFO *p8)
{
return p8->attributes;
}
int PKCS8_pkey_add1_attr_by_NID(PKCS8_PRIV_KEY_INFO *p8, int nid, int type,
const unsigned char *bytes, int len)
{
if (X509at_add1_attr_by_NID(&p8->attributes, nid, type, bytes, len) != NULL)
return 1;
return 0;
}

View File

@ -1,64 +1,14 @@
/* t_bitst.c */
/* /*
* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved.
* 1999.
*/
/* ====================================================================
* Copyright (c) 1999 The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
*
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* licensing@OpenSSL.org.
*
* 5. Products derived from this software may not be called "OpenSSL"
* nor may "OpenSSL" appear in their names without prior written
* permission of the OpenSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*
* This product includes cryptographic software written by Eric Young
* (eay@cryptsoft.com). This product includes software written by Tim
* Hudson (tjh@cryptsoft.com).
* *
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/ */
#include <stdio.h> #include <stdio.h>
#include "cryptlib.h" #include "internal/cryptlib.h"
#include <openssl/conf.h> #include <openssl/conf.h>
#include <openssl/x509v3.h> #include <openssl/x509v3.h>
@ -80,7 +30,7 @@ int ASN1_BIT_STRING_name_print(BIO *out, ASN1_BIT_STRING *bs,
return 1; return 1;
} }
int ASN1_BIT_STRING_set_asc(ASN1_BIT_STRING *bs, char *name, int value, int ASN1_BIT_STRING_set_asc(ASN1_BIT_STRING *bs, const char *name, int value,
BIT_STRING_BITNAME *tbl) BIT_STRING_BITNAME *tbl)
{ {
int bitnum; int bitnum;
@ -94,11 +44,12 @@ int ASN1_BIT_STRING_set_asc(ASN1_BIT_STRING *bs, char *name, int value,
return 1; return 1;
} }
int ASN1_BIT_STRING_num_asc(char *name, BIT_STRING_BITNAME *tbl) int ASN1_BIT_STRING_num_asc(const char *name, BIT_STRING_BITNAME *tbl)
{ {
BIT_STRING_BITNAME *bnam; BIT_STRING_BITNAME *bnam;
for (bnam = tbl; bnam->lname; bnam++) { for (bnam = tbl; bnam->lname; bnam++) {
if (!strcmp(bnam->sname, name) || !strcmp(bnam->lname, name)) if ((strcmp(bnam->sname, name) == 0)
|| (strcmp(bnam->lname, name) == 0))
return bnam->bitnum; return bnam->bitnum;
} }
return -1; return -1;

View File

@ -1,133 +0,0 @@
/* t_crl.c */
/*
* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project
* 1999.
*/
/* ====================================================================
* Copyright (c) 1999 The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
*
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* licensing@OpenSSL.org.
*
* 5. Products derived from this software may not be called "OpenSSL"
* nor may "OpenSSL" appear in their names without prior written
* permission of the OpenSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*
* This product includes cryptographic software written by Eric Young
* (eay@cryptsoft.com). This product includes software written by Tim
* Hudson (tjh@cryptsoft.com).
*
*/
#include <stdio.h>
#include "cryptlib.h"
#include <openssl/buffer.h>
#include <openssl/bn.h>
#include <openssl/objects.h>
#include <openssl/x509.h>
#include <openssl/x509v3.h>
#ifndef OPENSSL_NO_FP_API
int X509_CRL_print_fp(FILE *fp, X509_CRL *x)
{
BIO *b;
int ret;
if ((b = BIO_new(BIO_s_file())) == NULL) {
X509err(X509_F_X509_CRL_PRINT_FP, ERR_R_BUF_LIB);
return (0);
}
BIO_set_fp(b, fp, BIO_NOCLOSE);
ret = X509_CRL_print(b, x);
BIO_free(b);
return (ret);
}
#endif
int X509_CRL_print(BIO *out, X509_CRL *x)
{
STACK_OF(X509_REVOKED) *rev;
X509_REVOKED *r;
long l;
int i;
char *p;
BIO_printf(out, "Certificate Revocation List (CRL):\n");
l = X509_CRL_get_version(x);
BIO_printf(out, "%8sVersion %lu (0x%lx)\n", "", l + 1, l);
i = OBJ_obj2nid(x->sig_alg->algorithm);
X509_signature_print(out, x->sig_alg, NULL);
p = X509_NAME_oneline(X509_CRL_get_issuer(x), NULL, 0);
BIO_printf(out, "%8sIssuer: %s\n", "", p);
OPENSSL_free(p);
BIO_printf(out, "%8sLast Update: ", "");
ASN1_TIME_print(out, X509_CRL_get_lastUpdate(x));
BIO_printf(out, "\n%8sNext Update: ", "");
if (X509_CRL_get_nextUpdate(x))
ASN1_TIME_print(out, X509_CRL_get_nextUpdate(x));
else
BIO_printf(out, "NONE");
BIO_printf(out, "\n");
X509V3_extensions_print(out, "CRL extensions", x->crl->extensions, 0, 8);
rev = X509_CRL_get_REVOKED(x);
if (sk_X509_REVOKED_num(rev) > 0)
BIO_printf(out, "Revoked Certificates:\n");
else
BIO_printf(out, "No Revoked Certificates.\n");
for (i = 0; i < sk_X509_REVOKED_num(rev); i++) {
r = sk_X509_REVOKED_value(rev, i);
BIO_printf(out, " Serial Number: ");
i2a_ASN1_INTEGER(out, r->serialNumber);
BIO_printf(out, "\n Revocation Date: ");
ASN1_TIME_print(out, r->revocationDate);
BIO_printf(out, "\n");
X509V3_extensions_print(out, "CRL entry extensions",
r->extensions, 0, 8);
}
X509_signature_print(out, x->sig_alg, x->signature);
return 1;
}

View File

@ -1,77 +1,59 @@
/* crypto/asn1/t_pkey.c */ /*
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
* All rights reserved.
* *
* This package is an SSL implementation written * Licensed under the OpenSSL license (the "License"). You may not use
* by Eric Young (eay@cryptsoft.com). * this file except in compliance with the License. You can obtain a copy
* The implementation was written so as to conform with Netscapes SSL. * in the file LICENSE in the source distribution or at
* * https://www.openssl.org/source/license.html
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* "This product includes cryptographic software written by
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/ */
#include <stdio.h> #include <stdio.h>
#include "cryptlib.h" #include "internal/cryptlib.h"
#include <openssl/objects.h> #include <openssl/objects.h>
#include <openssl/buffer.h> #include <openssl/buffer.h>
#include <openssl/bn.h> #include "internal/bn_int.h"
/* Number of octets per line */
#define ASN1_BUF_PRINT_WIDTH 15
/* Maximum indent */
#define ASN1_PRINT_MAX_INDENT 128
int ASN1_buf_print(BIO *bp, const unsigned char *buf, size_t buflen, int indent)
{
size_t i;
for (i = 0; i < buflen; i++) {
if ((i % ASN1_BUF_PRINT_WIDTH) == 0) {
if (i > 0 && BIO_puts(bp, "\n") <= 0)
return 0;
if (!BIO_indent(bp, indent, ASN1_PRINT_MAX_INDENT))
return 0;
}
/*
* Use colon separators for each octet for compatibility as
* this function is used to print out key components.
*/
if (BIO_printf(bp, "%02x%s", buf[i],
(i == buflen - 1) ? "" : ":") <= 0)
return 0;
}
if (BIO_write(bp, "\n", 1) <= 0)
return 0;
return 1;
}
int ASN1_bn_print(BIO *bp, const char *number, const BIGNUM *num, int ASN1_bn_print(BIO *bp, const char *number, const BIGNUM *num,
unsigned char *buf, int off) unsigned char *ign, int indent)
{ {
int n, i; int n, rv = 0;
const char *neg; const char *neg;
unsigned char *buf = NULL, *tmp = NULL;
int buflen;
if (num == NULL) if (num == NULL)
return (1); return 1;
neg = (BN_is_negative(num)) ? "-" : ""; neg = BN_is_negative(num) ? "-" : "";
if (!BIO_indent(bp, off, 128)) if (!BIO_indent(bp, indent, ASN1_PRINT_MAX_INDENT))
return 0; return 0;
if (BN_is_zero(num)) { if (BN_is_zero(num)) {
if (BIO_printf(bp, "%s 0\n", number) <= 0) if (BIO_printf(bp, "%s 0\n", number) <= 0)
@ -81,33 +63,31 @@ int ASN1_bn_print(BIO *bp, const char *number, const BIGNUM *num,
if (BN_num_bytes(num) <= BN_BYTES) { if (BN_num_bytes(num) <= BN_BYTES) {
if (BIO_printf(bp, "%s %s%lu (%s0x%lx)\n", number, neg, if (BIO_printf(bp, "%s %s%lu (%s0x%lx)\n", number, neg,
(unsigned long)num->d[0], neg, (unsigned long)bn_get_words(num)[0], neg,
(unsigned long)num->d[0]) (unsigned long)bn_get_words(num)[0]) <= 0)
<= 0) return 0;
return (0); return 1;
} else { }
buflen = BN_num_bytes(num) + 1;
buf = tmp = OPENSSL_malloc(buflen);
if (buf == NULL)
goto err;
buf[0] = 0; buf[0] = 0;
if (BIO_printf(bp, "%s%s", number, if (BIO_printf(bp, "%s%s\n", number,
(neg[0] == '-') ? " (Negative)" : "") <= 0) (neg[0] == '-') ? " (Negative)" : "") <= 0)
return (0); goto err;
n = BN_bn2bin(num, &buf[1]); n = BN_bn2bin(num, buf + 1);
if (buf[1] & 0x80) if (buf[1] & 0x80)
n++; n++;
else else
buf++; tmp++;
for (i = 0; i < n; i++) { if (ASN1_buf_print(bp, tmp, n, indent + 4) == 0)
if ((i % 15) == 0) { goto err;
if (BIO_puts(bp, "\n") <= 0 || !BIO_indent(bp, off + 4, 128)) rv = 1;
return 0; err:
} OPENSSL_clear_free(buf, buflen);
if (BIO_printf(bp, "%02x%s", buf[i], ((i + 1) == n) ? "" : ":") return rv;
<= 0)
return (0);
}
if (BIO_write(bp, "\n", 1) <= 0)
return (0);
}
return (1);
} }

View File

@ -1,255 +0,0 @@
/* crypto/asn1/t_req.c */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
* This package is an SSL implementation written
* by Eric Young (eay@cryptsoft.com).
* The implementation was written so as to conform with Netscapes SSL.
*
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* "This product includes cryptographic software written by
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/
#include <stdio.h>
#include "cryptlib.h"
#include <openssl/buffer.h>
#include <openssl/bn.h>
#include <openssl/objects.h>
#include <openssl/x509.h>
#include <openssl/x509v3.h>
#ifndef OPENSSL_NO_RSA
# include <openssl/rsa.h>
#endif
#ifndef OPENSSL_NO_DSA
# include <openssl/dsa.h>
#endif
#ifndef OPENSSL_NO_FP_API
int X509_REQ_print_fp(FILE *fp, X509_REQ *x)
{
BIO *b;
int ret;
if ((b = BIO_new(BIO_s_file())) == NULL) {
X509err(X509_F_X509_REQ_PRINT_FP, ERR_R_BUF_LIB);
return (0);
}
BIO_set_fp(b, fp, BIO_NOCLOSE);
ret = X509_REQ_print(b, x);
BIO_free(b);
return (ret);
}
#endif
int X509_REQ_print_ex(BIO *bp, X509_REQ *x, unsigned long nmflags,
unsigned long cflag)
{
unsigned long l;
int i;
const char *neg;
X509_REQ_INFO *ri;
EVP_PKEY *pkey;
STACK_OF(X509_ATTRIBUTE) *sk;
STACK_OF(X509_EXTENSION) *exts;
char mlch = ' ';
int nmindent = 0;
if ((nmflags & XN_FLAG_SEP_MASK) == XN_FLAG_SEP_MULTILINE) {
mlch = '\n';
nmindent = 12;
}
if (nmflags == X509_FLAG_COMPAT)
nmindent = 16;
ri = x->req_info;
if (!(cflag & X509_FLAG_NO_HEADER)) {
if (BIO_write(bp, "Certificate Request:\n", 21) <= 0)
goto err;
if (BIO_write(bp, " Data:\n", 10) <= 0)
goto err;
}
if (!(cflag & X509_FLAG_NO_VERSION)) {
neg = (ri->version->type == V_ASN1_NEG_INTEGER) ? "-" : "";
l = 0;
for (i = 0; i < ri->version->length; i++) {
l <<= 8;
l += ri->version->data[i];
}
if (BIO_printf(bp, "%8sVersion: %s%lu (%s0x%lx)\n", "", neg, l, neg,
l) <= 0)
goto err;
}
if (!(cflag & X509_FLAG_NO_SUBJECT)) {
if (BIO_printf(bp, " Subject:%c", mlch) <= 0)
goto err;
if (X509_NAME_print_ex(bp, ri->subject, nmindent, nmflags) < 0)
goto err;
if (BIO_write(bp, "\n", 1) <= 0)
goto err;
}
if (!(cflag & X509_FLAG_NO_PUBKEY)) {
if (BIO_write(bp, " Subject Public Key Info:\n", 33) <= 0)
goto err;
if (BIO_printf(bp, "%12sPublic Key Algorithm: ", "") <= 0)
goto err;
if (i2a_ASN1_OBJECT(bp, ri->pubkey->algor->algorithm) <= 0)
goto err;
if (BIO_puts(bp, "\n") <= 0)
goto err;
pkey = X509_REQ_get_pubkey(x);
if (pkey == NULL) {
BIO_printf(bp, "%12sUnable to load Public Key\n", "");
ERR_print_errors(bp);
} else {
EVP_PKEY_print_public(bp, pkey, 16, NULL);
EVP_PKEY_free(pkey);
}
}
if (!(cflag & X509_FLAG_NO_ATTRIBUTES)) {
/* may not be */
if (BIO_printf(bp, "%8sAttributes:\n", "") <= 0)
goto err;
sk = x->req_info->attributes;
if (sk_X509_ATTRIBUTE_num(sk) == 0) {
if (BIO_printf(bp, "%12sa0:00\n", "") <= 0)
goto err;
} else {
for (i = 0; i < sk_X509_ATTRIBUTE_num(sk); i++) {
ASN1_TYPE *at;
X509_ATTRIBUTE *a;
ASN1_BIT_STRING *bs = NULL;
ASN1_TYPE *t;
int j, type = 0, count = 1, ii = 0;
a = sk_X509_ATTRIBUTE_value(sk, i);
if (X509_REQ_extension_nid(OBJ_obj2nid(a->object)))
continue;
if (BIO_printf(bp, "%12s", "") <= 0)
goto err;
if ((j = i2a_ASN1_OBJECT(bp, a->object)) > 0) {
if (a->single) {
t = a->value.single;
type = t->type;
bs = t->value.bit_string;
} else {
ii = 0;
count = sk_ASN1_TYPE_num(a->value.set);
get_next:
at = sk_ASN1_TYPE_value(a->value.set, ii);
type = at->type;
bs = at->value.asn1_string;
}
}
for (j = 25 - j; j > 0; j--)
if (BIO_write(bp, " ", 1) != 1)
goto err;
if (BIO_puts(bp, ":") <= 0)
goto err;
if ((type == V_ASN1_PRINTABLESTRING) ||
(type == V_ASN1_UTF8STRING) ||
(type == V_ASN1_T61STRING) ||
(type == V_ASN1_IA5STRING)) {
if (BIO_write(bp, (char *)bs->data, bs->length)
!= bs->length)
goto err;
BIO_puts(bp, "\n");
} else {
BIO_puts(bp, "unable to print attribute\n");
}
if (++ii < count)
goto get_next;
}
}
}
if (!(cflag & X509_FLAG_NO_EXTENSIONS)) {
exts = X509_REQ_get_extensions(x);
if (exts) {
BIO_printf(bp, "%8sRequested Extensions:\n", "");
for (i = 0; i < sk_X509_EXTENSION_num(exts); i++) {
ASN1_OBJECT *obj;
X509_EXTENSION *ex;
int j;
ex = sk_X509_EXTENSION_value(exts, i);
if (BIO_printf(bp, "%12s", "") <= 0)
goto err;
obj = X509_EXTENSION_get_object(ex);
i2a_ASN1_OBJECT(bp, obj);
j = X509_EXTENSION_get_critical(ex);
if (BIO_printf(bp, ": %s\n", j ? "critical" : "") <= 0)
goto err;
if (!X509V3_EXT_print(bp, ex, cflag, 16)) {
BIO_printf(bp, "%16s", "");
M_ASN1_OCTET_STRING_print(bp, ex->value);
}
if (BIO_write(bp, "\n", 1) <= 0)
goto err;
}
sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free);
}
}
if (!(cflag & X509_FLAG_NO_SIGDUMP)) {
if (!X509_signature_print(bp, x->sig_alg, x->signature))
goto err;
}
return (1);
err:
X509err(X509_F_X509_REQ_PRINT_EX, ERR_R_BUF_LIB);
return (0);
}
int X509_REQ_print(BIO *bp, X509_REQ *x)
{
return X509_REQ_print_ex(bp, x, XN_FLAG_COMPAT, X509_FLAG_COMPAT);
}

View File

@ -1,72 +1,18 @@
/* t_spki.c */
/* /*
* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved.
* 1999.
*/
/* ====================================================================
* Copyright (c) 1999 The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
*
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* licensing@OpenSSL.org.
*
* 5. Products derived from this software may not be called "OpenSSL"
* nor may "OpenSSL" appear in their names without prior written
* permission of the OpenSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*
* This product includes cryptographic software written by Eric Young
* (eay@cryptsoft.com). This product includes software written by Tim
* Hudson (tjh@cryptsoft.com).
* *
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/ */
#include <stdio.h> #include <stdio.h>
#include "cryptlib.h" #include "internal/cryptlib.h"
#include <openssl/x509.h> #include <openssl/x509.h>
#include <openssl/asn1.h> #include <openssl/asn1.h>
#ifndef OPENSSL_NO_RSA #include <openssl/rsa.h>
# include <openssl/rsa.h> #include <openssl/dsa.h>
#endif
#ifndef OPENSSL_NO_DSA
# include <openssl/dsa.h>
#endif
#include <openssl/bn.h> #include <openssl/bn.h>
/* Print out an SPKI */ /* Print out an SPKI */
@ -75,10 +21,12 @@ int NETSCAPE_SPKI_print(BIO *out, NETSCAPE_SPKI *spki)
{ {
EVP_PKEY *pkey; EVP_PKEY *pkey;
ASN1_IA5STRING *chal; ASN1_IA5STRING *chal;
ASN1_OBJECT *spkioid;
int i, n; int i, n;
char *s; char *s;
BIO_printf(out, "Netscape SPKI:\n"); BIO_printf(out, "Netscape SPKI:\n");
i = OBJ_obj2nid(spki->spkac->pubkey->algor->algorithm); X509_PUBKEY_get0_param(&spkioid, NULL, NULL, NULL, spki->spkac->pubkey);
i = OBJ_obj2nid(spkioid);
BIO_printf(out, " Public Key Algorithm: %s\n", BIO_printf(out, " Public Key Algorithm: %s\n",
(i == NID_undef) ? "UNKNOWN" : OBJ_nid2ln(i)); (i == NID_undef) ? "UNKNOWN" : OBJ_nid2ln(i));
pkey = X509_PUBKEY_get(spki->spkac->pubkey); pkey = X509_PUBKEY_get(spki->spkac->pubkey);
@ -91,7 +39,7 @@ int NETSCAPE_SPKI_print(BIO *out, NETSCAPE_SPKI *spki)
chal = spki->spkac->challenge; chal = spki->spkac->challenge;
if (chal->length) if (chal->length)
BIO_printf(out, " Challenge String: %s\n", chal->data); BIO_printf(out, " Challenge String: %s\n", chal->data);
i = OBJ_obj2nid(spki->sig_algor->algorithm); i = OBJ_obj2nid(spki->sig_algor.algorithm);
BIO_printf(out, " Signature Algorithm: %s", BIO_printf(out, " Signature Algorithm: %s",
(i == NID_undef) ? "UNKNOWN" : OBJ_nid2ln(i)); (i == NID_undef) ? "UNKNOWN" : OBJ_nid2ln(i));

View File

@ -1,556 +0,0 @@
/* crypto/asn1/t_x509.c */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
* This package is an SSL implementation written
* by Eric Young (eay@cryptsoft.com).
* The implementation was written so as to conform with Netscapes SSL.
*
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* "This product includes cryptographic software written by
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/
#include <stdio.h>
#include "cryptlib.h"
#include <openssl/buffer.h>
#include <openssl/bn.h>
#ifndef OPENSSL_NO_RSA
# include <openssl/rsa.h>
#endif
#ifndef OPENSSL_NO_DSA
# include <openssl/dsa.h>
#endif
#ifndef OPENSSL_NO_EC
# include <openssl/ec.h>
#endif
#include <openssl/objects.h>
#include <openssl/x509.h>
#include <openssl/x509v3.h>
#include "asn1_locl.h"
#ifndef OPENSSL_NO_FP_API
int X509_print_fp(FILE *fp, X509 *x)
{
return X509_print_ex_fp(fp, x, XN_FLAG_COMPAT, X509_FLAG_COMPAT);
}
int X509_print_ex_fp(FILE *fp, X509 *x, unsigned long nmflag,
unsigned long cflag)
{
BIO *b;
int ret;
if ((b = BIO_new(BIO_s_file())) == NULL) {
X509err(X509_F_X509_PRINT_EX_FP, ERR_R_BUF_LIB);
return (0);
}
BIO_set_fp(b, fp, BIO_NOCLOSE);
ret = X509_print_ex(b, x, nmflag, cflag);
BIO_free(b);
return (ret);
}
#endif
int X509_print(BIO *bp, X509 *x)
{
return X509_print_ex(bp, x, XN_FLAG_COMPAT, X509_FLAG_COMPAT);
}
int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags,
unsigned long cflag)
{
long l;
int ret = 0, i;
char *m = NULL, mlch = ' ';
int nmindent = 0;
X509_CINF *ci;
ASN1_INTEGER *bs;
EVP_PKEY *pkey = NULL;
const char *neg;
if ((nmflags & XN_FLAG_SEP_MASK) == XN_FLAG_SEP_MULTILINE) {
mlch = '\n';
nmindent = 12;
}
if (nmflags == X509_FLAG_COMPAT)
nmindent = 16;
ci = x->cert_info;
if (!(cflag & X509_FLAG_NO_HEADER)) {
if (BIO_write(bp, "Certificate:\n", 13) <= 0)
goto err;
if (BIO_write(bp, " Data:\n", 10) <= 0)
goto err;
}
if (!(cflag & X509_FLAG_NO_VERSION)) {
l = X509_get_version(x);
if (BIO_printf(bp, "%8sVersion: %lu (0x%lx)\n", "", l + 1, l) <= 0)
goto err;
}
if (!(cflag & X509_FLAG_NO_SERIAL)) {
if (BIO_write(bp, " Serial Number:", 22) <= 0)
goto err;
bs = X509_get_serialNumber(x);
if (bs->length < (int)sizeof(long)
|| (bs->length == sizeof(long) && (bs->data[0] & 0x80) == 0)) {
l = ASN1_INTEGER_get(bs);
if (bs->type == V_ASN1_NEG_INTEGER) {
l = -l;
neg = "-";
} else
neg = "";
if (BIO_printf(bp, " %s%lu (%s0x%lx)\n", neg, l, neg, l) <= 0)
goto err;
} else {
neg = (bs->type == V_ASN1_NEG_INTEGER) ? " (Negative)" : "";
if (BIO_printf(bp, "\n%12s%s", "", neg) <= 0)
goto err;
for (i = 0; i < bs->length; i++) {
if (BIO_printf(bp, "%02x%c", bs->data[i],
((i + 1 == bs->length) ? '\n' : ':')) <= 0)
goto err;
}
}
}
if (!(cflag & X509_FLAG_NO_SIGNAME)) {
if (X509_signature_print(bp, ci->signature, NULL) <= 0)
goto err;
#if 0
if (BIO_printf(bp, "%8sSignature Algorithm: ", "") <= 0)
goto err;
if (i2a_ASN1_OBJECT(bp, ci->signature->algorithm) <= 0)
goto err;
if (BIO_puts(bp, "\n") <= 0)
goto err;
#endif
}
if (!(cflag & X509_FLAG_NO_ISSUER)) {
if (BIO_printf(bp, " Issuer:%c", mlch) <= 0)
goto err;
if (X509_NAME_print_ex(bp, X509_get_issuer_name(x), nmindent, nmflags)
< 0)
goto err;
if (BIO_write(bp, "\n", 1) <= 0)
goto err;
}
if (!(cflag & X509_FLAG_NO_VALIDITY)) {
if (BIO_write(bp, " Validity\n", 17) <= 0)
goto err;
if (BIO_write(bp, " Not Before: ", 24) <= 0)
goto err;
if (!ASN1_TIME_print(bp, X509_get_notBefore(x)))
goto err;
if (BIO_write(bp, "\n Not After : ", 25) <= 0)
goto err;
if (!ASN1_TIME_print(bp, X509_get_notAfter(x)))
goto err;
if (BIO_write(bp, "\n", 1) <= 0)
goto err;
}
if (!(cflag & X509_FLAG_NO_SUBJECT)) {
if (BIO_printf(bp, " Subject:%c", mlch) <= 0)
goto err;
if (X509_NAME_print_ex
(bp, X509_get_subject_name(x), nmindent, nmflags) < 0)
goto err;
if (BIO_write(bp, "\n", 1) <= 0)
goto err;
}
if (!(cflag & X509_FLAG_NO_PUBKEY)) {
if (BIO_write(bp, " Subject Public Key Info:\n", 33) <= 0)
goto err;
if (BIO_printf(bp, "%12sPublic Key Algorithm: ", "") <= 0)
goto err;
if (i2a_ASN1_OBJECT(bp, ci->key->algor->algorithm) <= 0)
goto err;
if (BIO_puts(bp, "\n") <= 0)
goto err;
pkey = X509_get_pubkey(x);
if (pkey == NULL) {
BIO_printf(bp, "%12sUnable to load Public Key\n", "");
ERR_print_errors(bp);
} else {
EVP_PKEY_print_public(bp, pkey, 16, NULL);
EVP_PKEY_free(pkey);
}
}
if (!(cflag & X509_FLAG_NO_IDS)) {
if (ci->issuerUID) {
if (BIO_printf(bp, "%8sIssuer Unique ID: ", "") <= 0)
goto err;
if (!X509_signature_dump(bp, ci->issuerUID, 12))
goto err;
}
if (ci->subjectUID) {
if (BIO_printf(bp, "%8sSubject Unique ID: ", "") <= 0)
goto err;
if (!X509_signature_dump(bp, ci->subjectUID, 12))
goto err;
}
}
if (!(cflag & X509_FLAG_NO_EXTENSIONS))
X509V3_extensions_print(bp, "X509v3 extensions",
ci->extensions, cflag, 8);
if (!(cflag & X509_FLAG_NO_SIGDUMP)) {
if (X509_signature_print(bp, x->sig_alg, x->signature) <= 0)
goto err;
}
if (!(cflag & X509_FLAG_NO_AUX)) {
if (!X509_CERT_AUX_print(bp, x->aux, 0))
goto err;
}
ret = 1;
err:
if (m != NULL)
OPENSSL_free(m);
return (ret);
}
int X509_ocspid_print(BIO *bp, X509 *x)
{
unsigned char *der = NULL;
unsigned char *dertmp;
int derlen;
int i;
unsigned char SHA1md[SHA_DIGEST_LENGTH];
/*
* display the hash of the subject as it would appear in OCSP requests
*/
if (BIO_printf(bp, " Subject OCSP hash: ") <= 0)
goto err;
derlen = i2d_X509_NAME(x->cert_info->subject, NULL);
if ((der = dertmp = (unsigned char *)OPENSSL_malloc(derlen)) == NULL)
goto err;
i2d_X509_NAME(x->cert_info->subject, &dertmp);
if (!EVP_Digest(der, derlen, SHA1md, NULL, EVP_sha1(), NULL))
goto err;
for (i = 0; i < SHA_DIGEST_LENGTH; i++) {
if (BIO_printf(bp, "%02X", SHA1md[i]) <= 0)
goto err;
}
OPENSSL_free(der);
der = NULL;
/*
* display the hash of the public key as it would appear in OCSP requests
*/
if (BIO_printf(bp, "\n Public key OCSP hash: ") <= 0)
goto err;
if (!EVP_Digest(x->cert_info->key->public_key->data,
x->cert_info->key->public_key->length,
SHA1md, NULL, EVP_sha1(), NULL))
goto err;
for (i = 0; i < SHA_DIGEST_LENGTH; i++) {
if (BIO_printf(bp, "%02X", SHA1md[i]) <= 0)
goto err;
}
BIO_printf(bp, "\n");
return (1);
err:
if (der != NULL)
OPENSSL_free(der);
return (0);
}
int X509_signature_dump(BIO *bp, const ASN1_STRING *sig, int indent)
{
const unsigned char *s;
int i, n;
n = sig->length;
s = sig->data;
for (i = 0; i < n; i++) {
if ((i % 18) == 0) {
if (BIO_write(bp, "\n", 1) <= 0)
return 0;
if (BIO_indent(bp, indent, indent) <= 0)
return 0;
}
if (BIO_printf(bp, "%02x%s", s[i], ((i + 1) == n) ? "" : ":") <= 0)
return 0;
}
if (BIO_write(bp, "\n", 1) != 1)
return 0;
return 1;
}
int X509_signature_print(BIO *bp, X509_ALGOR *sigalg, ASN1_STRING *sig)
{
int sig_nid;
if (BIO_puts(bp, " Signature Algorithm: ") <= 0)
return 0;
if (i2a_ASN1_OBJECT(bp, sigalg->algorithm) <= 0)
return 0;
sig_nid = OBJ_obj2nid(sigalg->algorithm);
if (sig_nid != NID_undef) {
int pkey_nid, dig_nid;
const EVP_PKEY_ASN1_METHOD *ameth;
if (OBJ_find_sigid_algs(sig_nid, &dig_nid, &pkey_nid)) {
ameth = EVP_PKEY_asn1_find(NULL, pkey_nid);
if (ameth && ameth->sig_print)
return ameth->sig_print(bp, sigalg, sig, 9, 0);
}
}
if (sig)
return X509_signature_dump(bp, sig, 9);
else if (BIO_puts(bp, "\n") <= 0)
return 0;
return 1;
}
int ASN1_STRING_print(BIO *bp, const ASN1_STRING *v)
{
int i, n;
char buf[80];
const char *p;
if (v == NULL)
return (0);
n = 0;
p = (const char *)v->data;
for (i = 0; i < v->length; i++) {
if ((p[i] > '~') || ((p[i] < ' ') &&
(p[i] != '\n') && (p[i] != '\r')))
buf[n] = '.';
else
buf[n] = p[i];
n++;
if (n >= 80) {
if (BIO_write(bp, buf, n) <= 0)
return (0);
n = 0;
}
}
if (n > 0)
if (BIO_write(bp, buf, n) <= 0)
return (0);
return (1);
}
int ASN1_TIME_print(BIO *bp, const ASN1_TIME *tm)
{
if (tm->type == V_ASN1_UTCTIME)
return ASN1_UTCTIME_print(bp, tm);
if (tm->type == V_ASN1_GENERALIZEDTIME)
return ASN1_GENERALIZEDTIME_print(bp, tm);
BIO_write(bp, "Bad time value", 14);
return (0);
}
static const char *mon[12] = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};
int ASN1_GENERALIZEDTIME_print(BIO *bp, const ASN1_GENERALIZEDTIME *tm)
{
char *v;
int gmt = 0;
int i;
int y = 0, M = 0, d = 0, h = 0, m = 0, s = 0;
char *f = NULL;
int f_len = 0;
i = tm->length;
v = (char *)tm->data;
if (i < 12)
goto err;
if (v[i - 1] == 'Z')
gmt = 1;
for (i = 0; i < 12; i++)
if ((v[i] > '9') || (v[i] < '0'))
goto err;
y = (v[0] - '0') * 1000 + (v[1] - '0') * 100
+ (v[2] - '0') * 10 + (v[3] - '0');
M = (v[4] - '0') * 10 + (v[5] - '0');
if ((M > 12) || (M < 1))
goto err;
d = (v[6] - '0') * 10 + (v[7] - '0');
h = (v[8] - '0') * 10 + (v[9] - '0');
m = (v[10] - '0') * 10 + (v[11] - '0');
if (tm->length >= 14 &&
(v[12] >= '0') && (v[12] <= '9') &&
(v[13] >= '0') && (v[13] <= '9')) {
s = (v[12] - '0') * 10 + (v[13] - '0');
/* Check for fractions of seconds. */
if (tm->length >= 15 && v[14] == '.') {
int l = tm->length;
f = &v[14]; /* The decimal point. */
f_len = 1;
while (14 + f_len < l && f[f_len] >= '0' && f[f_len] <= '9')
++f_len;
}
}
if (BIO_printf(bp, "%s %2d %02d:%02d:%02d%.*s %d%s",
mon[M - 1], d, h, m, s, f_len, f, y,
(gmt) ? " GMT" : "") <= 0)
return (0);
else
return (1);
err:
BIO_write(bp, "Bad time value", 14);
return (0);
}
int ASN1_UTCTIME_print(BIO *bp, const ASN1_UTCTIME *tm)
{
const char *v;
int gmt = 0;
int i;
int y = 0, M = 0, d = 0, h = 0, m = 0, s = 0;
i = tm->length;
v = (const char *)tm->data;
if (i < 10)
goto err;
if (v[i - 1] == 'Z')
gmt = 1;
for (i = 0; i < 10; i++)
if ((v[i] > '9') || (v[i] < '0'))
goto err;
y = (v[0] - '0') * 10 + (v[1] - '0');
if (y < 50)
y += 100;
M = (v[2] - '0') * 10 + (v[3] - '0');
if ((M > 12) || (M < 1))
goto err;
d = (v[4] - '0') * 10 + (v[5] - '0');
h = (v[6] - '0') * 10 + (v[7] - '0');
m = (v[8] - '0') * 10 + (v[9] - '0');
if (tm->length >= 12 &&
(v[10] >= '0') && (v[10] <= '9') && (v[11] >= '0') && (v[11] <= '9'))
s = (v[10] - '0') * 10 + (v[11] - '0');
if (BIO_printf(bp, "%s %2d %02d:%02d:%02d %d%s",
mon[M - 1], d, h, m, s, y + 1900,
(gmt) ? " GMT" : "") <= 0)
return (0);
else
return (1);
err:
BIO_write(bp, "Bad time value", 14);
return (0);
}
int X509_NAME_print(BIO *bp, X509_NAME *name, int obase)
{
char *s, *c, *b;
int ret = 0, l, i;
l = 80 - 2 - obase;
b = X509_NAME_oneline(name, NULL, 0);
if (!b)
return 0;
if (!*b) {
OPENSSL_free(b);
return 1;
}
s = b + 1; /* skip the first slash */
c = s;
for (;;) {
#ifndef CHARSET_EBCDIC
if (((*s == '/') &&
((s[1] >= 'A') && (s[1] <= 'Z') && ((s[2] == '=') ||
((s[2] >= 'A')
&& (s[2] <= 'Z')
&& (s[3] == '='))
))) || (*s == '\0'))
#else
if (((*s == '/') &&
(isupper(s[1]) && ((s[2] == '=') ||
(isupper(s[2]) && (s[3] == '='))
))) || (*s == '\0'))
#endif
{
i = s - c;
if (BIO_write(bp, c, i) != i)
goto err;
c = s + 1; /* skip following slash */
if (*s != '\0') {
if (BIO_write(bp, ", ", 2) != 2)
goto err;
}
l--;
}
if (*s == '\0')
break;
s++;
l--;
}
ret = 1;
if (0) {
err:
X509err(X509_F_X509_NAME_PRINT, ERR_R_BUF_LIB);
}
OPENSSL_free(b);
return (ret);
}

View File

@ -1,115 +0,0 @@
/* t_x509a.c */
/*
* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project
* 1999.
*/
/* ====================================================================
* Copyright (c) 1999 The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
*
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* licensing@OpenSSL.org.
*
* 5. Products derived from this software may not be called "OpenSSL"
* nor may "OpenSSL" appear in their names without prior written
* permission of the OpenSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*
* This product includes cryptographic software written by Eric Young
* (eay@cryptsoft.com). This product includes software written by Tim
* Hudson (tjh@cryptsoft.com).
*
*/
#include <stdio.h>
#include "cryptlib.h"
#include <openssl/evp.h>
#include <openssl/asn1.h>
#include <openssl/x509.h>
/*
* X509_CERT_AUX and string set routines
*/
int X509_CERT_AUX_print(BIO *out, X509_CERT_AUX *aux, int indent)
{
char oidstr[80], first;
int i;
if (!aux)
return 1;
if (aux->trust) {
first = 1;
BIO_printf(out, "%*sTrusted Uses:\n%*s", indent, "", indent + 2, "");
for (i = 0; i < sk_ASN1_OBJECT_num(aux->trust); i++) {
if (!first)
BIO_puts(out, ", ");
else
first = 0;
OBJ_obj2txt(oidstr, sizeof oidstr,
sk_ASN1_OBJECT_value(aux->trust, i), 0);
BIO_puts(out, oidstr);
}
BIO_puts(out, "\n");
} else
BIO_printf(out, "%*sNo Trusted Uses.\n", indent, "");
if (aux->reject) {
first = 1;
BIO_printf(out, "%*sRejected Uses:\n%*s", indent, "", indent + 2, "");
for (i = 0; i < sk_ASN1_OBJECT_num(aux->reject); i++) {
if (!first)
BIO_puts(out, ", ");
else
first = 0;
OBJ_obj2txt(oidstr, sizeof oidstr,
sk_ASN1_OBJECT_value(aux->reject, i), 0);
BIO_puts(out, oidstr);
}
BIO_puts(out, "\n");
} else
BIO_printf(out, "%*sNo Rejected Uses.\n", indent, "");
if (aux->alias)
BIO_printf(out, "%*sAlias: %s\n", indent, "", aux->alias->data);
if (aux->keyid) {
BIO_printf(out, "%*sKey Id: ", indent, "");
for (i = 0; i < aux->keyid->length; i++)
BIO_printf(out, "%s%02X", i ? ":" : "", aux->keyid->data[i]);
BIO_write(out, "\n", 1);
}
return 1;
}

View File

@ -1,60 +1,10 @@
/* tasn_dec.c */
/* /*
* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project * Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
* 2000.
*/
/* ====================================================================
* Copyright (c) 2000-2005 The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
*
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* licensing@OpenSSL.org.
*
* 5. Products derived from this software may not be called "OpenSSL"
* nor may "OpenSSL" appear in their names without prior written
* permission of the OpenSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*
* This product includes cryptographic software written by Eric Young
* (eay@cryptsoft.com). This product includes software written by Tim
* Hudson (tjh@cryptsoft.com).
* *
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/ */
#include <stddef.h> #include <stddef.h>
@ -64,6 +14,12 @@
#include <openssl/objects.h> #include <openssl/objects.h>
#include <openssl/buffer.h> #include <openssl/buffer.h>
#include <openssl/err.h> #include <openssl/err.h>
#include "internal/numbers.h"
#include "asn1_locl.h"
static int asn1_item_embed_d2i(ASN1_VALUE **pval, const unsigned char **in,
long len, const ASN1_ITEM *it,
int tag, int aclass, char opt, ASN1_TLC *ctx);
static int asn1_check_eoc(const unsigned char **in, long len); static int asn1_check_eoc(const unsigned char **in, long len);
static int asn1_find_end(const unsigned char **in, long len, char inf); static int asn1_find_end(const unsigned char **in, long len, char inf);
@ -91,6 +47,8 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval,
const ASN1_ITEM *it, const ASN1_ITEM *it,
int tag, int aclass, char opt, int tag, int aclass, char opt,
ASN1_TLC *ctx); ASN1_TLC *ctx);
static int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,
int utype, char *free_cont, const ASN1_ITEM *it);
/* Table to convert tags to bit values, used for MSTRING type */ /* Table to convert tags to bit values, used for MSTRING type */
static const unsigned long tag2bit[32] = { static const unsigned long tag2bit[32] = {
@ -148,13 +106,15 @@ ASN1_VALUE *ASN1_item_d2i(ASN1_VALUE **pval,
return NULL; return NULL;
} }
int ASN1_template_d2i(ASN1_VALUE **pval, int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
const unsigned char **in, long len, const ASN1_ITEM *it,
const ASN1_TEMPLATE *tt) int tag, int aclass, char opt, ASN1_TLC *ctx)
{ {
ASN1_TLC c; int rv;
asn1_tlc_clear_nc(&c); rv = asn1_item_embed_d2i(pval, in, len, it, tag, aclass, opt, ctx);
return asn1_template_ex_d2i(pval, in, len, tt, 0, &c); if (rv <= 0)
ASN1_item_ex_free(pval, it);
return rv;
} }
/* /*
@ -162,26 +122,22 @@ int ASN1_template_d2i(ASN1_VALUE **pval,
* tag mismatch return -1 to handle OPTIONAL * tag mismatch return -1 to handle OPTIONAL
*/ */
int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, static int asn1_item_embed_d2i(ASN1_VALUE **pval, const unsigned char **in,
const ASN1_ITEM *it, long len, const ASN1_ITEM *it,
int tag, int aclass, char opt, ASN1_TLC *ctx) int tag, int aclass, char opt, ASN1_TLC *ctx)
{ {
const ASN1_TEMPLATE *tt, *errtt = NULL; const ASN1_TEMPLATE *tt, *errtt = NULL;
const ASN1_COMPAT_FUNCS *cf;
const ASN1_EXTERN_FUNCS *ef; const ASN1_EXTERN_FUNCS *ef;
const ASN1_AUX *aux = it->funcs; const ASN1_AUX *aux = it->funcs;
ASN1_aux_cb *asn1_cb; ASN1_aux_cb *asn1_cb;
const unsigned char *p = NULL, *q; const unsigned char *p = NULL, *q;
unsigned char *wp = NULL; /* BIG FAT WARNING! BREAKS CONST WHERE USED */ unsigned char oclass;
unsigned char imphack = 0, oclass;
char seq_eoc, seq_nolen, cst, isopt; char seq_eoc, seq_nolen, cst, isopt;
long tmplen; long tmplen;
int i; int i;
int otag; int otag;
int ret = 0; int ret = 0;
ASN1_VALUE **pchptr, *ptmpval; ASN1_VALUE **pchptr;
int combine = aclass & ASN1_TFLG_COMBINE;
aclass &= ~ASN1_TFLG_COMBINE;
if (!pval) if (!pval)
return 0; return 0;
if (aux && aux->asn1_cb) if (aux && aux->asn1_cb)
@ -199,7 +155,7 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
* template in the template itself. * template in the template itself.
*/ */
if ((tag != -1) || opt) { if ((tag != -1) || opt) {
ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1err(ASN1_F_ASN1_ITEM_EMBED_D2I,
ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE); ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE);
goto err; goto err;
} }
@ -208,7 +164,6 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
} }
return asn1_d2i_ex_primitive(pval, in, len, it, return asn1_d2i_ex_primitive(pval, in, len, it,
tag, aclass, opt, ctx); tag, aclass, opt, ctx);
break;
case ASN1_ITYPE_MSTRING: case ASN1_ITYPE_MSTRING:
p = *in; p = *in;
@ -216,7 +171,7 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
ret = asn1_check_tlen(NULL, &otag, &oclass, NULL, NULL, ret = asn1_check_tlen(NULL, &otag, &oclass, NULL, NULL,
&p, len, -1, 0, 1, ctx); &p, len, -1, 0, 1, ctx);
if (!ret) { if (!ret) {
ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR); ASN1err(ASN1_F_ASN1_ITEM_EMBED_D2I, ERR_R_NESTED_ASN1_ERROR);
goto err; goto err;
} }
@ -225,7 +180,7 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
/* If OPTIONAL, assume this is OK */ /* If OPTIONAL, assume this is OK */
if (opt) if (opt)
return -1; return -1;
ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_MSTRING_NOT_UNIVERSAL); ASN1err(ASN1_F_ASN1_ITEM_EMBED_D2I, ASN1_R_MSTRING_NOT_UNIVERSAL);
goto err; goto err;
} }
/* Check tag matches bit map */ /* Check tag matches bit map */
@ -233,7 +188,7 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
/* If OPTIONAL, assume this is OK */ /* If OPTIONAL, assume this is OK */
if (opt) if (opt)
return -1; return -1;
ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_MSTRING_WRONG_TAG); ASN1err(ASN1_F_ASN1_ITEM_EMBED_D2I, ASN1_R_MSTRING_WRONG_TAG);
goto err; goto err;
} }
return asn1_d2i_ex_primitive(pval, in, len, it, otag, 0, 0, ctx); return asn1_d2i_ex_primitive(pval, in, len, it, otag, 0, 0, ctx);
@ -243,66 +198,6 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
ef = it->funcs; ef = it->funcs;
return ef->asn1_ex_d2i(pval, in, len, it, tag, aclass, opt, ctx); return ef->asn1_ex_d2i(pval, in, len, it, tag, aclass, opt, ctx);
case ASN1_ITYPE_COMPAT:
/* we must resort to old style evil hackery */
cf = it->funcs;
/* If OPTIONAL see if it is there */
if (opt) {
int exptag;
p = *in;
if (tag == -1)
exptag = it->utype;
else
exptag = tag;
/*
* Don't care about anything other than presence of expected tag
*/
ret = asn1_check_tlen(NULL, NULL, NULL, NULL, NULL,
&p, len, exptag, aclass, 1, ctx);
if (!ret) {
ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR);
goto err;
}
if (ret == -1)
return -1;
}
/*
* This is the old style evil hack IMPLICIT handling: since the
* underlying code is expecting a tag and class other than the one
* present we change the buffer temporarily then change it back
* afterwards. This doesn't and never did work for tags > 30. Yes
* this is *horrible* but it is only needed for old style d2i which
* will hopefully not be around for much longer. FIXME: should copy
* the buffer then modify it so the input buffer can be const: we
* should *always* copy because the old style d2i might modify the
* buffer.
*/
if (tag != -1) {
wp = *(unsigned char **)in;
imphack = *wp;
if (p == NULL) {
ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR);
goto err;
}
*wp = (unsigned char)((*p & V_ASN1_CONSTRUCTED)
| it->utype);
}
ptmpval = cf->asn1_d2i(pval, in, len);
if (tag != -1)
*wp = imphack;
if (ptmpval)
return 1;
ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR);
goto err;
case ASN1_ITYPE_CHOICE: case ASN1_ITYPE_CHOICE:
if (asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it, NULL)) if (asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it, NULL))
goto auxerr; goto auxerr;
@ -312,11 +207,11 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
if ((i >= 0) && (i < it->tcount)) { if ((i >= 0) && (i < it->tcount)) {
tt = it->templates + i; tt = it->templates + i;
pchptr = asn1_get_field_ptr(pval, tt); pchptr = asn1_get_field_ptr(pval, tt);
ASN1_template_free(pchptr, tt); asn1_template_free(pchptr, tt);
asn1_set_choice_selector(pval, -1, it); asn1_set_choice_selector(pval, -1, it);
} }
} else if (!ASN1_item_ex_new(pval, it)) { } else if (!ASN1_item_ex_new(pval, it)) {
ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR); ASN1err(ASN1_F_ASN1_ITEM_EMBED_D2I, ERR_R_NESTED_ASN1_ERROR);
goto err; goto err;
} }
/* CHOICE type, try each possibility in turn */ /* CHOICE type, try each possibility in turn */
@ -333,9 +228,13 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
/* If positive return, read OK, break loop */ /* If positive return, read OK, break loop */
if (ret > 0) if (ret > 0)
break; break;
/* Otherwise must be an ASN1 parsing error */ /*
* Must be an ASN1 parsing error.
* Free up any partial choice value
*/
asn1_template_free(pchptr, tt);
errtt = tt; errtt = tt;
ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR); ASN1err(ASN1_F_ASN1_ITEM_EMBED_D2I, ERR_R_NESTED_ASN1_ERROR);
goto err; goto err;
} }
@ -347,11 +246,12 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
ASN1_item_ex_free(pval, it); ASN1_item_ex_free(pval, it);
return -1; return -1;
} }
ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_NO_MATCHING_CHOICE_TYPE); ASN1err(ASN1_F_ASN1_ITEM_EMBED_D2I, ASN1_R_NO_MATCHING_CHOICE_TYPE);
goto err; goto err;
} }
asn1_set_choice_selector(pval, i, it); asn1_set_choice_selector(pval, i, it);
if (asn1_cb && !asn1_cb(ASN1_OP_D2I_POST, pval, it, NULL)) if (asn1_cb && !asn1_cb(ASN1_OP_D2I_POST, pval, it, NULL))
goto auxerr; goto auxerr;
*in = p; *in = p;
@ -371,7 +271,7 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
ret = asn1_check_tlen(&len, NULL, NULL, &seq_eoc, &cst, ret = asn1_check_tlen(&len, NULL, NULL, &seq_eoc, &cst,
&p, len, tag, aclass, opt, ctx); &p, len, tag, aclass, opt, ctx);
if (!ret) { if (!ret) {
ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR); ASN1err(ASN1_F_ASN1_ITEM_EMBED_D2I, ERR_R_NESTED_ASN1_ERROR);
goto err; goto err;
} else if (ret == -1) } else if (ret == -1)
return -1; return -1;
@ -383,12 +283,12 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
else else
seq_nolen = seq_eoc; seq_nolen = seq_eoc;
if (!cst) { if (!cst) {
ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_SEQUENCE_NOT_CONSTRUCTED); ASN1err(ASN1_F_ASN1_ITEM_EMBED_D2I, ASN1_R_SEQUENCE_NOT_CONSTRUCTED);
goto err; goto err;
} }
if (!*pval && !ASN1_item_ex_new(pval, it)) { if (!*pval && !ASN1_item_ex_new(pval, it)) {
ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR); ASN1err(ASN1_F_ASN1_ITEM_EMBED_D2I, ERR_R_NESTED_ASN1_ERROR);
goto err; goto err;
} }
@ -404,7 +304,7 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
if (seqtt == NULL) if (seqtt == NULL)
continue; continue;
pseqval = asn1_get_field_ptr(pval, seqtt); pseqval = asn1_get_field_ptr(pval, seqtt);
ASN1_template_free(pseqval, seqtt); asn1_template_free(pseqval, seqtt);
} }
} }
@ -422,7 +322,7 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
q = p; q = p;
if (asn1_check_eoc(&p, len)) { if (asn1_check_eoc(&p, len)) {
if (!seq_eoc) { if (!seq_eoc) {
ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_UNEXPECTED_EOC); ASN1err(ASN1_F_ASN1_ITEM_EMBED_D2I, ASN1_R_UNEXPECTED_EOC);
goto err; goto err;
} }
len -= p - q; len -= p - q;
@ -452,7 +352,7 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
/* /*
* OPTIONAL component absent. Free and zero the field. * OPTIONAL component absent. Free and zero the field.
*/ */
ASN1_template_free(pseqval, seqtt); asn1_template_free(pseqval, seqtt);
continue; continue;
} }
/* Update length */ /* Update length */
@ -461,12 +361,12 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
/* Check for EOC if expecting one */ /* Check for EOC if expecting one */
if (seq_eoc && !asn1_check_eoc(&p, len)) { if (seq_eoc && !asn1_check_eoc(&p, len)) {
ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_MISSING_EOC); ASN1err(ASN1_F_ASN1_ITEM_EMBED_D2I, ASN1_R_MISSING_EOC);
goto err; goto err;
} }
/* Check all data read */ /* Check all data read */
if (!seq_nolen && len) { if (!seq_nolen && len) {
ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_SEQUENCE_LENGTH_MISMATCH); ASN1err(ASN1_F_ASN1_ITEM_EMBED_D2I, ASN1_R_SEQUENCE_LENGTH_MISMATCH);
goto err; goto err;
} }
@ -483,10 +383,10 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
if (seqtt->flags & ASN1_TFLG_OPTIONAL) { if (seqtt->flags & ASN1_TFLG_OPTIONAL) {
ASN1_VALUE **pseqval; ASN1_VALUE **pseqval;
pseqval = asn1_get_field_ptr(pval, seqtt); pseqval = asn1_get_field_ptr(pval, seqtt);
ASN1_template_free(pseqval, seqtt); asn1_template_free(pseqval, seqtt);
} else { } else {
errtt = seqtt; errtt = seqtt;
ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_FIELD_MISSING); ASN1err(ASN1_F_ASN1_ITEM_EMBED_D2I, ASN1_R_FIELD_MISSING);
goto err; goto err;
} }
} }
@ -502,10 +402,8 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
return 0; return 0;
} }
auxerr: auxerr:
ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_AUX_ERROR); ASN1err(ASN1_F_ASN1_ITEM_EMBED_D2I, ASN1_R_AUX_ERROR);
err: err:
if (combine == 0)
ASN1_item_ex_free(pval, it);
if (errtt) if (errtt)
ERR_add_error_data(4, "Field=", errtt->field_name, ERR_add_error_data(4, "Field=", errtt->field_name,
", Type=", it->sname); ", Type=", it->sname);
@ -587,7 +485,6 @@ static int asn1_template_ex_d2i(ASN1_VALUE **val,
return 1; return 1;
err: err:
ASN1_template_free(val, tt);
return 0; return 0;
} }
@ -598,6 +495,7 @@ static int asn1_template_noexp_d2i(ASN1_VALUE **val,
{ {
int flags, aclass; int flags, aclass;
int ret; int ret;
ASN1_VALUE *tval;
const unsigned char *p, *q; const unsigned char *p, *q;
if (!val) if (!val)
return 0; return 0;
@ -607,6 +505,15 @@ static int asn1_template_noexp_d2i(ASN1_VALUE **val,
p = *in; p = *in;
q = p; q = p;
/*
* If field is embedded then val needs fixing so it is a pointer to
* a pointer to a field.
*/
if (tt->flags & ASN1_TFLG_EMBED) {
tval = (ASN1_VALUE *)val;
val = &tval;
}
if (flags & ASN1_TFLG_SK_MASK) { if (flags & ASN1_TFLG_SK_MASK) {
/* SET OF, SEQUENCE OF */ /* SET OF, SEQUENCE OF */
int sktag, skaclass; int sktag, skaclass;
@ -631,7 +538,7 @@ static int asn1_template_noexp_d2i(ASN1_VALUE **val,
} else if (ret == -1) } else if (ret == -1)
return -1; return -1;
if (!*val) if (!*val)
*val = (ASN1_VALUE *)sk_new_null(); *val = (ASN1_VALUE *)OPENSSL_sk_new_null();
else { else {
/* /*
* We've got a valid STACK: free up any items present * We've got a valid STACK: free up any items present
@ -665,15 +572,18 @@ static int asn1_template_noexp_d2i(ASN1_VALUE **val,
break; break;
} }
skfield = NULL; skfield = NULL;
if (!ASN1_item_ex_d2i(&skfield, &p, len, if (!asn1_item_embed_d2i(&skfield, &p, len,
ASN1_ITEM_ptr(tt->item), -1, 0, 0, ctx)) { ASN1_ITEM_ptr(tt->item), -1, 0, 0, ctx)) {
ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I,
ERR_R_NESTED_ASN1_ERROR); ERR_R_NESTED_ASN1_ERROR);
/* |skfield| may be partially allocated despite failure. */
ASN1_item_free(skfield, ASN1_ITEM_ptr(tt->item));
goto err; goto err;
} }
len -= p - q; len -= p - q;
if (!sk_ASN1_VALUE_push((STACK_OF(ASN1_VALUE) *)*val, skfield)) { if (!sk_ASN1_VALUE_push((STACK_OF(ASN1_VALUE) *)*val, skfield)) {
ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, ERR_R_MALLOC_FAILURE); ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, ERR_R_MALLOC_FAILURE);
ASN1_item_free(skfield, ASN1_ITEM_ptr(tt->item));
goto err; goto err;
} }
} }
@ -683,7 +593,7 @@ static int asn1_template_noexp_d2i(ASN1_VALUE **val,
} }
} else if (flags & ASN1_TFLG_IMPTAG) { } else if (flags & ASN1_TFLG_IMPTAG) {
/* IMPLICIT tagging */ /* IMPLICIT tagging */
ret = ASN1_item_ex_d2i(val, &p, len, ret = asn1_item_embed_d2i(val, &p, len,
ASN1_ITEM_ptr(tt->item), tt->tag, aclass, opt, ASN1_ITEM_ptr(tt->item), tt->tag, aclass, opt,
ctx); ctx);
if (!ret) { if (!ret) {
@ -693,8 +603,8 @@ static int asn1_template_noexp_d2i(ASN1_VALUE **val,
return -1; return -1;
} else { } else {
/* Nothing special */ /* Nothing special */
ret = ASN1_item_ex_d2i(val, &p, len, ASN1_ITEM_ptr(tt->item), ret = asn1_item_embed_d2i(val, &p, len, ASN1_ITEM_ptr(tt->item),
-1, tt->flags & ASN1_TFLG_COMBINE, opt, ctx); -1, 0, opt, ctx);
if (!ret) { if (!ret) {
ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, ERR_R_NESTED_ASN1_ERROR); ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, ERR_R_NESTED_ASN1_ERROR);
goto err; goto err;
@ -706,7 +616,6 @@ static int asn1_template_noexp_d2i(ASN1_VALUE **val,
return 1; return 1;
err: err:
ASN1_template_free(val, tt);
return 0; return 0;
} }
@ -719,7 +628,7 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval,
long plen; long plen;
char cst, inf, free_cont = 0; char cst, inf, free_cont = 0;
const unsigned char *p; const unsigned char *p;
BUF_MEM buf = { 0, NULL, 0 }; BUF_MEM buf = { 0, NULL, 0, 0 };
const unsigned char *cont = NULL; const unsigned char *cont = NULL;
long len; long len;
if (!pval) { if (!pval) {
@ -774,7 +683,7 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval,
|| (utype == V_ASN1_SET) || (utype == V_ASN1_OTHER)) { || (utype == V_ASN1_SET) || (utype == V_ASN1_OTHER)) {
/* /*
* Clear context cache for type OTHER because the auto clear when we * Clear context cache for type OTHER because the auto clear when we
* have a exact match wont work * have a exact match won't work
*/ */
if (utype == V_ASN1_OTHER) { if (utype == V_ASN1_OTHER) {
asn1_tlc_clear(ctx); asn1_tlc_clear(ctx);
@ -837,14 +746,14 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval,
*in = p; *in = p;
ret = 1; ret = 1;
err: err:
if (free_cont && buf.data) if (free_cont)
OPENSSL_free(buf.data); OPENSSL_free(buf.data);
return ret; return ret;
} }
/* Translate ASN1 content octets into a structure */ /* Translate ASN1 content octets into a structure */
int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, static int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,
int utype, char *free_cont, const ASN1_ITEM *it) int utype, char *free_cont, const ASN1_ITEM *it)
{ {
ASN1_VALUE **opval = NULL; ASN1_VALUE **opval = NULL;
@ -941,7 +850,7 @@ int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,
/* All based on ASN1_STRING and handled the same */ /* All based on ASN1_STRING and handled the same */
if (!*pval) { if (!*pval) {
stmp = ASN1_STRING_type_new(utype); stmp = ASN1_STRING_type_new(utype);
if (!stmp) { if (stmp == NULL) {
ASN1err(ASN1_F_ASN1_EX_C2I, ERR_R_MALLOC_FAILURE); ASN1err(ASN1_F_ASN1_EX_C2I, ERR_R_MALLOC_FAILURE);
goto err; goto err;
} }
@ -952,7 +861,6 @@ int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,
} }
/* If we've already allocated a buffer use it */ /* If we've already allocated a buffer use it */
if (*free_cont) { if (*free_cont) {
if (stmp->data)
OPENSSL_free(stmp->data); OPENSSL_free(stmp->data);
stmp->data = (unsigned char *)cont; /* UGLY CAST! RL */ stmp->data = (unsigned char *)cont; /* UGLY CAST! RL */
stmp->length = len; stmp->length = len;
@ -990,7 +898,7 @@ int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,
static int asn1_find_end(const unsigned char **in, long len, char inf) static int asn1_find_end(const unsigned char **in, long len, char inf)
{ {
int expected_eoc; uint32_t expected_eoc;
long plen; long plen;
const unsigned char *p = *in, *q; const unsigned char *p = *in, *q;
/* If not indefinite length constructed just add length */ /* If not indefinite length constructed just add length */
@ -1020,10 +928,15 @@ static int asn1_find_end(const unsigned char **in, long len, char inf)
ASN1err(ASN1_F_ASN1_FIND_END, ERR_R_NESTED_ASN1_ERROR); ASN1err(ASN1_F_ASN1_FIND_END, ERR_R_NESTED_ASN1_ERROR);
return 0; return 0;
} }
if (inf) if (inf) {
if (expected_eoc == UINT32_MAX) {
ASN1err(ASN1_F_ASN1_FIND_END, ERR_R_NESTED_ASN1_ERROR);
return 0;
}
expected_eoc++; expected_eoc++;
else } else {
p += plen; p += plen;
}
len -= p - q; len -= p - q;
} }
if (expected_eoc) { if (expected_eoc) {
@ -1035,7 +948,7 @@ static int asn1_find_end(const unsigned char **in, long len, char inf)
} }
/* /*
* This function collects the asn1 data from a constructred string type into * This function collects the asn1 data from a constructed string type into
* a buffer. The values of 'in' and 'len' should refer to the contents of the * a buffer. The values of 'in' and 'len' should refer to the contents of the
* constructed type and 'inf' should be set if it is indefinite length. * constructed type and 'inf' should be set if it is indefinite length.
*/ */

View File

@ -1,69 +1,20 @@
/* tasn_enc.c */
/* /*
* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project * Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
* 2000.
*/
/* ====================================================================
* Copyright (c) 2000-2004 The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
*
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* licensing@OpenSSL.org.
*
* 5. Products derived from this software may not be called "OpenSSL"
* nor may "OpenSSL" appear in their names without prior written
* permission of the OpenSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*
* This product includes cryptographic software written by Eric Young
* (eay@cryptsoft.com). This product includes software written by Tim
* Hudson (tjh@cryptsoft.com).
* *
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/ */
#include <stddef.h> #include <stddef.h>
#include <string.h> #include <string.h>
#include <limits.h> #include "internal/cryptlib.h"
#include "cryptlib.h"
#include <openssl/asn1.h> #include <openssl/asn1.h>
#include <openssl/asn1t.h> #include <openssl/asn1t.h>
#include <openssl/objects.h> #include <openssl/objects.h>
#include "internal/asn1_int.h"
#include "asn1_locl.h"
static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out, static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out,
const ASN1_ITEM *it, int tag, int aclass); const ASN1_ITEM *it, int tag, int aclass);
@ -74,6 +25,8 @@ static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
const ASN1_TEMPLATE *tt, int tag, int aclass); const ASN1_TEMPLATE *tt, int tag, int aclass);
static int asn1_item_flags_i2d(ASN1_VALUE *val, unsigned char **out, static int asn1_item_flags_i2d(ASN1_VALUE *val, unsigned char **out,
const ASN1_ITEM *it, int flags); const ASN1_ITEM *it, int flags);
static int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype,
const ASN1_ITEM *it);
/* /*
* Top level i2d equivalents: the 'ndef' variant instructs the encoder to use * Top level i2d equivalents: the 'ndef' variant instructs the encoder to use
@ -108,7 +61,7 @@ static int asn1_item_flags_i2d(ASN1_VALUE *val, unsigned char **out,
if (len <= 0) if (len <= 0)
return len; return len;
buf = OPENSSL_malloc(len); buf = OPENSSL_malloc(len);
if (!buf) if (buf == NULL)
return -1; return -1;
p = buf; p = buf;
ASN1_item_ex_i2d(&val, &p, it, -1, flags); ASN1_item_ex_i2d(&val, &p, it, -1, flags);
@ -128,9 +81,7 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
const ASN1_ITEM *it, int tag, int aclass) const ASN1_ITEM *it, int tag, int aclass)
{ {
const ASN1_TEMPLATE *tt = NULL; const ASN1_TEMPLATE *tt = NULL;
unsigned char *p = NULL;
int i, seqcontlen, seqlen, ndef = 1; int i, seqcontlen, seqlen, ndef = 1;
const ASN1_COMPAT_FUNCS *cf;
const ASN1_EXTERN_FUNCS *ef; const ASN1_EXTERN_FUNCS *ef;
const ASN1_AUX *aux = it->funcs; const ASN1_AUX *aux = it->funcs;
ASN1_aux_cb *asn1_cb = 0; ASN1_aux_cb *asn1_cb = 0;
@ -148,7 +99,6 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
return asn1_template_ex_i2d(pval, out, it->templates, return asn1_template_ex_i2d(pval, out, it->templates,
tag, aclass); tag, aclass);
return asn1_i2d_ex_primitive(pval, out, it, tag, aclass); return asn1_i2d_ex_primitive(pval, out, it, tag, aclass);
break;
case ASN1_ITYPE_MSTRING: case ASN1_ITYPE_MSTRING:
return asn1_i2d_ex_primitive(pval, out, it, -1, aclass); return asn1_i2d_ex_primitive(pval, out, it, -1, aclass);
@ -174,20 +124,6 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
ef = it->funcs; ef = it->funcs;
return ef->asn1_ex_i2d(pval, out, it, tag, aclass); return ef->asn1_ex_i2d(pval, out, it, tag, aclass);
case ASN1_ITYPE_COMPAT:
/* old style hackery... */
cf = it->funcs;
if (out)
p = *out;
i = cf->asn1_i2d(*pval, out);
/*
* Fixup for IMPLICIT tag: note this messes up for tags > 30, but so
* did the old code. Tags > 30 are very rare anyway.
*/
if (out && (tag != -1))
*p = aclass | tag | (*p & V_ASN1_CONSTRUCTED);
return i;
case ASN1_ITYPE_NDEF_SEQUENCE: case ASN1_ITYPE_NDEF_SEQUENCE:
/* Use indefinite length constructed if requested */ /* Use indefinite length constructed if requested */
if (aclass & ASN1_TFLG_NDEF) if (aclass & ASN1_TFLG_NDEF)
@ -256,17 +192,21 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
return 0; return 0;
} }
int ASN1_template_i2d(ASN1_VALUE **pval, unsigned char **out,
const ASN1_TEMPLATE *tt)
{
return asn1_template_ex_i2d(pval, out, tt, -1, 0);
}
static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out, static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
const ASN1_TEMPLATE *tt, int tag, int iclass) const ASN1_TEMPLATE *tt, int tag, int iclass)
{ {
int i, ret, flags, ttag, tclass, ndef; int i, ret, flags, ttag, tclass, ndef;
ASN1_VALUE *tval;
flags = tt->flags; flags = tt->flags;
/*
* If field is embedded then val needs fixing so it is a pointer to
* a pointer to a field.
*/
if (flags & ASN1_TFLG_EMBED) {
tval = (ASN1_VALUE *)pval;
pval = &tval;
}
/* /*
* Work out tag and class to use: tagging may come either from the * Work out tag and class to use: tagging may come either from the
* template or the arguments, not both because this would create * template or the arguments, not both because this would create
@ -440,10 +380,10 @@ static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out,
else { else {
derlst = OPENSSL_malloc(sk_ASN1_VALUE_num(sk) derlst = OPENSSL_malloc(sk_ASN1_VALUE_num(sk)
* sizeof(*derlst)); * sizeof(*derlst));
if (!derlst) if (derlst == NULL)
return 0; return 0;
tmpdat = OPENSSL_malloc(skcontlen); tmpdat = OPENSSL_malloc(skcontlen);
if (!tmpdat) { if (tmpdat == NULL) {
OPENSSL_free(derlst); OPENSSL_free(derlst);
return 0; return 0;
} }
@ -546,7 +486,7 @@ static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out,
/* Produce content octets from a structure */ /* Produce content octets from a structure */
int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype, static int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype,
const ASN1_ITEM *it) const ASN1_ITEM *it)
{ {
ASN1_BOOLEAN *tbool = NULL; ASN1_BOOLEAN *tbool = NULL;
@ -616,7 +556,6 @@ int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype,
case V_ASN1_BIT_STRING: case V_ASN1_BIT_STRING:
return i2c_ASN1_BIT_STRING((ASN1_BIT_STRING *)*pval, return i2c_ASN1_BIT_STRING((ASN1_BIT_STRING *)*pval,
cout ? &cout : NULL); cout ? &cout : NULL);
break;
case V_ASN1_INTEGER: case V_ASN1_INTEGER:
case V_ASN1_ENUMERATED: case V_ASN1_ENUMERATED:
@ -624,7 +563,6 @@ int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype,
* These are all have the same content format as ASN1_INTEGER * These are all have the same content format as ASN1_INTEGER
*/ */
return i2c_ASN1_INTEGER((ASN1_INTEGER *)*pval, cout ? &cout : NULL); return i2c_ASN1_INTEGER((ASN1_INTEGER *)*pval, cout ? &cout : NULL);
break;
case V_ASN1_OCTET_STRING: case V_ASN1_OCTET_STRING:
case V_ASN1_NUMERICSTRING: case V_ASN1_NUMERICSTRING:

View File

@ -1,91 +1,42 @@
/* tasn_fre.c */
/* /*
* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project * Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
* 2000.
*/
/* ====================================================================
* Copyright (c) 2000 The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
*
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* licensing@OpenSSL.org.
*
* 5. Products derived from this software may not be called "OpenSSL"
* nor may "OpenSSL" appear in their names without prior written
* permission of the OpenSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*
* This product includes cryptographic software written by Eric Young
* (eay@cryptsoft.com). This product includes software written by Tim
* Hudson (tjh@cryptsoft.com).
* *
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/ */
#include <stddef.h> #include <stddef.h>
#include <openssl/asn1.h> #include <openssl/asn1.h>
#include <openssl/asn1t.h> #include <openssl/asn1t.h>
#include <openssl/objects.h> #include <openssl/objects.h>
#include "asn1_locl.h"
static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, static void asn1_item_embed_free(ASN1_VALUE **pval, const ASN1_ITEM *it,
int combine); int embed);
/* Free up an ASN1 structure */ /* Free up an ASN1 structure */
void ASN1_item_free(ASN1_VALUE *val, const ASN1_ITEM *it) void ASN1_item_free(ASN1_VALUE *val, const ASN1_ITEM *it)
{ {
asn1_item_combine_free(&val, it, 0); asn1_item_embed_free(&val, it, 0);
} }
void ASN1_item_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it) void ASN1_item_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
{ {
asn1_item_combine_free(pval, it, 0); asn1_item_embed_free(pval, it, 0);
} }
static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, static void asn1_item_embed_free(ASN1_VALUE **pval, const ASN1_ITEM *it,
int combine) int embed)
{ {
const ASN1_TEMPLATE *tt = NULL, *seqtt; const ASN1_TEMPLATE *tt = NULL, *seqtt;
const ASN1_EXTERN_FUNCS *ef; const ASN1_EXTERN_FUNCS *ef;
const ASN1_COMPAT_FUNCS *cf;
const ASN1_AUX *aux = it->funcs; const ASN1_AUX *aux = it->funcs;
ASN1_aux_cb *asn1_cb; ASN1_aux_cb *asn1_cb;
int i; int i;
if (!pval) if (!pval)
return; return;
if ((it->itype != ASN1_ITYPE_PRIMITIVE) && !*pval) if ((it->itype != ASN1_ITYPE_PRIMITIVE) && !*pval)
@ -99,13 +50,13 @@ static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it,
case ASN1_ITYPE_PRIMITIVE: case ASN1_ITYPE_PRIMITIVE:
if (it->templates) if (it->templates)
ASN1_template_free(pval, it->templates); asn1_template_free(pval, it->templates);
else else
ASN1_primitive_free(pval, it); asn1_primitive_free(pval, it, embed);
break; break;
case ASN1_ITYPE_MSTRING: case ASN1_ITYPE_MSTRING:
ASN1_primitive_free(pval, it); asn1_primitive_free(pval, it, embed);
break; break;
case ASN1_ITYPE_CHOICE: case ASN1_ITYPE_CHOICE:
@ -117,24 +68,19 @@ static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it,
i = asn1_get_choice_selector(pval, it); i = asn1_get_choice_selector(pval, it);
if ((i >= 0) && (i < it->tcount)) { if ((i >= 0) && (i < it->tcount)) {
ASN1_VALUE **pchval; ASN1_VALUE **pchval;
tt = it->templates + i; tt = it->templates + i;
pchval = asn1_get_field_ptr(pval, tt); pchval = asn1_get_field_ptr(pval, tt);
ASN1_template_free(pchval, tt); asn1_template_free(pchval, tt);
} }
if (asn1_cb) if (asn1_cb)
asn1_cb(ASN1_OP_FREE_POST, pval, it, NULL); asn1_cb(ASN1_OP_FREE_POST, pval, it, NULL);
if (!combine) { if (embed == 0) {
OPENSSL_free(*pval); OPENSSL_free(*pval);
*pval = NULL; *pval = NULL;
} }
break; break;
case ASN1_ITYPE_COMPAT:
cf = it->funcs;
if (cf && cf->asn1_free)
cf->asn1_free(*pval);
break;
case ASN1_ITYPE_EXTERN: case ASN1_ITYPE_EXTERN:
ef = it->funcs; ef = it->funcs;
if (ef && ef->asn1_ex_free) if (ef && ef->asn1_ex_free)
@ -143,7 +89,7 @@ static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it,
case ASN1_ITYPE_NDEF_SEQUENCE: case ASN1_ITYPE_NDEF_SEQUENCE:
case ASN1_ITYPE_SEQUENCE: case ASN1_ITYPE_SEQUENCE:
if (asn1_do_lock(pval, -1, it) > 0) if (asn1_do_lock(pval, -1, it) != 0) /* if error or ref-counter > 0 */
return; return;
if (asn1_cb) { if (asn1_cb) {
i = asn1_cb(ASN1_OP_FREE_PRE, pval, it, NULL); i = asn1_cb(ASN1_OP_FREE_PRE, pval, it, NULL);
@ -153,21 +99,23 @@ static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it,
asn1_enc_free(pval, it); asn1_enc_free(pval, it);
/* /*
* If we free up as normal we will invalidate any ANY DEFINED BY * If we free up as normal we will invalidate any ANY DEFINED BY
* field and we wont be able to determine the type of the field it * field and we won't be able to determine the type of the field it
* defines. So free up in reverse order. * defines. So free up in reverse order.
*/ */
tt = it->templates + it->tcount - 1; tt = it->templates + it->tcount;
for (i = 0; i < it->tcount; tt--, i++) { for (i = 0; i < it->tcount; i++) {
ASN1_VALUE **pseqval; ASN1_VALUE **pseqval;
tt--;
seqtt = asn1_do_adb(pval, tt, 0); seqtt = asn1_do_adb(pval, tt, 0);
if (!seqtt) if (!seqtt)
continue; continue;
pseqval = asn1_get_field_ptr(pval, seqtt); pseqval = asn1_get_field_ptr(pval, seqtt);
ASN1_template_free(pseqval, seqtt); asn1_template_free(pseqval, seqtt);
} }
if (asn1_cb) if (asn1_cb)
asn1_cb(ASN1_OP_FREE_POST, pval, it, NULL); asn1_cb(ASN1_OP_FREE_POST, pval, it, NULL);
if (!combine) { if (embed == 0) {
OPENSSL_free(*pval); OPENSSL_free(*pval);
*pval = NULL; *pval = NULL;
} }
@ -175,37 +123,48 @@ static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it,
} }
} }
void ASN1_template_free(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) void asn1_template_free(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
{ {
int i; int embed = tt->flags & ASN1_TFLG_EMBED;
ASN1_VALUE *tval;
if (embed) {
tval = (ASN1_VALUE *)pval;
pval = &tval;
}
if (tt->flags & ASN1_TFLG_SK_MASK) { if (tt->flags & ASN1_TFLG_SK_MASK) {
STACK_OF(ASN1_VALUE) *sk = (STACK_OF(ASN1_VALUE) *)*pval; STACK_OF(ASN1_VALUE) *sk = (STACK_OF(ASN1_VALUE) *)*pval;
int i;
for (i = 0; i < sk_ASN1_VALUE_num(sk); i++) { for (i = 0; i < sk_ASN1_VALUE_num(sk); i++) {
ASN1_VALUE *vtmp; ASN1_VALUE *vtmp = sk_ASN1_VALUE_value(sk, i);
vtmp = sk_ASN1_VALUE_value(sk, i);
asn1_item_combine_free(&vtmp, ASN1_ITEM_ptr(tt->item), 0); asn1_item_embed_free(&vtmp, ASN1_ITEM_ptr(tt->item), embed);
} }
sk_ASN1_VALUE_free(sk); sk_ASN1_VALUE_free(sk);
*pval = NULL; *pval = NULL;
} else } else {
asn1_item_combine_free(pval, ASN1_ITEM_ptr(tt->item), asn1_item_embed_free(pval, ASN1_ITEM_ptr(tt->item), embed);
tt->flags & ASN1_TFLG_COMBINE); }
} }
void ASN1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it) void asn1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int embed)
{ {
int utype; int utype;
/* Special case: if 'it' is a primitive with a free_func, use that. */
if (it) { if (it) {
const ASN1_PRIMITIVE_FUNCS *pf; const ASN1_PRIMITIVE_FUNCS *pf = it->funcs;
pf = it->funcs;
if (pf && pf->prim_free) { if (pf && pf->prim_free) {
pf->prim_free(pval, it); pf->prim_free(pval, it);
return; return;
} }
} }
/* Special case: if 'it' is NULL free contents of ASN1_TYPE */
/* Special case: if 'it' is NULL, free contents of ASN1_TYPE */
if (!it) { if (!it) {
ASN1_TYPE *typ = (ASN1_TYPE *)*pval; ASN1_TYPE *typ = (ASN1_TYPE *)*pval;
utype = typ->type; utype = typ->type;
pval = &typ->value.asn1_value; pval = &typ->value.asn1_value;
if (!*pval) if (!*pval)
@ -236,13 +195,12 @@ void ASN1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
break; break;
case V_ASN1_ANY: case V_ASN1_ANY:
ASN1_primitive_free(pval, NULL); asn1_primitive_free(pval, NULL, 0);
OPENSSL_free(*pval); OPENSSL_free(*pval);
break; break;
default: default:
ASN1_STRING_free((ASN1_STRING *)*pval); asn1_string_embed_free((ASN1_STRING *)*pval, embed);
*pval = NULL;
break; break;
} }
*pval = NULL; *pval = NULL;

View File

@ -1,60 +1,10 @@
/* tasn_new.c */
/* /*
* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project * Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
* 2000.
*/
/* ====================================================================
* Copyright (c) 2000-2004 The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
*
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* licensing@OpenSSL.org.
*
* 5. Products derived from this software may not be called "OpenSSL"
* nor may "OpenSSL" appear in their names without prior written
* permission of the OpenSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*
* This product includes cryptographic software written by Eric Young
* (eay@cryptsoft.com). This product includes software written by Tim
* Hudson (tjh@cryptsoft.com).
* *
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/ */
#include <stddef.h> #include <stddef.h>
@ -63,10 +13,14 @@
#include <openssl/err.h> #include <openssl/err.h>
#include <openssl/asn1t.h> #include <openssl/asn1t.h>
#include <string.h> #include <string.h>
#include "asn1_locl.h"
static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, static int asn1_item_embed_new(ASN1_VALUE **pval, const ASN1_ITEM *it,
int combine); int embed);
static int asn1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it,
int embed);
static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it); static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it);
static int asn1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt);
static void asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt); static void asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt);
static void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it); static void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it);
@ -82,14 +36,12 @@ ASN1_VALUE *ASN1_item_new(const ASN1_ITEM *it)
int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it) int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
{ {
return asn1_item_ex_combine_new(pval, it, 0); return asn1_item_embed_new(pval, it, 0);
} }
static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int asn1_item_embed_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int embed)
int combine)
{ {
const ASN1_TEMPLATE *tt = NULL; const ASN1_TEMPLATE *tt = NULL;
const ASN1_COMPAT_FUNCS *cf;
const ASN1_EXTERN_FUNCS *ef; const ASN1_EXTERN_FUNCS *ef;
const ASN1_AUX *aux = it->funcs; const ASN1_AUX *aux = it->funcs;
ASN1_aux_cb *asn1_cb; ASN1_aux_cb *asn1_cb;
@ -100,9 +52,8 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it,
else else
asn1_cb = 0; asn1_cb = 0;
#ifdef CRYPTO_MDEBUG #ifndef OPENSSL_NO_CRYPTO_MDEBUG
if (it->sname) OPENSSL_mem_debug_push(it->sname ? it->sname : "asn1_item_embed_new");
CRYPTO_push_info(it->sname);
#endif #endif
switch (it->itype) { switch (it->itype) {
@ -115,25 +66,16 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it,
} }
break; break;
case ASN1_ITYPE_COMPAT:
cf = it->funcs;
if (cf && cf->asn1_new) {
*pval = cf->asn1_new();
if (!*pval)
goto memerr;
}
break;
case ASN1_ITYPE_PRIMITIVE: case ASN1_ITYPE_PRIMITIVE:
if (it->templates) { if (it->templates) {
if (!ASN1_template_new(pval, it->templates)) if (!asn1_template_new(pval, it->templates))
goto memerr; goto memerr;
} else if (!ASN1_primitive_new(pval, it)) } else if (!asn1_primitive_new(pval, it, embed))
goto memerr; goto memerr;
break; break;
case ASN1_ITYPE_MSTRING: case ASN1_ITYPE_MSTRING:
if (!ASN1_primitive_new(pval, it)) if (!asn1_primitive_new(pval, it, embed))
goto memerr; goto memerr;
break; break;
@ -143,22 +85,22 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it,
if (!i) if (!i)
goto auxerr; goto auxerr;
if (i == 2) { if (i == 2) {
#ifdef CRYPTO_MDEBUG #ifndef OPENSSL_NO_CRYPTO_MDEBUG
if (it->sname) OPENSSL_mem_debug_pop();
CRYPTO_pop_info();
#endif #endif
return 1; return 1;
} }
} }
if (!combine) { if (embed) {
*pval = OPENSSL_malloc(it->size);
if (!*pval)
goto memerr;
memset(*pval, 0, it->size); memset(*pval, 0, it->size);
} else {
*pval = OPENSSL_zalloc(it->size);
if (*pval == NULL)
goto memerr;
} }
asn1_set_choice_selector(pval, -1, it); asn1_set_choice_selector(pval, -1, it);
if (asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it, NULL)) if (asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it, NULL))
goto auxerr; goto auxerr2;
break; break;
case ASN1_ITYPE_NDEF_SEQUENCE: case ASN1_ITYPE_NDEF_SEQUENCE:
@ -168,50 +110,52 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it,
if (!i) if (!i)
goto auxerr; goto auxerr;
if (i == 2) { if (i == 2) {
#ifdef CRYPTO_MDEBUG #ifndef OPENSSL_NO_CRYPTO_MDEBUG
if (it->sname) OPENSSL_mem_debug_pop();
CRYPTO_pop_info();
#endif #endif
return 1; return 1;
} }
} }
if (!combine) { if (embed) {
*pval = OPENSSL_malloc(it->size);
if (!*pval)
goto memerr;
memset(*pval, 0, it->size); memset(*pval, 0, it->size);
asn1_do_lock(pval, 0, it); } else {
asn1_enc_init(pval, it); *pval = OPENSSL_zalloc(it->size);
if (*pval == NULL)
goto memerr;
} }
/* 0 : init. lock */
if (asn1_do_lock(pval, 0, it) < 0)
goto memerr2;
asn1_enc_init(pval, it);
for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) { for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) {
pseqval = asn1_get_field_ptr(pval, tt); pseqval = asn1_get_field_ptr(pval, tt);
if (!ASN1_template_new(pseqval, tt)) if (!asn1_template_new(pseqval, tt))
goto memerr; goto memerr2;
} }
if (asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it, NULL)) if (asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it, NULL))
goto auxerr; goto auxerr2;
break; break;
} }
#ifdef CRYPTO_MDEBUG #ifndef OPENSSL_NO_CRYPTO_MDEBUG
if (it->sname) OPENSSL_mem_debug_pop();
CRYPTO_pop_info();
#endif #endif
return 1; return 1;
memerr2:
ASN1_item_ex_free(pval, it);
memerr: memerr:
ASN1err(ASN1_F_ASN1_ITEM_EX_COMBINE_NEW, ERR_R_MALLOC_FAILURE); ASN1err(ASN1_F_ASN1_ITEM_EMBED_NEW, ERR_R_MALLOC_FAILURE);
#ifdef CRYPTO_MDEBUG #ifndef OPENSSL_NO_CRYPTO_MDEBUG
if (it->sname) OPENSSL_mem_debug_pop();
CRYPTO_pop_info();
#endif #endif
return 0; return 0;
auxerr: auxerr2:
ASN1err(ASN1_F_ASN1_ITEM_EX_COMBINE_NEW, ASN1_R_AUX_ERROR);
ASN1_item_ex_free(pval, it); ASN1_item_ex_free(pval, it);
#ifdef CRYPTO_MDEBUG auxerr:
if (it->sname) ASN1err(ASN1_F_ASN1_ITEM_EMBED_NEW, ASN1_R_AUX_ERROR);
CRYPTO_pop_info(); #ifndef OPENSSL_NO_CRYPTO_MDEBUG
OPENSSL_mem_debug_pop();
#endif #endif
return 0; return 0;
@ -242,7 +186,6 @@ static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it)
asn1_primitive_clear(pval, it); asn1_primitive_clear(pval, it);
break; break;
case ASN1_ITYPE_COMPAT:
case ASN1_ITYPE_CHOICE: case ASN1_ITYPE_CHOICE:
case ASN1_ITYPE_SEQUENCE: case ASN1_ITYPE_SEQUENCE:
case ASN1_ITYPE_NDEF_SEQUENCE: case ASN1_ITYPE_NDEF_SEQUENCE:
@ -251,10 +194,16 @@ static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it)
} }
} }
int ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) static int asn1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
{ {
const ASN1_ITEM *it = ASN1_ITEM_ptr(tt->item); const ASN1_ITEM *it = ASN1_ITEM_ptr(tt->item);
int embed = tt->flags & ASN1_TFLG_EMBED;
ASN1_VALUE *tval;
int ret; int ret;
if (embed) {
tval = (ASN1_VALUE *)pval;
pval = &tval;
}
if (tt->flags & ASN1_TFLG_OPTIONAL) { if (tt->flags & ASN1_TFLG_OPTIONAL) {
asn1_template_clear(pval, tt); asn1_template_clear(pval, tt);
return 1; return 1;
@ -265,9 +214,9 @@ int ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
*pval = NULL; *pval = NULL;
return 1; return 1;
} }
#ifdef CRYPTO_MDEBUG #ifndef OPENSSL_NO_CRYPTO_MDEBUG
if (tt->field_name) OPENSSL_mem_debug_push(tt->field_name
CRYPTO_push_info(tt->field_name); ? tt->field_name : "asn1_template_new");
#endif #endif
/* If SET OF or SEQUENCE OF, its a STACK */ /* If SET OF or SEQUENCE OF, its a STACK */
if (tt->flags & ASN1_TFLG_SK_MASK) { if (tt->flags & ASN1_TFLG_SK_MASK) {
@ -283,11 +232,10 @@ int ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
goto done; goto done;
} }
/* Otherwise pass it back to the item routine */ /* Otherwise pass it back to the item routine */
ret = asn1_item_ex_combine_new(pval, it, tt->flags & ASN1_TFLG_COMBINE); ret = asn1_item_embed_new(pval, it, embed);
done: done:
#ifdef CRYPTO_MDEBUG #ifndef OPENSSL_NO_CRYPTO_MDEBUG
if (it->sname) OPENSSL_mem_debug_pop();
CRYPTO_pop_info();
#endif #endif
return ret; return ret;
} }
@ -306,7 +254,8 @@ static void asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
* all the old functions. * all the old functions.
*/ */
int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it) static int asn1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it,
int embed)
{ {
ASN1_TYPE *typ; ASN1_TYPE *typ;
ASN1_STRING *str; ASN1_STRING *str;
@ -339,8 +288,8 @@ int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
return 1; return 1;
case V_ASN1_ANY: case V_ASN1_ANY:
typ = OPENSSL_malloc(sizeof(ASN1_TYPE)); typ = OPENSSL_malloc(sizeof(*typ));
if (!typ) if (typ == NULL)
return 0; return 0;
typ->value.ptr = NULL; typ->value.ptr = NULL;
typ->type = -1; typ->type = -1;
@ -348,10 +297,17 @@ int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
break; break;
default: default:
if (embed) {
str = *(ASN1_STRING **)pval;
memset(str, 0, sizeof(*str));
str->type = utype;
str->flags = ASN1_STRING_FLAG_EMBED;
} else {
str = ASN1_STRING_type_new(utype); str = ASN1_STRING_type_new(utype);
*pval = (ASN1_VALUE *)str;
}
if (it->itype == ASN1_ITYPE_MSTRING && str) if (it->itype == ASN1_ITYPE_MSTRING && str)
str->flags |= ASN1_STRING_FLAG_MSTRING; str->flags |= ASN1_STRING_FLAG_MSTRING;
*pval = (ASN1_VALUE *)str;
break; break;
} }
if (*pval) if (*pval)

View File

@ -1,70 +1,21 @@
/* tasn_prn.c */
/* /*
* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project * Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
* 2000.
*/
/* ====================================================================
* Copyright (c) 2000,2005 The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
*
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* licensing@OpenSSL.org.
*
* 5. Products derived from this software may not be called "OpenSSL"
* nor may "OpenSSL" appear in their names without prior written
* permission of the OpenSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*
* This product includes cryptographic software written by Eric Young
* (eay@cryptsoft.com). This product includes software written by Tim
* Hudson (tjh@cryptsoft.com).
* *
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/ */
#include <stddef.h> #include <stddef.h>
#include "cryptlib.h" #include "internal/cryptlib.h"
#include <openssl/asn1.h> #include <openssl/asn1.h>
#include <openssl/asn1t.h> #include <openssl/asn1t.h>
#include <openssl/objects.h> #include <openssl/objects.h>
#include <openssl/buffer.h> #include <openssl/buffer.h>
#include <openssl/err.h> #include <openssl/err.h>
#include <openssl/x509v3.h> #include <openssl/x509v3.h>
#include "internal/asn1_int.h"
#include "asn1_locl.h" #include "asn1_locl.h"
/* /*
@ -73,7 +24,7 @@
/* ASN1_PCTX routines */ /* ASN1_PCTX routines */
ASN1_PCTX default_pctx = { static ASN1_PCTX default_pctx = {
ASN1_PCTX_FLAGS_SHOW_ABSENT, /* flags */ ASN1_PCTX_FLAGS_SHOW_ABSENT, /* flags */
0, /* nm_flags */ 0, /* nm_flags */
0, /* cert_flags */ 0, /* cert_flags */
@ -84,16 +35,12 @@ ASN1_PCTX default_pctx = {
ASN1_PCTX *ASN1_PCTX_new(void) ASN1_PCTX *ASN1_PCTX_new(void)
{ {
ASN1_PCTX *ret; ASN1_PCTX *ret;
ret = OPENSSL_malloc(sizeof(ASN1_PCTX));
ret = OPENSSL_zalloc(sizeof(*ret));
if (ret == NULL) { if (ret == NULL) {
ASN1err(ASN1_F_ASN1_PCTX_NEW, ERR_R_MALLOC_FAILURE); ASN1err(ASN1_F_ASN1_PCTX_NEW, ERR_R_MALLOC_FAILURE);
return NULL; return NULL;
} }
ret->flags = 0;
ret->nm_flags = 0;
ret->cert_flags = 0;
ret->oid_flags = 0;
ret->str_flags = 0;
return ret; return ret;
} }
@ -102,7 +49,7 @@ void ASN1_PCTX_free(ASN1_PCTX *p)
OPENSSL_free(p); OPENSSL_free(p);
} }
unsigned long ASN1_PCTX_get_flags(ASN1_PCTX *p) unsigned long ASN1_PCTX_get_flags(const ASN1_PCTX *p)
{ {
return p->flags; return p->flags;
} }
@ -112,7 +59,7 @@ void ASN1_PCTX_set_flags(ASN1_PCTX *p, unsigned long flags)
p->flags = flags; p->flags = flags;
} }
unsigned long ASN1_PCTX_get_nm_flags(ASN1_PCTX *p) unsigned long ASN1_PCTX_get_nm_flags(const ASN1_PCTX *p)
{ {
return p->nm_flags; return p->nm_flags;
} }
@ -122,7 +69,7 @@ void ASN1_PCTX_set_nm_flags(ASN1_PCTX *p, unsigned long flags)
p->nm_flags = flags; p->nm_flags = flags;
} }
unsigned long ASN1_PCTX_get_cert_flags(ASN1_PCTX *p) unsigned long ASN1_PCTX_get_cert_flags(const ASN1_PCTX *p)
{ {
return p->cert_flags; return p->cert_flags;
} }
@ -132,7 +79,7 @@ void ASN1_PCTX_set_cert_flags(ASN1_PCTX *p, unsigned long flags)
p->cert_flags = flags; p->cert_flags = flags;
} }
unsigned long ASN1_PCTX_get_oid_flags(ASN1_PCTX *p) unsigned long ASN1_PCTX_get_oid_flags(const ASN1_PCTX *p)
{ {
return p->oid_flags; return p->oid_flags;
} }
@ -142,7 +89,7 @@ void ASN1_PCTX_set_oid_flags(ASN1_PCTX *p, unsigned long flags)
p->oid_flags = flags; p->oid_flags = flags;
} }
unsigned long ASN1_PCTX_get_str_flags(ASN1_PCTX *p) unsigned long ASN1_PCTX_get_str_flags(const ASN1_PCTX *p)
{ {
return p->str_flags; return p->str_flags;
} }
@ -159,7 +106,7 @@ static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
const char *fname, const char *sname, const char *fname, const char *sname,
int nohdr, const ASN1_PCTX *pctx); int nohdr, const ASN1_PCTX *pctx);
int asn1_template_print_ctx(BIO *out, ASN1_VALUE **fld, int indent, static int asn1_template_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
const ASN1_TEMPLATE *tt, const ASN1_PCTX *pctx); const ASN1_TEMPLATE *tt, const ASN1_PCTX *pctx);
static int asn1_primitive_print(BIO *out, ASN1_VALUE **fld, static int asn1_primitive_print(BIO *out, ASN1_VALUE **fld,
@ -223,7 +170,7 @@ static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
return 0; return 0;
break; break;
} }
/* fall thru */ /* fall through */
case ASN1_ITYPE_MSTRING: case ASN1_ITYPE_MSTRING:
if (!asn1_primitive_print(out, fld, it, indent, fname, sname, pctx)) if (!asn1_primitive_print(out, fld, it, indent, fname, sname, pctx))
return 0; return 0;
@ -247,10 +194,6 @@ static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
break; break;
case ASN1_ITYPE_CHOICE: case ASN1_ITYPE_CHOICE:
#if 0
if (!nohdr && !asn1_print_fsname(out, indent, fname, sname, pctx))
return 0;
#endif
/* CHOICE type, get selector */ /* CHOICE type, get selector */
i = asn1_get_choice_selector(fld, it); i = asn1_get_choice_selector(fld, it);
/* This should never happen... */ /* This should never happen... */
@ -318,11 +261,12 @@ static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
return 1; return 1;
} }
int asn1_template_print_ctx(BIO *out, ASN1_VALUE **fld, int indent, static int asn1_template_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
const ASN1_TEMPLATE *tt, const ASN1_PCTX *pctx) const ASN1_TEMPLATE *tt, const ASN1_PCTX *pctx)
{ {
int i, flags; int i, flags;
const char *sname, *fname; const char *sname, *fname;
ASN1_VALUE *tfld;
flags = tt->flags; flags = tt->flags;
if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_FIELD_STRUCT_NAME) if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_FIELD_STRUCT_NAME)
sname = ASN1_ITEM_ptr(tt->item)->sname; sname = ASN1_ITEM_ptr(tt->item)->sname;
@ -332,6 +276,16 @@ int asn1_template_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
fname = NULL; fname = NULL;
else else
fname = tt->field_name; fname = tt->field_name;
/*
* If field is embedded then fld needs fixing so it is a pointer to
* a pointer to a field.
*/
if (flags & ASN1_TFLG_EMBED) {
tfld = (ASN1_VALUE *)fld;
fld = &tfld;
}
if (flags & ASN1_TFLG_SK_MASK) { if (flags & ASN1_TFLG_SK_MASK) {
char *tname; char *tname;
ASN1_VALUE *skitem; ASN1_VALUE *skitem;
@ -377,13 +331,8 @@ static int asn1_print_fsname(BIO *out, int indent,
const char *fname, const char *sname, const char *fname, const char *sname,
const ASN1_PCTX *pctx) const ASN1_PCTX *pctx)
{ {
static char spaces[] = " "; static const char spaces[] = " ";
const int nspaces = sizeof(spaces) - 1; static const int nspaces = sizeof(spaces) - 1;
#if 0
if (!sname && !fname)
return 1;
#endif
while (indent > nspaces) { while (indent > nspaces) {
if (BIO_write(out, spaces, nspaces) != nspaces) if (BIO_write(out, spaces, nspaces) != nspaces)
@ -416,8 +365,7 @@ static int asn1_print_fsname(BIO *out, int indent,
return 1; return 1;
} }
static int asn1_print_boolean_ctx(BIO *out, int boolval, static int asn1_print_boolean(BIO *out, int boolval)
const ASN1_PCTX *pctx)
{ {
const char *str; const char *str;
switch (boolval) { switch (boolval) {
@ -441,8 +389,7 @@ static int asn1_print_boolean_ctx(BIO *out, int boolval,
} }
static int asn1_print_integer_ctx(BIO *out, ASN1_INTEGER *str, static int asn1_print_integer(BIO *out, const ASN1_INTEGER *str)
const ASN1_PCTX *pctx)
{ {
char *s; char *s;
int ret = 1; int ret = 1;
@ -455,8 +402,7 @@ static int asn1_print_integer_ctx(BIO *out, ASN1_INTEGER *str,
return ret; return ret;
} }
static int asn1_print_oid_ctx(BIO *out, const ASN1_OBJECT *oid, static int asn1_print_oid(BIO *out, const ASN1_OBJECT *oid)
const ASN1_PCTX *pctx)
{ {
char objbuf[80]; char objbuf[80];
const char *ln; const char *ln;
@ -469,8 +415,7 @@ static int asn1_print_oid_ctx(BIO *out, const ASN1_OBJECT *oid,
return 1; return 1;
} }
static int asn1_print_obstring_ctx(BIO *out, ASN1_STRING *str, int indent, static int asn1_print_obstring(BIO *out, const ASN1_STRING *str, int indent)
const ASN1_PCTX *pctx)
{ {
if (str->type == V_ASN1_BIT_STRING) { if (str->type == V_ASN1_BIT_STRING) {
if (BIO_printf(out, " (%ld unused bits)\n", str->flags & 0x7) <= 0) if (BIO_printf(out, " (%ld unused bits)\n", str->flags & 0x7) <= 0)
@ -478,7 +423,7 @@ static int asn1_print_obstring_ctx(BIO *out, ASN1_STRING *str, int indent,
} else if (BIO_puts(out, "\n") <= 0) } else if (BIO_puts(out, "\n") <= 0)
return 0; return 0;
if ((str->length > 0) if ((str->length > 0)
&& BIO_dump_indent(out, (char *)str->data, str->length, && BIO_dump_indent(out, (const char *)str->data, str->length,
indent + 2) <= 0) indent + 2) <= 0)
return 0; return 0;
return 1; return 1;
@ -544,13 +489,13 @@ static int asn1_primitive_print(BIO *out, ASN1_VALUE **fld,
int boolval = *(int *)fld; int boolval = *(int *)fld;
if (boolval == -1) if (boolval == -1)
boolval = it->size; boolval = it->size;
ret = asn1_print_boolean_ctx(out, boolval, pctx); ret = asn1_print_boolean(out, boolval);
} }
break; break;
case V_ASN1_INTEGER: case V_ASN1_INTEGER:
case V_ASN1_ENUMERATED: case V_ASN1_ENUMERATED:
ret = asn1_print_integer_ctx(out, str, pctx); ret = asn1_print_integer(out, str);
break; break;
case V_ASN1_UTCTIME: case V_ASN1_UTCTIME:
@ -562,12 +507,12 @@ static int asn1_primitive_print(BIO *out, ASN1_VALUE **fld,
break; break;
case V_ASN1_OBJECT: case V_ASN1_OBJECT:
ret = asn1_print_oid_ctx(out, (const ASN1_OBJECT *)*fld, pctx); ret = asn1_print_oid(out, (const ASN1_OBJECT *)*fld);
break; break;
case V_ASN1_OCTET_STRING: case V_ASN1_OCTET_STRING:
case V_ASN1_BIT_STRING: case V_ASN1_BIT_STRING:
ret = asn1_print_obstring_ctx(out, str, indent, pctx); ret = asn1_print_obstring(out, str, indent);
needlf = 0; needlf = 0;
break; break;

View File

@ -0,0 +1,65 @@
/*
* Copyright 2010-2016 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
#include <stddef.h>
#include "internal/cryptlib.h"
#include <openssl/asn1.h>
#include <openssl/asn1t.h>
#include <openssl/objects.h>
#include <openssl/buffer.h>
#include <openssl/err.h>
#include <openssl/x509v3.h>
#include "asn1_locl.h"
/*
* General ASN1 structure recursive scanner: iterate through all fields
* passing details to a callback.
*/
ASN1_SCTX *ASN1_SCTX_new(int (*scan_cb) (ASN1_SCTX *ctx))
{
ASN1_SCTX *ret = OPENSSL_zalloc(sizeof(*ret));
if (ret == NULL) {
ASN1err(ASN1_F_ASN1_SCTX_NEW, ERR_R_MALLOC_FAILURE);
return NULL;
}
ret->scan_cb = scan_cb;
return ret;
}
void ASN1_SCTX_free(ASN1_SCTX *p)
{
OPENSSL_free(p);
}
const ASN1_ITEM *ASN1_SCTX_get_item(ASN1_SCTX *p)
{
return p->it;
}
const ASN1_TEMPLATE *ASN1_SCTX_get_template(ASN1_SCTX *p)
{
return p->tt;
}
unsigned long ASN1_SCTX_get_flags(ASN1_SCTX *p)
{
return p->flags;
}
void ASN1_SCTX_set_app_data(ASN1_SCTX *p, void *data)
{
p->app_data = data;
}
void *ASN1_SCTX_get_app_data(ASN1_SCTX *p)
{
return p->app_data;
}

View File

@ -1,115 +1,50 @@
/* tasn_typ.c */
/* /*
* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project * Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
* 2000. *
*/ * Licensed under the OpenSSL license (the "License"). You may not use
/* ==================================================================== * this file except in compliance with the License. You can obtain a copy
* Copyright (c) 2000 The OpenSSL Project. All rights reserved. * in the file LICENSE in the source distribution or at
* * https://www.openssl.org/source/license.html
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
*
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* licensing@OpenSSL.org.
*
* 5. Products derived from this software may not be called "OpenSSL"
* nor may "OpenSSL" appear in their names without prior written
* permission of the OpenSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*
* This product includes cryptographic software written by Eric Young
* (eay@cryptsoft.com). This product includes software written by Tim
* Hudson (tjh@cryptsoft.com).
*
*/ */
#include <stdio.h> #include <stdio.h>
#include <openssl/asn1.h> #include <openssl/asn1.h>
#include <openssl/asn1t.h> #include <openssl/asn1t.h>
/* Declarations for string types */ /* Declarations for string types */
#define IMPLEMENT_ASN1_STRING_FUNCTIONS(sname) \
IMPLEMENT_ASN1_TYPE(sname) \
IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(sname, sname, sname) \
sname *sname##_new(void) \
{ \
return ASN1_STRING_type_new(V_##sname); \
} \
void sname##_free(sname *x) \
{ \
ASN1_STRING_free(x); \
}
IMPLEMENT_ASN1_TYPE(ASN1_INTEGER) IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_OCTET_STRING)
IMPLEMENT_ASN1_FUNCTIONS(ASN1_INTEGER) IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_INTEGER)
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_ENUMERATED)
IMPLEMENT_ASN1_TYPE(ASN1_ENUMERATED) IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_BIT_STRING)
IMPLEMENT_ASN1_FUNCTIONS(ASN1_ENUMERATED) IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_UTF8STRING)
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_PRINTABLESTRING)
IMPLEMENT_ASN1_TYPE(ASN1_BIT_STRING) IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_T61STRING)
IMPLEMENT_ASN1_FUNCTIONS(ASN1_BIT_STRING) IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_IA5STRING)
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_GENERALSTRING)
IMPLEMENT_ASN1_TYPE(ASN1_OCTET_STRING) IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_UTCTIME)
IMPLEMENT_ASN1_FUNCTIONS(ASN1_OCTET_STRING) IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_GENERALIZEDTIME)
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_VISIBLESTRING)
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_UNIVERSALSTRING)
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_BMPSTRING)
IMPLEMENT_ASN1_TYPE(ASN1_NULL) IMPLEMENT_ASN1_TYPE(ASN1_NULL)
IMPLEMENT_ASN1_FUNCTIONS(ASN1_NULL) IMPLEMENT_ASN1_FUNCTIONS(ASN1_NULL)
IMPLEMENT_ASN1_TYPE(ASN1_OBJECT) IMPLEMENT_ASN1_TYPE(ASN1_OBJECT)
IMPLEMENT_ASN1_TYPE(ASN1_UTF8STRING)
IMPLEMENT_ASN1_FUNCTIONS(ASN1_UTF8STRING)
IMPLEMENT_ASN1_TYPE(ASN1_PRINTABLESTRING)
IMPLEMENT_ASN1_FUNCTIONS(ASN1_PRINTABLESTRING)
IMPLEMENT_ASN1_TYPE(ASN1_T61STRING)
IMPLEMENT_ASN1_FUNCTIONS(ASN1_T61STRING)
IMPLEMENT_ASN1_TYPE(ASN1_IA5STRING)
IMPLEMENT_ASN1_FUNCTIONS(ASN1_IA5STRING)
IMPLEMENT_ASN1_TYPE(ASN1_GENERALSTRING)
IMPLEMENT_ASN1_FUNCTIONS(ASN1_GENERALSTRING)
IMPLEMENT_ASN1_TYPE(ASN1_UTCTIME)
IMPLEMENT_ASN1_FUNCTIONS(ASN1_UTCTIME)
IMPLEMENT_ASN1_TYPE(ASN1_GENERALIZEDTIME)
IMPLEMENT_ASN1_FUNCTIONS(ASN1_GENERALIZEDTIME)
IMPLEMENT_ASN1_TYPE(ASN1_VISIBLESTRING)
IMPLEMENT_ASN1_FUNCTIONS(ASN1_VISIBLESTRING)
IMPLEMENT_ASN1_TYPE(ASN1_UNIVERSALSTRING)
IMPLEMENT_ASN1_FUNCTIONS(ASN1_UNIVERSALSTRING)
IMPLEMENT_ASN1_TYPE(ASN1_BMPSTRING)
IMPLEMENT_ASN1_FUNCTIONS(ASN1_BMPSTRING)
IMPLEMENT_ASN1_TYPE(ASN1_ANY) IMPLEMENT_ASN1_TYPE(ASN1_ANY)
/* Just swallow an ASN1_SEQUENCE in an ASN1_STRING */ /* Just swallow an ASN1_SEQUENCE in an ASN1_STRING */

View File

@ -1,68 +1,20 @@
/* tasn_utl.c */
/* /*
* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project * Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
* 2000.
*/
/* ====================================================================
* Copyright (c) 2000-2004 The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
*
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* licensing@OpenSSL.org.
*
* 5. Products derived from this software may not be called "OpenSSL"
* nor may "OpenSSL" appear in their names without prior written
* permission of the OpenSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*
* This product includes cryptographic software written by Eric Young
* (eay@cryptsoft.com). This product includes software written by Tim
* Hudson (tjh@cryptsoft.com).
* *
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/ */
#include <stddef.h> #include <stddef.h>
#include <string.h> #include <string.h>
#include <internal/cryptlib.h>
#include <openssl/asn1.h> #include <openssl/asn1.h>
#include <openssl/asn1t.h> #include <openssl/asn1t.h>
#include <openssl/objects.h> #include <openssl/objects.h>
#include <openssl/err.h> #include <openssl/err.h>
#include "asn1_locl.h"
/* Utility functions for manipulating fields and offsets */ /* Utility functions for manipulating fields and offsets */
@ -94,16 +46,19 @@ int asn1_set_choice_selector(ASN1_VALUE **pval, int value,
} }
/* /*
* Do reference counting. The value 'op' decides what to do. if it is +1 * Do atomic reference counting. The value 'op' decides what to do.
* then the count is incremented. If op is 0 count is set to 1. If op is -1 * If it is +1 then the count is incremented.
* count is decremented and the return value is the current refrence count or * If |op| is 0, lock is initialised and count is set to 1.
* 0 if no reference count exists. * If |op| is -1, count is decremented and the return value is the current
* reference count or 0 if no reference count is active.
* It returns -1 on initialisation error.
* Used by ASN1_SEQUENCE construct of X509, X509_REQ, X509_CRL objects
*/ */
int asn1_do_lock(ASN1_VALUE **pval, int op, const ASN1_ITEM *it) int asn1_do_lock(ASN1_VALUE **pval, int op, const ASN1_ITEM *it)
{ {
const ASN1_AUX *aux; const ASN1_AUX *aux;
int *lck, ret; int *lck, ret;
CRYPTO_RWLOCK **lock;
if ((it->itype != ASN1_ITYPE_SEQUENCE) if ((it->itype != ASN1_ITYPE_SEQUENCE)
&& (it->itype != ASN1_ITYPE_NDEF_SEQUENCE)) && (it->itype != ASN1_ITYPE_NDEF_SEQUENCE))
return 0; return 0;
@ -111,18 +66,26 @@ int asn1_do_lock(ASN1_VALUE **pval, int op, const ASN1_ITEM *it)
if (!aux || !(aux->flags & ASN1_AFLG_REFCOUNT)) if (!aux || !(aux->flags & ASN1_AFLG_REFCOUNT))
return 0; return 0;
lck = offset2ptr(*pval, aux->ref_offset); lck = offset2ptr(*pval, aux->ref_offset);
lock = offset2ptr(*pval, aux->ref_lock);
if (op == 0) { if (op == 0) {
*lck = 1; *lck = 1;
*lock = CRYPTO_THREAD_lock_new();
if (*lock == NULL) {
ASN1err(ASN1_F_ASN1_DO_LOCK, ERR_R_MALLOC_FAILURE);
return -1;
}
return 1; return 1;
} }
ret = CRYPTO_add(lck, op, aux->ref_lock); if (CRYPTO_atomic_add(lck, op, &ret, *lock) < 0)
return -1; /* failed */
#ifdef REF_PRINT #ifdef REF_PRINT
fprintf(stderr, "%s: Reference Count: %d\n", it->sname, *lck); fprintf(stderr, "%p:%4d:%s\n", it, *lck, it->sname);
#endif
#ifdef REF_CHECK
if (ret < 0)
fprintf(stderr, "%s, bad reference count\n", it->sname);
#endif #endif
REF_ASSERT_ISNT(ret < 0);
if (ret == 0) {
CRYPTO_THREAD_lock_free(*lock);
*lock = NULL;
}
return ret; return ret;
} }
@ -153,7 +116,6 @@ void asn1_enc_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
ASN1_ENCODING *enc; ASN1_ENCODING *enc;
enc = asn1_get_enc_ptr(pval, it); enc = asn1_get_enc_ptr(pval, it);
if (enc) { if (enc) {
if (enc->enc)
OPENSSL_free(enc->enc); OPENSSL_free(enc->enc);
enc->enc = NULL; enc->enc = NULL;
enc->len = 0; enc->len = 0;
@ -169,10 +131,9 @@ int asn1_enc_save(ASN1_VALUE **pval, const unsigned char *in, int inlen,
if (!enc) if (!enc)
return 1; return 1;
if (enc->enc)
OPENSSL_free(enc->enc); OPENSSL_free(enc->enc);
enc->enc = OPENSSL_malloc(inlen); enc->enc = OPENSSL_malloc(inlen);
if (!enc->enc) if (enc->enc == NULL)
return 0; return 0;
memcpy(enc->enc, in, inlen); memcpy(enc->enc, in, inlen);
enc->len = inlen; enc->len = inlen;
@ -201,8 +162,6 @@ int asn1_enc_restore(int *len, unsigned char **out, ASN1_VALUE **pval,
ASN1_VALUE **asn1_get_field_ptr(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) ASN1_VALUE **asn1_get_field_ptr(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
{ {
ASN1_VALUE **pvaltmp; ASN1_VALUE **pvaltmp;
if (tt->flags & ASN1_TFLG_COMBINE)
return pval;
pvaltmp = offset2ptr(*pval, tt->offset); pvaltmp = offset2ptr(*pval, tt->offset);
/* /*
* NOTE for BOOLEAN types the field is just a plain int so we can't * NOTE for BOOLEAN types the field is just a plain int so we can't
@ -249,6 +208,12 @@ const ASN1_TEMPLATE *asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt,
else else
selector = ASN1_INTEGER_get((ASN1_INTEGER *)*sfld); selector = ASN1_INTEGER_get((ASN1_INTEGER *)*sfld);
/* Let application callback translate value */
if (adb->adb_cb != NULL && adb->adb_cb(&selector) == 0) {
ASN1err(ASN1_F_ASN1_DO_ADB, ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE);
return NULL;
}
/* /*
* Try to find matching entry in table Maybe should check application * Try to find matching entry in table Maybe should check application
* types first to allow application override? Might also be useful to * types first to allow application override? Might also be useful to

View File

@ -1,66 +1,17 @@
/* x_algor.c */
/* /*
* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project * Copyright 1998-2016 The OpenSSL Project Authors. All Rights Reserved.
* 2000.
*/
/* ====================================================================
* Copyright (c) 2000 The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
*
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* licensing@OpenSSL.org.
*
* 5. Products derived from this software may not be called "OpenSSL"
* nor may "OpenSSL" appear in their names without prior written
* permission of the OpenSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*
* This product includes cryptographic software written by Eric Young
* (eay@cryptsoft.com). This product includes software written by Tim
* Hudson (tjh@cryptsoft.com).
* *
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/ */
#include <stddef.h> #include <stddef.h>
#include <openssl/x509.h> #include <openssl/x509.h>
#include <openssl/asn1.h> #include <openssl/asn1.h>
#include <openssl/asn1t.h> #include <openssl/asn1t.h>
#include "internal/evp_int.h"
ASN1_SEQUENCE(X509_ALGOR) = { ASN1_SEQUENCE(X509_ALGOR) = {
ASN1_SIMPLE(X509_ALGOR, algorithm, ASN1_OBJECT), ASN1_SIMPLE(X509_ALGOR, algorithm, ASN1_OBJECT),
@ -75,9 +26,6 @@ IMPLEMENT_ASN1_FUNCTIONS(X509_ALGOR)
IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(X509_ALGORS, X509_ALGORS, X509_ALGORS) IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(X509_ALGORS, X509_ALGORS, X509_ALGORS)
IMPLEMENT_ASN1_DUP_FUNCTION(X509_ALGOR) IMPLEMENT_ASN1_DUP_FUNCTION(X509_ALGOR)
IMPLEMENT_STACK_OF(X509_ALGOR)
IMPLEMENT_ASN1_SET_OF(X509_ALGOR)
int X509_ALGOR_set0(X509_ALGOR *alg, ASN1_OBJECT *aobj, int ptype, void *pval) int X509_ALGOR_set0(X509_ALGOR *alg, ASN1_OBJECT *aobj, int ptype, void *pval)
{ {
if (!alg) if (!alg)
@ -89,24 +37,21 @@ int X509_ALGOR_set0(X509_ALGOR *alg, ASN1_OBJECT *aobj, int ptype, void *pval)
return 0; return 0;
} }
if (alg) { if (alg) {
if (alg->algorithm)
ASN1_OBJECT_free(alg->algorithm); ASN1_OBJECT_free(alg->algorithm);
alg->algorithm = aobj; alg->algorithm = aobj;
} }
if (ptype == 0) if (ptype == 0)
return 1; return 1;
if (ptype == V_ASN1_UNDEF) { if (ptype == V_ASN1_UNDEF) {
if (alg->parameter) {
ASN1_TYPE_free(alg->parameter); ASN1_TYPE_free(alg->parameter);
alg->parameter = NULL; alg->parameter = NULL;
}
} else } else
ASN1_TYPE_set(alg->parameter, ptype, pval); ASN1_TYPE_set(alg->parameter, ptype, pval);
return 1; return 1;
} }
void X509_ALGOR_get0(ASN1_OBJECT **paobj, int *pptype, void **ppval, void X509_ALGOR_get0(const ASN1_OBJECT **paobj, int *pptype,
X509_ALGOR *algor) const void **ppval, const X509_ALGOR *algor)
{ {
if (paobj) if (paobj)
*paobj = algor->algorithm; *paobj = algor->algorithm;

View File

@ -1,124 +0,0 @@
/* crypto/asn1/x_attrib.c */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
* This package is an SSL implementation written
* by Eric Young (eay@cryptsoft.com).
* The implementation was written so as to conform with Netscapes SSL.
*
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* "This product includes cryptographic software written by
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/
#include <stdio.h>
#include "cryptlib.h"
#include <openssl/objects.h>
#include <openssl/asn1t.h>
#include <openssl/x509.h>
/*-
* X509_ATTRIBUTE: this has the following form:
*
* typedef struct x509_attributes_st
* {
* ASN1_OBJECT *object;
* int single;
* union {
* char *ptr;
* STACK_OF(ASN1_TYPE) *set;
* ASN1_TYPE *single;
* } value;
* } X509_ATTRIBUTE;
*
* this needs some extra thought because the CHOICE type is
* merged with the main structure and because the value can
* be anything at all we *must* try the SET OF first because
* the ASN1_ANY type will swallow anything including the whole
* SET OF structure.
*/
ASN1_CHOICE(X509_ATTRIBUTE_SET) = {
ASN1_SET_OF(X509_ATTRIBUTE, value.set, ASN1_ANY),
ASN1_SIMPLE(X509_ATTRIBUTE, value.single, ASN1_ANY)
} ASN1_CHOICE_END_selector(X509_ATTRIBUTE, X509_ATTRIBUTE_SET, single)
ASN1_SEQUENCE(X509_ATTRIBUTE) = {
ASN1_SIMPLE(X509_ATTRIBUTE, object, ASN1_OBJECT),
/* CHOICE type merged with parent */
ASN1_EX_COMBINE(0, 0, X509_ATTRIBUTE_SET)
} ASN1_SEQUENCE_END(X509_ATTRIBUTE)
IMPLEMENT_ASN1_FUNCTIONS(X509_ATTRIBUTE)
IMPLEMENT_ASN1_DUP_FUNCTION(X509_ATTRIBUTE)
X509_ATTRIBUTE *X509_ATTRIBUTE_create(int nid, int atrtype, void *value)
{
X509_ATTRIBUTE *ret = NULL;
ASN1_TYPE *val = NULL;
if ((ret = X509_ATTRIBUTE_new()) == NULL)
return (NULL);
ret->object = OBJ_nid2obj(nid);
ret->single = 0;
if ((ret->value.set = sk_ASN1_TYPE_new_null()) == NULL)
goto err;
if ((val = ASN1_TYPE_new()) == NULL)
goto err;
if (!sk_ASN1_TYPE_push(ret->value.set, val))
goto err;
ASN1_TYPE_set(val, atrtype, value);
return (ret);
err:
if (ret != NULL)
X509_ATTRIBUTE_free(ret);
if (val != NULL)
ASN1_TYPE_free(val);
return (NULL);
}

View File

@ -1,64 +1,14 @@
/* x_bignum.c */
/* /*
* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project * Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
* 2000.
*/
/* ====================================================================
* Copyright (c) 2000 The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
*
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* licensing@OpenSSL.org.
*
* 5. Products derived from this software may not be called "OpenSSL"
* nor may "OpenSSL" appear in their names without prior written
* permission of the OpenSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*
* This product includes cryptographic software written by Eric Young
* (eay@cryptsoft.com). This product includes software written by Tim
* Hudson (tjh@cryptsoft.com).
* *
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/ */
#include <stdio.h> #include <stdio.h>
#include "cryptlib.h" #include "internal/cryptlib.h"
#include <openssl/asn1t.h> #include <openssl/asn1t.h>
#include <openssl/bn.h> #include <openssl/bn.h>
@ -72,12 +22,15 @@
#define BN_SENSITIVE 1 #define BN_SENSITIVE 1
static int bn_new(ASN1_VALUE **pval, const ASN1_ITEM *it); static int bn_new(ASN1_VALUE **pval, const ASN1_ITEM *it);
static int bn_secure_new(ASN1_VALUE **pval, const ASN1_ITEM *it);
static void bn_free(ASN1_VALUE **pval, const ASN1_ITEM *it); static void bn_free(ASN1_VALUE **pval, const ASN1_ITEM *it);
static int bn_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, static int bn_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype,
const ASN1_ITEM *it); const ASN1_ITEM *it);
static int bn_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, static int bn_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,
int utype, char *free_cont, const ASN1_ITEM *it); int utype, char *free_cont, const ASN1_ITEM *it);
static int bn_secure_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,
int utype, char *free_cont, const ASN1_ITEM *it);
static int bn_print(BIO *out, ASN1_VALUE **pval, const ASN1_ITEM *it, static int bn_print(BIO *out, ASN1_VALUE **pval, const ASN1_ITEM *it,
int indent, const ASN1_PCTX *pctx); int indent, const ASN1_PCTX *pctx);
@ -91,18 +44,37 @@ static ASN1_PRIMITIVE_FUNCS bignum_pf = {
bn_print bn_print
}; };
static ASN1_PRIMITIVE_FUNCS cbignum_pf = {
NULL, 0,
bn_secure_new,
bn_free,
0,
bn_secure_c2i,
bn_i2c,
bn_print
};
ASN1_ITEM_start(BIGNUM) ASN1_ITEM_start(BIGNUM)
ASN1_ITYPE_PRIMITIVE, V_ASN1_INTEGER, NULL, 0, &bignum_pf, 0, "BIGNUM" ASN1_ITYPE_PRIMITIVE, V_ASN1_INTEGER, NULL, 0, &bignum_pf, 0, "BIGNUM"
ASN1_ITEM_end(BIGNUM) ASN1_ITEM_end(BIGNUM)
ASN1_ITEM_start(CBIGNUM) ASN1_ITEM_start(CBIGNUM)
ASN1_ITYPE_PRIMITIVE, V_ASN1_INTEGER, NULL, 0, &bignum_pf, BN_SENSITIVE, "BIGNUM" ASN1_ITYPE_PRIMITIVE, V_ASN1_INTEGER, NULL, 0, &cbignum_pf, BN_SENSITIVE, "CBIGNUM"
ASN1_ITEM_end(CBIGNUM) ASN1_ITEM_end(CBIGNUM)
static int bn_new(ASN1_VALUE **pval, const ASN1_ITEM *it) static int bn_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
{ {
*pval = (ASN1_VALUE *)BN_new(); *pval = (ASN1_VALUE *)BN_new();
if (*pval) if (*pval != NULL)
return 1;
else
return 0;
}
static int bn_secure_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
{
*pval = (ASN1_VALUE *)BN_secure_new();
if (*pval != NULL)
return 1; return 1;
else else
return 0; return 0;
@ -155,6 +127,14 @@ static int bn_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,
return 1; return 1;
} }
static int bn_secure_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,
int utype, char *free_cont, const ASN1_ITEM *it)
{
if (!*pval)
bn_secure_new(pval, it);
return bn_c2i(pval, cont, len, utype, free_cont, it);
}
static int bn_print(BIO *out, ASN1_VALUE **pval, const ASN1_ITEM *it, static int bn_print(BIO *out, ASN1_VALUE **pval, const ASN1_ITEM *it,
int indent, const ASN1_PCTX *pctx) int indent, const ASN1_PCTX *pctx)
{ {

View File

@ -1,77 +0,0 @@
/* x_exten.c */
/*
* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project
* 2000.
*/
/* ====================================================================
* Copyright (c) 2000 The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
*
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* licensing@OpenSSL.org.
*
* 5. Products derived from this software may not be called "OpenSSL"
* nor may "OpenSSL" appear in their names without prior written
* permission of the OpenSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*
* This product includes cryptographic software written by Eric Young
* (eay@cryptsoft.com). This product includes software written by Tim
* Hudson (tjh@cryptsoft.com).
*
*/
#include <stddef.h>
#include <openssl/x509.h>
#include <openssl/asn1.h>
#include <openssl/asn1t.h>
ASN1_SEQUENCE(X509_EXTENSION) = {
ASN1_SIMPLE(X509_EXTENSION, object, ASN1_OBJECT),
ASN1_OPT(X509_EXTENSION, critical, ASN1_BOOLEAN),
ASN1_SIMPLE(X509_EXTENSION, value, ASN1_OCTET_STRING)
} ASN1_SEQUENCE_END(X509_EXTENSION)
ASN1_ITEM_TEMPLATE(X509_EXTENSIONS) =
ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, Extension, X509_EXTENSION)
ASN1_ITEM_TEMPLATE_END(X509_EXTENSIONS)
IMPLEMENT_ASN1_FUNCTIONS(X509_EXTENSION)
IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(X509_EXTENSIONS, X509_EXTENSIONS, X509_EXTENSIONS)
IMPLEMENT_ASN1_DUP_FUNCTION(X509_EXTENSION)

View File

@ -1,117 +1,39 @@
/* crypto/asn1/x_info.c */ /*
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
* All rights reserved.
* *
* This package is an SSL implementation written * Licensed under the OpenSSL license (the "License"). You may not use
* by Eric Young (eay@cryptsoft.com). * this file except in compliance with the License. You can obtain a copy
* The implementation was written so as to conform with Netscapes SSL. * in the file LICENSE in the source distribution or at
* * https://www.openssl.org/source/license.html
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* "This product includes cryptographic software written by
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/ */
#include <stdio.h> #include <stdio.h>
#include "cryptlib.h" #include "internal/cryptlib.h"
#include <openssl/evp.h> #include <openssl/evp.h>
#include <openssl/asn1.h> #include <openssl/asn1.h>
#include <openssl/x509.h> #include <openssl/x509.h>
X509_INFO *X509_INFO_new(void) X509_INFO *X509_INFO_new(void)
{ {
X509_INFO *ret = NULL; X509_INFO *ret;
ret = (X509_INFO *)OPENSSL_malloc(sizeof(X509_INFO)); ret = OPENSSL_zalloc(sizeof(*ret));
if (ret == NULL) { if (ret == NULL) {
ASN1err(ASN1_F_X509_INFO_NEW, ERR_R_MALLOC_FAILURE); ASN1err(ASN1_F_X509_INFO_NEW, ERR_R_MALLOC_FAILURE);
return (NULL); return NULL;
} }
ret->enc_cipher.cipher = NULL; return ret;
ret->enc_len = 0;
ret->enc_data = NULL;
ret->references = 1;
ret->x509 = NULL;
ret->crl = NULL;
ret->x_pkey = NULL;
return (ret);
} }
void X509_INFO_free(X509_INFO *x) void X509_INFO_free(X509_INFO *x)
{ {
int i;
if (x == NULL) if (x == NULL)
return; return;
i = CRYPTO_add(&x->references, -1, CRYPTO_LOCK_X509_INFO);
#ifdef REF_PRINT
REF_PRINT("X509_INFO", x);
#endif
if (i > 0)
return;
#ifdef REF_CHECK
if (i < 0) {
fprintf(stderr, "X509_INFO_free, bad reference count\n");
abort();
}
#endif
if (x->x509 != NULL)
X509_free(x->x509); X509_free(x->x509);
if (x->crl != NULL)
X509_CRL_free(x->crl); X509_CRL_free(x->crl);
if (x->x_pkey != NULL)
X509_PKEY_free(x->x_pkey); X509_PKEY_free(x->x_pkey);
if (x->enc_data != NULL)
OPENSSL_free(x->enc_data); OPENSSL_free(x->enc_data);
OPENSSL_free(x); OPENSSL_free(x);
} }
IMPLEMENT_STACK_OF(X509_INFO)

View File

@ -1,64 +1,14 @@
/* x_long.c */
/* /*
* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project * Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
* 2000.
*/
/* ====================================================================
* Copyright (c) 2000 The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
*
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* licensing@OpenSSL.org.
*
* 5. Products derived from this software may not be called "OpenSSL"
* nor may "OpenSSL" appear in their names without prior written
* permission of the OpenSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*
* This product includes cryptographic software written by Eric Young
* (eay@cryptsoft.com). This product includes software written by Tim
* Hudson (tjh@cryptsoft.com).
* *
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/ */
#include <stdio.h> #include <stdio.h>
#include "cryptlib.h" #include "internal/cryptlib.h"
#include <openssl/asn1t.h> #include <openssl/asn1t.h>
#include <openssl/bn.h> #include <openssl/bn.h>
@ -126,7 +76,7 @@ static int long_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype,
* set. * set.
*/ */
if (ltmp < 0) if (ltmp < 0)
utmp = -ltmp - 1; utmp = 0 - (unsigned long)ltmp - 1;
else else
utmp = ltmp; utmp = ltmp;
clen = BN_num_bits_word(utmp); clen = BN_num_bits_word(utmp);
@ -178,8 +128,8 @@ static int long_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,
} }
ltmp = (long)utmp; ltmp = (long)utmp;
if (neg) { if (neg) {
ltmp++;
ltmp = -ltmp; ltmp = -ltmp;
ltmp--;
} }
if (ltmp == it->size) { if (ltmp == it->size) {
ASN1err(ASN1_F_LONG_C2I, ASN1_R_INTEGER_TOO_LARGE_FOR_LONG); ASN1err(ASN1_F_LONG_C2I, ASN1_R_INTEGER_TOO_LARGE_FOR_LONG);

View File

@ -1,72 +0,0 @@
/* x_nx509.c */
/*
* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project
* 2005.
*/
/* ====================================================================
* Copyright (c) 2005 The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
*
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* licensing@OpenSSL.org.
*
* 5. Products derived from this software may not be called "OpenSSL"
* nor may "OpenSSL" appear in their names without prior written
* permission of the OpenSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*
* This product includes cryptographic software written by Eric Young
* (eay@cryptsoft.com). This product includes software written by Tim
* Hudson (tjh@cryptsoft.com).
*
*/
#include <stddef.h>
#include <openssl/x509.h>
#include <openssl/asn1.h>
#include <openssl/asn1t.h>
/* Old netscape certificate wrapper format */
ASN1_SEQUENCE(NETSCAPE_X509) = {
ASN1_SIMPLE(NETSCAPE_X509, header, ASN1_OCTET_STRING),
ASN1_OPT(NETSCAPE_X509, cert, X509)
} ASN1_SEQUENCE_END(NETSCAPE_X509)
IMPLEMENT_ASN1_FUNCTIONS(NETSCAPE_X509)

View File

@ -1,153 +1,47 @@
/* crypto/asn1/x_pkey.c */ /*
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
* All rights reserved.
* *
* This package is an SSL implementation written * Licensed under the OpenSSL license (the "License"). You may not use
* by Eric Young (eay@cryptsoft.com). * this file except in compliance with the License. You can obtain a copy
* The implementation was written so as to conform with Netscapes SSL. * in the file LICENSE in the source distribution or at
* * https://www.openssl.org/source/license.html
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* "This product includes cryptographic software written by
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/ */
#include <stdio.h> #include <stdio.h>
#include "cryptlib.h" #include "internal/cryptlib.h"
#include <openssl/evp.h> #include <openssl/evp.h>
#include <openssl/objects.h> #include <openssl/objects.h>
#include <openssl/asn1_mac.h>
#include <openssl/x509.h> #include <openssl/x509.h>
/* need to implement */
int i2d_X509_PKEY(X509_PKEY *a, unsigned char **pp)
{
return (0);
}
X509_PKEY *d2i_X509_PKEY(X509_PKEY **a, const unsigned char **pp, long length)
{
int i;
M_ASN1_D2I_vars(a, X509_PKEY *, X509_PKEY_new);
M_ASN1_D2I_Init();
M_ASN1_D2I_start_sequence();
M_ASN1_D2I_get_x(X509_ALGOR, ret->enc_algor, d2i_X509_ALGOR);
M_ASN1_D2I_get_x(ASN1_OCTET_STRING, ret->enc_pkey, d2i_ASN1_OCTET_STRING);
ret->cipher.cipher =
EVP_get_cipherbyname(OBJ_nid2ln
(OBJ_obj2nid(ret->enc_algor->algorithm)));
if (ret->cipher.cipher == NULL) {
c.error = ASN1_R_UNSUPPORTED_CIPHER;
c.line = __LINE__;
goto err;
}
if (ret->enc_algor->parameter->type == V_ASN1_OCTET_STRING) {
i = ret->enc_algor->parameter->value.octet_string->length;
if (i > EVP_MAX_IV_LENGTH) {
c.error = ASN1_R_IV_TOO_LARGE;
c.line = __LINE__;
goto err;
}
memcpy(ret->cipher.iv,
ret->enc_algor->parameter->value.octet_string->data, i);
} else
memset(ret->cipher.iv, 0, EVP_MAX_IV_LENGTH);
M_ASN1_D2I_Finish(a, X509_PKEY_free, ASN1_F_D2I_X509_PKEY);
}
X509_PKEY *X509_PKEY_new(void) X509_PKEY *X509_PKEY_new(void)
{ {
X509_PKEY *ret = NULL; X509_PKEY *ret = NULL;
ASN1_CTX c;
M_ASN1_New_Malloc(ret, X509_PKEY); ret = OPENSSL_zalloc(sizeof(*ret));
ret->version = 0; if (ret == NULL)
M_ASN1_New(ret->enc_algor, X509_ALGOR_new); goto err;
M_ASN1_New(ret->enc_pkey, M_ASN1_OCTET_STRING_new);
ret->dec_pkey = NULL; ret->enc_algor = X509_ALGOR_new();
ret->key_length = 0; ret->enc_pkey = ASN1_OCTET_STRING_new();
ret->key_data = NULL; if (ret->enc_algor == NULL || ret->enc_pkey == NULL)
ret->key_free = 0; goto err;
ret->cipher.cipher = NULL;
memset(ret->cipher.iv, 0, EVP_MAX_IV_LENGTH); return ret;
ret->references = 1; err:
return (ret); X509_PKEY_free(ret);
M_ASN1_New_Error(ASN1_F_X509_PKEY_NEW); ASN1err(ASN1_F_X509_PKEY_NEW, ERR_R_MALLOC_FAILURE);
return NULL;
} }
void X509_PKEY_free(X509_PKEY *x) void X509_PKEY_free(X509_PKEY *x)
{ {
int i;
if (x == NULL) if (x == NULL)
return; return;
i = CRYPTO_add(&x->references, -1, CRYPTO_LOCK_X509_PKEY);
#ifdef REF_PRINT
REF_PRINT("X509_PKEY", x);
#endif
if (i > 0)
return;
#ifdef REF_CHECK
if (i < 0) {
fprintf(stderr, "X509_PKEY_free, bad reference count\n");
abort();
}
#endif
if (x->enc_algor != NULL)
X509_ALGOR_free(x->enc_algor); X509_ALGOR_free(x->enc_algor);
if (x->enc_pkey != NULL) ASN1_OCTET_STRING_free(x->enc_pkey);
M_ASN1_OCTET_STRING_free(x->enc_pkey);
if (x->dec_pkey != NULL)
EVP_PKEY_free(x->dec_pkey); EVP_PKEY_free(x->dec_pkey);
if ((x->key_data != NULL) && (x->key_free)) if (x->key_free)
OPENSSL_free(x->key_data); OPENSSL_free(x->key_data);
OPENSSL_free(x); OPENSSL_free(x);
} }

View File

@ -1,116 +0,0 @@
/* crypto/asn1/x_req.c */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
* This package is an SSL implementation written
* by Eric Young (eay@cryptsoft.com).
* The implementation was written so as to conform with Netscapes SSL.
*
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* "This product includes cryptographic software written by
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/
#include <stdio.h>
#include "cryptlib.h"
#include <openssl/asn1t.h>
#include <openssl/x509.h>
/*-
* X509_REQ_INFO is handled in an unusual way to get round
* invalid encodings. Some broken certificate requests don't
* encode the attributes field if it is empty. This is in
* violation of PKCS#10 but we need to tolerate it. We do
* this by making the attributes field OPTIONAL then using
* the callback to initialise it to an empty STACK.
*
* This means that the field will be correctly encoded unless
* we NULL out the field.
*
* As a result we no longer need the req_kludge field because
* the information is now contained in the attributes field:
* 1. If it is NULL then it's the invalid omission.
* 2. If it is empty it is the correct encoding.
* 3. If it is not empty then some attributes are present.
*
*/
static int rinf_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
void *exarg)
{
X509_REQ_INFO *rinf = (X509_REQ_INFO *)*pval;
if (operation == ASN1_OP_NEW_POST) {
rinf->attributes = sk_X509_ATTRIBUTE_new_null();
if (!rinf->attributes)
return 0;
}
return 1;
}
ASN1_SEQUENCE_enc(X509_REQ_INFO, enc, rinf_cb) = {
ASN1_SIMPLE(X509_REQ_INFO, version, ASN1_INTEGER),
ASN1_SIMPLE(X509_REQ_INFO, subject, X509_NAME),
ASN1_SIMPLE(X509_REQ_INFO, pubkey, X509_PUBKEY),
/* This isn't really OPTIONAL but it gets round invalid
* encodings
*/
ASN1_IMP_SET_OF_OPT(X509_REQ_INFO, attributes, X509_ATTRIBUTE, 0)
} ASN1_SEQUENCE_END_enc(X509_REQ_INFO, X509_REQ_INFO)
IMPLEMENT_ASN1_FUNCTIONS(X509_REQ_INFO)
ASN1_SEQUENCE_ref(X509_REQ, 0, CRYPTO_LOCK_X509_REQ) = {
ASN1_SIMPLE(X509_REQ, req_info, X509_REQ_INFO),
ASN1_SIMPLE(X509_REQ, sig_alg, X509_ALGOR),
ASN1_SIMPLE(X509_REQ, signature, ASN1_BIT_STRING)
} ASN1_SEQUENCE_END_ref(X509_REQ, X509_REQ)
IMPLEMENT_ASN1_FUNCTIONS(X509_REQ)
IMPLEMENT_ASN1_DUP_FUNCTION(X509_REQ)

View File

@ -1,65 +1,17 @@
/* crypto/asn1/x_sig.c */ /*
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
* All rights reserved.
* *
* This package is an SSL implementation written * Licensed under the OpenSSL license (the "License"). You may not use
* by Eric Young (eay@cryptsoft.com). * this file except in compliance with the License. You can obtain a copy
* The implementation was written so as to conform with Netscapes SSL. * in the file LICENSE in the source distribution or at
* * https://www.openssl.org/source/license.html
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* "This product includes cryptographic software written by
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/ */
#include <stdio.h> #include <stdio.h>
#include "cryptlib.h" #include "internal/cryptlib.h"
#include <openssl/asn1t.h> #include <openssl/asn1t.h>
#include <openssl/x509.h> #include <openssl/x509.h>
#include "internal/x509_int.h"
ASN1_SEQUENCE(X509_SIG) = { ASN1_SEQUENCE(X509_SIG) = {
ASN1_SIMPLE(X509_SIG, algor, X509_ALGOR), ASN1_SIMPLE(X509_SIG, algor, X509_ALGOR),
@ -67,3 +19,21 @@ ASN1_SEQUENCE(X509_SIG) = {
} ASN1_SEQUENCE_END(X509_SIG) } ASN1_SEQUENCE_END(X509_SIG)
IMPLEMENT_ASN1_FUNCTIONS(X509_SIG) IMPLEMENT_ASN1_FUNCTIONS(X509_SIG)
void X509_SIG_get0(const X509_SIG *sig, const X509_ALGOR **palg,
const ASN1_OCTET_STRING **pdigest)
{
if (palg)
*palg = sig->algor;
if (pdigest)
*pdigest = sig->digest;
}
void X509_SIG_getm(X509_SIG *sig, X509_ALGOR **palg,
ASN1_OCTET_STRING **pdigest)
{
if (palg)
*palg = sig->algor;
if (pdigest)
*pdigest = sig->digest;
}

View File

@ -1,59 +1,10 @@
/* crypto/asn1/x_spki.c */ /*
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
* All rights reserved.
* *
* This package is an SSL implementation written * Licensed under the OpenSSL license (the "License"). You may not use
* by Eric Young (eay@cryptsoft.com). * this file except in compliance with the License. You can obtain a copy
* The implementation was written so as to conform with Netscapes SSL. * in the file LICENSE in the source distribution or at
* * https://www.openssl.org/source/license.html
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* "This product includes cryptographic software written by
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/ */
/* /*
@ -62,7 +13,7 @@
*/ */
#include <stdio.h> #include <stdio.h>
#include "cryptlib.h" #include "internal/cryptlib.h"
#include <openssl/x509.h> #include <openssl/x509.h>
#include <openssl/asn1t.h> #include <openssl/asn1t.h>
@ -75,7 +26,7 @@ IMPLEMENT_ASN1_FUNCTIONS(NETSCAPE_SPKAC)
ASN1_SEQUENCE(NETSCAPE_SPKI) = { ASN1_SEQUENCE(NETSCAPE_SPKI) = {
ASN1_SIMPLE(NETSCAPE_SPKI, spkac, NETSCAPE_SPKAC), ASN1_SIMPLE(NETSCAPE_SPKI, spkac, NETSCAPE_SPKAC),
ASN1_SIMPLE(NETSCAPE_SPKI, sig_algor, X509_ALGOR), ASN1_EMBED(NETSCAPE_SPKI, sig_algor, X509_ALGOR),
ASN1_SIMPLE(NETSCAPE_SPKI, signature, ASN1_BIT_STRING) ASN1_SIMPLE(NETSCAPE_SPKI, signature, ASN1_BIT_STRING)
} ASN1_SEQUENCE_END(NETSCAPE_SPKI) } ASN1_SEQUENCE_END(NETSCAPE_SPKI)

View File

@ -1,63 +1,14 @@
/* crypto/asn1/x_val.c */ /*
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
* All rights reserved.
* *
* This package is an SSL implementation written * Licensed under the OpenSSL license (the "License"). You may not use
* by Eric Young (eay@cryptsoft.com). * this file except in compliance with the License. You can obtain a copy
* The implementation was written so as to conform with Netscapes SSL. * in the file LICENSE in the source distribution or at
* * https://www.openssl.org/source/license.html
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* "This product includes cryptographic software written by
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/ */
#include <stdio.h> #include <stdio.h>
#include "cryptlib.h" #include "internal/cryptlib.h"
#include <openssl/asn1t.h> #include <openssl/asn1t.h>
#include <openssl/x509.h> #include <openssl/x509.h>

View File

@ -1,196 +0,0 @@
/* a_x509a.c */
/*
* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project
* 1999.
*/
/* ====================================================================
* Copyright (c) 1999 The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
*
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* licensing@OpenSSL.org.
*
* 5. Products derived from this software may not be called "OpenSSL"
* nor may "OpenSSL" appear in their names without prior written
* permission of the OpenSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*
* This product includes cryptographic software written by Eric Young
* (eay@cryptsoft.com). This product includes software written by Tim
* Hudson (tjh@cryptsoft.com).
*
*/
#include <stdio.h>
#include "cryptlib.h"
#include <openssl/evp.h>
#include <openssl/asn1t.h>
#include <openssl/x509.h>
/*
* X509_CERT_AUX routines. These are used to encode additional user
* modifiable data about a certificate. This data is appended to the X509
* encoding when the *_X509_AUX routines are used. This means that the
* "traditional" X509 routines will simply ignore the extra data.
*/
static X509_CERT_AUX *aux_get(X509 *x);
ASN1_SEQUENCE(X509_CERT_AUX) = {
ASN1_SEQUENCE_OF_OPT(X509_CERT_AUX, trust, ASN1_OBJECT),
ASN1_IMP_SEQUENCE_OF_OPT(X509_CERT_AUX, reject, ASN1_OBJECT, 0),
ASN1_OPT(X509_CERT_AUX, alias, ASN1_UTF8STRING),
ASN1_OPT(X509_CERT_AUX, keyid, ASN1_OCTET_STRING),
ASN1_IMP_SEQUENCE_OF_OPT(X509_CERT_AUX, other, X509_ALGOR, 1)
} ASN1_SEQUENCE_END(X509_CERT_AUX)
IMPLEMENT_ASN1_FUNCTIONS(X509_CERT_AUX)
static X509_CERT_AUX *aux_get(X509 *x)
{
if (!x)
return NULL;
if (!x->aux && !(x->aux = X509_CERT_AUX_new()))
return NULL;
return x->aux;
}
int X509_alias_set1(X509 *x, unsigned char *name, int len)
{
X509_CERT_AUX *aux;
if (!name) {
if (!x || !x->aux || !x->aux->alias)
return 1;
ASN1_UTF8STRING_free(x->aux->alias);
x->aux->alias = NULL;
return 1;
}
if (!(aux = aux_get(x)))
return 0;
if (!aux->alias && !(aux->alias = ASN1_UTF8STRING_new()))
return 0;
return ASN1_STRING_set(aux->alias, name, len);
}
int X509_keyid_set1(X509 *x, unsigned char *id, int len)
{
X509_CERT_AUX *aux;
if (!id) {
if (!x || !x->aux || !x->aux->keyid)
return 1;
ASN1_OCTET_STRING_free(x->aux->keyid);
x->aux->keyid = NULL;
return 1;
}
if (!(aux = aux_get(x)))
return 0;
if (!aux->keyid && !(aux->keyid = ASN1_OCTET_STRING_new()))
return 0;
return ASN1_STRING_set(aux->keyid, id, len);
}
unsigned char *X509_alias_get0(X509 *x, int *len)
{
if (!x->aux || !x->aux->alias)
return NULL;
if (len)
*len = x->aux->alias->length;
return x->aux->alias->data;
}
unsigned char *X509_keyid_get0(X509 *x, int *len)
{
if (!x->aux || !x->aux->keyid)
return NULL;
if (len)
*len = x->aux->keyid->length;
return x->aux->keyid->data;
}
int X509_add1_trust_object(X509 *x, ASN1_OBJECT *obj)
{
X509_CERT_AUX *aux;
ASN1_OBJECT *objtmp;
if (!(objtmp = OBJ_dup(obj)))
return 0;
if (!(aux = aux_get(x)))
return 0;
if (!aux->trust && !(aux->trust = sk_ASN1_OBJECT_new_null()))
return 0;
return sk_ASN1_OBJECT_push(aux->trust, objtmp);
}
int X509_add1_reject_object(X509 *x, ASN1_OBJECT *obj)
{
X509_CERT_AUX *aux;
ASN1_OBJECT *objtmp;
if (!(objtmp = OBJ_dup(obj)))
return 0;
if (!(aux = aux_get(x)))
goto err;
if (!aux->reject && !(aux->reject = sk_ASN1_OBJECT_new_null()))
goto err;
return sk_ASN1_OBJECT_push(aux->reject, objtmp);
err:
ASN1_OBJECT_free(objtmp);
return 0;
}
void X509_trust_clear(X509 *x)
{
if (x->aux && x->aux->trust) {
sk_ASN1_OBJECT_pop_free(x->aux->trust, ASN1_OBJECT_free);
x->aux->trust = NULL;
}
}
void X509_reject_clear(X509 *x)
{
if (x->aux && x->aux->reject) {
sk_ASN1_OBJECT_pop_free(x->aux->reject, ASN1_OBJECT_free);
x->aux->reject = NULL;
}
}
ASN1_SEQUENCE(X509_CERT_PAIR) = {
ASN1_EXP_OPT(X509_CERT_PAIR, forward, X509, 0),
ASN1_EXP_OPT(X509_CERT_PAIR, reverse, X509, 1)
} ASN1_SEQUENCE_END(X509_CERT_PAIR)
IMPLEMENT_ASN1_FUNCTIONS(X509_CERT_PAIR)

View File

@ -0,0 +1,23 @@
/*
* Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
/* This must be the first #include file */
#include "../async_locl.h"
#ifdef ASYNC_NULL
int ASYNC_is_capable(void)
{
return 0;
}
void async_local_cleanup(void)
{
}
#endif

View File

@ -0,0 +1,30 @@
/*
* Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
#include <openssl/async.h>
/*
* If we haven't managed to detect any other async architecture then we default
* to NULL.
*/
#ifndef ASYNC_ARCH
# define ASYNC_NULL
# define ASYNC_ARCH
typedef struct async_fibre_st {
int dummy;
} async_fibre;
# define async_fibre_swapcontext(o,n,r) 0
# define async_fibre_makecontext(c) 0
# define async_fibre_free(f)
# define async_fibre_init_dispatcher(f)
#endif

View File

@ -0,0 +1,58 @@
/*
* Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
/* This must be the first #include file */
#include "../async_locl.h"
#ifdef ASYNC_POSIX
# include <stddef.h>
# include <unistd.h>
#define STACKSIZE 32768
int ASYNC_is_capable(void)
{
ucontext_t ctx;
/*
* Some platforms provide getcontext() but it does not work (notably
* MacOSX PPC64). Check for a working getcontext();
*/
return getcontext(&ctx) == 0;
}
void async_local_cleanup(void)
{
}
int async_fibre_makecontext(async_fibre *fibre)
{
fibre->env_init = 0;
if (getcontext(&fibre->fibre) == 0) {
fibre->fibre.uc_stack.ss_sp = OPENSSL_malloc(STACKSIZE);
if (fibre->fibre.uc_stack.ss_sp != NULL) {
fibre->fibre.uc_stack.ss_size = STACKSIZE;
fibre->fibre.uc_link = NULL;
makecontext(&fibre->fibre, async_start_func, 0);
return 1;
}
} else {
fibre->fibre.uc_stack.ss_sp = NULL;
}
return 0;
}
void async_fibre_free(async_fibre *fibre)
{
OPENSSL_free(fibre->fibre.uc_stack.ss_sp);
fibre->fibre.uc_stack.ss_sp = NULL;
}
#endif

View File

@ -0,0 +1,58 @@
/*
* Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
#ifndef OPENSSL_ASYNC_ARCH_ASYNC_POSIX_H
#define OPENSSL_ASYNC_ARCH_ASYNC_POSIX_H
#include <openssl/e_os2.h>
#if (defined(OPENSSL_SYS_UNIX) || defined(OPENSSL_SYS_CYGWIN)) \
&& defined(OPENSSL_THREADS) && !defined(OPENSSL_NO_ASYNC) \
&& !defined(__ANDROID__) && !defined(__OpenBSD__)
# include <unistd.h>
# if _POSIX_VERSION >= 200112L
# include <pthread.h>
# define ASYNC_POSIX
# define ASYNC_ARCH
# include <ucontext.h>
# include <setjmp.h>
# include "e_os.h"
typedef struct async_fibre_st {
ucontext_t fibre;
jmp_buf env;
int env_init;
} async_fibre;
static ossl_inline int async_fibre_swapcontext(async_fibre *o, async_fibre *n, int r)
{
o->env_init = 1;
if (!r || !_setjmp(o->env)) {
if (n->env_init)
_longjmp(n->env, 1);
else
setcontext(&n->fibre);
}
return 1;
}
# define async_fibre_init_dispatcher(d)
int async_fibre_makecontext(async_fibre *fibre);
void async_fibre_free(async_fibre *fibre);
# endif
#endif
#endif /* OPENSSL_ASYNC_ARCH_ASYNC_POSIX_H */

View File

@ -0,0 +1,55 @@
/*
* Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
/* This must be the first #include file */
#include "../async_locl.h"
#ifdef ASYNC_WIN
# include <windows.h>
# include "internal/cryptlib.h"
int ASYNC_is_capable(void)
{
return 1;
}
void async_local_cleanup(void)
{
async_ctx *ctx = async_get_ctx();
if (ctx != NULL) {
async_fibre *fibre = &ctx->dispatcher;
if (fibre != NULL && fibre->fibre != NULL && fibre->converted) {
ConvertFiberToThread();
fibre->fibre = NULL;
}
}
}
int async_fibre_init_dispatcher(async_fibre *fibre)
{
fibre->fibre = ConvertThreadToFiber(NULL);
if (fibre->fibre == NULL) {
fibre->converted = 0;
fibre->fibre = GetCurrentFiber();
if (fibre->fibre == NULL)
return 0;
} else {
fibre->converted = 1;
}
return 1;
}
VOID CALLBACK async_start_func_win(PVOID unused)
{
async_start_func();
}
#endif

View File

@ -0,0 +1,36 @@
/*
* Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
/*
* This is the same detection used in cryptlib to set up the thread local
* storage that we depend on, so just copy that
*/
#if defined(_WIN32) && !defined(OPENSSL_NO_ASYNC)
#include <openssl/async.h>
# define ASYNC_WIN
# define ASYNC_ARCH
# include <windows.h>
# include "internal/cryptlib.h"
typedef struct async_fibre_st {
LPVOID fibre;
int converted;
} async_fibre;
# define async_fibre_swapcontext(o,n,r) \
(SwitchToFiber((n)->fibre), 1)
# define async_fibre_makecontext(c) \
((c)->fibre = CreateFiber(0, async_start_func_win, 0))
# define async_fibre_free(f) (DeleteFiber((f)->fibre))
int async_fibre_init_dispatcher(async_fibre *fibre);
VOID CALLBACK async_start_func_win(PVOID unused);
#endif

View File

@ -0,0 +1,433 @@
/*
* Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
/*
* Without this we start getting longjmp crashes because it thinks we're jumping
* up the stack when in fact we are jumping to an entirely different stack. The
* cost of this is not having certain buffer overrun/underrun checks etc for
* this source file :-(
*/
#undef _FORTIFY_SOURCE
/* This must be the first #include file */
#include "async_locl.h"
#include <openssl/err.h>
#include <internal/cryptlib_int.h>
#include <string.h>
#define ASYNC_JOB_RUNNING 0
#define ASYNC_JOB_PAUSING 1
#define ASYNC_JOB_PAUSED 2
#define ASYNC_JOB_STOPPING 3
static CRYPTO_THREAD_LOCAL ctxkey;
static CRYPTO_THREAD_LOCAL poolkey;
static void async_free_pool_internal(async_pool *pool);
static async_ctx *async_ctx_new(void)
{
async_ctx *nctx = NULL;
nctx = OPENSSL_malloc(sizeof (async_ctx));
if (nctx == NULL) {
ASYNCerr(ASYNC_F_ASYNC_CTX_NEW, ERR_R_MALLOC_FAILURE);
goto err;
}
async_fibre_init_dispatcher(&nctx->dispatcher);
nctx->currjob = NULL;
nctx->blocked = 0;
if (!CRYPTO_THREAD_set_local(&ctxkey, nctx))
goto err;
return nctx;
err:
OPENSSL_free(nctx);
return NULL;
}
async_ctx *async_get_ctx(void)
{
if (!OPENSSL_init_crypto(OPENSSL_INIT_ASYNC, NULL))
return NULL;
return (async_ctx *)CRYPTO_THREAD_get_local(&ctxkey);
}
static int async_ctx_free(void)
{
async_ctx *ctx;
ctx = async_get_ctx();
if (!CRYPTO_THREAD_set_local(&ctxkey, NULL))
return 0;
OPENSSL_free(ctx);
return 1;
}
static ASYNC_JOB *async_job_new(void)
{
ASYNC_JOB *job = NULL;
job = OPENSSL_zalloc(sizeof (ASYNC_JOB));
if (job == NULL) {
ASYNCerr(ASYNC_F_ASYNC_JOB_NEW, ERR_R_MALLOC_FAILURE);
return NULL;
}
job->status = ASYNC_JOB_RUNNING;
return job;
}
static void async_job_free(ASYNC_JOB *job)
{
if (job != NULL) {
OPENSSL_free(job->funcargs);
async_fibre_free(&job->fibrectx);
OPENSSL_free(job);
}
}
static ASYNC_JOB *async_get_pool_job(void) {
ASYNC_JOB *job;
async_pool *pool;
pool = (async_pool *)CRYPTO_THREAD_get_local(&poolkey);
if (pool == NULL) {
/*
* Pool has not been initialised, so init with the defaults, i.e.
* no max size and no pre-created jobs
*/
if (ASYNC_init_thread(0, 0) == 0)
return NULL;
pool = (async_pool *)CRYPTO_THREAD_get_local(&poolkey);
}
job = sk_ASYNC_JOB_pop(pool->jobs);
if (job == NULL) {
/* Pool is empty */
if ((pool->max_size != 0) && (pool->curr_size >= pool->max_size))
return NULL;
job = async_job_new();
if (job != NULL) {
if (! async_fibre_makecontext(&job->fibrectx)) {
async_job_free(job);
return NULL;
}
pool->curr_size++;
}
}
return job;
}
static void async_release_job(ASYNC_JOB *job) {
async_pool *pool;
pool = (async_pool *)CRYPTO_THREAD_get_local(&poolkey);
OPENSSL_free(job->funcargs);
job->funcargs = NULL;
sk_ASYNC_JOB_push(pool->jobs, job);
}
void async_start_func(void)
{
ASYNC_JOB *job;
async_ctx *ctx = async_get_ctx();
while (1) {
/* Run the job */
job = ctx->currjob;
job->ret = job->func(job->funcargs);
/* Stop the job */
job->status = ASYNC_JOB_STOPPING;
if (!async_fibre_swapcontext(&job->fibrectx,
&ctx->dispatcher, 1)) {
/*
* Should not happen. Getting here will close the thread...can't do
* much about it
*/
ASYNCerr(ASYNC_F_ASYNC_START_FUNC, ASYNC_R_FAILED_TO_SWAP_CONTEXT);
}
}
}
int ASYNC_start_job(ASYNC_JOB **job, ASYNC_WAIT_CTX *wctx, int *ret,
int (*func)(void *), void *args, size_t size)
{
async_ctx *ctx = async_get_ctx();
if (ctx == NULL)
ctx = async_ctx_new();
if (ctx == NULL) {
return ASYNC_ERR;
}
if (*job) {
ctx->currjob = *job;
}
for (;;) {
if (ctx->currjob != NULL) {
if (ctx->currjob->status == ASYNC_JOB_STOPPING) {
*ret = ctx->currjob->ret;
ctx->currjob->waitctx = NULL;
async_release_job(ctx->currjob);
ctx->currjob = NULL;
*job = NULL;
return ASYNC_FINISH;
}
if (ctx->currjob->status == ASYNC_JOB_PAUSING) {
*job = ctx->currjob;
ctx->currjob->status = ASYNC_JOB_PAUSED;
ctx->currjob = NULL;
return ASYNC_PAUSE;
}
if (ctx->currjob->status == ASYNC_JOB_PAUSED) {
ctx->currjob = *job;
/* Resume previous job */
if (!async_fibre_swapcontext(&ctx->dispatcher,
&ctx->currjob->fibrectx, 1)) {
ASYNCerr(ASYNC_F_ASYNC_START_JOB,
ASYNC_R_FAILED_TO_SWAP_CONTEXT);
goto err;
}
continue;
}
/* Should not happen */
ASYNCerr(ASYNC_F_ASYNC_START_JOB, ERR_R_INTERNAL_ERROR);
async_release_job(ctx->currjob);
ctx->currjob = NULL;
*job = NULL;
return ASYNC_ERR;
}
/* Start a new job */
if ((ctx->currjob = async_get_pool_job()) == NULL) {
return ASYNC_NO_JOBS;
}
if (args != NULL) {
ctx->currjob->funcargs = OPENSSL_malloc(size);
if (ctx->currjob->funcargs == NULL) {
ASYNCerr(ASYNC_F_ASYNC_START_JOB, ERR_R_MALLOC_FAILURE);
async_release_job(ctx->currjob);
ctx->currjob = NULL;
return ASYNC_ERR;
}
memcpy(ctx->currjob->funcargs, args, size);
} else {
ctx->currjob->funcargs = NULL;
}
ctx->currjob->func = func;
ctx->currjob->waitctx = wctx;
if (!async_fibre_swapcontext(&ctx->dispatcher,
&ctx->currjob->fibrectx, 1)) {
ASYNCerr(ASYNC_F_ASYNC_START_JOB, ASYNC_R_FAILED_TO_SWAP_CONTEXT);
goto err;
}
}
err:
async_release_job(ctx->currjob);
ctx->currjob = NULL;
*job = NULL;
return ASYNC_ERR;
}
int ASYNC_pause_job(void)
{
ASYNC_JOB *job;
async_ctx *ctx = async_get_ctx();
if (ctx == NULL
|| ctx->currjob == NULL
|| ctx->blocked) {
/*
* Could be we've deliberately not been started within a job so this is
* counted as success.
*/
return 1;
}
job = ctx->currjob;
job->status = ASYNC_JOB_PAUSING;
if (!async_fibre_swapcontext(&job->fibrectx,
&ctx->dispatcher, 1)) {
ASYNCerr(ASYNC_F_ASYNC_PAUSE_JOB, ASYNC_R_FAILED_TO_SWAP_CONTEXT);
return 0;
}
/* Reset counts of added and deleted fds */
async_wait_ctx_reset_counts(job->waitctx);
return 1;
}
static void async_empty_pool(async_pool *pool)
{
ASYNC_JOB *job;
if (!pool || !pool->jobs)
return;
do {
job = sk_ASYNC_JOB_pop(pool->jobs);
async_job_free(job);
} while (job);
}
int async_init(void)
{
if (!CRYPTO_THREAD_init_local(&ctxkey, NULL))
return 0;
if (!CRYPTO_THREAD_init_local(&poolkey, NULL)) {
CRYPTO_THREAD_cleanup_local(&ctxkey);
return 0;
}
return 1;
}
void async_deinit(void)
{
CRYPTO_THREAD_cleanup_local(&ctxkey);
CRYPTO_THREAD_cleanup_local(&poolkey);
}
int ASYNC_init_thread(size_t max_size, size_t init_size)
{
async_pool *pool;
size_t curr_size = 0;
if (init_size > max_size) {
ASYNCerr(ASYNC_F_ASYNC_INIT_THREAD, ASYNC_R_INVALID_POOL_SIZE);
return 0;
}
if (!OPENSSL_init_crypto(OPENSSL_INIT_ASYNC, NULL)) {
return 0;
}
if (!ossl_init_thread_start(OPENSSL_INIT_THREAD_ASYNC)) {
return 0;
}
pool = OPENSSL_zalloc(sizeof *pool);
if (pool == NULL) {
ASYNCerr(ASYNC_F_ASYNC_INIT_THREAD, ERR_R_MALLOC_FAILURE);
return 0;
}
pool->jobs = sk_ASYNC_JOB_new_null();
if (pool->jobs == NULL) {
ASYNCerr(ASYNC_F_ASYNC_INIT_THREAD, ERR_R_MALLOC_FAILURE);
OPENSSL_free(pool);
return 0;
}
pool->max_size = max_size;
/* Pre-create jobs as required */
while (init_size--) {
ASYNC_JOB *job;
job = async_job_new();
if (job == NULL || !async_fibre_makecontext(&job->fibrectx)) {
/*
* Not actually fatal because we already created the pool, just
* skip creation of any more jobs
*/
async_job_free(job);
break;
}
job->funcargs = NULL;
sk_ASYNC_JOB_push(pool->jobs, job);
curr_size++;
}
pool->curr_size = curr_size;
if (!CRYPTO_THREAD_set_local(&poolkey, pool)) {
ASYNCerr(ASYNC_F_ASYNC_INIT_THREAD, ASYNC_R_FAILED_TO_SET_POOL);
goto err;
}
return 1;
err:
async_free_pool_internal(pool);
return 0;
}
static void async_free_pool_internal(async_pool *pool)
{
if (pool == NULL)
return;
async_empty_pool(pool);
sk_ASYNC_JOB_free(pool->jobs);
OPENSSL_free(pool);
CRYPTO_THREAD_set_local(&poolkey, NULL);
async_local_cleanup();
async_ctx_free();
}
void ASYNC_cleanup_thread(void)
{
async_free_pool_internal((async_pool *)CRYPTO_THREAD_get_local(&poolkey));
}
ASYNC_JOB *ASYNC_get_current_job(void)
{
async_ctx *ctx;
ctx = async_get_ctx();
if (ctx == NULL)
return NULL;
return ctx->currjob;
}
ASYNC_WAIT_CTX *ASYNC_get_wait_ctx(ASYNC_JOB *job)
{
return job->waitctx;
}
void ASYNC_block_pause(void)
{
async_ctx *ctx = async_get_ctx();
if (ctx == NULL || ctx->currjob == NULL) {
/*
* We're not in a job anyway so ignore this
*/
return;
}
ctx->blocked++;
}
void ASYNC_unblock_pause(void)
{
async_ctx *ctx = async_get_ctx();
if (ctx == NULL || ctx->currjob == NULL) {
/*
* We're not in a job anyway so ignore this
*/
return;
}
if (ctx->blocked > 0)
ctx->blocked--;
}

View File

@ -0,0 +1,51 @@
/*
* Generated by util/mkerr.pl DO NOT EDIT
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
#include <stdio.h>
#include <openssl/err.h>
#include <openssl/async.h>
/* BEGIN ERROR CODES */
#ifndef OPENSSL_NO_ERR
# define ERR_FUNC(func) ERR_PACK(ERR_LIB_ASYNC,func,0)
# define ERR_REASON(reason) ERR_PACK(ERR_LIB_ASYNC,0,reason)
static ERR_STRING_DATA ASYNC_str_functs[] = {
{ERR_FUNC(ASYNC_F_ASYNC_CTX_NEW), "async_ctx_new"},
{ERR_FUNC(ASYNC_F_ASYNC_INIT_THREAD), "ASYNC_init_thread"},
{ERR_FUNC(ASYNC_F_ASYNC_JOB_NEW), "async_job_new"},
{ERR_FUNC(ASYNC_F_ASYNC_PAUSE_JOB), "ASYNC_pause_job"},
{ERR_FUNC(ASYNC_F_ASYNC_START_FUNC), "async_start_func"},
{ERR_FUNC(ASYNC_F_ASYNC_START_JOB), "ASYNC_start_job"},
{0, NULL}
};
static ERR_STRING_DATA ASYNC_str_reasons[] = {
{ERR_REASON(ASYNC_R_FAILED_TO_SET_POOL), "failed to set pool"},
{ERR_REASON(ASYNC_R_FAILED_TO_SWAP_CONTEXT), "failed to swap context"},
{ERR_REASON(ASYNC_R_INIT_FAILED), "init failed"},
{ERR_REASON(ASYNC_R_INVALID_POOL_SIZE), "invalid pool size"},
{0, NULL}
};
#endif
int ERR_load_ASYNC_strings(void)
{
#ifndef OPENSSL_NO_ERR
if (ERR_func_error_string(ASYNC_str_functs[0].error) == NULL) {
ERR_load_strings(0, ASYNC_str_functs);
ERR_load_strings(0, ASYNC_str_reasons);
}
#endif
return 1;
}

View File

@ -0,0 +1,77 @@
/*
* Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
/*
* Must do this before including any header files, because on MacOS/X <stlib.h>
* includes <signal.h> which includes <ucontext.h>
*/
#if defined(__APPLE__) && defined(__MACH__) && !defined(_XOPEN_SOURCE)
# define _XOPEN_SOURCE /* Otherwise incomplete ucontext_t structure */
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
#if defined(_WIN32)
# include <windows.h>
#endif
#include <internal/async.h>
#include <openssl/crypto.h>
typedef struct async_ctx_st async_ctx;
typedef struct async_pool_st async_pool;
#include "arch/async_win.h"
#include "arch/async_posix.h"
#include "arch/async_null.h"
struct async_ctx_st {
async_fibre dispatcher;
ASYNC_JOB *currjob;
unsigned int blocked;
};
struct async_job_st {
async_fibre fibrectx;
int (*func) (void *);
void *funcargs;
int ret;
int status;
ASYNC_WAIT_CTX *waitctx;
};
struct fd_lookup_st {
const void *key;
OSSL_ASYNC_FD fd;
void *custom_data;
void (*cleanup)(ASYNC_WAIT_CTX *, const void *, OSSL_ASYNC_FD, void *);
int add;
int del;
struct fd_lookup_st *next;
};
struct async_wait_ctx_st {
struct fd_lookup_st *fds;
size_t numadd;
size_t numdel;
};
DEFINE_STACK_OF(ASYNC_JOB)
struct async_pool_st {
STACK_OF(ASYNC_JOB) *jobs;
size_t curr_size;
size_t max_size;
};
void async_local_cleanup(void);
void async_start_func(void);
async_ctx *async_get_ctx(void);
void async_wait_ctx_reset_counts(ASYNC_WAIT_CTX *ctx);

Some files were not shown because too many files have changed in this diff Show More