diff options
Diffstat (limited to 'src/lib/libcrypto/asn1')
82 files changed, 23052 insertions, 0 deletions
diff --git a/src/lib/libcrypto/asn1/Makefile b/src/lib/libcrypto/asn1/Makefile new file mode 100644 index 0000000000..63066899d0 --- /dev/null +++ b/src/lib/libcrypto/asn1/Makefile | |||
| @@ -0,0 +1,885 @@ | |||
| 1 | # | ||
| 2 | # OpenSSL/crypto/asn1/Makefile | ||
| 3 | # | ||
| 4 | |||
| 5 | DIR= asn1 | ||
| 6 | TOP= ../.. | ||
| 7 | CC= cc | ||
| 8 | INCLUDES= -I.. -I$(TOP) -I../../include | ||
| 9 | CFLAG=-g | ||
| 10 | MAKEFILE= Makefile | ||
| 11 | AR= ar r | ||
| 12 | |||
| 13 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
| 14 | |||
| 15 | GENERAL=Makefile README | ||
| 16 | TEST= | ||
| 17 | APPS= | ||
| 18 | |||
| 19 | LIB=$(TOP)/libcrypto.a | ||
| 20 | LIBSRC= a_object.c a_bitstr.c a_utctm.c a_gentm.c a_time.c a_int.c a_octet.c \ | ||
| 21 | a_print.c a_type.c a_set.c a_dup.c a_d2i_fp.c a_i2d_fp.c \ | ||
| 22 | a_enum.c a_utf8.c a_sign.c a_digest.c a_verify.c a_mbstr.c a_strex.c \ | ||
| 23 | x_algor.c x_val.c x_pubkey.c x_sig.c x_req.c x_attrib.c x_bignum.c \ | ||
| 24 | x_long.c x_name.c x_x509.c x_x509a.c x_crl.c x_info.c x_spki.c nsseq.c \ | ||
| 25 | d2i_pu.c d2i_pr.c i2d_pu.c i2d_pr.c\ | ||
| 26 | t_req.c t_x509.c t_x509a.c t_crl.c t_pkey.c t_spki.c t_bitst.c \ | ||
| 27 | tasn_new.c tasn_fre.c tasn_enc.c tasn_dec.c tasn_utl.c tasn_typ.c \ | ||
| 28 | f_int.c f_string.c n_pkey.c \ | ||
| 29 | f_enum.c a_hdr.c x_pkey.c a_bool.c x_exten.c asn_mime.c \ | ||
| 30 | asn1_gen.c asn1_par.c asn1_lib.c asn1_err.c a_meth.c a_bytes.c a_strnid.c \ | ||
| 31 | evp_asn1.c asn_pack.c p5_pbe.c p5_pbev2.c p8_pkey.c asn_moid.c | ||
| 32 | LIBOBJ= a_object.o a_bitstr.o a_utctm.o a_gentm.o a_time.o a_int.o a_octet.o \ | ||
| 33 | a_print.o a_type.o a_set.o a_dup.o a_d2i_fp.o a_i2d_fp.o \ | ||
| 34 | a_enum.o a_utf8.o a_sign.o a_digest.o a_verify.o a_mbstr.o a_strex.o \ | ||
| 35 | x_algor.o x_val.o x_pubkey.o x_sig.o x_req.o x_attrib.o x_bignum.o \ | ||
| 36 | x_long.o x_name.o x_x509.o x_x509a.o x_crl.o x_info.o x_spki.o nsseq.o \ | ||
| 37 | d2i_pu.o d2i_pr.o i2d_pu.o i2d_pr.o \ | ||
| 38 | t_req.o t_x509.o t_x509a.o t_crl.o t_pkey.o t_spki.o t_bitst.o \ | ||
| 39 | tasn_new.o tasn_fre.o tasn_enc.o tasn_dec.o tasn_utl.o tasn_typ.o \ | ||
| 40 | f_int.o f_string.o n_pkey.o \ | ||
| 41 | f_enum.o a_hdr.o x_pkey.o a_bool.o x_exten.o asn_mime.o \ | ||
| 42 | asn1_gen.o asn1_par.o asn1_lib.o asn1_err.o a_meth.o a_bytes.o a_strnid.o \ | ||
| 43 | evp_asn1.o asn_pack.o p5_pbe.o p5_pbev2.o p8_pkey.o asn_moid.o | ||
| 44 | |||
| 45 | SRC= $(LIBSRC) | ||
| 46 | |||
| 47 | EXHEADER= asn1.h asn1_mac.h asn1t.h | ||
| 48 | HEADER= $(EXHEADER) | ||
| 49 | |||
| 50 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
| 51 | |||
| 52 | top: | ||
| 53 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
| 54 | |||
| 55 | test: test.c | ||
| 56 | cc -g -I../../include -c test.c | ||
| 57 | cc -g -I../../include -o test test.o -L../.. -lcrypto | ||
| 58 | |||
| 59 | pk: pk.c | ||
| 60 | cc -g -I../../include -c pk.c | ||
| 61 | cc -g -I../../include -o pk pk.o -L../.. -lcrypto | ||
| 62 | |||
| 63 | all: lib | ||
| 64 | |||
| 65 | lib: $(LIBOBJ) | ||
| 66 | $(AR) $(LIB) $(LIBOBJ) | ||
| 67 | $(RANLIB) $(LIB) || echo Never mind. | ||
| 68 | @touch lib | ||
| 69 | |||
| 70 | files: | ||
| 71 | $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO | ||
| 72 | |||
| 73 | links: | ||
| 74 | @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) | ||
| 75 | @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) | ||
| 76 | @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) | ||
| 77 | |||
| 78 | install: | ||
| 79 | @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile... | ||
| 80 | @headerlist="$(EXHEADER)"; for i in $$headerlist ; \ | ||
| 81 | do \ | ||
| 82 | (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ | ||
| 83 | chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ | ||
| 84 | done; | ||
| 85 | |||
| 86 | tags: | ||
| 87 | ctags $(SRC) | ||
| 88 | |||
| 89 | tests: | ||
| 90 | |||
| 91 | lint: | ||
| 92 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
| 93 | |||
| 94 | depend: | ||
| 95 | @[ -n "$(MAKEDEPEND)" ] # should be set by top Makefile... | ||
| 96 | $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC) | ||
| 97 | |||
| 98 | dclean: | ||
| 99 | $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
| 100 | mv -f Makefile.new $(MAKEFILE) | ||
| 101 | |||
| 102 | clean: | ||
| 103 | rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
| 104 | |||
| 105 | |||
| 106 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
| 107 | |||
| 108 | a_bitstr.o: ../../e_os.h ../../include/openssl/asn1.h | ||
| 109 | a_bitstr.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h | ||
| 110 | a_bitstr.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
| 111 | a_bitstr.o: ../../include/openssl/err.h ../../include/openssl/lhash.h | ||
| 112 | a_bitstr.o: ../../include/openssl/opensslconf.h | ||
| 113 | a_bitstr.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 114 | a_bitstr.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
| 115 | a_bitstr.o: ../../include/openssl/symhacks.h ../cryptlib.h a_bitstr.c | ||
| 116 | a_bool.o: ../../e_os.h ../../include/openssl/asn1.h | ||
| 117 | a_bool.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h | ||
| 118 | a_bool.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
| 119 | a_bool.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
| 120 | a_bool.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
| 121 | a_bool.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 122 | a_bool.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
| 123 | a_bool.o: ../../include/openssl/symhacks.h ../cryptlib.h a_bool.c | ||
| 124 | a_bytes.o: ../../e_os.h ../../include/openssl/asn1.h | ||
| 125 | a_bytes.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h | ||
| 126 | a_bytes.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
| 127 | a_bytes.o: ../../include/openssl/err.h ../../include/openssl/lhash.h | ||
| 128 | a_bytes.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
| 129 | a_bytes.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h | ||
| 130 | a_bytes.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 131 | a_bytes.o: ../cryptlib.h a_bytes.c | ||
| 132 | a_d2i_fp.o: ../../e_os.h ../../include/openssl/asn1.h | ||
| 133 | a_d2i_fp.o: ../../include/openssl/asn1_mac.h ../../include/openssl/bio.h | ||
| 134 | a_d2i_fp.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
| 135 | a_d2i_fp.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
| 136 | a_d2i_fp.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
| 137 | a_d2i_fp.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 138 | a_d2i_fp.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
| 139 | a_d2i_fp.o: ../../include/openssl/symhacks.h ../cryptlib.h a_d2i_fp.c | ||
| 140 | a_digest.o: ../../e_os.h ../../include/openssl/asn1.h | ||
| 141 | a_digest.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h | ||
| 142 | a_digest.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
| 143 | a_digest.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h | ||
| 144 | a_digest.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h | ||
| 145 | a_digest.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h | ||
| 146 | a_digest.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
| 147 | a_digest.o: ../../include/openssl/opensslconf.h | ||
| 148 | a_digest.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 149 | a_digest.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h | ||
| 150 | a_digest.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
| 151 | a_digest.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h | ||
| 152 | a_digest.o: ../../include/openssl/x509_vfy.h ../cryptlib.h a_digest.c | ||
| 153 | a_dup.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
| 154 | a_dup.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
| 155 | a_dup.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
| 156 | a_dup.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
| 157 | a_dup.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 158 | a_dup.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
| 159 | a_dup.o: ../../include/openssl/symhacks.h ../cryptlib.h a_dup.c | ||
| 160 | a_enum.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
| 161 | a_enum.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h | ||
| 162 | a_enum.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
| 163 | a_enum.o: ../../include/openssl/err.h ../../include/openssl/lhash.h | ||
| 164 | a_enum.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
| 165 | a_enum.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h | ||
| 166 | a_enum.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 167 | a_enum.o: ../cryptlib.h a_enum.c | ||
| 168 | a_gentm.o: ../../e_os.h ../../include/openssl/asn1.h | ||
| 169 | a_gentm.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h | ||
| 170 | a_gentm.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
| 171 | a_gentm.o: ../../include/openssl/err.h ../../include/openssl/lhash.h | ||
| 172 | a_gentm.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
| 173 | a_gentm.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h | ||
| 174 | a_gentm.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 175 | a_gentm.o: ../cryptlib.h ../o_time.h a_gentm.c | ||
| 176 | a_hdr.o: ../../e_os.h ../../include/openssl/asn1.h | ||
| 177 | a_hdr.o: ../../include/openssl/asn1_mac.h ../../include/openssl/bio.h | ||
| 178 | a_hdr.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
| 179 | a_hdr.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
| 180 | a_hdr.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
| 181 | a_hdr.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 182 | a_hdr.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
| 183 | a_hdr.o: ../../include/openssl/symhacks.h ../cryptlib.h a_hdr.c | ||
| 184 | a_i2d_fp.o: ../../e_os.h ../../include/openssl/asn1.h | ||
| 185 | a_i2d_fp.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h | ||
| 186 | a_i2d_fp.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
| 187 | a_i2d_fp.o: ../../include/openssl/err.h ../../include/openssl/lhash.h | ||
| 188 | a_i2d_fp.o: ../../include/openssl/opensslconf.h | ||
| 189 | a_i2d_fp.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 190 | a_i2d_fp.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
| 191 | a_i2d_fp.o: ../../include/openssl/symhacks.h ../cryptlib.h a_i2d_fp.c | ||
| 192 | a_int.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
| 193 | a_int.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h | ||
| 194 | a_int.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
| 195 | a_int.o: ../../include/openssl/err.h ../../include/openssl/lhash.h | ||
| 196 | a_int.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
| 197 | a_int.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h | ||
| 198 | a_int.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 199 | a_int.o: ../cryptlib.h a_int.c | ||
| 200 | a_mbstr.o: ../../e_os.h ../../include/openssl/asn1.h | ||
| 201 | a_mbstr.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h | ||
| 202 | a_mbstr.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
| 203 | a_mbstr.o: ../../include/openssl/err.h ../../include/openssl/lhash.h | ||
| 204 | a_mbstr.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
| 205 | a_mbstr.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h | ||
| 206 | a_mbstr.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 207 | a_mbstr.o: ../cryptlib.h a_mbstr.c | ||
| 208 | a_meth.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
| 209 | a_meth.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
| 210 | a_meth.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
| 211 | a_meth.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
| 212 | a_meth.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 213 | a_meth.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
| 214 | a_meth.o: ../../include/openssl/symhacks.h ../cryptlib.h a_meth.c | ||
| 215 | a_object.o: ../../e_os.h ../../include/openssl/asn1.h | ||
| 216 | a_object.o: ../../include/openssl/bio.h ../../include/openssl/bn.h | ||
| 217 | a_object.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
| 218 | a_object.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
| 219 | a_object.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h | ||
| 220 | a_object.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | ||
| 221 | a_object.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 222 | a_object.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
| 223 | a_object.o: ../../include/openssl/symhacks.h ../cryptlib.h a_object.c | ||
| 224 | a_octet.o: ../../e_os.h ../../include/openssl/asn1.h | ||
| 225 | a_octet.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h | ||
| 226 | a_octet.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
| 227 | a_octet.o: ../../include/openssl/err.h ../../include/openssl/lhash.h | ||
| 228 | a_octet.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
| 229 | a_octet.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h | ||
| 230 | a_octet.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 231 | a_octet.o: ../cryptlib.h a_octet.c | ||
| 232 | a_print.o: ../../e_os.h ../../include/openssl/asn1.h | ||
| 233 | a_print.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h | ||
| 234 | a_print.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
| 235 | a_print.o: ../../include/openssl/err.h ../../include/openssl/lhash.h | ||
| 236 | a_print.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
| 237 | a_print.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h | ||
| 238 | a_print.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 239 | a_print.o: ../cryptlib.h a_print.c | ||
| 240 | a_set.o: ../../e_os.h ../../include/openssl/asn1.h | ||
| 241 | a_set.o: ../../include/openssl/asn1_mac.h ../../include/openssl/bio.h | ||
| 242 | a_set.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
| 243 | a_set.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
| 244 | a_set.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
| 245 | a_set.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 246 | a_set.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
| 247 | a_set.o: ../../include/openssl/symhacks.h ../cryptlib.h a_set.c | ||
| 248 | a_sign.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
| 249 | a_sign.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h | ||
| 250 | a_sign.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
| 251 | a_sign.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h | ||
| 252 | a_sign.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h | ||
| 253 | a_sign.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h | ||
| 254 | a_sign.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
| 255 | a_sign.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
| 256 | a_sign.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h | ||
| 257 | a_sign.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
| 258 | a_sign.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 259 | a_sign.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h | ||
| 260 | a_sign.o: ../cryptlib.h a_sign.c | ||
| 261 | a_strex.o: ../../e_os.h ../../include/openssl/asn1.h | ||
| 262 | a_strex.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h | ||
| 263 | a_strex.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
| 264 | a_strex.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h | ||
| 265 | a_strex.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h | ||
| 266 | a_strex.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h | ||
| 267 | a_strex.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
| 268 | a_strex.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
| 269 | a_strex.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h | ||
| 270 | a_strex.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
| 271 | a_strex.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 272 | a_strex.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h | ||
| 273 | a_strex.o: ../cryptlib.h a_strex.c charmap.h | ||
| 274 | a_strnid.o: ../../e_os.h ../../include/openssl/asn1.h | ||
| 275 | a_strnid.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h | ||
| 276 | a_strnid.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
| 277 | a_strnid.o: ../../include/openssl/err.h ../../include/openssl/lhash.h | ||
| 278 | a_strnid.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
| 279 | a_strnid.o: ../../include/openssl/opensslconf.h | ||
| 280 | a_strnid.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 281 | a_strnid.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
| 282 | a_strnid.o: ../../include/openssl/symhacks.h ../cryptlib.h a_strnid.c | ||
| 283 | a_time.o: ../../e_os.h ../../include/openssl/asn1.h | ||
| 284 | a_time.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h | ||
| 285 | a_time.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
| 286 | a_time.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
| 287 | a_time.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
| 288 | a_time.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 289 | a_time.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
| 290 | a_time.o: ../../include/openssl/symhacks.h ../cryptlib.h ../o_time.h a_time.c | ||
| 291 | a_type.o: ../../e_os.h ../../include/openssl/asn1.h | ||
| 292 | a_type.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h | ||
| 293 | a_type.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
| 294 | a_type.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
| 295 | a_type.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h | ||
| 296 | a_type.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | ||
| 297 | a_type.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 298 | a_type.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
| 299 | a_type.o: ../../include/openssl/symhacks.h ../cryptlib.h a_type.c | ||
| 300 | a_utctm.o: ../../e_os.h ../../include/openssl/asn1.h | ||
| 301 | a_utctm.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h | ||
| 302 | a_utctm.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
| 303 | a_utctm.o: ../../include/openssl/err.h ../../include/openssl/lhash.h | ||
| 304 | a_utctm.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
| 305 | a_utctm.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h | ||
| 306 | a_utctm.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 307 | a_utctm.o: ../cryptlib.h ../o_time.h a_utctm.c | ||
| 308 | a_utf8.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
| 309 | a_utf8.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
| 310 | a_utf8.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
| 311 | a_utf8.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
| 312 | a_utf8.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 313 | a_utf8.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
| 314 | a_utf8.o: ../../include/openssl/symhacks.h ../cryptlib.h a_utf8.c | ||
| 315 | a_verify.o: ../../e_os.h ../../include/openssl/asn1.h | ||
| 316 | a_verify.o: ../../include/openssl/bio.h ../../include/openssl/bn.h | ||
| 317 | a_verify.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
| 318 | a_verify.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h | ||
| 319 | a_verify.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h | ||
| 320 | a_verify.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
| 321 | a_verify.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h | ||
| 322 | a_verify.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | ||
| 323 | a_verify.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 324 | a_verify.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h | ||
| 325 | a_verify.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
| 326 | a_verify.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h | ||
| 327 | a_verify.o: ../../include/openssl/x509_vfy.h ../cryptlib.h a_verify.c | ||
| 328 | asn1_err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
| 329 | asn1_err.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
| 330 | asn1_err.o: ../../include/openssl/err.h ../../include/openssl/lhash.h | ||
| 331 | asn1_err.o: ../../include/openssl/opensslconf.h | ||
| 332 | asn1_err.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 333 | asn1_err.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
| 334 | asn1_err.o: ../../include/openssl/symhacks.h asn1_err.c | ||
| 335 | asn1_gen.o: ../../e_os.h ../../include/openssl/asn1.h | ||
| 336 | asn1_gen.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h | ||
| 337 | asn1_gen.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h | ||
| 338 | asn1_gen.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h | ||
| 339 | asn1_gen.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h | ||
| 340 | asn1_gen.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
| 341 | asn1_gen.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h | ||
| 342 | asn1_gen.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | ||
| 343 | asn1_gen.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 344 | asn1_gen.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h | ||
| 345 | asn1_gen.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
| 346 | asn1_gen.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h | ||
| 347 | asn1_gen.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h | ||
| 348 | asn1_gen.o: ../cryptlib.h asn1_gen.c | ||
| 349 | asn1_lib.o: ../../e_os.h ../../include/openssl/asn1.h | ||
| 350 | asn1_lib.o: ../../include/openssl/asn1_mac.h ../../include/openssl/bio.h | ||
| 351 | asn1_lib.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
| 352 | asn1_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
| 353 | asn1_lib.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
| 354 | asn1_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 355 | asn1_lib.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
| 356 | asn1_lib.o: ../../include/openssl/symhacks.h ../cryptlib.h asn1_lib.c | ||
| 357 | asn1_par.o: ../../e_os.h ../../include/openssl/asn1.h | ||
| 358 | asn1_par.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h | ||
| 359 | asn1_par.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
| 360 | asn1_par.o: ../../include/openssl/err.h ../../include/openssl/lhash.h | ||
| 361 | asn1_par.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
| 362 | asn1_par.o: ../../include/openssl/opensslconf.h | ||
| 363 | asn1_par.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 364 | asn1_par.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
| 365 | asn1_par.o: ../../include/openssl/symhacks.h ../cryptlib.h asn1_par.c | ||
| 366 | asn_mime.o: ../../e_os.h ../../include/openssl/asn1.h | ||
| 367 | asn_mime.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h | ||
| 368 | asn_mime.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
| 369 | asn_mime.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h | ||
| 370 | asn_mime.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h | ||
| 371 | asn_mime.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
| 372 | asn_mime.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h | ||
| 373 | asn_mime.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | ||
| 374 | asn_mime.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 375 | asn_mime.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h | ||
| 376 | asn_mime.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
| 377 | asn_mime.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 378 | asn_mime.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h | ||
| 379 | asn_mime.o: ../cryptlib.h asn_mime.c | ||
| 380 | asn_moid.o: ../../e_os.h ../../include/openssl/asn1.h | ||
| 381 | asn_moid.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h | ||
| 382 | asn_moid.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h | ||
| 383 | asn_moid.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h | ||
| 384 | asn_moid.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h | ||
| 385 | asn_moid.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h | ||
| 386 | asn_moid.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h | ||
| 387 | asn_moid.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
| 388 | asn_moid.o: ../../include/openssl/opensslconf.h | ||
| 389 | asn_moid.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 390 | asn_moid.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h | ||
| 391 | asn_moid.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
| 392 | asn_moid.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h | ||
| 393 | asn_moid.o: ../../include/openssl/x509_vfy.h ../cryptlib.h asn_moid.c | ||
| 394 | asn_pack.o: ../../e_os.h ../../include/openssl/asn1.h | ||
| 395 | asn_pack.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h | ||
| 396 | asn_pack.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
| 397 | asn_pack.o: ../../include/openssl/err.h ../../include/openssl/lhash.h | ||
| 398 | asn_pack.o: ../../include/openssl/opensslconf.h | ||
| 399 | asn_pack.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 400 | asn_pack.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
| 401 | asn_pack.o: ../../include/openssl/symhacks.h ../cryptlib.h asn_pack.c | ||
| 402 | d2i_pr.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
| 403 | d2i_pr.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h | ||
| 404 | d2i_pr.o: ../../include/openssl/crypto.h ../../include/openssl/dsa.h | ||
| 405 | d2i_pr.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h | ||
| 406 | d2i_pr.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
| 407 | d2i_pr.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h | ||
| 408 | d2i_pr.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | ||
| 409 | d2i_pr.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 410 | d2i_pr.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h | ||
| 411 | d2i_pr.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 412 | d2i_pr.o: ../cryptlib.h d2i_pr.c | ||
| 413 | d2i_pu.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
| 414 | d2i_pu.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h | ||
| 415 | d2i_pu.o: ../../include/openssl/crypto.h ../../include/openssl/dsa.h | ||
| 416 | d2i_pu.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h | ||
| 417 | d2i_pu.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
| 418 | d2i_pu.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h | ||
| 419 | d2i_pu.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | ||
| 420 | d2i_pu.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 421 | d2i_pu.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h | ||
| 422 | d2i_pu.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 423 | d2i_pu.o: ../cryptlib.h d2i_pu.c | ||
| 424 | evp_asn1.o: ../../e_os.h ../../include/openssl/asn1.h | ||
| 425 | evp_asn1.o: ../../include/openssl/asn1_mac.h ../../include/openssl/bio.h | ||
| 426 | evp_asn1.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
| 427 | evp_asn1.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
| 428 | evp_asn1.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
| 429 | evp_asn1.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 430 | evp_asn1.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
| 431 | evp_asn1.o: ../../include/openssl/symhacks.h ../cryptlib.h evp_asn1.c | ||
| 432 | f_enum.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
| 433 | f_enum.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
| 434 | f_enum.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
| 435 | f_enum.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
| 436 | f_enum.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 437 | f_enum.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
| 438 | f_enum.o: ../../include/openssl/symhacks.h ../cryptlib.h f_enum.c | ||
| 439 | f_int.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
| 440 | f_int.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
| 441 | f_int.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
| 442 | f_int.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
| 443 | f_int.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 444 | f_int.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
| 445 | f_int.o: ../../include/openssl/symhacks.h ../cryptlib.h f_int.c | ||
| 446 | f_string.o: ../../e_os.h ../../include/openssl/asn1.h | ||
| 447 | f_string.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h | ||
| 448 | f_string.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
| 449 | f_string.o: ../../include/openssl/err.h ../../include/openssl/lhash.h | ||
| 450 | f_string.o: ../../include/openssl/opensslconf.h | ||
| 451 | f_string.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 452 | f_string.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
| 453 | f_string.o: ../../include/openssl/symhacks.h ../cryptlib.h f_string.c | ||
| 454 | i2d_pr.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
| 455 | i2d_pr.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h | ||
| 456 | i2d_pr.o: ../../include/openssl/crypto.h ../../include/openssl/dsa.h | ||
| 457 | i2d_pr.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h | ||
| 458 | i2d_pr.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
| 459 | i2d_pr.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h | ||
| 460 | i2d_pr.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | ||
| 461 | i2d_pr.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 462 | i2d_pr.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h | ||
| 463 | i2d_pr.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 464 | i2d_pr.o: ../cryptlib.h i2d_pr.c | ||
| 465 | i2d_pu.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
| 466 | i2d_pu.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h | ||
| 467 | i2d_pu.o: ../../include/openssl/crypto.h ../../include/openssl/dsa.h | ||
| 468 | i2d_pu.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h | ||
| 469 | i2d_pu.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
| 470 | i2d_pu.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h | ||
| 471 | i2d_pu.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | ||
| 472 | i2d_pu.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 473 | i2d_pu.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h | ||
| 474 | i2d_pu.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 475 | i2d_pu.o: ../cryptlib.h i2d_pu.c | ||
| 476 | n_pkey.o: ../../e_os.h ../../include/openssl/asn1.h | ||
| 477 | n_pkey.o: ../../include/openssl/asn1_mac.h ../../include/openssl/asn1t.h | ||
| 478 | n_pkey.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h | ||
| 479 | n_pkey.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
| 480 | n_pkey.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h | ||
| 481 | n_pkey.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h | ||
| 482 | n_pkey.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h | ||
| 483 | n_pkey.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
| 484 | n_pkey.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
| 485 | n_pkey.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h | ||
| 486 | n_pkey.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h | ||
| 487 | n_pkey.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
| 488 | n_pkey.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h | ||
| 489 | n_pkey.o: ../../include/openssl/x509_vfy.h ../cryptlib.h n_pkey.c | ||
| 490 | nsseq.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h | ||
| 491 | nsseq.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h | ||
| 492 | nsseq.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
| 493 | nsseq.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h | ||
| 494 | nsseq.o: ../../include/openssl/ecdsa.h ../../include/openssl/evp.h | ||
| 495 | nsseq.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h | ||
| 496 | nsseq.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | ||
| 497 | nsseq.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 498 | nsseq.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h | ||
| 499 | nsseq.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
| 500 | nsseq.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h | ||
| 501 | nsseq.o: ../../include/openssl/x509_vfy.h nsseq.c | ||
| 502 | p5_pbe.o: ../../e_os.h ../../include/openssl/asn1.h | ||
| 503 | p5_pbe.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h | ||
| 504 | p5_pbe.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
| 505 | p5_pbe.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h | ||
| 506 | p5_pbe.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h | ||
| 507 | p5_pbe.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
| 508 | p5_pbe.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h | ||
| 509 | p5_pbe.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | ||
| 510 | p5_pbe.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 511 | p5_pbe.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h | ||
| 512 | p5_pbe.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
| 513 | p5_pbe.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 514 | p5_pbe.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h | ||
| 515 | p5_pbe.o: ../cryptlib.h p5_pbe.c | ||
| 516 | p5_pbev2.o: ../../e_os.h ../../include/openssl/asn1.h | ||
| 517 | p5_pbev2.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h | ||
| 518 | p5_pbev2.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
| 519 | p5_pbev2.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h | ||
| 520 | p5_pbev2.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h | ||
| 521 | p5_pbev2.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
| 522 | p5_pbev2.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h | ||
| 523 | p5_pbev2.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | ||
| 524 | p5_pbev2.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 525 | p5_pbev2.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h | ||
| 526 | p5_pbev2.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
| 527 | p5_pbev2.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 528 | p5_pbev2.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h | ||
| 529 | p5_pbev2.o: ../cryptlib.h p5_pbev2.c | ||
| 530 | p8_pkey.o: ../../e_os.h ../../include/openssl/asn1.h | ||
| 531 | p8_pkey.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h | ||
| 532 | p8_pkey.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
| 533 | p8_pkey.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h | ||
| 534 | p8_pkey.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h | ||
| 535 | p8_pkey.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
| 536 | p8_pkey.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h | ||
| 537 | p8_pkey.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | ||
| 538 | p8_pkey.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 539 | p8_pkey.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h | ||
| 540 | p8_pkey.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
| 541 | p8_pkey.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h | ||
| 542 | p8_pkey.o: ../../include/openssl/x509_vfy.h ../cryptlib.h p8_pkey.c | ||
| 543 | t_bitst.o: ../../e_os.h ../../include/openssl/asn1.h | ||
| 544 | t_bitst.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h | ||
| 545 | t_bitst.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h | ||
| 546 | t_bitst.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h | ||
| 547 | t_bitst.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h | ||
| 548 | t_bitst.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
| 549 | t_bitst.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h | ||
| 550 | t_bitst.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | ||
| 551 | t_bitst.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 552 | t_bitst.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h | ||
| 553 | t_bitst.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
| 554 | t_bitst.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h | ||
| 555 | t_bitst.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h | ||
| 556 | t_bitst.o: ../cryptlib.h t_bitst.c | ||
| 557 | t_crl.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
| 558 | t_crl.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h | ||
| 559 | t_crl.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h | ||
| 560 | t_crl.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h | ||
| 561 | t_crl.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h | ||
| 562 | t_crl.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
| 563 | t_crl.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h | ||
| 564 | t_crl.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | ||
| 565 | t_crl.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 566 | t_crl.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h | ||
| 567 | t_crl.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
| 568 | t_crl.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h | ||
| 569 | t_crl.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h | ||
| 570 | t_crl.o: ../cryptlib.h t_crl.c | ||
| 571 | t_pkey.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
| 572 | t_pkey.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h | ||
| 573 | t_pkey.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h | ||
| 574 | t_pkey.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h | ||
| 575 | t_pkey.o: ../../include/openssl/ec.h ../../include/openssl/err.h | ||
| 576 | t_pkey.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h | ||
| 577 | t_pkey.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | ||
| 578 | t_pkey.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 579 | t_pkey.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h | ||
| 580 | t_pkey.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 581 | t_pkey.o: ../cryptlib.h t_pkey.c | ||
| 582 | t_req.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
| 583 | t_req.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h | ||
| 584 | t_req.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h | ||
| 585 | t_req.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h | ||
| 586 | t_req.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h | ||
| 587 | t_req.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h | ||
| 588 | t_req.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h | ||
| 589 | t_req.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
| 590 | t_req.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
| 591 | t_req.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h | ||
| 592 | t_req.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h | ||
| 593 | t_req.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
| 594 | t_req.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h | ||
| 595 | t_req.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h | ||
| 596 | t_req.o: ../cryptlib.h t_req.c | ||
| 597 | t_spki.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
| 598 | t_spki.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h | ||
| 599 | t_spki.o: ../../include/openssl/crypto.h ../../include/openssl/dsa.h | ||
| 600 | t_spki.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h | ||
| 601 | t_spki.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h | ||
| 602 | t_spki.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
| 603 | t_spki.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h | ||
| 604 | t_spki.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | ||
| 605 | t_spki.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 606 | t_spki.o: ../../include/openssl/pkcs7.h ../../include/openssl/rsa.h | ||
| 607 | t_spki.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
| 608 | t_spki.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 609 | t_spki.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h | ||
| 610 | t_spki.o: ../cryptlib.h t_spki.c | ||
| 611 | t_x509.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
| 612 | t_x509.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h | ||
| 613 | t_x509.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h | ||
| 614 | t_x509.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h | ||
| 615 | t_x509.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h | ||
| 616 | t_x509.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h | ||
| 617 | t_x509.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h | ||
| 618 | t_x509.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
| 619 | t_x509.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
| 620 | t_x509.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h | ||
| 621 | t_x509.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h | ||
| 622 | t_x509.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
| 623 | t_x509.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h | ||
| 624 | t_x509.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h | ||
| 625 | t_x509.o: ../cryptlib.h t_x509.c | ||
| 626 | t_x509a.o: ../../e_os.h ../../include/openssl/asn1.h | ||
| 627 | t_x509a.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h | ||
| 628 | t_x509a.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
| 629 | t_x509a.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h | ||
| 630 | t_x509a.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h | ||
| 631 | t_x509a.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h | ||
| 632 | t_x509a.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
| 633 | t_x509a.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
| 634 | t_x509a.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h | ||
| 635 | t_x509a.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
| 636 | t_x509a.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 637 | t_x509a.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h | ||
| 638 | t_x509a.o: ../cryptlib.h t_x509a.c | ||
| 639 | tasn_dec.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h | ||
| 640 | tasn_dec.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h | ||
| 641 | tasn_dec.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
| 642 | tasn_dec.o: ../../include/openssl/err.h ../../include/openssl/lhash.h | ||
| 643 | tasn_dec.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
| 644 | tasn_dec.o: ../../include/openssl/opensslconf.h | ||
| 645 | tasn_dec.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 646 | tasn_dec.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
| 647 | tasn_dec.o: ../../include/openssl/symhacks.h tasn_dec.c | ||
| 648 | tasn_enc.o: ../../e_os.h ../../include/openssl/asn1.h | ||
| 649 | tasn_enc.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h | ||
| 650 | tasn_enc.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
| 651 | tasn_enc.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
| 652 | tasn_enc.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h | ||
| 653 | tasn_enc.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | ||
| 654 | tasn_enc.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 655 | tasn_enc.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
| 656 | tasn_enc.o: ../../include/openssl/symhacks.h ../cryptlib.h tasn_enc.c | ||
| 657 | tasn_fre.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h | ||
| 658 | tasn_fre.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h | ||
| 659 | tasn_fre.o: ../../include/openssl/e_os2.h ../../include/openssl/obj_mac.h | ||
| 660 | tasn_fre.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | ||
| 661 | tasn_fre.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 662 | tasn_fre.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
| 663 | tasn_fre.o: ../../include/openssl/symhacks.h tasn_fre.c | ||
| 664 | tasn_new.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h | ||
| 665 | tasn_new.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h | ||
| 666 | tasn_new.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
| 667 | tasn_new.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h | ||
| 668 | tasn_new.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | ||
| 669 | tasn_new.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 670 | tasn_new.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
| 671 | tasn_new.o: ../../include/openssl/symhacks.h tasn_new.c | ||
| 672 | tasn_typ.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h | ||
| 673 | tasn_typ.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h | ||
| 674 | tasn_typ.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h | ||
| 675 | tasn_typ.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 676 | tasn_typ.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
| 677 | tasn_typ.o: ../../include/openssl/symhacks.h tasn_typ.c | ||
| 678 | tasn_utl.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h | ||
| 679 | tasn_utl.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h | ||
| 680 | tasn_utl.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
| 681 | tasn_utl.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h | ||
| 682 | tasn_utl.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | ||
| 683 | tasn_utl.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 684 | tasn_utl.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
| 685 | tasn_utl.o: ../../include/openssl/symhacks.h tasn_utl.c | ||
| 686 | x_algor.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h | ||
| 687 | x_algor.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h | ||
| 688 | x_algor.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
| 689 | x_algor.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h | ||
| 690 | x_algor.o: ../../include/openssl/ecdsa.h ../../include/openssl/evp.h | ||
| 691 | x_algor.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h | ||
| 692 | x_algor.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | ||
| 693 | x_algor.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 694 | x_algor.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h | ||
| 695 | x_algor.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
| 696 | x_algor.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h | ||
| 697 | x_algor.o: ../../include/openssl/x509_vfy.h x_algor.c | ||
| 698 | x_attrib.o: ../../e_os.h ../../include/openssl/asn1.h | ||
| 699 | x_attrib.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h | ||
| 700 | x_attrib.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
| 701 | x_attrib.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h | ||
| 702 | x_attrib.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h | ||
| 703 | x_attrib.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
| 704 | x_attrib.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h | ||
| 705 | x_attrib.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | ||
| 706 | x_attrib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 707 | x_attrib.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h | ||
| 708 | x_attrib.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
| 709 | x_attrib.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h | ||
| 710 | x_attrib.o: ../../include/openssl/x509_vfy.h ../cryptlib.h x_attrib.c | ||
| 711 | x_bignum.o: ../../e_os.h ../../include/openssl/asn1.h | ||
| 712 | x_bignum.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h | ||
| 713 | x_bignum.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h | ||
| 714 | x_bignum.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
| 715 | x_bignum.o: ../../include/openssl/err.h ../../include/openssl/lhash.h | ||
| 716 | x_bignum.o: ../../include/openssl/opensslconf.h | ||
| 717 | x_bignum.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 718 | x_bignum.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
| 719 | x_bignum.o: ../../include/openssl/symhacks.h ../cryptlib.h x_bignum.c | ||
| 720 | x_crl.o: ../../e_os.h ../../include/openssl/asn1.h | ||
| 721 | x_crl.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h | ||
| 722 | x_crl.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
| 723 | x_crl.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h | ||
| 724 | x_crl.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h | ||
| 725 | x_crl.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
| 726 | x_crl.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h | ||
| 727 | x_crl.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | ||
| 728 | x_crl.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 729 | x_crl.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h | ||
| 730 | x_crl.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
| 731 | x_crl.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h | ||
| 732 | x_crl.o: ../../include/openssl/x509_vfy.h ../cryptlib.h x_crl.c | ||
| 733 | x_exten.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h | ||
| 734 | x_exten.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h | ||
| 735 | x_exten.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
| 736 | x_exten.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h | ||
| 737 | x_exten.o: ../../include/openssl/ecdsa.h ../../include/openssl/evp.h | ||
| 738 | x_exten.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h | ||
| 739 | x_exten.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | ||
| 740 | x_exten.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 741 | x_exten.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h | ||
| 742 | x_exten.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
| 743 | x_exten.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h | ||
| 744 | x_exten.o: ../../include/openssl/x509_vfy.h x_exten.c | ||
| 745 | x_info.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
| 746 | x_info.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
| 747 | x_info.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h | ||
| 748 | x_info.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h | ||
| 749 | x_info.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
| 750 | x_info.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h | ||
| 751 | x_info.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | ||
| 752 | x_info.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 753 | x_info.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h | ||
| 754 | x_info.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
| 755 | x_info.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h | ||
| 756 | x_info.o: ../../include/openssl/x509_vfy.h ../cryptlib.h x_info.c | ||
| 757 | x_long.o: ../../e_os.h ../../include/openssl/asn1.h | ||
| 758 | x_long.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h | ||
| 759 | x_long.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h | ||
| 760 | x_long.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
| 761 | x_long.o: ../../include/openssl/err.h ../../include/openssl/lhash.h | ||
| 762 | x_long.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
| 763 | x_long.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h | ||
| 764 | x_long.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 765 | x_long.o: ../cryptlib.h x_long.c | ||
| 766 | x_name.o: ../../e_os.h ../../include/openssl/asn1.h | ||
| 767 | x_name.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h | ||
| 768 | x_name.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
| 769 | x_name.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h | ||
| 770 | x_name.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h | ||
| 771 | x_name.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
| 772 | x_name.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h | ||
| 773 | x_name.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | ||
| 774 | x_name.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 775 | x_name.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h | ||
| 776 | x_name.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
| 777 | x_name.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h | ||
| 778 | x_name.o: ../../include/openssl/x509_vfy.h ../cryptlib.h x_name.c | ||
| 779 | x_pkey.o: ../../e_os.h ../../include/openssl/asn1.h | ||
| 780 | x_pkey.o: ../../include/openssl/asn1_mac.h ../../include/openssl/bio.h | ||
| 781 | x_pkey.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
| 782 | x_pkey.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h | ||
| 783 | x_pkey.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h | ||
| 784 | x_pkey.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
| 785 | x_pkey.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h | ||
| 786 | x_pkey.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | ||
| 787 | x_pkey.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 788 | x_pkey.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h | ||
| 789 | x_pkey.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
| 790 | x_pkey.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h | ||
| 791 | x_pkey.o: ../../include/openssl/x509_vfy.h ../cryptlib.h x_pkey.c | ||
| 792 | x_pubkey.o: ../../e_os.h ../../include/openssl/asn1.h | ||
| 793 | x_pubkey.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h | ||
| 794 | x_pubkey.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
| 795 | x_pubkey.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h | ||
| 796 | x_pubkey.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h | ||
| 797 | x_pubkey.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h | ||
| 798 | x_pubkey.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h | ||
| 799 | x_pubkey.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
| 800 | x_pubkey.o: ../../include/openssl/opensslconf.h | ||
| 801 | x_pubkey.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 802 | x_pubkey.o: ../../include/openssl/pkcs7.h ../../include/openssl/rsa.h | ||
| 803 | x_pubkey.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
| 804 | x_pubkey.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 805 | x_pubkey.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h | ||
| 806 | x_pubkey.o: ../cryptlib.h x_pubkey.c | ||
| 807 | x_req.o: ../../e_os.h ../../include/openssl/asn1.h | ||
| 808 | x_req.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h | ||
| 809 | x_req.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
| 810 | x_req.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h | ||
| 811 | x_req.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h | ||
| 812 | x_req.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
| 813 | x_req.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h | ||
| 814 | x_req.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | ||
| 815 | x_req.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 816 | x_req.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h | ||
| 817 | x_req.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
| 818 | x_req.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h | ||
| 819 | x_req.o: ../../include/openssl/x509_vfy.h ../cryptlib.h x_req.c | ||
| 820 | x_sig.o: ../../e_os.h ../../include/openssl/asn1.h | ||
| 821 | x_sig.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h | ||
| 822 | x_sig.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
| 823 | x_sig.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h | ||
| 824 | x_sig.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h | ||
| 825 | x_sig.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
| 826 | x_sig.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h | ||
| 827 | x_sig.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | ||
| 828 | x_sig.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 829 | x_sig.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h | ||
| 830 | x_sig.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
| 831 | x_sig.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h | ||
| 832 | x_sig.o: ../../include/openssl/x509_vfy.h ../cryptlib.h x_sig.c | ||
| 833 | x_spki.o: ../../e_os.h ../../include/openssl/asn1.h | ||
| 834 | x_spki.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h | ||
| 835 | x_spki.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
| 836 | x_spki.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h | ||
| 837 | x_spki.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h | ||
| 838 | x_spki.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
| 839 | x_spki.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h | ||
| 840 | x_spki.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | ||
| 841 | x_spki.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 842 | x_spki.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h | ||
| 843 | x_spki.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
| 844 | x_spki.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h | ||
| 845 | x_spki.o: ../../include/openssl/x509_vfy.h ../cryptlib.h x_spki.c | ||
| 846 | x_val.o: ../../e_os.h ../../include/openssl/asn1.h | ||
| 847 | x_val.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h | ||
| 848 | x_val.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
| 849 | x_val.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h | ||
| 850 | x_val.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h | ||
| 851 | x_val.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
| 852 | x_val.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h | ||
| 853 | x_val.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | ||
| 854 | x_val.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 855 | x_val.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h | ||
| 856 | x_val.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
| 857 | x_val.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h | ||
| 858 | x_val.o: ../../include/openssl/x509_vfy.h ../cryptlib.h x_val.c | ||
| 859 | x_x509.o: ../../e_os.h ../../include/openssl/asn1.h | ||
| 860 | x_x509.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h | ||
| 861 | x_x509.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h | ||
| 862 | x_x509.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
| 863 | x_x509.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h | ||
| 864 | x_x509.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h | ||
| 865 | x_x509.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h | ||
| 866 | x_x509.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
| 867 | x_x509.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
| 868 | x_x509.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h | ||
| 869 | x_x509.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
| 870 | x_x509.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 871 | x_x509.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h | ||
| 872 | x_x509.o: ../../include/openssl/x509v3.h ../cryptlib.h x_x509.c | ||
| 873 | x_x509a.o: ../../e_os.h ../../include/openssl/asn1.h | ||
| 874 | x_x509a.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h | ||
| 875 | x_x509a.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
| 876 | x_x509a.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h | ||
| 877 | x_x509a.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h | ||
| 878 | x_x509a.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
| 879 | x_x509a.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h | ||
| 880 | x_x509a.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | ||
| 881 | x_x509a.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 882 | x_x509a.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h | ||
| 883 | x_x509a.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
| 884 | x_x509a.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h | ||
| 885 | x_x509a.o: ../../include/openssl/x509_vfy.h ../cryptlib.h x_x509a.c | ||
diff --git a/src/lib/libcrypto/asn1/a_bitstr.c b/src/lib/libcrypto/asn1/a_bitstr.c new file mode 100644 index 0000000000..0fb9ce0c2a --- /dev/null +++ b/src/lib/libcrypto/asn1/a_bitstr.c | |||
| @@ -0,0 +1,225 @@ | |||
| 1 | /* crypto/asn1/a_bitstr.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/asn1.h> | ||
| 62 | |||
| 63 | int ASN1_BIT_STRING_set(ASN1_BIT_STRING *x, unsigned char *d, int len) | ||
| 64 | { return M_ASN1_BIT_STRING_set(x, d, len); } | ||
| 65 | |||
| 66 | int i2c_ASN1_BIT_STRING(ASN1_BIT_STRING *a, unsigned char **pp) | ||
| 67 | { | ||
| 68 | int ret,j,bits,len; | ||
| 69 | unsigned char *p,*d; | ||
| 70 | |||
| 71 | if (a == NULL) return(0); | ||
| 72 | |||
| 73 | len=a->length; | ||
| 74 | |||
| 75 | if (len > 0) | ||
| 76 | { | ||
| 77 | if (a->flags & ASN1_STRING_FLAG_BITS_LEFT) | ||
| 78 | { | ||
| 79 | bits=(int)a->flags&0x07; | ||
| 80 | } | ||
| 81 | else | ||
| 82 | { | ||
| 83 | for ( ; len > 0; len--) | ||
| 84 | { | ||
| 85 | if (a->data[len-1]) break; | ||
| 86 | } | ||
| 87 | j=a->data[len-1]; | ||
| 88 | if (j & 0x01) bits=0; | ||
| 89 | else if (j & 0x02) bits=1; | ||
| 90 | else if (j & 0x04) bits=2; | ||
| 91 | else if (j & 0x08) bits=3; | ||
| 92 | else if (j & 0x10) bits=4; | ||
| 93 | else if (j & 0x20) bits=5; | ||
| 94 | else if (j & 0x40) bits=6; | ||
| 95 | else if (j & 0x80) bits=7; | ||
| 96 | else bits=0; /* should not happen */ | ||
| 97 | } | ||
| 98 | } | ||
| 99 | else | ||
| 100 | bits=0; | ||
| 101 | |||
| 102 | ret=1+len; | ||
| 103 | if (pp == NULL) return(ret); | ||
| 104 | |||
| 105 | p= *pp; | ||
| 106 | |||
| 107 | *(p++)=(unsigned char)bits; | ||
| 108 | d=a->data; | ||
| 109 | memcpy(p,d,len); | ||
| 110 | p+=len; | ||
| 111 | if (len > 0) p[-1]&=(0xff<<bits); | ||
| 112 | *pp=p; | ||
| 113 | return(ret); | ||
| 114 | } | ||
| 115 | |||
| 116 | ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a, | ||
| 117 | const unsigned char **pp, long len) | ||
| 118 | { | ||
| 119 | ASN1_BIT_STRING *ret=NULL; | ||
| 120 | const unsigned char *p; | ||
| 121 | unsigned char *s; | ||
| 122 | int i; | ||
| 123 | |||
| 124 | if (len < 1) | ||
| 125 | { | ||
| 126 | i=ASN1_R_STRING_TOO_SHORT; | ||
| 127 | goto err; | ||
| 128 | } | ||
| 129 | |||
| 130 | if ((a == NULL) || ((*a) == NULL)) | ||
| 131 | { | ||
| 132 | if ((ret=M_ASN1_BIT_STRING_new()) == NULL) return(NULL); | ||
| 133 | } | ||
| 134 | else | ||
| 135 | ret=(*a); | ||
| 136 | |||
| 137 | p= *pp; | ||
| 138 | i= *(p++); | ||
| 139 | /* We do this to preserve the settings. If we modify | ||
| 140 | * the settings, via the _set_bit function, we will recalculate | ||
| 141 | * on output */ | ||
| 142 | ret->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); /* clear */ | ||
| 143 | ret->flags|=(ASN1_STRING_FLAG_BITS_LEFT|(i&0x07)); /* set */ | ||
| 144 | |||
| 145 | if (len-- > 1) /* using one because of the bits left byte */ | ||
| 146 | { | ||
| 147 | s=(unsigned char *)OPENSSL_malloc((int)len); | ||
| 148 | if (s == NULL) | ||
| 149 | { | ||
| 150 | i=ERR_R_MALLOC_FAILURE; | ||
| 151 | goto err; | ||
| 152 | } | ||
| 153 | memcpy(s,p,(int)len); | ||
| 154 | s[len-1]&=(0xff<<i); | ||
| 155 | p+=len; | ||
| 156 | } | ||
| 157 | else | ||
| 158 | s=NULL; | ||
| 159 | |||
| 160 | ret->length=(int)len; | ||
| 161 | if (ret->data != NULL) OPENSSL_free(ret->data); | ||
| 162 | ret->data=s; | ||
| 163 | ret->type=V_ASN1_BIT_STRING; | ||
| 164 | if (a != NULL) (*a)=ret; | ||
| 165 | *pp=p; | ||
| 166 | return(ret); | ||
| 167 | err: | ||
| 168 | ASN1err(ASN1_F_C2I_ASN1_BIT_STRING,i); | ||
| 169 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) | ||
| 170 | M_ASN1_BIT_STRING_free(ret); | ||
| 171 | return(NULL); | ||
| 172 | } | ||
| 173 | |||
| 174 | /* These next 2 functions from Goetz Babin-Ebell <babinebell@trustcenter.de> | ||
| 175 | */ | ||
| 176 | int ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value) | ||
| 177 | { | ||
| 178 | int w,v,iv; | ||
| 179 | unsigned char *c; | ||
| 180 | |||
| 181 | w=n/8; | ||
| 182 | v=1<<(7-(n&0x07)); | ||
| 183 | iv= ~v; | ||
| 184 | if (!value) v=0; | ||
| 185 | |||
| 186 | if (a == NULL) | ||
| 187 | return 0; | ||
| 188 | |||
| 189 | a->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); /* clear, set on write */ | ||
| 190 | |||
| 191 | if ((a->length < (w+1)) || (a->data == NULL)) | ||
| 192 | { | ||
| 193 | if (!value) return(1); /* Don't need to set */ | ||
| 194 | if (a->data == NULL) | ||
| 195 | c=(unsigned char *)OPENSSL_malloc(w+1); | ||
| 196 | else | ||
| 197 | c=(unsigned char *)OPENSSL_realloc_clean(a->data, | ||
| 198 | a->length, | ||
| 199 | w+1); | ||
| 200 | if (c == NULL) | ||
| 201 | { | ||
| 202 | ASN1err(ASN1_F_ASN1_BIT_STRING_SET_BIT,ERR_R_MALLOC_FAILURE); | ||
| 203 | return 0; | ||
| 204 | } | ||
| 205 | if (w+1-a->length > 0) memset(c+a->length, 0, w+1-a->length); | ||
| 206 | a->data=c; | ||
| 207 | a->length=w+1; | ||
| 208 | } | ||
| 209 | a->data[w]=((a->data[w])&iv)|v; | ||
| 210 | while ((a->length > 0) && (a->data[a->length-1] == 0)) | ||
| 211 | a->length--; | ||
| 212 | return(1); | ||
| 213 | } | ||
| 214 | |||
| 215 | int ASN1_BIT_STRING_get_bit(ASN1_BIT_STRING *a, int n) | ||
| 216 | { | ||
| 217 | int w,v; | ||
| 218 | |||
| 219 | w=n/8; | ||
| 220 | v=1<<(7-(n&0x07)); | ||
| 221 | if ((a == NULL) || (a->length < (w+1)) || (a->data == NULL)) | ||
| 222 | return(0); | ||
| 223 | return((a->data[w]&v) != 0); | ||
| 224 | } | ||
| 225 | |||
diff --git a/src/lib/libcrypto/asn1/a_bool.c b/src/lib/libcrypto/asn1/a_bool.c new file mode 100644 index 0000000000..331acdf053 --- /dev/null +++ b/src/lib/libcrypto/asn1/a_bool.c | |||
| @@ -0,0 +1,114 @@ | |||
| 1 | /* crypto/asn1/a_bool.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/asn1t.h> | ||
| 62 | |||
| 63 | int i2d_ASN1_BOOLEAN(int a, unsigned char **pp) | ||
| 64 | { | ||
| 65 | int r; | ||
| 66 | unsigned char *p; | ||
| 67 | |||
| 68 | r=ASN1_object_size(0,1,V_ASN1_BOOLEAN); | ||
| 69 | if (pp == NULL) return(r); | ||
| 70 | p= *pp; | ||
| 71 | |||
| 72 | ASN1_put_object(&p,0,1,V_ASN1_BOOLEAN,V_ASN1_UNIVERSAL); | ||
| 73 | *(p++)= (unsigned char)a; | ||
| 74 | *pp=p; | ||
| 75 | return(r); | ||
| 76 | } | ||
| 77 | |||
| 78 | int d2i_ASN1_BOOLEAN(int *a, const unsigned char **pp, long length) | ||
| 79 | { | ||
| 80 | int ret= -1; | ||
| 81 | const unsigned char *p; | ||
| 82 | long len; | ||
| 83 | int inf,tag,xclass; | ||
| 84 | int i=0; | ||
| 85 | |||
| 86 | p= *pp; | ||
| 87 | inf=ASN1_get_object(&p,&len,&tag,&xclass,length); | ||
| 88 | if (inf & 0x80) | ||
| 89 | { | ||
| 90 | i=ASN1_R_BAD_OBJECT_HEADER; | ||
| 91 | goto err; | ||
| 92 | } | ||
| 93 | |||
| 94 | if (tag != V_ASN1_BOOLEAN) | ||
| 95 | { | ||
| 96 | i=ASN1_R_EXPECTING_A_BOOLEAN; | ||
| 97 | goto err; | ||
| 98 | } | ||
| 99 | |||
| 100 | if (len != 1) | ||
| 101 | { | ||
| 102 | i=ASN1_R_BOOLEAN_IS_WRONG_LENGTH; | ||
| 103 | goto err; | ||
| 104 | } | ||
| 105 | ret= (int)*(p++); | ||
| 106 | if (a != NULL) (*a)=ret; | ||
| 107 | *pp=p; | ||
| 108 | return(ret); | ||
| 109 | err: | ||
| 110 | ASN1err(ASN1_F_D2I_ASN1_BOOLEAN,i); | ||
| 111 | return(ret); | ||
| 112 | } | ||
| 113 | |||
| 114 | |||
diff --git a/src/lib/libcrypto/asn1/a_bytes.c b/src/lib/libcrypto/asn1/a_bytes.c new file mode 100644 index 0000000000..92d630cdba --- /dev/null +++ b/src/lib/libcrypto/asn1/a_bytes.c | |||
| @@ -0,0 +1,314 @@ | |||
| 1 | /* crypto/asn1/a_bytes.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/asn1.h> | ||
| 62 | |||
| 63 | static int asn1_collate_primitive(ASN1_STRING *a, ASN1_const_CTX *c); | ||
| 64 | /* type is a 'bitmap' of acceptable string types. | ||
| 65 | */ | ||
| 66 | ASN1_STRING *d2i_ASN1_type_bytes(ASN1_STRING **a, const unsigned char **pp, | ||
| 67 | long length, int type) | ||
| 68 | { | ||
| 69 | ASN1_STRING *ret=NULL; | ||
| 70 | const unsigned char *p; | ||
| 71 | unsigned char *s; | ||
| 72 | long len; | ||
| 73 | int inf,tag,xclass; | ||
| 74 | int i=0; | ||
| 75 | |||
| 76 | p= *pp; | ||
| 77 | inf=ASN1_get_object(&p,&len,&tag,&xclass,length); | ||
| 78 | if (inf & 0x80) goto err; | ||
| 79 | |||
| 80 | if (tag >= 32) | ||
| 81 | { | ||
| 82 | i=ASN1_R_TAG_VALUE_TOO_HIGH; | ||
| 83 | goto err; | ||
| 84 | } | ||
| 85 | if (!(ASN1_tag2bit(tag) & type)) | ||
| 86 | { | ||
| 87 | i=ASN1_R_WRONG_TYPE; | ||
| 88 | goto err; | ||
| 89 | } | ||
| 90 | |||
| 91 | /* If a bit-string, exit early */ | ||
| 92 | if (tag == V_ASN1_BIT_STRING) | ||
| 93 | return(d2i_ASN1_BIT_STRING(a,pp,length)); | ||
| 94 | |||
| 95 | if ((a == NULL) || ((*a) == NULL)) | ||
| 96 | { | ||
| 97 | if ((ret=ASN1_STRING_new()) == NULL) return(NULL); | ||
| 98 | } | ||
| 99 | else | ||
| 100 | ret=(*a); | ||
| 101 | |||
| 102 | if (len != 0) | ||
| 103 | { | ||
| 104 | s=(unsigned char *)OPENSSL_malloc((int)len+1); | ||
| 105 | if (s == NULL) | ||
| 106 | { | ||
| 107 | i=ERR_R_MALLOC_FAILURE; | ||
| 108 | goto err; | ||
| 109 | } | ||
| 110 | memcpy(s,p,(int)len); | ||
| 111 | s[len]='\0'; | ||
| 112 | p+=len; | ||
| 113 | } | ||
| 114 | else | ||
| 115 | s=NULL; | ||
| 116 | |||
| 117 | if (ret->data != NULL) OPENSSL_free(ret->data); | ||
| 118 | ret->length=(int)len; | ||
| 119 | ret->data=s; | ||
| 120 | ret->type=tag; | ||
| 121 | if (a != NULL) (*a)=ret; | ||
| 122 | *pp=p; | ||
| 123 | return(ret); | ||
| 124 | err: | ||
| 125 | ASN1err(ASN1_F_D2I_ASN1_TYPE_BYTES,i); | ||
| 126 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) | ||
| 127 | ASN1_STRING_free(ret); | ||
| 128 | return(NULL); | ||
| 129 | } | ||
| 130 | |||
| 131 | int i2d_ASN1_bytes(ASN1_STRING *a, unsigned char **pp, int tag, int xclass) | ||
| 132 | { | ||
| 133 | int ret,r,constructed; | ||
| 134 | unsigned char *p; | ||
| 135 | |||
| 136 | if (a == NULL) return(0); | ||
| 137 | |||
| 138 | if (tag == V_ASN1_BIT_STRING) | ||
| 139 | return(i2d_ASN1_BIT_STRING(a,pp)); | ||
| 140 | |||
| 141 | ret=a->length; | ||
| 142 | r=ASN1_object_size(0,ret,tag); | ||
| 143 | if (pp == NULL) return(r); | ||
| 144 | p= *pp; | ||
| 145 | |||
| 146 | if ((tag == V_ASN1_SEQUENCE) || (tag == V_ASN1_SET)) | ||
| 147 | constructed=1; | ||
| 148 | else | ||
| 149 | constructed=0; | ||
| 150 | ASN1_put_object(&p,constructed,ret,tag,xclass); | ||
| 151 | memcpy(p,a->data,a->length); | ||
| 152 | p+=a->length; | ||
| 153 | *pp= p; | ||
| 154 | return(r); | ||
| 155 | } | ||
| 156 | |||
| 157 | ASN1_STRING *d2i_ASN1_bytes(ASN1_STRING **a, const unsigned char **pp, | ||
| 158 | long length, int Ptag, int Pclass) | ||
| 159 | { | ||
| 160 | ASN1_STRING *ret=NULL; | ||
| 161 | const unsigned char *p; | ||
| 162 | unsigned char *s; | ||
| 163 | long len; | ||
| 164 | int inf,tag,xclass; | ||
| 165 | int i=0; | ||
| 166 | |||
| 167 | if ((a == NULL) || ((*a) == NULL)) | ||
| 168 | { | ||
| 169 | if ((ret=ASN1_STRING_new()) == NULL) return(NULL); | ||
| 170 | } | ||
| 171 | else | ||
| 172 | ret=(*a); | ||
| 173 | |||
| 174 | p= *pp; | ||
| 175 | inf=ASN1_get_object(&p,&len,&tag,&xclass,length); | ||
| 176 | if (inf & 0x80) | ||
| 177 | { | ||
| 178 | i=ASN1_R_BAD_OBJECT_HEADER; | ||
| 179 | goto err; | ||
| 180 | } | ||
| 181 | |||
| 182 | if (tag != Ptag) | ||
| 183 | { | ||
| 184 | i=ASN1_R_WRONG_TAG; | ||
| 185 | goto err; | ||
| 186 | } | ||
| 187 | |||
| 188 | if (inf & V_ASN1_CONSTRUCTED) | ||
| 189 | { | ||
| 190 | ASN1_const_CTX c; | ||
| 191 | |||
| 192 | c.pp=pp; | ||
| 193 | c.p=p; | ||
| 194 | c.inf=inf; | ||
| 195 | c.slen=len; | ||
| 196 | c.tag=Ptag; | ||
| 197 | c.xclass=Pclass; | ||
| 198 | c.max=(length == 0)?0:(p+length); | ||
| 199 | if (!asn1_collate_primitive(ret,&c)) | ||
| 200 | goto err; | ||
| 201 | else | ||
| 202 | { | ||
| 203 | p=c.p; | ||
| 204 | } | ||
| 205 | } | ||
| 206 | else | ||
| 207 | { | ||
| 208 | if (len != 0) | ||
| 209 | { | ||
| 210 | if ((ret->length < len) || (ret->data == NULL)) | ||
| 211 | { | ||
| 212 | if (ret->data != NULL) OPENSSL_free(ret->data); | ||
| 213 | s=(unsigned char *)OPENSSL_malloc((int)len + 1); | ||
| 214 | if (s == NULL) | ||
| 215 | { | ||
| 216 | i=ERR_R_MALLOC_FAILURE; | ||
| 217 | goto err; | ||
| 218 | } | ||
| 219 | } | ||
| 220 | else | ||
| 221 | s=ret->data; | ||
| 222 | memcpy(s,p,(int)len); | ||
| 223 | s[len] = '\0'; | ||
| 224 | p+=len; | ||
| 225 | } | ||
| 226 | else | ||
| 227 | { | ||
| 228 | s=NULL; | ||
| 229 | if (ret->data != NULL) OPENSSL_free(ret->data); | ||
| 230 | } | ||
| 231 | |||
| 232 | ret->length=(int)len; | ||
| 233 | ret->data=s; | ||
| 234 | ret->type=Ptag; | ||
| 235 | } | ||
| 236 | |||
| 237 | if (a != NULL) (*a)=ret; | ||
| 238 | *pp=p; | ||
| 239 | return(ret); | ||
| 240 | err: | ||
| 241 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) | ||
| 242 | ASN1_STRING_free(ret); | ||
| 243 | ASN1err(ASN1_F_D2I_ASN1_BYTES,i); | ||
| 244 | return(NULL); | ||
| 245 | } | ||
| 246 | |||
| 247 | |||
| 248 | /* We are about to parse 0..n d2i_ASN1_bytes objects, we are to collapse | ||
| 249 | * them into the one structure that is then returned */ | ||
| 250 | /* There have been a few bug fixes for this function from | ||
| 251 | * Paul Keogh <paul.keogh@sse.ie>, many thanks to him */ | ||
| 252 | static int asn1_collate_primitive(ASN1_STRING *a, ASN1_const_CTX *c) | ||
| 253 | { | ||
| 254 | ASN1_STRING *os=NULL; | ||
| 255 | BUF_MEM b; | ||
| 256 | int num; | ||
| 257 | |||
| 258 | b.length=0; | ||
| 259 | b.max=0; | ||
| 260 | b.data=NULL; | ||
| 261 | |||
| 262 | if (a == NULL) | ||
| 263 | { | ||
| 264 | c->error=ERR_R_PASSED_NULL_PARAMETER; | ||
| 265 | goto err; | ||
| 266 | } | ||
| 267 | |||
| 268 | num=0; | ||
| 269 | for (;;) | ||
| 270 | { | ||
| 271 | if (c->inf & 1) | ||
| 272 | { | ||
| 273 | c->eos=ASN1_const_check_infinite_end(&c->p, | ||
| 274 | (long)(c->max-c->p)); | ||
| 275 | if (c->eos) break; | ||
| 276 | } | ||
| 277 | else | ||
| 278 | { | ||
| 279 | if (c->slen <= 0) break; | ||
| 280 | } | ||
| 281 | |||
| 282 | c->q=c->p; | ||
| 283 | if (d2i_ASN1_bytes(&os,&c->p,c->max-c->p,c->tag,c->xclass) | ||
| 284 | == NULL) | ||
| 285 | { | ||
| 286 | c->error=ERR_R_ASN1_LIB; | ||
| 287 | goto err; | ||
| 288 | } | ||
| 289 | |||
| 290 | if (!BUF_MEM_grow_clean(&b,num+os->length)) | ||
| 291 | { | ||
| 292 | c->error=ERR_R_BUF_LIB; | ||
| 293 | goto err; | ||
| 294 | } | ||
| 295 | memcpy(&(b.data[num]),os->data,os->length); | ||
| 296 | if (!(c->inf & 1)) | ||
| 297 | c->slen-=(c->p-c->q); | ||
| 298 | num+=os->length; | ||
| 299 | } | ||
| 300 | |||
| 301 | if (!asn1_const_Finish(c)) goto err; | ||
| 302 | |||
| 303 | a->length=num; | ||
| 304 | if (a->data != NULL) OPENSSL_free(a->data); | ||
| 305 | a->data=(unsigned char *)b.data; | ||
| 306 | if (os != NULL) ASN1_STRING_free(os); | ||
| 307 | return(1); | ||
| 308 | err: | ||
| 309 | ASN1err(ASN1_F_ASN1_COLLATE_PRIMITIVE,c->error); | ||
| 310 | if (os != NULL) ASN1_STRING_free(os); | ||
| 311 | if (b.data != NULL) OPENSSL_free(b.data); | ||
| 312 | return(0); | ||
| 313 | } | ||
| 314 | |||
diff --git a/src/lib/libcrypto/asn1/a_d2i_fp.c b/src/lib/libcrypto/asn1/a_d2i_fp.c new file mode 100644 index 0000000000..ece40bc4c0 --- /dev/null +++ b/src/lib/libcrypto/asn1/a_d2i_fp.c | |||
| @@ -0,0 +1,260 @@ | |||
| 1 | /* crypto/asn1/a_d2i_fp.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/buffer.h> | ||
| 62 | #include <openssl/asn1_mac.h> | ||
| 63 | |||
| 64 | static int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb); | ||
| 65 | |||
| 66 | #ifndef NO_OLD_ASN1 | ||
| 67 | #ifndef OPENSSL_NO_FP_API | ||
| 68 | |||
| 69 | void *ASN1_d2i_fp(void *(*xnew)(void), d2i_of_void *d2i, FILE *in, void **x) | ||
| 70 | { | ||
| 71 | BIO *b; | ||
| 72 | void *ret; | ||
| 73 | |||
| 74 | if ((b=BIO_new(BIO_s_file())) == NULL) | ||
| 75 | { | ||
| 76 | ASN1err(ASN1_F_ASN1_D2I_FP,ERR_R_BUF_LIB); | ||
| 77 | return(NULL); | ||
| 78 | } | ||
| 79 | BIO_set_fp(b,in,BIO_NOCLOSE); | ||
| 80 | ret=ASN1_d2i_bio(xnew,d2i,b,x); | ||
| 81 | BIO_free(b); | ||
| 82 | return(ret); | ||
| 83 | } | ||
| 84 | #endif | ||
| 85 | |||
| 86 | void *ASN1_d2i_bio(void *(*xnew)(void), d2i_of_void *d2i, BIO *in, void **x) | ||
| 87 | { | ||
| 88 | BUF_MEM *b = NULL; | ||
| 89 | const unsigned char *p; | ||
| 90 | void *ret=NULL; | ||
| 91 | int len; | ||
| 92 | |||
| 93 | len = asn1_d2i_read_bio(in, &b); | ||
| 94 | if(len < 0) goto err; | ||
| 95 | |||
| 96 | p=(unsigned char *)b->data; | ||
| 97 | ret=d2i(x,&p,len); | ||
| 98 | err: | ||
| 99 | if (b != NULL) BUF_MEM_free(b); | ||
| 100 | return(ret); | ||
| 101 | } | ||
| 102 | |||
| 103 | #endif | ||
| 104 | |||
| 105 | void *ASN1_item_d2i_bio(const ASN1_ITEM *it, BIO *in, void *x) | ||
| 106 | { | ||
| 107 | BUF_MEM *b = NULL; | ||
| 108 | const unsigned char *p; | ||
| 109 | void *ret=NULL; | ||
| 110 | int len; | ||
| 111 | |||
| 112 | len = asn1_d2i_read_bio(in, &b); | ||
| 113 | if(len < 0) goto err; | ||
| 114 | |||
| 115 | p=(const unsigned char *)b->data; | ||
| 116 | ret=ASN1_item_d2i(x,&p,len, it); | ||
| 117 | err: | ||
| 118 | if (b != NULL) BUF_MEM_free(b); | ||
| 119 | return(ret); | ||
| 120 | } | ||
| 121 | |||
| 122 | #ifndef OPENSSL_NO_FP_API | ||
| 123 | void *ASN1_item_d2i_fp(const ASN1_ITEM *it, FILE *in, void *x) | ||
| 124 | { | ||
| 125 | BIO *b; | ||
| 126 | char *ret; | ||
| 127 | |||
| 128 | if ((b=BIO_new(BIO_s_file())) == NULL) | ||
| 129 | { | ||
| 130 | ASN1err(ASN1_F_ASN1_ITEM_D2I_FP,ERR_R_BUF_LIB); | ||
| 131 | return(NULL); | ||
| 132 | } | ||
| 133 | BIO_set_fp(b,in,BIO_NOCLOSE); | ||
| 134 | ret=ASN1_item_d2i_bio(it,b,x); | ||
| 135 | BIO_free(b); | ||
| 136 | return(ret); | ||
| 137 | } | ||
| 138 | #endif | ||
| 139 | |||
| 140 | #define HEADER_SIZE 8 | ||
| 141 | static int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb) | ||
| 142 | { | ||
| 143 | BUF_MEM *b; | ||
| 144 | unsigned char *p; | ||
| 145 | int i; | ||
| 146 | int ret=-1; | ||
| 147 | ASN1_const_CTX c; | ||
| 148 | int want=HEADER_SIZE; | ||
| 149 | int eos=0; | ||
| 150 | #if defined(__GNUC__) && defined(__ia64) | ||
| 151 | /* pathetic compiler bug in all known versions as of Nov. 2002 */ | ||
| 152 | long off=0; | ||
| 153 | #else | ||
| 154 | int off=0; | ||
| 155 | #endif | ||
| 156 | int len=0; | ||
| 157 | |||
| 158 | b=BUF_MEM_new(); | ||
| 159 | if (b == NULL) | ||
| 160 | { | ||
| 161 | ASN1err(ASN1_F_ASN1_D2I_READ_BIO,ERR_R_MALLOC_FAILURE); | ||
| 162 | return -1; | ||
| 163 | } | ||
| 164 | |||
| 165 | ERR_clear_error(); | ||
| 166 | for (;;) | ||
| 167 | { | ||
| 168 | if (want >= (len-off)) | ||
| 169 | { | ||
| 170 | want-=(len-off); | ||
| 171 | |||
| 172 | if (!BUF_MEM_grow_clean(b,len+want)) | ||
| 173 | { | ||
| 174 | ASN1err(ASN1_F_ASN1_D2I_READ_BIO,ERR_R_MALLOC_FAILURE); | ||
| 175 | goto err; | ||
| 176 | } | ||
| 177 | i=BIO_read(in,&(b->data[len]),want); | ||
| 178 | if ((i < 0) && ((len-off) == 0)) | ||
| 179 | { | ||
| 180 | ASN1err(ASN1_F_ASN1_D2I_READ_BIO,ASN1_R_NOT_ENOUGH_DATA); | ||
| 181 | goto err; | ||
| 182 | } | ||
| 183 | if (i > 0) | ||
| 184 | len+=i; | ||
| 185 | } | ||
| 186 | /* else data already loaded */ | ||
| 187 | |||
| 188 | p=(unsigned char *)&(b->data[off]); | ||
| 189 | c.p=p; | ||
| 190 | c.inf=ASN1_get_object(&(c.p),&(c.slen),&(c.tag),&(c.xclass), | ||
| 191 | len-off); | ||
| 192 | if (c.inf & 0x80) | ||
| 193 | { | ||
| 194 | unsigned long e; | ||
| 195 | |||
| 196 | e=ERR_GET_REASON(ERR_peek_error()); | ||
| 197 | if (e != ASN1_R_TOO_LONG) | ||
| 198 | goto err; | ||
| 199 | else | ||
| 200 | ERR_clear_error(); /* clear error */ | ||
| 201 | } | ||
| 202 | i=c.p-p;/* header length */ | ||
| 203 | off+=i; /* end of data */ | ||
| 204 | |||
| 205 | if (c.inf & 1) | ||
| 206 | { | ||
| 207 | /* no data body so go round again */ | ||
| 208 | eos++; | ||
| 209 | want=HEADER_SIZE; | ||
| 210 | } | ||
| 211 | else if (eos && (c.slen == 0) && (c.tag == V_ASN1_EOC)) | ||
| 212 | { | ||
| 213 | /* eos value, so go back and read another header */ | ||
| 214 | eos--; | ||
| 215 | if (eos <= 0) | ||
| 216 | break; | ||
| 217 | else | ||
| 218 | want=HEADER_SIZE; | ||
| 219 | } | ||
| 220 | else | ||
| 221 | { | ||
| 222 | /* suck in c.slen bytes of data */ | ||
| 223 | want=(int)c.slen; | ||
| 224 | if (want > (len-off)) | ||
| 225 | { | ||
| 226 | want-=(len-off); | ||
| 227 | if (!BUF_MEM_grow_clean(b,len+want)) | ||
| 228 | { | ||
| 229 | ASN1err(ASN1_F_ASN1_D2I_READ_BIO,ERR_R_MALLOC_FAILURE); | ||
| 230 | goto err; | ||
| 231 | } | ||
| 232 | while (want > 0) | ||
| 233 | { | ||
| 234 | i=BIO_read(in,&(b->data[len]),want); | ||
| 235 | if (i <= 0) | ||
| 236 | { | ||
| 237 | ASN1err(ASN1_F_ASN1_D2I_READ_BIO, | ||
| 238 | ASN1_R_NOT_ENOUGH_DATA); | ||
| 239 | goto err; | ||
| 240 | } | ||
| 241 | len+=i; | ||
| 242 | want -= i; | ||
| 243 | } | ||
| 244 | } | ||
| 245 | off+=(int)c.slen; | ||
| 246 | if (eos <= 0) | ||
| 247 | { | ||
| 248 | break; | ||
| 249 | } | ||
| 250 | else | ||
| 251 | want=HEADER_SIZE; | ||
| 252 | } | ||
| 253 | } | ||
| 254 | |||
| 255 | *pb = b; | ||
| 256 | return off; | ||
| 257 | err: | ||
| 258 | if (b != NULL) BUF_MEM_free(b); | ||
| 259 | return(ret); | ||
| 260 | } | ||
diff --git a/src/lib/libcrypto/asn1/a_digest.c b/src/lib/libcrypto/asn1/a_digest.c new file mode 100644 index 0000000000..d00d9e22b1 --- /dev/null +++ b/src/lib/libcrypto/asn1/a_digest.c | |||
| @@ -0,0 +1,111 @@ | |||
| 1 | /* crypto/asn1/a_digest.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include <time.h> | ||
| 61 | |||
| 62 | #include "cryptlib.h" | ||
| 63 | |||
| 64 | #ifndef NO_SYS_TYPES_H | ||
| 65 | # include <sys/types.h> | ||
| 66 | #endif | ||
| 67 | |||
| 68 | #include <openssl/err.h> | ||
| 69 | #include <openssl/evp.h> | ||
| 70 | #include <openssl/buffer.h> | ||
| 71 | #include <openssl/x509.h> | ||
| 72 | |||
| 73 | #ifndef NO_ASN1_OLD | ||
| 74 | |||
| 75 | int ASN1_digest(i2d_of_void *i2d, const EVP_MD *type, char *data, | ||
| 76 | unsigned char *md, unsigned int *len) | ||
| 77 | { | ||
| 78 | int i; | ||
| 79 | unsigned char *str,*p; | ||
| 80 | |||
| 81 | i=i2d(data,NULL); | ||
| 82 | if ((str=(unsigned char *)OPENSSL_malloc(i)) == NULL) | ||
| 83 | { | ||
| 84 | ASN1err(ASN1_F_ASN1_DIGEST,ERR_R_MALLOC_FAILURE); | ||
| 85 | return(0); | ||
| 86 | } | ||
| 87 | p=str; | ||
| 88 | i2d(data,&p); | ||
| 89 | |||
| 90 | EVP_Digest(str, i, md, len, type, NULL); | ||
| 91 | OPENSSL_free(str); | ||
| 92 | return(1); | ||
| 93 | } | ||
| 94 | |||
| 95 | #endif | ||
| 96 | |||
| 97 | |||
| 98 | int ASN1_item_digest(const ASN1_ITEM *it, const EVP_MD *type, void *asn, | ||
| 99 | unsigned char *md, unsigned int *len) | ||
| 100 | { | ||
| 101 | int i; | ||
| 102 | unsigned char *str = NULL; | ||
| 103 | |||
| 104 | i=ASN1_item_i2d(asn,&str, it); | ||
| 105 | if (!str) return(0); | ||
| 106 | |||
| 107 | EVP_Digest(str, i, md, len, type, NULL); | ||
| 108 | OPENSSL_free(str); | ||
| 109 | return(1); | ||
| 110 | } | ||
| 111 | |||
diff --git a/src/lib/libcrypto/asn1/a_dup.c b/src/lib/libcrypto/asn1/a_dup.c new file mode 100644 index 0000000000..199d50f521 --- /dev/null +++ b/src/lib/libcrypto/asn1/a_dup.c | |||
| @@ -0,0 +1,109 @@ | |||
| 1 | /* crypto/asn1/a_dup.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/asn1.h> | ||
| 62 | |||
| 63 | #ifndef NO_OLD_ASN1 | ||
| 64 | |||
| 65 | void *ASN1_dup(i2d_of_void *i2d, d2i_of_void *d2i, char *x) | ||
| 66 | { | ||
| 67 | unsigned char *b,*p; | ||
| 68 | const unsigned char *p2; | ||
| 69 | int i; | ||
| 70 | char *ret; | ||
| 71 | |||
| 72 | if (x == NULL) return(NULL); | ||
| 73 | |||
| 74 | i=i2d(x,NULL); | ||
| 75 | b=OPENSSL_malloc(i+10); | ||
| 76 | if (b == NULL) | ||
| 77 | { ASN1err(ASN1_F_ASN1_DUP,ERR_R_MALLOC_FAILURE); return(NULL); } | ||
| 78 | p= b; | ||
| 79 | i=i2d(x,&p); | ||
| 80 | p2= b; | ||
| 81 | ret=d2i(NULL,&p2,i); | ||
| 82 | OPENSSL_free(b); | ||
| 83 | return(ret); | ||
| 84 | } | ||
| 85 | |||
| 86 | #endif | ||
| 87 | |||
| 88 | /* ASN1_ITEM version of dup: this follows the model above except we don't need | ||
| 89 | * to allocate the buffer. At some point this could be rewritten to directly dup | ||
| 90 | * the underlying structure instead of doing and encode and decode. | ||
| 91 | */ | ||
| 92 | |||
| 93 | void *ASN1_item_dup(const ASN1_ITEM *it, void *x) | ||
| 94 | { | ||
| 95 | unsigned char *b = NULL; | ||
| 96 | const unsigned char *p; | ||
| 97 | long i; | ||
| 98 | void *ret; | ||
| 99 | |||
| 100 | if (x == NULL) return(NULL); | ||
| 101 | |||
| 102 | i=ASN1_item_i2d(x,&b,it); | ||
| 103 | if (b == NULL) | ||
| 104 | { ASN1err(ASN1_F_ASN1_ITEM_DUP,ERR_R_MALLOC_FAILURE); return(NULL); } | ||
| 105 | p= b; | ||
| 106 | ret=ASN1_item_d2i(NULL,&p,i, it); | ||
| 107 | OPENSSL_free(b); | ||
| 108 | return(ret); | ||
| 109 | } | ||
diff --git a/src/lib/libcrypto/asn1/a_enum.c b/src/lib/libcrypto/asn1/a_enum.c new file mode 100644 index 0000000000..fe9aa13b9c --- /dev/null +++ b/src/lib/libcrypto/asn1/a_enum.c | |||
| @@ -0,0 +1,182 @@ | |||
| 1 | /* crypto/asn1/a_enum.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/asn1.h> | ||
| 62 | #include <openssl/bn.h> | ||
| 63 | |||
| 64 | /* | ||
| 65 | * Code for ENUMERATED type: identical to INTEGER apart from a different tag. | ||
| 66 | * for comments on encoding see a_int.c | ||
| 67 | */ | ||
| 68 | |||
| 69 | int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v) | ||
| 70 | { | ||
| 71 | int j,k; | ||
| 72 | unsigned int i; | ||
| 73 | unsigned char buf[sizeof(long)+1]; | ||
| 74 | long d; | ||
| 75 | |||
| 76 | a->type=V_ASN1_ENUMERATED; | ||
| 77 | if (a->length < (int)(sizeof(long)+1)) | ||
| 78 | { | ||
| 79 | if (a->data != NULL) | ||
| 80 | OPENSSL_free(a->data); | ||
| 81 | if ((a->data=(unsigned char *)OPENSSL_malloc(sizeof(long)+1)) != NULL) | ||
| 82 | memset((char *)a->data,0,sizeof(long)+1); | ||
| 83 | } | ||
| 84 | if (a->data == NULL) | ||
| 85 | { | ||
| 86 | ASN1err(ASN1_F_ASN1_ENUMERATED_SET,ERR_R_MALLOC_FAILURE); | ||
| 87 | return(0); | ||
| 88 | } | ||
| 89 | d=v; | ||
| 90 | if (d < 0) | ||
| 91 | { | ||
| 92 | d= -d; | ||
| 93 | a->type=V_ASN1_NEG_ENUMERATED; | ||
| 94 | } | ||
| 95 | |||
| 96 | for (i=0; i<sizeof(long); i++) | ||
| 97 | { | ||
| 98 | if (d == 0) break; | ||
| 99 | buf[i]=(int)d&0xff; | ||
| 100 | d>>=8; | ||
| 101 | } | ||
| 102 | j=0; | ||
| 103 | for (k=i-1; k >=0; k--) | ||
| 104 | a->data[j++]=buf[k]; | ||
| 105 | a->length=j; | ||
| 106 | return(1); | ||
| 107 | } | ||
| 108 | |||
| 109 | long ASN1_ENUMERATED_get(ASN1_ENUMERATED *a) | ||
| 110 | { | ||
| 111 | int neg=0,i; | ||
| 112 | long r=0; | ||
| 113 | |||
| 114 | if (a == NULL) return(0L); | ||
| 115 | i=a->type; | ||
| 116 | if (i == V_ASN1_NEG_ENUMERATED) | ||
| 117 | neg=1; | ||
| 118 | else if (i != V_ASN1_ENUMERATED) | ||
| 119 | return -1; | ||
| 120 | |||
| 121 | if (a->length > (int)sizeof(long)) | ||
| 122 | { | ||
| 123 | /* hmm... a bit ugly */ | ||
| 124 | return(0xffffffffL); | ||
| 125 | } | ||
| 126 | if (a->data == NULL) | ||
| 127 | return 0; | ||
| 128 | |||
| 129 | for (i=0; i<a->length; i++) | ||
| 130 | { | ||
| 131 | r<<=8; | ||
| 132 | r|=(unsigned char)a->data[i]; | ||
| 133 | } | ||
| 134 | if (neg) r= -r; | ||
| 135 | return(r); | ||
| 136 | } | ||
| 137 | |||
| 138 | ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai) | ||
| 139 | { | ||
| 140 | ASN1_ENUMERATED *ret; | ||
| 141 | int len,j; | ||
| 142 | |||
| 143 | if (ai == NULL) | ||
| 144 | ret=M_ASN1_ENUMERATED_new(); | ||
| 145 | else | ||
| 146 | ret=ai; | ||
| 147 | if (ret == NULL) | ||
| 148 | { | ||
| 149 | ASN1err(ASN1_F_BN_TO_ASN1_ENUMERATED,ERR_R_NESTED_ASN1_ERROR); | ||
| 150 | goto err; | ||
| 151 | } | ||
| 152 | if(BN_is_negative(bn)) ret->type = V_ASN1_NEG_ENUMERATED; | ||
| 153 | else ret->type=V_ASN1_ENUMERATED; | ||
| 154 | j=BN_num_bits(bn); | ||
| 155 | len=((j == 0)?0:((j/8)+1)); | ||
| 156 | if (ret->length < len+4) | ||
| 157 | { | ||
| 158 | unsigned char *new_data=OPENSSL_realloc(ret->data, len+4); | ||
| 159 | if (!new_data) | ||
| 160 | { | ||
| 161 | ASN1err(ASN1_F_BN_TO_ASN1_ENUMERATED,ERR_R_MALLOC_FAILURE); | ||
| 162 | goto err; | ||
| 163 | } | ||
| 164 | ret->data=new_data; | ||
| 165 | } | ||
| 166 | |||
| 167 | ret->length=BN_bn2bin(bn,ret->data); | ||
| 168 | return(ret); | ||
| 169 | err: | ||
| 170 | if (ret != ai) M_ASN1_ENUMERATED_free(ret); | ||
| 171 | return(NULL); | ||
| 172 | } | ||
| 173 | |||
| 174 | BIGNUM *ASN1_ENUMERATED_to_BN(ASN1_ENUMERATED *ai, BIGNUM *bn) | ||
| 175 | { | ||
| 176 | BIGNUM *ret; | ||
| 177 | |||
| 178 | if ((ret=BN_bin2bn(ai->data,ai->length,bn)) == NULL) | ||
| 179 | ASN1err(ASN1_F_ASN1_ENUMERATED_TO_BN,ASN1_R_BN_LIB); | ||
| 180 | else if(ai->type == V_ASN1_NEG_ENUMERATED) BN_set_negative(ret,1); | ||
| 181 | return(ret); | ||
| 182 | } | ||
diff --git a/src/lib/libcrypto/asn1/a_gentm.c b/src/lib/libcrypto/asn1/a_gentm.c new file mode 100644 index 0000000000..def79062a5 --- /dev/null +++ b/src/lib/libcrypto/asn1/a_gentm.c | |||
| @@ -0,0 +1,246 @@ | |||
| 1 | /* crypto/asn1/a_gentm.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | /* GENERALIZEDTIME implementation, written by Steve Henson. Based on UTCTIME */ | ||
| 60 | |||
| 61 | #include <stdio.h> | ||
| 62 | #include <time.h> | ||
| 63 | #include "cryptlib.h" | ||
| 64 | #include "o_time.h" | ||
| 65 | #include <openssl/asn1.h> | ||
| 66 | |||
| 67 | #if 0 | ||
| 68 | |||
| 69 | int i2d_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME *a, unsigned char **pp) | ||
| 70 | { | ||
| 71 | #ifdef CHARSET_EBCDIC | ||
| 72 | /* KLUDGE! We convert to ascii before writing DER */ | ||
| 73 | int len; | ||
| 74 | char tmp[24]; | ||
| 75 | ASN1_STRING tmpstr = *(ASN1_STRING *)a; | ||
| 76 | |||
| 77 | len = tmpstr.length; | ||
| 78 | ebcdic2ascii(tmp, tmpstr.data, (len >= sizeof tmp) ? sizeof tmp : len); | ||
| 79 | tmpstr.data = tmp; | ||
| 80 | |||
| 81 | a = (ASN1_GENERALIZEDTIME *) &tmpstr; | ||
| 82 | #endif | ||
| 83 | return(i2d_ASN1_bytes((ASN1_STRING *)a,pp, | ||
| 84 | V_ASN1_GENERALIZEDTIME,V_ASN1_UNIVERSAL)); | ||
| 85 | } | ||
| 86 | |||
| 87 | |||
| 88 | ASN1_GENERALIZEDTIME *d2i_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME **a, | ||
| 89 | unsigned char **pp, long length) | ||
| 90 | { | ||
| 91 | ASN1_GENERALIZEDTIME *ret=NULL; | ||
| 92 | |||
| 93 | ret=(ASN1_GENERALIZEDTIME *)d2i_ASN1_bytes((ASN1_STRING **)a,pp,length, | ||
| 94 | V_ASN1_GENERALIZEDTIME,V_ASN1_UNIVERSAL); | ||
| 95 | if (ret == NULL) | ||
| 96 | { | ||
| 97 | ASN1err(ASN1_F_D2I_ASN1_GENERALIZEDTIME,ERR_R_NESTED_ASN1_ERROR); | ||
| 98 | return(NULL); | ||
| 99 | } | ||
| 100 | #ifdef CHARSET_EBCDIC | ||
| 101 | ascii2ebcdic(ret->data, ret->data, ret->length); | ||
| 102 | #endif | ||
| 103 | if (!ASN1_GENERALIZEDTIME_check(ret)) | ||
| 104 | { | ||
| 105 | ASN1err(ASN1_F_D2I_ASN1_GENERALIZEDTIME,ASN1_R_INVALID_TIME_FORMAT); | ||
| 106 | goto err; | ||
| 107 | } | ||
| 108 | |||
| 109 | return(ret); | ||
| 110 | err: | ||
| 111 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) | ||
| 112 | M_ASN1_GENERALIZEDTIME_free(ret); | ||
| 113 | return(NULL); | ||
| 114 | } | ||
| 115 | |||
| 116 | #endif | ||
| 117 | |||
| 118 | int ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *d) | ||
| 119 | { | ||
| 120 | static int min[9]={ 0, 0, 1, 1, 0, 0, 0, 0, 0}; | ||
| 121 | static int max[9]={99, 99,12,31,23,59,59,12,59}; | ||
| 122 | char *a; | ||
| 123 | int n,i,l,o; | ||
| 124 | |||
| 125 | if (d->type != V_ASN1_GENERALIZEDTIME) return(0); | ||
| 126 | l=d->length; | ||
| 127 | a=(char *)d->data; | ||
| 128 | o=0; | ||
| 129 | /* GENERALIZEDTIME is similar to UTCTIME except the year is | ||
| 130 | * represented as YYYY. This stuff treats everything as a two digit | ||
| 131 | * field so make first two fields 00 to 99 | ||
| 132 | */ | ||
| 133 | if (l < 13) goto err; | ||
| 134 | for (i=0; i<7; i++) | ||
| 135 | { | ||
| 136 | if ((i == 6) && ((a[o] == 'Z') || | ||
| 137 | (a[o] == '+') || (a[o] == '-'))) | ||
| 138 | { i++; break; } | ||
| 139 | if ((a[o] < '0') || (a[o] > '9')) goto err; | ||
| 140 | n= a[o]-'0'; | ||
| 141 | if (++o > l) goto err; | ||
| 142 | |||
| 143 | if ((a[o] < '0') || (a[o] > '9')) goto err; | ||
| 144 | n=(n*10)+ a[o]-'0'; | ||
| 145 | if (++o > l) goto err; | ||
| 146 | |||
| 147 | if ((n < min[i]) || (n > max[i])) goto err; | ||
| 148 | } | ||
| 149 | /* Optional fractional seconds: decimal point followed by one | ||
| 150 | * or more digits. | ||
| 151 | */ | ||
| 152 | if (a[o] == '.') | ||
| 153 | { | ||
| 154 | if (++o > l) goto err; | ||
| 155 | i = o; | ||
| 156 | while ((a[o] >= '0') && (a[o] <= '9') && (o <= l)) | ||
| 157 | o++; | ||
| 158 | /* Must have at least one digit after decimal point */ | ||
| 159 | if (i == o) goto err; | ||
| 160 | } | ||
| 161 | |||
| 162 | if (a[o] == 'Z') | ||
| 163 | o++; | ||
| 164 | else if ((a[o] == '+') || (a[o] == '-')) | ||
| 165 | { | ||
| 166 | o++; | ||
| 167 | if (o+4 > l) goto err; | ||
| 168 | for (i=7; i<9; i++) | ||
| 169 | { | ||
| 170 | if ((a[o] < '0') || (a[o] > '9')) goto err; | ||
| 171 | n= a[o]-'0'; | ||
| 172 | o++; | ||
| 173 | if ((a[o] < '0') || (a[o] > '9')) goto err; | ||
| 174 | n=(n*10)+ a[o]-'0'; | ||
| 175 | if ((n < min[i]) || (n > max[i])) goto err; | ||
| 176 | o++; | ||
| 177 | } | ||
| 178 | } | ||
| 179 | return(o == l); | ||
| 180 | err: | ||
| 181 | return(0); | ||
| 182 | } | ||
| 183 | |||
| 184 | int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, const char *str) | ||
| 185 | { | ||
| 186 | ASN1_GENERALIZEDTIME t; | ||
| 187 | |||
| 188 | t.type=V_ASN1_GENERALIZEDTIME; | ||
| 189 | t.length=strlen(str); | ||
| 190 | t.data=(unsigned char *)str; | ||
| 191 | if (ASN1_GENERALIZEDTIME_check(&t)) | ||
| 192 | { | ||
| 193 | if (s != NULL) | ||
| 194 | { | ||
| 195 | if (!ASN1_STRING_set((ASN1_STRING *)s, | ||
| 196 | (unsigned char *)str,t.length)) | ||
| 197 | return 0; | ||
| 198 | s->type=V_ASN1_GENERALIZEDTIME; | ||
| 199 | } | ||
| 200 | return(1); | ||
| 201 | } | ||
| 202 | else | ||
| 203 | return(0); | ||
| 204 | } | ||
| 205 | |||
| 206 | ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s, | ||
| 207 | time_t t) | ||
| 208 | { | ||
| 209 | char *p; | ||
| 210 | struct tm *ts; | ||
| 211 | struct tm data; | ||
| 212 | size_t len = 20; | ||
| 213 | |||
| 214 | if (s == NULL) | ||
| 215 | s=M_ASN1_GENERALIZEDTIME_new(); | ||
| 216 | if (s == NULL) | ||
| 217 | return(NULL); | ||
| 218 | |||
| 219 | ts=OPENSSL_gmtime(&t, &data); | ||
| 220 | if (ts == NULL) | ||
| 221 | return(NULL); | ||
| 222 | |||
| 223 | p=(char *)s->data; | ||
| 224 | if ((p == NULL) || ((size_t)s->length < len)) | ||
| 225 | { | ||
| 226 | p=OPENSSL_malloc(len); | ||
| 227 | if (p == NULL) | ||
| 228 | { | ||
| 229 | ASN1err(ASN1_F_ASN1_GENERALIZEDTIME_SET, | ||
| 230 | ERR_R_MALLOC_FAILURE); | ||
| 231 | return(NULL); | ||
| 232 | } | ||
| 233 | if (s->data != NULL) | ||
| 234 | OPENSSL_free(s->data); | ||
| 235 | s->data=(unsigned char *)p; | ||
| 236 | } | ||
| 237 | |||
| 238 | BIO_snprintf(p,len,"%04d%02d%02d%02d%02d%02dZ",ts->tm_year + 1900, | ||
| 239 | ts->tm_mon+1,ts->tm_mday,ts->tm_hour,ts->tm_min,ts->tm_sec); | ||
| 240 | s->length=strlen(p); | ||
| 241 | s->type=V_ASN1_GENERALIZEDTIME; | ||
| 242 | #ifdef CHARSET_EBCDIC_not | ||
| 243 | ebcdic2ascii(s->data, s->data, s->length); | ||
| 244 | #endif | ||
| 245 | return(s); | ||
| 246 | } | ||
diff --git a/src/lib/libcrypto/asn1/a_hdr.c b/src/lib/libcrypto/asn1/a_hdr.c new file mode 100644 index 0000000000..d1c2a7b9e3 --- /dev/null +++ b/src/lib/libcrypto/asn1/a_hdr.c | |||
| @@ -0,0 +1,119 @@ | |||
| 1 | /* crypto/asn1/a_hdr.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/asn1_mac.h> | ||
| 62 | #include <openssl/asn1.h> | ||
| 63 | |||
| 64 | int i2d_ASN1_HEADER(ASN1_HEADER *a, unsigned char **pp) | ||
| 65 | { | ||
| 66 | M_ASN1_I2D_vars(a); | ||
| 67 | |||
| 68 | M_ASN1_I2D_len(a->header, i2d_ASN1_OCTET_STRING); | ||
| 69 | M_ASN1_I2D_len(a->data, a->meth->i2d); | ||
| 70 | |||
| 71 | M_ASN1_I2D_seq_total(); | ||
| 72 | |||
| 73 | M_ASN1_I2D_put(a->header, i2d_ASN1_OCTET_STRING); | ||
| 74 | M_ASN1_I2D_put(a->data, a->meth->i2d); | ||
| 75 | |||
| 76 | M_ASN1_I2D_finish(); | ||
| 77 | } | ||
| 78 | |||
| 79 | ASN1_HEADER *d2i_ASN1_HEADER(ASN1_HEADER **a, const unsigned char **pp, | ||
| 80 | long length) | ||
| 81 | { | ||
| 82 | M_ASN1_D2I_vars(a,ASN1_HEADER *,ASN1_HEADER_new); | ||
| 83 | |||
| 84 | M_ASN1_D2I_Init(); | ||
| 85 | M_ASN1_D2I_start_sequence(); | ||
| 86 | M_ASN1_D2I_get_x(ASN1_OCTET_STRING,ret->header,d2i_ASN1_OCTET_STRING); | ||
| 87 | if (ret->meth != NULL) | ||
| 88 | { | ||
| 89 | M_ASN1_D2I_get_x(void,ret->data,ret->meth->d2i); | ||
| 90 | } | ||
| 91 | else | ||
| 92 | { | ||
| 93 | if (a != NULL) (*a)=ret; | ||
| 94 | return(ret); | ||
| 95 | } | ||
| 96 | M_ASN1_D2I_Finish(a,ASN1_HEADER_free,ASN1_F_D2I_ASN1_HEADER); | ||
| 97 | } | ||
| 98 | |||
| 99 | ASN1_HEADER *ASN1_HEADER_new(void) | ||
| 100 | { | ||
| 101 | ASN1_HEADER *ret=NULL; | ||
| 102 | ASN1_CTX c; | ||
| 103 | |||
| 104 | M_ASN1_New_Malloc(ret,ASN1_HEADER); | ||
| 105 | M_ASN1_New(ret->header,M_ASN1_OCTET_STRING_new); | ||
| 106 | ret->meth=NULL; | ||
| 107 | ret->data=NULL; | ||
| 108 | return(ret); | ||
| 109 | M_ASN1_New_Error(ASN1_F_ASN1_HEADER_NEW); | ||
| 110 | } | ||
| 111 | |||
| 112 | void ASN1_HEADER_free(ASN1_HEADER *a) | ||
| 113 | { | ||
| 114 | if (a == NULL) return; | ||
| 115 | M_ASN1_OCTET_STRING_free(a->header); | ||
| 116 | if (a->meth != NULL) | ||
| 117 | a->meth->destroy(a->data); | ||
| 118 | OPENSSL_free(a); | ||
| 119 | } | ||
diff --git a/src/lib/libcrypto/asn1/a_i2d_fp.c b/src/lib/libcrypto/asn1/a_i2d_fp.c new file mode 100644 index 0000000000..a3ad76d356 --- /dev/null +++ b/src/lib/libcrypto/asn1/a_i2d_fp.c | |||
| @@ -0,0 +1,163 @@ | |||
| 1 | /* crypto/asn1/a_i2d_fp.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/buffer.h> | ||
| 62 | #include <openssl/asn1.h> | ||
| 63 | |||
| 64 | #ifndef NO_OLD_ASN1 | ||
| 65 | |||
| 66 | #ifndef OPENSSL_NO_FP_API | ||
| 67 | int ASN1_i2d_fp(i2d_of_void *i2d, FILE *out, void *x) | ||
| 68 | { | ||
| 69 | BIO *b; | ||
| 70 | int ret; | ||
| 71 | |||
| 72 | if ((b=BIO_new(BIO_s_file())) == NULL) | ||
| 73 | { | ||
| 74 | ASN1err(ASN1_F_ASN1_I2D_FP,ERR_R_BUF_LIB); | ||
| 75 | return(0); | ||
| 76 | } | ||
| 77 | BIO_set_fp(b,out,BIO_NOCLOSE); | ||
| 78 | ret=ASN1_i2d_bio(i2d,b,x); | ||
| 79 | BIO_free(b); | ||
| 80 | return(ret); | ||
| 81 | } | ||
| 82 | #endif | ||
| 83 | |||
| 84 | int ASN1_i2d_bio(i2d_of_void *i2d, BIO *out, unsigned char *x) | ||
| 85 | { | ||
| 86 | char *b; | ||
| 87 | unsigned char *p; | ||
| 88 | int i,j=0,n,ret=1; | ||
| 89 | |||
| 90 | n=i2d(x,NULL); | ||
| 91 | b=(char *)OPENSSL_malloc(n); | ||
| 92 | if (b == NULL) | ||
| 93 | { | ||
| 94 | ASN1err(ASN1_F_ASN1_I2D_BIO,ERR_R_MALLOC_FAILURE); | ||
| 95 | return(0); | ||
| 96 | } | ||
| 97 | |||
| 98 | p=(unsigned char *)b; | ||
| 99 | i2d(x,&p); | ||
| 100 | |||
| 101 | for (;;) | ||
| 102 | { | ||
| 103 | i=BIO_write(out,&(b[j]),n); | ||
| 104 | if (i == n) break; | ||
| 105 | if (i <= 0) | ||
| 106 | { | ||
| 107 | ret=0; | ||
| 108 | break; | ||
| 109 | } | ||
| 110 | j+=i; | ||
| 111 | n-=i; | ||
| 112 | } | ||
| 113 | OPENSSL_free(b); | ||
| 114 | return(ret); | ||
| 115 | } | ||
| 116 | |||
| 117 | #endif | ||
| 118 | |||
| 119 | #ifndef OPENSSL_NO_FP_API | ||
| 120 | int ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out, void *x) | ||
| 121 | { | ||
| 122 | BIO *b; | ||
| 123 | int ret; | ||
| 124 | |||
| 125 | if ((b=BIO_new(BIO_s_file())) == NULL) | ||
| 126 | { | ||
| 127 | ASN1err(ASN1_F_ASN1_ITEM_I2D_FP,ERR_R_BUF_LIB); | ||
| 128 | return(0); | ||
| 129 | } | ||
| 130 | BIO_set_fp(b,out,BIO_NOCLOSE); | ||
| 131 | ret=ASN1_item_i2d_bio(it,b,x); | ||
| 132 | BIO_free(b); | ||
| 133 | return(ret); | ||
| 134 | } | ||
| 135 | #endif | ||
| 136 | |||
| 137 | int ASN1_item_i2d_bio(const ASN1_ITEM *it, BIO *out, void *x) | ||
| 138 | { | ||
| 139 | unsigned char *b = NULL; | ||
| 140 | int i,j=0,n,ret=1; | ||
| 141 | |||
| 142 | n = ASN1_item_i2d(x, &b, it); | ||
| 143 | if (b == NULL) | ||
| 144 | { | ||
| 145 | ASN1err(ASN1_F_ASN1_ITEM_I2D_BIO,ERR_R_MALLOC_FAILURE); | ||
| 146 | return(0); | ||
| 147 | } | ||
| 148 | |||
| 149 | for (;;) | ||
| 150 | { | ||
| 151 | i=BIO_write(out,&(b[j]),n); | ||
| 152 | if (i == n) break; | ||
| 153 | if (i <= 0) | ||
| 154 | { | ||
| 155 | ret=0; | ||
| 156 | break; | ||
| 157 | } | ||
| 158 | j+=i; | ||
| 159 | n-=i; | ||
| 160 | } | ||
| 161 | OPENSSL_free(b); | ||
| 162 | return(ret); | ||
| 163 | } | ||
diff --git a/src/lib/libcrypto/asn1/a_int.c b/src/lib/libcrypto/asn1/a_int.c new file mode 100644 index 0000000000..f8d198efb1 --- /dev/null +++ b/src/lib/libcrypto/asn1/a_int.c | |||
| @@ -0,0 +1,459 @@ | |||
| 1 | /* crypto/asn1/a_int.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/asn1.h> | ||
| 62 | #include <openssl/bn.h> | ||
| 63 | |||
| 64 | ASN1_INTEGER *ASN1_INTEGER_dup(ASN1_INTEGER *x) | ||
| 65 | { return M_ASN1_INTEGER_dup(x);} | ||
| 66 | |||
| 67 | int ASN1_INTEGER_cmp(ASN1_INTEGER *x, ASN1_INTEGER *y) | ||
| 68 | { | ||
| 69 | int neg, ret; | ||
| 70 | /* Compare signs */ | ||
| 71 | neg = x->type & V_ASN1_NEG; | ||
| 72 | if (neg != (y->type & V_ASN1_NEG)) | ||
| 73 | { | ||
| 74 | if (neg) | ||
| 75 | return -1; | ||
| 76 | else | ||
| 77 | return 1; | ||
| 78 | } | ||
| 79 | |||
| 80 | ret = ASN1_STRING_cmp(x, y); | ||
| 81 | |||
| 82 | if (neg) | ||
| 83 | return -ret; | ||
| 84 | else | ||
| 85 | return ret; | ||
| 86 | } | ||
| 87 | |||
| 88 | |||
| 89 | /* | ||
| 90 | * This converts an ASN1 INTEGER into its content encoding. | ||
| 91 | * The internal representation is an ASN1_STRING whose data is a big endian | ||
| 92 | * representation of the value, ignoring the sign. The sign is determined by | ||
| 93 | * the type: V_ASN1_INTEGER for positive and V_ASN1_NEG_INTEGER for negative. | ||
| 94 | * | ||
| 95 | * Positive integers are no problem: they are almost the same as the DER | ||
| 96 | * encoding, except if the first byte is >= 0x80 we need to add a zero pad. | ||
| 97 | * | ||
| 98 | * Negative integers are a bit trickier... | ||
| 99 | * The DER representation of negative integers is in 2s complement form. | ||
| 100 | * The internal form is converted by complementing each octet and finally | ||
| 101 | * adding one to the result. This can be done less messily with a little trick. | ||
| 102 | * If the internal form has trailing zeroes then they will become FF by the | ||
| 103 | * complement and 0 by the add one (due to carry) so just copy as many trailing | ||
| 104 | * zeros to the destination as there are in the source. The carry will add one | ||
| 105 | * to the last none zero octet: so complement this octet and add one and finally | ||
| 106 | * complement any left over until you get to the start of the string. | ||
| 107 | * | ||
| 108 | * Padding is a little trickier too. If the first bytes is > 0x80 then we pad | ||
| 109 | * with 0xff. However if the first byte is 0x80 and one of the following bytes | ||
| 110 | * is non-zero we pad with 0xff. The reason for this distinction is that 0x80 | ||
| 111 | * followed by optional zeros isn't padded. | ||
| 112 | */ | ||
| 113 | |||
| 114 | int i2c_ASN1_INTEGER(ASN1_INTEGER *a, unsigned char **pp) | ||
| 115 | { | ||
| 116 | int pad=0,ret,i,neg; | ||
| 117 | unsigned char *p,*n,pb=0; | ||
| 118 | |||
| 119 | if ((a == NULL) || (a->data == NULL)) return(0); | ||
| 120 | neg=a->type & V_ASN1_NEG; | ||
| 121 | if (a->length == 0) | ||
| 122 | ret=1; | ||
| 123 | else | ||
| 124 | { | ||
| 125 | ret=a->length; | ||
| 126 | i=a->data[0]; | ||
| 127 | if (!neg && (i > 127)) { | ||
| 128 | pad=1; | ||
| 129 | pb=0; | ||
| 130 | } else if(neg) { | ||
| 131 | if(i>128) { | ||
| 132 | pad=1; | ||
| 133 | pb=0xFF; | ||
| 134 | } else if(i == 128) { | ||
| 135 | /* | ||
| 136 | * Special case: if any other bytes non zero we pad: | ||
| 137 | * otherwise we don't. | ||
| 138 | */ | ||
| 139 | for(i = 1; i < a->length; i++) if(a->data[i]) { | ||
| 140 | pad=1; | ||
| 141 | pb=0xFF; | ||
| 142 | break; | ||
| 143 | } | ||
| 144 | } | ||
| 145 | } | ||
| 146 | ret+=pad; | ||
| 147 | } | ||
| 148 | if (pp == NULL) return(ret); | ||
| 149 | p= *pp; | ||
| 150 | |||
| 151 | if (pad) *(p++)=pb; | ||
| 152 | if (a->length == 0) *(p++)=0; | ||
| 153 | else if (!neg) memcpy(p,a->data,(unsigned int)a->length); | ||
| 154 | else { | ||
| 155 | /* Begin at the end of the encoding */ | ||
| 156 | n=a->data + a->length - 1; | ||
| 157 | p += a->length - 1; | ||
| 158 | i = a->length; | ||
| 159 | /* Copy zeros to destination as long as source is zero */ | ||
| 160 | while(!*n) { | ||
| 161 | *(p--) = 0; | ||
| 162 | n--; | ||
| 163 | i--; | ||
| 164 | } | ||
| 165 | /* Complement and increment next octet */ | ||
| 166 | *(p--) = ((*(n--)) ^ 0xff) + 1; | ||
| 167 | i--; | ||
| 168 | /* Complement any octets left */ | ||
| 169 | for(;i > 0; i--) *(p--) = *(n--) ^ 0xff; | ||
| 170 | } | ||
| 171 | |||
| 172 | *pp+=ret; | ||
| 173 | return(ret); | ||
| 174 | } | ||
| 175 | |||
| 176 | /* Convert just ASN1 INTEGER content octets to ASN1_INTEGER structure */ | ||
| 177 | |||
| 178 | ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **a, const unsigned char **pp, | ||
| 179 | long len) | ||
| 180 | { | ||
| 181 | ASN1_INTEGER *ret=NULL; | ||
| 182 | const unsigned char *p, *pend; | ||
| 183 | unsigned char *to,*s; | ||
| 184 | int i; | ||
| 185 | |||
| 186 | if ((a == NULL) || ((*a) == NULL)) | ||
| 187 | { | ||
| 188 | if ((ret=M_ASN1_INTEGER_new()) == NULL) return(NULL); | ||
| 189 | ret->type=V_ASN1_INTEGER; | ||
| 190 | } | ||
| 191 | else | ||
| 192 | ret=(*a); | ||
| 193 | |||
| 194 | p= *pp; | ||
| 195 | pend = p + len; | ||
| 196 | |||
| 197 | /* We must OPENSSL_malloc stuff, even for 0 bytes otherwise it | ||
| 198 | * signifies a missing NULL parameter. */ | ||
| 199 | s=(unsigned char *)OPENSSL_malloc((int)len+1); | ||
| 200 | if (s == NULL) | ||
| 201 | { | ||
| 202 | i=ERR_R_MALLOC_FAILURE; | ||
| 203 | goto err; | ||
| 204 | } | ||
| 205 | to=s; | ||
| 206 | if(!len) { | ||
| 207 | /* Strictly speaking this is an illegal INTEGER but we | ||
| 208 | * tolerate it. | ||
| 209 | */ | ||
| 210 | ret->type=V_ASN1_INTEGER; | ||
| 211 | } else if (*p & 0x80) /* a negative number */ | ||
| 212 | { | ||
| 213 | ret->type=V_ASN1_NEG_INTEGER; | ||
| 214 | if ((*p == 0xff) && (len != 1)) { | ||
| 215 | p++; | ||
| 216 | len--; | ||
| 217 | } | ||
| 218 | i = len; | ||
| 219 | p += i - 1; | ||
| 220 | to += i - 1; | ||
| 221 | while((!*p) && i) { | ||
| 222 | *(to--) = 0; | ||
| 223 | i--; | ||
| 224 | p--; | ||
| 225 | } | ||
| 226 | /* Special case: if all zeros then the number will be of | ||
| 227 | * the form FF followed by n zero bytes: this corresponds to | ||
| 228 | * 1 followed by n zero bytes. We've already written n zeros | ||
| 229 | * so we just append an extra one and set the first byte to | ||
| 230 | * a 1. This is treated separately because it is the only case | ||
| 231 | * where the number of bytes is larger than len. | ||
| 232 | */ | ||
| 233 | if(!i) { | ||
| 234 | *s = 1; | ||
| 235 | s[len] = 0; | ||
| 236 | len++; | ||
| 237 | } else { | ||
| 238 | *(to--) = (*(p--) ^ 0xff) + 1; | ||
| 239 | i--; | ||
| 240 | for(;i > 0; i--) *(to--) = *(p--) ^ 0xff; | ||
| 241 | } | ||
| 242 | } else { | ||
| 243 | ret->type=V_ASN1_INTEGER; | ||
| 244 | if ((*p == 0) && (len != 1)) | ||
| 245 | { | ||
| 246 | p++; | ||
| 247 | len--; | ||
| 248 | } | ||
| 249 | memcpy(s,p,(int)len); | ||
| 250 | } | ||
| 251 | |||
| 252 | if (ret->data != NULL) OPENSSL_free(ret->data); | ||
| 253 | ret->data=s; | ||
| 254 | ret->length=(int)len; | ||
| 255 | if (a != NULL) (*a)=ret; | ||
| 256 | *pp=pend; | ||
| 257 | return(ret); | ||
| 258 | err: | ||
| 259 | ASN1err(ASN1_F_C2I_ASN1_INTEGER,i); | ||
| 260 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) | ||
| 261 | M_ASN1_INTEGER_free(ret); | ||
| 262 | return(NULL); | ||
| 263 | } | ||
| 264 | |||
| 265 | |||
| 266 | /* This is a version of d2i_ASN1_INTEGER that ignores the sign bit of | ||
| 267 | * ASN1 integers: some broken software can encode a positive INTEGER | ||
| 268 | * with its MSB set as negative (it doesn't add a padding zero). | ||
| 269 | */ | ||
| 270 | |||
| 271 | ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a, const unsigned char **pp, | ||
| 272 | long length) | ||
| 273 | { | ||
| 274 | ASN1_INTEGER *ret=NULL; | ||
| 275 | const unsigned char *p; | ||
| 276 | unsigned char *to,*s; | ||
| 277 | long len; | ||
| 278 | int inf,tag,xclass; | ||
| 279 | int i; | ||
| 280 | |||
| 281 | if ((a == NULL) || ((*a) == NULL)) | ||
| 282 | { | ||
| 283 | if ((ret=M_ASN1_INTEGER_new()) == NULL) return(NULL); | ||
| 284 | ret->type=V_ASN1_INTEGER; | ||
| 285 | } | ||
| 286 | else | ||
| 287 | ret=(*a); | ||
| 288 | |||
| 289 | p= *pp; | ||
| 290 | inf=ASN1_get_object(&p,&len,&tag,&xclass,length); | ||
| 291 | if (inf & 0x80) | ||
| 292 | { | ||
| 293 | i=ASN1_R_BAD_OBJECT_HEADER; | ||
| 294 | goto err; | ||
| 295 | } | ||
| 296 | |||
| 297 | if (tag != V_ASN1_INTEGER) | ||
| 298 | { | ||
| 299 | i=ASN1_R_EXPECTING_AN_INTEGER; | ||
| 300 | goto err; | ||
| 301 | } | ||
| 302 | |||
| 303 | /* We must OPENSSL_malloc stuff, even for 0 bytes otherwise it | ||
| 304 | * signifies a missing NULL parameter. */ | ||
| 305 | s=(unsigned char *)OPENSSL_malloc((int)len+1); | ||
| 306 | if (s == NULL) | ||
| 307 | { | ||
| 308 | i=ERR_R_MALLOC_FAILURE; | ||
| 309 | goto err; | ||
| 310 | } | ||
| 311 | to=s; | ||
| 312 | ret->type=V_ASN1_INTEGER; | ||
| 313 | if(len) { | ||
| 314 | if ((*p == 0) && (len != 1)) | ||
| 315 | { | ||
| 316 | p++; | ||
| 317 | len--; | ||
| 318 | } | ||
| 319 | memcpy(s,p,(int)len); | ||
| 320 | p+=len; | ||
| 321 | } | ||
| 322 | |||
| 323 | if (ret->data != NULL) OPENSSL_free(ret->data); | ||
| 324 | ret->data=s; | ||
| 325 | ret->length=(int)len; | ||
| 326 | if (a != NULL) (*a)=ret; | ||
| 327 | *pp=p; | ||
| 328 | return(ret); | ||
| 329 | err: | ||
| 330 | ASN1err(ASN1_F_D2I_ASN1_UINTEGER,i); | ||
| 331 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) | ||
| 332 | M_ASN1_INTEGER_free(ret); | ||
| 333 | return(NULL); | ||
| 334 | } | ||
| 335 | |||
| 336 | int ASN1_INTEGER_set(ASN1_INTEGER *a, long v) | ||
| 337 | { | ||
| 338 | int j,k; | ||
| 339 | unsigned int i; | ||
| 340 | unsigned char buf[sizeof(long)+1]; | ||
| 341 | long d; | ||
| 342 | |||
| 343 | a->type=V_ASN1_INTEGER; | ||
| 344 | if (a->length < (int)(sizeof(long)+1)) | ||
| 345 | { | ||
| 346 | if (a->data != NULL) | ||
| 347 | OPENSSL_free(a->data); | ||
| 348 | if ((a->data=(unsigned char *)OPENSSL_malloc(sizeof(long)+1)) != NULL) | ||
| 349 | memset((char *)a->data,0,sizeof(long)+1); | ||
| 350 | } | ||
| 351 | if (a->data == NULL) | ||
| 352 | { | ||
| 353 | ASN1err(ASN1_F_ASN1_INTEGER_SET,ERR_R_MALLOC_FAILURE); | ||
| 354 | return(0); | ||
| 355 | } | ||
| 356 | d=v; | ||
| 357 | if (d < 0) | ||
| 358 | { | ||
| 359 | d= -d; | ||
| 360 | a->type=V_ASN1_NEG_INTEGER; | ||
| 361 | } | ||
| 362 | |||
| 363 | for (i=0; i<sizeof(long); i++) | ||
| 364 | { | ||
| 365 | if (d == 0) break; | ||
| 366 | buf[i]=(int)d&0xff; | ||
| 367 | d>>=8; | ||
| 368 | } | ||
| 369 | j=0; | ||
| 370 | for (k=i-1; k >=0; k--) | ||
| 371 | a->data[j++]=buf[k]; | ||
| 372 | a->length=j; | ||
| 373 | return(1); | ||
| 374 | } | ||
| 375 | |||
| 376 | long ASN1_INTEGER_get(ASN1_INTEGER *a) | ||
| 377 | { | ||
| 378 | int neg=0,i; | ||
| 379 | long r=0; | ||
| 380 | |||
| 381 | if (a == NULL) return(0L); | ||
| 382 | i=a->type; | ||
| 383 | if (i == V_ASN1_NEG_INTEGER) | ||
| 384 | neg=1; | ||
| 385 | else if (i != V_ASN1_INTEGER) | ||
| 386 | return -1; | ||
| 387 | |||
| 388 | if (a->length > (int)sizeof(long)) | ||
| 389 | { | ||
| 390 | /* hmm... a bit ugly */ | ||
| 391 | return(0xffffffffL); | ||
| 392 | } | ||
| 393 | if (a->data == NULL) | ||
| 394 | return 0; | ||
| 395 | |||
| 396 | for (i=0; i<a->length; i++) | ||
| 397 | { | ||
| 398 | r<<=8; | ||
| 399 | r|=(unsigned char)a->data[i]; | ||
| 400 | } | ||
| 401 | if (neg) r= -r; | ||
| 402 | return(r); | ||
| 403 | } | ||
| 404 | |||
| 405 | ASN1_INTEGER *BN_to_ASN1_INTEGER(BIGNUM *bn, ASN1_INTEGER *ai) | ||
| 406 | { | ||
| 407 | ASN1_INTEGER *ret; | ||
| 408 | int len,j; | ||
| 409 | |||
| 410 | if (ai == NULL) | ||
| 411 | ret=M_ASN1_INTEGER_new(); | ||
| 412 | else | ||
| 413 | ret=ai; | ||
| 414 | if (ret == NULL) | ||
| 415 | { | ||
| 416 | ASN1err(ASN1_F_BN_TO_ASN1_INTEGER,ERR_R_NESTED_ASN1_ERROR); | ||
| 417 | goto err; | ||
| 418 | } | ||
| 419 | if (BN_is_negative(bn)) | ||
| 420 | ret->type = V_ASN1_NEG_INTEGER; | ||
| 421 | else ret->type=V_ASN1_INTEGER; | ||
| 422 | j=BN_num_bits(bn); | ||
| 423 | len=((j == 0)?0:((j/8)+1)); | ||
| 424 | if (ret->length < len+4) | ||
| 425 | { | ||
| 426 | unsigned char *new_data=OPENSSL_realloc(ret->data, len+4); | ||
| 427 | if (!new_data) | ||
| 428 | { | ||
| 429 | ASN1err(ASN1_F_BN_TO_ASN1_INTEGER,ERR_R_MALLOC_FAILURE); | ||
| 430 | goto err; | ||
| 431 | } | ||
| 432 | ret->data=new_data; | ||
| 433 | } | ||
| 434 | ret->length=BN_bn2bin(bn,ret->data); | ||
| 435 | /* Correct zero case */ | ||
| 436 | if(!ret->length) | ||
| 437 | { | ||
| 438 | ret->data[0] = 0; | ||
| 439 | ret->length = 1; | ||
| 440 | } | ||
| 441 | return(ret); | ||
| 442 | err: | ||
| 443 | if (ret != ai) M_ASN1_INTEGER_free(ret); | ||
| 444 | return(NULL); | ||
| 445 | } | ||
| 446 | |||
| 447 | BIGNUM *ASN1_INTEGER_to_BN(ASN1_INTEGER *ai, BIGNUM *bn) | ||
| 448 | { | ||
| 449 | BIGNUM *ret; | ||
| 450 | |||
| 451 | if ((ret=BN_bin2bn(ai->data,ai->length,bn)) == NULL) | ||
| 452 | ASN1err(ASN1_F_ASN1_INTEGER_TO_BN,ASN1_R_BN_LIB); | ||
| 453 | else if(ai->type == V_ASN1_NEG_INTEGER) | ||
| 454 | BN_set_negative(ret, 1); | ||
| 455 | return(ret); | ||
| 456 | } | ||
| 457 | |||
| 458 | IMPLEMENT_STACK_OF(ASN1_INTEGER) | ||
| 459 | IMPLEMENT_ASN1_SET_OF(ASN1_INTEGER) | ||
diff --git a/src/lib/libcrypto/asn1/a_mbstr.c b/src/lib/libcrypto/asn1/a_mbstr.c new file mode 100644 index 0000000000..2d4800a22a --- /dev/null +++ b/src/lib/libcrypto/asn1/a_mbstr.c | |||
| @@ -0,0 +1,400 @@ | |||
| 1 | /* a_mbstr.c */ | ||
| 2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
| 3 | * project 1999. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include <ctype.h> | ||
| 61 | #include "cryptlib.h" | ||
| 62 | #include <openssl/asn1.h> | ||
| 63 | |||
| 64 | static int traverse_string(const unsigned char *p, int len, int inform, | ||
| 65 | int (*rfunc)(unsigned long value, void *in), void *arg); | ||
| 66 | static int in_utf8(unsigned long value, void *arg); | ||
| 67 | static int out_utf8(unsigned long value, void *arg); | ||
| 68 | static int type_str(unsigned long value, void *arg); | ||
| 69 | static int cpy_asc(unsigned long value, void *arg); | ||
| 70 | static int cpy_bmp(unsigned long value, void *arg); | ||
| 71 | static int cpy_univ(unsigned long value, void *arg); | ||
| 72 | static int cpy_utf8(unsigned long value, void *arg); | ||
| 73 | static int is_printable(unsigned long value); | ||
| 74 | |||
| 75 | /* These functions take a string in UTF8, ASCII or multibyte form and | ||
| 76 | * a mask of permissible ASN1 string types. It then works out the minimal | ||
| 77 | * type (using the order Printable < IA5 < T61 < BMP < Universal < UTF8) | ||
| 78 | * and creates a string of the correct type with the supplied data. | ||
| 79 | * Yes this is horrible: it has to be :-( | ||
| 80 | * The 'ncopy' form checks minimum and maximum size limits too. | ||
| 81 | */ | ||
| 82 | |||
| 83 | int ASN1_mbstring_copy(ASN1_STRING **out, const unsigned char *in, int len, | ||
| 84 | int inform, unsigned long mask) | ||
| 85 | { | ||
| 86 | return ASN1_mbstring_ncopy(out, in, len, inform, mask, 0, 0); | ||
| 87 | } | ||
| 88 | |||
| 89 | int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len, | ||
| 90 | int inform, unsigned long mask, | ||
| 91 | long minsize, long maxsize) | ||
| 92 | { | ||
| 93 | int str_type; | ||
| 94 | int ret; | ||
| 95 | char free_out; | ||
| 96 | int outform, outlen; | ||
| 97 | ASN1_STRING *dest; | ||
| 98 | unsigned char *p; | ||
| 99 | int nchar; | ||
| 100 | char strbuf[32]; | ||
| 101 | int (*cpyfunc)(unsigned long,void *) = NULL; | ||
| 102 | if(len == -1) len = strlen((const char *)in); | ||
| 103 | if(!mask) mask = DIRSTRING_TYPE; | ||
| 104 | |||
| 105 | /* First do a string check and work out the number of characters */ | ||
| 106 | switch(inform) { | ||
| 107 | |||
| 108 | case MBSTRING_BMP: | ||
| 109 | if(len & 1) { | ||
| 110 | ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, | ||
| 111 | ASN1_R_INVALID_BMPSTRING_LENGTH); | ||
| 112 | return -1; | ||
| 113 | } | ||
| 114 | nchar = len >> 1; | ||
| 115 | break; | ||
| 116 | |||
| 117 | case MBSTRING_UNIV: | ||
| 118 | if(len & 3) { | ||
| 119 | ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, | ||
| 120 | ASN1_R_INVALID_UNIVERSALSTRING_LENGTH); | ||
| 121 | return -1; | ||
| 122 | } | ||
| 123 | nchar = len >> 2; | ||
| 124 | break; | ||
| 125 | |||
| 126 | case MBSTRING_UTF8: | ||
| 127 | nchar = 0; | ||
| 128 | /* This counts the characters and does utf8 syntax checking */ | ||
| 129 | ret = traverse_string(in, len, MBSTRING_UTF8, in_utf8, &nchar); | ||
| 130 | if(ret < 0) { | ||
| 131 | ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, | ||
| 132 | ASN1_R_INVALID_UTF8STRING); | ||
| 133 | return -1; | ||
| 134 | } | ||
| 135 | break; | ||
| 136 | |||
| 137 | case MBSTRING_ASC: | ||
| 138 | nchar = len; | ||
| 139 | break; | ||
| 140 | |||
| 141 | default: | ||
| 142 | ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, ASN1_R_UNKNOWN_FORMAT); | ||
| 143 | return -1; | ||
| 144 | } | ||
| 145 | |||
| 146 | if((minsize > 0) && (nchar < minsize)) { | ||
| 147 | ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, ASN1_R_STRING_TOO_SHORT); | ||
| 148 | BIO_snprintf(strbuf, sizeof strbuf, "%ld", minsize); | ||
| 149 | ERR_add_error_data(2, "minsize=", strbuf); | ||
| 150 | return -1; | ||
| 151 | } | ||
| 152 | |||
| 153 | if((maxsize > 0) && (nchar > maxsize)) { | ||
| 154 | ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, ASN1_R_STRING_TOO_LONG); | ||
| 155 | BIO_snprintf(strbuf, sizeof strbuf, "%ld", maxsize); | ||
| 156 | ERR_add_error_data(2, "maxsize=", strbuf); | ||
| 157 | return -1; | ||
| 158 | } | ||
| 159 | |||
| 160 | /* Now work out minimal type (if any) */ | ||
| 161 | if(traverse_string(in, len, inform, type_str, &mask) < 0) { | ||
| 162 | ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, ASN1_R_ILLEGAL_CHARACTERS); | ||
| 163 | return -1; | ||
| 164 | } | ||
| 165 | |||
| 166 | |||
| 167 | /* Now work out output format and string type */ | ||
| 168 | outform = MBSTRING_ASC; | ||
| 169 | if(mask & B_ASN1_PRINTABLESTRING) str_type = V_ASN1_PRINTABLESTRING; | ||
| 170 | else if(mask & B_ASN1_IA5STRING) str_type = V_ASN1_IA5STRING; | ||
| 171 | else if(mask & B_ASN1_T61STRING) str_type = V_ASN1_T61STRING; | ||
| 172 | else if(mask & B_ASN1_BMPSTRING) { | ||
| 173 | str_type = V_ASN1_BMPSTRING; | ||
| 174 | outform = MBSTRING_BMP; | ||
| 175 | } else if(mask & B_ASN1_UNIVERSALSTRING) { | ||
| 176 | str_type = V_ASN1_UNIVERSALSTRING; | ||
| 177 | outform = MBSTRING_UNIV; | ||
| 178 | } else { | ||
| 179 | str_type = V_ASN1_UTF8STRING; | ||
| 180 | outform = MBSTRING_UTF8; | ||
| 181 | } | ||
| 182 | if(!out) return str_type; | ||
| 183 | if(*out) { | ||
| 184 | free_out = 0; | ||
| 185 | dest = *out; | ||
| 186 | if(dest->data) { | ||
| 187 | dest->length = 0; | ||
| 188 | OPENSSL_free(dest->data); | ||
| 189 | dest->data = NULL; | ||
| 190 | } | ||
| 191 | dest->type = str_type; | ||
| 192 | } else { | ||
| 193 | free_out = 1; | ||
| 194 | dest = ASN1_STRING_type_new(str_type); | ||
| 195 | if(!dest) { | ||
| 196 | ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, | ||
| 197 | ERR_R_MALLOC_FAILURE); | ||
| 198 | return -1; | ||
| 199 | } | ||
| 200 | *out = dest; | ||
| 201 | } | ||
| 202 | /* If both the same type just copy across */ | ||
| 203 | if(inform == outform) { | ||
| 204 | if(!ASN1_STRING_set(dest, in, len)) { | ||
| 205 | ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY,ERR_R_MALLOC_FAILURE); | ||
| 206 | return -1; | ||
| 207 | } | ||
| 208 | return str_type; | ||
| 209 | } | ||
| 210 | |||
| 211 | /* Work out how much space the destination will need */ | ||
| 212 | switch(outform) { | ||
| 213 | case MBSTRING_ASC: | ||
| 214 | outlen = nchar; | ||
| 215 | cpyfunc = cpy_asc; | ||
| 216 | break; | ||
| 217 | |||
| 218 | case MBSTRING_BMP: | ||
| 219 | outlen = nchar << 1; | ||
| 220 | cpyfunc = cpy_bmp; | ||
| 221 | break; | ||
| 222 | |||
| 223 | case MBSTRING_UNIV: | ||
| 224 | outlen = nchar << 2; | ||
| 225 | cpyfunc = cpy_univ; | ||
| 226 | break; | ||
| 227 | |||
| 228 | case MBSTRING_UTF8: | ||
| 229 | outlen = 0; | ||
| 230 | traverse_string(in, len, inform, out_utf8, &outlen); | ||
| 231 | cpyfunc = cpy_utf8; | ||
| 232 | break; | ||
| 233 | } | ||
| 234 | if(!(p = OPENSSL_malloc(outlen + 1))) { | ||
| 235 | if(free_out) ASN1_STRING_free(dest); | ||
| 236 | ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY,ERR_R_MALLOC_FAILURE); | ||
| 237 | return -1; | ||
| 238 | } | ||
| 239 | dest->length = outlen; | ||
| 240 | dest->data = p; | ||
| 241 | p[outlen] = 0; | ||
| 242 | traverse_string(in, len, inform, cpyfunc, &p); | ||
| 243 | return str_type; | ||
| 244 | } | ||
| 245 | |||
| 246 | /* This function traverses a string and passes the value of each character | ||
| 247 | * to an optional function along with a void * argument. | ||
| 248 | */ | ||
| 249 | |||
| 250 | static int traverse_string(const unsigned char *p, int len, int inform, | ||
| 251 | int (*rfunc)(unsigned long value, void *in), void *arg) | ||
| 252 | { | ||
| 253 | unsigned long value; | ||
| 254 | int ret; | ||
| 255 | while(len) { | ||
| 256 | if(inform == MBSTRING_ASC) { | ||
| 257 | value = *p++; | ||
| 258 | len--; | ||
| 259 | } else if(inform == MBSTRING_BMP) { | ||
| 260 | value = *p++ << 8; | ||
| 261 | value |= *p++; | ||
| 262 | len -= 2; | ||
| 263 | } else if(inform == MBSTRING_UNIV) { | ||
| 264 | value = ((unsigned long)*p++) << 24; | ||
| 265 | value |= ((unsigned long)*p++) << 16; | ||
| 266 | value |= *p++ << 8; | ||
| 267 | value |= *p++; | ||
| 268 | len -= 4; | ||
| 269 | } else { | ||
| 270 | ret = UTF8_getc(p, len, &value); | ||
| 271 | if(ret < 0) return -1; | ||
| 272 | len -= ret; | ||
| 273 | p += ret; | ||
| 274 | } | ||
| 275 | if(rfunc) { | ||
| 276 | ret = rfunc(value, arg); | ||
| 277 | if(ret <= 0) return ret; | ||
| 278 | } | ||
| 279 | } | ||
| 280 | return 1; | ||
| 281 | } | ||
| 282 | |||
| 283 | /* Various utility functions for traverse_string */ | ||
| 284 | |||
| 285 | /* Just count number of characters */ | ||
| 286 | |||
| 287 | static int in_utf8(unsigned long value, void *arg) | ||
| 288 | { | ||
| 289 | int *nchar; | ||
| 290 | nchar = arg; | ||
| 291 | (*nchar)++; | ||
| 292 | return 1; | ||
| 293 | } | ||
| 294 | |||
| 295 | /* Determine size of output as a UTF8 String */ | ||
| 296 | |||
| 297 | static int out_utf8(unsigned long value, void *arg) | ||
| 298 | { | ||
| 299 | int *outlen; | ||
| 300 | outlen = arg; | ||
| 301 | *outlen += UTF8_putc(NULL, -1, value); | ||
| 302 | return 1; | ||
| 303 | } | ||
| 304 | |||
| 305 | /* Determine the "type" of a string: check each character against a | ||
| 306 | * supplied "mask". | ||
| 307 | */ | ||
| 308 | |||
| 309 | static int type_str(unsigned long value, void *arg) | ||
| 310 | { | ||
| 311 | unsigned long types; | ||
| 312 | types = *((unsigned long *)arg); | ||
| 313 | if((types & B_ASN1_PRINTABLESTRING) && !is_printable(value)) | ||
| 314 | types &= ~B_ASN1_PRINTABLESTRING; | ||
| 315 | if((types & B_ASN1_IA5STRING) && (value > 127)) | ||
| 316 | types &= ~B_ASN1_IA5STRING; | ||
| 317 | if((types & B_ASN1_T61STRING) && (value > 0xff)) | ||
| 318 | types &= ~B_ASN1_T61STRING; | ||
| 319 | if((types & B_ASN1_BMPSTRING) && (value > 0xffff)) | ||
| 320 | types &= ~B_ASN1_BMPSTRING; | ||
| 321 | if(!types) return -1; | ||
| 322 | *((unsigned long *)arg) = types; | ||
| 323 | return 1; | ||
| 324 | } | ||
| 325 | |||
| 326 | /* Copy one byte per character ASCII like strings */ | ||
| 327 | |||
| 328 | static int cpy_asc(unsigned long value, void *arg) | ||
| 329 | { | ||
| 330 | unsigned char **p, *q; | ||
| 331 | p = arg; | ||
| 332 | q = *p; | ||
| 333 | *q = (unsigned char) value; | ||
| 334 | (*p)++; | ||
| 335 | return 1; | ||
| 336 | } | ||
| 337 | |||
| 338 | /* Copy two byte per character BMPStrings */ | ||
| 339 | |||
| 340 | static int cpy_bmp(unsigned long value, void *arg) | ||
| 341 | { | ||
| 342 | unsigned char **p, *q; | ||
| 343 | p = arg; | ||
| 344 | q = *p; | ||
| 345 | *q++ = (unsigned char) ((value >> 8) & 0xff); | ||
| 346 | *q = (unsigned char) (value & 0xff); | ||
| 347 | *p += 2; | ||
| 348 | return 1; | ||
| 349 | } | ||
| 350 | |||
| 351 | /* Copy four byte per character UniversalStrings */ | ||
| 352 | |||
| 353 | static int cpy_univ(unsigned long value, void *arg) | ||
| 354 | { | ||
| 355 | unsigned char **p, *q; | ||
| 356 | p = arg; | ||
| 357 | q = *p; | ||
| 358 | *q++ = (unsigned char) ((value >> 24) & 0xff); | ||
| 359 | *q++ = (unsigned char) ((value >> 16) & 0xff); | ||
| 360 | *q++ = (unsigned char) ((value >> 8) & 0xff); | ||
| 361 | *q = (unsigned char) (value & 0xff); | ||
| 362 | *p += 4; | ||
| 363 | return 1; | ||
| 364 | } | ||
| 365 | |||
| 366 | /* Copy to a UTF8String */ | ||
| 367 | |||
| 368 | static int cpy_utf8(unsigned long value, void *arg) | ||
| 369 | { | ||
| 370 | unsigned char **p; | ||
| 371 | int ret; | ||
| 372 | p = arg; | ||
| 373 | /* We already know there is enough room so pass 0xff as the length */ | ||
| 374 | ret = UTF8_putc(*p, 0xff, value); | ||
| 375 | *p += ret; | ||
| 376 | return 1; | ||
| 377 | } | ||
| 378 | |||
| 379 | /* Return 1 if the character is permitted in a PrintableString */ | ||
| 380 | static int is_printable(unsigned long value) | ||
| 381 | { | ||
| 382 | int ch; | ||
| 383 | if(value > 0x7f) return 0; | ||
| 384 | ch = (int) value; | ||
| 385 | /* Note: we can't use 'isalnum' because certain accented | ||
| 386 | * characters may count as alphanumeric in some environments. | ||
| 387 | */ | ||
| 388 | #ifndef CHARSET_EBCDIC | ||
| 389 | if((ch >= 'a') && (ch <= 'z')) return 1; | ||
| 390 | if((ch >= 'A') && (ch <= 'Z')) return 1; | ||
| 391 | if((ch >= '0') && (ch <= '9')) return 1; | ||
| 392 | if ((ch == ' ') || strchr("'()+,-./:=?", ch)) return 1; | ||
| 393 | #else /*CHARSET_EBCDIC*/ | ||
| 394 | if((ch >= os_toascii['a']) && (ch <= os_toascii['z'])) return 1; | ||
| 395 | if((ch >= os_toascii['A']) && (ch <= os_toascii['Z'])) return 1; | ||
| 396 | if((ch >= os_toascii['0']) && (ch <= os_toascii['9'])) return 1; | ||
| 397 | if ((ch == os_toascii[' ']) || strchr("'()+,-./:=?", os_toebcdic[ch])) return 1; | ||
| 398 | #endif /*CHARSET_EBCDIC*/ | ||
| 399 | return 0; | ||
| 400 | } | ||
diff --git a/src/lib/libcrypto/asn1/a_meth.c b/src/lib/libcrypto/asn1/a_meth.c new file mode 100644 index 0000000000..50bea917e3 --- /dev/null +++ b/src/lib/libcrypto/asn1/a_meth.c | |||
| @@ -0,0 +1,84 @@ | |||
| 1 | /* crypto/asn1/a_meth.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/buffer.h> | ||
| 62 | #include <openssl/asn1.h> | ||
| 63 | |||
| 64 | static ASN1_METHOD ia5string_meth={ | ||
| 65 | (I2D_OF(void)) i2d_ASN1_IA5STRING, | ||
| 66 | (D2I_OF(void)) d2i_ASN1_IA5STRING, | ||
| 67 | (void *(*)(void))ASN1_STRING_new, | ||
| 68 | (void (*)(void *))ASN1_STRING_free}; | ||
| 69 | |||
| 70 | static ASN1_METHOD bit_string_meth={ | ||
| 71 | (I2D_OF(void)) i2d_ASN1_BIT_STRING, | ||
| 72 | (D2I_OF(void)) d2i_ASN1_BIT_STRING, | ||
| 73 | (void *(*)(void))ASN1_STRING_new, | ||
| 74 | (void (*)(void *))ASN1_STRING_free}; | ||
| 75 | |||
| 76 | ASN1_METHOD *ASN1_IA5STRING_asn1_meth(void) | ||
| 77 | { | ||
| 78 | return(&ia5string_meth); | ||
| 79 | } | ||
| 80 | |||
| 81 | ASN1_METHOD *ASN1_BIT_STRING_asn1_meth(void) | ||
| 82 | { | ||
| 83 | return(&bit_string_meth); | ||
| 84 | } | ||
diff --git a/src/lib/libcrypto/asn1/a_object.c b/src/lib/libcrypto/asn1/a_object.c new file mode 100644 index 0000000000..dc980421d0 --- /dev/null +++ b/src/lib/libcrypto/asn1/a_object.c | |||
| @@ -0,0 +1,386 @@ | |||
| 1 | /* crypto/asn1/a_object.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include <limits.h> | ||
| 61 | #include "cryptlib.h" | ||
| 62 | #include <openssl/buffer.h> | ||
| 63 | #include <openssl/asn1.h> | ||
| 64 | #include <openssl/objects.h> | ||
| 65 | #include <openssl/bn.h> | ||
| 66 | |||
| 67 | int i2d_ASN1_OBJECT(ASN1_OBJECT *a, unsigned char **pp) | ||
| 68 | { | ||
| 69 | unsigned char *p; | ||
| 70 | int objsize; | ||
| 71 | |||
| 72 | if ((a == NULL) || (a->data == NULL)) return(0); | ||
| 73 | |||
| 74 | objsize = ASN1_object_size(0,a->length,V_ASN1_OBJECT); | ||
| 75 | if (pp == NULL) return objsize; | ||
| 76 | |||
| 77 | p= *pp; | ||
| 78 | ASN1_put_object(&p,0,a->length,V_ASN1_OBJECT,V_ASN1_UNIVERSAL); | ||
| 79 | memcpy(p,a->data,a->length); | ||
| 80 | p+=a->length; | ||
| 81 | |||
| 82 | *pp=p; | ||
| 83 | return(objsize); | ||
| 84 | } | ||
| 85 | |||
| 86 | int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num) | ||
| 87 | { | ||
| 88 | int i,first,len=0,c, use_bn; | ||
| 89 | char ftmp[24], *tmp = ftmp; | ||
| 90 | int tmpsize = sizeof ftmp; | ||
| 91 | const char *p; | ||
| 92 | unsigned long l; | ||
| 93 | BIGNUM *bl = NULL; | ||
| 94 | |||
| 95 | if (num == 0) | ||
| 96 | return(0); | ||
| 97 | else if (num == -1) | ||
| 98 | num=strlen(buf); | ||
| 99 | |||
| 100 | p=buf; | ||
| 101 | c= *(p++); | ||
| 102 | num--; | ||
| 103 | if ((c >= '0') && (c <= '2')) | ||
| 104 | { | ||
| 105 | first= c-'0'; | ||
| 106 | } | ||
| 107 | else | ||
| 108 | { | ||
| 109 | ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_FIRST_NUM_TOO_LARGE); | ||
| 110 | goto err; | ||
| 111 | } | ||
| 112 | |||
| 113 | if (num <= 0) | ||
| 114 | { | ||
| 115 | ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_MISSING_SECOND_NUMBER); | ||
| 116 | goto err; | ||
| 117 | } | ||
| 118 | c= *(p++); | ||
| 119 | num--; | ||
| 120 | for (;;) | ||
| 121 | { | ||
| 122 | if (num <= 0) break; | ||
| 123 | if ((c != '.') && (c != ' ')) | ||
| 124 | { | ||
| 125 | ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_INVALID_SEPARATOR); | ||
| 126 | goto err; | ||
| 127 | } | ||
| 128 | l=0; | ||
| 129 | use_bn = 0; | ||
| 130 | for (;;) | ||
| 131 | { | ||
| 132 | if (num <= 0) break; | ||
| 133 | num--; | ||
| 134 | c= *(p++); | ||
| 135 | if ((c == ' ') || (c == '.')) | ||
| 136 | break; | ||
| 137 | if ((c < '0') || (c > '9')) | ||
| 138 | { | ||
| 139 | ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_INVALID_DIGIT); | ||
| 140 | goto err; | ||
| 141 | } | ||
| 142 | if (!use_bn && l > (ULONG_MAX / 10L)) | ||
| 143 | { | ||
| 144 | use_bn = 1; | ||
| 145 | if (!bl) | ||
| 146 | bl = BN_new(); | ||
| 147 | if (!bl || !BN_set_word(bl, l)) | ||
| 148 | goto err; | ||
| 149 | } | ||
| 150 | if (use_bn) | ||
| 151 | { | ||
| 152 | if (!BN_mul_word(bl, 10L) | ||
| 153 | || !BN_add_word(bl, c-'0')) | ||
| 154 | goto err; | ||
| 155 | } | ||
| 156 | else | ||
| 157 | l=l*10L+(long)(c-'0'); | ||
| 158 | } | ||
| 159 | if (len == 0) | ||
| 160 | { | ||
| 161 | if ((first < 2) && (l >= 40)) | ||
| 162 | { | ||
| 163 | ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_SECOND_NUMBER_TOO_LARGE); | ||
| 164 | goto err; | ||
| 165 | } | ||
| 166 | if (use_bn) | ||
| 167 | { | ||
| 168 | if (!BN_add_word(bl, first * 40)) | ||
| 169 | goto err; | ||
| 170 | } | ||
| 171 | else | ||
| 172 | l+=(long)first*40; | ||
| 173 | } | ||
| 174 | i=0; | ||
| 175 | if (use_bn) | ||
| 176 | { | ||
| 177 | int blsize; | ||
| 178 | blsize = BN_num_bits(bl); | ||
| 179 | blsize = (blsize + 6)/7; | ||
| 180 | if (blsize > tmpsize) | ||
| 181 | { | ||
| 182 | if (tmp != ftmp) | ||
| 183 | OPENSSL_free(tmp); | ||
| 184 | tmpsize = blsize + 32; | ||
| 185 | tmp = OPENSSL_malloc(tmpsize); | ||
| 186 | if (!tmp) | ||
| 187 | goto err; | ||
| 188 | } | ||
| 189 | while(blsize--) | ||
| 190 | tmp[i++] = (unsigned char)BN_div_word(bl, 0x80L); | ||
| 191 | } | ||
| 192 | else | ||
| 193 | { | ||
| 194 | |||
| 195 | for (;;) | ||
| 196 | { | ||
| 197 | tmp[i++]=(unsigned char)l&0x7f; | ||
| 198 | l>>=7L; | ||
| 199 | if (l == 0L) break; | ||
| 200 | } | ||
| 201 | |||
| 202 | } | ||
| 203 | if (out != NULL) | ||
| 204 | { | ||
| 205 | if (len+i > olen) | ||
| 206 | { | ||
| 207 | ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_BUFFER_TOO_SMALL); | ||
| 208 | goto err; | ||
| 209 | } | ||
| 210 | while (--i > 0) | ||
| 211 | out[len++]=tmp[i]|0x80; | ||
| 212 | out[len++]=tmp[0]; | ||
| 213 | } | ||
| 214 | else | ||
| 215 | len+=i; | ||
| 216 | } | ||
| 217 | if (tmp != ftmp) | ||
| 218 | OPENSSL_free(tmp); | ||
| 219 | if (bl) | ||
| 220 | BN_free(bl); | ||
| 221 | return(len); | ||
| 222 | err: | ||
| 223 | if (tmp != ftmp) | ||
| 224 | OPENSSL_free(tmp); | ||
| 225 | if (bl) | ||
| 226 | BN_free(bl); | ||
| 227 | return(0); | ||
| 228 | } | ||
| 229 | |||
| 230 | int i2t_ASN1_OBJECT(char *buf, int buf_len, ASN1_OBJECT *a) | ||
| 231 | { | ||
| 232 | return OBJ_obj2txt(buf, buf_len, a, 0); | ||
| 233 | } | ||
| 234 | |||
| 235 | int i2a_ASN1_OBJECT(BIO *bp, ASN1_OBJECT *a) | ||
| 236 | { | ||
| 237 | char buf[80], *p = buf; | ||
| 238 | int i; | ||
| 239 | |||
| 240 | if ((a == NULL) || (a->data == NULL)) | ||
| 241 | return(BIO_write(bp,"NULL",4)); | ||
| 242 | i=i2t_ASN1_OBJECT(buf,sizeof buf,a); | ||
| 243 | if (i > (int)(sizeof(buf) - 1)) | ||
| 244 | { | ||
| 245 | p = OPENSSL_malloc(i + 1); | ||
| 246 | if (!p) | ||
| 247 | return -1; | ||
| 248 | i2t_ASN1_OBJECT(p,i + 1,a); | ||
| 249 | } | ||
| 250 | if (i <= 0) | ||
| 251 | return BIO_write(bp, "<INVALID>", 9); | ||
| 252 | BIO_write(bp,p,i); | ||
| 253 | if (p != buf) | ||
| 254 | OPENSSL_free(p); | ||
| 255 | return(i); | ||
| 256 | } | ||
| 257 | |||
| 258 | ASN1_OBJECT *d2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, | ||
| 259 | long length) | ||
| 260 | { | ||
| 261 | const unsigned char *p; | ||
| 262 | long len; | ||
| 263 | int tag,xclass; | ||
| 264 | int inf,i; | ||
| 265 | ASN1_OBJECT *ret = NULL; | ||
| 266 | p= *pp; | ||
| 267 | inf=ASN1_get_object(&p,&len,&tag,&xclass,length); | ||
| 268 | if (inf & 0x80) | ||
| 269 | { | ||
| 270 | i=ASN1_R_BAD_OBJECT_HEADER; | ||
| 271 | goto err; | ||
| 272 | } | ||
| 273 | |||
| 274 | if (tag != V_ASN1_OBJECT) | ||
| 275 | { | ||
| 276 | i=ASN1_R_EXPECTING_AN_OBJECT; | ||
| 277 | goto err; | ||
| 278 | } | ||
| 279 | ret = c2i_ASN1_OBJECT(a, &p, len); | ||
| 280 | if(ret) *pp = p; | ||
| 281 | return ret; | ||
| 282 | err: | ||
| 283 | ASN1err(ASN1_F_D2I_ASN1_OBJECT,i); | ||
| 284 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) | ||
| 285 | ASN1_OBJECT_free(ret); | ||
| 286 | return(NULL); | ||
| 287 | } | ||
| 288 | ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, | ||
| 289 | long len) | ||
| 290 | { | ||
| 291 | ASN1_OBJECT *ret=NULL; | ||
| 292 | const unsigned char *p; | ||
| 293 | int i; | ||
| 294 | |||
| 295 | /* only the ASN1_OBJECTs from the 'table' will have values | ||
| 296 | * for ->sn or ->ln */ | ||
| 297 | if ((a == NULL) || ((*a) == NULL) || | ||
| 298 | !((*a)->flags & ASN1_OBJECT_FLAG_DYNAMIC)) | ||
| 299 | { | ||
| 300 | if ((ret=ASN1_OBJECT_new()) == NULL) return(NULL); | ||
| 301 | } | ||
| 302 | else ret=(*a); | ||
| 303 | |||
| 304 | p= *pp; | ||
| 305 | if ((ret->data == NULL) || (ret->length < len)) | ||
| 306 | { | ||
| 307 | if (ret->data != NULL) OPENSSL_free(ret->data); | ||
| 308 | ret->data=(unsigned char *)OPENSSL_malloc(len ? (int)len : 1); | ||
| 309 | ret->flags|=ASN1_OBJECT_FLAG_DYNAMIC_DATA; | ||
| 310 | if (ret->data == NULL) | ||
| 311 | { i=ERR_R_MALLOC_FAILURE; goto err; } | ||
| 312 | } | ||
| 313 | memcpy(ret->data,p,(int)len); | ||
| 314 | ret->length=(int)len; | ||
| 315 | ret->sn=NULL; | ||
| 316 | ret->ln=NULL; | ||
| 317 | /* ret->flags=ASN1_OBJECT_FLAG_DYNAMIC; we know it is dynamic */ | ||
| 318 | p+=len; | ||
| 319 | |||
| 320 | if (a != NULL) (*a)=ret; | ||
| 321 | *pp=p; | ||
| 322 | return(ret); | ||
| 323 | err: | ||
| 324 | ASN1err(ASN1_F_C2I_ASN1_OBJECT,i); | ||
| 325 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) | ||
| 326 | ASN1_OBJECT_free(ret); | ||
| 327 | return(NULL); | ||
| 328 | } | ||
| 329 | |||
| 330 | ASN1_OBJECT *ASN1_OBJECT_new(void) | ||
| 331 | { | ||
| 332 | ASN1_OBJECT *ret; | ||
| 333 | |||
| 334 | ret=(ASN1_OBJECT *)OPENSSL_malloc(sizeof(ASN1_OBJECT)); | ||
| 335 | if (ret == NULL) | ||
| 336 | { | ||
| 337 | ASN1err(ASN1_F_ASN1_OBJECT_NEW,ERR_R_MALLOC_FAILURE); | ||
| 338 | return(NULL); | ||
| 339 | } | ||
| 340 | ret->length=0; | ||
| 341 | ret->data=NULL; | ||
| 342 | ret->nid=0; | ||
| 343 | ret->sn=NULL; | ||
| 344 | ret->ln=NULL; | ||
| 345 | ret->flags=ASN1_OBJECT_FLAG_DYNAMIC; | ||
| 346 | return(ret); | ||
| 347 | } | ||
| 348 | |||
| 349 | void ASN1_OBJECT_free(ASN1_OBJECT *a) | ||
| 350 | { | ||
| 351 | if (a == NULL) return; | ||
| 352 | if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_STRINGS) | ||
| 353 | { | ||
| 354 | #ifndef CONST_STRICT /* disable purely for compile-time strict const checking. Doing this on a "real" compile will cause memory leaks */ | ||
| 355 | if (a->sn != NULL) OPENSSL_free((void *)a->sn); | ||
| 356 | if (a->ln != NULL) OPENSSL_free((void *)a->ln); | ||
| 357 | #endif | ||
| 358 | a->sn=a->ln=NULL; | ||
| 359 | } | ||
| 360 | if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_DATA) | ||
| 361 | { | ||
| 362 | if (a->data != NULL) OPENSSL_free(a->data); | ||
| 363 | a->data=NULL; | ||
| 364 | a->length=0; | ||
| 365 | } | ||
| 366 | if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC) | ||
| 367 | OPENSSL_free(a); | ||
| 368 | } | ||
| 369 | |||
| 370 | ASN1_OBJECT *ASN1_OBJECT_create(int nid, unsigned char *data, int len, | ||
| 371 | const char *sn, const char *ln) | ||
| 372 | { | ||
| 373 | ASN1_OBJECT o; | ||
| 374 | |||
| 375 | o.sn=sn; | ||
| 376 | o.ln=ln; | ||
| 377 | o.data=data; | ||
| 378 | o.nid=nid; | ||
| 379 | o.length=len; | ||
| 380 | o.flags=ASN1_OBJECT_FLAG_DYNAMIC|ASN1_OBJECT_FLAG_DYNAMIC_STRINGS| | ||
| 381 | ASN1_OBJECT_FLAG_DYNAMIC_DATA; | ||
| 382 | return(OBJ_dup(&o)); | ||
| 383 | } | ||
| 384 | |||
| 385 | IMPLEMENT_STACK_OF(ASN1_OBJECT) | ||
| 386 | IMPLEMENT_ASN1_SET_OF(ASN1_OBJECT) | ||
diff --git a/src/lib/libcrypto/asn1/a_octet.c b/src/lib/libcrypto/asn1/a_octet.c new file mode 100644 index 0000000000..24fd0f8e5a --- /dev/null +++ b/src/lib/libcrypto/asn1/a_octet.c | |||
| @@ -0,0 +1,71 @@ | |||
| 1 | /* crypto/asn1/a_octet.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/asn1.h> | ||
| 62 | |||
| 63 | ASN1_OCTET_STRING *ASN1_OCTET_STRING_dup(ASN1_OCTET_STRING *x) | ||
| 64 | { return M_ASN1_OCTET_STRING_dup(x); } | ||
| 65 | |||
| 66 | int ASN1_OCTET_STRING_cmp(ASN1_OCTET_STRING *a, ASN1_OCTET_STRING *b) | ||
| 67 | { return M_ASN1_OCTET_STRING_cmp(a, b); } | ||
| 68 | |||
| 69 | int ASN1_OCTET_STRING_set(ASN1_OCTET_STRING *x, const unsigned char *d, int len) | ||
| 70 | { return M_ASN1_OCTET_STRING_set(x, d, len); } | ||
| 71 | |||
diff --git a/src/lib/libcrypto/asn1/a_print.c b/src/lib/libcrypto/asn1/a_print.c new file mode 100644 index 0000000000..d18e772320 --- /dev/null +++ b/src/lib/libcrypto/asn1/a_print.c | |||
| @@ -0,0 +1,127 @@ | |||
| 1 | /* crypto/asn1/a_print.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/asn1.h> | ||
| 62 | |||
| 63 | int ASN1_PRINTABLE_type(const unsigned char *s, int len) | ||
| 64 | { | ||
| 65 | int c; | ||
| 66 | int ia5=0; | ||
| 67 | int t61=0; | ||
| 68 | |||
| 69 | if (len <= 0) len= -1; | ||
| 70 | if (s == NULL) return(V_ASN1_PRINTABLESTRING); | ||
| 71 | |||
| 72 | while ((*s) && (len-- != 0)) | ||
| 73 | { | ||
| 74 | c= *(s++); | ||
| 75 | #ifndef CHARSET_EBCDIC | ||
| 76 | if (!( ((c >= 'a') && (c <= 'z')) || | ||
| 77 | ((c >= 'A') && (c <= 'Z')) || | ||
| 78 | (c == ' ') || | ||
| 79 | ((c >= '0') && (c <= '9')) || | ||
| 80 | (c == ' ') || (c == '\'') || | ||
| 81 | (c == '(') || (c == ')') || | ||
| 82 | (c == '+') || (c == ',') || | ||
| 83 | (c == '-') || (c == '.') || | ||
| 84 | (c == '/') || (c == ':') || | ||
| 85 | (c == '=') || (c == '?'))) | ||
| 86 | ia5=1; | ||
| 87 | if (c&0x80) | ||
| 88 | t61=1; | ||
| 89 | #else | ||
| 90 | if (!isalnum(c) && (c != ' ') && | ||
| 91 | strchr("'()+,-./:=?", c) == NULL) | ||
| 92 | ia5=1; | ||
| 93 | if (os_toascii[c] & 0x80) | ||
| 94 | t61=1; | ||
| 95 | #endif | ||
| 96 | } | ||
| 97 | if (t61) return(V_ASN1_T61STRING); | ||
| 98 | if (ia5) return(V_ASN1_IA5STRING); | ||
| 99 | return(V_ASN1_PRINTABLESTRING); | ||
| 100 | } | ||
| 101 | |||
| 102 | int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s) | ||
| 103 | { | ||
| 104 | int i; | ||
| 105 | unsigned char *p; | ||
| 106 | |||
| 107 | if (s->type != V_ASN1_UNIVERSALSTRING) return(0); | ||
| 108 | if ((s->length%4) != 0) return(0); | ||
| 109 | p=s->data; | ||
| 110 | for (i=0; i<s->length; i+=4) | ||
| 111 | { | ||
| 112 | if ((p[0] != '\0') || (p[1] != '\0') || (p[2] != '\0')) | ||
| 113 | break; | ||
| 114 | else | ||
| 115 | p+=4; | ||
| 116 | } | ||
| 117 | if (i < s->length) return(0); | ||
| 118 | p=s->data; | ||
| 119 | for (i=3; i<s->length; i+=4) | ||
| 120 | { | ||
| 121 | *(p++)=s->data[i]; | ||
| 122 | } | ||
| 123 | *(p)='\0'; | ||
| 124 | s->length/=4; | ||
| 125 | s->type=ASN1_PRINTABLE_type(s->data,s->length); | ||
| 126 | return(1); | ||
| 127 | } | ||
diff --git a/src/lib/libcrypto/asn1/a_set.c b/src/lib/libcrypto/asn1/a_set.c new file mode 100644 index 0000000000..958558c204 --- /dev/null +++ b/src/lib/libcrypto/asn1/a_set.c | |||
| @@ -0,0 +1,238 @@ | |||
| 1 | /* crypto/asn1/a_set.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/asn1_mac.h> | ||
| 62 | |||
| 63 | #ifndef NO_ASN1_OLD | ||
| 64 | |||
| 65 | typedef struct | ||
| 66 | { | ||
| 67 | unsigned char *pbData; | ||
| 68 | int cbData; | ||
| 69 | } MYBLOB; | ||
| 70 | |||
| 71 | /* SetBlobCmp | ||
| 72 | * This function compares two elements of SET_OF block | ||
| 73 | */ | ||
| 74 | static int SetBlobCmp(const void *elem1, const void *elem2 ) | ||
| 75 | { | ||
| 76 | const MYBLOB *b1 = (const MYBLOB *)elem1; | ||
| 77 | const MYBLOB *b2 = (const MYBLOB *)elem2; | ||
| 78 | int r; | ||
| 79 | |||
| 80 | r = memcmp(b1->pbData, b2->pbData, | ||
| 81 | b1->cbData < b2->cbData ? b1->cbData : b2->cbData); | ||
| 82 | if(r != 0) | ||
| 83 | return r; | ||
| 84 | return b1->cbData-b2->cbData; | ||
| 85 | } | ||
| 86 | |||
| 87 | /* int is_set: if TRUE, then sort the contents (i.e. it isn't a SEQUENCE) */ | ||
| 88 | int i2d_ASN1_SET(STACK *a, unsigned char **pp, i2d_of_void *i2d, int ex_tag, | ||
| 89 | int ex_class, int is_set) | ||
| 90 | { | ||
| 91 | int ret=0,r; | ||
| 92 | int i; | ||
| 93 | unsigned char *p; | ||
| 94 | unsigned char *pStart, *pTempMem; | ||
| 95 | MYBLOB *rgSetBlob; | ||
| 96 | int totSize; | ||
| 97 | |||
| 98 | if (a == NULL) return(0); | ||
| 99 | for (i=sk_num(a)-1; i>=0; i--) | ||
| 100 | ret+=i2d(sk_value(a,i),NULL); | ||
| 101 | r=ASN1_object_size(1,ret,ex_tag); | ||
| 102 | if (pp == NULL) return(r); | ||
| 103 | |||
| 104 | p= *pp; | ||
| 105 | ASN1_put_object(&p,1,ret,ex_tag,ex_class); | ||
| 106 | |||
| 107 | /* Modified by gp@nsj.co.jp */ | ||
| 108 | /* And then again by Ben */ | ||
| 109 | /* And again by Steve */ | ||
| 110 | |||
| 111 | if(!is_set || (sk_num(a) < 2)) | ||
| 112 | { | ||
| 113 | for (i=0; i<sk_num(a); i++) | ||
| 114 | i2d(sk_value(a,i),&p); | ||
| 115 | |||
| 116 | *pp=p; | ||
| 117 | return(r); | ||
| 118 | } | ||
| 119 | |||
| 120 | pStart = p; /* Catch the beg of Setblobs*/ | ||
| 121 | /* In this array we will store the SET blobs */ | ||
| 122 | rgSetBlob = (MYBLOB *)OPENSSL_malloc(sk_num(a) * sizeof(MYBLOB)); | ||
| 123 | if (rgSetBlob == NULL) | ||
| 124 | { | ||
| 125 | ASN1err(ASN1_F_I2D_ASN1_SET,ERR_R_MALLOC_FAILURE); | ||
| 126 | return(0); | ||
| 127 | } | ||
| 128 | |||
| 129 | for (i=0; i<sk_num(a); i++) | ||
| 130 | { | ||
| 131 | rgSetBlob[i].pbData = p; /* catch each set encode blob */ | ||
| 132 | i2d(sk_value(a,i),&p); | ||
| 133 | rgSetBlob[i].cbData = p - rgSetBlob[i].pbData; /* Length of this | ||
| 134 | SetBlob | ||
| 135 | */ | ||
| 136 | } | ||
| 137 | *pp=p; | ||
| 138 | totSize = p - pStart; /* This is the total size of all set blobs */ | ||
| 139 | |||
| 140 | /* Now we have to sort the blobs. I am using a simple algo. | ||
| 141 | *Sort ptrs *Copy to temp-mem *Copy from temp-mem to user-mem*/ | ||
| 142 | qsort( rgSetBlob, sk_num(a), sizeof(MYBLOB), SetBlobCmp); | ||
| 143 | if (!(pTempMem = OPENSSL_malloc(totSize))) | ||
| 144 | { | ||
| 145 | ASN1err(ASN1_F_I2D_ASN1_SET,ERR_R_MALLOC_FAILURE); | ||
| 146 | return(0); | ||
| 147 | } | ||
| 148 | |||
| 149 | /* Copy to temp mem */ | ||
| 150 | p = pTempMem; | ||
| 151 | for(i=0; i<sk_num(a); ++i) | ||
| 152 | { | ||
| 153 | memcpy(p, rgSetBlob[i].pbData, rgSetBlob[i].cbData); | ||
| 154 | p += rgSetBlob[i].cbData; | ||
| 155 | } | ||
| 156 | |||
| 157 | /* Copy back to user mem*/ | ||
| 158 | memcpy(pStart, pTempMem, totSize); | ||
| 159 | OPENSSL_free(pTempMem); | ||
| 160 | OPENSSL_free(rgSetBlob); | ||
| 161 | |||
| 162 | return(r); | ||
| 163 | } | ||
| 164 | |||
| 165 | STACK *d2i_ASN1_SET(STACK **a, const unsigned char **pp, long length, | ||
| 166 | d2i_of_void *d2i, void (*free_func)(void *), int ex_tag, | ||
| 167 | int ex_class) | ||
| 168 | { | ||
| 169 | ASN1_const_CTX c; | ||
| 170 | STACK *ret=NULL; | ||
| 171 | |||
| 172 | if ((a == NULL) || ((*a) == NULL)) | ||
| 173 | { | ||
| 174 | if ((ret=sk_new_null()) == NULL) | ||
| 175 | { | ||
| 176 | ASN1err(ASN1_F_D2I_ASN1_SET,ERR_R_MALLOC_FAILURE); | ||
| 177 | goto err; | ||
| 178 | } | ||
| 179 | } | ||
| 180 | else | ||
| 181 | ret=(*a); | ||
| 182 | |||
| 183 | c.p= *pp; | ||
| 184 | c.max=(length == 0)?0:(c.p+length); | ||
| 185 | |||
| 186 | c.inf=ASN1_get_object(&c.p,&c.slen,&c.tag,&c.xclass,c.max-c.p); | ||
| 187 | if (c.inf & 0x80) goto err; | ||
| 188 | if (ex_class != c.xclass) | ||
| 189 | { | ||
| 190 | ASN1err(ASN1_F_D2I_ASN1_SET,ASN1_R_BAD_CLASS); | ||
| 191 | goto err; | ||
| 192 | } | ||
| 193 | if (ex_tag != c.tag) | ||
| 194 | { | ||
| 195 | ASN1err(ASN1_F_D2I_ASN1_SET,ASN1_R_BAD_TAG); | ||
| 196 | goto err; | ||
| 197 | } | ||
| 198 | if ((c.slen+c.p) > c.max) | ||
| 199 | { | ||
| 200 | ASN1err(ASN1_F_D2I_ASN1_SET,ASN1_R_LENGTH_ERROR); | ||
| 201 | goto err; | ||
| 202 | } | ||
| 203 | /* check for infinite constructed - it can be as long | ||
| 204 | * as the amount of data passed to us */ | ||
| 205 | if (c.inf == (V_ASN1_CONSTRUCTED+1)) | ||
| 206 | c.slen=length+ *pp-c.p; | ||
| 207 | c.max=c.p+c.slen; | ||
| 208 | |||
| 209 | while (c.p < c.max) | ||
| 210 | { | ||
| 211 | char *s; | ||
| 212 | |||
| 213 | if (M_ASN1_D2I_end_sequence()) break; | ||
| 214 | /* XXX: This was called with 4 arguments, incorrectly, it seems | ||
| 215 | if ((s=func(NULL,&c.p,c.slen,c.max-c.p)) == NULL) */ | ||
| 216 | if ((s=d2i(NULL,&c.p,c.slen)) == NULL) | ||
| 217 | { | ||
| 218 | ASN1err(ASN1_F_D2I_ASN1_SET,ASN1_R_ERROR_PARSING_SET_ELEMENT); | ||
| 219 | asn1_add_error(*pp,(int)(c.q- *pp)); | ||
| 220 | goto err; | ||
| 221 | } | ||
| 222 | if (!sk_push(ret,s)) goto err; | ||
| 223 | } | ||
| 224 | if (a != NULL) (*a)=ret; | ||
| 225 | *pp=c.p; | ||
| 226 | return(ret); | ||
| 227 | err: | ||
| 228 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) | ||
| 229 | { | ||
| 230 | if (free_func != NULL) | ||
| 231 | sk_pop_free(ret,free_func); | ||
| 232 | else | ||
| 233 | sk_free(ret); | ||
| 234 | } | ||
| 235 | return(NULL); | ||
| 236 | } | ||
| 237 | |||
| 238 | #endif | ||
diff --git a/src/lib/libcrypto/asn1/a_sign.c b/src/lib/libcrypto/asn1/a_sign.c new file mode 100644 index 0000000000..1081950518 --- /dev/null +++ b/src/lib/libcrypto/asn1/a_sign.c | |||
| @@ -0,0 +1,295 @@ | |||
| 1 | /* crypto/asn1/a_sign.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | /* ==================================================================== | ||
| 59 | * Copyright (c) 1998-2003 The OpenSSL Project. All rights reserved. | ||
| 60 | * | ||
| 61 | * Redistribution and use in source and binary forms, with or without | ||
| 62 | * modification, are permitted provided that the following conditions | ||
| 63 | * are met: | ||
| 64 | * | ||
| 65 | * 1. Redistributions of source code must retain the above copyright | ||
| 66 | * notice, this list of conditions and the following disclaimer. | ||
| 67 | * | ||
| 68 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 69 | * notice, this list of conditions and the following disclaimer in | ||
| 70 | * the documentation and/or other materials provided with the | ||
| 71 | * distribution. | ||
| 72 | * | ||
| 73 | * 3. All advertising materials mentioning features or use of this | ||
| 74 | * software must display the following acknowledgment: | ||
| 75 | * "This product includes software developed by the OpenSSL Project | ||
| 76 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
| 77 | * | ||
| 78 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 79 | * endorse or promote products derived from this software without | ||
| 80 | * prior written permission. For written permission, please contact | ||
| 81 | * openssl-core@openssl.org. | ||
| 82 | * | ||
| 83 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 84 | * nor may "OpenSSL" appear in their names without prior written | ||
| 85 | * permission of the OpenSSL Project. | ||
| 86 | * | ||
| 87 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 88 | * acknowledgment: | ||
| 89 | * "This product includes software developed by the OpenSSL Project | ||
| 90 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
| 91 | * | ||
| 92 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 93 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 94 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 95 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 96 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 97 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 98 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 99 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 100 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 101 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 102 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 103 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 104 | * ==================================================================== | ||
| 105 | * | ||
| 106 | * This product includes cryptographic software written by Eric Young | ||
| 107 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 108 | * Hudson (tjh@cryptsoft.com). | ||
| 109 | * | ||
| 110 | */ | ||
| 111 | |||
| 112 | #include <stdio.h> | ||
| 113 | #include <time.h> | ||
| 114 | |||
| 115 | #include "cryptlib.h" | ||
| 116 | |||
| 117 | #ifndef NO_SYS_TYPES_H | ||
| 118 | # include <sys/types.h> | ||
| 119 | #endif | ||
| 120 | |||
| 121 | #include <openssl/bn.h> | ||
| 122 | #include <openssl/evp.h> | ||
| 123 | #include <openssl/x509.h> | ||
| 124 | #include <openssl/objects.h> | ||
| 125 | #include <openssl/buffer.h> | ||
| 126 | |||
| 127 | #ifndef NO_ASN1_OLD | ||
| 128 | |||
| 129 | int ASN1_sign(i2d_of_void *i2d, X509_ALGOR *algor1, X509_ALGOR *algor2, | ||
| 130 | ASN1_BIT_STRING *signature, char *data, EVP_PKEY *pkey, | ||
| 131 | const EVP_MD *type) | ||
| 132 | { | ||
| 133 | EVP_MD_CTX ctx; | ||
| 134 | unsigned char *p,*buf_in=NULL,*buf_out=NULL; | ||
| 135 | int i,inl=0,outl=0,outll=0; | ||
| 136 | X509_ALGOR *a; | ||
| 137 | |||
| 138 | EVP_MD_CTX_init(&ctx); | ||
| 139 | for (i=0; i<2; i++) | ||
| 140 | { | ||
| 141 | if (i == 0) | ||
| 142 | a=algor1; | ||
| 143 | else | ||
| 144 | a=algor2; | ||
| 145 | if (a == NULL) continue; | ||
| 146 | if (type->pkey_type == NID_dsaWithSHA1) | ||
| 147 | { | ||
| 148 | /* special case: RFC 2459 tells us to omit 'parameters' | ||
| 149 | * with id-dsa-with-sha1 */ | ||
| 150 | ASN1_TYPE_free(a->parameter); | ||
| 151 | a->parameter = NULL; | ||
| 152 | } | ||
| 153 | else if ((a->parameter == NULL) || | ||
| 154 | (a->parameter->type != V_ASN1_NULL)) | ||
| 155 | { | ||
| 156 | ASN1_TYPE_free(a->parameter); | ||
| 157 | if ((a->parameter=ASN1_TYPE_new()) == NULL) goto err; | ||
| 158 | a->parameter->type=V_ASN1_NULL; | ||
| 159 | } | ||
| 160 | ASN1_OBJECT_free(a->algorithm); | ||
| 161 | a->algorithm=OBJ_nid2obj(type->pkey_type); | ||
| 162 | if (a->algorithm == NULL) | ||
| 163 | { | ||
| 164 | ASN1err(ASN1_F_ASN1_SIGN,ASN1_R_UNKNOWN_OBJECT_TYPE); | ||
| 165 | goto err; | ||
| 166 | } | ||
| 167 | if (a->algorithm->length == 0) | ||
| 168 | { | ||
| 169 | ASN1err(ASN1_F_ASN1_SIGN,ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD); | ||
| 170 | goto err; | ||
| 171 | } | ||
| 172 | } | ||
| 173 | inl=i2d(data,NULL); | ||
| 174 | buf_in=(unsigned char *)OPENSSL_malloc((unsigned int)inl); | ||
| 175 | outll=outl=EVP_PKEY_size(pkey); | ||
| 176 | buf_out=(unsigned char *)OPENSSL_malloc((unsigned int)outl); | ||
| 177 | if ((buf_in == NULL) || (buf_out == NULL)) | ||
| 178 | { | ||
| 179 | outl=0; | ||
| 180 | ASN1err(ASN1_F_ASN1_SIGN,ERR_R_MALLOC_FAILURE); | ||
| 181 | goto err; | ||
| 182 | } | ||
| 183 | p=buf_in; | ||
| 184 | |||
| 185 | i2d(data,&p); | ||
| 186 | EVP_SignInit_ex(&ctx,type, NULL); | ||
| 187 | EVP_SignUpdate(&ctx,(unsigned char *)buf_in,inl); | ||
| 188 | if (!EVP_SignFinal(&ctx,(unsigned char *)buf_out, | ||
| 189 | (unsigned int *)&outl,pkey)) | ||
| 190 | { | ||
| 191 | outl=0; | ||
| 192 | ASN1err(ASN1_F_ASN1_SIGN,ERR_R_EVP_LIB); | ||
| 193 | goto err; | ||
| 194 | } | ||
| 195 | if (signature->data != NULL) OPENSSL_free(signature->data); | ||
| 196 | signature->data=buf_out; | ||
| 197 | buf_out=NULL; | ||
| 198 | signature->length=outl; | ||
| 199 | /* In the interests of compatibility, I'll make sure that | ||
| 200 | * the bit string has a 'not-used bits' value of 0 | ||
| 201 | */ | ||
| 202 | signature->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); | ||
| 203 | signature->flags|=ASN1_STRING_FLAG_BITS_LEFT; | ||
| 204 | err: | ||
| 205 | EVP_MD_CTX_cleanup(&ctx); | ||
| 206 | if (buf_in != NULL) | ||
| 207 | { OPENSSL_cleanse((char *)buf_in,(unsigned int)inl); OPENSSL_free(buf_in); } | ||
| 208 | if (buf_out != NULL) | ||
| 209 | { OPENSSL_cleanse((char *)buf_out,outll); OPENSSL_free(buf_out); } | ||
| 210 | return(outl); | ||
| 211 | } | ||
| 212 | |||
| 213 | #endif | ||
| 214 | |||
| 215 | int ASN1_item_sign(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2, | ||
| 216 | ASN1_BIT_STRING *signature, void *asn, EVP_PKEY *pkey, | ||
| 217 | const EVP_MD *type) | ||
| 218 | { | ||
| 219 | EVP_MD_CTX ctx; | ||
| 220 | unsigned char *buf_in=NULL,*buf_out=NULL; | ||
| 221 | int i,inl=0,outl=0,outll=0; | ||
| 222 | X509_ALGOR *a; | ||
| 223 | |||
| 224 | EVP_MD_CTX_init(&ctx); | ||
| 225 | for (i=0; i<2; i++) | ||
| 226 | { | ||
| 227 | if (i == 0) | ||
| 228 | a=algor1; | ||
| 229 | else | ||
| 230 | a=algor2; | ||
| 231 | if (a == NULL) continue; | ||
| 232 | if (type->pkey_type == NID_dsaWithSHA1 || | ||
| 233 | type->pkey_type == NID_ecdsa_with_SHA1) | ||
| 234 | { | ||
| 235 | /* special case: RFC 3279 tells us to omit 'parameters' | ||
| 236 | * with id-dsa-with-sha1 and ecdsa-with-SHA1 */ | ||
| 237 | ASN1_TYPE_free(a->parameter); | ||
| 238 | a->parameter = NULL; | ||
| 239 | } | ||
| 240 | else if ((a->parameter == NULL) || | ||
| 241 | (a->parameter->type != V_ASN1_NULL)) | ||
| 242 | { | ||
| 243 | ASN1_TYPE_free(a->parameter); | ||
| 244 | if ((a->parameter=ASN1_TYPE_new()) == NULL) goto err; | ||
| 245 | a->parameter->type=V_ASN1_NULL; | ||
| 246 | } | ||
| 247 | ASN1_OBJECT_free(a->algorithm); | ||
| 248 | a->algorithm=OBJ_nid2obj(type->pkey_type); | ||
| 249 | if (a->algorithm == NULL) | ||
| 250 | { | ||
| 251 | ASN1err(ASN1_F_ASN1_ITEM_SIGN,ASN1_R_UNKNOWN_OBJECT_TYPE); | ||
| 252 | goto err; | ||
| 253 | } | ||
| 254 | if (a->algorithm->length == 0) | ||
| 255 | { | ||
| 256 | ASN1err(ASN1_F_ASN1_ITEM_SIGN,ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD); | ||
| 257 | goto err; | ||
| 258 | } | ||
| 259 | } | ||
| 260 | inl=ASN1_item_i2d(asn,&buf_in, it); | ||
| 261 | outll=outl=EVP_PKEY_size(pkey); | ||
| 262 | buf_out=(unsigned char *)OPENSSL_malloc((unsigned int)outl); | ||
| 263 | if ((buf_in == NULL) || (buf_out == NULL)) | ||
| 264 | { | ||
| 265 | outl=0; | ||
| 266 | ASN1err(ASN1_F_ASN1_ITEM_SIGN,ERR_R_MALLOC_FAILURE); | ||
| 267 | goto err; | ||
| 268 | } | ||
| 269 | |||
| 270 | EVP_SignInit_ex(&ctx,type, NULL); | ||
| 271 | EVP_SignUpdate(&ctx,(unsigned char *)buf_in,inl); | ||
| 272 | if (!EVP_SignFinal(&ctx,(unsigned char *)buf_out, | ||
| 273 | (unsigned int *)&outl,pkey)) | ||
| 274 | { | ||
| 275 | outl=0; | ||
| 276 | ASN1err(ASN1_F_ASN1_ITEM_SIGN,ERR_R_EVP_LIB); | ||
| 277 | goto err; | ||
| 278 | } | ||
| 279 | if (signature->data != NULL) OPENSSL_free(signature->data); | ||
| 280 | signature->data=buf_out; | ||
| 281 | buf_out=NULL; | ||
| 282 | signature->length=outl; | ||
| 283 | /* In the interests of compatibility, I'll make sure that | ||
| 284 | * the bit string has a 'not-used bits' value of 0 | ||
| 285 | */ | ||
| 286 | signature->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); | ||
| 287 | signature->flags|=ASN1_STRING_FLAG_BITS_LEFT; | ||
| 288 | err: | ||
| 289 | EVP_MD_CTX_cleanup(&ctx); | ||
| 290 | if (buf_in != NULL) | ||
| 291 | { OPENSSL_cleanse((char *)buf_in,(unsigned int)inl); OPENSSL_free(buf_in); } | ||
| 292 | if (buf_out != NULL) | ||
| 293 | { OPENSSL_cleanse((char *)buf_out,outll); OPENSSL_free(buf_out); } | ||
| 294 | return(outl); | ||
| 295 | } | ||
diff --git a/src/lib/libcrypto/asn1/a_strex.c b/src/lib/libcrypto/asn1/a_strex.c new file mode 100644 index 0000000000..c2dbb6f9a5 --- /dev/null +++ b/src/lib/libcrypto/asn1/a_strex.c | |||
| @@ -0,0 +1,567 @@ | |||
| 1 | /* a_strex.c */ | ||
| 2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
| 3 | * project 2000. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 2000 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include <string.h> | ||
| 61 | #include "cryptlib.h" | ||
| 62 | #include <openssl/crypto.h> | ||
| 63 | #include <openssl/x509.h> | ||
| 64 | #include <openssl/asn1.h> | ||
| 65 | |||
| 66 | #include "charmap.h" | ||
| 67 | |||
| 68 | /* ASN1_STRING_print_ex() and X509_NAME_print_ex(). | ||
| 69 | * Enhanced string and name printing routines handling | ||
| 70 | * multibyte characters, RFC2253 and a host of other | ||
| 71 | * options. | ||
| 72 | */ | ||
| 73 | |||
| 74 | |||
| 75 | #define CHARTYPE_BS_ESC (ASN1_STRFLGS_ESC_2253 | CHARTYPE_FIRST_ESC_2253 | CHARTYPE_LAST_ESC_2253) | ||
| 76 | |||
| 77 | |||
| 78 | /* Three IO functions for sending data to memory, a BIO and | ||
| 79 | * and a FILE pointer. | ||
| 80 | */ | ||
| 81 | #if 0 /* never used */ | ||
| 82 | static int send_mem_chars(void *arg, const void *buf, int len) | ||
| 83 | { | ||
| 84 | unsigned char **out = arg; | ||
| 85 | if(!out) return 1; | ||
| 86 | memcpy(*out, buf, len); | ||
| 87 | *out += len; | ||
| 88 | return 1; | ||
| 89 | } | ||
| 90 | #endif | ||
| 91 | |||
| 92 | static int send_bio_chars(void *arg, const void *buf, int len) | ||
| 93 | { | ||
| 94 | if(!arg) return 1; | ||
| 95 | if(BIO_write(arg, buf, len) != len) return 0; | ||
| 96 | return 1; | ||
| 97 | } | ||
| 98 | |||
| 99 | static int send_fp_chars(void *arg, const void *buf, int len) | ||
| 100 | { | ||
| 101 | if(!arg) return 1; | ||
| 102 | if(fwrite(buf, 1, len, arg) != (unsigned int)len) return 0; | ||
| 103 | return 1; | ||
| 104 | } | ||
| 105 | |||
| 106 | typedef int char_io(void *arg, const void *buf, int len); | ||
| 107 | |||
| 108 | /* This function handles display of | ||
| 109 | * strings, one character at a time. | ||
| 110 | * It is passed an unsigned long for each | ||
| 111 | * character because it could come from 2 or even | ||
| 112 | * 4 byte forms. | ||
| 113 | */ | ||
| 114 | |||
| 115 | static int do_esc_char(unsigned long c, unsigned char flags, char *do_quotes, char_io *io_ch, void *arg) | ||
| 116 | { | ||
| 117 | unsigned char chflgs, chtmp; | ||
| 118 | char tmphex[HEX_SIZE(long)+3]; | ||
| 119 | |||
| 120 | if(c > 0xffffffffL) | ||
| 121 | return -1; | ||
| 122 | if(c > 0xffff) { | ||
| 123 | BIO_snprintf(tmphex, sizeof tmphex, "\\W%08lX", c); | ||
| 124 | if(!io_ch(arg, tmphex, 10)) return -1; | ||
| 125 | return 10; | ||
| 126 | } | ||
| 127 | if(c > 0xff) { | ||
| 128 | BIO_snprintf(tmphex, sizeof tmphex, "\\U%04lX", c); | ||
| 129 | if(!io_ch(arg, tmphex, 6)) return -1; | ||
| 130 | return 6; | ||
| 131 | } | ||
| 132 | chtmp = (unsigned char)c; | ||
| 133 | if(chtmp > 0x7f) chflgs = flags & ASN1_STRFLGS_ESC_MSB; | ||
| 134 | else chflgs = char_type[chtmp] & flags; | ||
| 135 | if(chflgs & CHARTYPE_BS_ESC) { | ||
| 136 | /* If we don't escape with quotes, signal we need quotes */ | ||
| 137 | if(chflgs & ASN1_STRFLGS_ESC_QUOTE) { | ||
| 138 | if(do_quotes) *do_quotes = 1; | ||
| 139 | if(!io_ch(arg, &chtmp, 1)) return -1; | ||
| 140 | return 1; | ||
| 141 | } | ||
| 142 | if(!io_ch(arg, "\\", 1)) return -1; | ||
| 143 | if(!io_ch(arg, &chtmp, 1)) return -1; | ||
| 144 | return 2; | ||
| 145 | } | ||
| 146 | if(chflgs & (ASN1_STRFLGS_ESC_CTRL|ASN1_STRFLGS_ESC_MSB)) { | ||
| 147 | BIO_snprintf(tmphex, 11, "\\%02X", chtmp); | ||
| 148 | if(!io_ch(arg, tmphex, 3)) return -1; | ||
| 149 | return 3; | ||
| 150 | } | ||
| 151 | if(!io_ch(arg, &chtmp, 1)) return -1; | ||
| 152 | return 1; | ||
| 153 | } | ||
| 154 | |||
| 155 | #define BUF_TYPE_WIDTH_MASK 0x7 | ||
| 156 | #define BUF_TYPE_CONVUTF8 0x8 | ||
| 157 | |||
| 158 | /* This function sends each character in a buffer to | ||
| 159 | * do_esc_char(). It interprets the content formats | ||
| 160 | * and converts to or from UTF8 as appropriate. | ||
| 161 | */ | ||
| 162 | |||
| 163 | static int do_buf(unsigned char *buf, int buflen, | ||
| 164 | int type, unsigned char flags, char *quotes, char_io *io_ch, void *arg) | ||
| 165 | { | ||
| 166 | int i, outlen, len; | ||
| 167 | unsigned char orflags, *p, *q; | ||
| 168 | unsigned long c; | ||
| 169 | p = buf; | ||
| 170 | q = buf + buflen; | ||
| 171 | outlen = 0; | ||
| 172 | while(p != q) { | ||
| 173 | if(p == buf && flags & ASN1_STRFLGS_ESC_2253) orflags = CHARTYPE_FIRST_ESC_2253; | ||
| 174 | else orflags = 0; | ||
| 175 | switch(type & BUF_TYPE_WIDTH_MASK) { | ||
| 176 | case 4: | ||
| 177 | c = ((unsigned long)*p++) << 24; | ||
| 178 | c |= ((unsigned long)*p++) << 16; | ||
| 179 | c |= ((unsigned long)*p++) << 8; | ||
| 180 | c |= *p++; | ||
| 181 | break; | ||
| 182 | |||
| 183 | case 2: | ||
| 184 | c = ((unsigned long)*p++) << 8; | ||
| 185 | c |= *p++; | ||
| 186 | break; | ||
| 187 | |||
| 188 | case 1: | ||
| 189 | c = *p++; | ||
| 190 | break; | ||
| 191 | |||
| 192 | case 0: | ||
| 193 | i = UTF8_getc(p, buflen, &c); | ||
| 194 | if(i < 0) return -1; /* Invalid UTF8String */ | ||
| 195 | p += i; | ||
| 196 | break; | ||
| 197 | default: | ||
| 198 | return -1; /* invalid width */ | ||
| 199 | } | ||
| 200 | if (p == q && flags & ASN1_STRFLGS_ESC_2253) orflags = CHARTYPE_LAST_ESC_2253; | ||
| 201 | if(type & BUF_TYPE_CONVUTF8) { | ||
| 202 | unsigned char utfbuf[6]; | ||
| 203 | int utflen; | ||
| 204 | utflen = UTF8_putc(utfbuf, sizeof utfbuf, c); | ||
| 205 | for(i = 0; i < utflen; i++) { | ||
| 206 | /* We don't need to worry about setting orflags correctly | ||
| 207 | * because if utflen==1 its value will be correct anyway | ||
| 208 | * otherwise each character will be > 0x7f and so the | ||
| 209 | * character will never be escaped on first and last. | ||
| 210 | */ | ||
| 211 | len = do_esc_char(utfbuf[i], (unsigned char)(flags | orflags), quotes, io_ch, arg); | ||
| 212 | if(len < 0) return -1; | ||
| 213 | outlen += len; | ||
| 214 | } | ||
| 215 | } else { | ||
| 216 | len = do_esc_char(c, (unsigned char)(flags | orflags), quotes, io_ch, arg); | ||
| 217 | if(len < 0) return -1; | ||
| 218 | outlen += len; | ||
| 219 | } | ||
| 220 | } | ||
| 221 | return outlen; | ||
| 222 | } | ||
| 223 | |||
| 224 | /* This function hex dumps a buffer of characters */ | ||
| 225 | |||
| 226 | static int do_hex_dump(char_io *io_ch, void *arg, unsigned char *buf, int buflen) | ||
| 227 | { | ||
| 228 | static const char hexdig[] = "0123456789ABCDEF"; | ||
| 229 | unsigned char *p, *q; | ||
| 230 | char hextmp[2]; | ||
| 231 | if(arg) { | ||
| 232 | p = buf; | ||
| 233 | q = buf + buflen; | ||
| 234 | while(p != q) { | ||
| 235 | hextmp[0] = hexdig[*p >> 4]; | ||
| 236 | hextmp[1] = hexdig[*p & 0xf]; | ||
| 237 | if(!io_ch(arg, hextmp, 2)) return -1; | ||
| 238 | p++; | ||
| 239 | } | ||
| 240 | } | ||
| 241 | return buflen << 1; | ||
| 242 | } | ||
| 243 | |||
| 244 | /* "dump" a string. This is done when the type is unknown, | ||
| 245 | * or the flags request it. We can either dump the content | ||
| 246 | * octets or the entire DER encoding. This uses the RFC2253 | ||
| 247 | * #01234 format. | ||
| 248 | */ | ||
| 249 | |||
| 250 | static int do_dump(unsigned long lflags, char_io *io_ch, void *arg, ASN1_STRING *str) | ||
| 251 | { | ||
| 252 | /* Placing the ASN1_STRING in a temp ASN1_TYPE allows | ||
| 253 | * the DER encoding to readily obtained | ||
| 254 | */ | ||
| 255 | ASN1_TYPE t; | ||
| 256 | unsigned char *der_buf, *p; | ||
| 257 | int outlen, der_len; | ||
| 258 | |||
| 259 | if(!io_ch(arg, "#", 1)) return -1; | ||
| 260 | /* If we don't dump DER encoding just dump content octets */ | ||
| 261 | if(!(lflags & ASN1_STRFLGS_DUMP_DER)) { | ||
| 262 | outlen = do_hex_dump(io_ch, arg, str->data, str->length); | ||
| 263 | if(outlen < 0) return -1; | ||
| 264 | return outlen + 1; | ||
| 265 | } | ||
| 266 | t.type = str->type; | ||
| 267 | t.value.ptr = (char *)str; | ||
| 268 | der_len = i2d_ASN1_TYPE(&t, NULL); | ||
| 269 | der_buf = OPENSSL_malloc(der_len); | ||
| 270 | if(!der_buf) return -1; | ||
| 271 | p = der_buf; | ||
| 272 | i2d_ASN1_TYPE(&t, &p); | ||
| 273 | outlen = do_hex_dump(io_ch, arg, der_buf, der_len); | ||
| 274 | OPENSSL_free(der_buf); | ||
| 275 | if(outlen < 0) return -1; | ||
| 276 | return outlen + 1; | ||
| 277 | } | ||
| 278 | |||
| 279 | /* Lookup table to convert tags to character widths, | ||
| 280 | * 0 = UTF8 encoded, -1 is used for non string types | ||
| 281 | * otherwise it is the number of bytes per character | ||
| 282 | */ | ||
| 283 | |||
| 284 | static const signed char tag2nbyte[] = { | ||
| 285 | -1, -1, -1, -1, -1, /* 0-4 */ | ||
| 286 | -1, -1, -1, -1, -1, /* 5-9 */ | ||
| 287 | -1, -1, 0, -1, /* 10-13 */ | ||
| 288 | -1, -1, -1, -1, /* 15-17 */ | ||
| 289 | -1, 1, 1, /* 18-20 */ | ||
| 290 | -1, 1, 1, 1, /* 21-24 */ | ||
| 291 | -1, 1, -1, /* 25-27 */ | ||
| 292 | 4, -1, 2 /* 28-30 */ | ||
| 293 | }; | ||
| 294 | |||
| 295 | #define ESC_FLAGS (ASN1_STRFLGS_ESC_2253 | \ | ||
| 296 | ASN1_STRFLGS_ESC_QUOTE | \ | ||
| 297 | ASN1_STRFLGS_ESC_CTRL | \ | ||
| 298 | ASN1_STRFLGS_ESC_MSB) | ||
| 299 | |||
| 300 | /* This is the main function, print out an | ||
| 301 | * ASN1_STRING taking note of various escape | ||
| 302 | * and display options. Returns number of | ||
| 303 | * characters written or -1 if an error | ||
| 304 | * occurred. | ||
| 305 | */ | ||
| 306 | |||
| 307 | static int do_print_ex(char_io *io_ch, void *arg, unsigned long lflags, ASN1_STRING *str) | ||
| 308 | { | ||
| 309 | int outlen, len; | ||
| 310 | int type; | ||
| 311 | char quotes; | ||
| 312 | unsigned char flags; | ||
| 313 | quotes = 0; | ||
| 314 | /* Keep a copy of escape flags */ | ||
| 315 | flags = (unsigned char)(lflags & ESC_FLAGS); | ||
| 316 | |||
| 317 | type = str->type; | ||
| 318 | |||
| 319 | outlen = 0; | ||
| 320 | |||
| 321 | |||
| 322 | if(lflags & ASN1_STRFLGS_SHOW_TYPE) { | ||
| 323 | const char *tagname; | ||
| 324 | tagname = ASN1_tag2str(type); | ||
| 325 | outlen += strlen(tagname); | ||
| 326 | if(!io_ch(arg, tagname, outlen) || !io_ch(arg, ":", 1)) return -1; | ||
| 327 | outlen++; | ||
| 328 | } | ||
| 329 | |||
| 330 | /* Decide what to do with type, either dump content or display it */ | ||
| 331 | |||
| 332 | /* Dump everything */ | ||
| 333 | if(lflags & ASN1_STRFLGS_DUMP_ALL) type = -1; | ||
| 334 | /* Ignore the string type */ | ||
| 335 | else if(lflags & ASN1_STRFLGS_IGNORE_TYPE) type = 1; | ||
| 336 | else { | ||
| 337 | /* Else determine width based on type */ | ||
| 338 | if((type > 0) && (type < 31)) type = tag2nbyte[type]; | ||
| 339 | else type = -1; | ||
| 340 | if((type == -1) && !(lflags & ASN1_STRFLGS_DUMP_UNKNOWN)) type = 1; | ||
| 341 | } | ||
| 342 | |||
| 343 | if(type == -1) { | ||
| 344 | len = do_dump(lflags, io_ch, arg, str); | ||
| 345 | if(len < 0) return -1; | ||
| 346 | outlen += len; | ||
| 347 | return outlen; | ||
| 348 | } | ||
| 349 | |||
| 350 | if(lflags & ASN1_STRFLGS_UTF8_CONVERT) { | ||
| 351 | /* Note: if string is UTF8 and we want | ||
| 352 | * to convert to UTF8 then we just interpret | ||
| 353 | * it as 1 byte per character to avoid converting | ||
| 354 | * twice. | ||
| 355 | */ | ||
| 356 | if(!type) type = 1; | ||
| 357 | else type |= BUF_TYPE_CONVUTF8; | ||
| 358 | } | ||
| 359 | |||
| 360 | len = do_buf(str->data, str->length, type, flags, "es, io_ch, NULL); | ||
| 361 | if(len < 0) return -1; | ||
| 362 | outlen += len; | ||
| 363 | if(quotes) outlen += 2; | ||
| 364 | if(!arg) return outlen; | ||
| 365 | if(quotes && !io_ch(arg, "\"", 1)) return -1; | ||
| 366 | if(do_buf(str->data, str->length, type, flags, NULL, io_ch, arg) < 0) | ||
| 367 | return -1; | ||
| 368 | if(quotes && !io_ch(arg, "\"", 1)) return -1; | ||
| 369 | return outlen; | ||
| 370 | } | ||
| 371 | |||
| 372 | /* Used for line indenting: print 'indent' spaces */ | ||
| 373 | |||
| 374 | static int do_indent(char_io *io_ch, void *arg, int indent) | ||
| 375 | { | ||
| 376 | int i; | ||
| 377 | for(i = 0; i < indent; i++) | ||
| 378 | if(!io_ch(arg, " ", 1)) return 0; | ||
| 379 | return 1; | ||
| 380 | } | ||
| 381 | |||
| 382 | #define FN_WIDTH_LN 25 | ||
| 383 | #define FN_WIDTH_SN 10 | ||
| 384 | |||
| 385 | static int do_name_ex(char_io *io_ch, void *arg, X509_NAME *n, | ||
| 386 | int indent, unsigned long flags) | ||
| 387 | { | ||
| 388 | int i, prev = -1, orflags, cnt; | ||
| 389 | int fn_opt, fn_nid; | ||
| 390 | ASN1_OBJECT *fn; | ||
| 391 | ASN1_STRING *val; | ||
| 392 | X509_NAME_ENTRY *ent; | ||
| 393 | char objtmp[80]; | ||
| 394 | const char *objbuf; | ||
| 395 | int outlen, len; | ||
| 396 | char *sep_dn, *sep_mv, *sep_eq; | ||
| 397 | int sep_dn_len, sep_mv_len, sep_eq_len; | ||
| 398 | if(indent < 0) indent = 0; | ||
| 399 | outlen = indent; | ||
| 400 | if(!do_indent(io_ch, arg, indent)) return -1; | ||
| 401 | switch (flags & XN_FLAG_SEP_MASK) | ||
| 402 | { | ||
| 403 | case XN_FLAG_SEP_MULTILINE: | ||
| 404 | sep_dn = "\n"; | ||
| 405 | sep_dn_len = 1; | ||
| 406 | sep_mv = " + "; | ||
| 407 | sep_mv_len = 3; | ||
| 408 | break; | ||
| 409 | |||
| 410 | case XN_FLAG_SEP_COMMA_PLUS: | ||
| 411 | sep_dn = ","; | ||
| 412 | sep_dn_len = 1; | ||
| 413 | sep_mv = "+"; | ||
| 414 | sep_mv_len = 1; | ||
| 415 | indent = 0; | ||
| 416 | break; | ||
| 417 | |||
| 418 | case XN_FLAG_SEP_CPLUS_SPC: | ||
| 419 | sep_dn = ", "; | ||
| 420 | sep_dn_len = 2; | ||
| 421 | sep_mv = " + "; | ||
| 422 | sep_mv_len = 3; | ||
| 423 | indent = 0; | ||
| 424 | break; | ||
| 425 | |||
| 426 | case XN_FLAG_SEP_SPLUS_SPC: | ||
| 427 | sep_dn = "; "; | ||
| 428 | sep_dn_len = 2; | ||
| 429 | sep_mv = " + "; | ||
| 430 | sep_mv_len = 3; | ||
| 431 | indent = 0; | ||
| 432 | break; | ||
| 433 | |||
| 434 | default: | ||
| 435 | return -1; | ||
| 436 | } | ||
| 437 | |||
| 438 | if(flags & XN_FLAG_SPC_EQ) { | ||
| 439 | sep_eq = " = "; | ||
| 440 | sep_eq_len = 3; | ||
| 441 | } else { | ||
| 442 | sep_eq = "="; | ||
| 443 | sep_eq_len = 1; | ||
| 444 | } | ||
| 445 | |||
| 446 | fn_opt = flags & XN_FLAG_FN_MASK; | ||
| 447 | |||
| 448 | cnt = X509_NAME_entry_count(n); | ||
| 449 | for(i = 0; i < cnt; i++) { | ||
| 450 | if(flags & XN_FLAG_DN_REV) | ||
| 451 | ent = X509_NAME_get_entry(n, cnt - i - 1); | ||
| 452 | else ent = X509_NAME_get_entry(n, i); | ||
| 453 | if(prev != -1) { | ||
| 454 | if(prev == ent->set) { | ||
| 455 | if(!io_ch(arg, sep_mv, sep_mv_len)) return -1; | ||
| 456 | outlen += sep_mv_len; | ||
| 457 | } else { | ||
| 458 | if(!io_ch(arg, sep_dn, sep_dn_len)) return -1; | ||
| 459 | outlen += sep_dn_len; | ||
| 460 | if(!do_indent(io_ch, arg, indent)) return -1; | ||
| 461 | outlen += indent; | ||
| 462 | } | ||
| 463 | } | ||
| 464 | prev = ent->set; | ||
| 465 | fn = X509_NAME_ENTRY_get_object(ent); | ||
| 466 | val = X509_NAME_ENTRY_get_data(ent); | ||
| 467 | fn_nid = OBJ_obj2nid(fn); | ||
| 468 | if(fn_opt != XN_FLAG_FN_NONE) { | ||
| 469 | int objlen, fld_len; | ||
| 470 | if((fn_opt == XN_FLAG_FN_OID) || (fn_nid==NID_undef) ) { | ||
| 471 | OBJ_obj2txt(objtmp, sizeof objtmp, fn, 1); | ||
| 472 | fld_len = 0; /* XXX: what should this be? */ | ||
| 473 | objbuf = objtmp; | ||
| 474 | } else { | ||
| 475 | if(fn_opt == XN_FLAG_FN_SN) { | ||
| 476 | fld_len = FN_WIDTH_SN; | ||
| 477 | objbuf = OBJ_nid2sn(fn_nid); | ||
| 478 | } else if(fn_opt == XN_FLAG_FN_LN) { | ||
| 479 | fld_len = FN_WIDTH_LN; | ||
| 480 | objbuf = OBJ_nid2ln(fn_nid); | ||
| 481 | } else { | ||
| 482 | fld_len = 0; /* XXX: what should this be? */ | ||
| 483 | objbuf = ""; | ||
| 484 | } | ||
| 485 | } | ||
| 486 | objlen = strlen(objbuf); | ||
| 487 | if(!io_ch(arg, objbuf, objlen)) return -1; | ||
| 488 | if ((objlen < fld_len) && (flags & XN_FLAG_FN_ALIGN)) { | ||
| 489 | if (!do_indent(io_ch, arg, fld_len - objlen)) return -1; | ||
| 490 | outlen += fld_len - objlen; | ||
| 491 | } | ||
| 492 | if(!io_ch(arg, sep_eq, sep_eq_len)) return -1; | ||
| 493 | outlen += objlen + sep_eq_len; | ||
| 494 | } | ||
| 495 | /* If the field name is unknown then fix up the DER dump | ||
| 496 | * flag. We might want to limit this further so it will | ||
| 497 | * DER dump on anything other than a few 'standard' fields. | ||
| 498 | */ | ||
| 499 | if((fn_nid == NID_undef) && (flags & XN_FLAG_DUMP_UNKNOWN_FIELDS)) | ||
| 500 | orflags = ASN1_STRFLGS_DUMP_ALL; | ||
| 501 | else orflags = 0; | ||
| 502 | |||
| 503 | len = do_print_ex(io_ch, arg, flags | orflags, val); | ||
| 504 | if(len < 0) return -1; | ||
| 505 | outlen += len; | ||
| 506 | } | ||
| 507 | return outlen; | ||
| 508 | } | ||
| 509 | |||
| 510 | /* Wrappers round the main functions */ | ||
| 511 | |||
| 512 | int X509_NAME_print_ex(BIO *out, X509_NAME *nm, int indent, unsigned long flags) | ||
| 513 | { | ||
| 514 | if(flags == XN_FLAG_COMPAT) | ||
| 515 | return X509_NAME_print(out, nm, indent); | ||
| 516 | return do_name_ex(send_bio_chars, out, nm, indent, flags); | ||
| 517 | } | ||
| 518 | |||
| 519 | #ifndef OPENSSL_NO_FP_API | ||
| 520 | int X509_NAME_print_ex_fp(FILE *fp, X509_NAME *nm, int indent, unsigned long flags) | ||
| 521 | { | ||
| 522 | if(flags == XN_FLAG_COMPAT) | ||
| 523 | { | ||
| 524 | BIO *btmp; | ||
| 525 | int ret; | ||
| 526 | btmp = BIO_new_fp(fp, BIO_NOCLOSE); | ||
| 527 | if(!btmp) return -1; | ||
| 528 | ret = X509_NAME_print(btmp, nm, indent); | ||
| 529 | BIO_free(btmp); | ||
| 530 | return ret; | ||
| 531 | } | ||
| 532 | return do_name_ex(send_fp_chars, fp, nm, indent, flags); | ||
| 533 | } | ||
| 534 | #endif | ||
| 535 | |||
| 536 | int ASN1_STRING_print_ex(BIO *out, ASN1_STRING *str, unsigned long flags) | ||
| 537 | { | ||
| 538 | return do_print_ex(send_bio_chars, out, flags, str); | ||
| 539 | } | ||
| 540 | |||
| 541 | #ifndef OPENSSL_NO_FP_API | ||
| 542 | int ASN1_STRING_print_ex_fp(FILE *fp, ASN1_STRING *str, unsigned long flags) | ||
| 543 | { | ||
| 544 | return do_print_ex(send_fp_chars, fp, flags, str); | ||
| 545 | } | ||
| 546 | #endif | ||
| 547 | |||
| 548 | /* Utility function: convert any string type to UTF8, returns number of bytes | ||
| 549 | * in output string or a negative error code | ||
| 550 | */ | ||
| 551 | |||
| 552 | int ASN1_STRING_to_UTF8(unsigned char **out, ASN1_STRING *in) | ||
| 553 | { | ||
| 554 | ASN1_STRING stmp, *str = &stmp; | ||
| 555 | int mbflag, type, ret; | ||
| 556 | if(!in) return -1; | ||
| 557 | type = in->type; | ||
| 558 | if((type < 0) || (type > 30)) return -1; | ||
| 559 | mbflag = tag2nbyte[type]; | ||
| 560 | if(mbflag == -1) return -1; | ||
| 561 | mbflag |= MBSTRING_FLAG; | ||
| 562 | stmp.data = NULL; | ||
| 563 | ret = ASN1_mbstring_copy(&str, in->data, in->length, mbflag, B_ASN1_UTF8STRING); | ||
| 564 | if(ret < 0) return ret; | ||
| 565 | *out = stmp.data; | ||
| 566 | return stmp.length; | ||
| 567 | } | ||
diff --git a/src/lib/libcrypto/asn1/a_strnid.c b/src/lib/libcrypto/asn1/a_strnid.c new file mode 100644 index 0000000000..613bbc4a7d --- /dev/null +++ b/src/lib/libcrypto/asn1/a_strnid.c | |||
| @@ -0,0 +1,290 @@ | |||
| 1 | /* a_strnid.c */ | ||
| 2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
| 3 | * project 1999. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include <ctype.h> | ||
| 61 | #include "cryptlib.h" | ||
| 62 | #include <openssl/asn1.h> | ||
| 63 | #include <openssl/objects.h> | ||
| 64 | |||
| 65 | |||
| 66 | static STACK_OF(ASN1_STRING_TABLE) *stable = NULL; | ||
| 67 | static void st_free(ASN1_STRING_TABLE *tbl); | ||
| 68 | static int sk_table_cmp(const ASN1_STRING_TABLE * const *a, | ||
| 69 | const ASN1_STRING_TABLE * const *b); | ||
| 70 | static int table_cmp(const void *a, const void *b); | ||
| 71 | |||
| 72 | |||
| 73 | /* This is the global mask for the mbstring functions: this is use to | ||
| 74 | * mask out certain types (such as BMPString and UTF8String) because | ||
| 75 | * certain software (e.g. Netscape) has problems with them. | ||
| 76 | */ | ||
| 77 | |||
| 78 | static unsigned long global_mask = 0xFFFFFFFFL; | ||
| 79 | |||
| 80 | void ASN1_STRING_set_default_mask(unsigned long mask) | ||
| 81 | { | ||
| 82 | global_mask = mask; | ||
| 83 | } | ||
| 84 | |||
| 85 | unsigned long ASN1_STRING_get_default_mask(void) | ||
| 86 | { | ||
| 87 | return global_mask; | ||
| 88 | } | ||
| 89 | |||
| 90 | /* This function sets the default to various "flavours" of configuration. | ||
| 91 | * based on an ASCII string. Currently this is: | ||
| 92 | * MASK:XXXX : a numerical mask value. | ||
| 93 | * nobmp : Don't use BMPStrings (just Printable, T61). | ||
| 94 | * pkix : PKIX recommendation in RFC2459. | ||
| 95 | * utf8only : only use UTF8Strings (RFC2459 recommendation for 2004). | ||
| 96 | * default: the default value, Printable, T61, BMP. | ||
| 97 | */ | ||
| 98 | |||
| 99 | int ASN1_STRING_set_default_mask_asc(char *p) | ||
| 100 | { | ||
| 101 | unsigned long mask; | ||
| 102 | char *end; | ||
| 103 | if(!strncmp(p, "MASK:", 5)) { | ||
| 104 | if(!p[5]) return 0; | ||
| 105 | mask = strtoul(p + 5, &end, 0); | ||
| 106 | if(*end) return 0; | ||
| 107 | } else if(!strcmp(p, "nombstr")) | ||
| 108 | mask = ~((unsigned long)(B_ASN1_BMPSTRING|B_ASN1_UTF8STRING)); | ||
| 109 | else if(!strcmp(p, "pkix")) | ||
| 110 | mask = ~((unsigned long)B_ASN1_T61STRING); | ||
| 111 | else if(!strcmp(p, "utf8only")) mask = B_ASN1_UTF8STRING; | ||
| 112 | else if(!strcmp(p, "default")) | ||
| 113 | mask = 0xFFFFFFFFL; | ||
| 114 | else return 0; | ||
| 115 | ASN1_STRING_set_default_mask(mask); | ||
| 116 | return 1; | ||
| 117 | } | ||
| 118 | |||
| 119 | /* The following function generates an ASN1_STRING based on limits in a table. | ||
| 120 | * Frequently the types and length of an ASN1_STRING are restricted by a | ||
| 121 | * corresponding OID. For example certificates and certificate requests. | ||
| 122 | */ | ||
| 123 | |||
| 124 | ASN1_STRING *ASN1_STRING_set_by_NID(ASN1_STRING **out, const unsigned char *in, | ||
| 125 | int inlen, int inform, int nid) | ||
| 126 | { | ||
| 127 | ASN1_STRING_TABLE *tbl; | ||
| 128 | ASN1_STRING *str = NULL; | ||
| 129 | unsigned long mask; | ||
| 130 | int ret; | ||
| 131 | if(!out) out = &str; | ||
| 132 | tbl = ASN1_STRING_TABLE_get(nid); | ||
| 133 | if(tbl) { | ||
| 134 | mask = tbl->mask; | ||
| 135 | if(!(tbl->flags & STABLE_NO_MASK)) mask &= global_mask; | ||
| 136 | ret = ASN1_mbstring_ncopy(out, in, inlen, inform, mask, | ||
| 137 | tbl->minsize, tbl->maxsize); | ||
| 138 | } else ret = ASN1_mbstring_copy(out, in, inlen, inform, DIRSTRING_TYPE & global_mask); | ||
| 139 | if(ret <= 0) return NULL; | ||
| 140 | return *out; | ||
| 141 | } | ||
| 142 | |||
| 143 | /* Now the tables and helper functions for the string table: | ||
| 144 | */ | ||
| 145 | |||
| 146 | /* size limits: this stuff is taken straight from RFC3280 */ | ||
| 147 | |||
| 148 | #define ub_name 32768 | ||
| 149 | #define ub_common_name 64 | ||
| 150 | #define ub_locality_name 128 | ||
| 151 | #define ub_state_name 128 | ||
| 152 | #define ub_organization_name 64 | ||
| 153 | #define ub_organization_unit_name 64 | ||
| 154 | #define ub_title 64 | ||
| 155 | #define ub_email_address 128 | ||
| 156 | #define ub_serial_number 64 | ||
| 157 | |||
| 158 | |||
| 159 | /* This table must be kept in NID order */ | ||
| 160 | |||
| 161 | static ASN1_STRING_TABLE tbl_standard[] = { | ||
| 162 | {NID_commonName, 1, ub_common_name, DIRSTRING_TYPE, 0}, | ||
| 163 | {NID_countryName, 2, 2, B_ASN1_PRINTABLESTRING, STABLE_NO_MASK}, | ||
| 164 | {NID_localityName, 1, ub_locality_name, DIRSTRING_TYPE, 0}, | ||
| 165 | {NID_stateOrProvinceName, 1, ub_state_name, DIRSTRING_TYPE, 0}, | ||
| 166 | {NID_organizationName, 1, ub_organization_name, DIRSTRING_TYPE, 0}, | ||
| 167 | {NID_organizationalUnitName, 1, ub_organization_unit_name, DIRSTRING_TYPE, 0}, | ||
| 168 | {NID_pkcs9_emailAddress, 1, ub_email_address, B_ASN1_IA5STRING, STABLE_NO_MASK}, | ||
| 169 | {NID_pkcs9_unstructuredName, 1, -1, PKCS9STRING_TYPE, 0}, | ||
| 170 | {NID_pkcs9_challengePassword, 1, -1, PKCS9STRING_TYPE, 0}, | ||
| 171 | {NID_pkcs9_unstructuredAddress, 1, -1, DIRSTRING_TYPE, 0}, | ||
| 172 | {NID_givenName, 1, ub_name, DIRSTRING_TYPE, 0}, | ||
| 173 | {NID_surname, 1, ub_name, DIRSTRING_TYPE, 0}, | ||
| 174 | {NID_initials, 1, ub_name, DIRSTRING_TYPE, 0}, | ||
| 175 | {NID_serialNumber, 1, ub_serial_number, B_ASN1_PRINTABLESTRING, STABLE_NO_MASK}, | ||
| 176 | {NID_friendlyName, -1, -1, B_ASN1_BMPSTRING, STABLE_NO_MASK}, | ||
| 177 | {NID_name, 1, ub_name, DIRSTRING_TYPE, 0}, | ||
| 178 | {NID_dnQualifier, -1, -1, B_ASN1_PRINTABLESTRING, STABLE_NO_MASK}, | ||
| 179 | {NID_domainComponent, 1, -1, B_ASN1_IA5STRING, STABLE_NO_MASK}, | ||
| 180 | {NID_ms_csp_name, -1, -1, B_ASN1_BMPSTRING, STABLE_NO_MASK} | ||
| 181 | }; | ||
| 182 | |||
| 183 | static int sk_table_cmp(const ASN1_STRING_TABLE * const *a, | ||
| 184 | const ASN1_STRING_TABLE * const *b) | ||
| 185 | { | ||
| 186 | return (*a)->nid - (*b)->nid; | ||
| 187 | } | ||
| 188 | |||
| 189 | static int table_cmp(const void *a, const void *b) | ||
| 190 | { | ||
| 191 | const ASN1_STRING_TABLE *sa = a, *sb = b; | ||
| 192 | return sa->nid - sb->nid; | ||
| 193 | } | ||
| 194 | |||
| 195 | ASN1_STRING_TABLE *ASN1_STRING_TABLE_get(int nid) | ||
| 196 | { | ||
| 197 | int idx; | ||
| 198 | ASN1_STRING_TABLE *ttmp; | ||
| 199 | ASN1_STRING_TABLE fnd; | ||
| 200 | fnd.nid = nid; | ||
| 201 | ttmp = (ASN1_STRING_TABLE *) OBJ_bsearch((char *)&fnd, | ||
| 202 | (char *)tbl_standard, | ||
| 203 | sizeof(tbl_standard)/sizeof(ASN1_STRING_TABLE), | ||
| 204 | sizeof(ASN1_STRING_TABLE), table_cmp); | ||
| 205 | if(ttmp) return ttmp; | ||
| 206 | if(!stable) return NULL; | ||
| 207 | idx = sk_ASN1_STRING_TABLE_find(stable, &fnd); | ||
| 208 | if(idx < 0) return NULL; | ||
| 209 | return sk_ASN1_STRING_TABLE_value(stable, idx); | ||
| 210 | } | ||
| 211 | |||
| 212 | int ASN1_STRING_TABLE_add(int nid, | ||
| 213 | long minsize, long maxsize, unsigned long mask, | ||
| 214 | unsigned long flags) | ||
| 215 | { | ||
| 216 | ASN1_STRING_TABLE *tmp; | ||
| 217 | char new_nid = 0; | ||
| 218 | flags &= ~STABLE_FLAGS_MALLOC; | ||
| 219 | if(!stable) stable = sk_ASN1_STRING_TABLE_new(sk_table_cmp); | ||
| 220 | if(!stable) { | ||
| 221 | ASN1err(ASN1_F_ASN1_STRING_TABLE_ADD, ERR_R_MALLOC_FAILURE); | ||
| 222 | return 0; | ||
| 223 | } | ||
| 224 | if(!(tmp = ASN1_STRING_TABLE_get(nid))) { | ||
| 225 | tmp = OPENSSL_malloc(sizeof(ASN1_STRING_TABLE)); | ||
| 226 | if(!tmp) { | ||
| 227 | ASN1err(ASN1_F_ASN1_STRING_TABLE_ADD, | ||
| 228 | ERR_R_MALLOC_FAILURE); | ||
| 229 | return 0; | ||
| 230 | } | ||
| 231 | tmp->flags = flags | STABLE_FLAGS_MALLOC; | ||
| 232 | tmp->nid = nid; | ||
| 233 | new_nid = 1; | ||
| 234 | } else tmp->flags = (tmp->flags & STABLE_FLAGS_MALLOC) | flags; | ||
| 235 | if(minsize != -1) tmp->minsize = minsize; | ||
| 236 | if(maxsize != -1) tmp->maxsize = maxsize; | ||
| 237 | tmp->mask = mask; | ||
| 238 | if(new_nid) sk_ASN1_STRING_TABLE_push(stable, tmp); | ||
| 239 | return 1; | ||
| 240 | } | ||
| 241 | |||
| 242 | void ASN1_STRING_TABLE_cleanup(void) | ||
| 243 | { | ||
| 244 | STACK_OF(ASN1_STRING_TABLE) *tmp; | ||
| 245 | tmp = stable; | ||
| 246 | if(!tmp) return; | ||
| 247 | stable = NULL; | ||
| 248 | sk_ASN1_STRING_TABLE_pop_free(tmp, st_free); | ||
| 249 | } | ||
| 250 | |||
| 251 | static void st_free(ASN1_STRING_TABLE *tbl) | ||
| 252 | { | ||
| 253 | if(tbl->flags & STABLE_FLAGS_MALLOC) OPENSSL_free(tbl); | ||
| 254 | } | ||
| 255 | |||
| 256 | |||
| 257 | IMPLEMENT_STACK_OF(ASN1_STRING_TABLE) | ||
| 258 | |||
| 259 | #ifdef STRING_TABLE_TEST | ||
| 260 | |||
| 261 | main() | ||
| 262 | { | ||
| 263 | ASN1_STRING_TABLE *tmp; | ||
| 264 | int i, last_nid = -1; | ||
| 265 | |||
| 266 | for (tmp = tbl_standard, i = 0; | ||
| 267 | i < sizeof(tbl_standard)/sizeof(ASN1_STRING_TABLE); i++, tmp++) | ||
| 268 | { | ||
| 269 | if (tmp->nid < last_nid) | ||
| 270 | { | ||
| 271 | last_nid = 0; | ||
| 272 | break; | ||
| 273 | } | ||
| 274 | last_nid = tmp->nid; | ||
| 275 | } | ||
| 276 | |||
| 277 | if (last_nid != 0) | ||
| 278 | { | ||
| 279 | printf("Table order OK\n"); | ||
| 280 | exit(0); | ||
| 281 | } | ||
| 282 | |||
| 283 | for (tmp = tbl_standard, i = 0; | ||
| 284 | i < sizeof(tbl_standard)/sizeof(ASN1_STRING_TABLE); i++, tmp++) | ||
| 285 | printf("Index %d, NID %d, Name=%s\n", i, tmp->nid, | ||
| 286 | OBJ_nid2ln(tmp->nid)); | ||
| 287 | |||
| 288 | } | ||
| 289 | |||
| 290 | #endif | ||
diff --git a/src/lib/libcrypto/asn1/a_time.c b/src/lib/libcrypto/asn1/a_time.c new file mode 100644 index 0000000000..159681fbcb --- /dev/null +++ b/src/lib/libcrypto/asn1/a_time.c | |||
| @@ -0,0 +1,164 @@ | |||
| 1 | /* crypto/asn1/a_time.c */ | ||
| 2 | /* ==================================================================== | ||
| 3 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
| 4 | * | ||
| 5 | * Redistribution and use in source and binary forms, with or without | ||
| 6 | * modification, are permitted provided that the following conditions | ||
| 7 | * are met: | ||
| 8 | * | ||
| 9 | * 1. Redistributions of source code must retain the above copyright | ||
| 10 | * notice, this list of conditions and the following disclaimer. | ||
| 11 | * | ||
| 12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer in | ||
| 14 | * the documentation and/or other materials provided with the | ||
| 15 | * distribution. | ||
| 16 | * | ||
| 17 | * 3. All advertising materials mentioning features or use of this | ||
| 18 | * software must display the following acknowledgment: | ||
| 19 | * "This product includes software developed by the OpenSSL Project | ||
| 20 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 21 | * | ||
| 22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 23 | * endorse or promote products derived from this software without | ||
| 24 | * prior written permission. For written permission, please contact | ||
| 25 | * licensing@OpenSSL.org. | ||
| 26 | * | ||
| 27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 28 | * nor may "OpenSSL" appear in their names without prior written | ||
| 29 | * permission of the OpenSSL Project. | ||
| 30 | * | ||
| 31 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 32 | * acknowledgment: | ||
| 33 | * "This product includes software developed by the OpenSSL Project | ||
| 34 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 35 | * | ||
| 36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 48 | * ==================================================================== | ||
| 49 | * | ||
| 50 | * This product includes cryptographic software written by Eric Young | ||
| 51 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 52 | * Hudson (tjh@cryptsoft.com). | ||
| 53 | * | ||
| 54 | */ | ||
| 55 | |||
| 56 | |||
| 57 | /* This is an implementation of the ASN1 Time structure which is: | ||
| 58 | * Time ::= CHOICE { | ||
| 59 | * utcTime UTCTime, | ||
| 60 | * generalTime GeneralizedTime } | ||
| 61 | * written by Steve Henson. | ||
| 62 | */ | ||
| 63 | |||
| 64 | #include <stdio.h> | ||
| 65 | #include <time.h> | ||
| 66 | #include "cryptlib.h" | ||
| 67 | #include "o_time.h" | ||
| 68 | #include <openssl/asn1t.h> | ||
| 69 | |||
| 70 | IMPLEMENT_ASN1_MSTRING(ASN1_TIME, B_ASN1_TIME) | ||
| 71 | |||
| 72 | IMPLEMENT_ASN1_FUNCTIONS(ASN1_TIME) | ||
| 73 | |||
| 74 | #if 0 | ||
| 75 | int i2d_ASN1_TIME(ASN1_TIME *a, unsigned char **pp) | ||
| 76 | { | ||
| 77 | #ifdef CHARSET_EBCDIC | ||
| 78 | /* KLUDGE! We convert to ascii before writing DER */ | ||
| 79 | char tmp[24]; | ||
| 80 | ASN1_STRING tmpstr; | ||
| 81 | |||
| 82 | if(a->type == V_ASN1_UTCTIME || a->type == V_ASN1_GENERALIZEDTIME) { | ||
| 83 | int len; | ||
| 84 | |||
| 85 | tmpstr = *(ASN1_STRING *)a; | ||
| 86 | len = tmpstr.length; | ||
| 87 | ebcdic2ascii(tmp, tmpstr.data, (len >= sizeof tmp) ? sizeof tmp : len); | ||
| 88 | tmpstr.data = tmp; | ||
| 89 | a = (ASN1_GENERALIZEDTIME *) &tmpstr; | ||
| 90 | } | ||
| 91 | #endif | ||
| 92 | if(a->type == V_ASN1_UTCTIME || a->type == V_ASN1_GENERALIZEDTIME) | ||
| 93 | return(i2d_ASN1_bytes((ASN1_STRING *)a,pp, | ||
| 94 | a->type ,V_ASN1_UNIVERSAL)); | ||
| 95 | ASN1err(ASN1_F_I2D_ASN1_TIME,ASN1_R_EXPECTING_A_TIME); | ||
| 96 | return -1; | ||
| 97 | } | ||
| 98 | #endif | ||
| 99 | |||
| 100 | |||
| 101 | ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t) | ||
| 102 | { | ||
| 103 | struct tm *ts; | ||
| 104 | struct tm data; | ||
| 105 | |||
| 106 | ts=OPENSSL_gmtime(&t,&data); | ||
| 107 | if (ts == NULL) | ||
| 108 | { | ||
| 109 | ASN1err(ASN1_F_ASN1_TIME_SET, ASN1_R_ERROR_GETTING_TIME); | ||
| 110 | return NULL; | ||
| 111 | } | ||
| 112 | if((ts->tm_year >= 50) && (ts->tm_year < 150)) | ||
| 113 | return ASN1_UTCTIME_set(s, t); | ||
| 114 | return ASN1_GENERALIZEDTIME_set(s,t); | ||
| 115 | } | ||
| 116 | |||
| 117 | int ASN1_TIME_check(ASN1_TIME *t) | ||
| 118 | { | ||
| 119 | if (t->type == V_ASN1_GENERALIZEDTIME) | ||
| 120 | return ASN1_GENERALIZEDTIME_check(t); | ||
| 121 | else if (t->type == V_ASN1_UTCTIME) | ||
| 122 | return ASN1_UTCTIME_check(t); | ||
| 123 | return 0; | ||
| 124 | } | ||
| 125 | |||
| 126 | /* Convert an ASN1_TIME structure to GeneralizedTime */ | ||
| 127 | ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(ASN1_TIME *t, ASN1_GENERALIZEDTIME **out) | ||
| 128 | { | ||
| 129 | ASN1_GENERALIZEDTIME *ret; | ||
| 130 | char *str; | ||
| 131 | int newlen; | ||
| 132 | |||
| 133 | if (!ASN1_TIME_check(t)) return NULL; | ||
| 134 | |||
| 135 | if (!out || !*out) | ||
| 136 | { | ||
| 137 | if (!(ret = ASN1_GENERALIZEDTIME_new ())) | ||
| 138 | return NULL; | ||
| 139 | if (out) *out = ret; | ||
| 140 | } | ||
| 141 | else ret = *out; | ||
| 142 | |||
| 143 | /* If already GeneralizedTime just copy across */ | ||
| 144 | if (t->type == V_ASN1_GENERALIZEDTIME) | ||
| 145 | { | ||
| 146 | if(!ASN1_STRING_set(ret, t->data, t->length)) | ||
| 147 | return NULL; | ||
| 148 | return ret; | ||
| 149 | } | ||
| 150 | |||
| 151 | /* grow the string */ | ||
| 152 | if (!ASN1_STRING_set(ret, NULL, t->length + 2)) | ||
| 153 | return NULL; | ||
| 154 | /* ASN1_STRING_set() allocated 'len + 1' bytes. */ | ||
| 155 | newlen = t->length + 2 + 1; | ||
| 156 | str = (char *)ret->data; | ||
| 157 | /* Work out the century and prepend */ | ||
| 158 | if (t->data[0] >= '5') BUF_strlcpy(str, "19", newlen); | ||
| 159 | else BUF_strlcpy(str, "20", newlen); | ||
| 160 | |||
| 161 | BUF_strlcat(str, (char *)t->data, newlen); | ||
| 162 | |||
| 163 | return ret; | ||
| 164 | } | ||
diff --git a/src/lib/libcrypto/asn1/a_type.c b/src/lib/libcrypto/asn1/a_type.c new file mode 100644 index 0000000000..36beceacdb --- /dev/null +++ b/src/lib/libcrypto/asn1/a_type.c | |||
| @@ -0,0 +1,110 @@ | |||
| 1 | /* crypto/asn1/a_type.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/asn1t.h> | ||
| 62 | #include <openssl/objects.h> | ||
| 63 | |||
| 64 | int ASN1_TYPE_get(ASN1_TYPE *a) | ||
| 65 | { | ||
| 66 | if ((a->value.ptr != NULL) || (a->type == V_ASN1_NULL)) | ||
| 67 | return(a->type); | ||
| 68 | else | ||
| 69 | return(0); | ||
| 70 | } | ||
| 71 | |||
| 72 | void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value) | ||
| 73 | { | ||
| 74 | if (a->value.ptr != NULL) | ||
| 75 | { | ||
| 76 | ASN1_TYPE **tmp_a = &a; | ||
| 77 | ASN1_primitive_free((ASN1_VALUE **)tmp_a, NULL); | ||
| 78 | } | ||
| 79 | a->type=type; | ||
| 80 | a->value.ptr=value; | ||
| 81 | } | ||
| 82 | |||
| 83 | int ASN1_TYPE_set1(ASN1_TYPE *a, int type, const void *value) | ||
| 84 | { | ||
| 85 | if (!value || (type == V_ASN1_BOOLEAN)) | ||
| 86 | { | ||
| 87 | void *p = (void *)value; | ||
| 88 | ASN1_TYPE_set(a, type, p); | ||
| 89 | } | ||
| 90 | else if (type == V_ASN1_OBJECT) | ||
| 91 | { | ||
| 92 | ASN1_OBJECT *odup; | ||
| 93 | odup = OBJ_dup(value); | ||
| 94 | if (!odup) | ||
| 95 | return 0; | ||
| 96 | ASN1_TYPE_set(a, type, odup); | ||
| 97 | } | ||
| 98 | else | ||
| 99 | { | ||
| 100 | ASN1_STRING *sdup; | ||
| 101 | sdup = ASN1_STRING_dup((ASN1_STRING *)value); | ||
| 102 | if (!sdup) | ||
| 103 | return 0; | ||
| 104 | ASN1_TYPE_set(a, type, sdup); | ||
| 105 | } | ||
| 106 | return 1; | ||
| 107 | } | ||
| 108 | |||
| 109 | IMPLEMENT_STACK_OF(ASN1_TYPE) | ||
| 110 | IMPLEMENT_ASN1_SET_OF(ASN1_TYPE) | ||
diff --git a/src/lib/libcrypto/asn1/a_utctm.c b/src/lib/libcrypto/asn1/a_utctm.c new file mode 100644 index 0000000000..d31c028193 --- /dev/null +++ b/src/lib/libcrypto/asn1/a_utctm.c | |||
| @@ -0,0 +1,303 @@ | |||
| 1 | /* crypto/asn1/a_utctm.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include <time.h> | ||
| 61 | #include "cryptlib.h" | ||
| 62 | #include "o_time.h" | ||
| 63 | #include <openssl/asn1.h> | ||
| 64 | |||
| 65 | #if 0 | ||
| 66 | int i2d_ASN1_UTCTIME(ASN1_UTCTIME *a, unsigned char **pp) | ||
| 67 | { | ||
| 68 | #ifndef CHARSET_EBCDIC | ||
| 69 | return(i2d_ASN1_bytes((ASN1_STRING *)a,pp, | ||
| 70 | V_ASN1_UTCTIME,V_ASN1_UNIVERSAL)); | ||
| 71 | #else | ||
| 72 | /* KLUDGE! We convert to ascii before writing DER */ | ||
| 73 | int len; | ||
| 74 | char tmp[24]; | ||
| 75 | ASN1_STRING x = *(ASN1_STRING *)a; | ||
| 76 | |||
| 77 | len = x.length; | ||
| 78 | ebcdic2ascii(tmp, x.data, (len >= sizeof tmp) ? sizeof tmp : len); | ||
| 79 | x.data = tmp; | ||
| 80 | return i2d_ASN1_bytes(&x, pp, V_ASN1_UTCTIME,V_ASN1_UNIVERSAL); | ||
| 81 | #endif | ||
| 82 | } | ||
| 83 | |||
| 84 | |||
| 85 | ASN1_UTCTIME *d2i_ASN1_UTCTIME(ASN1_UTCTIME **a, unsigned char **pp, | ||
| 86 | long length) | ||
| 87 | { | ||
| 88 | ASN1_UTCTIME *ret=NULL; | ||
| 89 | |||
| 90 | ret=(ASN1_UTCTIME *)d2i_ASN1_bytes((ASN1_STRING **)a,pp,length, | ||
| 91 | V_ASN1_UTCTIME,V_ASN1_UNIVERSAL); | ||
| 92 | if (ret == NULL) | ||
| 93 | { | ||
| 94 | ASN1err(ASN1_F_D2I_ASN1_UTCTIME,ERR_R_NESTED_ASN1_ERROR); | ||
| 95 | return(NULL); | ||
| 96 | } | ||
| 97 | #ifdef CHARSET_EBCDIC | ||
| 98 | ascii2ebcdic(ret->data, ret->data, ret->length); | ||
| 99 | #endif | ||
| 100 | if (!ASN1_UTCTIME_check(ret)) | ||
| 101 | { | ||
| 102 | ASN1err(ASN1_F_D2I_ASN1_UTCTIME,ASN1_R_INVALID_TIME_FORMAT); | ||
| 103 | goto err; | ||
| 104 | } | ||
| 105 | |||
| 106 | return(ret); | ||
| 107 | err: | ||
| 108 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) | ||
| 109 | M_ASN1_UTCTIME_free(ret); | ||
| 110 | return(NULL); | ||
| 111 | } | ||
| 112 | |||
| 113 | #endif | ||
| 114 | |||
| 115 | int ASN1_UTCTIME_check(ASN1_UTCTIME *d) | ||
| 116 | { | ||
| 117 | static int min[8]={ 0, 1, 1, 0, 0, 0, 0, 0}; | ||
| 118 | static int max[8]={99,12,31,23,59,59,12,59}; | ||
| 119 | char *a; | ||
| 120 | int n,i,l,o; | ||
| 121 | |||
| 122 | if (d->type != V_ASN1_UTCTIME) return(0); | ||
| 123 | l=d->length; | ||
| 124 | a=(char *)d->data; | ||
| 125 | o=0; | ||
| 126 | |||
| 127 | if (l < 11) goto err; | ||
| 128 | for (i=0; i<6; i++) | ||
| 129 | { | ||
| 130 | if ((i == 5) && ((a[o] == 'Z') || | ||
| 131 | (a[o] == '+') || (a[o] == '-'))) | ||
| 132 | { i++; break; } | ||
| 133 | if ((a[o] < '0') || (a[o] > '9')) goto err; | ||
| 134 | n= a[o]-'0'; | ||
| 135 | if (++o > l) goto err; | ||
| 136 | |||
| 137 | if ((a[o] < '0') || (a[o] > '9')) goto err; | ||
| 138 | n=(n*10)+ a[o]-'0'; | ||
| 139 | if (++o > l) goto err; | ||
| 140 | |||
| 141 | if ((n < min[i]) || (n > max[i])) goto err; | ||
| 142 | } | ||
| 143 | if (a[o] == 'Z') | ||
| 144 | o++; | ||
| 145 | else if ((a[o] == '+') || (a[o] == '-')) | ||
| 146 | { | ||
| 147 | o++; | ||
| 148 | if (o+4 > l) goto err; | ||
| 149 | for (i=6; i<8; i++) | ||
| 150 | { | ||
| 151 | if ((a[o] < '0') || (a[o] > '9')) goto err; | ||
| 152 | n= a[o]-'0'; | ||
| 153 | o++; | ||
| 154 | if ((a[o] < '0') || (a[o] > '9')) goto err; | ||
| 155 | n=(n*10)+ a[o]-'0'; | ||
| 156 | if ((n < min[i]) || (n > max[i])) goto err; | ||
| 157 | o++; | ||
| 158 | } | ||
| 159 | } | ||
| 160 | return(o == l); | ||
| 161 | err: | ||
| 162 | return(0); | ||
| 163 | } | ||
| 164 | |||
| 165 | int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, const char *str) | ||
| 166 | { | ||
| 167 | ASN1_UTCTIME t; | ||
| 168 | |||
| 169 | t.type=V_ASN1_UTCTIME; | ||
| 170 | t.length=strlen(str); | ||
| 171 | t.data=(unsigned char *)str; | ||
| 172 | if (ASN1_UTCTIME_check(&t)) | ||
| 173 | { | ||
| 174 | if (s != NULL) | ||
| 175 | { | ||
| 176 | if (!ASN1_STRING_set((ASN1_STRING *)s, | ||
| 177 | (unsigned char *)str,t.length)) | ||
| 178 | return 0; | ||
| 179 | s->type = V_ASN1_UTCTIME; | ||
| 180 | } | ||
| 181 | return(1); | ||
| 182 | } | ||
| 183 | else | ||
| 184 | return(0); | ||
| 185 | } | ||
| 186 | |||
| 187 | ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s, time_t t) | ||
| 188 | { | ||
| 189 | char *p; | ||
| 190 | struct tm *ts; | ||
| 191 | struct tm data; | ||
| 192 | size_t len = 20; | ||
| 193 | |||
| 194 | if (s == NULL) | ||
| 195 | s=M_ASN1_UTCTIME_new(); | ||
| 196 | if (s == NULL) | ||
| 197 | return(NULL); | ||
| 198 | |||
| 199 | ts=OPENSSL_gmtime(&t, &data); | ||
| 200 | if (ts == NULL) | ||
| 201 | return(NULL); | ||
| 202 | |||
| 203 | p=(char *)s->data; | ||
| 204 | if ((p == NULL) || ((size_t)s->length < len)) | ||
| 205 | { | ||
| 206 | p=OPENSSL_malloc(len); | ||
| 207 | if (p == NULL) | ||
| 208 | { | ||
| 209 | ASN1err(ASN1_F_ASN1_UTCTIME_SET,ERR_R_MALLOC_FAILURE); | ||
| 210 | return(NULL); | ||
| 211 | } | ||
| 212 | if (s->data != NULL) | ||
| 213 | OPENSSL_free(s->data); | ||
| 214 | s->data=(unsigned char *)p; | ||
| 215 | } | ||
| 216 | |||
| 217 | BIO_snprintf(p,len,"%02d%02d%02d%02d%02d%02dZ",ts->tm_year%100, | ||
| 218 | ts->tm_mon+1,ts->tm_mday,ts->tm_hour,ts->tm_min,ts->tm_sec); | ||
| 219 | s->length=strlen(p); | ||
| 220 | s->type=V_ASN1_UTCTIME; | ||
| 221 | #ifdef CHARSET_EBCDIC_not | ||
| 222 | ebcdic2ascii(s->data, s->data, s->length); | ||
| 223 | #endif | ||
| 224 | return(s); | ||
| 225 | } | ||
| 226 | |||
| 227 | |||
| 228 | int ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t) | ||
| 229 | { | ||
| 230 | struct tm *tm; | ||
| 231 | struct tm data; | ||
| 232 | int offset; | ||
| 233 | int year; | ||
| 234 | |||
| 235 | #define g2(p) (((p)[0]-'0')*10+(p)[1]-'0') | ||
| 236 | |||
| 237 | if (s->data[12] == 'Z') | ||
| 238 | offset=0; | ||
| 239 | else | ||
| 240 | { | ||
| 241 | offset = g2(s->data+13)*60+g2(s->data+15); | ||
| 242 | if (s->data[12] == '-') | ||
| 243 | offset = -offset; | ||
| 244 | } | ||
| 245 | |||
| 246 | t -= offset*60; /* FIXME: may overflow in extreme cases */ | ||
| 247 | |||
| 248 | tm = OPENSSL_gmtime(&t, &data); | ||
| 249 | |||
| 250 | #define return_cmp(a,b) if ((a)<(b)) return -1; else if ((a)>(b)) return 1 | ||
| 251 | year = g2(s->data); | ||
| 252 | if (year < 50) | ||
| 253 | year += 100; | ||
| 254 | return_cmp(year, tm->tm_year); | ||
| 255 | return_cmp(g2(s->data+2) - 1, tm->tm_mon); | ||
| 256 | return_cmp(g2(s->data+4), tm->tm_mday); | ||
| 257 | return_cmp(g2(s->data+6), tm->tm_hour); | ||
| 258 | return_cmp(g2(s->data+8), tm->tm_min); | ||
| 259 | return_cmp(g2(s->data+10), tm->tm_sec); | ||
| 260 | #undef g2 | ||
| 261 | #undef return_cmp | ||
| 262 | |||
| 263 | return 0; | ||
| 264 | } | ||
| 265 | |||
| 266 | |||
| 267 | #if 0 | ||
| 268 | time_t ASN1_UTCTIME_get(const ASN1_UTCTIME *s) | ||
| 269 | { | ||
| 270 | struct tm tm; | ||
| 271 | int offset; | ||
| 272 | |||
| 273 | memset(&tm,'\0',sizeof tm); | ||
| 274 | |||
| 275 | #define g2(p) (((p)[0]-'0')*10+(p)[1]-'0') | ||
| 276 | tm.tm_year=g2(s->data); | ||
| 277 | if(tm.tm_year < 50) | ||
| 278 | tm.tm_year+=100; | ||
| 279 | tm.tm_mon=g2(s->data+2)-1; | ||
| 280 | tm.tm_mday=g2(s->data+4); | ||
| 281 | tm.tm_hour=g2(s->data+6); | ||
| 282 | tm.tm_min=g2(s->data+8); | ||
| 283 | tm.tm_sec=g2(s->data+10); | ||
| 284 | if(s->data[12] == 'Z') | ||
| 285 | offset=0; | ||
| 286 | else | ||
| 287 | { | ||
| 288 | offset=g2(s->data+13)*60+g2(s->data+15); | ||
| 289 | if(s->data[12] == '-') | ||
| 290 | offset= -offset; | ||
| 291 | } | ||
| 292 | #undef g2 | ||
| 293 | |||
| 294 | return mktime(&tm)-offset*60; /* FIXME: mktime assumes the current timezone | ||
| 295 | * instead of UTC, and unless we rewrite OpenSSL | ||
| 296 | * in Lisp we cannot locally change the timezone | ||
| 297 | * without possibly interfering with other parts | ||
| 298 | * of the program. timegm, which uses UTC, is | ||
| 299 | * non-standard. | ||
| 300 | * Also time_t is inappropriate for general | ||
| 301 | * UTC times because it may a 32 bit type. */ | ||
| 302 | } | ||
| 303 | #endif | ||
diff --git a/src/lib/libcrypto/asn1/a_utf8.c b/src/lib/libcrypto/asn1/a_utf8.c new file mode 100644 index 0000000000..508e11e527 --- /dev/null +++ b/src/lib/libcrypto/asn1/a_utf8.c | |||
| @@ -0,0 +1,211 @@ | |||
| 1 | /* crypto/asn1/a_utf8.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/asn1.h> | ||
| 62 | |||
| 63 | |||
| 64 | /* UTF8 utilities */ | ||
| 65 | |||
| 66 | /* This parses a UTF8 string one character at a time. It is passed a pointer | ||
| 67 | * to the string and the length of the string. It sets 'value' to the value of | ||
| 68 | * the current character. It returns the number of characters read or a | ||
| 69 | * negative error code: | ||
| 70 | * -1 = string too short | ||
| 71 | * -2 = illegal character | ||
| 72 | * -3 = subsequent characters not of the form 10xxxxxx | ||
| 73 | * -4 = character encoded incorrectly (not minimal length). | ||
| 74 | */ | ||
| 75 | |||
| 76 | int UTF8_getc(const unsigned char *str, int len, unsigned long *val) | ||
| 77 | { | ||
| 78 | const unsigned char *p; | ||
| 79 | unsigned long value; | ||
| 80 | int ret; | ||
| 81 | if(len <= 0) return 0; | ||
| 82 | p = str; | ||
| 83 | |||
| 84 | /* Check syntax and work out the encoded value (if correct) */ | ||
| 85 | if((*p & 0x80) == 0) { | ||
| 86 | value = *p++ & 0x7f; | ||
| 87 | ret = 1; | ||
| 88 | } else if((*p & 0xe0) == 0xc0) { | ||
| 89 | if(len < 2) return -1; | ||
| 90 | if((p[1] & 0xc0) != 0x80) return -3; | ||
| 91 | value = (*p++ & 0x1f) << 6; | ||
| 92 | value |= *p++ & 0x3f; | ||
| 93 | if(value < 0x80) return -4; | ||
| 94 | ret = 2; | ||
| 95 | } else if((*p & 0xf0) == 0xe0) { | ||
| 96 | if(len < 3) return -1; | ||
| 97 | if( ((p[1] & 0xc0) != 0x80) | ||
| 98 | || ((p[2] & 0xc0) != 0x80) ) return -3; | ||
| 99 | value = (*p++ & 0xf) << 12; | ||
| 100 | value |= (*p++ & 0x3f) << 6; | ||
| 101 | value |= *p++ & 0x3f; | ||
| 102 | if(value < 0x800) return -4; | ||
| 103 | ret = 3; | ||
| 104 | } else if((*p & 0xf8) == 0xf0) { | ||
| 105 | if(len < 4) return -1; | ||
| 106 | if( ((p[1] & 0xc0) != 0x80) | ||
| 107 | || ((p[2] & 0xc0) != 0x80) | ||
| 108 | || ((p[3] & 0xc0) != 0x80) ) return -3; | ||
| 109 | value = ((unsigned long)(*p++ & 0x7)) << 18; | ||
| 110 | value |= (*p++ & 0x3f) << 12; | ||
| 111 | value |= (*p++ & 0x3f) << 6; | ||
| 112 | value |= *p++ & 0x3f; | ||
| 113 | if(value < 0x10000) return -4; | ||
| 114 | ret = 4; | ||
| 115 | } else if((*p & 0xfc) == 0xf8) { | ||
| 116 | if(len < 5) return -1; | ||
| 117 | if( ((p[1] & 0xc0) != 0x80) | ||
| 118 | || ((p[2] & 0xc0) != 0x80) | ||
| 119 | || ((p[3] & 0xc0) != 0x80) | ||
| 120 | || ((p[4] & 0xc0) != 0x80) ) return -3; | ||
| 121 | value = ((unsigned long)(*p++ & 0x3)) << 24; | ||
| 122 | value |= ((unsigned long)(*p++ & 0x3f)) << 18; | ||
| 123 | value |= ((unsigned long)(*p++ & 0x3f)) << 12; | ||
| 124 | value |= (*p++ & 0x3f) << 6; | ||
| 125 | value |= *p++ & 0x3f; | ||
| 126 | if(value < 0x200000) return -4; | ||
| 127 | ret = 5; | ||
| 128 | } else if((*p & 0xfe) == 0xfc) { | ||
| 129 | if(len < 6) return -1; | ||
| 130 | if( ((p[1] & 0xc0) != 0x80) | ||
| 131 | || ((p[2] & 0xc0) != 0x80) | ||
| 132 | || ((p[3] & 0xc0) != 0x80) | ||
| 133 | || ((p[4] & 0xc0) != 0x80) | ||
| 134 | || ((p[5] & 0xc0) != 0x80) ) return -3; | ||
| 135 | value = ((unsigned long)(*p++ & 0x1)) << 30; | ||
| 136 | value |= ((unsigned long)(*p++ & 0x3f)) << 24; | ||
| 137 | value |= ((unsigned long)(*p++ & 0x3f)) << 18; | ||
| 138 | value |= ((unsigned long)(*p++ & 0x3f)) << 12; | ||
| 139 | value |= (*p++ & 0x3f) << 6; | ||
| 140 | value |= *p++ & 0x3f; | ||
| 141 | if(value < 0x4000000) return -4; | ||
| 142 | ret = 6; | ||
| 143 | } else return -2; | ||
| 144 | *val = value; | ||
| 145 | return ret; | ||
| 146 | } | ||
| 147 | |||
| 148 | /* This takes a character 'value' and writes the UTF8 encoded value in | ||
| 149 | * 'str' where 'str' is a buffer containing 'len' characters. Returns | ||
| 150 | * the number of characters written or -1 if 'len' is too small. 'str' can | ||
| 151 | * be set to NULL in which case it just returns the number of characters. | ||
| 152 | * It will need at most 6 characters. | ||
| 153 | */ | ||
| 154 | |||
| 155 | int UTF8_putc(unsigned char *str, int len, unsigned long value) | ||
| 156 | { | ||
| 157 | if(!str) len = 6; /* Maximum we will need */ | ||
| 158 | else if(len <= 0) return -1; | ||
| 159 | if(value < 0x80) { | ||
| 160 | if(str) *str = (unsigned char)value; | ||
| 161 | return 1; | ||
| 162 | } | ||
| 163 | if(value < 0x800) { | ||
| 164 | if(len < 2) return -1; | ||
| 165 | if(str) { | ||
| 166 | *str++ = (unsigned char)(((value >> 6) & 0x1f) | 0xc0); | ||
| 167 | *str = (unsigned char)((value & 0x3f) | 0x80); | ||
| 168 | } | ||
| 169 | return 2; | ||
| 170 | } | ||
| 171 | if(value < 0x10000) { | ||
| 172 | if(len < 3) return -1; | ||
| 173 | if(str) { | ||
| 174 | *str++ = (unsigned char)(((value >> 12) & 0xf) | 0xe0); | ||
| 175 | *str++ = (unsigned char)(((value >> 6) & 0x3f) | 0x80); | ||
| 176 | *str = (unsigned char)((value & 0x3f) | 0x80); | ||
| 177 | } | ||
| 178 | return 3; | ||
| 179 | } | ||
| 180 | if(value < 0x200000) { | ||
| 181 | if(len < 4) return -1; | ||
| 182 | if(str) { | ||
| 183 | *str++ = (unsigned char)(((value >> 18) & 0x7) | 0xf0); | ||
| 184 | *str++ = (unsigned char)(((value >> 12) & 0x3f) | 0x80); | ||
| 185 | *str++ = (unsigned char)(((value >> 6) & 0x3f) | 0x80); | ||
| 186 | *str = (unsigned char)((value & 0x3f) | 0x80); | ||
| 187 | } | ||
| 188 | return 4; | ||
| 189 | } | ||
| 190 | if(value < 0x4000000) { | ||
| 191 | if(len < 5) return -1; | ||
| 192 | if(str) { | ||
| 193 | *str++ = (unsigned char)(((value >> 24) & 0x3) | 0xf8); | ||
| 194 | *str++ = (unsigned char)(((value >> 18) & 0x3f) | 0x80); | ||
| 195 | *str++ = (unsigned char)(((value >> 12) & 0x3f) | 0x80); | ||
| 196 | *str++ = (unsigned char)(((value >> 6) & 0x3f) | 0x80); | ||
| 197 | *str = (unsigned char)((value & 0x3f) | 0x80); | ||
| 198 | } | ||
| 199 | return 5; | ||
| 200 | } | ||
| 201 | if(len < 6) return -1; | ||
| 202 | if(str) { | ||
| 203 | *str++ = (unsigned char)(((value >> 30) & 0x1) | 0xfc); | ||
| 204 | *str++ = (unsigned char)(((value >> 24) & 0x3f) | 0x80); | ||
| 205 | *str++ = (unsigned char)(((value >> 18) & 0x3f) | 0x80); | ||
| 206 | *str++ = (unsigned char)(((value >> 12) & 0x3f) | 0x80); | ||
| 207 | *str++ = (unsigned char)(((value >> 6) & 0x3f) | 0x80); | ||
| 208 | *str = (unsigned char)((value & 0x3f) | 0x80); | ||
| 209 | } | ||
| 210 | return 6; | ||
| 211 | } | ||
diff --git a/src/lib/libcrypto/asn1/a_verify.c b/src/lib/libcrypto/asn1/a_verify.c new file mode 100644 index 0000000000..fdce6e4380 --- /dev/null +++ b/src/lib/libcrypto/asn1/a_verify.c | |||
| @@ -0,0 +1,181 @@ | |||
| 1 | /* crypto/asn1/a_verify.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include <time.h> | ||
| 61 | |||
| 62 | #include "cryptlib.h" | ||
| 63 | |||
| 64 | #ifndef NO_SYS_TYPES_H | ||
| 65 | # include <sys/types.h> | ||
| 66 | #endif | ||
| 67 | |||
| 68 | #include <openssl/bn.h> | ||
| 69 | #include <openssl/x509.h> | ||
| 70 | #include <openssl/objects.h> | ||
| 71 | #include <openssl/buffer.h> | ||
| 72 | #include <openssl/evp.h> | ||
| 73 | |||
| 74 | #ifndef NO_ASN1_OLD | ||
| 75 | |||
| 76 | int ASN1_verify(i2d_of_void *i2d, X509_ALGOR *a, ASN1_BIT_STRING *signature, | ||
| 77 | char *data, EVP_PKEY *pkey) | ||
| 78 | { | ||
| 79 | EVP_MD_CTX ctx; | ||
| 80 | const EVP_MD *type; | ||
| 81 | unsigned char *p,*buf_in=NULL; | ||
| 82 | int ret= -1,i,inl; | ||
| 83 | |||
| 84 | EVP_MD_CTX_init(&ctx); | ||
| 85 | i=OBJ_obj2nid(a->algorithm); | ||
| 86 | type=EVP_get_digestbyname(OBJ_nid2sn(i)); | ||
| 87 | if (type == NULL) | ||
| 88 | { | ||
| 89 | ASN1err(ASN1_F_ASN1_VERIFY,ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM); | ||
| 90 | goto err; | ||
| 91 | } | ||
| 92 | |||
| 93 | inl=i2d(data,NULL); | ||
| 94 | buf_in=OPENSSL_malloc((unsigned int)inl); | ||
| 95 | if (buf_in == NULL) | ||
| 96 | { | ||
| 97 | ASN1err(ASN1_F_ASN1_VERIFY,ERR_R_MALLOC_FAILURE); | ||
| 98 | goto err; | ||
| 99 | } | ||
| 100 | p=buf_in; | ||
| 101 | |||
| 102 | i2d(data,&p); | ||
| 103 | EVP_VerifyInit_ex(&ctx,type, NULL); | ||
| 104 | EVP_VerifyUpdate(&ctx,(unsigned char *)buf_in,inl); | ||
| 105 | |||
| 106 | OPENSSL_cleanse(buf_in,(unsigned int)inl); | ||
| 107 | OPENSSL_free(buf_in); | ||
| 108 | |||
| 109 | if (EVP_VerifyFinal(&ctx,(unsigned char *)signature->data, | ||
| 110 | (unsigned int)signature->length,pkey) <= 0) | ||
| 111 | { | ||
| 112 | ASN1err(ASN1_F_ASN1_VERIFY,ERR_R_EVP_LIB); | ||
| 113 | ret=0; | ||
| 114 | goto err; | ||
| 115 | } | ||
| 116 | /* we don't need to zero the 'ctx' because we just checked | ||
| 117 | * public information */ | ||
| 118 | /* memset(&ctx,0,sizeof(ctx)); */ | ||
| 119 | ret=1; | ||
| 120 | err: | ||
| 121 | EVP_MD_CTX_cleanup(&ctx); | ||
| 122 | return(ret); | ||
| 123 | } | ||
| 124 | |||
| 125 | #endif | ||
| 126 | |||
| 127 | |||
| 128 | int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a, ASN1_BIT_STRING *signature, | ||
| 129 | void *asn, EVP_PKEY *pkey) | ||
| 130 | { | ||
| 131 | EVP_MD_CTX ctx; | ||
| 132 | const EVP_MD *type; | ||
| 133 | unsigned char *buf_in=NULL; | ||
| 134 | int ret= -1,i,inl; | ||
| 135 | |||
| 136 | EVP_MD_CTX_init(&ctx); | ||
| 137 | i=OBJ_obj2nid(a->algorithm); | ||
| 138 | type=EVP_get_digestbyname(OBJ_nid2sn(i)); | ||
| 139 | if (type == NULL) | ||
| 140 | { | ||
| 141 | ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM); | ||
| 142 | goto err; | ||
| 143 | } | ||
| 144 | |||
| 145 | if (!EVP_VerifyInit_ex(&ctx,type, NULL)) | ||
| 146 | { | ||
| 147 | ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ERR_R_EVP_LIB); | ||
| 148 | ret=0; | ||
| 149 | goto err; | ||
| 150 | } | ||
| 151 | |||
| 152 | inl = ASN1_item_i2d(asn, &buf_in, it); | ||
| 153 | |||
| 154 | if (buf_in == NULL) | ||
| 155 | { | ||
| 156 | ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ERR_R_MALLOC_FAILURE); | ||
| 157 | goto err; | ||
| 158 | } | ||
| 159 | |||
| 160 | EVP_VerifyUpdate(&ctx,(unsigned char *)buf_in,inl); | ||
| 161 | |||
| 162 | OPENSSL_cleanse(buf_in,(unsigned int)inl); | ||
| 163 | OPENSSL_free(buf_in); | ||
| 164 | |||
| 165 | if (EVP_VerifyFinal(&ctx,(unsigned char *)signature->data, | ||
| 166 | (unsigned int)signature->length,pkey) <= 0) | ||
| 167 | { | ||
| 168 | ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ERR_R_EVP_LIB); | ||
| 169 | ret=0; | ||
| 170 | goto err; | ||
| 171 | } | ||
| 172 | /* we don't need to zero the 'ctx' because we just checked | ||
| 173 | * public information */ | ||
| 174 | /* memset(&ctx,0,sizeof(ctx)); */ | ||
| 175 | ret=1; | ||
| 176 | err: | ||
| 177 | EVP_MD_CTX_cleanup(&ctx); | ||
| 178 | return(ret); | ||
| 179 | } | ||
| 180 | |||
| 181 | |||
diff --git a/src/lib/libcrypto/asn1/asn1.h b/src/lib/libcrypto/asn1/asn1.h new file mode 100644 index 0000000000..424cd348bb --- /dev/null +++ b/src/lib/libcrypto/asn1/asn1.h | |||
| @@ -0,0 +1,1326 @@ | |||
| 1 | /* crypto/asn1/asn1.h */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #ifndef HEADER_ASN1_H | ||
| 60 | #define HEADER_ASN1_H | ||
| 61 | |||
| 62 | #include <time.h> | ||
| 63 | #include <openssl/e_os2.h> | ||
| 64 | #ifndef OPENSSL_NO_BIO | ||
| 65 | #include <openssl/bio.h> | ||
| 66 | #endif | ||
| 67 | #include <openssl/stack.h> | ||
| 68 | #include <openssl/safestack.h> | ||
| 69 | |||
| 70 | #include <openssl/symhacks.h> | ||
| 71 | |||
| 72 | #include <openssl/ossl_typ.h> | ||
| 73 | #ifndef OPENSSL_NO_DEPRECATED | ||
| 74 | #include <openssl/bn.h> | ||
| 75 | #endif | ||
| 76 | |||
| 77 | #ifdef OPENSSL_BUILD_SHLIBCRYPTO | ||
| 78 | # undef OPENSSL_EXTERN | ||
| 79 | # define OPENSSL_EXTERN OPENSSL_EXPORT | ||
| 80 | #endif | ||
| 81 | |||
| 82 | #ifdef __cplusplus | ||
| 83 | extern "C" { | ||
| 84 | #endif | ||
| 85 | |||
| 86 | #define V_ASN1_UNIVERSAL 0x00 | ||
| 87 | #define V_ASN1_APPLICATION 0x40 | ||
| 88 | #define V_ASN1_CONTEXT_SPECIFIC 0x80 | ||
| 89 | #define V_ASN1_PRIVATE 0xc0 | ||
| 90 | |||
| 91 | #define V_ASN1_CONSTRUCTED 0x20 | ||
| 92 | #define V_ASN1_PRIMITIVE_TAG 0x1f | ||
| 93 | #define V_ASN1_PRIMATIVE_TAG 0x1f | ||
| 94 | |||
| 95 | #define V_ASN1_APP_CHOOSE -2 /* let the recipient choose */ | ||
| 96 | #define V_ASN1_OTHER -3 /* used in ASN1_TYPE */ | ||
| 97 | #define V_ASN1_ANY -4 /* used in ASN1 template code */ | ||
| 98 | |||
| 99 | #define V_ASN1_NEG 0x100 /* negative flag */ | ||
| 100 | |||
| 101 | #define V_ASN1_UNDEF -1 | ||
| 102 | #define V_ASN1_EOC 0 | ||
| 103 | #define V_ASN1_BOOLEAN 1 /**/ | ||
| 104 | #define V_ASN1_INTEGER 2 | ||
| 105 | #define V_ASN1_NEG_INTEGER (2 | V_ASN1_NEG) | ||
| 106 | #define V_ASN1_BIT_STRING 3 | ||
| 107 | #define V_ASN1_OCTET_STRING 4 | ||
| 108 | #define V_ASN1_NULL 5 | ||
| 109 | #define V_ASN1_OBJECT 6 | ||
| 110 | #define V_ASN1_OBJECT_DESCRIPTOR 7 | ||
| 111 | #define V_ASN1_EXTERNAL 8 | ||
| 112 | #define V_ASN1_REAL 9 | ||
| 113 | #define V_ASN1_ENUMERATED 10 | ||
| 114 | #define V_ASN1_NEG_ENUMERATED (10 | V_ASN1_NEG) | ||
| 115 | #define V_ASN1_UTF8STRING 12 | ||
| 116 | #define V_ASN1_SEQUENCE 16 | ||
| 117 | #define V_ASN1_SET 17 | ||
| 118 | #define V_ASN1_NUMERICSTRING 18 /**/ | ||
| 119 | #define V_ASN1_PRINTABLESTRING 19 | ||
| 120 | #define V_ASN1_T61STRING 20 | ||
| 121 | #define V_ASN1_TELETEXSTRING 20 /* alias */ | ||
| 122 | #define V_ASN1_VIDEOTEXSTRING 21 /**/ | ||
| 123 | #define V_ASN1_IA5STRING 22 | ||
| 124 | #define V_ASN1_UTCTIME 23 | ||
| 125 | #define V_ASN1_GENERALIZEDTIME 24 /**/ | ||
| 126 | #define V_ASN1_GRAPHICSTRING 25 /**/ | ||
| 127 | #define V_ASN1_ISO64STRING 26 /**/ | ||
| 128 | #define V_ASN1_VISIBLESTRING 26 /* alias */ | ||
| 129 | #define V_ASN1_GENERALSTRING 27 /**/ | ||
| 130 | #define V_ASN1_UNIVERSALSTRING 28 /**/ | ||
| 131 | #define V_ASN1_BMPSTRING 30 | ||
| 132 | |||
| 133 | /* For use with d2i_ASN1_type_bytes() */ | ||
| 134 | #define B_ASN1_NUMERICSTRING 0x0001 | ||
| 135 | #define B_ASN1_PRINTABLESTRING 0x0002 | ||
| 136 | #define B_ASN1_T61STRING 0x0004 | ||
| 137 | #define B_ASN1_TELETEXSTRING 0x0004 | ||
| 138 | #define B_ASN1_VIDEOTEXSTRING 0x0008 | ||
| 139 | #define B_ASN1_IA5STRING 0x0010 | ||
| 140 | #define B_ASN1_GRAPHICSTRING 0x0020 | ||
| 141 | #define B_ASN1_ISO64STRING 0x0040 | ||
| 142 | #define B_ASN1_VISIBLESTRING 0x0040 | ||
| 143 | #define B_ASN1_GENERALSTRING 0x0080 | ||
| 144 | #define B_ASN1_UNIVERSALSTRING 0x0100 | ||
| 145 | #define B_ASN1_OCTET_STRING 0x0200 | ||
| 146 | #define B_ASN1_BIT_STRING 0x0400 | ||
| 147 | #define B_ASN1_BMPSTRING 0x0800 | ||
| 148 | #define B_ASN1_UNKNOWN 0x1000 | ||
| 149 | #define B_ASN1_UTF8STRING 0x2000 | ||
| 150 | #define B_ASN1_UTCTIME 0x4000 | ||
| 151 | #define B_ASN1_GENERALIZEDTIME 0x8000 | ||
| 152 | #define B_ASN1_SEQUENCE 0x10000 | ||
| 153 | |||
| 154 | /* For use with ASN1_mbstring_copy() */ | ||
| 155 | #define MBSTRING_FLAG 0x1000 | ||
| 156 | #define MBSTRING_UTF8 (MBSTRING_FLAG) | ||
| 157 | #define MBSTRING_ASC (MBSTRING_FLAG|1) | ||
| 158 | #define MBSTRING_BMP (MBSTRING_FLAG|2) | ||
| 159 | #define MBSTRING_UNIV (MBSTRING_FLAG|4) | ||
| 160 | |||
| 161 | #define SMIME_OLDMIME 0x400 | ||
| 162 | #define SMIME_CRLFEOL 0x800 | ||
| 163 | #define SMIME_STREAM 0x1000 | ||
| 164 | |||
| 165 | struct X509_algor_st; | ||
| 166 | DECLARE_STACK_OF(X509_ALGOR) | ||
| 167 | |||
| 168 | #define DECLARE_ASN1_SET_OF(type) /* filled in by mkstack.pl */ | ||
| 169 | #define IMPLEMENT_ASN1_SET_OF(type) /* nothing, no longer needed */ | ||
| 170 | |||
| 171 | /* We MUST make sure that, except for constness, asn1_ctx_st and | ||
| 172 | asn1_const_ctx are exactly the same. Fortunately, as soon as | ||
| 173 | the old ASN1 parsing macros are gone, we can throw this away | ||
| 174 | as well... */ | ||
| 175 | typedef struct asn1_ctx_st | ||
| 176 | { | ||
| 177 | unsigned char *p;/* work char pointer */ | ||
| 178 | int eos; /* end of sequence read for indefinite encoding */ | ||
| 179 | int error; /* error code to use when returning an error */ | ||
| 180 | int inf; /* constructed if 0x20, indefinite is 0x21 */ | ||
| 181 | int tag; /* tag from last 'get object' */ | ||
| 182 | int xclass; /* class from last 'get object' */ | ||
| 183 | long slen; /* length of last 'get object' */ | ||
| 184 | unsigned char *max; /* largest value of p allowed */ | ||
| 185 | unsigned char *q;/* temporary variable */ | ||
| 186 | unsigned char **pp;/* variable */ | ||
| 187 | int line; /* used in error processing */ | ||
| 188 | } ASN1_CTX; | ||
| 189 | |||
| 190 | typedef struct asn1_const_ctx_st | ||
| 191 | { | ||
| 192 | const unsigned char *p;/* work char pointer */ | ||
| 193 | int eos; /* end of sequence read for indefinite encoding */ | ||
| 194 | int error; /* error code to use when returning an error */ | ||
| 195 | int inf; /* constructed if 0x20, indefinite is 0x21 */ | ||
| 196 | int tag; /* tag from last 'get object' */ | ||
| 197 | int xclass; /* class from last 'get object' */ | ||
| 198 | long slen; /* length of last 'get object' */ | ||
| 199 | const unsigned char *max; /* largest value of p allowed */ | ||
| 200 | const unsigned char *q;/* temporary variable */ | ||
| 201 | const unsigned char **pp;/* variable */ | ||
| 202 | int line; /* used in error processing */ | ||
| 203 | } ASN1_const_CTX; | ||
| 204 | |||
| 205 | /* These are used internally in the ASN1_OBJECT to keep track of | ||
| 206 | * whether the names and data need to be free()ed */ | ||
| 207 | #define ASN1_OBJECT_FLAG_DYNAMIC 0x01 /* internal use */ | ||
| 208 | #define ASN1_OBJECT_FLAG_CRITICAL 0x02 /* critical x509v3 object id */ | ||
| 209 | #define ASN1_OBJECT_FLAG_DYNAMIC_STRINGS 0x04 /* internal use */ | ||
| 210 | #define ASN1_OBJECT_FLAG_DYNAMIC_DATA 0x08 /* internal use */ | ||
| 211 | typedef struct asn1_object_st | ||
| 212 | { | ||
| 213 | const char *sn,*ln; | ||
| 214 | int nid; | ||
| 215 | int length; | ||
| 216 | unsigned char *data; | ||
| 217 | int flags; /* Should we free this one */ | ||
| 218 | } ASN1_OBJECT; | ||
| 219 | |||
| 220 | #define ASN1_STRING_FLAG_BITS_LEFT 0x08 /* Set if 0x07 has bits left value */ | ||
| 221 | /* This indicates that the ASN1_STRING is not a real value but just a place | ||
| 222 | * holder for the location where indefinite length constructed data should | ||
| 223 | * be inserted in the memory buffer | ||
| 224 | */ | ||
| 225 | #define ASN1_STRING_FLAG_NDEF 0x010 | ||
| 226 | |||
| 227 | /* This flag is used by the CMS code to indicate that a string is not | ||
| 228 | * complete and is a place holder for content when it had all been | ||
| 229 | * accessed. The flag will be reset when content has been written to it. | ||
| 230 | */ | ||
| 231 | #define ASN1_STRING_FLAG_CONT 0x020 | ||
| 232 | |||
| 233 | /* This is the base type that holds just about everything :-) */ | ||
| 234 | typedef struct asn1_string_st | ||
| 235 | { | ||
| 236 | int length; | ||
| 237 | int type; | ||
| 238 | unsigned char *data; | ||
| 239 | /* The value of the following field depends on the type being | ||
| 240 | * held. It is mostly being used for BIT_STRING so if the | ||
| 241 | * input data has a non-zero 'unused bits' value, it will be | ||
| 242 | * handled correctly */ | ||
| 243 | long flags; | ||
| 244 | } ASN1_STRING; | ||
| 245 | |||
| 246 | /* ASN1_ENCODING structure: this is used to save the received | ||
| 247 | * encoding of an ASN1 type. This is useful to get round | ||
| 248 | * problems with invalid encodings which can break signatures. | ||
| 249 | */ | ||
| 250 | |||
| 251 | typedef struct ASN1_ENCODING_st | ||
| 252 | { | ||
| 253 | unsigned char *enc; /* DER encoding */ | ||
| 254 | long len; /* Length of encoding */ | ||
| 255 | int modified; /* set to 1 if 'enc' is invalid */ | ||
| 256 | } ASN1_ENCODING; | ||
| 257 | |||
| 258 | /* Used with ASN1 LONG type: if a long is set to this it is omitted */ | ||
| 259 | #define ASN1_LONG_UNDEF 0x7fffffffL | ||
| 260 | |||
| 261 | #define STABLE_FLAGS_MALLOC 0x01 | ||
| 262 | #define STABLE_NO_MASK 0x02 | ||
| 263 | #define DIRSTRING_TYPE \ | ||
| 264 | (B_ASN1_PRINTABLESTRING|B_ASN1_T61STRING|B_ASN1_BMPSTRING|B_ASN1_UTF8STRING) | ||
| 265 | #define PKCS9STRING_TYPE (DIRSTRING_TYPE|B_ASN1_IA5STRING) | ||
| 266 | |||
| 267 | typedef struct asn1_string_table_st { | ||
| 268 | int nid; | ||
| 269 | long minsize; | ||
| 270 | long maxsize; | ||
| 271 | unsigned long mask; | ||
| 272 | unsigned long flags; | ||
| 273 | } ASN1_STRING_TABLE; | ||
| 274 | |||
| 275 | DECLARE_STACK_OF(ASN1_STRING_TABLE) | ||
| 276 | |||
| 277 | /* size limits: this stuff is taken straight from RFC2459 */ | ||
| 278 | |||
| 279 | #define ub_name 32768 | ||
| 280 | #define ub_common_name 64 | ||
| 281 | #define ub_locality_name 128 | ||
| 282 | #define ub_state_name 128 | ||
| 283 | #define ub_organization_name 64 | ||
| 284 | #define ub_organization_unit_name 64 | ||
| 285 | #define ub_title 64 | ||
| 286 | #define ub_email_address 128 | ||
| 287 | |||
| 288 | /* Declarations for template structures: for full definitions | ||
| 289 | * see asn1t.h | ||
| 290 | */ | ||
| 291 | typedef struct ASN1_TEMPLATE_st ASN1_TEMPLATE; | ||
| 292 | typedef struct ASN1_ITEM_st ASN1_ITEM; | ||
| 293 | typedef struct ASN1_TLC_st ASN1_TLC; | ||
| 294 | /* This is just an opaque pointer */ | ||
| 295 | typedef struct ASN1_VALUE_st ASN1_VALUE; | ||
| 296 | |||
| 297 | /* Declare ASN1 functions: the implement macro in in asn1t.h */ | ||
| 298 | |||
| 299 | #define DECLARE_ASN1_FUNCTIONS(type) DECLARE_ASN1_FUNCTIONS_name(type, type) | ||
| 300 | |||
| 301 | #define DECLARE_ASN1_ALLOC_FUNCTIONS(type) \ | ||
| 302 | DECLARE_ASN1_ALLOC_FUNCTIONS_name(type, type) | ||
| 303 | |||
| 304 | #define DECLARE_ASN1_FUNCTIONS_name(type, name) \ | ||
| 305 | DECLARE_ASN1_ALLOC_FUNCTIONS_name(type, name) \ | ||
| 306 | DECLARE_ASN1_ENCODE_FUNCTIONS(type, name, name) | ||
| 307 | |||
| 308 | #define DECLARE_ASN1_FUNCTIONS_fname(type, itname, name) \ | ||
| 309 | DECLARE_ASN1_ALLOC_FUNCTIONS_name(type, name) \ | ||
| 310 | DECLARE_ASN1_ENCODE_FUNCTIONS(type, itname, name) | ||
| 311 | |||
| 312 | #define DECLARE_ASN1_ENCODE_FUNCTIONS(type, itname, name) \ | ||
| 313 | type *d2i_##name(type **a, const unsigned char **in, long len); \ | ||
| 314 | int i2d_##name(type *a, unsigned char **out); \ | ||
| 315 | DECLARE_ASN1_ITEM(itname) | ||
| 316 | |||
| 317 | #define DECLARE_ASN1_ENCODE_FUNCTIONS_const(type, name) \ | ||
| 318 | type *d2i_##name(type **a, const unsigned char **in, long len); \ | ||
| 319 | int i2d_##name(const type *a, unsigned char **out); \ | ||
| 320 | DECLARE_ASN1_ITEM(name) | ||
| 321 | |||
| 322 | #define DECLARE_ASN1_NDEF_FUNCTION(name) \ | ||
| 323 | int i2d_##name##_NDEF(name *a, unsigned char **out); | ||
| 324 | |||
| 325 | #define DECLARE_ASN1_FUNCTIONS_const(name) \ | ||
| 326 | DECLARE_ASN1_ALLOC_FUNCTIONS(name) \ | ||
| 327 | DECLARE_ASN1_ENCODE_FUNCTIONS_const(name, name) | ||
| 328 | |||
| 329 | #define DECLARE_ASN1_ALLOC_FUNCTIONS_name(type, name) \ | ||
| 330 | type *name##_new(void); \ | ||
| 331 | void name##_free(type *a); | ||
| 332 | |||
| 333 | #define D2I_OF(type) type *(*)(type **,const unsigned char **,long) | ||
| 334 | #define I2D_OF(type) int (*)(type *,unsigned char **) | ||
| 335 | #define I2D_OF_const(type) int (*)(const type *,unsigned char **) | ||
| 336 | |||
| 337 | #define CHECKED_D2I_OF(type, d2i) \ | ||
| 338 | ((d2i_of_void*) (1 ? d2i : ((D2I_OF(type))0))) | ||
| 339 | #define CHECKED_I2D_OF(type, i2d) \ | ||
| 340 | ((i2d_of_void*) (1 ? i2d : ((I2D_OF(type))0))) | ||
| 341 | #define CHECKED_NEW_OF(type, xnew) \ | ||
| 342 | ((void *(*)(void)) (1 ? xnew : ((type *(*)(void))0))) | ||
| 343 | #define CHECKED_PTR_OF(type, p) \ | ||
| 344 | ((void*) (1 ? p : (type*)0)) | ||
| 345 | #define CHECKED_PPTR_OF(type, p) \ | ||
| 346 | ((void**) (1 ? p : (type**)0)) | ||
| 347 | |||
| 348 | #define TYPEDEF_D2I_OF(type) typedef type *d2i_of_##type(type **,const unsigned char **,long) | ||
| 349 | #define TYPEDEF_I2D_OF(type) typedef int i2d_of_##type(type *,unsigned char **) | ||
| 350 | #define TYPEDEF_D2I2D_OF(type) TYPEDEF_D2I_OF(type); TYPEDEF_I2D_OF(type) | ||
| 351 | |||
| 352 | TYPEDEF_D2I2D_OF(void); | ||
| 353 | |||
| 354 | /* The following macros and typedefs allow an ASN1_ITEM | ||
| 355 | * to be embedded in a structure and referenced. Since | ||
| 356 | * the ASN1_ITEM pointers need to be globally accessible | ||
| 357 | * (possibly from shared libraries) they may exist in | ||
| 358 | * different forms. On platforms that support it the | ||
| 359 | * ASN1_ITEM structure itself will be globally exported. | ||
| 360 | * Other platforms will export a function that returns | ||
| 361 | * an ASN1_ITEM pointer. | ||
| 362 | * | ||
| 363 | * To handle both cases transparently the macros below | ||
| 364 | * should be used instead of hard coding an ASN1_ITEM | ||
| 365 | * pointer in a structure. | ||
| 366 | * | ||
| 367 | * The structure will look like this: | ||
| 368 | * | ||
| 369 | * typedef struct SOMETHING_st { | ||
| 370 | * ... | ||
| 371 | * ASN1_ITEM_EXP *iptr; | ||
| 372 | * ... | ||
| 373 | * } SOMETHING; | ||
| 374 | * | ||
| 375 | * It would be initialised as e.g.: | ||
| 376 | * | ||
| 377 | * SOMETHING somevar = {...,ASN1_ITEM_ref(X509),...}; | ||
| 378 | * | ||
| 379 | * and the actual pointer extracted with: | ||
| 380 | * | ||
| 381 | * const ASN1_ITEM *it = ASN1_ITEM_ptr(somevar.iptr); | ||
| 382 | * | ||
| 383 | * Finally an ASN1_ITEM pointer can be extracted from an | ||
| 384 | * appropriate reference with: ASN1_ITEM_rptr(X509). This | ||
| 385 | * would be used when a function takes an ASN1_ITEM * argument. | ||
| 386 | * | ||
| 387 | */ | ||
| 388 | |||
| 389 | #ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION | ||
| 390 | |||
| 391 | /* ASN1_ITEM pointer exported type */ | ||
| 392 | typedef const ASN1_ITEM ASN1_ITEM_EXP; | ||
| 393 | |||
| 394 | /* Macro to obtain ASN1_ITEM pointer from exported type */ | ||
| 395 | #define ASN1_ITEM_ptr(iptr) (iptr) | ||
| 396 | |||
| 397 | /* Macro to include ASN1_ITEM pointer from base type */ | ||
| 398 | #define ASN1_ITEM_ref(iptr) (&(iptr##_it)) | ||
| 399 | |||
| 400 | #define ASN1_ITEM_rptr(ref) (&(ref##_it)) | ||
| 401 | |||
| 402 | #define DECLARE_ASN1_ITEM(name) \ | ||
| 403 | OPENSSL_EXTERN const ASN1_ITEM name##_it; | ||
| 404 | |||
| 405 | #else | ||
| 406 | |||
| 407 | /* Platforms that can't easily handle shared global variables are declared | ||
| 408 | * as functions returning ASN1_ITEM pointers. | ||
| 409 | */ | ||
| 410 | |||
| 411 | /* ASN1_ITEM pointer exported type */ | ||
| 412 | typedef const ASN1_ITEM * ASN1_ITEM_EXP(void); | ||
| 413 | |||
| 414 | /* Macro to obtain ASN1_ITEM pointer from exported type */ | ||
| 415 | #define ASN1_ITEM_ptr(iptr) (iptr()) | ||
| 416 | |||
| 417 | /* Macro to include ASN1_ITEM pointer from base type */ | ||
| 418 | #define ASN1_ITEM_ref(iptr) (iptr##_it) | ||
| 419 | |||
| 420 | #define ASN1_ITEM_rptr(ref) (ref##_it()) | ||
| 421 | |||
| 422 | #define DECLARE_ASN1_ITEM(name) \ | ||
| 423 | const ASN1_ITEM * name##_it(void); | ||
| 424 | |||
| 425 | #endif | ||
| 426 | |||
| 427 | /* Parameters used by ASN1_STRING_print_ex() */ | ||
| 428 | |||
| 429 | /* These determine which characters to escape: | ||
| 430 | * RFC2253 special characters, control characters and | ||
| 431 | * MSB set characters | ||
| 432 | */ | ||
| 433 | |||
| 434 | #define ASN1_STRFLGS_ESC_2253 1 | ||
| 435 | #define ASN1_STRFLGS_ESC_CTRL 2 | ||
| 436 | #define ASN1_STRFLGS_ESC_MSB 4 | ||
| 437 | |||
| 438 | |||
| 439 | /* This flag determines how we do escaping: normally | ||
| 440 | * RC2253 backslash only, set this to use backslash and | ||
| 441 | * quote. | ||
| 442 | */ | ||
| 443 | |||
| 444 | #define ASN1_STRFLGS_ESC_QUOTE 8 | ||
| 445 | |||
| 446 | |||
| 447 | /* These three flags are internal use only. */ | ||
| 448 | |||
| 449 | /* Character is a valid PrintableString character */ | ||
| 450 | #define CHARTYPE_PRINTABLESTRING 0x10 | ||
| 451 | /* Character needs escaping if it is the first character */ | ||
| 452 | #define CHARTYPE_FIRST_ESC_2253 0x20 | ||
| 453 | /* Character needs escaping if it is the last character */ | ||
| 454 | #define CHARTYPE_LAST_ESC_2253 0x40 | ||
| 455 | |||
| 456 | /* NB the internal flags are safely reused below by flags | ||
| 457 | * handled at the top level. | ||
| 458 | */ | ||
| 459 | |||
| 460 | /* If this is set we convert all character strings | ||
| 461 | * to UTF8 first | ||
| 462 | */ | ||
| 463 | |||
| 464 | #define ASN1_STRFLGS_UTF8_CONVERT 0x10 | ||
| 465 | |||
| 466 | /* If this is set we don't attempt to interpret content: | ||
| 467 | * just assume all strings are 1 byte per character. This | ||
| 468 | * will produce some pretty odd looking output! | ||
| 469 | */ | ||
| 470 | |||
| 471 | #define ASN1_STRFLGS_IGNORE_TYPE 0x20 | ||
| 472 | |||
| 473 | /* If this is set we include the string type in the output */ | ||
| 474 | #define ASN1_STRFLGS_SHOW_TYPE 0x40 | ||
| 475 | |||
| 476 | /* This determines which strings to display and which to | ||
| 477 | * 'dump' (hex dump of content octets or DER encoding). We can | ||
| 478 | * only dump non character strings or everything. If we | ||
| 479 | * don't dump 'unknown' they are interpreted as character | ||
| 480 | * strings with 1 octet per character and are subject to | ||
| 481 | * the usual escaping options. | ||
| 482 | */ | ||
| 483 | |||
| 484 | #define ASN1_STRFLGS_DUMP_ALL 0x80 | ||
| 485 | #define ASN1_STRFLGS_DUMP_UNKNOWN 0x100 | ||
| 486 | |||
| 487 | /* These determine what 'dumping' does, we can dump the | ||
| 488 | * content octets or the DER encoding: both use the | ||
| 489 | * RFC2253 #XXXXX notation. | ||
| 490 | */ | ||
| 491 | |||
| 492 | #define ASN1_STRFLGS_DUMP_DER 0x200 | ||
| 493 | |||
| 494 | /* All the string flags consistent with RFC2253, | ||
| 495 | * escaping control characters isn't essential in | ||
| 496 | * RFC2253 but it is advisable anyway. | ||
| 497 | */ | ||
| 498 | |||
| 499 | #define ASN1_STRFLGS_RFC2253 (ASN1_STRFLGS_ESC_2253 | \ | ||
| 500 | ASN1_STRFLGS_ESC_CTRL | \ | ||
| 501 | ASN1_STRFLGS_ESC_MSB | \ | ||
| 502 | ASN1_STRFLGS_UTF8_CONVERT | \ | ||
| 503 | ASN1_STRFLGS_DUMP_UNKNOWN | \ | ||
| 504 | ASN1_STRFLGS_DUMP_DER) | ||
| 505 | |||
| 506 | DECLARE_STACK_OF(ASN1_INTEGER) | ||
| 507 | DECLARE_ASN1_SET_OF(ASN1_INTEGER) | ||
| 508 | |||
| 509 | DECLARE_STACK_OF(ASN1_GENERALSTRING) | ||
| 510 | |||
| 511 | typedef struct asn1_type_st | ||
| 512 | { | ||
| 513 | int type; | ||
| 514 | union { | ||
| 515 | char *ptr; | ||
| 516 | ASN1_BOOLEAN boolean; | ||
| 517 | ASN1_STRING * asn1_string; | ||
| 518 | ASN1_OBJECT * object; | ||
| 519 | ASN1_INTEGER * integer; | ||
| 520 | ASN1_ENUMERATED * enumerated; | ||
| 521 | ASN1_BIT_STRING * bit_string; | ||
| 522 | ASN1_OCTET_STRING * octet_string; | ||
| 523 | ASN1_PRINTABLESTRING * printablestring; | ||
| 524 | ASN1_T61STRING * t61string; | ||
| 525 | ASN1_IA5STRING * ia5string; | ||
| 526 | ASN1_GENERALSTRING * generalstring; | ||
| 527 | ASN1_BMPSTRING * bmpstring; | ||
| 528 | ASN1_UNIVERSALSTRING * universalstring; | ||
| 529 | ASN1_UTCTIME * utctime; | ||
| 530 | ASN1_GENERALIZEDTIME * generalizedtime; | ||
| 531 | ASN1_VISIBLESTRING * visiblestring; | ||
| 532 | ASN1_UTF8STRING * utf8string; | ||
| 533 | /* set and sequence are left complete and still | ||
| 534 | * contain the set or sequence bytes */ | ||
| 535 | ASN1_STRING * set; | ||
| 536 | ASN1_STRING * sequence; | ||
| 537 | ASN1_VALUE * asn1_value; | ||
| 538 | } value; | ||
| 539 | } ASN1_TYPE; | ||
| 540 | |||
| 541 | DECLARE_STACK_OF(ASN1_TYPE) | ||
| 542 | DECLARE_ASN1_SET_OF(ASN1_TYPE) | ||
| 543 | |||
| 544 | typedef struct asn1_method_st | ||
| 545 | { | ||
| 546 | i2d_of_void *i2d; | ||
| 547 | d2i_of_void *d2i; | ||
| 548 | void *(*create)(void); | ||
| 549 | void (*destroy)(void *); | ||
| 550 | } ASN1_METHOD; | ||
| 551 | |||
| 552 | /* This is used when parsing some Netscape objects */ | ||
| 553 | typedef struct asn1_header_st | ||
| 554 | { | ||
| 555 | ASN1_OCTET_STRING *header; | ||
| 556 | void *data; | ||
| 557 | ASN1_METHOD *meth; | ||
| 558 | } ASN1_HEADER; | ||
| 559 | |||
| 560 | /* This is used to contain a list of bit names */ | ||
| 561 | typedef struct BIT_STRING_BITNAME_st { | ||
| 562 | int bitnum; | ||
| 563 | const char *lname; | ||
| 564 | const char *sname; | ||
| 565 | } BIT_STRING_BITNAME; | ||
| 566 | |||
| 567 | |||
| 568 | #define M_ASN1_STRING_length(x) ((x)->length) | ||
| 569 | #define M_ASN1_STRING_length_set(x, n) ((x)->length = (n)) | ||
| 570 | #define M_ASN1_STRING_type(x) ((x)->type) | ||
| 571 | #define M_ASN1_STRING_data(x) ((x)->data) | ||
| 572 | |||
| 573 | /* Macros for string operations */ | ||
| 574 | #define M_ASN1_BIT_STRING_new() (ASN1_BIT_STRING *)\ | ||
| 575 | ASN1_STRING_type_new(V_ASN1_BIT_STRING) | ||
| 576 | #define M_ASN1_BIT_STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a) | ||
| 577 | #define M_ASN1_BIT_STRING_dup(a) (ASN1_BIT_STRING *)\ | ||
| 578 | ASN1_STRING_dup((ASN1_STRING *)a) | ||
| 579 | #define M_ASN1_BIT_STRING_cmp(a,b) ASN1_STRING_cmp(\ | ||
| 580 | (ASN1_STRING *)a,(ASN1_STRING *)b) | ||
| 581 | #define M_ASN1_BIT_STRING_set(a,b,c) ASN1_STRING_set((ASN1_STRING *)a,b,c) | ||
| 582 | |||
| 583 | #define M_ASN1_INTEGER_new() (ASN1_INTEGER *)\ | ||
| 584 | ASN1_STRING_type_new(V_ASN1_INTEGER) | ||
| 585 | #define M_ASN1_INTEGER_free(a) ASN1_STRING_free((ASN1_STRING *)a) | ||
| 586 | #define M_ASN1_INTEGER_dup(a) (ASN1_INTEGER *)ASN1_STRING_dup((ASN1_STRING *)a) | ||
| 587 | #define M_ASN1_INTEGER_cmp(a,b) ASN1_STRING_cmp(\ | ||
| 588 | (ASN1_STRING *)a,(ASN1_STRING *)b) | ||
| 589 | |||
| 590 | #define M_ASN1_ENUMERATED_new() (ASN1_ENUMERATED *)\ | ||
| 591 | ASN1_STRING_type_new(V_ASN1_ENUMERATED) | ||
| 592 | #define M_ASN1_ENUMERATED_free(a) ASN1_STRING_free((ASN1_STRING *)a) | ||
| 593 | #define M_ASN1_ENUMERATED_dup(a) (ASN1_ENUMERATED *)ASN1_STRING_dup((ASN1_STRING *)a) | ||
| 594 | #define M_ASN1_ENUMERATED_cmp(a,b) ASN1_STRING_cmp(\ | ||
| 595 | (ASN1_STRING *)a,(ASN1_STRING *)b) | ||
| 596 | |||
| 597 | #define M_ASN1_OCTET_STRING_new() (ASN1_OCTET_STRING *)\ | ||
| 598 | ASN1_STRING_type_new(V_ASN1_OCTET_STRING) | ||
| 599 | #define M_ASN1_OCTET_STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a) | ||
| 600 | #define M_ASN1_OCTET_STRING_dup(a) (ASN1_OCTET_STRING *)\ | ||
| 601 | ASN1_STRING_dup((ASN1_STRING *)a) | ||
| 602 | #define M_ASN1_OCTET_STRING_cmp(a,b) ASN1_STRING_cmp(\ | ||
| 603 | (ASN1_STRING *)a,(ASN1_STRING *)b) | ||
| 604 | #define M_ASN1_OCTET_STRING_set(a,b,c) ASN1_STRING_set((ASN1_STRING *)a,b,c) | ||
| 605 | #define M_ASN1_OCTET_STRING_print(a,b) ASN1_STRING_print(a,(ASN1_STRING *)b) | ||
| 606 | #define M_i2d_ASN1_OCTET_STRING(a,pp) \ | ||
| 607 | i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_OCTET_STRING,\ | ||
| 608 | V_ASN1_UNIVERSAL) | ||
| 609 | |||
| 610 | #define B_ASN1_TIME \ | ||
| 611 | B_ASN1_UTCTIME | \ | ||
| 612 | B_ASN1_GENERALIZEDTIME | ||
| 613 | |||
| 614 | #define B_ASN1_PRINTABLE \ | ||
| 615 | B_ASN1_PRINTABLESTRING| \ | ||
| 616 | B_ASN1_T61STRING| \ | ||
| 617 | B_ASN1_IA5STRING| \ | ||
| 618 | B_ASN1_BIT_STRING| \ | ||
| 619 | B_ASN1_UNIVERSALSTRING|\ | ||
| 620 | B_ASN1_BMPSTRING|\ | ||
| 621 | B_ASN1_UTF8STRING|\ | ||
| 622 | B_ASN1_SEQUENCE|\ | ||
| 623 | B_ASN1_UNKNOWN | ||
| 624 | |||
| 625 | #define B_ASN1_DIRECTORYSTRING \ | ||
| 626 | B_ASN1_PRINTABLESTRING| \ | ||
| 627 | B_ASN1_TELETEXSTRING|\ | ||
| 628 | B_ASN1_BMPSTRING|\ | ||
| 629 | B_ASN1_UNIVERSALSTRING|\ | ||
| 630 | B_ASN1_UTF8STRING | ||
| 631 | |||
| 632 | #define B_ASN1_DISPLAYTEXT \ | ||
| 633 | B_ASN1_IA5STRING| \ | ||
| 634 | B_ASN1_VISIBLESTRING| \ | ||
| 635 | B_ASN1_BMPSTRING|\ | ||
| 636 | B_ASN1_UTF8STRING | ||
| 637 | |||
| 638 | #define M_ASN1_PRINTABLE_new() ASN1_STRING_type_new(V_ASN1_T61STRING) | ||
| 639 | #define M_ASN1_PRINTABLE_free(a) ASN1_STRING_free((ASN1_STRING *)a) | ||
| 640 | #define M_i2d_ASN1_PRINTABLE(a,pp) i2d_ASN1_bytes((ASN1_STRING *)a,\ | ||
| 641 | pp,a->type,V_ASN1_UNIVERSAL) | ||
| 642 | #define M_d2i_ASN1_PRINTABLE(a,pp,l) \ | ||
| 643 | d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l, \ | ||
| 644 | B_ASN1_PRINTABLE) | ||
| 645 | |||
| 646 | #define M_DIRECTORYSTRING_new() ASN1_STRING_type_new(V_ASN1_PRINTABLESTRING) | ||
| 647 | #define M_DIRECTORYSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a) | ||
| 648 | #define M_i2d_DIRECTORYSTRING(a,pp) i2d_ASN1_bytes((ASN1_STRING *)a,\ | ||
| 649 | pp,a->type,V_ASN1_UNIVERSAL) | ||
| 650 | #define M_d2i_DIRECTORYSTRING(a,pp,l) \ | ||
| 651 | d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l, \ | ||
| 652 | B_ASN1_DIRECTORYSTRING) | ||
| 653 | |||
| 654 | #define M_DISPLAYTEXT_new() ASN1_STRING_type_new(V_ASN1_VISIBLESTRING) | ||
| 655 | #define M_DISPLAYTEXT_free(a) ASN1_STRING_free((ASN1_STRING *)a) | ||
| 656 | #define M_i2d_DISPLAYTEXT(a,pp) i2d_ASN1_bytes((ASN1_STRING *)a,\ | ||
| 657 | pp,a->type,V_ASN1_UNIVERSAL) | ||
| 658 | #define M_d2i_DISPLAYTEXT(a,pp,l) \ | ||
| 659 | d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l, \ | ||
| 660 | B_ASN1_DISPLAYTEXT) | ||
| 661 | |||
| 662 | #define M_ASN1_PRINTABLESTRING_new() (ASN1_PRINTABLESTRING *)\ | ||
| 663 | ASN1_STRING_type_new(V_ASN1_PRINTABLESTRING) | ||
| 664 | #define M_ASN1_PRINTABLESTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a) | ||
| 665 | #define M_i2d_ASN1_PRINTABLESTRING(a,pp) \ | ||
| 666 | i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_PRINTABLESTRING,\ | ||
| 667 | V_ASN1_UNIVERSAL) | ||
| 668 | #define M_d2i_ASN1_PRINTABLESTRING(a,pp,l) \ | ||
| 669 | (ASN1_PRINTABLESTRING *)d2i_ASN1_type_bytes\ | ||
| 670 | ((ASN1_STRING **)a,pp,l,B_ASN1_PRINTABLESTRING) | ||
| 671 | |||
| 672 | #define M_ASN1_T61STRING_new() (ASN1_T61STRING *)\ | ||
| 673 | ASN1_STRING_type_new(V_ASN1_T61STRING) | ||
| 674 | #define M_ASN1_T61STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a) | ||
| 675 | #define M_i2d_ASN1_T61STRING(a,pp) \ | ||
| 676 | i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_T61STRING,\ | ||
| 677 | V_ASN1_UNIVERSAL) | ||
| 678 | #define M_d2i_ASN1_T61STRING(a,pp,l) \ | ||
| 679 | (ASN1_T61STRING *)d2i_ASN1_type_bytes\ | ||
| 680 | ((ASN1_STRING **)a,pp,l,B_ASN1_T61STRING) | ||
| 681 | |||
| 682 | #define M_ASN1_IA5STRING_new() (ASN1_IA5STRING *)\ | ||
| 683 | ASN1_STRING_type_new(V_ASN1_IA5STRING) | ||
| 684 | #define M_ASN1_IA5STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a) | ||
| 685 | #define M_ASN1_IA5STRING_dup(a) \ | ||
| 686 | (ASN1_IA5STRING *)ASN1_STRING_dup((ASN1_STRING *)a) | ||
| 687 | #define M_i2d_ASN1_IA5STRING(a,pp) \ | ||
| 688 | i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_IA5STRING,\ | ||
| 689 | V_ASN1_UNIVERSAL) | ||
| 690 | #define M_d2i_ASN1_IA5STRING(a,pp,l) \ | ||
| 691 | (ASN1_IA5STRING *)d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l,\ | ||
| 692 | B_ASN1_IA5STRING) | ||
| 693 | |||
| 694 | #define M_ASN1_UTCTIME_new() (ASN1_UTCTIME *)\ | ||
| 695 | ASN1_STRING_type_new(V_ASN1_UTCTIME) | ||
| 696 | #define M_ASN1_UTCTIME_free(a) ASN1_STRING_free((ASN1_STRING *)a) | ||
| 697 | #define M_ASN1_UTCTIME_dup(a) (ASN1_UTCTIME *)ASN1_STRING_dup((ASN1_STRING *)a) | ||
| 698 | |||
| 699 | #define M_ASN1_GENERALIZEDTIME_new() (ASN1_GENERALIZEDTIME *)\ | ||
| 700 | ASN1_STRING_type_new(V_ASN1_GENERALIZEDTIME) | ||
| 701 | #define M_ASN1_GENERALIZEDTIME_free(a) ASN1_STRING_free((ASN1_STRING *)a) | ||
| 702 | #define M_ASN1_GENERALIZEDTIME_dup(a) (ASN1_GENERALIZEDTIME *)ASN1_STRING_dup(\ | ||
| 703 | (ASN1_STRING *)a) | ||
| 704 | |||
| 705 | #define M_ASN1_TIME_new() (ASN1_TIME *)\ | ||
| 706 | ASN1_STRING_type_new(V_ASN1_UTCTIME) | ||
| 707 | #define M_ASN1_TIME_free(a) ASN1_STRING_free((ASN1_STRING *)a) | ||
| 708 | #define M_ASN1_TIME_dup(a) (ASN1_TIME *)ASN1_STRING_dup((ASN1_STRING *)a) | ||
| 709 | |||
| 710 | #define M_ASN1_GENERALSTRING_new() (ASN1_GENERALSTRING *)\ | ||
| 711 | ASN1_STRING_type_new(V_ASN1_GENERALSTRING) | ||
| 712 | #define M_ASN1_GENERALSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a) | ||
| 713 | #define M_i2d_ASN1_GENERALSTRING(a,pp) \ | ||
| 714 | i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_GENERALSTRING,\ | ||
| 715 | V_ASN1_UNIVERSAL) | ||
| 716 | #define M_d2i_ASN1_GENERALSTRING(a,pp,l) \ | ||
| 717 | (ASN1_GENERALSTRING *)d2i_ASN1_type_bytes\ | ||
| 718 | ((ASN1_STRING **)a,pp,l,B_ASN1_GENERALSTRING) | ||
| 719 | |||
| 720 | #define M_ASN1_UNIVERSALSTRING_new() (ASN1_UNIVERSALSTRING *)\ | ||
| 721 | ASN1_STRING_type_new(V_ASN1_UNIVERSALSTRING) | ||
| 722 | #define M_ASN1_UNIVERSALSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a) | ||
| 723 | #define M_i2d_ASN1_UNIVERSALSTRING(a,pp) \ | ||
| 724 | i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_UNIVERSALSTRING,\ | ||
| 725 | V_ASN1_UNIVERSAL) | ||
| 726 | #define M_d2i_ASN1_UNIVERSALSTRING(a,pp,l) \ | ||
| 727 | (ASN1_UNIVERSALSTRING *)d2i_ASN1_type_bytes\ | ||
| 728 | ((ASN1_STRING **)a,pp,l,B_ASN1_UNIVERSALSTRING) | ||
| 729 | |||
| 730 | #define M_ASN1_BMPSTRING_new() (ASN1_BMPSTRING *)\ | ||
| 731 | ASN1_STRING_type_new(V_ASN1_BMPSTRING) | ||
| 732 | #define M_ASN1_BMPSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a) | ||
| 733 | #define M_i2d_ASN1_BMPSTRING(a,pp) \ | ||
| 734 | i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_BMPSTRING,\ | ||
| 735 | V_ASN1_UNIVERSAL) | ||
| 736 | #define M_d2i_ASN1_BMPSTRING(a,pp,l) \ | ||
| 737 | (ASN1_BMPSTRING *)d2i_ASN1_type_bytes\ | ||
| 738 | ((ASN1_STRING **)a,pp,l,B_ASN1_BMPSTRING) | ||
| 739 | |||
| 740 | #define M_ASN1_VISIBLESTRING_new() (ASN1_VISIBLESTRING *)\ | ||
| 741 | ASN1_STRING_type_new(V_ASN1_VISIBLESTRING) | ||
| 742 | #define M_ASN1_VISIBLESTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a) | ||
| 743 | #define M_i2d_ASN1_VISIBLESTRING(a,pp) \ | ||
| 744 | i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_VISIBLESTRING,\ | ||
| 745 | V_ASN1_UNIVERSAL) | ||
| 746 | #define M_d2i_ASN1_VISIBLESTRING(a,pp,l) \ | ||
| 747 | (ASN1_VISIBLESTRING *)d2i_ASN1_type_bytes\ | ||
| 748 | ((ASN1_STRING **)a,pp,l,B_ASN1_VISIBLESTRING) | ||
| 749 | |||
| 750 | #define M_ASN1_UTF8STRING_new() (ASN1_UTF8STRING *)\ | ||
| 751 | ASN1_STRING_type_new(V_ASN1_UTF8STRING) | ||
| 752 | #define M_ASN1_UTF8STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a) | ||
| 753 | #define M_i2d_ASN1_UTF8STRING(a,pp) \ | ||
| 754 | i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_UTF8STRING,\ | ||
| 755 | V_ASN1_UNIVERSAL) | ||
| 756 | #define M_d2i_ASN1_UTF8STRING(a,pp,l) \ | ||
| 757 | (ASN1_UTF8STRING *)d2i_ASN1_type_bytes\ | ||
| 758 | ((ASN1_STRING **)a,pp,l,B_ASN1_UTF8STRING) | ||
| 759 | |||
| 760 | /* for the is_set parameter to i2d_ASN1_SET */ | ||
| 761 | #define IS_SEQUENCE 0 | ||
| 762 | #define IS_SET 1 | ||
| 763 | |||
| 764 | DECLARE_ASN1_FUNCTIONS_fname(ASN1_TYPE, ASN1_ANY, ASN1_TYPE) | ||
| 765 | |||
| 766 | int ASN1_TYPE_get(ASN1_TYPE *a); | ||
| 767 | void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value); | ||
| 768 | int ASN1_TYPE_set1(ASN1_TYPE *a, int type, const void *value); | ||
| 769 | |||
| 770 | ASN1_OBJECT * ASN1_OBJECT_new(void ); | ||
| 771 | void ASN1_OBJECT_free(ASN1_OBJECT *a); | ||
| 772 | int i2d_ASN1_OBJECT(ASN1_OBJECT *a,unsigned char **pp); | ||
| 773 | ASN1_OBJECT * c2i_ASN1_OBJECT(ASN1_OBJECT **a,const unsigned char **pp, | ||
| 774 | long length); | ||
| 775 | ASN1_OBJECT * d2i_ASN1_OBJECT(ASN1_OBJECT **a,const unsigned char **pp, | ||
| 776 | long length); | ||
| 777 | |||
| 778 | DECLARE_ASN1_ITEM(ASN1_OBJECT) | ||
| 779 | |||
| 780 | DECLARE_STACK_OF(ASN1_OBJECT) | ||
| 781 | DECLARE_ASN1_SET_OF(ASN1_OBJECT) | ||
| 782 | |||
| 783 | ASN1_STRING * ASN1_STRING_new(void); | ||
| 784 | void ASN1_STRING_free(ASN1_STRING *a); | ||
| 785 | ASN1_STRING * ASN1_STRING_dup(ASN1_STRING *a); | ||
| 786 | ASN1_STRING * ASN1_STRING_type_new(int type ); | ||
| 787 | int ASN1_STRING_cmp(ASN1_STRING *a, ASN1_STRING *b); | ||
| 788 | /* Since this is used to store all sorts of things, via macros, for now, make | ||
| 789 | its data void * */ | ||
| 790 | int ASN1_STRING_set(ASN1_STRING *str, const void *data, int len); | ||
| 791 | void ASN1_STRING_set0(ASN1_STRING *str, void *data, int len); | ||
| 792 | int ASN1_STRING_length(ASN1_STRING *x); | ||
| 793 | void ASN1_STRING_length_set(ASN1_STRING *x, int n); | ||
| 794 | int ASN1_STRING_type(ASN1_STRING *x); | ||
| 795 | unsigned char * ASN1_STRING_data(ASN1_STRING *x); | ||
| 796 | |||
| 797 | DECLARE_ASN1_FUNCTIONS(ASN1_BIT_STRING) | ||
| 798 | int i2c_ASN1_BIT_STRING(ASN1_BIT_STRING *a,unsigned char **pp); | ||
| 799 | ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,const unsigned char **pp, | ||
| 800 | long length); | ||
| 801 | int ASN1_BIT_STRING_set(ASN1_BIT_STRING *a, unsigned char *d, | ||
| 802 | int length ); | ||
| 803 | int ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value); | ||
| 804 | int ASN1_BIT_STRING_get_bit(ASN1_BIT_STRING *a, int n); | ||
| 805 | |||
| 806 | #ifndef OPENSSL_NO_BIO | ||
| 807 | int ASN1_BIT_STRING_name_print(BIO *out, ASN1_BIT_STRING *bs, | ||
| 808 | BIT_STRING_BITNAME *tbl, int indent); | ||
| 809 | #endif | ||
| 810 | int ASN1_BIT_STRING_num_asc(char *name, BIT_STRING_BITNAME *tbl); | ||
| 811 | int ASN1_BIT_STRING_set_asc(ASN1_BIT_STRING *bs, char *name, int value, | ||
| 812 | BIT_STRING_BITNAME *tbl); | ||
| 813 | |||
| 814 | int i2d_ASN1_BOOLEAN(int a,unsigned char **pp); | ||
| 815 | int d2i_ASN1_BOOLEAN(int *a,const unsigned char **pp,long length); | ||
| 816 | |||
| 817 | DECLARE_ASN1_FUNCTIONS(ASN1_INTEGER) | ||
| 818 | int i2c_ASN1_INTEGER(ASN1_INTEGER *a,unsigned char **pp); | ||
| 819 | ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **a,const unsigned char **pp, | ||
| 820 | long length); | ||
| 821 | ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a,const unsigned char **pp, | ||
| 822 | long length); | ||
| 823 | ASN1_INTEGER * ASN1_INTEGER_dup(ASN1_INTEGER *x); | ||
| 824 | int ASN1_INTEGER_cmp(ASN1_INTEGER *x, ASN1_INTEGER *y); | ||
| 825 | |||
| 826 | DECLARE_ASN1_FUNCTIONS(ASN1_ENUMERATED) | ||
| 827 | |||
| 828 | int ASN1_UTCTIME_check(ASN1_UTCTIME *a); | ||
| 829 | ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s,time_t t); | ||
| 830 | int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, const char *str); | ||
| 831 | int ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t); | ||
| 832 | #if 0 | ||
| 833 | time_t ASN1_UTCTIME_get(const ASN1_UTCTIME *s); | ||
| 834 | #endif | ||
| 835 | |||
| 836 | int ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *a); | ||
| 837 | ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s,time_t t); | ||
| 838 | int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, const char *str); | ||
| 839 | |||
| 840 | DECLARE_ASN1_FUNCTIONS(ASN1_OCTET_STRING) | ||
| 841 | ASN1_OCTET_STRING * ASN1_OCTET_STRING_dup(ASN1_OCTET_STRING *a); | ||
| 842 | int ASN1_OCTET_STRING_cmp(ASN1_OCTET_STRING *a, ASN1_OCTET_STRING *b); | ||
| 843 | int ASN1_OCTET_STRING_set(ASN1_OCTET_STRING *str, const unsigned char *data, int len); | ||
| 844 | |||
| 845 | DECLARE_ASN1_FUNCTIONS(ASN1_VISIBLESTRING) | ||
| 846 | DECLARE_ASN1_FUNCTIONS(ASN1_UNIVERSALSTRING) | ||
| 847 | DECLARE_ASN1_FUNCTIONS(ASN1_UTF8STRING) | ||
| 848 | DECLARE_ASN1_FUNCTIONS(ASN1_NULL) | ||
| 849 | DECLARE_ASN1_FUNCTIONS(ASN1_BMPSTRING) | ||
| 850 | |||
| 851 | int UTF8_getc(const unsigned char *str, int len, unsigned long *val); | ||
| 852 | int UTF8_putc(unsigned char *str, int len, unsigned long value); | ||
| 853 | |||
| 854 | DECLARE_ASN1_FUNCTIONS_name(ASN1_STRING, ASN1_PRINTABLE) | ||
| 855 | |||
| 856 | DECLARE_ASN1_FUNCTIONS_name(ASN1_STRING, DIRECTORYSTRING) | ||
| 857 | DECLARE_ASN1_FUNCTIONS_name(ASN1_STRING, DISPLAYTEXT) | ||
| 858 | DECLARE_ASN1_FUNCTIONS(ASN1_PRINTABLESTRING) | ||
| 859 | DECLARE_ASN1_FUNCTIONS(ASN1_T61STRING) | ||
| 860 | DECLARE_ASN1_FUNCTIONS(ASN1_IA5STRING) | ||
| 861 | DECLARE_ASN1_FUNCTIONS(ASN1_GENERALSTRING) | ||
| 862 | DECLARE_ASN1_FUNCTIONS(ASN1_UTCTIME) | ||
| 863 | DECLARE_ASN1_FUNCTIONS(ASN1_GENERALIZEDTIME) | ||
| 864 | DECLARE_ASN1_FUNCTIONS(ASN1_TIME) | ||
| 865 | |||
| 866 | DECLARE_ASN1_ITEM(ASN1_OCTET_STRING_NDEF) | ||
| 867 | |||
| 868 | ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s,time_t t); | ||
| 869 | int ASN1_TIME_check(ASN1_TIME *t); | ||
| 870 | ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(ASN1_TIME *t, ASN1_GENERALIZEDTIME **out); | ||
| 871 | |||
| 872 | int i2d_ASN1_SET(STACK *a, unsigned char **pp, | ||
| 873 | i2d_of_void *i2d, int ex_tag, int ex_class, int is_set); | ||
| 874 | STACK * d2i_ASN1_SET(STACK **a, const unsigned char **pp, long length, | ||
| 875 | d2i_of_void *d2i, void (*free_func)(void *), | ||
| 876 | int ex_tag, int ex_class); | ||
| 877 | |||
| 878 | #ifndef OPENSSL_NO_BIO | ||
| 879 | int i2a_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *a); | ||
| 880 | int a2i_ASN1_INTEGER(BIO *bp,ASN1_INTEGER *bs,char *buf,int size); | ||
| 881 | int i2a_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *a); | ||
| 882 | int a2i_ASN1_ENUMERATED(BIO *bp,ASN1_ENUMERATED *bs,char *buf,int size); | ||
| 883 | int i2a_ASN1_OBJECT(BIO *bp,ASN1_OBJECT *a); | ||
| 884 | int a2i_ASN1_STRING(BIO *bp,ASN1_STRING *bs,char *buf,int size); | ||
| 885 | int i2a_ASN1_STRING(BIO *bp, ASN1_STRING *a, int type); | ||
| 886 | #endif | ||
| 887 | int i2t_ASN1_OBJECT(char *buf,int buf_len,ASN1_OBJECT *a); | ||
| 888 | |||
| 889 | int a2d_ASN1_OBJECT(unsigned char *out,int olen, const char *buf, int num); | ||
| 890 | ASN1_OBJECT *ASN1_OBJECT_create(int nid, unsigned char *data,int len, | ||
| 891 | const char *sn, const char *ln); | ||
| 892 | |||
| 893 | int ASN1_INTEGER_set(ASN1_INTEGER *a, long v); | ||
| 894 | long ASN1_INTEGER_get(ASN1_INTEGER *a); | ||
| 895 | ASN1_INTEGER *BN_to_ASN1_INTEGER(BIGNUM *bn, ASN1_INTEGER *ai); | ||
| 896 | BIGNUM *ASN1_INTEGER_to_BN(ASN1_INTEGER *ai,BIGNUM *bn); | ||
| 897 | |||
| 898 | int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v); | ||
| 899 | long ASN1_ENUMERATED_get(ASN1_ENUMERATED *a); | ||
| 900 | ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai); | ||
| 901 | BIGNUM *ASN1_ENUMERATED_to_BN(ASN1_ENUMERATED *ai,BIGNUM *bn); | ||
| 902 | |||
| 903 | /* General */ | ||
| 904 | /* given a string, return the correct type, max is the maximum length */ | ||
| 905 | int ASN1_PRINTABLE_type(const unsigned char *s, int max); | ||
| 906 | |||
| 907 | int i2d_ASN1_bytes(ASN1_STRING *a, unsigned char **pp, int tag, int xclass); | ||
| 908 | ASN1_STRING *d2i_ASN1_bytes(ASN1_STRING **a, const unsigned char **pp, | ||
| 909 | long length, int Ptag, int Pclass); | ||
| 910 | unsigned long ASN1_tag2bit(int tag); | ||
| 911 | /* type is one or more of the B_ASN1_ values. */ | ||
| 912 | ASN1_STRING *d2i_ASN1_type_bytes(ASN1_STRING **a,const unsigned char **pp, | ||
| 913 | long length,int type); | ||
| 914 | |||
| 915 | /* PARSING */ | ||
| 916 | int asn1_Finish(ASN1_CTX *c); | ||
| 917 | int asn1_const_Finish(ASN1_const_CTX *c); | ||
| 918 | |||
| 919 | /* SPECIALS */ | ||
| 920 | int ASN1_get_object(const unsigned char **pp, long *plength, int *ptag, | ||
| 921 | int *pclass, long omax); | ||
| 922 | int ASN1_check_infinite_end(unsigned char **p,long len); | ||
| 923 | int ASN1_const_check_infinite_end(const unsigned char **p,long len); | ||
| 924 | void ASN1_put_object(unsigned char **pp, int constructed, int length, | ||
| 925 | int tag, int xclass); | ||
| 926 | int ASN1_put_eoc(unsigned char **pp); | ||
| 927 | int ASN1_object_size(int constructed, int length, int tag); | ||
| 928 | |||
| 929 | /* Used to implement other functions */ | ||
| 930 | void *ASN1_dup(i2d_of_void *i2d, d2i_of_void *d2i, char *x); | ||
| 931 | |||
| 932 | #define ASN1_dup_of(type,i2d,d2i,x) \ | ||
| 933 | ((type*)ASN1_dup(CHECKED_I2D_OF(type, i2d), \ | ||
| 934 | CHECKED_D2I_OF(type, d2i), \ | ||
| 935 | CHECKED_PTR_OF(type, x))) | ||
| 936 | |||
| 937 | #define ASN1_dup_of_const(type,i2d,d2i,x) \ | ||
| 938 | ((type*)ASN1_dup(CHECKED_I2D_OF(const type, i2d), \ | ||
| 939 | CHECKED_D2I_OF(type, d2i), \ | ||
| 940 | CHECKED_PTR_OF(const type, x))) | ||
| 941 | |||
| 942 | void *ASN1_item_dup(const ASN1_ITEM *it, void *x); | ||
| 943 | |||
| 944 | /* ASN1 alloc/free macros for when a type is only used internally */ | ||
| 945 | |||
| 946 | #define M_ASN1_new_of(type) (type *)ASN1_item_new(ASN1_ITEM_rptr(type)) | ||
| 947 | #define M_ASN1_free_of(x, type) \ | ||
| 948 | ASN1_item_free(CHECKED_PTR_OF(type, x), ASN1_ITEM_rptr(type)) | ||
| 949 | |||
| 950 | #ifndef OPENSSL_NO_FP_API | ||
| 951 | void *ASN1_d2i_fp(void *(*xnew)(void), d2i_of_void *d2i, FILE *in, void **x); | ||
| 952 | |||
| 953 | #define ASN1_d2i_fp_of(type,xnew,d2i,in,x) \ | ||
| 954 | ((type*)ASN1_d2i_fp(CHECKED_NEW_OF(type, xnew), \ | ||
| 955 | CHECKED_D2I_OF(type, d2i), \ | ||
| 956 | in, \ | ||
| 957 | CHECKED_PPTR_OF(type, x))) | ||
| 958 | |||
| 959 | void *ASN1_item_d2i_fp(const ASN1_ITEM *it, FILE *in, void *x); | ||
| 960 | int ASN1_i2d_fp(i2d_of_void *i2d,FILE *out,void *x); | ||
| 961 | |||
| 962 | #define ASN1_i2d_fp_of(type,i2d,out,x) \ | ||
| 963 | (ASN1_i2d_fp(CHECKED_I2D_OF(type, i2d), \ | ||
| 964 | out, \ | ||
| 965 | CHECKED_PTR_OF(type, x))) | ||
| 966 | |||
| 967 | #define ASN1_i2d_fp_of_const(type,i2d,out,x) \ | ||
| 968 | (ASN1_i2d_fp(CHECKED_I2D_OF(const type, i2d), \ | ||
| 969 | out, \ | ||
| 970 | CHECKED_PTR_OF(const type, x))) | ||
| 971 | |||
| 972 | int ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out, void *x); | ||
| 973 | int ASN1_STRING_print_ex_fp(FILE *fp, ASN1_STRING *str, unsigned long flags); | ||
| 974 | #endif | ||
| 975 | |||
| 976 | int ASN1_STRING_to_UTF8(unsigned char **out, ASN1_STRING *in); | ||
| 977 | |||
| 978 | #ifndef OPENSSL_NO_BIO | ||
| 979 | void *ASN1_d2i_bio(void *(*xnew)(void), d2i_of_void *d2i, BIO *in, void **x); | ||
| 980 | |||
| 981 | #define ASN1_d2i_bio_of(type,xnew,d2i,in,x) \ | ||
| 982 | ((type*)ASN1_d2i_bio( CHECKED_NEW_OF(type, xnew), \ | ||
| 983 | CHECKED_D2I_OF(type, d2i), \ | ||
| 984 | in, \ | ||
| 985 | CHECKED_PPTR_OF(type, x))) | ||
| 986 | |||
| 987 | void *ASN1_item_d2i_bio(const ASN1_ITEM *it, BIO *in, void *x); | ||
| 988 | int ASN1_i2d_bio(i2d_of_void *i2d,BIO *out, unsigned char *x); | ||
| 989 | |||
| 990 | #define ASN1_i2d_bio_of(type,i2d,out,x) \ | ||
| 991 | (ASN1_i2d_bio(CHECKED_I2D_OF(type, i2d), \ | ||
| 992 | out, \ | ||
| 993 | CHECKED_PTR_OF(type, x))) | ||
| 994 | |||
| 995 | #define ASN1_i2d_bio_of_const(type,i2d,out,x) \ | ||
| 996 | (ASN1_i2d_bio(CHECKED_I2D_OF(const type, i2d), \ | ||
| 997 | out, \ | ||
| 998 | CHECKED_PTR_OF(const type, x))) | ||
| 999 | |||
| 1000 | int ASN1_item_i2d_bio(const ASN1_ITEM *it, BIO *out, void *x); | ||
| 1001 | int ASN1_UTCTIME_print(BIO *fp,ASN1_UTCTIME *a); | ||
| 1002 | int ASN1_GENERALIZEDTIME_print(BIO *fp,ASN1_GENERALIZEDTIME *a); | ||
| 1003 | int ASN1_TIME_print(BIO *fp,ASN1_TIME *a); | ||
| 1004 | int ASN1_STRING_print(BIO *bp,ASN1_STRING *v); | ||
| 1005 | int ASN1_STRING_print_ex(BIO *out, ASN1_STRING *str, unsigned long flags); | ||
| 1006 | int ASN1_parse(BIO *bp,const unsigned char *pp,long len,int indent); | ||
| 1007 | int ASN1_parse_dump(BIO *bp,const unsigned char *pp,long len,int indent,int dump); | ||
| 1008 | #endif | ||
| 1009 | const char *ASN1_tag2str(int tag); | ||
| 1010 | |||
| 1011 | /* Used to load and write netscape format cert/key */ | ||
| 1012 | int i2d_ASN1_HEADER(ASN1_HEADER *a,unsigned char **pp); | ||
| 1013 | ASN1_HEADER *d2i_ASN1_HEADER(ASN1_HEADER **a,const unsigned char **pp, long length); | ||
| 1014 | ASN1_HEADER *ASN1_HEADER_new(void ); | ||
| 1015 | void ASN1_HEADER_free(ASN1_HEADER *a); | ||
| 1016 | |||
| 1017 | int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s); | ||
| 1018 | |||
| 1019 | /* Not used that much at this point, except for the first two */ | ||
| 1020 | ASN1_METHOD *X509_asn1_meth(void); | ||
| 1021 | ASN1_METHOD *RSAPrivateKey_asn1_meth(void); | ||
| 1022 | ASN1_METHOD *ASN1_IA5STRING_asn1_meth(void); | ||
| 1023 | ASN1_METHOD *ASN1_BIT_STRING_asn1_meth(void); | ||
| 1024 | |||
| 1025 | int ASN1_TYPE_set_octetstring(ASN1_TYPE *a, | ||
| 1026 | unsigned char *data, int len); | ||
| 1027 | int ASN1_TYPE_get_octetstring(ASN1_TYPE *a, | ||
| 1028 | unsigned char *data, int max_len); | ||
| 1029 | int ASN1_TYPE_set_int_octetstring(ASN1_TYPE *a, long num, | ||
| 1030 | unsigned char *data, int len); | ||
| 1031 | int ASN1_TYPE_get_int_octetstring(ASN1_TYPE *a,long *num, | ||
| 1032 | unsigned char *data, int max_len); | ||
| 1033 | |||
| 1034 | STACK *ASN1_seq_unpack(const unsigned char *buf, int len, | ||
| 1035 | d2i_of_void *d2i, void (*free_func)(void *)); | ||
| 1036 | unsigned char *ASN1_seq_pack(STACK *safes, i2d_of_void *i2d, | ||
| 1037 | unsigned char **buf, int *len ); | ||
| 1038 | void *ASN1_unpack_string(ASN1_STRING *oct, d2i_of_void *d2i); | ||
| 1039 | void *ASN1_item_unpack(ASN1_STRING *oct, const ASN1_ITEM *it); | ||
| 1040 | ASN1_STRING *ASN1_pack_string(void *obj, i2d_of_void *i2d, | ||
| 1041 | ASN1_OCTET_STRING **oct); | ||
| 1042 | |||
| 1043 | #define ASN1_pack_string_of(type,obj,i2d,oct) \ | ||
| 1044 | (ASN1_pack_string(CHECKED_PTR_OF(type, obj), \ | ||
| 1045 | CHECKED_I2D_OF(type, i2d), \ | ||
| 1046 | oct)) | ||
| 1047 | |||
| 1048 | ASN1_STRING *ASN1_item_pack(void *obj, const ASN1_ITEM *it, ASN1_OCTET_STRING **oct); | ||
| 1049 | |||
| 1050 | void ASN1_STRING_set_default_mask(unsigned long mask); | ||
| 1051 | int ASN1_STRING_set_default_mask_asc(char *p); | ||
| 1052 | unsigned long ASN1_STRING_get_default_mask(void); | ||
| 1053 | int ASN1_mbstring_copy(ASN1_STRING **out, const unsigned char *in, int len, | ||
| 1054 | int inform, unsigned long mask); | ||
| 1055 | int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len, | ||
| 1056 | int inform, unsigned long mask, | ||
| 1057 | long minsize, long maxsize); | ||
| 1058 | |||
| 1059 | ASN1_STRING *ASN1_STRING_set_by_NID(ASN1_STRING **out, | ||
| 1060 | const unsigned char *in, int inlen, int inform, int nid); | ||
| 1061 | ASN1_STRING_TABLE *ASN1_STRING_TABLE_get(int nid); | ||
| 1062 | int ASN1_STRING_TABLE_add(int, long, long, unsigned long, unsigned long); | ||
| 1063 | void ASN1_STRING_TABLE_cleanup(void); | ||
| 1064 | |||
| 1065 | /* ASN1 template functions */ | ||
| 1066 | |||
| 1067 | /* Old API compatible functions */ | ||
| 1068 | ASN1_VALUE *ASN1_item_new(const ASN1_ITEM *it); | ||
| 1069 | void ASN1_item_free(ASN1_VALUE *val, const ASN1_ITEM *it); | ||
| 1070 | ASN1_VALUE * ASN1_item_d2i(ASN1_VALUE **val, const unsigned char **in, long len, const ASN1_ITEM *it); | ||
| 1071 | int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it); | ||
| 1072 | int ASN1_item_ndef_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it); | ||
| 1073 | |||
| 1074 | void ASN1_add_oid_module(void); | ||
| 1075 | |||
| 1076 | ASN1_TYPE *ASN1_generate_nconf(char *str, CONF *nconf); | ||
| 1077 | ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf); | ||
| 1078 | |||
| 1079 | typedef int asn1_output_data_fn(BIO *out, BIO *data, ASN1_VALUE *val, int flags, | ||
| 1080 | const ASN1_ITEM *it); | ||
| 1081 | |||
| 1082 | int int_smime_write_ASN1(BIO *bio, ASN1_VALUE *val, BIO *data, int flags, | ||
| 1083 | int ctype_nid, int econt_nid, | ||
| 1084 | STACK_OF(X509_ALGOR) *mdalgs, | ||
| 1085 | asn1_output_data_fn *data_fn, | ||
| 1086 | const ASN1_ITEM *it); | ||
| 1087 | ASN1_VALUE *SMIME_read_ASN1(BIO *bio, BIO **bcont, const ASN1_ITEM *it); | ||
| 1088 | |||
| 1089 | /* BEGIN ERROR CODES */ | ||
| 1090 | /* The following lines are auto generated by the script mkerr.pl. Any changes | ||
| 1091 | * made after this point may be overwritten when the script is next run. | ||
| 1092 | */ | ||
| 1093 | void ERR_load_ASN1_strings(void); | ||
| 1094 | |||
| 1095 | /* Error codes for the ASN1 functions. */ | ||
| 1096 | |||
| 1097 | /* Function codes. */ | ||
| 1098 | #define ASN1_F_A2D_ASN1_OBJECT 100 | ||
| 1099 | #define ASN1_F_A2I_ASN1_ENUMERATED 101 | ||
| 1100 | #define ASN1_F_A2I_ASN1_INTEGER 102 | ||
| 1101 | #define ASN1_F_A2I_ASN1_STRING 103 | ||
| 1102 | #define ASN1_F_APPEND_EXP 176 | ||
| 1103 | #define ASN1_F_ASN1_BIT_STRING_SET_BIT 183 | ||
| 1104 | #define ASN1_F_ASN1_CB 177 | ||
| 1105 | #define ASN1_F_ASN1_CHECK_TLEN 104 | ||
| 1106 | #define ASN1_F_ASN1_COLLATE_PRIMITIVE 105 | ||
| 1107 | #define ASN1_F_ASN1_COLLECT 106 | ||
| 1108 | #define ASN1_F_ASN1_D2I_EX_PRIMITIVE 108 | ||
| 1109 | #define ASN1_F_ASN1_D2I_FP 109 | ||
| 1110 | #define ASN1_F_ASN1_D2I_READ_BIO 107 | ||
| 1111 | #define ASN1_F_ASN1_DIGEST 184 | ||
| 1112 | #define ASN1_F_ASN1_DO_ADB 110 | ||
| 1113 | #define ASN1_F_ASN1_DUP 111 | ||
| 1114 | #define ASN1_F_ASN1_ENUMERATED_SET 112 | ||
| 1115 | #define ASN1_F_ASN1_ENUMERATED_TO_BN 113 | ||
| 1116 | #define ASN1_F_ASN1_EX_C2I 204 | ||
| 1117 | #define ASN1_F_ASN1_FIND_END 190 | ||
| 1118 | #define ASN1_F_ASN1_GENERALIZEDTIME_SET 185 | ||
| 1119 | #define ASN1_F_ASN1_GENERATE_V3 178 | ||
| 1120 | #define ASN1_F_ASN1_GET_OBJECT 114 | ||
| 1121 | #define ASN1_F_ASN1_HEADER_NEW 115 | ||
| 1122 | #define ASN1_F_ASN1_I2D_BIO 116 | ||
| 1123 | #define ASN1_F_ASN1_I2D_FP 117 | ||
| 1124 | #define ASN1_F_ASN1_INTEGER_SET 118 | ||
| 1125 | #define ASN1_F_ASN1_INTEGER_TO_BN 119 | ||
| 1126 | #define ASN1_F_ASN1_ITEM_D2I_FP 206 | ||
| 1127 | #define ASN1_F_ASN1_ITEM_DUP 191 | ||
| 1128 | #define ASN1_F_ASN1_ITEM_EX_COMBINE_NEW 121 | ||
| 1129 | #define ASN1_F_ASN1_ITEM_EX_D2I 120 | ||
| 1130 | #define ASN1_F_ASN1_ITEM_I2D_BIO 192 | ||
| 1131 | #define ASN1_F_ASN1_ITEM_I2D_FP 193 | ||
| 1132 | #define ASN1_F_ASN1_ITEM_PACK 198 | ||
| 1133 | #define ASN1_F_ASN1_ITEM_SIGN 195 | ||
| 1134 | #define ASN1_F_ASN1_ITEM_UNPACK 199 | ||
| 1135 | #define ASN1_F_ASN1_ITEM_VERIFY 197 | ||
| 1136 | #define ASN1_F_ASN1_MBSTRING_NCOPY 122 | ||
| 1137 | #define ASN1_F_ASN1_OBJECT_NEW 123 | ||
| 1138 | #define ASN1_F_ASN1_OUTPUT_DATA 207 | ||
| 1139 | #define ASN1_F_ASN1_PACK_STRING 124 | ||
| 1140 | #define ASN1_F_ASN1_PCTX_NEW 205 | ||
| 1141 | #define ASN1_F_ASN1_PKCS5_PBE_SET 125 | ||
| 1142 | #define ASN1_F_ASN1_SEQ_PACK 126 | ||
| 1143 | #define ASN1_F_ASN1_SEQ_UNPACK 127 | ||
| 1144 | #define ASN1_F_ASN1_SIGN 128 | ||
| 1145 | #define ASN1_F_ASN1_STR2TYPE 179 | ||
| 1146 | #define ASN1_F_ASN1_STRING_SET 186 | ||
| 1147 | #define ASN1_F_ASN1_STRING_TABLE_ADD 129 | ||
| 1148 | #define ASN1_F_ASN1_STRING_TYPE_NEW 130 | ||
| 1149 | #define ASN1_F_ASN1_TEMPLATE_EX_D2I 132 | ||
| 1150 | #define ASN1_F_ASN1_TEMPLATE_NEW 133 | ||
| 1151 | #define ASN1_F_ASN1_TEMPLATE_NOEXP_D2I 131 | ||
| 1152 | #define ASN1_F_ASN1_TIME_SET 175 | ||
| 1153 | #define ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING 134 | ||
| 1154 | #define ASN1_F_ASN1_TYPE_GET_OCTETSTRING 135 | ||
| 1155 | #define ASN1_F_ASN1_UNPACK_STRING 136 | ||
| 1156 | #define ASN1_F_ASN1_UTCTIME_SET 187 | ||
| 1157 | #define ASN1_F_ASN1_VERIFY 137 | ||
| 1158 | #define ASN1_F_B64_READ_ASN1 208 | ||
| 1159 | #define ASN1_F_B64_WRITE_ASN1 209 | ||
| 1160 | #define ASN1_F_BITSTR_CB 180 | ||
| 1161 | #define ASN1_F_BN_TO_ASN1_ENUMERATED 138 | ||
| 1162 | #define ASN1_F_BN_TO_ASN1_INTEGER 139 | ||
| 1163 | #define ASN1_F_C2I_ASN1_BIT_STRING 189 | ||
| 1164 | #define ASN1_F_C2I_ASN1_INTEGER 194 | ||
| 1165 | #define ASN1_F_C2I_ASN1_OBJECT 196 | ||
| 1166 | #define ASN1_F_COLLECT_DATA 140 | ||
| 1167 | #define ASN1_F_D2I_ASN1_BIT_STRING 141 | ||
| 1168 | #define ASN1_F_D2I_ASN1_BOOLEAN 142 | ||
| 1169 | #define ASN1_F_D2I_ASN1_BYTES 143 | ||
| 1170 | #define ASN1_F_D2I_ASN1_GENERALIZEDTIME 144 | ||
| 1171 | #define ASN1_F_D2I_ASN1_HEADER 145 | ||
| 1172 | #define ASN1_F_D2I_ASN1_INTEGER 146 | ||
| 1173 | #define ASN1_F_D2I_ASN1_OBJECT 147 | ||
| 1174 | #define ASN1_F_D2I_ASN1_SET 148 | ||
| 1175 | #define ASN1_F_D2I_ASN1_TYPE_BYTES 149 | ||
| 1176 | #define ASN1_F_D2I_ASN1_UINTEGER 150 | ||
| 1177 | #define ASN1_F_D2I_ASN1_UTCTIME 151 | ||
| 1178 | #define ASN1_F_D2I_NETSCAPE_RSA 152 | ||
| 1179 | #define ASN1_F_D2I_NETSCAPE_RSA_2 153 | ||
| 1180 | #define ASN1_F_D2I_PRIVATEKEY 154 | ||
| 1181 | #define ASN1_F_D2I_PUBLICKEY 155 | ||
| 1182 | #define ASN1_F_D2I_RSA_NET 200 | ||
| 1183 | #define ASN1_F_D2I_RSA_NET_2 201 | ||
| 1184 | #define ASN1_F_D2I_X509 156 | ||
| 1185 | #define ASN1_F_D2I_X509_CINF 157 | ||
| 1186 | #define ASN1_F_D2I_X509_PKEY 159 | ||
| 1187 | #define ASN1_F_I2D_ASN1_SET 188 | ||
| 1188 | #define ASN1_F_I2D_ASN1_TIME 160 | ||
| 1189 | #define ASN1_F_I2D_DSA_PUBKEY 161 | ||
| 1190 | #define ASN1_F_I2D_EC_PUBKEY 181 | ||
| 1191 | #define ASN1_F_I2D_PRIVATEKEY 163 | ||
| 1192 | #define ASN1_F_I2D_PUBLICKEY 164 | ||
| 1193 | #define ASN1_F_I2D_RSA_NET 162 | ||
| 1194 | #define ASN1_F_I2D_RSA_PUBKEY 165 | ||
| 1195 | #define ASN1_F_LONG_C2I 166 | ||
| 1196 | #define ASN1_F_OID_MODULE_INIT 174 | ||
| 1197 | #define ASN1_F_PARSE_TAGGING 182 | ||
| 1198 | #define ASN1_F_PKCS5_PBE2_SET 167 | ||
| 1199 | #define ASN1_F_PKCS5_PBE_SET 202 | ||
| 1200 | #define ASN1_F_SMIME_READ_ASN1 210 | ||
| 1201 | #define ASN1_F_SMIME_TEXT 211 | ||
| 1202 | #define ASN1_F_X509_CINF_NEW 168 | ||
| 1203 | #define ASN1_F_X509_CRL_ADD0_REVOKED 169 | ||
| 1204 | #define ASN1_F_X509_INFO_NEW 170 | ||
| 1205 | #define ASN1_F_X509_NAME_ENCODE 203 | ||
| 1206 | #define ASN1_F_X509_NAME_EX_D2I 158 | ||
| 1207 | #define ASN1_F_X509_NAME_EX_NEW 171 | ||
| 1208 | #define ASN1_F_X509_NEW 172 | ||
| 1209 | #define ASN1_F_X509_PKEY_NEW 173 | ||
| 1210 | |||
| 1211 | /* Reason codes. */ | ||
| 1212 | #define ASN1_R_ADDING_OBJECT 171 | ||
| 1213 | #define ASN1_R_ASN1_PARSE_ERROR 198 | ||
| 1214 | #define ASN1_R_ASN1_SIG_PARSE_ERROR 199 | ||
| 1215 | #define ASN1_R_AUX_ERROR 100 | ||
| 1216 | #define ASN1_R_BAD_CLASS 101 | ||
| 1217 | #define ASN1_R_BAD_OBJECT_HEADER 102 | ||
| 1218 | #define ASN1_R_BAD_PASSWORD_READ 103 | ||
| 1219 | #define ASN1_R_BAD_TAG 104 | ||
| 1220 | #define ASN1_R_BN_LIB 105 | ||
| 1221 | #define ASN1_R_BOOLEAN_IS_WRONG_LENGTH 106 | ||
| 1222 | #define ASN1_R_BUFFER_TOO_SMALL 107 | ||
| 1223 | #define ASN1_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER 108 | ||
| 1224 | #define ASN1_R_DATA_IS_WRONG 109 | ||
| 1225 | #define ASN1_R_DECODE_ERROR 110 | ||
| 1226 | #define ASN1_R_DECODING_ERROR 111 | ||
| 1227 | #define ASN1_R_DEPTH_EXCEEDED 174 | ||
| 1228 | #define ASN1_R_ENCODE_ERROR 112 | ||
| 1229 | #define ASN1_R_ERROR_GETTING_TIME 173 | ||
| 1230 | #define ASN1_R_ERROR_LOADING_SECTION 172 | ||
| 1231 | #define ASN1_R_ERROR_PARSING_SET_ELEMENT 113 | ||
| 1232 | #define ASN1_R_ERROR_SETTING_CIPHER_PARAMS 114 | ||
| 1233 | #define ASN1_R_EXPECTING_AN_INTEGER 115 | ||
| 1234 | #define ASN1_R_EXPECTING_AN_OBJECT 116 | ||
| 1235 | #define ASN1_R_EXPECTING_A_BOOLEAN 117 | ||
| 1236 | #define ASN1_R_EXPECTING_A_TIME 118 | ||
| 1237 | #define ASN1_R_EXPLICIT_LENGTH_MISMATCH 119 | ||
| 1238 | #define ASN1_R_EXPLICIT_TAG_NOT_CONSTRUCTED 120 | ||
| 1239 | #define ASN1_R_FIELD_MISSING 121 | ||
| 1240 | #define ASN1_R_FIRST_NUM_TOO_LARGE 122 | ||
| 1241 | #define ASN1_R_HEADER_TOO_LONG 123 | ||
| 1242 | #define ASN1_R_ILLEGAL_BITSTRING_FORMAT 175 | ||
| 1243 | #define ASN1_R_ILLEGAL_BOOLEAN 176 | ||
| 1244 | #define ASN1_R_ILLEGAL_CHARACTERS 124 | ||
| 1245 | #define ASN1_R_ILLEGAL_FORMAT 177 | ||
| 1246 | #define ASN1_R_ILLEGAL_HEX 178 | ||
| 1247 | #define ASN1_R_ILLEGAL_IMPLICIT_TAG 179 | ||
| 1248 | #define ASN1_R_ILLEGAL_INTEGER 180 | ||
| 1249 | #define ASN1_R_ILLEGAL_NESTED_TAGGING 181 | ||
| 1250 | #define ASN1_R_ILLEGAL_NULL 125 | ||
| 1251 | #define ASN1_R_ILLEGAL_NULL_VALUE 182 | ||
| 1252 | #define ASN1_R_ILLEGAL_OBJECT 183 | ||
| 1253 | #define ASN1_R_ILLEGAL_OPTIONAL_ANY 126 | ||
| 1254 | #define ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE 170 | ||
| 1255 | #define ASN1_R_ILLEGAL_TAGGED_ANY 127 | ||
| 1256 | #define ASN1_R_ILLEGAL_TIME_VALUE 184 | ||
| 1257 | #define ASN1_R_INTEGER_NOT_ASCII_FORMAT 185 | ||
| 1258 | #define ASN1_R_INTEGER_TOO_LARGE_FOR_LONG 128 | ||
| 1259 | #define ASN1_R_INVALID_BMPSTRING_LENGTH 129 | ||
| 1260 | #define ASN1_R_INVALID_DIGIT 130 | ||
| 1261 | #define ASN1_R_INVALID_MIME_TYPE 200 | ||
| 1262 | #define ASN1_R_INVALID_MODIFIER 186 | ||
| 1263 | #define ASN1_R_INVALID_NUMBER 187 | ||
| 1264 | #define ASN1_R_INVALID_SEPARATOR 131 | ||
| 1265 | #define ASN1_R_INVALID_TIME_FORMAT 132 | ||
| 1266 | #define ASN1_R_INVALID_UNIVERSALSTRING_LENGTH 133 | ||
| 1267 | #define ASN1_R_INVALID_UTF8STRING 134 | ||
| 1268 | #define ASN1_R_IV_TOO_LARGE 135 | ||
| 1269 | #define ASN1_R_LENGTH_ERROR 136 | ||
| 1270 | #define ASN1_R_LIST_ERROR 188 | ||
| 1271 | #define ASN1_R_MIME_NO_CONTENT_TYPE 201 | ||
| 1272 | #define ASN1_R_MIME_PARSE_ERROR 202 | ||
| 1273 | #define ASN1_R_MIME_SIG_PARSE_ERROR 203 | ||
| 1274 | #define ASN1_R_MISSING_EOC 137 | ||
| 1275 | #define ASN1_R_MISSING_SECOND_NUMBER 138 | ||
| 1276 | #define ASN1_R_MISSING_VALUE 189 | ||
| 1277 | #define ASN1_R_MSTRING_NOT_UNIVERSAL 139 | ||
| 1278 | #define ASN1_R_MSTRING_WRONG_TAG 140 | ||
| 1279 | #define ASN1_R_NESTED_ASN1_STRING 197 | ||
| 1280 | #define ASN1_R_NON_HEX_CHARACTERS 141 | ||
| 1281 | #define ASN1_R_NOT_ASCII_FORMAT 190 | ||
| 1282 | #define ASN1_R_NOT_ENOUGH_DATA 142 | ||
| 1283 | #define ASN1_R_NO_CONTENT_TYPE 204 | ||
| 1284 | #define ASN1_R_NO_MATCHING_CHOICE_TYPE 143 | ||
| 1285 | #define ASN1_R_NO_MULTIPART_BODY_FAILURE 205 | ||
| 1286 | #define ASN1_R_NO_MULTIPART_BOUNDARY 206 | ||
| 1287 | #define ASN1_R_NO_SIG_CONTENT_TYPE 207 | ||
| 1288 | #define ASN1_R_NULL_IS_WRONG_LENGTH 144 | ||
| 1289 | #define ASN1_R_OBJECT_NOT_ASCII_FORMAT 191 | ||
| 1290 | #define ASN1_R_ODD_NUMBER_OF_CHARS 145 | ||
| 1291 | #define ASN1_R_PRIVATE_KEY_HEADER_MISSING 146 | ||
| 1292 | #define ASN1_R_SECOND_NUMBER_TOO_LARGE 147 | ||
| 1293 | #define ASN1_R_SEQUENCE_LENGTH_MISMATCH 148 | ||
| 1294 | #define ASN1_R_SEQUENCE_NOT_CONSTRUCTED 149 | ||
| 1295 | #define ASN1_R_SEQUENCE_OR_SET_NEEDS_CONFIG 192 | ||
| 1296 | #define ASN1_R_SHORT_LINE 150 | ||
| 1297 | #define ASN1_R_SIG_INVALID_MIME_TYPE 208 | ||
| 1298 | #define ASN1_R_STREAMING_NOT_SUPPORTED 209 | ||
| 1299 | #define ASN1_R_STRING_TOO_LONG 151 | ||
| 1300 | #define ASN1_R_STRING_TOO_SHORT 152 | ||
| 1301 | #define ASN1_R_TAG_VALUE_TOO_HIGH 153 | ||
| 1302 | #define ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 154 | ||
| 1303 | #define ASN1_R_TIME_NOT_ASCII_FORMAT 193 | ||
| 1304 | #define ASN1_R_TOO_LONG 155 | ||
| 1305 | #define ASN1_R_TYPE_NOT_CONSTRUCTED 156 | ||
| 1306 | #define ASN1_R_UNABLE_TO_DECODE_RSA_KEY 157 | ||
| 1307 | #define ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY 158 | ||
| 1308 | #define ASN1_R_UNEXPECTED_EOC 159 | ||
| 1309 | #define ASN1_R_UNKNOWN_FORMAT 160 | ||
| 1310 | #define ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM 161 | ||
| 1311 | #define ASN1_R_UNKNOWN_OBJECT_TYPE 162 | ||
| 1312 | #define ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE 163 | ||
| 1313 | #define ASN1_R_UNKNOWN_TAG 194 | ||
| 1314 | #define ASN1_R_UNKOWN_FORMAT 195 | ||
| 1315 | #define ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE 164 | ||
| 1316 | #define ASN1_R_UNSUPPORTED_CIPHER 165 | ||
| 1317 | #define ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM 166 | ||
| 1318 | #define ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE 167 | ||
| 1319 | #define ASN1_R_UNSUPPORTED_TYPE 196 | ||
| 1320 | #define ASN1_R_WRONG_TAG 168 | ||
| 1321 | #define ASN1_R_WRONG_TYPE 169 | ||
| 1322 | |||
| 1323 | #ifdef __cplusplus | ||
| 1324 | } | ||
| 1325 | #endif | ||
| 1326 | #endif | ||
diff --git a/src/lib/libcrypto/asn1/asn1_err.c b/src/lib/libcrypto/asn1/asn1_err.c new file mode 100644 index 0000000000..f8a3e2e6cd --- /dev/null +++ b/src/lib/libcrypto/asn1/asn1_err.c | |||
| @@ -0,0 +1,315 @@ | |||
| 1 | /* crypto/asn1/asn1_err.c */ | ||
| 2 | /* ==================================================================== | ||
| 3 | * Copyright (c) 1999-2008 The OpenSSL Project. All rights reserved. | ||
| 4 | * | ||
| 5 | * Redistribution and use in source and binary forms, with or without | ||
| 6 | * modification, are permitted provided that the following conditions | ||
| 7 | * are met: | ||
| 8 | * | ||
| 9 | * 1. Redistributions of source code must retain the above copyright | ||
| 10 | * notice, this list of conditions and the following disclaimer. | ||
| 11 | * | ||
| 12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer in | ||
| 14 | * the documentation and/or other materials provided with the | ||
| 15 | * distribution. | ||
| 16 | * | ||
| 17 | * 3. All advertising materials mentioning features or use of this | ||
| 18 | * software must display the following acknowledgment: | ||
| 19 | * "This product includes software developed by the OpenSSL Project | ||
| 20 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 21 | * | ||
| 22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 23 | * endorse or promote products derived from this software without | ||
| 24 | * prior written permission. For written permission, please contact | ||
| 25 | * openssl-core@OpenSSL.org. | ||
| 26 | * | ||
| 27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 28 | * nor may "OpenSSL" appear in their names without prior written | ||
| 29 | * permission of the OpenSSL Project. | ||
| 30 | * | ||
| 31 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 32 | * acknowledgment: | ||
| 33 | * "This product includes software developed by the OpenSSL Project | ||
| 34 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 35 | * | ||
| 36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 48 | * ==================================================================== | ||
| 49 | * | ||
| 50 | * This product includes cryptographic software written by Eric Young | ||
| 51 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 52 | * Hudson (tjh@cryptsoft.com). | ||
| 53 | * | ||
| 54 | */ | ||
| 55 | |||
| 56 | /* NOTE: this file was auto generated by the mkerr.pl script: any changes | ||
| 57 | * made to it will be overwritten when the script next updates this file, | ||
| 58 | * only reason strings will be preserved. | ||
| 59 | */ | ||
| 60 | |||
| 61 | #include <stdio.h> | ||
| 62 | #include <openssl/err.h> | ||
| 63 | #include <openssl/asn1.h> | ||
| 64 | |||
| 65 | /* BEGIN ERROR CODES */ | ||
| 66 | #ifndef OPENSSL_NO_ERR | ||
| 67 | |||
| 68 | #define ERR_FUNC(func) ERR_PACK(ERR_LIB_ASN1,func,0) | ||
| 69 | #define ERR_REASON(reason) ERR_PACK(ERR_LIB_ASN1,0,reason) | ||
| 70 | |||
| 71 | static ERR_STRING_DATA ASN1_str_functs[]= | ||
| 72 | { | ||
| 73 | {ERR_FUNC(ASN1_F_A2D_ASN1_OBJECT), "a2d_ASN1_OBJECT"}, | ||
| 74 | {ERR_FUNC(ASN1_F_A2I_ASN1_ENUMERATED), "a2i_ASN1_ENUMERATED"}, | ||
| 75 | {ERR_FUNC(ASN1_F_A2I_ASN1_INTEGER), "a2i_ASN1_INTEGER"}, | ||
| 76 | {ERR_FUNC(ASN1_F_A2I_ASN1_STRING), "a2i_ASN1_STRING"}, | ||
| 77 | {ERR_FUNC(ASN1_F_APPEND_EXP), "APPEND_EXP"}, | ||
| 78 | {ERR_FUNC(ASN1_F_ASN1_BIT_STRING_SET_BIT), "ASN1_BIT_STRING_set_bit"}, | ||
| 79 | {ERR_FUNC(ASN1_F_ASN1_CB), "ASN1_CB"}, | ||
| 80 | {ERR_FUNC(ASN1_F_ASN1_CHECK_TLEN), "ASN1_CHECK_TLEN"}, | ||
| 81 | {ERR_FUNC(ASN1_F_ASN1_COLLATE_PRIMITIVE), "ASN1_COLLATE_PRIMITIVE"}, | ||
| 82 | {ERR_FUNC(ASN1_F_ASN1_COLLECT), "ASN1_COLLECT"}, | ||
| 83 | {ERR_FUNC(ASN1_F_ASN1_D2I_EX_PRIMITIVE), "ASN1_D2I_EX_PRIMITIVE"}, | ||
| 84 | {ERR_FUNC(ASN1_F_ASN1_D2I_FP), "ASN1_d2i_fp"}, | ||
| 85 | {ERR_FUNC(ASN1_F_ASN1_D2I_READ_BIO), "ASN1_D2I_READ_BIO"}, | ||
| 86 | {ERR_FUNC(ASN1_F_ASN1_DIGEST), "ASN1_digest"}, | ||
| 87 | {ERR_FUNC(ASN1_F_ASN1_DO_ADB), "ASN1_DO_ADB"}, | ||
| 88 | {ERR_FUNC(ASN1_F_ASN1_DUP), "ASN1_dup"}, | ||
| 89 | {ERR_FUNC(ASN1_F_ASN1_ENUMERATED_SET), "ASN1_ENUMERATED_set"}, | ||
| 90 | {ERR_FUNC(ASN1_F_ASN1_ENUMERATED_TO_BN), "ASN1_ENUMERATED_to_BN"}, | ||
| 91 | {ERR_FUNC(ASN1_F_ASN1_EX_C2I), "ASN1_EX_C2I"}, | ||
| 92 | {ERR_FUNC(ASN1_F_ASN1_FIND_END), "ASN1_FIND_END"}, | ||
| 93 | {ERR_FUNC(ASN1_F_ASN1_GENERALIZEDTIME_SET), "ASN1_GENERALIZEDTIME_set"}, | ||
| 94 | {ERR_FUNC(ASN1_F_ASN1_GENERATE_V3), "ASN1_generate_v3"}, | ||
| 95 | {ERR_FUNC(ASN1_F_ASN1_GET_OBJECT), "ASN1_get_object"}, | ||
| 96 | {ERR_FUNC(ASN1_F_ASN1_HEADER_NEW), "ASN1_HEADER_new"}, | ||
| 97 | {ERR_FUNC(ASN1_F_ASN1_I2D_BIO), "ASN1_i2d_bio"}, | ||
| 98 | {ERR_FUNC(ASN1_F_ASN1_I2D_FP), "ASN1_i2d_fp"}, | ||
| 99 | {ERR_FUNC(ASN1_F_ASN1_INTEGER_SET), "ASN1_INTEGER_set"}, | ||
| 100 | {ERR_FUNC(ASN1_F_ASN1_INTEGER_TO_BN), "ASN1_INTEGER_to_BN"}, | ||
| 101 | {ERR_FUNC(ASN1_F_ASN1_ITEM_D2I_FP), "ASN1_item_d2i_fp"}, | ||
| 102 | {ERR_FUNC(ASN1_F_ASN1_ITEM_DUP), "ASN1_item_dup"}, | ||
| 103 | {ERR_FUNC(ASN1_F_ASN1_ITEM_EX_COMBINE_NEW), "ASN1_ITEM_EX_COMBINE_NEW"}, | ||
| 104 | {ERR_FUNC(ASN1_F_ASN1_ITEM_EX_D2I), "ASN1_ITEM_EX_D2I"}, | ||
| 105 | {ERR_FUNC(ASN1_F_ASN1_ITEM_I2D_BIO), "ASN1_item_i2d_bio"}, | ||
| 106 | {ERR_FUNC(ASN1_F_ASN1_ITEM_I2D_FP), "ASN1_item_i2d_fp"}, | ||
| 107 | {ERR_FUNC(ASN1_F_ASN1_ITEM_PACK), "ASN1_item_pack"}, | ||
| 108 | {ERR_FUNC(ASN1_F_ASN1_ITEM_SIGN), "ASN1_item_sign"}, | ||
| 109 | {ERR_FUNC(ASN1_F_ASN1_ITEM_UNPACK), "ASN1_item_unpack"}, | ||
| 110 | {ERR_FUNC(ASN1_F_ASN1_ITEM_VERIFY), "ASN1_item_verify"}, | ||
| 111 | {ERR_FUNC(ASN1_F_ASN1_MBSTRING_NCOPY), "ASN1_mbstring_ncopy"}, | ||
| 112 | {ERR_FUNC(ASN1_F_ASN1_OBJECT_NEW), "ASN1_OBJECT_new"}, | ||
| 113 | {ERR_FUNC(ASN1_F_ASN1_OUTPUT_DATA), "ASN1_OUTPUT_DATA"}, | ||
| 114 | {ERR_FUNC(ASN1_F_ASN1_PACK_STRING), "ASN1_pack_string"}, | ||
| 115 | {ERR_FUNC(ASN1_F_ASN1_PCTX_NEW), "ASN1_PCTX_NEW"}, | ||
| 116 | {ERR_FUNC(ASN1_F_ASN1_PKCS5_PBE_SET), "ASN1_PKCS5_PBE_SET"}, | ||
| 117 | {ERR_FUNC(ASN1_F_ASN1_SEQ_PACK), "ASN1_seq_pack"}, | ||
| 118 | {ERR_FUNC(ASN1_F_ASN1_SEQ_UNPACK), "ASN1_seq_unpack"}, | ||
| 119 | {ERR_FUNC(ASN1_F_ASN1_SIGN), "ASN1_sign"}, | ||
| 120 | {ERR_FUNC(ASN1_F_ASN1_STR2TYPE), "ASN1_STR2TYPE"}, | ||
| 121 | {ERR_FUNC(ASN1_F_ASN1_STRING_SET), "ASN1_STRING_set"}, | ||
| 122 | {ERR_FUNC(ASN1_F_ASN1_STRING_TABLE_ADD), "ASN1_STRING_TABLE_add"}, | ||
| 123 | {ERR_FUNC(ASN1_F_ASN1_STRING_TYPE_NEW), "ASN1_STRING_type_new"}, | ||
| 124 | {ERR_FUNC(ASN1_F_ASN1_TEMPLATE_EX_D2I), "ASN1_TEMPLATE_EX_D2I"}, | ||
| 125 | {ERR_FUNC(ASN1_F_ASN1_TEMPLATE_NEW), "ASN1_TEMPLATE_NEW"}, | ||
| 126 | {ERR_FUNC(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I), "ASN1_TEMPLATE_NOEXP_D2I"}, | ||
| 127 | {ERR_FUNC(ASN1_F_ASN1_TIME_SET), "ASN1_TIME_set"}, | ||
| 128 | {ERR_FUNC(ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING), "ASN1_TYPE_get_int_octetstring"}, | ||
| 129 | {ERR_FUNC(ASN1_F_ASN1_TYPE_GET_OCTETSTRING), "ASN1_TYPE_get_octetstring"}, | ||
| 130 | {ERR_FUNC(ASN1_F_ASN1_UNPACK_STRING), "ASN1_unpack_string"}, | ||
| 131 | {ERR_FUNC(ASN1_F_ASN1_UTCTIME_SET), "ASN1_UTCTIME_set"}, | ||
| 132 | {ERR_FUNC(ASN1_F_ASN1_VERIFY), "ASN1_verify"}, | ||
| 133 | {ERR_FUNC(ASN1_F_B64_READ_ASN1), "B64_READ_ASN1"}, | ||
| 134 | {ERR_FUNC(ASN1_F_B64_WRITE_ASN1), "B64_WRITE_ASN1"}, | ||
| 135 | {ERR_FUNC(ASN1_F_BITSTR_CB), "BITSTR_CB"}, | ||
| 136 | {ERR_FUNC(ASN1_F_BN_TO_ASN1_ENUMERATED), "BN_to_ASN1_ENUMERATED"}, | ||
| 137 | {ERR_FUNC(ASN1_F_BN_TO_ASN1_INTEGER), "BN_to_ASN1_INTEGER"}, | ||
| 138 | {ERR_FUNC(ASN1_F_C2I_ASN1_BIT_STRING), "c2i_ASN1_BIT_STRING"}, | ||
| 139 | {ERR_FUNC(ASN1_F_C2I_ASN1_INTEGER), "c2i_ASN1_INTEGER"}, | ||
| 140 | {ERR_FUNC(ASN1_F_C2I_ASN1_OBJECT), "c2i_ASN1_OBJECT"}, | ||
| 141 | {ERR_FUNC(ASN1_F_COLLECT_DATA), "COLLECT_DATA"}, | ||
| 142 | {ERR_FUNC(ASN1_F_D2I_ASN1_BIT_STRING), "D2I_ASN1_BIT_STRING"}, | ||
| 143 | {ERR_FUNC(ASN1_F_D2I_ASN1_BOOLEAN), "d2i_ASN1_BOOLEAN"}, | ||
| 144 | {ERR_FUNC(ASN1_F_D2I_ASN1_BYTES), "d2i_ASN1_bytes"}, | ||
| 145 | {ERR_FUNC(ASN1_F_D2I_ASN1_GENERALIZEDTIME), "D2I_ASN1_GENERALIZEDTIME"}, | ||
| 146 | {ERR_FUNC(ASN1_F_D2I_ASN1_HEADER), "d2i_ASN1_HEADER"}, | ||
| 147 | {ERR_FUNC(ASN1_F_D2I_ASN1_INTEGER), "D2I_ASN1_INTEGER"}, | ||
| 148 | {ERR_FUNC(ASN1_F_D2I_ASN1_OBJECT), "d2i_ASN1_OBJECT"}, | ||
| 149 | {ERR_FUNC(ASN1_F_D2I_ASN1_SET), "d2i_ASN1_SET"}, | ||
| 150 | {ERR_FUNC(ASN1_F_D2I_ASN1_TYPE_BYTES), "d2i_ASN1_type_bytes"}, | ||
| 151 | {ERR_FUNC(ASN1_F_D2I_ASN1_UINTEGER), "d2i_ASN1_UINTEGER"}, | ||
| 152 | {ERR_FUNC(ASN1_F_D2I_ASN1_UTCTIME), "D2I_ASN1_UTCTIME"}, | ||
| 153 | {ERR_FUNC(ASN1_F_D2I_NETSCAPE_RSA), "d2i_Netscape_RSA"}, | ||
| 154 | {ERR_FUNC(ASN1_F_D2I_NETSCAPE_RSA_2), "D2I_NETSCAPE_RSA_2"}, | ||
| 155 | {ERR_FUNC(ASN1_F_D2I_PRIVATEKEY), "d2i_PrivateKey"}, | ||
| 156 | {ERR_FUNC(ASN1_F_D2I_PUBLICKEY), "d2i_PublicKey"}, | ||
| 157 | {ERR_FUNC(ASN1_F_D2I_RSA_NET), "d2i_RSA_NET"}, | ||
| 158 | {ERR_FUNC(ASN1_F_D2I_RSA_NET_2), "D2I_RSA_NET_2"}, | ||
| 159 | {ERR_FUNC(ASN1_F_D2I_X509), "D2I_X509"}, | ||
| 160 | {ERR_FUNC(ASN1_F_D2I_X509_CINF), "D2I_X509_CINF"}, | ||
| 161 | {ERR_FUNC(ASN1_F_D2I_X509_PKEY), "d2i_X509_PKEY"}, | ||
| 162 | {ERR_FUNC(ASN1_F_I2D_ASN1_SET), "i2d_ASN1_SET"}, | ||
| 163 | {ERR_FUNC(ASN1_F_I2D_ASN1_TIME), "I2D_ASN1_TIME"}, | ||
| 164 | {ERR_FUNC(ASN1_F_I2D_DSA_PUBKEY), "i2d_DSA_PUBKEY"}, | ||
| 165 | {ERR_FUNC(ASN1_F_I2D_EC_PUBKEY), "i2d_EC_PUBKEY"}, | ||
| 166 | {ERR_FUNC(ASN1_F_I2D_PRIVATEKEY), "i2d_PrivateKey"}, | ||
| 167 | {ERR_FUNC(ASN1_F_I2D_PUBLICKEY), "i2d_PublicKey"}, | ||
| 168 | {ERR_FUNC(ASN1_F_I2D_RSA_NET), "i2d_RSA_NET"}, | ||
| 169 | {ERR_FUNC(ASN1_F_I2D_RSA_PUBKEY), "i2d_RSA_PUBKEY"}, | ||
| 170 | {ERR_FUNC(ASN1_F_LONG_C2I), "LONG_C2I"}, | ||
| 171 | {ERR_FUNC(ASN1_F_OID_MODULE_INIT), "OID_MODULE_INIT"}, | ||
| 172 | {ERR_FUNC(ASN1_F_PARSE_TAGGING), "PARSE_TAGGING"}, | ||
| 173 | {ERR_FUNC(ASN1_F_PKCS5_PBE2_SET), "PKCS5_pbe2_set"}, | ||
| 174 | {ERR_FUNC(ASN1_F_PKCS5_PBE_SET), "PKCS5_pbe_set"}, | ||
| 175 | {ERR_FUNC(ASN1_F_SMIME_READ_ASN1), "SMIME_read_ASN1"}, | ||
| 176 | {ERR_FUNC(ASN1_F_SMIME_TEXT), "SMIME_text"}, | ||
| 177 | {ERR_FUNC(ASN1_F_X509_CINF_NEW), "X509_CINF_NEW"}, | ||
| 178 | {ERR_FUNC(ASN1_F_X509_CRL_ADD0_REVOKED), "X509_CRL_add0_revoked"}, | ||
| 179 | {ERR_FUNC(ASN1_F_X509_INFO_NEW), "X509_INFO_new"}, | ||
| 180 | {ERR_FUNC(ASN1_F_X509_NAME_ENCODE), "X509_NAME_ENCODE"}, | ||
| 181 | {ERR_FUNC(ASN1_F_X509_NAME_EX_D2I), "X509_NAME_EX_D2I"}, | ||
| 182 | {ERR_FUNC(ASN1_F_X509_NAME_EX_NEW), "X509_NAME_EX_NEW"}, | ||
| 183 | {ERR_FUNC(ASN1_F_X509_NEW), "X509_NEW"}, | ||
| 184 | {ERR_FUNC(ASN1_F_X509_PKEY_NEW), "X509_PKEY_new"}, | ||
| 185 | {0,NULL} | ||
| 186 | }; | ||
| 187 | |||
| 188 | static ERR_STRING_DATA ASN1_str_reasons[]= | ||
| 189 | { | ||
| 190 | {ERR_REASON(ASN1_R_ADDING_OBJECT) ,"adding object"}, | ||
| 191 | {ERR_REASON(ASN1_R_ASN1_PARSE_ERROR) ,"asn1 parse error"}, | ||
| 192 | {ERR_REASON(ASN1_R_ASN1_SIG_PARSE_ERROR) ,"asn1 sig parse error"}, | ||
| 193 | {ERR_REASON(ASN1_R_AUX_ERROR) ,"aux error"}, | ||
| 194 | {ERR_REASON(ASN1_R_BAD_CLASS) ,"bad class"}, | ||
| 195 | {ERR_REASON(ASN1_R_BAD_OBJECT_HEADER) ,"bad object header"}, | ||
| 196 | {ERR_REASON(ASN1_R_BAD_PASSWORD_READ) ,"bad password read"}, | ||
| 197 | {ERR_REASON(ASN1_R_BAD_TAG) ,"bad tag"}, | ||
| 198 | {ERR_REASON(ASN1_R_BN_LIB) ,"bn lib"}, | ||
| 199 | {ERR_REASON(ASN1_R_BOOLEAN_IS_WRONG_LENGTH),"boolean is wrong length"}, | ||
| 200 | {ERR_REASON(ASN1_R_BUFFER_TOO_SMALL) ,"buffer too small"}, | ||
| 201 | {ERR_REASON(ASN1_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER),"cipher has no object identifier"}, | ||
| 202 | {ERR_REASON(ASN1_R_DATA_IS_WRONG) ,"data is wrong"}, | ||
| 203 | {ERR_REASON(ASN1_R_DECODE_ERROR) ,"decode error"}, | ||
| 204 | {ERR_REASON(ASN1_R_DECODING_ERROR) ,"decoding error"}, | ||
| 205 | {ERR_REASON(ASN1_R_DEPTH_EXCEEDED) ,"depth exceeded"}, | ||
| 206 | {ERR_REASON(ASN1_R_ENCODE_ERROR) ,"encode error"}, | ||
| 207 | {ERR_REASON(ASN1_R_ERROR_GETTING_TIME) ,"error getting time"}, | ||
| 208 | {ERR_REASON(ASN1_R_ERROR_LOADING_SECTION),"error loading section"}, | ||
| 209 | {ERR_REASON(ASN1_R_ERROR_PARSING_SET_ELEMENT),"error parsing set element"}, | ||
| 210 | {ERR_REASON(ASN1_R_ERROR_SETTING_CIPHER_PARAMS),"error setting cipher params"}, | ||
| 211 | {ERR_REASON(ASN1_R_EXPECTING_AN_INTEGER) ,"expecting an integer"}, | ||
| 212 | {ERR_REASON(ASN1_R_EXPECTING_AN_OBJECT) ,"expecting an object"}, | ||
| 213 | {ERR_REASON(ASN1_R_EXPECTING_A_BOOLEAN) ,"expecting a boolean"}, | ||
| 214 | {ERR_REASON(ASN1_R_EXPECTING_A_TIME) ,"expecting a time"}, | ||
| 215 | {ERR_REASON(ASN1_R_EXPLICIT_LENGTH_MISMATCH),"explicit length mismatch"}, | ||
| 216 | {ERR_REASON(ASN1_R_EXPLICIT_TAG_NOT_CONSTRUCTED),"explicit tag not constructed"}, | ||
| 217 | {ERR_REASON(ASN1_R_FIELD_MISSING) ,"field missing"}, | ||
| 218 | {ERR_REASON(ASN1_R_FIRST_NUM_TOO_LARGE) ,"first num too large"}, | ||
| 219 | {ERR_REASON(ASN1_R_HEADER_TOO_LONG) ,"header too long"}, | ||
| 220 | {ERR_REASON(ASN1_R_ILLEGAL_BITSTRING_FORMAT),"illegal bitstring format"}, | ||
| 221 | {ERR_REASON(ASN1_R_ILLEGAL_BOOLEAN) ,"illegal boolean"}, | ||
| 222 | {ERR_REASON(ASN1_R_ILLEGAL_CHARACTERS) ,"illegal characters"}, | ||
| 223 | {ERR_REASON(ASN1_R_ILLEGAL_FORMAT) ,"illegal format"}, | ||
| 224 | {ERR_REASON(ASN1_R_ILLEGAL_HEX) ,"illegal hex"}, | ||
| 225 | {ERR_REASON(ASN1_R_ILLEGAL_IMPLICIT_TAG) ,"illegal implicit tag"}, | ||
| 226 | {ERR_REASON(ASN1_R_ILLEGAL_INTEGER) ,"illegal integer"}, | ||
| 227 | {ERR_REASON(ASN1_R_ILLEGAL_NESTED_TAGGING),"illegal nested tagging"}, | ||
| 228 | {ERR_REASON(ASN1_R_ILLEGAL_NULL) ,"illegal null"}, | ||
| 229 | {ERR_REASON(ASN1_R_ILLEGAL_NULL_VALUE) ,"illegal null value"}, | ||
| 230 | {ERR_REASON(ASN1_R_ILLEGAL_OBJECT) ,"illegal object"}, | ||
| 231 | {ERR_REASON(ASN1_R_ILLEGAL_OPTIONAL_ANY) ,"illegal optional any"}, | ||
| 232 | {ERR_REASON(ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE),"illegal options on item template"}, | ||
| 233 | {ERR_REASON(ASN1_R_ILLEGAL_TAGGED_ANY) ,"illegal tagged any"}, | ||
| 234 | {ERR_REASON(ASN1_R_ILLEGAL_TIME_VALUE) ,"illegal time value"}, | ||
| 235 | {ERR_REASON(ASN1_R_INTEGER_NOT_ASCII_FORMAT),"integer not ascii format"}, | ||
| 236 | {ERR_REASON(ASN1_R_INTEGER_TOO_LARGE_FOR_LONG),"integer too large for long"}, | ||
| 237 | {ERR_REASON(ASN1_R_INVALID_BMPSTRING_LENGTH),"invalid bmpstring length"}, | ||
| 238 | {ERR_REASON(ASN1_R_INVALID_DIGIT) ,"invalid digit"}, | ||
| 239 | {ERR_REASON(ASN1_R_INVALID_MIME_TYPE) ,"invalid mime type"}, | ||
| 240 | {ERR_REASON(ASN1_R_INVALID_MODIFIER) ,"invalid modifier"}, | ||
| 241 | {ERR_REASON(ASN1_R_INVALID_NUMBER) ,"invalid number"}, | ||
| 242 | {ERR_REASON(ASN1_R_INVALID_SEPARATOR) ,"invalid separator"}, | ||
| 243 | {ERR_REASON(ASN1_R_INVALID_TIME_FORMAT) ,"invalid time format"}, | ||
| 244 | {ERR_REASON(ASN1_R_INVALID_UNIVERSALSTRING_LENGTH),"invalid universalstring length"}, | ||
| 245 | {ERR_REASON(ASN1_R_INVALID_UTF8STRING) ,"invalid utf8string"}, | ||
| 246 | {ERR_REASON(ASN1_R_IV_TOO_LARGE) ,"iv too large"}, | ||
| 247 | {ERR_REASON(ASN1_R_LENGTH_ERROR) ,"length error"}, | ||
| 248 | {ERR_REASON(ASN1_R_LIST_ERROR) ,"list error"}, | ||
| 249 | {ERR_REASON(ASN1_R_MIME_NO_CONTENT_TYPE) ,"mime no content type"}, | ||
| 250 | {ERR_REASON(ASN1_R_MIME_PARSE_ERROR) ,"mime parse error"}, | ||
| 251 | {ERR_REASON(ASN1_R_MIME_SIG_PARSE_ERROR) ,"mime sig parse error"}, | ||
| 252 | {ERR_REASON(ASN1_R_MISSING_EOC) ,"missing eoc"}, | ||
| 253 | {ERR_REASON(ASN1_R_MISSING_SECOND_NUMBER),"missing second number"}, | ||
| 254 | {ERR_REASON(ASN1_R_MISSING_VALUE) ,"missing value"}, | ||
| 255 | {ERR_REASON(ASN1_R_MSTRING_NOT_UNIVERSAL),"mstring not universal"}, | ||
| 256 | {ERR_REASON(ASN1_R_MSTRING_WRONG_TAG) ,"mstring wrong tag"}, | ||
| 257 | {ERR_REASON(ASN1_R_NESTED_ASN1_STRING) ,"nested asn1 string"}, | ||
| 258 | {ERR_REASON(ASN1_R_NON_HEX_CHARACTERS) ,"non hex characters"}, | ||
| 259 | {ERR_REASON(ASN1_R_NOT_ASCII_FORMAT) ,"not ascii format"}, | ||
| 260 | {ERR_REASON(ASN1_R_NOT_ENOUGH_DATA) ,"not enough data"}, | ||
| 261 | {ERR_REASON(ASN1_R_NO_CONTENT_TYPE) ,"no content type"}, | ||
| 262 | {ERR_REASON(ASN1_R_NO_MATCHING_CHOICE_TYPE),"no matching choice type"}, | ||
| 263 | {ERR_REASON(ASN1_R_NO_MULTIPART_BODY_FAILURE),"no multipart body failure"}, | ||
| 264 | {ERR_REASON(ASN1_R_NO_MULTIPART_BOUNDARY),"no multipart boundary"}, | ||
| 265 | {ERR_REASON(ASN1_R_NO_SIG_CONTENT_TYPE) ,"no sig content type"}, | ||
| 266 | {ERR_REASON(ASN1_R_NULL_IS_WRONG_LENGTH) ,"null is wrong length"}, | ||
| 267 | {ERR_REASON(ASN1_R_OBJECT_NOT_ASCII_FORMAT),"object not ascii format"}, | ||
| 268 | {ERR_REASON(ASN1_R_ODD_NUMBER_OF_CHARS) ,"odd number of chars"}, | ||
| 269 | {ERR_REASON(ASN1_R_PRIVATE_KEY_HEADER_MISSING),"private key header missing"}, | ||
| 270 | {ERR_REASON(ASN1_R_SECOND_NUMBER_TOO_LARGE),"second number too large"}, | ||
| 271 | {ERR_REASON(ASN1_R_SEQUENCE_LENGTH_MISMATCH),"sequence length mismatch"}, | ||
| 272 | {ERR_REASON(ASN1_R_SEQUENCE_NOT_CONSTRUCTED),"sequence not constructed"}, | ||
| 273 | {ERR_REASON(ASN1_R_SEQUENCE_OR_SET_NEEDS_CONFIG),"sequence or set needs config"}, | ||
| 274 | {ERR_REASON(ASN1_R_SHORT_LINE) ,"short line"}, | ||
| 275 | {ERR_REASON(ASN1_R_SIG_INVALID_MIME_TYPE),"sig invalid mime type"}, | ||
| 276 | {ERR_REASON(ASN1_R_STREAMING_NOT_SUPPORTED),"streaming not supported"}, | ||
| 277 | {ERR_REASON(ASN1_R_STRING_TOO_LONG) ,"string too long"}, | ||
| 278 | {ERR_REASON(ASN1_R_STRING_TOO_SHORT) ,"string too short"}, | ||
| 279 | {ERR_REASON(ASN1_R_TAG_VALUE_TOO_HIGH) ,"tag value too high"}, | ||
| 280 | {ERR_REASON(ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD),"the asn1 object identifier is not known for this md"}, | ||
| 281 | {ERR_REASON(ASN1_R_TIME_NOT_ASCII_FORMAT),"time not ascii format"}, | ||
| 282 | {ERR_REASON(ASN1_R_TOO_LONG) ,"too long"}, | ||
| 283 | {ERR_REASON(ASN1_R_TYPE_NOT_CONSTRUCTED) ,"type not constructed"}, | ||
| 284 | {ERR_REASON(ASN1_R_UNABLE_TO_DECODE_RSA_KEY),"unable to decode rsa key"}, | ||
| 285 | {ERR_REASON(ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY),"unable to decode rsa private key"}, | ||
| 286 | {ERR_REASON(ASN1_R_UNEXPECTED_EOC) ,"unexpected eoc"}, | ||
| 287 | {ERR_REASON(ASN1_R_UNKNOWN_FORMAT) ,"unknown format"}, | ||
| 288 | {ERR_REASON(ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM),"unknown message digest algorithm"}, | ||
| 289 | {ERR_REASON(ASN1_R_UNKNOWN_OBJECT_TYPE) ,"unknown object type"}, | ||
| 290 | {ERR_REASON(ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE),"unknown public key type"}, | ||
| 291 | {ERR_REASON(ASN1_R_UNKNOWN_TAG) ,"unknown tag"}, | ||
| 292 | {ERR_REASON(ASN1_R_UNKOWN_FORMAT) ,"unkown format"}, | ||
| 293 | {ERR_REASON(ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE),"unsupported any defined by type"}, | ||
| 294 | {ERR_REASON(ASN1_R_UNSUPPORTED_CIPHER) ,"unsupported cipher"}, | ||
| 295 | {ERR_REASON(ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM),"unsupported encryption algorithm"}, | ||
| 296 | {ERR_REASON(ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE),"unsupported public key type"}, | ||
| 297 | {ERR_REASON(ASN1_R_UNSUPPORTED_TYPE) ,"unsupported type"}, | ||
| 298 | {ERR_REASON(ASN1_R_WRONG_TAG) ,"wrong tag"}, | ||
| 299 | {ERR_REASON(ASN1_R_WRONG_TYPE) ,"wrong type"}, | ||
| 300 | {0,NULL} | ||
| 301 | }; | ||
| 302 | |||
| 303 | #endif | ||
| 304 | |||
| 305 | void ERR_load_ASN1_strings(void) | ||
| 306 | { | ||
| 307 | #ifndef OPENSSL_NO_ERR | ||
| 308 | |||
| 309 | if (ERR_func_error_string(ASN1_str_functs[0].error) == NULL) | ||
| 310 | { | ||
| 311 | ERR_load_strings(0,ASN1_str_functs); | ||
| 312 | ERR_load_strings(0,ASN1_str_reasons); | ||
| 313 | } | ||
| 314 | #endif | ||
| 315 | } | ||
diff --git a/src/lib/libcrypto/asn1/asn1_gen.c b/src/lib/libcrypto/asn1/asn1_gen.c new file mode 100644 index 0000000000..26c832781e --- /dev/null +++ b/src/lib/libcrypto/asn1/asn1_gen.c | |||
| @@ -0,0 +1,848 @@ | |||
| 1 | /* asn1_gen.c */ | ||
| 2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
| 3 | * project 2002. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 2002 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include "cryptlib.h" | ||
| 60 | #include <openssl/asn1.h> | ||
| 61 | #include <openssl/x509v3.h> | ||
| 62 | |||
| 63 | #define ASN1_GEN_FLAG 0x10000 | ||
| 64 | #define ASN1_GEN_FLAG_IMP (ASN1_GEN_FLAG|1) | ||
| 65 | #define ASN1_GEN_FLAG_EXP (ASN1_GEN_FLAG|2) | ||
| 66 | #define ASN1_GEN_FLAG_TAG (ASN1_GEN_FLAG|3) | ||
| 67 | #define ASN1_GEN_FLAG_BITWRAP (ASN1_GEN_FLAG|4) | ||
| 68 | #define ASN1_GEN_FLAG_OCTWRAP (ASN1_GEN_FLAG|5) | ||
| 69 | #define ASN1_GEN_FLAG_SEQWRAP (ASN1_GEN_FLAG|6) | ||
| 70 | #define ASN1_GEN_FLAG_SETWRAP (ASN1_GEN_FLAG|7) | ||
| 71 | #define ASN1_GEN_FLAG_FORMAT (ASN1_GEN_FLAG|8) | ||
| 72 | |||
| 73 | #define ASN1_GEN_STR(str,val) {str, sizeof(str) - 1, val} | ||
| 74 | |||
| 75 | #define ASN1_FLAG_EXP_MAX 20 | ||
| 76 | |||
| 77 | /* Input formats */ | ||
| 78 | |||
| 79 | /* ASCII: default */ | ||
| 80 | #define ASN1_GEN_FORMAT_ASCII 1 | ||
| 81 | /* UTF8 */ | ||
| 82 | #define ASN1_GEN_FORMAT_UTF8 2 | ||
| 83 | /* Hex */ | ||
| 84 | #define ASN1_GEN_FORMAT_HEX 3 | ||
| 85 | /* List of bits */ | ||
| 86 | #define ASN1_GEN_FORMAT_BITLIST 4 | ||
| 87 | |||
| 88 | |||
| 89 | struct tag_name_st | ||
| 90 | { | ||
| 91 | const char *strnam; | ||
| 92 | int len; | ||
| 93 | int tag; | ||
| 94 | }; | ||
| 95 | |||
| 96 | typedef struct | ||
| 97 | { | ||
| 98 | int exp_tag; | ||
| 99 | int exp_class; | ||
| 100 | int exp_constructed; | ||
| 101 | int exp_pad; | ||
| 102 | long exp_len; | ||
| 103 | } tag_exp_type; | ||
| 104 | |||
| 105 | typedef struct | ||
| 106 | { | ||
| 107 | int imp_tag; | ||
| 108 | int imp_class; | ||
| 109 | int utype; | ||
| 110 | int format; | ||
| 111 | const char *str; | ||
| 112 | tag_exp_type exp_list[ASN1_FLAG_EXP_MAX]; | ||
| 113 | int exp_count; | ||
| 114 | } tag_exp_arg; | ||
| 115 | |||
| 116 | static int bitstr_cb(const char *elem, int len, void *bitstr); | ||
| 117 | static int asn1_cb(const char *elem, int len, void *bitstr); | ||
| 118 | static int append_exp(tag_exp_arg *arg, int exp_tag, int exp_class, int exp_constructed, int exp_pad, int imp_ok); | ||
| 119 | static int parse_tagging(const char *vstart, int vlen, int *ptag, int *pclass); | ||
| 120 | static ASN1_TYPE *asn1_multi(int utype, const char *section, X509V3_CTX *cnf); | ||
| 121 | static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype); | ||
| 122 | static int asn1_str2tag(const char *tagstr, int len); | ||
| 123 | |||
| 124 | ASN1_TYPE *ASN1_generate_nconf(char *str, CONF *nconf) | ||
| 125 | { | ||
| 126 | X509V3_CTX cnf; | ||
| 127 | |||
| 128 | if (!nconf) | ||
| 129 | return ASN1_generate_v3(str, NULL); | ||
| 130 | |||
| 131 | X509V3_set_nconf(&cnf, nconf); | ||
| 132 | return ASN1_generate_v3(str, &cnf); | ||
| 133 | } | ||
| 134 | |||
| 135 | ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf) | ||
| 136 | { | ||
| 137 | ASN1_TYPE *ret; | ||
| 138 | tag_exp_arg asn1_tags; | ||
| 139 | tag_exp_type *etmp; | ||
| 140 | |||
| 141 | int i, len; | ||
| 142 | |||
| 143 | unsigned char *orig_der = NULL, *new_der = NULL; | ||
| 144 | const unsigned char *cpy_start; | ||
| 145 | unsigned char *p; | ||
| 146 | const unsigned char *cp; | ||
| 147 | int cpy_len; | ||
| 148 | long hdr_len; | ||
| 149 | int hdr_constructed = 0, hdr_tag, hdr_class; | ||
| 150 | int r; | ||
| 151 | |||
| 152 | asn1_tags.imp_tag = -1; | ||
| 153 | asn1_tags.imp_class = -1; | ||
| 154 | asn1_tags.format = ASN1_GEN_FORMAT_ASCII; | ||
| 155 | asn1_tags.exp_count = 0; | ||
| 156 | if (CONF_parse_list(str, ',', 1, asn1_cb, &asn1_tags) != 0) | ||
| 157 | return NULL; | ||
| 158 | |||
| 159 | if ((asn1_tags.utype == V_ASN1_SEQUENCE) || (asn1_tags.utype == V_ASN1_SET)) | ||
| 160 | { | ||
| 161 | if (!cnf) | ||
| 162 | { | ||
| 163 | ASN1err(ASN1_F_ASN1_GENERATE_V3, ASN1_R_SEQUENCE_OR_SET_NEEDS_CONFIG); | ||
| 164 | return NULL; | ||
| 165 | } | ||
| 166 | ret = asn1_multi(asn1_tags.utype, asn1_tags.str, cnf); | ||
| 167 | } | ||
| 168 | else | ||
| 169 | ret = asn1_str2type(asn1_tags.str, asn1_tags.format, asn1_tags.utype); | ||
| 170 | |||
| 171 | if (!ret) | ||
| 172 | return NULL; | ||
| 173 | |||
| 174 | /* If no tagging return base type */ | ||
| 175 | if ((asn1_tags.imp_tag == -1) && (asn1_tags.exp_count == 0)) | ||
| 176 | return ret; | ||
| 177 | |||
| 178 | /* Generate the encoding */ | ||
| 179 | cpy_len = i2d_ASN1_TYPE(ret, &orig_der); | ||
| 180 | ASN1_TYPE_free(ret); | ||
| 181 | ret = NULL; | ||
| 182 | /* Set point to start copying for modified encoding */ | ||
| 183 | cpy_start = orig_der; | ||
| 184 | |||
| 185 | /* Do we need IMPLICIT tagging? */ | ||
| 186 | if (asn1_tags.imp_tag != -1) | ||
| 187 | { | ||
| 188 | /* If IMPLICIT we will replace the underlying tag */ | ||
| 189 | /* Skip existing tag+len */ | ||
| 190 | r = ASN1_get_object(&cpy_start, &hdr_len, &hdr_tag, &hdr_class, cpy_len); | ||
| 191 | if (r & 0x80) | ||
| 192 | goto err; | ||
| 193 | /* Update copy length */ | ||
| 194 | cpy_len -= cpy_start - orig_der; | ||
| 195 | /* For IMPLICIT tagging the length should match the | ||
| 196 | * original length and constructed flag should be | ||
| 197 | * consistent. | ||
| 198 | */ | ||
| 199 | if (r & 0x1) | ||
| 200 | { | ||
| 201 | /* Indefinite length constructed */ | ||
| 202 | hdr_constructed = 2; | ||
| 203 | hdr_len = 0; | ||
| 204 | } | ||
| 205 | else | ||
| 206 | /* Just retain constructed flag */ | ||
| 207 | hdr_constructed = r & V_ASN1_CONSTRUCTED; | ||
| 208 | /* Work out new length with IMPLICIT tag: ignore constructed | ||
| 209 | * because it will mess up if indefinite length | ||
| 210 | */ | ||
| 211 | len = ASN1_object_size(0, hdr_len, asn1_tags.imp_tag); | ||
| 212 | } | ||
| 213 | else | ||
| 214 | len = cpy_len; | ||
| 215 | |||
| 216 | /* Work out length in any EXPLICIT, starting from end */ | ||
| 217 | |||
| 218 | for(i = 0, etmp = asn1_tags.exp_list + asn1_tags.exp_count - 1; i < asn1_tags.exp_count; i++, etmp--) | ||
| 219 | { | ||
| 220 | /* Content length: number of content octets + any padding */ | ||
| 221 | len += etmp->exp_pad; | ||
| 222 | etmp->exp_len = len; | ||
| 223 | /* Total object length: length including new header */ | ||
| 224 | len = ASN1_object_size(0, len, etmp->exp_tag); | ||
| 225 | } | ||
| 226 | |||
| 227 | /* Allocate buffer for new encoding */ | ||
| 228 | |||
| 229 | new_der = OPENSSL_malloc(len); | ||
| 230 | |||
| 231 | /* Generate tagged encoding */ | ||
| 232 | |||
| 233 | p = new_der; | ||
| 234 | |||
| 235 | /* Output explicit tags first */ | ||
| 236 | |||
| 237 | for (i = 0, etmp = asn1_tags.exp_list; i < asn1_tags.exp_count; i++, etmp++) | ||
| 238 | { | ||
| 239 | ASN1_put_object(&p, etmp->exp_constructed, etmp->exp_len, | ||
| 240 | etmp->exp_tag, etmp->exp_class); | ||
| 241 | if (etmp->exp_pad) | ||
| 242 | *p++ = 0; | ||
| 243 | } | ||
| 244 | |||
| 245 | /* If IMPLICIT, output tag */ | ||
| 246 | |||
| 247 | if (asn1_tags.imp_tag != -1) | ||
| 248 | ASN1_put_object(&p, hdr_constructed, hdr_len, | ||
| 249 | asn1_tags.imp_tag, asn1_tags.imp_class); | ||
| 250 | |||
| 251 | /* Copy across original encoding */ | ||
| 252 | memcpy(p, cpy_start, cpy_len); | ||
| 253 | |||
| 254 | cp = new_der; | ||
| 255 | |||
| 256 | /* Obtain new ASN1_TYPE structure */ | ||
| 257 | ret = d2i_ASN1_TYPE(NULL, &cp, len); | ||
| 258 | |||
| 259 | err: | ||
| 260 | if (orig_der) | ||
| 261 | OPENSSL_free(orig_der); | ||
| 262 | if (new_der) | ||
| 263 | OPENSSL_free(new_der); | ||
| 264 | |||
| 265 | return ret; | ||
| 266 | |||
| 267 | } | ||
| 268 | |||
| 269 | static int asn1_cb(const char *elem, int len, void *bitstr) | ||
| 270 | { | ||
| 271 | tag_exp_arg *arg = bitstr; | ||
| 272 | int i; | ||
| 273 | int utype; | ||
| 274 | int vlen = 0; | ||
| 275 | const char *p, *vstart = NULL; | ||
| 276 | |||
| 277 | int tmp_tag, tmp_class; | ||
| 278 | |||
| 279 | for(i = 0, p = elem; i < len; p++, i++) | ||
| 280 | { | ||
| 281 | /* Look for the ':' in name value pairs */ | ||
| 282 | if (*p == ':') | ||
| 283 | { | ||
| 284 | vstart = p + 1; | ||
| 285 | vlen = len - (vstart - elem); | ||
| 286 | len = p - elem; | ||
| 287 | break; | ||
| 288 | } | ||
| 289 | } | ||
| 290 | |||
| 291 | utype = asn1_str2tag(elem, len); | ||
| 292 | |||
| 293 | if (utype == -1) | ||
| 294 | { | ||
| 295 | ASN1err(ASN1_F_ASN1_CB, ASN1_R_UNKNOWN_TAG); | ||
| 296 | ERR_add_error_data(2, "tag=", elem); | ||
| 297 | return -1; | ||
| 298 | } | ||
| 299 | |||
| 300 | /* If this is not a modifier mark end of string and exit */ | ||
| 301 | if (!(utype & ASN1_GEN_FLAG)) | ||
| 302 | { | ||
| 303 | arg->utype = utype; | ||
| 304 | arg->str = vstart; | ||
| 305 | /* If no value and not end of string, error */ | ||
| 306 | if (!vstart && elem[len]) | ||
| 307 | { | ||
| 308 | ASN1err(ASN1_F_ASN1_CB, ASN1_R_MISSING_VALUE); | ||
| 309 | return -1; | ||
| 310 | } | ||
| 311 | return 0; | ||
| 312 | } | ||
| 313 | |||
| 314 | switch(utype) | ||
| 315 | { | ||
| 316 | |||
| 317 | case ASN1_GEN_FLAG_IMP: | ||
| 318 | /* Check for illegal multiple IMPLICIT tagging */ | ||
| 319 | if (arg->imp_tag != -1) | ||
| 320 | { | ||
| 321 | ASN1err(ASN1_F_ASN1_CB, ASN1_R_ILLEGAL_NESTED_TAGGING); | ||
| 322 | return -1; | ||
| 323 | } | ||
| 324 | if (!parse_tagging(vstart, vlen, &arg->imp_tag, &arg->imp_class)) | ||
| 325 | return -1; | ||
| 326 | break; | ||
| 327 | |||
| 328 | case ASN1_GEN_FLAG_EXP: | ||
| 329 | |||
| 330 | if (!parse_tagging(vstart, vlen, &tmp_tag, &tmp_class)) | ||
| 331 | return -1; | ||
| 332 | if (!append_exp(arg, tmp_tag, tmp_class, 1, 0, 0)) | ||
| 333 | return -1; | ||
| 334 | break; | ||
| 335 | |||
| 336 | case ASN1_GEN_FLAG_SEQWRAP: | ||
| 337 | if (!append_exp(arg, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL, 1, 0, 1)) | ||
| 338 | return -1; | ||
| 339 | break; | ||
| 340 | |||
| 341 | case ASN1_GEN_FLAG_SETWRAP: | ||
| 342 | if (!append_exp(arg, V_ASN1_SET, V_ASN1_UNIVERSAL, 1, 0, 1)) | ||
| 343 | return -1; | ||
| 344 | break; | ||
| 345 | |||
| 346 | case ASN1_GEN_FLAG_BITWRAP: | ||
| 347 | if (!append_exp(arg, V_ASN1_BIT_STRING, V_ASN1_UNIVERSAL, 0, 1, 1)) | ||
| 348 | return -1; | ||
| 349 | break; | ||
| 350 | |||
| 351 | case ASN1_GEN_FLAG_OCTWRAP: | ||
| 352 | if (!append_exp(arg, V_ASN1_OCTET_STRING, V_ASN1_UNIVERSAL, 0, 0, 1)) | ||
| 353 | return -1; | ||
| 354 | break; | ||
| 355 | |||
| 356 | case ASN1_GEN_FLAG_FORMAT: | ||
| 357 | if (!strncmp(vstart, "ASCII", 5)) | ||
| 358 | arg->format = ASN1_GEN_FORMAT_ASCII; | ||
| 359 | else if (!strncmp(vstart, "UTF8", 4)) | ||
| 360 | arg->format = ASN1_GEN_FORMAT_UTF8; | ||
| 361 | else if (!strncmp(vstart, "HEX", 3)) | ||
| 362 | arg->format = ASN1_GEN_FORMAT_HEX; | ||
| 363 | else if (!strncmp(vstart, "BITLIST", 3)) | ||
| 364 | arg->format = ASN1_GEN_FORMAT_BITLIST; | ||
| 365 | else | ||
| 366 | { | ||
| 367 | ASN1err(ASN1_F_ASN1_CB, ASN1_R_UNKOWN_FORMAT); | ||
| 368 | return -1; | ||
| 369 | } | ||
| 370 | break; | ||
| 371 | |||
| 372 | } | ||
| 373 | |||
| 374 | return 1; | ||
| 375 | |||
| 376 | } | ||
| 377 | |||
| 378 | static int parse_tagging(const char *vstart, int vlen, int *ptag, int *pclass) | ||
| 379 | { | ||
| 380 | char erch[2]; | ||
| 381 | long tag_num; | ||
| 382 | char *eptr; | ||
| 383 | if (!vstart) | ||
| 384 | return 0; | ||
| 385 | tag_num = strtoul(vstart, &eptr, 10); | ||
| 386 | /* Check we haven't gone past max length: should be impossible */ | ||
| 387 | if (eptr && *eptr && (eptr > vstart + vlen)) | ||
| 388 | return 0; | ||
| 389 | if (tag_num < 0) | ||
| 390 | { | ||
| 391 | ASN1err(ASN1_F_PARSE_TAGGING, ASN1_R_INVALID_NUMBER); | ||
| 392 | return 0; | ||
| 393 | } | ||
| 394 | *ptag = tag_num; | ||
| 395 | /* If we have non numeric characters, parse them */ | ||
| 396 | if (eptr) | ||
| 397 | vlen -= eptr - vstart; | ||
| 398 | else | ||
| 399 | vlen = 0; | ||
| 400 | if (vlen) | ||
| 401 | { | ||
| 402 | switch (*eptr) | ||
| 403 | { | ||
| 404 | |||
| 405 | case 'U': | ||
| 406 | *pclass = V_ASN1_UNIVERSAL; | ||
| 407 | break; | ||
| 408 | |||
| 409 | case 'A': | ||
| 410 | *pclass = V_ASN1_APPLICATION; | ||
| 411 | break; | ||
| 412 | |||
| 413 | case 'P': | ||
| 414 | *pclass = V_ASN1_PRIVATE; | ||
| 415 | break; | ||
| 416 | |||
| 417 | case 'C': | ||
| 418 | *pclass = V_ASN1_CONTEXT_SPECIFIC; | ||
| 419 | break; | ||
| 420 | |||
| 421 | default: | ||
| 422 | erch[0] = *eptr; | ||
| 423 | erch[1] = 0; | ||
| 424 | ASN1err(ASN1_F_PARSE_TAGGING, ASN1_R_INVALID_MODIFIER); | ||
| 425 | ERR_add_error_data(2, "Char=", erch); | ||
| 426 | return 0; | ||
| 427 | break; | ||
| 428 | |||
| 429 | } | ||
| 430 | } | ||
| 431 | else | ||
| 432 | *pclass = V_ASN1_CONTEXT_SPECIFIC; | ||
| 433 | |||
| 434 | return 1; | ||
| 435 | |||
| 436 | } | ||
| 437 | |||
| 438 | /* Handle multiple types: SET and SEQUENCE */ | ||
| 439 | |||
| 440 | static ASN1_TYPE *asn1_multi(int utype, const char *section, X509V3_CTX *cnf) | ||
| 441 | { | ||
| 442 | ASN1_TYPE *ret = NULL, *typ = NULL; | ||
| 443 | STACK_OF(ASN1_TYPE) *sk = NULL; | ||
| 444 | STACK_OF(CONF_VALUE) *sect = NULL; | ||
| 445 | unsigned char *der = NULL, *p; | ||
| 446 | int derlen; | ||
| 447 | int i, is_set; | ||
| 448 | sk = sk_ASN1_TYPE_new_null(); | ||
| 449 | if (section) | ||
| 450 | { | ||
| 451 | if (!cnf) | ||
| 452 | goto bad; | ||
| 453 | sect = X509V3_get_section(cnf, (char *)section); | ||
| 454 | if (!sect) | ||
| 455 | goto bad; | ||
| 456 | for (i = 0; i < sk_CONF_VALUE_num(sect); i++) | ||
| 457 | { | ||
| 458 | typ = ASN1_generate_v3(sk_CONF_VALUE_value(sect, i)->value, cnf); | ||
| 459 | if (!typ) | ||
| 460 | goto bad; | ||
| 461 | sk_ASN1_TYPE_push(sk, typ); | ||
| 462 | typ = NULL; | ||
| 463 | } | ||
| 464 | } | ||
| 465 | |||
| 466 | /* Now we has a STACK of the components, convert to the correct form */ | ||
| 467 | |||
| 468 | if (utype == V_ASN1_SET) | ||
| 469 | is_set = 1; | ||
| 470 | else | ||
| 471 | is_set = 0; | ||
| 472 | |||
| 473 | |||
| 474 | derlen = i2d_ASN1_SET_OF_ASN1_TYPE(sk, NULL, i2d_ASN1_TYPE, utype, | ||
| 475 | V_ASN1_UNIVERSAL, is_set); | ||
| 476 | der = OPENSSL_malloc(derlen); | ||
| 477 | p = der; | ||
| 478 | i2d_ASN1_SET_OF_ASN1_TYPE(sk, &p, i2d_ASN1_TYPE, utype, | ||
| 479 | V_ASN1_UNIVERSAL, is_set); | ||
| 480 | |||
| 481 | if (!(ret = ASN1_TYPE_new())) | ||
| 482 | goto bad; | ||
| 483 | |||
| 484 | if (!(ret->value.asn1_string = ASN1_STRING_type_new(utype))) | ||
| 485 | goto bad; | ||
| 486 | |||
| 487 | ret->type = utype; | ||
| 488 | |||
| 489 | ret->value.asn1_string->data = der; | ||
| 490 | ret->value.asn1_string->length = derlen; | ||
| 491 | |||
| 492 | der = NULL; | ||
| 493 | |||
| 494 | bad: | ||
| 495 | |||
| 496 | if (der) | ||
| 497 | OPENSSL_free(der); | ||
| 498 | |||
| 499 | if (sk) | ||
| 500 | sk_ASN1_TYPE_pop_free(sk, ASN1_TYPE_free); | ||
| 501 | if (typ) | ||
| 502 | ASN1_TYPE_free(typ); | ||
| 503 | if (sect) | ||
| 504 | X509V3_section_free(cnf, sect); | ||
| 505 | |||
| 506 | return ret; | ||
| 507 | } | ||
| 508 | |||
| 509 | static int append_exp(tag_exp_arg *arg, int exp_tag, int exp_class, int exp_constructed, int exp_pad, int imp_ok) | ||
| 510 | { | ||
| 511 | tag_exp_type *exp_tmp; | ||
| 512 | /* Can only have IMPLICIT if permitted */ | ||
| 513 | if ((arg->imp_tag != -1) && !imp_ok) | ||
| 514 | { | ||
| 515 | ASN1err(ASN1_F_APPEND_EXP, ASN1_R_ILLEGAL_IMPLICIT_TAG); | ||
| 516 | return 0; | ||
| 517 | } | ||
| 518 | |||
| 519 | if (arg->exp_count == ASN1_FLAG_EXP_MAX) | ||
| 520 | { | ||
| 521 | ASN1err(ASN1_F_APPEND_EXP, ASN1_R_DEPTH_EXCEEDED); | ||
| 522 | return 0; | ||
| 523 | } | ||
| 524 | |||
| 525 | exp_tmp = &arg->exp_list[arg->exp_count++]; | ||
| 526 | |||
| 527 | /* If IMPLICIT set tag to implicit value then | ||
| 528 | * reset implicit tag since it has been used. | ||
| 529 | */ | ||
| 530 | if (arg->imp_tag != -1) | ||
| 531 | { | ||
| 532 | exp_tmp->exp_tag = arg->imp_tag; | ||
| 533 | exp_tmp->exp_class = arg->imp_class; | ||
| 534 | arg->imp_tag = -1; | ||
| 535 | arg->imp_class = -1; | ||
| 536 | } | ||
| 537 | else | ||
| 538 | { | ||
| 539 | exp_tmp->exp_tag = exp_tag; | ||
| 540 | exp_tmp->exp_class = exp_class; | ||
| 541 | } | ||
| 542 | exp_tmp->exp_constructed = exp_constructed; | ||
| 543 | exp_tmp->exp_pad = exp_pad; | ||
| 544 | |||
| 545 | return 1; | ||
| 546 | } | ||
| 547 | |||
| 548 | |||
| 549 | static int asn1_str2tag(const char *tagstr, int len) | ||
| 550 | { | ||
| 551 | unsigned int i; | ||
| 552 | static struct tag_name_st *tntmp, tnst [] = { | ||
| 553 | ASN1_GEN_STR("BOOL", V_ASN1_BOOLEAN), | ||
| 554 | ASN1_GEN_STR("BOOLEAN", V_ASN1_BOOLEAN), | ||
| 555 | ASN1_GEN_STR("NULL", V_ASN1_NULL), | ||
| 556 | ASN1_GEN_STR("INT", V_ASN1_INTEGER), | ||
| 557 | ASN1_GEN_STR("INTEGER", V_ASN1_INTEGER), | ||
| 558 | ASN1_GEN_STR("ENUM", V_ASN1_ENUMERATED), | ||
| 559 | ASN1_GEN_STR("ENUMERATED", V_ASN1_ENUMERATED), | ||
| 560 | ASN1_GEN_STR("OID", V_ASN1_OBJECT), | ||
| 561 | ASN1_GEN_STR("OBJECT", V_ASN1_OBJECT), | ||
| 562 | ASN1_GEN_STR("UTCTIME", V_ASN1_UTCTIME), | ||
| 563 | ASN1_GEN_STR("UTC", V_ASN1_UTCTIME), | ||
| 564 | ASN1_GEN_STR("GENERALIZEDTIME", V_ASN1_GENERALIZEDTIME), | ||
| 565 | ASN1_GEN_STR("GENTIME", V_ASN1_GENERALIZEDTIME), | ||
| 566 | ASN1_GEN_STR("OCT", V_ASN1_OCTET_STRING), | ||
| 567 | ASN1_GEN_STR("OCTETSTRING", V_ASN1_OCTET_STRING), | ||
| 568 | ASN1_GEN_STR("BITSTR", V_ASN1_BIT_STRING), | ||
| 569 | ASN1_GEN_STR("BITSTRING", V_ASN1_BIT_STRING), | ||
| 570 | ASN1_GEN_STR("UNIVERSALSTRING", V_ASN1_UNIVERSALSTRING), | ||
| 571 | ASN1_GEN_STR("UNIV", V_ASN1_UNIVERSALSTRING), | ||
| 572 | ASN1_GEN_STR("IA5", V_ASN1_IA5STRING), | ||
| 573 | ASN1_GEN_STR("IA5STRING", V_ASN1_IA5STRING), | ||
| 574 | ASN1_GEN_STR("UTF8", V_ASN1_UTF8STRING), | ||
| 575 | ASN1_GEN_STR("UTF8String", V_ASN1_UTF8STRING), | ||
| 576 | ASN1_GEN_STR("BMP", V_ASN1_BMPSTRING), | ||
| 577 | ASN1_GEN_STR("BMPSTRING", V_ASN1_BMPSTRING), | ||
| 578 | ASN1_GEN_STR("VISIBLESTRING", V_ASN1_VISIBLESTRING), | ||
| 579 | ASN1_GEN_STR("VISIBLE", V_ASN1_VISIBLESTRING), | ||
| 580 | ASN1_GEN_STR("PRINTABLESTRING", V_ASN1_PRINTABLESTRING), | ||
| 581 | ASN1_GEN_STR("PRINTABLE", V_ASN1_PRINTABLESTRING), | ||
| 582 | ASN1_GEN_STR("T61", V_ASN1_T61STRING), | ||
| 583 | ASN1_GEN_STR("T61STRING", V_ASN1_T61STRING), | ||
| 584 | ASN1_GEN_STR("TELETEXSTRING", V_ASN1_T61STRING), | ||
| 585 | ASN1_GEN_STR("GeneralString", V_ASN1_GENERALSTRING), | ||
| 586 | ASN1_GEN_STR("GENSTR", V_ASN1_GENERALSTRING), | ||
| 587 | |||
| 588 | /* Special cases */ | ||
| 589 | ASN1_GEN_STR("SEQUENCE", V_ASN1_SEQUENCE), | ||
| 590 | ASN1_GEN_STR("SEQ", V_ASN1_SEQUENCE), | ||
| 591 | ASN1_GEN_STR("SET", V_ASN1_SET), | ||
| 592 | /* type modifiers */ | ||
| 593 | /* Explicit tag */ | ||
| 594 | ASN1_GEN_STR("EXP", ASN1_GEN_FLAG_EXP), | ||
| 595 | ASN1_GEN_STR("EXPLICIT", ASN1_GEN_FLAG_EXP), | ||
| 596 | /* Implicit tag */ | ||
| 597 | ASN1_GEN_STR("IMP", ASN1_GEN_FLAG_IMP), | ||
| 598 | ASN1_GEN_STR("IMPLICIT", ASN1_GEN_FLAG_IMP), | ||
| 599 | /* OCTET STRING wrapper */ | ||
| 600 | ASN1_GEN_STR("OCTWRAP", ASN1_GEN_FLAG_OCTWRAP), | ||
| 601 | /* SEQUENCE wrapper */ | ||
| 602 | ASN1_GEN_STR("SEQWRAP", ASN1_GEN_FLAG_SEQWRAP), | ||
| 603 | /* SET wrapper */ | ||
| 604 | ASN1_GEN_STR("SETWRAP", ASN1_GEN_FLAG_SETWRAP), | ||
| 605 | /* BIT STRING wrapper */ | ||
| 606 | ASN1_GEN_STR("BITWRAP", ASN1_GEN_FLAG_BITWRAP), | ||
| 607 | ASN1_GEN_STR("FORM", ASN1_GEN_FLAG_FORMAT), | ||
| 608 | ASN1_GEN_STR("FORMAT", ASN1_GEN_FLAG_FORMAT), | ||
| 609 | }; | ||
| 610 | |||
| 611 | if (len == -1) | ||
| 612 | len = strlen(tagstr); | ||
| 613 | |||
| 614 | tntmp = tnst; | ||
| 615 | for (i = 0; i < sizeof(tnst) / sizeof(struct tag_name_st); i++, tntmp++) | ||
| 616 | { | ||
| 617 | if ((len == tntmp->len) && !strncmp(tntmp->strnam, tagstr, len)) | ||
| 618 | return tntmp->tag; | ||
| 619 | } | ||
| 620 | |||
| 621 | return -1; | ||
| 622 | } | ||
| 623 | |||
| 624 | static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype) | ||
| 625 | { | ||
| 626 | ASN1_TYPE *atmp = NULL; | ||
| 627 | |||
| 628 | CONF_VALUE vtmp; | ||
| 629 | |||
| 630 | unsigned char *rdata; | ||
| 631 | long rdlen; | ||
| 632 | |||
| 633 | int no_unused = 1; | ||
| 634 | |||
| 635 | if (!(atmp = ASN1_TYPE_new())) | ||
| 636 | { | ||
| 637 | ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE); | ||
| 638 | return NULL; | ||
| 639 | } | ||
| 640 | |||
| 641 | if (!str) | ||
| 642 | str = ""; | ||
| 643 | |||
| 644 | switch(utype) | ||
| 645 | { | ||
| 646 | |||
| 647 | case V_ASN1_NULL: | ||
| 648 | if (str && *str) | ||
| 649 | { | ||
| 650 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_NULL_VALUE); | ||
| 651 | goto bad_form; | ||
| 652 | } | ||
| 653 | break; | ||
| 654 | |||
| 655 | case V_ASN1_BOOLEAN: | ||
| 656 | if (format != ASN1_GEN_FORMAT_ASCII) | ||
| 657 | { | ||
| 658 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_NOT_ASCII_FORMAT); | ||
| 659 | goto bad_form; | ||
| 660 | } | ||
| 661 | vtmp.name = NULL; | ||
| 662 | vtmp.section = NULL; | ||
| 663 | vtmp.value = (char *)str; | ||
| 664 | if (!X509V3_get_value_bool(&vtmp, &atmp->value.boolean)) | ||
| 665 | { | ||
| 666 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_BOOLEAN); | ||
| 667 | goto bad_str; | ||
| 668 | } | ||
| 669 | break; | ||
| 670 | |||
| 671 | case V_ASN1_INTEGER: | ||
| 672 | case V_ASN1_ENUMERATED: | ||
| 673 | if (format != ASN1_GEN_FORMAT_ASCII) | ||
| 674 | { | ||
| 675 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_INTEGER_NOT_ASCII_FORMAT); | ||
| 676 | goto bad_form; | ||
| 677 | } | ||
| 678 | if (!(atmp->value.integer = s2i_ASN1_INTEGER(NULL, (char *)str))) | ||
| 679 | { | ||
| 680 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_INTEGER); | ||
| 681 | goto bad_str; | ||
| 682 | } | ||
| 683 | break; | ||
| 684 | |||
| 685 | case V_ASN1_OBJECT: | ||
| 686 | if (format != ASN1_GEN_FORMAT_ASCII) | ||
| 687 | { | ||
| 688 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_OBJECT_NOT_ASCII_FORMAT); | ||
| 689 | goto bad_form; | ||
| 690 | } | ||
| 691 | if (!(atmp->value.object = OBJ_txt2obj(str, 0))) | ||
| 692 | { | ||
| 693 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_OBJECT); | ||
| 694 | goto bad_str; | ||
| 695 | } | ||
| 696 | break; | ||
| 697 | |||
| 698 | case V_ASN1_UTCTIME: | ||
| 699 | case V_ASN1_GENERALIZEDTIME: | ||
| 700 | if (format != ASN1_GEN_FORMAT_ASCII) | ||
| 701 | { | ||
| 702 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_TIME_NOT_ASCII_FORMAT); | ||
| 703 | goto bad_form; | ||
| 704 | } | ||
| 705 | if (!(atmp->value.asn1_string = ASN1_STRING_new())) | ||
| 706 | { | ||
| 707 | ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE); | ||
| 708 | goto bad_str; | ||
| 709 | } | ||
| 710 | if (!ASN1_STRING_set(atmp->value.asn1_string, str, -1)) | ||
| 711 | { | ||
| 712 | ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE); | ||
| 713 | goto bad_str; | ||
| 714 | } | ||
| 715 | atmp->value.asn1_string->type = utype; | ||
| 716 | if (!ASN1_TIME_check(atmp->value.asn1_string)) | ||
| 717 | { | ||
| 718 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_TIME_VALUE); | ||
| 719 | goto bad_str; | ||
| 720 | } | ||
| 721 | |||
| 722 | break; | ||
| 723 | |||
| 724 | case V_ASN1_BMPSTRING: | ||
| 725 | case V_ASN1_PRINTABLESTRING: | ||
| 726 | case V_ASN1_IA5STRING: | ||
| 727 | case V_ASN1_T61STRING: | ||
| 728 | case V_ASN1_UTF8STRING: | ||
| 729 | case V_ASN1_VISIBLESTRING: | ||
| 730 | case V_ASN1_UNIVERSALSTRING: | ||
| 731 | case V_ASN1_GENERALSTRING: | ||
| 732 | |||
| 733 | if (format == ASN1_GEN_FORMAT_ASCII) | ||
| 734 | format = MBSTRING_ASC; | ||
| 735 | else if (format == ASN1_GEN_FORMAT_UTF8) | ||
| 736 | format = MBSTRING_UTF8; | ||
| 737 | else | ||
| 738 | { | ||
| 739 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_FORMAT); | ||
| 740 | goto bad_form; | ||
| 741 | } | ||
| 742 | |||
| 743 | |||
| 744 | if (ASN1_mbstring_copy(&atmp->value.asn1_string, (unsigned char *)str, | ||
| 745 | -1, format, ASN1_tag2bit(utype)) <= 0) | ||
| 746 | { | ||
| 747 | ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE); | ||
| 748 | goto bad_str; | ||
| 749 | } | ||
| 750 | |||
| 751 | |||
| 752 | break; | ||
| 753 | |||
| 754 | case V_ASN1_BIT_STRING: | ||
| 755 | |||
| 756 | case V_ASN1_OCTET_STRING: | ||
| 757 | |||
| 758 | if (!(atmp->value.asn1_string = ASN1_STRING_new())) | ||
| 759 | { | ||
| 760 | ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE); | ||
| 761 | goto bad_form; | ||
| 762 | } | ||
| 763 | |||
| 764 | if (format == ASN1_GEN_FORMAT_HEX) | ||
| 765 | { | ||
| 766 | |||
| 767 | if (!(rdata = string_to_hex((char *)str, &rdlen))) | ||
| 768 | { | ||
| 769 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_HEX); | ||
| 770 | goto bad_str; | ||
| 771 | } | ||
| 772 | |||
| 773 | atmp->value.asn1_string->data = rdata; | ||
| 774 | atmp->value.asn1_string->length = rdlen; | ||
| 775 | atmp->value.asn1_string->type = utype; | ||
| 776 | |||
| 777 | } | ||
| 778 | else if (format == ASN1_GEN_FORMAT_ASCII) | ||
| 779 | ASN1_STRING_set(atmp->value.asn1_string, str, -1); | ||
| 780 | else if ((format == ASN1_GEN_FORMAT_BITLIST) && (utype == V_ASN1_BIT_STRING)) | ||
| 781 | { | ||
| 782 | if (!CONF_parse_list(str, ',', 1, bitstr_cb, atmp->value.bit_string)) | ||
| 783 | { | ||
| 784 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_LIST_ERROR); | ||
| 785 | goto bad_str; | ||
| 786 | } | ||
| 787 | no_unused = 0; | ||
| 788 | |||
| 789 | } | ||
| 790 | else | ||
| 791 | { | ||
| 792 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_BITSTRING_FORMAT); | ||
| 793 | goto bad_form; | ||
| 794 | } | ||
| 795 | |||
| 796 | if ((utype == V_ASN1_BIT_STRING) && no_unused) | ||
| 797 | { | ||
| 798 | atmp->value.asn1_string->flags | ||
| 799 | &= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); | ||
| 800 | atmp->value.asn1_string->flags | ||
| 801 | |= ASN1_STRING_FLAG_BITS_LEFT; | ||
| 802 | } | ||
| 803 | |||
| 804 | |||
| 805 | break; | ||
| 806 | |||
| 807 | default: | ||
| 808 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_UNSUPPORTED_TYPE); | ||
| 809 | goto bad_str; | ||
| 810 | break; | ||
| 811 | } | ||
| 812 | |||
| 813 | |||
| 814 | atmp->type = utype; | ||
| 815 | return atmp; | ||
| 816 | |||
| 817 | |||
| 818 | bad_str: | ||
| 819 | ERR_add_error_data(2, "string=", str); | ||
| 820 | bad_form: | ||
| 821 | |||
| 822 | ASN1_TYPE_free(atmp); | ||
| 823 | return NULL; | ||
| 824 | |||
| 825 | } | ||
| 826 | |||
| 827 | static int bitstr_cb(const char *elem, int len, void *bitstr) | ||
| 828 | { | ||
| 829 | long bitnum; | ||
| 830 | char *eptr; | ||
| 831 | if (!elem) | ||
| 832 | return 0; | ||
| 833 | bitnum = strtoul(elem, &eptr, 10); | ||
| 834 | if (eptr && *eptr && (eptr != elem + len)) | ||
| 835 | return 0; | ||
| 836 | if (bitnum < 0) | ||
| 837 | { | ||
| 838 | ASN1err(ASN1_F_BITSTR_CB, ASN1_R_INVALID_NUMBER); | ||
| 839 | return 0; | ||
| 840 | } | ||
| 841 | if (!ASN1_BIT_STRING_set_bit(bitstr, bitnum, 1)) | ||
| 842 | { | ||
| 843 | ASN1err(ASN1_F_BITSTR_CB, ERR_R_MALLOC_FAILURE); | ||
| 844 | return 0; | ||
| 845 | } | ||
| 846 | return 1; | ||
| 847 | } | ||
| 848 | |||
diff --git a/src/lib/libcrypto/asn1/asn1_lib.c b/src/lib/libcrypto/asn1/asn1_lib.c new file mode 100644 index 0000000000..5af559ef8d --- /dev/null +++ b/src/lib/libcrypto/asn1/asn1_lib.c | |||
| @@ -0,0 +1,470 @@ | |||
| 1 | /* crypto/asn1/asn1_lib.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include <limits.h> | ||
| 61 | #include "cryptlib.h" | ||
| 62 | #include <openssl/asn1.h> | ||
| 63 | #include <openssl/asn1_mac.h> | ||
| 64 | |||
| 65 | static int asn1_get_length(const unsigned char **pp,int *inf,long *rl,int max); | ||
| 66 | static void asn1_put_length(unsigned char **pp, int length); | ||
| 67 | const char ASN1_version[]="ASN.1" OPENSSL_VERSION_PTEXT; | ||
| 68 | |||
| 69 | static int _asn1_check_infinite_end(const unsigned char **p, long len) | ||
| 70 | { | ||
| 71 | /* If there is 0 or 1 byte left, the length check should pick | ||
| 72 | * things up */ | ||
| 73 | if (len <= 0) | ||
| 74 | return(1); | ||
| 75 | else if ((len >= 2) && ((*p)[0] == 0) && ((*p)[1] == 0)) | ||
| 76 | { | ||
| 77 | (*p)+=2; | ||
| 78 | return(1); | ||
| 79 | } | ||
| 80 | return(0); | ||
| 81 | } | ||
| 82 | |||
| 83 | int ASN1_check_infinite_end(unsigned char **p, long len) | ||
| 84 | { | ||
| 85 | return _asn1_check_infinite_end((const unsigned char **)p, len); | ||
| 86 | } | ||
| 87 | |||
| 88 | int ASN1_const_check_infinite_end(const unsigned char **p, long len) | ||
| 89 | { | ||
| 90 | return _asn1_check_infinite_end(p, len); | ||
| 91 | } | ||
| 92 | |||
| 93 | |||
| 94 | int ASN1_get_object(const unsigned char **pp, long *plength, int *ptag, | ||
| 95 | int *pclass, long omax) | ||
| 96 | { | ||
| 97 | int i,ret; | ||
| 98 | long l; | ||
| 99 | const unsigned char *p= *pp; | ||
| 100 | int tag,xclass,inf; | ||
| 101 | long max=omax; | ||
| 102 | |||
| 103 | if (!max) goto err; | ||
| 104 | ret=(*p&V_ASN1_CONSTRUCTED); | ||
| 105 | xclass=(*p&V_ASN1_PRIVATE); | ||
| 106 | i= *p&V_ASN1_PRIMITIVE_TAG; | ||
| 107 | if (i == V_ASN1_PRIMITIVE_TAG) | ||
| 108 | { /* high-tag */ | ||
| 109 | p++; | ||
| 110 | if (--max == 0) goto err; | ||
| 111 | l=0; | ||
| 112 | while (*p&0x80) | ||
| 113 | { | ||
| 114 | l<<=7L; | ||
| 115 | l|= *(p++)&0x7f; | ||
| 116 | if (--max == 0) goto err; | ||
| 117 | if (l > (INT_MAX >> 7L)) goto err; | ||
| 118 | } | ||
| 119 | l<<=7L; | ||
| 120 | l|= *(p++)&0x7f; | ||
| 121 | tag=(int)l; | ||
| 122 | if (--max == 0) goto err; | ||
| 123 | } | ||
| 124 | else | ||
| 125 | { | ||
| 126 | tag=i; | ||
| 127 | p++; | ||
| 128 | if (--max == 0) goto err; | ||
| 129 | } | ||
| 130 | *ptag=tag; | ||
| 131 | *pclass=xclass; | ||
| 132 | if (!asn1_get_length(&p,&inf,plength,(int)max)) goto err; | ||
| 133 | |||
| 134 | #if 0 | ||
| 135 | fprintf(stderr,"p=%d + *plength=%ld > omax=%ld + *pp=%d (%d > %d)\n", | ||
| 136 | (int)p,*plength,omax,(int)*pp,(int)(p+ *plength), | ||
| 137 | (int)(omax+ *pp)); | ||
| 138 | |||
| 139 | #endif | ||
| 140 | if (*plength > (omax - (p - *pp))) | ||
| 141 | { | ||
| 142 | ASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_TOO_LONG); | ||
| 143 | /* Set this so that even if things are not long enough | ||
| 144 | * the values are set correctly */ | ||
| 145 | ret|=0x80; | ||
| 146 | } | ||
| 147 | *pp=p; | ||
| 148 | return(ret|inf); | ||
| 149 | err: | ||
| 150 | ASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_HEADER_TOO_LONG); | ||
| 151 | return(0x80); | ||
| 152 | } | ||
| 153 | |||
| 154 | static int asn1_get_length(const unsigned char **pp, int *inf, long *rl, int max) | ||
| 155 | { | ||
| 156 | const unsigned char *p= *pp; | ||
| 157 | unsigned long ret=0; | ||
| 158 | unsigned int i; | ||
| 159 | |||
| 160 | if (max-- < 1) return(0); | ||
| 161 | if (*p == 0x80) | ||
| 162 | { | ||
| 163 | *inf=1; | ||
| 164 | ret=0; | ||
| 165 | p++; | ||
| 166 | } | ||
| 167 | else | ||
| 168 | { | ||
| 169 | *inf=0; | ||
| 170 | i= *p&0x7f; | ||
| 171 | if (*(p++) & 0x80) | ||
| 172 | { | ||
| 173 | if (i > sizeof(long)) | ||
| 174 | return 0; | ||
| 175 | if (max-- == 0) return(0); | ||
| 176 | while (i-- > 0) | ||
| 177 | { | ||
| 178 | ret<<=8L; | ||
| 179 | ret|= *(p++); | ||
| 180 | if (max-- == 0) return(0); | ||
| 181 | } | ||
| 182 | } | ||
| 183 | else | ||
| 184 | ret=i; | ||
| 185 | } | ||
| 186 | if (ret > LONG_MAX) | ||
| 187 | return 0; | ||
| 188 | *pp=p; | ||
| 189 | *rl=(long)ret; | ||
| 190 | return(1); | ||
| 191 | } | ||
| 192 | |||
| 193 | /* class 0 is constructed | ||
| 194 | * constructed == 2 for indefinite length constructed */ | ||
| 195 | void ASN1_put_object(unsigned char **pp, int constructed, int length, int tag, | ||
| 196 | int xclass) | ||
| 197 | { | ||
| 198 | unsigned char *p= *pp; | ||
| 199 | int i, ttag; | ||
| 200 | |||
| 201 | i=(constructed)?V_ASN1_CONSTRUCTED:0; | ||
| 202 | i|=(xclass&V_ASN1_PRIVATE); | ||
| 203 | if (tag < 31) | ||
| 204 | *(p++)=i|(tag&V_ASN1_PRIMITIVE_TAG); | ||
| 205 | else | ||
| 206 | { | ||
| 207 | *(p++)=i|V_ASN1_PRIMITIVE_TAG; | ||
| 208 | for(i = 0, ttag = tag; ttag > 0; i++) ttag >>=7; | ||
| 209 | ttag = i; | ||
| 210 | while(i-- > 0) | ||
| 211 | { | ||
| 212 | p[i] = tag & 0x7f; | ||
| 213 | if(i != (ttag - 1)) p[i] |= 0x80; | ||
| 214 | tag >>= 7; | ||
| 215 | } | ||
| 216 | p += ttag; | ||
| 217 | } | ||
| 218 | if (constructed == 2) | ||
| 219 | *(p++)=0x80; | ||
| 220 | else | ||
| 221 | asn1_put_length(&p,length); | ||
| 222 | *pp=p; | ||
| 223 | } | ||
| 224 | |||
| 225 | int ASN1_put_eoc(unsigned char **pp) | ||
| 226 | { | ||
| 227 | unsigned char *p = *pp; | ||
| 228 | *p++ = 0; | ||
| 229 | *p++ = 0; | ||
| 230 | *pp = p; | ||
| 231 | return 2; | ||
| 232 | } | ||
| 233 | |||
| 234 | static void asn1_put_length(unsigned char **pp, int length) | ||
| 235 | { | ||
| 236 | unsigned char *p= *pp; | ||
| 237 | int i,l; | ||
| 238 | if (length <= 127) | ||
| 239 | *(p++)=(unsigned char)length; | ||
| 240 | else | ||
| 241 | { | ||
| 242 | l=length; | ||
| 243 | for (i=0; l > 0; i++) | ||
| 244 | l>>=8; | ||
| 245 | *(p++)=i|0x80; | ||
| 246 | l=i; | ||
| 247 | while (i-- > 0) | ||
| 248 | { | ||
| 249 | p[i]=length&0xff; | ||
| 250 | length>>=8; | ||
| 251 | } | ||
| 252 | p+=l; | ||
| 253 | } | ||
| 254 | *pp=p; | ||
| 255 | } | ||
| 256 | |||
| 257 | int ASN1_object_size(int constructed, int length, int tag) | ||
| 258 | { | ||
| 259 | int ret; | ||
| 260 | |||
| 261 | ret=length; | ||
| 262 | ret++; | ||
| 263 | if (tag >= 31) | ||
| 264 | { | ||
| 265 | while (tag > 0) | ||
| 266 | { | ||
| 267 | tag>>=7; | ||
| 268 | ret++; | ||
| 269 | } | ||
| 270 | } | ||
| 271 | if (constructed == 2) | ||
| 272 | return ret + 3; | ||
| 273 | ret++; | ||
| 274 | if (length > 127) | ||
| 275 | { | ||
| 276 | while (length > 0) | ||
| 277 | { | ||
| 278 | length>>=8; | ||
| 279 | ret++; | ||
| 280 | } | ||
| 281 | } | ||
| 282 | return(ret); | ||
| 283 | } | ||
| 284 | |||
| 285 | static int _asn1_Finish(ASN1_const_CTX *c) | ||
| 286 | { | ||
| 287 | if ((c->inf == (1|V_ASN1_CONSTRUCTED)) && (!c->eos)) | ||
| 288 | { | ||
| 289 | if (!ASN1_const_check_infinite_end(&c->p,c->slen)) | ||
| 290 | { | ||
| 291 | c->error=ERR_R_MISSING_ASN1_EOS; | ||
| 292 | return(0); | ||
| 293 | } | ||
| 294 | } | ||
| 295 | if ( ((c->slen != 0) && !(c->inf & 1)) || | ||
| 296 | ((c->slen < 0) && (c->inf & 1))) | ||
| 297 | { | ||
| 298 | c->error=ERR_R_ASN1_LENGTH_MISMATCH; | ||
| 299 | return(0); | ||
| 300 | } | ||
| 301 | return(1); | ||
| 302 | } | ||
| 303 | |||
| 304 | int asn1_Finish(ASN1_CTX *c) | ||
| 305 | { | ||
| 306 | return _asn1_Finish((ASN1_const_CTX *)c); | ||
| 307 | } | ||
| 308 | |||
| 309 | int asn1_const_Finish(ASN1_const_CTX *c) | ||
| 310 | { | ||
| 311 | return _asn1_Finish(c); | ||
| 312 | } | ||
| 313 | |||
| 314 | int asn1_GetSequence(ASN1_const_CTX *c, long *length) | ||
| 315 | { | ||
| 316 | const unsigned char *q; | ||
| 317 | |||
| 318 | q=c->p; | ||
| 319 | c->inf=ASN1_get_object(&(c->p),&(c->slen),&(c->tag),&(c->xclass), | ||
| 320 | *length); | ||
| 321 | if (c->inf & 0x80) | ||
| 322 | { | ||
| 323 | c->error=ERR_R_BAD_GET_ASN1_OBJECT_CALL; | ||
| 324 | return(0); | ||
| 325 | } | ||
| 326 | if (c->tag != V_ASN1_SEQUENCE) | ||
| 327 | { | ||
| 328 | c->error=ERR_R_EXPECTING_AN_ASN1_SEQUENCE; | ||
| 329 | return(0); | ||
| 330 | } | ||
| 331 | (*length)-=(c->p-q); | ||
| 332 | if (c->max && (*length < 0)) | ||
| 333 | { | ||
| 334 | c->error=ERR_R_ASN1_LENGTH_MISMATCH; | ||
| 335 | return(0); | ||
| 336 | } | ||
| 337 | if (c->inf == (1|V_ASN1_CONSTRUCTED)) | ||
| 338 | c->slen= *length+ *(c->pp)-c->p; | ||
| 339 | c->eos=0; | ||
| 340 | return(1); | ||
| 341 | } | ||
| 342 | |||
| 343 | ASN1_STRING *ASN1_STRING_dup(ASN1_STRING *str) | ||
| 344 | { | ||
| 345 | ASN1_STRING *ret; | ||
| 346 | |||
| 347 | if (str == NULL) return(NULL); | ||
| 348 | if ((ret=ASN1_STRING_type_new(str->type)) == NULL) | ||
| 349 | return(NULL); | ||
| 350 | if (!ASN1_STRING_set(ret,str->data,str->length)) | ||
| 351 | { | ||
| 352 | ASN1_STRING_free(ret); | ||
| 353 | return(NULL); | ||
| 354 | } | ||
| 355 | ret->flags = str->flags; | ||
| 356 | return(ret); | ||
| 357 | } | ||
| 358 | |||
| 359 | int ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len) | ||
| 360 | { | ||
| 361 | unsigned char *c; | ||
| 362 | const char *data=_data; | ||
| 363 | |||
| 364 | if (len < 0) | ||
| 365 | { | ||
| 366 | if (data == NULL) | ||
| 367 | return(0); | ||
| 368 | else | ||
| 369 | len=strlen(data); | ||
| 370 | } | ||
| 371 | if ((str->length < len) || (str->data == NULL)) | ||
| 372 | { | ||
| 373 | c=str->data; | ||
| 374 | if (c == NULL) | ||
| 375 | str->data=OPENSSL_malloc(len+1); | ||
| 376 | else | ||
| 377 | str->data=OPENSSL_realloc(c,len+1); | ||
| 378 | |||
| 379 | if (str->data == NULL) | ||
| 380 | { | ||
| 381 | ASN1err(ASN1_F_ASN1_STRING_SET,ERR_R_MALLOC_FAILURE); | ||
| 382 | str->data=c; | ||
| 383 | return(0); | ||
| 384 | } | ||
| 385 | } | ||
| 386 | str->length=len; | ||
| 387 | if (data != NULL) | ||
| 388 | { | ||
| 389 | memcpy(str->data,data,len); | ||
| 390 | /* an allowance for strings :-) */ | ||
| 391 | str->data[len]='\0'; | ||
| 392 | } | ||
| 393 | return(1); | ||
| 394 | } | ||
| 395 | |||
| 396 | void ASN1_STRING_set0(ASN1_STRING *str, void *data, int len) | ||
| 397 | { | ||
| 398 | if (str->data) | ||
| 399 | OPENSSL_free(str->data); | ||
| 400 | str->data = data; | ||
| 401 | str->length = len; | ||
| 402 | } | ||
| 403 | |||
| 404 | ASN1_STRING *ASN1_STRING_new(void) | ||
| 405 | { | ||
| 406 | return(ASN1_STRING_type_new(V_ASN1_OCTET_STRING)); | ||
| 407 | } | ||
| 408 | |||
| 409 | |||
| 410 | ASN1_STRING *ASN1_STRING_type_new(int type) | ||
| 411 | { | ||
| 412 | ASN1_STRING *ret; | ||
| 413 | |||
| 414 | ret=(ASN1_STRING *)OPENSSL_malloc(sizeof(ASN1_STRING)); | ||
| 415 | if (ret == NULL) | ||
| 416 | { | ||
| 417 | ASN1err(ASN1_F_ASN1_STRING_TYPE_NEW,ERR_R_MALLOC_FAILURE); | ||
| 418 | return(NULL); | ||
| 419 | } | ||
| 420 | ret->length=0; | ||
| 421 | ret->type=type; | ||
| 422 | ret->data=NULL; | ||
| 423 | ret->flags=0; | ||
| 424 | return(ret); | ||
| 425 | } | ||
| 426 | |||
| 427 | void ASN1_STRING_free(ASN1_STRING *a) | ||
| 428 | { | ||
| 429 | if (a == NULL) return; | ||
| 430 | if (a->data != NULL) OPENSSL_free(a->data); | ||
| 431 | OPENSSL_free(a); | ||
| 432 | } | ||
| 433 | |||
| 434 | int ASN1_STRING_cmp(ASN1_STRING *a, ASN1_STRING *b) | ||
| 435 | { | ||
| 436 | int i; | ||
| 437 | |||
| 438 | i=(a->length-b->length); | ||
| 439 | if (i == 0) | ||
| 440 | { | ||
| 441 | i=memcmp(a->data,b->data,a->length); | ||
| 442 | if (i == 0) | ||
| 443 | return(a->type-b->type); | ||
| 444 | else | ||
| 445 | return(i); | ||
| 446 | } | ||
| 447 | else | ||
| 448 | return(i); | ||
| 449 | } | ||
| 450 | |||
| 451 | void asn1_add_error(const unsigned char *address, int offset) | ||
| 452 | { | ||
| 453 | char buf1[DECIMAL_SIZE(address)+1],buf2[DECIMAL_SIZE(offset)+1]; | ||
| 454 | |||
| 455 | BIO_snprintf(buf1,sizeof buf1,"%lu",(unsigned long)address); | ||
| 456 | BIO_snprintf(buf2,sizeof buf2,"%d",offset); | ||
| 457 | ERR_add_error_data(4,"address=",buf1," offset=",buf2); | ||
| 458 | } | ||
| 459 | |||
| 460 | int ASN1_STRING_length(ASN1_STRING *x) | ||
| 461 | { return M_ASN1_STRING_length(x); } | ||
| 462 | |||
| 463 | void ASN1_STRING_length_set(ASN1_STRING *x, int len) | ||
| 464 | { M_ASN1_STRING_length_set(x, len); return; } | ||
| 465 | |||
| 466 | int ASN1_STRING_type(ASN1_STRING *x) | ||
| 467 | { return M_ASN1_STRING_type(x); } | ||
| 468 | |||
| 469 | unsigned char * ASN1_STRING_data(ASN1_STRING *x) | ||
| 470 | { return M_ASN1_STRING_data(x); } | ||
diff --git a/src/lib/libcrypto/asn1/asn1_mac.h b/src/lib/libcrypto/asn1/asn1_mac.h new file mode 100644 index 0000000000..d958ca60d9 --- /dev/null +++ b/src/lib/libcrypto/asn1/asn1_mac.h | |||
| @@ -0,0 +1,571 @@ | |||
| 1 | /* crypto/asn1/asn1_mac.h */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #ifndef HEADER_ASN1_MAC_H | ||
| 60 | #define HEADER_ASN1_MAC_H | ||
| 61 | |||
| 62 | #include <openssl/asn1.h> | ||
| 63 | |||
| 64 | #ifdef __cplusplus | ||
| 65 | extern "C" { | ||
| 66 | #endif | ||
| 67 | |||
| 68 | #ifndef ASN1_MAC_ERR_LIB | ||
| 69 | #define ASN1_MAC_ERR_LIB ERR_LIB_ASN1 | ||
| 70 | #endif | ||
| 71 | |||
| 72 | #define ASN1_MAC_H_err(f,r,line) \ | ||
| 73 | ERR_PUT_error(ASN1_MAC_ERR_LIB,(f),(r),__FILE__,(line)) | ||
| 74 | |||
| 75 | #define M_ASN1_D2I_vars(a,type,func) \ | ||
| 76 | ASN1_const_CTX c; \ | ||
| 77 | type ret=NULL; \ | ||
| 78 | \ | ||
| 79 | c.pp=(const unsigned char **)pp; \ | ||
| 80 | c.q= *(const unsigned char **)pp; \ | ||
| 81 | c.error=ERR_R_NESTED_ASN1_ERROR; \ | ||
| 82 | if ((a == NULL) || ((*a) == NULL)) \ | ||
| 83 | { if ((ret=(type)func()) == NULL) \ | ||
| 84 | { c.line=__LINE__; goto err; } } \ | ||
| 85 | else ret=(*a); | ||
| 86 | |||
| 87 | #define M_ASN1_D2I_Init() \ | ||
| 88 | c.p= *(const unsigned char **)pp; \ | ||
| 89 | c.max=(length == 0)?0:(c.p+length); | ||
| 90 | |||
| 91 | #define M_ASN1_D2I_Finish_2(a) \ | ||
| 92 | if (!asn1_const_Finish(&c)) \ | ||
| 93 | { c.line=__LINE__; goto err; } \ | ||
| 94 | *(const unsigned char **)pp=c.p; \ | ||
| 95 | if (a != NULL) (*a)=ret; \ | ||
| 96 | return(ret); | ||
| 97 | |||
| 98 | #define M_ASN1_D2I_Finish(a,func,e) \ | ||
| 99 | M_ASN1_D2I_Finish_2(a); \ | ||
| 100 | err:\ | ||
| 101 | ASN1_MAC_H_err((e),c.error,c.line); \ | ||
| 102 | asn1_add_error(*(const unsigned char **)pp,(int)(c.q- *pp)); \ | ||
| 103 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) func(ret); \ | ||
| 104 | return(NULL) | ||
| 105 | |||
| 106 | #define M_ASN1_D2I_start_sequence() \ | ||
| 107 | if (!asn1_GetSequence(&c,&length)) \ | ||
| 108 | { c.line=__LINE__; goto err; } | ||
| 109 | /* Begin reading ASN1 without a surrounding sequence */ | ||
| 110 | #define M_ASN1_D2I_begin() \ | ||
| 111 | c.slen = length; | ||
| 112 | |||
| 113 | /* End reading ASN1 with no check on length */ | ||
| 114 | #define M_ASN1_D2I_Finish_nolen(a, func, e) \ | ||
| 115 | *pp=c.p; \ | ||
| 116 | if (a != NULL) (*a)=ret; \ | ||
| 117 | return(ret); \ | ||
| 118 | err:\ | ||
| 119 | ASN1_MAC_H_err((e),c.error,c.line); \ | ||
| 120 | asn1_add_error(*pp,(int)(c.q- *pp)); \ | ||
| 121 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) func(ret); \ | ||
| 122 | return(NULL) | ||
| 123 | |||
| 124 | #define M_ASN1_D2I_end_sequence() \ | ||
| 125 | (((c.inf&1) == 0)?(c.slen <= 0): \ | ||
| 126 | (c.eos=ASN1_const_check_infinite_end(&c.p,c.slen))) | ||
| 127 | |||
| 128 | /* Don't use this with d2i_ASN1_BOOLEAN() */ | ||
| 129 | #define M_ASN1_D2I_get(b, func) \ | ||
| 130 | c.q=c.p; \ | ||
| 131 | if (func(&(b),&c.p,c.slen) == NULL) \ | ||
| 132 | {c.line=__LINE__; goto err; } \ | ||
| 133 | c.slen-=(c.p-c.q); | ||
| 134 | |||
| 135 | /* Don't use this with d2i_ASN1_BOOLEAN() */ | ||
| 136 | #define M_ASN1_D2I_get_x(type,b,func) \ | ||
| 137 | c.q=c.p; \ | ||
| 138 | if (((D2I_OF(type))func)(&(b),&c.p,c.slen) == NULL) \ | ||
| 139 | {c.line=__LINE__; goto err; } \ | ||
| 140 | c.slen-=(c.p-c.q); | ||
| 141 | |||
| 142 | /* use this instead () */ | ||
| 143 | #define M_ASN1_D2I_get_int(b,func) \ | ||
| 144 | c.q=c.p; \ | ||
| 145 | if (func(&(b),&c.p,c.slen) < 0) \ | ||
| 146 | {c.line=__LINE__; goto err; } \ | ||
| 147 | c.slen-=(c.p-c.q); | ||
| 148 | |||
| 149 | #define M_ASN1_D2I_get_opt(b,func,type) \ | ||
| 150 | if ((c.slen != 0) && ((M_ASN1_next & (~V_ASN1_CONSTRUCTED)) \ | ||
| 151 | == (V_ASN1_UNIVERSAL|(type)))) \ | ||
| 152 | { \ | ||
| 153 | M_ASN1_D2I_get(b,func); \ | ||
| 154 | } | ||
| 155 | |||
| 156 | #define M_ASN1_D2I_get_imp(b,func, type) \ | ||
| 157 | M_ASN1_next=(_tmp& V_ASN1_CONSTRUCTED)|type; \ | ||
| 158 | c.q=c.p; \ | ||
| 159 | if (func(&(b),&c.p,c.slen) == NULL) \ | ||
| 160 | {c.line=__LINE__; M_ASN1_next_prev = _tmp; goto err; } \ | ||
| 161 | c.slen-=(c.p-c.q);\ | ||
| 162 | M_ASN1_next_prev=_tmp; | ||
| 163 | |||
| 164 | #define M_ASN1_D2I_get_IMP_opt(b,func,tag,type) \ | ||
| 165 | if ((c.slen != 0) && ((M_ASN1_next & (~V_ASN1_CONSTRUCTED)) == \ | ||
| 166 | (V_ASN1_CONTEXT_SPECIFIC|(tag)))) \ | ||
| 167 | { \ | ||
| 168 | unsigned char _tmp = M_ASN1_next; \ | ||
| 169 | M_ASN1_D2I_get_imp(b,func, type);\ | ||
| 170 | } | ||
| 171 | |||
| 172 | #define M_ASN1_D2I_get_set(r,func,free_func) \ | ||
| 173 | M_ASN1_D2I_get_imp_set(r,func,free_func, \ | ||
| 174 | V_ASN1_SET,V_ASN1_UNIVERSAL); | ||
| 175 | |||
| 176 | #define M_ASN1_D2I_get_set_type(type,r,func,free_func) \ | ||
| 177 | M_ASN1_D2I_get_imp_set_type(type,r,func,free_func, \ | ||
| 178 | V_ASN1_SET,V_ASN1_UNIVERSAL); | ||
| 179 | |||
| 180 | #define M_ASN1_D2I_get_set_opt(r,func,free_func) \ | ||
| 181 | if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \ | ||
| 182 | V_ASN1_CONSTRUCTED|V_ASN1_SET)))\ | ||
| 183 | { M_ASN1_D2I_get_set(r,func,free_func); } | ||
| 184 | |||
| 185 | #define M_ASN1_D2I_get_set_opt_type(type,r,func,free_func) \ | ||
| 186 | if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \ | ||
| 187 | V_ASN1_CONSTRUCTED|V_ASN1_SET)))\ | ||
| 188 | { M_ASN1_D2I_get_set_type(type,r,func,free_func); } | ||
| 189 | |||
| 190 | #define M_ASN1_I2D_len_SET_opt(a,f) \ | ||
| 191 | if ((a != NULL) && (sk_num(a) != 0)) \ | ||
| 192 | M_ASN1_I2D_len_SET(a,f); | ||
| 193 | |||
| 194 | #define M_ASN1_I2D_put_SET_opt(a,f) \ | ||
| 195 | if ((a != NULL) && (sk_num(a) != 0)) \ | ||
| 196 | M_ASN1_I2D_put_SET(a,f); | ||
| 197 | |||
| 198 | #define M_ASN1_I2D_put_SEQUENCE_opt(a,f) \ | ||
| 199 | if ((a != NULL) && (sk_num(a) != 0)) \ | ||
| 200 | M_ASN1_I2D_put_SEQUENCE(a,f); | ||
| 201 | |||
| 202 | #define M_ASN1_I2D_put_SEQUENCE_opt_type(type,a,f) \ | ||
| 203 | if ((a != NULL) && (sk_##type##_num(a) != 0)) \ | ||
| 204 | M_ASN1_I2D_put_SEQUENCE_type(type,a,f); | ||
| 205 | |||
| 206 | #define M_ASN1_D2I_get_IMP_set_opt(b,func,free_func,tag) \ | ||
| 207 | if ((c.slen != 0) && \ | ||
| 208 | (M_ASN1_next == \ | ||
| 209 | (V_ASN1_CONTEXT_SPECIFIC|V_ASN1_CONSTRUCTED|(tag))))\ | ||
| 210 | { \ | ||
| 211 | M_ASN1_D2I_get_imp_set(b,func,free_func,\ | ||
| 212 | tag,V_ASN1_CONTEXT_SPECIFIC); \ | ||
| 213 | } | ||
| 214 | |||
| 215 | #define M_ASN1_D2I_get_IMP_set_opt_type(type,b,func,free_func,tag) \ | ||
| 216 | if ((c.slen != 0) && \ | ||
| 217 | (M_ASN1_next == \ | ||
| 218 | (V_ASN1_CONTEXT_SPECIFIC|V_ASN1_CONSTRUCTED|(tag))))\ | ||
| 219 | { \ | ||
| 220 | M_ASN1_D2I_get_imp_set_type(type,b,func,free_func,\ | ||
| 221 | tag,V_ASN1_CONTEXT_SPECIFIC); \ | ||
| 222 | } | ||
| 223 | |||
| 224 | #define M_ASN1_D2I_get_seq(r,func,free_func) \ | ||
| 225 | M_ASN1_D2I_get_imp_set(r,func,free_func,\ | ||
| 226 | V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL); | ||
| 227 | |||
| 228 | #define M_ASN1_D2I_get_seq_type(type,r,func,free_func) \ | ||
| 229 | M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,\ | ||
| 230 | V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL) | ||
| 231 | |||
| 232 | #define M_ASN1_D2I_get_seq_opt(r,func,free_func) \ | ||
| 233 | if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \ | ||
| 234 | V_ASN1_CONSTRUCTED|V_ASN1_SEQUENCE)))\ | ||
| 235 | { M_ASN1_D2I_get_seq(r,func,free_func); } | ||
| 236 | |||
| 237 | #define M_ASN1_D2I_get_seq_opt_type(type,r,func,free_func) \ | ||
| 238 | if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \ | ||
| 239 | V_ASN1_CONSTRUCTED|V_ASN1_SEQUENCE)))\ | ||
| 240 | { M_ASN1_D2I_get_seq_type(type,r,func,free_func); } | ||
| 241 | |||
| 242 | #define M_ASN1_D2I_get_IMP_set(r,func,free_func,x) \ | ||
| 243 | M_ASN1_D2I_get_imp_set(r,func,free_func,\ | ||
| 244 | x,V_ASN1_CONTEXT_SPECIFIC); | ||
| 245 | |||
| 246 | #define M_ASN1_D2I_get_IMP_set_type(type,r,func,free_func,x) \ | ||
| 247 | M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,\ | ||
| 248 | x,V_ASN1_CONTEXT_SPECIFIC); | ||
| 249 | |||
| 250 | #define M_ASN1_D2I_get_imp_set(r,func,free_func,a,b) \ | ||
| 251 | c.q=c.p; \ | ||
| 252 | if (d2i_ASN1_SET(&(r),&c.p,c.slen,(char *(*)())func,\ | ||
| 253 | (void (*)())free_func,a,b) == NULL) \ | ||
| 254 | { c.line=__LINE__; goto err; } \ | ||
| 255 | c.slen-=(c.p-c.q); | ||
| 256 | |||
| 257 | #define M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,a,b) \ | ||
| 258 | c.q=c.p; \ | ||
| 259 | if (d2i_ASN1_SET_OF_##type(&(r),&c.p,c.slen,func,\ | ||
| 260 | free_func,a,b) == NULL) \ | ||
| 261 | { c.line=__LINE__; goto err; } \ | ||
| 262 | c.slen-=(c.p-c.q); | ||
| 263 | |||
| 264 | #define M_ASN1_D2I_get_set_strings(r,func,a,b) \ | ||
| 265 | c.q=c.p; \ | ||
| 266 | if (d2i_ASN1_STRING_SET(&(r),&c.p,c.slen,a,b) == NULL) \ | ||
| 267 | { c.line=__LINE__; goto err; } \ | ||
| 268 | c.slen-=(c.p-c.q); | ||
| 269 | |||
| 270 | #define M_ASN1_D2I_get_EXP_opt(r,func,tag) \ | ||
| 271 | if ((c.slen != 0L) && (M_ASN1_next == \ | ||
| 272 | (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \ | ||
| 273 | { \ | ||
| 274 | int Tinf,Ttag,Tclass; \ | ||
| 275 | long Tlen; \ | ||
| 276 | \ | ||
| 277 | c.q=c.p; \ | ||
| 278 | Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \ | ||
| 279 | if (Tinf & 0x80) \ | ||
| 280 | { c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \ | ||
| 281 | c.line=__LINE__; goto err; } \ | ||
| 282 | if (Tinf == (V_ASN1_CONSTRUCTED+1)) \ | ||
| 283 | Tlen = c.slen - (c.p - c.q) - 2; \ | ||
| 284 | if (func(&(r),&c.p,Tlen) == NULL) \ | ||
| 285 | { c.line=__LINE__; goto err; } \ | ||
| 286 | if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \ | ||
| 287 | Tlen = c.slen - (c.p - c.q); \ | ||
| 288 | if(!ASN1_const_check_infinite_end(&c.p, Tlen)) \ | ||
| 289 | { c.error=ERR_R_MISSING_ASN1_EOS; \ | ||
| 290 | c.line=__LINE__; goto err; } \ | ||
| 291 | }\ | ||
| 292 | c.slen-=(c.p-c.q); \ | ||
| 293 | } | ||
| 294 | |||
| 295 | #define M_ASN1_D2I_get_EXP_set_opt(r,func,free_func,tag,b) \ | ||
| 296 | if ((c.slen != 0) && (M_ASN1_next == \ | ||
| 297 | (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \ | ||
| 298 | { \ | ||
| 299 | int Tinf,Ttag,Tclass; \ | ||
| 300 | long Tlen; \ | ||
| 301 | \ | ||
| 302 | c.q=c.p; \ | ||
| 303 | Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \ | ||
| 304 | if (Tinf & 0x80) \ | ||
| 305 | { c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \ | ||
| 306 | c.line=__LINE__; goto err; } \ | ||
| 307 | if (Tinf == (V_ASN1_CONSTRUCTED+1)) \ | ||
| 308 | Tlen = c.slen - (c.p - c.q) - 2; \ | ||
| 309 | if (d2i_ASN1_SET(&(r),&c.p,Tlen,(char *(*)())func, \ | ||
| 310 | (void (*)())free_func, \ | ||
| 311 | b,V_ASN1_UNIVERSAL) == NULL) \ | ||
| 312 | { c.line=__LINE__; goto err; } \ | ||
| 313 | if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \ | ||
| 314 | Tlen = c.slen - (c.p - c.q); \ | ||
| 315 | if(!ASN1_check_infinite_end(&c.p, Tlen)) \ | ||
| 316 | { c.error=ERR_R_MISSING_ASN1_EOS; \ | ||
| 317 | c.line=__LINE__; goto err; } \ | ||
| 318 | }\ | ||
| 319 | c.slen-=(c.p-c.q); \ | ||
| 320 | } | ||
| 321 | |||
| 322 | #define M_ASN1_D2I_get_EXP_set_opt_type(type,r,func,free_func,tag,b) \ | ||
| 323 | if ((c.slen != 0) && (M_ASN1_next == \ | ||
| 324 | (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \ | ||
| 325 | { \ | ||
| 326 | int Tinf,Ttag,Tclass; \ | ||
| 327 | long Tlen; \ | ||
| 328 | \ | ||
| 329 | c.q=c.p; \ | ||
| 330 | Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \ | ||
| 331 | if (Tinf & 0x80) \ | ||
| 332 | { c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \ | ||
| 333 | c.line=__LINE__; goto err; } \ | ||
| 334 | if (Tinf == (V_ASN1_CONSTRUCTED+1)) \ | ||
| 335 | Tlen = c.slen - (c.p - c.q) - 2; \ | ||
| 336 | if (d2i_ASN1_SET_OF_##type(&(r),&c.p,Tlen,func, \ | ||
| 337 | free_func,b,V_ASN1_UNIVERSAL) == NULL) \ | ||
| 338 | { c.line=__LINE__; goto err; } \ | ||
| 339 | if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \ | ||
| 340 | Tlen = c.slen - (c.p - c.q); \ | ||
| 341 | if(!ASN1_check_infinite_end(&c.p, Tlen)) \ | ||
| 342 | { c.error=ERR_R_MISSING_ASN1_EOS; \ | ||
| 343 | c.line=__LINE__; goto err; } \ | ||
| 344 | }\ | ||
| 345 | c.slen-=(c.p-c.q); \ | ||
| 346 | } | ||
| 347 | |||
| 348 | /* New macros */ | ||
| 349 | #define M_ASN1_New_Malloc(ret,type) \ | ||
| 350 | if ((ret=(type *)OPENSSL_malloc(sizeof(type))) == NULL) \ | ||
| 351 | { c.line=__LINE__; goto err2; } | ||
| 352 | |||
| 353 | #define M_ASN1_New(arg,func) \ | ||
| 354 | if (((arg)=func()) == NULL) return(NULL) | ||
| 355 | |||
| 356 | #define M_ASN1_New_Error(a) \ | ||
| 357 | /* err: ASN1_MAC_H_err((a),ERR_R_NESTED_ASN1_ERROR,c.line); \ | ||
| 358 | return(NULL);*/ \ | ||
| 359 | err2: ASN1_MAC_H_err((a),ERR_R_MALLOC_FAILURE,c.line); \ | ||
| 360 | return(NULL) | ||
| 361 | |||
| 362 | |||
| 363 | /* BIG UGLY WARNING! This is so damn ugly I wanna puke. Unfortunately, | ||
| 364 | some macros that use ASN1_const_CTX still insist on writing in the input | ||
| 365 | stream. ARGH! ARGH! ARGH! Let's get rid of this macro package. | ||
| 366 | Please? -- Richard Levitte */ | ||
| 367 | #define M_ASN1_next (*((unsigned char *)(c.p))) | ||
| 368 | #define M_ASN1_next_prev (*((unsigned char *)(c.q))) | ||
| 369 | |||
| 370 | /*************************************************/ | ||
| 371 | |||
| 372 | #define M_ASN1_I2D_vars(a) int r=0,ret=0; \ | ||
| 373 | unsigned char *p; \ | ||
| 374 | if (a == NULL) return(0) | ||
| 375 | |||
| 376 | /* Length Macros */ | ||
| 377 | #define M_ASN1_I2D_len(a,f) ret+=f(a,NULL) | ||
| 378 | #define M_ASN1_I2D_len_IMP_opt(a,f) if (a != NULL) M_ASN1_I2D_len(a,f) | ||
| 379 | |||
| 380 | #define M_ASN1_I2D_len_SET(a,f) \ | ||
| 381 | ret+=i2d_ASN1_SET(a,NULL,f,V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET); | ||
| 382 | |||
| 383 | #define M_ASN1_I2D_len_SET_type(type,a,f) \ | ||
| 384 | ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,V_ASN1_SET, \ | ||
| 385 | V_ASN1_UNIVERSAL,IS_SET); | ||
| 386 | |||
| 387 | #define M_ASN1_I2D_len_SEQUENCE(a,f) \ | ||
| 388 | ret+=i2d_ASN1_SET(a,NULL,f,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL, \ | ||
| 389 | IS_SEQUENCE); | ||
| 390 | |||
| 391 | #define M_ASN1_I2D_len_SEQUENCE_type(type,a,f) \ | ||
| 392 | ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,V_ASN1_SEQUENCE, \ | ||
| 393 | V_ASN1_UNIVERSAL,IS_SEQUENCE) | ||
| 394 | |||
| 395 | #define M_ASN1_I2D_len_SEQUENCE_opt(a,f) \ | ||
| 396 | if ((a != NULL) && (sk_num(a) != 0)) \ | ||
| 397 | M_ASN1_I2D_len_SEQUENCE(a,f); | ||
| 398 | |||
| 399 | #define M_ASN1_I2D_len_SEQUENCE_opt_type(type,a,f) \ | ||
| 400 | if ((a != NULL) && (sk_##type##_num(a) != 0)) \ | ||
| 401 | M_ASN1_I2D_len_SEQUENCE_type(type,a,f); | ||
| 402 | |||
| 403 | #define M_ASN1_I2D_len_IMP_SET(a,f,x) \ | ||
| 404 | ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC,IS_SET); | ||
| 405 | |||
| 406 | #define M_ASN1_I2D_len_IMP_SET_type(type,a,f,x) \ | ||
| 407 | ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \ | ||
| 408 | V_ASN1_CONTEXT_SPECIFIC,IS_SET); | ||
| 409 | |||
| 410 | #define M_ASN1_I2D_len_IMP_SET_opt(a,f,x) \ | ||
| 411 | if ((a != NULL) && (sk_num(a) != 0)) \ | ||
| 412 | ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \ | ||
| 413 | IS_SET); | ||
| 414 | |||
| 415 | #define M_ASN1_I2D_len_IMP_SET_opt_type(type,a,f,x) \ | ||
| 416 | if ((a != NULL) && (sk_##type##_num(a) != 0)) \ | ||
| 417 | ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \ | ||
| 418 | V_ASN1_CONTEXT_SPECIFIC,IS_SET); | ||
| 419 | |||
| 420 | #define M_ASN1_I2D_len_IMP_SEQUENCE(a,f,x) \ | ||
| 421 | ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \ | ||
| 422 | IS_SEQUENCE); | ||
| 423 | |||
| 424 | #define M_ASN1_I2D_len_IMP_SEQUENCE_opt(a,f,x) \ | ||
| 425 | if ((a != NULL) && (sk_num(a) != 0)) \ | ||
| 426 | ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \ | ||
| 427 | IS_SEQUENCE); | ||
| 428 | |||
| 429 | #define M_ASN1_I2D_len_IMP_SEQUENCE_opt_type(type,a,f,x) \ | ||
| 430 | if ((a != NULL) && (sk_##type##_num(a) != 0)) \ | ||
| 431 | ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \ | ||
| 432 | V_ASN1_CONTEXT_SPECIFIC, \ | ||
| 433 | IS_SEQUENCE); | ||
| 434 | |||
| 435 | #define M_ASN1_I2D_len_EXP_opt(a,f,mtag,v) \ | ||
| 436 | if (a != NULL)\ | ||
| 437 | { \ | ||
| 438 | v=f(a,NULL); \ | ||
| 439 | ret+=ASN1_object_size(1,v,mtag); \ | ||
| 440 | } | ||
| 441 | |||
| 442 | #define M_ASN1_I2D_len_EXP_SET_opt(a,f,mtag,tag,v) \ | ||
| 443 | if ((a != NULL) && (sk_num(a) != 0))\ | ||
| 444 | { \ | ||
| 445 | v=i2d_ASN1_SET(a,NULL,f,tag,V_ASN1_UNIVERSAL,IS_SET); \ | ||
| 446 | ret+=ASN1_object_size(1,v,mtag); \ | ||
| 447 | } | ||
| 448 | |||
| 449 | #define M_ASN1_I2D_len_EXP_SEQUENCE_opt(a,f,mtag,tag,v) \ | ||
| 450 | if ((a != NULL) && (sk_num(a) != 0))\ | ||
| 451 | { \ | ||
| 452 | v=i2d_ASN1_SET(a,NULL,f,tag,V_ASN1_UNIVERSAL, \ | ||
| 453 | IS_SEQUENCE); \ | ||
| 454 | ret+=ASN1_object_size(1,v,mtag); \ | ||
| 455 | } | ||
| 456 | |||
| 457 | #define M_ASN1_I2D_len_EXP_SEQUENCE_opt_type(type,a,f,mtag,tag,v) \ | ||
| 458 | if ((a != NULL) && (sk_##type##_num(a) != 0))\ | ||
| 459 | { \ | ||
| 460 | v=i2d_ASN1_SET_OF_##type(a,NULL,f,tag, \ | ||
| 461 | V_ASN1_UNIVERSAL, \ | ||
| 462 | IS_SEQUENCE); \ | ||
| 463 | ret+=ASN1_object_size(1,v,mtag); \ | ||
| 464 | } | ||
| 465 | |||
| 466 | /* Put Macros */ | ||
| 467 | #define M_ASN1_I2D_put(a,f) f(a,&p) | ||
| 468 | |||
| 469 | #define M_ASN1_I2D_put_IMP_opt(a,f,t) \ | ||
| 470 | if (a != NULL) \ | ||
| 471 | { \ | ||
| 472 | unsigned char *q=p; \ | ||
| 473 | f(a,&p); \ | ||
| 474 | *q=(V_ASN1_CONTEXT_SPECIFIC|t|(*q&V_ASN1_CONSTRUCTED));\ | ||
| 475 | } | ||
| 476 | |||
| 477 | #define M_ASN1_I2D_put_SET(a,f) i2d_ASN1_SET(a,&p,f,V_ASN1_SET,\ | ||
| 478 | V_ASN1_UNIVERSAL,IS_SET) | ||
| 479 | #define M_ASN1_I2D_put_SET_type(type,a,f) \ | ||
| 480 | i2d_ASN1_SET_OF_##type(a,&p,f,V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET) | ||
| 481 | #define M_ASN1_I2D_put_IMP_SET(a,f,x) i2d_ASN1_SET(a,&p,f,x,\ | ||
| 482 | V_ASN1_CONTEXT_SPECIFIC,IS_SET) | ||
| 483 | #define M_ASN1_I2D_put_IMP_SET_type(type,a,f,x) \ | ||
| 484 | i2d_ASN1_SET_OF_##type(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC,IS_SET) | ||
| 485 | #define M_ASN1_I2D_put_IMP_SEQUENCE(a,f,x) i2d_ASN1_SET(a,&p,f,x,\ | ||
| 486 | V_ASN1_CONTEXT_SPECIFIC,IS_SEQUENCE) | ||
| 487 | |||
| 488 | #define M_ASN1_I2D_put_SEQUENCE(a,f) i2d_ASN1_SET(a,&p,f,V_ASN1_SEQUENCE,\ | ||
| 489 | V_ASN1_UNIVERSAL,IS_SEQUENCE) | ||
| 490 | |||
| 491 | #define M_ASN1_I2D_put_SEQUENCE_type(type,a,f) \ | ||
| 492 | i2d_ASN1_SET_OF_##type(a,&p,f,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL, \ | ||
| 493 | IS_SEQUENCE) | ||
| 494 | |||
| 495 | #define M_ASN1_I2D_put_SEQUENCE_opt(a,f) \ | ||
| 496 | if ((a != NULL) && (sk_num(a) != 0)) \ | ||
| 497 | M_ASN1_I2D_put_SEQUENCE(a,f); | ||
| 498 | |||
| 499 | #define M_ASN1_I2D_put_IMP_SET_opt(a,f,x) \ | ||
| 500 | if ((a != NULL) && (sk_num(a) != 0)) \ | ||
| 501 | { i2d_ASN1_SET(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC, \ | ||
| 502 | IS_SET); } | ||
| 503 | |||
| 504 | #define M_ASN1_I2D_put_IMP_SET_opt_type(type,a,f,x) \ | ||
| 505 | if ((a != NULL) && (sk_##type##_num(a) != 0)) \ | ||
| 506 | { i2d_ASN1_SET_OF_##type(a,&p,f,x, \ | ||
| 507 | V_ASN1_CONTEXT_SPECIFIC, \ | ||
| 508 | IS_SET); } | ||
| 509 | |||
| 510 | #define M_ASN1_I2D_put_IMP_SEQUENCE_opt(a,f,x) \ | ||
| 511 | if ((a != NULL) && (sk_num(a) != 0)) \ | ||
| 512 | { i2d_ASN1_SET(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC, \ | ||
| 513 | IS_SEQUENCE); } | ||
| 514 | |||
| 515 | #define M_ASN1_I2D_put_IMP_SEQUENCE_opt_type(type,a,f,x) \ | ||
| 516 | if ((a != NULL) && (sk_##type##_num(a) != 0)) \ | ||
| 517 | { i2d_ASN1_SET_OF_##type(a,&p,f,x, \ | ||
| 518 | V_ASN1_CONTEXT_SPECIFIC, \ | ||
| 519 | IS_SEQUENCE); } | ||
| 520 | |||
| 521 | #define M_ASN1_I2D_put_EXP_opt(a,f,tag,v) \ | ||
| 522 | if (a != NULL) \ | ||
| 523 | { \ | ||
| 524 | ASN1_put_object(&p,1,v,tag,V_ASN1_CONTEXT_SPECIFIC); \ | ||
| 525 | f(a,&p); \ | ||
| 526 | } | ||
| 527 | |||
| 528 | #define M_ASN1_I2D_put_EXP_SET_opt(a,f,mtag,tag,v) \ | ||
| 529 | if ((a != NULL) && (sk_num(a) != 0)) \ | ||
| 530 | { \ | ||
| 531 | ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \ | ||
| 532 | i2d_ASN1_SET(a,&p,f,tag,V_ASN1_UNIVERSAL,IS_SET); \ | ||
| 533 | } | ||
| 534 | |||
| 535 | #define M_ASN1_I2D_put_EXP_SEQUENCE_opt(a,f,mtag,tag,v) \ | ||
| 536 | if ((a != NULL) && (sk_num(a) != 0)) \ | ||
| 537 | { \ | ||
| 538 | ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \ | ||
| 539 | i2d_ASN1_SET(a,&p,f,tag,V_ASN1_UNIVERSAL,IS_SEQUENCE); \ | ||
| 540 | } | ||
| 541 | |||
| 542 | #define M_ASN1_I2D_put_EXP_SEQUENCE_opt_type(type,a,f,mtag,tag,v) \ | ||
| 543 | if ((a != NULL) && (sk_##type##_num(a) != 0)) \ | ||
| 544 | { \ | ||
| 545 | ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \ | ||
| 546 | i2d_ASN1_SET_OF_##type(a,&p,f,tag,V_ASN1_UNIVERSAL, \ | ||
| 547 | IS_SEQUENCE); \ | ||
| 548 | } | ||
| 549 | |||
| 550 | #define M_ASN1_I2D_seq_total() \ | ||
| 551 | r=ASN1_object_size(1,ret,V_ASN1_SEQUENCE); \ | ||
| 552 | if (pp == NULL) return(r); \ | ||
| 553 | p= *pp; \ | ||
| 554 | ASN1_put_object(&p,1,ret,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL) | ||
| 555 | |||
| 556 | #define M_ASN1_I2D_INF_seq_start(tag,ctx) \ | ||
| 557 | *(p++)=(V_ASN1_CONSTRUCTED|(tag)|(ctx)); \ | ||
| 558 | *(p++)=0x80 | ||
| 559 | |||
| 560 | #define M_ASN1_I2D_INF_seq_end() *(p++)=0x00; *(p++)=0x00 | ||
| 561 | |||
| 562 | #define M_ASN1_I2D_finish() *pp=p; \ | ||
| 563 | return(r); | ||
| 564 | |||
| 565 | int asn1_GetSequence(ASN1_const_CTX *c, long *length); | ||
| 566 | void asn1_add_error(const unsigned char *address,int offset); | ||
| 567 | #ifdef __cplusplus | ||
| 568 | } | ||
| 569 | #endif | ||
| 570 | |||
| 571 | #endif | ||
diff --git a/src/lib/libcrypto/asn1/asn1_par.c b/src/lib/libcrypto/asn1/asn1_par.c new file mode 100644 index 0000000000..501b62a4b1 --- /dev/null +++ b/src/lib/libcrypto/asn1/asn1_par.c | |||
| @@ -0,0 +1,442 @@ | |||
| 1 | /* crypto/asn1/asn1_par.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/buffer.h> | ||
| 62 | #include <openssl/objects.h> | ||
| 63 | #include <openssl/asn1.h> | ||
| 64 | |||
| 65 | static int asn1_print_info(BIO *bp, int tag, int xclass,int constructed, | ||
| 66 | int indent); | ||
| 67 | static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, | ||
| 68 | int offset, int depth, int indent, int dump); | ||
| 69 | static int asn1_print_info(BIO *bp, int tag, int xclass, int constructed, | ||
| 70 | int indent) | ||
| 71 | { | ||
| 72 | static const char fmt[]="%-18s"; | ||
| 73 | static const char fmt2[]="%2d %-15s"; | ||
| 74 | char str[128]; | ||
| 75 | const char *p,*p2=NULL; | ||
| 76 | |||
| 77 | if (constructed & V_ASN1_CONSTRUCTED) | ||
| 78 | p="cons: "; | ||
| 79 | else | ||
| 80 | p="prim: "; | ||
| 81 | if (BIO_write(bp,p,6) < 6) goto err; | ||
| 82 | BIO_indent(bp,indent,128); | ||
| 83 | |||
| 84 | p=str; | ||
| 85 | if ((xclass & V_ASN1_PRIVATE) == V_ASN1_PRIVATE) | ||
| 86 | BIO_snprintf(str,sizeof str,"priv [ %d ] ",tag); | ||
| 87 | else if ((xclass & V_ASN1_CONTEXT_SPECIFIC) == V_ASN1_CONTEXT_SPECIFIC) | ||
| 88 | BIO_snprintf(str,sizeof str,"cont [ %d ]",tag); | ||
| 89 | else if ((xclass & V_ASN1_APPLICATION) == V_ASN1_APPLICATION) | ||
| 90 | BIO_snprintf(str,sizeof str,"appl [ %d ]",tag); | ||
| 91 | else if (tag > 30) | ||
| 92 | BIO_snprintf(str,sizeof str,"<ASN1 %d>",tag); | ||
| 93 | else | ||
| 94 | p = ASN1_tag2str(tag); | ||
| 95 | |||
| 96 | if (p2 != NULL) | ||
| 97 | { | ||
| 98 | if (BIO_printf(bp,fmt2,tag,p2) <= 0) goto err; | ||
| 99 | } | ||
| 100 | else | ||
| 101 | { | ||
| 102 | if (BIO_printf(bp,fmt,p) <= 0) goto err; | ||
| 103 | } | ||
| 104 | return(1); | ||
| 105 | err: | ||
| 106 | return(0); | ||
| 107 | } | ||
| 108 | |||
| 109 | int ASN1_parse(BIO *bp, const unsigned char *pp, long len, int indent) | ||
| 110 | { | ||
| 111 | return(asn1_parse2(bp,&pp,len,0,0,indent,0)); | ||
| 112 | } | ||
| 113 | |||
| 114 | int ASN1_parse_dump(BIO *bp, const unsigned char *pp, long len, int indent, int dump) | ||
| 115 | { | ||
| 116 | return(asn1_parse2(bp,&pp,len,0,0,indent,dump)); | ||
| 117 | } | ||
| 118 | |||
| 119 | static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offset, | ||
| 120 | int depth, int indent, int dump) | ||
| 121 | { | ||
| 122 | const unsigned char *p,*ep,*tot,*op,*opp; | ||
| 123 | long len; | ||
| 124 | int tag,xclass,ret=0; | ||
| 125 | int nl,hl,j,r; | ||
| 126 | ASN1_OBJECT *o=NULL; | ||
| 127 | ASN1_OCTET_STRING *os=NULL; | ||
| 128 | /* ASN1_BMPSTRING *bmp=NULL;*/ | ||
| 129 | int dump_indent; | ||
| 130 | |||
| 131 | #if 0 | ||
| 132 | dump_indent = indent; | ||
| 133 | #else | ||
| 134 | dump_indent = 6; /* Because we know BIO_dump_indent() */ | ||
| 135 | #endif | ||
| 136 | p= *pp; | ||
| 137 | tot=p+length; | ||
| 138 | op=p-1; | ||
| 139 | while ((p < tot) && (op < p)) | ||
| 140 | { | ||
| 141 | op=p; | ||
| 142 | j=ASN1_get_object(&p,&len,&tag,&xclass,length); | ||
| 143 | #ifdef LINT | ||
| 144 | j=j; | ||
| 145 | #endif | ||
| 146 | if (j & 0x80) | ||
| 147 | { | ||
| 148 | if (BIO_write(bp,"Error in encoding\n",18) <= 0) | ||
| 149 | goto end; | ||
| 150 | ret=0; | ||
| 151 | goto end; | ||
| 152 | } | ||
| 153 | hl=(p-op); | ||
| 154 | length-=hl; | ||
| 155 | /* if j == 0x21 it is a constructed indefinite length object */ | ||
| 156 | if (BIO_printf(bp,"%5ld:",(long)offset+(long)(op- *pp)) | ||
| 157 | <= 0) goto end; | ||
| 158 | |||
| 159 | if (j != (V_ASN1_CONSTRUCTED | 1)) | ||
| 160 | { | ||
| 161 | if (BIO_printf(bp,"d=%-2d hl=%ld l=%4ld ", | ||
| 162 | depth,(long)hl,len) <= 0) | ||
| 163 | goto end; | ||
| 164 | } | ||
| 165 | else | ||
| 166 | { | ||
| 167 | if (BIO_printf(bp,"d=%-2d hl=%ld l=inf ", | ||
| 168 | depth,(long)hl) <= 0) | ||
| 169 | goto end; | ||
| 170 | } | ||
| 171 | if (!asn1_print_info(bp,tag,xclass,j,(indent)?depth:0)) | ||
| 172 | goto end; | ||
| 173 | if (j & V_ASN1_CONSTRUCTED) | ||
| 174 | { | ||
| 175 | ep=p+len; | ||
| 176 | if (BIO_write(bp,"\n",1) <= 0) goto end; | ||
| 177 | if (len > length) | ||
| 178 | { | ||
| 179 | BIO_printf(bp, | ||
| 180 | "length is greater than %ld\n",length); | ||
| 181 | ret=0; | ||
| 182 | goto end; | ||
| 183 | } | ||
| 184 | if ((j == 0x21) && (len == 0)) | ||
| 185 | { | ||
| 186 | for (;;) | ||
| 187 | { | ||
| 188 | r=asn1_parse2(bp,&p,(long)(tot-p), | ||
| 189 | offset+(p - *pp),depth+1, | ||
| 190 | indent,dump); | ||
| 191 | if (r == 0) { ret=0; goto end; } | ||
| 192 | if ((r == 2) || (p >= tot)) break; | ||
| 193 | } | ||
| 194 | } | ||
| 195 | else | ||
| 196 | while (p < ep) | ||
| 197 | { | ||
| 198 | r=asn1_parse2(bp,&p,(long)len, | ||
| 199 | offset+(p - *pp),depth+1, | ||
| 200 | indent,dump); | ||
| 201 | if (r == 0) { ret=0; goto end; } | ||
| 202 | } | ||
| 203 | } | ||
| 204 | else if (xclass != 0) | ||
| 205 | { | ||
| 206 | p+=len; | ||
| 207 | if (BIO_write(bp,"\n",1) <= 0) goto end; | ||
| 208 | } | ||
| 209 | else | ||
| 210 | { | ||
| 211 | nl=0; | ||
| 212 | if ( (tag == V_ASN1_PRINTABLESTRING) || | ||
| 213 | (tag == V_ASN1_T61STRING) || | ||
| 214 | (tag == V_ASN1_IA5STRING) || | ||
| 215 | (tag == V_ASN1_VISIBLESTRING) || | ||
| 216 | (tag == V_ASN1_UTCTIME) || | ||
| 217 | (tag == V_ASN1_GENERALIZEDTIME)) | ||
| 218 | { | ||
| 219 | if (BIO_write(bp,":",1) <= 0) goto end; | ||
| 220 | if ((len > 0) && | ||
| 221 | BIO_write(bp,(const char *)p,(int)len) | ||
| 222 | != (int)len) | ||
| 223 | goto end; | ||
| 224 | } | ||
| 225 | else if (tag == V_ASN1_OBJECT) | ||
| 226 | { | ||
| 227 | opp=op; | ||
| 228 | if (d2i_ASN1_OBJECT(&o,&opp,len+hl) != NULL) | ||
| 229 | { | ||
| 230 | if (BIO_write(bp,":",1) <= 0) goto end; | ||
| 231 | i2a_ASN1_OBJECT(bp,o); | ||
| 232 | } | ||
| 233 | else | ||
| 234 | { | ||
| 235 | if (BIO_write(bp,":BAD OBJECT",11) <= 0) | ||
| 236 | goto end; | ||
| 237 | } | ||
| 238 | } | ||
| 239 | else if (tag == V_ASN1_BOOLEAN) | ||
| 240 | { | ||
| 241 | int ii; | ||
| 242 | |||
| 243 | opp=op; | ||
| 244 | ii=d2i_ASN1_BOOLEAN(NULL,&opp,len+hl); | ||
| 245 | if (ii < 0) | ||
| 246 | { | ||
| 247 | if (BIO_write(bp,"Bad boolean\n",12)) | ||
| 248 | goto end; | ||
| 249 | } | ||
| 250 | BIO_printf(bp,":%d",ii); | ||
| 251 | } | ||
| 252 | else if (tag == V_ASN1_BMPSTRING) | ||
| 253 | { | ||
| 254 | /* do the BMP thang */ | ||
| 255 | } | ||
| 256 | else if (tag == V_ASN1_OCTET_STRING) | ||
| 257 | { | ||
| 258 | int i,printable=1; | ||
| 259 | |||
| 260 | opp=op; | ||
| 261 | os=d2i_ASN1_OCTET_STRING(NULL,&opp,len+hl); | ||
| 262 | if (os != NULL && os->length > 0) | ||
| 263 | { | ||
| 264 | opp = os->data; | ||
| 265 | /* testing whether the octet string is | ||
| 266 | * printable */ | ||
| 267 | for (i=0; i<os->length; i++) | ||
| 268 | { | ||
| 269 | if (( (opp[i] < ' ') && | ||
| 270 | (opp[i] != '\n') && | ||
| 271 | (opp[i] != '\r') && | ||
| 272 | (opp[i] != '\t')) || | ||
| 273 | (opp[i] > '~')) | ||
| 274 | { | ||
| 275 | printable=0; | ||
| 276 | break; | ||
| 277 | } | ||
| 278 | } | ||
| 279 | if (printable) | ||
| 280 | /* printable string */ | ||
| 281 | { | ||
| 282 | if (BIO_write(bp,":",1) <= 0) | ||
| 283 | goto end; | ||
| 284 | if (BIO_write(bp,(const char *)opp, | ||
| 285 | os->length) <= 0) | ||
| 286 | goto end; | ||
| 287 | } | ||
| 288 | else if (!dump) | ||
| 289 | /* not printable => print octet string | ||
| 290 | * as hex dump */ | ||
| 291 | { | ||
| 292 | if (BIO_write(bp,"[HEX DUMP]:",11) <= 0) | ||
| 293 | goto end; | ||
| 294 | for (i=0; i<os->length; i++) | ||
| 295 | { | ||
| 296 | if (BIO_printf(bp,"%02X" | ||
| 297 | , opp[i]) <= 0) | ||
| 298 | goto end; | ||
| 299 | } | ||
| 300 | } | ||
| 301 | else | ||
| 302 | /* print the normal dump */ | ||
| 303 | { | ||
| 304 | if (!nl) | ||
| 305 | { | ||
| 306 | if (BIO_write(bp,"\n",1) <= 0) | ||
| 307 | goto end; | ||
| 308 | } | ||
| 309 | if (BIO_dump_indent(bp, | ||
| 310 | (const char *)opp, | ||
| 311 | ((dump == -1 || dump > | ||
| 312 | os->length)?os->length:dump), | ||
| 313 | dump_indent) <= 0) | ||
| 314 | goto end; | ||
| 315 | nl=1; | ||
| 316 | } | ||
| 317 | } | ||
| 318 | if (os != NULL) | ||
| 319 | { | ||
| 320 | M_ASN1_OCTET_STRING_free(os); | ||
| 321 | os=NULL; | ||
| 322 | } | ||
| 323 | } | ||
| 324 | else if (tag == V_ASN1_INTEGER) | ||
| 325 | { | ||
| 326 | ASN1_INTEGER *bs; | ||
| 327 | int i; | ||
| 328 | |||
| 329 | opp=op; | ||
| 330 | bs=d2i_ASN1_INTEGER(NULL,&opp,len+hl); | ||
| 331 | if (bs != NULL) | ||
| 332 | { | ||
| 333 | if (BIO_write(bp,":",1) <= 0) goto end; | ||
| 334 | if (bs->type == V_ASN1_NEG_INTEGER) | ||
| 335 | if (BIO_write(bp,"-",1) <= 0) | ||
| 336 | goto end; | ||
| 337 | for (i=0; i<bs->length; i++) | ||
| 338 | { | ||
| 339 | if (BIO_printf(bp,"%02X", | ||
| 340 | bs->data[i]) <= 0) | ||
| 341 | goto end; | ||
| 342 | } | ||
| 343 | if (bs->length == 0) | ||
| 344 | { | ||
| 345 | if (BIO_write(bp,"00",2) <= 0) | ||
| 346 | goto end; | ||
| 347 | } | ||
| 348 | } | ||
| 349 | else | ||
| 350 | { | ||
| 351 | if (BIO_write(bp,"BAD INTEGER",11) <= 0) | ||
| 352 | goto end; | ||
| 353 | } | ||
| 354 | M_ASN1_INTEGER_free(bs); | ||
| 355 | } | ||
| 356 | else if (tag == V_ASN1_ENUMERATED) | ||
| 357 | { | ||
| 358 | ASN1_ENUMERATED *bs; | ||
| 359 | int i; | ||
| 360 | |||
| 361 | opp=op; | ||
| 362 | bs=d2i_ASN1_ENUMERATED(NULL,&opp,len+hl); | ||
| 363 | if (bs != NULL) | ||
| 364 | { | ||
| 365 | if (BIO_write(bp,":",1) <= 0) goto end; | ||
| 366 | if (bs->type == V_ASN1_NEG_ENUMERATED) | ||
| 367 | if (BIO_write(bp,"-",1) <= 0) | ||
| 368 | goto end; | ||
| 369 | for (i=0; i<bs->length; i++) | ||
| 370 | { | ||
| 371 | if (BIO_printf(bp,"%02X", | ||
| 372 | bs->data[i]) <= 0) | ||
| 373 | goto end; | ||
| 374 | } | ||
| 375 | if (bs->length == 0) | ||
| 376 | { | ||
| 377 | if (BIO_write(bp,"00",2) <= 0) | ||
| 378 | goto end; | ||
| 379 | } | ||
| 380 | } | ||
| 381 | else | ||
| 382 | { | ||
| 383 | if (BIO_write(bp,"BAD ENUMERATED",11) <= 0) | ||
| 384 | goto end; | ||
| 385 | } | ||
| 386 | M_ASN1_ENUMERATED_free(bs); | ||
| 387 | } | ||
| 388 | else if (len > 0 && dump) | ||
| 389 | { | ||
| 390 | if (!nl) | ||
| 391 | { | ||
| 392 | if (BIO_write(bp,"\n",1) <= 0) | ||
| 393 | goto end; | ||
| 394 | } | ||
| 395 | if (BIO_dump_indent(bp,(const char *)p, | ||
| 396 | ((dump == -1 || dump > len)?len:dump), | ||
| 397 | dump_indent) <= 0) | ||
| 398 | goto end; | ||
| 399 | nl=1; | ||
| 400 | } | ||
| 401 | |||
| 402 | if (!nl) | ||
| 403 | { | ||
| 404 | if (BIO_write(bp,"\n",1) <= 0) goto end; | ||
| 405 | } | ||
| 406 | p+=len; | ||
| 407 | if ((tag == V_ASN1_EOC) && (xclass == 0)) | ||
| 408 | { | ||
| 409 | ret=2; /* End of sequence */ | ||
| 410 | goto end; | ||
| 411 | } | ||
| 412 | } | ||
| 413 | length-=len; | ||
| 414 | } | ||
| 415 | ret=1; | ||
| 416 | end: | ||
| 417 | if (o != NULL) ASN1_OBJECT_free(o); | ||
| 418 | if (os != NULL) M_ASN1_OCTET_STRING_free(os); | ||
| 419 | *pp=p; | ||
| 420 | return(ret); | ||
| 421 | } | ||
| 422 | |||
| 423 | const char *ASN1_tag2str(int tag) | ||
| 424 | { | ||
| 425 | static const char *tag2str[] = { | ||
| 426 | "EOC", "BOOLEAN", "INTEGER", "BIT STRING", "OCTET STRING", /* 0-4 */ | ||
| 427 | "NULL", "OBJECT", "OBJECT DESCRIPTOR", "EXTERNAL", "REAL", /* 5-9 */ | ||
| 428 | "ENUMERATED", "<ASN1 11>", "UTF8STRING", "<ASN1 13>", /* 10-13 */ | ||
| 429 | "<ASN1 14>", "<ASN1 15>", "SEQUENCE", "SET", /* 15-17 */ | ||
| 430 | "NUMERICSTRING", "PRINTABLESTRING", "T61STRING", /* 18-20 */ | ||
| 431 | "VIDEOTEXSTRING", "IA5STRING", "UTCTIME","GENERALIZEDTIME", /* 21-24 */ | ||
| 432 | "GRAPHICSTRING", "VISIBLESTRING", "GENERALSTRING", /* 25-27 */ | ||
| 433 | "UNIVERSALSTRING", "<ASN1 29>", "BMPSTRING" /* 28-30 */ | ||
| 434 | }; | ||
| 435 | |||
| 436 | if((tag == V_ASN1_NEG_INTEGER) || (tag == V_ASN1_NEG_ENUMERATED)) | ||
| 437 | tag &= ~0x100; | ||
| 438 | |||
| 439 | if(tag < 0 || tag > 30) return "(unknown)"; | ||
| 440 | return tag2str[tag]; | ||
| 441 | } | ||
| 442 | |||
diff --git a/src/lib/libcrypto/asn1/asn1t.h b/src/lib/libcrypto/asn1/asn1t.h new file mode 100644 index 0000000000..bf315e65ed --- /dev/null +++ b/src/lib/libcrypto/asn1/asn1t.h | |||
| @@ -0,0 +1,893 @@ | |||
| 1 | /* asn1t.h */ | ||
| 2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
| 3 | * project 2000. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 2000 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | #ifndef HEADER_ASN1T_H | ||
| 59 | #define HEADER_ASN1T_H | ||
| 60 | |||
| 61 | #include <stddef.h> | ||
| 62 | #include <openssl/e_os2.h> | ||
| 63 | #include <openssl/asn1.h> | ||
| 64 | |||
| 65 | #ifdef OPENSSL_BUILD_SHLIBCRYPTO | ||
| 66 | # undef OPENSSL_EXTERN | ||
| 67 | # define OPENSSL_EXTERN OPENSSL_EXPORT | ||
| 68 | #endif | ||
| 69 | |||
| 70 | /* ASN1 template defines, structures and functions */ | ||
| 71 | |||
| 72 | #ifdef __cplusplus | ||
| 73 | extern "C" { | ||
| 74 | #endif | ||
| 75 | |||
| 76 | |||
| 77 | #ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION | ||
| 78 | |||
| 79 | /* Macro to obtain ASN1_ADB pointer from a type (only used internally) */ | ||
| 80 | #define ASN1_ADB_ptr(iptr) ((const ASN1_ADB *)(iptr)) | ||
| 81 | |||
| 82 | |||
| 83 | /* Macros for start and end of ASN1_ITEM definition */ | ||
| 84 | |||
| 85 | #define ASN1_ITEM_start(itname) \ | ||
| 86 | OPENSSL_GLOBAL const ASN1_ITEM itname##_it = { | ||
| 87 | |||
| 88 | #define ASN1_ITEM_end(itname) \ | ||
| 89 | }; | ||
| 90 | |||
| 91 | #else | ||
| 92 | |||
| 93 | /* Macro to obtain ASN1_ADB pointer from a type (only used internally) */ | ||
| 94 | #define ASN1_ADB_ptr(iptr) ((const ASN1_ADB *)(iptr())) | ||
| 95 | |||
| 96 | |||
| 97 | /* Macros for start and end of ASN1_ITEM definition */ | ||
| 98 | |||
| 99 | #define ASN1_ITEM_start(itname) \ | ||
| 100 | const ASN1_ITEM * itname##_it(void) \ | ||
| 101 | { \ | ||
| 102 | static const ASN1_ITEM local_it = { | ||
| 103 | |||
| 104 | #define ASN1_ITEM_end(itname) \ | ||
| 105 | }; \ | ||
| 106 | return &local_it; \ | ||
| 107 | } | ||
| 108 | |||
| 109 | #endif | ||
| 110 | |||
| 111 | |||
| 112 | /* Macros to aid ASN1 template writing */ | ||
| 113 | |||
| 114 | #define ASN1_ITEM_TEMPLATE(tname) \ | ||
| 115 | static const ASN1_TEMPLATE tname##_item_tt | ||
| 116 | |||
| 117 | #define ASN1_ITEM_TEMPLATE_END(tname) \ | ||
| 118 | ;\ | ||
| 119 | ASN1_ITEM_start(tname) \ | ||
| 120 | ASN1_ITYPE_PRIMITIVE,\ | ||
| 121 | -1,\ | ||
| 122 | &tname##_item_tt,\ | ||
| 123 | 0,\ | ||
| 124 | NULL,\ | ||
| 125 | 0,\ | ||
| 126 | #tname \ | ||
| 127 | ASN1_ITEM_end(tname) | ||
| 128 | |||
| 129 | |||
| 130 | /* This is a ASN1 type which just embeds a template */ | ||
| 131 | |||
| 132 | /* This pair helps declare a SEQUENCE. We can do: | ||
| 133 | * | ||
| 134 | * ASN1_SEQUENCE(stname) = { | ||
| 135 | * ... SEQUENCE components ... | ||
| 136 | * } ASN1_SEQUENCE_END(stname) | ||
| 137 | * | ||
| 138 | * This will produce an ASN1_ITEM called stname_it | ||
| 139 | * for a structure called stname. | ||
| 140 | * | ||
| 141 | * If you want the same structure but a different | ||
| 142 | * name then use: | ||
| 143 | * | ||
| 144 | * ASN1_SEQUENCE(itname) = { | ||
| 145 | * ... SEQUENCE components ... | ||
| 146 | * } ASN1_SEQUENCE_END_name(stname, itname) | ||
| 147 | * | ||
| 148 | * This will create an item called itname_it using | ||
| 149 | * a structure called stname. | ||
| 150 | */ | ||
| 151 | |||
| 152 | #define ASN1_SEQUENCE(tname) \ | ||
| 153 | static const ASN1_TEMPLATE tname##_seq_tt[] | ||
| 154 | |||
| 155 | #define ASN1_SEQUENCE_END(stname) ASN1_SEQUENCE_END_name(stname, stname) | ||
| 156 | |||
| 157 | #define ASN1_SEQUENCE_END_name(stname, tname) \ | ||
| 158 | ;\ | ||
| 159 | ASN1_ITEM_start(tname) \ | ||
| 160 | ASN1_ITYPE_SEQUENCE,\ | ||
| 161 | V_ASN1_SEQUENCE,\ | ||
| 162 | tname##_seq_tt,\ | ||
| 163 | sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\ | ||
| 164 | NULL,\ | ||
| 165 | sizeof(stname),\ | ||
| 166 | #stname \ | ||
| 167 | ASN1_ITEM_end(tname) | ||
| 168 | |||
| 169 | #define ASN1_NDEF_SEQUENCE(tname) \ | ||
| 170 | ASN1_SEQUENCE(tname) | ||
| 171 | |||
| 172 | #define ASN1_NDEF_SEQUENCE_cb(tname, cb) \ | ||
| 173 | ASN1_SEQUENCE_cb(tname, cb) | ||
| 174 | |||
| 175 | #define ASN1_SEQUENCE_cb(tname, cb) \ | ||
| 176 | static const ASN1_AUX tname##_aux = {NULL, 0, 0, 0, cb, 0}; \ | ||
| 177 | ASN1_SEQUENCE(tname) | ||
| 178 | |||
| 179 | #define ASN1_BROKEN_SEQUENCE(tname) \ | ||
| 180 | static const ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_BROKEN, 0, 0, 0, 0}; \ | ||
| 181 | ASN1_SEQUENCE(tname) | ||
| 182 | |||
| 183 | #define ASN1_SEQUENCE_ref(tname, cb, lck) \ | ||
| 184 | static const ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_REFCOUNT, offsetof(tname, references), lck, cb, 0}; \ | ||
| 185 | ASN1_SEQUENCE(tname) | ||
| 186 | |||
| 187 | #define ASN1_SEQUENCE_enc(tname, enc, cb) \ | ||
| 188 | static const ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_ENCODING, 0, 0, cb, offsetof(tname, enc)}; \ | ||
| 189 | ASN1_SEQUENCE(tname) | ||
| 190 | |||
| 191 | #define ASN1_NDEF_SEQUENCE_END(tname) \ | ||
| 192 | ;\ | ||
| 193 | ASN1_ITEM_start(tname) \ | ||
| 194 | ASN1_ITYPE_NDEF_SEQUENCE,\ | ||
| 195 | V_ASN1_SEQUENCE,\ | ||
| 196 | tname##_seq_tt,\ | ||
| 197 | sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\ | ||
| 198 | NULL,\ | ||
| 199 | sizeof(tname),\ | ||
| 200 | #tname \ | ||
| 201 | ASN1_ITEM_end(tname) | ||
| 202 | |||
| 203 | #define ASN1_BROKEN_SEQUENCE_END(stname) ASN1_SEQUENCE_END_ref(stname, stname) | ||
| 204 | |||
| 205 | #define ASN1_SEQUENCE_END_enc(stname, tname) ASN1_SEQUENCE_END_ref(stname, tname) | ||
| 206 | |||
| 207 | #define ASN1_SEQUENCE_END_cb(stname, tname) ASN1_SEQUENCE_END_ref(stname, tname) | ||
| 208 | |||
| 209 | #define ASN1_SEQUENCE_END_ref(stname, tname) \ | ||
| 210 | ;\ | ||
| 211 | ASN1_ITEM_start(tname) \ | ||
| 212 | ASN1_ITYPE_SEQUENCE,\ | ||
| 213 | V_ASN1_SEQUENCE,\ | ||
| 214 | tname##_seq_tt,\ | ||
| 215 | sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\ | ||
| 216 | &tname##_aux,\ | ||
| 217 | sizeof(stname),\ | ||
| 218 | #stname \ | ||
| 219 | ASN1_ITEM_end(tname) | ||
| 220 | |||
| 221 | |||
| 222 | /* This pair helps declare a CHOICE type. We can do: | ||
| 223 | * | ||
| 224 | * ASN1_CHOICE(chname) = { | ||
| 225 | * ... CHOICE options ... | ||
| 226 | * ASN1_CHOICE_END(chname) | ||
| 227 | * | ||
| 228 | * This will produce an ASN1_ITEM called chname_it | ||
| 229 | * for a structure called chname. The structure | ||
| 230 | * definition must look like this: | ||
| 231 | * typedef struct { | ||
| 232 | * int type; | ||
| 233 | * union { | ||
| 234 | * ASN1_SOMETHING *opt1; | ||
| 235 | * ASN1_SOMEOTHER *opt2; | ||
| 236 | * } value; | ||
| 237 | * } chname; | ||
| 238 | * | ||
| 239 | * the name of the selector must be 'type'. | ||
| 240 | * to use an alternative selector name use the | ||
| 241 | * ASN1_CHOICE_END_selector() version. | ||
| 242 | */ | ||
| 243 | |||
| 244 | #define ASN1_CHOICE(tname) \ | ||
| 245 | static const ASN1_TEMPLATE tname##_ch_tt[] | ||
| 246 | |||
| 247 | #define ASN1_CHOICE_cb(tname, cb) \ | ||
| 248 | static const ASN1_AUX tname##_aux = {NULL, 0, 0, 0, cb, 0}; \ | ||
| 249 | ASN1_CHOICE(tname) | ||
| 250 | |||
| 251 | #define ASN1_CHOICE_END(stname) ASN1_CHOICE_END_name(stname, stname) | ||
| 252 | |||
| 253 | #define ASN1_CHOICE_END_name(stname, tname) ASN1_CHOICE_END_selector(stname, tname, type) | ||
| 254 | |||
| 255 | #define ASN1_CHOICE_END_selector(stname, tname, selname) \ | ||
| 256 | ;\ | ||
| 257 | ASN1_ITEM_start(tname) \ | ||
| 258 | ASN1_ITYPE_CHOICE,\ | ||
| 259 | offsetof(stname,selname) ,\ | ||
| 260 | tname##_ch_tt,\ | ||
| 261 | sizeof(tname##_ch_tt) / sizeof(ASN1_TEMPLATE),\ | ||
| 262 | NULL,\ | ||
| 263 | sizeof(stname),\ | ||
| 264 | #stname \ | ||
| 265 | ASN1_ITEM_end(tname) | ||
| 266 | |||
| 267 | #define ASN1_CHOICE_END_cb(stname, tname, selname) \ | ||
| 268 | ;\ | ||
| 269 | ASN1_ITEM_start(tname) \ | ||
| 270 | ASN1_ITYPE_CHOICE,\ | ||
| 271 | offsetof(stname,selname) ,\ | ||
| 272 | tname##_ch_tt,\ | ||
| 273 | sizeof(tname##_ch_tt) / sizeof(ASN1_TEMPLATE),\ | ||
| 274 | &tname##_aux,\ | ||
| 275 | sizeof(stname),\ | ||
| 276 | #stname \ | ||
| 277 | ASN1_ITEM_end(tname) | ||
| 278 | |||
| 279 | /* This helps with the template wrapper form of ASN1_ITEM */ | ||
| 280 | |||
| 281 | #define ASN1_EX_TEMPLATE_TYPE(flags, tag, name, type) { \ | ||
| 282 | (flags), (tag), 0,\ | ||
| 283 | #name, ASN1_ITEM_ref(type) } | ||
| 284 | |||
| 285 | /* These help with SEQUENCE or CHOICE components */ | ||
| 286 | |||
| 287 | /* used to declare other types */ | ||
| 288 | |||
| 289 | #define ASN1_EX_TYPE(flags, tag, stname, field, type) { \ | ||
| 290 | (flags), (tag), offsetof(stname, field),\ | ||
| 291 | #field, ASN1_ITEM_ref(type) } | ||
| 292 | |||
| 293 | /* used when the structure is combined with the parent */ | ||
| 294 | |||
| 295 | #define ASN1_EX_COMBINE(flags, tag, type) { \ | ||
| 296 | (flags)|ASN1_TFLG_COMBINE, (tag), 0, NULL, ASN1_ITEM_ref(type) } | ||
| 297 | |||
| 298 | /* implicit and explicit helper macros */ | ||
| 299 | |||
| 300 | #define ASN1_IMP_EX(stname, field, type, tag, ex) \ | ||
| 301 | ASN1_EX_TYPE(ASN1_TFLG_IMPLICIT | ex, tag, stname, field, type) | ||
| 302 | |||
| 303 | #define ASN1_EXP_EX(stname, field, type, tag, ex) \ | ||
| 304 | ASN1_EX_TYPE(ASN1_TFLG_EXPLICIT | ex, tag, stname, field, type) | ||
| 305 | |||
| 306 | /* Any defined by macros: the field used is in the table itself */ | ||
| 307 | |||
| 308 | #ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION | ||
| 309 | #define ASN1_ADB_OBJECT(tblname) { ASN1_TFLG_ADB_OID, -1, 0, #tblname, (const ASN1_ITEM *)&(tblname##_adb) } | ||
| 310 | #define ASN1_ADB_INTEGER(tblname) { ASN1_TFLG_ADB_INT, -1, 0, #tblname, (const ASN1_ITEM *)&(tblname##_adb) } | ||
| 311 | #else | ||
| 312 | #define ASN1_ADB_OBJECT(tblname) { ASN1_TFLG_ADB_OID, -1, 0, #tblname, tblname##_adb } | ||
| 313 | #define ASN1_ADB_INTEGER(tblname) { ASN1_TFLG_ADB_INT, -1, 0, #tblname, tblname##_adb } | ||
| 314 | #endif | ||
| 315 | /* Plain simple type */ | ||
| 316 | #define ASN1_SIMPLE(stname, field, type) ASN1_EX_TYPE(0,0, stname, field, type) | ||
| 317 | |||
| 318 | /* OPTIONAL simple type */ | ||
| 319 | #define ASN1_OPT(stname, field, type) ASN1_EX_TYPE(ASN1_TFLG_OPTIONAL, 0, stname, field, type) | ||
| 320 | |||
| 321 | /* IMPLICIT tagged simple type */ | ||
| 322 | #define ASN1_IMP(stname, field, type, tag) ASN1_IMP_EX(stname, field, type, tag, 0) | ||
| 323 | |||
| 324 | /* IMPLICIT tagged OPTIONAL simple type */ | ||
| 325 | #define ASN1_IMP_OPT(stname, field, type, tag) ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL) | ||
| 326 | |||
| 327 | /* Same as above but EXPLICIT */ | ||
| 328 | |||
| 329 | #define ASN1_EXP(stname, field, type, tag) ASN1_EXP_EX(stname, field, type, tag, 0) | ||
| 330 | #define ASN1_EXP_OPT(stname, field, type, tag) ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL) | ||
| 331 | |||
| 332 | /* SEQUENCE OF type */ | ||
| 333 | #define ASN1_SEQUENCE_OF(stname, field, type) \ | ||
| 334 | ASN1_EX_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, stname, field, type) | ||
| 335 | |||
| 336 | /* OPTIONAL SEQUENCE OF */ | ||
| 337 | #define ASN1_SEQUENCE_OF_OPT(stname, field, type) \ | ||
| 338 | ASN1_EX_TYPE(ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL, 0, stname, field, type) | ||
| 339 | |||
| 340 | /* Same as above but for SET OF */ | ||
| 341 | |||
| 342 | #define ASN1_SET_OF(stname, field, type) \ | ||
| 343 | ASN1_EX_TYPE(ASN1_TFLG_SET_OF, 0, stname, field, type) | ||
| 344 | |||
| 345 | #define ASN1_SET_OF_OPT(stname, field, type) \ | ||
| 346 | ASN1_EX_TYPE(ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL, 0, stname, field, type) | ||
| 347 | |||
| 348 | /* Finally compound types of SEQUENCE, SET, IMPLICIT, EXPLICIT and OPTIONAL */ | ||
| 349 | |||
| 350 | #define ASN1_IMP_SET_OF(stname, field, type, tag) \ | ||
| 351 | ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF) | ||
| 352 | |||
| 353 | #define ASN1_EXP_SET_OF(stname, field, type, tag) \ | ||
| 354 | ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF) | ||
| 355 | |||
| 356 | #define ASN1_IMP_SET_OF_OPT(stname, field, type, tag) \ | ||
| 357 | ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL) | ||
| 358 | |||
| 359 | #define ASN1_EXP_SET_OF_OPT(stname, field, type, tag) \ | ||
| 360 | ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL) | ||
| 361 | |||
| 362 | #define ASN1_IMP_SEQUENCE_OF(stname, field, type, tag) \ | ||
| 363 | ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF) | ||
| 364 | |||
| 365 | #define ASN1_IMP_SEQUENCE_OF_OPT(stname, field, type, tag) \ | ||
| 366 | ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL) | ||
| 367 | |||
| 368 | #define ASN1_EXP_SEQUENCE_OF(stname, field, type, tag) \ | ||
| 369 | ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF) | ||
| 370 | |||
| 371 | #define ASN1_EXP_SEQUENCE_OF_OPT(stname, field, type, tag) \ | ||
| 372 | ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL) | ||
| 373 | |||
| 374 | /* EXPLICIT using indefinite length constructed form */ | ||
| 375 | #define ASN1_NDEF_EXP(stname, field, type, tag) \ | ||
| 376 | ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_NDEF) | ||
| 377 | |||
| 378 | /* EXPLICIT OPTIONAL using indefinite length constructed form */ | ||
| 379 | #define ASN1_NDEF_EXP_OPT(stname, field, type, tag) \ | ||
| 380 | ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL|ASN1_TFLG_NDEF) | ||
| 381 | |||
| 382 | /* Macros for the ASN1_ADB structure */ | ||
| 383 | |||
| 384 | #define ASN1_ADB(name) \ | ||
| 385 | static const ASN1_ADB_TABLE name##_adbtbl[] | ||
| 386 | |||
| 387 | #ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION | ||
| 388 | |||
| 389 | #define ASN1_ADB_END(name, flags, field, app_table, def, none) \ | ||
| 390 | ;\ | ||
| 391 | static const ASN1_ADB name##_adb = {\ | ||
| 392 | flags,\ | ||
| 393 | offsetof(name, field),\ | ||
| 394 | app_table,\ | ||
| 395 | name##_adbtbl,\ | ||
| 396 | sizeof(name##_adbtbl) / sizeof(ASN1_ADB_TABLE),\ | ||
| 397 | def,\ | ||
| 398 | none\ | ||
| 399 | } | ||
| 400 | |||
| 401 | #else | ||
| 402 | |||
| 403 | #define ASN1_ADB_END(name, flags, field, app_table, def, none) \ | ||
| 404 | ;\ | ||
| 405 | static const ASN1_ITEM *name##_adb(void) \ | ||
| 406 | { \ | ||
| 407 | static const ASN1_ADB internal_adb = \ | ||
| 408 | {\ | ||
| 409 | flags,\ | ||
| 410 | offsetof(name, field),\ | ||
| 411 | app_table,\ | ||
| 412 | name##_adbtbl,\ | ||
| 413 | sizeof(name##_adbtbl) / sizeof(ASN1_ADB_TABLE),\ | ||
| 414 | def,\ | ||
| 415 | none\ | ||
| 416 | }; \ | ||
| 417 | return (const ASN1_ITEM *) &internal_adb; \ | ||
| 418 | } \ | ||
| 419 | void dummy_function(void) | ||
| 420 | |||
| 421 | #endif | ||
| 422 | |||
| 423 | #define ADB_ENTRY(val, template) {val, template} | ||
| 424 | |||
| 425 | #define ASN1_ADB_TEMPLATE(name) \ | ||
| 426 | static const ASN1_TEMPLATE name##_tt | ||
| 427 | |||
| 428 | /* This is the ASN1 template structure that defines | ||
| 429 | * a wrapper round the actual type. It determines the | ||
| 430 | * actual position of the field in the value structure, | ||
| 431 | * various flags such as OPTIONAL and the field name. | ||
| 432 | */ | ||
| 433 | |||
| 434 | struct ASN1_TEMPLATE_st { | ||
| 435 | unsigned long flags; /* Various flags */ | ||
| 436 | long tag; /* tag, not used if no tagging */ | ||
| 437 | unsigned long offset; /* Offset of this field in structure */ | ||
| 438 | #ifndef NO_ASN1_FIELD_NAMES | ||
| 439 | const char *field_name; /* Field name */ | ||
| 440 | #endif | ||
| 441 | ASN1_ITEM_EXP *item; /* Relevant ASN1_ITEM or ASN1_ADB */ | ||
| 442 | }; | ||
| 443 | |||
| 444 | /* Macro to extract ASN1_ITEM and ASN1_ADB pointer from ASN1_TEMPLATE */ | ||
| 445 | |||
| 446 | #define ASN1_TEMPLATE_item(t) (t->item_ptr) | ||
| 447 | #define ASN1_TEMPLATE_adb(t) (t->item_ptr) | ||
| 448 | |||
| 449 | typedef struct ASN1_ADB_TABLE_st ASN1_ADB_TABLE; | ||
| 450 | typedef struct ASN1_ADB_st ASN1_ADB; | ||
| 451 | |||
| 452 | struct ASN1_ADB_st { | ||
| 453 | unsigned long flags; /* Various flags */ | ||
| 454 | unsigned long offset; /* Offset of selector field */ | ||
| 455 | STACK_OF(ASN1_ADB_TABLE) **app_items; /* Application defined items */ | ||
| 456 | const ASN1_ADB_TABLE *tbl; /* Table of possible types */ | ||
| 457 | long tblcount; /* Number of entries in tbl */ | ||
| 458 | const ASN1_TEMPLATE *default_tt; /* Type to use if no match */ | ||
| 459 | const ASN1_TEMPLATE *null_tt; /* Type to use if selector is NULL */ | ||
| 460 | }; | ||
| 461 | |||
| 462 | struct ASN1_ADB_TABLE_st { | ||
| 463 | long value; /* NID for an object or value for an int */ | ||
| 464 | const ASN1_TEMPLATE tt; /* item for this value */ | ||
| 465 | }; | ||
| 466 | |||
| 467 | /* template flags */ | ||
| 468 | |||
| 469 | /* Field is optional */ | ||
| 470 | #define ASN1_TFLG_OPTIONAL (0x1) | ||
| 471 | |||
| 472 | /* Field is a SET OF */ | ||
| 473 | #define ASN1_TFLG_SET_OF (0x1 << 1) | ||
| 474 | |||
| 475 | /* Field is a SEQUENCE OF */ | ||
| 476 | #define ASN1_TFLG_SEQUENCE_OF (0x2 << 1) | ||
| 477 | |||
| 478 | /* Special case: this refers to a SET OF that | ||
| 479 | * will be sorted into DER order when encoded *and* | ||
| 480 | * the corresponding STACK will be modified to match | ||
| 481 | * the new order. | ||
| 482 | */ | ||
| 483 | #define ASN1_TFLG_SET_ORDER (0x3 << 1) | ||
| 484 | |||
| 485 | /* Mask for SET OF or SEQUENCE OF */ | ||
| 486 | #define ASN1_TFLG_SK_MASK (0x3 << 1) | ||
| 487 | |||
| 488 | /* These flags mean the tag should be taken from the | ||
| 489 | * tag field. If EXPLICIT then the underlying type | ||
| 490 | * is used for the inner tag. | ||
| 491 | */ | ||
| 492 | |||
| 493 | /* IMPLICIT tagging */ | ||
| 494 | #define ASN1_TFLG_IMPTAG (0x1 << 3) | ||
| 495 | |||
| 496 | |||
| 497 | /* EXPLICIT tagging, inner tag from underlying type */ | ||
| 498 | #define ASN1_TFLG_EXPTAG (0x2 << 3) | ||
| 499 | |||
| 500 | #define ASN1_TFLG_TAG_MASK (0x3 << 3) | ||
| 501 | |||
| 502 | /* context specific IMPLICIT */ | ||
| 503 | #define ASN1_TFLG_IMPLICIT ASN1_TFLG_IMPTAG|ASN1_TFLG_CONTEXT | ||
| 504 | |||
| 505 | /* context specific EXPLICIT */ | ||
| 506 | #define ASN1_TFLG_EXPLICIT ASN1_TFLG_EXPTAG|ASN1_TFLG_CONTEXT | ||
| 507 | |||
| 508 | /* If tagging is in force these determine the | ||
| 509 | * type of tag to use. Otherwise the tag is | ||
| 510 | * determined by the underlying type. These | ||
| 511 | * values reflect the actual octet format. | ||
| 512 | */ | ||
| 513 | |||
| 514 | /* Universal tag */ | ||
| 515 | #define ASN1_TFLG_UNIVERSAL (0x0<<6) | ||
| 516 | /* Application tag */ | ||
| 517 | #define ASN1_TFLG_APPLICATION (0x1<<6) | ||
| 518 | /* Context specific tag */ | ||
| 519 | #define ASN1_TFLG_CONTEXT (0x2<<6) | ||
| 520 | /* Private tag */ | ||
| 521 | #define ASN1_TFLG_PRIVATE (0x3<<6) | ||
| 522 | |||
| 523 | #define ASN1_TFLG_TAG_CLASS (0x3<<6) | ||
| 524 | |||
| 525 | /* These are for ANY DEFINED BY type. In this case | ||
| 526 | * the 'item' field points to an ASN1_ADB structure | ||
| 527 | * which contains a table of values to decode the | ||
| 528 | * relevant type | ||
| 529 | */ | ||
| 530 | |||
| 531 | #define ASN1_TFLG_ADB_MASK (0x3<<8) | ||
| 532 | |||
| 533 | #define ASN1_TFLG_ADB_OID (0x1<<8) | ||
| 534 | |||
| 535 | #define ASN1_TFLG_ADB_INT (0x1<<9) | ||
| 536 | |||
| 537 | /* This flag means a parent structure is passed | ||
| 538 | * instead of the field: this is useful is a | ||
| 539 | * SEQUENCE is being combined with a CHOICE for | ||
| 540 | * example. Since this means the structure and | ||
| 541 | * item name will differ we need to use the | ||
| 542 | * ASN1_CHOICE_END_name() macro for example. | ||
| 543 | */ | ||
| 544 | |||
| 545 | #define ASN1_TFLG_COMBINE (0x1<<10) | ||
| 546 | |||
| 547 | /* This flag when present in a SEQUENCE OF, SET OF | ||
| 548 | * or EXPLICIT causes indefinite length constructed | ||
| 549 | * encoding to be used if required. | ||
| 550 | */ | ||
| 551 | |||
| 552 | #define ASN1_TFLG_NDEF (0x1<<11) | ||
| 553 | |||
| 554 | /* This is the actual ASN1 item itself */ | ||
| 555 | |||
| 556 | struct ASN1_ITEM_st { | ||
| 557 | char itype; /* The item type, primitive, SEQUENCE, CHOICE or extern */ | ||
| 558 | long utype; /* underlying type */ | ||
| 559 | const ASN1_TEMPLATE *templates; /* If SEQUENCE or CHOICE this contains the contents */ | ||
| 560 | long tcount; /* Number of templates if SEQUENCE or CHOICE */ | ||
| 561 | const void *funcs; /* functions that handle this type */ | ||
| 562 | long size; /* Structure size (usually)*/ | ||
| 563 | #ifndef NO_ASN1_FIELD_NAMES | ||
| 564 | const char *sname; /* Structure name */ | ||
| 565 | #endif | ||
| 566 | }; | ||
| 567 | |||
| 568 | /* These are values for the itype field and | ||
| 569 | * determine how the type is interpreted. | ||
| 570 | * | ||
| 571 | * For PRIMITIVE types the underlying type | ||
| 572 | * determines the behaviour if items is NULL. | ||
| 573 | * | ||
| 574 | * Otherwise templates must contain a single | ||
| 575 | * template and the type is treated in the | ||
| 576 | * same way as the type specified in the template. | ||
| 577 | * | ||
| 578 | * For SEQUENCE types the templates field points | ||
| 579 | * to the members, the size field is the | ||
| 580 | * structure size. | ||
| 581 | * | ||
| 582 | * For CHOICE types the templates field points | ||
| 583 | * to each possible member (typically a union) | ||
| 584 | * and the 'size' field is the offset of the | ||
| 585 | * selector. | ||
| 586 | * | ||
| 587 | * The 'funcs' field is used for application | ||
| 588 | * specific functions. | ||
| 589 | * | ||
| 590 | * For COMPAT types the funcs field gives a | ||
| 591 | * set of functions that handle this type, this | ||
| 592 | * supports the old d2i, i2d convention. | ||
| 593 | * | ||
| 594 | * The EXTERN type uses a new style d2i/i2d. | ||
| 595 | * The new style should be used where possible | ||
| 596 | * because it avoids things like the d2i IMPLICIT | ||
| 597 | * hack. | ||
| 598 | * | ||
| 599 | * MSTRING is a multiple string type, it is used | ||
| 600 | * for a CHOICE of character strings where the | ||
| 601 | * actual strings all occupy an ASN1_STRING | ||
| 602 | * structure. In this case the 'utype' field | ||
| 603 | * has a special meaning, it is used as a mask | ||
| 604 | * of acceptable types using the B_ASN1 constants. | ||
| 605 | * | ||
| 606 | * NDEF_SEQUENCE is the same as SEQUENCE except | ||
| 607 | * that it will use indefinite length constructed | ||
| 608 | * encoding if requested. | ||
| 609 | * | ||
| 610 | */ | ||
| 611 | |||
| 612 | #define ASN1_ITYPE_PRIMITIVE 0x0 | ||
| 613 | |||
| 614 | #define ASN1_ITYPE_SEQUENCE 0x1 | ||
| 615 | |||
| 616 | #define ASN1_ITYPE_CHOICE 0x2 | ||
| 617 | |||
| 618 | #define ASN1_ITYPE_COMPAT 0x3 | ||
| 619 | |||
| 620 | #define ASN1_ITYPE_EXTERN 0x4 | ||
| 621 | |||
| 622 | #define ASN1_ITYPE_MSTRING 0x5 | ||
| 623 | |||
| 624 | #define ASN1_ITYPE_NDEF_SEQUENCE 0x6 | ||
| 625 | |||
| 626 | /* Cache for ASN1 tag and length, so we | ||
| 627 | * don't keep re-reading it for things | ||
| 628 | * like CHOICE | ||
| 629 | */ | ||
| 630 | |||
| 631 | struct ASN1_TLC_st{ | ||
| 632 | char valid; /* Values below are valid */ | ||
| 633 | int ret; /* return value */ | ||
| 634 | long plen; /* length */ | ||
| 635 | int ptag; /* class value */ | ||
| 636 | int pclass; /* class value */ | ||
| 637 | int hdrlen; /* header length */ | ||
| 638 | }; | ||
| 639 | |||
| 640 | /* Typedefs for ASN1 function pointers */ | ||
| 641 | |||
| 642 | typedef ASN1_VALUE * ASN1_new_func(void); | ||
| 643 | typedef void ASN1_free_func(ASN1_VALUE *a); | ||
| 644 | typedef ASN1_VALUE * ASN1_d2i_func(ASN1_VALUE **a, const unsigned char ** in, long length); | ||
| 645 | typedef int ASN1_i2d_func(ASN1_VALUE * a, unsigned char **in); | ||
| 646 | |||
| 647 | typedef int ASN1_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, const ASN1_ITEM *it, | ||
| 648 | int tag, int aclass, char opt, ASN1_TLC *ctx); | ||
| 649 | |||
| 650 | typedef int ASN1_ex_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass); | ||
| 651 | typedef int ASN1_ex_new_func(ASN1_VALUE **pval, const ASN1_ITEM *it); | ||
| 652 | typedef void ASN1_ex_free_func(ASN1_VALUE **pval, const ASN1_ITEM *it); | ||
| 653 | |||
| 654 | typedef int ASN1_primitive_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it); | ||
| 655 | typedef int ASN1_primitive_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it); | ||
| 656 | |||
| 657 | typedef struct ASN1_COMPAT_FUNCS_st { | ||
| 658 | ASN1_new_func *asn1_new; | ||
| 659 | ASN1_free_func *asn1_free; | ||
| 660 | ASN1_d2i_func *asn1_d2i; | ||
| 661 | ASN1_i2d_func *asn1_i2d; | ||
| 662 | } ASN1_COMPAT_FUNCS; | ||
| 663 | |||
| 664 | typedef struct ASN1_EXTERN_FUNCS_st { | ||
| 665 | void *app_data; | ||
| 666 | ASN1_ex_new_func *asn1_ex_new; | ||
| 667 | ASN1_ex_free_func *asn1_ex_free; | ||
| 668 | ASN1_ex_free_func *asn1_ex_clear; | ||
| 669 | ASN1_ex_d2i *asn1_ex_d2i; | ||
| 670 | ASN1_ex_i2d *asn1_ex_i2d; | ||
| 671 | } ASN1_EXTERN_FUNCS; | ||
| 672 | |||
| 673 | typedef struct ASN1_PRIMITIVE_FUNCS_st { | ||
| 674 | void *app_data; | ||
| 675 | unsigned long flags; | ||
| 676 | ASN1_ex_new_func *prim_new; | ||
| 677 | ASN1_ex_free_func *prim_free; | ||
| 678 | ASN1_ex_free_func *prim_clear; | ||
| 679 | ASN1_primitive_c2i *prim_c2i; | ||
| 680 | ASN1_primitive_i2c *prim_i2c; | ||
| 681 | } ASN1_PRIMITIVE_FUNCS; | ||
| 682 | |||
| 683 | /* This is the ASN1_AUX structure: it handles various | ||
| 684 | * miscellaneous requirements. For example the use of | ||
| 685 | * reference counts and an informational callback. | ||
| 686 | * | ||
| 687 | * The "informational callback" is called at various | ||
| 688 | * points during the ASN1 encoding and decoding. It can | ||
| 689 | * be used to provide minor customisation of the structures | ||
| 690 | * used. This is most useful where the supplied routines | ||
| 691 | * *almost* do the right thing but need some extra help | ||
| 692 | * at a few points. If the callback returns zero then | ||
| 693 | * it is assumed a fatal error has occurred and the | ||
| 694 | * main operation should be abandoned. | ||
| 695 | * | ||
| 696 | * If major changes in the default behaviour are required | ||
| 697 | * then an external type is more appropriate. | ||
| 698 | */ | ||
| 699 | |||
| 700 | typedef int ASN1_aux_cb(int operation, ASN1_VALUE **in, const ASN1_ITEM *it); | ||
| 701 | |||
| 702 | typedef struct ASN1_AUX_st { | ||
| 703 | void *app_data; | ||
| 704 | int flags; | ||
| 705 | int ref_offset; /* Offset of reference value */ | ||
| 706 | int ref_lock; /* Lock type to use */ | ||
| 707 | ASN1_aux_cb *asn1_cb; | ||
| 708 | int enc_offset; /* Offset of ASN1_ENCODING structure */ | ||
| 709 | } ASN1_AUX; | ||
| 710 | |||
| 711 | /* Flags in ASN1_AUX */ | ||
| 712 | |||
| 713 | /* Use a reference count */ | ||
| 714 | #define ASN1_AFLG_REFCOUNT 1 | ||
| 715 | /* Save the encoding of structure (useful for signatures) */ | ||
| 716 | #define ASN1_AFLG_ENCODING 2 | ||
| 717 | /* The Sequence length is invalid */ | ||
| 718 | #define ASN1_AFLG_BROKEN 4 | ||
| 719 | |||
| 720 | /* operation values for asn1_cb */ | ||
| 721 | |||
| 722 | #define ASN1_OP_NEW_PRE 0 | ||
| 723 | #define ASN1_OP_NEW_POST 1 | ||
| 724 | #define ASN1_OP_FREE_PRE 2 | ||
| 725 | #define ASN1_OP_FREE_POST 3 | ||
| 726 | #define ASN1_OP_D2I_PRE 4 | ||
| 727 | #define ASN1_OP_D2I_POST 5 | ||
| 728 | #define ASN1_OP_I2D_PRE 6 | ||
| 729 | #define ASN1_OP_I2D_POST 7 | ||
| 730 | |||
| 731 | /* Macro to implement a primitive type */ | ||
| 732 | #define IMPLEMENT_ASN1_TYPE(stname) IMPLEMENT_ASN1_TYPE_ex(stname, stname, 0) | ||
| 733 | #define IMPLEMENT_ASN1_TYPE_ex(itname, vname, ex) \ | ||
| 734 | ASN1_ITEM_start(itname) \ | ||
| 735 | ASN1_ITYPE_PRIMITIVE, V_##vname, NULL, 0, NULL, ex, #itname \ | ||
| 736 | ASN1_ITEM_end(itname) | ||
| 737 | |||
| 738 | /* Macro to implement a multi string type */ | ||
| 739 | #define IMPLEMENT_ASN1_MSTRING(itname, mask) \ | ||
| 740 | ASN1_ITEM_start(itname) \ | ||
| 741 | ASN1_ITYPE_MSTRING, mask, NULL, 0, NULL, sizeof(ASN1_STRING), #itname \ | ||
| 742 | ASN1_ITEM_end(itname) | ||
| 743 | |||
| 744 | /* Macro to implement an ASN1_ITEM in terms of old style funcs */ | ||
| 745 | |||
| 746 | #define IMPLEMENT_COMPAT_ASN1(sname) IMPLEMENT_COMPAT_ASN1_type(sname, V_ASN1_SEQUENCE) | ||
| 747 | |||
| 748 | #define IMPLEMENT_COMPAT_ASN1_type(sname, tag) \ | ||
| 749 | static const ASN1_COMPAT_FUNCS sname##_ff = { \ | ||
| 750 | (ASN1_new_func *)sname##_new, \ | ||
| 751 | (ASN1_free_func *)sname##_free, \ | ||
| 752 | (ASN1_d2i_func *)d2i_##sname, \ | ||
| 753 | (ASN1_i2d_func *)i2d_##sname, \ | ||
| 754 | }; \ | ||
| 755 | ASN1_ITEM_start(sname) \ | ||
| 756 | ASN1_ITYPE_COMPAT, \ | ||
| 757 | tag, \ | ||
| 758 | NULL, \ | ||
| 759 | 0, \ | ||
| 760 | &sname##_ff, \ | ||
| 761 | 0, \ | ||
| 762 | #sname \ | ||
| 763 | ASN1_ITEM_end(sname) | ||
| 764 | |||
| 765 | #define IMPLEMENT_EXTERN_ASN1(sname, tag, fptrs) \ | ||
| 766 | ASN1_ITEM_start(sname) \ | ||
| 767 | ASN1_ITYPE_EXTERN, \ | ||
| 768 | tag, \ | ||
| 769 | NULL, \ | ||
| 770 | 0, \ | ||
| 771 | &fptrs, \ | ||
| 772 | 0, \ | ||
| 773 | #sname \ | ||
| 774 | ASN1_ITEM_end(sname) | ||
| 775 | |||
| 776 | /* Macro to implement standard functions in terms of ASN1_ITEM structures */ | ||
| 777 | |||
| 778 | #define IMPLEMENT_ASN1_FUNCTIONS(stname) IMPLEMENT_ASN1_FUNCTIONS_fname(stname, stname, stname) | ||
| 779 | |||
| 780 | #define IMPLEMENT_ASN1_FUNCTIONS_name(stname, itname) IMPLEMENT_ASN1_FUNCTIONS_fname(stname, itname, itname) | ||
| 781 | |||
| 782 | #define IMPLEMENT_ASN1_FUNCTIONS_ENCODE_name(stname, itname) \ | ||
| 783 | IMPLEMENT_ASN1_FUNCTIONS_ENCODE_fname(stname, itname, itname) | ||
| 784 | |||
| 785 | #define IMPLEMENT_ASN1_ALLOC_FUNCTIONS(stname) \ | ||
| 786 | IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, stname, stname) | ||
| 787 | |||
| 788 | #define IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname) \ | ||
| 789 | stname *fname##_new(void) \ | ||
| 790 | { \ | ||
| 791 | return (stname *)ASN1_item_new(ASN1_ITEM_rptr(itname)); \ | ||
| 792 | } \ | ||
| 793 | void fname##_free(stname *a) \ | ||
| 794 | { \ | ||
| 795 | ASN1_item_free((ASN1_VALUE *)a, ASN1_ITEM_rptr(itname)); \ | ||
| 796 | } | ||
| 797 | |||
| 798 | #define IMPLEMENT_ASN1_FUNCTIONS_fname(stname, itname, fname) \ | ||
| 799 | IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(stname, itname, fname) \ | ||
| 800 | IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname) | ||
| 801 | |||
| 802 | #define IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(stname, itname, fname) \ | ||
| 803 | stname *d2i_##fname(stname **a, const unsigned char **in, long len) \ | ||
| 804 | { \ | ||
| 805 | return (stname *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, ASN1_ITEM_rptr(itname));\ | ||
| 806 | } \ | ||
| 807 | int i2d_##fname(stname *a, unsigned char **out) \ | ||
| 808 | { \ | ||
| 809 | return ASN1_item_i2d((ASN1_VALUE *)a, out, ASN1_ITEM_rptr(itname));\ | ||
| 810 | } | ||
| 811 | |||
| 812 | #define IMPLEMENT_ASN1_NDEF_FUNCTION(stname) \ | ||
| 813 | int i2d_##stname##_NDEF(stname *a, unsigned char **out) \ | ||
| 814 | { \ | ||
| 815 | return ASN1_item_ndef_i2d((ASN1_VALUE *)a, out, ASN1_ITEM_rptr(stname));\ | ||
| 816 | } | ||
| 817 | |||
| 818 | /* This includes evil casts to remove const: they will go away when full | ||
| 819 | * ASN1 constification is done. | ||
| 820 | */ | ||
| 821 | #define IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(stname, itname, fname) \ | ||
| 822 | stname *d2i_##fname(stname **a, const unsigned char **in, long len) \ | ||
| 823 | { \ | ||
| 824 | return (stname *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, ASN1_ITEM_rptr(itname));\ | ||
| 825 | } \ | ||
| 826 | int i2d_##fname(const stname *a, unsigned char **out) \ | ||
| 827 | { \ | ||
| 828 | return ASN1_item_i2d((ASN1_VALUE *)a, out, ASN1_ITEM_rptr(itname));\ | ||
| 829 | } | ||
| 830 | |||
| 831 | #define IMPLEMENT_ASN1_DUP_FUNCTION(stname) \ | ||
| 832 | stname * stname##_dup(stname *x) \ | ||
| 833 | { \ | ||
| 834 | return ASN1_item_dup(ASN1_ITEM_rptr(stname), x); \ | ||
| 835 | } | ||
| 836 | |||
| 837 | #define IMPLEMENT_ASN1_FUNCTIONS_const(name) \ | ||
| 838 | IMPLEMENT_ASN1_FUNCTIONS_const_fname(name, name, name) | ||
| 839 | |||
| 840 | #define IMPLEMENT_ASN1_FUNCTIONS_const_fname(stname, itname, fname) \ | ||
| 841 | IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(stname, itname, fname) \ | ||
| 842 | IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname) | ||
| 843 | |||
| 844 | /* external definitions for primitive types */ | ||
| 845 | |||
| 846 | DECLARE_ASN1_ITEM(ASN1_BOOLEAN) | ||
| 847 | DECLARE_ASN1_ITEM(ASN1_TBOOLEAN) | ||
| 848 | DECLARE_ASN1_ITEM(ASN1_FBOOLEAN) | ||
| 849 | DECLARE_ASN1_ITEM(ASN1_SEQUENCE) | ||
| 850 | DECLARE_ASN1_ITEM(CBIGNUM) | ||
| 851 | DECLARE_ASN1_ITEM(BIGNUM) | ||
| 852 | DECLARE_ASN1_ITEM(LONG) | ||
| 853 | DECLARE_ASN1_ITEM(ZLONG) | ||
| 854 | |||
| 855 | DECLARE_STACK_OF(ASN1_VALUE) | ||
| 856 | |||
| 857 | /* Functions used internally by the ASN1 code */ | ||
| 858 | |||
| 859 | int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it); | ||
| 860 | void ASN1_item_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it); | ||
| 861 | int ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt); | ||
| 862 | int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it); | ||
| 863 | |||
| 864 | void ASN1_template_free(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt); | ||
| 865 | int ASN1_template_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, const ASN1_TEMPLATE *tt); | ||
| 866 | int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, const ASN1_ITEM *it, | ||
| 867 | int tag, int aclass, char opt, ASN1_TLC *ctx); | ||
| 868 | |||
| 869 | int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass); | ||
| 870 | int ASN1_template_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_TEMPLATE *tt); | ||
| 871 | void ASN1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it); | ||
| 872 | |||
| 873 | int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it); | ||
| 874 | int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it); | ||
| 875 | |||
| 876 | int asn1_get_choice_selector(ASN1_VALUE **pval, const ASN1_ITEM *it); | ||
| 877 | int asn1_set_choice_selector(ASN1_VALUE **pval, int value, const ASN1_ITEM *it); | ||
| 878 | |||
| 879 | ASN1_VALUE ** asn1_get_field_ptr(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt); | ||
| 880 | |||
| 881 | const ASN1_TEMPLATE *asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt, int nullerr); | ||
| 882 | |||
| 883 | int asn1_do_lock(ASN1_VALUE **pval, int op, const ASN1_ITEM *it); | ||
| 884 | |||
| 885 | void asn1_enc_init(ASN1_VALUE **pval, const ASN1_ITEM *it); | ||
| 886 | void asn1_enc_free(ASN1_VALUE **pval, const ASN1_ITEM *it); | ||
| 887 | int asn1_enc_restore(int *len, unsigned char **out, ASN1_VALUE **pval, const ASN1_ITEM *it); | ||
| 888 | int asn1_enc_save(ASN1_VALUE **pval, const unsigned char *in, int inlen, const ASN1_ITEM *it); | ||
| 889 | |||
| 890 | #ifdef __cplusplus | ||
| 891 | } | ||
| 892 | #endif | ||
| 893 | #endif | ||
diff --git a/src/lib/libcrypto/asn1/asn_mime.c b/src/lib/libcrypto/asn1/asn_mime.c new file mode 100644 index 0000000000..bc80b20d63 --- /dev/null +++ b/src/lib/libcrypto/asn1/asn_mime.c | |||
| @@ -0,0 +1,876 @@ | |||
| 1 | /* asn_mime.c */ | ||
| 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | ||
| 3 | * project. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 1999-2008 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | */ | ||
| 54 | |||
| 55 | #include <stdio.h> | ||
| 56 | #include <ctype.h> | ||
| 57 | #include "cryptlib.h" | ||
| 58 | #include <openssl/rand.h> | ||
| 59 | #include <openssl/x509.h> | ||
| 60 | #include <openssl/asn1.h> | ||
| 61 | #include <openssl/asn1t.h> | ||
| 62 | |||
| 63 | /* Generalised MIME like utilities for streaming ASN1. Although many | ||
| 64 | * have a PKCS7/CMS like flavour others are more general purpose. | ||
| 65 | */ | ||
| 66 | |||
| 67 | /* MIME format structures | ||
| 68 | * Note that all are translated to lower case apart from | ||
| 69 | * parameter values. Quotes are stripped off | ||
| 70 | */ | ||
| 71 | |||
| 72 | typedef struct { | ||
| 73 | char *param_name; /* Param name e.g. "micalg" */ | ||
| 74 | char *param_value; /* Param value e.g. "sha1" */ | ||
| 75 | } MIME_PARAM; | ||
| 76 | |||
| 77 | DECLARE_STACK_OF(MIME_PARAM) | ||
| 78 | IMPLEMENT_STACK_OF(MIME_PARAM) | ||
| 79 | |||
| 80 | typedef struct { | ||
| 81 | char *name; /* Name of line e.g. "content-type" */ | ||
| 82 | char *value; /* Value of line e.g. "text/plain" */ | ||
| 83 | STACK_OF(MIME_PARAM) *params; /* Zero or more parameters */ | ||
| 84 | } MIME_HEADER; | ||
| 85 | |||
| 86 | DECLARE_STACK_OF(MIME_HEADER) | ||
| 87 | IMPLEMENT_STACK_OF(MIME_HEADER) | ||
| 88 | |||
| 89 | static char * strip_ends(char *name); | ||
| 90 | static char * strip_start(char *name); | ||
| 91 | static char * strip_end(char *name); | ||
| 92 | static MIME_HEADER *mime_hdr_new(char *name, char *value); | ||
| 93 | static int mime_hdr_addparam(MIME_HEADER *mhdr, char *name, char *value); | ||
| 94 | static STACK_OF(MIME_HEADER) *mime_parse_hdr(BIO *bio); | ||
| 95 | static int mime_hdr_cmp(const MIME_HEADER * const *a, | ||
| 96 | const MIME_HEADER * const *b); | ||
| 97 | static int mime_param_cmp(const MIME_PARAM * const *a, | ||
| 98 | const MIME_PARAM * const *b); | ||
| 99 | static void mime_param_free(MIME_PARAM *param); | ||
| 100 | static int mime_bound_check(char *line, int linelen, char *bound, int blen); | ||
| 101 | static int multi_split(BIO *bio, char *bound, STACK_OF(BIO) **ret); | ||
| 102 | static int strip_eol(char *linebuf, int *plen); | ||
| 103 | static MIME_HEADER *mime_hdr_find(STACK_OF(MIME_HEADER) *hdrs, char *name); | ||
| 104 | static MIME_PARAM *mime_param_find(MIME_HEADER *hdr, char *name); | ||
| 105 | static void mime_hdr_free(MIME_HEADER *hdr); | ||
| 106 | |||
| 107 | #define MAX_SMLEN 1024 | ||
| 108 | #define mime_debug(x) /* x */ | ||
| 109 | |||
| 110 | /* Base 64 read and write of ASN1 structure */ | ||
| 111 | |||
| 112 | static int B64_write_ASN1(BIO *out, ASN1_VALUE *val, BIO *in, int flags, | ||
| 113 | const ASN1_ITEM *it) | ||
| 114 | { | ||
| 115 | BIO *b64; | ||
| 116 | int r; | ||
| 117 | b64 = BIO_new(BIO_f_base64()); | ||
| 118 | if(!b64) | ||
| 119 | { | ||
| 120 | ASN1err(ASN1_F_B64_WRITE_ASN1,ERR_R_MALLOC_FAILURE); | ||
| 121 | return 0; | ||
| 122 | } | ||
| 123 | /* prepend the b64 BIO so all data is base64 encoded. | ||
| 124 | */ | ||
| 125 | out = BIO_push(b64, out); | ||
| 126 | r = ASN1_item_i2d_bio(it, out, val); | ||
| 127 | (void)BIO_flush(out); | ||
| 128 | BIO_pop(out); | ||
| 129 | BIO_free(b64); | ||
| 130 | return r; | ||
| 131 | } | ||
| 132 | |||
| 133 | static ASN1_VALUE *b64_read_asn1(BIO *bio, const ASN1_ITEM *it) | ||
| 134 | { | ||
| 135 | BIO *b64; | ||
| 136 | ASN1_VALUE *val; | ||
| 137 | if(!(b64 = BIO_new(BIO_f_base64()))) { | ||
| 138 | ASN1err(ASN1_F_B64_READ_ASN1,ERR_R_MALLOC_FAILURE); | ||
| 139 | return 0; | ||
| 140 | } | ||
| 141 | bio = BIO_push(b64, bio); | ||
| 142 | val = ASN1_item_d2i_bio(it, bio, NULL); | ||
| 143 | if(!val) | ||
| 144 | ASN1err(ASN1_F_B64_READ_ASN1,ASN1_R_DECODE_ERROR); | ||
| 145 | (void)BIO_flush(bio); | ||
| 146 | bio = BIO_pop(bio); | ||
| 147 | BIO_free(b64); | ||
| 148 | return val; | ||
| 149 | } | ||
| 150 | |||
| 151 | /* Generate the MIME "micalg" parameter from RFC3851, RFC4490 */ | ||
| 152 | |||
| 153 | static int asn1_write_micalg(BIO *out, STACK_OF(X509_ALGOR) *mdalgs) | ||
| 154 | { | ||
| 155 | const EVP_MD *md; | ||
| 156 | int i, have_unknown = 0, write_comma, md_nid; | ||
| 157 | have_unknown = 0; | ||
| 158 | write_comma = 0; | ||
| 159 | for (i = 0; i < sk_X509_ALGOR_num(mdalgs); i++) | ||
| 160 | { | ||
| 161 | if (write_comma) | ||
| 162 | BIO_write(out, ",", 1); | ||
| 163 | write_comma = 1; | ||
| 164 | md_nid = OBJ_obj2nid(sk_X509_ALGOR_value(mdalgs, i)->algorithm); | ||
| 165 | md = EVP_get_digestbynid(md_nid); | ||
| 166 | switch(md_nid) | ||
| 167 | { | ||
| 168 | case NID_sha1: | ||
| 169 | BIO_puts(out, "sha1"); | ||
| 170 | break; | ||
| 171 | |||
| 172 | case NID_md5: | ||
| 173 | BIO_puts(out, "md5"); | ||
| 174 | break; | ||
| 175 | |||
| 176 | case NID_sha256: | ||
| 177 | BIO_puts(out, "sha-256"); | ||
| 178 | break; | ||
| 179 | |||
| 180 | case NID_sha384: | ||
| 181 | BIO_puts(out, "sha-384"); | ||
| 182 | break; | ||
| 183 | |||
| 184 | case NID_sha512: | ||
| 185 | BIO_puts(out, "sha-512"); | ||
| 186 | break; | ||
| 187 | |||
| 188 | default: | ||
| 189 | if (have_unknown) | ||
| 190 | write_comma = 0; | ||
| 191 | else | ||
| 192 | { | ||
| 193 | BIO_puts(out, "unknown"); | ||
| 194 | have_unknown = 1; | ||
| 195 | } | ||
| 196 | break; | ||
| 197 | |||
| 198 | } | ||
| 199 | } | ||
| 200 | |||
| 201 | return 1; | ||
| 202 | |||
| 203 | } | ||
| 204 | |||
| 205 | /* SMIME sender */ | ||
| 206 | |||
| 207 | int int_smime_write_ASN1(BIO *bio, ASN1_VALUE *val, BIO *data, int flags, | ||
| 208 | int ctype_nid, int econt_nid, | ||
| 209 | STACK_OF(X509_ALGOR) *mdalgs, | ||
| 210 | asn1_output_data_fn *data_fn, | ||
| 211 | const ASN1_ITEM *it) | ||
| 212 | { | ||
| 213 | char bound[33], c; | ||
| 214 | int i; | ||
| 215 | const char *mime_prefix, *mime_eol, *cname = "smime.p7m"; | ||
| 216 | const char *msg_type=NULL; | ||
| 217 | if (flags & SMIME_OLDMIME) | ||
| 218 | mime_prefix = "application/x-pkcs7-"; | ||
| 219 | else | ||
| 220 | mime_prefix = "application/pkcs7-"; | ||
| 221 | |||
| 222 | if (flags & SMIME_CRLFEOL) | ||
| 223 | mime_eol = "\r\n"; | ||
| 224 | else | ||
| 225 | mime_eol = "\n"; | ||
| 226 | if((flags & SMIME_DETACHED) && data) { | ||
| 227 | /* We want multipart/signed */ | ||
| 228 | /* Generate a random boundary */ | ||
| 229 | RAND_pseudo_bytes((unsigned char *)bound, 32); | ||
| 230 | for(i = 0; i < 32; i++) { | ||
| 231 | c = bound[i] & 0xf; | ||
| 232 | if(c < 10) c += '0'; | ||
| 233 | else c += 'A' - 10; | ||
| 234 | bound[i] = c; | ||
| 235 | } | ||
| 236 | bound[32] = 0; | ||
| 237 | BIO_printf(bio, "MIME-Version: 1.0%s", mime_eol); | ||
| 238 | BIO_printf(bio, "Content-Type: multipart/signed;"); | ||
| 239 | BIO_printf(bio, " protocol=\"%ssignature\";", mime_prefix); | ||
| 240 | BIO_puts(bio, " micalg=\""); | ||
| 241 | asn1_write_micalg(bio, mdalgs); | ||
| 242 | BIO_printf(bio, "\"; boundary=\"----%s\"%s%s", | ||
| 243 | bound, mime_eol, mime_eol); | ||
| 244 | BIO_printf(bio, "This is an S/MIME signed message%s%s", | ||
| 245 | mime_eol, mime_eol); | ||
| 246 | /* Now write out the first part */ | ||
| 247 | BIO_printf(bio, "------%s%s", bound, mime_eol); | ||
| 248 | if (!data_fn(bio, data, val, flags, it)) | ||
| 249 | return 0; | ||
| 250 | BIO_printf(bio, "%s------%s%s", mime_eol, bound, mime_eol); | ||
| 251 | |||
| 252 | /* Headers for signature */ | ||
| 253 | |||
| 254 | BIO_printf(bio, "Content-Type: %ssignature;", mime_prefix); | ||
| 255 | BIO_printf(bio, " name=\"smime.p7s\"%s", mime_eol); | ||
| 256 | BIO_printf(bio, "Content-Transfer-Encoding: base64%s", | ||
| 257 | mime_eol); | ||
| 258 | BIO_printf(bio, "Content-Disposition: attachment;"); | ||
| 259 | BIO_printf(bio, " filename=\"smime.p7s\"%s%s", | ||
| 260 | mime_eol, mime_eol); | ||
| 261 | B64_write_ASN1(bio, val, NULL, 0, it); | ||
| 262 | BIO_printf(bio,"%s------%s--%s%s", mime_eol, bound, | ||
| 263 | mime_eol, mime_eol); | ||
| 264 | return 1; | ||
| 265 | } | ||
| 266 | |||
| 267 | /* Determine smime-type header */ | ||
| 268 | |||
| 269 | if (ctype_nid == NID_pkcs7_enveloped) | ||
| 270 | msg_type = "enveloped-data"; | ||
| 271 | else if (ctype_nid == NID_pkcs7_signed) | ||
| 272 | { | ||
| 273 | if (econt_nid == NID_id_smime_ct_receipt) | ||
| 274 | msg_type = "signed-receipt"; | ||
| 275 | else if (sk_X509_ALGOR_num(mdalgs) >= 0) | ||
| 276 | msg_type = "signed-data"; | ||
| 277 | else | ||
| 278 | msg_type = "certs-only"; | ||
| 279 | } | ||
| 280 | else if (ctype_nid == NID_id_smime_ct_compressedData) | ||
| 281 | { | ||
| 282 | msg_type = "compressed-data"; | ||
| 283 | cname = "smime.p7z"; | ||
| 284 | } | ||
| 285 | /* MIME headers */ | ||
| 286 | BIO_printf(bio, "MIME-Version: 1.0%s", mime_eol); | ||
| 287 | BIO_printf(bio, "Content-Disposition: attachment;"); | ||
| 288 | BIO_printf(bio, " filename=\"%s\"%s", cname, mime_eol); | ||
| 289 | BIO_printf(bio, "Content-Type: %smime;", mime_prefix); | ||
| 290 | if (msg_type) | ||
| 291 | BIO_printf(bio, " smime-type=%s;", msg_type); | ||
| 292 | BIO_printf(bio, " name=\"%s\"%s", cname, mime_eol); | ||
| 293 | BIO_printf(bio, "Content-Transfer-Encoding: base64%s%s", | ||
| 294 | mime_eol, mime_eol); | ||
| 295 | if (!B64_write_ASN1(bio, val, data, flags, it)) | ||
| 296 | return 0; | ||
| 297 | BIO_printf(bio, "%s", mime_eol); | ||
| 298 | return 1; | ||
| 299 | } | ||
| 300 | |||
| 301 | #if 0 | ||
| 302 | |||
| 303 | /* Handle output of ASN1 data */ | ||
| 304 | |||
| 305 | |||
| 306 | static int asn1_output_data(BIO *out, BIO *data, ASN1_VALUE *val, int flags, | ||
| 307 | const ASN1_ITEM *it) | ||
| 308 | { | ||
| 309 | BIO *tmpbio; | ||
| 310 | const ASN1_AUX *aux = it->funcs; | ||
| 311 | ASN1_STREAM_ARG sarg; | ||
| 312 | |||
| 313 | if (!(flags & SMIME_DETACHED)) | ||
| 314 | { | ||
| 315 | SMIME_crlf_copy(data, out, flags); | ||
| 316 | return 1; | ||
| 317 | } | ||
| 318 | |||
| 319 | if (!aux || !aux->asn1_cb) | ||
| 320 | { | ||
| 321 | ASN1err(ASN1_F_ASN1_OUTPUT_DATA, | ||
| 322 | ASN1_R_STREAMING_NOT_SUPPORTED); | ||
| 323 | return 0; | ||
| 324 | } | ||
| 325 | |||
| 326 | sarg.out = out; | ||
| 327 | sarg.ndef_bio = NULL; | ||
| 328 | sarg.boundary = NULL; | ||
| 329 | |||
| 330 | /* Let ASN1 code prepend any needed BIOs */ | ||
| 331 | |||
| 332 | if (aux->asn1_cb(ASN1_OP_DETACHED_PRE, &val, it, &sarg) <= 0) | ||
| 333 | return 0; | ||
| 334 | |||
| 335 | /* Copy data across, passing through filter BIOs for processing */ | ||
| 336 | SMIME_crlf_copy(data, sarg.ndef_bio, flags); | ||
| 337 | |||
| 338 | /* Finalize structure */ | ||
| 339 | if (aux->asn1_cb(ASN1_OP_DETACHED_POST, &val, it, &sarg) <= 0) | ||
| 340 | return 0; | ||
| 341 | |||
| 342 | /* Now remove any digests prepended to the BIO */ | ||
| 343 | |||
| 344 | while (sarg.ndef_bio != out) | ||
| 345 | { | ||
| 346 | tmpbio = BIO_pop(sarg.ndef_bio); | ||
| 347 | BIO_free(sarg.ndef_bio); | ||
| 348 | sarg.ndef_bio = tmpbio; | ||
| 349 | } | ||
| 350 | |||
| 351 | return 1; | ||
| 352 | |||
| 353 | } | ||
| 354 | |||
| 355 | #endif | ||
| 356 | |||
| 357 | /* SMIME reader: handle multipart/signed and opaque signing. | ||
| 358 | * in multipart case the content is placed in a memory BIO | ||
| 359 | * pointed to by "bcont". In opaque this is set to NULL | ||
| 360 | */ | ||
| 361 | |||
| 362 | ASN1_VALUE *SMIME_read_ASN1(BIO *bio, BIO **bcont, const ASN1_ITEM *it) | ||
| 363 | { | ||
| 364 | BIO *asnin; | ||
| 365 | STACK_OF(MIME_HEADER) *headers = NULL; | ||
| 366 | STACK_OF(BIO) *parts = NULL; | ||
| 367 | MIME_HEADER *hdr; | ||
| 368 | MIME_PARAM *prm; | ||
| 369 | ASN1_VALUE *val; | ||
| 370 | int ret; | ||
| 371 | |||
| 372 | if(bcont) *bcont = NULL; | ||
| 373 | |||
| 374 | if (!(headers = mime_parse_hdr(bio))) { | ||
| 375 | ASN1err(ASN1_F_SMIME_READ_ASN1,ASN1_R_MIME_PARSE_ERROR); | ||
| 376 | return NULL; | ||
| 377 | } | ||
| 378 | |||
| 379 | if(!(hdr = mime_hdr_find(headers, "content-type")) || !hdr->value) { | ||
| 380 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); | ||
| 381 | ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_NO_CONTENT_TYPE); | ||
| 382 | return NULL; | ||
| 383 | } | ||
| 384 | |||
| 385 | /* Handle multipart/signed */ | ||
| 386 | |||
| 387 | if(!strcmp(hdr->value, "multipart/signed")) { | ||
| 388 | /* Split into two parts */ | ||
| 389 | prm = mime_param_find(hdr, "boundary"); | ||
| 390 | if(!prm || !prm->param_value) { | ||
| 391 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); | ||
| 392 | ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_NO_MULTIPART_BOUNDARY); | ||
| 393 | return NULL; | ||
| 394 | } | ||
| 395 | ret = multi_split(bio, prm->param_value, &parts); | ||
| 396 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); | ||
| 397 | if(!ret || (sk_BIO_num(parts) != 2) ) { | ||
| 398 | ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_NO_MULTIPART_BODY_FAILURE); | ||
| 399 | sk_BIO_pop_free(parts, BIO_vfree); | ||
| 400 | return NULL; | ||
| 401 | } | ||
| 402 | |||
| 403 | /* Parse the signature piece */ | ||
| 404 | asnin = sk_BIO_value(parts, 1); | ||
| 405 | |||
| 406 | if (!(headers = mime_parse_hdr(asnin))) { | ||
| 407 | ASN1err(ASN1_F_SMIME_READ_ASN1,ASN1_R_MIME_SIG_PARSE_ERROR); | ||
| 408 | sk_BIO_pop_free(parts, BIO_vfree); | ||
| 409 | return NULL; | ||
| 410 | } | ||
| 411 | |||
| 412 | /* Get content type */ | ||
| 413 | |||
| 414 | if(!(hdr = mime_hdr_find(headers, "content-type")) || | ||
| 415 | !hdr->value) { | ||
| 416 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); | ||
| 417 | ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_NO_SIG_CONTENT_TYPE); | ||
| 418 | return NULL; | ||
| 419 | } | ||
| 420 | |||
| 421 | if(strcmp(hdr->value, "application/x-pkcs7-signature") && | ||
| 422 | strcmp(hdr->value, "application/pkcs7-signature")) { | ||
| 423 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); | ||
| 424 | ASN1err(ASN1_F_SMIME_READ_ASN1,ASN1_R_SIG_INVALID_MIME_TYPE); | ||
| 425 | ERR_add_error_data(2, "type: ", hdr->value); | ||
| 426 | sk_BIO_pop_free(parts, BIO_vfree); | ||
| 427 | return NULL; | ||
| 428 | } | ||
| 429 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); | ||
| 430 | /* Read in ASN1 */ | ||
| 431 | if(!(val = b64_read_asn1(asnin, it))) { | ||
| 432 | ASN1err(ASN1_F_SMIME_READ_ASN1,ASN1_R_ASN1_SIG_PARSE_ERROR); | ||
| 433 | sk_BIO_pop_free(parts, BIO_vfree); | ||
| 434 | return NULL; | ||
| 435 | } | ||
| 436 | |||
| 437 | if(bcont) { | ||
| 438 | *bcont = sk_BIO_value(parts, 0); | ||
| 439 | BIO_free(asnin); | ||
| 440 | sk_BIO_free(parts); | ||
| 441 | } else sk_BIO_pop_free(parts, BIO_vfree); | ||
| 442 | return val; | ||
| 443 | } | ||
| 444 | |||
| 445 | /* OK, if not multipart/signed try opaque signature */ | ||
| 446 | |||
| 447 | if (strcmp (hdr->value, "application/x-pkcs7-mime") && | ||
| 448 | strcmp (hdr->value, "application/pkcs7-mime")) { | ||
| 449 | ASN1err(ASN1_F_SMIME_READ_ASN1,ASN1_R_INVALID_MIME_TYPE); | ||
| 450 | ERR_add_error_data(2, "type: ", hdr->value); | ||
| 451 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); | ||
| 452 | return NULL; | ||
| 453 | } | ||
| 454 | |||
| 455 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); | ||
| 456 | |||
| 457 | if(!(val = b64_read_asn1(bio, it))) { | ||
| 458 | ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_ASN1_PARSE_ERROR); | ||
| 459 | return NULL; | ||
| 460 | } | ||
| 461 | return val; | ||
| 462 | |||
| 463 | } | ||
| 464 | |||
| 465 | /* Copy text from one BIO to another making the output CRLF at EOL */ | ||
| 466 | int SMIME_crlf_copy(BIO *in, BIO *out, int flags) | ||
| 467 | { | ||
| 468 | BIO *bf; | ||
| 469 | char eol; | ||
| 470 | int len; | ||
| 471 | char linebuf[MAX_SMLEN]; | ||
| 472 | /* Buffer output so we don't write one line at a time. This is | ||
| 473 | * useful when streaming as we don't end up with one OCTET STRING | ||
| 474 | * per line. | ||
| 475 | */ | ||
| 476 | bf = BIO_new(BIO_f_buffer()); | ||
| 477 | if (!bf) | ||
| 478 | return 0; | ||
| 479 | out = BIO_push(bf, out); | ||
| 480 | if(flags & SMIME_BINARY) | ||
| 481 | { | ||
| 482 | while((len = BIO_read(in, linebuf, MAX_SMLEN)) > 0) | ||
| 483 | BIO_write(out, linebuf, len); | ||
| 484 | } | ||
| 485 | else | ||
| 486 | { | ||
| 487 | if(flags & SMIME_TEXT) | ||
| 488 | BIO_printf(out, "Content-Type: text/plain\r\n\r\n"); | ||
| 489 | while ((len = BIO_gets(in, linebuf, MAX_SMLEN)) > 0) | ||
| 490 | { | ||
| 491 | eol = strip_eol(linebuf, &len); | ||
| 492 | if (len) | ||
| 493 | BIO_write(out, linebuf, len); | ||
| 494 | if(eol) BIO_write(out, "\r\n", 2); | ||
| 495 | } | ||
| 496 | } | ||
| 497 | (void)BIO_flush(out); | ||
| 498 | BIO_pop(out); | ||
| 499 | BIO_free(bf); | ||
| 500 | return 1; | ||
| 501 | } | ||
| 502 | |||
| 503 | /* Strip off headers if they are text/plain */ | ||
| 504 | int SMIME_text(BIO *in, BIO *out) | ||
| 505 | { | ||
| 506 | char iobuf[4096]; | ||
| 507 | int len; | ||
| 508 | STACK_OF(MIME_HEADER) *headers; | ||
| 509 | MIME_HEADER *hdr; | ||
| 510 | |||
| 511 | if (!(headers = mime_parse_hdr(in))) { | ||
| 512 | ASN1err(ASN1_F_SMIME_TEXT,ASN1_R_MIME_PARSE_ERROR); | ||
| 513 | return 0; | ||
| 514 | } | ||
| 515 | if(!(hdr = mime_hdr_find(headers, "content-type")) || !hdr->value) { | ||
| 516 | ASN1err(ASN1_F_SMIME_TEXT,ASN1_R_MIME_NO_CONTENT_TYPE); | ||
| 517 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); | ||
| 518 | return 0; | ||
| 519 | } | ||
| 520 | if (strcmp (hdr->value, "text/plain")) { | ||
| 521 | ASN1err(ASN1_F_SMIME_TEXT,ASN1_R_INVALID_MIME_TYPE); | ||
| 522 | ERR_add_error_data(2, "type: ", hdr->value); | ||
| 523 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); | ||
| 524 | return 0; | ||
| 525 | } | ||
| 526 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); | ||
| 527 | while ((len = BIO_read(in, iobuf, sizeof(iobuf))) > 0) | ||
| 528 | BIO_write(out, iobuf, len); | ||
| 529 | if (len < 0) | ||
| 530 | return 0; | ||
| 531 | return 1; | ||
| 532 | } | ||
| 533 | |||
| 534 | /* Split a multipart/XXX message body into component parts: result is | ||
| 535 | * canonical parts in a STACK of bios | ||
| 536 | */ | ||
| 537 | |||
| 538 | static int multi_split(BIO *bio, char *bound, STACK_OF(BIO) **ret) | ||
| 539 | { | ||
| 540 | char linebuf[MAX_SMLEN]; | ||
| 541 | int len, blen; | ||
| 542 | int eol = 0, next_eol = 0; | ||
| 543 | BIO *bpart = NULL; | ||
| 544 | STACK_OF(BIO) *parts; | ||
| 545 | char state, part, first; | ||
| 546 | |||
| 547 | blen = strlen(bound); | ||
| 548 | part = 0; | ||
| 549 | state = 0; | ||
| 550 | first = 1; | ||
| 551 | parts = sk_BIO_new_null(); | ||
| 552 | *ret = parts; | ||
| 553 | while ((len = BIO_gets(bio, linebuf, MAX_SMLEN)) > 0) { | ||
| 554 | state = mime_bound_check(linebuf, len, bound, blen); | ||
| 555 | if(state == 1) { | ||
| 556 | first = 1; | ||
| 557 | part++; | ||
| 558 | } else if(state == 2) { | ||
| 559 | sk_BIO_push(parts, bpart); | ||
| 560 | return 1; | ||
| 561 | } else if(part) { | ||
| 562 | /* Strip CR+LF from linebuf */ | ||
| 563 | next_eol = strip_eol(linebuf, &len); | ||
| 564 | if(first) { | ||
| 565 | first = 0; | ||
| 566 | if(bpart) sk_BIO_push(parts, bpart); | ||
| 567 | bpart = BIO_new(BIO_s_mem()); | ||
| 568 | BIO_set_mem_eof_return(bpart, 0); | ||
| 569 | } else if (eol) | ||
| 570 | BIO_write(bpart, "\r\n", 2); | ||
| 571 | eol = next_eol; | ||
| 572 | if (len) | ||
| 573 | BIO_write(bpart, linebuf, len); | ||
| 574 | } | ||
| 575 | } | ||
| 576 | return 0; | ||
| 577 | } | ||
| 578 | |||
| 579 | /* This is the big one: parse MIME header lines up to message body */ | ||
| 580 | |||
| 581 | #define MIME_INVALID 0 | ||
| 582 | #define MIME_START 1 | ||
| 583 | #define MIME_TYPE 2 | ||
| 584 | #define MIME_NAME 3 | ||
| 585 | #define MIME_VALUE 4 | ||
| 586 | #define MIME_QUOTE 5 | ||
| 587 | #define MIME_COMMENT 6 | ||
| 588 | |||
| 589 | |||
| 590 | static STACK_OF(MIME_HEADER) *mime_parse_hdr(BIO *bio) | ||
| 591 | { | ||
| 592 | char *p, *q, c; | ||
| 593 | char *ntmp; | ||
| 594 | char linebuf[MAX_SMLEN]; | ||
| 595 | MIME_HEADER *mhdr = NULL; | ||
| 596 | STACK_OF(MIME_HEADER) *headers; | ||
| 597 | int len, state, save_state = 0; | ||
| 598 | |||
| 599 | headers = sk_MIME_HEADER_new(mime_hdr_cmp); | ||
| 600 | while ((len = BIO_gets(bio, linebuf, MAX_SMLEN)) > 0) { | ||
| 601 | /* If whitespace at line start then continuation line */ | ||
| 602 | if(mhdr && isspace((unsigned char)linebuf[0])) state = MIME_NAME; | ||
| 603 | else state = MIME_START; | ||
| 604 | ntmp = NULL; | ||
| 605 | /* Go through all characters */ | ||
| 606 | for(p = linebuf, q = linebuf; (c = *p) && (c!='\r') && (c!='\n'); p++) { | ||
| 607 | |||
| 608 | /* State machine to handle MIME headers | ||
| 609 | * if this looks horrible that's because it *is* | ||
| 610 | */ | ||
| 611 | |||
| 612 | switch(state) { | ||
| 613 | case MIME_START: | ||
| 614 | if(c == ':') { | ||
| 615 | state = MIME_TYPE; | ||
| 616 | *p = 0; | ||
| 617 | ntmp = strip_ends(q); | ||
| 618 | q = p + 1; | ||
| 619 | } | ||
| 620 | break; | ||
| 621 | |||
| 622 | case MIME_TYPE: | ||
| 623 | if(c == ';') { | ||
| 624 | mime_debug("Found End Value\n"); | ||
| 625 | *p = 0; | ||
| 626 | mhdr = mime_hdr_new(ntmp, strip_ends(q)); | ||
| 627 | sk_MIME_HEADER_push(headers, mhdr); | ||
| 628 | ntmp = NULL; | ||
| 629 | q = p + 1; | ||
| 630 | state = MIME_NAME; | ||
| 631 | } else if(c == '(') { | ||
| 632 | save_state = state; | ||
| 633 | state = MIME_COMMENT; | ||
| 634 | } | ||
| 635 | break; | ||
| 636 | |||
| 637 | case MIME_COMMENT: | ||
| 638 | if(c == ')') { | ||
| 639 | state = save_state; | ||
| 640 | } | ||
| 641 | break; | ||
| 642 | |||
| 643 | case MIME_NAME: | ||
| 644 | if(c == '=') { | ||
| 645 | state = MIME_VALUE; | ||
| 646 | *p = 0; | ||
| 647 | ntmp = strip_ends(q); | ||
| 648 | q = p + 1; | ||
| 649 | } | ||
| 650 | break ; | ||
| 651 | |||
| 652 | case MIME_VALUE: | ||
| 653 | if(c == ';') { | ||
| 654 | state = MIME_NAME; | ||
| 655 | *p = 0; | ||
| 656 | mime_hdr_addparam(mhdr, ntmp, strip_ends(q)); | ||
| 657 | ntmp = NULL; | ||
| 658 | q = p + 1; | ||
| 659 | } else if (c == '"') { | ||
| 660 | mime_debug("Found Quote\n"); | ||
| 661 | state = MIME_QUOTE; | ||
| 662 | } else if(c == '(') { | ||
| 663 | save_state = state; | ||
| 664 | state = MIME_COMMENT; | ||
| 665 | } | ||
| 666 | break; | ||
| 667 | |||
| 668 | case MIME_QUOTE: | ||
| 669 | if(c == '"') { | ||
| 670 | mime_debug("Found Match Quote\n"); | ||
| 671 | state = MIME_VALUE; | ||
| 672 | } | ||
| 673 | break; | ||
| 674 | } | ||
| 675 | } | ||
| 676 | |||
| 677 | if(state == MIME_TYPE) { | ||
| 678 | mhdr = mime_hdr_new(ntmp, strip_ends(q)); | ||
| 679 | sk_MIME_HEADER_push(headers, mhdr); | ||
| 680 | } else if(state == MIME_VALUE) | ||
| 681 | mime_hdr_addparam(mhdr, ntmp, strip_ends(q)); | ||
| 682 | if(p == linebuf) break; /* Blank line means end of headers */ | ||
| 683 | } | ||
| 684 | |||
| 685 | return headers; | ||
| 686 | |||
| 687 | } | ||
| 688 | |||
| 689 | static char *strip_ends(char *name) | ||
| 690 | { | ||
| 691 | return strip_end(strip_start(name)); | ||
| 692 | } | ||
| 693 | |||
| 694 | /* Strip a parameter of whitespace from start of param */ | ||
| 695 | static char *strip_start(char *name) | ||
| 696 | { | ||
| 697 | char *p, c; | ||
| 698 | /* Look for first non white space or quote */ | ||
| 699 | for(p = name; (c = *p) ;p++) { | ||
| 700 | if(c == '"') { | ||
| 701 | /* Next char is start of string if non null */ | ||
| 702 | if(p[1]) return p + 1; | ||
| 703 | /* Else null string */ | ||
| 704 | return NULL; | ||
| 705 | } | ||
| 706 | if(!isspace((unsigned char)c)) return p; | ||
| 707 | } | ||
| 708 | return NULL; | ||
| 709 | } | ||
| 710 | |||
| 711 | /* As above but strip from end of string : maybe should handle brackets? */ | ||
| 712 | static char *strip_end(char *name) | ||
| 713 | { | ||
| 714 | char *p, c; | ||
| 715 | if(!name) return NULL; | ||
| 716 | /* Look for first non white space or quote */ | ||
| 717 | for(p = name + strlen(name) - 1; p >= name ;p--) { | ||
| 718 | c = *p; | ||
| 719 | if(c == '"') { | ||
| 720 | if(p - 1 == name) return NULL; | ||
| 721 | *p = 0; | ||
| 722 | return name; | ||
| 723 | } | ||
| 724 | if(isspace((unsigned char)c)) *p = 0; | ||
| 725 | else return name; | ||
| 726 | } | ||
| 727 | return NULL; | ||
| 728 | } | ||
| 729 | |||
| 730 | static MIME_HEADER *mime_hdr_new(char *name, char *value) | ||
| 731 | { | ||
| 732 | MIME_HEADER *mhdr; | ||
| 733 | char *tmpname, *tmpval, *p; | ||
| 734 | int c; | ||
| 735 | if(name) { | ||
| 736 | if(!(tmpname = BUF_strdup(name))) return NULL; | ||
| 737 | for(p = tmpname ; *p; p++) { | ||
| 738 | c = *p; | ||
| 739 | if(isupper(c)) { | ||
| 740 | c = tolower(c); | ||
| 741 | *p = c; | ||
| 742 | } | ||
| 743 | } | ||
| 744 | } else tmpname = NULL; | ||
| 745 | if(value) { | ||
| 746 | if(!(tmpval = BUF_strdup(value))) return NULL; | ||
| 747 | for(p = tmpval ; *p; p++) { | ||
| 748 | c = *p; | ||
| 749 | if(isupper(c)) { | ||
| 750 | c = tolower(c); | ||
| 751 | *p = c; | ||
| 752 | } | ||
| 753 | } | ||
| 754 | } else tmpval = NULL; | ||
| 755 | mhdr = (MIME_HEADER *) OPENSSL_malloc(sizeof(MIME_HEADER)); | ||
| 756 | if(!mhdr) return NULL; | ||
| 757 | mhdr->name = tmpname; | ||
| 758 | mhdr->value = tmpval; | ||
| 759 | if(!(mhdr->params = sk_MIME_PARAM_new(mime_param_cmp))) return NULL; | ||
| 760 | return mhdr; | ||
| 761 | } | ||
| 762 | |||
| 763 | static int mime_hdr_addparam(MIME_HEADER *mhdr, char *name, char *value) | ||
| 764 | { | ||
| 765 | char *tmpname, *tmpval, *p; | ||
| 766 | int c; | ||
| 767 | MIME_PARAM *mparam; | ||
| 768 | if(name) { | ||
| 769 | tmpname = BUF_strdup(name); | ||
| 770 | if(!tmpname) return 0; | ||
| 771 | for(p = tmpname ; *p; p++) { | ||
| 772 | c = *p; | ||
| 773 | if(isupper(c)) { | ||
| 774 | c = tolower(c); | ||
| 775 | *p = c; | ||
| 776 | } | ||
| 777 | } | ||
| 778 | } else tmpname = NULL; | ||
| 779 | if(value) { | ||
| 780 | tmpval = BUF_strdup(value); | ||
| 781 | if(!tmpval) return 0; | ||
| 782 | } else tmpval = NULL; | ||
| 783 | /* Parameter values are case sensitive so leave as is */ | ||
| 784 | mparam = (MIME_PARAM *) OPENSSL_malloc(sizeof(MIME_PARAM)); | ||
| 785 | if(!mparam) return 0; | ||
| 786 | mparam->param_name = tmpname; | ||
| 787 | mparam->param_value = tmpval; | ||
| 788 | sk_MIME_PARAM_push(mhdr->params, mparam); | ||
| 789 | return 1; | ||
| 790 | } | ||
| 791 | |||
| 792 | static int mime_hdr_cmp(const MIME_HEADER * const *a, | ||
| 793 | const MIME_HEADER * const *b) | ||
| 794 | { | ||
| 795 | return(strcmp((*a)->name, (*b)->name)); | ||
| 796 | } | ||
| 797 | |||
| 798 | static int mime_param_cmp(const MIME_PARAM * const *a, | ||
| 799 | const MIME_PARAM * const *b) | ||
| 800 | { | ||
| 801 | return(strcmp((*a)->param_name, (*b)->param_name)); | ||
| 802 | } | ||
| 803 | |||
| 804 | /* Find a header with a given name (if possible) */ | ||
| 805 | |||
| 806 | static MIME_HEADER *mime_hdr_find(STACK_OF(MIME_HEADER) *hdrs, char *name) | ||
| 807 | { | ||
| 808 | MIME_HEADER htmp; | ||
| 809 | int idx; | ||
| 810 | htmp.name = name; | ||
| 811 | idx = sk_MIME_HEADER_find(hdrs, &htmp); | ||
| 812 | if(idx < 0) return NULL; | ||
| 813 | return sk_MIME_HEADER_value(hdrs, idx); | ||
| 814 | } | ||
| 815 | |||
| 816 | static MIME_PARAM *mime_param_find(MIME_HEADER *hdr, char *name) | ||
| 817 | { | ||
| 818 | MIME_PARAM param; | ||
| 819 | int idx; | ||
| 820 | param.param_name = name; | ||
| 821 | idx = sk_MIME_PARAM_find(hdr->params, ¶m); | ||
| 822 | if(idx < 0) return NULL; | ||
| 823 | return sk_MIME_PARAM_value(hdr->params, idx); | ||
| 824 | } | ||
| 825 | |||
| 826 | static void mime_hdr_free(MIME_HEADER *hdr) | ||
| 827 | { | ||
| 828 | if(hdr->name) OPENSSL_free(hdr->name); | ||
| 829 | if(hdr->value) OPENSSL_free(hdr->value); | ||
| 830 | if(hdr->params) sk_MIME_PARAM_pop_free(hdr->params, mime_param_free); | ||
| 831 | OPENSSL_free(hdr); | ||
| 832 | } | ||
| 833 | |||
| 834 | static void mime_param_free(MIME_PARAM *param) | ||
| 835 | { | ||
| 836 | if(param->param_name) OPENSSL_free(param->param_name); | ||
| 837 | if(param->param_value) OPENSSL_free(param->param_value); | ||
| 838 | OPENSSL_free(param); | ||
| 839 | } | ||
| 840 | |||
| 841 | /* Check for a multipart boundary. Returns: | ||
| 842 | * 0 : no boundary | ||
| 843 | * 1 : part boundary | ||
| 844 | * 2 : final boundary | ||
| 845 | */ | ||
| 846 | static int mime_bound_check(char *line, int linelen, char *bound, int blen) | ||
| 847 | { | ||
| 848 | if(linelen == -1) linelen = strlen(line); | ||
| 849 | if(blen == -1) blen = strlen(bound); | ||
| 850 | /* Quickly eliminate if line length too short */ | ||
| 851 | if(blen + 2 > linelen) return 0; | ||
| 852 | /* Check for part boundary */ | ||
| 853 | if(!strncmp(line, "--", 2) && !strncmp(line + 2, bound, blen)) { | ||
| 854 | if(!strncmp(line + blen + 2, "--", 2)) return 2; | ||
| 855 | else return 1; | ||
| 856 | } | ||
| 857 | return 0; | ||
| 858 | } | ||
| 859 | |||
| 860 | static int strip_eol(char *linebuf, int *plen) | ||
| 861 | { | ||
| 862 | int len = *plen; | ||
| 863 | char *p, c; | ||
| 864 | int is_eol = 0; | ||
| 865 | p = linebuf + len - 1; | ||
| 866 | for (p = linebuf + len - 1; len > 0; len--, p--) | ||
| 867 | { | ||
| 868 | c = *p; | ||
| 869 | if (c == '\n') | ||
| 870 | is_eol = 1; | ||
| 871 | else if (c != '\r') | ||
| 872 | break; | ||
| 873 | } | ||
| 874 | *plen = len; | ||
| 875 | return is_eol; | ||
| 876 | } | ||
diff --git a/src/lib/libcrypto/asn1/asn_moid.c b/src/lib/libcrypto/asn1/asn_moid.c new file mode 100644 index 0000000000..9132350f10 --- /dev/null +++ b/src/lib/libcrypto/asn1/asn_moid.c | |||
| @@ -0,0 +1,160 @@ | |||
| 1 | /* asn_moid.c */ | ||
| 2 | /* Written by Stephen Henson (shenson@bigfoot.com) for the OpenSSL | ||
| 3 | * project 2001. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 2001-2004 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include <ctype.h> | ||
| 61 | #include <openssl/crypto.h> | ||
| 62 | #include "cryptlib.h" | ||
| 63 | #include <openssl/conf.h> | ||
| 64 | #include <openssl/dso.h> | ||
| 65 | #include <openssl/x509.h> | ||
| 66 | |||
| 67 | /* Simple ASN1 OID module: add all objects in a given section */ | ||
| 68 | |||
| 69 | static int do_create(char *value, char *name); | ||
| 70 | |||
| 71 | static int oid_module_init(CONF_IMODULE *md, const CONF *cnf) | ||
| 72 | { | ||
| 73 | int i; | ||
| 74 | const char *oid_section; | ||
| 75 | STACK_OF(CONF_VALUE) *sktmp; | ||
| 76 | CONF_VALUE *oval; | ||
| 77 | oid_section = CONF_imodule_get_value(md); | ||
| 78 | if(!(sktmp = NCONF_get_section(cnf, oid_section))) | ||
| 79 | { | ||
| 80 | ASN1err(ASN1_F_OID_MODULE_INIT, ASN1_R_ERROR_LOADING_SECTION); | ||
| 81 | return 0; | ||
| 82 | } | ||
| 83 | for(i = 0; i < sk_CONF_VALUE_num(sktmp); i++) | ||
| 84 | { | ||
| 85 | oval = sk_CONF_VALUE_value(sktmp, i); | ||
| 86 | if(!do_create(oval->value, oval->name)) | ||
| 87 | { | ||
| 88 | ASN1err(ASN1_F_OID_MODULE_INIT, ASN1_R_ADDING_OBJECT); | ||
| 89 | return 0; | ||
| 90 | } | ||
| 91 | } | ||
| 92 | return 1; | ||
| 93 | } | ||
| 94 | |||
| 95 | static void oid_module_finish(CONF_IMODULE *md) | ||
| 96 | { | ||
| 97 | OBJ_cleanup(); | ||
| 98 | } | ||
| 99 | |||
| 100 | void ASN1_add_oid_module(void) | ||
| 101 | { | ||
| 102 | CONF_module_add("oid_section", oid_module_init, oid_module_finish); | ||
| 103 | } | ||
| 104 | |||
| 105 | /* Create an OID based on a name value pair. Accept two formats. | ||
| 106 | * shortname = 1.2.3.4 | ||
| 107 | * shortname = some long name, 1.2.3.4 | ||
| 108 | */ | ||
| 109 | |||
| 110 | |||
| 111 | static int do_create(char *value, char *name) | ||
| 112 | { | ||
| 113 | int nid; | ||
| 114 | ASN1_OBJECT *oid; | ||
| 115 | char *ln, *ostr, *p, *lntmp; | ||
| 116 | p = strrchr(value, ','); | ||
| 117 | if (!p) | ||
| 118 | { | ||
| 119 | ln = name; | ||
| 120 | ostr = value; | ||
| 121 | } | ||
| 122 | else | ||
| 123 | { | ||
| 124 | ln = NULL; | ||
| 125 | ostr = p + 1; | ||
| 126 | if (!*ostr) | ||
| 127 | return 0; | ||
| 128 | while(isspace((unsigned char)*ostr)) ostr++; | ||
| 129 | } | ||
| 130 | |||
| 131 | nid = OBJ_create(ostr, name, ln); | ||
| 132 | |||
| 133 | if (nid == NID_undef) | ||
| 134 | return 0; | ||
| 135 | |||
| 136 | if (p) | ||
| 137 | { | ||
| 138 | ln = value; | ||
| 139 | while(isspace((unsigned char)*ln)) ln++; | ||
| 140 | p--; | ||
| 141 | while(isspace((unsigned char)*p)) | ||
| 142 | { | ||
| 143 | if (p == ln) | ||
| 144 | return 0; | ||
| 145 | p--; | ||
| 146 | } | ||
| 147 | p++; | ||
| 148 | lntmp = OPENSSL_malloc((p - ln) + 1); | ||
| 149 | if (lntmp == NULL) | ||
| 150 | return 0; | ||
| 151 | memcpy(lntmp, ln, p - ln); | ||
| 152 | lntmp[p - ln] = 0; | ||
| 153 | oid = OBJ_nid2obj(nid); | ||
| 154 | oid->ln = lntmp; | ||
| 155 | } | ||
| 156 | |||
| 157 | return 1; | ||
| 158 | } | ||
| 159 | |||
| 160 | |||
diff --git a/src/lib/libcrypto/asn1/asn_pack.c b/src/lib/libcrypto/asn1/asn_pack.c new file mode 100644 index 0000000000..e8b671b7b5 --- /dev/null +++ b/src/lib/libcrypto/asn1/asn_pack.c | |||
| @@ -0,0 +1,191 @@ | |||
| 1 | /* asn_pack.c */ | ||
| 2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
| 3 | * project 1999. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/asn1.h> | ||
| 62 | |||
| 63 | #ifndef NO_ASN1_OLD | ||
| 64 | |||
| 65 | /* ASN1 packing and unpacking functions */ | ||
| 66 | |||
| 67 | /* Turn an ASN1 encoded SEQUENCE OF into a STACK of structures */ | ||
| 68 | |||
| 69 | STACK *ASN1_seq_unpack(const unsigned char *buf, int len, | ||
| 70 | d2i_of_void *d2i,void (*free_func)(void *)) | ||
| 71 | { | ||
| 72 | STACK *sk; | ||
| 73 | const unsigned char *pbuf; | ||
| 74 | pbuf = buf; | ||
| 75 | if (!(sk = d2i_ASN1_SET(NULL, &pbuf, len, d2i, free_func, | ||
| 76 | V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL))) | ||
| 77 | ASN1err(ASN1_F_ASN1_SEQ_UNPACK,ASN1_R_DECODE_ERROR); | ||
| 78 | return sk; | ||
| 79 | } | ||
| 80 | |||
| 81 | /* Turn a STACK structures into an ASN1 encoded SEQUENCE OF structure in a | ||
| 82 | * OPENSSL_malloc'ed buffer | ||
| 83 | */ | ||
| 84 | |||
| 85 | unsigned char *ASN1_seq_pack(STACK *safes, i2d_of_void *i2d, | ||
| 86 | unsigned char **buf, int *len) | ||
| 87 | { | ||
| 88 | int safelen; | ||
| 89 | unsigned char *safe, *p; | ||
| 90 | if (!(safelen = i2d_ASN1_SET(safes, NULL, i2d, V_ASN1_SEQUENCE, | ||
| 91 | V_ASN1_UNIVERSAL, IS_SEQUENCE))) { | ||
| 92 | ASN1err(ASN1_F_ASN1_SEQ_PACK,ASN1_R_ENCODE_ERROR); | ||
| 93 | return NULL; | ||
| 94 | } | ||
| 95 | if (!(safe = OPENSSL_malloc (safelen))) { | ||
| 96 | ASN1err(ASN1_F_ASN1_SEQ_PACK,ERR_R_MALLOC_FAILURE); | ||
| 97 | return NULL; | ||
| 98 | } | ||
| 99 | p = safe; | ||
| 100 | i2d_ASN1_SET(safes, &p, i2d, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL, | ||
| 101 | IS_SEQUENCE); | ||
| 102 | if (len) *len = safelen; | ||
| 103 | if (buf) *buf = safe; | ||
| 104 | return safe; | ||
| 105 | } | ||
| 106 | |||
| 107 | /* Extract an ASN1 object from an ASN1_STRING */ | ||
| 108 | |||
| 109 | void *ASN1_unpack_string(ASN1_STRING *oct, d2i_of_void *d2i) | ||
| 110 | { | ||
| 111 | const unsigned char *p; | ||
| 112 | char *ret; | ||
| 113 | |||
| 114 | p = oct->data; | ||
| 115 | if(!(ret = d2i(NULL, &p, oct->length))) | ||
| 116 | ASN1err(ASN1_F_ASN1_UNPACK_STRING,ASN1_R_DECODE_ERROR); | ||
| 117 | return ret; | ||
| 118 | } | ||
| 119 | |||
| 120 | /* Pack an ASN1 object into an ASN1_STRING */ | ||
| 121 | |||
| 122 | ASN1_STRING *ASN1_pack_string(void *obj, i2d_of_void *i2d, ASN1_STRING **oct) | ||
| 123 | { | ||
| 124 | unsigned char *p; | ||
| 125 | ASN1_STRING *octmp; | ||
| 126 | |||
| 127 | if (!oct || !*oct) { | ||
| 128 | if (!(octmp = ASN1_STRING_new ())) { | ||
| 129 | ASN1err(ASN1_F_ASN1_PACK_STRING,ERR_R_MALLOC_FAILURE); | ||
| 130 | return NULL; | ||
| 131 | } | ||
| 132 | if (oct) *oct = octmp; | ||
| 133 | } else octmp = *oct; | ||
| 134 | |||
| 135 | if (!(octmp->length = i2d(obj, NULL))) { | ||
| 136 | ASN1err(ASN1_F_ASN1_PACK_STRING,ASN1_R_ENCODE_ERROR); | ||
| 137 | return NULL; | ||
| 138 | } | ||
| 139 | if (!(p = OPENSSL_malloc (octmp->length))) { | ||
| 140 | ASN1err(ASN1_F_ASN1_PACK_STRING,ERR_R_MALLOC_FAILURE); | ||
| 141 | return NULL; | ||
| 142 | } | ||
| 143 | octmp->data = p; | ||
| 144 | i2d (obj, &p); | ||
| 145 | return octmp; | ||
| 146 | } | ||
| 147 | |||
| 148 | #endif | ||
| 149 | |||
| 150 | /* ASN1_ITEM versions of the above */ | ||
| 151 | |||
| 152 | ASN1_STRING *ASN1_item_pack(void *obj, const ASN1_ITEM *it, ASN1_STRING **oct) | ||
| 153 | { | ||
| 154 | ASN1_STRING *octmp; | ||
| 155 | |||
| 156 | if (!oct || !*oct) { | ||
| 157 | if (!(octmp = ASN1_STRING_new ())) { | ||
| 158 | ASN1err(ASN1_F_ASN1_ITEM_PACK,ERR_R_MALLOC_FAILURE); | ||
| 159 | return NULL; | ||
| 160 | } | ||
| 161 | if (oct) *oct = octmp; | ||
| 162 | } else octmp = *oct; | ||
| 163 | |||
| 164 | if(octmp->data) { | ||
| 165 | OPENSSL_free(octmp->data); | ||
| 166 | octmp->data = NULL; | ||
| 167 | } | ||
| 168 | |||
| 169 | if (!(octmp->length = ASN1_item_i2d(obj, &octmp->data, it))) { | ||
| 170 | ASN1err(ASN1_F_ASN1_ITEM_PACK,ASN1_R_ENCODE_ERROR); | ||
| 171 | return NULL; | ||
| 172 | } | ||
| 173 | if (!octmp->data) { | ||
| 174 | ASN1err(ASN1_F_ASN1_ITEM_PACK,ERR_R_MALLOC_FAILURE); | ||
| 175 | return NULL; | ||
| 176 | } | ||
| 177 | return octmp; | ||
| 178 | } | ||
| 179 | |||
| 180 | /* Extract an ASN1 object from an ASN1_STRING */ | ||
| 181 | |||
| 182 | void *ASN1_item_unpack(ASN1_STRING *oct, const ASN1_ITEM *it) | ||
| 183 | { | ||
| 184 | const unsigned char *p; | ||
| 185 | void *ret; | ||
| 186 | |||
| 187 | p = oct->data; | ||
| 188 | if(!(ret = ASN1_item_d2i(NULL, &p, oct->length, it))) | ||
| 189 | ASN1err(ASN1_F_ASN1_ITEM_UNPACK,ASN1_R_DECODE_ERROR); | ||
| 190 | return ret; | ||
| 191 | } | ||
diff --git a/src/lib/libcrypto/asn1/charmap.h b/src/lib/libcrypto/asn1/charmap.h new file mode 100644 index 0000000000..bd020a9562 --- /dev/null +++ b/src/lib/libcrypto/asn1/charmap.h | |||
| @@ -0,0 +1,15 @@ | |||
| 1 | /* Auto generated with chartype.pl script. | ||
| 2 | * Mask of various character properties | ||
| 3 | */ | ||
| 4 | |||
| 5 | static unsigned char char_type[] = { | ||
| 6 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | ||
| 7 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | ||
| 8 | 120, 0, 1,40, 0, 0, 0,16,16,16, 0,25,25,16,16,16, | ||
| 9 | 16,16,16,16,16,16,16,16,16,16,16, 9, 9,16, 9,16, | ||
| 10 | 0,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, | ||
| 11 | 16,16,16,16,16,16,16,16,16,16,16, 0, 1, 0, 0, 0, | ||
| 12 | 0,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, | ||
| 13 | 16,16,16,16,16,16,16,16,16,16,16, 0, 0, 0, 0, 2 | ||
| 14 | }; | ||
| 15 | |||
diff --git a/src/lib/libcrypto/asn1/charmap.pl b/src/lib/libcrypto/asn1/charmap.pl new file mode 100644 index 0000000000..2875c59867 --- /dev/null +++ b/src/lib/libcrypto/asn1/charmap.pl | |||
| @@ -0,0 +1,80 @@ | |||
| 1 | #!/usr/local/bin/perl -w | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | |||
| 5 | my ($i, @arr); | ||
| 6 | |||
| 7 | # Set up an array with the type of ASCII characters | ||
| 8 | # Each set bit represents a character property. | ||
| 9 | |||
| 10 | # RFC2253 character properties | ||
| 11 | my $RFC2253_ESC = 1; # Character escaped with \ | ||
| 12 | my $ESC_CTRL = 2; # Escaped control character | ||
| 13 | # These are used with RFC1779 quoting using " | ||
| 14 | my $NOESC_QUOTE = 8; # Not escaped if quoted | ||
| 15 | my $PSTRING_CHAR = 0x10; # Valid PrintableString character | ||
| 16 | my $RFC2253_FIRST_ESC = 0x20; # Escaped with \ if first character | ||
| 17 | my $RFC2253_LAST_ESC = 0x40; # Escaped with \ if last character | ||
| 18 | |||
| 19 | for($i = 0; $i < 128; $i++) { | ||
| 20 | # Set the RFC2253 escape characters (control) | ||
| 21 | $arr[$i] = 0; | ||
| 22 | if(($i < 32) || ($i > 126)) { | ||
| 23 | $arr[$i] |= $ESC_CTRL; | ||
| 24 | } | ||
| 25 | |||
| 26 | # Some PrintableString characters | ||
| 27 | if( ( ( $i >= ord("a")) && ( $i <= ord("z")) ) | ||
| 28 | || ( ( $i >= ord("A")) && ( $i <= ord("Z")) ) | ||
| 29 | || ( ( $i >= ord("0")) && ( $i <= ord("9")) ) ) { | ||
| 30 | $arr[$i] |= $PSTRING_CHAR; | ||
| 31 | } | ||
| 32 | } | ||
| 33 | |||
| 34 | # Now setup the rest | ||
| 35 | |||
| 36 | # Remaining RFC2253 escaped characters | ||
| 37 | |||
| 38 | $arr[ord(" ")] |= $NOESC_QUOTE | $RFC2253_FIRST_ESC | $RFC2253_LAST_ESC; | ||
| 39 | $arr[ord("#")] |= $NOESC_QUOTE | $RFC2253_FIRST_ESC; | ||
| 40 | |||
| 41 | $arr[ord(",")] |= $NOESC_QUOTE | $RFC2253_ESC; | ||
| 42 | $arr[ord("+")] |= $NOESC_QUOTE | $RFC2253_ESC; | ||
| 43 | $arr[ord("\"")] |= $RFC2253_ESC; | ||
| 44 | $arr[ord("\\")] |= $RFC2253_ESC; | ||
| 45 | $arr[ord("<")] |= $NOESC_QUOTE | $RFC2253_ESC; | ||
| 46 | $arr[ord(">")] |= $NOESC_QUOTE | $RFC2253_ESC; | ||
| 47 | $arr[ord(";")] |= $NOESC_QUOTE | $RFC2253_ESC; | ||
| 48 | |||
| 49 | # Remaining PrintableString characters | ||
| 50 | |||
| 51 | $arr[ord(" ")] |= $PSTRING_CHAR; | ||
| 52 | $arr[ord("'")] |= $PSTRING_CHAR; | ||
| 53 | $arr[ord("(")] |= $PSTRING_CHAR; | ||
| 54 | $arr[ord(")")] |= $PSTRING_CHAR; | ||
| 55 | $arr[ord("+")] |= $PSTRING_CHAR; | ||
| 56 | $arr[ord(",")] |= $PSTRING_CHAR; | ||
| 57 | $arr[ord("-")] |= $PSTRING_CHAR; | ||
| 58 | $arr[ord(".")] |= $PSTRING_CHAR; | ||
| 59 | $arr[ord("/")] |= $PSTRING_CHAR; | ||
| 60 | $arr[ord(":")] |= $PSTRING_CHAR; | ||
| 61 | $arr[ord("=")] |= $PSTRING_CHAR; | ||
| 62 | $arr[ord("?")] |= $PSTRING_CHAR; | ||
| 63 | |||
| 64 | # Now generate the C code | ||
| 65 | |||
| 66 | print <<EOF; | ||
| 67 | /* Auto generated with chartype.pl script. | ||
| 68 | * Mask of various character properties | ||
| 69 | */ | ||
| 70 | |||
| 71 | static unsigned char char_type[] = { | ||
| 72 | EOF | ||
| 73 | |||
| 74 | for($i = 0; $i < 128; $i++) { | ||
| 75 | print("\n") if($i && (($i % 16) == 0)); | ||
| 76 | printf("%2d", $arr[$i]); | ||
| 77 | print(",") if ($i != 127); | ||
| 78 | } | ||
| 79 | print("\n};\n\n"); | ||
| 80 | |||
diff --git a/src/lib/libcrypto/asn1/d2i_pr.c b/src/lib/libcrypto/asn1/d2i_pr.c new file mode 100644 index 0000000000..207ccda5ac --- /dev/null +++ b/src/lib/libcrypto/asn1/d2i_pr.c | |||
| @@ -0,0 +1,161 @@ | |||
| 1 | /* crypto/asn1/d2i_pr.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/bn.h> | ||
| 62 | #include <openssl/evp.h> | ||
| 63 | #include <openssl/objects.h> | ||
| 64 | #include <openssl/asn1.h> | ||
| 65 | #ifndef OPENSSL_NO_RSA | ||
| 66 | #include <openssl/rsa.h> | ||
| 67 | #endif | ||
| 68 | #ifndef OPENSSL_NO_DSA | ||
| 69 | #include <openssl/dsa.h> | ||
| 70 | #endif | ||
| 71 | #ifndef OPENSSL_NO_EC | ||
| 72 | #include <openssl/ec.h> | ||
| 73 | #endif | ||
| 74 | |||
| 75 | EVP_PKEY *d2i_PrivateKey(int type, EVP_PKEY **a, const unsigned char **pp, | ||
| 76 | long length) | ||
| 77 | { | ||
| 78 | EVP_PKEY *ret; | ||
| 79 | |||
| 80 | if ((a == NULL) || (*a == NULL)) | ||
| 81 | { | ||
| 82 | if ((ret=EVP_PKEY_new()) == NULL) | ||
| 83 | { | ||
| 84 | ASN1err(ASN1_F_D2I_PRIVATEKEY,ERR_R_EVP_LIB); | ||
| 85 | return(NULL); | ||
| 86 | } | ||
| 87 | } | ||
| 88 | else ret= *a; | ||
| 89 | |||
| 90 | ret->save_type=type; | ||
| 91 | ret->type=EVP_PKEY_type(type); | ||
| 92 | switch (ret->type) | ||
| 93 | { | ||
| 94 | #ifndef OPENSSL_NO_RSA | ||
| 95 | case EVP_PKEY_RSA: | ||
| 96 | if ((ret->pkey.rsa=d2i_RSAPrivateKey(NULL, | ||
| 97 | (const unsigned char **)pp,length)) == NULL) /* TMP UGLY CAST */ | ||
| 98 | { | ||
| 99 | ASN1err(ASN1_F_D2I_PRIVATEKEY,ERR_R_ASN1_LIB); | ||
| 100 | goto err; | ||
| 101 | } | ||
| 102 | break; | ||
| 103 | #endif | ||
| 104 | #ifndef OPENSSL_NO_DSA | ||
| 105 | case EVP_PKEY_DSA: | ||
| 106 | if ((ret->pkey.dsa=d2i_DSAPrivateKey(NULL, | ||
| 107 | (const unsigned char **)pp,length)) == NULL) /* TMP UGLY CAST */ | ||
| 108 | { | ||
| 109 | ASN1err(ASN1_F_D2I_PRIVATEKEY,ERR_R_ASN1_LIB); | ||
| 110 | goto err; | ||
| 111 | } | ||
| 112 | break; | ||
| 113 | #endif | ||
| 114 | #ifndef OPENSSL_NO_EC | ||
| 115 | case EVP_PKEY_EC: | ||
| 116 | if ((ret->pkey.ec = d2i_ECPrivateKey(NULL, | ||
| 117 | (const unsigned char **)pp, length)) == NULL) | ||
| 118 | { | ||
| 119 | ASN1err(ASN1_F_D2I_PRIVATEKEY, ERR_R_ASN1_LIB); | ||
| 120 | goto err; | ||
| 121 | } | ||
| 122 | break; | ||
| 123 | #endif | ||
| 124 | default: | ||
| 125 | ASN1err(ASN1_F_D2I_PRIVATEKEY,ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE); | ||
| 126 | goto err; | ||
| 127 | /* break; */ | ||
| 128 | } | ||
| 129 | if (a != NULL) (*a)=ret; | ||
| 130 | return(ret); | ||
| 131 | err: | ||
| 132 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) EVP_PKEY_free(ret); | ||
| 133 | return(NULL); | ||
| 134 | } | ||
| 135 | |||
| 136 | /* This works like d2i_PrivateKey() except it automatically works out the type */ | ||
| 137 | |||
| 138 | EVP_PKEY *d2i_AutoPrivateKey(EVP_PKEY **a, const unsigned char **pp, | ||
| 139 | long length) | ||
| 140 | { | ||
| 141 | STACK_OF(ASN1_TYPE) *inkey; | ||
| 142 | const unsigned char *p; | ||
| 143 | int keytype; | ||
| 144 | p = *pp; | ||
| 145 | /* Dirty trick: read in the ASN1 data into a STACK_OF(ASN1_TYPE): | ||
| 146 | * by analyzing it we can determine the passed structure: this | ||
| 147 | * assumes the input is surrounded by an ASN1 SEQUENCE. | ||
| 148 | */ | ||
| 149 | inkey = d2i_ASN1_SET_OF_ASN1_TYPE(NULL, &p, length, d2i_ASN1_TYPE, | ||
| 150 | ASN1_TYPE_free, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL); | ||
| 151 | /* Since we only need to discern "traditional format" RSA and DSA | ||
| 152 | * keys we can just count the elements. | ||
| 153 | */ | ||
| 154 | if(sk_ASN1_TYPE_num(inkey) == 6) | ||
| 155 | keytype = EVP_PKEY_DSA; | ||
| 156 | else if (sk_ASN1_TYPE_num(inkey) == 4) | ||
| 157 | keytype = EVP_PKEY_EC; | ||
| 158 | else keytype = EVP_PKEY_RSA; | ||
| 159 | sk_ASN1_TYPE_pop_free(inkey, ASN1_TYPE_free); | ||
| 160 | return d2i_PrivateKey(keytype, a, pp, length); | ||
| 161 | } | ||
diff --git a/src/lib/libcrypto/asn1/d2i_pu.c b/src/lib/libcrypto/asn1/d2i_pu.c new file mode 100644 index 0000000000..3694f51a8c --- /dev/null +++ b/src/lib/libcrypto/asn1/d2i_pu.c | |||
| @@ -0,0 +1,135 @@ | |||
| 1 | /* crypto/asn1/d2i_pu.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/bn.h> | ||
| 62 | #include <openssl/evp.h> | ||
| 63 | #include <openssl/objects.h> | ||
| 64 | #include <openssl/asn1.h> | ||
| 65 | #ifndef OPENSSL_NO_RSA | ||
| 66 | #include <openssl/rsa.h> | ||
| 67 | #endif | ||
| 68 | #ifndef OPENSSL_NO_DSA | ||
| 69 | #include <openssl/dsa.h> | ||
| 70 | #endif | ||
| 71 | #ifndef OPENSSL_NO_EC | ||
| 72 | #include <openssl/ec.h> | ||
| 73 | #endif | ||
| 74 | |||
| 75 | EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **a, const unsigned char **pp, | ||
| 76 | long length) | ||
| 77 | { | ||
| 78 | EVP_PKEY *ret; | ||
| 79 | |||
| 80 | if ((a == NULL) || (*a == NULL)) | ||
| 81 | { | ||
| 82 | if ((ret=EVP_PKEY_new()) == NULL) | ||
| 83 | { | ||
| 84 | ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_EVP_LIB); | ||
| 85 | return(NULL); | ||
| 86 | } | ||
| 87 | } | ||
| 88 | else ret= *a; | ||
| 89 | |||
| 90 | ret->save_type=type; | ||
| 91 | ret->type=EVP_PKEY_type(type); | ||
| 92 | switch (ret->type) | ||
| 93 | { | ||
| 94 | #ifndef OPENSSL_NO_RSA | ||
| 95 | case EVP_PKEY_RSA: | ||
| 96 | if ((ret->pkey.rsa=d2i_RSAPublicKey(NULL, | ||
| 97 | (const unsigned char **)pp,length)) == NULL) /* TMP UGLY CAST */ | ||
| 98 | { | ||
| 99 | ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_ASN1_LIB); | ||
| 100 | goto err; | ||
| 101 | } | ||
| 102 | break; | ||
| 103 | #endif | ||
| 104 | #ifndef OPENSSL_NO_DSA | ||
| 105 | case EVP_PKEY_DSA: | ||
| 106 | if (!d2i_DSAPublicKey(&(ret->pkey.dsa), | ||
| 107 | (const unsigned char **)pp,length)) /* TMP UGLY CAST */ | ||
| 108 | { | ||
| 109 | ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_ASN1_LIB); | ||
| 110 | goto err; | ||
| 111 | } | ||
| 112 | break; | ||
| 113 | #endif | ||
| 114 | #ifndef OPENSSL_NO_EC | ||
| 115 | case EVP_PKEY_EC: | ||
| 116 | if (!o2i_ECPublicKey(&(ret->pkey.ec), | ||
| 117 | (const unsigned char **)pp, length)) | ||
| 118 | { | ||
| 119 | ASN1err(ASN1_F_D2I_PUBLICKEY, ERR_R_ASN1_LIB); | ||
| 120 | goto err; | ||
| 121 | } | ||
| 122 | break; | ||
| 123 | #endif | ||
| 124 | default: | ||
| 125 | ASN1err(ASN1_F_D2I_PUBLICKEY,ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE); | ||
| 126 | goto err; | ||
| 127 | /* break; */ | ||
| 128 | } | ||
| 129 | if (a != NULL) (*a)=ret; | ||
| 130 | return(ret); | ||
| 131 | err: | ||
| 132 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) EVP_PKEY_free(ret); | ||
| 133 | return(NULL); | ||
| 134 | } | ||
| 135 | |||
diff --git a/src/lib/libcrypto/asn1/evp_asn1.c b/src/lib/libcrypto/asn1/evp_asn1.c new file mode 100644 index 0000000000..f3d9804860 --- /dev/null +++ b/src/lib/libcrypto/asn1/evp_asn1.c | |||
| @@ -0,0 +1,189 @@ | |||
| 1 | /* crypto/asn1/evp_asn1.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/asn1.h> | ||
| 62 | #include <openssl/asn1_mac.h> | ||
| 63 | |||
| 64 | int ASN1_TYPE_set_octetstring(ASN1_TYPE *a, unsigned char *data, int len) | ||
| 65 | { | ||
| 66 | ASN1_STRING *os; | ||
| 67 | |||
| 68 | if ((os=M_ASN1_OCTET_STRING_new()) == NULL) return(0); | ||
| 69 | if (!M_ASN1_OCTET_STRING_set(os,data,len)) return(0); | ||
| 70 | ASN1_TYPE_set(a,V_ASN1_OCTET_STRING,os); | ||
| 71 | return(1); | ||
| 72 | } | ||
| 73 | |||
| 74 | /* int max_len: for returned value */ | ||
| 75 | int ASN1_TYPE_get_octetstring(ASN1_TYPE *a, unsigned char *data, | ||
| 76 | int max_len) | ||
| 77 | { | ||
| 78 | int ret,num; | ||
| 79 | unsigned char *p; | ||
| 80 | |||
| 81 | if ((a->type != V_ASN1_OCTET_STRING) || (a->value.octet_string == NULL)) | ||
| 82 | { | ||
| 83 | ASN1err(ASN1_F_ASN1_TYPE_GET_OCTETSTRING,ASN1_R_DATA_IS_WRONG); | ||
| 84 | return(-1); | ||
| 85 | } | ||
| 86 | p=M_ASN1_STRING_data(a->value.octet_string); | ||
| 87 | ret=M_ASN1_STRING_length(a->value.octet_string); | ||
| 88 | if (ret < max_len) | ||
| 89 | num=ret; | ||
| 90 | else | ||
| 91 | num=max_len; | ||
| 92 | memcpy(data,p,num); | ||
| 93 | return(ret); | ||
| 94 | } | ||
| 95 | |||
| 96 | int ASN1_TYPE_set_int_octetstring(ASN1_TYPE *a, long num, unsigned char *data, | ||
| 97 | int len) | ||
| 98 | { | ||
| 99 | int n,size; | ||
| 100 | ASN1_OCTET_STRING os,*osp; | ||
| 101 | ASN1_INTEGER in; | ||
| 102 | unsigned char *p; | ||
| 103 | unsigned char buf[32]; /* when they have 256bit longs, | ||
| 104 | * I'll be in trouble */ | ||
| 105 | in.data=buf; | ||
| 106 | in.length=32; | ||
| 107 | os.data=data; | ||
| 108 | os.type=V_ASN1_OCTET_STRING; | ||
| 109 | os.length=len; | ||
| 110 | ASN1_INTEGER_set(&in,num); | ||
| 111 | n = i2d_ASN1_INTEGER(&in,NULL); | ||
| 112 | n+=M_i2d_ASN1_OCTET_STRING(&os,NULL); | ||
| 113 | |||
| 114 | size=ASN1_object_size(1,n,V_ASN1_SEQUENCE); | ||
| 115 | |||
| 116 | if ((osp=ASN1_STRING_new()) == NULL) return(0); | ||
| 117 | /* Grow the 'string' */ | ||
| 118 | if (!ASN1_STRING_set(osp,NULL,size)) | ||
| 119 | { | ||
| 120 | ASN1_STRING_free(osp); | ||
| 121 | return(0); | ||
| 122 | } | ||
| 123 | |||
| 124 | M_ASN1_STRING_length_set(osp, size); | ||
| 125 | p=M_ASN1_STRING_data(osp); | ||
| 126 | |||
| 127 | ASN1_put_object(&p,1,n,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL); | ||
| 128 | i2d_ASN1_INTEGER(&in,&p); | ||
| 129 | M_i2d_ASN1_OCTET_STRING(&os,&p); | ||
| 130 | |||
| 131 | ASN1_TYPE_set(a,V_ASN1_SEQUENCE,osp); | ||
| 132 | return(1); | ||
| 133 | } | ||
| 134 | |||
| 135 | /* we return the actual length..., num may be missing, in which | ||
| 136 | * case, set it to zero */ | ||
| 137 | /* int max_len: for returned value */ | ||
| 138 | int ASN1_TYPE_get_int_octetstring(ASN1_TYPE *a, long *num, unsigned char *data, | ||
| 139 | int max_len) | ||
| 140 | { | ||
| 141 | int ret= -1,n; | ||
| 142 | ASN1_INTEGER *ai=NULL; | ||
| 143 | ASN1_OCTET_STRING *os=NULL; | ||
| 144 | const unsigned char *p; | ||
| 145 | long length; | ||
| 146 | ASN1_const_CTX c; | ||
| 147 | |||
| 148 | if ((a->type != V_ASN1_SEQUENCE) || (a->value.sequence == NULL)) | ||
| 149 | { | ||
| 150 | goto err; | ||
| 151 | } | ||
| 152 | p=M_ASN1_STRING_data(a->value.sequence); | ||
| 153 | length=M_ASN1_STRING_length(a->value.sequence); | ||
| 154 | |||
| 155 | c.pp= &p; | ||
| 156 | c.p=p; | ||
| 157 | c.max=p+length; | ||
| 158 | c.error=ASN1_R_DATA_IS_WRONG; | ||
| 159 | |||
| 160 | M_ASN1_D2I_start_sequence(); | ||
| 161 | c.q=c.p; | ||
| 162 | if ((ai=d2i_ASN1_INTEGER(NULL,&c.p,c.slen)) == NULL) goto err; | ||
| 163 | c.slen-=(c.p-c.q); | ||
| 164 | c.q=c.p; | ||
| 165 | if ((os=d2i_ASN1_OCTET_STRING(NULL,&c.p,c.slen)) == NULL) goto err; | ||
| 166 | c.slen-=(c.p-c.q); | ||
| 167 | if (!M_ASN1_D2I_end_sequence()) goto err; | ||
| 168 | |||
| 169 | if (num != NULL) | ||
| 170 | *num=ASN1_INTEGER_get(ai); | ||
| 171 | |||
| 172 | ret=M_ASN1_STRING_length(os); | ||
| 173 | if (max_len > ret) | ||
| 174 | n=ret; | ||
| 175 | else | ||
| 176 | n=max_len; | ||
| 177 | |||
| 178 | if (data != NULL) | ||
| 179 | memcpy(data,M_ASN1_STRING_data(os),n); | ||
| 180 | if (0) | ||
| 181 | { | ||
| 182 | err: | ||
| 183 | ASN1err(ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING,ASN1_R_DATA_IS_WRONG); | ||
| 184 | } | ||
| 185 | if (os != NULL) M_ASN1_OCTET_STRING_free(os); | ||
| 186 | if (ai != NULL) M_ASN1_INTEGER_free(ai); | ||
| 187 | return(ret); | ||
| 188 | } | ||
| 189 | |||
diff --git a/src/lib/libcrypto/asn1/f_enum.c b/src/lib/libcrypto/asn1/f_enum.c new file mode 100644 index 0000000000..56e3cc8df2 --- /dev/null +++ b/src/lib/libcrypto/asn1/f_enum.c | |||
| @@ -0,0 +1,207 @@ | |||
| 1 | /* crypto/asn1/f_enum.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/buffer.h> | ||
| 62 | #include <openssl/asn1.h> | ||
| 63 | |||
| 64 | /* Based on a_int.c: equivalent ENUMERATED functions */ | ||
| 65 | |||
| 66 | int i2a_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *a) | ||
| 67 | { | ||
| 68 | int i,n=0; | ||
| 69 | static const char *h="0123456789ABCDEF"; | ||
| 70 | char buf[2]; | ||
| 71 | |||
| 72 | if (a == NULL) return(0); | ||
| 73 | |||
| 74 | if (a->length == 0) | ||
| 75 | { | ||
| 76 | if (BIO_write(bp,"00",2) != 2) goto err; | ||
| 77 | n=2; | ||
| 78 | } | ||
| 79 | else | ||
| 80 | { | ||
| 81 | for (i=0; i<a->length; i++) | ||
| 82 | { | ||
| 83 | if ((i != 0) && (i%35 == 0)) | ||
| 84 | { | ||
| 85 | if (BIO_write(bp,"\\\n",2) != 2) goto err; | ||
| 86 | n+=2; | ||
| 87 | } | ||
| 88 | buf[0]=h[((unsigned char)a->data[i]>>4)&0x0f]; | ||
| 89 | buf[1]=h[((unsigned char)a->data[i] )&0x0f]; | ||
| 90 | if (BIO_write(bp,buf,2) != 2) goto err; | ||
| 91 | n+=2; | ||
| 92 | } | ||
| 93 | } | ||
| 94 | return(n); | ||
| 95 | err: | ||
| 96 | return(-1); | ||
| 97 | } | ||
| 98 | |||
| 99 | int a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size) | ||
| 100 | { | ||
| 101 | int ret=0; | ||
| 102 | int i,j,k,m,n,again,bufsize; | ||
| 103 | unsigned char *s=NULL,*sp; | ||
| 104 | unsigned char *bufp; | ||
| 105 | int num=0,slen=0,first=1; | ||
| 106 | |||
| 107 | bs->type=V_ASN1_ENUMERATED; | ||
| 108 | |||
| 109 | bufsize=BIO_gets(bp,buf,size); | ||
| 110 | for (;;) | ||
| 111 | { | ||
| 112 | if (bufsize < 1) goto err_sl; | ||
| 113 | i=bufsize; | ||
| 114 | if (buf[i-1] == '\n') buf[--i]='\0'; | ||
| 115 | if (i == 0) goto err_sl; | ||
| 116 | if (buf[i-1] == '\r') buf[--i]='\0'; | ||
| 117 | if (i == 0) goto err_sl; | ||
| 118 | again=(buf[i-1] == '\\'); | ||
| 119 | |||
| 120 | for (j=0; j<i; j++) | ||
| 121 | { | ||
| 122 | if (!( ((buf[j] >= '0') && (buf[j] <= '9')) || | ||
| 123 | ((buf[j] >= 'a') && (buf[j] <= 'f')) || | ||
| 124 | ((buf[j] >= 'A') && (buf[j] <= 'F')))) | ||
| 125 | { | ||
| 126 | i=j; | ||
| 127 | break; | ||
| 128 | } | ||
| 129 | } | ||
| 130 | buf[i]='\0'; | ||
| 131 | /* We have now cleared all the crap off the end of the | ||
| 132 | * line */ | ||
| 133 | if (i < 2) goto err_sl; | ||
| 134 | |||
| 135 | bufp=(unsigned char *)buf; | ||
| 136 | if (first) | ||
| 137 | { | ||
| 138 | first=0; | ||
| 139 | if ((bufp[0] == '0') && (buf[1] == '0')) | ||
| 140 | { | ||
| 141 | bufp+=2; | ||
| 142 | i-=2; | ||
| 143 | } | ||
| 144 | } | ||
| 145 | k=0; | ||
| 146 | i-=again; | ||
| 147 | if (i%2 != 0) | ||
| 148 | { | ||
| 149 | ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ASN1_R_ODD_NUMBER_OF_CHARS); | ||
| 150 | goto err; | ||
| 151 | } | ||
| 152 | i/=2; | ||
| 153 | if (num+i > slen) | ||
| 154 | { | ||
| 155 | if (s == NULL) | ||
| 156 | sp=(unsigned char *)OPENSSL_malloc( | ||
| 157 | (unsigned int)num+i*2); | ||
| 158 | else | ||
| 159 | sp=(unsigned char *)OPENSSL_realloc(s, | ||
| 160 | (unsigned int)num+i*2); | ||
| 161 | if (sp == NULL) | ||
| 162 | { | ||
| 163 | ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ERR_R_MALLOC_FAILURE); | ||
| 164 | if (s != NULL) OPENSSL_free(s); | ||
| 165 | goto err; | ||
| 166 | } | ||
| 167 | s=sp; | ||
| 168 | slen=num+i*2; | ||
| 169 | } | ||
| 170 | for (j=0; j<i; j++,k+=2) | ||
| 171 | { | ||
| 172 | for (n=0; n<2; n++) | ||
| 173 | { | ||
| 174 | m=bufp[k+n]; | ||
| 175 | if ((m >= '0') && (m <= '9')) | ||
| 176 | m-='0'; | ||
| 177 | else if ((m >= 'a') && (m <= 'f')) | ||
| 178 | m=m-'a'+10; | ||
| 179 | else if ((m >= 'A') && (m <= 'F')) | ||
| 180 | m=m-'A'+10; | ||
| 181 | else | ||
| 182 | { | ||
| 183 | ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ASN1_R_NON_HEX_CHARACTERS); | ||
| 184 | goto err; | ||
| 185 | } | ||
| 186 | s[num+j]<<=4; | ||
| 187 | s[num+j]|=m; | ||
| 188 | } | ||
| 189 | } | ||
| 190 | num+=i; | ||
| 191 | if (again) | ||
| 192 | bufsize=BIO_gets(bp,buf,size); | ||
| 193 | else | ||
| 194 | break; | ||
| 195 | } | ||
| 196 | bs->length=num; | ||
| 197 | bs->data=s; | ||
| 198 | ret=1; | ||
| 199 | err: | ||
| 200 | if (0) | ||
| 201 | { | ||
| 202 | err_sl: | ||
| 203 | ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ASN1_R_SHORT_LINE); | ||
| 204 | } | ||
| 205 | return(ret); | ||
| 206 | } | ||
| 207 | |||
diff --git a/src/lib/libcrypto/asn1/f_int.c b/src/lib/libcrypto/asn1/f_int.c new file mode 100644 index 0000000000..9494e597ab --- /dev/null +++ b/src/lib/libcrypto/asn1/f_int.c | |||
| @@ -0,0 +1,219 @@ | |||
| 1 | /* crypto/asn1/f_int.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/buffer.h> | ||
| 62 | #include <openssl/asn1.h> | ||
| 63 | |||
| 64 | int i2a_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *a) | ||
| 65 | { | ||
| 66 | int i,n=0; | ||
| 67 | static const char *h="0123456789ABCDEF"; | ||
| 68 | char buf[2]; | ||
| 69 | |||
| 70 | if (a == NULL) return(0); | ||
| 71 | |||
| 72 | if (a->type & V_ASN1_NEG) | ||
| 73 | { | ||
| 74 | if (BIO_write(bp, "-", 1) != 1) goto err; | ||
| 75 | n = 1; | ||
| 76 | } | ||
| 77 | |||
| 78 | if (a->length == 0) | ||
| 79 | { | ||
| 80 | if (BIO_write(bp,"00",2) != 2) goto err; | ||
| 81 | n += 2; | ||
| 82 | } | ||
| 83 | else | ||
| 84 | { | ||
| 85 | for (i=0; i<a->length; i++) | ||
| 86 | { | ||
| 87 | if ((i != 0) && (i%35 == 0)) | ||
| 88 | { | ||
| 89 | if (BIO_write(bp,"\\\n",2) != 2) goto err; | ||
| 90 | n+=2; | ||
| 91 | } | ||
| 92 | buf[0]=h[((unsigned char)a->data[i]>>4)&0x0f]; | ||
| 93 | buf[1]=h[((unsigned char)a->data[i] )&0x0f]; | ||
| 94 | if (BIO_write(bp,buf,2) != 2) goto err; | ||
| 95 | n+=2; | ||
| 96 | } | ||
| 97 | } | ||
| 98 | return(n); | ||
| 99 | err: | ||
| 100 | return(-1); | ||
| 101 | } | ||
| 102 | |||
| 103 | int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size) | ||
| 104 | { | ||
| 105 | int ret=0; | ||
| 106 | int i,j,k,m,n,again,bufsize; | ||
| 107 | unsigned char *s=NULL,*sp; | ||
| 108 | unsigned char *bufp; | ||
| 109 | int num=0,slen=0,first=1; | ||
| 110 | |||
| 111 | bs->type=V_ASN1_INTEGER; | ||
| 112 | |||
| 113 | bufsize=BIO_gets(bp,buf,size); | ||
| 114 | for (;;) | ||
| 115 | { | ||
| 116 | if (bufsize < 1) goto err_sl; | ||
| 117 | i=bufsize; | ||
| 118 | if (buf[i-1] == '\n') buf[--i]='\0'; | ||
| 119 | if (i == 0) goto err_sl; | ||
| 120 | if (buf[i-1] == '\r') buf[--i]='\0'; | ||
| 121 | if (i == 0) goto err_sl; | ||
| 122 | again=(buf[i-1] == '\\'); | ||
| 123 | |||
| 124 | for (j=0; j<i; j++) | ||
| 125 | { | ||
| 126 | #ifndef CHARSET_EBCDIC | ||
| 127 | if (!( ((buf[j] >= '0') && (buf[j] <= '9')) || | ||
| 128 | ((buf[j] >= 'a') && (buf[j] <= 'f')) || | ||
| 129 | ((buf[j] >= 'A') && (buf[j] <= 'F')))) | ||
| 130 | #else | ||
| 131 | /* This #ifdef is not strictly necessary, since | ||
| 132 | * the characters A...F a...f 0...9 are contiguous | ||
| 133 | * (yes, even in EBCDIC - but not the whole alphabet). | ||
| 134 | * Nevertheless, isxdigit() is faster. | ||
| 135 | */ | ||
| 136 | if (!isxdigit(buf[j])) | ||
| 137 | #endif | ||
| 138 | { | ||
| 139 | i=j; | ||
| 140 | break; | ||
| 141 | } | ||
| 142 | } | ||
| 143 | buf[i]='\0'; | ||
| 144 | /* We have now cleared all the crap off the end of the | ||
| 145 | * line */ | ||
| 146 | if (i < 2) goto err_sl; | ||
| 147 | |||
| 148 | bufp=(unsigned char *)buf; | ||
| 149 | if (first) | ||
| 150 | { | ||
| 151 | first=0; | ||
| 152 | if ((bufp[0] == '0') && (buf[1] == '0')) | ||
| 153 | { | ||
| 154 | bufp+=2; | ||
| 155 | i-=2; | ||
| 156 | } | ||
| 157 | } | ||
| 158 | k=0; | ||
| 159 | i-=again; | ||
| 160 | if (i%2 != 0) | ||
| 161 | { | ||
| 162 | ASN1err(ASN1_F_A2I_ASN1_INTEGER,ASN1_R_ODD_NUMBER_OF_CHARS); | ||
| 163 | goto err; | ||
| 164 | } | ||
| 165 | i/=2; | ||
| 166 | if (num+i > slen) | ||
| 167 | { | ||
| 168 | if (s == NULL) | ||
| 169 | sp=(unsigned char *)OPENSSL_malloc( | ||
| 170 | (unsigned int)num+i*2); | ||
| 171 | else | ||
| 172 | sp=OPENSSL_realloc_clean(s,slen,num+i*2); | ||
| 173 | if (sp == NULL) | ||
| 174 | { | ||
| 175 | ASN1err(ASN1_F_A2I_ASN1_INTEGER,ERR_R_MALLOC_FAILURE); | ||
| 176 | if (s != NULL) OPENSSL_free(s); | ||
| 177 | goto err; | ||
| 178 | } | ||
| 179 | s=sp; | ||
| 180 | slen=num+i*2; | ||
| 181 | } | ||
| 182 | for (j=0; j<i; j++,k+=2) | ||
| 183 | { | ||
| 184 | for (n=0; n<2; n++) | ||
| 185 | { | ||
| 186 | m=bufp[k+n]; | ||
| 187 | if ((m >= '0') && (m <= '9')) | ||
| 188 | m-='0'; | ||
| 189 | else if ((m >= 'a') && (m <= 'f')) | ||
| 190 | m=m-'a'+10; | ||
| 191 | else if ((m >= 'A') && (m <= 'F')) | ||
| 192 | m=m-'A'+10; | ||
| 193 | else | ||
| 194 | { | ||
| 195 | ASN1err(ASN1_F_A2I_ASN1_INTEGER,ASN1_R_NON_HEX_CHARACTERS); | ||
| 196 | goto err; | ||
| 197 | } | ||
| 198 | s[num+j]<<=4; | ||
| 199 | s[num+j]|=m; | ||
| 200 | } | ||
| 201 | } | ||
| 202 | num+=i; | ||
| 203 | if (again) | ||
| 204 | bufsize=BIO_gets(bp,buf,size); | ||
| 205 | else | ||
| 206 | break; | ||
| 207 | } | ||
| 208 | bs->length=num; | ||
| 209 | bs->data=s; | ||
| 210 | ret=1; | ||
| 211 | err: | ||
| 212 | if (0) | ||
| 213 | { | ||
| 214 | err_sl: | ||
| 215 | ASN1err(ASN1_F_A2I_ASN1_INTEGER,ASN1_R_SHORT_LINE); | ||
| 216 | } | ||
| 217 | return(ret); | ||
| 218 | } | ||
| 219 | |||
diff --git a/src/lib/libcrypto/asn1/f_string.c b/src/lib/libcrypto/asn1/f_string.c new file mode 100644 index 0000000000..968698a798 --- /dev/null +++ b/src/lib/libcrypto/asn1/f_string.c | |||
| @@ -0,0 +1,212 @@ | |||
| 1 | /* crypto/asn1/f_string.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/buffer.h> | ||
| 62 | #include <openssl/asn1.h> | ||
| 63 | |||
| 64 | int i2a_ASN1_STRING(BIO *bp, ASN1_STRING *a, int type) | ||
| 65 | { | ||
| 66 | int i,n=0; | ||
| 67 | static const char *h="0123456789ABCDEF"; | ||
| 68 | char buf[2]; | ||
| 69 | |||
| 70 | if (a == NULL) return(0); | ||
| 71 | |||
| 72 | if (a->length == 0) | ||
| 73 | { | ||
| 74 | if (BIO_write(bp,"0",1) != 1) goto err; | ||
| 75 | n=1; | ||
| 76 | } | ||
| 77 | else | ||
| 78 | { | ||
| 79 | for (i=0; i<a->length; i++) | ||
| 80 | { | ||
| 81 | if ((i != 0) && (i%35 == 0)) | ||
| 82 | { | ||
| 83 | if (BIO_write(bp,"\\\n",2) != 2) goto err; | ||
| 84 | n+=2; | ||
| 85 | } | ||
| 86 | buf[0]=h[((unsigned char)a->data[i]>>4)&0x0f]; | ||
| 87 | buf[1]=h[((unsigned char)a->data[i] )&0x0f]; | ||
| 88 | if (BIO_write(bp,buf,2) != 2) goto err; | ||
| 89 | n+=2; | ||
| 90 | } | ||
| 91 | } | ||
| 92 | return(n); | ||
| 93 | err: | ||
| 94 | return(-1); | ||
| 95 | } | ||
| 96 | |||
| 97 | int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size) | ||
| 98 | { | ||
| 99 | int ret=0; | ||
| 100 | int i,j,k,m,n,again,bufsize; | ||
| 101 | unsigned char *s=NULL,*sp; | ||
| 102 | unsigned char *bufp; | ||
| 103 | int num=0,slen=0,first=1; | ||
| 104 | |||
| 105 | bufsize=BIO_gets(bp,buf,size); | ||
| 106 | for (;;) | ||
| 107 | { | ||
| 108 | if (bufsize < 1) | ||
| 109 | { | ||
| 110 | if (first) | ||
| 111 | break; | ||
| 112 | else | ||
| 113 | goto err_sl; | ||
| 114 | } | ||
| 115 | first=0; | ||
| 116 | |||
| 117 | i=bufsize; | ||
| 118 | if (buf[i-1] == '\n') buf[--i]='\0'; | ||
| 119 | if (i == 0) goto err_sl; | ||
| 120 | if (buf[i-1] == '\r') buf[--i]='\0'; | ||
| 121 | if (i == 0) goto err_sl; | ||
| 122 | again=(buf[i-1] == '\\'); | ||
| 123 | |||
| 124 | for (j=i-1; j>0; j--) | ||
| 125 | { | ||
| 126 | #ifndef CHARSET_EBCDIC | ||
| 127 | if (!( ((buf[j] >= '0') && (buf[j] <= '9')) || | ||
| 128 | ((buf[j] >= 'a') && (buf[j] <= 'f')) || | ||
| 129 | ((buf[j] >= 'A') && (buf[j] <= 'F')))) | ||
| 130 | #else | ||
| 131 | /* This #ifdef is not strictly necessary, since | ||
| 132 | * the characters A...F a...f 0...9 are contiguous | ||
| 133 | * (yes, even in EBCDIC - but not the whole alphabet). | ||
| 134 | * Nevertheless, isxdigit() is faster. | ||
| 135 | */ | ||
| 136 | if (!isxdigit(buf[j])) | ||
| 137 | #endif | ||
| 138 | { | ||
| 139 | i=j; | ||
| 140 | break; | ||
| 141 | } | ||
| 142 | } | ||
| 143 | buf[i]='\0'; | ||
| 144 | /* We have now cleared all the crap off the end of the | ||
| 145 | * line */ | ||
| 146 | if (i < 2) goto err_sl; | ||
| 147 | |||
| 148 | bufp=(unsigned char *)buf; | ||
| 149 | |||
| 150 | k=0; | ||
| 151 | i-=again; | ||
| 152 | if (i%2 != 0) | ||
| 153 | { | ||
| 154 | ASN1err(ASN1_F_A2I_ASN1_STRING,ASN1_R_ODD_NUMBER_OF_CHARS); | ||
| 155 | goto err; | ||
| 156 | } | ||
| 157 | i/=2; | ||
| 158 | if (num+i > slen) | ||
| 159 | { | ||
| 160 | if (s == NULL) | ||
| 161 | sp=(unsigned char *)OPENSSL_malloc( | ||
| 162 | (unsigned int)num+i*2); | ||
| 163 | else | ||
| 164 | sp=(unsigned char *)OPENSSL_realloc(s, | ||
| 165 | (unsigned int)num+i*2); | ||
| 166 | if (sp == NULL) | ||
| 167 | { | ||
| 168 | ASN1err(ASN1_F_A2I_ASN1_STRING,ERR_R_MALLOC_FAILURE); | ||
| 169 | if (s != NULL) OPENSSL_free(s); | ||
| 170 | goto err; | ||
| 171 | } | ||
| 172 | s=sp; | ||
| 173 | slen=num+i*2; | ||
| 174 | } | ||
| 175 | for (j=0; j<i; j++,k+=2) | ||
| 176 | { | ||
| 177 | for (n=0; n<2; n++) | ||
| 178 | { | ||
| 179 | m=bufp[k+n]; | ||
| 180 | if ((m >= '0') && (m <= '9')) | ||
| 181 | m-='0'; | ||
| 182 | else if ((m >= 'a') && (m <= 'f')) | ||
| 183 | m=m-'a'+10; | ||
| 184 | else if ((m >= 'A') && (m <= 'F')) | ||
| 185 | m=m-'A'+10; | ||
| 186 | else | ||
| 187 | { | ||
| 188 | ASN1err(ASN1_F_A2I_ASN1_STRING,ASN1_R_NON_HEX_CHARACTERS); | ||
| 189 | goto err; | ||
| 190 | } | ||
| 191 | s[num+j]<<=4; | ||
| 192 | s[num+j]|=m; | ||
| 193 | } | ||
| 194 | } | ||
| 195 | num+=i; | ||
| 196 | if (again) | ||
| 197 | bufsize=BIO_gets(bp,buf,size); | ||
| 198 | else | ||
| 199 | break; | ||
| 200 | } | ||
| 201 | bs->length=num; | ||
| 202 | bs->data=s; | ||
| 203 | ret=1; | ||
| 204 | err: | ||
| 205 | if (0) | ||
| 206 | { | ||
| 207 | err_sl: | ||
| 208 | ASN1err(ASN1_F_A2I_ASN1_STRING,ASN1_R_SHORT_LINE); | ||
| 209 | } | ||
| 210 | return(ret); | ||
| 211 | } | ||
| 212 | |||
diff --git a/src/lib/libcrypto/asn1/i2d_pr.c b/src/lib/libcrypto/asn1/i2d_pr.c new file mode 100644 index 0000000000..0be52c5b76 --- /dev/null +++ b/src/lib/libcrypto/asn1/i2d_pr.c | |||
| @@ -0,0 +1,99 @@ | |||
| 1 | /* crypto/asn1/i2d_pr.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/bn.h> | ||
| 62 | #include <openssl/evp.h> | ||
| 63 | #include <openssl/objects.h> | ||
| 64 | #ifndef OPENSSL_NO_RSA | ||
| 65 | #include <openssl/rsa.h> | ||
| 66 | #endif | ||
| 67 | #ifndef OPENSSL_NO_DSA | ||
| 68 | #include <openssl/dsa.h> | ||
| 69 | #endif | ||
| 70 | #ifndef OPENSSL_NO_EC | ||
| 71 | #include <openssl/ec.h> | ||
| 72 | #endif | ||
| 73 | |||
| 74 | int i2d_PrivateKey(EVP_PKEY *a, unsigned char **pp) | ||
| 75 | { | ||
| 76 | #ifndef OPENSSL_NO_RSA | ||
| 77 | if (a->type == EVP_PKEY_RSA) | ||
| 78 | { | ||
| 79 | return(i2d_RSAPrivateKey(a->pkey.rsa,pp)); | ||
| 80 | } | ||
| 81 | else | ||
| 82 | #endif | ||
| 83 | #ifndef OPENSSL_NO_DSA | ||
| 84 | if (a->type == EVP_PKEY_DSA) | ||
| 85 | { | ||
| 86 | return(i2d_DSAPrivateKey(a->pkey.dsa,pp)); | ||
| 87 | } | ||
| 88 | #endif | ||
| 89 | #ifndef OPENSSL_NO_EC | ||
| 90 | if (a->type == EVP_PKEY_EC) | ||
| 91 | { | ||
| 92 | return(i2d_ECPrivateKey(a->pkey.ec, pp)); | ||
| 93 | } | ||
| 94 | #endif | ||
| 95 | |||
| 96 | ASN1err(ASN1_F_I2D_PRIVATEKEY,ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE); | ||
| 97 | return(-1); | ||
| 98 | } | ||
| 99 | |||
diff --git a/src/lib/libcrypto/asn1/i2d_pu.c b/src/lib/libcrypto/asn1/i2d_pu.c new file mode 100644 index 0000000000..34286dbd35 --- /dev/null +++ b/src/lib/libcrypto/asn1/i2d_pu.c | |||
| @@ -0,0 +1,95 @@ | |||
| 1 | /* crypto/asn1/i2d_pu.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/bn.h> | ||
| 62 | #include <openssl/evp.h> | ||
| 63 | #include <openssl/objects.h> | ||
| 64 | #ifndef OPENSSL_NO_RSA | ||
| 65 | #include <openssl/rsa.h> | ||
| 66 | #endif | ||
| 67 | #ifndef OPENSSL_NO_DSA | ||
| 68 | #include <openssl/dsa.h> | ||
| 69 | #endif | ||
| 70 | #ifndef OPENSSL_NO_EC | ||
| 71 | #include <openssl/ec.h> | ||
| 72 | #endif | ||
| 73 | |||
| 74 | int i2d_PublicKey(EVP_PKEY *a, unsigned char **pp) | ||
| 75 | { | ||
| 76 | switch (a->type) | ||
| 77 | { | ||
| 78 | #ifndef OPENSSL_NO_RSA | ||
| 79 | case EVP_PKEY_RSA: | ||
| 80 | return(i2d_RSAPublicKey(a->pkey.rsa,pp)); | ||
| 81 | #endif | ||
| 82 | #ifndef OPENSSL_NO_DSA | ||
| 83 | case EVP_PKEY_DSA: | ||
| 84 | return(i2d_DSAPublicKey(a->pkey.dsa,pp)); | ||
| 85 | #endif | ||
| 86 | #ifndef OPENSSL_NO_EC | ||
| 87 | case EVP_PKEY_EC: | ||
| 88 | return(i2o_ECPublicKey(a->pkey.ec, pp)); | ||
| 89 | #endif | ||
| 90 | default: | ||
| 91 | ASN1err(ASN1_F_I2D_PUBLICKEY,ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE); | ||
| 92 | return(-1); | ||
| 93 | } | ||
| 94 | } | ||
| 95 | |||
diff --git a/src/lib/libcrypto/asn1/n_pkey.c b/src/lib/libcrypto/asn1/n_pkey.c new file mode 100644 index 0000000000..60bc437938 --- /dev/null +++ b/src/lib/libcrypto/asn1/n_pkey.c | |||
| @@ -0,0 +1,344 @@ | |||
| 1 | /* crypto/asn1/n_pkey.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #ifndef OPENSSL_NO_RSA | ||
| 62 | #include <openssl/rsa.h> | ||
| 63 | #include <openssl/objects.h> | ||
| 64 | #include <openssl/asn1t.h> | ||
| 65 | #include <openssl/asn1_mac.h> | ||
| 66 | #include <openssl/evp.h> | ||
| 67 | #include <openssl/x509.h> | ||
| 68 | |||
| 69 | |||
| 70 | #ifndef OPENSSL_NO_RC4 | ||
| 71 | |||
| 72 | typedef struct netscape_pkey_st | ||
| 73 | { | ||
| 74 | long version; | ||
| 75 | X509_ALGOR *algor; | ||
| 76 | ASN1_OCTET_STRING *private_key; | ||
| 77 | } NETSCAPE_PKEY; | ||
| 78 | |||
| 79 | typedef struct netscape_encrypted_pkey_st | ||
| 80 | { | ||
| 81 | ASN1_OCTET_STRING *os; | ||
| 82 | /* This is the same structure as DigestInfo so use it: | ||
| 83 | * although this isn't really anything to do with | ||
| 84 | * digests. | ||
| 85 | */ | ||
| 86 | X509_SIG *enckey; | ||
| 87 | } NETSCAPE_ENCRYPTED_PKEY; | ||
| 88 | |||
| 89 | |||
| 90 | ASN1_BROKEN_SEQUENCE(NETSCAPE_ENCRYPTED_PKEY) = { | ||
| 91 | ASN1_SIMPLE(NETSCAPE_ENCRYPTED_PKEY, os, ASN1_OCTET_STRING), | ||
| 92 | ASN1_SIMPLE(NETSCAPE_ENCRYPTED_PKEY, enckey, X509_SIG) | ||
| 93 | } ASN1_BROKEN_SEQUENCE_END(NETSCAPE_ENCRYPTED_PKEY) | ||
| 94 | |||
| 95 | DECLARE_ASN1_FUNCTIONS_const(NETSCAPE_ENCRYPTED_PKEY) | ||
| 96 | DECLARE_ASN1_ENCODE_FUNCTIONS_const(NETSCAPE_ENCRYPTED_PKEY,NETSCAPE_ENCRYPTED_PKEY) | ||
| 97 | IMPLEMENT_ASN1_FUNCTIONS_const(NETSCAPE_ENCRYPTED_PKEY) | ||
| 98 | |||
| 99 | ASN1_SEQUENCE(NETSCAPE_PKEY) = { | ||
| 100 | ASN1_SIMPLE(NETSCAPE_PKEY, version, LONG), | ||
| 101 | ASN1_SIMPLE(NETSCAPE_PKEY, algor, X509_ALGOR), | ||
| 102 | ASN1_SIMPLE(NETSCAPE_PKEY, private_key, ASN1_OCTET_STRING) | ||
| 103 | } ASN1_SEQUENCE_END(NETSCAPE_PKEY) | ||
| 104 | |||
| 105 | DECLARE_ASN1_FUNCTIONS_const(NETSCAPE_PKEY) | ||
| 106 | DECLARE_ASN1_ENCODE_FUNCTIONS_const(NETSCAPE_PKEY,NETSCAPE_PKEY) | ||
| 107 | IMPLEMENT_ASN1_FUNCTIONS_const(NETSCAPE_PKEY) | ||
| 108 | |||
| 109 | static RSA *d2i_RSA_NET_2(RSA **a, ASN1_OCTET_STRING *os, | ||
| 110 | int (*cb)(char *buf, int len, const char *prompt, | ||
| 111 | int verify), | ||
| 112 | int sgckey); | ||
| 113 | |||
| 114 | int i2d_Netscape_RSA(const RSA *a, unsigned char **pp, | ||
| 115 | int (*cb)(char *buf, int len, const char *prompt, | ||
| 116 | int verify)) | ||
| 117 | { | ||
| 118 | return i2d_RSA_NET(a, pp, cb, 0); | ||
| 119 | } | ||
| 120 | |||
| 121 | int i2d_RSA_NET(const RSA *a, unsigned char **pp, | ||
| 122 | int (*cb)(char *buf, int len, const char *prompt, int verify), | ||
| 123 | int sgckey) | ||
| 124 | { | ||
| 125 | int i, j, ret = 0; | ||
| 126 | int rsalen, pkeylen, olen; | ||
| 127 | NETSCAPE_PKEY *pkey = NULL; | ||
| 128 | NETSCAPE_ENCRYPTED_PKEY *enckey = NULL; | ||
| 129 | unsigned char buf[256],*zz; | ||
| 130 | unsigned char key[EVP_MAX_KEY_LENGTH]; | ||
| 131 | EVP_CIPHER_CTX ctx; | ||
| 132 | |||
| 133 | if (a == NULL) return(0); | ||
| 134 | |||
| 135 | if ((pkey=NETSCAPE_PKEY_new()) == NULL) goto err; | ||
| 136 | if ((enckey=NETSCAPE_ENCRYPTED_PKEY_new()) == NULL) goto err; | ||
| 137 | pkey->version = 0; | ||
| 138 | |||
| 139 | pkey->algor->algorithm=OBJ_nid2obj(NID_rsaEncryption); | ||
| 140 | if ((pkey->algor->parameter=ASN1_TYPE_new()) == NULL) goto err; | ||
| 141 | pkey->algor->parameter->type=V_ASN1_NULL; | ||
| 142 | |||
| 143 | rsalen = i2d_RSAPrivateKey(a, NULL); | ||
| 144 | |||
| 145 | /* Fake some octet strings just for the initial length | ||
| 146 | * calculation. | ||
| 147 | */ | ||
| 148 | |||
| 149 | pkey->private_key->length=rsalen; | ||
| 150 | |||
| 151 | pkeylen=i2d_NETSCAPE_PKEY(pkey,NULL); | ||
| 152 | |||
| 153 | enckey->enckey->digest->length = pkeylen; | ||
| 154 | |||
| 155 | enckey->os->length = 11; /* "private-key" */ | ||
| 156 | |||
| 157 | enckey->enckey->algor->algorithm=OBJ_nid2obj(NID_rc4); | ||
| 158 | if ((enckey->enckey->algor->parameter=ASN1_TYPE_new()) == NULL) goto err; | ||
| 159 | enckey->enckey->algor->parameter->type=V_ASN1_NULL; | ||
| 160 | |||
| 161 | if (pp == NULL) | ||
| 162 | { | ||
| 163 | olen = i2d_NETSCAPE_ENCRYPTED_PKEY(enckey, NULL); | ||
| 164 | NETSCAPE_PKEY_free(pkey); | ||
| 165 | NETSCAPE_ENCRYPTED_PKEY_free(enckey); | ||
| 166 | return olen; | ||
| 167 | } | ||
| 168 | |||
| 169 | |||
| 170 | /* Since its RC4 encrypted length is actual length */ | ||
| 171 | if ((zz=(unsigned char *)OPENSSL_malloc(rsalen)) == NULL) | ||
| 172 | { | ||
| 173 | ASN1err(ASN1_F_I2D_RSA_NET,ERR_R_MALLOC_FAILURE); | ||
| 174 | goto err; | ||
| 175 | } | ||
| 176 | |||
| 177 | pkey->private_key->data = zz; | ||
| 178 | /* Write out private key encoding */ | ||
| 179 | i2d_RSAPrivateKey(a,&zz); | ||
| 180 | |||
| 181 | if ((zz=OPENSSL_malloc(pkeylen)) == NULL) | ||
| 182 | { | ||
| 183 | ASN1err(ASN1_F_I2D_RSA_NET,ERR_R_MALLOC_FAILURE); | ||
| 184 | goto err; | ||
| 185 | } | ||
| 186 | |||
| 187 | if (!ASN1_STRING_set(enckey->os, "private-key", -1)) | ||
| 188 | { | ||
| 189 | ASN1err(ASN1_F_I2D_RSA_NET,ERR_R_MALLOC_FAILURE); | ||
| 190 | goto err; | ||
| 191 | } | ||
| 192 | enckey->enckey->digest->data = zz; | ||
| 193 | i2d_NETSCAPE_PKEY(pkey,&zz); | ||
| 194 | |||
| 195 | /* Wipe the private key encoding */ | ||
| 196 | OPENSSL_cleanse(pkey->private_key->data, rsalen); | ||
| 197 | |||
| 198 | if (cb == NULL) | ||
| 199 | cb=EVP_read_pw_string; | ||
| 200 | i=cb((char *)buf,256,"Enter Private Key password:",1); | ||
| 201 | if (i != 0) | ||
| 202 | { | ||
| 203 | ASN1err(ASN1_F_I2D_RSA_NET,ASN1_R_BAD_PASSWORD_READ); | ||
| 204 | goto err; | ||
| 205 | } | ||
| 206 | i = strlen((char *)buf); | ||
| 207 | /* If the key is used for SGC the algorithm is modified a little. */ | ||
| 208 | if(sgckey) { | ||
| 209 | EVP_Digest(buf, i, buf, NULL, EVP_md5(), NULL); | ||
| 210 | memcpy(buf + 16, "SGCKEYSALT", 10); | ||
| 211 | i = 26; | ||
| 212 | } | ||
| 213 | |||
| 214 | EVP_BytesToKey(EVP_rc4(),EVP_md5(),NULL,buf,i,1,key,NULL); | ||
| 215 | OPENSSL_cleanse(buf,256); | ||
| 216 | |||
| 217 | /* Encrypt private key in place */ | ||
| 218 | zz = enckey->enckey->digest->data; | ||
| 219 | EVP_CIPHER_CTX_init(&ctx); | ||
| 220 | EVP_EncryptInit_ex(&ctx,EVP_rc4(),NULL,key,NULL); | ||
| 221 | EVP_EncryptUpdate(&ctx,zz,&i,zz,pkeylen); | ||
| 222 | EVP_EncryptFinal_ex(&ctx,zz + i,&j); | ||
| 223 | EVP_CIPHER_CTX_cleanup(&ctx); | ||
| 224 | |||
| 225 | ret = i2d_NETSCAPE_ENCRYPTED_PKEY(enckey, pp); | ||
| 226 | err: | ||
| 227 | NETSCAPE_ENCRYPTED_PKEY_free(enckey); | ||
| 228 | NETSCAPE_PKEY_free(pkey); | ||
| 229 | return(ret); | ||
| 230 | } | ||
| 231 | |||
| 232 | |||
| 233 | RSA *d2i_Netscape_RSA(RSA **a, const unsigned char **pp, long length, | ||
| 234 | int (*cb)(char *buf, int len, const char *prompt, | ||
| 235 | int verify)) | ||
| 236 | { | ||
| 237 | return d2i_RSA_NET(a, pp, length, cb, 0); | ||
| 238 | } | ||
| 239 | |||
| 240 | RSA *d2i_RSA_NET(RSA **a, const unsigned char **pp, long length, | ||
| 241 | int (*cb)(char *buf, int len, const char *prompt, int verify), | ||
| 242 | int sgckey) | ||
| 243 | { | ||
| 244 | RSA *ret=NULL; | ||
| 245 | const unsigned char *p, *kp; | ||
| 246 | NETSCAPE_ENCRYPTED_PKEY *enckey = NULL; | ||
| 247 | |||
| 248 | p = *pp; | ||
| 249 | |||
| 250 | enckey = d2i_NETSCAPE_ENCRYPTED_PKEY(NULL, &p, length); | ||
| 251 | if(!enckey) { | ||
| 252 | ASN1err(ASN1_F_D2I_RSA_NET,ASN1_R_DECODING_ERROR); | ||
| 253 | return NULL; | ||
| 254 | } | ||
| 255 | |||
| 256 | if ((enckey->os->length != 11) || (strncmp("private-key", | ||
| 257 | (char *)enckey->os->data,11) != 0)) | ||
| 258 | { | ||
| 259 | ASN1err(ASN1_F_D2I_RSA_NET,ASN1_R_PRIVATE_KEY_HEADER_MISSING); | ||
| 260 | NETSCAPE_ENCRYPTED_PKEY_free(enckey); | ||
| 261 | return NULL; | ||
| 262 | } | ||
| 263 | if (OBJ_obj2nid(enckey->enckey->algor->algorithm) != NID_rc4) | ||
| 264 | { | ||
| 265 | ASN1err(ASN1_F_D2I_RSA_NET,ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM); | ||
| 266 | goto err; | ||
| 267 | } | ||
| 268 | kp = enckey->enckey->digest->data; | ||
| 269 | if (cb == NULL) | ||
| 270 | cb=EVP_read_pw_string; | ||
| 271 | if ((ret=d2i_RSA_NET_2(a, enckey->enckey->digest,cb, sgckey)) == NULL) goto err; | ||
| 272 | |||
| 273 | *pp = p; | ||
| 274 | |||
| 275 | err: | ||
| 276 | NETSCAPE_ENCRYPTED_PKEY_free(enckey); | ||
| 277 | return ret; | ||
| 278 | |||
| 279 | } | ||
| 280 | |||
| 281 | static RSA *d2i_RSA_NET_2(RSA **a, ASN1_OCTET_STRING *os, | ||
| 282 | int (*cb)(char *buf, int len, const char *prompt, | ||
| 283 | int verify), int sgckey) | ||
| 284 | { | ||
| 285 | NETSCAPE_PKEY *pkey=NULL; | ||
| 286 | RSA *ret=NULL; | ||
| 287 | int i,j; | ||
| 288 | unsigned char buf[256]; | ||
| 289 | const unsigned char *zz; | ||
| 290 | unsigned char key[EVP_MAX_KEY_LENGTH]; | ||
| 291 | EVP_CIPHER_CTX ctx; | ||
| 292 | |||
| 293 | i=cb((char *)buf,256,"Enter Private Key password:",0); | ||
| 294 | if (i != 0) | ||
| 295 | { | ||
| 296 | ASN1err(ASN1_F_D2I_RSA_NET_2,ASN1_R_BAD_PASSWORD_READ); | ||
| 297 | goto err; | ||
| 298 | } | ||
| 299 | |||
| 300 | i = strlen((char *)buf); | ||
| 301 | if(sgckey){ | ||
| 302 | EVP_Digest(buf, i, buf, NULL, EVP_md5(), NULL); | ||
| 303 | memcpy(buf + 16, "SGCKEYSALT", 10); | ||
| 304 | i = 26; | ||
| 305 | } | ||
| 306 | |||
| 307 | EVP_BytesToKey(EVP_rc4(),EVP_md5(),NULL,buf,i,1,key,NULL); | ||
| 308 | OPENSSL_cleanse(buf,256); | ||
| 309 | |||
| 310 | EVP_CIPHER_CTX_init(&ctx); | ||
| 311 | EVP_DecryptInit_ex(&ctx,EVP_rc4(),NULL, key,NULL); | ||
| 312 | EVP_DecryptUpdate(&ctx,os->data,&i,os->data,os->length); | ||
| 313 | EVP_DecryptFinal_ex(&ctx,&(os->data[i]),&j); | ||
| 314 | EVP_CIPHER_CTX_cleanup(&ctx); | ||
| 315 | os->length=i+j; | ||
| 316 | |||
| 317 | zz=os->data; | ||
| 318 | |||
| 319 | if ((pkey=d2i_NETSCAPE_PKEY(NULL,&zz,os->length)) == NULL) | ||
| 320 | { | ||
| 321 | ASN1err(ASN1_F_D2I_RSA_NET_2,ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY); | ||
| 322 | goto err; | ||
| 323 | } | ||
| 324 | |||
| 325 | zz=pkey->private_key->data; | ||
| 326 | if ((ret=d2i_RSAPrivateKey(a,&zz,pkey->private_key->length)) == NULL) | ||
| 327 | { | ||
| 328 | ASN1err(ASN1_F_D2I_RSA_NET_2,ASN1_R_UNABLE_TO_DECODE_RSA_KEY); | ||
| 329 | goto err; | ||
| 330 | } | ||
| 331 | err: | ||
| 332 | NETSCAPE_PKEY_free(pkey); | ||
| 333 | return(ret); | ||
| 334 | } | ||
| 335 | |||
| 336 | #endif /* OPENSSL_NO_RC4 */ | ||
| 337 | |||
| 338 | #else /* !OPENSSL_NO_RSA */ | ||
| 339 | |||
| 340 | # if PEDANTIC | ||
| 341 | static void *dummy=&dummy; | ||
| 342 | # endif | ||
| 343 | |||
| 344 | #endif | ||
diff --git a/src/lib/libcrypto/asn1/nsseq.c b/src/lib/libcrypto/asn1/nsseq.c new file mode 100644 index 0000000000..50e2d4d07a --- /dev/null +++ b/src/lib/libcrypto/asn1/nsseq.c | |||
| @@ -0,0 +1,82 @@ | |||
| 1 | /* nsseq.c */ | ||
| 2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
| 3 | * project 1999. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include <stdlib.h> | ||
| 61 | #include <openssl/asn1t.h> | ||
| 62 | #include <openssl/x509.h> | ||
| 63 | #include <openssl/objects.h> | ||
| 64 | |||
| 65 | static int nsseq_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it) | ||
| 66 | { | ||
| 67 | if(operation == ASN1_OP_NEW_POST) { | ||
| 68 | NETSCAPE_CERT_SEQUENCE *nsseq; | ||
| 69 | nsseq = (NETSCAPE_CERT_SEQUENCE *)*pval; | ||
| 70 | nsseq->type = OBJ_nid2obj(NID_netscape_cert_sequence); | ||
| 71 | } | ||
| 72 | return 1; | ||
| 73 | } | ||
| 74 | |||
| 75 | /* Netscape certificate sequence structure */ | ||
| 76 | |||
| 77 | ASN1_SEQUENCE_cb(NETSCAPE_CERT_SEQUENCE, nsseq_cb) = { | ||
| 78 | ASN1_SIMPLE(NETSCAPE_CERT_SEQUENCE, type, ASN1_OBJECT), | ||
| 79 | ASN1_EXP_SEQUENCE_OF_OPT(NETSCAPE_CERT_SEQUENCE, certs, X509, 0) | ||
| 80 | } ASN1_SEQUENCE_END_cb(NETSCAPE_CERT_SEQUENCE, NETSCAPE_CERT_SEQUENCE) | ||
| 81 | |||
| 82 | IMPLEMENT_ASN1_FUNCTIONS(NETSCAPE_CERT_SEQUENCE) | ||
diff --git a/src/lib/libcrypto/asn1/p5_pbe.c b/src/lib/libcrypto/asn1/p5_pbe.c new file mode 100644 index 0000000000..da91170094 --- /dev/null +++ b/src/lib/libcrypto/asn1/p5_pbe.c | |||
| @@ -0,0 +1,131 @@ | |||
| 1 | /* p5_pbe.c */ | ||
| 2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
| 3 | * project 1999. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/asn1t.h> | ||
| 62 | #include <openssl/x509.h> | ||
| 63 | #include <openssl/rand.h> | ||
| 64 | |||
| 65 | /* PKCS#5 password based encryption structure */ | ||
| 66 | |||
| 67 | ASN1_SEQUENCE(PBEPARAM) = { | ||
| 68 | ASN1_SIMPLE(PBEPARAM, salt, ASN1_OCTET_STRING), | ||
| 69 | ASN1_SIMPLE(PBEPARAM, iter, ASN1_INTEGER) | ||
| 70 | } ASN1_SEQUENCE_END(PBEPARAM) | ||
| 71 | |||
| 72 | IMPLEMENT_ASN1_FUNCTIONS(PBEPARAM) | ||
| 73 | |||
| 74 | /* Return an algorithm identifier for a PKCS#5 PBE algorithm */ | ||
| 75 | |||
| 76 | X509_ALGOR *PKCS5_pbe_set(int alg, int iter, unsigned char *salt, | ||
| 77 | int saltlen) | ||
| 78 | { | ||
| 79 | PBEPARAM *pbe=NULL; | ||
| 80 | ASN1_OBJECT *al; | ||
| 81 | X509_ALGOR *algor; | ||
| 82 | ASN1_TYPE *astype=NULL; | ||
| 83 | |||
| 84 | if (!(pbe = PBEPARAM_new ())) { | ||
| 85 | ASN1err(ASN1_F_PKCS5_PBE_SET,ERR_R_MALLOC_FAILURE); | ||
| 86 | goto err; | ||
| 87 | } | ||
| 88 | if(iter <= 0) iter = PKCS5_DEFAULT_ITER; | ||
| 89 | if (!ASN1_INTEGER_set(pbe->iter, iter)) { | ||
| 90 | ASN1err(ASN1_F_PKCS5_PBE_SET,ERR_R_MALLOC_FAILURE); | ||
| 91 | goto err; | ||
| 92 | } | ||
| 93 | if (!saltlen) saltlen = PKCS5_SALT_LEN; | ||
| 94 | if (!(pbe->salt->data = OPENSSL_malloc (saltlen))) { | ||
| 95 | ASN1err(ASN1_F_PKCS5_PBE_SET,ERR_R_MALLOC_FAILURE); | ||
| 96 | goto err; | ||
| 97 | } | ||
| 98 | pbe->salt->length = saltlen; | ||
| 99 | if (salt) memcpy (pbe->salt->data, salt, saltlen); | ||
| 100 | else if (RAND_pseudo_bytes (pbe->salt->data, saltlen) < 0) | ||
| 101 | goto err; | ||
| 102 | |||
| 103 | if (!(astype = ASN1_TYPE_new())) { | ||
| 104 | ASN1err(ASN1_F_PKCS5_PBE_SET,ERR_R_MALLOC_FAILURE); | ||
| 105 | goto err; | ||
| 106 | } | ||
| 107 | |||
| 108 | astype->type = V_ASN1_SEQUENCE; | ||
| 109 | if(!ASN1_pack_string_of(PBEPARAM, pbe, i2d_PBEPARAM, | ||
| 110 | &astype->value.sequence)) { | ||
| 111 | ASN1err(ASN1_F_PKCS5_PBE_SET,ERR_R_MALLOC_FAILURE); | ||
| 112 | goto err; | ||
| 113 | } | ||
| 114 | PBEPARAM_free (pbe); | ||
| 115 | pbe = NULL; | ||
| 116 | |||
| 117 | al = OBJ_nid2obj(alg); /* never need to free al */ | ||
| 118 | if (!(algor = X509_ALGOR_new())) { | ||
| 119 | ASN1err(ASN1_F_PKCS5_PBE_SET,ERR_R_MALLOC_FAILURE); | ||
| 120 | goto err; | ||
| 121 | } | ||
| 122 | ASN1_OBJECT_free(algor->algorithm); | ||
| 123 | algor->algorithm = al; | ||
| 124 | algor->parameter = astype; | ||
| 125 | |||
| 126 | return (algor); | ||
| 127 | err: | ||
| 128 | if (pbe != NULL) PBEPARAM_free(pbe); | ||
| 129 | if (astype != NULL) ASN1_TYPE_free(astype); | ||
| 130 | return NULL; | ||
| 131 | } | ||
diff --git a/src/lib/libcrypto/asn1/p5_pbev2.c b/src/lib/libcrypto/asn1/p5_pbev2.c new file mode 100644 index 0000000000..c834a38ddf --- /dev/null +++ b/src/lib/libcrypto/asn1/p5_pbev2.c | |||
| @@ -0,0 +1,205 @@ | |||
| 1 | /* p5_pbev2.c */ | ||
| 2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
| 3 | * project 1999-2004. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/asn1t.h> | ||
| 62 | #include <openssl/x509.h> | ||
| 63 | #include <openssl/rand.h> | ||
| 64 | |||
| 65 | /* PKCS#5 v2.0 password based encryption structures */ | ||
| 66 | |||
| 67 | ASN1_SEQUENCE(PBE2PARAM) = { | ||
| 68 | ASN1_SIMPLE(PBE2PARAM, keyfunc, X509_ALGOR), | ||
| 69 | ASN1_SIMPLE(PBE2PARAM, encryption, X509_ALGOR) | ||
| 70 | } ASN1_SEQUENCE_END(PBE2PARAM) | ||
| 71 | |||
| 72 | IMPLEMENT_ASN1_FUNCTIONS(PBE2PARAM) | ||
| 73 | |||
| 74 | ASN1_SEQUENCE(PBKDF2PARAM) = { | ||
| 75 | ASN1_SIMPLE(PBKDF2PARAM, salt, ASN1_ANY), | ||
| 76 | ASN1_SIMPLE(PBKDF2PARAM, iter, ASN1_INTEGER), | ||
| 77 | ASN1_OPT(PBKDF2PARAM, keylength, ASN1_INTEGER), | ||
| 78 | ASN1_OPT(PBKDF2PARAM, prf, X509_ALGOR) | ||
| 79 | } ASN1_SEQUENCE_END(PBKDF2PARAM) | ||
| 80 | |||
| 81 | IMPLEMENT_ASN1_FUNCTIONS(PBKDF2PARAM) | ||
| 82 | |||
| 83 | /* Return an algorithm identifier for a PKCS#5 v2.0 PBE algorithm: | ||
| 84 | * yes I know this is horrible! | ||
| 85 | */ | ||
| 86 | |||
| 87 | X509_ALGOR *PKCS5_pbe2_set(const EVP_CIPHER *cipher, int iter, | ||
| 88 | unsigned char *salt, int saltlen) | ||
| 89 | { | ||
| 90 | X509_ALGOR *scheme = NULL, *kalg = NULL, *ret = NULL; | ||
| 91 | int alg_nid; | ||
| 92 | EVP_CIPHER_CTX ctx; | ||
| 93 | unsigned char iv[EVP_MAX_IV_LENGTH]; | ||
| 94 | PBKDF2PARAM *kdf = NULL; | ||
| 95 | PBE2PARAM *pbe2 = NULL; | ||
| 96 | ASN1_OCTET_STRING *osalt = NULL; | ||
| 97 | ASN1_OBJECT *obj; | ||
| 98 | |||
| 99 | alg_nid = EVP_CIPHER_type(cipher); | ||
| 100 | if(alg_nid == NID_undef) { | ||
| 101 | ASN1err(ASN1_F_PKCS5_PBE2_SET, | ||
| 102 | ASN1_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER); | ||
| 103 | goto err; | ||
| 104 | } | ||
| 105 | obj = OBJ_nid2obj(alg_nid); | ||
| 106 | |||
| 107 | if(!(pbe2 = PBE2PARAM_new())) goto merr; | ||
| 108 | |||
| 109 | /* Setup the AlgorithmIdentifier for the encryption scheme */ | ||
| 110 | scheme = pbe2->encryption; | ||
| 111 | |||
| 112 | scheme->algorithm = obj; | ||
| 113 | if(!(scheme->parameter = ASN1_TYPE_new())) goto merr; | ||
| 114 | |||
| 115 | /* Create random IV */ | ||
| 116 | if (EVP_CIPHER_iv_length(cipher) && | ||
| 117 | RAND_pseudo_bytes(iv, EVP_CIPHER_iv_length(cipher)) < 0) | ||
| 118 | goto err; | ||
| 119 | |||
| 120 | EVP_CIPHER_CTX_init(&ctx); | ||
| 121 | |||
| 122 | /* Dummy cipherinit to just setup the IV */ | ||
| 123 | EVP_CipherInit_ex(&ctx, cipher, NULL, NULL, iv, 0); | ||
| 124 | if(EVP_CIPHER_param_to_asn1(&ctx, scheme->parameter) < 0) { | ||
| 125 | ASN1err(ASN1_F_PKCS5_PBE2_SET, | ||
| 126 | ASN1_R_ERROR_SETTING_CIPHER_PARAMS); | ||
| 127 | EVP_CIPHER_CTX_cleanup(&ctx); | ||
| 128 | goto err; | ||
| 129 | } | ||
| 130 | EVP_CIPHER_CTX_cleanup(&ctx); | ||
| 131 | |||
| 132 | if(!(kdf = PBKDF2PARAM_new())) goto merr; | ||
| 133 | if(!(osalt = M_ASN1_OCTET_STRING_new())) goto merr; | ||
| 134 | |||
| 135 | if (!saltlen) saltlen = PKCS5_SALT_LEN; | ||
| 136 | if (!(osalt->data = OPENSSL_malloc (saltlen))) goto merr; | ||
| 137 | osalt->length = saltlen; | ||
| 138 | if (salt) memcpy (osalt->data, salt, saltlen); | ||
| 139 | else if (RAND_pseudo_bytes (osalt->data, saltlen) < 0) goto merr; | ||
| 140 | |||
| 141 | if(iter <= 0) iter = PKCS5_DEFAULT_ITER; | ||
| 142 | if(!ASN1_INTEGER_set(kdf->iter, iter)) goto merr; | ||
| 143 | |||
| 144 | /* Now include salt in kdf structure */ | ||
| 145 | kdf->salt->value.octet_string = osalt; | ||
| 146 | kdf->salt->type = V_ASN1_OCTET_STRING; | ||
| 147 | osalt = NULL; | ||
| 148 | |||
| 149 | /* If its RC2 then we'd better setup the key length */ | ||
| 150 | |||
| 151 | if(alg_nid == NID_rc2_cbc) { | ||
| 152 | if(!(kdf->keylength = M_ASN1_INTEGER_new())) goto merr; | ||
| 153 | if(!ASN1_INTEGER_set (kdf->keylength, | ||
| 154 | EVP_CIPHER_key_length(cipher))) goto merr; | ||
| 155 | } | ||
| 156 | |||
| 157 | /* prf can stay NULL because we are using hmacWithSHA1 */ | ||
| 158 | |||
| 159 | /* Now setup the PBE2PARAM keyfunc structure */ | ||
| 160 | |||
| 161 | pbe2->keyfunc->algorithm = OBJ_nid2obj(NID_id_pbkdf2); | ||
| 162 | |||
| 163 | /* Encode PBKDF2PARAM into parameter of pbe2 */ | ||
| 164 | |||
| 165 | if(!(pbe2->keyfunc->parameter = ASN1_TYPE_new())) goto merr; | ||
| 166 | |||
| 167 | if(!ASN1_pack_string_of(PBKDF2PARAM, kdf, i2d_PBKDF2PARAM, | ||
| 168 | &pbe2->keyfunc->parameter->value.sequence)) goto merr; | ||
| 169 | pbe2->keyfunc->parameter->type = V_ASN1_SEQUENCE; | ||
| 170 | |||
| 171 | PBKDF2PARAM_free(kdf); | ||
| 172 | kdf = NULL; | ||
| 173 | |||
| 174 | /* Now set up top level AlgorithmIdentifier */ | ||
| 175 | |||
| 176 | if(!(ret = X509_ALGOR_new())) goto merr; | ||
| 177 | if(!(ret->parameter = ASN1_TYPE_new())) goto merr; | ||
| 178 | |||
| 179 | ret->algorithm = OBJ_nid2obj(NID_pbes2); | ||
| 180 | |||
| 181 | /* Encode PBE2PARAM into parameter */ | ||
| 182 | |||
| 183 | if(!ASN1_pack_string_of(PBE2PARAM, pbe2, i2d_PBE2PARAM, | ||
| 184 | &ret->parameter->value.sequence)) goto merr; | ||
| 185 | ret->parameter->type = V_ASN1_SEQUENCE; | ||
| 186 | |||
| 187 | PBE2PARAM_free(pbe2); | ||
| 188 | pbe2 = NULL; | ||
| 189 | |||
| 190 | return ret; | ||
| 191 | |||
| 192 | merr: | ||
| 193 | ASN1err(ASN1_F_PKCS5_PBE2_SET,ERR_R_MALLOC_FAILURE); | ||
| 194 | |||
| 195 | err: | ||
| 196 | PBE2PARAM_free(pbe2); | ||
| 197 | /* Note 'scheme' is freed as part of pbe2 */ | ||
| 198 | M_ASN1_OCTET_STRING_free(osalt); | ||
| 199 | PBKDF2PARAM_free(kdf); | ||
| 200 | X509_ALGOR_free(kalg); | ||
| 201 | X509_ALGOR_free(ret); | ||
| 202 | |||
| 203 | return NULL; | ||
| 204 | |||
| 205 | } | ||
diff --git a/src/lib/libcrypto/asn1/p8_key.c b/src/lib/libcrypto/asn1/p8_key.c new file mode 100644 index 0000000000..3a31248e14 --- /dev/null +++ b/src/lib/libcrypto/asn1/p8_key.c | |||
| @@ -0,0 +1,131 @@ | |||
| 1 | /* crypto/asn1/p8_key.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/asn1_mac.h> | ||
| 62 | #include <openssl/objects.h> | ||
| 63 | |||
| 64 | int i2d_X509_KEY(X509 *a, unsigned char **pp) | ||
| 65 | { | ||
| 66 | M_ASN1_I2D_vars(a); | ||
| 67 | |||
| 68 | M_ASN1_I2D_len(a->cert_info, i2d_X509_CINF); | ||
| 69 | M_ASN1_I2D_len(a->sig_alg, i2d_X509_ALGOR); | ||
| 70 | M_ASN1_I2D_len(a->signature, i2d_ASN1_BIT_STRING); | ||
| 71 | |||
| 72 | M_ASN1_I2D_seq_total(); | ||
| 73 | |||
| 74 | M_ASN1_I2D_put(a->cert_info, i2d_X509_CINF); | ||
| 75 | M_ASN1_I2D_put(a->sig_alg, i2d_X509_ALGOR); | ||
| 76 | M_ASN1_I2D_put(a->signature, i2d_ASN1_BIT_STRING); | ||
| 77 | |||
| 78 | M_ASN1_I2D_finish(); | ||
| 79 | } | ||
| 80 | |||
| 81 | X509 *d2i_X509_KEY(X509 **a, unsigned char **pp, long length) | ||
| 82 | { | ||
| 83 | M_ASN1_D2I_vars(a,X509 *,X509_new); | ||
| 84 | |||
| 85 | M_ASN1_D2I_Init(); | ||
| 86 | M_ASN1_D2I_start_sequence(); | ||
| 87 | M_ASN1_D2I_get(ret->cert_info,d2i_X509_CINF); | ||
| 88 | M_ASN1_D2I_get(ret->sig_alg,d2i_X509_ALGOR); | ||
| 89 | M_ASN1_D2I_get(ret->signature,d2i_ASN1_BIT_STRING); | ||
| 90 | M_ASN1_D2I_Finish(a,X509_free,ASN1_F_D2I_X509); | ||
| 91 | } | ||
| 92 | |||
| 93 | X509 *X509_KEY_new(void) | ||
| 94 | { | ||
| 95 | X509_KEY *ret=NULL; | ||
| 96 | |||
| 97 | M_ASN1_New_OPENSSL_malloc(ret,X509_KEY); | ||
| 98 | ret->references=1; | ||
| 99 | ret->type=NID | ||
| 100 | M_ASN1_New(ret->cert_info,X509_CINF_new); | ||
| 101 | M_ASN1_New(ret->sig_alg,X509_ALGOR_new); | ||
| 102 | M_ASN1_New(ret->signature,ASN1_BIT_STRING_new); | ||
| 103 | return(ret); | ||
| 104 | M_ASN1_New_Error(ASN1_F_X509_NEW); | ||
| 105 | } | ||
| 106 | |||
| 107 | void X509_KEY_free(X509 *a) | ||
| 108 | { | ||
| 109 | int i; | ||
| 110 | |||
| 111 | if (a == NULL) return; | ||
| 112 | |||
| 113 | i=CRYPTO_add_lock(&a->references,-1,CRYPTO_LOCK_X509_KEY); | ||
| 114 | #ifdef REF_PRINT | ||
| 115 | REF_PRINT("X509_KEY",a); | ||
| 116 | #endif | ||
| 117 | if (i > 0) return; | ||
| 118 | #ifdef REF_CHECK | ||
| 119 | if (i < 0) | ||
| 120 | { | ||
| 121 | fprintf(stderr,"X509_KEY_free, bad reference count\n"); | ||
| 122 | abort(); | ||
| 123 | } | ||
| 124 | #endif | ||
| 125 | |||
| 126 | X509_CINF_free(a->cert_info); | ||
| 127 | X509_ALGOR_free(a->sig_alg); | ||
| 128 | ASN1_BIT_STRING_free(a->signature); | ||
| 129 | OPENSSL_free(a); | ||
| 130 | } | ||
| 131 | |||
diff --git a/src/lib/libcrypto/asn1/p8_pkey.c b/src/lib/libcrypto/asn1/p8_pkey.c new file mode 100644 index 0000000000..24b409132f --- /dev/null +++ b/src/lib/libcrypto/asn1/p8_pkey.c | |||
| @@ -0,0 +1,84 @@ | |||
| 1 | /* p8_pkey.c */ | ||
| 2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
| 3 | * project 1999. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/asn1t.h> | ||
| 62 | #include <openssl/x509.h> | ||
| 63 | |||
| 64 | /* Minor tweak to operation: zero private key data */ | ||
| 65 | static int pkey_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it) | ||
| 66 | { | ||
| 67 | /* Since the structure must still be valid use ASN1_OP_FREE_PRE */ | ||
| 68 | if(operation == ASN1_OP_FREE_PRE) { | ||
| 69 | PKCS8_PRIV_KEY_INFO *key = (PKCS8_PRIV_KEY_INFO *)*pval; | ||
| 70 | if (key->pkey->value.octet_string) | ||
| 71 | OPENSSL_cleanse(key->pkey->value.octet_string->data, | ||
| 72 | key->pkey->value.octet_string->length); | ||
| 73 | } | ||
| 74 | return 1; | ||
| 75 | } | ||
| 76 | |||
| 77 | ASN1_SEQUENCE_cb(PKCS8_PRIV_KEY_INFO, pkey_cb) = { | ||
| 78 | ASN1_SIMPLE(PKCS8_PRIV_KEY_INFO, version, ASN1_INTEGER), | ||
| 79 | ASN1_SIMPLE(PKCS8_PRIV_KEY_INFO, pkeyalg, X509_ALGOR), | ||
| 80 | ASN1_SIMPLE(PKCS8_PRIV_KEY_INFO, pkey, ASN1_ANY), | ||
| 81 | ASN1_IMP_SET_OF_OPT(PKCS8_PRIV_KEY_INFO, attributes, X509_ATTRIBUTE, 0) | ||
| 82 | } ASN1_SEQUENCE_END_cb(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO) | ||
| 83 | |||
| 84 | IMPLEMENT_ASN1_FUNCTIONS(PKCS8_PRIV_KEY_INFO) | ||
diff --git a/src/lib/libcrypto/asn1/t_bitst.c b/src/lib/libcrypto/asn1/t_bitst.c new file mode 100644 index 0000000000..397332d9b8 --- /dev/null +++ b/src/lib/libcrypto/asn1/t_bitst.c | |||
| @@ -0,0 +1,102 @@ | |||
| 1 | /* t_bitst.c */ | ||
| 2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
| 3 | * project 1999. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/conf.h> | ||
| 62 | #include <openssl/x509v3.h> | ||
| 63 | |||
| 64 | int ASN1_BIT_STRING_name_print(BIO *out, ASN1_BIT_STRING *bs, | ||
| 65 | BIT_STRING_BITNAME *tbl, int indent) | ||
| 66 | { | ||
| 67 | BIT_STRING_BITNAME *bnam; | ||
| 68 | char first = 1; | ||
| 69 | BIO_printf(out, "%*s", indent, ""); | ||
| 70 | for(bnam = tbl; bnam->lname; bnam++) { | ||
| 71 | if(ASN1_BIT_STRING_get_bit(bs, bnam->bitnum)) { | ||
| 72 | if(!first) BIO_puts(out, ", "); | ||
| 73 | BIO_puts(out, bnam->lname); | ||
| 74 | first = 0; | ||
| 75 | } | ||
| 76 | } | ||
| 77 | BIO_puts(out, "\n"); | ||
| 78 | return 1; | ||
| 79 | } | ||
| 80 | |||
| 81 | int ASN1_BIT_STRING_set_asc(ASN1_BIT_STRING *bs, char *name, int value, | ||
| 82 | BIT_STRING_BITNAME *tbl) | ||
| 83 | { | ||
| 84 | int bitnum; | ||
| 85 | bitnum = ASN1_BIT_STRING_num_asc(name, tbl); | ||
| 86 | if(bitnum < 0) return 0; | ||
| 87 | if(bs) { | ||
| 88 | if(!ASN1_BIT_STRING_set_bit(bs, bitnum, value)) | ||
| 89 | return 0; | ||
| 90 | } | ||
| 91 | return 1; | ||
| 92 | } | ||
| 93 | |||
| 94 | int ASN1_BIT_STRING_num_asc(char *name, BIT_STRING_BITNAME *tbl) | ||
| 95 | { | ||
| 96 | BIT_STRING_BITNAME *bnam; | ||
| 97 | for(bnam = tbl; bnam->lname; bnam++) { | ||
| 98 | if(!strcmp(bnam->sname, name) || | ||
| 99 | !strcmp(bnam->lname, name) ) return bnam->bitnum; | ||
| 100 | } | ||
| 101 | return -1; | ||
| 102 | } | ||
diff --git a/src/lib/libcrypto/asn1/t_crl.c b/src/lib/libcrypto/asn1/t_crl.c new file mode 100644 index 0000000000..929b3e5904 --- /dev/null +++ b/src/lib/libcrypto/asn1/t_crl.c | |||
| @@ -0,0 +1,134 @@ | |||
| 1 | /* t_crl.c */ | ||
| 2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
| 3 | * project 1999. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/buffer.h> | ||
| 62 | #include <openssl/bn.h> | ||
| 63 | #include <openssl/objects.h> | ||
| 64 | #include <openssl/x509.h> | ||
| 65 | #include <openssl/x509v3.h> | ||
| 66 | |||
| 67 | #ifndef OPENSSL_NO_FP_API | ||
| 68 | int X509_CRL_print_fp(FILE *fp, X509_CRL *x) | ||
| 69 | { | ||
| 70 | BIO *b; | ||
| 71 | int ret; | ||
| 72 | |||
| 73 | if ((b=BIO_new(BIO_s_file())) == NULL) | ||
| 74 | { | ||
| 75 | X509err(X509_F_X509_CRL_PRINT_FP,ERR_R_BUF_LIB); | ||
| 76 | return(0); | ||
| 77 | } | ||
| 78 | BIO_set_fp(b,fp,BIO_NOCLOSE); | ||
| 79 | ret=X509_CRL_print(b, x); | ||
| 80 | BIO_free(b); | ||
| 81 | return(ret); | ||
| 82 | } | ||
| 83 | #endif | ||
| 84 | |||
| 85 | int X509_CRL_print(BIO *out, X509_CRL *x) | ||
| 86 | { | ||
| 87 | STACK_OF(X509_REVOKED) *rev; | ||
| 88 | X509_REVOKED *r; | ||
| 89 | long l; | ||
| 90 | int i, n; | ||
| 91 | char *p; | ||
| 92 | |||
| 93 | BIO_printf(out, "Certificate Revocation List (CRL):\n"); | ||
| 94 | l = X509_CRL_get_version(x); | ||
| 95 | BIO_printf(out, "%8sVersion %lu (0x%lx)\n", "", l+1, l); | ||
| 96 | i = OBJ_obj2nid(x->sig_alg->algorithm); | ||
| 97 | BIO_printf(out, "%8sSignature Algorithm: %s\n", "", | ||
| 98 | (i == NID_undef) ? "NONE" : OBJ_nid2ln(i)); | ||
| 99 | p=X509_NAME_oneline(X509_CRL_get_issuer(x),NULL,0); | ||
| 100 | BIO_printf(out,"%8sIssuer: %s\n","",p); | ||
| 101 | OPENSSL_free(p); | ||
| 102 | BIO_printf(out,"%8sLast Update: ",""); | ||
| 103 | ASN1_TIME_print(out,X509_CRL_get_lastUpdate(x)); | ||
| 104 | BIO_printf(out,"\n%8sNext Update: ",""); | ||
| 105 | if (X509_CRL_get_nextUpdate(x)) | ||
| 106 | ASN1_TIME_print(out,X509_CRL_get_nextUpdate(x)); | ||
| 107 | else BIO_printf(out,"NONE"); | ||
| 108 | BIO_printf(out,"\n"); | ||
| 109 | |||
| 110 | n=X509_CRL_get_ext_count(x); | ||
| 111 | X509V3_extensions_print(out, "CRL extensions", | ||
| 112 | x->crl->extensions, 0, 8); | ||
| 113 | |||
| 114 | rev = X509_CRL_get_REVOKED(x); | ||
| 115 | |||
| 116 | if(sk_X509_REVOKED_num(rev) > 0) | ||
| 117 | BIO_printf(out, "Revoked Certificates:\n"); | ||
| 118 | else BIO_printf(out, "No Revoked Certificates.\n"); | ||
| 119 | |||
| 120 | for(i = 0; i < sk_X509_REVOKED_num(rev); i++) { | ||
| 121 | r = sk_X509_REVOKED_value(rev, i); | ||
| 122 | BIO_printf(out," Serial Number: "); | ||
| 123 | i2a_ASN1_INTEGER(out,r->serialNumber); | ||
| 124 | BIO_printf(out,"\n Revocation Date: "); | ||
| 125 | ASN1_TIME_print(out,r->revocationDate); | ||
| 126 | BIO_printf(out,"\n"); | ||
| 127 | X509V3_extensions_print(out, "CRL entry extensions", | ||
| 128 | r->extensions, 0, 8); | ||
| 129 | } | ||
| 130 | X509_signature_print(out, x->sig_alg, x->signature); | ||
| 131 | |||
| 132 | return 1; | ||
| 133 | |||
| 134 | } | ||
diff --git a/src/lib/libcrypto/asn1/t_pkey.c b/src/lib/libcrypto/asn1/t_pkey.c new file mode 100644 index 0000000000..afb95d6712 --- /dev/null +++ b/src/lib/libcrypto/asn1/t_pkey.c | |||
| @@ -0,0 +1,839 @@ | |||
| 1 | /* crypto/asn1/t_pkey.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | /* ==================================================================== | ||
| 59 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. | ||
| 60 | * Binary polynomial ECC support in OpenSSL originally developed by | ||
| 61 | * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project. | ||
| 62 | */ | ||
| 63 | |||
| 64 | #include <stdio.h> | ||
| 65 | #include "cryptlib.h" | ||
| 66 | #include <openssl/objects.h> | ||
| 67 | #include <openssl/buffer.h> | ||
| 68 | #include <openssl/bn.h> | ||
| 69 | #ifndef OPENSSL_NO_RSA | ||
| 70 | #include <openssl/rsa.h> | ||
| 71 | #endif | ||
| 72 | #ifndef OPENSSL_NO_DH | ||
| 73 | #include <openssl/dh.h> | ||
| 74 | #endif | ||
| 75 | #ifndef OPENSSL_NO_DSA | ||
| 76 | #include <openssl/dsa.h> | ||
| 77 | #endif | ||
| 78 | #ifndef OPENSSL_NO_EC | ||
| 79 | #include <openssl/ec.h> | ||
| 80 | #endif | ||
| 81 | |||
| 82 | static int print(BIO *fp,const char *str, const BIGNUM *num, | ||
| 83 | unsigned char *buf,int off); | ||
| 84 | #ifndef OPENSSL_NO_EC | ||
| 85 | static int print_bin(BIO *fp, const char *str, const unsigned char *num, | ||
| 86 | size_t len, int off); | ||
| 87 | #endif | ||
| 88 | #ifndef OPENSSL_NO_RSA | ||
| 89 | #ifndef OPENSSL_NO_FP_API | ||
| 90 | int RSA_print_fp(FILE *fp, const RSA *x, int off) | ||
| 91 | { | ||
| 92 | BIO *b; | ||
| 93 | int ret; | ||
| 94 | |||
| 95 | if ((b=BIO_new(BIO_s_file())) == NULL) | ||
| 96 | { | ||
| 97 | RSAerr(RSA_F_RSA_PRINT_FP,ERR_R_BUF_LIB); | ||
| 98 | return(0); | ||
| 99 | } | ||
| 100 | BIO_set_fp(b,fp,BIO_NOCLOSE); | ||
| 101 | ret=RSA_print(b,x,off); | ||
| 102 | BIO_free(b); | ||
| 103 | return(ret); | ||
| 104 | } | ||
| 105 | #endif | ||
| 106 | |||
| 107 | int RSA_print(BIO *bp, const RSA *x, int off) | ||
| 108 | { | ||
| 109 | char str[128]; | ||
| 110 | const char *s; | ||
| 111 | unsigned char *m=NULL; | ||
| 112 | int ret=0, mod_len = 0; | ||
| 113 | size_t buf_len=0, i; | ||
| 114 | |||
| 115 | if (x->n) | ||
| 116 | buf_len = (size_t)BN_num_bytes(x->n); | ||
| 117 | if (x->e) | ||
| 118 | if (buf_len < (i = (size_t)BN_num_bytes(x->e))) | ||
| 119 | buf_len = i; | ||
| 120 | if (x->d) | ||
| 121 | if (buf_len < (i = (size_t)BN_num_bytes(x->d))) | ||
| 122 | buf_len = i; | ||
| 123 | if (x->p) | ||
| 124 | if (buf_len < (i = (size_t)BN_num_bytes(x->p))) | ||
| 125 | buf_len = i; | ||
| 126 | if (x->q) | ||
| 127 | if (buf_len < (i = (size_t)BN_num_bytes(x->q))) | ||
| 128 | buf_len = i; | ||
| 129 | if (x->dmp1) | ||
| 130 | if (buf_len < (i = (size_t)BN_num_bytes(x->dmp1))) | ||
| 131 | buf_len = i; | ||
| 132 | if (x->dmq1) | ||
| 133 | if (buf_len < (i = (size_t)BN_num_bytes(x->dmq1))) | ||
| 134 | buf_len = i; | ||
| 135 | if (x->iqmp) | ||
| 136 | if (buf_len < (i = (size_t)BN_num_bytes(x->iqmp))) | ||
| 137 | buf_len = i; | ||
| 138 | |||
| 139 | m=(unsigned char *)OPENSSL_malloc(buf_len+10); | ||
| 140 | if (m == NULL) | ||
| 141 | { | ||
| 142 | RSAerr(RSA_F_RSA_PRINT,ERR_R_MALLOC_FAILURE); | ||
| 143 | goto err; | ||
| 144 | } | ||
| 145 | |||
| 146 | if (x->n != NULL) | ||
| 147 | mod_len = BN_num_bits(x->n); | ||
| 148 | |||
| 149 | if (x->d != NULL) | ||
| 150 | { | ||
| 151 | if(!BIO_indent(bp,off,128)) | ||
| 152 | goto err; | ||
| 153 | if (BIO_printf(bp,"Private-Key: (%d bit)\n", mod_len) | ||
| 154 | <= 0) goto err; | ||
| 155 | } | ||
| 156 | |||
| 157 | if (x->d == NULL) | ||
| 158 | BIO_snprintf(str,sizeof str,"Modulus (%d bit):", mod_len); | ||
| 159 | else | ||
| 160 | BUF_strlcpy(str,"modulus:",sizeof str); | ||
| 161 | if (!print(bp,str,x->n,m,off)) goto err; | ||
| 162 | s=(x->d == NULL)?"Exponent:":"publicExponent:"; | ||
| 163 | if ((x->e != NULL) && !print(bp,s,x->e,m,off)) | ||
| 164 | goto err; | ||
| 165 | if ((x->d != NULL) && !print(bp,"privateExponent:",x->d,m,off)) | ||
| 166 | goto err; | ||
| 167 | if ((x->p != NULL) && !print(bp,"prime1:",x->p,m,off)) | ||
| 168 | goto err; | ||
| 169 | if ((x->q != NULL) && !print(bp,"prime2:",x->q,m,off)) | ||
| 170 | goto err; | ||
| 171 | if ((x->dmp1 != NULL) && !print(bp,"exponent1:",x->dmp1,m,off)) | ||
| 172 | goto err; | ||
| 173 | if ((x->dmq1 != NULL) && !print(bp,"exponent2:",x->dmq1,m,off)) | ||
| 174 | goto err; | ||
| 175 | if ((x->iqmp != NULL) && !print(bp,"coefficient:",x->iqmp,m,off)) | ||
| 176 | goto err; | ||
| 177 | ret=1; | ||
| 178 | err: | ||
| 179 | if (m != NULL) OPENSSL_free(m); | ||
| 180 | return(ret); | ||
| 181 | } | ||
| 182 | #endif /* OPENSSL_NO_RSA */ | ||
| 183 | |||
| 184 | #ifndef OPENSSL_NO_DSA | ||
| 185 | #ifndef OPENSSL_NO_FP_API | ||
| 186 | int DSA_print_fp(FILE *fp, const DSA *x, int off) | ||
| 187 | { | ||
| 188 | BIO *b; | ||
| 189 | int ret; | ||
| 190 | |||
| 191 | if ((b=BIO_new(BIO_s_file())) == NULL) | ||
| 192 | { | ||
| 193 | DSAerr(DSA_F_DSA_PRINT_FP,ERR_R_BUF_LIB); | ||
| 194 | return(0); | ||
| 195 | } | ||
| 196 | BIO_set_fp(b,fp,BIO_NOCLOSE); | ||
| 197 | ret=DSA_print(b,x,off); | ||
| 198 | BIO_free(b); | ||
| 199 | return(ret); | ||
| 200 | } | ||
| 201 | #endif | ||
| 202 | |||
| 203 | int DSA_print(BIO *bp, const DSA *x, int off) | ||
| 204 | { | ||
| 205 | unsigned char *m=NULL; | ||
| 206 | int ret=0; | ||
| 207 | size_t buf_len=0,i; | ||
| 208 | |||
| 209 | if (x->p) | ||
| 210 | buf_len = (size_t)BN_num_bytes(x->p); | ||
| 211 | else | ||
| 212 | { | ||
| 213 | DSAerr(DSA_F_DSA_PRINT,DSA_R_MISSING_PARAMETERS); | ||
| 214 | goto err; | ||
| 215 | } | ||
| 216 | if (x->q) | ||
| 217 | if (buf_len < (i = (size_t)BN_num_bytes(x->q))) | ||
| 218 | buf_len = i; | ||
| 219 | if (x->g) | ||
| 220 | if (buf_len < (i = (size_t)BN_num_bytes(x->g))) | ||
| 221 | buf_len = i; | ||
| 222 | if (x->priv_key) | ||
| 223 | if (buf_len < (i = (size_t)BN_num_bytes(x->priv_key))) | ||
| 224 | buf_len = i; | ||
| 225 | if (x->pub_key) | ||
| 226 | if (buf_len < (i = (size_t)BN_num_bytes(x->pub_key))) | ||
| 227 | buf_len = i; | ||
| 228 | |||
| 229 | m=(unsigned char *)OPENSSL_malloc(buf_len+10); | ||
| 230 | if (m == NULL) | ||
| 231 | { | ||
| 232 | DSAerr(DSA_F_DSA_PRINT,ERR_R_MALLOC_FAILURE); | ||
| 233 | goto err; | ||
| 234 | } | ||
| 235 | |||
| 236 | if (x->priv_key != NULL) | ||
| 237 | { | ||
| 238 | if(!BIO_indent(bp,off,128)) | ||
| 239 | goto err; | ||
| 240 | if (BIO_printf(bp,"Private-Key: (%d bit)\n",BN_num_bits(x->p)) | ||
| 241 | <= 0) goto err; | ||
| 242 | } | ||
| 243 | |||
| 244 | if ((x->priv_key != NULL) && !print(bp,"priv:",x->priv_key,m,off)) | ||
| 245 | goto err; | ||
| 246 | if ((x->pub_key != NULL) && !print(bp,"pub: ",x->pub_key,m,off)) | ||
| 247 | goto err; | ||
| 248 | if ((x->p != NULL) && !print(bp,"P: ",x->p,m,off)) goto err; | ||
| 249 | if ((x->q != NULL) && !print(bp,"Q: ",x->q,m,off)) goto err; | ||
| 250 | if ((x->g != NULL) && !print(bp,"G: ",x->g,m,off)) goto err; | ||
| 251 | ret=1; | ||
| 252 | err: | ||
| 253 | if (m != NULL) OPENSSL_free(m); | ||
| 254 | return(ret); | ||
| 255 | } | ||
| 256 | #endif /* !OPENSSL_NO_DSA */ | ||
| 257 | |||
| 258 | #ifndef OPENSSL_NO_EC | ||
| 259 | #ifndef OPENSSL_NO_FP_API | ||
| 260 | int ECPKParameters_print_fp(FILE *fp, const EC_GROUP *x, int off) | ||
| 261 | { | ||
| 262 | BIO *b; | ||
| 263 | int ret; | ||
| 264 | |||
| 265 | if ((b=BIO_new(BIO_s_file())) == NULL) | ||
| 266 | { | ||
| 267 | ECerr(EC_F_ECPKPARAMETERS_PRINT_FP,ERR_R_BUF_LIB); | ||
| 268 | return(0); | ||
| 269 | } | ||
| 270 | BIO_set_fp(b, fp, BIO_NOCLOSE); | ||
| 271 | ret = ECPKParameters_print(b, x, off); | ||
| 272 | BIO_free(b); | ||
| 273 | return(ret); | ||
| 274 | } | ||
| 275 | |||
| 276 | int EC_KEY_print_fp(FILE *fp, const EC_KEY *x, int off) | ||
| 277 | { | ||
| 278 | BIO *b; | ||
| 279 | int ret; | ||
| 280 | |||
| 281 | if ((b=BIO_new(BIO_s_file())) == NULL) | ||
| 282 | { | ||
| 283 | ECerr(EC_F_EC_KEY_PRINT_FP, ERR_R_BIO_LIB); | ||
| 284 | return(0); | ||
| 285 | } | ||
| 286 | BIO_set_fp(b, fp, BIO_NOCLOSE); | ||
| 287 | ret = EC_KEY_print(b, x, off); | ||
| 288 | BIO_free(b); | ||
| 289 | return(ret); | ||
| 290 | } | ||
| 291 | #endif | ||
| 292 | |||
| 293 | int ECPKParameters_print(BIO *bp, const EC_GROUP *x, int off) | ||
| 294 | { | ||
| 295 | unsigned char *buffer=NULL; | ||
| 296 | size_t buf_len=0, i; | ||
| 297 | int ret=0, reason=ERR_R_BIO_LIB; | ||
| 298 | BN_CTX *ctx=NULL; | ||
| 299 | const EC_POINT *point=NULL; | ||
| 300 | BIGNUM *p=NULL, *a=NULL, *b=NULL, *gen=NULL, | ||
| 301 | *order=NULL, *cofactor=NULL; | ||
| 302 | const unsigned char *seed; | ||
| 303 | size_t seed_len=0; | ||
| 304 | |||
| 305 | static const char *gen_compressed = "Generator (compressed):"; | ||
| 306 | static const char *gen_uncompressed = "Generator (uncompressed):"; | ||
| 307 | static const char *gen_hybrid = "Generator (hybrid):"; | ||
| 308 | |||
| 309 | if (!x) | ||
| 310 | { | ||
| 311 | reason = ERR_R_PASSED_NULL_PARAMETER; | ||
| 312 | goto err; | ||
| 313 | } | ||
| 314 | |||
| 315 | if (EC_GROUP_get_asn1_flag(x)) | ||
| 316 | { | ||
| 317 | /* the curve parameter are given by an asn1 OID */ | ||
| 318 | int nid; | ||
| 319 | |||
| 320 | if (!BIO_indent(bp, off, 128)) | ||
| 321 | goto err; | ||
| 322 | |||
| 323 | nid = EC_GROUP_get_curve_name(x); | ||
| 324 | if (nid == 0) | ||
| 325 | goto err; | ||
| 326 | |||
| 327 | if (BIO_printf(bp, "ASN1 OID: %s", OBJ_nid2sn(nid)) <= 0) | ||
| 328 | goto err; | ||
| 329 | if (BIO_printf(bp, "\n") <= 0) | ||
| 330 | goto err; | ||
| 331 | } | ||
| 332 | else | ||
| 333 | { | ||
| 334 | /* explicit parameters */ | ||
| 335 | int is_char_two = 0; | ||
| 336 | point_conversion_form_t form; | ||
| 337 | int tmp_nid = EC_METHOD_get_field_type(EC_GROUP_method_of(x)); | ||
| 338 | |||
| 339 | if (tmp_nid == NID_X9_62_characteristic_two_field) | ||
| 340 | is_char_two = 1; | ||
| 341 | |||
| 342 | if ((p = BN_new()) == NULL || (a = BN_new()) == NULL || | ||
| 343 | (b = BN_new()) == NULL || (order = BN_new()) == NULL || | ||
| 344 | (cofactor = BN_new()) == NULL) | ||
| 345 | { | ||
| 346 | reason = ERR_R_MALLOC_FAILURE; | ||
| 347 | goto err; | ||
| 348 | } | ||
| 349 | |||
| 350 | if (is_char_two) | ||
| 351 | { | ||
| 352 | if (!EC_GROUP_get_curve_GF2m(x, p, a, b, ctx)) | ||
| 353 | { | ||
| 354 | reason = ERR_R_EC_LIB; | ||
| 355 | goto err; | ||
| 356 | } | ||
| 357 | } | ||
| 358 | else /* prime field */ | ||
| 359 | { | ||
| 360 | if (!EC_GROUP_get_curve_GFp(x, p, a, b, ctx)) | ||
| 361 | { | ||
| 362 | reason = ERR_R_EC_LIB; | ||
| 363 | goto err; | ||
| 364 | } | ||
| 365 | } | ||
| 366 | |||
| 367 | if ((point = EC_GROUP_get0_generator(x)) == NULL) | ||
| 368 | { | ||
| 369 | reason = ERR_R_EC_LIB; | ||
| 370 | goto err; | ||
| 371 | } | ||
| 372 | if (!EC_GROUP_get_order(x, order, NULL) || | ||
| 373 | !EC_GROUP_get_cofactor(x, cofactor, NULL)) | ||
| 374 | { | ||
| 375 | reason = ERR_R_EC_LIB; | ||
| 376 | goto err; | ||
| 377 | } | ||
| 378 | |||
| 379 | form = EC_GROUP_get_point_conversion_form(x); | ||
| 380 | |||
| 381 | if ((gen = EC_POINT_point2bn(x, point, | ||
| 382 | form, NULL, ctx)) == NULL) | ||
| 383 | { | ||
| 384 | reason = ERR_R_EC_LIB; | ||
| 385 | goto err; | ||
| 386 | } | ||
| 387 | |||
| 388 | buf_len = (size_t)BN_num_bytes(p); | ||
| 389 | if (buf_len < (i = (size_t)BN_num_bytes(a))) | ||
| 390 | buf_len = i; | ||
| 391 | if (buf_len < (i = (size_t)BN_num_bytes(b))) | ||
| 392 | buf_len = i; | ||
| 393 | if (buf_len < (i = (size_t)BN_num_bytes(gen))) | ||
| 394 | buf_len = i; | ||
| 395 | if (buf_len < (i = (size_t)BN_num_bytes(order))) | ||
| 396 | buf_len = i; | ||
| 397 | if (buf_len < (i = (size_t)BN_num_bytes(cofactor))) | ||
| 398 | buf_len = i; | ||
| 399 | |||
| 400 | if ((seed = EC_GROUP_get0_seed(x)) != NULL) | ||
| 401 | seed_len = EC_GROUP_get_seed_len(x); | ||
| 402 | |||
| 403 | buf_len += 10; | ||
| 404 | if ((buffer = OPENSSL_malloc(buf_len)) == NULL) | ||
| 405 | { | ||
| 406 | reason = ERR_R_MALLOC_FAILURE; | ||
| 407 | goto err; | ||
| 408 | } | ||
| 409 | |||
| 410 | if (!BIO_indent(bp, off, 128)) | ||
| 411 | goto err; | ||
| 412 | |||
| 413 | /* print the 'short name' of the field type */ | ||
| 414 | if (BIO_printf(bp, "Field Type: %s\n", OBJ_nid2sn(tmp_nid)) | ||
| 415 | <= 0) | ||
| 416 | goto err; | ||
| 417 | |||
| 418 | if (is_char_two) | ||
| 419 | { | ||
| 420 | /* print the 'short name' of the base type OID */ | ||
| 421 | int basis_type = EC_GROUP_get_basis_type(x); | ||
| 422 | if (basis_type == 0) | ||
| 423 | goto err; | ||
| 424 | |||
| 425 | if (!BIO_indent(bp, off, 128)) | ||
| 426 | goto err; | ||
| 427 | |||
| 428 | if (BIO_printf(bp, "Basis Type: %s\n", | ||
| 429 | OBJ_nid2sn(basis_type)) <= 0) | ||
| 430 | goto err; | ||
| 431 | |||
| 432 | /* print the polynomial */ | ||
| 433 | if ((p != NULL) && !print(bp, "Polynomial:", p, buffer, | ||
| 434 | off)) | ||
| 435 | goto err; | ||
| 436 | } | ||
| 437 | else | ||
| 438 | { | ||
| 439 | if ((p != NULL) && !print(bp, "Prime:", p, buffer,off)) | ||
| 440 | goto err; | ||
| 441 | } | ||
| 442 | if ((a != NULL) && !print(bp, "A: ", a, buffer, off)) | ||
| 443 | goto err; | ||
| 444 | if ((b != NULL) && !print(bp, "B: ", b, buffer, off)) | ||
| 445 | goto err; | ||
| 446 | if (form == POINT_CONVERSION_COMPRESSED) | ||
| 447 | { | ||
| 448 | if ((gen != NULL) && !print(bp, gen_compressed, gen, | ||
| 449 | buffer, off)) | ||
| 450 | goto err; | ||
| 451 | } | ||
| 452 | else if (form == POINT_CONVERSION_UNCOMPRESSED) | ||
| 453 | { | ||
| 454 | if ((gen != NULL) && !print(bp, gen_uncompressed, gen, | ||
| 455 | buffer, off)) | ||
| 456 | goto err; | ||
| 457 | } | ||
| 458 | else /* form == POINT_CONVERSION_HYBRID */ | ||
| 459 | { | ||
| 460 | if ((gen != NULL) && !print(bp, gen_hybrid, gen, | ||
| 461 | buffer, off)) | ||
| 462 | goto err; | ||
| 463 | } | ||
| 464 | if ((order != NULL) && !print(bp, "Order: ", order, | ||
| 465 | buffer, off)) goto err; | ||
| 466 | if ((cofactor != NULL) && !print(bp, "Cofactor: ", cofactor, | ||
| 467 | buffer, off)) goto err; | ||
| 468 | if (seed && !print_bin(bp, "Seed:", seed, seed_len, off)) | ||
| 469 | goto err; | ||
| 470 | } | ||
| 471 | ret=1; | ||
| 472 | err: | ||
| 473 | if (!ret) | ||
| 474 | ECerr(EC_F_ECPKPARAMETERS_PRINT, reason); | ||
| 475 | if (p) | ||
| 476 | BN_free(p); | ||
| 477 | if (a) | ||
| 478 | BN_free(a); | ||
| 479 | if (b) | ||
| 480 | BN_free(b); | ||
| 481 | if (gen) | ||
| 482 | BN_free(gen); | ||
| 483 | if (order) | ||
| 484 | BN_free(order); | ||
| 485 | if (cofactor) | ||
| 486 | BN_free(cofactor); | ||
| 487 | if (ctx) | ||
| 488 | BN_CTX_free(ctx); | ||
| 489 | if (buffer != NULL) | ||
| 490 | OPENSSL_free(buffer); | ||
| 491 | return(ret); | ||
| 492 | } | ||
| 493 | |||
| 494 | int EC_KEY_print(BIO *bp, const EC_KEY *x, int off) | ||
| 495 | { | ||
| 496 | unsigned char *buffer=NULL; | ||
| 497 | size_t buf_len=0, i; | ||
| 498 | int ret=0, reason=ERR_R_BIO_LIB; | ||
| 499 | BIGNUM *pub_key=NULL, *order=NULL; | ||
| 500 | BN_CTX *ctx=NULL; | ||
| 501 | const EC_GROUP *group; | ||
| 502 | const EC_POINT *public_key; | ||
| 503 | const BIGNUM *priv_key; | ||
| 504 | |||
| 505 | if (x == NULL || (group = EC_KEY_get0_group(x)) == NULL) | ||
| 506 | { | ||
| 507 | reason = ERR_R_PASSED_NULL_PARAMETER; | ||
| 508 | goto err; | ||
| 509 | } | ||
| 510 | |||
| 511 | public_key = EC_KEY_get0_public_key(x); | ||
| 512 | if ((pub_key = EC_POINT_point2bn(group, public_key, | ||
| 513 | EC_KEY_get_conv_form(x), NULL, ctx)) == NULL) | ||
| 514 | { | ||
| 515 | reason = ERR_R_EC_LIB; | ||
| 516 | goto err; | ||
| 517 | } | ||
| 518 | |||
| 519 | buf_len = (size_t)BN_num_bytes(pub_key); | ||
| 520 | priv_key = EC_KEY_get0_private_key(x); | ||
| 521 | if (priv_key != NULL) | ||
| 522 | { | ||
| 523 | if ((i = (size_t)BN_num_bytes(priv_key)) > buf_len) | ||
| 524 | buf_len = i; | ||
| 525 | } | ||
| 526 | |||
| 527 | buf_len += 10; | ||
| 528 | if ((buffer = OPENSSL_malloc(buf_len)) == NULL) | ||
| 529 | { | ||
| 530 | reason = ERR_R_MALLOC_FAILURE; | ||
| 531 | goto err; | ||
| 532 | } | ||
| 533 | |||
| 534 | if (priv_key != NULL) | ||
| 535 | { | ||
| 536 | if (!BIO_indent(bp, off, 128)) | ||
| 537 | goto err; | ||
| 538 | if ((order = BN_new()) == NULL) | ||
| 539 | goto err; | ||
| 540 | if (!EC_GROUP_get_order(group, order, NULL)) | ||
| 541 | goto err; | ||
| 542 | if (BIO_printf(bp, "Private-Key: (%d bit)\n", | ||
| 543 | BN_num_bits(order)) <= 0) goto err; | ||
| 544 | } | ||
| 545 | |||
| 546 | if ((priv_key != NULL) && !print(bp, "priv:", priv_key, | ||
| 547 | buffer, off)) | ||
| 548 | goto err; | ||
| 549 | if ((pub_key != NULL) && !print(bp, "pub: ", pub_key, | ||
| 550 | buffer, off)) | ||
| 551 | goto err; | ||
| 552 | if (!ECPKParameters_print(bp, group, off)) | ||
| 553 | goto err; | ||
| 554 | ret=1; | ||
| 555 | err: | ||
| 556 | if (!ret) | ||
| 557 | ECerr(EC_F_EC_KEY_PRINT, reason); | ||
| 558 | if (pub_key) | ||
| 559 | BN_free(pub_key); | ||
| 560 | if (order) | ||
| 561 | BN_free(order); | ||
| 562 | if (ctx) | ||
| 563 | BN_CTX_free(ctx); | ||
| 564 | if (buffer != NULL) | ||
| 565 | OPENSSL_free(buffer); | ||
| 566 | return(ret); | ||
| 567 | } | ||
| 568 | #endif /* OPENSSL_NO_EC */ | ||
| 569 | |||
| 570 | static int print(BIO *bp, const char *number, const BIGNUM *num, unsigned char *buf, | ||
| 571 | int off) | ||
| 572 | { | ||
| 573 | int n,i; | ||
| 574 | const char *neg; | ||
| 575 | |||
| 576 | if (num == NULL) return(1); | ||
| 577 | neg = (BN_is_negative(num))?"-":""; | ||
| 578 | if(!BIO_indent(bp,off,128)) | ||
| 579 | return 0; | ||
| 580 | if (BN_is_zero(num)) | ||
| 581 | { | ||
| 582 | if (BIO_printf(bp, "%s 0\n", number) <= 0) | ||
| 583 | return 0; | ||
| 584 | return 1; | ||
| 585 | } | ||
| 586 | |||
| 587 | if (BN_num_bytes(num) <= BN_BYTES) | ||
| 588 | { | ||
| 589 | if (BIO_printf(bp,"%s %s%lu (%s0x%lx)\n",number,neg, | ||
| 590 | (unsigned long)num->d[0],neg,(unsigned long)num->d[0]) | ||
| 591 | <= 0) return(0); | ||
| 592 | } | ||
| 593 | else | ||
| 594 | { | ||
| 595 | buf[0]=0; | ||
| 596 | if (BIO_printf(bp,"%s%s",number, | ||
| 597 | (neg[0] == '-')?" (Negative)":"") <= 0) | ||
| 598 | return(0); | ||
| 599 | n=BN_bn2bin(num,&buf[1]); | ||
| 600 | |||
| 601 | if (buf[1] & 0x80) | ||
| 602 | n++; | ||
| 603 | else buf++; | ||
| 604 | |||
| 605 | for (i=0; i<n; i++) | ||
| 606 | { | ||
| 607 | if ((i%15) == 0) | ||
| 608 | { | ||
| 609 | if(BIO_puts(bp,"\n") <= 0 | ||
| 610 | || !BIO_indent(bp,off+4,128)) | ||
| 611 | return 0; | ||
| 612 | } | ||
| 613 | if (BIO_printf(bp,"%02x%s",buf[i],((i+1) == n)?"":":") | ||
| 614 | <= 0) return(0); | ||
| 615 | } | ||
| 616 | if (BIO_write(bp,"\n",1) <= 0) return(0); | ||
| 617 | } | ||
| 618 | return(1); | ||
| 619 | } | ||
| 620 | |||
| 621 | #ifndef OPENSSL_NO_EC | ||
| 622 | static int print_bin(BIO *fp, const char *name, const unsigned char *buf, | ||
| 623 | size_t len, int off) | ||
| 624 | { | ||
| 625 | size_t i; | ||
| 626 | char str[128]; | ||
| 627 | |||
| 628 | if (buf == NULL) | ||
| 629 | return 1; | ||
| 630 | if (off) | ||
| 631 | { | ||
| 632 | if (off > 128) | ||
| 633 | off=128; | ||
| 634 | memset(str,' ',off); | ||
| 635 | if (BIO_write(fp, str, off) <= 0) | ||
| 636 | return 0; | ||
| 637 | } | ||
| 638 | |||
| 639 | if (BIO_printf(fp,"%s", name) <= 0) | ||
| 640 | return 0; | ||
| 641 | |||
| 642 | for (i=0; i<len; i++) | ||
| 643 | { | ||
| 644 | if ((i%15) == 0) | ||
| 645 | { | ||
| 646 | str[0]='\n'; | ||
| 647 | memset(&(str[1]),' ',off+4); | ||
| 648 | if (BIO_write(fp, str, off+1+4) <= 0) | ||
| 649 | return 0; | ||
| 650 | } | ||
| 651 | if (BIO_printf(fp,"%02x%s",buf[i],((i+1) == len)?"":":") <= 0) | ||
| 652 | return 0; | ||
| 653 | } | ||
| 654 | if (BIO_write(fp,"\n",1) <= 0) | ||
| 655 | return 0; | ||
| 656 | |||
| 657 | return 1; | ||
| 658 | } | ||
| 659 | #endif | ||
| 660 | |||
| 661 | #ifndef OPENSSL_NO_DH | ||
| 662 | #ifndef OPENSSL_NO_FP_API | ||
| 663 | int DHparams_print_fp(FILE *fp, const DH *x) | ||
| 664 | { | ||
| 665 | BIO *b; | ||
| 666 | int ret; | ||
| 667 | |||
| 668 | if ((b=BIO_new(BIO_s_file())) == NULL) | ||
| 669 | { | ||
| 670 | DHerr(DH_F_DHPARAMS_PRINT_FP,ERR_R_BUF_LIB); | ||
| 671 | return(0); | ||
| 672 | } | ||
| 673 | BIO_set_fp(b,fp,BIO_NOCLOSE); | ||
| 674 | ret=DHparams_print(b, x); | ||
| 675 | BIO_free(b); | ||
| 676 | return(ret); | ||
| 677 | } | ||
| 678 | #endif | ||
| 679 | |||
| 680 | int DHparams_print(BIO *bp, const DH *x) | ||
| 681 | { | ||
| 682 | unsigned char *m=NULL; | ||
| 683 | int reason=ERR_R_BUF_LIB,ret=0; | ||
| 684 | size_t buf_len=0, i; | ||
| 685 | |||
| 686 | if (x->p) | ||
| 687 | buf_len = (size_t)BN_num_bytes(x->p); | ||
| 688 | else | ||
| 689 | { | ||
| 690 | reason = ERR_R_PASSED_NULL_PARAMETER; | ||
| 691 | goto err; | ||
| 692 | } | ||
| 693 | if (x->g) | ||
| 694 | if (buf_len < (i = (size_t)BN_num_bytes(x->g))) | ||
| 695 | buf_len = i; | ||
| 696 | m=(unsigned char *)OPENSSL_malloc(buf_len+10); | ||
| 697 | if (m == NULL) | ||
| 698 | { | ||
| 699 | reason=ERR_R_MALLOC_FAILURE; | ||
| 700 | goto err; | ||
| 701 | } | ||
| 702 | |||
| 703 | if (BIO_printf(bp,"Diffie-Hellman-Parameters: (%d bit)\n", | ||
| 704 | BN_num_bits(x->p)) <= 0) | ||
| 705 | goto err; | ||
| 706 | if (!print(bp,"prime:",x->p,m,4)) goto err; | ||
| 707 | if (!print(bp,"generator:",x->g,m,4)) goto err; | ||
| 708 | if (x->length != 0) | ||
| 709 | { | ||
| 710 | if (BIO_printf(bp," recommended-private-length: %d bits\n", | ||
| 711 | (int)x->length) <= 0) goto err; | ||
| 712 | } | ||
| 713 | ret=1; | ||
| 714 | if (0) | ||
| 715 | { | ||
| 716 | err: | ||
| 717 | DHerr(DH_F_DHPARAMS_PRINT,reason); | ||
| 718 | } | ||
| 719 | if (m != NULL) OPENSSL_free(m); | ||
| 720 | return(ret); | ||
| 721 | } | ||
| 722 | #endif | ||
| 723 | |||
| 724 | #ifndef OPENSSL_NO_DSA | ||
| 725 | #ifndef OPENSSL_NO_FP_API | ||
| 726 | int DSAparams_print_fp(FILE *fp, const DSA *x) | ||
| 727 | { | ||
| 728 | BIO *b; | ||
| 729 | int ret; | ||
| 730 | |||
| 731 | if ((b=BIO_new(BIO_s_file())) == NULL) | ||
| 732 | { | ||
| 733 | DSAerr(DSA_F_DSAPARAMS_PRINT_FP,ERR_R_BUF_LIB); | ||
| 734 | return(0); | ||
| 735 | } | ||
| 736 | BIO_set_fp(b,fp,BIO_NOCLOSE); | ||
| 737 | ret=DSAparams_print(b, x); | ||
| 738 | BIO_free(b); | ||
| 739 | return(ret); | ||
| 740 | } | ||
| 741 | #endif | ||
| 742 | |||
| 743 | int DSAparams_print(BIO *bp, const DSA *x) | ||
| 744 | { | ||
| 745 | unsigned char *m=NULL; | ||
| 746 | int ret=0; | ||
| 747 | size_t buf_len=0,i; | ||
| 748 | |||
| 749 | if (x->p) | ||
| 750 | buf_len = (size_t)BN_num_bytes(x->p); | ||
| 751 | else | ||
| 752 | { | ||
| 753 | DSAerr(DSA_F_DSAPARAMS_PRINT,DSA_R_MISSING_PARAMETERS); | ||
| 754 | goto err; | ||
| 755 | } | ||
| 756 | if (x->q) | ||
| 757 | if (buf_len < (i = (size_t)BN_num_bytes(x->q))) | ||
| 758 | buf_len = i; | ||
| 759 | if (x->g) | ||
| 760 | if (buf_len < (i = (size_t)BN_num_bytes(x->g))) | ||
| 761 | buf_len = i; | ||
| 762 | m=(unsigned char *)OPENSSL_malloc(buf_len+10); | ||
| 763 | if (m == NULL) | ||
| 764 | { | ||
| 765 | DSAerr(DSA_F_DSAPARAMS_PRINT,ERR_R_MALLOC_FAILURE); | ||
| 766 | goto err; | ||
| 767 | } | ||
| 768 | |||
| 769 | if (BIO_printf(bp,"DSA-Parameters: (%d bit)\n", | ||
| 770 | BN_num_bits(x->p)) <= 0) | ||
| 771 | goto err; | ||
| 772 | if (!print(bp,"p:",x->p,m,4)) goto err; | ||
| 773 | if ((x->q != NULL) && !print(bp,"q:",x->q,m,4)) goto err; | ||
| 774 | if ((x->g != NULL) && !print(bp,"g:",x->g,m,4)) goto err; | ||
| 775 | ret=1; | ||
| 776 | err: | ||
| 777 | if (m != NULL) OPENSSL_free(m); | ||
| 778 | return(ret); | ||
| 779 | } | ||
| 780 | |||
| 781 | #endif /* !OPENSSL_NO_DSA */ | ||
| 782 | |||
| 783 | #ifndef OPENSSL_NO_EC | ||
| 784 | #ifndef OPENSSL_NO_FP_API | ||
| 785 | int ECParameters_print_fp(FILE *fp, const EC_KEY *x) | ||
| 786 | { | ||
| 787 | BIO *b; | ||
| 788 | int ret; | ||
| 789 | |||
| 790 | if ((b=BIO_new(BIO_s_file())) == NULL) | ||
| 791 | { | ||
| 792 | ECerr(EC_F_ECPARAMETERS_PRINT_FP, ERR_R_BIO_LIB); | ||
| 793 | return(0); | ||
| 794 | } | ||
| 795 | BIO_set_fp(b, fp, BIO_NOCLOSE); | ||
| 796 | ret = ECParameters_print(b, x); | ||
| 797 | BIO_free(b); | ||
| 798 | return(ret); | ||
| 799 | } | ||
| 800 | #endif | ||
| 801 | |||
| 802 | int ECParameters_print(BIO *bp, const EC_KEY *x) | ||
| 803 | { | ||
| 804 | int reason=ERR_R_EC_LIB, ret=0; | ||
| 805 | BIGNUM *order=NULL; | ||
| 806 | const EC_GROUP *group; | ||
| 807 | |||
| 808 | if (x == NULL || (group = EC_KEY_get0_group(x)) == NULL) | ||
| 809 | { | ||
| 810 | reason = ERR_R_PASSED_NULL_PARAMETER;; | ||
| 811 | goto err; | ||
| 812 | } | ||
| 813 | |||
| 814 | if ((order = BN_new()) == NULL) | ||
| 815 | { | ||
| 816 | reason = ERR_R_MALLOC_FAILURE; | ||
| 817 | goto err; | ||
| 818 | } | ||
| 819 | |||
| 820 | if (!EC_GROUP_get_order(group, order, NULL)) | ||
| 821 | { | ||
| 822 | reason = ERR_R_EC_LIB; | ||
| 823 | goto err; | ||
| 824 | } | ||
| 825 | |||
| 826 | if (BIO_printf(bp, "ECDSA-Parameters: (%d bit)\n", | ||
| 827 | BN_num_bits(order)) <= 0) | ||
| 828 | goto err; | ||
| 829 | if (!ECPKParameters_print(bp, group, 4)) | ||
| 830 | goto err; | ||
| 831 | ret=1; | ||
| 832 | err: | ||
| 833 | if (order) | ||
| 834 | BN_free(order); | ||
| 835 | ECerr(EC_F_ECPARAMETERS_PRINT, reason); | ||
| 836 | return(ret); | ||
| 837 | } | ||
| 838 | |||
| 839 | #endif | ||
diff --git a/src/lib/libcrypto/asn1/t_req.c b/src/lib/libcrypto/asn1/t_req.c new file mode 100644 index 0000000000..5557e06584 --- /dev/null +++ b/src/lib/libcrypto/asn1/t_req.c | |||
| @@ -0,0 +1,290 @@ | |||
| 1 | /* crypto/asn1/t_req.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/buffer.h> | ||
| 62 | #include <openssl/bn.h> | ||
| 63 | #include <openssl/objects.h> | ||
| 64 | #include <openssl/x509.h> | ||
| 65 | #include <openssl/x509v3.h> | ||
| 66 | #ifndef OPENSSL_NO_RSA | ||
| 67 | #include <openssl/rsa.h> | ||
| 68 | #endif | ||
| 69 | #ifndef OPENSSL_NO_DSA | ||
| 70 | #include <openssl/dsa.h> | ||
| 71 | #endif | ||
| 72 | |||
| 73 | #ifndef OPENSSL_NO_FP_API | ||
| 74 | int X509_REQ_print_fp(FILE *fp, X509_REQ *x) | ||
| 75 | { | ||
| 76 | BIO *b; | ||
| 77 | int ret; | ||
| 78 | |||
| 79 | if ((b=BIO_new(BIO_s_file())) == NULL) | ||
| 80 | { | ||
| 81 | X509err(X509_F_X509_REQ_PRINT_FP,ERR_R_BUF_LIB); | ||
| 82 | return(0); | ||
| 83 | } | ||
| 84 | BIO_set_fp(b,fp,BIO_NOCLOSE); | ||
| 85 | ret=X509_REQ_print(b, x); | ||
| 86 | BIO_free(b); | ||
| 87 | return(ret); | ||
| 88 | } | ||
| 89 | #endif | ||
| 90 | |||
| 91 | int X509_REQ_print_ex(BIO *bp, X509_REQ *x, unsigned long nmflags, unsigned long cflag) | ||
| 92 | { | ||
| 93 | unsigned long l; | ||
| 94 | int i; | ||
| 95 | const char *neg; | ||
| 96 | X509_REQ_INFO *ri; | ||
| 97 | EVP_PKEY *pkey; | ||
| 98 | STACK_OF(X509_ATTRIBUTE) *sk; | ||
| 99 | STACK_OF(X509_EXTENSION) *exts; | ||
| 100 | char mlch = ' '; | ||
| 101 | int nmindent = 0; | ||
| 102 | |||
| 103 | if((nmflags & XN_FLAG_SEP_MASK) == XN_FLAG_SEP_MULTILINE) { | ||
| 104 | mlch = '\n'; | ||
| 105 | nmindent = 12; | ||
| 106 | } | ||
| 107 | |||
| 108 | if(nmflags == X509_FLAG_COMPAT) | ||
| 109 | nmindent = 16; | ||
| 110 | |||
| 111 | |||
| 112 | ri=x->req_info; | ||
| 113 | if(!(cflag & X509_FLAG_NO_HEADER)) | ||
| 114 | { | ||
| 115 | if (BIO_write(bp,"Certificate Request:\n",21) <= 0) goto err; | ||
| 116 | if (BIO_write(bp," Data:\n",10) <= 0) goto err; | ||
| 117 | } | ||
| 118 | if(!(cflag & X509_FLAG_NO_VERSION)) | ||
| 119 | { | ||
| 120 | neg=(ri->version->type == V_ASN1_NEG_INTEGER)?"-":""; | ||
| 121 | l=0; | ||
| 122 | for (i=0; i<ri->version->length; i++) | ||
| 123 | { l<<=8; l+=ri->version->data[i]; } | ||
| 124 | if(BIO_printf(bp,"%8sVersion: %s%lu (%s0x%lx)\n","",neg,l,neg, | ||
| 125 | l) <= 0) | ||
| 126 | goto err; | ||
| 127 | } | ||
| 128 | if(!(cflag & X509_FLAG_NO_SUBJECT)) | ||
| 129 | { | ||
| 130 | if (BIO_printf(bp," Subject:%c",mlch) <= 0) goto err; | ||
| 131 | if (X509_NAME_print_ex(bp,ri->subject,nmindent, nmflags) < 0) goto err; | ||
| 132 | if (BIO_write(bp,"\n",1) <= 0) goto err; | ||
| 133 | } | ||
| 134 | if(!(cflag & X509_FLAG_NO_PUBKEY)) | ||
| 135 | { | ||
| 136 | if (BIO_write(bp," Subject Public Key Info:\n",33) <= 0) | ||
| 137 | goto err; | ||
| 138 | if (BIO_printf(bp,"%12sPublic Key Algorithm: ","") <= 0) | ||
| 139 | goto err; | ||
| 140 | if (i2a_ASN1_OBJECT(bp, ri->pubkey->algor->algorithm) <= 0) | ||
| 141 | goto err; | ||
| 142 | if (BIO_puts(bp, "\n") <= 0) | ||
| 143 | goto err; | ||
| 144 | |||
| 145 | pkey=X509_REQ_get_pubkey(x); | ||
| 146 | if (pkey == NULL) | ||
| 147 | { | ||
| 148 | BIO_printf(bp,"%12sUnable to load Public Key\n",""); | ||
| 149 | ERR_print_errors(bp); | ||
| 150 | } | ||
| 151 | else | ||
| 152 | #ifndef OPENSSL_NO_RSA | ||
| 153 | if (pkey->type == EVP_PKEY_RSA) | ||
| 154 | { | ||
| 155 | BIO_printf(bp,"%12sRSA Public Key: (%d bit)\n","", | ||
| 156 | BN_num_bits(pkey->pkey.rsa->n)); | ||
| 157 | RSA_print(bp,pkey->pkey.rsa,16); | ||
| 158 | } | ||
| 159 | else | ||
| 160 | #endif | ||
| 161 | #ifndef OPENSSL_NO_DSA | ||
| 162 | if (pkey->type == EVP_PKEY_DSA) | ||
| 163 | { | ||
| 164 | BIO_printf(bp,"%12sDSA Public Key:\n",""); | ||
| 165 | DSA_print(bp,pkey->pkey.dsa,16); | ||
| 166 | } | ||
| 167 | else | ||
| 168 | #endif | ||
| 169 | #ifndef OPENSSL_NO_EC | ||
| 170 | if (pkey->type == EVP_PKEY_EC) | ||
| 171 | { | ||
| 172 | BIO_printf(bp, "%12sEC Public Key: \n",""); | ||
| 173 | EC_KEY_print(bp, pkey->pkey.ec, 16); | ||
| 174 | } | ||
| 175 | else | ||
| 176 | #endif | ||
| 177 | BIO_printf(bp,"%12sUnknown Public Key:\n",""); | ||
| 178 | |||
| 179 | EVP_PKEY_free(pkey); | ||
| 180 | } | ||
| 181 | |||
| 182 | if(!(cflag & X509_FLAG_NO_ATTRIBUTES)) | ||
| 183 | { | ||
| 184 | /* may not be */ | ||
| 185 | if(BIO_printf(bp,"%8sAttributes:\n","") <= 0) | ||
| 186 | goto err; | ||
| 187 | |||
| 188 | sk=x->req_info->attributes; | ||
| 189 | if (sk_X509_ATTRIBUTE_num(sk) == 0) | ||
| 190 | { | ||
| 191 | if(BIO_printf(bp,"%12sa0:00\n","") <= 0) | ||
| 192 | goto err; | ||
| 193 | } | ||
| 194 | else | ||
| 195 | { | ||
| 196 | for (i=0; i<sk_X509_ATTRIBUTE_num(sk); i++) | ||
| 197 | { | ||
| 198 | ASN1_TYPE *at; | ||
| 199 | X509_ATTRIBUTE *a; | ||
| 200 | ASN1_BIT_STRING *bs=NULL; | ||
| 201 | ASN1_TYPE *t; | ||
| 202 | int j,type=0,count=1,ii=0; | ||
| 203 | |||
| 204 | a=sk_X509_ATTRIBUTE_value(sk,i); | ||
| 205 | if(X509_REQ_extension_nid(OBJ_obj2nid(a->object))) | ||
| 206 | continue; | ||
| 207 | if(BIO_printf(bp,"%12s","") <= 0) | ||
| 208 | goto err; | ||
| 209 | if ((j=i2a_ASN1_OBJECT(bp,a->object)) > 0) | ||
| 210 | { | ||
| 211 | if (a->single) | ||
| 212 | { | ||
| 213 | t=a->value.single; | ||
| 214 | type=t->type; | ||
| 215 | bs=t->value.bit_string; | ||
| 216 | } | ||
| 217 | else | ||
| 218 | { | ||
| 219 | ii=0; | ||
| 220 | count=sk_ASN1_TYPE_num(a->value.set); | ||
| 221 | get_next: | ||
| 222 | at=sk_ASN1_TYPE_value(a->value.set,ii); | ||
| 223 | type=at->type; | ||
| 224 | bs=at->value.asn1_string; | ||
| 225 | } | ||
| 226 | } | ||
| 227 | for (j=25-j; j>0; j--) | ||
| 228 | if (BIO_write(bp," ",1) != 1) goto err; | ||
| 229 | if (BIO_puts(bp,":") <= 0) goto err; | ||
| 230 | if ( (type == V_ASN1_PRINTABLESTRING) || | ||
| 231 | (type == V_ASN1_T61STRING) || | ||
| 232 | (type == V_ASN1_IA5STRING)) | ||
| 233 | { | ||
| 234 | if (BIO_write(bp,(char *)bs->data,bs->length) | ||
| 235 | != bs->length) | ||
| 236 | goto err; | ||
| 237 | BIO_puts(bp,"\n"); | ||
| 238 | } | ||
| 239 | else | ||
| 240 | { | ||
| 241 | BIO_puts(bp,"unable to print attribute\n"); | ||
| 242 | } | ||
| 243 | if (++ii < count) goto get_next; | ||
| 244 | } | ||
| 245 | } | ||
| 246 | } | ||
| 247 | if(!(cflag & X509_FLAG_NO_EXTENSIONS)) | ||
| 248 | { | ||
| 249 | exts = X509_REQ_get_extensions(x); | ||
| 250 | if(exts) | ||
| 251 | { | ||
| 252 | BIO_printf(bp,"%8sRequested Extensions:\n",""); | ||
| 253 | for (i=0; i<sk_X509_EXTENSION_num(exts); i++) | ||
| 254 | { | ||
| 255 | ASN1_OBJECT *obj; | ||
| 256 | X509_EXTENSION *ex; | ||
| 257 | int j; | ||
| 258 | ex=sk_X509_EXTENSION_value(exts, i); | ||
| 259 | if (BIO_printf(bp,"%12s","") <= 0) goto err; | ||
| 260 | obj=X509_EXTENSION_get_object(ex); | ||
| 261 | i2a_ASN1_OBJECT(bp,obj); | ||
| 262 | j=X509_EXTENSION_get_critical(ex); | ||
| 263 | if (BIO_printf(bp,": %s\n",j?"critical":"") <= 0) | ||
| 264 | goto err; | ||
| 265 | if(!X509V3_EXT_print(bp, ex, cflag, 16)) | ||
| 266 | { | ||
| 267 | BIO_printf(bp, "%16s", ""); | ||
| 268 | M_ASN1_OCTET_STRING_print(bp,ex->value); | ||
| 269 | } | ||
| 270 | if (BIO_write(bp,"\n",1) <= 0) goto err; | ||
| 271 | } | ||
| 272 | sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free); | ||
| 273 | } | ||
| 274 | } | ||
| 275 | |||
| 276 | if(!(cflag & X509_FLAG_NO_SIGDUMP)) | ||
| 277 | { | ||
| 278 | if(!X509_signature_print(bp, x->sig_alg, x->signature)) goto err; | ||
| 279 | } | ||
| 280 | |||
| 281 | return(1); | ||
| 282 | err: | ||
| 283 | X509err(X509_F_X509_REQ_PRINT_EX,ERR_R_BUF_LIB); | ||
| 284 | return(0); | ||
| 285 | } | ||
| 286 | |||
| 287 | int X509_REQ_print(BIO *bp, X509_REQ *x) | ||
| 288 | { | ||
| 289 | return X509_REQ_print_ex(bp, x, XN_FLAG_COMPAT, X509_FLAG_COMPAT); | ||
| 290 | } | ||
diff --git a/src/lib/libcrypto/asn1/t_spki.c b/src/lib/libcrypto/asn1/t_spki.c new file mode 100644 index 0000000000..c2a5797dd8 --- /dev/null +++ b/src/lib/libcrypto/asn1/t_spki.c | |||
| @@ -0,0 +1,132 @@ | |||
| 1 | /* t_spki.c */ | ||
| 2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
| 3 | * project 1999. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/x509.h> | ||
| 62 | #include <openssl/asn1.h> | ||
| 63 | #ifndef OPENSSL_NO_RSA | ||
| 64 | #include <openssl/rsa.h> | ||
| 65 | #endif | ||
| 66 | #ifndef OPENSSL_NO_DSA | ||
| 67 | #include <openssl/dsa.h> | ||
| 68 | #endif | ||
| 69 | #include <openssl/bn.h> | ||
| 70 | |||
| 71 | /* Print out an SPKI */ | ||
| 72 | |||
| 73 | int NETSCAPE_SPKI_print(BIO *out, NETSCAPE_SPKI *spki) | ||
| 74 | { | ||
| 75 | EVP_PKEY *pkey; | ||
| 76 | ASN1_IA5STRING *chal; | ||
| 77 | int i, n; | ||
| 78 | char *s; | ||
| 79 | BIO_printf(out, "Netscape SPKI:\n"); | ||
| 80 | i=OBJ_obj2nid(spki->spkac->pubkey->algor->algorithm); | ||
| 81 | BIO_printf(out," Public Key Algorithm: %s\n", | ||
| 82 | (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i)); | ||
| 83 | pkey = X509_PUBKEY_get(spki->spkac->pubkey); | ||
| 84 | if(!pkey) BIO_printf(out, " Unable to load public key\n"); | ||
| 85 | else { | ||
| 86 | #ifndef OPENSSL_NO_RSA | ||
| 87 | if (pkey->type == EVP_PKEY_RSA) | ||
| 88 | { | ||
| 89 | BIO_printf(out," RSA Public Key: (%d bit)\n", | ||
| 90 | BN_num_bits(pkey->pkey.rsa->n)); | ||
| 91 | RSA_print(out,pkey->pkey.rsa,2); | ||
| 92 | } | ||
| 93 | else | ||
| 94 | #endif | ||
| 95 | #ifndef OPENSSL_NO_DSA | ||
| 96 | if (pkey->type == EVP_PKEY_DSA) | ||
| 97 | { | ||
| 98 | BIO_printf(out," DSA Public Key:\n"); | ||
| 99 | DSA_print(out,pkey->pkey.dsa,2); | ||
| 100 | } | ||
| 101 | else | ||
| 102 | #endif | ||
| 103 | #ifndef OPENSSL_NO_EC | ||
| 104 | if (pkey->type == EVP_PKEY_EC) | ||
| 105 | { | ||
| 106 | BIO_printf(out, " EC Public Key:\n"); | ||
| 107 | EC_KEY_print(out, pkey->pkey.ec,2); | ||
| 108 | } | ||
| 109 | else | ||
| 110 | #endif | ||
| 111 | |||
| 112 | BIO_printf(out," Unknown Public Key:\n"); | ||
| 113 | EVP_PKEY_free(pkey); | ||
| 114 | } | ||
| 115 | chal = spki->spkac->challenge; | ||
| 116 | if(chal->length) | ||
| 117 | BIO_printf(out, " Challenge String: %s\n", chal->data); | ||
| 118 | i=OBJ_obj2nid(spki->sig_algor->algorithm); | ||
| 119 | BIO_printf(out," Signature Algorithm: %s", | ||
| 120 | (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i)); | ||
| 121 | |||
| 122 | n=spki->signature->length; | ||
| 123 | s=(char *)spki->signature->data; | ||
| 124 | for (i=0; i<n; i++) | ||
| 125 | { | ||
| 126 | if ((i%18) == 0) BIO_write(out,"\n ",7); | ||
| 127 | BIO_printf(out,"%02x%s",(unsigned char)s[i], | ||
| 128 | ((i+1) == n)?"":":"); | ||
| 129 | } | ||
| 130 | BIO_write(out,"\n",1); | ||
| 131 | return 1; | ||
| 132 | } | ||
diff --git a/src/lib/libcrypto/asn1/t_x509.c b/src/lib/libcrypto/asn1/t_x509.c new file mode 100644 index 0000000000..cb76c32c8d --- /dev/null +++ b/src/lib/libcrypto/asn1/t_x509.c | |||
| @@ -0,0 +1,505 @@ | |||
| 1 | /* crypto/asn1/t_x509.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/buffer.h> | ||
| 62 | #include <openssl/bn.h> | ||
| 63 | #ifndef OPENSSL_NO_RSA | ||
| 64 | #include <openssl/rsa.h> | ||
| 65 | #endif | ||
| 66 | #ifndef OPENSSL_NO_DSA | ||
| 67 | #include <openssl/dsa.h> | ||
| 68 | #endif | ||
| 69 | #ifndef OPENSSL_NO_EC | ||
| 70 | #include <openssl/ec.h> | ||
| 71 | #endif | ||
| 72 | #include <openssl/objects.h> | ||
| 73 | #include <openssl/x509.h> | ||
| 74 | #include <openssl/x509v3.h> | ||
| 75 | |||
| 76 | #ifndef OPENSSL_NO_FP_API | ||
| 77 | int X509_print_fp(FILE *fp, X509 *x) | ||
| 78 | { | ||
| 79 | return X509_print_ex_fp(fp, x, XN_FLAG_COMPAT, X509_FLAG_COMPAT); | ||
| 80 | } | ||
| 81 | |||
| 82 | int X509_print_ex_fp(FILE *fp, X509 *x, unsigned long nmflag, unsigned long cflag) | ||
| 83 | { | ||
| 84 | BIO *b; | ||
| 85 | int ret; | ||
| 86 | |||
| 87 | if ((b=BIO_new(BIO_s_file())) == NULL) | ||
| 88 | { | ||
| 89 | X509err(X509_F_X509_PRINT_EX_FP,ERR_R_BUF_LIB); | ||
| 90 | return(0); | ||
| 91 | } | ||
| 92 | BIO_set_fp(b,fp,BIO_NOCLOSE); | ||
| 93 | ret=X509_print_ex(b, x, nmflag, cflag); | ||
| 94 | BIO_free(b); | ||
| 95 | return(ret); | ||
| 96 | } | ||
| 97 | #endif | ||
| 98 | |||
| 99 | int X509_print(BIO *bp, X509 *x) | ||
| 100 | { | ||
| 101 | return X509_print_ex(bp, x, XN_FLAG_COMPAT, X509_FLAG_COMPAT); | ||
| 102 | } | ||
| 103 | |||
| 104 | int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags, unsigned long cflag) | ||
| 105 | { | ||
| 106 | long l; | ||
| 107 | int ret=0,i; | ||
| 108 | char *m=NULL,mlch = ' '; | ||
| 109 | int nmindent = 0; | ||
| 110 | X509_CINF *ci; | ||
| 111 | ASN1_INTEGER *bs; | ||
| 112 | EVP_PKEY *pkey=NULL; | ||
| 113 | const char *neg; | ||
| 114 | ASN1_STRING *str=NULL; | ||
| 115 | |||
| 116 | if((nmflags & XN_FLAG_SEP_MASK) == XN_FLAG_SEP_MULTILINE) { | ||
| 117 | mlch = '\n'; | ||
| 118 | nmindent = 12; | ||
| 119 | } | ||
| 120 | |||
| 121 | if(nmflags == X509_FLAG_COMPAT) | ||
| 122 | nmindent = 16; | ||
| 123 | |||
| 124 | ci=x->cert_info; | ||
| 125 | if(!(cflag & X509_FLAG_NO_HEADER)) | ||
| 126 | { | ||
| 127 | if (BIO_write(bp,"Certificate:\n",13) <= 0) goto err; | ||
| 128 | if (BIO_write(bp," Data:\n",10) <= 0) goto err; | ||
| 129 | } | ||
| 130 | if(!(cflag & X509_FLAG_NO_VERSION)) | ||
| 131 | { | ||
| 132 | l=X509_get_version(x); | ||
| 133 | if (BIO_printf(bp,"%8sVersion: %lu (0x%lx)\n","",l+1,l) <= 0) goto err; | ||
| 134 | } | ||
| 135 | if(!(cflag & X509_FLAG_NO_SERIAL)) | ||
| 136 | { | ||
| 137 | |||
| 138 | if (BIO_write(bp," Serial Number:",22) <= 0) goto err; | ||
| 139 | |||
| 140 | bs=X509_get_serialNumber(x); | ||
| 141 | if (bs->length <= 4) | ||
| 142 | { | ||
| 143 | l=ASN1_INTEGER_get(bs); | ||
| 144 | if (l < 0) | ||
| 145 | { | ||
| 146 | l= -l; | ||
| 147 | neg="-"; | ||
| 148 | } | ||
| 149 | else | ||
| 150 | neg=""; | ||
| 151 | if (BIO_printf(bp," %s%lu (%s0x%lx)\n",neg,l,neg,l) <= 0) | ||
| 152 | goto err; | ||
| 153 | } | ||
| 154 | else | ||
| 155 | { | ||
| 156 | neg=(bs->type == V_ASN1_NEG_INTEGER)?" (Negative)":""; | ||
| 157 | if (BIO_printf(bp,"\n%12s%s","",neg) <= 0) goto err; | ||
| 158 | |||
| 159 | for (i=0; i<bs->length; i++) | ||
| 160 | { | ||
| 161 | if (BIO_printf(bp,"%02x%c",bs->data[i], | ||
| 162 | ((i+1 == bs->length)?'\n':':')) <= 0) | ||
| 163 | goto err; | ||
| 164 | } | ||
| 165 | } | ||
| 166 | |||
| 167 | } | ||
| 168 | |||
| 169 | if(!(cflag & X509_FLAG_NO_SIGNAME)) | ||
| 170 | { | ||
| 171 | if (BIO_printf(bp,"%8sSignature Algorithm: ","") <= 0) | ||
| 172 | goto err; | ||
| 173 | if (i2a_ASN1_OBJECT(bp, ci->signature->algorithm) <= 0) | ||
| 174 | goto err; | ||
| 175 | if (BIO_puts(bp, "\n") <= 0) | ||
| 176 | goto err; | ||
| 177 | } | ||
| 178 | |||
| 179 | if(!(cflag & X509_FLAG_NO_ISSUER)) | ||
| 180 | { | ||
| 181 | if (BIO_printf(bp," Issuer:%c",mlch) <= 0) goto err; | ||
| 182 | if (X509_NAME_print_ex(bp,X509_get_issuer_name(x),nmindent, nmflags) < 0) goto err; | ||
| 183 | if (BIO_write(bp,"\n",1) <= 0) goto err; | ||
| 184 | } | ||
| 185 | if(!(cflag & X509_FLAG_NO_VALIDITY)) | ||
| 186 | { | ||
| 187 | if (BIO_write(bp," Validity\n",17) <= 0) goto err; | ||
| 188 | if (BIO_write(bp," Not Before: ",24) <= 0) goto err; | ||
| 189 | if (!ASN1_TIME_print(bp,X509_get_notBefore(x))) goto err; | ||
| 190 | if (BIO_write(bp,"\n Not After : ",25) <= 0) goto err; | ||
| 191 | if (!ASN1_TIME_print(bp,X509_get_notAfter(x))) goto err; | ||
| 192 | if (BIO_write(bp,"\n",1) <= 0) goto err; | ||
| 193 | } | ||
| 194 | if(!(cflag & X509_FLAG_NO_SUBJECT)) | ||
| 195 | { | ||
| 196 | if (BIO_printf(bp," Subject:%c",mlch) <= 0) goto err; | ||
| 197 | if (X509_NAME_print_ex(bp,X509_get_subject_name(x),nmindent, nmflags) < 0) goto err; | ||
| 198 | if (BIO_write(bp,"\n",1) <= 0) goto err; | ||
| 199 | } | ||
| 200 | if(!(cflag & X509_FLAG_NO_PUBKEY)) | ||
| 201 | { | ||
| 202 | if (BIO_write(bp," Subject Public Key Info:\n",33) <= 0) | ||
| 203 | goto err; | ||
| 204 | if (BIO_printf(bp,"%12sPublic Key Algorithm: ","") <= 0) | ||
| 205 | goto err; | ||
| 206 | if (i2a_ASN1_OBJECT(bp, ci->key->algor->algorithm) <= 0) | ||
| 207 | goto err; | ||
| 208 | if (BIO_puts(bp, "\n") <= 0) | ||
| 209 | goto err; | ||
| 210 | |||
| 211 | pkey=X509_get_pubkey(x); | ||
| 212 | if (pkey == NULL) | ||
| 213 | { | ||
| 214 | BIO_printf(bp,"%12sUnable to load Public Key\n",""); | ||
| 215 | ERR_print_errors(bp); | ||
| 216 | } | ||
| 217 | else | ||
| 218 | #ifndef OPENSSL_NO_RSA | ||
| 219 | if (pkey->type == EVP_PKEY_RSA) | ||
| 220 | { | ||
| 221 | BIO_printf(bp,"%12sRSA Public Key: (%d bit)\n","", | ||
| 222 | BN_num_bits(pkey->pkey.rsa->n)); | ||
| 223 | RSA_print(bp,pkey->pkey.rsa,16); | ||
| 224 | } | ||
| 225 | else | ||
| 226 | #endif | ||
| 227 | #ifndef OPENSSL_NO_DSA | ||
| 228 | if (pkey->type == EVP_PKEY_DSA) | ||
| 229 | { | ||
| 230 | BIO_printf(bp,"%12sDSA Public Key:\n",""); | ||
| 231 | DSA_print(bp,pkey->pkey.dsa,16); | ||
| 232 | } | ||
| 233 | else | ||
| 234 | #endif | ||
| 235 | #ifndef OPENSSL_NO_EC | ||
| 236 | if (pkey->type == EVP_PKEY_EC) | ||
| 237 | { | ||
| 238 | BIO_printf(bp, "%12sEC Public Key:\n",""); | ||
| 239 | EC_KEY_print(bp, pkey->pkey.ec, 16); | ||
| 240 | } | ||
| 241 | else | ||
| 242 | #endif | ||
| 243 | BIO_printf(bp,"%12sUnknown Public Key:\n",""); | ||
| 244 | |||
| 245 | EVP_PKEY_free(pkey); | ||
| 246 | } | ||
| 247 | |||
| 248 | if (!(cflag & X509_FLAG_NO_EXTENSIONS)) | ||
| 249 | X509V3_extensions_print(bp, "X509v3 extensions", | ||
| 250 | ci->extensions, cflag, 8); | ||
| 251 | |||
| 252 | if(!(cflag & X509_FLAG_NO_SIGDUMP)) | ||
| 253 | { | ||
| 254 | if(X509_signature_print(bp, x->sig_alg, x->signature) <= 0) goto err; | ||
| 255 | } | ||
| 256 | if(!(cflag & X509_FLAG_NO_AUX)) | ||
| 257 | { | ||
| 258 | if (!X509_CERT_AUX_print(bp, x->aux, 0)) goto err; | ||
| 259 | } | ||
| 260 | ret=1; | ||
| 261 | err: | ||
| 262 | if (str != NULL) ASN1_STRING_free(str); | ||
| 263 | if (m != NULL) OPENSSL_free(m); | ||
| 264 | return(ret); | ||
| 265 | } | ||
| 266 | |||
| 267 | int X509_ocspid_print (BIO *bp, X509 *x) | ||
| 268 | { | ||
| 269 | unsigned char *der=NULL ; | ||
| 270 | unsigned char *dertmp; | ||
| 271 | int derlen; | ||
| 272 | int i; | ||
| 273 | unsigned char SHA1md[SHA_DIGEST_LENGTH]; | ||
| 274 | |||
| 275 | /* display the hash of the subject as it would appear | ||
| 276 | in OCSP requests */ | ||
| 277 | if (BIO_printf(bp," Subject OCSP hash: ") <= 0) | ||
| 278 | goto err; | ||
| 279 | derlen = i2d_X509_NAME(x->cert_info->subject, NULL); | ||
| 280 | if ((der = dertmp = (unsigned char *)OPENSSL_malloc (derlen)) == NULL) | ||
| 281 | goto err; | ||
| 282 | i2d_X509_NAME(x->cert_info->subject, &dertmp); | ||
| 283 | |||
| 284 | EVP_Digest(der, derlen, SHA1md, NULL, EVP_sha1(), NULL); | ||
| 285 | for (i=0; i < SHA_DIGEST_LENGTH; i++) | ||
| 286 | { | ||
| 287 | if (BIO_printf(bp,"%02X",SHA1md[i]) <= 0) goto err; | ||
| 288 | } | ||
| 289 | OPENSSL_free (der); | ||
| 290 | der=NULL; | ||
| 291 | |||
| 292 | /* display the hash of the public key as it would appear | ||
| 293 | in OCSP requests */ | ||
| 294 | if (BIO_printf(bp,"\n Public key OCSP hash: ") <= 0) | ||
| 295 | goto err; | ||
| 296 | |||
| 297 | EVP_Digest(x->cert_info->key->public_key->data, | ||
| 298 | x->cert_info->key->public_key->length, SHA1md, NULL, EVP_sha1(), NULL); | ||
| 299 | for (i=0; i < SHA_DIGEST_LENGTH; i++) | ||
| 300 | { | ||
| 301 | if (BIO_printf(bp,"%02X",SHA1md[i]) <= 0) | ||
| 302 | goto err; | ||
| 303 | } | ||
| 304 | BIO_printf(bp,"\n"); | ||
| 305 | |||
| 306 | return (1); | ||
| 307 | err: | ||
| 308 | if (der != NULL) OPENSSL_free(der); | ||
| 309 | return(0); | ||
| 310 | } | ||
| 311 | |||
| 312 | int X509_signature_print(BIO *bp, X509_ALGOR *sigalg, ASN1_STRING *sig) | ||
| 313 | { | ||
| 314 | unsigned char *s; | ||
| 315 | int i, n; | ||
| 316 | if (BIO_puts(bp," Signature Algorithm: ") <= 0) return 0; | ||
| 317 | if (i2a_ASN1_OBJECT(bp, sigalg->algorithm) <= 0) return 0; | ||
| 318 | |||
| 319 | n=sig->length; | ||
| 320 | s=sig->data; | ||
| 321 | for (i=0; i<n; i++) | ||
| 322 | { | ||
| 323 | if ((i%18) == 0) | ||
| 324 | if (BIO_write(bp,"\n ",9) <= 0) return 0; | ||
| 325 | if (BIO_printf(bp,"%02x%s",s[i], | ||
| 326 | ((i+1) == n)?"":":") <= 0) return 0; | ||
| 327 | } | ||
| 328 | if (BIO_write(bp,"\n",1) != 1) return 0; | ||
| 329 | return 1; | ||
| 330 | } | ||
| 331 | |||
| 332 | int ASN1_STRING_print(BIO *bp, ASN1_STRING *v) | ||
| 333 | { | ||
| 334 | int i,n; | ||
| 335 | char buf[80],*p; | ||
| 336 | |||
| 337 | if (v == NULL) return(0); | ||
| 338 | n=0; | ||
| 339 | p=(char *)v->data; | ||
| 340 | for (i=0; i<v->length; i++) | ||
| 341 | { | ||
| 342 | if ((p[i] > '~') || ((p[i] < ' ') && | ||
| 343 | (p[i] != '\n') && (p[i] != '\r'))) | ||
| 344 | buf[n]='.'; | ||
| 345 | else | ||
| 346 | buf[n]=p[i]; | ||
| 347 | n++; | ||
| 348 | if (n >= 80) | ||
| 349 | { | ||
| 350 | if (BIO_write(bp,buf,n) <= 0) | ||
| 351 | return(0); | ||
| 352 | n=0; | ||
| 353 | } | ||
| 354 | } | ||
| 355 | if (n > 0) | ||
| 356 | if (BIO_write(bp,buf,n) <= 0) | ||
| 357 | return(0); | ||
| 358 | return(1); | ||
| 359 | } | ||
| 360 | |||
| 361 | int ASN1_TIME_print(BIO *bp, ASN1_TIME *tm) | ||
| 362 | { | ||
| 363 | if(tm->type == V_ASN1_UTCTIME) return ASN1_UTCTIME_print(bp, tm); | ||
| 364 | if(tm->type == V_ASN1_GENERALIZEDTIME) | ||
| 365 | return ASN1_GENERALIZEDTIME_print(bp, tm); | ||
| 366 | BIO_write(bp,"Bad time value",14); | ||
| 367 | return(0); | ||
| 368 | } | ||
| 369 | |||
| 370 | static const char *mon[12]= | ||
| 371 | { | ||
| 372 | "Jan","Feb","Mar","Apr","May","Jun", | ||
| 373 | "Jul","Aug","Sep","Oct","Nov","Dec" | ||
| 374 | }; | ||
| 375 | |||
| 376 | int ASN1_GENERALIZEDTIME_print(BIO *bp, ASN1_GENERALIZEDTIME *tm) | ||
| 377 | { | ||
| 378 | char *v; | ||
| 379 | int gmt=0; | ||
| 380 | int i; | ||
| 381 | int y=0,M=0,d=0,h=0,m=0,s=0; | ||
| 382 | |||
| 383 | i=tm->length; | ||
| 384 | v=(char *)tm->data; | ||
| 385 | |||
| 386 | if (i < 12) goto err; | ||
| 387 | if (v[i-1] == 'Z') gmt=1; | ||
| 388 | for (i=0; i<12; i++) | ||
| 389 | if ((v[i] > '9') || (v[i] < '0')) goto err; | ||
| 390 | y= (v[0]-'0')*1000+(v[1]-'0')*100 + (v[2]-'0')*10+(v[3]-'0'); | ||
| 391 | M= (v[4]-'0')*10+(v[5]-'0'); | ||
| 392 | if ((M > 12) || (M < 1)) goto err; | ||
| 393 | d= (v[6]-'0')*10+(v[7]-'0'); | ||
| 394 | h= (v[8]-'0')*10+(v[9]-'0'); | ||
| 395 | m= (v[10]-'0')*10+(v[11]-'0'); | ||
| 396 | if (i >= 14 && | ||
| 397 | (v[12] >= '0') && (v[12] <= '9') && | ||
| 398 | (v[13] >= '0') && (v[13] <= '9')) | ||
| 399 | s= (v[12]-'0')*10+(v[13]-'0'); | ||
| 400 | |||
| 401 | if (BIO_printf(bp,"%s %2d %02d:%02d:%02d %d%s", | ||
| 402 | mon[M-1],d,h,m,s,y,(gmt)?" GMT":"") <= 0) | ||
| 403 | return(0); | ||
| 404 | else | ||
| 405 | return(1); | ||
| 406 | err: | ||
| 407 | BIO_write(bp,"Bad time value",14); | ||
| 408 | return(0); | ||
| 409 | } | ||
| 410 | |||
| 411 | int ASN1_UTCTIME_print(BIO *bp, ASN1_UTCTIME *tm) | ||
| 412 | { | ||
| 413 | char *v; | ||
| 414 | int gmt=0; | ||
| 415 | int i; | ||
| 416 | int y=0,M=0,d=0,h=0,m=0,s=0; | ||
| 417 | |||
| 418 | i=tm->length; | ||
| 419 | v=(char *)tm->data; | ||
| 420 | |||
| 421 | if (i < 10) goto err; | ||
| 422 | if (v[i-1] == 'Z') gmt=1; | ||
| 423 | for (i=0; i<10; i++) | ||
| 424 | if ((v[i] > '9') || (v[i] < '0')) goto err; | ||
| 425 | y= (v[0]-'0')*10+(v[1]-'0'); | ||
| 426 | if (y < 50) y+=100; | ||
| 427 | M= (v[2]-'0')*10+(v[3]-'0'); | ||
| 428 | if ((M > 12) || (M < 1)) goto err; | ||
| 429 | d= (v[4]-'0')*10+(v[5]-'0'); | ||
| 430 | h= (v[6]-'0')*10+(v[7]-'0'); | ||
| 431 | m= (v[8]-'0')*10+(v[9]-'0'); | ||
| 432 | if (i >=12 && | ||
| 433 | (v[10] >= '0') && (v[10] <= '9') && | ||
| 434 | (v[11] >= '0') && (v[11] <= '9')) | ||
| 435 | s= (v[10]-'0')*10+(v[11]-'0'); | ||
| 436 | |||
| 437 | if (BIO_printf(bp,"%s %2d %02d:%02d:%02d %d%s", | ||
| 438 | mon[M-1],d,h,m,s,y+1900,(gmt)?" GMT":"") <= 0) | ||
| 439 | return(0); | ||
| 440 | else | ||
| 441 | return(1); | ||
| 442 | err: | ||
| 443 | BIO_write(bp,"Bad time value",14); | ||
| 444 | return(0); | ||
| 445 | } | ||
| 446 | |||
| 447 | int X509_NAME_print(BIO *bp, X509_NAME *name, int obase) | ||
| 448 | { | ||
| 449 | char *s,*c,*b; | ||
| 450 | int ret=0,l,i; | ||
| 451 | |||
| 452 | l=80-2-obase; | ||
| 453 | |||
| 454 | b=X509_NAME_oneline(name,NULL,0); | ||
| 455 | if (!*b) | ||
| 456 | { | ||
| 457 | OPENSSL_free(b); | ||
| 458 | return 1; | ||
| 459 | } | ||
| 460 | s=b+1; /* skip the first slash */ | ||
| 461 | |||
| 462 | c=s; | ||
| 463 | for (;;) | ||
| 464 | { | ||
| 465 | #ifndef CHARSET_EBCDIC | ||
| 466 | if ( ((*s == '/') && | ||
| 467 | ((s[1] >= 'A') && (s[1] <= 'Z') && ( | ||
| 468 | (s[2] == '=') || | ||
| 469 | ((s[2] >= 'A') && (s[2] <= 'Z') && | ||
| 470 | (s[3] == '=')) | ||
| 471 | ))) || | ||
| 472 | (*s == '\0')) | ||
| 473 | #else | ||
| 474 | if ( ((*s == '/') && | ||
| 475 | (isupper(s[1]) && ( | ||
| 476 | (s[2] == '=') || | ||
| 477 | (isupper(s[2]) && | ||
| 478 | (s[3] == '=')) | ||
| 479 | ))) || | ||
| 480 | (*s == '\0')) | ||
| 481 | #endif | ||
| 482 | { | ||
| 483 | i=s-c; | ||
| 484 | if (BIO_write(bp,c,i) != i) goto err; | ||
| 485 | c=s+1; /* skip following slash */ | ||
| 486 | if (*s != '\0') | ||
| 487 | { | ||
| 488 | if (BIO_write(bp,", ",2) != 2) goto err; | ||
| 489 | } | ||
| 490 | l--; | ||
| 491 | } | ||
| 492 | if (*s == '\0') break; | ||
| 493 | s++; | ||
| 494 | l--; | ||
| 495 | } | ||
| 496 | |||
| 497 | ret=1; | ||
| 498 | if (0) | ||
| 499 | { | ||
| 500 | err: | ||
| 501 | X509err(X509_F_X509_NAME_PRINT,ERR_R_BUF_LIB); | ||
| 502 | } | ||
| 503 | OPENSSL_free(b); | ||
| 504 | return(ret); | ||
| 505 | } | ||
diff --git a/src/lib/libcrypto/asn1/t_x509a.c b/src/lib/libcrypto/asn1/t_x509a.c new file mode 100644 index 0000000000..ffbbfb51f4 --- /dev/null +++ b/src/lib/libcrypto/asn1/t_x509a.c | |||
| @@ -0,0 +1,110 @@ | |||
| 1 | /* t_x509a.c */ | ||
| 2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
| 3 | * project 1999. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/evp.h> | ||
| 62 | #include <openssl/asn1.h> | ||
| 63 | #include <openssl/x509.h> | ||
| 64 | |||
| 65 | /* X509_CERT_AUX and string set routines | ||
| 66 | */ | ||
| 67 | |||
| 68 | int X509_CERT_AUX_print(BIO *out, X509_CERT_AUX *aux, int indent) | ||
| 69 | { | ||
| 70 | char oidstr[80], first; | ||
| 71 | int i; | ||
| 72 | if(!aux) return 1; | ||
| 73 | if(aux->trust) { | ||
| 74 | first = 1; | ||
| 75 | BIO_printf(out, "%*sTrusted Uses:\n%*s", | ||
| 76 | indent, "", indent + 2, ""); | ||
| 77 | for(i = 0; i < sk_ASN1_OBJECT_num(aux->trust); i++) { | ||
| 78 | if(!first) BIO_puts(out, ", "); | ||
| 79 | else first = 0; | ||
| 80 | OBJ_obj2txt(oidstr, sizeof oidstr, | ||
| 81 | sk_ASN1_OBJECT_value(aux->trust, i), 0); | ||
| 82 | BIO_puts(out, oidstr); | ||
| 83 | } | ||
| 84 | BIO_puts(out, "\n"); | ||
| 85 | } else BIO_printf(out, "%*sNo Trusted Uses.\n", indent, ""); | ||
| 86 | if(aux->reject) { | ||
| 87 | first = 1; | ||
| 88 | BIO_printf(out, "%*sRejected Uses:\n%*s", | ||
| 89 | indent, "", indent + 2, ""); | ||
| 90 | for(i = 0; i < sk_ASN1_OBJECT_num(aux->reject); i++) { | ||
| 91 | if(!first) BIO_puts(out, ", "); | ||
| 92 | else first = 0; | ||
| 93 | OBJ_obj2txt(oidstr, sizeof oidstr, | ||
| 94 | sk_ASN1_OBJECT_value(aux->reject, i), 0); | ||
| 95 | BIO_puts(out, oidstr); | ||
| 96 | } | ||
| 97 | BIO_puts(out, "\n"); | ||
| 98 | } else BIO_printf(out, "%*sNo Rejected Uses.\n", indent, ""); | ||
| 99 | if(aux->alias) BIO_printf(out, "%*sAlias: %s\n", indent, "", | ||
| 100 | aux->alias->data); | ||
| 101 | if(aux->keyid) { | ||
| 102 | BIO_printf(out, "%*sKey Id: ", indent, ""); | ||
| 103 | for(i = 0; i < aux->keyid->length; i++) | ||
| 104 | BIO_printf(out, "%s%02X", | ||
| 105 | i ? ":" : "", | ||
| 106 | aux->keyid->data[i]); | ||
| 107 | BIO_write(out,"\n",1); | ||
| 108 | } | ||
| 109 | return 1; | ||
| 110 | } | ||
diff --git a/src/lib/libcrypto/asn1/tasn_dec.c b/src/lib/libcrypto/asn1/tasn_dec.c new file mode 100644 index 0000000000..0ee406231e --- /dev/null +++ b/src/lib/libcrypto/asn1/tasn_dec.c | |||
| @@ -0,0 +1,1322 @@ | |||
| 1 | /* tasn_dec.c */ | ||
| 2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
| 3 | * project 2000. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 2000-2005 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | |||
| 60 | #include <stddef.h> | ||
| 61 | #include <string.h> | ||
| 62 | #include <openssl/asn1.h> | ||
| 63 | #include <openssl/asn1t.h> | ||
| 64 | #include <openssl/objects.h> | ||
| 65 | #include <openssl/buffer.h> | ||
| 66 | #include <openssl/err.h> | ||
| 67 | |||
| 68 | static int asn1_check_eoc(const unsigned char **in, long len); | ||
| 69 | static int asn1_find_end(const unsigned char **in, long len, char inf); | ||
| 70 | |||
| 71 | static int asn1_collect(BUF_MEM *buf, const unsigned char **in, long len, | ||
| 72 | char inf, int tag, int aclass); | ||
| 73 | |||
| 74 | static int collect_data(BUF_MEM *buf, const unsigned char **p, long plen); | ||
| 75 | |||
| 76 | static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass, | ||
| 77 | char *inf, char *cst, | ||
| 78 | const unsigned char **in, long len, | ||
| 79 | int exptag, int expclass, char opt, | ||
| 80 | ASN1_TLC *ctx); | ||
| 81 | |||
| 82 | static int asn1_template_ex_d2i(ASN1_VALUE **pval, | ||
| 83 | const unsigned char **in, long len, | ||
| 84 | const ASN1_TEMPLATE *tt, char opt, | ||
| 85 | ASN1_TLC *ctx); | ||
| 86 | static int asn1_template_noexp_d2i(ASN1_VALUE **val, | ||
| 87 | const unsigned char **in, long len, | ||
| 88 | const ASN1_TEMPLATE *tt, char opt, | ||
| 89 | ASN1_TLC *ctx); | ||
| 90 | static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, | ||
| 91 | const unsigned char **in, long len, | ||
| 92 | const ASN1_ITEM *it, | ||
| 93 | int tag, int aclass, char opt, ASN1_TLC *ctx); | ||
| 94 | |||
| 95 | /* Table to convert tags to bit values, used for MSTRING type */ | ||
| 96 | static const unsigned long tag2bit[32] = { | ||
| 97 | 0, 0, 0, B_ASN1_BIT_STRING, /* tags 0 - 3 */ | ||
| 98 | B_ASN1_OCTET_STRING, 0, 0, B_ASN1_UNKNOWN,/* tags 4- 7 */ | ||
| 99 | B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN,/* tags 8-11 */ | ||
| 100 | B_ASN1_UTF8STRING,B_ASN1_UNKNOWN,B_ASN1_UNKNOWN,B_ASN1_UNKNOWN,/* tags 12-15 */ | ||
| 101 | B_ASN1_SEQUENCE,0,B_ASN1_NUMERICSTRING,B_ASN1_PRINTABLESTRING, /* tags 16-19 */ | ||
| 102 | B_ASN1_T61STRING,B_ASN1_VIDEOTEXSTRING,B_ASN1_IA5STRING, /* tags 20-22 */ | ||
| 103 | B_ASN1_UTCTIME, B_ASN1_GENERALIZEDTIME, /* tags 23-24 */ | ||
| 104 | B_ASN1_GRAPHICSTRING,B_ASN1_ISO64STRING,B_ASN1_GENERALSTRING, /* tags 25-27 */ | ||
| 105 | B_ASN1_UNIVERSALSTRING,B_ASN1_UNKNOWN,B_ASN1_BMPSTRING,B_ASN1_UNKNOWN, /* tags 28-31 */ | ||
| 106 | }; | ||
| 107 | |||
| 108 | unsigned long ASN1_tag2bit(int tag) | ||
| 109 | { | ||
| 110 | if ((tag < 0) || (tag > 30)) return 0; | ||
| 111 | return tag2bit[tag]; | ||
| 112 | } | ||
| 113 | |||
| 114 | /* Macro to initialize and invalidate the cache */ | ||
| 115 | |||
| 116 | #define asn1_tlc_clear(c) if (c) (c)->valid = 0 | ||
| 117 | |||
| 118 | /* Decode an ASN1 item, this currently behaves just | ||
| 119 | * like a standard 'd2i' function. 'in' points to | ||
| 120 | * a buffer to read the data from, in future we will | ||
| 121 | * have more advanced versions that can input data | ||
| 122 | * a piece at a time and this will simply be a special | ||
| 123 | * case. | ||
| 124 | */ | ||
| 125 | |||
| 126 | ASN1_VALUE *ASN1_item_d2i(ASN1_VALUE **pval, | ||
| 127 | const unsigned char **in, long len, const ASN1_ITEM *it) | ||
| 128 | { | ||
| 129 | ASN1_TLC c; | ||
| 130 | ASN1_VALUE *ptmpval = NULL; | ||
| 131 | if (!pval) | ||
| 132 | pval = &ptmpval; | ||
| 133 | c.valid = 0; | ||
| 134 | if (ASN1_item_ex_d2i(pval, in, len, it, -1, 0, 0, &c) > 0) | ||
| 135 | return *pval; | ||
| 136 | return NULL; | ||
| 137 | } | ||
| 138 | |||
| 139 | int ASN1_template_d2i(ASN1_VALUE **pval, | ||
| 140 | const unsigned char **in, long len, const ASN1_TEMPLATE *tt) | ||
| 141 | { | ||
| 142 | ASN1_TLC c; | ||
| 143 | c.valid = 0; | ||
| 144 | return asn1_template_ex_d2i(pval, in, len, tt, 0, &c); | ||
| 145 | } | ||
| 146 | |||
| 147 | |||
| 148 | /* Decode an item, taking care of IMPLICIT tagging, if any. | ||
| 149 | * If 'opt' set and tag mismatch return -1 to handle OPTIONAL | ||
| 150 | */ | ||
| 151 | |||
| 152 | int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, | ||
| 153 | const ASN1_ITEM *it, | ||
| 154 | int tag, int aclass, char opt, ASN1_TLC *ctx) | ||
| 155 | { | ||
| 156 | const ASN1_TEMPLATE *tt, *errtt = NULL; | ||
| 157 | const ASN1_COMPAT_FUNCS *cf; | ||
| 158 | const ASN1_EXTERN_FUNCS *ef; | ||
| 159 | const ASN1_AUX *aux = it->funcs; | ||
| 160 | ASN1_aux_cb *asn1_cb; | ||
| 161 | const unsigned char *p = NULL, *q; | ||
| 162 | unsigned char *wp=NULL; /* BIG FAT WARNING! BREAKS CONST WHERE USED */ | ||
| 163 | unsigned char imphack = 0, oclass; | ||
| 164 | char seq_eoc, seq_nolen, cst, isopt; | ||
| 165 | long tmplen; | ||
| 166 | int i; | ||
| 167 | int otag; | ||
| 168 | int ret = 0; | ||
| 169 | ASN1_VALUE *pchval, **pchptr, *ptmpval; | ||
| 170 | if (!pval) | ||
| 171 | return 0; | ||
| 172 | if (aux && aux->asn1_cb) | ||
| 173 | asn1_cb = aux->asn1_cb; | ||
| 174 | else asn1_cb = 0; | ||
| 175 | |||
| 176 | switch(it->itype) | ||
| 177 | { | ||
| 178 | case ASN1_ITYPE_PRIMITIVE: | ||
| 179 | if (it->templates) | ||
| 180 | { | ||
| 181 | /* tagging or OPTIONAL is currently illegal on an item | ||
| 182 | * template because the flags can't get passed down. | ||
| 183 | * In practice this isn't a problem: we include the | ||
| 184 | * relevant flags from the item template in the | ||
| 185 | * template itself. | ||
| 186 | */ | ||
| 187 | if ((tag != -1) || opt) | ||
| 188 | { | ||
| 189 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, | ||
| 190 | ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE); | ||
| 191 | goto err; | ||
| 192 | } | ||
| 193 | return asn1_template_ex_d2i(pval, in, len, | ||
| 194 | it->templates, opt, ctx); | ||
| 195 | } | ||
| 196 | return asn1_d2i_ex_primitive(pval, in, len, it, | ||
| 197 | tag, aclass, opt, ctx); | ||
| 198 | break; | ||
| 199 | |||
| 200 | case ASN1_ITYPE_MSTRING: | ||
| 201 | p = *in; | ||
| 202 | /* Just read in tag and class */ | ||
| 203 | ret = asn1_check_tlen(NULL, &otag, &oclass, NULL, NULL, | ||
| 204 | &p, len, -1, 0, 1, ctx); | ||
| 205 | if (!ret) | ||
| 206 | { | ||
| 207 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, | ||
| 208 | ERR_R_NESTED_ASN1_ERROR); | ||
| 209 | goto err; | ||
| 210 | } | ||
| 211 | |||
| 212 | /* Must be UNIVERSAL class */ | ||
| 213 | if (oclass != V_ASN1_UNIVERSAL) | ||
| 214 | { | ||
| 215 | /* If OPTIONAL, assume this is OK */ | ||
| 216 | if (opt) return -1; | ||
| 217 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, | ||
| 218 | ASN1_R_MSTRING_NOT_UNIVERSAL); | ||
| 219 | goto err; | ||
| 220 | } | ||
| 221 | /* Check tag matches bit map */ | ||
| 222 | if (!(ASN1_tag2bit(otag) & it->utype)) | ||
| 223 | { | ||
| 224 | /* If OPTIONAL, assume this is OK */ | ||
| 225 | if (opt) | ||
| 226 | return -1; | ||
| 227 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, | ||
| 228 | ASN1_R_MSTRING_WRONG_TAG); | ||
| 229 | goto err; | ||
| 230 | } | ||
| 231 | return asn1_d2i_ex_primitive(pval, in, len, | ||
| 232 | it, otag, 0, 0, ctx); | ||
| 233 | |||
| 234 | case ASN1_ITYPE_EXTERN: | ||
| 235 | /* Use new style d2i */ | ||
| 236 | ef = it->funcs; | ||
| 237 | return ef->asn1_ex_d2i(pval, in, len, | ||
| 238 | it, tag, aclass, opt, ctx); | ||
| 239 | |||
| 240 | case ASN1_ITYPE_COMPAT: | ||
| 241 | /* we must resort to old style evil hackery */ | ||
| 242 | cf = it->funcs; | ||
| 243 | |||
| 244 | /* If OPTIONAL see if it is there */ | ||
| 245 | if (opt) | ||
| 246 | { | ||
| 247 | int exptag; | ||
| 248 | p = *in; | ||
| 249 | if (tag == -1) | ||
| 250 | exptag = it->utype; | ||
| 251 | else exptag = tag; | ||
| 252 | /* Don't care about anything other than presence | ||
| 253 | * of expected tag */ | ||
| 254 | |||
| 255 | ret = asn1_check_tlen(NULL, NULL, NULL, NULL, NULL, | ||
| 256 | &p, len, exptag, aclass, 1, ctx); | ||
| 257 | if (!ret) | ||
| 258 | { | ||
| 259 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, | ||
| 260 | ERR_R_NESTED_ASN1_ERROR); | ||
| 261 | goto err; | ||
| 262 | } | ||
| 263 | if (ret == -1) | ||
| 264 | return -1; | ||
| 265 | } | ||
| 266 | |||
| 267 | /* This is the old style evil hack IMPLICIT handling: | ||
| 268 | * since the underlying code is expecting a tag and | ||
| 269 | * class other than the one present we change the | ||
| 270 | * buffer temporarily then change it back afterwards. | ||
| 271 | * This doesn't and never did work for tags > 30. | ||
| 272 | * | ||
| 273 | * Yes this is *horrible* but it is only needed for | ||
| 274 | * old style d2i which will hopefully not be around | ||
| 275 | * for much longer. | ||
| 276 | * FIXME: should copy the buffer then modify it so | ||
| 277 | * the input buffer can be const: we should *always* | ||
| 278 | * copy because the old style d2i might modify the | ||
| 279 | * buffer. | ||
| 280 | */ | ||
| 281 | |||
| 282 | if (tag != -1) | ||
| 283 | { | ||
| 284 | wp = *(unsigned char **)in; | ||
| 285 | imphack = *wp; | ||
| 286 | if (p == NULL) | ||
| 287 | { | ||
| 288 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, | ||
| 289 | ERR_R_NESTED_ASN1_ERROR); | ||
| 290 | goto err; | ||
| 291 | } | ||
| 292 | *wp = (unsigned char)((*p & V_ASN1_CONSTRUCTED) | ||
| 293 | | it->utype); | ||
| 294 | } | ||
| 295 | |||
| 296 | ptmpval = cf->asn1_d2i(pval, in, len); | ||
| 297 | |||
| 298 | if (tag != -1) | ||
| 299 | *wp = imphack; | ||
| 300 | |||
| 301 | if (ptmpval) | ||
| 302 | return 1; | ||
| 303 | |||
| 304 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR); | ||
| 305 | goto err; | ||
| 306 | |||
| 307 | |||
| 308 | case ASN1_ITYPE_CHOICE: | ||
| 309 | if (asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it)) | ||
| 310 | goto auxerr; | ||
| 311 | |||
| 312 | /* Allocate structure */ | ||
| 313 | if (!*pval && !ASN1_item_ex_new(pval, it)) | ||
| 314 | { | ||
| 315 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, | ||
| 316 | ERR_R_NESTED_ASN1_ERROR); | ||
| 317 | goto err; | ||
| 318 | } | ||
| 319 | /* CHOICE type, try each possibility in turn */ | ||
| 320 | pchval = NULL; | ||
| 321 | p = *in; | ||
| 322 | for (i = 0, tt=it->templates; i < it->tcount; i++, tt++) | ||
| 323 | { | ||
| 324 | pchptr = asn1_get_field_ptr(pval, tt); | ||
| 325 | /* We mark field as OPTIONAL so its absence | ||
| 326 | * can be recognised. | ||
| 327 | */ | ||
| 328 | ret = asn1_template_ex_d2i(pchptr, &p, len, tt, 1, ctx); | ||
| 329 | /* If field not present, try the next one */ | ||
| 330 | if (ret == -1) | ||
| 331 | continue; | ||
| 332 | /* If positive return, read OK, break loop */ | ||
| 333 | if (ret > 0) | ||
| 334 | break; | ||
| 335 | /* Otherwise must be an ASN1 parsing error */ | ||
| 336 | errtt = tt; | ||
| 337 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, | ||
| 338 | ERR_R_NESTED_ASN1_ERROR); | ||
| 339 | goto err; | ||
| 340 | } | ||
| 341 | |||
| 342 | /* Did we fall off the end without reading anything? */ | ||
| 343 | if (i == it->tcount) | ||
| 344 | { | ||
| 345 | /* If OPTIONAL, this is OK */ | ||
| 346 | if (opt) | ||
| 347 | { | ||
| 348 | /* Free and zero it */ | ||
| 349 | ASN1_item_ex_free(pval, it); | ||
| 350 | return -1; | ||
| 351 | } | ||
| 352 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, | ||
| 353 | ASN1_R_NO_MATCHING_CHOICE_TYPE); | ||
| 354 | goto err; | ||
| 355 | } | ||
| 356 | |||
| 357 | asn1_set_choice_selector(pval, i, it); | ||
| 358 | *in = p; | ||
| 359 | if (asn1_cb && !asn1_cb(ASN1_OP_D2I_POST, pval, it)) | ||
| 360 | goto auxerr; | ||
| 361 | return 1; | ||
| 362 | |||
| 363 | case ASN1_ITYPE_NDEF_SEQUENCE: | ||
| 364 | case ASN1_ITYPE_SEQUENCE: | ||
| 365 | p = *in; | ||
| 366 | tmplen = len; | ||
| 367 | |||
| 368 | /* If no IMPLICIT tagging set to SEQUENCE, UNIVERSAL */ | ||
| 369 | if (tag == -1) | ||
| 370 | { | ||
| 371 | tag = V_ASN1_SEQUENCE; | ||
| 372 | aclass = V_ASN1_UNIVERSAL; | ||
| 373 | } | ||
| 374 | /* Get SEQUENCE length and update len, p */ | ||
| 375 | ret = asn1_check_tlen(&len, NULL, NULL, &seq_eoc, &cst, | ||
| 376 | &p, len, tag, aclass, opt, ctx); | ||
| 377 | if (!ret) | ||
| 378 | { | ||
| 379 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, | ||
| 380 | ERR_R_NESTED_ASN1_ERROR); | ||
| 381 | goto err; | ||
| 382 | } | ||
| 383 | else if (ret == -1) | ||
| 384 | return -1; | ||
| 385 | if (aux && (aux->flags & ASN1_AFLG_BROKEN)) | ||
| 386 | { | ||
| 387 | len = tmplen - (p - *in); | ||
| 388 | seq_nolen = 1; | ||
| 389 | } | ||
| 390 | /* If indefinite we don't do a length check */ | ||
| 391 | else seq_nolen = seq_eoc; | ||
| 392 | if (!cst) | ||
| 393 | { | ||
| 394 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, | ||
| 395 | ASN1_R_SEQUENCE_NOT_CONSTRUCTED); | ||
| 396 | goto err; | ||
| 397 | } | ||
| 398 | |||
| 399 | if (!*pval && !ASN1_item_ex_new(pval, it)) | ||
| 400 | { | ||
| 401 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, | ||
| 402 | ERR_R_NESTED_ASN1_ERROR); | ||
| 403 | goto err; | ||
| 404 | } | ||
| 405 | |||
| 406 | if (asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it)) | ||
| 407 | goto auxerr; | ||
| 408 | |||
| 409 | /* Get each field entry */ | ||
| 410 | for (i = 0, tt = it->templates; i < it->tcount; i++, tt++) | ||
| 411 | { | ||
| 412 | const ASN1_TEMPLATE *seqtt; | ||
| 413 | ASN1_VALUE **pseqval; | ||
| 414 | seqtt = asn1_do_adb(pval, tt, 1); | ||
| 415 | if (!seqtt) | ||
| 416 | goto err; | ||
| 417 | pseqval = asn1_get_field_ptr(pval, seqtt); | ||
| 418 | /* Have we ran out of data? */ | ||
| 419 | if (!len) | ||
| 420 | break; | ||
| 421 | q = p; | ||
| 422 | if (asn1_check_eoc(&p, len)) | ||
| 423 | { | ||
| 424 | if (!seq_eoc) | ||
| 425 | { | ||
| 426 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, | ||
| 427 | ASN1_R_UNEXPECTED_EOC); | ||
| 428 | goto err; | ||
| 429 | } | ||
| 430 | len -= p - q; | ||
| 431 | seq_eoc = 0; | ||
| 432 | q = p; | ||
| 433 | break; | ||
| 434 | } | ||
| 435 | /* This determines the OPTIONAL flag value. The field | ||
| 436 | * cannot be omitted if it is the last of a SEQUENCE | ||
| 437 | * and there is still data to be read. This isn't | ||
| 438 | * strictly necessary but it increases efficiency in | ||
| 439 | * some cases. | ||
| 440 | */ | ||
| 441 | if (i == (it->tcount - 1)) | ||
| 442 | isopt = 0; | ||
| 443 | else isopt = (char)(seqtt->flags & ASN1_TFLG_OPTIONAL); | ||
| 444 | /* attempt to read in field, allowing each to be | ||
| 445 | * OPTIONAL */ | ||
| 446 | |||
| 447 | ret = asn1_template_ex_d2i(pseqval, &p, len, | ||
| 448 | seqtt, isopt, ctx); | ||
| 449 | if (!ret) | ||
| 450 | { | ||
| 451 | errtt = seqtt; | ||
| 452 | goto err; | ||
| 453 | } | ||
| 454 | else if (ret == -1) | ||
| 455 | { | ||
| 456 | /* OPTIONAL component absent. | ||
| 457 | * Free and zero the field. | ||
| 458 | */ | ||
| 459 | ASN1_template_free(pseqval, seqtt); | ||
| 460 | continue; | ||
| 461 | } | ||
| 462 | /* Update length */ | ||
| 463 | len -= p - q; | ||
| 464 | } | ||
| 465 | |||
| 466 | /* Check for EOC if expecting one */ | ||
| 467 | if (seq_eoc && !asn1_check_eoc(&p, len)) | ||
| 468 | { | ||
| 469 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_MISSING_EOC); | ||
| 470 | goto err; | ||
| 471 | } | ||
| 472 | /* Check all data read */ | ||
| 473 | if (!seq_nolen && len) | ||
| 474 | { | ||
| 475 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, | ||
| 476 | ASN1_R_SEQUENCE_LENGTH_MISMATCH); | ||
| 477 | goto err; | ||
| 478 | } | ||
| 479 | |||
| 480 | /* If we get here we've got no more data in the SEQUENCE, | ||
| 481 | * however we may not have read all fields so check all | ||
| 482 | * remaining are OPTIONAL and clear any that are. | ||
| 483 | */ | ||
| 484 | for (; i < it->tcount; tt++, i++) | ||
| 485 | { | ||
| 486 | const ASN1_TEMPLATE *seqtt; | ||
| 487 | seqtt = asn1_do_adb(pval, tt, 1); | ||
| 488 | if (!seqtt) | ||
| 489 | goto err; | ||
| 490 | if (seqtt->flags & ASN1_TFLG_OPTIONAL) | ||
| 491 | { | ||
| 492 | ASN1_VALUE **pseqval; | ||
| 493 | pseqval = asn1_get_field_ptr(pval, seqtt); | ||
| 494 | ASN1_template_free(pseqval, seqtt); | ||
| 495 | } | ||
| 496 | else | ||
| 497 | { | ||
| 498 | errtt = seqtt; | ||
| 499 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, | ||
| 500 | ASN1_R_FIELD_MISSING); | ||
| 501 | goto err; | ||
| 502 | } | ||
| 503 | } | ||
| 504 | /* Save encoding */ | ||
| 505 | if (!asn1_enc_save(pval, *in, p - *in, it)) | ||
| 506 | goto auxerr; | ||
| 507 | *in = p; | ||
| 508 | if (asn1_cb && !asn1_cb(ASN1_OP_D2I_POST, pval, it)) | ||
| 509 | goto auxerr; | ||
| 510 | return 1; | ||
| 511 | |||
| 512 | default: | ||
| 513 | return 0; | ||
| 514 | } | ||
| 515 | auxerr: | ||
| 516 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_AUX_ERROR); | ||
| 517 | err: | ||
| 518 | ASN1_item_ex_free(pval, it); | ||
| 519 | if (errtt) | ||
| 520 | ERR_add_error_data(4, "Field=", errtt->field_name, | ||
| 521 | ", Type=", it->sname); | ||
| 522 | else | ||
| 523 | ERR_add_error_data(2, "Type=", it->sname); | ||
| 524 | return 0; | ||
| 525 | } | ||
| 526 | |||
| 527 | /* Templates are handled with two separate functions. | ||
| 528 | * One handles any EXPLICIT tag and the other handles the rest. | ||
| 529 | */ | ||
| 530 | |||
| 531 | static int asn1_template_ex_d2i(ASN1_VALUE **val, | ||
| 532 | const unsigned char **in, long inlen, | ||
| 533 | const ASN1_TEMPLATE *tt, char opt, | ||
| 534 | ASN1_TLC *ctx) | ||
| 535 | { | ||
| 536 | int flags, aclass; | ||
| 537 | int ret; | ||
| 538 | long len; | ||
| 539 | const unsigned char *p, *q; | ||
| 540 | char exp_eoc; | ||
| 541 | if (!val) | ||
| 542 | return 0; | ||
| 543 | flags = tt->flags; | ||
| 544 | aclass = flags & ASN1_TFLG_TAG_CLASS; | ||
| 545 | |||
| 546 | p = *in; | ||
| 547 | |||
| 548 | /* Check if EXPLICIT tag expected */ | ||
| 549 | if (flags & ASN1_TFLG_EXPTAG) | ||
| 550 | { | ||
| 551 | char cst; | ||
| 552 | /* Need to work out amount of data available to the inner | ||
| 553 | * content and where it starts: so read in EXPLICIT header to | ||
| 554 | * get the info. | ||
| 555 | */ | ||
| 556 | ret = asn1_check_tlen(&len, NULL, NULL, &exp_eoc, &cst, | ||
| 557 | &p, inlen, tt->tag, aclass, opt, ctx); | ||
| 558 | q = p; | ||
| 559 | if (!ret) | ||
| 560 | { | ||
| 561 | ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, | ||
| 562 | ERR_R_NESTED_ASN1_ERROR); | ||
| 563 | return 0; | ||
| 564 | } | ||
| 565 | else if (ret == -1) | ||
| 566 | return -1; | ||
| 567 | if (!cst) | ||
| 568 | { | ||
| 569 | ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, | ||
| 570 | ASN1_R_EXPLICIT_TAG_NOT_CONSTRUCTED); | ||
| 571 | return 0; | ||
| 572 | } | ||
| 573 | /* We've found the field so it can't be OPTIONAL now */ | ||
| 574 | ret = asn1_template_noexp_d2i(val, &p, len, tt, 0, ctx); | ||
| 575 | if (!ret) | ||
| 576 | { | ||
| 577 | ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, | ||
| 578 | ERR_R_NESTED_ASN1_ERROR); | ||
| 579 | return 0; | ||
| 580 | } | ||
| 581 | /* We read the field in OK so update length */ | ||
| 582 | len -= p - q; | ||
| 583 | if (exp_eoc) | ||
| 584 | { | ||
| 585 | /* If NDEF we must have an EOC here */ | ||
| 586 | if (!asn1_check_eoc(&p, len)) | ||
| 587 | { | ||
| 588 | ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, | ||
| 589 | ASN1_R_MISSING_EOC); | ||
| 590 | goto err; | ||
| 591 | } | ||
| 592 | } | ||
| 593 | else | ||
| 594 | { | ||
| 595 | /* Otherwise we must hit the EXPLICIT tag end or its | ||
| 596 | * an error */ | ||
| 597 | if (len) | ||
| 598 | { | ||
| 599 | ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, | ||
| 600 | ASN1_R_EXPLICIT_LENGTH_MISMATCH); | ||
| 601 | goto err; | ||
| 602 | } | ||
| 603 | } | ||
| 604 | } | ||
| 605 | else | ||
| 606 | return asn1_template_noexp_d2i(val, in, inlen, | ||
| 607 | tt, opt, ctx); | ||
| 608 | |||
| 609 | *in = p; | ||
| 610 | return 1; | ||
| 611 | |||
| 612 | err: | ||
| 613 | ASN1_template_free(val, tt); | ||
| 614 | *val = NULL; | ||
| 615 | return 0; | ||
| 616 | } | ||
| 617 | |||
| 618 | static int asn1_template_noexp_d2i(ASN1_VALUE **val, | ||
| 619 | const unsigned char **in, long len, | ||
| 620 | const ASN1_TEMPLATE *tt, char opt, | ||
| 621 | ASN1_TLC *ctx) | ||
| 622 | { | ||
| 623 | int flags, aclass; | ||
| 624 | int ret; | ||
| 625 | const unsigned char *p, *q; | ||
| 626 | if (!val) | ||
| 627 | return 0; | ||
| 628 | flags = tt->flags; | ||
| 629 | aclass = flags & ASN1_TFLG_TAG_CLASS; | ||
| 630 | |||
| 631 | p = *in; | ||
| 632 | q = p; | ||
| 633 | |||
| 634 | if (flags & ASN1_TFLG_SK_MASK) | ||
| 635 | { | ||
| 636 | /* SET OF, SEQUENCE OF */ | ||
| 637 | int sktag, skaclass; | ||
| 638 | char sk_eoc; | ||
| 639 | /* First work out expected inner tag value */ | ||
| 640 | if (flags & ASN1_TFLG_IMPTAG) | ||
| 641 | { | ||
| 642 | sktag = tt->tag; | ||
| 643 | skaclass = aclass; | ||
| 644 | } | ||
| 645 | else | ||
| 646 | { | ||
| 647 | skaclass = V_ASN1_UNIVERSAL; | ||
| 648 | if (flags & ASN1_TFLG_SET_OF) | ||
| 649 | sktag = V_ASN1_SET; | ||
| 650 | else | ||
| 651 | sktag = V_ASN1_SEQUENCE; | ||
| 652 | } | ||
| 653 | /* Get the tag */ | ||
| 654 | ret = asn1_check_tlen(&len, NULL, NULL, &sk_eoc, NULL, | ||
| 655 | &p, len, sktag, skaclass, opt, ctx); | ||
| 656 | if (!ret) | ||
| 657 | { | ||
| 658 | ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, | ||
| 659 | ERR_R_NESTED_ASN1_ERROR); | ||
| 660 | return 0; | ||
| 661 | } | ||
| 662 | else if (ret == -1) | ||
| 663 | return -1; | ||
| 664 | if (!*val) | ||
| 665 | *val = (ASN1_VALUE *)sk_new_null(); | ||
| 666 | else | ||
| 667 | { | ||
| 668 | /* We've got a valid STACK: free up any items present */ | ||
| 669 | STACK *sktmp = (STACK *)*val; | ||
| 670 | ASN1_VALUE *vtmp; | ||
| 671 | while(sk_num(sktmp) > 0) | ||
| 672 | { | ||
| 673 | vtmp = (ASN1_VALUE *)sk_pop(sktmp); | ||
| 674 | ASN1_item_ex_free(&vtmp, | ||
| 675 | ASN1_ITEM_ptr(tt->item)); | ||
| 676 | } | ||
| 677 | } | ||
| 678 | |||
| 679 | if (!*val) | ||
| 680 | { | ||
| 681 | ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, | ||
| 682 | ERR_R_MALLOC_FAILURE); | ||
| 683 | goto err; | ||
| 684 | } | ||
| 685 | |||
| 686 | /* Read as many items as we can */ | ||
| 687 | while(len > 0) | ||
| 688 | { | ||
| 689 | ASN1_VALUE *skfield; | ||
| 690 | q = p; | ||
| 691 | /* See if EOC found */ | ||
| 692 | if (asn1_check_eoc(&p, len)) | ||
| 693 | { | ||
| 694 | if (!sk_eoc) | ||
| 695 | { | ||
| 696 | ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, | ||
| 697 | ASN1_R_UNEXPECTED_EOC); | ||
| 698 | goto err; | ||
| 699 | } | ||
| 700 | len -= p - q; | ||
| 701 | sk_eoc = 0; | ||
| 702 | break; | ||
| 703 | } | ||
| 704 | skfield = NULL; | ||
| 705 | if (!ASN1_item_ex_d2i(&skfield, &p, len, | ||
| 706 | ASN1_ITEM_ptr(tt->item), | ||
| 707 | -1, 0, 0, ctx)) | ||
| 708 | { | ||
| 709 | ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, | ||
| 710 | ERR_R_NESTED_ASN1_ERROR); | ||
| 711 | goto err; | ||
| 712 | } | ||
| 713 | len -= p - q; | ||
| 714 | if (!sk_push((STACK *)*val, (char *)skfield)) | ||
| 715 | { | ||
| 716 | ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, | ||
| 717 | ERR_R_MALLOC_FAILURE); | ||
| 718 | goto err; | ||
| 719 | } | ||
| 720 | } | ||
| 721 | if (sk_eoc) | ||
| 722 | { | ||
| 723 | ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, ASN1_R_MISSING_EOC); | ||
| 724 | goto err; | ||
| 725 | } | ||
| 726 | } | ||
| 727 | else if (flags & ASN1_TFLG_IMPTAG) | ||
| 728 | { | ||
| 729 | /* IMPLICIT tagging */ | ||
| 730 | ret = ASN1_item_ex_d2i(val, &p, len, | ||
| 731 | ASN1_ITEM_ptr(tt->item), tt->tag, aclass, opt, ctx); | ||
| 732 | if (!ret) | ||
| 733 | { | ||
| 734 | ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, | ||
| 735 | ERR_R_NESTED_ASN1_ERROR); | ||
| 736 | goto err; | ||
| 737 | } | ||
| 738 | else if (ret == -1) | ||
| 739 | return -1; | ||
| 740 | } | ||
| 741 | else | ||
| 742 | { | ||
| 743 | /* Nothing special */ | ||
| 744 | ret = ASN1_item_ex_d2i(val, &p, len, ASN1_ITEM_ptr(tt->item), | ||
| 745 | -1, 0, opt, ctx); | ||
| 746 | if (!ret) | ||
| 747 | { | ||
| 748 | ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, | ||
| 749 | ERR_R_NESTED_ASN1_ERROR); | ||
| 750 | goto err; | ||
| 751 | } | ||
| 752 | else if (ret == -1) | ||
| 753 | return -1; | ||
| 754 | } | ||
| 755 | |||
| 756 | *in = p; | ||
| 757 | return 1; | ||
| 758 | |||
| 759 | err: | ||
| 760 | ASN1_template_free(val, tt); | ||
| 761 | *val = NULL; | ||
| 762 | return 0; | ||
| 763 | } | ||
| 764 | |||
| 765 | static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, | ||
| 766 | const unsigned char **in, long inlen, | ||
| 767 | const ASN1_ITEM *it, | ||
| 768 | int tag, int aclass, char opt, ASN1_TLC *ctx) | ||
| 769 | { | ||
| 770 | int ret = 0, utype; | ||
| 771 | long plen; | ||
| 772 | char cst, inf, free_cont = 0; | ||
| 773 | const unsigned char *p; | ||
| 774 | BUF_MEM buf; | ||
| 775 | const unsigned char *cont = NULL; | ||
| 776 | long len; | ||
| 777 | if (!pval) | ||
| 778 | { | ||
| 779 | ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ASN1_R_ILLEGAL_NULL); | ||
| 780 | return 0; /* Should never happen */ | ||
| 781 | } | ||
| 782 | |||
| 783 | if (it->itype == ASN1_ITYPE_MSTRING) | ||
| 784 | { | ||
| 785 | utype = tag; | ||
| 786 | tag = -1; | ||
| 787 | } | ||
| 788 | else | ||
| 789 | utype = it->utype; | ||
| 790 | |||
| 791 | if (utype == V_ASN1_ANY) | ||
| 792 | { | ||
| 793 | /* If type is ANY need to figure out type from tag */ | ||
| 794 | unsigned char oclass; | ||
| 795 | if (tag >= 0) | ||
| 796 | { | ||
| 797 | ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, | ||
| 798 | ASN1_R_ILLEGAL_TAGGED_ANY); | ||
| 799 | return 0; | ||
| 800 | } | ||
| 801 | if (opt) | ||
| 802 | { | ||
| 803 | ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, | ||
| 804 | ASN1_R_ILLEGAL_OPTIONAL_ANY); | ||
| 805 | return 0; | ||
| 806 | } | ||
| 807 | p = *in; | ||
| 808 | ret = asn1_check_tlen(NULL, &utype, &oclass, NULL, NULL, | ||
| 809 | &p, inlen, -1, 0, 0, ctx); | ||
| 810 | if (!ret) | ||
| 811 | { | ||
| 812 | ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, | ||
| 813 | ERR_R_NESTED_ASN1_ERROR); | ||
| 814 | return 0; | ||
| 815 | } | ||
| 816 | if (oclass != V_ASN1_UNIVERSAL) | ||
| 817 | utype = V_ASN1_OTHER; | ||
| 818 | } | ||
| 819 | if (tag == -1) | ||
| 820 | { | ||
| 821 | tag = utype; | ||
| 822 | aclass = V_ASN1_UNIVERSAL; | ||
| 823 | } | ||
| 824 | p = *in; | ||
| 825 | /* Check header */ | ||
| 826 | ret = asn1_check_tlen(&plen, NULL, NULL, &inf, &cst, | ||
| 827 | &p, inlen, tag, aclass, opt, ctx); | ||
| 828 | if (!ret) | ||
| 829 | { | ||
| 830 | ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ERR_R_NESTED_ASN1_ERROR); | ||
| 831 | return 0; | ||
| 832 | } | ||
| 833 | else if (ret == -1) | ||
| 834 | return -1; | ||
| 835 | ret = 0; | ||
| 836 | /* SEQUENCE, SET and "OTHER" are left in encoded form */ | ||
| 837 | if ((utype == V_ASN1_SEQUENCE) | ||
| 838 | || (utype == V_ASN1_SET) || (utype == V_ASN1_OTHER)) | ||
| 839 | { | ||
| 840 | /* Clear context cache for type OTHER because the auto clear | ||
| 841 | * when we have a exact match wont work | ||
| 842 | */ | ||
| 843 | if (utype == V_ASN1_OTHER) | ||
| 844 | { | ||
| 845 | asn1_tlc_clear(ctx); | ||
| 846 | } | ||
| 847 | /* SEQUENCE and SET must be constructed */ | ||
| 848 | else if (!cst) | ||
| 849 | { | ||
| 850 | ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, | ||
| 851 | ASN1_R_TYPE_NOT_CONSTRUCTED); | ||
| 852 | return 0; | ||
| 853 | } | ||
| 854 | |||
| 855 | cont = *in; | ||
| 856 | /* If indefinite length constructed find the real end */ | ||
| 857 | if (inf) | ||
| 858 | { | ||
| 859 | if (!asn1_find_end(&p, plen, inf)) | ||
| 860 | goto err; | ||
| 861 | len = p - cont; | ||
| 862 | } | ||
| 863 | else | ||
| 864 | { | ||
| 865 | len = p - cont + plen; | ||
| 866 | p += plen; | ||
| 867 | buf.data = NULL; | ||
| 868 | } | ||
| 869 | } | ||
| 870 | else if (cst) | ||
| 871 | { | ||
| 872 | buf.length = 0; | ||
| 873 | buf.max = 0; | ||
| 874 | buf.data = NULL; | ||
| 875 | /* Should really check the internal tags are correct but | ||
| 876 | * some things may get this wrong. The relevant specs | ||
| 877 | * say that constructed string types should be OCTET STRINGs | ||
| 878 | * internally irrespective of the type. So instead just check | ||
| 879 | * for UNIVERSAL class and ignore the tag. | ||
| 880 | */ | ||
| 881 | if (!asn1_collect(&buf, &p, plen, inf, -1, V_ASN1_UNIVERSAL)) | ||
| 882 | { | ||
| 883 | free_cont = 1; | ||
| 884 | goto err; | ||
| 885 | } | ||
| 886 | len = buf.length; | ||
| 887 | /* Append a final null to string */ | ||
| 888 | if (!BUF_MEM_grow_clean(&buf, len + 1)) | ||
| 889 | { | ||
| 890 | ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, | ||
| 891 | ERR_R_MALLOC_FAILURE); | ||
| 892 | return 0; | ||
| 893 | } | ||
| 894 | buf.data[len] = 0; | ||
| 895 | cont = (const unsigned char *)buf.data; | ||
| 896 | free_cont = 1; | ||
| 897 | } | ||
| 898 | else | ||
| 899 | { | ||
| 900 | cont = p; | ||
| 901 | len = plen; | ||
| 902 | p += plen; | ||
| 903 | } | ||
| 904 | |||
| 905 | /* We now have content length and type: translate into a structure */ | ||
| 906 | if (!asn1_ex_c2i(pval, cont, len, utype, &free_cont, it)) | ||
| 907 | goto err; | ||
| 908 | |||
| 909 | *in = p; | ||
| 910 | ret = 1; | ||
| 911 | err: | ||
| 912 | if (free_cont && buf.data) OPENSSL_free(buf.data); | ||
| 913 | return ret; | ||
| 914 | } | ||
| 915 | |||
| 916 | /* Translate ASN1 content octets into a structure */ | ||
| 917 | |||
| 918 | int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, | ||
| 919 | int utype, char *free_cont, const ASN1_ITEM *it) | ||
| 920 | { | ||
| 921 | ASN1_VALUE **opval = NULL; | ||
| 922 | ASN1_STRING *stmp; | ||
| 923 | ASN1_TYPE *typ = NULL; | ||
| 924 | int ret = 0; | ||
| 925 | const ASN1_PRIMITIVE_FUNCS *pf; | ||
| 926 | ASN1_INTEGER **tint; | ||
| 927 | pf = it->funcs; | ||
| 928 | |||
| 929 | if (pf && pf->prim_c2i) | ||
| 930 | return pf->prim_c2i(pval, cont, len, utype, free_cont, it); | ||
| 931 | /* If ANY type clear type and set pointer to internal value */ | ||
| 932 | if (it->utype == V_ASN1_ANY) | ||
| 933 | { | ||
| 934 | if (!*pval) | ||
| 935 | { | ||
| 936 | typ = ASN1_TYPE_new(); | ||
| 937 | if (typ == NULL) | ||
| 938 | goto err; | ||
| 939 | *pval = (ASN1_VALUE *)typ; | ||
| 940 | } | ||
| 941 | else | ||
| 942 | typ = (ASN1_TYPE *)*pval; | ||
| 943 | |||
| 944 | if (utype != typ->type) | ||
| 945 | ASN1_TYPE_set(typ, utype, NULL); | ||
| 946 | opval = pval; | ||
| 947 | pval = &typ->value.asn1_value; | ||
| 948 | } | ||
| 949 | switch(utype) | ||
| 950 | { | ||
| 951 | case V_ASN1_OBJECT: | ||
| 952 | if (!c2i_ASN1_OBJECT((ASN1_OBJECT **)pval, &cont, len)) | ||
| 953 | goto err; | ||
| 954 | break; | ||
| 955 | |||
| 956 | case V_ASN1_NULL: | ||
| 957 | if (len) | ||
| 958 | { | ||
| 959 | ASN1err(ASN1_F_ASN1_EX_C2I, | ||
| 960 | ASN1_R_NULL_IS_WRONG_LENGTH); | ||
| 961 | goto err; | ||
| 962 | } | ||
| 963 | *pval = (ASN1_VALUE *)1; | ||
| 964 | break; | ||
| 965 | |||
| 966 | case V_ASN1_BOOLEAN: | ||
| 967 | if (len != 1) | ||
| 968 | { | ||
| 969 | ASN1err(ASN1_F_ASN1_EX_C2I, | ||
| 970 | ASN1_R_BOOLEAN_IS_WRONG_LENGTH); | ||
| 971 | goto err; | ||
| 972 | } | ||
| 973 | else | ||
| 974 | { | ||
| 975 | ASN1_BOOLEAN *tbool; | ||
| 976 | tbool = (ASN1_BOOLEAN *)pval; | ||
| 977 | *tbool = *cont; | ||
| 978 | } | ||
| 979 | break; | ||
| 980 | |||
| 981 | case V_ASN1_BIT_STRING: | ||
| 982 | if (!c2i_ASN1_BIT_STRING((ASN1_BIT_STRING **)pval, &cont, len)) | ||
| 983 | goto err; | ||
| 984 | break; | ||
| 985 | |||
| 986 | case V_ASN1_INTEGER: | ||
| 987 | case V_ASN1_NEG_INTEGER: | ||
| 988 | case V_ASN1_ENUMERATED: | ||
| 989 | case V_ASN1_NEG_ENUMERATED: | ||
| 990 | tint = (ASN1_INTEGER **)pval; | ||
| 991 | if (!c2i_ASN1_INTEGER(tint, &cont, len)) | ||
| 992 | goto err; | ||
| 993 | /* Fixup type to match the expected form */ | ||
| 994 | (*tint)->type = utype | ((*tint)->type & V_ASN1_NEG); | ||
| 995 | break; | ||
| 996 | |||
| 997 | case V_ASN1_OCTET_STRING: | ||
| 998 | case V_ASN1_NUMERICSTRING: | ||
| 999 | case V_ASN1_PRINTABLESTRING: | ||
| 1000 | case V_ASN1_T61STRING: | ||
| 1001 | case V_ASN1_VIDEOTEXSTRING: | ||
| 1002 | case V_ASN1_IA5STRING: | ||
| 1003 | case V_ASN1_UTCTIME: | ||
| 1004 | case V_ASN1_GENERALIZEDTIME: | ||
| 1005 | case V_ASN1_GRAPHICSTRING: | ||
| 1006 | case V_ASN1_VISIBLESTRING: | ||
| 1007 | case V_ASN1_GENERALSTRING: | ||
| 1008 | case V_ASN1_UNIVERSALSTRING: | ||
| 1009 | case V_ASN1_BMPSTRING: | ||
| 1010 | case V_ASN1_UTF8STRING: | ||
| 1011 | case V_ASN1_OTHER: | ||
| 1012 | case V_ASN1_SET: | ||
| 1013 | case V_ASN1_SEQUENCE: | ||
| 1014 | default: | ||
| 1015 | /* All based on ASN1_STRING and handled the same */ | ||
| 1016 | if (!*pval) | ||
| 1017 | { | ||
| 1018 | stmp = ASN1_STRING_type_new(utype); | ||
| 1019 | if (!stmp) | ||
| 1020 | { | ||
| 1021 | ASN1err(ASN1_F_ASN1_EX_C2I, | ||
| 1022 | ERR_R_MALLOC_FAILURE); | ||
| 1023 | goto err; | ||
| 1024 | } | ||
| 1025 | *pval = (ASN1_VALUE *)stmp; | ||
| 1026 | } | ||
| 1027 | else | ||
| 1028 | { | ||
| 1029 | stmp = (ASN1_STRING *)*pval; | ||
| 1030 | stmp->type = utype; | ||
| 1031 | } | ||
| 1032 | /* If we've already allocated a buffer use it */ | ||
| 1033 | if (*free_cont) | ||
| 1034 | { | ||
| 1035 | if (stmp->data) | ||
| 1036 | OPENSSL_free(stmp->data); | ||
| 1037 | stmp->data = (unsigned char *)cont; /* UGLY CAST! RL */ | ||
| 1038 | stmp->length = len; | ||
| 1039 | *free_cont = 0; | ||
| 1040 | } | ||
| 1041 | else | ||
| 1042 | { | ||
| 1043 | if (!ASN1_STRING_set(stmp, cont, len)) | ||
| 1044 | { | ||
| 1045 | ASN1err(ASN1_F_ASN1_EX_C2I, | ||
| 1046 | ERR_R_MALLOC_FAILURE); | ||
| 1047 | ASN1_STRING_free(stmp); | ||
| 1048 | *pval = NULL; | ||
| 1049 | goto err; | ||
| 1050 | } | ||
| 1051 | } | ||
| 1052 | break; | ||
| 1053 | } | ||
| 1054 | /* If ASN1_ANY and NULL type fix up value */ | ||
| 1055 | if (typ && (utype == V_ASN1_NULL)) | ||
| 1056 | typ->value.ptr = NULL; | ||
| 1057 | |||
| 1058 | ret = 1; | ||
| 1059 | err: | ||
| 1060 | if (!ret) | ||
| 1061 | { | ||
| 1062 | ASN1_TYPE_free(typ); | ||
| 1063 | if (opval) | ||
| 1064 | *opval = NULL; | ||
| 1065 | } | ||
| 1066 | return ret; | ||
| 1067 | } | ||
| 1068 | |||
| 1069 | |||
| 1070 | /* This function finds the end of an ASN1 structure when passed its maximum | ||
| 1071 | * length, whether it is indefinite length and a pointer to the content. | ||
| 1072 | * This is more efficient than calling asn1_collect because it does not | ||
| 1073 | * recurse on each indefinite length header. | ||
| 1074 | */ | ||
| 1075 | |||
| 1076 | static int asn1_find_end(const unsigned char **in, long len, char inf) | ||
| 1077 | { | ||
| 1078 | int expected_eoc; | ||
| 1079 | long plen; | ||
| 1080 | const unsigned char *p = *in, *q; | ||
| 1081 | /* If not indefinite length constructed just add length */ | ||
| 1082 | if (inf == 0) | ||
| 1083 | { | ||
| 1084 | *in += len; | ||
| 1085 | return 1; | ||
| 1086 | } | ||
| 1087 | expected_eoc = 1; | ||
| 1088 | /* Indefinite length constructed form. Find the end when enough EOCs | ||
| 1089 | * are found. If more indefinite length constructed headers | ||
| 1090 | * are encountered increment the expected eoc count otherwise just | ||
| 1091 | * skip to the end of the data. | ||
| 1092 | */ | ||
| 1093 | while (len > 0) | ||
| 1094 | { | ||
| 1095 | if(asn1_check_eoc(&p, len)) | ||
| 1096 | { | ||
| 1097 | expected_eoc--; | ||
| 1098 | if (expected_eoc == 0) | ||
| 1099 | break; | ||
| 1100 | len -= 2; | ||
| 1101 | continue; | ||
| 1102 | } | ||
| 1103 | q = p; | ||
| 1104 | /* Just read in a header: only care about the length */ | ||
| 1105 | if(!asn1_check_tlen(&plen, NULL, NULL, &inf, NULL, &p, len, | ||
| 1106 | -1, 0, 0, NULL)) | ||
| 1107 | { | ||
| 1108 | ASN1err(ASN1_F_ASN1_FIND_END, ERR_R_NESTED_ASN1_ERROR); | ||
| 1109 | return 0; | ||
| 1110 | } | ||
| 1111 | if (inf) | ||
| 1112 | expected_eoc++; | ||
| 1113 | else | ||
| 1114 | p += plen; | ||
| 1115 | len -= p - q; | ||
| 1116 | } | ||
| 1117 | if (expected_eoc) | ||
| 1118 | { | ||
| 1119 | ASN1err(ASN1_F_ASN1_FIND_END, ASN1_R_MISSING_EOC); | ||
| 1120 | return 0; | ||
| 1121 | } | ||
| 1122 | *in = p; | ||
| 1123 | return 1; | ||
| 1124 | } | ||
| 1125 | /* This function collects the asn1 data from a constructred string | ||
| 1126 | * type into a buffer. The values of 'in' and 'len' should refer | ||
| 1127 | * to the contents of the constructed type and 'inf' should be set | ||
| 1128 | * if it is indefinite length. | ||
| 1129 | */ | ||
| 1130 | |||
| 1131 | static int asn1_collect(BUF_MEM *buf, const unsigned char **in, long len, | ||
| 1132 | char inf, int tag, int aclass) | ||
| 1133 | { | ||
| 1134 | const unsigned char *p, *q; | ||
| 1135 | long plen; | ||
| 1136 | char cst, ininf; | ||
| 1137 | p = *in; | ||
| 1138 | inf &= 1; | ||
| 1139 | /* If no buffer and not indefinite length constructed just pass over | ||
| 1140 | * the encoded data */ | ||
| 1141 | if (!buf && !inf) | ||
| 1142 | { | ||
| 1143 | *in += len; | ||
| 1144 | return 1; | ||
| 1145 | } | ||
| 1146 | while(len > 0) | ||
| 1147 | { | ||
| 1148 | q = p; | ||
| 1149 | /* Check for EOC */ | ||
| 1150 | if (asn1_check_eoc(&p, len)) | ||
| 1151 | { | ||
| 1152 | /* EOC is illegal outside indefinite length | ||
| 1153 | * constructed form */ | ||
| 1154 | if (!inf) | ||
| 1155 | { | ||
| 1156 | ASN1err(ASN1_F_ASN1_COLLECT, | ||
| 1157 | ASN1_R_UNEXPECTED_EOC); | ||
| 1158 | return 0; | ||
| 1159 | } | ||
| 1160 | inf = 0; | ||
| 1161 | break; | ||
| 1162 | } | ||
| 1163 | |||
| 1164 | if (!asn1_check_tlen(&plen, NULL, NULL, &ininf, &cst, &p, | ||
| 1165 | len, tag, aclass, 0, NULL)) | ||
| 1166 | { | ||
| 1167 | ASN1err(ASN1_F_ASN1_COLLECT, ERR_R_NESTED_ASN1_ERROR); | ||
| 1168 | return 0; | ||
| 1169 | } | ||
| 1170 | |||
| 1171 | /* If indefinite length constructed update max length */ | ||
| 1172 | if (cst) | ||
| 1173 | { | ||
| 1174 | #ifdef OPENSSL_ALLOW_NESTED_ASN1_STRINGS | ||
| 1175 | if (!asn1_collect(buf, &p, plen, ininf, tag, aclass)) | ||
| 1176 | return 0; | ||
| 1177 | #else | ||
| 1178 | ASN1err(ASN1_F_ASN1_COLLECT, ASN1_R_NESTED_ASN1_STRING); | ||
| 1179 | return 0; | ||
| 1180 | #endif | ||
| 1181 | } | ||
| 1182 | else if (plen && !collect_data(buf, &p, plen)) | ||
| 1183 | return 0; | ||
| 1184 | len -= p - q; | ||
| 1185 | } | ||
| 1186 | if (inf) | ||
| 1187 | { | ||
| 1188 | ASN1err(ASN1_F_ASN1_COLLECT, ASN1_R_MISSING_EOC); | ||
| 1189 | return 0; | ||
| 1190 | } | ||
| 1191 | *in = p; | ||
| 1192 | return 1; | ||
| 1193 | } | ||
| 1194 | |||
| 1195 | static int collect_data(BUF_MEM *buf, const unsigned char **p, long plen) | ||
| 1196 | { | ||
| 1197 | int len; | ||
| 1198 | if (buf) | ||
| 1199 | { | ||
| 1200 | len = buf->length; | ||
| 1201 | if (!BUF_MEM_grow_clean(buf, len + plen)) | ||
| 1202 | { | ||
| 1203 | ASN1err(ASN1_F_COLLECT_DATA, ERR_R_MALLOC_FAILURE); | ||
| 1204 | return 0; | ||
| 1205 | } | ||
| 1206 | memcpy(buf->data + len, *p, plen); | ||
| 1207 | } | ||
| 1208 | *p += plen; | ||
| 1209 | return 1; | ||
| 1210 | } | ||
| 1211 | |||
| 1212 | /* Check for ASN1 EOC and swallow it if found */ | ||
| 1213 | |||
| 1214 | static int asn1_check_eoc(const unsigned char **in, long len) | ||
| 1215 | { | ||
| 1216 | const unsigned char *p; | ||
| 1217 | if (len < 2) return 0; | ||
| 1218 | p = *in; | ||
| 1219 | if (!p[0] && !p[1]) | ||
| 1220 | { | ||
| 1221 | *in += 2; | ||
| 1222 | return 1; | ||
| 1223 | } | ||
| 1224 | return 0; | ||
| 1225 | } | ||
| 1226 | |||
| 1227 | /* Check an ASN1 tag and length: a bit like ASN1_get_object | ||
| 1228 | * but it sets the length for indefinite length constructed | ||
| 1229 | * form, we don't know the exact length but we can set an | ||
| 1230 | * upper bound to the amount of data available minus the | ||
| 1231 | * header length just read. | ||
| 1232 | */ | ||
| 1233 | |||
| 1234 | static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass, | ||
| 1235 | char *inf, char *cst, | ||
| 1236 | const unsigned char **in, long len, | ||
| 1237 | int exptag, int expclass, char opt, | ||
| 1238 | ASN1_TLC *ctx) | ||
| 1239 | { | ||
| 1240 | int i; | ||
| 1241 | int ptag, pclass; | ||
| 1242 | long plen; | ||
| 1243 | const unsigned char *p, *q; | ||
| 1244 | p = *in; | ||
| 1245 | q = p; | ||
| 1246 | |||
| 1247 | if (ctx && ctx->valid) | ||
| 1248 | { | ||
| 1249 | i = ctx->ret; | ||
| 1250 | plen = ctx->plen; | ||
| 1251 | pclass = ctx->pclass; | ||
| 1252 | ptag = ctx->ptag; | ||
| 1253 | p += ctx->hdrlen; | ||
| 1254 | } | ||
| 1255 | else | ||
| 1256 | { | ||
| 1257 | i = ASN1_get_object(&p, &plen, &ptag, &pclass, len); | ||
| 1258 | if (ctx) | ||
| 1259 | { | ||
| 1260 | ctx->ret = i; | ||
| 1261 | ctx->plen = plen; | ||
| 1262 | ctx->pclass = pclass; | ||
| 1263 | ctx->ptag = ptag; | ||
| 1264 | ctx->hdrlen = p - q; | ||
| 1265 | ctx->valid = 1; | ||
| 1266 | /* If definite length, and no error, length + | ||
| 1267 | * header can't exceed total amount of data available. | ||
| 1268 | */ | ||
| 1269 | if (!(i & 0x81) && ((plen + ctx->hdrlen) > len)) | ||
| 1270 | { | ||
| 1271 | ASN1err(ASN1_F_ASN1_CHECK_TLEN, | ||
| 1272 | ASN1_R_TOO_LONG); | ||
| 1273 | asn1_tlc_clear(ctx); | ||
| 1274 | return 0; | ||
| 1275 | } | ||
| 1276 | } | ||
| 1277 | } | ||
| 1278 | |||
| 1279 | if (i & 0x80) | ||
| 1280 | { | ||
| 1281 | ASN1err(ASN1_F_ASN1_CHECK_TLEN, ASN1_R_BAD_OBJECT_HEADER); | ||
| 1282 | asn1_tlc_clear(ctx); | ||
| 1283 | return 0; | ||
| 1284 | } | ||
| 1285 | if (exptag >= 0) | ||
| 1286 | { | ||
| 1287 | if ((exptag != ptag) || (expclass != pclass)) | ||
| 1288 | { | ||
| 1289 | /* If type is OPTIONAL, not an error: | ||
| 1290 | * indicate missing type. | ||
| 1291 | */ | ||
| 1292 | if (opt) return -1; | ||
| 1293 | asn1_tlc_clear(ctx); | ||
| 1294 | ASN1err(ASN1_F_ASN1_CHECK_TLEN, ASN1_R_WRONG_TAG); | ||
| 1295 | return 0; | ||
| 1296 | } | ||
| 1297 | /* We have a tag and class match: | ||
| 1298 | * assume we are going to do something with it */ | ||
| 1299 | asn1_tlc_clear(ctx); | ||
| 1300 | } | ||
| 1301 | |||
| 1302 | if (i & 1) | ||
| 1303 | plen = len - (p - q); | ||
| 1304 | |||
| 1305 | if (inf) | ||
| 1306 | *inf = i & 1; | ||
| 1307 | |||
| 1308 | if (cst) | ||
| 1309 | *cst = i & V_ASN1_CONSTRUCTED; | ||
| 1310 | |||
| 1311 | if (olen) | ||
| 1312 | *olen = plen; | ||
| 1313 | |||
| 1314 | if (oclass) | ||
| 1315 | *oclass = pclass; | ||
| 1316 | |||
| 1317 | if (otag) | ||
| 1318 | *otag = ptag; | ||
| 1319 | |||
| 1320 | *in = p; | ||
| 1321 | return 1; | ||
| 1322 | } | ||
diff --git a/src/lib/libcrypto/asn1/tasn_enc.c b/src/lib/libcrypto/asn1/tasn_enc.c new file mode 100644 index 0000000000..be19b36acd --- /dev/null +++ b/src/lib/libcrypto/asn1/tasn_enc.c | |||
| @@ -0,0 +1,690 @@ | |||
| 1 | /* tasn_enc.c */ | ||
| 2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
| 3 | * project 2000. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 2000-2004 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | |||
| 60 | #include <stddef.h> | ||
| 61 | #include <string.h> | ||
| 62 | #include "cryptlib.h" | ||
| 63 | #include <openssl/asn1.h> | ||
| 64 | #include <openssl/asn1t.h> | ||
| 65 | #include <openssl/objects.h> | ||
| 66 | |||
| 67 | static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out, | ||
| 68 | const ASN1_ITEM *it, | ||
| 69 | int tag, int aclass); | ||
| 70 | static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out, | ||
| 71 | int skcontlen, const ASN1_ITEM *item, | ||
| 72 | int do_sort, int iclass); | ||
| 73 | static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out, | ||
| 74 | const ASN1_TEMPLATE *tt, | ||
| 75 | int tag, int aclass); | ||
| 76 | static int asn1_item_flags_i2d(ASN1_VALUE *val, unsigned char **out, | ||
| 77 | const ASN1_ITEM *it, int flags); | ||
| 78 | |||
| 79 | /* Top level i2d equivalents: the 'ndef' variant instructs the encoder | ||
| 80 | * to use indefinite length constructed encoding, where appropriate | ||
| 81 | */ | ||
| 82 | |||
| 83 | int ASN1_item_ndef_i2d(ASN1_VALUE *val, unsigned char **out, | ||
| 84 | const ASN1_ITEM *it) | ||
| 85 | { | ||
| 86 | return asn1_item_flags_i2d(val, out, it, ASN1_TFLG_NDEF); | ||
| 87 | } | ||
| 88 | |||
| 89 | int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it) | ||
| 90 | { | ||
| 91 | return asn1_item_flags_i2d(val, out, it, 0); | ||
| 92 | } | ||
| 93 | |||
| 94 | /* Encode an ASN1 item, this is use by the | ||
| 95 | * standard 'i2d' function. 'out' points to | ||
| 96 | * a buffer to output the data to. | ||
| 97 | * | ||
| 98 | * The new i2d has one additional feature. If the output | ||
| 99 | * buffer is NULL (i.e. *out == NULL) then a buffer is | ||
| 100 | * allocated and populated with the encoding. | ||
| 101 | */ | ||
| 102 | |||
| 103 | static int asn1_item_flags_i2d(ASN1_VALUE *val, unsigned char **out, | ||
| 104 | const ASN1_ITEM *it, int flags) | ||
| 105 | { | ||
| 106 | if (out && !*out) | ||
| 107 | { | ||
| 108 | unsigned char *p, *buf; | ||
| 109 | int len; | ||
| 110 | len = ASN1_item_ex_i2d(&val, NULL, it, -1, flags); | ||
| 111 | if (len <= 0) | ||
| 112 | return len; | ||
| 113 | buf = OPENSSL_malloc(len); | ||
| 114 | if (!buf) | ||
| 115 | return -1; | ||
| 116 | p = buf; | ||
| 117 | ASN1_item_ex_i2d(&val, &p, it, -1, flags); | ||
| 118 | *out = buf; | ||
| 119 | return len; | ||
| 120 | } | ||
| 121 | |||
| 122 | return ASN1_item_ex_i2d(&val, out, it, -1, flags); | ||
| 123 | } | ||
| 124 | |||
| 125 | /* Encode an item, taking care of IMPLICIT tagging (if any). | ||
| 126 | * This function performs the normal item handling: it can be | ||
| 127 | * used in external types. | ||
| 128 | */ | ||
| 129 | |||
| 130 | int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, | ||
| 131 | const ASN1_ITEM *it, int tag, int aclass) | ||
| 132 | { | ||
| 133 | const ASN1_TEMPLATE *tt = NULL; | ||
| 134 | unsigned char *p = NULL; | ||
| 135 | int i, seqcontlen, seqlen, ndef = 1; | ||
| 136 | const ASN1_COMPAT_FUNCS *cf; | ||
| 137 | const ASN1_EXTERN_FUNCS *ef; | ||
| 138 | const ASN1_AUX *aux = it->funcs; | ||
| 139 | ASN1_aux_cb *asn1_cb = 0; | ||
| 140 | |||
| 141 | if ((it->itype != ASN1_ITYPE_PRIMITIVE) && !*pval) | ||
| 142 | return 0; | ||
| 143 | |||
| 144 | if (aux && aux->asn1_cb) | ||
| 145 | asn1_cb = aux->asn1_cb; | ||
| 146 | |||
| 147 | switch(it->itype) | ||
| 148 | { | ||
| 149 | |||
| 150 | case ASN1_ITYPE_PRIMITIVE: | ||
| 151 | if (it->templates) | ||
| 152 | return asn1_template_ex_i2d(pval, out, it->templates, | ||
| 153 | tag, aclass); | ||
| 154 | return asn1_i2d_ex_primitive(pval, out, it, tag, aclass); | ||
| 155 | break; | ||
| 156 | |||
| 157 | case ASN1_ITYPE_MSTRING: | ||
| 158 | return asn1_i2d_ex_primitive(pval, out, it, -1, aclass); | ||
| 159 | |||
| 160 | case ASN1_ITYPE_CHOICE: | ||
| 161 | if (asn1_cb && !asn1_cb(ASN1_OP_I2D_PRE, pval, it)) | ||
| 162 | return 0; | ||
| 163 | i = asn1_get_choice_selector(pval, it); | ||
| 164 | if ((i >= 0) && (i < it->tcount)) | ||
| 165 | { | ||
| 166 | ASN1_VALUE **pchval; | ||
| 167 | const ASN1_TEMPLATE *chtt; | ||
| 168 | chtt = it->templates + i; | ||
| 169 | pchval = asn1_get_field_ptr(pval, chtt); | ||
| 170 | return asn1_template_ex_i2d(pchval, out, chtt, | ||
| 171 | -1, aclass); | ||
| 172 | } | ||
| 173 | /* Fixme: error condition if selector out of range */ | ||
| 174 | if (asn1_cb && !asn1_cb(ASN1_OP_I2D_POST, pval, it)) | ||
| 175 | return 0; | ||
| 176 | break; | ||
| 177 | |||
| 178 | case ASN1_ITYPE_EXTERN: | ||
| 179 | /* If new style i2d it does all the work */ | ||
| 180 | ef = it->funcs; | ||
| 181 | return ef->asn1_ex_i2d(pval, out, it, tag, aclass); | ||
| 182 | |||
| 183 | case ASN1_ITYPE_COMPAT: | ||
| 184 | /* old style hackery... */ | ||
| 185 | cf = it->funcs; | ||
| 186 | if (out) | ||
| 187 | p = *out; | ||
| 188 | i = cf->asn1_i2d(*pval, out); | ||
| 189 | /* Fixup for IMPLICIT tag: note this messes up for tags > 30, | ||
| 190 | * but so did the old code. Tags > 30 are very rare anyway. | ||
| 191 | */ | ||
| 192 | if (out && (tag != -1)) | ||
| 193 | *p = aclass | tag | (*p & V_ASN1_CONSTRUCTED); | ||
| 194 | return i; | ||
| 195 | |||
| 196 | case ASN1_ITYPE_NDEF_SEQUENCE: | ||
| 197 | /* Use indefinite length constructed if requested */ | ||
| 198 | if (aclass & ASN1_TFLG_NDEF) ndef = 2; | ||
| 199 | /* fall through */ | ||
| 200 | |||
| 201 | case ASN1_ITYPE_SEQUENCE: | ||
| 202 | i = asn1_enc_restore(&seqcontlen, out, pval, it); | ||
| 203 | /* An error occurred */ | ||
| 204 | if (i < 0) | ||
| 205 | return 0; | ||
| 206 | /* We have a valid cached encoding... */ | ||
| 207 | if (i > 0) | ||
| 208 | return seqcontlen; | ||
| 209 | /* Otherwise carry on */ | ||
| 210 | seqcontlen = 0; | ||
| 211 | /* If no IMPLICIT tagging set to SEQUENCE, UNIVERSAL */ | ||
| 212 | if (tag == -1) | ||
| 213 | { | ||
| 214 | tag = V_ASN1_SEQUENCE; | ||
| 215 | /* Retain any other flags in aclass */ | ||
| 216 | aclass = (aclass & ~ASN1_TFLG_TAG_CLASS) | ||
| 217 | | V_ASN1_UNIVERSAL; | ||
| 218 | } | ||
| 219 | if (asn1_cb && !asn1_cb(ASN1_OP_I2D_PRE, pval, it)) | ||
| 220 | return 0; | ||
| 221 | /* First work out sequence content length */ | ||
| 222 | for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) | ||
| 223 | { | ||
| 224 | const ASN1_TEMPLATE *seqtt; | ||
| 225 | ASN1_VALUE **pseqval; | ||
| 226 | seqtt = asn1_do_adb(pval, tt, 1); | ||
| 227 | if (!seqtt) | ||
| 228 | return 0; | ||
| 229 | pseqval = asn1_get_field_ptr(pval, seqtt); | ||
| 230 | /* FIXME: check for errors in enhanced version */ | ||
| 231 | seqcontlen += asn1_template_ex_i2d(pseqval, NULL, seqtt, | ||
| 232 | -1, aclass); | ||
| 233 | } | ||
| 234 | |||
| 235 | seqlen = ASN1_object_size(ndef, seqcontlen, tag); | ||
| 236 | if (!out) | ||
| 237 | return seqlen; | ||
| 238 | /* Output SEQUENCE header */ | ||
| 239 | ASN1_put_object(out, ndef, seqcontlen, tag, aclass); | ||
| 240 | for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) | ||
| 241 | { | ||
| 242 | const ASN1_TEMPLATE *seqtt; | ||
| 243 | ASN1_VALUE **pseqval; | ||
| 244 | seqtt = asn1_do_adb(pval, tt, 1); | ||
| 245 | if (!seqtt) | ||
| 246 | return 0; | ||
| 247 | pseqval = asn1_get_field_ptr(pval, seqtt); | ||
| 248 | /* FIXME: check for errors in enhanced version */ | ||
| 249 | asn1_template_ex_i2d(pseqval, out, seqtt, -1, aclass); | ||
| 250 | } | ||
| 251 | if (ndef == 2) | ||
| 252 | ASN1_put_eoc(out); | ||
| 253 | if (asn1_cb && !asn1_cb(ASN1_OP_I2D_POST, pval, it)) | ||
| 254 | return 0; | ||
| 255 | return seqlen; | ||
| 256 | |||
| 257 | default: | ||
| 258 | return 0; | ||
| 259 | |||
| 260 | } | ||
| 261 | return 0; | ||
| 262 | } | ||
| 263 | |||
| 264 | int ASN1_template_i2d(ASN1_VALUE **pval, unsigned char **out, | ||
| 265 | const ASN1_TEMPLATE *tt) | ||
| 266 | { | ||
| 267 | return asn1_template_ex_i2d(pval, out, tt, -1, 0); | ||
| 268 | } | ||
| 269 | |||
| 270 | static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out, | ||
| 271 | const ASN1_TEMPLATE *tt, int tag, int iclass) | ||
| 272 | { | ||
| 273 | int i, ret, flags, ttag, tclass, ndef; | ||
| 274 | flags = tt->flags; | ||
| 275 | /* Work out tag and class to use: tagging may come | ||
| 276 | * either from the template or the arguments, not both | ||
| 277 | * because this would create ambiguity. Additionally | ||
| 278 | * the iclass argument may contain some additional flags | ||
| 279 | * which should be noted and passed down to other levels. | ||
| 280 | */ | ||
| 281 | if (flags & ASN1_TFLG_TAG_MASK) | ||
| 282 | { | ||
| 283 | /* Error if argument and template tagging */ | ||
| 284 | if (tag != -1) | ||
| 285 | /* FIXME: error code here */ | ||
| 286 | return -1; | ||
| 287 | /* Get tagging from template */ | ||
| 288 | ttag = tt->tag; | ||
| 289 | tclass = flags & ASN1_TFLG_TAG_CLASS; | ||
| 290 | } | ||
| 291 | else if (tag != -1) | ||
| 292 | { | ||
| 293 | /* No template tagging, get from arguments */ | ||
| 294 | ttag = tag; | ||
| 295 | tclass = iclass & ASN1_TFLG_TAG_CLASS; | ||
| 296 | } | ||
| 297 | else | ||
| 298 | { | ||
| 299 | ttag = -1; | ||
| 300 | tclass = 0; | ||
| 301 | } | ||
| 302 | /* | ||
| 303 | * Remove any class mask from iflag. | ||
| 304 | */ | ||
| 305 | iclass &= ~ASN1_TFLG_TAG_CLASS; | ||
| 306 | |||
| 307 | /* At this point 'ttag' contains the outer tag to use, | ||
| 308 | * 'tclass' is the class and iclass is any flags passed | ||
| 309 | * to this function. | ||
| 310 | */ | ||
| 311 | |||
| 312 | /* if template and arguments require ndef, use it */ | ||
| 313 | if ((flags & ASN1_TFLG_NDEF) && (iclass & ASN1_TFLG_NDEF)) | ||
| 314 | ndef = 2; | ||
| 315 | else ndef = 1; | ||
| 316 | |||
| 317 | if (flags & ASN1_TFLG_SK_MASK) | ||
| 318 | { | ||
| 319 | /* SET OF, SEQUENCE OF */ | ||
| 320 | STACK_OF(ASN1_VALUE) *sk = (STACK_OF(ASN1_VALUE) *)*pval; | ||
| 321 | int isset, sktag, skaclass; | ||
| 322 | int skcontlen, sklen; | ||
| 323 | ASN1_VALUE *skitem; | ||
| 324 | |||
| 325 | if (!*pval) | ||
| 326 | return 0; | ||
| 327 | |||
| 328 | if (flags & ASN1_TFLG_SET_OF) | ||
| 329 | { | ||
| 330 | isset = 1; | ||
| 331 | /* 2 means we reorder */ | ||
| 332 | if (flags & ASN1_TFLG_SEQUENCE_OF) | ||
| 333 | isset = 2; | ||
| 334 | } | ||
| 335 | else isset = 0; | ||
| 336 | |||
| 337 | /* Work out inner tag value: if EXPLICIT | ||
| 338 | * or no tagging use underlying type. | ||
| 339 | */ | ||
| 340 | if ((ttag != -1) && !(flags & ASN1_TFLG_EXPTAG)) | ||
| 341 | { | ||
| 342 | sktag = ttag; | ||
| 343 | skaclass = tclass; | ||
| 344 | } | ||
| 345 | else | ||
| 346 | { | ||
| 347 | skaclass = V_ASN1_UNIVERSAL; | ||
| 348 | if (isset) | ||
| 349 | sktag = V_ASN1_SET; | ||
| 350 | else sktag = V_ASN1_SEQUENCE; | ||
| 351 | } | ||
| 352 | |||
| 353 | /* Determine total length of items */ | ||
| 354 | skcontlen = 0; | ||
| 355 | for (i = 0; i < sk_ASN1_VALUE_num(sk); i++) | ||
| 356 | { | ||
| 357 | skitem = sk_ASN1_VALUE_value(sk, i); | ||
| 358 | skcontlen += ASN1_item_ex_i2d(&skitem, NULL, | ||
| 359 | ASN1_ITEM_ptr(tt->item), | ||
| 360 | -1, iclass); | ||
| 361 | } | ||
| 362 | sklen = ASN1_object_size(ndef, skcontlen, sktag); | ||
| 363 | /* If EXPLICIT need length of surrounding tag */ | ||
| 364 | if (flags & ASN1_TFLG_EXPTAG) | ||
| 365 | ret = ASN1_object_size(ndef, sklen, ttag); | ||
| 366 | else ret = sklen; | ||
| 367 | |||
| 368 | if (!out) | ||
| 369 | return ret; | ||
| 370 | |||
| 371 | /* Now encode this lot... */ | ||
| 372 | /* EXPLICIT tag */ | ||
| 373 | if (flags & ASN1_TFLG_EXPTAG) | ||
| 374 | ASN1_put_object(out, ndef, sklen, ttag, tclass); | ||
| 375 | /* SET or SEQUENCE and IMPLICIT tag */ | ||
| 376 | ASN1_put_object(out, ndef, skcontlen, sktag, skaclass); | ||
| 377 | /* And the stuff itself */ | ||
| 378 | asn1_set_seq_out(sk, out, skcontlen, ASN1_ITEM_ptr(tt->item), | ||
| 379 | isset, iclass); | ||
| 380 | if (ndef == 2) | ||
| 381 | { | ||
| 382 | ASN1_put_eoc(out); | ||
| 383 | if (flags & ASN1_TFLG_EXPTAG) | ||
| 384 | ASN1_put_eoc(out); | ||
| 385 | } | ||
| 386 | |||
| 387 | return ret; | ||
| 388 | } | ||
| 389 | |||
| 390 | if (flags & ASN1_TFLG_EXPTAG) | ||
| 391 | { | ||
| 392 | /* EXPLICIT tagging */ | ||
| 393 | /* Find length of tagged item */ | ||
| 394 | i = ASN1_item_ex_i2d(pval, NULL, ASN1_ITEM_ptr(tt->item), | ||
| 395 | -1, iclass); | ||
| 396 | if (!i) | ||
| 397 | return 0; | ||
| 398 | /* Find length of EXPLICIT tag */ | ||
| 399 | ret = ASN1_object_size(ndef, i, ttag); | ||
| 400 | if (out) | ||
| 401 | { | ||
| 402 | /* Output tag and item */ | ||
| 403 | ASN1_put_object(out, ndef, i, ttag, tclass); | ||
| 404 | ASN1_item_ex_i2d(pval, out, ASN1_ITEM_ptr(tt->item), | ||
| 405 | -1, iclass); | ||
| 406 | if (ndef == 2) | ||
| 407 | ASN1_put_eoc(out); | ||
| 408 | } | ||
| 409 | return ret; | ||
| 410 | } | ||
| 411 | |||
| 412 | /* Either normal or IMPLICIT tagging: combine class and flags */ | ||
| 413 | return ASN1_item_ex_i2d(pval, out, ASN1_ITEM_ptr(tt->item), | ||
| 414 | ttag, tclass | iclass); | ||
| 415 | |||
| 416 | } | ||
| 417 | |||
| 418 | /* Temporary structure used to hold DER encoding of items for SET OF */ | ||
| 419 | |||
| 420 | typedef struct { | ||
| 421 | unsigned char *data; | ||
| 422 | int length; | ||
| 423 | ASN1_VALUE *field; | ||
| 424 | } DER_ENC; | ||
| 425 | |||
| 426 | static int der_cmp(const void *a, const void *b) | ||
| 427 | { | ||
| 428 | const DER_ENC *d1 = a, *d2 = b; | ||
| 429 | int cmplen, i; | ||
| 430 | cmplen = (d1->length < d2->length) ? d1->length : d2->length; | ||
| 431 | i = memcmp(d1->data, d2->data, cmplen); | ||
| 432 | if (i) | ||
| 433 | return i; | ||
| 434 | return d1->length - d2->length; | ||
| 435 | } | ||
| 436 | |||
| 437 | /* Output the content octets of SET OF or SEQUENCE OF */ | ||
| 438 | |||
| 439 | static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out, | ||
| 440 | int skcontlen, const ASN1_ITEM *item, | ||
| 441 | int do_sort, int iclass) | ||
| 442 | { | ||
| 443 | int i; | ||
| 444 | ASN1_VALUE *skitem; | ||
| 445 | unsigned char *tmpdat = NULL, *p = NULL; | ||
| 446 | DER_ENC *derlst = NULL, *tder; | ||
| 447 | if (do_sort) | ||
| 448 | { | ||
| 449 | /* Don't need to sort less than 2 items */ | ||
| 450 | if (sk_ASN1_VALUE_num(sk) < 2) | ||
| 451 | do_sort = 0; | ||
| 452 | else | ||
| 453 | { | ||
| 454 | derlst = OPENSSL_malloc(sk_ASN1_VALUE_num(sk) | ||
| 455 | * sizeof(*derlst)); | ||
| 456 | tmpdat = OPENSSL_malloc(skcontlen); | ||
| 457 | if (!derlst || !tmpdat) | ||
| 458 | return 0; | ||
| 459 | } | ||
| 460 | } | ||
| 461 | /* If not sorting just output each item */ | ||
| 462 | if (!do_sort) | ||
| 463 | { | ||
| 464 | for (i = 0; i < sk_ASN1_VALUE_num(sk); i++) | ||
| 465 | { | ||
| 466 | skitem = sk_ASN1_VALUE_value(sk, i); | ||
| 467 | ASN1_item_ex_i2d(&skitem, out, item, -1, iclass); | ||
| 468 | } | ||
| 469 | return 1; | ||
| 470 | } | ||
| 471 | p = tmpdat; | ||
| 472 | |||
| 473 | /* Doing sort: build up a list of each member's DER encoding */ | ||
| 474 | for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++) | ||
| 475 | { | ||
| 476 | skitem = sk_ASN1_VALUE_value(sk, i); | ||
| 477 | tder->data = p; | ||
| 478 | tder->length = ASN1_item_ex_i2d(&skitem, &p, item, -1, iclass); | ||
| 479 | tder->field = skitem; | ||
| 480 | } | ||
| 481 | |||
| 482 | /* Now sort them */ | ||
| 483 | qsort(derlst, sk_ASN1_VALUE_num(sk), sizeof(*derlst), der_cmp); | ||
| 484 | /* Output sorted DER encoding */ | ||
| 485 | p = *out; | ||
| 486 | for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++) | ||
| 487 | { | ||
| 488 | memcpy(p, tder->data, tder->length); | ||
| 489 | p += tder->length; | ||
| 490 | } | ||
| 491 | *out = p; | ||
| 492 | /* If do_sort is 2 then reorder the STACK */ | ||
| 493 | if (do_sort == 2) | ||
| 494 | { | ||
| 495 | for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); | ||
| 496 | i++, tder++) | ||
| 497 | (void)sk_ASN1_VALUE_set(sk, i, tder->field); | ||
| 498 | } | ||
| 499 | OPENSSL_free(derlst); | ||
| 500 | OPENSSL_free(tmpdat); | ||
| 501 | return 1; | ||
| 502 | } | ||
| 503 | |||
| 504 | static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out, | ||
| 505 | const ASN1_ITEM *it, int tag, int aclass) | ||
| 506 | { | ||
| 507 | int len; | ||
| 508 | int utype; | ||
| 509 | int usetag; | ||
| 510 | int ndef = 0; | ||
| 511 | |||
| 512 | utype = it->utype; | ||
| 513 | |||
| 514 | /* Get length of content octets and maybe find | ||
| 515 | * out the underlying type. | ||
| 516 | */ | ||
| 517 | |||
| 518 | len = asn1_ex_i2c(pval, NULL, &utype, it); | ||
| 519 | |||
| 520 | /* If SEQUENCE, SET or OTHER then header is | ||
| 521 | * included in pseudo content octets so don't | ||
| 522 | * include tag+length. We need to check here | ||
| 523 | * because the call to asn1_ex_i2c() could change | ||
| 524 | * utype. | ||
| 525 | */ | ||
| 526 | if ((utype == V_ASN1_SEQUENCE) || (utype == V_ASN1_SET) || | ||
| 527 | (utype == V_ASN1_OTHER)) | ||
| 528 | usetag = 0; | ||
| 529 | else usetag = 1; | ||
| 530 | |||
| 531 | /* -1 means omit type */ | ||
| 532 | |||
| 533 | if (len == -1) | ||
| 534 | return 0; | ||
| 535 | |||
| 536 | /* -2 return is special meaning use ndef */ | ||
| 537 | if (len == -2) | ||
| 538 | { | ||
| 539 | ndef = 2; | ||
| 540 | len = 0; | ||
| 541 | } | ||
| 542 | |||
| 543 | /* If not implicitly tagged get tag from underlying type */ | ||
| 544 | if (tag == -1) tag = utype; | ||
| 545 | |||
| 546 | /* Output tag+length followed by content octets */ | ||
| 547 | if (out) | ||
| 548 | { | ||
| 549 | if (usetag) | ||
| 550 | ASN1_put_object(out, ndef, len, tag, aclass); | ||
| 551 | asn1_ex_i2c(pval, *out, &utype, it); | ||
| 552 | if (ndef) | ||
| 553 | ASN1_put_eoc(out); | ||
| 554 | else | ||
| 555 | *out += len; | ||
| 556 | } | ||
| 557 | |||
| 558 | if (usetag) | ||
| 559 | return ASN1_object_size(ndef, len, tag); | ||
| 560 | return len; | ||
| 561 | } | ||
| 562 | |||
| 563 | /* Produce content octets from a structure */ | ||
| 564 | |||
| 565 | int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype, | ||
| 566 | const ASN1_ITEM *it) | ||
| 567 | { | ||
| 568 | ASN1_BOOLEAN *tbool = NULL; | ||
| 569 | ASN1_STRING *strtmp; | ||
| 570 | ASN1_OBJECT *otmp; | ||
| 571 | int utype; | ||
| 572 | unsigned char *cont, c; | ||
| 573 | int len; | ||
| 574 | const ASN1_PRIMITIVE_FUNCS *pf; | ||
| 575 | pf = it->funcs; | ||
| 576 | if (pf && pf->prim_i2c) | ||
| 577 | return pf->prim_i2c(pval, cout, putype, it); | ||
| 578 | |||
| 579 | /* Should type be omitted? */ | ||
| 580 | if ((it->itype != ASN1_ITYPE_PRIMITIVE) | ||
| 581 | || (it->utype != V_ASN1_BOOLEAN)) | ||
| 582 | { | ||
| 583 | if (!*pval) return -1; | ||
| 584 | } | ||
| 585 | |||
| 586 | if (it->itype == ASN1_ITYPE_MSTRING) | ||
| 587 | { | ||
| 588 | /* If MSTRING type set the underlying type */ | ||
| 589 | strtmp = (ASN1_STRING *)*pval; | ||
| 590 | utype = strtmp->type; | ||
| 591 | *putype = utype; | ||
| 592 | } | ||
| 593 | else if (it->utype == V_ASN1_ANY) | ||
| 594 | { | ||
| 595 | /* If ANY set type and pointer to value */ | ||
| 596 | ASN1_TYPE *typ; | ||
| 597 | typ = (ASN1_TYPE *)*pval; | ||
| 598 | utype = typ->type; | ||
| 599 | *putype = utype; | ||
| 600 | pval = &typ->value.asn1_value; | ||
| 601 | } | ||
| 602 | else utype = *putype; | ||
| 603 | |||
| 604 | switch(utype) | ||
| 605 | { | ||
| 606 | case V_ASN1_OBJECT: | ||
| 607 | otmp = (ASN1_OBJECT *)*pval; | ||
| 608 | cont = otmp->data; | ||
| 609 | len = otmp->length; | ||
| 610 | break; | ||
| 611 | |||
| 612 | case V_ASN1_NULL: | ||
| 613 | cont = NULL; | ||
| 614 | len = 0; | ||
| 615 | break; | ||
| 616 | |||
| 617 | case V_ASN1_BOOLEAN: | ||
| 618 | tbool = (ASN1_BOOLEAN *)pval; | ||
| 619 | if (*tbool == -1) | ||
| 620 | return -1; | ||
| 621 | if (it->utype != V_ASN1_ANY) | ||
| 622 | { | ||
| 623 | /* Default handling if value == size field then omit */ | ||
| 624 | if (*tbool && (it->size > 0)) | ||
| 625 | return -1; | ||
| 626 | if (!*tbool && !it->size) | ||
| 627 | return -1; | ||
| 628 | } | ||
| 629 | c = (unsigned char)*tbool; | ||
| 630 | cont = &c; | ||
| 631 | len = 1; | ||
| 632 | break; | ||
| 633 | |||
| 634 | case V_ASN1_BIT_STRING: | ||
| 635 | return i2c_ASN1_BIT_STRING((ASN1_BIT_STRING *)*pval, | ||
| 636 | cout ? &cout : NULL); | ||
| 637 | break; | ||
| 638 | |||
| 639 | case V_ASN1_INTEGER: | ||
| 640 | case V_ASN1_NEG_INTEGER: | ||
| 641 | case V_ASN1_ENUMERATED: | ||
| 642 | case V_ASN1_NEG_ENUMERATED: | ||
| 643 | /* These are all have the same content format | ||
| 644 | * as ASN1_INTEGER | ||
| 645 | */ | ||
| 646 | return i2c_ASN1_INTEGER((ASN1_INTEGER *)*pval, | ||
| 647 | cout ? &cout : NULL); | ||
| 648 | break; | ||
| 649 | |||
| 650 | case V_ASN1_OCTET_STRING: | ||
| 651 | case V_ASN1_NUMERICSTRING: | ||
| 652 | case V_ASN1_PRINTABLESTRING: | ||
| 653 | case V_ASN1_T61STRING: | ||
| 654 | case V_ASN1_VIDEOTEXSTRING: | ||
| 655 | case V_ASN1_IA5STRING: | ||
| 656 | case V_ASN1_UTCTIME: | ||
| 657 | case V_ASN1_GENERALIZEDTIME: | ||
| 658 | case V_ASN1_GRAPHICSTRING: | ||
| 659 | case V_ASN1_VISIBLESTRING: | ||
| 660 | case V_ASN1_GENERALSTRING: | ||
| 661 | case V_ASN1_UNIVERSALSTRING: | ||
| 662 | case V_ASN1_BMPSTRING: | ||
| 663 | case V_ASN1_UTF8STRING: | ||
| 664 | case V_ASN1_SEQUENCE: | ||
| 665 | case V_ASN1_SET: | ||
| 666 | default: | ||
| 667 | /* All based on ASN1_STRING and handled the same */ | ||
| 668 | strtmp = (ASN1_STRING *)*pval; | ||
| 669 | /* Special handling for NDEF */ | ||
| 670 | if ((it->size == ASN1_TFLG_NDEF) | ||
| 671 | && (strtmp->flags & ASN1_STRING_FLAG_NDEF)) | ||
| 672 | { | ||
| 673 | if (cout) | ||
| 674 | { | ||
| 675 | strtmp->data = cout; | ||
| 676 | strtmp->length = 0; | ||
| 677 | } | ||
| 678 | /* Special return code */ | ||
| 679 | return -2; | ||
| 680 | } | ||
| 681 | cont = strtmp->data; | ||
| 682 | len = strtmp->length; | ||
| 683 | |||
| 684 | break; | ||
| 685 | |||
| 686 | } | ||
| 687 | if (cout && len) | ||
| 688 | memcpy(cout, cont, len); | ||
| 689 | return len; | ||
| 690 | } | ||
diff --git a/src/lib/libcrypto/asn1/tasn_fre.c b/src/lib/libcrypto/asn1/tasn_fre.c new file mode 100644 index 0000000000..bb7c1e2af4 --- /dev/null +++ b/src/lib/libcrypto/asn1/tasn_fre.c | |||
| @@ -0,0 +1,266 @@ | |||
| 1 | /* tasn_fre.c */ | ||
| 2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
| 3 | * project 2000. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 2000 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | |||
| 60 | #include <stddef.h> | ||
| 61 | #include <openssl/asn1.h> | ||
| 62 | #include <openssl/asn1t.h> | ||
| 63 | #include <openssl/objects.h> | ||
| 64 | |||
| 65 | static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine); | ||
| 66 | |||
| 67 | /* Free up an ASN1 structure */ | ||
| 68 | |||
| 69 | void ASN1_item_free(ASN1_VALUE *val, const ASN1_ITEM *it) | ||
| 70 | { | ||
| 71 | asn1_item_combine_free(&val, it, 0); | ||
| 72 | } | ||
| 73 | |||
| 74 | void ASN1_item_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it) | ||
| 75 | { | ||
| 76 | asn1_item_combine_free(pval, it, 0); | ||
| 77 | } | ||
| 78 | |||
| 79 | static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine) | ||
| 80 | { | ||
| 81 | const ASN1_TEMPLATE *tt = NULL, *seqtt; | ||
| 82 | const ASN1_EXTERN_FUNCS *ef; | ||
| 83 | const ASN1_COMPAT_FUNCS *cf; | ||
| 84 | const ASN1_AUX *aux = it->funcs; | ||
| 85 | ASN1_aux_cb *asn1_cb; | ||
| 86 | int i; | ||
| 87 | if (!pval) | ||
| 88 | return; | ||
| 89 | if ((it->itype != ASN1_ITYPE_PRIMITIVE) && !*pval) | ||
| 90 | return; | ||
| 91 | if (aux && aux->asn1_cb) | ||
| 92 | asn1_cb = aux->asn1_cb; | ||
| 93 | else | ||
| 94 | asn1_cb = 0; | ||
| 95 | |||
| 96 | switch(it->itype) | ||
| 97 | { | ||
| 98 | |||
| 99 | case ASN1_ITYPE_PRIMITIVE: | ||
| 100 | if (it->templates) | ||
| 101 | ASN1_template_free(pval, it->templates); | ||
| 102 | else | ||
| 103 | ASN1_primitive_free(pval, it); | ||
| 104 | break; | ||
| 105 | |||
| 106 | case ASN1_ITYPE_MSTRING: | ||
| 107 | ASN1_primitive_free(pval, it); | ||
| 108 | break; | ||
| 109 | |||
| 110 | case ASN1_ITYPE_CHOICE: | ||
| 111 | if (asn1_cb) | ||
| 112 | { | ||
| 113 | i = asn1_cb(ASN1_OP_FREE_PRE, pval, it); | ||
| 114 | if (i == 2) | ||
| 115 | return; | ||
| 116 | } | ||
| 117 | i = asn1_get_choice_selector(pval, it); | ||
| 118 | if ((i >= 0) && (i < it->tcount)) | ||
| 119 | { | ||
| 120 | ASN1_VALUE **pchval; | ||
| 121 | tt = it->templates + i; | ||
| 122 | pchval = asn1_get_field_ptr(pval, tt); | ||
| 123 | ASN1_template_free(pchval, tt); | ||
| 124 | } | ||
| 125 | if (asn1_cb) | ||
| 126 | asn1_cb(ASN1_OP_FREE_POST, pval, it); | ||
| 127 | if (!combine) | ||
| 128 | { | ||
| 129 | OPENSSL_free(*pval); | ||
| 130 | *pval = NULL; | ||
| 131 | } | ||
| 132 | break; | ||
| 133 | |||
| 134 | case ASN1_ITYPE_COMPAT: | ||
| 135 | cf = it->funcs; | ||
| 136 | if (cf && cf->asn1_free) | ||
| 137 | cf->asn1_free(*pval); | ||
| 138 | break; | ||
| 139 | |||
| 140 | case ASN1_ITYPE_EXTERN: | ||
| 141 | ef = it->funcs; | ||
| 142 | if (ef && ef->asn1_ex_free) | ||
| 143 | ef->asn1_ex_free(pval, it); | ||
| 144 | break; | ||
| 145 | |||
| 146 | case ASN1_ITYPE_NDEF_SEQUENCE: | ||
| 147 | case ASN1_ITYPE_SEQUENCE: | ||
| 148 | if (asn1_do_lock(pval, -1, it) > 0) | ||
| 149 | return; | ||
| 150 | if (asn1_cb) | ||
| 151 | { | ||
| 152 | i = asn1_cb(ASN1_OP_FREE_PRE, pval, it); | ||
| 153 | if (i == 2) | ||
| 154 | return; | ||
| 155 | } | ||
| 156 | asn1_enc_free(pval, it); | ||
| 157 | /* If we free up as normal we will invalidate any | ||
| 158 | * ANY DEFINED BY field and we wont be able to | ||
| 159 | * determine the type of the field it defines. So | ||
| 160 | * free up in reverse order. | ||
| 161 | */ | ||
| 162 | tt = it->templates + it->tcount - 1; | ||
| 163 | for (i = 0; i < it->tcount; tt--, i++) | ||
| 164 | { | ||
| 165 | ASN1_VALUE **pseqval; | ||
| 166 | seqtt = asn1_do_adb(pval, tt, 0); | ||
| 167 | if (!seqtt) | ||
| 168 | continue; | ||
| 169 | pseqval = asn1_get_field_ptr(pval, seqtt); | ||
| 170 | ASN1_template_free(pseqval, seqtt); | ||
| 171 | } | ||
| 172 | if (asn1_cb) | ||
| 173 | asn1_cb(ASN1_OP_FREE_POST, pval, it); | ||
| 174 | if (!combine) | ||
| 175 | { | ||
| 176 | OPENSSL_free(*pval); | ||
| 177 | *pval = NULL; | ||
| 178 | } | ||
| 179 | break; | ||
| 180 | } | ||
| 181 | } | ||
| 182 | |||
| 183 | void ASN1_template_free(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) | ||
| 184 | { | ||
| 185 | int i; | ||
| 186 | if (tt->flags & ASN1_TFLG_SK_MASK) | ||
| 187 | { | ||
| 188 | STACK_OF(ASN1_VALUE) *sk = (STACK_OF(ASN1_VALUE) *)*pval; | ||
| 189 | for (i = 0; i < sk_ASN1_VALUE_num(sk); i++) | ||
| 190 | { | ||
| 191 | ASN1_VALUE *vtmp; | ||
| 192 | vtmp = sk_ASN1_VALUE_value(sk, i); | ||
| 193 | asn1_item_combine_free(&vtmp, ASN1_ITEM_ptr(tt->item), | ||
| 194 | 0); | ||
| 195 | } | ||
| 196 | sk_ASN1_VALUE_free(sk); | ||
| 197 | *pval = NULL; | ||
| 198 | } | ||
| 199 | else | ||
| 200 | asn1_item_combine_free(pval, ASN1_ITEM_ptr(tt->item), | ||
| 201 | tt->flags & ASN1_TFLG_COMBINE); | ||
| 202 | } | ||
| 203 | |||
| 204 | void ASN1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it) | ||
| 205 | { | ||
| 206 | int utype; | ||
| 207 | if (it) | ||
| 208 | { | ||
| 209 | const ASN1_PRIMITIVE_FUNCS *pf; | ||
| 210 | pf = it->funcs; | ||
| 211 | if (pf && pf->prim_free) | ||
| 212 | { | ||
| 213 | pf->prim_free(pval, it); | ||
| 214 | return; | ||
| 215 | } | ||
| 216 | } | ||
| 217 | /* Special case: if 'it' is NULL free contents of ASN1_TYPE */ | ||
| 218 | if (!it) | ||
| 219 | { | ||
| 220 | ASN1_TYPE *typ = (ASN1_TYPE *)*pval; | ||
| 221 | utype = typ->type; | ||
| 222 | pval = &typ->value.asn1_value; | ||
| 223 | if (!*pval) | ||
| 224 | return; | ||
| 225 | } | ||
| 226 | else if (it->itype == ASN1_ITYPE_MSTRING) | ||
| 227 | { | ||
| 228 | utype = -1; | ||
| 229 | if (!*pval) | ||
| 230 | return; | ||
| 231 | } | ||
| 232 | else | ||
| 233 | { | ||
| 234 | utype = it->utype; | ||
| 235 | if ((utype != V_ASN1_BOOLEAN) && !*pval) | ||
| 236 | return; | ||
| 237 | } | ||
| 238 | |||
| 239 | switch(utype) | ||
| 240 | { | ||
| 241 | case V_ASN1_OBJECT: | ||
| 242 | ASN1_OBJECT_free((ASN1_OBJECT *)*pval); | ||
| 243 | break; | ||
| 244 | |||
| 245 | case V_ASN1_BOOLEAN: | ||
| 246 | if (it) | ||
| 247 | *(ASN1_BOOLEAN *)pval = it->size; | ||
| 248 | else | ||
| 249 | *(ASN1_BOOLEAN *)pval = -1; | ||
| 250 | return; | ||
| 251 | |||
| 252 | case V_ASN1_NULL: | ||
| 253 | break; | ||
| 254 | |||
| 255 | case V_ASN1_ANY: | ||
| 256 | ASN1_primitive_free(pval, NULL); | ||
| 257 | OPENSSL_free(*pval); | ||
| 258 | break; | ||
| 259 | |||
| 260 | default: | ||
| 261 | ASN1_STRING_free((ASN1_STRING *)*pval); | ||
| 262 | *pval = NULL; | ||
| 263 | break; | ||
| 264 | } | ||
| 265 | *pval = NULL; | ||
| 266 | } | ||
diff --git a/src/lib/libcrypto/asn1/tasn_new.c b/src/lib/libcrypto/asn1/tasn_new.c new file mode 100644 index 0000000000..531dad365c --- /dev/null +++ b/src/lib/libcrypto/asn1/tasn_new.c | |||
| @@ -0,0 +1,395 @@ | |||
| 1 | /* tasn_new.c */ | ||
| 2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
| 3 | * project 2000. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 2000-2004 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | |||
| 60 | #include <stddef.h> | ||
| 61 | #include <openssl/asn1.h> | ||
| 62 | #include <openssl/objects.h> | ||
| 63 | #include <openssl/err.h> | ||
| 64 | #include <openssl/asn1t.h> | ||
| 65 | #include <string.h> | ||
| 66 | |||
| 67 | static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, | ||
| 68 | int combine); | ||
| 69 | static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it); | ||
| 70 | static void asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt); | ||
| 71 | void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it); | ||
| 72 | |||
| 73 | ASN1_VALUE *ASN1_item_new(const ASN1_ITEM *it) | ||
| 74 | { | ||
| 75 | ASN1_VALUE *ret = NULL; | ||
| 76 | if (ASN1_item_ex_new(&ret, it) > 0) | ||
| 77 | return ret; | ||
| 78 | return NULL; | ||
| 79 | } | ||
| 80 | |||
| 81 | /* Allocate an ASN1 structure */ | ||
| 82 | |||
| 83 | int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it) | ||
| 84 | { | ||
| 85 | return asn1_item_ex_combine_new(pval, it, 0); | ||
| 86 | } | ||
| 87 | |||
| 88 | static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, | ||
| 89 | int combine) | ||
| 90 | { | ||
| 91 | const ASN1_TEMPLATE *tt = NULL; | ||
| 92 | const ASN1_COMPAT_FUNCS *cf; | ||
| 93 | const ASN1_EXTERN_FUNCS *ef; | ||
| 94 | const ASN1_AUX *aux = it->funcs; | ||
| 95 | ASN1_aux_cb *asn1_cb; | ||
| 96 | ASN1_VALUE **pseqval; | ||
| 97 | int i; | ||
| 98 | if (aux && aux->asn1_cb) | ||
| 99 | asn1_cb = aux->asn1_cb; | ||
| 100 | else | ||
| 101 | asn1_cb = 0; | ||
| 102 | |||
| 103 | if (!combine) *pval = NULL; | ||
| 104 | |||
| 105 | #ifdef CRYPTO_MDEBUG | ||
| 106 | if (it->sname) | ||
| 107 | CRYPTO_push_info(it->sname); | ||
| 108 | #endif | ||
| 109 | |||
| 110 | switch(it->itype) | ||
| 111 | { | ||
| 112 | |||
| 113 | case ASN1_ITYPE_EXTERN: | ||
| 114 | ef = it->funcs; | ||
| 115 | if (ef && ef->asn1_ex_new) | ||
| 116 | { | ||
| 117 | if (!ef->asn1_ex_new(pval, it)) | ||
| 118 | goto memerr; | ||
| 119 | } | ||
| 120 | break; | ||
| 121 | |||
| 122 | case ASN1_ITYPE_COMPAT: | ||
| 123 | cf = it->funcs; | ||
| 124 | if (cf && cf->asn1_new) { | ||
| 125 | *pval = cf->asn1_new(); | ||
| 126 | if (!*pval) | ||
| 127 | goto memerr; | ||
| 128 | } | ||
| 129 | break; | ||
| 130 | |||
| 131 | case ASN1_ITYPE_PRIMITIVE: | ||
| 132 | if (it->templates) | ||
| 133 | { | ||
| 134 | if (!ASN1_template_new(pval, it->templates)) | ||
| 135 | goto memerr; | ||
| 136 | } | ||
| 137 | else if (!ASN1_primitive_new(pval, it)) | ||
| 138 | goto memerr; | ||
| 139 | break; | ||
| 140 | |||
| 141 | case ASN1_ITYPE_MSTRING: | ||
| 142 | if (!ASN1_primitive_new(pval, it)) | ||
| 143 | goto memerr; | ||
| 144 | break; | ||
| 145 | |||
| 146 | case ASN1_ITYPE_CHOICE: | ||
| 147 | if (asn1_cb) | ||
| 148 | { | ||
| 149 | i = asn1_cb(ASN1_OP_NEW_PRE, pval, it); | ||
| 150 | if (!i) | ||
| 151 | goto auxerr; | ||
| 152 | if (i==2) | ||
| 153 | { | ||
| 154 | #ifdef CRYPTO_MDEBUG | ||
| 155 | if (it->sname) | ||
| 156 | CRYPTO_pop_info(); | ||
| 157 | #endif | ||
| 158 | return 1; | ||
| 159 | } | ||
| 160 | } | ||
| 161 | if (!combine) | ||
| 162 | { | ||
| 163 | *pval = OPENSSL_malloc(it->size); | ||
| 164 | if (!*pval) | ||
| 165 | goto memerr; | ||
| 166 | memset(*pval, 0, it->size); | ||
| 167 | } | ||
| 168 | asn1_set_choice_selector(pval, -1, it); | ||
| 169 | if (asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it)) | ||
| 170 | goto auxerr; | ||
| 171 | break; | ||
| 172 | |||
| 173 | case ASN1_ITYPE_NDEF_SEQUENCE: | ||
| 174 | case ASN1_ITYPE_SEQUENCE: | ||
| 175 | if (asn1_cb) | ||
| 176 | { | ||
| 177 | i = asn1_cb(ASN1_OP_NEW_PRE, pval, it); | ||
| 178 | if (!i) | ||
| 179 | goto auxerr; | ||
| 180 | if (i==2) | ||
| 181 | { | ||
| 182 | #ifdef CRYPTO_MDEBUG | ||
| 183 | if (it->sname) | ||
| 184 | CRYPTO_pop_info(); | ||
| 185 | #endif | ||
| 186 | return 1; | ||
| 187 | } | ||
| 188 | } | ||
| 189 | if (!combine) | ||
| 190 | { | ||
| 191 | *pval = OPENSSL_malloc(it->size); | ||
| 192 | if (!*pval) | ||
| 193 | goto memerr; | ||
| 194 | memset(*pval, 0, it->size); | ||
| 195 | asn1_do_lock(pval, 0, it); | ||
| 196 | asn1_enc_init(pval, it); | ||
| 197 | } | ||
| 198 | for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) | ||
| 199 | { | ||
| 200 | pseqval = asn1_get_field_ptr(pval, tt); | ||
| 201 | if (!ASN1_template_new(pseqval, tt)) | ||
| 202 | goto memerr; | ||
| 203 | } | ||
| 204 | if (asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it)) | ||
| 205 | goto auxerr; | ||
| 206 | break; | ||
| 207 | } | ||
| 208 | #ifdef CRYPTO_MDEBUG | ||
| 209 | if (it->sname) CRYPTO_pop_info(); | ||
| 210 | #endif | ||
| 211 | return 1; | ||
| 212 | |||
| 213 | memerr: | ||
| 214 | ASN1err(ASN1_F_ASN1_ITEM_EX_COMBINE_NEW, ERR_R_MALLOC_FAILURE); | ||
| 215 | #ifdef CRYPTO_MDEBUG | ||
| 216 | if (it->sname) CRYPTO_pop_info(); | ||
| 217 | #endif | ||
| 218 | return 0; | ||
| 219 | |||
| 220 | auxerr: | ||
| 221 | ASN1err(ASN1_F_ASN1_ITEM_EX_COMBINE_NEW, ASN1_R_AUX_ERROR); | ||
| 222 | ASN1_item_ex_free(pval, it); | ||
| 223 | #ifdef CRYPTO_MDEBUG | ||
| 224 | if (it->sname) CRYPTO_pop_info(); | ||
| 225 | #endif | ||
| 226 | return 0; | ||
| 227 | |||
| 228 | } | ||
| 229 | |||
| 230 | static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it) | ||
| 231 | { | ||
| 232 | const ASN1_EXTERN_FUNCS *ef; | ||
| 233 | |||
| 234 | switch(it->itype) | ||
| 235 | { | ||
| 236 | |||
| 237 | case ASN1_ITYPE_EXTERN: | ||
| 238 | ef = it->funcs; | ||
| 239 | if (ef && ef->asn1_ex_clear) | ||
| 240 | ef->asn1_ex_clear(pval, it); | ||
| 241 | else *pval = NULL; | ||
| 242 | break; | ||
| 243 | |||
| 244 | |||
| 245 | case ASN1_ITYPE_PRIMITIVE: | ||
| 246 | if (it->templates) | ||
| 247 | asn1_template_clear(pval, it->templates); | ||
| 248 | else | ||
| 249 | asn1_primitive_clear(pval, it); | ||
| 250 | break; | ||
| 251 | |||
| 252 | case ASN1_ITYPE_MSTRING: | ||
| 253 | asn1_primitive_clear(pval, it); | ||
| 254 | break; | ||
| 255 | |||
| 256 | case ASN1_ITYPE_COMPAT: | ||
| 257 | case ASN1_ITYPE_CHOICE: | ||
| 258 | case ASN1_ITYPE_SEQUENCE: | ||
| 259 | case ASN1_ITYPE_NDEF_SEQUENCE: | ||
| 260 | *pval = NULL; | ||
| 261 | break; | ||
| 262 | } | ||
| 263 | } | ||
| 264 | |||
| 265 | |||
| 266 | int ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) | ||
| 267 | { | ||
| 268 | const ASN1_ITEM *it = ASN1_ITEM_ptr(tt->item); | ||
| 269 | int ret; | ||
| 270 | if (tt->flags & ASN1_TFLG_OPTIONAL) | ||
| 271 | { | ||
| 272 | asn1_template_clear(pval, tt); | ||
| 273 | return 1; | ||
| 274 | } | ||
| 275 | /* If ANY DEFINED BY nothing to do */ | ||
| 276 | |||
| 277 | if (tt->flags & ASN1_TFLG_ADB_MASK) | ||
| 278 | { | ||
| 279 | *pval = NULL; | ||
| 280 | return 1; | ||
| 281 | } | ||
| 282 | #ifdef CRYPTO_MDEBUG | ||
| 283 | if (tt->field_name) | ||
| 284 | CRYPTO_push_info(tt->field_name); | ||
| 285 | #endif | ||
| 286 | /* If SET OF or SEQUENCE OF, its a STACK */ | ||
| 287 | if (tt->flags & ASN1_TFLG_SK_MASK) | ||
| 288 | { | ||
| 289 | STACK_OF(ASN1_VALUE) *skval; | ||
| 290 | skval = sk_ASN1_VALUE_new_null(); | ||
| 291 | if (!skval) | ||
| 292 | { | ||
| 293 | ASN1err(ASN1_F_ASN1_TEMPLATE_NEW, ERR_R_MALLOC_FAILURE); | ||
| 294 | ret = 0; | ||
| 295 | goto done; | ||
| 296 | } | ||
| 297 | *pval = (ASN1_VALUE *)skval; | ||
| 298 | ret = 1; | ||
| 299 | goto done; | ||
| 300 | } | ||
| 301 | /* Otherwise pass it back to the item routine */ | ||
| 302 | ret = asn1_item_ex_combine_new(pval, it, tt->flags & ASN1_TFLG_COMBINE); | ||
| 303 | done: | ||
| 304 | #ifdef CRYPTO_MDEBUG | ||
| 305 | if (it->sname) | ||
| 306 | CRYPTO_pop_info(); | ||
| 307 | #endif | ||
| 308 | return ret; | ||
| 309 | } | ||
| 310 | |||
| 311 | static void asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) | ||
| 312 | { | ||
| 313 | /* If ADB or STACK just NULL the field */ | ||
| 314 | if (tt->flags & (ASN1_TFLG_ADB_MASK|ASN1_TFLG_SK_MASK)) | ||
| 315 | *pval = NULL; | ||
| 316 | else | ||
| 317 | asn1_item_clear(pval, ASN1_ITEM_ptr(tt->item)); | ||
| 318 | } | ||
| 319 | |||
| 320 | |||
| 321 | /* NB: could probably combine most of the real XXX_new() behaviour and junk | ||
| 322 | * all the old functions. | ||
| 323 | */ | ||
| 324 | |||
| 325 | int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it) | ||
| 326 | { | ||
| 327 | ASN1_TYPE *typ; | ||
| 328 | int utype; | ||
| 329 | |||
| 330 | if (it && it->funcs) | ||
| 331 | { | ||
| 332 | const ASN1_PRIMITIVE_FUNCS *pf = it->funcs; | ||
| 333 | if (pf->prim_new) | ||
| 334 | return pf->prim_new(pval, it); | ||
| 335 | } | ||
| 336 | |||
| 337 | if (!it || (it->itype == ASN1_ITYPE_MSTRING)) | ||
| 338 | utype = -1; | ||
| 339 | else | ||
| 340 | utype = it->utype; | ||
| 341 | switch(utype) | ||
| 342 | { | ||
| 343 | case V_ASN1_OBJECT: | ||
| 344 | *pval = (ASN1_VALUE *)OBJ_nid2obj(NID_undef); | ||
| 345 | return 1; | ||
| 346 | |||
| 347 | case V_ASN1_BOOLEAN: | ||
| 348 | if (it) | ||
| 349 | *(ASN1_BOOLEAN *)pval = it->size; | ||
| 350 | else | ||
| 351 | *(ASN1_BOOLEAN *)pval = -1; | ||
| 352 | return 1; | ||
| 353 | |||
| 354 | case V_ASN1_NULL: | ||
| 355 | *pval = (ASN1_VALUE *)1; | ||
| 356 | return 1; | ||
| 357 | |||
| 358 | case V_ASN1_ANY: | ||
| 359 | typ = OPENSSL_malloc(sizeof(ASN1_TYPE)); | ||
| 360 | if (!typ) | ||
| 361 | return 0; | ||
| 362 | typ->value.ptr = NULL; | ||
| 363 | typ->type = -1; | ||
| 364 | *pval = (ASN1_VALUE *)typ; | ||
| 365 | break; | ||
| 366 | |||
| 367 | default: | ||
| 368 | *pval = (ASN1_VALUE *)ASN1_STRING_type_new(utype); | ||
| 369 | break; | ||
| 370 | } | ||
| 371 | if (*pval) | ||
| 372 | return 1; | ||
| 373 | return 0; | ||
| 374 | } | ||
| 375 | |||
| 376 | void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it) | ||
| 377 | { | ||
| 378 | int utype; | ||
| 379 | if (it && it->funcs) | ||
| 380 | { | ||
| 381 | const ASN1_PRIMITIVE_FUNCS *pf = it->funcs; | ||
| 382 | if (pf->prim_clear) | ||
| 383 | pf->prim_clear(pval, it); | ||
| 384 | else | ||
| 385 | *pval = NULL; | ||
| 386 | return; | ||
| 387 | } | ||
| 388 | if (!it || (it->itype == ASN1_ITYPE_MSTRING)) | ||
| 389 | utype = -1; | ||
| 390 | else | ||
| 391 | utype = it->utype; | ||
| 392 | if (utype == V_ASN1_BOOLEAN) | ||
| 393 | *(ASN1_BOOLEAN *)pval = it->size; | ||
| 394 | else *pval = NULL; | ||
| 395 | } | ||
diff --git a/src/lib/libcrypto/asn1/tasn_prn.c b/src/lib/libcrypto/asn1/tasn_prn.c new file mode 100644 index 0000000000..719639b511 --- /dev/null +++ b/src/lib/libcrypto/asn1/tasn_prn.c | |||
| @@ -0,0 +1,198 @@ | |||
| 1 | /* tasn_prn.c */ | ||
| 2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
| 3 | * project 2000. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 2000 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | |||
| 60 | #include <stddef.h> | ||
| 61 | #include <openssl/asn1.h> | ||
| 62 | #include <openssl/objects.h> | ||
| 63 | #include <openssl/buffer.h> | ||
| 64 | #include <openssl/err.h> | ||
| 65 | #include <openssl/nasn.h> | ||
| 66 | |||
| 67 | /* Print routines. Print out a whole structure from a template. | ||
| 68 | */ | ||
| 69 | |||
| 70 | static int asn1_item_print_nm(BIO *out, void *fld, int indent, const ASN1_ITEM *it, const char *name); | ||
| 71 | |||
| 72 | int ASN1_item_print(BIO *out, void *fld, int indent, const ASN1_ITEM *it) | ||
| 73 | { | ||
| 74 | return asn1_item_print_nm(out, fld, indent, it, it->sname); | ||
| 75 | } | ||
| 76 | |||
| 77 | static int asn1_item_print_nm(BIO *out, void *fld, int indent, const ASN1_ITEM *it, const char *name) | ||
| 78 | { | ||
| 79 | ASN1_STRING *str; | ||
| 80 | const ASN1_TEMPLATE *tt; | ||
| 81 | void *tmpfld; | ||
| 82 | int i; | ||
| 83 | if(!fld) { | ||
| 84 | BIO_printf(out, "%*s%s ABSENT\n", indent, "", name); | ||
| 85 | return 1; | ||
| 86 | } | ||
| 87 | switch(it->itype) { | ||
| 88 | |||
| 89 | case ASN1_ITYPE_PRIMITIVE: | ||
| 90 | if(it->templates) | ||
| 91 | return ASN1_template_print(out, fld, indent, it->templates); | ||
| 92 | return asn1_primitive_print(out, fld, it->utype, indent, name); | ||
| 93 | break; | ||
| 94 | |||
| 95 | case ASN1_ITYPE_MSTRING: | ||
| 96 | str = fld; | ||
| 97 | return asn1_primitive_print(out, fld, str->type, indent, name); | ||
| 98 | |||
| 99 | case ASN1_ITYPE_EXTERN: | ||
| 100 | BIO_printf(out, "%*s%s:EXTERNAL TYPE %s %s\n", indent, "", name, it->sname, fld ? "" : "ABSENT"); | ||
| 101 | return 1; | ||
| 102 | case ASN1_ITYPE_COMPAT: | ||
| 103 | BIO_printf(out, "%*s%s:COMPATIBLE TYPE %s %s\n", indent, "", name, it->sname, fld ? "" : "ABSENT"); | ||
| 104 | return 1; | ||
| 105 | |||
| 106 | |||
| 107 | case ASN1_ITYPE_CHOICE: | ||
| 108 | /* CHOICE type, get selector */ | ||
| 109 | i = asn1_get_choice_selector(fld, it); | ||
| 110 | /* This should never happen... */ | ||
| 111 | if((i < 0) || (i >= it->tcount)) { | ||
| 112 | BIO_printf(out, "%s selector [%d] out of range\n", it->sname, i); | ||
| 113 | return 1; | ||
| 114 | } | ||
| 115 | tt = it->templates + i; | ||
| 116 | tmpfld = asn1_get_field(fld, tt); | ||
| 117 | return ASN1_template_print(out, tmpfld, indent, tt); | ||
| 118 | |||
| 119 | case ASN1_ITYPE_SEQUENCE: | ||
| 120 | BIO_printf(out, "%*s%s {\n", indent, "", name); | ||
| 121 | /* Get each field entry */ | ||
| 122 | for(i = 0, tt = it->templates; i < it->tcount; i++, tt++) { | ||
| 123 | tmpfld = asn1_get_field(fld, tt); | ||
| 124 | ASN1_template_print(out, tmpfld, indent + 2, tt); | ||
| 125 | } | ||
| 126 | BIO_printf(out, "%*s}\n", indent, ""); | ||
| 127 | return 1; | ||
| 128 | |||
| 129 | default: | ||
| 130 | return 0; | ||
| 131 | } | ||
| 132 | } | ||
| 133 | |||
| 134 | int ASN1_template_print(BIO *out, void *fld, int indent, const ASN1_TEMPLATE *tt) | ||
| 135 | { | ||
| 136 | int i, flags; | ||
| 137 | #if 0 | ||
| 138 | if(!fld) return 0; | ||
| 139 | #endif | ||
| 140 | flags = tt->flags; | ||
| 141 | if(flags & ASN1_TFLG_SK_MASK) { | ||
| 142 | char *tname; | ||
| 143 | void *skitem; | ||
| 144 | /* SET OF, SEQUENCE OF */ | ||
| 145 | if(flags & ASN1_TFLG_SET_OF) tname = "SET"; | ||
| 146 | else tname = "SEQUENCE"; | ||
| 147 | if(fld) { | ||
| 148 | BIO_printf(out, "%*s%s OF %s {\n", indent, "", tname, tt->field_name); | ||
| 149 | for(i = 0; i < sk_num(fld); i++) { | ||
| 150 | skitem = sk_value(fld, i); | ||
| 151 | asn1_item_print_nm(out, skitem, indent + 2, tt->item, ""); | ||
| 152 | } | ||
| 153 | BIO_printf(out, "%*s}\n", indent, ""); | ||
| 154 | } else | ||
| 155 | BIO_printf(out, "%*s%s OF %s ABSENT\n", indent, "", tname, tt->field_name); | ||
| 156 | return 1; | ||
| 157 | } | ||
| 158 | return asn1_item_print_nm(out, fld, indent, tt->item, tt->field_name); | ||
| 159 | } | ||
| 160 | |||
| 161 | static int asn1_primitive_print(BIO *out, void *fld, long utype, int indent, const char *name) | ||
| 162 | { | ||
| 163 | ASN1_STRING *str = fld; | ||
| 164 | if(fld) { | ||
| 165 | if(utype == V_ASN1_BOOLEAN) { | ||
| 166 | int *bool = fld; | ||
| 167 | if(*bool == -1) printf("BOOL MISSING\n"); | ||
| 168 | BIO_printf(out, "%*s%s:%s", indent, "", "BOOLEAN", *bool ? "TRUE" : "FALSE"); | ||
| 169 | } else if((utype == V_ASN1_INTEGER) | ||
| 170 | || (utype == V_ASN1_ENUMERATED)) { | ||
| 171 | char *s, *nm; | ||
| 172 | s = i2s_ASN1_INTEGER(NULL, fld); | ||
| 173 | if(utype == V_ASN1_INTEGER) nm = "INTEGER"; | ||
| 174 | else nm = "ENUMERATED"; | ||
| 175 | BIO_printf(out, "%*s%s:%s", indent, "", nm, s); | ||
| 176 | OPENSSL_free(s); | ||
| 177 | } else if(utype == V_ASN1_NULL) { | ||
| 178 | BIO_printf(out, "%*s%s", indent, "", "NULL"); | ||
| 179 | } else if(utype == V_ASN1_UTCTIME) { | ||
| 180 | BIO_printf(out, "%*s%s:%s:", indent, "", name, "UTCTIME"); | ||
| 181 | ASN1_UTCTIME_print(out, str); | ||
| 182 | } else if(utype == V_ASN1_GENERALIZEDTIME) { | ||
| 183 | BIO_printf(out, "%*s%s:%s:", indent, "", name, "GENERALIZEDTIME"); | ||
| 184 | ASN1_GENERALIZEDTIME_print(out, str); | ||
| 185 | } else if(utype == V_ASN1_OBJECT) { | ||
| 186 | char objbuf[80], *ln; | ||
| 187 | ln = OBJ_nid2ln(OBJ_obj2nid(fld)); | ||
| 188 | if(!ln) ln = ""; | ||
| 189 | OBJ_obj2txt(objbuf, sizeof objbuf, fld, 1); | ||
| 190 | BIO_printf(out, "%*s%s:%s (%s)", indent, "", "OBJECT", ln, objbuf); | ||
| 191 | } else { | ||
| 192 | BIO_printf(out, "%*s%s:", indent, "", name); | ||
| 193 | ASN1_STRING_print_ex(out, str, ASN1_STRFLGS_DUMP_UNKNOWN|ASN1_STRFLGS_SHOW_TYPE); | ||
| 194 | } | ||
| 195 | BIO_printf(out, "\n"); | ||
| 196 | } else BIO_printf(out, "%*s%s [ABSENT]\n", indent, "", name); | ||
| 197 | return 1; | ||
| 198 | } | ||
diff --git a/src/lib/libcrypto/asn1/tasn_typ.c b/src/lib/libcrypto/asn1/tasn_typ.c new file mode 100644 index 0000000000..6f17f1bec7 --- /dev/null +++ b/src/lib/libcrypto/asn1/tasn_typ.c | |||
| @@ -0,0 +1,137 @@ | |||
| 1 | /* tasn_typ.c */ | ||
| 2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
| 3 | * project 2000. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 2000 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | #include <stdio.h> | ||
| 59 | #include <openssl/asn1.h> | ||
| 60 | #include <openssl/asn1t.h> | ||
| 61 | |||
| 62 | /* Declarations for string types */ | ||
| 63 | |||
| 64 | |||
| 65 | IMPLEMENT_ASN1_TYPE(ASN1_INTEGER) | ||
| 66 | IMPLEMENT_ASN1_FUNCTIONS(ASN1_INTEGER) | ||
| 67 | |||
| 68 | IMPLEMENT_ASN1_TYPE(ASN1_ENUMERATED) | ||
| 69 | IMPLEMENT_ASN1_FUNCTIONS(ASN1_ENUMERATED) | ||
| 70 | |||
| 71 | IMPLEMENT_ASN1_TYPE(ASN1_BIT_STRING) | ||
| 72 | IMPLEMENT_ASN1_FUNCTIONS(ASN1_BIT_STRING) | ||
| 73 | |||
| 74 | IMPLEMENT_ASN1_TYPE(ASN1_OCTET_STRING) | ||
| 75 | IMPLEMENT_ASN1_FUNCTIONS(ASN1_OCTET_STRING) | ||
| 76 | |||
| 77 | IMPLEMENT_ASN1_TYPE(ASN1_NULL) | ||
| 78 | IMPLEMENT_ASN1_FUNCTIONS(ASN1_NULL) | ||
| 79 | |||
| 80 | IMPLEMENT_ASN1_TYPE(ASN1_OBJECT) | ||
| 81 | |||
| 82 | IMPLEMENT_ASN1_TYPE(ASN1_UTF8STRING) | ||
| 83 | IMPLEMENT_ASN1_FUNCTIONS(ASN1_UTF8STRING) | ||
| 84 | |||
| 85 | IMPLEMENT_ASN1_TYPE(ASN1_PRINTABLESTRING) | ||
| 86 | IMPLEMENT_ASN1_FUNCTIONS(ASN1_PRINTABLESTRING) | ||
| 87 | |||
| 88 | IMPLEMENT_ASN1_TYPE(ASN1_T61STRING) | ||
| 89 | IMPLEMENT_ASN1_FUNCTIONS(ASN1_T61STRING) | ||
| 90 | |||
| 91 | IMPLEMENT_ASN1_TYPE(ASN1_IA5STRING) | ||
| 92 | IMPLEMENT_ASN1_FUNCTIONS(ASN1_IA5STRING) | ||
| 93 | |||
| 94 | IMPLEMENT_ASN1_TYPE(ASN1_GENERALSTRING) | ||
| 95 | IMPLEMENT_ASN1_FUNCTIONS(ASN1_GENERALSTRING) | ||
| 96 | |||
| 97 | IMPLEMENT_ASN1_TYPE(ASN1_UTCTIME) | ||
| 98 | IMPLEMENT_ASN1_FUNCTIONS(ASN1_UTCTIME) | ||
| 99 | |||
| 100 | IMPLEMENT_ASN1_TYPE(ASN1_GENERALIZEDTIME) | ||
| 101 | IMPLEMENT_ASN1_FUNCTIONS(ASN1_GENERALIZEDTIME) | ||
| 102 | |||
| 103 | IMPLEMENT_ASN1_TYPE(ASN1_VISIBLESTRING) | ||
| 104 | IMPLEMENT_ASN1_FUNCTIONS(ASN1_VISIBLESTRING) | ||
| 105 | |||
| 106 | IMPLEMENT_ASN1_TYPE(ASN1_UNIVERSALSTRING) | ||
| 107 | IMPLEMENT_ASN1_FUNCTIONS(ASN1_UNIVERSALSTRING) | ||
| 108 | |||
| 109 | IMPLEMENT_ASN1_TYPE(ASN1_BMPSTRING) | ||
| 110 | IMPLEMENT_ASN1_FUNCTIONS(ASN1_BMPSTRING) | ||
| 111 | |||
| 112 | IMPLEMENT_ASN1_TYPE(ASN1_ANY) | ||
| 113 | |||
| 114 | /* Just swallow an ASN1_SEQUENCE in an ASN1_STRING */ | ||
| 115 | IMPLEMENT_ASN1_TYPE(ASN1_SEQUENCE) | ||
| 116 | |||
| 117 | IMPLEMENT_ASN1_FUNCTIONS_fname(ASN1_TYPE, ASN1_ANY, ASN1_TYPE) | ||
| 118 | |||
| 119 | /* Multistring types */ | ||
| 120 | |||
| 121 | IMPLEMENT_ASN1_MSTRING(ASN1_PRINTABLE, B_ASN1_PRINTABLE) | ||
| 122 | IMPLEMENT_ASN1_FUNCTIONS_name(ASN1_STRING, ASN1_PRINTABLE) | ||
| 123 | |||
| 124 | IMPLEMENT_ASN1_MSTRING(DISPLAYTEXT, B_ASN1_DISPLAYTEXT) | ||
| 125 | IMPLEMENT_ASN1_FUNCTIONS_name(ASN1_STRING, DISPLAYTEXT) | ||
| 126 | |||
| 127 | IMPLEMENT_ASN1_MSTRING(DIRECTORYSTRING, B_ASN1_DIRECTORYSTRING) | ||
| 128 | IMPLEMENT_ASN1_FUNCTIONS_name(ASN1_STRING, DIRECTORYSTRING) | ||
| 129 | |||
| 130 | /* Three separate BOOLEAN type: normal, DEFAULT TRUE and DEFAULT FALSE */ | ||
| 131 | IMPLEMENT_ASN1_TYPE_ex(ASN1_BOOLEAN, ASN1_BOOLEAN, -1) | ||
| 132 | IMPLEMENT_ASN1_TYPE_ex(ASN1_TBOOLEAN, ASN1_BOOLEAN, 1) | ||
| 133 | IMPLEMENT_ASN1_TYPE_ex(ASN1_FBOOLEAN, ASN1_BOOLEAN, 0) | ||
| 134 | |||
| 135 | /* Special, OCTET STRING with indefinite length constructed support */ | ||
| 136 | |||
| 137 | IMPLEMENT_ASN1_TYPE_ex(ASN1_OCTET_STRING_NDEF, ASN1_OCTET_STRING, ASN1_TFLG_NDEF) | ||
diff --git a/src/lib/libcrypto/asn1/tasn_utl.c b/src/lib/libcrypto/asn1/tasn_utl.c new file mode 100644 index 0000000000..34d520b180 --- /dev/null +++ b/src/lib/libcrypto/asn1/tasn_utl.c | |||
| @@ -0,0 +1,279 @@ | |||
| 1 | /* tasn_utl.c */ | ||
| 2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
| 3 | * project 2000. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 2000-2004 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | |||
| 60 | #include <stddef.h> | ||
| 61 | #include <string.h> | ||
| 62 | #include <openssl/asn1.h> | ||
| 63 | #include <openssl/asn1t.h> | ||
| 64 | #include <openssl/objects.h> | ||
| 65 | #include <openssl/err.h> | ||
| 66 | |||
| 67 | /* Utility functions for manipulating fields and offsets */ | ||
| 68 | |||
| 69 | /* Add 'offset' to 'addr' */ | ||
| 70 | #define offset2ptr(addr, offset) (void *)(((char *) addr) + offset) | ||
| 71 | |||
| 72 | /* Given an ASN1_ITEM CHOICE type return | ||
| 73 | * the selector value | ||
| 74 | */ | ||
| 75 | |||
| 76 | int asn1_get_choice_selector(ASN1_VALUE **pval, const ASN1_ITEM *it) | ||
| 77 | { | ||
| 78 | int *sel = offset2ptr(*pval, it->utype); | ||
| 79 | return *sel; | ||
| 80 | } | ||
| 81 | |||
| 82 | /* Given an ASN1_ITEM CHOICE type set | ||
| 83 | * the selector value, return old value. | ||
| 84 | */ | ||
| 85 | |||
| 86 | int asn1_set_choice_selector(ASN1_VALUE **pval, int value, const ASN1_ITEM *it) | ||
| 87 | { | ||
| 88 | int *sel, ret; | ||
| 89 | sel = offset2ptr(*pval, it->utype); | ||
| 90 | ret = *sel; | ||
| 91 | *sel = value; | ||
| 92 | return ret; | ||
| 93 | } | ||
| 94 | |||
| 95 | /* Do reference counting. The value 'op' decides what to do. | ||
| 96 | * if it is +1 then the count is incremented. If op is 0 count is | ||
| 97 | * set to 1. If op is -1 count is decremented and the return value | ||
| 98 | * is the current refrence count or 0 if no reference count exists. | ||
| 99 | */ | ||
| 100 | |||
| 101 | int asn1_do_lock(ASN1_VALUE **pval, int op, const ASN1_ITEM *it) | ||
| 102 | { | ||
| 103 | const ASN1_AUX *aux; | ||
| 104 | int *lck, ret; | ||
| 105 | if ((it->itype != ASN1_ITYPE_SEQUENCE) | ||
| 106 | && (it->itype != ASN1_ITYPE_NDEF_SEQUENCE)) | ||
| 107 | return 0; | ||
| 108 | aux = it->funcs; | ||
| 109 | if (!aux || !(aux->flags & ASN1_AFLG_REFCOUNT)) | ||
| 110 | return 0; | ||
| 111 | lck = offset2ptr(*pval, aux->ref_offset); | ||
| 112 | if (op == 0) | ||
| 113 | { | ||
| 114 | *lck = 1; | ||
| 115 | return 1; | ||
| 116 | } | ||
| 117 | ret = CRYPTO_add(lck, op, aux->ref_lock); | ||
| 118 | #ifdef REF_PRINT | ||
| 119 | fprintf(stderr, "%s: Reference Count: %d\n", it->sname, *lck); | ||
| 120 | #endif | ||
| 121 | #ifdef REF_CHECK | ||
| 122 | if (ret < 0) | ||
| 123 | fprintf(stderr, "%s, bad reference count\n", it->sname); | ||
| 124 | #endif | ||
| 125 | return ret; | ||
| 126 | } | ||
| 127 | |||
| 128 | static ASN1_ENCODING *asn1_get_enc_ptr(ASN1_VALUE **pval, const ASN1_ITEM *it) | ||
| 129 | { | ||
| 130 | const ASN1_AUX *aux; | ||
| 131 | if (!pval || !*pval) | ||
| 132 | return NULL; | ||
| 133 | aux = it->funcs; | ||
| 134 | if (!aux || !(aux->flags & ASN1_AFLG_ENCODING)) | ||
| 135 | return NULL; | ||
| 136 | return offset2ptr(*pval, aux->enc_offset); | ||
| 137 | } | ||
| 138 | |||
| 139 | void asn1_enc_init(ASN1_VALUE **pval, const ASN1_ITEM *it) | ||
| 140 | { | ||
| 141 | ASN1_ENCODING *enc; | ||
| 142 | enc = asn1_get_enc_ptr(pval, it); | ||
| 143 | if (enc) | ||
| 144 | { | ||
| 145 | enc->enc = NULL; | ||
| 146 | enc->len = 0; | ||
| 147 | enc->modified = 1; | ||
| 148 | } | ||
| 149 | } | ||
| 150 | |||
| 151 | void asn1_enc_free(ASN1_VALUE **pval, const ASN1_ITEM *it) | ||
| 152 | { | ||
| 153 | ASN1_ENCODING *enc; | ||
| 154 | enc = asn1_get_enc_ptr(pval, it); | ||
| 155 | if (enc) | ||
| 156 | { | ||
| 157 | if (enc->enc) | ||
| 158 | OPENSSL_free(enc->enc); | ||
| 159 | enc->enc = NULL; | ||
| 160 | enc->len = 0; | ||
| 161 | enc->modified = 1; | ||
| 162 | } | ||
| 163 | } | ||
| 164 | |||
| 165 | int asn1_enc_save(ASN1_VALUE **pval, const unsigned char *in, int inlen, | ||
| 166 | const ASN1_ITEM *it) | ||
| 167 | { | ||
| 168 | ASN1_ENCODING *enc; | ||
| 169 | enc = asn1_get_enc_ptr(pval, it); | ||
| 170 | if (!enc) | ||
| 171 | return 1; | ||
| 172 | |||
| 173 | if (enc->enc) | ||
| 174 | OPENSSL_free(enc->enc); | ||
| 175 | enc->enc = OPENSSL_malloc(inlen); | ||
| 176 | if (!enc->enc) | ||
| 177 | return 0; | ||
| 178 | memcpy(enc->enc, in, inlen); | ||
| 179 | enc->len = inlen; | ||
| 180 | enc->modified = 0; | ||
| 181 | |||
| 182 | return 1; | ||
| 183 | } | ||
| 184 | |||
| 185 | int asn1_enc_restore(int *len, unsigned char **out, ASN1_VALUE **pval, | ||
| 186 | const ASN1_ITEM *it) | ||
| 187 | { | ||
| 188 | ASN1_ENCODING *enc; | ||
| 189 | enc = asn1_get_enc_ptr(pval, it); | ||
| 190 | if (!enc || enc->modified) | ||
| 191 | return 0; | ||
| 192 | if (out) | ||
| 193 | { | ||
| 194 | memcpy(*out, enc->enc, enc->len); | ||
| 195 | *out += enc->len; | ||
| 196 | } | ||
| 197 | if (len) | ||
| 198 | *len = enc->len; | ||
| 199 | return 1; | ||
| 200 | } | ||
| 201 | |||
| 202 | /* Given an ASN1_TEMPLATE get a pointer to a field */ | ||
| 203 | ASN1_VALUE ** asn1_get_field_ptr(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) | ||
| 204 | { | ||
| 205 | ASN1_VALUE **pvaltmp; | ||
| 206 | if (tt->flags & ASN1_TFLG_COMBINE) | ||
| 207 | return pval; | ||
| 208 | pvaltmp = offset2ptr(*pval, tt->offset); | ||
| 209 | /* NOTE for BOOLEAN types the field is just a plain | ||
| 210 | * int so we can't return int **, so settle for | ||
| 211 | * (int *). | ||
| 212 | */ | ||
| 213 | return pvaltmp; | ||
| 214 | } | ||
| 215 | |||
| 216 | /* Handle ANY DEFINED BY template, find the selector, look up | ||
| 217 | * the relevant ASN1_TEMPLATE in the table and return it. | ||
| 218 | */ | ||
| 219 | |||
| 220 | const ASN1_TEMPLATE *asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt, | ||
| 221 | int nullerr) | ||
| 222 | { | ||
| 223 | const ASN1_ADB *adb; | ||
| 224 | const ASN1_ADB_TABLE *atbl; | ||
| 225 | long selector; | ||
| 226 | ASN1_VALUE **sfld; | ||
| 227 | int i; | ||
| 228 | if (!(tt->flags & ASN1_TFLG_ADB_MASK)) | ||
| 229 | return tt; | ||
| 230 | |||
| 231 | /* Else ANY DEFINED BY ... get the table */ | ||
| 232 | adb = ASN1_ADB_ptr(tt->item); | ||
| 233 | |||
| 234 | /* Get the selector field */ | ||
| 235 | sfld = offset2ptr(*pval, adb->offset); | ||
| 236 | |||
| 237 | /* Check if NULL */ | ||
| 238 | if (!sfld) | ||
| 239 | { | ||
| 240 | if (!adb->null_tt) | ||
| 241 | goto err; | ||
| 242 | return adb->null_tt; | ||
| 243 | } | ||
| 244 | |||
| 245 | /* Convert type to a long: | ||
| 246 | * NB: don't check for NID_undef here because it | ||
| 247 | * might be a legitimate value in the table | ||
| 248 | */ | ||
| 249 | if (tt->flags & ASN1_TFLG_ADB_OID) | ||
| 250 | selector = OBJ_obj2nid((ASN1_OBJECT *)*sfld); | ||
| 251 | else | ||
| 252 | selector = ASN1_INTEGER_get((ASN1_INTEGER *)*sfld); | ||
| 253 | |||
| 254 | /* Try to find matching entry in table | ||
| 255 | * Maybe should check application types first to | ||
| 256 | * allow application override? Might also be useful | ||
| 257 | * to have a flag which indicates table is sorted and | ||
| 258 | * we can do a binary search. For now stick to a | ||
| 259 | * linear search. | ||
| 260 | */ | ||
| 261 | |||
| 262 | for (atbl = adb->tbl, i = 0; i < adb->tblcount; i++, atbl++) | ||
| 263 | if (atbl->value == selector) | ||
| 264 | return &atbl->tt; | ||
| 265 | |||
| 266 | /* FIXME: need to search application table too */ | ||
| 267 | |||
| 268 | /* No match, return default type */ | ||
| 269 | if (!adb->default_tt) | ||
| 270 | goto err; | ||
| 271 | return adb->default_tt; | ||
| 272 | |||
| 273 | err: | ||
| 274 | /* FIXME: should log the value or OID of unsupported type */ | ||
| 275 | if (nullerr) | ||
| 276 | ASN1err(ASN1_F_ASN1_DO_ADB, | ||
| 277 | ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE); | ||
| 278 | return NULL; | ||
| 279 | } | ||
diff --git a/src/lib/libcrypto/asn1/x_algor.c b/src/lib/libcrypto/asn1/x_algor.c new file mode 100644 index 0000000000..33533aba86 --- /dev/null +++ b/src/lib/libcrypto/asn1/x_algor.c | |||
| @@ -0,0 +1,130 @@ | |||
| 1 | /* x_algor.c */ | ||
| 2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
| 3 | * project 2000. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 2000 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stddef.h> | ||
| 60 | #include <openssl/x509.h> | ||
| 61 | #include <openssl/asn1.h> | ||
| 62 | #include <openssl/asn1t.h> | ||
| 63 | |||
| 64 | ASN1_SEQUENCE(X509_ALGOR) = { | ||
| 65 | ASN1_SIMPLE(X509_ALGOR, algorithm, ASN1_OBJECT), | ||
| 66 | ASN1_OPT(X509_ALGOR, parameter, ASN1_ANY) | ||
| 67 | } ASN1_SEQUENCE_END(X509_ALGOR) | ||
| 68 | |||
| 69 | ASN1_ITEM_TEMPLATE(X509_ALGORS) = | ||
| 70 | ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, algorithms, X509_ALGOR) | ||
| 71 | ASN1_ITEM_TEMPLATE_END(X509_ALGORS) | ||
| 72 | |||
| 73 | IMPLEMENT_ASN1_FUNCTIONS(X509_ALGOR) | ||
| 74 | IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(X509_ALGORS, X509_ALGORS, X509_ALGORS) | ||
| 75 | IMPLEMENT_ASN1_DUP_FUNCTION(X509_ALGOR) | ||
| 76 | |||
| 77 | IMPLEMENT_STACK_OF(X509_ALGOR) | ||
| 78 | IMPLEMENT_ASN1_SET_OF(X509_ALGOR) | ||
| 79 | |||
| 80 | int X509_ALGOR_set0(X509_ALGOR *alg, ASN1_OBJECT *aobj, int ptype, void *pval) | ||
| 81 | { | ||
| 82 | if (!alg) | ||
| 83 | return 0; | ||
| 84 | if (ptype != V_ASN1_UNDEF) | ||
| 85 | { | ||
| 86 | if (alg->parameter == NULL) | ||
| 87 | alg->parameter = ASN1_TYPE_new(); | ||
| 88 | if (alg->parameter == NULL) | ||
| 89 | return 0; | ||
| 90 | } | ||
| 91 | if (alg) | ||
| 92 | { | ||
| 93 | if (alg->algorithm) | ||
| 94 | ASN1_OBJECT_free(alg->algorithm); | ||
| 95 | alg->algorithm = aobj; | ||
| 96 | } | ||
| 97 | if (ptype == 0) | ||
| 98 | return 1; | ||
| 99 | if (ptype == V_ASN1_UNDEF) | ||
| 100 | { | ||
| 101 | if (alg->parameter) | ||
| 102 | { | ||
| 103 | ASN1_TYPE_free(alg->parameter); | ||
| 104 | alg->parameter = NULL; | ||
| 105 | } | ||
| 106 | } | ||
| 107 | else | ||
| 108 | ASN1_TYPE_set(alg->parameter, ptype, pval); | ||
| 109 | return 1; | ||
| 110 | } | ||
| 111 | |||
| 112 | void X509_ALGOR_get0(ASN1_OBJECT **paobj, int *pptype, void **ppval, | ||
| 113 | X509_ALGOR *algor) | ||
| 114 | { | ||
| 115 | if (paobj) | ||
| 116 | *paobj = algor->algorithm; | ||
| 117 | if (pptype) | ||
| 118 | { | ||
| 119 | if (algor->parameter == NULL) | ||
| 120 | { | ||
| 121 | *pptype = V_ASN1_UNDEF; | ||
| 122 | return; | ||
| 123 | } | ||
| 124 | else | ||
| 125 | *pptype = algor->parameter->type; | ||
| 126 | if (ppval) | ||
| 127 | *ppval = algor->parameter->value.ptr; | ||
| 128 | } | ||
| 129 | } | ||
| 130 | |||
diff --git a/src/lib/libcrypto/asn1/x_attrib.c b/src/lib/libcrypto/asn1/x_attrib.c new file mode 100644 index 0000000000..1e3713f18f --- /dev/null +++ b/src/lib/libcrypto/asn1/x_attrib.c | |||
| @@ -0,0 +1,118 @@ | |||
| 1 | /* crypto/asn1/x_attrib.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/objects.h> | ||
| 62 | #include <openssl/asn1t.h> | ||
| 63 | #include <openssl/x509.h> | ||
| 64 | |||
| 65 | /* X509_ATTRIBUTE: this has the following form: | ||
| 66 | * | ||
| 67 | * typedef struct x509_attributes_st | ||
| 68 | * { | ||
| 69 | * ASN1_OBJECT *object; | ||
| 70 | * int single; | ||
| 71 | * union { | ||
| 72 | * char *ptr; | ||
| 73 | * STACK_OF(ASN1_TYPE) *set; | ||
| 74 | * ASN1_TYPE *single; | ||
| 75 | * } value; | ||
| 76 | * } X509_ATTRIBUTE; | ||
| 77 | * | ||
| 78 | * this needs some extra thought because the CHOICE type is | ||
| 79 | * merged with the main structure and because the value can | ||
| 80 | * be anything at all we *must* try the SET OF first because | ||
| 81 | * the ASN1_ANY type will swallow anything including the whole | ||
| 82 | * SET OF structure. | ||
| 83 | */ | ||
| 84 | |||
| 85 | ASN1_CHOICE(X509_ATTRIBUTE_SET) = { | ||
| 86 | ASN1_SET_OF(X509_ATTRIBUTE, value.set, ASN1_ANY), | ||
| 87 | ASN1_SIMPLE(X509_ATTRIBUTE, value.single, ASN1_ANY) | ||
| 88 | } ASN1_CHOICE_END_selector(X509_ATTRIBUTE, X509_ATTRIBUTE_SET, single) | ||
| 89 | |||
| 90 | ASN1_SEQUENCE(X509_ATTRIBUTE) = { | ||
| 91 | ASN1_SIMPLE(X509_ATTRIBUTE, object, ASN1_OBJECT), | ||
| 92 | /* CHOICE type merged with parent */ | ||
| 93 | ASN1_EX_COMBINE(0, 0, X509_ATTRIBUTE_SET) | ||
| 94 | } ASN1_SEQUENCE_END(X509_ATTRIBUTE) | ||
| 95 | |||
| 96 | IMPLEMENT_ASN1_FUNCTIONS(X509_ATTRIBUTE) | ||
| 97 | IMPLEMENT_ASN1_DUP_FUNCTION(X509_ATTRIBUTE) | ||
| 98 | |||
| 99 | X509_ATTRIBUTE *X509_ATTRIBUTE_create(int nid, int atrtype, void *value) | ||
| 100 | { | ||
| 101 | X509_ATTRIBUTE *ret=NULL; | ||
| 102 | ASN1_TYPE *val=NULL; | ||
| 103 | |||
| 104 | if ((ret=X509_ATTRIBUTE_new()) == NULL) | ||
| 105 | return(NULL); | ||
| 106 | ret->object=OBJ_nid2obj(nid); | ||
| 107 | ret->single=0; | ||
| 108 | if ((ret->value.set=sk_ASN1_TYPE_new_null()) == NULL) goto err; | ||
| 109 | if ((val=ASN1_TYPE_new()) == NULL) goto err; | ||
| 110 | if (!sk_ASN1_TYPE_push(ret->value.set,val)) goto err; | ||
| 111 | |||
| 112 | ASN1_TYPE_set(val,atrtype,value); | ||
| 113 | return(ret); | ||
| 114 | err: | ||
| 115 | if (ret != NULL) X509_ATTRIBUTE_free(ret); | ||
| 116 | if (val != NULL) ASN1_TYPE_free(val); | ||
| 117 | return(NULL); | ||
| 118 | } | ||
diff --git a/src/lib/libcrypto/asn1/x_bignum.c b/src/lib/libcrypto/asn1/x_bignum.c new file mode 100644 index 0000000000..869c05d931 --- /dev/null +++ b/src/lib/libcrypto/asn1/x_bignum.c | |||
| @@ -0,0 +1,139 @@ | |||
| 1 | /* x_bignum.c */ | ||
| 2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
| 3 | * project 2000. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 2000 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/asn1t.h> | ||
| 62 | #include <openssl/bn.h> | ||
| 63 | |||
| 64 | /* Custom primitive type for BIGNUM handling. This reads in an ASN1_INTEGER as a | ||
| 65 | * BIGNUM directly. Currently it ignores the sign which isn't a problem since all | ||
| 66 | * BIGNUMs used are non negative and anything that looks negative is normally due | ||
| 67 | * to an encoding error. | ||
| 68 | */ | ||
| 69 | |||
| 70 | #define BN_SENSITIVE 1 | ||
| 71 | |||
| 72 | static int bn_new(ASN1_VALUE **pval, const ASN1_ITEM *it); | ||
| 73 | static void bn_free(ASN1_VALUE **pval, const ASN1_ITEM *it); | ||
| 74 | |||
| 75 | static int bn_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it); | ||
| 76 | static int bn_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it); | ||
| 77 | |||
| 78 | static ASN1_PRIMITIVE_FUNCS bignum_pf = { | ||
| 79 | NULL, 0, | ||
| 80 | bn_new, | ||
| 81 | bn_free, | ||
| 82 | 0, | ||
| 83 | bn_c2i, | ||
| 84 | bn_i2c | ||
| 85 | }; | ||
| 86 | |||
| 87 | ASN1_ITEM_start(BIGNUM) | ||
| 88 | ASN1_ITYPE_PRIMITIVE, V_ASN1_INTEGER, NULL, 0, &bignum_pf, 0, "BIGNUM" | ||
| 89 | ASN1_ITEM_end(BIGNUM) | ||
| 90 | |||
| 91 | ASN1_ITEM_start(CBIGNUM) | ||
| 92 | ASN1_ITYPE_PRIMITIVE, V_ASN1_INTEGER, NULL, 0, &bignum_pf, BN_SENSITIVE, "BIGNUM" | ||
| 93 | ASN1_ITEM_end(CBIGNUM) | ||
| 94 | |||
| 95 | static int bn_new(ASN1_VALUE **pval, const ASN1_ITEM *it) | ||
| 96 | { | ||
| 97 | *pval = (ASN1_VALUE *)BN_new(); | ||
| 98 | if(*pval) return 1; | ||
| 99 | else return 0; | ||
| 100 | } | ||
| 101 | |||
| 102 | static void bn_free(ASN1_VALUE **pval, const ASN1_ITEM *it) | ||
| 103 | { | ||
| 104 | if(!*pval) return; | ||
| 105 | if(it->size & BN_SENSITIVE) BN_clear_free((BIGNUM *)*pval); | ||
| 106 | else BN_free((BIGNUM *)*pval); | ||
| 107 | *pval = NULL; | ||
| 108 | } | ||
| 109 | |||
| 110 | static int bn_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it) | ||
| 111 | { | ||
| 112 | BIGNUM *bn; | ||
| 113 | int pad; | ||
| 114 | if(!*pval) return -1; | ||
| 115 | bn = (BIGNUM *)*pval; | ||
| 116 | /* If MSB set in an octet we need a padding byte */ | ||
| 117 | if(BN_num_bits(bn) & 0x7) pad = 0; | ||
| 118 | else pad = 1; | ||
| 119 | if(cont) { | ||
| 120 | if(pad) *cont++ = 0; | ||
| 121 | BN_bn2bin(bn, cont); | ||
| 122 | } | ||
| 123 | return pad + BN_num_bytes(bn); | ||
| 124 | } | ||
| 125 | |||
| 126 | static int bn_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, | ||
| 127 | int utype, char *free_cont, const ASN1_ITEM *it) | ||
| 128 | { | ||
| 129 | BIGNUM *bn; | ||
| 130 | if(!*pval) bn_new(pval, it); | ||
| 131 | bn = (BIGNUM *)*pval; | ||
| 132 | if(!BN_bin2bn(cont, len, bn)) { | ||
| 133 | bn_free(pval, it); | ||
| 134 | return 0; | ||
| 135 | } | ||
| 136 | return 1; | ||
| 137 | } | ||
| 138 | |||
| 139 | |||
diff --git a/src/lib/libcrypto/asn1/x_crl.c b/src/lib/libcrypto/asn1/x_crl.c new file mode 100644 index 0000000000..70d56a67f2 --- /dev/null +++ b/src/lib/libcrypto/asn1/x_crl.c | |||
| @@ -0,0 +1,140 @@ | |||
| 1 | /* crypto/asn1/x_crl.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/asn1t.h> | ||
| 62 | #include <openssl/x509.h> | ||
| 63 | |||
| 64 | static int X509_REVOKED_cmp(const X509_REVOKED * const *a, | ||
| 65 | const X509_REVOKED * const *b); | ||
| 66 | |||
| 67 | ASN1_SEQUENCE(X509_REVOKED) = { | ||
| 68 | ASN1_SIMPLE(X509_REVOKED,serialNumber, ASN1_INTEGER), | ||
| 69 | ASN1_SIMPLE(X509_REVOKED,revocationDate, ASN1_TIME), | ||
| 70 | ASN1_SEQUENCE_OF_OPT(X509_REVOKED,extensions, X509_EXTENSION) | ||
| 71 | } ASN1_SEQUENCE_END(X509_REVOKED) | ||
| 72 | |||
| 73 | /* The X509_CRL_INFO structure needs a bit of customisation. | ||
| 74 | * Since we cache the original encoding the signature wont be affected by | ||
| 75 | * reordering of the revoked field. | ||
| 76 | */ | ||
| 77 | static int crl_inf_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it) | ||
| 78 | { | ||
| 79 | X509_CRL_INFO *a = (X509_CRL_INFO *)*pval; | ||
| 80 | |||
| 81 | if(!a || !a->revoked) return 1; | ||
| 82 | switch(operation) { | ||
| 83 | /* Just set cmp function here. We don't sort because that | ||
| 84 | * would affect the output of X509_CRL_print(). | ||
| 85 | */ | ||
| 86 | case ASN1_OP_D2I_POST: | ||
| 87 | (void)sk_X509_REVOKED_set_cmp_func(a->revoked,X509_REVOKED_cmp); | ||
| 88 | break; | ||
| 89 | } | ||
| 90 | return 1; | ||
| 91 | } | ||
| 92 | |||
| 93 | |||
| 94 | ASN1_SEQUENCE_enc(X509_CRL_INFO, enc, crl_inf_cb) = { | ||
| 95 | ASN1_OPT(X509_CRL_INFO, version, ASN1_INTEGER), | ||
| 96 | ASN1_SIMPLE(X509_CRL_INFO, sig_alg, X509_ALGOR), | ||
| 97 | ASN1_SIMPLE(X509_CRL_INFO, issuer, X509_NAME), | ||
| 98 | ASN1_SIMPLE(X509_CRL_INFO, lastUpdate, ASN1_TIME), | ||
| 99 | ASN1_OPT(X509_CRL_INFO, nextUpdate, ASN1_TIME), | ||
| 100 | ASN1_SEQUENCE_OF_OPT(X509_CRL_INFO, revoked, X509_REVOKED), | ||
| 101 | ASN1_EXP_SEQUENCE_OF_OPT(X509_CRL_INFO, extensions, X509_EXTENSION, 0) | ||
| 102 | } ASN1_SEQUENCE_END_enc(X509_CRL_INFO, X509_CRL_INFO) | ||
| 103 | |||
| 104 | ASN1_SEQUENCE_ref(X509_CRL, 0, CRYPTO_LOCK_X509_CRL) = { | ||
| 105 | ASN1_SIMPLE(X509_CRL, crl, X509_CRL_INFO), | ||
| 106 | ASN1_SIMPLE(X509_CRL, sig_alg, X509_ALGOR), | ||
| 107 | ASN1_SIMPLE(X509_CRL, signature, ASN1_BIT_STRING) | ||
| 108 | } ASN1_SEQUENCE_END_ref(X509_CRL, X509_CRL) | ||
| 109 | |||
| 110 | IMPLEMENT_ASN1_FUNCTIONS(X509_REVOKED) | ||
| 111 | IMPLEMENT_ASN1_FUNCTIONS(X509_CRL_INFO) | ||
| 112 | IMPLEMENT_ASN1_FUNCTIONS(X509_CRL) | ||
| 113 | IMPLEMENT_ASN1_DUP_FUNCTION(X509_CRL) | ||
| 114 | |||
| 115 | static int X509_REVOKED_cmp(const X509_REVOKED * const *a, | ||
| 116 | const X509_REVOKED * const *b) | ||
| 117 | { | ||
| 118 | return(ASN1_STRING_cmp( | ||
| 119 | (ASN1_STRING *)(*a)->serialNumber, | ||
| 120 | (ASN1_STRING *)(*b)->serialNumber)); | ||
| 121 | } | ||
| 122 | |||
| 123 | int X509_CRL_add0_revoked(X509_CRL *crl, X509_REVOKED *rev) | ||
| 124 | { | ||
| 125 | X509_CRL_INFO *inf; | ||
| 126 | inf = crl->crl; | ||
| 127 | if(!inf->revoked) | ||
| 128 | inf->revoked = sk_X509_REVOKED_new(X509_REVOKED_cmp); | ||
| 129 | if(!inf->revoked || !sk_X509_REVOKED_push(inf->revoked, rev)) { | ||
| 130 | ASN1err(ASN1_F_X509_CRL_ADD0_REVOKED, ERR_R_MALLOC_FAILURE); | ||
| 131 | return 0; | ||
| 132 | } | ||
| 133 | inf->enc.modified = 1; | ||
| 134 | return 1; | ||
| 135 | } | ||
| 136 | |||
| 137 | IMPLEMENT_STACK_OF(X509_REVOKED) | ||
| 138 | IMPLEMENT_ASN1_SET_OF(X509_REVOKED) | ||
| 139 | IMPLEMENT_STACK_OF(X509_CRL) | ||
| 140 | IMPLEMENT_ASN1_SET_OF(X509_CRL) | ||
diff --git a/src/lib/libcrypto/asn1/x_exten.c b/src/lib/libcrypto/asn1/x_exten.c new file mode 100644 index 0000000000..1732e66712 --- /dev/null +++ b/src/lib/libcrypto/asn1/x_exten.c | |||
| @@ -0,0 +1,76 @@ | |||
| 1 | /* x_exten.c */ | ||
| 2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
| 3 | * project 2000. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 2000 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stddef.h> | ||
| 60 | #include <openssl/x509.h> | ||
| 61 | #include <openssl/asn1.h> | ||
| 62 | #include <openssl/asn1t.h> | ||
| 63 | |||
| 64 | ASN1_SEQUENCE(X509_EXTENSION) = { | ||
| 65 | ASN1_SIMPLE(X509_EXTENSION, object, ASN1_OBJECT), | ||
| 66 | ASN1_OPT(X509_EXTENSION, critical, ASN1_BOOLEAN), | ||
| 67 | ASN1_SIMPLE(X509_EXTENSION, value, ASN1_OCTET_STRING) | ||
| 68 | } ASN1_SEQUENCE_END(X509_EXTENSION) | ||
| 69 | |||
| 70 | ASN1_ITEM_TEMPLATE(X509_EXTENSIONS) = | ||
| 71 | ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, Extension, X509_EXTENSION) | ||
| 72 | ASN1_ITEM_TEMPLATE_END(X509_EXTENSIONS) | ||
| 73 | |||
| 74 | IMPLEMENT_ASN1_FUNCTIONS(X509_EXTENSION) | ||
| 75 | IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(X509_EXTENSIONS, X509_EXTENSIONS, X509_EXTENSIONS) | ||
| 76 | IMPLEMENT_ASN1_DUP_FUNCTION(X509_EXTENSION) | ||
diff --git a/src/lib/libcrypto/asn1/x_info.c b/src/lib/libcrypto/asn1/x_info.c new file mode 100644 index 0000000000..d44f6cdb01 --- /dev/null +++ b/src/lib/libcrypto/asn1/x_info.c | |||
| @@ -0,0 +1,114 @@ | |||
| 1 | /* crypto/asn1/x_info.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/evp.h> | ||
| 62 | #include <openssl/asn1.h> | ||
| 63 | #include <openssl/x509.h> | ||
| 64 | |||
| 65 | X509_INFO *X509_INFO_new(void) | ||
| 66 | { | ||
| 67 | X509_INFO *ret=NULL; | ||
| 68 | |||
| 69 | ret=(X509_INFO *)OPENSSL_malloc(sizeof(X509_INFO)); | ||
| 70 | if (ret == NULL) | ||
| 71 | { | ||
| 72 | ASN1err(ASN1_F_X509_INFO_NEW,ERR_R_MALLOC_FAILURE); | ||
| 73 | return(NULL); | ||
| 74 | } | ||
| 75 | |||
| 76 | ret->enc_cipher.cipher=NULL; | ||
| 77 | ret->enc_len=0; | ||
| 78 | ret->enc_data=NULL; | ||
| 79 | |||
| 80 | ret->references=1; | ||
| 81 | ret->x509=NULL; | ||
| 82 | ret->crl=NULL; | ||
| 83 | ret->x_pkey=NULL; | ||
| 84 | return(ret); | ||
| 85 | } | ||
| 86 | |||
| 87 | void X509_INFO_free(X509_INFO *x) | ||
| 88 | { | ||
| 89 | int i; | ||
| 90 | |||
| 91 | if (x == NULL) return; | ||
| 92 | |||
| 93 | i=CRYPTO_add(&x->references,-1,CRYPTO_LOCK_X509_INFO); | ||
| 94 | #ifdef REF_PRINT | ||
| 95 | REF_PRINT("X509_INFO",x); | ||
| 96 | #endif | ||
| 97 | if (i > 0) return; | ||
| 98 | #ifdef REF_CHECK | ||
| 99 | if (i < 0) | ||
| 100 | { | ||
| 101 | fprintf(stderr,"X509_INFO_free, bad reference count\n"); | ||
| 102 | abort(); | ||
| 103 | } | ||
| 104 | #endif | ||
| 105 | |||
| 106 | if (x->x509 != NULL) X509_free(x->x509); | ||
| 107 | if (x->crl != NULL) X509_CRL_free(x->crl); | ||
| 108 | if (x->x_pkey != NULL) X509_PKEY_free(x->x_pkey); | ||
| 109 | if (x->enc_data != NULL) OPENSSL_free(x->enc_data); | ||
| 110 | OPENSSL_free(x); | ||
| 111 | } | ||
| 112 | |||
| 113 | IMPLEMENT_STACK_OF(X509_INFO) | ||
| 114 | |||
diff --git a/src/lib/libcrypto/asn1/x_long.c b/src/lib/libcrypto/asn1/x_long.c new file mode 100644 index 0000000000..0db233cb95 --- /dev/null +++ b/src/lib/libcrypto/asn1/x_long.c | |||
| @@ -0,0 +1,171 @@ | |||
| 1 | /* x_long.c */ | ||
| 2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
| 3 | * project 2000. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 2000 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/asn1t.h> | ||
| 62 | #include <openssl/bn.h> | ||
| 63 | |||
| 64 | /* Custom primitive type for long handling. This converts between an ASN1_INTEGER | ||
| 65 | * and a long directly. | ||
| 66 | */ | ||
| 67 | |||
| 68 | |||
| 69 | static int long_new(ASN1_VALUE **pval, const ASN1_ITEM *it); | ||
| 70 | static void long_free(ASN1_VALUE **pval, const ASN1_ITEM *it); | ||
| 71 | |||
| 72 | static int long_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it); | ||
| 73 | static int long_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it); | ||
| 74 | |||
| 75 | static ASN1_PRIMITIVE_FUNCS long_pf = { | ||
| 76 | NULL, 0, | ||
| 77 | long_new, | ||
| 78 | long_free, | ||
| 79 | long_free, /* Clear should set to initial value */ | ||
| 80 | long_c2i, | ||
| 81 | long_i2c | ||
| 82 | }; | ||
| 83 | |||
| 84 | ASN1_ITEM_start(LONG) | ||
| 85 | ASN1_ITYPE_PRIMITIVE, V_ASN1_INTEGER, NULL, 0, &long_pf, ASN1_LONG_UNDEF, "LONG" | ||
| 86 | ASN1_ITEM_end(LONG) | ||
| 87 | |||
| 88 | ASN1_ITEM_start(ZLONG) | ||
| 89 | ASN1_ITYPE_PRIMITIVE, V_ASN1_INTEGER, NULL, 0, &long_pf, 0, "ZLONG" | ||
| 90 | ASN1_ITEM_end(ZLONG) | ||
| 91 | |||
| 92 | static int long_new(ASN1_VALUE **pval, const ASN1_ITEM *it) | ||
| 93 | { | ||
| 94 | *(long *)pval = it->size; | ||
| 95 | return 1; | ||
| 96 | } | ||
| 97 | |||
| 98 | static void long_free(ASN1_VALUE **pval, const ASN1_ITEM *it) | ||
| 99 | { | ||
| 100 | *(long *)pval = it->size; | ||
| 101 | } | ||
| 102 | |||
| 103 | static int long_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it) | ||
| 104 | { | ||
| 105 | long ltmp; | ||
| 106 | unsigned long utmp; | ||
| 107 | int clen, pad, i; | ||
| 108 | /* this exists to bypass broken gcc optimization */ | ||
| 109 | char *cp = (char *)pval; | ||
| 110 | |||
| 111 | /* use memcpy, because we may not be long aligned */ | ||
| 112 | memcpy(<mp, cp, sizeof(long)); | ||
| 113 | |||
| 114 | if(ltmp == it->size) return -1; | ||
| 115 | /* Convert the long to positive: we subtract one if negative so | ||
| 116 | * we can cleanly handle the padding if only the MSB of the leading | ||
| 117 | * octet is set. | ||
| 118 | */ | ||
| 119 | if(ltmp < 0) utmp = -ltmp - 1; | ||
| 120 | else utmp = ltmp; | ||
| 121 | clen = BN_num_bits_word(utmp); | ||
| 122 | /* If MSB of leading octet set we need to pad */ | ||
| 123 | if(!(clen & 0x7)) pad = 1; | ||
| 124 | else pad = 0; | ||
| 125 | |||
| 126 | /* Convert number of bits to number of octets */ | ||
| 127 | clen = (clen + 7) >> 3; | ||
| 128 | |||
| 129 | if(cont) { | ||
| 130 | if(pad) *cont++ = (ltmp < 0) ? 0xff : 0; | ||
| 131 | for(i = clen - 1; i >= 0; i--) { | ||
| 132 | cont[i] = (unsigned char)(utmp & 0xff); | ||
| 133 | if(ltmp < 0) cont[i] ^= 0xff; | ||
| 134 | utmp >>= 8; | ||
| 135 | } | ||
| 136 | } | ||
| 137 | return clen + pad; | ||
| 138 | } | ||
| 139 | |||
| 140 | static int long_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, | ||
| 141 | int utype, char *free_cont, const ASN1_ITEM *it) | ||
| 142 | { | ||
| 143 | int neg, i; | ||
| 144 | long ltmp; | ||
| 145 | unsigned long utmp = 0; | ||
| 146 | char *cp = (char *)pval; | ||
| 147 | if(len > (int)sizeof(long)) { | ||
| 148 | ASN1err(ASN1_F_LONG_C2I, ASN1_R_INTEGER_TOO_LARGE_FOR_LONG); | ||
| 149 | return 0; | ||
| 150 | } | ||
| 151 | /* Is it negative? */ | ||
| 152 | if(len && (cont[0] & 0x80)) neg = 1; | ||
| 153 | else neg = 0; | ||
| 154 | utmp = 0; | ||
| 155 | for(i = 0; i < len; i++) { | ||
| 156 | utmp <<= 8; | ||
| 157 | if(neg) utmp |= cont[i] ^ 0xff; | ||
| 158 | else utmp |= cont[i]; | ||
| 159 | } | ||
| 160 | ltmp = (long)utmp; | ||
| 161 | if(neg) { | ||
| 162 | ltmp++; | ||
| 163 | ltmp = -ltmp; | ||
| 164 | } | ||
| 165 | if(ltmp == it->size) { | ||
| 166 | ASN1err(ASN1_F_LONG_C2I, ASN1_R_INTEGER_TOO_LARGE_FOR_LONG); | ||
| 167 | return 0; | ||
| 168 | } | ||
| 169 | memcpy(cp, <mp, sizeof(long)); | ||
| 170 | return 1; | ||
| 171 | } | ||
diff --git a/src/lib/libcrypto/asn1/x_name.c b/src/lib/libcrypto/asn1/x_name.c new file mode 100644 index 0000000000..04380abc3f --- /dev/null +++ b/src/lib/libcrypto/asn1/x_name.c | |||
| @@ -0,0 +1,275 @@ | |||
| 1 | /* crypto/asn1/x_name.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/asn1t.h> | ||
| 62 | #include <openssl/x509.h> | ||
| 63 | |||
| 64 | static int x509_name_ex_d2i(ASN1_VALUE **val, const unsigned char **in, long len, const ASN1_ITEM *it, | ||
| 65 | int tag, int aclass, char opt, ASN1_TLC *ctx); | ||
| 66 | |||
| 67 | static int x509_name_ex_i2d(ASN1_VALUE **val, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass); | ||
| 68 | static int x509_name_ex_new(ASN1_VALUE **val, const ASN1_ITEM *it); | ||
| 69 | static void x509_name_ex_free(ASN1_VALUE **val, const ASN1_ITEM *it); | ||
| 70 | |||
| 71 | static int x509_name_encode(X509_NAME *a); | ||
| 72 | |||
| 73 | ASN1_SEQUENCE(X509_NAME_ENTRY) = { | ||
| 74 | ASN1_SIMPLE(X509_NAME_ENTRY, object, ASN1_OBJECT), | ||
| 75 | ASN1_SIMPLE(X509_NAME_ENTRY, value, ASN1_PRINTABLE) | ||
| 76 | } ASN1_SEQUENCE_END(X509_NAME_ENTRY) | ||
| 77 | |||
| 78 | IMPLEMENT_ASN1_FUNCTIONS(X509_NAME_ENTRY) | ||
| 79 | IMPLEMENT_ASN1_DUP_FUNCTION(X509_NAME_ENTRY) | ||
| 80 | |||
| 81 | /* For the "Name" type we need a SEQUENCE OF { SET OF X509_NAME_ENTRY } | ||
| 82 | * so declare two template wrappers for this | ||
| 83 | */ | ||
| 84 | |||
| 85 | ASN1_ITEM_TEMPLATE(X509_NAME_ENTRIES) = | ||
| 86 | ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SET_OF, 0, RDNS, X509_NAME_ENTRY) | ||
| 87 | ASN1_ITEM_TEMPLATE_END(X509_NAME_ENTRIES) | ||
| 88 | |||
| 89 | ASN1_ITEM_TEMPLATE(X509_NAME_INTERNAL) = | ||
| 90 | ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, Name, X509_NAME_ENTRIES) | ||
| 91 | ASN1_ITEM_TEMPLATE_END(X509_NAME_INTERNAL) | ||
| 92 | |||
| 93 | /* Normally that's where it would end: we'd have two nested STACK structures | ||
| 94 | * representing the ASN1. Unfortunately X509_NAME uses a completely different | ||
| 95 | * form and caches encodings so we have to process the internal form and convert | ||
| 96 | * to the external form. | ||
| 97 | */ | ||
| 98 | |||
| 99 | const ASN1_EXTERN_FUNCS x509_name_ff = { | ||
| 100 | NULL, | ||
| 101 | x509_name_ex_new, | ||
| 102 | x509_name_ex_free, | ||
| 103 | 0, /* Default clear behaviour is OK */ | ||
| 104 | x509_name_ex_d2i, | ||
| 105 | x509_name_ex_i2d | ||
| 106 | }; | ||
| 107 | |||
| 108 | IMPLEMENT_EXTERN_ASN1(X509_NAME, V_ASN1_SEQUENCE, x509_name_ff) | ||
| 109 | |||
| 110 | IMPLEMENT_ASN1_FUNCTIONS(X509_NAME) | ||
| 111 | IMPLEMENT_ASN1_DUP_FUNCTION(X509_NAME) | ||
| 112 | |||
| 113 | static int x509_name_ex_new(ASN1_VALUE **val, const ASN1_ITEM *it) | ||
| 114 | { | ||
| 115 | X509_NAME *ret = NULL; | ||
| 116 | ret = OPENSSL_malloc(sizeof(X509_NAME)); | ||
| 117 | if(!ret) goto memerr; | ||
| 118 | if ((ret->entries=sk_X509_NAME_ENTRY_new_null()) == NULL) | ||
| 119 | goto memerr; | ||
| 120 | if((ret->bytes = BUF_MEM_new()) == NULL) goto memerr; | ||
| 121 | ret->modified=1; | ||
| 122 | *val = (ASN1_VALUE *)ret; | ||
| 123 | return 1; | ||
| 124 | |||
| 125 | memerr: | ||
| 126 | ASN1err(ASN1_F_X509_NAME_EX_NEW, ERR_R_MALLOC_FAILURE); | ||
| 127 | if (ret) | ||
| 128 | { | ||
| 129 | if (ret->entries) | ||
| 130 | sk_X509_NAME_ENTRY_free(ret->entries); | ||
| 131 | OPENSSL_free(ret); | ||
| 132 | } | ||
| 133 | return 0; | ||
| 134 | } | ||
| 135 | |||
| 136 | static void x509_name_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it) | ||
| 137 | { | ||
| 138 | X509_NAME *a; | ||
| 139 | if(!pval || !*pval) | ||
| 140 | return; | ||
| 141 | a = (X509_NAME *)*pval; | ||
| 142 | |||
| 143 | BUF_MEM_free(a->bytes); | ||
| 144 | sk_X509_NAME_ENTRY_pop_free(a->entries,X509_NAME_ENTRY_free); | ||
| 145 | OPENSSL_free(a); | ||
| 146 | *pval = NULL; | ||
| 147 | } | ||
| 148 | |||
| 149 | /* Used with sk_pop_free() to free up the internal representation. | ||
| 150 | * NB: we only free the STACK and not its contents because it is | ||
| 151 | * already present in the X509_NAME structure. | ||
| 152 | */ | ||
| 153 | |||
| 154 | static void sk_internal_free(void *a) | ||
| 155 | { | ||
| 156 | sk_free(a); | ||
| 157 | } | ||
| 158 | |||
| 159 | static int x509_name_ex_d2i(ASN1_VALUE **val, const unsigned char **in, long len, const ASN1_ITEM *it, | ||
| 160 | int tag, int aclass, char opt, ASN1_TLC *ctx) | ||
| 161 | { | ||
| 162 | const unsigned char *p = *in, *q; | ||
| 163 | union { STACK *s; ASN1_VALUE *a; } intname = {NULL}; | ||
| 164 | union { X509_NAME *x; ASN1_VALUE *a; } nm = {NULL}; | ||
| 165 | int i, j, ret; | ||
| 166 | STACK_OF(X509_NAME_ENTRY) *entries; | ||
| 167 | X509_NAME_ENTRY *entry; | ||
| 168 | q = p; | ||
| 169 | |||
| 170 | /* Get internal representation of Name */ | ||
| 171 | ret = ASN1_item_ex_d2i(&intname.a, | ||
| 172 | &p, len, ASN1_ITEM_rptr(X509_NAME_INTERNAL), | ||
| 173 | tag, aclass, opt, ctx); | ||
| 174 | |||
| 175 | if(ret <= 0) return ret; | ||
| 176 | |||
| 177 | if(*val) x509_name_ex_free(val, NULL); | ||
| 178 | if(!x509_name_ex_new(&nm.a, NULL)) goto err; | ||
| 179 | /* We've decoded it: now cache encoding */ | ||
| 180 | if(!BUF_MEM_grow(nm.x->bytes, p - q)) goto err; | ||
| 181 | memcpy(nm.x->bytes->data, q, p - q); | ||
| 182 | |||
| 183 | /* Convert internal representation to X509_NAME structure */ | ||
| 184 | for(i = 0; i < sk_num(intname.s); i++) { | ||
| 185 | entries = (STACK_OF(X509_NAME_ENTRY) *)sk_value(intname.s, i); | ||
| 186 | for(j = 0; j < sk_X509_NAME_ENTRY_num(entries); j++) { | ||
| 187 | entry = sk_X509_NAME_ENTRY_value(entries, j); | ||
| 188 | entry->set = i; | ||
| 189 | if(!sk_X509_NAME_ENTRY_push(nm.x->entries, entry)) | ||
| 190 | goto err; | ||
| 191 | } | ||
| 192 | sk_X509_NAME_ENTRY_free(entries); | ||
| 193 | } | ||
| 194 | sk_free(intname.s); | ||
| 195 | nm.x->modified = 0; | ||
| 196 | *val = nm.a; | ||
| 197 | *in = p; | ||
| 198 | return ret; | ||
| 199 | err: | ||
| 200 | ASN1err(ASN1_F_X509_NAME_EX_D2I, ERR_R_NESTED_ASN1_ERROR); | ||
| 201 | return 0; | ||
| 202 | } | ||
| 203 | |||
| 204 | static int x509_name_ex_i2d(ASN1_VALUE **val, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass) | ||
| 205 | { | ||
| 206 | int ret; | ||
| 207 | X509_NAME *a = (X509_NAME *)*val; | ||
| 208 | if(a->modified) { | ||
| 209 | ret = x509_name_encode((X509_NAME *)a); | ||
| 210 | if(ret < 0) return ret; | ||
| 211 | } | ||
| 212 | ret = a->bytes->length; | ||
| 213 | if(out != NULL) { | ||
| 214 | memcpy(*out,a->bytes->data,ret); | ||
| 215 | *out+=ret; | ||
| 216 | } | ||
| 217 | return ret; | ||
| 218 | } | ||
| 219 | |||
| 220 | static int x509_name_encode(X509_NAME *a) | ||
| 221 | { | ||
| 222 | union { STACK *s; ASN1_VALUE *a; } intname = {NULL}; | ||
| 223 | int len; | ||
| 224 | unsigned char *p; | ||
| 225 | STACK_OF(X509_NAME_ENTRY) *entries = NULL; | ||
| 226 | X509_NAME_ENTRY *entry; | ||
| 227 | int i, set = -1; | ||
| 228 | intname.s = sk_new_null(); | ||
| 229 | if(!intname.s) goto memerr; | ||
| 230 | for(i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++) { | ||
| 231 | entry = sk_X509_NAME_ENTRY_value(a->entries, i); | ||
| 232 | if(entry->set != set) { | ||
| 233 | entries = sk_X509_NAME_ENTRY_new_null(); | ||
| 234 | if(!entries) goto memerr; | ||
| 235 | if(!sk_push(intname.s, (char *)entries)) goto memerr; | ||
| 236 | set = entry->set; | ||
| 237 | } | ||
| 238 | if(!sk_X509_NAME_ENTRY_push(entries, entry)) goto memerr; | ||
| 239 | } | ||
| 240 | len = ASN1_item_ex_i2d(&intname.a, NULL, | ||
| 241 | ASN1_ITEM_rptr(X509_NAME_INTERNAL), -1, -1); | ||
| 242 | if (!BUF_MEM_grow(a->bytes,len)) goto memerr; | ||
| 243 | p=(unsigned char *)a->bytes->data; | ||
| 244 | ASN1_item_ex_i2d(&intname.a, | ||
| 245 | &p, ASN1_ITEM_rptr(X509_NAME_INTERNAL), -1, -1); | ||
| 246 | sk_pop_free(intname.s, sk_internal_free); | ||
| 247 | a->modified = 0; | ||
| 248 | return len; | ||
| 249 | memerr: | ||
| 250 | sk_pop_free(intname.s, sk_internal_free); | ||
| 251 | ASN1err(ASN1_F_X509_NAME_ENCODE, ERR_R_MALLOC_FAILURE); | ||
| 252 | return -1; | ||
| 253 | } | ||
| 254 | |||
| 255 | |||
| 256 | int X509_NAME_set(X509_NAME **xn, X509_NAME *name) | ||
| 257 | { | ||
| 258 | X509_NAME *in; | ||
| 259 | |||
| 260 | if (!xn || !name) return(0); | ||
| 261 | |||
| 262 | if (*xn != name) | ||
| 263 | { | ||
| 264 | in=X509_NAME_dup(name); | ||
| 265 | if (in != NULL) | ||
| 266 | { | ||
| 267 | X509_NAME_free(*xn); | ||
| 268 | *xn=in; | ||
| 269 | } | ||
| 270 | } | ||
| 271 | return(*xn != NULL); | ||
| 272 | } | ||
| 273 | |||
| 274 | IMPLEMENT_STACK_OF(X509_NAME_ENTRY) | ||
| 275 | IMPLEMENT_ASN1_SET_OF(X509_NAME_ENTRY) | ||
diff --git a/src/lib/libcrypto/asn1/x_pkey.c b/src/lib/libcrypto/asn1/x_pkey.c new file mode 100644 index 0000000000..8453618426 --- /dev/null +++ b/src/lib/libcrypto/asn1/x_pkey.c | |||
| @@ -0,0 +1,151 @@ | |||
| 1 | /* crypto/asn1/x_pkey.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/evp.h> | ||
| 62 | #include <openssl/objects.h> | ||
| 63 | #include <openssl/asn1_mac.h> | ||
| 64 | #include <openssl/x509.h> | ||
| 65 | |||
| 66 | /* need to implement */ | ||
| 67 | int i2d_X509_PKEY(X509_PKEY *a, unsigned char **pp) | ||
| 68 | { | ||
| 69 | return(0); | ||
| 70 | } | ||
| 71 | |||
| 72 | X509_PKEY *d2i_X509_PKEY(X509_PKEY **a, const unsigned char **pp, long length) | ||
| 73 | { | ||
| 74 | int i; | ||
| 75 | M_ASN1_D2I_vars(a,X509_PKEY *,X509_PKEY_new); | ||
| 76 | |||
| 77 | M_ASN1_D2I_Init(); | ||
| 78 | M_ASN1_D2I_start_sequence(); | ||
| 79 | M_ASN1_D2I_get_x(X509_ALGOR,ret->enc_algor,d2i_X509_ALGOR); | ||
| 80 | M_ASN1_D2I_get_x(ASN1_OCTET_STRING,ret->enc_pkey,d2i_ASN1_OCTET_STRING); | ||
| 81 | |||
| 82 | ret->cipher.cipher=EVP_get_cipherbyname( | ||
| 83 | OBJ_nid2ln(OBJ_obj2nid(ret->enc_algor->algorithm))); | ||
| 84 | if (ret->cipher.cipher == NULL) | ||
| 85 | { | ||
| 86 | c.error=ASN1_R_UNSUPPORTED_CIPHER; | ||
| 87 | c.line=__LINE__; | ||
| 88 | goto err; | ||
| 89 | } | ||
| 90 | if (ret->enc_algor->parameter->type == V_ASN1_OCTET_STRING) | ||
| 91 | { | ||
| 92 | i=ret->enc_algor->parameter->value.octet_string->length; | ||
| 93 | if (i > EVP_MAX_IV_LENGTH) | ||
| 94 | { | ||
| 95 | c.error=ASN1_R_IV_TOO_LARGE; | ||
| 96 | c.line=__LINE__; | ||
| 97 | goto err; | ||
| 98 | } | ||
| 99 | memcpy(ret->cipher.iv, | ||
| 100 | ret->enc_algor->parameter->value.octet_string->data,i); | ||
| 101 | } | ||
| 102 | else | ||
| 103 | memset(ret->cipher.iv,0,EVP_MAX_IV_LENGTH); | ||
| 104 | M_ASN1_D2I_Finish(a,X509_PKEY_free,ASN1_F_D2I_X509_PKEY); | ||
| 105 | } | ||
| 106 | |||
| 107 | X509_PKEY *X509_PKEY_new(void) | ||
| 108 | { | ||
| 109 | X509_PKEY *ret=NULL; | ||
| 110 | ASN1_CTX c; | ||
| 111 | |||
| 112 | M_ASN1_New_Malloc(ret,X509_PKEY); | ||
| 113 | ret->version=0; | ||
| 114 | M_ASN1_New(ret->enc_algor,X509_ALGOR_new); | ||
| 115 | M_ASN1_New(ret->enc_pkey,M_ASN1_OCTET_STRING_new); | ||
| 116 | ret->dec_pkey=NULL; | ||
| 117 | ret->key_length=0; | ||
| 118 | ret->key_data=NULL; | ||
| 119 | ret->key_free=0; | ||
| 120 | ret->cipher.cipher=NULL; | ||
| 121 | memset(ret->cipher.iv,0,EVP_MAX_IV_LENGTH); | ||
| 122 | ret->references=1; | ||
| 123 | return(ret); | ||
| 124 | M_ASN1_New_Error(ASN1_F_X509_PKEY_NEW); | ||
| 125 | } | ||
| 126 | |||
| 127 | void X509_PKEY_free(X509_PKEY *x) | ||
| 128 | { | ||
| 129 | int i; | ||
| 130 | |||
| 131 | if (x == NULL) return; | ||
| 132 | |||
| 133 | i=CRYPTO_add(&x->references,-1,CRYPTO_LOCK_X509_PKEY); | ||
| 134 | #ifdef REF_PRINT | ||
| 135 | REF_PRINT("X509_PKEY",x); | ||
| 136 | #endif | ||
| 137 | if (i > 0) return; | ||
| 138 | #ifdef REF_CHECK | ||
| 139 | if (i < 0) | ||
| 140 | { | ||
| 141 | fprintf(stderr,"X509_PKEY_free, bad reference count\n"); | ||
| 142 | abort(); | ||
| 143 | } | ||
| 144 | #endif | ||
| 145 | |||
| 146 | if (x->enc_algor != NULL) X509_ALGOR_free(x->enc_algor); | ||
| 147 | if (x->enc_pkey != NULL) M_ASN1_OCTET_STRING_free(x->enc_pkey); | ||
| 148 | if (x->dec_pkey != NULL)EVP_PKEY_free(x->dec_pkey); | ||
| 149 | if ((x->key_data != NULL) && (x->key_free)) OPENSSL_free(x->key_data); | ||
| 150 | OPENSSL_free(x); | ||
| 151 | } | ||
diff --git a/src/lib/libcrypto/asn1/x_pubkey.c b/src/lib/libcrypto/asn1/x_pubkey.c new file mode 100644 index 0000000000..91c2756116 --- /dev/null +++ b/src/lib/libcrypto/asn1/x_pubkey.c | |||
| @@ -0,0 +1,531 @@ | |||
| 1 | /* crypto/asn1/x_pubkey.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/asn1t.h> | ||
| 62 | #include <openssl/x509.h> | ||
| 63 | #ifndef OPENSSL_NO_RSA | ||
| 64 | #include <openssl/rsa.h> | ||
| 65 | #endif | ||
| 66 | #ifndef OPENSSL_NO_DSA | ||
| 67 | #include <openssl/dsa.h> | ||
| 68 | #endif | ||
| 69 | |||
| 70 | /* Minor tweak to operation: free up EVP_PKEY */ | ||
| 71 | static int pubkey_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it) | ||
| 72 | { | ||
| 73 | if (operation == ASN1_OP_FREE_POST) | ||
| 74 | { | ||
| 75 | X509_PUBKEY *pubkey = (X509_PUBKEY *)*pval; | ||
| 76 | EVP_PKEY_free(pubkey->pkey); | ||
| 77 | } | ||
| 78 | return 1; | ||
| 79 | } | ||
| 80 | |||
| 81 | ASN1_SEQUENCE_cb(X509_PUBKEY, pubkey_cb) = { | ||
| 82 | ASN1_SIMPLE(X509_PUBKEY, algor, X509_ALGOR), | ||
| 83 | ASN1_SIMPLE(X509_PUBKEY, public_key, ASN1_BIT_STRING) | ||
| 84 | } ASN1_SEQUENCE_END_cb(X509_PUBKEY, X509_PUBKEY) | ||
| 85 | |||
| 86 | IMPLEMENT_ASN1_FUNCTIONS(X509_PUBKEY) | ||
| 87 | |||
| 88 | int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey) | ||
| 89 | { | ||
| 90 | X509_PUBKEY *pk=NULL; | ||
| 91 | X509_ALGOR *a; | ||
| 92 | ASN1_OBJECT *o; | ||
| 93 | unsigned char *s,*p = NULL; | ||
| 94 | int i; | ||
| 95 | |||
| 96 | if (x == NULL) return(0); | ||
| 97 | |||
| 98 | if ((pk=X509_PUBKEY_new()) == NULL) goto err; | ||
| 99 | a=pk->algor; | ||
| 100 | |||
| 101 | /* set the algorithm id */ | ||
| 102 | if ((o=OBJ_nid2obj(pkey->type)) == NULL) goto err; | ||
| 103 | ASN1_OBJECT_free(a->algorithm); | ||
| 104 | a->algorithm=o; | ||
| 105 | |||
| 106 | /* Set the parameter list */ | ||
| 107 | if (!pkey->save_parameters || (pkey->type == EVP_PKEY_RSA)) | ||
| 108 | { | ||
| 109 | if ((a->parameter == NULL) || | ||
| 110 | (a->parameter->type != V_ASN1_NULL)) | ||
| 111 | { | ||
| 112 | ASN1_TYPE_free(a->parameter); | ||
| 113 | if (!(a->parameter=ASN1_TYPE_new())) | ||
| 114 | { | ||
| 115 | X509err(X509_F_X509_PUBKEY_SET,ERR_R_MALLOC_FAILURE); | ||
| 116 | goto err; | ||
| 117 | } | ||
| 118 | a->parameter->type=V_ASN1_NULL; | ||
| 119 | } | ||
| 120 | } | ||
| 121 | #ifndef OPENSSL_NO_DSA | ||
| 122 | else if (pkey->type == EVP_PKEY_DSA) | ||
| 123 | { | ||
| 124 | unsigned char *pp; | ||
| 125 | DSA *dsa; | ||
| 126 | |||
| 127 | dsa=pkey->pkey.dsa; | ||
| 128 | dsa->write_params=0; | ||
| 129 | ASN1_TYPE_free(a->parameter); | ||
| 130 | if ((i=i2d_DSAparams(dsa,NULL)) <= 0) | ||
| 131 | goto err; | ||
| 132 | if (!(p=(unsigned char *)OPENSSL_malloc(i))) | ||
| 133 | { | ||
| 134 | X509err(X509_F_X509_PUBKEY_SET,ERR_R_MALLOC_FAILURE); | ||
| 135 | goto err; | ||
| 136 | } | ||
| 137 | pp=p; | ||
| 138 | i2d_DSAparams(dsa,&pp); | ||
| 139 | if (!(a->parameter=ASN1_TYPE_new())) | ||
| 140 | { | ||
| 141 | OPENSSL_free(p); | ||
| 142 | X509err(X509_F_X509_PUBKEY_SET,ERR_R_MALLOC_FAILURE); | ||
| 143 | goto err; | ||
| 144 | } | ||
| 145 | a->parameter->type=V_ASN1_SEQUENCE; | ||
| 146 | if (!(a->parameter->value.sequence=ASN1_STRING_new())) | ||
| 147 | { | ||
| 148 | OPENSSL_free(p); | ||
| 149 | X509err(X509_F_X509_PUBKEY_SET,ERR_R_MALLOC_FAILURE); | ||
| 150 | goto err; | ||
| 151 | } | ||
| 152 | if (!ASN1_STRING_set(a->parameter->value.sequence,p,i)) | ||
| 153 | { | ||
| 154 | OPENSSL_free(p); | ||
| 155 | X509err(X509_F_X509_PUBKEY_SET,ERR_R_MALLOC_FAILURE); | ||
| 156 | goto err; | ||
| 157 | } | ||
| 158 | OPENSSL_free(p); | ||
| 159 | } | ||
| 160 | #endif | ||
| 161 | #ifndef OPENSSL_NO_EC | ||
| 162 | else if (pkey->type == EVP_PKEY_EC) | ||
| 163 | { | ||
| 164 | int nid=0; | ||
| 165 | unsigned char *pp; | ||
| 166 | EC_KEY *ec_key; | ||
| 167 | const EC_GROUP *group; | ||
| 168 | |||
| 169 | ec_key = pkey->pkey.ec; | ||
| 170 | ASN1_TYPE_free(a->parameter); | ||
| 171 | |||
| 172 | if ((a->parameter = ASN1_TYPE_new()) == NULL) | ||
| 173 | { | ||
| 174 | X509err(X509_F_X509_PUBKEY_SET, ERR_R_ASN1_LIB); | ||
| 175 | goto err; | ||
| 176 | } | ||
| 177 | |||
| 178 | group = EC_KEY_get0_group(ec_key); | ||
| 179 | if (EC_GROUP_get_asn1_flag(group) | ||
| 180 | && (nid = EC_GROUP_get_curve_name(group))) | ||
| 181 | { | ||
| 182 | /* just set the OID */ | ||
| 183 | a->parameter->type = V_ASN1_OBJECT; | ||
| 184 | a->parameter->value.object = OBJ_nid2obj(nid); | ||
| 185 | } | ||
| 186 | else /* explicit parameters */ | ||
| 187 | { | ||
| 188 | if ((i = i2d_ECParameters(ec_key, NULL)) == 0) | ||
| 189 | { | ||
| 190 | X509err(X509_F_X509_PUBKEY_SET, ERR_R_EC_LIB); | ||
| 191 | goto err; | ||
| 192 | } | ||
| 193 | if ((p = (unsigned char *) OPENSSL_malloc(i)) == NULL) | ||
| 194 | { | ||
| 195 | X509err(X509_F_X509_PUBKEY_SET, ERR_R_MALLOC_FAILURE); | ||
| 196 | goto err; | ||
| 197 | } | ||
| 198 | pp = p; | ||
| 199 | if (!i2d_ECParameters(ec_key, &pp)) | ||
| 200 | { | ||
| 201 | X509err(X509_F_X509_PUBKEY_SET, ERR_R_EC_LIB); | ||
| 202 | OPENSSL_free(p); | ||
| 203 | goto err; | ||
| 204 | } | ||
| 205 | a->parameter->type = V_ASN1_SEQUENCE; | ||
| 206 | if ((a->parameter->value.sequence = ASN1_STRING_new()) == NULL) | ||
| 207 | { | ||
| 208 | X509err(X509_F_X509_PUBKEY_SET, ERR_R_ASN1_LIB); | ||
| 209 | OPENSSL_free(p); | ||
| 210 | goto err; | ||
| 211 | } | ||
| 212 | ASN1_STRING_set(a->parameter->value.sequence, p, i); | ||
| 213 | OPENSSL_free(p); | ||
| 214 | } | ||
| 215 | } | ||
| 216 | #endif | ||
| 217 | else if (1) | ||
| 218 | { | ||
| 219 | X509err(X509_F_X509_PUBKEY_SET,X509_R_UNSUPPORTED_ALGORITHM); | ||
| 220 | goto err; | ||
| 221 | } | ||
| 222 | |||
| 223 | if ((i=i2d_PublicKey(pkey,NULL)) <= 0) goto err; | ||
| 224 | if ((s=(unsigned char *)OPENSSL_malloc(i+1)) == NULL) | ||
| 225 | { | ||
| 226 | X509err(X509_F_X509_PUBKEY_SET,ERR_R_MALLOC_FAILURE); | ||
| 227 | goto err; | ||
| 228 | } | ||
| 229 | p=s; | ||
| 230 | i2d_PublicKey(pkey,&p); | ||
| 231 | if (!M_ASN1_BIT_STRING_set(pk->public_key,s,i)) | ||
| 232 | { | ||
| 233 | X509err(X509_F_X509_PUBKEY_SET,ERR_R_MALLOC_FAILURE); | ||
| 234 | goto err; | ||
| 235 | } | ||
| 236 | /* Set number of unused bits to zero */ | ||
| 237 | pk->public_key->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); | ||
| 238 | pk->public_key->flags|=ASN1_STRING_FLAG_BITS_LEFT; | ||
| 239 | |||
| 240 | OPENSSL_free(s); | ||
| 241 | |||
| 242 | #if 0 | ||
| 243 | CRYPTO_add(&pkey->references,1,CRYPTO_LOCK_EVP_PKEY); | ||
| 244 | pk->pkey=pkey; | ||
| 245 | #endif | ||
| 246 | |||
| 247 | if (*x != NULL) | ||
| 248 | X509_PUBKEY_free(*x); | ||
| 249 | |||
| 250 | *x=pk; | ||
| 251 | |||
| 252 | return 1; | ||
| 253 | err: | ||
| 254 | if (pk != NULL) X509_PUBKEY_free(pk); | ||
| 255 | return 0; | ||
| 256 | } | ||
| 257 | |||
| 258 | EVP_PKEY *X509_PUBKEY_get(X509_PUBKEY *key) | ||
| 259 | { | ||
| 260 | EVP_PKEY *ret=NULL; | ||
| 261 | long j; | ||
| 262 | int type; | ||
| 263 | const unsigned char *p; | ||
| 264 | #if !defined(OPENSSL_NO_DSA) || !defined(OPENSSL_NO_ECDSA) | ||
| 265 | const unsigned char *cp; | ||
| 266 | X509_ALGOR *a; | ||
| 267 | #endif | ||
| 268 | |||
| 269 | if (key == NULL) goto err; | ||
| 270 | |||
| 271 | if (key->pkey != NULL) | ||
| 272 | { | ||
| 273 | CRYPTO_add(&key->pkey->references, 1, CRYPTO_LOCK_EVP_PKEY); | ||
| 274 | return(key->pkey); | ||
| 275 | } | ||
| 276 | |||
| 277 | if (key->public_key == NULL) goto err; | ||
| 278 | |||
| 279 | type=OBJ_obj2nid(key->algor->algorithm); | ||
| 280 | if ((ret = EVP_PKEY_new()) == NULL) | ||
| 281 | { | ||
| 282 | X509err(X509_F_X509_PUBKEY_GET, ERR_R_MALLOC_FAILURE); | ||
| 283 | goto err; | ||
| 284 | } | ||
| 285 | ret->type = EVP_PKEY_type(type); | ||
| 286 | |||
| 287 | /* the parameters must be extracted before the public key (ECDSA!) */ | ||
| 288 | |||
| 289 | #if !defined(OPENSSL_NO_DSA) || !defined(OPENSSL_NO_ECDSA) | ||
| 290 | a=key->algor; | ||
| 291 | #endif | ||
| 292 | |||
| 293 | if (0) | ||
| 294 | ; | ||
| 295 | #ifndef OPENSSL_NO_DSA | ||
| 296 | else if (ret->type == EVP_PKEY_DSA) | ||
| 297 | { | ||
| 298 | if (a->parameter && (a->parameter->type == V_ASN1_SEQUENCE)) | ||
| 299 | { | ||
| 300 | if ((ret->pkey.dsa = DSA_new()) == NULL) | ||
| 301 | { | ||
| 302 | X509err(X509_F_X509_PUBKEY_GET, ERR_R_MALLOC_FAILURE); | ||
| 303 | goto err; | ||
| 304 | } | ||
| 305 | ret->pkey.dsa->write_params=0; | ||
| 306 | cp=p=a->parameter->value.sequence->data; | ||
| 307 | j=a->parameter->value.sequence->length; | ||
| 308 | if (!d2i_DSAparams(&ret->pkey.dsa, &cp, (long)j)) | ||
| 309 | goto err; | ||
| 310 | } | ||
| 311 | ret->save_parameters=1; | ||
| 312 | } | ||
| 313 | #endif | ||
| 314 | #ifndef OPENSSL_NO_EC | ||
| 315 | else if (ret->type == EVP_PKEY_EC) | ||
| 316 | { | ||
| 317 | if (a->parameter && (a->parameter->type == V_ASN1_SEQUENCE)) | ||
| 318 | { | ||
| 319 | /* type == V_ASN1_SEQUENCE => we have explicit parameters | ||
| 320 | * (e.g. parameters in the X9_62_EC_PARAMETERS-structure ) | ||
| 321 | */ | ||
| 322 | if ((ret->pkey.ec= EC_KEY_new()) == NULL) | ||
| 323 | { | ||
| 324 | X509err(X509_F_X509_PUBKEY_GET, | ||
| 325 | ERR_R_MALLOC_FAILURE); | ||
| 326 | goto err; | ||
| 327 | } | ||
| 328 | cp = p = a->parameter->value.sequence->data; | ||
| 329 | j = a->parameter->value.sequence->length; | ||
| 330 | if (!d2i_ECParameters(&ret->pkey.ec, &cp, (long)j)) | ||
| 331 | { | ||
| 332 | X509err(X509_F_X509_PUBKEY_GET, ERR_R_EC_LIB); | ||
| 333 | goto err; | ||
| 334 | } | ||
| 335 | } | ||
| 336 | else if (a->parameter && (a->parameter->type == V_ASN1_OBJECT)) | ||
| 337 | { | ||
| 338 | /* type == V_ASN1_OBJECT => the parameters are given | ||
| 339 | * by an asn1 OID | ||
| 340 | */ | ||
| 341 | EC_KEY *ec_key; | ||
| 342 | EC_GROUP *group; | ||
| 343 | |||
| 344 | if (ret->pkey.ec == NULL) | ||
| 345 | ret->pkey.ec = EC_KEY_new(); | ||
| 346 | ec_key = ret->pkey.ec; | ||
| 347 | if (ec_key == NULL) | ||
| 348 | goto err; | ||
| 349 | group = EC_GROUP_new_by_curve_name(OBJ_obj2nid(a->parameter->value.object)); | ||
| 350 | if (group == NULL) | ||
| 351 | goto err; | ||
| 352 | EC_GROUP_set_asn1_flag(group, OPENSSL_EC_NAMED_CURVE); | ||
| 353 | if (EC_KEY_set_group(ec_key, group) == 0) | ||
| 354 | goto err; | ||
| 355 | EC_GROUP_free(group); | ||
| 356 | } | ||
| 357 | /* the case implicitlyCA is currently not implemented */ | ||
| 358 | ret->save_parameters = 1; | ||
| 359 | } | ||
| 360 | #endif | ||
| 361 | |||
| 362 | p=key->public_key->data; | ||
| 363 | j=key->public_key->length; | ||
| 364 | if (!d2i_PublicKey(type, &ret, &p, (long)j)) | ||
| 365 | { | ||
| 366 | X509err(X509_F_X509_PUBKEY_GET, X509_R_ERR_ASN1_LIB); | ||
| 367 | goto err; | ||
| 368 | } | ||
| 369 | |||
| 370 | key->pkey = ret; | ||
| 371 | CRYPTO_add(&ret->references, 1, CRYPTO_LOCK_EVP_PKEY); | ||
| 372 | return(ret); | ||
| 373 | err: | ||
| 374 | if (ret != NULL) | ||
| 375 | EVP_PKEY_free(ret); | ||
| 376 | return(NULL); | ||
| 377 | } | ||
| 378 | |||
| 379 | /* Now two pseudo ASN1 routines that take an EVP_PKEY structure | ||
| 380 | * and encode or decode as X509_PUBKEY | ||
| 381 | */ | ||
| 382 | |||
| 383 | EVP_PKEY *d2i_PUBKEY(EVP_PKEY **a, const unsigned char **pp, | ||
| 384 | long length) | ||
| 385 | { | ||
| 386 | X509_PUBKEY *xpk; | ||
| 387 | EVP_PKEY *pktmp; | ||
| 388 | xpk = d2i_X509_PUBKEY(NULL, pp, length); | ||
| 389 | if(!xpk) return NULL; | ||
| 390 | pktmp = X509_PUBKEY_get(xpk); | ||
| 391 | X509_PUBKEY_free(xpk); | ||
| 392 | if(!pktmp) return NULL; | ||
| 393 | if(a) | ||
| 394 | { | ||
| 395 | EVP_PKEY_free(*a); | ||
| 396 | *a = pktmp; | ||
| 397 | } | ||
| 398 | return pktmp; | ||
| 399 | } | ||
| 400 | |||
| 401 | int i2d_PUBKEY(EVP_PKEY *a, unsigned char **pp) | ||
| 402 | { | ||
| 403 | X509_PUBKEY *xpk=NULL; | ||
| 404 | int ret; | ||
| 405 | if(!a) return 0; | ||
| 406 | if(!X509_PUBKEY_set(&xpk, a)) return 0; | ||
| 407 | ret = i2d_X509_PUBKEY(xpk, pp); | ||
| 408 | X509_PUBKEY_free(xpk); | ||
| 409 | return ret; | ||
| 410 | } | ||
| 411 | |||
| 412 | /* The following are equivalents but which return RSA and DSA | ||
| 413 | * keys | ||
| 414 | */ | ||
| 415 | #ifndef OPENSSL_NO_RSA | ||
| 416 | RSA *d2i_RSA_PUBKEY(RSA **a, const unsigned char **pp, | ||
| 417 | long length) | ||
| 418 | { | ||
| 419 | EVP_PKEY *pkey; | ||
| 420 | RSA *key; | ||
| 421 | const unsigned char *q; | ||
| 422 | q = *pp; | ||
| 423 | pkey = d2i_PUBKEY(NULL, &q, length); | ||
| 424 | if (!pkey) return NULL; | ||
| 425 | key = EVP_PKEY_get1_RSA(pkey); | ||
| 426 | EVP_PKEY_free(pkey); | ||
| 427 | if (!key) return NULL; | ||
| 428 | *pp = q; | ||
| 429 | if (a) | ||
| 430 | { | ||
| 431 | RSA_free(*a); | ||
| 432 | *a = key; | ||
| 433 | } | ||
| 434 | return key; | ||
| 435 | } | ||
| 436 | |||
| 437 | int i2d_RSA_PUBKEY(RSA *a, unsigned char **pp) | ||
| 438 | { | ||
| 439 | EVP_PKEY *pktmp; | ||
| 440 | int ret; | ||
| 441 | if (!a) return 0; | ||
| 442 | pktmp = EVP_PKEY_new(); | ||
| 443 | if (!pktmp) | ||
| 444 | { | ||
| 445 | ASN1err(ASN1_F_I2D_RSA_PUBKEY, ERR_R_MALLOC_FAILURE); | ||
| 446 | return 0; | ||
| 447 | } | ||
| 448 | EVP_PKEY_set1_RSA(pktmp, a); | ||
| 449 | ret = i2d_PUBKEY(pktmp, pp); | ||
| 450 | EVP_PKEY_free(pktmp); | ||
| 451 | return ret; | ||
| 452 | } | ||
| 453 | #endif | ||
| 454 | |||
| 455 | #ifndef OPENSSL_NO_DSA | ||
| 456 | DSA *d2i_DSA_PUBKEY(DSA **a, const unsigned char **pp, | ||
| 457 | long length) | ||
| 458 | { | ||
| 459 | EVP_PKEY *pkey; | ||
| 460 | DSA *key; | ||
| 461 | const unsigned char *q; | ||
| 462 | q = *pp; | ||
| 463 | pkey = d2i_PUBKEY(NULL, &q, length); | ||
| 464 | if (!pkey) return NULL; | ||
| 465 | key = EVP_PKEY_get1_DSA(pkey); | ||
| 466 | EVP_PKEY_free(pkey); | ||
| 467 | if (!key) return NULL; | ||
| 468 | *pp = q; | ||
| 469 | if (a) | ||
| 470 | { | ||
| 471 | DSA_free(*a); | ||
| 472 | *a = key; | ||
| 473 | } | ||
| 474 | return key; | ||
| 475 | } | ||
| 476 | |||
| 477 | int i2d_DSA_PUBKEY(DSA *a, unsigned char **pp) | ||
| 478 | { | ||
| 479 | EVP_PKEY *pktmp; | ||
| 480 | int ret; | ||
| 481 | if(!a) return 0; | ||
| 482 | pktmp = EVP_PKEY_new(); | ||
| 483 | if(!pktmp) | ||
| 484 | { | ||
| 485 | ASN1err(ASN1_F_I2D_DSA_PUBKEY, ERR_R_MALLOC_FAILURE); | ||
| 486 | return 0; | ||
| 487 | } | ||
| 488 | EVP_PKEY_set1_DSA(pktmp, a); | ||
| 489 | ret = i2d_PUBKEY(pktmp, pp); | ||
| 490 | EVP_PKEY_free(pktmp); | ||
| 491 | return ret; | ||
| 492 | } | ||
| 493 | #endif | ||
| 494 | |||
| 495 | #ifndef OPENSSL_NO_EC | ||
| 496 | EC_KEY *d2i_EC_PUBKEY(EC_KEY **a, const unsigned char **pp, long length) | ||
| 497 | { | ||
| 498 | EVP_PKEY *pkey; | ||
| 499 | EC_KEY *key; | ||
| 500 | const unsigned char *q; | ||
| 501 | q = *pp; | ||
| 502 | pkey = d2i_PUBKEY(NULL, &q, length); | ||
| 503 | if (!pkey) return(NULL); | ||
| 504 | key = EVP_PKEY_get1_EC_KEY(pkey); | ||
| 505 | EVP_PKEY_free(pkey); | ||
| 506 | if (!key) return(NULL); | ||
| 507 | *pp = q; | ||
| 508 | if (a) | ||
| 509 | { | ||
| 510 | EC_KEY_free(*a); | ||
| 511 | *a = key; | ||
| 512 | } | ||
| 513 | return(key); | ||
| 514 | } | ||
| 515 | |||
| 516 | int i2d_EC_PUBKEY(EC_KEY *a, unsigned char **pp) | ||
| 517 | { | ||
| 518 | EVP_PKEY *pktmp; | ||
| 519 | int ret; | ||
| 520 | if (!a) return(0); | ||
| 521 | if ((pktmp = EVP_PKEY_new()) == NULL) | ||
| 522 | { | ||
| 523 | ASN1err(ASN1_F_I2D_EC_PUBKEY, ERR_R_MALLOC_FAILURE); | ||
| 524 | return(0); | ||
| 525 | } | ||
| 526 | EVP_PKEY_set1_EC_KEY(pktmp, a); | ||
| 527 | ret = i2d_PUBKEY(pktmp, pp); | ||
| 528 | EVP_PKEY_free(pktmp); | ||
| 529 | return(ret); | ||
| 530 | } | ||
| 531 | #endif | ||
diff --git a/src/lib/libcrypto/asn1/x_req.c b/src/lib/libcrypto/asn1/x_req.c new file mode 100644 index 0000000000..59ca8ce329 --- /dev/null +++ b/src/lib/libcrypto/asn1/x_req.c | |||
| @@ -0,0 +1,112 @@ | |||
| 1 | /* crypto/asn1/x_req.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/asn1t.h> | ||
| 62 | #include <openssl/x509.h> | ||
| 63 | |||
| 64 | /* X509_REQ_INFO is handled in an unusual way to get round | ||
| 65 | * invalid encodings. Some broken certificate requests don't | ||
| 66 | * encode the attributes field if it is empty. This is in | ||
| 67 | * violation of PKCS#10 but we need to tolerate it. We do | ||
| 68 | * this by making the attributes field OPTIONAL then using | ||
| 69 | * the callback to initialise it to an empty STACK. | ||
| 70 | * | ||
| 71 | * This means that the field will be correctly encoded unless | ||
| 72 | * we NULL out the field. | ||
| 73 | * | ||
| 74 | * As a result we no longer need the req_kludge field because | ||
| 75 | * the information is now contained in the attributes field: | ||
| 76 | * 1. If it is NULL then it's the invalid omission. | ||
| 77 | * 2. If it is empty it is the correct encoding. | ||
| 78 | * 3. If it is not empty then some attributes are present. | ||
| 79 | * | ||
| 80 | */ | ||
| 81 | |||
| 82 | static int rinf_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it) | ||
| 83 | { | ||
| 84 | X509_REQ_INFO *rinf = (X509_REQ_INFO *)*pval; | ||
| 85 | |||
| 86 | if(operation == ASN1_OP_NEW_POST) { | ||
| 87 | rinf->attributes = sk_X509_ATTRIBUTE_new_null(); | ||
| 88 | if(!rinf->attributes) return 0; | ||
| 89 | } | ||
| 90 | return 1; | ||
| 91 | } | ||
| 92 | |||
| 93 | ASN1_SEQUENCE_enc(X509_REQ_INFO, enc, rinf_cb) = { | ||
| 94 | ASN1_SIMPLE(X509_REQ_INFO, version, ASN1_INTEGER), | ||
| 95 | ASN1_SIMPLE(X509_REQ_INFO, subject, X509_NAME), | ||
| 96 | ASN1_SIMPLE(X509_REQ_INFO, pubkey, X509_PUBKEY), | ||
| 97 | /* This isn't really OPTIONAL but it gets round invalid | ||
| 98 | * encodings | ||
| 99 | */ | ||
| 100 | ASN1_IMP_SET_OF_OPT(X509_REQ_INFO, attributes, X509_ATTRIBUTE, 0) | ||
| 101 | } ASN1_SEQUENCE_END_enc(X509_REQ_INFO, X509_REQ_INFO) | ||
| 102 | |||
| 103 | IMPLEMENT_ASN1_FUNCTIONS(X509_REQ_INFO) | ||
| 104 | |||
| 105 | ASN1_SEQUENCE_ref(X509_REQ, 0, CRYPTO_LOCK_X509_REQ) = { | ||
| 106 | ASN1_SIMPLE(X509_REQ, req_info, X509_REQ_INFO), | ||
| 107 | ASN1_SIMPLE(X509_REQ, sig_alg, X509_ALGOR), | ||
| 108 | ASN1_SIMPLE(X509_REQ, signature, ASN1_BIT_STRING) | ||
| 109 | } ASN1_SEQUENCE_END_ref(X509_REQ, X509_REQ) | ||
| 110 | |||
| 111 | IMPLEMENT_ASN1_FUNCTIONS(X509_REQ) | ||
| 112 | IMPLEMENT_ASN1_DUP_FUNCTION(X509_REQ) | ||
diff --git a/src/lib/libcrypto/asn1/x_sig.c b/src/lib/libcrypto/asn1/x_sig.c new file mode 100644 index 0000000000..42efa86c1c --- /dev/null +++ b/src/lib/libcrypto/asn1/x_sig.c | |||
| @@ -0,0 +1,69 @@ | |||
| 1 | /* crypto/asn1/x_sig.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/asn1t.h> | ||
| 62 | #include <openssl/x509.h> | ||
| 63 | |||
| 64 | ASN1_SEQUENCE(X509_SIG) = { | ||
| 65 | ASN1_SIMPLE(X509_SIG, algor, X509_ALGOR), | ||
| 66 | ASN1_SIMPLE(X509_SIG, digest, ASN1_OCTET_STRING) | ||
| 67 | } ASN1_SEQUENCE_END(X509_SIG) | ||
| 68 | |||
| 69 | IMPLEMENT_ASN1_FUNCTIONS(X509_SIG) | ||
diff --git a/src/lib/libcrypto/asn1/x_spki.c b/src/lib/libcrypto/asn1/x_spki.c new file mode 100644 index 0000000000..2aece077c5 --- /dev/null +++ b/src/lib/libcrypto/asn1/x_spki.c | |||
| @@ -0,0 +1,81 @@ | |||
| 1 | /* crypto/asn1/x_spki.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | /* This module was send to me my Pat Richards <patr@x509.com> who | ||
| 60 | * wrote it. It is under my Copyright with his permission | ||
| 61 | */ | ||
| 62 | |||
| 63 | #include <stdio.h> | ||
| 64 | #include "cryptlib.h" | ||
| 65 | #include <openssl/x509.h> | ||
| 66 | #include <openssl/asn1t.h> | ||
| 67 | |||
| 68 | ASN1_SEQUENCE(NETSCAPE_SPKAC) = { | ||
| 69 | ASN1_SIMPLE(NETSCAPE_SPKAC, pubkey, X509_PUBKEY), | ||
| 70 | ASN1_SIMPLE(NETSCAPE_SPKAC, challenge, ASN1_IA5STRING) | ||
| 71 | } ASN1_SEQUENCE_END(NETSCAPE_SPKAC) | ||
| 72 | |||
| 73 | IMPLEMENT_ASN1_FUNCTIONS(NETSCAPE_SPKAC) | ||
| 74 | |||
| 75 | ASN1_SEQUENCE(NETSCAPE_SPKI) = { | ||
| 76 | ASN1_SIMPLE(NETSCAPE_SPKI, spkac, NETSCAPE_SPKAC), | ||
| 77 | ASN1_SIMPLE(NETSCAPE_SPKI, sig_algor, X509_ALGOR), | ||
| 78 | ASN1_SIMPLE(NETSCAPE_SPKI, signature, ASN1_BIT_STRING) | ||
| 79 | } ASN1_SEQUENCE_END(NETSCAPE_SPKI) | ||
| 80 | |||
| 81 | IMPLEMENT_ASN1_FUNCTIONS(NETSCAPE_SPKI) | ||
diff --git a/src/lib/libcrypto/asn1/x_val.c b/src/lib/libcrypto/asn1/x_val.c new file mode 100644 index 0000000000..dc17c67758 --- /dev/null +++ b/src/lib/libcrypto/asn1/x_val.c | |||
| @@ -0,0 +1,69 @@ | |||
| 1 | /* crypto/asn1/x_val.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/asn1t.h> | ||
| 62 | #include <openssl/x509.h> | ||
| 63 | |||
| 64 | ASN1_SEQUENCE(X509_VAL) = { | ||
| 65 | ASN1_SIMPLE(X509_VAL, notBefore, ASN1_TIME), | ||
| 66 | ASN1_SIMPLE(X509_VAL, notAfter, ASN1_TIME) | ||
| 67 | } ASN1_SEQUENCE_END(X509_VAL) | ||
| 68 | |||
| 69 | IMPLEMENT_ASN1_FUNCTIONS(X509_VAL) | ||
diff --git a/src/lib/libcrypto/asn1/x_x509.c b/src/lib/libcrypto/asn1/x_x509.c new file mode 100644 index 0000000000..e118696625 --- /dev/null +++ b/src/lib/libcrypto/asn1/x_x509.c | |||
| @@ -0,0 +1,202 @@ | |||
| 1 | /* crypto/asn1/x_x509.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/evp.h> | ||
| 62 | #include <openssl/asn1t.h> | ||
| 63 | #include <openssl/x509.h> | ||
| 64 | #include <openssl/x509v3.h> | ||
| 65 | |||
| 66 | ASN1_SEQUENCE(X509_CINF) = { | ||
| 67 | ASN1_EXP_OPT(X509_CINF, version, ASN1_INTEGER, 0), | ||
| 68 | ASN1_SIMPLE(X509_CINF, serialNumber, ASN1_INTEGER), | ||
| 69 | ASN1_SIMPLE(X509_CINF, signature, X509_ALGOR), | ||
| 70 | ASN1_SIMPLE(X509_CINF, issuer, X509_NAME), | ||
| 71 | ASN1_SIMPLE(X509_CINF, validity, X509_VAL), | ||
| 72 | ASN1_SIMPLE(X509_CINF, subject, X509_NAME), | ||
| 73 | ASN1_SIMPLE(X509_CINF, key, X509_PUBKEY), | ||
| 74 | ASN1_IMP_OPT(X509_CINF, issuerUID, ASN1_BIT_STRING, 1), | ||
| 75 | ASN1_IMP_OPT(X509_CINF, subjectUID, ASN1_BIT_STRING, 2), | ||
| 76 | ASN1_EXP_SEQUENCE_OF_OPT(X509_CINF, extensions, X509_EXTENSION, 3) | ||
| 77 | } ASN1_SEQUENCE_END(X509_CINF) | ||
| 78 | |||
| 79 | IMPLEMENT_ASN1_FUNCTIONS(X509_CINF) | ||
| 80 | /* X509 top level structure needs a bit of customisation */ | ||
| 81 | |||
| 82 | extern void policy_cache_free(X509_POLICY_CACHE *cache); | ||
| 83 | |||
| 84 | static int x509_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it) | ||
| 85 | { | ||
| 86 | X509 *ret = (X509 *)*pval; | ||
| 87 | |||
| 88 | switch(operation) { | ||
| 89 | |||
| 90 | case ASN1_OP_NEW_POST: | ||
| 91 | ret->valid=0; | ||
| 92 | ret->name = NULL; | ||
| 93 | ret->ex_flags = 0; | ||
| 94 | ret->ex_pathlen = -1; | ||
| 95 | ret->skid = NULL; | ||
| 96 | ret->akid = NULL; | ||
| 97 | #ifndef OPENSSL_NO_RFC3779 | ||
| 98 | ret->rfc3779_addr = NULL; | ||
| 99 | ret->rfc3779_asid = NULL; | ||
| 100 | #endif | ||
| 101 | ret->aux = NULL; | ||
| 102 | CRYPTO_new_ex_data(CRYPTO_EX_INDEX_X509, ret, &ret->ex_data); | ||
| 103 | break; | ||
| 104 | |||
| 105 | case ASN1_OP_D2I_POST: | ||
| 106 | if (ret->name != NULL) OPENSSL_free(ret->name); | ||
| 107 | ret->name=X509_NAME_oneline(ret->cert_info->subject,NULL,0); | ||
| 108 | break; | ||
| 109 | |||
| 110 | case ASN1_OP_FREE_POST: | ||
| 111 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_X509, ret, &ret->ex_data); | ||
| 112 | X509_CERT_AUX_free(ret->aux); | ||
| 113 | ASN1_OCTET_STRING_free(ret->skid); | ||
| 114 | AUTHORITY_KEYID_free(ret->akid); | ||
| 115 | policy_cache_free(ret->policy_cache); | ||
| 116 | #ifndef OPENSSL_NO_RFC3779 | ||
| 117 | sk_IPAddressFamily_pop_free(ret->rfc3779_addr, IPAddressFamily_free); | ||
| 118 | ASIdentifiers_free(ret->rfc3779_asid); | ||
| 119 | #endif | ||
| 120 | |||
| 121 | if (ret->name != NULL) OPENSSL_free(ret->name); | ||
| 122 | break; | ||
| 123 | |||
| 124 | } | ||
| 125 | |||
| 126 | return 1; | ||
| 127 | |||
| 128 | } | ||
| 129 | |||
| 130 | ASN1_SEQUENCE_ref(X509, x509_cb, CRYPTO_LOCK_X509) = { | ||
| 131 | ASN1_SIMPLE(X509, cert_info, X509_CINF), | ||
| 132 | ASN1_SIMPLE(X509, sig_alg, X509_ALGOR), | ||
| 133 | ASN1_SIMPLE(X509, signature, ASN1_BIT_STRING) | ||
| 134 | } ASN1_SEQUENCE_END_ref(X509, X509) | ||
| 135 | |||
| 136 | IMPLEMENT_ASN1_FUNCTIONS(X509) | ||
| 137 | IMPLEMENT_ASN1_DUP_FUNCTION(X509) | ||
| 138 | |||
| 139 | static ASN1_METHOD meth= | ||
| 140 | { | ||
| 141 | (I2D_OF(void)) i2d_X509, | ||
| 142 | (D2I_OF(void)) d2i_X509, | ||
| 143 | (void *(*)(void))X509_new, | ||
| 144 | (void (*)(void *)) X509_free | ||
| 145 | }; | ||
| 146 | |||
| 147 | ASN1_METHOD *X509_asn1_meth(void) | ||
| 148 | { | ||
| 149 | return(&meth); | ||
| 150 | } | ||
| 151 | |||
| 152 | int X509_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, | ||
| 153 | CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func) | ||
| 154 | { | ||
| 155 | return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_X509, argl, argp, | ||
| 156 | new_func, dup_func, free_func); | ||
| 157 | } | ||
| 158 | |||
| 159 | int X509_set_ex_data(X509 *r, int idx, void *arg) | ||
| 160 | { | ||
| 161 | return(CRYPTO_set_ex_data(&r->ex_data,idx,arg)); | ||
| 162 | } | ||
| 163 | |||
| 164 | void *X509_get_ex_data(X509 *r, int idx) | ||
| 165 | { | ||
| 166 | return(CRYPTO_get_ex_data(&r->ex_data,idx)); | ||
| 167 | } | ||
| 168 | |||
| 169 | /* X509_AUX ASN1 routines. X509_AUX is the name given to | ||
| 170 | * a certificate with extra info tagged on the end. Since these | ||
| 171 | * functions set how a certificate is trusted they should only | ||
| 172 | * be used when the certificate comes from a reliable source | ||
| 173 | * such as local storage. | ||
| 174 | * | ||
| 175 | */ | ||
| 176 | |||
| 177 | X509 *d2i_X509_AUX(X509 **a, const unsigned char **pp, long length) | ||
| 178 | { | ||
| 179 | const unsigned char *q; | ||
| 180 | X509 *ret; | ||
| 181 | /* Save start position */ | ||
| 182 | q = *pp; | ||
| 183 | ret = d2i_X509(a, pp, length); | ||
| 184 | /* If certificate unreadable then forget it */ | ||
| 185 | if(!ret) return NULL; | ||
| 186 | /* update length */ | ||
| 187 | length -= *pp - q; | ||
| 188 | if(!length) return ret; | ||
| 189 | if(!d2i_X509_CERT_AUX(&ret->aux, pp, length)) goto err; | ||
| 190 | return ret; | ||
| 191 | err: | ||
| 192 | X509_free(ret); | ||
| 193 | return NULL; | ||
| 194 | } | ||
| 195 | |||
| 196 | int i2d_X509_AUX(X509 *a, unsigned char **pp) | ||
| 197 | { | ||
| 198 | int length; | ||
| 199 | length = i2d_X509(a, pp); | ||
| 200 | if(a) length += i2d_X509_CERT_AUX(a->aux, pp); | ||
| 201 | return length; | ||
| 202 | } | ||
diff --git a/src/lib/libcrypto/asn1/x_x509a.c b/src/lib/libcrypto/asn1/x_x509a.c new file mode 100644 index 0000000000..13db5fd03f --- /dev/null +++ b/src/lib/libcrypto/asn1/x_x509a.c | |||
| @@ -0,0 +1,180 @@ | |||
| 1 | /* a_x509a.c */ | ||
| 2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
| 3 | * project 1999. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/evp.h> | ||
| 62 | #include <openssl/asn1t.h> | ||
| 63 | #include <openssl/x509.h> | ||
| 64 | |||
| 65 | /* X509_CERT_AUX routines. These are used to encode additional | ||
| 66 | * user modifiable data about a certificate. This data is | ||
| 67 | * appended to the X509 encoding when the *_X509_AUX routines | ||
| 68 | * are used. This means that the "traditional" X509 routines | ||
| 69 | * will simply ignore the extra data. | ||
| 70 | */ | ||
| 71 | |||
| 72 | static X509_CERT_AUX *aux_get(X509 *x); | ||
| 73 | |||
| 74 | ASN1_SEQUENCE(X509_CERT_AUX) = { | ||
| 75 | ASN1_SEQUENCE_OF_OPT(X509_CERT_AUX, trust, ASN1_OBJECT), | ||
| 76 | ASN1_IMP_SEQUENCE_OF_OPT(X509_CERT_AUX, reject, ASN1_OBJECT, 0), | ||
| 77 | ASN1_OPT(X509_CERT_AUX, alias, ASN1_UTF8STRING), | ||
| 78 | ASN1_OPT(X509_CERT_AUX, keyid, ASN1_OCTET_STRING), | ||
| 79 | ASN1_IMP_SEQUENCE_OF_OPT(X509_CERT_AUX, other, X509_ALGOR, 1) | ||
| 80 | } ASN1_SEQUENCE_END(X509_CERT_AUX) | ||
| 81 | |||
| 82 | IMPLEMENT_ASN1_FUNCTIONS(X509_CERT_AUX) | ||
| 83 | |||
| 84 | static X509_CERT_AUX *aux_get(X509 *x) | ||
| 85 | { | ||
| 86 | if(!x) return NULL; | ||
| 87 | if(!x->aux && !(x->aux = X509_CERT_AUX_new())) return NULL; | ||
| 88 | return x->aux; | ||
| 89 | } | ||
| 90 | |||
| 91 | int X509_alias_set1(X509 *x, unsigned char *name, int len) | ||
| 92 | { | ||
| 93 | X509_CERT_AUX *aux; | ||
| 94 | if (!name) | ||
| 95 | { | ||
| 96 | if (!x || !x->aux || !x->aux->alias) | ||
| 97 | return 1; | ||
| 98 | ASN1_UTF8STRING_free(x->aux->alias); | ||
| 99 | x->aux->alias = NULL; | ||
| 100 | return 1; | ||
| 101 | } | ||
| 102 | if(!(aux = aux_get(x))) return 0; | ||
| 103 | if(!aux->alias && !(aux->alias = ASN1_UTF8STRING_new())) return 0; | ||
| 104 | return ASN1_STRING_set(aux->alias, name, len); | ||
| 105 | } | ||
| 106 | |||
| 107 | int X509_keyid_set1(X509 *x, unsigned char *id, int len) | ||
| 108 | { | ||
| 109 | X509_CERT_AUX *aux; | ||
| 110 | if (!id) | ||
| 111 | { | ||
| 112 | if (!x || !x->aux || !x->aux->keyid) | ||
| 113 | return 1; | ||
| 114 | ASN1_OCTET_STRING_free(x->aux->keyid); | ||
| 115 | x->aux->keyid = NULL; | ||
| 116 | return 1; | ||
| 117 | } | ||
| 118 | if(!(aux = aux_get(x))) return 0; | ||
| 119 | if(!aux->keyid && !(aux->keyid = ASN1_OCTET_STRING_new())) return 0; | ||
| 120 | return ASN1_STRING_set(aux->keyid, id, len); | ||
| 121 | } | ||
| 122 | |||
| 123 | unsigned char *X509_alias_get0(X509 *x, int *len) | ||
| 124 | { | ||
| 125 | if(!x->aux || !x->aux->alias) return NULL; | ||
| 126 | if(len) *len = x->aux->alias->length; | ||
| 127 | return x->aux->alias->data; | ||
| 128 | } | ||
| 129 | |||
| 130 | unsigned char *X509_keyid_get0(X509 *x, int *len) | ||
| 131 | { | ||
| 132 | if(!x->aux || !x->aux->keyid) return NULL; | ||
| 133 | if(len) *len = x->aux->keyid->length; | ||
| 134 | return x->aux->keyid->data; | ||
| 135 | } | ||
| 136 | |||
| 137 | int X509_add1_trust_object(X509 *x, ASN1_OBJECT *obj) | ||
| 138 | { | ||
| 139 | X509_CERT_AUX *aux; | ||
| 140 | ASN1_OBJECT *objtmp; | ||
| 141 | if(!(objtmp = OBJ_dup(obj))) return 0; | ||
| 142 | if(!(aux = aux_get(x))) return 0; | ||
| 143 | if(!aux->trust | ||
| 144 | && !(aux->trust = sk_ASN1_OBJECT_new_null())) return 0; | ||
| 145 | return sk_ASN1_OBJECT_push(aux->trust, objtmp); | ||
| 146 | } | ||
| 147 | |||
| 148 | int X509_add1_reject_object(X509 *x, ASN1_OBJECT *obj) | ||
| 149 | { | ||
| 150 | X509_CERT_AUX *aux; | ||
| 151 | ASN1_OBJECT *objtmp; | ||
| 152 | if(!(objtmp = OBJ_dup(obj))) return 0; | ||
| 153 | if(!(aux = aux_get(x))) return 0; | ||
| 154 | if(!aux->reject | ||
| 155 | && !(aux->reject = sk_ASN1_OBJECT_new_null())) return 0; | ||
| 156 | return sk_ASN1_OBJECT_push(aux->reject, objtmp); | ||
| 157 | } | ||
| 158 | |||
| 159 | void X509_trust_clear(X509 *x) | ||
| 160 | { | ||
| 161 | if(x->aux && x->aux->trust) { | ||
| 162 | sk_ASN1_OBJECT_pop_free(x->aux->trust, ASN1_OBJECT_free); | ||
| 163 | x->aux->trust = NULL; | ||
| 164 | } | ||
| 165 | } | ||
| 166 | |||
| 167 | void X509_reject_clear(X509 *x) | ||
| 168 | { | ||
| 169 | if(x->aux && x->aux->reject) { | ||
| 170 | sk_ASN1_OBJECT_pop_free(x->aux->reject, ASN1_OBJECT_free); | ||
| 171 | x->aux->reject = NULL; | ||
| 172 | } | ||
| 173 | } | ||
| 174 | |||
| 175 | ASN1_SEQUENCE(X509_CERT_PAIR) = { | ||
| 176 | ASN1_EXP_OPT(X509_CERT_PAIR, forward, X509, 0), | ||
| 177 | ASN1_EXP_OPT(X509_CERT_PAIR, reverse, X509, 1) | ||
| 178 | } ASN1_SEQUENCE_END(X509_CERT_PAIR) | ||
| 179 | |||
| 180 | IMPLEMENT_ASN1_FUNCTIONS(X509_CERT_PAIR) | ||
