diff options
Diffstat (limited to 'src/lib/libcrypto/pem')
| -rw-r--r-- | src/lib/libcrypto/pem/Makefile | 335 | ||||
| -rw-r--r-- | src/lib/libcrypto/pem/message | 16 | ||||
| -rw-r--r-- | src/lib/libcrypto/pem/pem.h | 672 | ||||
| -rw-r--r-- | src/lib/libcrypto/pem/pem2.h | 70 | ||||
| -rw-r--r-- | src/lib/libcrypto/pem/pem_all.c | 315 | ||||
| -rw-r--r-- | src/lib/libcrypto/pem/pem_err.c | 135 | ||||
| -rw-r--r-- | src/lib/libcrypto/pem/pem_info.c | 365 | ||||
| -rw-r--r-- | src/lib/libcrypto/pem/pem_lib.c | 776 | ||||
| -rw-r--r-- | src/lib/libcrypto/pem/pem_oth.c | 85 | ||||
| -rw-r--r-- | src/lib/libcrypto/pem/pem_pk8.c | 243 | ||||
| -rw-r--r-- | src/lib/libcrypto/pem/pem_pkey.c | 145 | ||||
| -rw-r--r-- | src/lib/libcrypto/pem/pem_seal.c | 187 | ||||
| -rw-r--r-- | src/lib/libcrypto/pem/pem_sign.c | 102 | ||||
| -rw-r--r-- | src/lib/libcrypto/pem/pem_x509.c | 69 | ||||
| -rw-r--r-- | src/lib/libcrypto/pem/pem_xaux.c | 68 | ||||
| -rw-r--r-- | src/lib/libcrypto/pem/pkcs7.lis | 22 |
16 files changed, 3605 insertions, 0 deletions
diff --git a/src/lib/libcrypto/pem/Makefile b/src/lib/libcrypto/pem/Makefile new file mode 100644 index 0000000000..fbc2b5d056 --- /dev/null +++ b/src/lib/libcrypto/pem/Makefile | |||
| @@ -0,0 +1,335 @@ | |||
| 1 | # | ||
| 2 | # OpenSSL/crypto/pem/Makefile | ||
| 3 | # | ||
| 4 | |||
| 5 | DIR= pem | ||
| 6 | TOP= ../.. | ||
| 7 | CC= cc | ||
| 8 | INCLUDES= -I.. -I$(TOP) -I../../include | ||
| 9 | CFLAG=-g | ||
| 10 | INSTALL_PREFIX= | ||
| 11 | OPENSSLDIR= /usr/local/ssl | ||
| 12 | INSTALLTOP=/usr/local/ssl | ||
| 13 | MAKEDEPPROG= makedepend | ||
| 14 | MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG) | ||
| 15 | MAKEFILE= Makefile | ||
| 16 | AR= ar r | ||
| 17 | |||
| 18 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
| 19 | |||
| 20 | GENERAL=Makefile | ||
| 21 | TEST= | ||
| 22 | APPS= | ||
| 23 | |||
| 24 | LIB=$(TOP)/libcrypto.a | ||
| 25 | LIBSRC= pem_sign.c pem_seal.c pem_info.c pem_lib.c pem_all.c pem_err.c \ | ||
| 26 | pem_x509.c pem_xaux.c pem_oth.c pem_pk8.c pem_pkey.c | ||
| 27 | |||
| 28 | LIBOBJ= pem_sign.o pem_seal.o pem_info.o pem_lib.o pem_all.o pem_err.o \ | ||
| 29 | pem_x509.o pem_xaux.o pem_oth.o pem_pk8.o pem_pkey.o | ||
| 30 | |||
| 31 | SRC= $(LIBSRC) | ||
| 32 | |||
| 33 | EXHEADER= pem.h pem2.h | ||
| 34 | HEADER= $(EXHEADER) | ||
| 35 | |||
| 36 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
| 37 | |||
| 38 | top: | ||
| 39 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
| 40 | |||
| 41 | all: lib | ||
| 42 | |||
| 43 | lib: $(LIBOBJ) | ||
| 44 | $(AR) $(LIB) $(LIBOBJ) | ||
| 45 | $(RANLIB) $(LIB) || echo Never mind. | ||
| 46 | @touch lib | ||
| 47 | |||
| 48 | files: | ||
| 49 | $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO | ||
| 50 | |||
| 51 | links: $(EXHEADER) | ||
| 52 | @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) | ||
| 53 | @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) | ||
| 54 | @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) | ||
| 55 | |||
| 56 | install: | ||
| 57 | @headerlist="$(EXHEADER)"; for i in $$headerlist ; \ | ||
| 58 | do \ | ||
| 59 | (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ | ||
| 60 | chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ | ||
| 61 | done; | ||
| 62 | |||
| 63 | tags: | ||
| 64 | ctags $(SRC) | ||
| 65 | |||
| 66 | tests: | ||
| 67 | |||
| 68 | lint: | ||
| 69 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
| 70 | |||
| 71 | depend: | ||
| 72 | $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(LIBSRC) | ||
| 73 | |||
| 74 | dclean: | ||
| 75 | $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
| 76 | mv -f Makefile.new $(MAKEFILE) | ||
| 77 | |||
| 78 | clean: | ||
| 79 | rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
| 80 | |||
| 81 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
| 82 | |||
| 83 | pem_all.o: ../../e_os.h ../../include/openssl/aes.h | ||
| 84 | pem_all.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
| 85 | pem_all.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h | ||
| 86 | pem_all.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h | ||
| 87 | pem_all.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
| 88 | pem_all.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h | ||
| 89 | pem_all.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h | ||
| 90 | pem_all.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
| 91 | pem_all.o: ../../include/openssl/fips.h ../../include/openssl/idea.h | ||
| 92 | pem_all.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h | ||
| 93 | pem_all.o: ../../include/openssl/md4.h ../../include/openssl/md5.h | ||
| 94 | pem_all.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h | ||
| 95 | pem_all.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | ||
| 96 | pem_all.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 97 | pem_all.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h | ||
| 98 | pem_all.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h | ||
| 99 | pem_all.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h | ||
| 100 | pem_all.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h | ||
| 101 | pem_all.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
| 102 | pem_all.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 103 | pem_all.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h | ||
| 104 | pem_all.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h | ||
| 105 | pem_all.o: ../cryptlib.h pem_all.c | ||
| 106 | pem_err.o: ../../include/openssl/aes.h ../../include/openssl/asn1.h | ||
| 107 | pem_err.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h | ||
| 108 | pem_err.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h | ||
| 109 | pem_err.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h | ||
| 110 | pem_err.o: ../../include/openssl/des.h ../../include/openssl/des_old.h | ||
| 111 | pem_err.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h | ||
| 112 | pem_err.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
| 113 | pem_err.o: ../../include/openssl/evp.h ../../include/openssl/idea.h | ||
| 114 | pem_err.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h | ||
| 115 | pem_err.o: ../../include/openssl/md4.h ../../include/openssl/md5.h | ||
| 116 | pem_err.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h | ||
| 117 | pem_err.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | ||
| 118 | pem_err.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 119 | pem_err.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h | ||
| 120 | pem_err.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h | ||
| 121 | pem_err.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h | ||
| 122 | pem_err.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h | ||
| 123 | pem_err.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
| 124 | pem_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 125 | pem_err.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h | ||
| 126 | pem_err.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h | ||
| 127 | pem_err.o: pem_err.c | ||
| 128 | pem_info.o: ../../e_os.h ../../include/openssl/aes.h | ||
| 129 | pem_info.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
| 130 | pem_info.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h | ||
| 131 | pem_info.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h | ||
| 132 | pem_info.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
| 133 | pem_info.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h | ||
| 134 | pem_info.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h | ||
| 135 | pem_info.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
| 136 | pem_info.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h | ||
| 137 | pem_info.o: ../../include/openssl/md2.h ../../include/openssl/md4.h | ||
| 138 | pem_info.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h | ||
| 139 | pem_info.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
| 140 | pem_info.o: ../../include/openssl/opensslconf.h | ||
| 141 | pem_info.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 142 | pem_info.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h | ||
| 143 | pem_info.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h | ||
| 144 | pem_info.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h | ||
| 145 | pem_info.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h | ||
| 146 | pem_info.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
| 147 | pem_info.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 148 | pem_info.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h | ||
| 149 | pem_info.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h | ||
| 150 | pem_info.o: ../cryptlib.h pem_info.c | ||
| 151 | pem_lib.o: ../../e_os.h ../../include/openssl/aes.h | ||
| 152 | pem_lib.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
| 153 | pem_lib.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h | ||
| 154 | pem_lib.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h | ||
| 155 | pem_lib.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
| 156 | pem_lib.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h | ||
| 157 | pem_lib.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h | ||
| 158 | pem_lib.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
| 159 | pem_lib.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h | ||
| 160 | pem_lib.o: ../../include/openssl/md2.h ../../include/openssl/md4.h | ||
| 161 | pem_lib.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h | ||
| 162 | pem_lib.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
| 163 | pem_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
| 164 | pem_lib.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pem.h | ||
| 165 | pem_lib.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs12.h | ||
| 166 | pem_lib.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h | ||
| 167 | pem_lib.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h | ||
| 168 | pem_lib.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h | ||
| 169 | pem_lib.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h | ||
| 170 | pem_lib.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
| 171 | pem_lib.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h | ||
| 172 | pem_lib.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h | ||
| 173 | pem_lib.o: ../../include/openssl/x509_vfy.h ../cryptlib.h pem_lib.c | ||
| 174 | pem_oth.o: ../../e_os.h ../../include/openssl/aes.h | ||
| 175 | pem_oth.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
| 176 | pem_oth.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h | ||
| 177 | pem_oth.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h | ||
| 178 | pem_oth.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
| 179 | pem_oth.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h | ||
| 180 | pem_oth.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h | ||
| 181 | pem_oth.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
| 182 | pem_oth.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h | ||
| 183 | pem_oth.o: ../../include/openssl/md2.h ../../include/openssl/md4.h | ||
| 184 | pem_oth.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h | ||
| 185 | pem_oth.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
| 186 | pem_oth.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
| 187 | pem_oth.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pem.h | ||
| 188 | pem_oth.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs7.h | ||
| 189 | pem_oth.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h | ||
| 190 | pem_oth.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h | ||
| 191 | pem_oth.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h | ||
| 192 | pem_oth.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
| 193 | pem_oth.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 194 | pem_oth.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h | ||
| 195 | pem_oth.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h | ||
| 196 | pem_oth.o: ../cryptlib.h pem_oth.c | ||
| 197 | pem_pk8.o: ../../e_os.h ../../include/openssl/aes.h | ||
| 198 | pem_pk8.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
| 199 | pem_pk8.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h | ||
| 200 | pem_pk8.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h | ||
| 201 | pem_pk8.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
| 202 | pem_pk8.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h | ||
| 203 | pem_pk8.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h | ||
| 204 | pem_pk8.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
| 205 | pem_pk8.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h | ||
| 206 | pem_pk8.o: ../../include/openssl/md2.h ../../include/openssl/md4.h | ||
| 207 | pem_pk8.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h | ||
| 208 | pem_pk8.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
| 209 | pem_pk8.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
| 210 | pem_pk8.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pem.h | ||
| 211 | pem_pk8.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs12.h | ||
| 212 | pem_pk8.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h | ||
| 213 | pem_pk8.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h | ||
| 214 | pem_pk8.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h | ||
| 215 | pem_pk8.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h | ||
| 216 | pem_pk8.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
| 217 | pem_pk8.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h | ||
| 218 | pem_pk8.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h | ||
| 219 | pem_pk8.o: ../../include/openssl/x509_vfy.h ../cryptlib.h pem_pk8.c | ||
| 220 | pem_pkey.o: ../../e_os.h ../../include/openssl/aes.h | ||
| 221 | pem_pkey.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
| 222 | pem_pkey.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h | ||
| 223 | pem_pkey.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h | ||
| 224 | pem_pkey.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
| 225 | pem_pkey.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h | ||
| 226 | pem_pkey.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h | ||
| 227 | pem_pkey.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
| 228 | pem_pkey.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h | ||
| 229 | pem_pkey.o: ../../include/openssl/md2.h ../../include/openssl/md4.h | ||
| 230 | pem_pkey.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h | ||
| 231 | pem_pkey.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
| 232 | pem_pkey.o: ../../include/openssl/opensslconf.h | ||
| 233 | pem_pkey.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 234 | pem_pkey.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h | ||
| 235 | pem_pkey.o: ../../include/openssl/pkcs12.h ../../include/openssl/pkcs7.h | ||
| 236 | pem_pkey.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h | ||
| 237 | pem_pkey.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h | ||
| 238 | pem_pkey.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h | ||
| 239 | pem_pkey.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
| 240 | pem_pkey.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 241 | pem_pkey.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h | ||
| 242 | pem_pkey.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h | ||
| 243 | pem_pkey.o: ../cryptlib.h pem_pkey.c | ||
| 244 | pem_seal.o: ../../e_os.h ../../include/openssl/aes.h | ||
| 245 | pem_seal.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
| 246 | pem_seal.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h | ||
| 247 | pem_seal.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h | ||
| 248 | pem_seal.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
| 249 | pem_seal.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h | ||
| 250 | pem_seal.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h | ||
| 251 | pem_seal.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
| 252 | pem_seal.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h | ||
| 253 | pem_seal.o: ../../include/openssl/md2.h ../../include/openssl/md4.h | ||
| 254 | pem_seal.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h | ||
| 255 | pem_seal.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
| 256 | pem_seal.o: ../../include/openssl/opensslconf.h | ||
| 257 | pem_seal.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 258 | pem_seal.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h | ||
| 259 | pem_seal.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h | ||
| 260 | pem_seal.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h | ||
| 261 | pem_seal.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h | ||
| 262 | pem_seal.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h | ||
| 263 | pem_seal.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
| 264 | pem_seal.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h | ||
| 265 | pem_seal.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h | ||
| 266 | pem_seal.o: ../../include/openssl/x509_vfy.h ../cryptlib.h pem_seal.c | ||
| 267 | pem_sign.o: ../../e_os.h ../../include/openssl/aes.h | ||
| 268 | pem_sign.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
| 269 | pem_sign.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h | ||
| 270 | pem_sign.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h | ||
| 271 | pem_sign.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
| 272 | pem_sign.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h | ||
| 273 | pem_sign.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h | ||
| 274 | pem_sign.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
| 275 | pem_sign.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h | ||
| 276 | pem_sign.o: ../../include/openssl/md2.h ../../include/openssl/md4.h | ||
| 277 | pem_sign.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h | ||
| 278 | pem_sign.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
| 279 | pem_sign.o: ../../include/openssl/opensslconf.h | ||
| 280 | pem_sign.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 281 | pem_sign.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h | ||
| 282 | pem_sign.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h | ||
| 283 | pem_sign.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h | ||
| 284 | pem_sign.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h | ||
| 285 | pem_sign.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h | ||
| 286 | pem_sign.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
| 287 | pem_sign.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h | ||
| 288 | pem_sign.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h | ||
| 289 | pem_sign.o: ../../include/openssl/x509_vfy.h ../cryptlib.h pem_sign.c | ||
| 290 | pem_x509.o: ../../e_os.h ../../include/openssl/aes.h | ||
| 291 | pem_x509.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
| 292 | pem_x509.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h | ||
| 293 | pem_x509.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h | ||
| 294 | pem_x509.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
| 295 | pem_x509.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h | ||
| 296 | pem_x509.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h | ||
| 297 | pem_x509.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
| 298 | pem_x509.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h | ||
| 299 | pem_x509.o: ../../include/openssl/md2.h ../../include/openssl/md4.h | ||
| 300 | pem_x509.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h | ||
| 301 | pem_x509.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
| 302 | pem_x509.o: ../../include/openssl/opensslconf.h | ||
| 303 | pem_x509.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 304 | pem_x509.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h | ||
| 305 | pem_x509.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h | ||
| 306 | pem_x509.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h | ||
| 307 | pem_x509.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h | ||
| 308 | pem_x509.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
| 309 | pem_x509.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 310 | pem_x509.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h | ||
| 311 | pem_x509.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h | ||
| 312 | pem_x509.o: ../cryptlib.h pem_x509.c | ||
| 313 | pem_xaux.o: ../../e_os.h ../../include/openssl/aes.h | ||
| 314 | pem_xaux.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
| 315 | pem_xaux.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h | ||
| 316 | pem_xaux.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h | ||
| 317 | pem_xaux.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
| 318 | pem_xaux.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h | ||
| 319 | pem_xaux.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h | ||
| 320 | pem_xaux.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
| 321 | pem_xaux.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h | ||
| 322 | pem_xaux.o: ../../include/openssl/md2.h ../../include/openssl/md4.h | ||
| 323 | pem_xaux.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h | ||
| 324 | pem_xaux.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
| 325 | pem_xaux.o: ../../include/openssl/opensslconf.h | ||
| 326 | pem_xaux.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 327 | pem_xaux.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h | ||
| 328 | pem_xaux.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h | ||
| 329 | pem_xaux.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h | ||
| 330 | pem_xaux.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h | ||
| 331 | pem_xaux.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
| 332 | pem_xaux.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 333 | pem_xaux.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h | ||
| 334 | pem_xaux.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h | ||
| 335 | pem_xaux.o: ../cryptlib.h pem_xaux.c | ||
diff --git a/src/lib/libcrypto/pem/message b/src/lib/libcrypto/pem/message new file mode 100644 index 0000000000..e8bf9d7592 --- /dev/null +++ b/src/lib/libcrypto/pem/message | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | -----BEGIN PRIVACY-ENHANCED MESSAGE----- | ||
| 2 | Proc-Type: 4,ENCRYPTED | ||
| 3 | Proc-Type: 4,MIC-ONLY | ||
| 4 | Proc-Type: 4,MIC-CLEAR | ||
| 5 | Content-Domain: RFC822 | ||
| 6 | DEK-Info: DES-CBC,0123456789abcdef | ||
| 7 | Originator-Certificate | ||
| 8 | xxxx | ||
| 9 | Issuer-Certificate | ||
| 10 | xxxx | ||
| 11 | MIC-Info: RSA-MD5,RSA, | ||
| 12 | xxxx | ||
| 13 | |||
| 14 | |||
| 15 | -----END PRIVACY-ENHANCED MESSAGE----- | ||
| 16 | |||
diff --git a/src/lib/libcrypto/pem/pem.h b/src/lib/libcrypto/pem/pem.h new file mode 100644 index 0000000000..d330cbf9a3 --- /dev/null +++ b/src/lib/libcrypto/pem/pem.h | |||
| @@ -0,0 +1,672 @@ | |||
| 1 | /* crypto/pem/pem.h */ | ||
| 2 | /* Copyright (C) 1995-1997 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_PEM_H | ||
| 60 | #define HEADER_PEM_H | ||
| 61 | |||
| 62 | #ifndef OPENSSL_NO_BIO | ||
| 63 | #include <openssl/bio.h> | ||
| 64 | #endif | ||
| 65 | #ifndef OPENSSL_NO_STACK | ||
| 66 | #include <openssl/stack.h> | ||
| 67 | #endif | ||
| 68 | #include <openssl/evp.h> | ||
| 69 | #include <openssl/x509.h> | ||
| 70 | #include <openssl/pem2.h> | ||
| 71 | #include <openssl/e_os2.h> | ||
| 72 | |||
| 73 | #ifdef __cplusplus | ||
| 74 | extern "C" { | ||
| 75 | #endif | ||
| 76 | |||
| 77 | #define PEM_BUFSIZE 1024 | ||
| 78 | |||
| 79 | #define PEM_OBJ_UNDEF 0 | ||
| 80 | #define PEM_OBJ_X509 1 | ||
| 81 | #define PEM_OBJ_X509_REQ 2 | ||
| 82 | #define PEM_OBJ_CRL 3 | ||
| 83 | #define PEM_OBJ_SSL_SESSION 4 | ||
| 84 | #define PEM_OBJ_PRIV_KEY 10 | ||
| 85 | #define PEM_OBJ_PRIV_RSA 11 | ||
| 86 | #define PEM_OBJ_PRIV_DSA 12 | ||
| 87 | #define PEM_OBJ_PRIV_DH 13 | ||
| 88 | #define PEM_OBJ_PUB_RSA 14 | ||
| 89 | #define PEM_OBJ_PUB_DSA 15 | ||
| 90 | #define PEM_OBJ_PUB_DH 16 | ||
| 91 | #define PEM_OBJ_DHPARAMS 17 | ||
| 92 | #define PEM_OBJ_DSAPARAMS 18 | ||
| 93 | #define PEM_OBJ_PRIV_RSA_PUBLIC 19 | ||
| 94 | |||
| 95 | #define PEM_ERROR 30 | ||
| 96 | #define PEM_DEK_DES_CBC 40 | ||
| 97 | #define PEM_DEK_IDEA_CBC 45 | ||
| 98 | #define PEM_DEK_DES_EDE 50 | ||
| 99 | #define PEM_DEK_DES_ECB 60 | ||
| 100 | #define PEM_DEK_RSA 70 | ||
| 101 | #define PEM_DEK_RSA_MD2 80 | ||
| 102 | #define PEM_DEK_RSA_MD5 90 | ||
| 103 | |||
| 104 | #define PEM_MD_MD2 NID_md2 | ||
| 105 | #define PEM_MD_MD5 NID_md5 | ||
| 106 | #define PEM_MD_SHA NID_sha | ||
| 107 | #define PEM_MD_MD2_RSA NID_md2WithRSAEncryption | ||
| 108 | #define PEM_MD_MD5_RSA NID_md5WithRSAEncryption | ||
| 109 | #define PEM_MD_SHA_RSA NID_sha1WithRSAEncryption | ||
| 110 | |||
| 111 | #define PEM_STRING_X509_OLD "X509 CERTIFICATE" | ||
| 112 | #define PEM_STRING_X509 "CERTIFICATE" | ||
| 113 | #define PEM_STRING_X509_TRUSTED "TRUSTED CERTIFICATE" | ||
| 114 | #define PEM_STRING_X509_REQ_OLD "NEW CERTIFICATE REQUEST" | ||
| 115 | #define PEM_STRING_X509_REQ "CERTIFICATE REQUEST" | ||
| 116 | #define PEM_STRING_X509_CRL "X509 CRL" | ||
| 117 | #define PEM_STRING_EVP_PKEY "ANY PRIVATE KEY" | ||
| 118 | #define PEM_STRING_PUBLIC "PUBLIC KEY" | ||
| 119 | #define PEM_STRING_RSA "RSA PRIVATE KEY" | ||
| 120 | #define PEM_STRING_RSA_PUBLIC "RSA PUBLIC KEY" | ||
| 121 | #define PEM_STRING_DSA "DSA PRIVATE KEY" | ||
| 122 | #define PEM_STRING_DSA_PUBLIC "DSA PUBLIC KEY" | ||
| 123 | #define PEM_STRING_PKCS7 "PKCS7" | ||
| 124 | #define PEM_STRING_PKCS8 "ENCRYPTED PRIVATE KEY" | ||
| 125 | #define PEM_STRING_PKCS8INF "PRIVATE KEY" | ||
| 126 | #define PEM_STRING_DHPARAMS "DH PARAMETERS" | ||
| 127 | #define PEM_STRING_SSL_SESSION "SSL SESSION PARAMETERS" | ||
| 128 | #define PEM_STRING_DSAPARAMS "DSA PARAMETERS" | ||
| 129 | |||
| 130 | /* Note that this structure is initialised by PEM_SealInit and cleaned up | ||
| 131 | by PEM_SealFinal (at least for now) */ | ||
| 132 | typedef struct PEM_Encode_Seal_st | ||
| 133 | { | ||
| 134 | EVP_ENCODE_CTX encode; | ||
| 135 | EVP_MD_CTX md; | ||
| 136 | EVP_CIPHER_CTX cipher; | ||
| 137 | } PEM_ENCODE_SEAL_CTX; | ||
| 138 | |||
| 139 | /* enc_type is one off */ | ||
| 140 | #define PEM_TYPE_ENCRYPTED 10 | ||
| 141 | #define PEM_TYPE_MIC_ONLY 20 | ||
| 142 | #define PEM_TYPE_MIC_CLEAR 30 | ||
| 143 | #define PEM_TYPE_CLEAR 40 | ||
| 144 | |||
| 145 | typedef struct pem_recip_st | ||
| 146 | { | ||
| 147 | char *name; | ||
| 148 | X509_NAME *dn; | ||
| 149 | |||
| 150 | int cipher; | ||
| 151 | int key_enc; | ||
| 152 | /* char iv[8]; unused and wrong size */ | ||
| 153 | } PEM_USER; | ||
| 154 | |||
| 155 | typedef struct pem_ctx_st | ||
| 156 | { | ||
| 157 | int type; /* what type of object */ | ||
| 158 | |||
| 159 | struct { | ||
| 160 | int version; | ||
| 161 | int mode; | ||
| 162 | } proc_type; | ||
| 163 | |||
| 164 | char *domain; | ||
| 165 | |||
| 166 | struct { | ||
| 167 | int cipher; | ||
| 168 | /* unused, and wrong size | ||
| 169 | unsigned char iv[8]; */ | ||
| 170 | } DEK_info; | ||
| 171 | |||
| 172 | PEM_USER *originator; | ||
| 173 | |||
| 174 | int num_recipient; | ||
| 175 | PEM_USER **recipient; | ||
| 176 | |||
| 177 | #ifndef OPENSSL_NO_STACK | ||
| 178 | STACK *x509_chain; /* certificate chain */ | ||
| 179 | #else | ||
| 180 | char *x509_chain; /* certificate chain */ | ||
| 181 | #endif | ||
| 182 | EVP_MD *md; /* signature type */ | ||
| 183 | |||
| 184 | int md_enc; /* is the md encrypted or not? */ | ||
| 185 | int md_len; /* length of md_data */ | ||
| 186 | char *md_data; /* message digest, could be pkey encrypted */ | ||
| 187 | |||
| 188 | EVP_CIPHER *dec; /* date encryption cipher */ | ||
| 189 | int key_len; /* key length */ | ||
| 190 | unsigned char *key; /* key */ | ||
| 191 | /* unused, and wrong size | ||
| 192 | unsigned char iv[8]; */ | ||
| 193 | |||
| 194 | |||
| 195 | int data_enc; /* is the data encrypted */ | ||
| 196 | int data_len; | ||
| 197 | unsigned char *data; | ||
| 198 | } PEM_CTX; | ||
| 199 | |||
| 200 | /* These macros make the PEM_read/PEM_write functions easier to maintain and | ||
| 201 | * write. Now they are all implemented with either: | ||
| 202 | * IMPLEMENT_PEM_rw(...) or IMPLEMENT_PEM_rw_cb(...) | ||
| 203 | */ | ||
| 204 | |||
| 205 | #ifdef OPENSSL_NO_FP_API | ||
| 206 | |||
| 207 | #define IMPLEMENT_PEM_read_fp(name, type, str, asn1) /**/ | ||
| 208 | #define IMPLEMENT_PEM_write_fp(name, type, str, asn1) /**/ | ||
| 209 | #define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) /**/ | ||
| 210 | |||
| 211 | #else | ||
| 212 | |||
| 213 | #define IMPLEMENT_PEM_read_fp(name, type, str, asn1) \ | ||
| 214 | type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u)\ | ||
| 215 | { \ | ||
| 216 | return((type *)PEM_ASN1_read((char *(*)())d2i_##asn1, str,fp,(char **)x,\ | ||
| 217 | cb,u)); \ | ||
| 218 | } \ | ||
| 219 | |||
| 220 | #define IMPLEMENT_PEM_write_fp(name, type, str, asn1) \ | ||
| 221 | int PEM_write_##name(FILE *fp, type *x) \ | ||
| 222 | { \ | ||
| 223 | return(PEM_ASN1_write((int (*)())i2d_##asn1,str,fp, (char *)x, \ | ||
| 224 | NULL,NULL,0,NULL,NULL)); \ | ||
| 225 | } | ||
| 226 | |||
| 227 | #define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) \ | ||
| 228 | int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \ | ||
| 229 | unsigned char *kstr, int klen, pem_password_cb *cb, \ | ||
| 230 | void *u) \ | ||
| 231 | { \ | ||
| 232 | return(PEM_ASN1_write((int (*)())i2d_##asn1,str,fp, \ | ||
| 233 | (char *)x,enc,kstr,klen,cb,u)); \ | ||
| 234 | } | ||
| 235 | |||
| 236 | #endif | ||
| 237 | |||
| 238 | #define IMPLEMENT_PEM_read_bio(name, type, str, asn1) \ | ||
| 239 | type *PEM_read_bio_##name(BIO *bp, type **x, pem_password_cb *cb, void *u)\ | ||
| 240 | { \ | ||
| 241 | return((type *)PEM_ASN1_read_bio((char *(*)())d2i_##asn1, str,bp,\ | ||
| 242 | (char **)x,cb,u)); \ | ||
| 243 | } | ||
| 244 | |||
| 245 | #define IMPLEMENT_PEM_write_bio(name, type, str, asn1) \ | ||
| 246 | int PEM_write_bio_##name(BIO *bp, type *x) \ | ||
| 247 | { \ | ||
| 248 | return(PEM_ASN1_write_bio((int (*)())i2d_##asn1,str,bp, (char *)x, \ | ||
| 249 | NULL,NULL,0,NULL,NULL)); \ | ||
| 250 | } | ||
| 251 | |||
| 252 | #define IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \ | ||
| 253 | int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \ | ||
| 254 | unsigned char *kstr, int klen, pem_password_cb *cb, void *u) \ | ||
| 255 | { \ | ||
| 256 | return(PEM_ASN1_write_bio((int (*)())i2d_##asn1,str,bp, \ | ||
| 257 | (char *)x,enc,kstr,klen,cb,u)); \ | ||
| 258 | } | ||
| 259 | |||
| 260 | #define IMPLEMENT_PEM_write(name, type, str, asn1) \ | ||
| 261 | IMPLEMENT_PEM_write_bio(name, type, str, asn1) \ | ||
| 262 | IMPLEMENT_PEM_write_fp(name, type, str, asn1) | ||
| 263 | |||
| 264 | #define IMPLEMENT_PEM_write_cb(name, type, str, asn1) \ | ||
| 265 | IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \ | ||
| 266 | IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) | ||
| 267 | |||
| 268 | #define IMPLEMENT_PEM_read(name, type, str, asn1) \ | ||
| 269 | IMPLEMENT_PEM_read_bio(name, type, str, asn1) \ | ||
| 270 | IMPLEMENT_PEM_read_fp(name, type, str, asn1) | ||
| 271 | |||
| 272 | #define IMPLEMENT_PEM_rw(name, type, str, asn1) \ | ||
| 273 | IMPLEMENT_PEM_read(name, type, str, asn1) \ | ||
| 274 | IMPLEMENT_PEM_write(name, type, str, asn1) | ||
| 275 | |||
| 276 | #define IMPLEMENT_PEM_rw_cb(name, type, str, asn1) \ | ||
| 277 | IMPLEMENT_PEM_read(name, type, str, asn1) \ | ||
| 278 | IMPLEMENT_PEM_write_cb(name, type, str, asn1) | ||
| 279 | |||
| 280 | /* These are the same except they are for the declarations */ | ||
| 281 | |||
| 282 | #if defined(OPENSSL_SYS_WIN16) || defined(OPENSSL_NO_FP_API) | ||
| 283 | |||
| 284 | #define DECLARE_PEM_read_fp(name, type) /**/ | ||
| 285 | #define DECLARE_PEM_write_fp(name, type) /**/ | ||
| 286 | #define DECLARE_PEM_write_cb_fp(name, type) /**/ | ||
| 287 | |||
| 288 | #else | ||
| 289 | |||
| 290 | #define DECLARE_PEM_read_fp(name, type) \ | ||
| 291 | type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u); | ||
| 292 | |||
| 293 | #define DECLARE_PEM_write_fp(name, type) \ | ||
| 294 | int PEM_write_##name(FILE *fp, type *x); | ||
| 295 | |||
| 296 | #define DECLARE_PEM_write_cb_fp(name, type) \ | ||
| 297 | int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \ | ||
| 298 | unsigned char *kstr, int klen, pem_password_cb *cb, void *u); | ||
| 299 | |||
| 300 | #endif | ||
| 301 | |||
| 302 | #ifndef OPENSSL_NO_BIO | ||
| 303 | #define DECLARE_PEM_read_bio(name, type) \ | ||
| 304 | type *PEM_read_bio_##name(BIO *bp, type **x, pem_password_cb *cb, void *u); | ||
| 305 | |||
| 306 | #define DECLARE_PEM_write_bio(name, type) \ | ||
| 307 | int PEM_write_bio_##name(BIO *bp, type *x); | ||
| 308 | |||
| 309 | #define DECLARE_PEM_write_cb_bio(name, type) \ | ||
| 310 | int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \ | ||
| 311 | unsigned char *kstr, int klen, pem_password_cb *cb, void *u); | ||
| 312 | |||
| 313 | #else | ||
| 314 | |||
| 315 | #define DECLARE_PEM_read_bio(name, type) /**/ | ||
| 316 | #define DECLARE_PEM_write_bio(name, type) /**/ | ||
| 317 | #define DECLARE_PEM_write_cb_bio(name, type) /**/ | ||
| 318 | |||
| 319 | #endif | ||
| 320 | |||
| 321 | #define DECLARE_PEM_write(name, type) \ | ||
| 322 | DECLARE_PEM_write_bio(name, type) \ | ||
| 323 | DECLARE_PEM_write_fp(name, type) | ||
| 324 | |||
| 325 | #define DECLARE_PEM_write_cb(name, type) \ | ||
| 326 | DECLARE_PEM_write_cb_bio(name, type) \ | ||
| 327 | DECLARE_PEM_write_cb_fp(name, type) | ||
| 328 | |||
| 329 | #define DECLARE_PEM_read(name, type) \ | ||
| 330 | DECLARE_PEM_read_bio(name, type) \ | ||
| 331 | DECLARE_PEM_read_fp(name, type) | ||
| 332 | |||
| 333 | #define DECLARE_PEM_rw(name, type) \ | ||
| 334 | DECLARE_PEM_read(name, type) \ | ||
| 335 | DECLARE_PEM_write(name, type) | ||
| 336 | |||
| 337 | #define DECLARE_PEM_rw_cb(name, type) \ | ||
| 338 | DECLARE_PEM_read(name, type) \ | ||
| 339 | DECLARE_PEM_write_cb(name, type) | ||
| 340 | |||
| 341 | #ifdef SSLEAY_MACROS | ||
| 342 | |||
| 343 | #define PEM_write_SSL_SESSION(fp,x) \ | ||
| 344 | PEM_ASN1_write((int (*)())i2d_SSL_SESSION, \ | ||
| 345 | PEM_STRING_SSL_SESSION,fp, (char *)x, NULL,NULL,0,NULL,NULL) | ||
| 346 | #define PEM_write_X509(fp,x) \ | ||
| 347 | PEM_ASN1_write((int (*)())i2d_X509,PEM_STRING_X509,fp, \ | ||
| 348 | (char *)x, NULL,NULL,0,NULL,NULL) | ||
| 349 | #define PEM_write_X509_REQ(fp,x) PEM_ASN1_write( \ | ||
| 350 | (int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,fp,(char *)x, \ | ||
| 351 | NULL,NULL,0,NULL,NULL) | ||
| 352 | #define PEM_write_X509_CRL(fp,x) \ | ||
| 353 | PEM_ASN1_write((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL, \ | ||
| 354 | fp,(char *)x, NULL,NULL,0,NULL,NULL) | ||
| 355 | #define PEM_write_RSAPrivateKey(fp,x,enc,kstr,klen,cb,u) \ | ||
| 356 | PEM_ASN1_write((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,fp,\ | ||
| 357 | (char *)x,enc,kstr,klen,cb,u) | ||
| 358 | #define PEM_write_RSAPublicKey(fp,x) \ | ||
| 359 | PEM_ASN1_write((int (*)())i2d_RSAPublicKey,\ | ||
| 360 | PEM_STRING_RSA_PUBLIC,fp,(char *)x,NULL,NULL,0,NULL,NULL) | ||
| 361 | #define PEM_write_DSAPrivateKey(fp,x,enc,kstr,klen,cb,u) \ | ||
| 362 | PEM_ASN1_write((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,fp,\ | ||
| 363 | (char *)x,enc,kstr,klen,cb,u) | ||
| 364 | #define PEM_write_PrivateKey(bp,x,enc,kstr,klen,cb,u) \ | ||
| 365 | PEM_ASN1_write((int (*)())i2d_PrivateKey,\ | ||
| 366 | (((x)->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),\ | ||
| 367 | bp,(char *)x,enc,kstr,klen,cb,u) | ||
| 368 | #define PEM_write_PKCS7(fp,x) \ | ||
| 369 | PEM_ASN1_write((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,fp, \ | ||
| 370 | (char *)x, NULL,NULL,0,NULL,NULL) | ||
| 371 | #define PEM_write_DHparams(fp,x) \ | ||
| 372 | PEM_ASN1_write((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,fp,\ | ||
| 373 | (char *)x,NULL,NULL,0,NULL,NULL) | ||
| 374 | |||
| 375 | #define PEM_write_NETSCAPE_CERT_SEQUENCE(fp,x) \ | ||
| 376 | PEM_ASN1_write((int (*)())i2d_NETSCAPE_CERT_SEQUENCE, \ | ||
| 377 | PEM_STRING_X509,fp, \ | ||
| 378 | (char *)x, NULL,NULL,0,NULL,NULL) | ||
| 379 | |||
| 380 | #define PEM_read_SSL_SESSION(fp,x,cb,u) (SSL_SESSION *)PEM_ASN1_read( \ | ||
| 381 | (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,fp,(char **)x,cb,u) | ||
| 382 | #define PEM_read_X509(fp,x,cb,u) (X509 *)PEM_ASN1_read( \ | ||
| 383 | (char *(*)())d2i_X509,PEM_STRING_X509,fp,(char **)x,cb,u) | ||
| 384 | #define PEM_read_X509_REQ(fp,x,cb,u) (X509_REQ *)PEM_ASN1_read( \ | ||
| 385 | (char *(*)())d2i_X509_REQ,PEM_STRING_X509_REQ,fp,(char **)x,cb,u) | ||
| 386 | #define PEM_read_X509_CRL(fp,x,cb,u) (X509_CRL *)PEM_ASN1_read( \ | ||
| 387 | (char *(*)())d2i_X509_CRL,PEM_STRING_X509_CRL,fp,(char **)x,cb,u) | ||
| 388 | #define PEM_read_RSAPrivateKey(fp,x,cb,u) (RSA *)PEM_ASN1_read( \ | ||
| 389 | (char *(*)())d2i_RSAPrivateKey,PEM_STRING_RSA,fp,(char **)x,cb,u) | ||
| 390 | #define PEM_read_RSAPublicKey(fp,x,cb,u) (RSA *)PEM_ASN1_read( \ | ||
| 391 | (char *(*)())d2i_RSAPublicKey,PEM_STRING_RSA_PUBLIC,fp,(char **)x,cb,u) | ||
| 392 | #define PEM_read_DSAPrivateKey(fp,x,cb,u) (DSA *)PEM_ASN1_read( \ | ||
| 393 | (char *(*)())d2i_DSAPrivateKey,PEM_STRING_DSA,fp,(char **)x,cb,u) | ||
| 394 | #define PEM_read_PrivateKey(fp,x,cb,u) (EVP_PKEY *)PEM_ASN1_read( \ | ||
| 395 | (char *(*)())d2i_PrivateKey,PEM_STRING_EVP_PKEY,fp,(char **)x,cb,u) | ||
| 396 | #define PEM_read_PKCS7(fp,x,cb,u) (PKCS7 *)PEM_ASN1_read( \ | ||
| 397 | (char *(*)())d2i_PKCS7,PEM_STRING_PKCS7,fp,(char **)x,cb,u) | ||
| 398 | #define PEM_read_DHparams(fp,x,cb,u) (DH *)PEM_ASN1_read( \ | ||
| 399 | (char *(*)())d2i_DHparams,PEM_STRING_DHPARAMS,fp,(char **)x,cb,u) | ||
| 400 | |||
| 401 | #define PEM_read_NETSCAPE_CERT_SEQUENCE(fp,x,cb,u) \ | ||
| 402 | (NETSCAPE_CERT_SEQUENCE *)PEM_ASN1_read( \ | ||
| 403 | (char *(*)())d2i_NETSCAPE_CERT_SEQUENCE,PEM_STRING_X509,fp,\ | ||
| 404 | (char **)x,cb,u) | ||
| 405 | |||
| 406 | #define PEM_write_bio_SSL_SESSION(bp,x) \ | ||
| 407 | PEM_ASN1_write_bio((int (*)())i2d_SSL_SESSION, \ | ||
| 408 | PEM_STRING_SSL_SESSION,bp, (char *)x, NULL,NULL,0,NULL,NULL) | ||
| 409 | #define PEM_write_bio_X509(bp,x) \ | ||
| 410 | PEM_ASN1_write_bio((int (*)())i2d_X509,PEM_STRING_X509,bp, \ | ||
| 411 | (char *)x, NULL,NULL,0,NULL,NULL) | ||
| 412 | #define PEM_write_bio_X509_REQ(bp,x) PEM_ASN1_write_bio( \ | ||
| 413 | (int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,bp,(char *)x, \ | ||
| 414 | NULL,NULL,0,NULL,NULL) | ||
| 415 | #define PEM_write_bio_X509_CRL(bp,x) \ | ||
| 416 | PEM_ASN1_write_bio((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL,\ | ||
| 417 | bp,(char *)x, NULL,NULL,0,NULL,NULL) | ||
| 418 | #define PEM_write_bio_RSAPrivateKey(bp,x,enc,kstr,klen,cb,u) \ | ||
| 419 | PEM_ASN1_write_bio((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,\ | ||
| 420 | bp,(char *)x,enc,kstr,klen,cb,u) | ||
| 421 | #define PEM_write_bio_RSAPublicKey(bp,x) \ | ||
| 422 | PEM_ASN1_write_bio((int (*)())i2d_RSAPublicKey, \ | ||
| 423 | PEM_STRING_RSA_PUBLIC,\ | ||
| 424 | bp,(char *)x,NULL,NULL,0,NULL,NULL) | ||
| 425 | #define PEM_write_bio_DSAPrivateKey(bp,x,enc,kstr,klen,cb,u) \ | ||
| 426 | PEM_ASN1_write_bio((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,\ | ||
| 427 | bp,(char *)x,enc,kstr,klen,cb,u) | ||
| 428 | #define PEM_write_bio_PrivateKey(bp,x,enc,kstr,klen,cb,u) \ | ||
| 429 | PEM_ASN1_write_bio((int (*)())i2d_PrivateKey,\ | ||
| 430 | (((x)->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),\ | ||
| 431 | bp,(char *)x,enc,kstr,klen,cb,u) | ||
| 432 | #define PEM_write_bio_PKCS7(bp,x) \ | ||
| 433 | PEM_ASN1_write_bio((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,bp, \ | ||
| 434 | (char *)x, NULL,NULL,0,NULL,NULL) | ||
| 435 | #define PEM_write_bio_DHparams(bp,x) \ | ||
| 436 | PEM_ASN1_write_bio((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,\ | ||
| 437 | bp,(char *)x,NULL,NULL,0,NULL,NULL) | ||
| 438 | #define PEM_write_bio_DSAparams(bp,x) \ | ||
| 439 | PEM_ASN1_write_bio((int (*)())i2d_DSAparams, \ | ||
| 440 | PEM_STRING_DSAPARAMS,bp,(char *)x,NULL,NULL,0,NULL,NULL) | ||
| 441 | |||
| 442 | #define PEM_write_bio_NETSCAPE_CERT_SEQUENCE(bp,x) \ | ||
| 443 | PEM_ASN1_write_bio((int (*)())i2d_NETSCAPE_CERT_SEQUENCE, \ | ||
| 444 | PEM_STRING_X509,bp, \ | ||
| 445 | (char *)x, NULL,NULL,0,NULL,NULL) | ||
| 446 | |||
| 447 | #define PEM_read_bio_SSL_SESSION(bp,x,cb,u) (SSL_SESSION *)PEM_ASN1_read_bio( \ | ||
| 448 | (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,bp,(char **)x,cb,u) | ||
| 449 | #define PEM_read_bio_X509(bp,x,cb,u) (X509 *)PEM_ASN1_read_bio( \ | ||
| 450 | (char *(*)())d2i_X509,PEM_STRING_X509,bp,(char **)x,cb,u) | ||
| 451 | #define PEM_read_bio_X509_REQ(bp,x,cb,u) (X509_REQ *)PEM_ASN1_read_bio( \ | ||
| 452 | (char *(*)())d2i_X509_REQ,PEM_STRING_X509_REQ,bp,(char **)x,cb,u) | ||
| 453 | #define PEM_read_bio_X509_CRL(bp,x,cb,u) (X509_CRL *)PEM_ASN1_read_bio( \ | ||
| 454 | (char *(*)())d2i_X509_CRL,PEM_STRING_X509_CRL,bp,(char **)x,cb,u) | ||
| 455 | #define PEM_read_bio_RSAPrivateKey(bp,x,cb,u) (RSA *)PEM_ASN1_read_bio( \ | ||
| 456 | (char *(*)())d2i_RSAPrivateKey,PEM_STRING_RSA,bp,(char **)x,cb,u) | ||
| 457 | #define PEM_read_bio_RSAPublicKey(bp,x,cb,u) (RSA *)PEM_ASN1_read_bio( \ | ||
| 458 | (char *(*)())d2i_RSAPublicKey,PEM_STRING_RSA_PUBLIC,bp,(char **)x,cb,u) | ||
| 459 | #define PEM_read_bio_DSAPrivateKey(bp,x,cb,u) (DSA *)PEM_ASN1_read_bio( \ | ||
| 460 | (char *(*)())d2i_DSAPrivateKey,PEM_STRING_DSA,bp,(char **)x,cb,u) | ||
| 461 | #define PEM_read_bio_PrivateKey(bp,x,cb,u) (EVP_PKEY *)PEM_ASN1_read_bio( \ | ||
| 462 | (char *(*)())d2i_PrivateKey,PEM_STRING_EVP_PKEY,bp,(char **)x,cb,u) | ||
| 463 | |||
| 464 | #define PEM_read_bio_PKCS7(bp,x,cb,u) (PKCS7 *)PEM_ASN1_read_bio( \ | ||
| 465 | (char *(*)())d2i_PKCS7,PEM_STRING_PKCS7,bp,(char **)x,cb,u) | ||
| 466 | #define PEM_read_bio_DHparams(bp,x,cb,u) (DH *)PEM_ASN1_read_bio( \ | ||
| 467 | (char *(*)())d2i_DHparams,PEM_STRING_DHPARAMS,bp,(char **)x,cb,u) | ||
| 468 | #define PEM_read_bio_DSAparams(bp,x,cb,u) (DSA *)PEM_ASN1_read_bio( \ | ||
| 469 | (char *(*)())d2i_DSAparams,PEM_STRING_DSAPARAMS,bp,(char **)x,cb,u) | ||
| 470 | |||
| 471 | #define PEM_read_bio_NETSCAPE_CERT_SEQUENCE(bp,x,cb,u) \ | ||
| 472 | (NETSCAPE_CERT_SEQUENCE *)PEM_ASN1_read_bio( \ | ||
| 473 | (char *(*)())d2i_NETSCAPE_CERT_SEQUENCE,PEM_STRING_X509,bp,\ | ||
| 474 | (char **)x,cb,u) | ||
| 475 | |||
| 476 | #endif | ||
| 477 | |||
| 478 | #if 1 | ||
| 479 | /* "userdata": new with OpenSSL 0.9.4 */ | ||
| 480 | typedef int pem_password_cb(char *buf, int size, int rwflag, void *userdata); | ||
| 481 | #else | ||
| 482 | /* OpenSSL 0.9.3, 0.9.3a */ | ||
| 483 | typedef int pem_password_cb(char *buf, int size, int rwflag); | ||
| 484 | #endif | ||
| 485 | |||
| 486 | int PEM_get_EVP_CIPHER_INFO(char *header, EVP_CIPHER_INFO *cipher); | ||
| 487 | int PEM_do_header (EVP_CIPHER_INFO *cipher, unsigned char *data,long *len, | ||
| 488 | pem_password_cb *callback,void *u); | ||
| 489 | |||
| 490 | #ifndef OPENSSL_NO_BIO | ||
| 491 | int PEM_read_bio(BIO *bp, char **name, char **header, | ||
| 492 | unsigned char **data,long *len); | ||
| 493 | int PEM_write_bio(BIO *bp,const char *name,char *hdr,unsigned char *data, | ||
| 494 | long len); | ||
| 495 | int PEM_bytes_read_bio(unsigned char **pdata, long *plen, char **pnm, const char *name, BIO *bp, | ||
| 496 | pem_password_cb *cb, void *u); | ||
| 497 | char * PEM_ASN1_read_bio(char *(*d2i)(),const char *name,BIO *bp,char **x, | ||
| 498 | pem_password_cb *cb, void *u); | ||
| 499 | int PEM_ASN1_write_bio(int (*i2d)(),const char *name,BIO *bp,char *x, | ||
| 500 | const EVP_CIPHER *enc,unsigned char *kstr,int klen, | ||
| 501 | pem_password_cb *cb, void *u); | ||
| 502 | STACK_OF(X509_INFO) * PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u); | ||
| 503 | int PEM_X509_INFO_write_bio(BIO *bp,X509_INFO *xi, EVP_CIPHER *enc, | ||
| 504 | unsigned char *kstr, int klen, pem_password_cb *cd, void *u); | ||
| 505 | #endif | ||
| 506 | |||
| 507 | #ifndef OPENSSL_SYS_WIN16 | ||
| 508 | int PEM_read(FILE *fp, char **name, char **header, | ||
| 509 | unsigned char **data,long *len); | ||
| 510 | int PEM_write(FILE *fp,char *name,char *hdr,unsigned char *data,long len); | ||
| 511 | char * PEM_ASN1_read(char *(*d2i)(),const char *name,FILE *fp,char **x, | ||
| 512 | pem_password_cb *cb, void *u); | ||
| 513 | int PEM_ASN1_write(int (*i2d)(),const char *name,FILE *fp,char *x, | ||
| 514 | const EVP_CIPHER *enc,unsigned char *kstr,int klen, | ||
| 515 | pem_password_cb *callback, void *u); | ||
| 516 | STACK_OF(X509_INFO) * PEM_X509_INFO_read(FILE *fp, STACK_OF(X509_INFO) *sk, | ||
| 517 | pem_password_cb *cb, void *u); | ||
| 518 | #endif | ||
| 519 | |||
| 520 | int PEM_SealInit(PEM_ENCODE_SEAL_CTX *ctx, EVP_CIPHER *type, | ||
| 521 | EVP_MD *md_type, unsigned char **ek, int *ekl, | ||
| 522 | unsigned char *iv, EVP_PKEY **pubk, int npubk); | ||
| 523 | void PEM_SealUpdate(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *out, int *outl, | ||
| 524 | unsigned char *in, int inl); | ||
| 525 | int PEM_SealFinal(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *sig,int *sigl, | ||
| 526 | unsigned char *out, int *outl, EVP_PKEY *priv); | ||
| 527 | |||
| 528 | void PEM_SignInit(EVP_MD_CTX *ctx, EVP_MD *type); | ||
| 529 | void PEM_SignUpdate(EVP_MD_CTX *ctx,unsigned char *d,unsigned int cnt); | ||
| 530 | int PEM_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, | ||
| 531 | unsigned int *siglen, EVP_PKEY *pkey); | ||
| 532 | |||
| 533 | int PEM_def_callback(char *buf, int num, int w, void *key); | ||
| 534 | void PEM_proc_type(char *buf, int type); | ||
| 535 | void PEM_dek_info(char *buf, const char *type, int len, char *str); | ||
| 536 | |||
| 537 | #ifndef SSLEAY_MACROS | ||
| 538 | |||
| 539 | #include <openssl/symhacks.h> | ||
| 540 | |||
| 541 | DECLARE_PEM_rw(X509, X509) | ||
| 542 | |||
| 543 | DECLARE_PEM_rw(X509_AUX, X509) | ||
| 544 | |||
| 545 | DECLARE_PEM_rw(X509_REQ, X509_REQ) | ||
| 546 | DECLARE_PEM_write(X509_REQ_NEW, X509_REQ) | ||
| 547 | |||
| 548 | DECLARE_PEM_rw(X509_CRL, X509_CRL) | ||
| 549 | |||
| 550 | DECLARE_PEM_rw(PKCS7, PKCS7) | ||
| 551 | |||
| 552 | DECLARE_PEM_rw(NETSCAPE_CERT_SEQUENCE, NETSCAPE_CERT_SEQUENCE) | ||
| 553 | |||
| 554 | DECLARE_PEM_rw(PKCS8, X509_SIG) | ||
| 555 | |||
| 556 | DECLARE_PEM_rw(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO) | ||
| 557 | |||
| 558 | #ifndef OPENSSL_NO_RSA | ||
| 559 | |||
| 560 | DECLARE_PEM_rw_cb(RSAPrivateKey, RSA) | ||
| 561 | |||
| 562 | DECLARE_PEM_rw(RSAPublicKey, RSA) | ||
| 563 | DECLARE_PEM_rw(RSA_PUBKEY, RSA) | ||
| 564 | |||
| 565 | #endif | ||
| 566 | |||
| 567 | #ifndef OPENSSL_NO_DSA | ||
| 568 | |||
| 569 | DECLARE_PEM_rw_cb(DSAPrivateKey, DSA) | ||
| 570 | |||
| 571 | DECLARE_PEM_rw(DSA_PUBKEY, DSA) | ||
| 572 | |||
| 573 | DECLARE_PEM_rw(DSAparams, DSA) | ||
| 574 | |||
| 575 | #endif | ||
| 576 | |||
| 577 | #ifndef OPENSSL_NO_DH | ||
| 578 | |||
| 579 | DECLARE_PEM_rw(DHparams, DH) | ||
| 580 | |||
| 581 | #endif | ||
| 582 | |||
| 583 | DECLARE_PEM_rw_cb(PrivateKey, EVP_PKEY) | ||
| 584 | |||
| 585 | DECLARE_PEM_rw(PUBKEY, EVP_PKEY) | ||
| 586 | |||
| 587 | int PEM_write_bio_PKCS8PrivateKey_nid(BIO *bp, EVP_PKEY *x, int nid, | ||
| 588 | char *kstr, int klen, | ||
| 589 | pem_password_cb *cb, void *u); | ||
| 590 | int PEM_write_bio_PKCS8PrivateKey(BIO *, EVP_PKEY *, const EVP_CIPHER *, | ||
| 591 | char *, int, pem_password_cb *, void *); | ||
| 592 | int i2d_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc, | ||
| 593 | char *kstr, int klen, | ||
| 594 | pem_password_cb *cb, void *u); | ||
| 595 | int i2d_PKCS8PrivateKey_nid_bio(BIO *bp, EVP_PKEY *x, int nid, | ||
| 596 | char *kstr, int klen, | ||
| 597 | pem_password_cb *cb, void *u); | ||
| 598 | EVP_PKEY *d2i_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, void *u); | ||
| 599 | |||
| 600 | int i2d_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc, | ||
| 601 | char *kstr, int klen, | ||
| 602 | pem_password_cb *cb, void *u); | ||
| 603 | int i2d_PKCS8PrivateKey_nid_fp(FILE *fp, EVP_PKEY *x, int nid, | ||
| 604 | char *kstr, int klen, | ||
| 605 | pem_password_cb *cb, void *u); | ||
| 606 | int PEM_write_PKCS8PrivateKey_nid(FILE *fp, EVP_PKEY *x, int nid, | ||
| 607 | char *kstr, int klen, | ||
| 608 | pem_password_cb *cb, void *u); | ||
| 609 | |||
| 610 | EVP_PKEY *d2i_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, void *u); | ||
| 611 | |||
| 612 | int PEM_write_PKCS8PrivateKey(FILE *fp,EVP_PKEY *x,const EVP_CIPHER *enc, | ||
| 613 | char *kstr,int klen, pem_password_cb *cd, void *u); | ||
| 614 | |||
| 615 | #endif /* SSLEAY_MACROS */ | ||
| 616 | |||
| 617 | |||
| 618 | /* BEGIN ERROR CODES */ | ||
| 619 | /* The following lines are auto generated by the script mkerr.pl. Any changes | ||
| 620 | * made after this point may be overwritten when the script is next run. | ||
| 621 | */ | ||
| 622 | void ERR_load_PEM_strings(void); | ||
| 623 | |||
| 624 | /* Error codes for the PEM functions. */ | ||
| 625 | |||
| 626 | /* Function codes. */ | ||
| 627 | #define PEM_F_D2I_PKCS8PRIVATEKEY_BIO 120 | ||
| 628 | #define PEM_F_D2I_PKCS8PRIVATEKEY_FP 121 | ||
| 629 | #define PEM_F_DEF_CALLBACK 100 | ||
| 630 | #define PEM_F_LOAD_IV 101 | ||
| 631 | #define PEM_F_PEM_ASN1_READ 102 | ||
| 632 | #define PEM_F_PEM_ASN1_READ_BIO 103 | ||
| 633 | #define PEM_F_PEM_ASN1_WRITE 104 | ||
| 634 | #define PEM_F_PEM_ASN1_WRITE_BIO 105 | ||
| 635 | #define PEM_F_PEM_DO_HEADER 106 | ||
| 636 | #define PEM_F_PEM_F_DO_PK8KEY_FP 122 | ||
| 637 | #define PEM_F_PEM_F_PEM_WRITE_PKCS8PRIVATEKEY 118 | ||
| 638 | #define PEM_F_PEM_GET_EVP_CIPHER_INFO 107 | ||
| 639 | #define PEM_F_PEM_READ 108 | ||
| 640 | #define PEM_F_PEM_READ_BIO 109 | ||
| 641 | #define PEM_F_PEM_SEALFINAL 110 | ||
| 642 | #define PEM_F_PEM_SEALINIT 111 | ||
| 643 | #define PEM_F_PEM_SIGNFINAL 112 | ||
| 644 | #define PEM_F_PEM_WRITE 113 | ||
| 645 | #define PEM_F_PEM_WRITE_BIO 114 | ||
| 646 | #define PEM_F_PEM_WRITE_BIO_PKCS8PRIVATEKEY 119 | ||
| 647 | #define PEM_F_PEM_X509_INFO_READ 115 | ||
| 648 | #define PEM_F_PEM_X509_INFO_READ_BIO 116 | ||
| 649 | #define PEM_F_PEM_X509_INFO_WRITE_BIO 117 | ||
| 650 | |||
| 651 | /* Reason codes. */ | ||
| 652 | #define PEM_R_BAD_BASE64_DECODE 100 | ||
| 653 | #define PEM_R_BAD_DECRYPT 101 | ||
| 654 | #define PEM_R_BAD_END_LINE 102 | ||
| 655 | #define PEM_R_BAD_IV_CHARS 103 | ||
| 656 | #define PEM_R_BAD_PASSWORD_READ 104 | ||
| 657 | #define PEM_R_ERROR_CONVERTING_PRIVATE_KEY 115 | ||
| 658 | #define PEM_R_NOT_DEK_INFO 105 | ||
| 659 | #define PEM_R_NOT_ENCRYPTED 106 | ||
| 660 | #define PEM_R_NOT_PROC_TYPE 107 | ||
| 661 | #define PEM_R_NO_START_LINE 108 | ||
| 662 | #define PEM_R_PROBLEMS_GETTING_PASSWORD 109 | ||
| 663 | #define PEM_R_PUBLIC_KEY_NO_RSA 110 | ||
| 664 | #define PEM_R_READ_KEY 111 | ||
| 665 | #define PEM_R_SHORT_HEADER 112 | ||
| 666 | #define PEM_R_UNSUPPORTED_CIPHER 113 | ||
| 667 | #define PEM_R_UNSUPPORTED_ENCRYPTION 114 | ||
| 668 | |||
| 669 | #ifdef __cplusplus | ||
| 670 | } | ||
| 671 | #endif | ||
| 672 | #endif | ||
diff --git a/src/lib/libcrypto/pem/pem2.h b/src/lib/libcrypto/pem/pem2.h new file mode 100644 index 0000000000..f31790d69c --- /dev/null +++ b/src/lib/libcrypto/pem/pem2.h | |||
| @@ -0,0 +1,70 @@ | |||
| 1 | /* ==================================================================== | ||
| 2 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
| 3 | * | ||
| 4 | * Redistribution and use in source and binary forms, with or without | ||
| 5 | * modification, are permitted provided that the following conditions | ||
| 6 | * are met: | ||
| 7 | * | ||
| 8 | * 1. Redistributions of source code must retain the above copyright | ||
| 9 | * notice, this list of conditions and the following disclaimer. | ||
| 10 | * | ||
| 11 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 12 | * notice, this list of conditions and the following disclaimer in | ||
| 13 | * the documentation and/or other materials provided with the | ||
| 14 | * distribution. | ||
| 15 | * | ||
| 16 | * 3. All advertising materials mentioning features or use of this | ||
| 17 | * software must display the following acknowledgment: | ||
| 18 | * "This product includes software developed by the OpenSSL Project | ||
| 19 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 20 | * | ||
| 21 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 22 | * endorse or promote products derived from this software without | ||
| 23 | * prior written permission. For written permission, please contact | ||
| 24 | * licensing@OpenSSL.org. | ||
| 25 | * | ||
| 26 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 27 | * nor may "OpenSSL" appear in their names without prior written | ||
| 28 | * permission of the OpenSSL Project. | ||
| 29 | * | ||
| 30 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 31 | * acknowledgment: | ||
| 32 | * "This product includes software developed by the OpenSSL Project | ||
| 33 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 34 | * | ||
| 35 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 36 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 37 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 38 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 39 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 40 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 41 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 42 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 43 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 44 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 45 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 46 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 47 | * ==================================================================== | ||
| 48 | * | ||
| 49 | * This product includes cryptographic software written by Eric Young | ||
| 50 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 51 | * Hudson (tjh@cryptsoft.com). | ||
| 52 | * | ||
| 53 | */ | ||
| 54 | |||
| 55 | /* | ||
| 56 | * This header only exists to break a circular dependency between pem and err | ||
| 57 | * Ben 30 Jan 1999. | ||
| 58 | */ | ||
| 59 | |||
| 60 | #ifdef __cplusplus | ||
| 61 | extern "C" { | ||
| 62 | #endif | ||
| 63 | |||
| 64 | #ifndef HEADER_PEM_H | ||
| 65 | void ERR_load_PEM_strings(void); | ||
| 66 | #endif | ||
| 67 | |||
| 68 | #ifdef __cplusplus | ||
| 69 | } | ||
| 70 | #endif | ||
diff --git a/src/lib/libcrypto/pem/pem_all.c b/src/lib/libcrypto/pem/pem_all.c new file mode 100644 index 0000000000..07963314c9 --- /dev/null +++ b/src/lib/libcrypto/pem/pem_all.c | |||
| @@ -0,0 +1,315 @@ | |||
| 1 | /* crypto/pem/pem_all.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 | #undef SSLEAY_MACROS | ||
| 61 | #include "cryptlib.h" | ||
| 62 | #include <openssl/bio.h> | ||
| 63 | #include <openssl/evp.h> | ||
| 64 | #include <openssl/x509.h> | ||
| 65 | #include <openssl/pkcs7.h> | ||
| 66 | #include <openssl/pem.h> | ||
| 67 | #include <openssl/fips.h> | ||
| 68 | |||
| 69 | #ifndef OPENSSL_NO_RSA | ||
| 70 | static RSA *pkey_get_rsa(EVP_PKEY *key, RSA **rsa); | ||
| 71 | #endif | ||
| 72 | #ifndef OPENSSL_NO_DSA | ||
| 73 | static DSA *pkey_get_dsa(EVP_PKEY *key, DSA **dsa); | ||
| 74 | #endif | ||
| 75 | |||
| 76 | IMPLEMENT_PEM_rw(X509_REQ, X509_REQ, PEM_STRING_X509_REQ, X509_REQ) | ||
| 77 | |||
| 78 | IMPLEMENT_PEM_write(X509_REQ_NEW, X509_REQ, PEM_STRING_X509_REQ_OLD, X509_REQ) | ||
| 79 | |||
| 80 | IMPLEMENT_PEM_rw(X509_CRL, X509_CRL, PEM_STRING_X509_CRL, X509_CRL) | ||
| 81 | |||
| 82 | IMPLEMENT_PEM_rw(PKCS7, PKCS7, PEM_STRING_PKCS7, PKCS7) | ||
| 83 | |||
| 84 | IMPLEMENT_PEM_rw(NETSCAPE_CERT_SEQUENCE, NETSCAPE_CERT_SEQUENCE, | ||
| 85 | PEM_STRING_X509, NETSCAPE_CERT_SEQUENCE) | ||
| 86 | |||
| 87 | |||
| 88 | #ifndef OPENSSL_NO_RSA | ||
| 89 | |||
| 90 | /* We treat RSA or DSA private keys as a special case. | ||
| 91 | * | ||
| 92 | * For private keys we read in an EVP_PKEY structure with | ||
| 93 | * PEM_read_bio_PrivateKey() and extract the relevant private | ||
| 94 | * key: this means can handle "traditional" and PKCS#8 formats | ||
| 95 | * transparently. | ||
| 96 | */ | ||
| 97 | |||
| 98 | static RSA *pkey_get_rsa(EVP_PKEY *key, RSA **rsa) | ||
| 99 | { | ||
| 100 | RSA *rtmp; | ||
| 101 | if(!key) return NULL; | ||
| 102 | rtmp = EVP_PKEY_get1_RSA(key); | ||
| 103 | EVP_PKEY_free(key); | ||
| 104 | if(!rtmp) return NULL; | ||
| 105 | if(rsa) { | ||
| 106 | RSA_free(*rsa); | ||
| 107 | *rsa = rtmp; | ||
| 108 | } | ||
| 109 | return rtmp; | ||
| 110 | } | ||
| 111 | |||
| 112 | RSA *PEM_read_bio_RSAPrivateKey(BIO *bp, RSA **rsa, pem_password_cb *cb, | ||
| 113 | void *u) | ||
| 114 | { | ||
| 115 | EVP_PKEY *pktmp; | ||
| 116 | pktmp = PEM_read_bio_PrivateKey(bp, NULL, cb, u); | ||
| 117 | return pkey_get_rsa(pktmp, rsa); | ||
| 118 | } | ||
| 119 | |||
| 120 | #ifndef OPENSSL_NO_FP_API | ||
| 121 | |||
| 122 | RSA *PEM_read_RSAPrivateKey(FILE *fp, RSA **rsa, pem_password_cb *cb, | ||
| 123 | void *u) | ||
| 124 | { | ||
| 125 | EVP_PKEY *pktmp; | ||
| 126 | pktmp = PEM_read_PrivateKey(fp, NULL, cb, u); | ||
| 127 | return pkey_get_rsa(pktmp, rsa); | ||
| 128 | } | ||
| 129 | |||
| 130 | #endif | ||
| 131 | |||
| 132 | #ifdef OPENSSL_FIPS | ||
| 133 | |||
| 134 | int PEM_write_bio_RSAPrivateKey(BIO *bp, RSA *x, const EVP_CIPHER *enc, | ||
| 135 | unsigned char *kstr, int klen, | ||
| 136 | pem_password_cb *cb, void *u) | ||
| 137 | { | ||
| 138 | EVP_PKEY *k; | ||
| 139 | int ret; | ||
| 140 | k = EVP_PKEY_new(); | ||
| 141 | if (!k) | ||
| 142 | return 0; | ||
| 143 | EVP_PKEY_set1_RSA(k, x); | ||
| 144 | |||
| 145 | ret = PEM_write_bio_PrivateKey(bp, k, enc, kstr, klen, cb, u); | ||
| 146 | EVP_PKEY_free(k); | ||
| 147 | return ret; | ||
| 148 | } | ||
| 149 | |||
| 150 | #ifndef OPENSSL_NO_FP_API | ||
| 151 | int PEM_write_RSAPrivateKey(FILE *fp, RSA *x, const EVP_CIPHER *enc, | ||
| 152 | unsigned char *kstr, int klen, | ||
| 153 | pem_password_cb *cb, void *u) | ||
| 154 | { | ||
| 155 | EVP_PKEY *k; | ||
| 156 | int ret; | ||
| 157 | k = EVP_PKEY_new(); | ||
| 158 | if (!k) | ||
| 159 | return 0; | ||
| 160 | |||
| 161 | EVP_PKEY_set1_RSA(k, x); | ||
| 162 | |||
| 163 | ret = PEM_write_PrivateKey(fp, k, enc, kstr, klen, cb, u); | ||
| 164 | EVP_PKEY_free(k); | ||
| 165 | return ret; | ||
| 166 | } | ||
| 167 | #endif | ||
| 168 | |||
| 169 | #else | ||
| 170 | |||
| 171 | IMPLEMENT_PEM_write_cb(RSAPrivateKey, RSA, PEM_STRING_RSA, RSAPrivateKey) | ||
| 172 | |||
| 173 | #endif | ||
| 174 | |||
| 175 | IMPLEMENT_PEM_rw(RSAPublicKey, RSA, PEM_STRING_RSA_PUBLIC, RSAPublicKey) | ||
| 176 | IMPLEMENT_PEM_rw(RSA_PUBKEY, RSA, PEM_STRING_PUBLIC, RSA_PUBKEY) | ||
| 177 | |||
| 178 | #endif | ||
| 179 | |||
| 180 | #ifndef OPENSSL_NO_DSA | ||
| 181 | |||
| 182 | static DSA *pkey_get_dsa(EVP_PKEY *key, DSA **dsa) | ||
| 183 | { | ||
| 184 | DSA *dtmp; | ||
| 185 | if(!key) return NULL; | ||
| 186 | dtmp = EVP_PKEY_get1_DSA(key); | ||
| 187 | EVP_PKEY_free(key); | ||
| 188 | if(!dtmp) return NULL; | ||
| 189 | if(dsa) { | ||
| 190 | DSA_free(*dsa); | ||
| 191 | *dsa = dtmp; | ||
| 192 | } | ||
| 193 | return dtmp; | ||
| 194 | } | ||
| 195 | |||
| 196 | DSA *PEM_read_bio_DSAPrivateKey(BIO *bp, DSA **dsa, pem_password_cb *cb, | ||
| 197 | void *u) | ||
| 198 | { | ||
| 199 | EVP_PKEY *pktmp; | ||
| 200 | pktmp = PEM_read_bio_PrivateKey(bp, NULL, cb, u); | ||
| 201 | return pkey_get_dsa(pktmp, dsa); | ||
| 202 | } | ||
| 203 | |||
| 204 | |||
| 205 | #ifdef OPENSSL_FIPS | ||
| 206 | |||
| 207 | int PEM_write_bio_DSAPrivateKey(BIO *bp, DSA *x, const EVP_CIPHER *enc, | ||
| 208 | unsigned char *kstr, int klen, | ||
| 209 | pem_password_cb *cb, void *u) | ||
| 210 | { | ||
| 211 | EVP_PKEY *k; | ||
| 212 | int ret; | ||
| 213 | k = EVP_PKEY_new(); | ||
| 214 | if (!k) | ||
| 215 | return 0; | ||
| 216 | EVP_PKEY_set1_DSA(k, x); | ||
| 217 | |||
| 218 | ret = PEM_write_bio_PrivateKey(bp, k, enc, kstr, klen, cb, u); | ||
| 219 | EVP_PKEY_free(k); | ||
| 220 | return ret; | ||
| 221 | } | ||
| 222 | |||
| 223 | #ifndef OPENSSL_NO_FP_API | ||
| 224 | int PEM_write_DSAPrivateKey(FILE *fp, DSA *x, const EVP_CIPHER *enc, | ||
| 225 | unsigned char *kstr, int klen, | ||
| 226 | pem_password_cb *cb, void *u) | ||
| 227 | { | ||
| 228 | EVP_PKEY *k; | ||
| 229 | int ret; | ||
| 230 | k = EVP_PKEY_new(); | ||
| 231 | if (!k) | ||
| 232 | return 0; | ||
| 233 | EVP_PKEY_set1_DSA(k, x); | ||
| 234 | ret = PEM_write_PrivateKey(fp, k, enc, kstr, klen, cb, u); | ||
| 235 | EVP_PKEY_free(k); | ||
| 236 | return ret; | ||
| 237 | } | ||
| 238 | #endif | ||
| 239 | |||
| 240 | #else | ||
| 241 | |||
| 242 | IMPLEMENT_PEM_write_cb(DSAPrivateKey, DSA, PEM_STRING_DSA, DSAPrivateKey) | ||
| 243 | |||
| 244 | #endif | ||
| 245 | |||
| 246 | IMPLEMENT_PEM_rw(DSA_PUBKEY, DSA, PEM_STRING_PUBLIC, DSA_PUBKEY) | ||
| 247 | |||
| 248 | #ifndef OPENSSL_NO_FP_API | ||
| 249 | |||
| 250 | DSA *PEM_read_DSAPrivateKey(FILE *fp, DSA **dsa, pem_password_cb *cb, | ||
| 251 | void *u) | ||
| 252 | { | ||
| 253 | EVP_PKEY *pktmp; | ||
| 254 | pktmp = PEM_read_PrivateKey(fp, NULL, cb, u); | ||
| 255 | return pkey_get_dsa(pktmp, dsa); | ||
| 256 | } | ||
| 257 | |||
| 258 | #endif | ||
| 259 | |||
| 260 | IMPLEMENT_PEM_rw(DSAparams, DSA, PEM_STRING_DSAPARAMS, DSAparams) | ||
| 261 | |||
| 262 | #endif | ||
| 263 | |||
| 264 | #ifndef OPENSSL_NO_DH | ||
| 265 | |||
| 266 | IMPLEMENT_PEM_rw(DHparams, DH, PEM_STRING_DHPARAMS, DHparams) | ||
| 267 | |||
| 268 | #endif | ||
| 269 | |||
| 270 | |||
| 271 | /* The PrivateKey case is not that straightforward. | ||
| 272 | * IMPLEMENT_PEM_rw_cb(PrivateKey, EVP_PKEY, PEM_STRING_EVP_PKEY, PrivateKey) | ||
| 273 | * does not work, RSA and DSA keys have specific strings. | ||
| 274 | * (When reading, parameter PEM_STRING_EVP_PKEY is a wildcard for anything | ||
| 275 | * appropriate.) | ||
| 276 | */ | ||
| 277 | |||
| 278 | #ifdef OPENSSL_FIPS | ||
| 279 | |||
| 280 | int PEM_write_bio_PrivateKey(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc, | ||
| 281 | unsigned char *kstr, int klen, | ||
| 282 | pem_password_cb *cb, void *u) | ||
| 283 | { | ||
| 284 | if (FIPS_mode()) | ||
| 285 | return PEM_write_bio_PKCS8PrivateKey(bp, x, enc, | ||
| 286 | (char *)kstr, klen, cb, u); | ||
| 287 | else | ||
| 288 | return PEM_ASN1_write_bio((int (*)())i2d_PrivateKey, | ||
| 289 | (((x)->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA), | ||
| 290 | bp,(char *)x,enc,kstr,klen,cb,u); | ||
| 291 | } | ||
| 292 | |||
| 293 | #ifndef OPENSSL_NO_FP_API | ||
| 294 | int PEM_write_PrivateKey(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc, | ||
| 295 | unsigned char *kstr, int klen, | ||
| 296 | pem_password_cb *cb, void *u) | ||
| 297 | { | ||
| 298 | if (FIPS_mode()) | ||
| 299 | return PEM_write_PKCS8PrivateKey(fp, x, enc, | ||
| 300 | (char *)kstr, klen, cb, u); | ||
| 301 | else | ||
| 302 | return PEM_ASN1_write((int (*)())i2d_PrivateKey, | ||
| 303 | (((x)->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA), | ||
| 304 | fp,(char *)x,enc,kstr,klen,cb,u); | ||
| 305 | } | ||
| 306 | #endif | ||
| 307 | |||
| 308 | #else | ||
| 309 | |||
| 310 | IMPLEMENT_PEM_write_cb(PrivateKey, EVP_PKEY, ((x->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA), PrivateKey) | ||
| 311 | |||
| 312 | #endif | ||
| 313 | |||
| 314 | IMPLEMENT_PEM_rw(PUBKEY, EVP_PKEY, PEM_STRING_PUBLIC, PUBKEY) | ||
| 315 | |||
diff --git a/src/lib/libcrypto/pem/pem_err.c b/src/lib/libcrypto/pem/pem_err.c new file mode 100644 index 0000000000..8527028ebc --- /dev/null +++ b/src/lib/libcrypto/pem/pem_err.c | |||
| @@ -0,0 +1,135 @@ | |||
| 1 | /* crypto/pem/pem_err.c */ | ||
| 2 | /* ==================================================================== | ||
| 3 | * Copyright (c) 1999-2005 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/pem.h> | ||
| 64 | |||
| 65 | /* BEGIN ERROR CODES */ | ||
| 66 | #ifndef OPENSSL_NO_ERR | ||
| 67 | |||
| 68 | #define ERR_FUNC(func) ERR_PACK(ERR_LIB_PEM,func,0) | ||
| 69 | #define ERR_REASON(reason) ERR_PACK(ERR_LIB_PEM,0,reason) | ||
| 70 | |||
| 71 | static ERR_STRING_DATA PEM_str_functs[]= | ||
| 72 | { | ||
| 73 | {ERR_FUNC(PEM_F_D2I_PKCS8PRIVATEKEY_BIO), "d2i_PKCS8PrivateKey_bio"}, | ||
| 74 | {ERR_FUNC(PEM_F_D2I_PKCS8PRIVATEKEY_FP), "d2i_PKCS8PrivateKey_fp"}, | ||
| 75 | {ERR_FUNC(PEM_F_DEF_CALLBACK), "DEF_CALLBACK"}, | ||
| 76 | {ERR_FUNC(PEM_F_LOAD_IV), "LOAD_IV"}, | ||
| 77 | {ERR_FUNC(PEM_F_PEM_ASN1_READ), "PEM_ASN1_read"}, | ||
| 78 | {ERR_FUNC(PEM_F_PEM_ASN1_READ_BIO), "PEM_ASN1_read_bio"}, | ||
| 79 | {ERR_FUNC(PEM_F_PEM_ASN1_WRITE), "PEM_ASN1_write"}, | ||
| 80 | {ERR_FUNC(PEM_F_PEM_ASN1_WRITE_BIO), "PEM_ASN1_write_bio"}, | ||
| 81 | {ERR_FUNC(PEM_F_PEM_DO_HEADER), "PEM_do_header"}, | ||
| 82 | {ERR_FUNC(PEM_F_PEM_F_DO_PK8KEY_FP), "PEM_F_DO_PK8KEY_FP"}, | ||
| 83 | {ERR_FUNC(PEM_F_PEM_F_PEM_WRITE_PKCS8PRIVATEKEY), "PEM_F_PEM_WRITE_PKCS8PRIVATEKEY"}, | ||
| 84 | {ERR_FUNC(PEM_F_PEM_GET_EVP_CIPHER_INFO), "PEM_get_EVP_CIPHER_INFO"}, | ||
| 85 | {ERR_FUNC(PEM_F_PEM_READ), "PEM_read"}, | ||
| 86 | {ERR_FUNC(PEM_F_PEM_READ_BIO), "PEM_read_bio"}, | ||
| 87 | {ERR_FUNC(PEM_F_PEM_SEALFINAL), "PEM_SealFinal"}, | ||
| 88 | {ERR_FUNC(PEM_F_PEM_SEALINIT), "PEM_SealInit"}, | ||
| 89 | {ERR_FUNC(PEM_F_PEM_SIGNFINAL), "PEM_SignFinal"}, | ||
| 90 | {ERR_FUNC(PEM_F_PEM_WRITE), "PEM_write"}, | ||
| 91 | {ERR_FUNC(PEM_F_PEM_WRITE_BIO), "PEM_write_bio"}, | ||
| 92 | {ERR_FUNC(PEM_F_PEM_WRITE_BIO_PKCS8PRIVATEKEY), "PEM_write_bio_PKCS8PrivateKey"}, | ||
| 93 | {ERR_FUNC(PEM_F_PEM_X509_INFO_READ), "PEM_X509_INFO_read"}, | ||
| 94 | {ERR_FUNC(PEM_F_PEM_X509_INFO_READ_BIO), "PEM_X509_INFO_read_bio"}, | ||
| 95 | {ERR_FUNC(PEM_F_PEM_X509_INFO_WRITE_BIO), "PEM_X509_INFO_write_bio"}, | ||
| 96 | {0,NULL} | ||
| 97 | }; | ||
| 98 | |||
| 99 | static ERR_STRING_DATA PEM_str_reasons[]= | ||
| 100 | { | ||
| 101 | {ERR_REASON(PEM_R_BAD_BASE64_DECODE) ,"bad base64 decode"}, | ||
| 102 | {ERR_REASON(PEM_R_BAD_DECRYPT) ,"bad decrypt"}, | ||
| 103 | {ERR_REASON(PEM_R_BAD_END_LINE) ,"bad end line"}, | ||
| 104 | {ERR_REASON(PEM_R_BAD_IV_CHARS) ,"bad iv chars"}, | ||
| 105 | {ERR_REASON(PEM_R_BAD_PASSWORD_READ) ,"bad password read"}, | ||
| 106 | {ERR_REASON(PEM_R_ERROR_CONVERTING_PRIVATE_KEY),"error converting private key"}, | ||
| 107 | {ERR_REASON(PEM_R_NOT_DEK_INFO) ,"not dek info"}, | ||
| 108 | {ERR_REASON(PEM_R_NOT_ENCRYPTED) ,"not encrypted"}, | ||
| 109 | {ERR_REASON(PEM_R_NOT_PROC_TYPE) ,"not proc type"}, | ||
| 110 | {ERR_REASON(PEM_R_NO_START_LINE) ,"no start line"}, | ||
| 111 | {ERR_REASON(PEM_R_PROBLEMS_GETTING_PASSWORD),"problems getting password"}, | ||
| 112 | {ERR_REASON(PEM_R_PUBLIC_KEY_NO_RSA) ,"public key no rsa"}, | ||
| 113 | {ERR_REASON(PEM_R_READ_KEY) ,"read key"}, | ||
| 114 | {ERR_REASON(PEM_R_SHORT_HEADER) ,"short header"}, | ||
| 115 | {ERR_REASON(PEM_R_UNSUPPORTED_CIPHER) ,"unsupported cipher"}, | ||
| 116 | {ERR_REASON(PEM_R_UNSUPPORTED_ENCRYPTION),"unsupported encryption"}, | ||
| 117 | {0,NULL} | ||
| 118 | }; | ||
| 119 | |||
| 120 | #endif | ||
| 121 | |||
| 122 | void ERR_load_PEM_strings(void) | ||
| 123 | { | ||
| 124 | static int init=1; | ||
| 125 | |||
| 126 | if (init) | ||
| 127 | { | ||
| 128 | init=0; | ||
| 129 | #ifndef OPENSSL_NO_ERR | ||
| 130 | ERR_load_strings(0,PEM_str_functs); | ||
| 131 | ERR_load_strings(0,PEM_str_reasons); | ||
| 132 | #endif | ||
| 133 | |||
| 134 | } | ||
| 135 | } | ||
diff --git a/src/lib/libcrypto/pem/pem_info.c b/src/lib/libcrypto/pem/pem_info.c new file mode 100644 index 0000000000..9e4af29c95 --- /dev/null +++ b/src/lib/libcrypto/pem/pem_info.c | |||
| @@ -0,0 +1,365 @@ | |||
| 1 | /* crypto/pem/pem_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/buffer.h> | ||
| 62 | #include <openssl/objects.h> | ||
| 63 | #include <openssl/evp.h> | ||
| 64 | #include <openssl/x509.h> | ||
| 65 | #include <openssl/pem.h> | ||
| 66 | |||
| 67 | #ifndef OPENSSL_NO_FP_API | ||
| 68 | STACK_OF(X509_INFO) *PEM_X509_INFO_read(FILE *fp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u) | ||
| 69 | { | ||
| 70 | BIO *b; | ||
| 71 | STACK_OF(X509_INFO) *ret; | ||
| 72 | |||
| 73 | if ((b=BIO_new(BIO_s_file())) == NULL) | ||
| 74 | { | ||
| 75 | PEMerr(PEM_F_PEM_X509_INFO_READ,ERR_R_BUF_LIB); | ||
| 76 | return(0); | ||
| 77 | } | ||
| 78 | BIO_set_fp(b,fp,BIO_NOCLOSE); | ||
| 79 | ret=PEM_X509_INFO_read_bio(b,sk,cb,u); | ||
| 80 | BIO_free(b); | ||
| 81 | return(ret); | ||
| 82 | } | ||
| 83 | #endif | ||
| 84 | |||
| 85 | STACK_OF(X509_INFO) *PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u) | ||
| 86 | { | ||
| 87 | X509_INFO *xi=NULL; | ||
| 88 | char *name=NULL,*header=NULL,**pp; | ||
| 89 | unsigned char *data=NULL,*p; | ||
| 90 | long len,error=0; | ||
| 91 | int ok=0; | ||
| 92 | STACK_OF(X509_INFO) *ret=NULL; | ||
| 93 | unsigned int i,raw; | ||
| 94 | char *(*d2i)(); | ||
| 95 | |||
| 96 | if (sk == NULL) | ||
| 97 | { | ||
| 98 | if ((ret=sk_X509_INFO_new_null()) == NULL) | ||
| 99 | { | ||
| 100 | PEMerr(PEM_F_PEM_X509_INFO_READ_BIO,ERR_R_MALLOC_FAILURE); | ||
| 101 | goto err; | ||
| 102 | } | ||
| 103 | } | ||
| 104 | else | ||
| 105 | ret=sk; | ||
| 106 | |||
| 107 | if ((xi=X509_INFO_new()) == NULL) goto err; | ||
| 108 | for (;;) | ||
| 109 | { | ||
| 110 | raw=0; | ||
| 111 | i=PEM_read_bio(bp,&name,&header,&data,&len); | ||
| 112 | if (i == 0) | ||
| 113 | { | ||
| 114 | error=ERR_GET_REASON(ERR_peek_last_error()); | ||
| 115 | if (error == PEM_R_NO_START_LINE) | ||
| 116 | { | ||
| 117 | ERR_clear_error(); | ||
| 118 | break; | ||
| 119 | } | ||
| 120 | goto err; | ||
| 121 | } | ||
| 122 | start: | ||
| 123 | if ( (strcmp(name,PEM_STRING_X509) == 0) || | ||
| 124 | (strcmp(name,PEM_STRING_X509_OLD) == 0)) | ||
| 125 | { | ||
| 126 | d2i=(char *(*)())d2i_X509; | ||
| 127 | if (xi->x509 != NULL) | ||
| 128 | { | ||
| 129 | if (!sk_X509_INFO_push(ret,xi)) goto err; | ||
| 130 | if ((xi=X509_INFO_new()) == NULL) goto err; | ||
| 131 | goto start; | ||
| 132 | } | ||
| 133 | pp=(char **)&(xi->x509); | ||
| 134 | } | ||
| 135 | else if ((strcmp(name,PEM_STRING_X509_TRUSTED) == 0)) | ||
| 136 | { | ||
| 137 | d2i=(char *(*)())d2i_X509_AUX; | ||
| 138 | if (xi->x509 != NULL) | ||
| 139 | { | ||
| 140 | if (!sk_X509_INFO_push(ret,xi)) goto err; | ||
| 141 | if ((xi=X509_INFO_new()) == NULL) goto err; | ||
| 142 | goto start; | ||
| 143 | } | ||
| 144 | pp=(char **)&(xi->x509); | ||
| 145 | } | ||
| 146 | else if (strcmp(name,PEM_STRING_X509_CRL) == 0) | ||
| 147 | { | ||
| 148 | d2i=(char *(*)())d2i_X509_CRL; | ||
| 149 | if (xi->crl != NULL) | ||
| 150 | { | ||
| 151 | if (!sk_X509_INFO_push(ret,xi)) goto err; | ||
| 152 | if ((xi=X509_INFO_new()) == NULL) goto err; | ||
| 153 | goto start; | ||
| 154 | } | ||
| 155 | pp=(char **)&(xi->crl); | ||
| 156 | } | ||
| 157 | else | ||
| 158 | #ifndef OPENSSL_NO_RSA | ||
| 159 | if (strcmp(name,PEM_STRING_RSA) == 0) | ||
| 160 | { | ||
| 161 | d2i=(char *(*)())d2i_RSAPrivateKey; | ||
| 162 | if (xi->x_pkey != NULL) | ||
| 163 | { | ||
| 164 | if (!sk_X509_INFO_push(ret,xi)) goto err; | ||
| 165 | if ((xi=X509_INFO_new()) == NULL) goto err; | ||
| 166 | goto start; | ||
| 167 | } | ||
| 168 | |||
| 169 | xi->enc_data=NULL; | ||
| 170 | xi->enc_len=0; | ||
| 171 | |||
| 172 | xi->x_pkey=X509_PKEY_new(); | ||
| 173 | if ((xi->x_pkey->dec_pkey=EVP_PKEY_new()) == NULL) | ||
| 174 | goto err; | ||
| 175 | xi->x_pkey->dec_pkey->type=EVP_PKEY_RSA; | ||
| 176 | pp=(char **)&(xi->x_pkey->dec_pkey->pkey.rsa); | ||
| 177 | if ((int)strlen(header) > 10) /* assume encrypted */ | ||
| 178 | raw=1; | ||
| 179 | } | ||
| 180 | else | ||
| 181 | #endif | ||
| 182 | #ifndef OPENSSL_NO_DSA | ||
| 183 | if (strcmp(name,PEM_STRING_DSA) == 0) | ||
| 184 | { | ||
| 185 | d2i=(char *(*)())d2i_DSAPrivateKey; | ||
| 186 | if (xi->x_pkey != NULL) | ||
| 187 | { | ||
| 188 | if (!sk_X509_INFO_push(ret,xi)) goto err; | ||
| 189 | if ((xi=X509_INFO_new()) == NULL) goto err; | ||
| 190 | goto start; | ||
| 191 | } | ||
| 192 | |||
| 193 | xi->enc_data=NULL; | ||
| 194 | xi->enc_len=0; | ||
| 195 | |||
| 196 | xi->x_pkey=X509_PKEY_new(); | ||
| 197 | if ((xi->x_pkey->dec_pkey=EVP_PKEY_new()) == NULL) | ||
| 198 | goto err; | ||
| 199 | xi->x_pkey->dec_pkey->type=EVP_PKEY_DSA; | ||
| 200 | pp=(char **)&(xi->x_pkey->dec_pkey->pkey.dsa); | ||
| 201 | if ((int)strlen(header) > 10) /* assume encrypted */ | ||
| 202 | raw=1; | ||
| 203 | } | ||
| 204 | else | ||
| 205 | #endif | ||
| 206 | { | ||
| 207 | d2i=NULL; | ||
| 208 | pp=NULL; | ||
| 209 | } | ||
| 210 | |||
| 211 | if (d2i != NULL) | ||
| 212 | { | ||
| 213 | if (!raw) | ||
| 214 | { | ||
| 215 | EVP_CIPHER_INFO cipher; | ||
| 216 | |||
| 217 | if (!PEM_get_EVP_CIPHER_INFO(header,&cipher)) | ||
| 218 | goto err; | ||
| 219 | if (!PEM_do_header(&cipher,data,&len,cb,u)) | ||
| 220 | goto err; | ||
| 221 | p=data; | ||
| 222 | if (d2i(pp,&p,len) == NULL) | ||
| 223 | { | ||
| 224 | PEMerr(PEM_F_PEM_X509_INFO_READ_BIO,ERR_R_ASN1_LIB); | ||
| 225 | goto err; | ||
| 226 | } | ||
| 227 | } | ||
| 228 | else | ||
| 229 | { /* encrypted RSA data */ | ||
| 230 | if (!PEM_get_EVP_CIPHER_INFO(header, | ||
| 231 | &xi->enc_cipher)) goto err; | ||
| 232 | xi->enc_data=(char *)data; | ||
| 233 | xi->enc_len=(int)len; | ||
| 234 | data=NULL; | ||
| 235 | } | ||
| 236 | } | ||
| 237 | else { | ||
| 238 | /* unknown */ | ||
| 239 | } | ||
| 240 | if (name != NULL) OPENSSL_free(name); | ||
| 241 | if (header != NULL) OPENSSL_free(header); | ||
| 242 | if (data != NULL) OPENSSL_free(data); | ||
| 243 | name=NULL; | ||
| 244 | header=NULL; | ||
| 245 | data=NULL; | ||
| 246 | } | ||
| 247 | |||
| 248 | /* if the last one hasn't been pushed yet and there is anything | ||
| 249 | * in it then add it to the stack ... | ||
| 250 | */ | ||
| 251 | if ((xi->x509 != NULL) || (xi->crl != NULL) || | ||
| 252 | (xi->x_pkey != NULL) || (xi->enc_data != NULL)) | ||
| 253 | { | ||
| 254 | if (!sk_X509_INFO_push(ret,xi)) goto err; | ||
| 255 | xi=NULL; | ||
| 256 | } | ||
| 257 | ok=1; | ||
| 258 | err: | ||
| 259 | if (xi != NULL) X509_INFO_free(xi); | ||
| 260 | if (!ok) | ||
| 261 | { | ||
| 262 | for (i=0; ((int)i)<sk_X509_INFO_num(ret); i++) | ||
| 263 | { | ||
| 264 | xi=sk_X509_INFO_value(ret,i); | ||
| 265 | X509_INFO_free(xi); | ||
| 266 | } | ||
| 267 | if (ret != sk) sk_X509_INFO_free(ret); | ||
| 268 | ret=NULL; | ||
| 269 | } | ||
| 270 | |||
| 271 | if (name != NULL) OPENSSL_free(name); | ||
| 272 | if (header != NULL) OPENSSL_free(header); | ||
| 273 | if (data != NULL) OPENSSL_free(data); | ||
| 274 | return(ret); | ||
| 275 | } | ||
| 276 | |||
| 277 | |||
| 278 | /* A TJH addition */ | ||
| 279 | int PEM_X509_INFO_write_bio(BIO *bp, X509_INFO *xi, EVP_CIPHER *enc, | ||
| 280 | unsigned char *kstr, int klen, pem_password_cb *cb, void *u) | ||
| 281 | { | ||
| 282 | EVP_CIPHER_CTX ctx; | ||
| 283 | int i,ret=0; | ||
| 284 | unsigned char *data=NULL; | ||
| 285 | const char *objstr=NULL; | ||
| 286 | char buf[PEM_BUFSIZE]; | ||
| 287 | unsigned char *iv=NULL; | ||
| 288 | |||
| 289 | if (enc != NULL) | ||
| 290 | { | ||
| 291 | objstr=OBJ_nid2sn(EVP_CIPHER_nid(enc)); | ||
| 292 | if (objstr == NULL) | ||
| 293 | { | ||
| 294 | PEMerr(PEM_F_PEM_X509_INFO_WRITE_BIO,PEM_R_UNSUPPORTED_CIPHER); | ||
| 295 | goto err; | ||
| 296 | } | ||
| 297 | } | ||
| 298 | |||
| 299 | /* now for the fun part ... if we have a private key then | ||
| 300 | * we have to be able to handle a not-yet-decrypted key | ||
| 301 | * being written out correctly ... if it is decrypted or | ||
| 302 | * it is non-encrypted then we use the base code | ||
| 303 | */ | ||
| 304 | if (xi->x_pkey!=NULL) | ||
| 305 | { | ||
| 306 | if ( (xi->enc_data!=NULL) && (xi->enc_len>0) ) | ||
| 307 | { | ||
| 308 | /* copy from weirdo names into more normal things */ | ||
| 309 | iv=xi->enc_cipher.iv; | ||
| 310 | data=(unsigned char *)xi->enc_data; | ||
| 311 | i=xi->enc_len; | ||
| 312 | |||
| 313 | /* we take the encryption data from the | ||
| 314 | * internal stuff rather than what the | ||
| 315 | * user has passed us ... as we have to | ||
| 316 | * match exactly for some strange reason | ||
| 317 | */ | ||
| 318 | objstr=OBJ_nid2sn( | ||
| 319 | EVP_CIPHER_nid(xi->enc_cipher.cipher)); | ||
| 320 | if (objstr == NULL) | ||
| 321 | { | ||
| 322 | PEMerr(PEM_F_PEM_X509_INFO_WRITE_BIO,PEM_R_UNSUPPORTED_CIPHER); | ||
| 323 | goto err; | ||
| 324 | } | ||
| 325 | |||
| 326 | /* create the right magic header stuff */ | ||
| 327 | OPENSSL_assert(strlen(objstr)+23+2*enc->iv_len+13 <= sizeof buf); | ||
| 328 | buf[0]='\0'; | ||
| 329 | PEM_proc_type(buf,PEM_TYPE_ENCRYPTED); | ||
| 330 | PEM_dek_info(buf,objstr,enc->iv_len,(char *)iv); | ||
| 331 | |||
| 332 | /* use the normal code to write things out */ | ||
| 333 | i=PEM_write_bio(bp,PEM_STRING_RSA,buf,data,i); | ||
| 334 | if (i <= 0) goto err; | ||
| 335 | } | ||
| 336 | else | ||
| 337 | { | ||
| 338 | /* Add DSA/DH */ | ||
| 339 | #ifndef OPENSSL_NO_RSA | ||
| 340 | /* normal optionally encrypted stuff */ | ||
| 341 | if (PEM_write_bio_RSAPrivateKey(bp, | ||
| 342 | xi->x_pkey->dec_pkey->pkey.rsa, | ||
| 343 | enc,kstr,klen,cb,u)<=0) | ||
| 344 | goto err; | ||
| 345 | #endif | ||
| 346 | } | ||
| 347 | } | ||
| 348 | |||
| 349 | /* if we have a certificate then write it out now */ | ||
| 350 | if ((xi->x509 != NULL) && (PEM_write_bio_X509(bp,xi->x509) <= 0)) | ||
| 351 | goto err; | ||
| 352 | |||
| 353 | /* we are ignoring anything else that is loaded into the X509_INFO | ||
| 354 | * structure for the moment ... as I don't need it so I'm not | ||
| 355 | * coding it here and Eric can do it when this makes it into the | ||
| 356 | * base library --tjh | ||
| 357 | */ | ||
| 358 | |||
| 359 | ret=1; | ||
| 360 | |||
| 361 | err: | ||
| 362 | OPENSSL_cleanse((char *)&ctx,sizeof(ctx)); | ||
| 363 | OPENSSL_cleanse(buf,PEM_BUFSIZE); | ||
| 364 | return(ret); | ||
| 365 | } | ||
diff --git a/src/lib/libcrypto/pem/pem_lib.c b/src/lib/libcrypto/pem/pem_lib.c new file mode 100644 index 0000000000..82815067b3 --- /dev/null +++ b/src/lib/libcrypto/pem/pem_lib.c | |||
| @@ -0,0 +1,776 @@ | |||
| 1 | /* crypto/pem/pem_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 "cryptlib.h" | ||
| 61 | #include <openssl/buffer.h> | ||
| 62 | #include <openssl/objects.h> | ||
| 63 | #include <openssl/evp.h> | ||
| 64 | #include <openssl/rand.h> | ||
| 65 | #include <openssl/x509.h> | ||
| 66 | #include <openssl/pem.h> | ||
| 67 | #include <openssl/pkcs12.h> | ||
| 68 | #ifndef OPENSSL_NO_DES | ||
| 69 | #include <openssl/des.h> | ||
| 70 | #endif | ||
| 71 | |||
| 72 | const char *PEM_version="PEM" OPENSSL_VERSION_PTEXT; | ||
| 73 | |||
| 74 | #define MIN_LENGTH 4 | ||
| 75 | |||
| 76 | static int load_iv(char **fromp,unsigned char *to, int num); | ||
| 77 | static int check_pem(const char *nm, const char *name); | ||
| 78 | |||
| 79 | int PEM_def_callback(char *buf, int num, int w, void *key) | ||
| 80 | { | ||
| 81 | #ifdef OPENSSL_NO_FP_API | ||
| 82 | /* We should not ever call the default callback routine from | ||
| 83 | * windows. */ | ||
| 84 | PEMerr(PEM_F_DEF_CALLBACK,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | ||
| 85 | return(-1); | ||
| 86 | #else | ||
| 87 | int i,j; | ||
| 88 | const char *prompt; | ||
| 89 | if(key) { | ||
| 90 | i=strlen(key); | ||
| 91 | i=(i > num)?num:i; | ||
| 92 | memcpy(buf,key,i); | ||
| 93 | return(i); | ||
| 94 | } | ||
| 95 | |||
| 96 | prompt=EVP_get_pw_prompt(); | ||
| 97 | if (prompt == NULL) | ||
| 98 | prompt="Enter PEM pass phrase:"; | ||
| 99 | |||
| 100 | for (;;) | ||
| 101 | { | ||
| 102 | i=EVP_read_pw_string(buf,num,prompt,w); | ||
| 103 | if (i != 0) | ||
| 104 | { | ||
| 105 | PEMerr(PEM_F_DEF_CALLBACK,PEM_R_PROBLEMS_GETTING_PASSWORD); | ||
| 106 | memset(buf,0,(unsigned int)num); | ||
| 107 | return(-1); | ||
| 108 | } | ||
| 109 | j=strlen(buf); | ||
| 110 | if (j < MIN_LENGTH) | ||
| 111 | { | ||
| 112 | fprintf(stderr,"phrase is too short, needs to be at least %d chars\n",MIN_LENGTH); | ||
| 113 | } | ||
| 114 | else | ||
| 115 | break; | ||
| 116 | } | ||
| 117 | return(j); | ||
| 118 | #endif | ||
| 119 | } | ||
| 120 | |||
| 121 | void PEM_proc_type(char *buf, int type) | ||
| 122 | { | ||
| 123 | const char *str; | ||
| 124 | |||
| 125 | if (type == PEM_TYPE_ENCRYPTED) | ||
| 126 | str="ENCRYPTED"; | ||
| 127 | else if (type == PEM_TYPE_MIC_CLEAR) | ||
| 128 | str="MIC-CLEAR"; | ||
| 129 | else if (type == PEM_TYPE_MIC_ONLY) | ||
| 130 | str="MIC-ONLY"; | ||
| 131 | else | ||
| 132 | str="BAD-TYPE"; | ||
| 133 | |||
| 134 | BUF_strlcat(buf,"Proc-Type: 4,",PEM_BUFSIZE); | ||
| 135 | BUF_strlcat(buf,str,PEM_BUFSIZE); | ||
| 136 | BUF_strlcat(buf,"\n",PEM_BUFSIZE); | ||
| 137 | } | ||
| 138 | |||
| 139 | void PEM_dek_info(char *buf, const char *type, int len, char *str) | ||
| 140 | { | ||
| 141 | static const unsigned char map[17]="0123456789ABCDEF"; | ||
| 142 | long i; | ||
| 143 | int j; | ||
| 144 | |||
| 145 | BUF_strlcat(buf,"DEK-Info: ",PEM_BUFSIZE); | ||
| 146 | BUF_strlcat(buf,type,PEM_BUFSIZE); | ||
| 147 | BUF_strlcat(buf,",",PEM_BUFSIZE); | ||
| 148 | j=strlen(buf); | ||
| 149 | if (j + (len * 2) + 1 > PEM_BUFSIZE) | ||
| 150 | return; | ||
| 151 | for (i=0; i<len; i++) | ||
| 152 | { | ||
| 153 | buf[j+i*2] =map[(str[i]>>4)&0x0f]; | ||
| 154 | buf[j+i*2+1]=map[(str[i] )&0x0f]; | ||
| 155 | } | ||
| 156 | buf[j+i*2]='\n'; | ||
| 157 | buf[j+i*2+1]='\0'; | ||
| 158 | } | ||
| 159 | |||
| 160 | #ifndef OPENSSL_NO_FP_API | ||
| 161 | char *PEM_ASN1_read(char *(*d2i)(), const char *name, FILE *fp, char **x, | ||
| 162 | pem_password_cb *cb, void *u) | ||
| 163 | { | ||
| 164 | BIO *b; | ||
| 165 | char *ret; | ||
| 166 | |||
| 167 | if ((b=BIO_new(BIO_s_file())) == NULL) | ||
| 168 | { | ||
| 169 | PEMerr(PEM_F_PEM_ASN1_READ,ERR_R_BUF_LIB); | ||
| 170 | return(0); | ||
| 171 | } | ||
| 172 | BIO_set_fp(b,fp,BIO_NOCLOSE); | ||
| 173 | ret=PEM_ASN1_read_bio(d2i,name,b,x,cb,u); | ||
| 174 | BIO_free(b); | ||
| 175 | return(ret); | ||
| 176 | } | ||
| 177 | #endif | ||
| 178 | |||
| 179 | static int check_pem(const char *nm, const char *name) | ||
| 180 | { | ||
| 181 | /* Normal matching nm and name */ | ||
| 182 | if (!strcmp(nm,name)) return 1; | ||
| 183 | |||
| 184 | /* Make PEM_STRING_EVP_PKEY match any private key */ | ||
| 185 | |||
| 186 | if(!strcmp(nm,PEM_STRING_PKCS8) && | ||
| 187 | !strcmp(name,PEM_STRING_EVP_PKEY)) return 1; | ||
| 188 | |||
| 189 | if(!strcmp(nm,PEM_STRING_PKCS8INF) && | ||
| 190 | !strcmp(name,PEM_STRING_EVP_PKEY)) return 1; | ||
| 191 | |||
| 192 | if(!strcmp(nm,PEM_STRING_RSA) && | ||
| 193 | !strcmp(name,PEM_STRING_EVP_PKEY)) return 1; | ||
| 194 | |||
| 195 | if(!strcmp(nm,PEM_STRING_DSA) && | ||
| 196 | !strcmp(name,PEM_STRING_EVP_PKEY)) return 1; | ||
| 197 | |||
| 198 | /* Permit older strings */ | ||
| 199 | |||
| 200 | if(!strcmp(nm,PEM_STRING_X509_OLD) && | ||
| 201 | !strcmp(name,PEM_STRING_X509)) return 1; | ||
| 202 | |||
| 203 | if(!strcmp(nm,PEM_STRING_X509_REQ_OLD) && | ||
| 204 | !strcmp(name,PEM_STRING_X509_REQ)) return 1; | ||
| 205 | |||
| 206 | /* Allow normal certs to be read as trusted certs */ | ||
| 207 | if(!strcmp(nm,PEM_STRING_X509) && | ||
| 208 | !strcmp(name,PEM_STRING_X509_TRUSTED)) return 1; | ||
| 209 | |||
| 210 | if(!strcmp(nm,PEM_STRING_X509_OLD) && | ||
| 211 | !strcmp(name,PEM_STRING_X509_TRUSTED)) return 1; | ||
| 212 | |||
| 213 | /* Some CAs use PKCS#7 with CERTIFICATE headers */ | ||
| 214 | if(!strcmp(nm, PEM_STRING_X509) && | ||
| 215 | !strcmp(name, PEM_STRING_PKCS7)) return 1; | ||
| 216 | |||
| 217 | return 0; | ||
| 218 | } | ||
| 219 | |||
| 220 | int PEM_bytes_read_bio(unsigned char **pdata, long *plen, char **pnm, const char *name, BIO *bp, | ||
| 221 | pem_password_cb *cb, void *u) | ||
| 222 | { | ||
| 223 | EVP_CIPHER_INFO cipher; | ||
| 224 | char *nm=NULL,*header=NULL; | ||
| 225 | unsigned char *data=NULL; | ||
| 226 | long len; | ||
| 227 | int ret = 0; | ||
| 228 | |||
| 229 | for (;;) | ||
| 230 | { | ||
| 231 | if (!PEM_read_bio(bp,&nm,&header,&data,&len)) { | ||
| 232 | if(ERR_GET_REASON(ERR_peek_error()) == | ||
| 233 | PEM_R_NO_START_LINE) | ||
| 234 | ERR_add_error_data(2, "Expecting: ", name); | ||
| 235 | return 0; | ||
| 236 | } | ||
| 237 | if(check_pem(nm, name)) break; | ||
| 238 | OPENSSL_free(nm); | ||
| 239 | OPENSSL_free(header); | ||
| 240 | OPENSSL_free(data); | ||
| 241 | } | ||
| 242 | if (!PEM_get_EVP_CIPHER_INFO(header,&cipher)) goto err; | ||
| 243 | if (!PEM_do_header(&cipher,data,&len,cb,u)) goto err; | ||
| 244 | |||
| 245 | *pdata = data; | ||
| 246 | *plen = len; | ||
| 247 | |||
| 248 | if (pnm) | ||
| 249 | *pnm = nm; | ||
| 250 | |||
| 251 | ret = 1; | ||
| 252 | |||
| 253 | err: | ||
| 254 | if (!ret || !pnm) OPENSSL_free(nm); | ||
| 255 | OPENSSL_free(header); | ||
| 256 | if (!ret) OPENSSL_free(data); | ||
| 257 | return ret; | ||
| 258 | } | ||
| 259 | |||
| 260 | #ifndef OPENSSL_NO_FP_API | ||
| 261 | int PEM_ASN1_write(int (*i2d)(), const char *name, FILE *fp, char *x, | ||
| 262 | const EVP_CIPHER *enc, unsigned char *kstr, int klen, | ||
| 263 | pem_password_cb *callback, void *u) | ||
| 264 | { | ||
| 265 | BIO *b; | ||
| 266 | int ret; | ||
| 267 | |||
| 268 | if ((b=BIO_new(BIO_s_file())) == NULL) | ||
| 269 | { | ||
| 270 | PEMerr(PEM_F_PEM_ASN1_WRITE,ERR_R_BUF_LIB); | ||
| 271 | return(0); | ||
| 272 | } | ||
| 273 | BIO_set_fp(b,fp,BIO_NOCLOSE); | ||
| 274 | ret=PEM_ASN1_write_bio(i2d,name,b,x,enc,kstr,klen,callback,u); | ||
| 275 | BIO_free(b); | ||
| 276 | return(ret); | ||
| 277 | } | ||
| 278 | #endif | ||
| 279 | |||
| 280 | int PEM_ASN1_write_bio(int (*i2d)(), const char *name, BIO *bp, char *x, | ||
| 281 | const EVP_CIPHER *enc, unsigned char *kstr, int klen, | ||
| 282 | pem_password_cb *callback, void *u) | ||
| 283 | { | ||
| 284 | EVP_CIPHER_CTX ctx; | ||
| 285 | int dsize=0,i,j,ret=0; | ||
| 286 | unsigned char *p,*data=NULL; | ||
| 287 | const char *objstr=NULL; | ||
| 288 | char buf[PEM_BUFSIZE]; | ||
| 289 | unsigned char key[EVP_MAX_KEY_LENGTH]; | ||
| 290 | unsigned char iv[EVP_MAX_IV_LENGTH]; | ||
| 291 | |||
| 292 | if (enc != NULL) | ||
| 293 | { | ||
| 294 | objstr=OBJ_nid2sn(EVP_CIPHER_nid(enc)); | ||
| 295 | if (objstr == NULL) | ||
| 296 | { | ||
| 297 | PEMerr(PEM_F_PEM_ASN1_WRITE_BIO,PEM_R_UNSUPPORTED_CIPHER); | ||
| 298 | goto err; | ||
| 299 | } | ||
| 300 | } | ||
| 301 | |||
| 302 | if ((dsize=i2d(x,NULL)) < 0) | ||
| 303 | { | ||
| 304 | PEMerr(PEM_F_PEM_ASN1_WRITE_BIO,ERR_R_ASN1_LIB); | ||
| 305 | dsize=0; | ||
| 306 | goto err; | ||
| 307 | } | ||
| 308 | /* dzise + 8 bytes are needed */ | ||
| 309 | /* actually it needs the cipher block size extra... */ | ||
| 310 | data=(unsigned char *)OPENSSL_malloc((unsigned int)dsize+20); | ||
| 311 | if (data == NULL) | ||
| 312 | { | ||
| 313 | PEMerr(PEM_F_PEM_ASN1_WRITE_BIO,ERR_R_MALLOC_FAILURE); | ||
| 314 | goto err; | ||
| 315 | } | ||
| 316 | p=data; | ||
| 317 | i=i2d(x,&p); | ||
| 318 | |||
| 319 | if (enc != NULL) | ||
| 320 | { | ||
| 321 | if (kstr == NULL) | ||
| 322 | { | ||
| 323 | if (callback == NULL) | ||
| 324 | klen=PEM_def_callback(buf,PEM_BUFSIZE,1,u); | ||
| 325 | else | ||
| 326 | klen=(*callback)(buf,PEM_BUFSIZE,1,u); | ||
| 327 | if (klen <= 0) | ||
| 328 | { | ||
| 329 | PEMerr(PEM_F_PEM_ASN1_WRITE_BIO,PEM_R_READ_KEY); | ||
| 330 | goto err; | ||
| 331 | } | ||
| 332 | #ifdef CHARSET_EBCDIC | ||
| 333 | /* Convert the pass phrase from EBCDIC */ | ||
| 334 | ebcdic2ascii(buf, buf, klen); | ||
| 335 | #endif | ||
| 336 | kstr=(unsigned char *)buf; | ||
| 337 | } | ||
| 338 | RAND_add(data,i,0);/* put in the RSA key. */ | ||
| 339 | OPENSSL_assert(enc->iv_len <= sizeof iv); | ||
| 340 | if (RAND_pseudo_bytes(iv,enc->iv_len) < 0) /* Generate a salt */ | ||
| 341 | goto err; | ||
| 342 | /* The 'iv' is used as the iv and as a salt. It is | ||
| 343 | * NOT taken from the BytesToKey function */ | ||
| 344 | EVP_BytesToKey(enc,EVP_md5(),iv,kstr,klen,1,key,NULL); | ||
| 345 | |||
| 346 | if (kstr == (unsigned char *)buf) OPENSSL_cleanse(buf,PEM_BUFSIZE); | ||
| 347 | |||
| 348 | OPENSSL_assert(strlen(objstr)+23+2*enc->iv_len+13 <= sizeof buf); | ||
| 349 | |||
| 350 | buf[0]='\0'; | ||
| 351 | PEM_proc_type(buf,PEM_TYPE_ENCRYPTED); | ||
| 352 | PEM_dek_info(buf,objstr,enc->iv_len,(char *)iv); | ||
| 353 | /* k=strlen(buf); */ | ||
| 354 | |||
| 355 | EVP_CIPHER_CTX_init(&ctx); | ||
| 356 | EVP_EncryptInit_ex(&ctx,enc,NULL,key,iv); | ||
| 357 | EVP_EncryptUpdate(&ctx,data,&j,data,i); | ||
| 358 | EVP_EncryptFinal_ex(&ctx,&(data[j]),&i); | ||
| 359 | EVP_CIPHER_CTX_cleanup(&ctx); | ||
| 360 | i+=j; | ||
| 361 | ret=1; | ||
| 362 | } | ||
| 363 | else | ||
| 364 | { | ||
| 365 | ret=1; | ||
| 366 | buf[0]='\0'; | ||
| 367 | } | ||
| 368 | i=PEM_write_bio(bp,name,buf,data,i); | ||
| 369 | if (i <= 0) ret=0; | ||
| 370 | err: | ||
| 371 | OPENSSL_cleanse(key,sizeof(key)); | ||
| 372 | OPENSSL_cleanse(iv,sizeof(iv)); | ||
| 373 | OPENSSL_cleanse((char *)&ctx,sizeof(ctx)); | ||
| 374 | OPENSSL_cleanse(buf,PEM_BUFSIZE); | ||
| 375 | if (data != NULL) | ||
| 376 | { | ||
| 377 | OPENSSL_cleanse(data,(unsigned int)dsize); | ||
| 378 | OPENSSL_free(data); | ||
| 379 | } | ||
| 380 | return(ret); | ||
| 381 | } | ||
| 382 | |||
| 383 | int PEM_do_header(EVP_CIPHER_INFO *cipher, unsigned char *data, long *plen, | ||
| 384 | pem_password_cb *callback,void *u) | ||
| 385 | { | ||
| 386 | int i,j,o,klen; | ||
| 387 | long len; | ||
| 388 | EVP_CIPHER_CTX ctx; | ||
| 389 | unsigned char key[EVP_MAX_KEY_LENGTH]; | ||
| 390 | char buf[PEM_BUFSIZE]; | ||
| 391 | |||
| 392 | len= *plen; | ||
| 393 | |||
| 394 | if (cipher->cipher == NULL) return(1); | ||
| 395 | if (callback == NULL) | ||
| 396 | klen=PEM_def_callback(buf,PEM_BUFSIZE,0,u); | ||
| 397 | else | ||
| 398 | klen=callback(buf,PEM_BUFSIZE,0,u); | ||
| 399 | if (klen <= 0) | ||
| 400 | { | ||
| 401 | PEMerr(PEM_F_PEM_DO_HEADER,PEM_R_BAD_PASSWORD_READ); | ||
| 402 | return(0); | ||
| 403 | } | ||
| 404 | #ifdef CHARSET_EBCDIC | ||
| 405 | /* Convert the pass phrase from EBCDIC */ | ||
| 406 | ebcdic2ascii(buf, buf, klen); | ||
| 407 | #endif | ||
| 408 | |||
| 409 | EVP_BytesToKey(cipher->cipher,EVP_md5(),&(cipher->iv[0]), | ||
| 410 | (unsigned char *)buf,klen,1,key,NULL); | ||
| 411 | |||
| 412 | j=(int)len; | ||
| 413 | EVP_CIPHER_CTX_init(&ctx); | ||
| 414 | EVP_DecryptInit_ex(&ctx,cipher->cipher,NULL, key,&(cipher->iv[0])); | ||
| 415 | EVP_DecryptUpdate(&ctx,data,&i,data,j); | ||
| 416 | o=EVP_DecryptFinal_ex(&ctx,&(data[i]),&j); | ||
| 417 | EVP_CIPHER_CTX_cleanup(&ctx); | ||
| 418 | OPENSSL_cleanse((char *)buf,sizeof(buf)); | ||
| 419 | OPENSSL_cleanse((char *)key,sizeof(key)); | ||
| 420 | j+=i; | ||
| 421 | if (!o) | ||
| 422 | { | ||
| 423 | PEMerr(PEM_F_PEM_DO_HEADER,PEM_R_BAD_DECRYPT); | ||
| 424 | return(0); | ||
| 425 | } | ||
| 426 | *plen=j; | ||
| 427 | return(1); | ||
| 428 | } | ||
| 429 | |||
| 430 | int PEM_get_EVP_CIPHER_INFO(char *header, EVP_CIPHER_INFO *cipher) | ||
| 431 | { | ||
| 432 | int o; | ||
| 433 | const EVP_CIPHER *enc=NULL; | ||
| 434 | char *p,c; | ||
| 435 | char **header_pp = &header; | ||
| 436 | |||
| 437 | cipher->cipher=NULL; | ||
| 438 | if ((header == NULL) || (*header == '\0') || (*header == '\n')) | ||
| 439 | return(1); | ||
| 440 | if (strncmp(header,"Proc-Type: ",11) != 0) | ||
| 441 | { PEMerr(PEM_F_PEM_GET_EVP_CIPHER_INFO,PEM_R_NOT_PROC_TYPE); return(0); } | ||
| 442 | header+=11; | ||
| 443 | if (*header != '4') return(0); header++; | ||
| 444 | if (*header != ',') return(0); header++; | ||
| 445 | if (strncmp(header,"ENCRYPTED",9) != 0) | ||
| 446 | { PEMerr(PEM_F_PEM_GET_EVP_CIPHER_INFO,PEM_R_NOT_ENCRYPTED); return(0); } | ||
| 447 | for (; (*header != '\n') && (*header != '\0'); header++) | ||
| 448 | ; | ||
| 449 | if (*header == '\0') | ||
| 450 | { PEMerr(PEM_F_PEM_GET_EVP_CIPHER_INFO,PEM_R_SHORT_HEADER); return(0); } | ||
| 451 | header++; | ||
| 452 | if (strncmp(header,"DEK-Info: ",10) != 0) | ||
| 453 | { PEMerr(PEM_F_PEM_GET_EVP_CIPHER_INFO,PEM_R_NOT_DEK_INFO); return(0); } | ||
| 454 | header+=10; | ||
| 455 | |||
| 456 | p=header; | ||
| 457 | for (;;) | ||
| 458 | { | ||
| 459 | c= *header; | ||
| 460 | #ifndef CHARSET_EBCDIC | ||
| 461 | if (!( ((c >= 'A') && (c <= 'Z')) || (c == '-') || | ||
| 462 | ((c >= '0') && (c <= '9')))) | ||
| 463 | break; | ||
| 464 | #else | ||
| 465 | if (!( isupper(c) || (c == '-') || | ||
| 466 | isdigit(c))) | ||
| 467 | break; | ||
| 468 | #endif | ||
| 469 | header++; | ||
| 470 | } | ||
| 471 | *header='\0'; | ||
| 472 | o=OBJ_sn2nid(p); | ||
| 473 | cipher->cipher=enc=EVP_get_cipherbyname(p); | ||
| 474 | *header=c; | ||
| 475 | header++; | ||
| 476 | |||
| 477 | if (enc == NULL) | ||
| 478 | { | ||
| 479 | PEMerr(PEM_F_PEM_GET_EVP_CIPHER_INFO,PEM_R_UNSUPPORTED_ENCRYPTION); | ||
| 480 | return(0); | ||
| 481 | } | ||
| 482 | if (!load_iv(header_pp,&(cipher->iv[0]),enc->iv_len)) | ||
| 483 | return(0); | ||
| 484 | |||
| 485 | return(1); | ||
| 486 | } | ||
| 487 | |||
| 488 | static int load_iv(char **fromp, unsigned char *to, int num) | ||
| 489 | { | ||
| 490 | int v,i; | ||
| 491 | char *from; | ||
| 492 | |||
| 493 | from= *fromp; | ||
| 494 | for (i=0; i<num; i++) to[i]=0; | ||
| 495 | num*=2; | ||
| 496 | for (i=0; i<num; i++) | ||
| 497 | { | ||
| 498 | if ((*from >= '0') && (*from <= '9')) | ||
| 499 | v= *from-'0'; | ||
| 500 | else if ((*from >= 'A') && (*from <= 'F')) | ||
| 501 | v= *from-'A'+10; | ||
| 502 | else if ((*from >= 'a') && (*from <= 'f')) | ||
| 503 | v= *from-'a'+10; | ||
| 504 | else | ||
| 505 | { | ||
| 506 | PEMerr(PEM_F_LOAD_IV,PEM_R_BAD_IV_CHARS); | ||
| 507 | return(0); | ||
| 508 | } | ||
| 509 | from++; | ||
| 510 | to[i/2]|=v<<(long)((!(i&1))*4); | ||
| 511 | } | ||
| 512 | |||
| 513 | *fromp=from; | ||
| 514 | return(1); | ||
| 515 | } | ||
| 516 | |||
| 517 | #ifndef OPENSSL_NO_FP_API | ||
| 518 | int PEM_write(FILE *fp, char *name, char *header, unsigned char *data, | ||
| 519 | long len) | ||
| 520 | { | ||
| 521 | BIO *b; | ||
| 522 | int ret; | ||
| 523 | |||
| 524 | if ((b=BIO_new(BIO_s_file())) == NULL) | ||
| 525 | { | ||
| 526 | PEMerr(PEM_F_PEM_WRITE,ERR_R_BUF_LIB); | ||
| 527 | return(0); | ||
| 528 | } | ||
| 529 | BIO_set_fp(b,fp,BIO_NOCLOSE); | ||
| 530 | ret=PEM_write_bio(b, name, header, data,len); | ||
| 531 | BIO_free(b); | ||
| 532 | return(ret); | ||
| 533 | } | ||
| 534 | #endif | ||
| 535 | |||
| 536 | int PEM_write_bio(BIO *bp, const char *name, char *header, unsigned char *data, | ||
| 537 | long len) | ||
| 538 | { | ||
| 539 | int nlen,n,i,j,outl; | ||
| 540 | unsigned char *buf = NULL; | ||
| 541 | EVP_ENCODE_CTX ctx; | ||
| 542 | int reason=ERR_R_BUF_LIB; | ||
| 543 | |||
| 544 | EVP_EncodeInit(&ctx); | ||
| 545 | nlen=strlen(name); | ||
| 546 | |||
| 547 | if ( (BIO_write(bp,"-----BEGIN ",11) != 11) || | ||
| 548 | (BIO_write(bp,name,nlen) != nlen) || | ||
| 549 | (BIO_write(bp,"-----\n",6) != 6)) | ||
| 550 | goto err; | ||
| 551 | |||
| 552 | i=strlen(header); | ||
| 553 | if (i > 0) | ||
| 554 | { | ||
| 555 | if ( (BIO_write(bp,header,i) != i) || | ||
| 556 | (BIO_write(bp,"\n",1) != 1)) | ||
| 557 | goto err; | ||
| 558 | } | ||
| 559 | |||
| 560 | buf = OPENSSL_malloc(PEM_BUFSIZE*8); | ||
| 561 | if (buf == NULL) | ||
| 562 | { | ||
| 563 | reason=ERR_R_MALLOC_FAILURE; | ||
| 564 | goto err; | ||
| 565 | } | ||
| 566 | |||
| 567 | i=j=0; | ||
| 568 | while (len > 0) | ||
| 569 | { | ||
| 570 | n=(int)((len>(PEM_BUFSIZE*5))?(PEM_BUFSIZE*5):len); | ||
| 571 | EVP_EncodeUpdate(&ctx,buf,&outl,&(data[j]),n); | ||
| 572 | if ((outl) && (BIO_write(bp,(char *)buf,outl) != outl)) | ||
| 573 | goto err; | ||
| 574 | i+=outl; | ||
| 575 | len-=n; | ||
| 576 | j+=n; | ||
| 577 | } | ||
| 578 | EVP_EncodeFinal(&ctx,buf,&outl); | ||
| 579 | if ((outl > 0) && (BIO_write(bp,(char *)buf,outl) != outl)) goto err; | ||
| 580 | OPENSSL_free(buf); | ||
| 581 | buf = NULL; | ||
| 582 | if ( (BIO_write(bp,"-----END ",9) != 9) || | ||
| 583 | (BIO_write(bp,name,nlen) != nlen) || | ||
| 584 | (BIO_write(bp,"-----\n",6) != 6)) | ||
| 585 | goto err; | ||
| 586 | return(i+outl); | ||
| 587 | err: | ||
| 588 | if (buf) | ||
| 589 | OPENSSL_free(buf); | ||
| 590 | PEMerr(PEM_F_PEM_WRITE_BIO,reason); | ||
| 591 | return(0); | ||
| 592 | } | ||
| 593 | |||
| 594 | #ifndef OPENSSL_NO_FP_API | ||
| 595 | int PEM_read(FILE *fp, char **name, char **header, unsigned char **data, | ||
| 596 | long *len) | ||
| 597 | { | ||
| 598 | BIO *b; | ||
| 599 | int ret; | ||
| 600 | |||
| 601 | if ((b=BIO_new(BIO_s_file())) == NULL) | ||
| 602 | { | ||
| 603 | PEMerr(PEM_F_PEM_READ,ERR_R_BUF_LIB); | ||
| 604 | return(0); | ||
| 605 | } | ||
| 606 | BIO_set_fp(b,fp,BIO_NOCLOSE); | ||
| 607 | ret=PEM_read_bio(b, name, header, data,len); | ||
| 608 | BIO_free(b); | ||
| 609 | return(ret); | ||
| 610 | } | ||
| 611 | #endif | ||
| 612 | |||
| 613 | int PEM_read_bio(BIO *bp, char **name, char **header, unsigned char **data, | ||
| 614 | long *len) | ||
| 615 | { | ||
| 616 | EVP_ENCODE_CTX ctx; | ||
| 617 | int end=0,i,k,bl=0,hl=0,nohead=0; | ||
| 618 | char buf[256]; | ||
| 619 | BUF_MEM *nameB; | ||
| 620 | BUF_MEM *headerB; | ||
| 621 | BUF_MEM *dataB,*tmpB; | ||
| 622 | |||
| 623 | nameB=BUF_MEM_new(); | ||
| 624 | headerB=BUF_MEM_new(); | ||
| 625 | dataB=BUF_MEM_new(); | ||
| 626 | if ((nameB == NULL) || (headerB == NULL) || (dataB == NULL)) | ||
| 627 | { | ||
| 628 | BUF_MEM_free(nameB); | ||
| 629 | BUF_MEM_free(headerB); | ||
| 630 | BUF_MEM_free(dataB); | ||
| 631 | PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE); | ||
| 632 | return(0); | ||
| 633 | } | ||
| 634 | |||
| 635 | buf[254]='\0'; | ||
| 636 | for (;;) | ||
| 637 | { | ||
| 638 | i=BIO_gets(bp,buf,254); | ||
| 639 | |||
| 640 | if (i <= 0) | ||
| 641 | { | ||
| 642 | PEMerr(PEM_F_PEM_READ_BIO,PEM_R_NO_START_LINE); | ||
| 643 | goto err; | ||
| 644 | } | ||
| 645 | |||
| 646 | while ((i >= 0) && (buf[i] <= ' ')) i--; | ||
| 647 | buf[++i]='\n'; buf[++i]='\0'; | ||
| 648 | |||
| 649 | if (strncmp(buf,"-----BEGIN ",11) == 0) | ||
| 650 | { | ||
| 651 | i=strlen(&(buf[11])); | ||
| 652 | |||
| 653 | if (strncmp(&(buf[11+i-6]),"-----\n",6) != 0) | ||
| 654 | continue; | ||
| 655 | if (!BUF_MEM_grow(nameB,i+9)) | ||
| 656 | { | ||
| 657 | PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE); | ||
| 658 | goto err; | ||
| 659 | } | ||
| 660 | memcpy(nameB->data,&(buf[11]),i-6); | ||
| 661 | nameB->data[i-6]='\0'; | ||
| 662 | break; | ||
| 663 | } | ||
| 664 | } | ||
| 665 | hl=0; | ||
| 666 | if (!BUF_MEM_grow(headerB,256)) | ||
| 667 | { PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE); goto err; } | ||
| 668 | headerB->data[0]='\0'; | ||
| 669 | for (;;) | ||
| 670 | { | ||
| 671 | i=BIO_gets(bp,buf,254); | ||
| 672 | if (i <= 0) break; | ||
| 673 | |||
| 674 | while ((i >= 0) && (buf[i] <= ' ')) i--; | ||
| 675 | buf[++i]='\n'; buf[++i]='\0'; | ||
| 676 | |||
| 677 | if (buf[0] == '\n') break; | ||
| 678 | if (!BUF_MEM_grow(headerB,hl+i+9)) | ||
| 679 | { PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE); goto err; } | ||
| 680 | if (strncmp(buf,"-----END ",9) == 0) | ||
| 681 | { | ||
| 682 | nohead=1; | ||
| 683 | break; | ||
| 684 | } | ||
| 685 | memcpy(&(headerB->data[hl]),buf,i); | ||
| 686 | headerB->data[hl+i]='\0'; | ||
| 687 | hl+=i; | ||
| 688 | } | ||
| 689 | |||
| 690 | bl=0; | ||
| 691 | if (!BUF_MEM_grow(dataB,1024)) | ||
| 692 | { PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE); goto err; } | ||
| 693 | dataB->data[0]='\0'; | ||
| 694 | if (!nohead) | ||
| 695 | { | ||
| 696 | for (;;) | ||
| 697 | { | ||
| 698 | i=BIO_gets(bp,buf,254); | ||
| 699 | if (i <= 0) break; | ||
| 700 | |||
| 701 | while ((i >= 0) && (buf[i] <= ' ')) i--; | ||
| 702 | buf[++i]='\n'; buf[++i]='\0'; | ||
| 703 | |||
| 704 | if (i != 65) end=1; | ||
| 705 | if (strncmp(buf,"-----END ",9) == 0) | ||
| 706 | break; | ||
| 707 | if (i > 65) break; | ||
| 708 | if (!BUF_MEM_grow_clean(dataB,i+bl+9)) | ||
| 709 | { | ||
| 710 | PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE); | ||
| 711 | goto err; | ||
| 712 | } | ||
| 713 | memcpy(&(dataB->data[bl]),buf,i); | ||
| 714 | dataB->data[bl+i]='\0'; | ||
| 715 | bl+=i; | ||
| 716 | if (end) | ||
| 717 | { | ||
| 718 | buf[0]='\0'; | ||
| 719 | i=BIO_gets(bp,buf,254); | ||
| 720 | if (i <= 0) break; | ||
| 721 | |||
| 722 | while ((i >= 0) && (buf[i] <= ' ')) i--; | ||
| 723 | buf[++i]='\n'; buf[++i]='\0'; | ||
| 724 | |||
| 725 | break; | ||
| 726 | } | ||
| 727 | } | ||
| 728 | } | ||
| 729 | else | ||
| 730 | { | ||
| 731 | tmpB=headerB; | ||
| 732 | headerB=dataB; | ||
| 733 | dataB=tmpB; | ||
| 734 | bl=hl; | ||
| 735 | } | ||
| 736 | i=strlen(nameB->data); | ||
| 737 | if ( (strncmp(buf,"-----END ",9) != 0) || | ||
| 738 | (strncmp(nameB->data,&(buf[9]),i) != 0) || | ||
| 739 | (strncmp(&(buf[9+i]),"-----\n",6) != 0)) | ||
| 740 | { | ||
| 741 | PEMerr(PEM_F_PEM_READ_BIO,PEM_R_BAD_END_LINE); | ||
| 742 | goto err; | ||
| 743 | } | ||
| 744 | |||
| 745 | EVP_DecodeInit(&ctx); | ||
| 746 | i=EVP_DecodeUpdate(&ctx, | ||
| 747 | (unsigned char *)dataB->data,&bl, | ||
| 748 | (unsigned char *)dataB->data,bl); | ||
| 749 | if (i < 0) | ||
| 750 | { | ||
| 751 | PEMerr(PEM_F_PEM_READ_BIO,PEM_R_BAD_BASE64_DECODE); | ||
| 752 | goto err; | ||
| 753 | } | ||
| 754 | i=EVP_DecodeFinal(&ctx,(unsigned char *)&(dataB->data[bl]),&k); | ||
| 755 | if (i < 0) | ||
| 756 | { | ||
| 757 | PEMerr(PEM_F_PEM_READ_BIO,PEM_R_BAD_BASE64_DECODE); | ||
| 758 | goto err; | ||
| 759 | } | ||
| 760 | bl+=k; | ||
| 761 | |||
| 762 | if (bl == 0) goto err; | ||
| 763 | *name=nameB->data; | ||
| 764 | *header=headerB->data; | ||
| 765 | *data=(unsigned char *)dataB->data; | ||
| 766 | *len=bl; | ||
| 767 | OPENSSL_free(nameB); | ||
| 768 | OPENSSL_free(headerB); | ||
| 769 | OPENSSL_free(dataB); | ||
| 770 | return(1); | ||
| 771 | err: | ||
| 772 | BUF_MEM_free(nameB); | ||
| 773 | BUF_MEM_free(headerB); | ||
| 774 | BUF_MEM_free(dataB); | ||
| 775 | return(0); | ||
| 776 | } | ||
diff --git a/src/lib/libcrypto/pem/pem_oth.c b/src/lib/libcrypto/pem/pem_oth.c new file mode 100644 index 0000000000..8d9064ea7c --- /dev/null +++ b/src/lib/libcrypto/pem/pem_oth.c | |||
| @@ -0,0 +1,85 @@ | |||
| 1 | /* crypto/pem/pem_oth.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/evp.h> | ||
| 64 | #include <openssl/rand.h> | ||
| 65 | #include <openssl/x509.h> | ||
| 66 | #include <openssl/pem.h> | ||
| 67 | |||
| 68 | /* Handle 'other' PEMs: not private keys */ | ||
| 69 | |||
| 70 | char *PEM_ASN1_read_bio(char *(*d2i)(), const char *name, BIO *bp, char **x, | ||
| 71 | pem_password_cb *cb, void *u) | ||
| 72 | { | ||
| 73 | unsigned char *p=NULL,*data=NULL; | ||
| 74 | long len; | ||
| 75 | char *ret=NULL; | ||
| 76 | |||
| 77 | if (!PEM_bytes_read_bio(&data, &len, NULL, name, bp, cb, u)) | ||
| 78 | return NULL; | ||
| 79 | p = data; | ||
| 80 | ret=d2i(x,&p,len); | ||
| 81 | if (ret == NULL) | ||
| 82 | PEMerr(PEM_F_PEM_ASN1_READ_BIO,ERR_R_ASN1_LIB); | ||
| 83 | OPENSSL_free(data); | ||
| 84 | return(ret); | ||
| 85 | } | ||
diff --git a/src/lib/libcrypto/pem/pem_pk8.c b/src/lib/libcrypto/pem/pem_pk8.c new file mode 100644 index 0000000000..db38a2a79d --- /dev/null +++ b/src/lib/libcrypto/pem/pem_pk8.c | |||
| @@ -0,0 +1,243 @@ | |||
| 1 | /* crypto/pem/pem_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/buffer.h> | ||
| 62 | #include <openssl/objects.h> | ||
| 63 | #include <openssl/evp.h> | ||
| 64 | #include <openssl/rand.h> | ||
| 65 | #include <openssl/x509.h> | ||
| 66 | #include <openssl/pkcs12.h> | ||
| 67 | #include <openssl/pem.h> | ||
| 68 | |||
| 69 | static int do_pk8pkey(BIO *bp, EVP_PKEY *x, int isder, | ||
| 70 | int nid, const EVP_CIPHER *enc, | ||
| 71 | char *kstr, int klen, | ||
| 72 | pem_password_cb *cb, void *u); | ||
| 73 | static int do_pk8pkey_fp(FILE *bp, EVP_PKEY *x, int isder, | ||
| 74 | int nid, const EVP_CIPHER *enc, | ||
| 75 | char *kstr, int klen, | ||
| 76 | pem_password_cb *cb, void *u); | ||
| 77 | |||
| 78 | /* These functions write a private key in PKCS#8 format: it is a "drop in" | ||
| 79 | * replacement for PEM_write_bio_PrivateKey() and friends. As usual if 'enc' | ||
| 80 | * is NULL then it uses the unencrypted private key form. The 'nid' versions | ||
| 81 | * uses PKCS#5 v1.5 PBE algorithms whereas the others use PKCS#5 v2.0. | ||
| 82 | */ | ||
| 83 | |||
| 84 | int PEM_write_bio_PKCS8PrivateKey_nid(BIO *bp, EVP_PKEY *x, int nid, | ||
| 85 | char *kstr, int klen, | ||
| 86 | pem_password_cb *cb, void *u) | ||
| 87 | { | ||
| 88 | return do_pk8pkey(bp, x, 0, nid, NULL, kstr, klen, cb, u); | ||
| 89 | } | ||
| 90 | |||
| 91 | int PEM_write_bio_PKCS8PrivateKey(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc, | ||
| 92 | char *kstr, int klen, | ||
| 93 | pem_password_cb *cb, void *u) | ||
| 94 | { | ||
| 95 | return do_pk8pkey(bp, x, 0, -1, enc, kstr, klen, cb, u); | ||
| 96 | } | ||
| 97 | |||
| 98 | int i2d_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc, | ||
| 99 | char *kstr, int klen, | ||
| 100 | pem_password_cb *cb, void *u) | ||
| 101 | { | ||
| 102 | return do_pk8pkey(bp, x, 1, -1, enc, kstr, klen, cb, u); | ||
| 103 | } | ||
| 104 | |||
| 105 | int i2d_PKCS8PrivateKey_nid_bio(BIO *bp, EVP_PKEY *x, int nid, | ||
| 106 | char *kstr, int klen, | ||
| 107 | pem_password_cb *cb, void *u) | ||
| 108 | { | ||
| 109 | return do_pk8pkey(bp, x, 1, nid, NULL, kstr, klen, cb, u); | ||
| 110 | } | ||
| 111 | |||
| 112 | static int do_pk8pkey(BIO *bp, EVP_PKEY *x, int isder, int nid, const EVP_CIPHER *enc, | ||
| 113 | char *kstr, int klen, | ||
| 114 | pem_password_cb *cb, void *u) | ||
| 115 | { | ||
| 116 | X509_SIG *p8; | ||
| 117 | PKCS8_PRIV_KEY_INFO *p8inf; | ||
| 118 | char buf[PEM_BUFSIZE]; | ||
| 119 | int ret; | ||
| 120 | if(!(p8inf = EVP_PKEY2PKCS8(x))) { | ||
| 121 | PEMerr(PEM_F_PEM_WRITE_BIO_PKCS8PRIVATEKEY, | ||
| 122 | PEM_R_ERROR_CONVERTING_PRIVATE_KEY); | ||
| 123 | return 0; | ||
| 124 | } | ||
| 125 | if(enc || (nid != -1)) { | ||
| 126 | if(!kstr) { | ||
| 127 | if(!cb) klen = PEM_def_callback(buf, PEM_BUFSIZE, 1, u); | ||
| 128 | else klen = cb(buf, PEM_BUFSIZE, 1, u); | ||
| 129 | if(klen <= 0) { | ||
| 130 | PEMerr(PEM_F_PEM_WRITE_BIO_PKCS8PRIVATEKEY, | ||
| 131 | PEM_R_READ_KEY); | ||
| 132 | PKCS8_PRIV_KEY_INFO_free(p8inf); | ||
| 133 | return 0; | ||
| 134 | } | ||
| 135 | |||
| 136 | kstr = buf; | ||
| 137 | } | ||
| 138 | p8 = PKCS8_encrypt(nid, enc, kstr, klen, NULL, 0, 0, p8inf); | ||
| 139 | if(kstr == buf) OPENSSL_cleanse(buf, klen); | ||
| 140 | PKCS8_PRIV_KEY_INFO_free(p8inf); | ||
| 141 | if(isder) ret = i2d_PKCS8_bio(bp, p8); | ||
| 142 | else ret = PEM_write_bio_PKCS8(bp, p8); | ||
| 143 | X509_SIG_free(p8); | ||
| 144 | return ret; | ||
| 145 | } else { | ||
| 146 | if(isder) ret = i2d_PKCS8_PRIV_KEY_INFO_bio(bp, p8inf); | ||
| 147 | else ret = PEM_write_bio_PKCS8_PRIV_KEY_INFO(bp, p8inf); | ||
| 148 | PKCS8_PRIV_KEY_INFO_free(p8inf); | ||
| 149 | return ret; | ||
| 150 | } | ||
| 151 | } | ||
| 152 | |||
| 153 | EVP_PKEY *d2i_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, void *u) | ||
| 154 | { | ||
| 155 | PKCS8_PRIV_KEY_INFO *p8inf = NULL; | ||
| 156 | X509_SIG *p8 = NULL; | ||
| 157 | int klen; | ||
| 158 | EVP_PKEY *ret; | ||
| 159 | char psbuf[PEM_BUFSIZE]; | ||
| 160 | p8 = d2i_PKCS8_bio(bp, NULL); | ||
| 161 | if(!p8) return NULL; | ||
| 162 | if (cb) klen=cb(psbuf,PEM_BUFSIZE,0,u); | ||
| 163 | else klen=PEM_def_callback(psbuf,PEM_BUFSIZE,0,u); | ||
| 164 | if (klen <= 0) { | ||
| 165 | PEMerr(PEM_F_D2I_PKCS8PRIVATEKEY_BIO, PEM_R_BAD_PASSWORD_READ); | ||
| 166 | X509_SIG_free(p8); | ||
| 167 | return NULL; | ||
| 168 | } | ||
| 169 | p8inf = PKCS8_decrypt(p8, psbuf, klen); | ||
| 170 | X509_SIG_free(p8); | ||
| 171 | if(!p8inf) return NULL; | ||
| 172 | ret = EVP_PKCS82PKEY(p8inf); | ||
| 173 | PKCS8_PRIV_KEY_INFO_free(p8inf); | ||
| 174 | if(!ret) return NULL; | ||
| 175 | if(x) { | ||
| 176 | if(*x) EVP_PKEY_free(*x); | ||
| 177 | *x = ret; | ||
| 178 | } | ||
| 179 | return ret; | ||
| 180 | } | ||
| 181 | |||
| 182 | #ifndef OPENSSL_NO_FP_API | ||
| 183 | |||
| 184 | int i2d_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc, | ||
| 185 | char *kstr, int klen, | ||
| 186 | pem_password_cb *cb, void *u) | ||
| 187 | { | ||
| 188 | return do_pk8pkey_fp(fp, x, 1, -1, enc, kstr, klen, cb, u); | ||
| 189 | } | ||
| 190 | |||
| 191 | int i2d_PKCS8PrivateKey_nid_fp(FILE *fp, EVP_PKEY *x, int nid, | ||
| 192 | char *kstr, int klen, | ||
| 193 | pem_password_cb *cb, void *u) | ||
| 194 | { | ||
| 195 | return do_pk8pkey_fp(fp, x, 1, nid, NULL, kstr, klen, cb, u); | ||
| 196 | } | ||
| 197 | |||
| 198 | int PEM_write_PKCS8PrivateKey_nid(FILE *fp, EVP_PKEY *x, int nid, | ||
| 199 | char *kstr, int klen, | ||
| 200 | pem_password_cb *cb, void *u) | ||
| 201 | { | ||
| 202 | return do_pk8pkey_fp(fp, x, 0, nid, NULL, kstr, klen, cb, u); | ||
| 203 | } | ||
| 204 | |||
| 205 | int PEM_write_PKCS8PrivateKey(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc, | ||
| 206 | char *kstr, int klen, pem_password_cb *cb, void *u) | ||
| 207 | { | ||
| 208 | return do_pk8pkey_fp(fp, x, 0, -1, enc, kstr, klen, cb, u); | ||
| 209 | } | ||
| 210 | |||
| 211 | static int do_pk8pkey_fp(FILE *fp, EVP_PKEY *x, int isder, int nid, const EVP_CIPHER *enc, | ||
| 212 | char *kstr, int klen, | ||
| 213 | pem_password_cb *cb, void *u) | ||
| 214 | { | ||
| 215 | BIO *bp; | ||
| 216 | int ret; | ||
| 217 | if(!(bp = BIO_new_fp(fp, BIO_NOCLOSE))) { | ||
| 218 | PEMerr(PEM_F_PEM_F_DO_PK8KEY_FP,ERR_R_BUF_LIB); | ||
| 219 | return(0); | ||
| 220 | } | ||
| 221 | ret = do_pk8pkey(bp, x, isder, nid, enc, kstr, klen, cb, u); | ||
| 222 | BIO_free(bp); | ||
| 223 | return ret; | ||
| 224 | } | ||
| 225 | |||
| 226 | EVP_PKEY *d2i_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, void *u) | ||
| 227 | { | ||
| 228 | BIO *bp; | ||
| 229 | EVP_PKEY *ret; | ||
| 230 | if(!(bp = BIO_new_fp(fp, BIO_NOCLOSE))) { | ||
| 231 | PEMerr(PEM_F_D2I_PKCS8PRIVATEKEY_FP,ERR_R_BUF_LIB); | ||
| 232 | return NULL; | ||
| 233 | } | ||
| 234 | ret = d2i_PKCS8PrivateKey_bio(bp, x, cb, u); | ||
| 235 | BIO_free(bp); | ||
| 236 | return ret; | ||
| 237 | } | ||
| 238 | |||
| 239 | #endif | ||
| 240 | |||
| 241 | IMPLEMENT_PEM_rw(PKCS8, X509_SIG, PEM_STRING_PKCS8, X509_SIG) | ||
| 242 | IMPLEMENT_PEM_rw(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO, PEM_STRING_PKCS8INF, | ||
| 243 | PKCS8_PRIV_KEY_INFO) | ||
diff --git a/src/lib/libcrypto/pem/pem_pkey.c b/src/lib/libcrypto/pem/pem_pkey.c new file mode 100644 index 0000000000..9ecdbd5419 --- /dev/null +++ b/src/lib/libcrypto/pem/pem_pkey.c | |||
| @@ -0,0 +1,145 @@ | |||
| 1 | /* crypto/pem/pem_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/buffer.h> | ||
| 62 | #include <openssl/objects.h> | ||
| 63 | #include <openssl/evp.h> | ||
| 64 | #include <openssl/rand.h> | ||
| 65 | #include <openssl/x509.h> | ||
| 66 | #include <openssl/pkcs12.h> | ||
| 67 | #include <openssl/pem.h> | ||
| 68 | |||
| 69 | |||
| 70 | EVP_PKEY *PEM_read_bio_PrivateKey(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, void *u) | ||
| 71 | { | ||
| 72 | char *nm=NULL; | ||
| 73 | unsigned char *p=NULL,*data=NULL; | ||
| 74 | long len; | ||
| 75 | EVP_PKEY *ret=NULL; | ||
| 76 | |||
| 77 | if (!PEM_bytes_read_bio(&data, &len, &nm, PEM_STRING_EVP_PKEY, bp, cb, u)) | ||
| 78 | return NULL; | ||
| 79 | p = data; | ||
| 80 | |||
| 81 | if (strcmp(nm,PEM_STRING_RSA) == 0) | ||
| 82 | ret=d2i_PrivateKey(EVP_PKEY_RSA,x,&p,len); | ||
| 83 | else if (strcmp(nm,PEM_STRING_DSA) == 0) | ||
| 84 | ret=d2i_PrivateKey(EVP_PKEY_DSA,x,&p,len); | ||
| 85 | else if (strcmp(nm,PEM_STRING_PKCS8INF) == 0) { | ||
| 86 | PKCS8_PRIV_KEY_INFO *p8inf; | ||
| 87 | p8inf=d2i_PKCS8_PRIV_KEY_INFO(NULL, &p, len); | ||
| 88 | if(!p8inf) goto p8err; | ||
| 89 | ret = EVP_PKCS82PKEY(p8inf); | ||
| 90 | if(x) { | ||
| 91 | if(*x) EVP_PKEY_free((EVP_PKEY *)*x); | ||
| 92 | *x = ret; | ||
| 93 | } | ||
| 94 | PKCS8_PRIV_KEY_INFO_free(p8inf); | ||
| 95 | } else if (strcmp(nm,PEM_STRING_PKCS8) == 0) { | ||
| 96 | PKCS8_PRIV_KEY_INFO *p8inf; | ||
| 97 | X509_SIG *p8; | ||
| 98 | int klen; | ||
| 99 | char psbuf[PEM_BUFSIZE]; | ||
| 100 | p8 = d2i_X509_SIG(NULL, &p, len); | ||
| 101 | if(!p8) goto p8err; | ||
| 102 | if (cb) klen=cb(psbuf,PEM_BUFSIZE,0,u); | ||
| 103 | else klen=PEM_def_callback(psbuf,PEM_BUFSIZE,0,u); | ||
| 104 | if (klen <= 0) { | ||
| 105 | PEMerr(PEM_F_PEM_ASN1_READ_BIO, | ||
| 106 | PEM_R_BAD_PASSWORD_READ); | ||
| 107 | X509_SIG_free(p8); | ||
| 108 | goto err; | ||
| 109 | } | ||
| 110 | p8inf = PKCS8_decrypt(p8, psbuf, klen); | ||
| 111 | X509_SIG_free(p8); | ||
| 112 | if(!p8inf) goto p8err; | ||
| 113 | ret = EVP_PKCS82PKEY(p8inf); | ||
| 114 | if(x) { | ||
| 115 | if(*x) EVP_PKEY_free((EVP_PKEY *)*x); | ||
| 116 | *x = ret; | ||
| 117 | } | ||
| 118 | PKCS8_PRIV_KEY_INFO_free(p8inf); | ||
| 119 | } | ||
| 120 | p8err: | ||
| 121 | if (ret == NULL) | ||
| 122 | PEMerr(PEM_F_PEM_ASN1_READ_BIO,ERR_R_ASN1_LIB); | ||
| 123 | err: | ||
| 124 | OPENSSL_free(nm); | ||
| 125 | OPENSSL_free(data); | ||
| 126 | return(ret); | ||
| 127 | } | ||
| 128 | |||
| 129 | #ifndef OPENSSL_NO_FP_API | ||
| 130 | EVP_PKEY *PEM_read_PrivateKey(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, void *u) | ||
| 131 | { | ||
| 132 | BIO *b; | ||
| 133 | EVP_PKEY *ret; | ||
| 134 | |||
| 135 | if ((b=BIO_new(BIO_s_file())) == NULL) | ||
| 136 | { | ||
| 137 | PEMerr(PEM_F_PEM_ASN1_READ,ERR_R_BUF_LIB); | ||
| 138 | return(0); | ||
| 139 | } | ||
| 140 | BIO_set_fp(b,fp,BIO_NOCLOSE); | ||
| 141 | ret=PEM_read_bio_PrivateKey(b,x,cb,u); | ||
| 142 | BIO_free(b); | ||
| 143 | return(ret); | ||
| 144 | } | ||
| 145 | #endif | ||
diff --git a/src/lib/libcrypto/pem/pem_seal.c b/src/lib/libcrypto/pem/pem_seal.c new file mode 100644 index 0000000000..56e08abd70 --- /dev/null +++ b/src/lib/libcrypto/pem/pem_seal.c | |||
| @@ -0,0 +1,187 @@ | |||
| 1 | /* crypto/pem/pem_seal.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 | #ifndef OPENSSL_NO_RSA | ||
| 60 | #include <stdio.h> | ||
| 61 | #include "cryptlib.h" | ||
| 62 | #include <openssl/evp.h> | ||
| 63 | #include <openssl/rand.h> | ||
| 64 | #include <openssl/objects.h> | ||
| 65 | #include <openssl/x509.h> | ||
| 66 | #include <openssl/pem.h> | ||
| 67 | |||
| 68 | int PEM_SealInit(PEM_ENCODE_SEAL_CTX *ctx, EVP_CIPHER *type, EVP_MD *md_type, | ||
| 69 | unsigned char **ek, int *ekl, unsigned char *iv, EVP_PKEY **pubk, | ||
| 70 | int npubk) | ||
| 71 | { | ||
| 72 | unsigned char key[EVP_MAX_KEY_LENGTH]; | ||
| 73 | int ret= -1; | ||
| 74 | int i,j,max=0; | ||
| 75 | char *s=NULL; | ||
| 76 | |||
| 77 | for (i=0; i<npubk; i++) | ||
| 78 | { | ||
| 79 | if (pubk[i]->type != EVP_PKEY_RSA) | ||
| 80 | { | ||
| 81 | PEMerr(PEM_F_PEM_SEALINIT,PEM_R_PUBLIC_KEY_NO_RSA); | ||
| 82 | goto err; | ||
| 83 | } | ||
| 84 | j=RSA_size(pubk[i]->pkey.rsa); | ||
| 85 | if (j > max) max=j; | ||
| 86 | } | ||
| 87 | s=(char *)OPENSSL_malloc(max*2); | ||
| 88 | if (s == NULL) | ||
| 89 | { | ||
| 90 | PEMerr(PEM_F_PEM_SEALINIT,ERR_R_MALLOC_FAILURE); | ||
| 91 | goto err; | ||
| 92 | } | ||
| 93 | |||
| 94 | EVP_EncodeInit(&ctx->encode); | ||
| 95 | |||
| 96 | EVP_MD_CTX_init(&ctx->md); | ||
| 97 | EVP_SignInit(&ctx->md,md_type); | ||
| 98 | |||
| 99 | EVP_CIPHER_CTX_init(&ctx->cipher); | ||
| 100 | ret=EVP_SealInit(&ctx->cipher,type,ek,ekl,iv,pubk,npubk); | ||
| 101 | if (!ret) goto err; | ||
| 102 | |||
| 103 | /* base64 encode the keys */ | ||
| 104 | for (i=0; i<npubk; i++) | ||
| 105 | { | ||
| 106 | j=EVP_EncodeBlock((unsigned char *)s,ek[i], | ||
| 107 | RSA_size(pubk[i]->pkey.rsa)); | ||
| 108 | ekl[i]=j; | ||
| 109 | memcpy(ek[i],s,j+1); | ||
| 110 | } | ||
| 111 | |||
| 112 | ret=npubk; | ||
| 113 | err: | ||
| 114 | if (s != NULL) OPENSSL_free(s); | ||
| 115 | OPENSSL_cleanse(key,EVP_MAX_KEY_LENGTH); | ||
| 116 | return(ret); | ||
| 117 | } | ||
| 118 | |||
| 119 | void PEM_SealUpdate(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *out, int *outl, | ||
| 120 | unsigned char *in, int inl) | ||
| 121 | { | ||
| 122 | unsigned char buffer[1600]; | ||
| 123 | int i,j; | ||
| 124 | |||
| 125 | *outl=0; | ||
| 126 | EVP_SignUpdate(&ctx->md,in,inl); | ||
| 127 | for (;;) | ||
| 128 | { | ||
| 129 | if (inl <= 0) break; | ||
| 130 | if (inl > 1200) | ||
| 131 | i=1200; | ||
| 132 | else | ||
| 133 | i=inl; | ||
| 134 | EVP_EncryptUpdate(&ctx->cipher,buffer,&j,in,i); | ||
| 135 | EVP_EncodeUpdate(&ctx->encode,out,&j,buffer,j); | ||
| 136 | *outl+=j; | ||
| 137 | out+=j; | ||
| 138 | in+=i; | ||
| 139 | inl-=i; | ||
| 140 | } | ||
| 141 | } | ||
| 142 | |||
| 143 | int PEM_SealFinal(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *sig, int *sigl, | ||
| 144 | unsigned char *out, int *outl, EVP_PKEY *priv) | ||
| 145 | { | ||
| 146 | unsigned char *s=NULL; | ||
| 147 | int ret=0,j; | ||
| 148 | unsigned int i; | ||
| 149 | |||
| 150 | if (priv->type != EVP_PKEY_RSA) | ||
| 151 | { | ||
| 152 | PEMerr(PEM_F_PEM_SEALFINAL,PEM_R_PUBLIC_KEY_NO_RSA); | ||
| 153 | goto err; | ||
| 154 | } | ||
| 155 | i=RSA_size(priv->pkey.rsa); | ||
| 156 | if (i < 100) i=100; | ||
| 157 | s=(unsigned char *)OPENSSL_malloc(i*2); | ||
| 158 | if (s == NULL) | ||
| 159 | { | ||
| 160 | PEMerr(PEM_F_PEM_SEALFINAL,ERR_R_MALLOC_FAILURE); | ||
| 161 | goto err; | ||
| 162 | } | ||
| 163 | |||
| 164 | EVP_EncryptFinal_ex(&ctx->cipher,s,(int *)&i); | ||
| 165 | EVP_EncodeUpdate(&ctx->encode,out,&j,s,i); | ||
| 166 | *outl=j; | ||
| 167 | out+=j; | ||
| 168 | EVP_EncodeFinal(&ctx->encode,out,&j); | ||
| 169 | *outl+=j; | ||
| 170 | |||
| 171 | if (!EVP_SignFinal(&ctx->md,s,&i,priv)) goto err; | ||
| 172 | *sigl=EVP_EncodeBlock(sig,s,i); | ||
| 173 | |||
| 174 | ret=1; | ||
| 175 | err: | ||
| 176 | EVP_MD_CTX_cleanup(&ctx->md); | ||
| 177 | EVP_CIPHER_CTX_cleanup(&ctx->cipher); | ||
| 178 | if (s != NULL) OPENSSL_free(s); | ||
| 179 | return(ret); | ||
| 180 | } | ||
| 181 | #else /* !OPENSSL_NO_RSA */ | ||
| 182 | |||
| 183 | # if PEDANTIC | ||
| 184 | static void *dummy=&dummy; | ||
| 185 | # endif | ||
| 186 | |||
| 187 | #endif | ||
diff --git a/src/lib/libcrypto/pem/pem_sign.c b/src/lib/libcrypto/pem/pem_sign.c new file mode 100644 index 0000000000..c3b9808cb2 --- /dev/null +++ b/src/lib/libcrypto/pem/pem_sign.c | |||
| @@ -0,0 +1,102 @@ | |||
| 1 | /* crypto/pem/pem_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 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/rand.h> | ||
| 62 | #include <openssl/evp.h> | ||
| 63 | #include <openssl/objects.h> | ||
| 64 | #include <openssl/x509.h> | ||
| 65 | #include <openssl/pem.h> | ||
| 66 | |||
| 67 | void PEM_SignInit(EVP_MD_CTX *ctx, EVP_MD *type) | ||
| 68 | { | ||
| 69 | EVP_DigestInit_ex(ctx, type, NULL); | ||
| 70 | } | ||
| 71 | |||
| 72 | void PEM_SignUpdate(EVP_MD_CTX *ctx, unsigned char *data, | ||
| 73 | unsigned int count) | ||
| 74 | { | ||
| 75 | EVP_DigestUpdate(ctx,data,count); | ||
| 76 | } | ||
| 77 | |||
| 78 | int PEM_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, unsigned int *siglen, | ||
| 79 | EVP_PKEY *pkey) | ||
| 80 | { | ||
| 81 | unsigned char *m; | ||
| 82 | int i,ret=0; | ||
| 83 | unsigned int m_len; | ||
| 84 | |||
| 85 | m=(unsigned char *)OPENSSL_malloc(EVP_PKEY_size(pkey)+2); | ||
| 86 | if (m == NULL) | ||
| 87 | { | ||
| 88 | PEMerr(PEM_F_PEM_SIGNFINAL,ERR_R_MALLOC_FAILURE); | ||
| 89 | goto err; | ||
| 90 | } | ||
| 91 | |||
| 92 | if (EVP_SignFinal(ctx,m,&m_len,pkey) <= 0) goto err; | ||
| 93 | |||
| 94 | i=EVP_EncodeBlock(sigret,m,m_len); | ||
| 95 | *siglen=i; | ||
| 96 | ret=1; | ||
| 97 | err: | ||
| 98 | /* ctx has been zeroed by EVP_SignFinal() */ | ||
| 99 | if (m != NULL) OPENSSL_free(m); | ||
| 100 | return(ret); | ||
| 101 | } | ||
| 102 | |||
diff --git a/src/lib/libcrypto/pem/pem_x509.c b/src/lib/libcrypto/pem/pem_x509.c new file mode 100644 index 0000000000..19f88d8d3a --- /dev/null +++ b/src/lib/libcrypto/pem/pem_x509.c | |||
| @@ -0,0 +1,69 @@ | |||
| 1 | /* pem_x509.c */ | ||
| 2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
| 3 | * project 2001. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 2001 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 | #undef SSLEAY_MACROS | ||
| 61 | #include "cryptlib.h" | ||
| 62 | #include <openssl/bio.h> | ||
| 63 | #include <openssl/evp.h> | ||
| 64 | #include <openssl/x509.h> | ||
| 65 | #include <openssl/pkcs7.h> | ||
| 66 | #include <openssl/pem.h> | ||
| 67 | |||
| 68 | IMPLEMENT_PEM_rw(X509, X509, PEM_STRING_X509, X509) | ||
| 69 | |||
diff --git a/src/lib/libcrypto/pem/pem_xaux.c b/src/lib/libcrypto/pem/pem_xaux.c new file mode 100644 index 0000000000..2f579b5421 --- /dev/null +++ b/src/lib/libcrypto/pem/pem_xaux.c | |||
| @@ -0,0 +1,68 @@ | |||
| 1 | /* pem_xaux.c */ | ||
| 2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
| 3 | * project 2001. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 2001 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 | #undef SSLEAY_MACROS | ||
| 61 | #include "cryptlib.h" | ||
| 62 | #include <openssl/bio.h> | ||
| 63 | #include <openssl/evp.h> | ||
| 64 | #include <openssl/x509.h> | ||
| 65 | #include <openssl/pkcs7.h> | ||
| 66 | #include <openssl/pem.h> | ||
| 67 | |||
| 68 | IMPLEMENT_PEM_rw(X509_AUX, X509, PEM_STRING_X509_TRUSTED, X509_AUX) | ||
diff --git a/src/lib/libcrypto/pem/pkcs7.lis b/src/lib/libcrypto/pem/pkcs7.lis new file mode 100644 index 0000000000..be90c5d87f --- /dev/null +++ b/src/lib/libcrypto/pem/pkcs7.lis | |||
| @@ -0,0 +1,22 @@ | |||
| 1 | 21 0:d=0 hl=2 l= 0 cons: univ: SEQUENCE | ||
| 2 | 00 2:d=0 hl=2 l= 9 prim: univ: OBJECT_IDENTIFIER :pkcs-7-signedData | ||
| 3 | 21 13:d=0 hl=2 l= 0 cons: cont: 00 # explicit tag | ||
| 4 | 21 15:d=0 hl=2 l= 0 cons: univ: SEQUENCE | ||
| 5 | 00 17:d=0 hl=2 l= 1 prim: univ: INTEGER # version | ||
| 6 | 20 20:d=0 hl=2 l= 0 cons: univ: SET | ||
| 7 | 21 22:d=0 hl=2 l= 0 cons: univ: SEQUENCE | ||
| 8 | 00 24:d=0 hl=2 l= 9 prim: univ: OBJECT_IDENTIFIER :pkcs-7-data | ||
| 9 | 00 35:d=0 hl=2 l= 0 prim: univ: EOC | ||
| 10 | 21 37:d=0 hl=2 l= 0 cons: cont: 00 # cert tag | ||
| 11 | 20 39:d=0 hl=4 l=545 cons: univ: SEQUENCE | ||
| 12 | 20 588:d=0 hl=4 l=524 cons: univ: SEQUENCE | ||
| 13 | 00 1116:d=0 hl=2 l= 0 prim: univ: EOC | ||
| 14 | 21 1118:d=0 hl=2 l= 0 cons: cont: 01 # crl tag | ||
| 15 | 20 1120:d=0 hl=4 l=653 cons: univ: SEQUENCE | ||
| 16 | 20 1777:d=0 hl=4 l=285 cons: univ: SEQUENCE | ||
| 17 | 00 2066:d=0 hl=2 l= 0 prim: univ: EOC | ||
| 18 | 21 2068:d=0 hl=2 l= 0 cons: univ: SET # signers | ||
| 19 | 00 2070:d=0 hl=2 l= 0 prim: univ: EOC | ||
| 20 | 00 2072:d=0 hl=2 l= 0 prim: univ: EOC | ||
| 21 | 00 2074:d=0 hl=2 l= 0 prim: univ: EOC | ||
| 22 | 00 2076:d=0 hl=2 l= 0 prim: univ: EOC | ||
