diff options
Diffstat (limited to 'src/lib/libcrypto/pkcs12')
| -rw-r--r-- | src/lib/libcrypto/pkcs12/Makefile | 415 | ||||
| -rw-r--r-- | src/lib/libcrypto/pkcs12/p12_add.c | 224 | ||||
| -rw-r--r-- | src/lib/libcrypto/pkcs12/p12_asn.c | 125 | ||||
| -rw-r--r-- | src/lib/libcrypto/pkcs12/p12_attr.c | 145 | ||||
| -rw-r--r-- | src/lib/libcrypto/pkcs12/p12_crpt.c | 124 | ||||
| -rw-r--r-- | src/lib/libcrypto/pkcs12/p12_crt.c | 172 | ||||
| -rw-r--r-- | src/lib/libcrypto/pkcs12/p12_decr.c | 176 | ||||
| -rw-r--r-- | src/lib/libcrypto/pkcs12/p12_init.c | 92 | ||||
| -rw-r--r-- | src/lib/libcrypto/pkcs12/p12_key.c | 206 | ||||
| -rw-r--r-- | src/lib/libcrypto/pkcs12/p12_kiss.c | 297 | ||||
| -rw-r--r-- | src/lib/libcrypto/pkcs12/p12_mutl.c | 182 | ||||
| -rw-r--r-- | src/lib/libcrypto/pkcs12/p12_npas.c | 217 | ||||
| -rw-r--r-- | src/lib/libcrypto/pkcs12/p12_p8d.c | 68 | ||||
| -rw-r--r-- | src/lib/libcrypto/pkcs12/p12_p8e.c | 97 | ||||
| -rw-r--r-- | src/lib/libcrypto/pkcs12/p12_utl.c | 146 | ||||
| -rw-r--r-- | src/lib/libcrypto/pkcs12/pk12err.c | 146 | ||||
| -rw-r--r-- | src/lib/libcrypto/pkcs12/pkcs12.h | 323 |
17 files changed, 3155 insertions, 0 deletions
diff --git a/src/lib/libcrypto/pkcs12/Makefile b/src/lib/libcrypto/pkcs12/Makefile new file mode 100644 index 0000000000..bef4f27912 --- /dev/null +++ b/src/lib/libcrypto/pkcs12/Makefile | |||
| @@ -0,0 +1,415 @@ | |||
| 1 | # | ||
| 2 | # OpenSSL/crypto/pkcs12/Makefile | ||
| 3 | # | ||
| 4 | |||
| 5 | DIR= pkcs12 | ||
| 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= p12_add.c p12_asn.c p12_attr.c p12_crpt.c p12_crt.c p12_decr.c \ | ||
| 26 | p12_init.c p12_key.c p12_kiss.c p12_mutl.c\ | ||
| 27 | p12_utl.c p12_npas.c pk12err.c p12_p8d.c p12_p8e.c | ||
| 28 | LIBOBJ= p12_add.o p12_asn.o p12_attr.o p12_crpt.o p12_crt.o p12_decr.o \ | ||
| 29 | p12_init.o p12_key.o p12_kiss.o p12_mutl.o\ | ||
| 30 | p12_utl.o p12_npas.o pk12err.o p12_p8d.o p12_p8e.o | ||
| 31 | |||
| 32 | SRC= $(LIBSRC) | ||
| 33 | |||
| 34 | EXHEADER= pkcs12.h | ||
| 35 | HEADER= $(EXHEADER) | ||
| 36 | |||
| 37 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
| 38 | |||
| 39 | top: | ||
| 40 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
| 41 | |||
| 42 | test: | ||
| 43 | |||
| 44 | all: lib | ||
| 45 | |||
| 46 | lib: $(LIBOBJ) | ||
| 47 | $(AR) $(LIB) $(LIBOBJ) | ||
| 48 | $(RANLIB) $(LIB) || echo Never mind. | ||
| 49 | @touch lib | ||
| 50 | |||
| 51 | files: | ||
| 52 | $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO | ||
| 53 | |||
| 54 | links: | ||
| 55 | @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) | ||
| 56 | @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) | ||
| 57 | @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) | ||
| 58 | |||
| 59 | install: | ||
| 60 | @headerlist="$(EXHEADER)"; for i in $$headerlist ; \ | ||
| 61 | do \ | ||
| 62 | (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ | ||
| 63 | chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ | ||
| 64 | done; | ||
| 65 | |||
| 66 | tags: | ||
| 67 | ctags $(SRC) | ||
| 68 | |||
| 69 | tests: | ||
| 70 | |||
| 71 | lint: | ||
| 72 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
| 73 | |||
| 74 | depend: | ||
| 75 | $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC) | ||
| 76 | |||
| 77 | dclean: | ||
| 78 | $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
| 79 | mv -f Makefile.new $(MAKEFILE) | ||
| 80 | |||
| 81 | clean: | ||
| 82 | rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
| 83 | |||
| 84 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
| 85 | |||
| 86 | p12_add.o: ../../e_os.h ../../include/openssl/aes.h | ||
| 87 | p12_add.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
| 88 | p12_add.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h | ||
| 89 | p12_add.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h | ||
| 90 | p12_add.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
| 91 | p12_add.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h | ||
| 92 | p12_add.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h | ||
| 93 | p12_add.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
| 94 | p12_add.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h | ||
| 95 | p12_add.o: ../../include/openssl/md2.h ../../include/openssl/md4.h | ||
| 96 | p12_add.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h | ||
| 97 | p12_add.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
| 98 | p12_add.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
| 99 | p12_add.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs12.h | ||
| 100 | p12_add.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h | ||
| 101 | p12_add.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h | ||
| 102 | p12_add.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h | ||
| 103 | p12_add.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
| 104 | p12_add.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 105 | p12_add.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h | ||
| 106 | p12_add.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h | ||
| 107 | p12_add.o: ../cryptlib.h p12_add.c | ||
| 108 | p12_asn.o: ../../e_os.h ../../include/openssl/aes.h | ||
| 109 | p12_asn.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h | ||
| 110 | p12_asn.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h | ||
| 111 | p12_asn.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h | ||
| 112 | p12_asn.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h | ||
| 113 | p12_asn.o: ../../include/openssl/des.h ../../include/openssl/des_old.h | ||
| 114 | p12_asn.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h | ||
| 115 | p12_asn.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
| 116 | p12_asn.o: ../../include/openssl/evp.h ../../include/openssl/idea.h | ||
| 117 | p12_asn.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h | ||
| 118 | p12_asn.o: ../../include/openssl/md4.h ../../include/openssl/md5.h | ||
| 119 | p12_asn.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h | ||
| 120 | p12_asn.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | ||
| 121 | p12_asn.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 122 | p12_asn.o: ../../include/openssl/pkcs12.h ../../include/openssl/pkcs7.h | ||
| 123 | p12_asn.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h | ||
| 124 | p12_asn.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h | ||
| 125 | p12_asn.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h | ||
| 126 | p12_asn.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
| 127 | p12_asn.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h | ||
| 128 | p12_asn.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h | ||
| 129 | p12_asn.o: ../../include/openssl/x509_vfy.h ../cryptlib.h p12_asn.c | ||
| 130 | p12_attr.o: ../../e_os.h ../../include/openssl/aes.h | ||
| 131 | p12_attr.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
| 132 | p12_attr.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h | ||
| 133 | p12_attr.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h | ||
| 134 | p12_attr.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
| 135 | p12_attr.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h | ||
| 136 | p12_attr.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h | ||
| 137 | p12_attr.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
| 138 | p12_attr.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h | ||
| 139 | p12_attr.o: ../../include/openssl/md2.h ../../include/openssl/md4.h | ||
| 140 | p12_attr.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h | ||
| 141 | p12_attr.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
| 142 | p12_attr.o: ../../include/openssl/opensslconf.h | ||
| 143 | p12_attr.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 144 | p12_attr.o: ../../include/openssl/pkcs12.h ../../include/openssl/pkcs7.h | ||
| 145 | p12_attr.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h | ||
| 146 | p12_attr.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h | ||
| 147 | p12_attr.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h | ||
| 148 | p12_attr.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
| 149 | p12_attr.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h | ||
| 150 | p12_attr.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h | ||
| 151 | p12_attr.o: ../../include/openssl/x509_vfy.h ../cryptlib.h p12_attr.c | ||
| 152 | p12_crpt.o: ../../e_os.h ../../include/openssl/aes.h | ||
| 153 | p12_crpt.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
| 154 | p12_crpt.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h | ||
| 155 | p12_crpt.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h | ||
| 156 | p12_crpt.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
| 157 | p12_crpt.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h | ||
| 158 | p12_crpt.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h | ||
| 159 | p12_crpt.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
| 160 | p12_crpt.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h | ||
| 161 | p12_crpt.o: ../../include/openssl/md2.h ../../include/openssl/md4.h | ||
| 162 | p12_crpt.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h | ||
| 163 | p12_crpt.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
| 164 | p12_crpt.o: ../../include/openssl/opensslconf.h | ||
| 165 | p12_crpt.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 166 | p12_crpt.o: ../../include/openssl/pkcs12.h ../../include/openssl/pkcs7.h | ||
| 167 | p12_crpt.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h | ||
| 168 | p12_crpt.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h | ||
| 169 | p12_crpt.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h | ||
| 170 | p12_crpt.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
| 171 | p12_crpt.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h | ||
| 172 | p12_crpt.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h | ||
| 173 | p12_crpt.o: ../../include/openssl/x509_vfy.h ../cryptlib.h p12_crpt.c | ||
| 174 | p12_crt.o: ../../e_os.h ../../include/openssl/aes.h | ||
| 175 | p12_crt.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
| 176 | p12_crt.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h | ||
| 177 | p12_crt.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h | ||
| 178 | p12_crt.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
| 179 | p12_crt.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h | ||
| 180 | p12_crt.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h | ||
| 181 | p12_crt.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
| 182 | p12_crt.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h | ||
| 183 | p12_crt.o: ../../include/openssl/md2.h ../../include/openssl/md4.h | ||
| 184 | p12_crt.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h | ||
| 185 | p12_crt.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
| 186 | p12_crt.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
| 187 | p12_crt.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs12.h | ||
| 188 | p12_crt.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h | ||
| 189 | p12_crt.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h | ||
| 190 | p12_crt.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h | ||
| 191 | p12_crt.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
| 192 | p12_crt.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 193 | p12_crt.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h | ||
| 194 | p12_crt.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h | ||
| 195 | p12_crt.o: ../cryptlib.h p12_crt.c | ||
| 196 | p12_decr.o: ../../e_os.h ../../include/openssl/aes.h | ||
| 197 | p12_decr.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
| 198 | p12_decr.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h | ||
| 199 | p12_decr.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h | ||
| 200 | p12_decr.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
| 201 | p12_decr.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h | ||
| 202 | p12_decr.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h | ||
| 203 | p12_decr.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
| 204 | p12_decr.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h | ||
| 205 | p12_decr.o: ../../include/openssl/md2.h ../../include/openssl/md4.h | ||
| 206 | p12_decr.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h | ||
| 207 | p12_decr.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
| 208 | p12_decr.o: ../../include/openssl/opensslconf.h | ||
| 209 | p12_decr.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 210 | p12_decr.o: ../../include/openssl/pkcs12.h ../../include/openssl/pkcs7.h | ||
| 211 | p12_decr.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h | ||
| 212 | p12_decr.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h | ||
| 213 | p12_decr.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h | ||
| 214 | p12_decr.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
| 215 | p12_decr.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h | ||
| 216 | p12_decr.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h | ||
| 217 | p12_decr.o: ../../include/openssl/x509_vfy.h ../cryptlib.h p12_decr.c | ||
| 218 | p12_init.o: ../../e_os.h ../../include/openssl/aes.h | ||
| 219 | p12_init.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
| 220 | p12_init.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h | ||
| 221 | p12_init.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h | ||
| 222 | p12_init.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
| 223 | p12_init.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h | ||
| 224 | p12_init.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h | ||
| 225 | p12_init.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
| 226 | p12_init.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h | ||
| 227 | p12_init.o: ../../include/openssl/md2.h ../../include/openssl/md4.h | ||
| 228 | p12_init.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h | ||
| 229 | p12_init.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
| 230 | p12_init.o: ../../include/openssl/opensslconf.h | ||
| 231 | p12_init.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 232 | p12_init.o: ../../include/openssl/pkcs12.h ../../include/openssl/pkcs7.h | ||
| 233 | p12_init.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h | ||
| 234 | p12_init.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h | ||
| 235 | p12_init.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h | ||
| 236 | p12_init.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
| 237 | p12_init.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h | ||
| 238 | p12_init.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h | ||
| 239 | p12_init.o: ../../include/openssl/x509_vfy.h ../cryptlib.h p12_init.c | ||
| 240 | p12_key.o: ../../e_os.h ../../include/openssl/aes.h | ||
| 241 | p12_key.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
| 242 | p12_key.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h | ||
| 243 | p12_key.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h | ||
| 244 | p12_key.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
| 245 | p12_key.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h | ||
| 246 | p12_key.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h | ||
| 247 | p12_key.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
| 248 | p12_key.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h | ||
| 249 | p12_key.o: ../../include/openssl/md2.h ../../include/openssl/md4.h | ||
| 250 | p12_key.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h | ||
| 251 | p12_key.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
| 252 | p12_key.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
| 253 | p12_key.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs12.h | ||
| 254 | p12_key.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h | ||
| 255 | p12_key.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h | ||
| 256 | p12_key.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h | ||
| 257 | p12_key.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
| 258 | p12_key.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 259 | p12_key.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h | ||
| 260 | p12_key.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h | ||
| 261 | p12_key.o: ../cryptlib.h p12_key.c | ||
| 262 | p12_kiss.o: ../../e_os.h ../../include/openssl/aes.h | ||
| 263 | p12_kiss.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
| 264 | p12_kiss.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h | ||
| 265 | p12_kiss.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h | ||
| 266 | p12_kiss.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
| 267 | p12_kiss.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h | ||
| 268 | p12_kiss.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h | ||
| 269 | p12_kiss.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
| 270 | p12_kiss.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h | ||
| 271 | p12_kiss.o: ../../include/openssl/md2.h ../../include/openssl/md4.h | ||
| 272 | p12_kiss.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h | ||
| 273 | p12_kiss.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
| 274 | p12_kiss.o: ../../include/openssl/opensslconf.h | ||
| 275 | p12_kiss.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 276 | p12_kiss.o: ../../include/openssl/pkcs12.h ../../include/openssl/pkcs7.h | ||
| 277 | p12_kiss.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h | ||
| 278 | p12_kiss.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h | ||
| 279 | p12_kiss.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h | ||
| 280 | p12_kiss.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
| 281 | p12_kiss.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h | ||
| 282 | p12_kiss.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h | ||
| 283 | p12_kiss.o: ../../include/openssl/x509_vfy.h ../cryptlib.h p12_kiss.c | ||
| 284 | p12_mutl.o: ../../e_os.h ../../include/openssl/aes.h | ||
| 285 | p12_mutl.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
| 286 | p12_mutl.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h | ||
| 287 | p12_mutl.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h | ||
| 288 | p12_mutl.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
| 289 | p12_mutl.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h | ||
| 290 | p12_mutl.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h | ||
| 291 | p12_mutl.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
| 292 | p12_mutl.o: ../../include/openssl/hmac.h ../../include/openssl/idea.h | ||
| 293 | p12_mutl.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h | ||
| 294 | p12_mutl.o: ../../include/openssl/md4.h ../../include/openssl/md5.h | ||
| 295 | p12_mutl.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h | ||
| 296 | p12_mutl.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | ||
| 297 | p12_mutl.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 298 | p12_mutl.o: ../../include/openssl/pkcs12.h ../../include/openssl/pkcs7.h | ||
| 299 | p12_mutl.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h | ||
| 300 | p12_mutl.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h | ||
| 301 | p12_mutl.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h | ||
| 302 | p12_mutl.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
| 303 | p12_mutl.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 304 | p12_mutl.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h | ||
| 305 | p12_mutl.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h | ||
| 306 | p12_mutl.o: ../cryptlib.h p12_mutl.c | ||
| 307 | p12_npas.o: ../../include/openssl/aes.h ../../include/openssl/asn1.h | ||
| 308 | p12_npas.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h | ||
| 309 | p12_npas.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h | ||
| 310 | p12_npas.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h | ||
| 311 | p12_npas.o: ../../include/openssl/des.h ../../include/openssl/des_old.h | ||
| 312 | p12_npas.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h | ||
| 313 | p12_npas.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
| 314 | p12_npas.o: ../../include/openssl/evp.h ../../include/openssl/idea.h | ||
| 315 | p12_npas.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h | ||
| 316 | p12_npas.o: ../../include/openssl/md4.h ../../include/openssl/md5.h | ||
| 317 | p12_npas.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h | ||
| 318 | p12_npas.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | ||
| 319 | p12_npas.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 320 | p12_npas.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h | ||
| 321 | p12_npas.o: ../../include/openssl/pkcs12.h ../../include/openssl/pkcs7.h | ||
| 322 | p12_npas.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h | ||
| 323 | p12_npas.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h | ||
| 324 | p12_npas.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h | ||
| 325 | p12_npas.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
| 326 | p12_npas.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h | ||
| 327 | p12_npas.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h | ||
| 328 | p12_npas.o: ../../include/openssl/x509_vfy.h p12_npas.c | ||
| 329 | p12_p8d.o: ../../e_os.h ../../include/openssl/aes.h | ||
| 330 | p12_p8d.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
| 331 | p12_p8d.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h | ||
| 332 | p12_p8d.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h | ||
| 333 | p12_p8d.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
| 334 | p12_p8d.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h | ||
| 335 | p12_p8d.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h | ||
| 336 | p12_p8d.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
| 337 | p12_p8d.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h | ||
| 338 | p12_p8d.o: ../../include/openssl/md2.h ../../include/openssl/md4.h | ||
| 339 | p12_p8d.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h | ||
| 340 | p12_p8d.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
| 341 | p12_p8d.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
| 342 | p12_p8d.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs12.h | ||
| 343 | p12_p8d.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h | ||
| 344 | p12_p8d.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h | ||
| 345 | p12_p8d.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h | ||
| 346 | p12_p8d.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
| 347 | p12_p8d.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 348 | p12_p8d.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h | ||
| 349 | p12_p8d.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h | ||
| 350 | p12_p8d.o: ../cryptlib.h p12_p8d.c | ||
| 351 | p12_p8e.o: ../../e_os.h ../../include/openssl/aes.h | ||
| 352 | p12_p8e.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
| 353 | p12_p8e.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h | ||
| 354 | p12_p8e.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h | ||
| 355 | p12_p8e.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
| 356 | p12_p8e.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h | ||
| 357 | p12_p8e.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h | ||
| 358 | p12_p8e.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
| 359 | p12_p8e.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h | ||
| 360 | p12_p8e.o: ../../include/openssl/md2.h ../../include/openssl/md4.h | ||
| 361 | p12_p8e.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h | ||
| 362 | p12_p8e.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
| 363 | p12_p8e.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
| 364 | p12_p8e.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs12.h | ||
| 365 | p12_p8e.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h | ||
| 366 | p12_p8e.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h | ||
| 367 | p12_p8e.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h | ||
| 368 | p12_p8e.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
| 369 | p12_p8e.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 370 | p12_p8e.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h | ||
| 371 | p12_p8e.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h | ||
| 372 | p12_p8e.o: ../cryptlib.h p12_p8e.c | ||
| 373 | p12_utl.o: ../../e_os.h ../../include/openssl/aes.h | ||
| 374 | p12_utl.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
| 375 | p12_utl.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h | ||
| 376 | p12_utl.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h | ||
| 377 | p12_utl.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
| 378 | p12_utl.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h | ||
| 379 | p12_utl.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h | ||
| 380 | p12_utl.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
| 381 | p12_utl.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h | ||
| 382 | p12_utl.o: ../../include/openssl/md2.h ../../include/openssl/md4.h | ||
| 383 | p12_utl.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h | ||
| 384 | p12_utl.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
| 385 | p12_utl.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
| 386 | p12_utl.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs12.h | ||
| 387 | p12_utl.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h | ||
| 388 | p12_utl.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h | ||
| 389 | p12_utl.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h | ||
| 390 | p12_utl.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
| 391 | p12_utl.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 392 | p12_utl.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h | ||
| 393 | p12_utl.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h | ||
| 394 | p12_utl.o: ../cryptlib.h p12_utl.c | ||
| 395 | pk12err.o: ../../include/openssl/aes.h ../../include/openssl/asn1.h | ||
| 396 | pk12err.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h | ||
| 397 | pk12err.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h | ||
| 398 | pk12err.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h | ||
| 399 | pk12err.o: ../../include/openssl/des.h ../../include/openssl/des_old.h | ||
| 400 | pk12err.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h | ||
| 401 | pk12err.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
| 402 | pk12err.o: ../../include/openssl/evp.h ../../include/openssl/idea.h | ||
| 403 | pk12err.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h | ||
| 404 | pk12err.o: ../../include/openssl/md4.h ../../include/openssl/md5.h | ||
| 405 | pk12err.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h | ||
| 406 | pk12err.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | ||
| 407 | pk12err.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 408 | pk12err.o: ../../include/openssl/pkcs12.h ../../include/openssl/pkcs7.h | ||
| 409 | pk12err.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h | ||
| 410 | pk12err.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h | ||
| 411 | pk12err.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h | ||
| 412 | pk12err.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
| 413 | pk12err.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h | ||
| 414 | pk12err.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h | ||
| 415 | pk12err.o: ../../include/openssl/x509_vfy.h pk12err.c | ||
diff --git a/src/lib/libcrypto/pkcs12/p12_add.c b/src/lib/libcrypto/pkcs12/p12_add.c new file mode 100644 index 0000000000..27015dd8c3 --- /dev/null +++ b/src/lib/libcrypto/pkcs12/p12_add.c | |||
| @@ -0,0 +1,224 @@ | |||
| 1 | /* p12_add.c */ | ||
| 2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
| 3 | * project 1999. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/pkcs12.h> | ||
| 62 | |||
| 63 | /* Pack an object into an OCTET STRING and turn into a safebag */ | ||
| 64 | |||
| 65 | PKCS12_SAFEBAG *PKCS12_item_pack_safebag(void *obj, const ASN1_ITEM *it, int nid1, | ||
| 66 | int nid2) | ||
| 67 | { | ||
| 68 | PKCS12_BAGS *bag; | ||
| 69 | PKCS12_SAFEBAG *safebag; | ||
| 70 | if (!(bag = PKCS12_BAGS_new())) { | ||
| 71 | PKCS12err(PKCS12_F_PKCS12_PACK_SAFEBAG, ERR_R_MALLOC_FAILURE); | ||
| 72 | return NULL; | ||
| 73 | } | ||
| 74 | bag->type = OBJ_nid2obj(nid1); | ||
| 75 | if (!ASN1_item_pack(obj, it, &bag->value.octet)) { | ||
| 76 | PKCS12err(PKCS12_F_PKCS12_PACK_SAFEBAG, ERR_R_MALLOC_FAILURE); | ||
| 77 | return NULL; | ||
| 78 | } | ||
| 79 | if (!(safebag = PKCS12_SAFEBAG_new())) { | ||
| 80 | PKCS12err(PKCS12_F_PKCS12_PACK_SAFEBAG, ERR_R_MALLOC_FAILURE); | ||
| 81 | return NULL; | ||
| 82 | } | ||
| 83 | safebag->value.bag = bag; | ||
| 84 | safebag->type = OBJ_nid2obj(nid2); | ||
| 85 | return safebag; | ||
| 86 | } | ||
| 87 | |||
| 88 | /* Turn PKCS8 object into a keybag */ | ||
| 89 | |||
| 90 | PKCS12_SAFEBAG *PKCS12_MAKE_KEYBAG(PKCS8_PRIV_KEY_INFO *p8) | ||
| 91 | { | ||
| 92 | PKCS12_SAFEBAG *bag; | ||
| 93 | if (!(bag = PKCS12_SAFEBAG_new())) { | ||
| 94 | PKCS12err(PKCS12_F_PKCS12_MAKE_KEYBAG,ERR_R_MALLOC_FAILURE); | ||
| 95 | return NULL; | ||
| 96 | } | ||
| 97 | bag->type = OBJ_nid2obj(NID_keyBag); | ||
| 98 | bag->value.keybag = p8; | ||
| 99 | return bag; | ||
| 100 | } | ||
| 101 | |||
| 102 | /* Turn PKCS8 object into a shrouded keybag */ | ||
| 103 | |||
| 104 | PKCS12_SAFEBAG *PKCS12_MAKE_SHKEYBAG(int pbe_nid, const char *pass, | ||
| 105 | int passlen, unsigned char *salt, int saltlen, int iter, | ||
| 106 | PKCS8_PRIV_KEY_INFO *p8) | ||
| 107 | { | ||
| 108 | PKCS12_SAFEBAG *bag; | ||
| 109 | |||
| 110 | /* Set up the safe bag */ | ||
| 111 | if (!(bag = PKCS12_SAFEBAG_new())) { | ||
| 112 | PKCS12err(PKCS12_F_PKCS12_MAKE_SHKEYBAG, ERR_R_MALLOC_FAILURE); | ||
| 113 | return NULL; | ||
| 114 | } | ||
| 115 | |||
| 116 | bag->type = OBJ_nid2obj(NID_pkcs8ShroudedKeyBag); | ||
| 117 | if (!(bag->value.shkeybag = | ||
| 118 | PKCS8_encrypt(pbe_nid, NULL, pass, passlen, salt, saltlen, iter, | ||
| 119 | p8))) { | ||
| 120 | PKCS12err(PKCS12_F_PKCS12_MAKE_SHKEYBAG, ERR_R_MALLOC_FAILURE); | ||
| 121 | return NULL; | ||
| 122 | } | ||
| 123 | |||
| 124 | return bag; | ||
| 125 | } | ||
| 126 | |||
| 127 | /* Turn a stack of SAFEBAGS into a PKCS#7 data Contentinfo */ | ||
| 128 | PKCS7 *PKCS12_pack_p7data(STACK_OF(PKCS12_SAFEBAG) *sk) | ||
| 129 | { | ||
| 130 | PKCS7 *p7; | ||
| 131 | if (!(p7 = PKCS7_new())) { | ||
| 132 | PKCS12err(PKCS12_F_PKCS12_PACK_P7DATA, ERR_R_MALLOC_FAILURE); | ||
| 133 | return NULL; | ||
| 134 | } | ||
| 135 | p7->type = OBJ_nid2obj(NID_pkcs7_data); | ||
| 136 | if (!(p7->d.data = M_ASN1_OCTET_STRING_new())) { | ||
| 137 | PKCS12err(PKCS12_F_PKCS12_PACK_P7DATA, ERR_R_MALLOC_FAILURE); | ||
| 138 | return NULL; | ||
| 139 | } | ||
| 140 | |||
| 141 | if (!ASN1_item_pack(sk, ASN1_ITEM_rptr(PKCS12_SAFEBAGS), &p7->d.data)) { | ||
| 142 | PKCS12err(PKCS12_F_PKCS12_PACK_P7DATA, PKCS12_R_CANT_PACK_STRUCTURE); | ||
| 143 | return NULL; | ||
| 144 | } | ||
| 145 | return p7; | ||
| 146 | } | ||
| 147 | |||
| 148 | /* Unpack SAFEBAGS from PKCS#7 data ContentInfo */ | ||
| 149 | STACK_OF(PKCS12_SAFEBAG) *PKCS12_unpack_p7data(PKCS7 *p7) | ||
| 150 | { | ||
| 151 | if(!PKCS7_type_is_data(p7)) | ||
| 152 | { | ||
| 153 | PKCS12err(PKCS12_F_PKCS12_UNPACK_P7DATA,PKCS12_R_CONTENT_TYPE_NOT_DATA); | ||
| 154 | return NULL; | ||
| 155 | } | ||
| 156 | return ASN1_item_unpack(p7->d.data, ASN1_ITEM_rptr(PKCS12_SAFEBAGS)); | ||
| 157 | } | ||
| 158 | |||
| 159 | /* Turn a stack of SAFEBAGS into a PKCS#7 encrypted data ContentInfo */ | ||
| 160 | |||
| 161 | PKCS7 *PKCS12_pack_p7encdata(int pbe_nid, const char *pass, int passlen, | ||
| 162 | unsigned char *salt, int saltlen, int iter, | ||
| 163 | STACK_OF(PKCS12_SAFEBAG) *bags) | ||
| 164 | { | ||
| 165 | PKCS7 *p7; | ||
| 166 | X509_ALGOR *pbe; | ||
| 167 | if (!(p7 = PKCS7_new())) { | ||
| 168 | PKCS12err(PKCS12_F_PKCS12_PACK_P7ENCDATA, ERR_R_MALLOC_FAILURE); | ||
| 169 | return NULL; | ||
| 170 | } | ||
| 171 | if(!PKCS7_set_type(p7, NID_pkcs7_encrypted)) { | ||
| 172 | PKCS12err(PKCS12_F_PKCS12_PACK_P7ENCDATA, | ||
| 173 | PKCS12_R_ERROR_SETTING_ENCRYPTED_DATA_TYPE); | ||
| 174 | return NULL; | ||
| 175 | } | ||
| 176 | if (!(pbe = PKCS5_pbe_set(pbe_nid, iter, salt, saltlen))) { | ||
| 177 | PKCS12err(PKCS12_F_PKCS12_PACK_P7ENCDATA, ERR_R_MALLOC_FAILURE); | ||
| 178 | return NULL; | ||
| 179 | } | ||
| 180 | X509_ALGOR_free(p7->d.encrypted->enc_data->algorithm); | ||
| 181 | p7->d.encrypted->enc_data->algorithm = pbe; | ||
| 182 | M_ASN1_OCTET_STRING_free(p7->d.encrypted->enc_data->enc_data); | ||
| 183 | if (!(p7->d.encrypted->enc_data->enc_data = | ||
| 184 | PKCS12_item_i2d_encrypt(pbe, ASN1_ITEM_rptr(PKCS12_SAFEBAGS), pass, passlen, | ||
| 185 | bags, 1))) { | ||
| 186 | PKCS12err(PKCS12_F_PKCS12_PACK_P7ENCDATA, PKCS12_R_ENCRYPT_ERROR); | ||
| 187 | return NULL; | ||
| 188 | } | ||
| 189 | |||
| 190 | return p7; | ||
| 191 | } | ||
| 192 | |||
| 193 | STACK_OF(PKCS12_SAFEBAG) *PKCS12_unpack_p7encdata(PKCS7 *p7, const char *pass, int passlen) | ||
| 194 | { | ||
| 195 | if(!PKCS7_type_is_encrypted(p7)) return NULL; | ||
| 196 | return PKCS12_item_decrypt_d2i(p7->d.encrypted->enc_data->algorithm, | ||
| 197 | ASN1_ITEM_rptr(PKCS12_SAFEBAGS), | ||
| 198 | pass, passlen, | ||
| 199 | p7->d.encrypted->enc_data->enc_data, 1); | ||
| 200 | } | ||
| 201 | |||
| 202 | PKCS8_PRIV_KEY_INFO *PKCS12_decrypt_skey(PKCS12_SAFEBAG *bag, const char *pass, | ||
| 203 | int passlen) | ||
| 204 | { | ||
| 205 | return PKCS8_decrypt(bag->value.shkeybag, pass, passlen); | ||
| 206 | } | ||
| 207 | |||
| 208 | int PKCS12_pack_authsafes(PKCS12 *p12, STACK_OF(PKCS7) *safes) | ||
| 209 | { | ||
| 210 | if(ASN1_item_pack(safes, ASN1_ITEM_rptr(PKCS12_AUTHSAFES), | ||
| 211 | &p12->authsafes->d.data)) | ||
| 212 | return 1; | ||
| 213 | return 0; | ||
| 214 | } | ||
| 215 | |||
| 216 | STACK_OF(PKCS7) *PKCS12_unpack_authsafes(PKCS12 *p12) | ||
| 217 | { | ||
| 218 | if (!PKCS7_type_is_data(p12->authsafes)) | ||
| 219 | { | ||
| 220 | PKCS12err(PKCS12_F_PKCS12_UNPACK_AUTHSAFES,PKCS12_R_CONTENT_TYPE_NOT_DATA); | ||
| 221 | return NULL; | ||
| 222 | } | ||
| 223 | return ASN1_item_unpack(p12->authsafes->d.data, ASN1_ITEM_rptr(PKCS12_AUTHSAFES)); | ||
| 224 | } | ||
diff --git a/src/lib/libcrypto/pkcs12/p12_asn.c b/src/lib/libcrypto/pkcs12/p12_asn.c new file mode 100644 index 0000000000..a3739fee1a --- /dev/null +++ b/src/lib/libcrypto/pkcs12/p12_asn.c | |||
| @@ -0,0 +1,125 @@ | |||
| 1 | /* p12_asn.c */ | ||
| 2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
| 3 | * project 1999. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/asn1t.h> | ||
| 62 | #include <openssl/pkcs12.h> | ||
| 63 | |||
| 64 | /* PKCS#12 ASN1 module */ | ||
| 65 | |||
| 66 | ASN1_SEQUENCE(PKCS12) = { | ||
| 67 | ASN1_SIMPLE(PKCS12, version, ASN1_INTEGER), | ||
| 68 | ASN1_SIMPLE(PKCS12, authsafes, PKCS7), | ||
| 69 | ASN1_OPT(PKCS12, mac, PKCS12_MAC_DATA) | ||
| 70 | } ASN1_SEQUENCE_END(PKCS12) | ||
| 71 | |||
| 72 | IMPLEMENT_ASN1_FUNCTIONS(PKCS12) | ||
| 73 | |||
| 74 | ASN1_SEQUENCE(PKCS12_MAC_DATA) = { | ||
| 75 | ASN1_SIMPLE(PKCS12_MAC_DATA, dinfo, X509_SIG), | ||
| 76 | ASN1_SIMPLE(PKCS12_MAC_DATA, salt, ASN1_OCTET_STRING), | ||
| 77 | ASN1_OPT(PKCS12_MAC_DATA, iter, ASN1_INTEGER) | ||
| 78 | } ASN1_SEQUENCE_END(PKCS12_MAC_DATA) | ||
| 79 | |||
| 80 | IMPLEMENT_ASN1_FUNCTIONS(PKCS12_MAC_DATA) | ||
| 81 | |||
| 82 | ASN1_ADB_TEMPLATE(bag_default) = ASN1_EXP(PKCS12_BAGS, value.other, ASN1_ANY, 0); | ||
| 83 | |||
| 84 | ASN1_ADB(PKCS12_BAGS) = { | ||
| 85 | ADB_ENTRY(NID_x509Certificate, ASN1_EXP(PKCS12_BAGS, value.x509cert, ASN1_OCTET_STRING, 0)), | ||
| 86 | ADB_ENTRY(NID_x509Crl, ASN1_EXP(PKCS12_BAGS, value.x509crl, ASN1_OCTET_STRING, 0)), | ||
| 87 | ADB_ENTRY(NID_sdsiCertificate, ASN1_EXP(PKCS12_BAGS, value.sdsicert, ASN1_IA5STRING, 0)), | ||
| 88 | } ASN1_ADB_END(PKCS12_BAGS, 0, type, 0, &bag_default_tt, NULL); | ||
| 89 | |||
| 90 | ASN1_SEQUENCE(PKCS12_BAGS) = { | ||
| 91 | ASN1_SIMPLE(PKCS12_BAGS, type, ASN1_OBJECT), | ||
| 92 | ASN1_ADB_OBJECT(PKCS12_BAGS), | ||
| 93 | } ASN1_SEQUENCE_END(PKCS12_BAGS) | ||
| 94 | |||
| 95 | IMPLEMENT_ASN1_FUNCTIONS(PKCS12_BAGS) | ||
| 96 | |||
| 97 | ASN1_ADB_TEMPLATE(safebag_default) = ASN1_EXP(PKCS12_SAFEBAG, value.other, ASN1_ANY, 0); | ||
| 98 | |||
| 99 | ASN1_ADB(PKCS12_SAFEBAG) = { | ||
| 100 | ADB_ENTRY(NID_keyBag, ASN1_EXP(PKCS12_SAFEBAG, value.keybag, PKCS8_PRIV_KEY_INFO, 0)), | ||
| 101 | ADB_ENTRY(NID_pkcs8ShroudedKeyBag, ASN1_EXP(PKCS12_SAFEBAG, value.shkeybag, X509_SIG, 0)), | ||
| 102 | ADB_ENTRY(NID_safeContentsBag, ASN1_EXP_SET_OF(PKCS12_SAFEBAG, value.safes, PKCS12_SAFEBAG, 0)), | ||
| 103 | ADB_ENTRY(NID_certBag, ASN1_EXP(PKCS12_SAFEBAG, value.bag, PKCS12_BAGS, 0)), | ||
| 104 | ADB_ENTRY(NID_crlBag, ASN1_EXP(PKCS12_SAFEBAG, value.bag, PKCS12_BAGS, 0)), | ||
| 105 | ADB_ENTRY(NID_secretBag, ASN1_EXP(PKCS12_SAFEBAG, value.bag, PKCS12_BAGS, 0)) | ||
| 106 | } ASN1_ADB_END(PKCS12_SAFEBAG, 0, type, 0, &safebag_default_tt, NULL); | ||
| 107 | |||
| 108 | ASN1_SEQUENCE(PKCS12_SAFEBAG) = { | ||
| 109 | ASN1_SIMPLE(PKCS12_SAFEBAG, type, ASN1_OBJECT), | ||
| 110 | ASN1_ADB_OBJECT(PKCS12_SAFEBAG), | ||
| 111 | ASN1_SET_OF_OPT(PKCS12_SAFEBAG, attrib, X509_ATTRIBUTE) | ||
| 112 | } ASN1_SEQUENCE_END(PKCS12_SAFEBAG) | ||
| 113 | |||
| 114 | IMPLEMENT_ASN1_FUNCTIONS(PKCS12_SAFEBAG) | ||
| 115 | |||
| 116 | /* SEQUENCE OF SafeBag */ | ||
| 117 | ASN1_ITEM_TEMPLATE(PKCS12_SAFEBAGS) = | ||
| 118 | ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, PKCS12_SAFEBAGS, PKCS12_SAFEBAG) | ||
| 119 | ASN1_ITEM_TEMPLATE_END(PKCS12_SAFEBAGS) | ||
| 120 | |||
| 121 | /* Authsafes: SEQUENCE OF PKCS7 */ | ||
| 122 | ASN1_ITEM_TEMPLATE(PKCS12_AUTHSAFES) = | ||
| 123 | ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, PKCS12_AUTHSAFES, PKCS7) | ||
| 124 | ASN1_ITEM_TEMPLATE_END(PKCS12_AUTHSAFES) | ||
| 125 | |||
diff --git a/src/lib/libcrypto/pkcs12/p12_attr.c b/src/lib/libcrypto/pkcs12/p12_attr.c new file mode 100644 index 0000000000..026cf3826a --- /dev/null +++ b/src/lib/libcrypto/pkcs12/p12_attr.c | |||
| @@ -0,0 +1,145 @@ | |||
| 1 | /* p12_attr.c */ | ||
| 2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
| 3 | * project 1999. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/pkcs12.h> | ||
| 62 | |||
| 63 | /* Add a local keyid to a safebag */ | ||
| 64 | |||
| 65 | int PKCS12_add_localkeyid(PKCS12_SAFEBAG *bag, unsigned char *name, | ||
| 66 | int namelen) | ||
| 67 | { | ||
| 68 | if (X509at_add1_attr_by_NID(&bag->attrib, NID_localKeyID, | ||
| 69 | V_ASN1_OCTET_STRING, name, namelen)) | ||
| 70 | return 1; | ||
| 71 | else | ||
| 72 | return 0; | ||
| 73 | } | ||
| 74 | |||
| 75 | /* Add key usage to PKCS#8 structure */ | ||
| 76 | |||
| 77 | int PKCS8_add_keyusage(PKCS8_PRIV_KEY_INFO *p8, int usage) | ||
| 78 | { | ||
| 79 | unsigned char us_val; | ||
| 80 | us_val = (unsigned char) usage; | ||
| 81 | if (X509at_add1_attr_by_NID(&p8->attributes, NID_key_usage, | ||
| 82 | V_ASN1_BIT_STRING, &us_val, 1)) | ||
| 83 | return 1; | ||
| 84 | else | ||
| 85 | return 0; | ||
| 86 | } | ||
| 87 | |||
| 88 | /* Add a friendlyname to a safebag */ | ||
| 89 | |||
| 90 | int PKCS12_add_friendlyname_asc(PKCS12_SAFEBAG *bag, const char *name, | ||
| 91 | int namelen) | ||
| 92 | { | ||
| 93 | if (X509at_add1_attr_by_NID(&bag->attrib, NID_friendlyName, | ||
| 94 | MBSTRING_ASC, (unsigned char *)name, namelen)) | ||
| 95 | return 1; | ||
| 96 | else | ||
| 97 | return 0; | ||
| 98 | } | ||
| 99 | |||
| 100 | |||
| 101 | int PKCS12_add_friendlyname_uni(PKCS12_SAFEBAG *bag, | ||
| 102 | const unsigned char *name, int namelen) | ||
| 103 | { | ||
| 104 | if (X509at_add1_attr_by_NID(&bag->attrib, NID_friendlyName, | ||
| 105 | MBSTRING_BMP, name, namelen)) | ||
| 106 | return 1; | ||
| 107 | else | ||
| 108 | return 0; | ||
| 109 | } | ||
| 110 | |||
| 111 | int PKCS12_add_CSPName_asc(PKCS12_SAFEBAG *bag, const char *name, | ||
| 112 | int namelen) | ||
| 113 | { | ||
| 114 | if (X509at_add1_attr_by_NID(&bag->attrib, NID_ms_csp_name, | ||
| 115 | MBSTRING_ASC, (unsigned char *)name, namelen)) | ||
| 116 | return 1; | ||
| 117 | else | ||
| 118 | return 0; | ||
| 119 | } | ||
| 120 | |||
| 121 | ASN1_TYPE *PKCS12_get_attr_gen(STACK_OF(X509_ATTRIBUTE) *attrs, int attr_nid) | ||
| 122 | { | ||
| 123 | X509_ATTRIBUTE *attrib; | ||
| 124 | int i; | ||
| 125 | if (!attrs) return NULL; | ||
| 126 | for (i = 0; i < sk_X509_ATTRIBUTE_num (attrs); i++) { | ||
| 127 | attrib = sk_X509_ATTRIBUTE_value (attrs, i); | ||
| 128 | if (OBJ_obj2nid (attrib->object) == attr_nid) { | ||
| 129 | if (sk_ASN1_TYPE_num (attrib->value.set)) | ||
| 130 | return sk_ASN1_TYPE_value(attrib->value.set, 0); | ||
| 131 | else return NULL; | ||
| 132 | } | ||
| 133 | } | ||
| 134 | return NULL; | ||
| 135 | } | ||
| 136 | |||
| 137 | char *PKCS12_get_friendlyname(PKCS12_SAFEBAG *bag) | ||
| 138 | { | ||
| 139 | ASN1_TYPE *atype; | ||
| 140 | if (!(atype = PKCS12_get_attr(bag, NID_friendlyName))) return NULL; | ||
| 141 | if (atype->type != V_ASN1_BMPSTRING) return NULL; | ||
| 142 | return uni2asc(atype->value.bmpstring->data, | ||
| 143 | atype->value.bmpstring->length); | ||
| 144 | } | ||
| 145 | |||
diff --git a/src/lib/libcrypto/pkcs12/p12_crpt.c b/src/lib/libcrypto/pkcs12/p12_crpt.c new file mode 100644 index 0000000000..003ec7a33e --- /dev/null +++ b/src/lib/libcrypto/pkcs12/p12_crpt.c | |||
| @@ -0,0 +1,124 @@ | |||
| 1 | /* p12_crpt.c */ | ||
| 2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
| 3 | * project 1999. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/pkcs12.h> | ||
| 62 | |||
| 63 | /* PKCS#12 specific PBE functions */ | ||
| 64 | |||
| 65 | void PKCS12_PBE_add(void) | ||
| 66 | { | ||
| 67 | #ifndef OPENSSL_NO_RC4 | ||
| 68 | EVP_PBE_alg_add(NID_pbe_WithSHA1And128BitRC4, EVP_rc4(), EVP_sha1(), | ||
| 69 | PKCS12_PBE_keyivgen); | ||
| 70 | EVP_PBE_alg_add(NID_pbe_WithSHA1And40BitRC4, EVP_rc4_40(), EVP_sha1(), | ||
| 71 | PKCS12_PBE_keyivgen); | ||
| 72 | #endif | ||
| 73 | #ifndef OPENSSL_NO_DES | ||
| 74 | EVP_PBE_alg_add(NID_pbe_WithSHA1And3_Key_TripleDES_CBC, | ||
| 75 | EVP_des_ede3_cbc(), EVP_sha1(), PKCS12_PBE_keyivgen); | ||
| 76 | EVP_PBE_alg_add(NID_pbe_WithSHA1And2_Key_TripleDES_CBC, | ||
| 77 | EVP_des_ede_cbc(), EVP_sha1(), PKCS12_PBE_keyivgen); | ||
| 78 | #endif | ||
| 79 | #ifndef OPENSSL_NO_RC2 | ||
| 80 | EVP_PBE_alg_add(NID_pbe_WithSHA1And128BitRC2_CBC, EVP_rc2_cbc(), | ||
| 81 | EVP_sha1(), PKCS12_PBE_keyivgen); | ||
| 82 | EVP_PBE_alg_add(NID_pbe_WithSHA1And40BitRC2_CBC, EVP_rc2_40_cbc(), | ||
| 83 | EVP_sha1(), PKCS12_PBE_keyivgen); | ||
| 84 | #endif | ||
| 85 | } | ||
| 86 | |||
| 87 | int PKCS12_PBE_keyivgen (EVP_CIPHER_CTX *ctx, const char *pass, int passlen, | ||
| 88 | ASN1_TYPE *param, const EVP_CIPHER *cipher, const EVP_MD *md, int en_de) | ||
| 89 | { | ||
| 90 | PBEPARAM *pbe; | ||
| 91 | int saltlen, iter, ret; | ||
| 92 | unsigned char *salt, *pbuf; | ||
| 93 | unsigned char key[EVP_MAX_KEY_LENGTH], iv[EVP_MAX_IV_LENGTH]; | ||
| 94 | |||
| 95 | /* Extract useful info from parameter */ | ||
| 96 | pbuf = param->value.sequence->data; | ||
| 97 | if (!param || (param->type != V_ASN1_SEQUENCE) || | ||
| 98 | !(pbe = d2i_PBEPARAM (NULL, &pbuf, param->value.sequence->length))) { | ||
| 99 | EVPerr(PKCS12_F_PKCS12_PBE_KEYIVGEN,EVP_R_DECODE_ERROR); | ||
| 100 | return 0; | ||
| 101 | } | ||
| 102 | |||
| 103 | if (!pbe->iter) iter = 1; | ||
| 104 | else iter = ASN1_INTEGER_get (pbe->iter); | ||
| 105 | salt = pbe->salt->data; | ||
| 106 | saltlen = pbe->salt->length; | ||
| 107 | if (!PKCS12_key_gen (pass, passlen, salt, saltlen, PKCS12_KEY_ID, | ||
| 108 | iter, EVP_CIPHER_key_length(cipher), key, md)) { | ||
| 109 | PKCS12err(PKCS12_F_PKCS12_PBE_KEYIVGEN,PKCS12_R_KEY_GEN_ERROR); | ||
| 110 | PBEPARAM_free(pbe); | ||
| 111 | return 0; | ||
| 112 | } | ||
| 113 | if (!PKCS12_key_gen (pass, passlen, salt, saltlen, PKCS12_IV_ID, | ||
| 114 | iter, EVP_CIPHER_iv_length(cipher), iv, md)) { | ||
| 115 | PKCS12err(PKCS12_F_PKCS12_PBE_KEYIVGEN,PKCS12_R_IV_GEN_ERROR); | ||
| 116 | PBEPARAM_free(pbe); | ||
| 117 | return 0; | ||
| 118 | } | ||
| 119 | PBEPARAM_free(pbe); | ||
| 120 | ret = EVP_CipherInit_ex(ctx, cipher, NULL, key, iv, en_de); | ||
| 121 | OPENSSL_cleanse(key, EVP_MAX_KEY_LENGTH); | ||
| 122 | OPENSSL_cleanse(iv, EVP_MAX_IV_LENGTH); | ||
| 123 | return ret; | ||
| 124 | } | ||
diff --git a/src/lib/libcrypto/pkcs12/p12_crt.c b/src/lib/libcrypto/pkcs12/p12_crt.c new file mode 100644 index 0000000000..40340a7bef --- /dev/null +++ b/src/lib/libcrypto/pkcs12/p12_crt.c | |||
| @@ -0,0 +1,172 @@ | |||
| 1 | /* p12_crt.c */ | ||
| 2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
| 3 | * project 1999. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/pkcs12.h> | ||
| 62 | |||
| 63 | PKCS12 *PKCS12_create(char *pass, char *name, EVP_PKEY *pkey, X509 *cert, | ||
| 64 | STACK_OF(X509) *ca, int nid_key, int nid_cert, int iter, int mac_iter, | ||
| 65 | int keytype) | ||
| 66 | { | ||
| 67 | PKCS12 *p12; | ||
| 68 | STACK_OF(PKCS12_SAFEBAG) *bags; | ||
| 69 | STACK_OF(PKCS7) *safes; | ||
| 70 | PKCS12_SAFEBAG *bag; | ||
| 71 | PKCS8_PRIV_KEY_INFO *p8; | ||
| 72 | PKCS7 *authsafe; | ||
| 73 | X509 *tcert; | ||
| 74 | int i; | ||
| 75 | unsigned char keyid[EVP_MAX_MD_SIZE]; | ||
| 76 | unsigned int keyidlen; | ||
| 77 | |||
| 78 | /* Set defaults */ | ||
| 79 | if(!nid_cert) | ||
| 80 | { | ||
| 81 | #ifdef OPENSSL_FIPS | ||
| 82 | if (FIPS_mode()) | ||
| 83 | nid_cert = NID_pbe_WithSHA1And3_Key_TripleDES_CBC; | ||
| 84 | else | ||
| 85 | #endif | ||
| 86 | nid_cert = NID_pbe_WithSHA1And40BitRC2_CBC; | ||
| 87 | } | ||
| 88 | if(!nid_key) nid_key = NID_pbe_WithSHA1And3_Key_TripleDES_CBC; | ||
| 89 | if(!iter) iter = PKCS12_DEFAULT_ITER; | ||
| 90 | if(!mac_iter) mac_iter = 1; | ||
| 91 | |||
| 92 | if(!pkey || !cert) { | ||
| 93 | PKCS12err(PKCS12_F_PKCS12_CREATE,PKCS12_R_INVALID_NULL_ARGUMENT); | ||
| 94 | return NULL; | ||
| 95 | } | ||
| 96 | |||
| 97 | if(!X509_check_private_key(cert, pkey)) return NULL; | ||
| 98 | |||
| 99 | if(!(bags = sk_PKCS12_SAFEBAG_new_null ())) { | ||
| 100 | PKCS12err(PKCS12_F_PKCS12_CREATE,ERR_R_MALLOC_FAILURE); | ||
| 101 | return NULL; | ||
| 102 | } | ||
| 103 | |||
| 104 | /* Add user certificate */ | ||
| 105 | if(!(bag = PKCS12_x5092certbag(cert))) return NULL; | ||
| 106 | if(name && !PKCS12_add_friendlyname(bag, name, -1)) return NULL; | ||
| 107 | X509_digest(cert, EVP_sha1(), keyid, &keyidlen); | ||
| 108 | if(!PKCS12_add_localkeyid(bag, keyid, keyidlen)) return NULL; | ||
| 109 | |||
| 110 | if(!sk_PKCS12_SAFEBAG_push(bags, bag)) { | ||
| 111 | PKCS12err(PKCS12_F_PKCS12_CREATE,ERR_R_MALLOC_FAILURE); | ||
| 112 | return NULL; | ||
| 113 | } | ||
| 114 | |||
| 115 | /* Add all other certificates */ | ||
| 116 | if(ca) { | ||
| 117 | for(i = 0; i < sk_X509_num(ca); i++) { | ||
| 118 | tcert = sk_X509_value(ca, i); | ||
| 119 | if(!(bag = PKCS12_x5092certbag(tcert))) return NULL; | ||
| 120 | if(!sk_PKCS12_SAFEBAG_push(bags, bag)) { | ||
| 121 | PKCS12err(PKCS12_F_PKCS12_CREATE,ERR_R_MALLOC_FAILURE); | ||
| 122 | return NULL; | ||
| 123 | } | ||
| 124 | } | ||
| 125 | } | ||
| 126 | |||
| 127 | /* Turn certbags into encrypted authsafe */ | ||
| 128 | authsafe = PKCS12_pack_p7encdata (nid_cert, pass, -1, NULL, 0, | ||
| 129 | iter, bags); | ||
| 130 | sk_PKCS12_SAFEBAG_pop_free(bags, PKCS12_SAFEBAG_free); | ||
| 131 | |||
| 132 | if (!authsafe) return NULL; | ||
| 133 | |||
| 134 | if(!(safes = sk_PKCS7_new_null ()) | ||
| 135 | || !sk_PKCS7_push(safes, authsafe)) { | ||
| 136 | PKCS12err(PKCS12_F_PKCS12_CREATE,ERR_R_MALLOC_FAILURE); | ||
| 137 | return NULL; | ||
| 138 | } | ||
| 139 | |||
| 140 | /* Make a shrouded key bag */ | ||
| 141 | if(!(p8 = EVP_PKEY2PKCS8 (pkey))) return NULL; | ||
| 142 | if(keytype && !PKCS8_add_keyusage(p8, keytype)) return NULL; | ||
| 143 | bag = PKCS12_MAKE_SHKEYBAG (nid_key, pass, -1, NULL, 0, iter, p8); | ||
| 144 | if(!bag) return NULL; | ||
| 145 | PKCS8_PRIV_KEY_INFO_free(p8); | ||
| 146 | if (name && !PKCS12_add_friendlyname (bag, name, -1)) return NULL; | ||
| 147 | if(!PKCS12_add_localkeyid (bag, keyid, keyidlen)) return NULL; | ||
| 148 | if(!(bags = sk_PKCS12_SAFEBAG_new_null()) | ||
| 149 | || !sk_PKCS12_SAFEBAG_push (bags, bag)) { | ||
| 150 | PKCS12err(PKCS12_F_PKCS12_CREATE,ERR_R_MALLOC_FAILURE); | ||
| 151 | return NULL; | ||
| 152 | } | ||
| 153 | /* Turn it into unencrypted safe bag */ | ||
| 154 | if(!(authsafe = PKCS12_pack_p7data (bags))) return NULL; | ||
| 155 | sk_PKCS12_SAFEBAG_pop_free(bags, PKCS12_SAFEBAG_free); | ||
| 156 | if(!sk_PKCS7_push(safes, authsafe)) { | ||
| 157 | PKCS12err(PKCS12_F_PKCS12_CREATE,ERR_R_MALLOC_FAILURE); | ||
| 158 | return NULL; | ||
| 159 | } | ||
| 160 | |||
| 161 | if(!(p12 = PKCS12_init (NID_pkcs7_data))) return NULL; | ||
| 162 | |||
| 163 | if(!PKCS12_pack_authsafes (p12, safes)) return NULL; | ||
| 164 | |||
| 165 | sk_PKCS7_pop_free(safes, PKCS7_free); | ||
| 166 | |||
| 167 | if(!PKCS12_set_mac (p12, pass, -1, NULL, 0, mac_iter, NULL)) | ||
| 168 | return NULL; | ||
| 169 | |||
| 170 | return p12; | ||
| 171 | |||
| 172 | } | ||
diff --git a/src/lib/libcrypto/pkcs12/p12_decr.c b/src/lib/libcrypto/pkcs12/p12_decr.c new file mode 100644 index 0000000000..b5684a83ba --- /dev/null +++ b/src/lib/libcrypto/pkcs12/p12_decr.c | |||
| @@ -0,0 +1,176 @@ | |||
| 1 | /* p12_decr.c */ | ||
| 2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
| 3 | * project 1999. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/pkcs12.h> | ||
| 62 | |||
| 63 | /* Define this to dump decrypted output to files called DERnnn */ | ||
| 64 | /*#define DEBUG_DECRYPT*/ | ||
| 65 | |||
| 66 | |||
| 67 | /* Encrypt/Decrypt a buffer based on password and algor, result in a | ||
| 68 | * OPENSSL_malloc'ed buffer | ||
| 69 | */ | ||
| 70 | |||
| 71 | unsigned char * PKCS12_pbe_crypt(X509_ALGOR *algor, const char *pass, | ||
| 72 | int passlen, unsigned char *in, int inlen, unsigned char **data, | ||
| 73 | int *datalen, int en_de) | ||
| 74 | { | ||
| 75 | unsigned char *out; | ||
| 76 | int outlen, i; | ||
| 77 | EVP_CIPHER_CTX ctx; | ||
| 78 | |||
| 79 | EVP_CIPHER_CTX_init(&ctx); | ||
| 80 | /* Decrypt data */ | ||
| 81 | if (!EVP_PBE_CipherInit(algor->algorithm, pass, passlen, | ||
| 82 | algor->parameter, &ctx, en_de)) { | ||
| 83 | PKCS12err(PKCS12_F_PKCS12_PBE_CRYPT,PKCS12_R_PKCS12_ALGOR_CIPHERINIT_ERROR); | ||
| 84 | return NULL; | ||
| 85 | } | ||
| 86 | |||
| 87 | if(!(out = OPENSSL_malloc(inlen + EVP_CIPHER_CTX_block_size(&ctx)))) { | ||
| 88 | PKCS12err(PKCS12_F_PKCS12_PBE_CRYPT,ERR_R_MALLOC_FAILURE); | ||
| 89 | goto err; | ||
| 90 | } | ||
| 91 | |||
| 92 | EVP_CipherUpdate(&ctx, out, &i, in, inlen); | ||
| 93 | outlen = i; | ||
| 94 | if(!EVP_CipherFinal_ex(&ctx, out + i, &i)) { | ||
| 95 | OPENSSL_free(out); | ||
| 96 | out = NULL; | ||
| 97 | PKCS12err(PKCS12_F_PKCS12_PBE_CRYPT,PKCS12_R_PKCS12_CIPHERFINAL_ERROR); | ||
| 98 | goto err; | ||
| 99 | } | ||
| 100 | outlen += i; | ||
| 101 | if (datalen) *datalen = outlen; | ||
| 102 | if (data) *data = out; | ||
| 103 | err: | ||
| 104 | EVP_CIPHER_CTX_cleanup(&ctx); | ||
| 105 | return out; | ||
| 106 | |||
| 107 | } | ||
| 108 | |||
| 109 | /* Decrypt an OCTET STRING and decode ASN1 structure | ||
| 110 | * if zbuf set zero buffer after use. | ||
| 111 | */ | ||
| 112 | |||
| 113 | void * PKCS12_item_decrypt_d2i(X509_ALGOR *algor, const ASN1_ITEM *it, | ||
| 114 | const char *pass, int passlen, ASN1_OCTET_STRING *oct, int zbuf) | ||
| 115 | { | ||
| 116 | unsigned char *out, *p; | ||
| 117 | void *ret; | ||
| 118 | int outlen; | ||
| 119 | |||
| 120 | if (!PKCS12_pbe_crypt(algor, pass, passlen, oct->data, oct->length, | ||
| 121 | &out, &outlen, 0)) { | ||
| 122 | PKCS12err(PKCS12_F_PKCS12_DECRYPT_D2I,PKCS12_R_PKCS12_PBE_CRYPT_ERROR); | ||
| 123 | return NULL; | ||
| 124 | } | ||
| 125 | p = out; | ||
| 126 | #ifdef DEBUG_DECRYPT | ||
| 127 | { | ||
| 128 | FILE *op; | ||
| 129 | |||
| 130 | char fname[30]; | ||
| 131 | static int fnm = 1; | ||
| 132 | sprintf(fname, "DER%d", fnm++); | ||
| 133 | op = fopen(fname, "wb"); | ||
| 134 | fwrite (p, 1, outlen, op); | ||
| 135 | fclose(op); | ||
| 136 | } | ||
| 137 | #endif | ||
| 138 | ret = ASN1_item_d2i(NULL, &p, outlen, it); | ||
| 139 | if (zbuf) OPENSSL_cleanse(out, outlen); | ||
| 140 | if(!ret) PKCS12err(PKCS12_F_PKCS12_DECRYPT_D2I,PKCS12_R_DECODE_ERROR); | ||
| 141 | OPENSSL_free(out); | ||
| 142 | return ret; | ||
| 143 | } | ||
| 144 | |||
| 145 | /* Encode ASN1 structure and encrypt, return OCTET STRING | ||
| 146 | * if zbuf set zero encoding. | ||
| 147 | */ | ||
| 148 | |||
| 149 | ASN1_OCTET_STRING *PKCS12_item_i2d_encrypt(X509_ALGOR *algor, const ASN1_ITEM *it, | ||
| 150 | const char *pass, int passlen, | ||
| 151 | void *obj, int zbuf) | ||
| 152 | { | ||
| 153 | ASN1_OCTET_STRING *oct; | ||
| 154 | unsigned char *in = NULL; | ||
| 155 | int inlen; | ||
| 156 | if (!(oct = M_ASN1_OCTET_STRING_new ())) { | ||
| 157 | PKCS12err(PKCS12_F_PKCS12_I2D_ENCRYPT,ERR_R_MALLOC_FAILURE); | ||
| 158 | return NULL; | ||
| 159 | } | ||
| 160 | inlen = ASN1_item_i2d(obj, &in, it); | ||
| 161 | if (!in) { | ||
| 162 | PKCS12err(PKCS12_F_PKCS12_I2D_ENCRYPT,PKCS12_R_ENCODE_ERROR); | ||
| 163 | return NULL; | ||
| 164 | } | ||
| 165 | if (!PKCS12_pbe_crypt(algor, pass, passlen, in, inlen, &oct->data, | ||
| 166 | &oct->length, 1)) { | ||
| 167 | PKCS12err(PKCS12_F_PKCS12_I2D_ENCRYPT,PKCS12_R_ENCRYPT_ERROR); | ||
| 168 | OPENSSL_free(in); | ||
| 169 | return NULL; | ||
| 170 | } | ||
| 171 | if (zbuf) OPENSSL_cleanse(in, inlen); | ||
| 172 | OPENSSL_free(in); | ||
| 173 | return oct; | ||
| 174 | } | ||
| 175 | |||
| 176 | IMPLEMENT_PKCS12_STACK_OF(PKCS7) | ||
diff --git a/src/lib/libcrypto/pkcs12/p12_init.c b/src/lib/libcrypto/pkcs12/p12_init.c new file mode 100644 index 0000000000..5276b12669 --- /dev/null +++ b/src/lib/libcrypto/pkcs12/p12_init.c | |||
| @@ -0,0 +1,92 @@ | |||
| 1 | /* p12_init.c */ | ||
| 2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
| 3 | * project 1999. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/pkcs12.h> | ||
| 62 | |||
| 63 | /* Initialise a PKCS12 structure to take data */ | ||
| 64 | |||
| 65 | PKCS12 *PKCS12_init (int mode) | ||
| 66 | { | ||
| 67 | PKCS12 *pkcs12; | ||
| 68 | if (!(pkcs12 = PKCS12_new())) { | ||
| 69 | PKCS12err(PKCS12_F_PKCS12_INIT,ERR_R_MALLOC_FAILURE); | ||
| 70 | return NULL; | ||
| 71 | } | ||
| 72 | ASN1_INTEGER_set(pkcs12->version, 3); | ||
| 73 | pkcs12->authsafes->type = OBJ_nid2obj(mode); | ||
| 74 | switch (mode) { | ||
| 75 | case NID_pkcs7_data: | ||
| 76 | if (!(pkcs12->authsafes->d.data = | ||
| 77 | M_ASN1_OCTET_STRING_new())) { | ||
| 78 | PKCS12err(PKCS12_F_PKCS12_INIT,ERR_R_MALLOC_FAILURE); | ||
| 79 | goto err; | ||
| 80 | } | ||
| 81 | break; | ||
| 82 | default: | ||
| 83 | PKCS12err(PKCS12_F_PKCS12_INIT, | ||
| 84 | PKCS12_R_UNSUPPORTED_PKCS12_MODE); | ||
| 85 | goto err; | ||
| 86 | } | ||
| 87 | |||
| 88 | return pkcs12; | ||
| 89 | err: | ||
| 90 | if (pkcs12 != NULL) PKCS12_free(pkcs12); | ||
| 91 | return NULL; | ||
| 92 | } | ||
diff --git a/src/lib/libcrypto/pkcs12/p12_key.c b/src/lib/libcrypto/pkcs12/p12_key.c new file mode 100644 index 0000000000..9196a34b4a --- /dev/null +++ b/src/lib/libcrypto/pkcs12/p12_key.c | |||
| @@ -0,0 +1,206 @@ | |||
| 1 | /* p12_key.c */ | ||
| 2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
| 3 | * project 1999. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/pkcs12.h> | ||
| 62 | |||
| 63 | |||
| 64 | /* Uncomment out this line to get debugging info about key generation */ | ||
| 65 | /*#define DEBUG_KEYGEN*/ | ||
| 66 | #ifdef DEBUG_KEYGEN | ||
| 67 | #include <openssl/bio.h> | ||
| 68 | extern BIO *bio_err; | ||
| 69 | void h__dump (unsigned char *p, int len); | ||
| 70 | #endif | ||
| 71 | |||
| 72 | /* PKCS12 compatible key/IV generation */ | ||
| 73 | #ifndef min | ||
| 74 | #define min(a,b) ((a) < (b) ? (a) : (b)) | ||
| 75 | #endif | ||
| 76 | |||
| 77 | int PKCS12_key_gen_asc(const char *pass, int passlen, unsigned char *salt, | ||
| 78 | int saltlen, int id, int iter, int n, unsigned char *out, | ||
| 79 | const EVP_MD *md_type) | ||
| 80 | { | ||
| 81 | int ret; | ||
| 82 | unsigned char *unipass; | ||
| 83 | int uniplen; | ||
| 84 | if(!pass) { | ||
| 85 | unipass = NULL; | ||
| 86 | uniplen = 0; | ||
| 87 | } else if (!asc2uni(pass, passlen, &unipass, &uniplen)) { | ||
| 88 | PKCS12err(PKCS12_F_PKCS12_KEY_GEN_ASC,ERR_R_MALLOC_FAILURE); | ||
| 89 | return 0; | ||
| 90 | } | ||
| 91 | ret = PKCS12_key_gen_uni(unipass, uniplen, salt, saltlen, | ||
| 92 | id, iter, n, out, md_type); | ||
| 93 | if(unipass) { | ||
| 94 | OPENSSL_cleanse(unipass, uniplen); /* Clear password from memory */ | ||
| 95 | OPENSSL_free(unipass); | ||
| 96 | } | ||
| 97 | return ret; | ||
| 98 | } | ||
| 99 | |||
| 100 | int PKCS12_key_gen_uni(unsigned char *pass, int passlen, unsigned char *salt, | ||
| 101 | int saltlen, int id, int iter, int n, unsigned char *out, | ||
| 102 | const EVP_MD *md_type) | ||
| 103 | { | ||
| 104 | unsigned char *B, *D, *I, *p, *Ai; | ||
| 105 | int Slen, Plen, Ilen, Ijlen; | ||
| 106 | int i, j, u, v; | ||
| 107 | BIGNUM *Ij, *Bpl1; /* These hold Ij and B + 1 */ | ||
| 108 | EVP_MD_CTX ctx; | ||
| 109 | #ifdef DEBUG_KEYGEN | ||
| 110 | unsigned char *tmpout = out; | ||
| 111 | int tmpn = n; | ||
| 112 | #endif | ||
| 113 | |||
| 114 | #if 0 | ||
| 115 | if (!pass) { | ||
| 116 | PKCS12err(PKCS12_F_PKCS12_KEY_GEN_UNI,ERR_R_PASSED_NULL_PARAMETER); | ||
| 117 | return 0; | ||
| 118 | } | ||
| 119 | #endif | ||
| 120 | |||
| 121 | EVP_MD_CTX_init(&ctx); | ||
| 122 | #ifdef DEBUG_KEYGEN | ||
| 123 | fprintf(stderr, "KEYGEN DEBUG\n"); | ||
| 124 | fprintf(stderr, "ID %d, ITER %d\n", id, iter); | ||
| 125 | fprintf(stderr, "Password (length %d):\n", passlen); | ||
| 126 | h__dump(pass, passlen); | ||
| 127 | fprintf(stderr, "Salt (length %d):\n", saltlen); | ||
| 128 | h__dump(salt, saltlen); | ||
| 129 | #endif | ||
| 130 | v = EVP_MD_block_size (md_type); | ||
| 131 | u = EVP_MD_size (md_type); | ||
| 132 | D = OPENSSL_malloc (v); | ||
| 133 | Ai = OPENSSL_malloc (u); | ||
| 134 | B = OPENSSL_malloc (v + 1); | ||
| 135 | Slen = v * ((saltlen+v-1)/v); | ||
| 136 | if(passlen) Plen = v * ((passlen+v-1)/v); | ||
| 137 | else Plen = 0; | ||
| 138 | Ilen = Slen + Plen; | ||
| 139 | I = OPENSSL_malloc (Ilen); | ||
| 140 | Ij = BN_new(); | ||
| 141 | Bpl1 = BN_new(); | ||
| 142 | if (!D || !Ai || !B || !I || !Ij || !Bpl1) { | ||
| 143 | PKCS12err(PKCS12_F_PKCS12_KEY_GEN_UNI,ERR_R_MALLOC_FAILURE); | ||
| 144 | return 0; | ||
| 145 | } | ||
| 146 | for (i = 0; i < v; i++) D[i] = id; | ||
| 147 | p = I; | ||
| 148 | for (i = 0; i < Slen; i++) *p++ = salt[i % saltlen]; | ||
| 149 | for (i = 0; i < Plen; i++) *p++ = pass[i % passlen]; | ||
| 150 | for (;;) { | ||
| 151 | EVP_DigestInit_ex(&ctx, md_type, NULL); | ||
| 152 | EVP_DigestUpdate(&ctx, D, v); | ||
| 153 | EVP_DigestUpdate(&ctx, I, Ilen); | ||
| 154 | EVP_DigestFinal_ex(&ctx, Ai, NULL); | ||
| 155 | for (j = 1; j < iter; j++) { | ||
| 156 | EVP_DigestInit_ex(&ctx, md_type, NULL); | ||
| 157 | EVP_DigestUpdate(&ctx, Ai, u); | ||
| 158 | EVP_DigestFinal_ex(&ctx, Ai, NULL); | ||
| 159 | } | ||
| 160 | memcpy (out, Ai, min (n, u)); | ||
| 161 | if (u >= n) { | ||
| 162 | OPENSSL_free (Ai); | ||
| 163 | OPENSSL_free (B); | ||
| 164 | OPENSSL_free (D); | ||
| 165 | OPENSSL_free (I); | ||
| 166 | BN_free (Ij); | ||
| 167 | BN_free (Bpl1); | ||
| 168 | EVP_MD_CTX_cleanup(&ctx); | ||
| 169 | #ifdef DEBUG_KEYGEN | ||
| 170 | fprintf(stderr, "Output KEY (length %d)\n", tmpn); | ||
| 171 | h__dump(tmpout, tmpn); | ||
| 172 | #endif | ||
| 173 | return 1; | ||
| 174 | } | ||
| 175 | n -= u; | ||
| 176 | out += u; | ||
| 177 | for (j = 0; j < v; j++) B[j] = Ai[j % u]; | ||
| 178 | /* Work out B + 1 first then can use B as tmp space */ | ||
| 179 | BN_bin2bn (B, v, Bpl1); | ||
| 180 | BN_add_word (Bpl1, 1); | ||
| 181 | for (j = 0; j < Ilen ; j+=v) { | ||
| 182 | BN_bin2bn (I + j, v, Ij); | ||
| 183 | BN_add (Ij, Ij, Bpl1); | ||
| 184 | BN_bn2bin (Ij, B); | ||
| 185 | Ijlen = BN_num_bytes (Ij); | ||
| 186 | /* If more than 2^(v*8) - 1 cut off MSB */ | ||
| 187 | if (Ijlen > v) { | ||
| 188 | BN_bn2bin (Ij, B); | ||
| 189 | memcpy (I + j, B + 1, v); | ||
| 190 | #ifndef PKCS12_BROKEN_KEYGEN | ||
| 191 | /* If less than v bytes pad with zeroes */ | ||
| 192 | } else if (Ijlen < v) { | ||
| 193 | memset(I + j, 0, v - Ijlen); | ||
| 194 | BN_bn2bin(Ij, I + j + v - Ijlen); | ||
| 195 | #endif | ||
| 196 | } else BN_bn2bin (Ij, I + j); | ||
| 197 | } | ||
| 198 | } | ||
| 199 | } | ||
| 200 | #ifdef DEBUG_KEYGEN | ||
| 201 | void h__dump (unsigned char *p, int len) | ||
| 202 | { | ||
| 203 | for (; len --; p++) fprintf(stderr, "%02X", *p); | ||
| 204 | fprintf(stderr, "\n"); | ||
| 205 | } | ||
| 206 | #endif | ||
diff --git a/src/lib/libcrypto/pkcs12/p12_kiss.c b/src/lib/libcrypto/pkcs12/p12_kiss.c new file mode 100644 index 0000000000..2b31999e11 --- /dev/null +++ b/src/lib/libcrypto/pkcs12/p12_kiss.c | |||
| @@ -0,0 +1,297 @@ | |||
| 1 | /* p12_kiss.c */ | ||
| 2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
| 3 | * project 1999. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/pkcs12.h> | ||
| 62 | |||
| 63 | /* Simplified PKCS#12 routines */ | ||
| 64 | |||
| 65 | static int parse_pk12( PKCS12 *p12, const char *pass, int passlen, | ||
| 66 | EVP_PKEY **pkey, X509 **cert, STACK_OF(X509) **ca); | ||
| 67 | |||
| 68 | static int parse_bags( STACK_OF(PKCS12_SAFEBAG) *bags, const char *pass, | ||
| 69 | int passlen, EVP_PKEY **pkey, X509 **cert, | ||
| 70 | STACK_OF(X509) **ca, ASN1_OCTET_STRING **keyid, | ||
| 71 | char *keymatch); | ||
| 72 | |||
| 73 | static int parse_bag( PKCS12_SAFEBAG *bag, const char *pass, int passlen, | ||
| 74 | EVP_PKEY **pkey, X509 **cert, STACK_OF(X509) **ca, | ||
| 75 | ASN1_OCTET_STRING **keyid, char *keymatch); | ||
| 76 | |||
| 77 | /* Parse and decrypt a PKCS#12 structure returning user key, user cert | ||
| 78 | * and other (CA) certs. Note either ca should be NULL, *ca should be NULL, | ||
| 79 | * or it should point to a valid STACK structure. pkey and cert can be | ||
| 80 | * passed unitialised. | ||
| 81 | */ | ||
| 82 | |||
| 83 | int PKCS12_parse (PKCS12 *p12, const char *pass, EVP_PKEY **pkey, X509 **cert, | ||
| 84 | STACK_OF(X509) **ca) | ||
| 85 | { | ||
| 86 | |||
| 87 | /* Check for NULL PKCS12 structure */ | ||
| 88 | |||
| 89 | if(!p12) { | ||
| 90 | PKCS12err(PKCS12_F_PKCS12_PARSE,PKCS12_R_INVALID_NULL_PKCS12_POINTER); | ||
| 91 | return 0; | ||
| 92 | } | ||
| 93 | |||
| 94 | /* Allocate stack for ca certificates if needed */ | ||
| 95 | if ((ca != NULL) && (*ca == NULL)) { | ||
| 96 | if (!(*ca = sk_X509_new_null())) { | ||
| 97 | PKCS12err(PKCS12_F_PKCS12_PARSE,ERR_R_MALLOC_FAILURE); | ||
| 98 | return 0; | ||
| 99 | } | ||
| 100 | } | ||
| 101 | |||
| 102 | if(pkey) *pkey = NULL; | ||
| 103 | if(cert) *cert = NULL; | ||
| 104 | |||
| 105 | /* Check the mac */ | ||
| 106 | |||
| 107 | /* If password is zero length or NULL then try verifying both cases | ||
| 108 | * to determine which password is correct. The reason for this is that | ||
| 109 | * under PKCS#12 password based encryption no password and a zero length | ||
| 110 | * password are two different things... | ||
| 111 | */ | ||
| 112 | |||
| 113 | if(!pass || !*pass) { | ||
| 114 | if(PKCS12_verify_mac(p12, NULL, 0)) pass = NULL; | ||
| 115 | else if(PKCS12_verify_mac(p12, "", 0)) pass = ""; | ||
| 116 | else { | ||
| 117 | PKCS12err(PKCS12_F_PKCS12_PARSE,PKCS12_R_MAC_VERIFY_FAILURE); | ||
| 118 | goto err; | ||
| 119 | } | ||
| 120 | } else if (!PKCS12_verify_mac(p12, pass, -1)) { | ||
| 121 | PKCS12err(PKCS12_F_PKCS12_PARSE,PKCS12_R_MAC_VERIFY_FAILURE); | ||
| 122 | goto err; | ||
| 123 | } | ||
| 124 | |||
| 125 | if (!parse_pk12 (p12, pass, -1, pkey, cert, ca)) | ||
| 126 | { | ||
| 127 | PKCS12err(PKCS12_F_PKCS12_PARSE,PKCS12_R_PARSE_ERROR); | ||
| 128 | goto err; | ||
| 129 | } | ||
| 130 | |||
| 131 | return 1; | ||
| 132 | |||
| 133 | err: | ||
| 134 | |||
| 135 | if (pkey && *pkey) EVP_PKEY_free(*pkey); | ||
| 136 | if (cert && *cert) X509_free(*cert); | ||
| 137 | if (ca) sk_X509_pop_free(*ca, X509_free); | ||
| 138 | return 0; | ||
| 139 | |||
| 140 | } | ||
| 141 | |||
| 142 | /* Parse the outer PKCS#12 structure */ | ||
| 143 | |||
| 144 | static int parse_pk12 (PKCS12 *p12, const char *pass, int passlen, | ||
| 145 | EVP_PKEY **pkey, X509 **cert, STACK_OF(X509) **ca) | ||
| 146 | { | ||
| 147 | STACK_OF(PKCS7) *asafes; | ||
| 148 | STACK_OF(PKCS12_SAFEBAG) *bags; | ||
| 149 | int i, bagnid; | ||
| 150 | PKCS7 *p7; | ||
| 151 | ASN1_OCTET_STRING *keyid = NULL; | ||
| 152 | |||
| 153 | char keymatch = 0; | ||
| 154 | if (!(asafes = PKCS12_unpack_authsafes (p12))) return 0; | ||
| 155 | for (i = 0; i < sk_PKCS7_num (asafes); i++) { | ||
| 156 | p7 = sk_PKCS7_value (asafes, i); | ||
| 157 | bagnid = OBJ_obj2nid (p7->type); | ||
| 158 | if (bagnid == NID_pkcs7_data) { | ||
| 159 | bags = PKCS12_unpack_p7data(p7); | ||
| 160 | } else if (bagnid == NID_pkcs7_encrypted) { | ||
| 161 | bags = PKCS12_unpack_p7encdata(p7, pass, passlen); | ||
| 162 | } else continue; | ||
| 163 | if (!bags) { | ||
| 164 | sk_PKCS7_pop_free(asafes, PKCS7_free); | ||
| 165 | return 0; | ||
| 166 | } | ||
| 167 | if (!parse_bags(bags, pass, passlen, pkey, cert, ca, | ||
| 168 | &keyid, &keymatch)) { | ||
| 169 | sk_PKCS12_SAFEBAG_pop_free(bags, PKCS12_SAFEBAG_free); | ||
| 170 | sk_PKCS7_pop_free(asafes, PKCS7_free); | ||
| 171 | return 0; | ||
| 172 | } | ||
| 173 | sk_PKCS12_SAFEBAG_pop_free(bags, PKCS12_SAFEBAG_free); | ||
| 174 | } | ||
| 175 | sk_PKCS7_pop_free(asafes, PKCS7_free); | ||
| 176 | if (keyid) M_ASN1_OCTET_STRING_free(keyid); | ||
| 177 | return 1; | ||
| 178 | } | ||
| 179 | |||
| 180 | |||
| 181 | static int parse_bags (STACK_OF(PKCS12_SAFEBAG) *bags, const char *pass, | ||
| 182 | int passlen, EVP_PKEY **pkey, X509 **cert, | ||
| 183 | STACK_OF(X509) **ca, ASN1_OCTET_STRING **keyid, | ||
| 184 | char *keymatch) | ||
| 185 | { | ||
| 186 | int i; | ||
| 187 | for (i = 0; i < sk_PKCS12_SAFEBAG_num(bags); i++) { | ||
| 188 | if (!parse_bag(sk_PKCS12_SAFEBAG_value (bags, i), | ||
| 189 | pass, passlen, pkey, cert, ca, keyid, | ||
| 190 | keymatch)) return 0; | ||
| 191 | } | ||
| 192 | return 1; | ||
| 193 | } | ||
| 194 | |||
| 195 | #define MATCH_KEY 0x1 | ||
| 196 | #define MATCH_CERT 0x2 | ||
| 197 | #define MATCH_ALL 0x3 | ||
| 198 | |||
| 199 | static int parse_bag(PKCS12_SAFEBAG *bag, const char *pass, int passlen, | ||
| 200 | EVP_PKEY **pkey, X509 **cert, STACK_OF(X509) **ca, | ||
| 201 | ASN1_OCTET_STRING **keyid, | ||
| 202 | char *keymatch) | ||
| 203 | { | ||
| 204 | PKCS8_PRIV_KEY_INFO *p8; | ||
| 205 | X509 *x509; | ||
| 206 | ASN1_OCTET_STRING *lkey = NULL, *ckid = NULL; | ||
| 207 | ASN1_TYPE *attrib; | ||
| 208 | ASN1_BMPSTRING *fname = NULL; | ||
| 209 | |||
| 210 | if ((attrib = PKCS12_get_attr (bag, NID_friendlyName))) | ||
| 211 | fname = attrib->value.bmpstring; | ||
| 212 | |||
| 213 | if ((attrib = PKCS12_get_attr (bag, NID_localKeyID))) { | ||
| 214 | lkey = attrib->value.octet_string; | ||
| 215 | ckid = lkey; | ||
| 216 | } | ||
| 217 | |||
| 218 | /* Check for any local key id matching (if needed) */ | ||
| 219 | if (lkey && ((*keymatch & MATCH_ALL) != MATCH_ALL)) { | ||
| 220 | if (*keyid) { | ||
| 221 | if (M_ASN1_OCTET_STRING_cmp(*keyid, lkey)) lkey = NULL; | ||
| 222 | } else { | ||
| 223 | if (!(*keyid = M_ASN1_OCTET_STRING_dup(lkey))) { | ||
| 224 | PKCS12err(PKCS12_F_PARSE_BAGS,ERR_R_MALLOC_FAILURE); | ||
| 225 | return 0; | ||
| 226 | } | ||
| 227 | } | ||
| 228 | } | ||
| 229 | |||
| 230 | switch (M_PKCS12_bag_type(bag)) | ||
| 231 | { | ||
| 232 | case NID_keyBag: | ||
| 233 | if (!lkey || !pkey) return 1; | ||
| 234 | if (!(*pkey = EVP_PKCS82PKEY(bag->value.keybag))) return 0; | ||
| 235 | *keymatch |= MATCH_KEY; | ||
| 236 | break; | ||
| 237 | |||
| 238 | case NID_pkcs8ShroudedKeyBag: | ||
| 239 | if (!lkey || !pkey) return 1; | ||
| 240 | if (!(p8 = PKCS12_decrypt_skey(bag, pass, passlen))) | ||
| 241 | return 0; | ||
| 242 | *pkey = EVP_PKCS82PKEY(p8); | ||
| 243 | PKCS8_PRIV_KEY_INFO_free(p8); | ||
| 244 | if (!(*pkey)) return 0; | ||
| 245 | *keymatch |= MATCH_KEY; | ||
| 246 | break; | ||
| 247 | |||
| 248 | case NID_certBag: | ||
| 249 | if (M_PKCS12_cert_bag_type(bag) != NID_x509Certificate ) | ||
| 250 | return 1; | ||
| 251 | if (!(x509 = PKCS12_certbag2x509(bag))) return 0; | ||
| 252 | if(ckid) | ||
| 253 | { | ||
| 254 | if (!X509_keyid_set1(x509, ckid->data, ckid->length)) | ||
| 255 | { | ||
| 256 | X509_free(x509); | ||
| 257 | return 0; | ||
| 258 | } | ||
| 259 | } | ||
| 260 | if(fname) { | ||
| 261 | int len, r; | ||
| 262 | unsigned char *data; | ||
| 263 | len = ASN1_STRING_to_UTF8(&data, fname); | ||
| 264 | if(len > 0) { | ||
| 265 | r = X509_alias_set1(x509, data, len); | ||
| 266 | OPENSSL_free(data); | ||
| 267 | if (!r) | ||
| 268 | { | ||
| 269 | X509_free(x509); | ||
| 270 | return 0; | ||
| 271 | } | ||
| 272 | } | ||
| 273 | } | ||
| 274 | |||
| 275 | |||
| 276 | if (lkey) { | ||
| 277 | *keymatch |= MATCH_CERT; | ||
| 278 | if (cert) *cert = x509; | ||
| 279 | else X509_free(x509); | ||
| 280 | } else { | ||
| 281 | if(ca) sk_X509_push (*ca, x509); | ||
| 282 | else X509_free(x509); | ||
| 283 | } | ||
| 284 | break; | ||
| 285 | |||
| 286 | case NID_safeContentsBag: | ||
| 287 | return parse_bags(bag->value.safes, pass, passlen, | ||
| 288 | pkey, cert, ca, keyid, keymatch); | ||
| 289 | break; | ||
| 290 | |||
| 291 | default: | ||
| 292 | return 1; | ||
| 293 | break; | ||
| 294 | } | ||
| 295 | return 1; | ||
| 296 | } | ||
| 297 | |||
diff --git a/src/lib/libcrypto/pkcs12/p12_mutl.c b/src/lib/libcrypto/pkcs12/p12_mutl.c new file mode 100644 index 0000000000..140d21155e --- /dev/null +++ b/src/lib/libcrypto/pkcs12/p12_mutl.c | |||
| @@ -0,0 +1,182 @@ | |||
| 1 | /* p12_mutl.c */ | ||
| 2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
| 3 | * project 1999. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | #ifndef OPENSSL_NO_HMAC | ||
| 60 | #include <stdio.h> | ||
| 61 | #include "cryptlib.h" | ||
| 62 | #include <openssl/hmac.h> | ||
| 63 | #include <openssl/rand.h> | ||
| 64 | #include <openssl/pkcs12.h> | ||
| 65 | |||
| 66 | /* Generate a MAC */ | ||
| 67 | int PKCS12_gen_mac (PKCS12 *p12, const char *pass, int passlen, | ||
| 68 | unsigned char *mac, unsigned int *maclen) | ||
| 69 | { | ||
| 70 | const EVP_MD *md_type; | ||
| 71 | HMAC_CTX hmac; | ||
| 72 | unsigned char key[PKCS12_MAC_KEY_LENGTH], *salt; | ||
| 73 | int saltlen, iter; | ||
| 74 | |||
| 75 | if (!PKCS7_type_is_data(p12->authsafes)) | ||
| 76 | { | ||
| 77 | PKCS12err(PKCS12_F_PKCS12_GEN_MAC,PKCS12_R_CONTENT_TYPE_NOT_DATA); | ||
| 78 | return 0; | ||
| 79 | } | ||
| 80 | |||
| 81 | salt = p12->mac->salt->data; | ||
| 82 | saltlen = p12->mac->salt->length; | ||
| 83 | if (!p12->mac->iter) iter = 1; | ||
| 84 | else iter = ASN1_INTEGER_get (p12->mac->iter); | ||
| 85 | if(!(md_type = | ||
| 86 | EVP_get_digestbyobj (p12->mac->dinfo->algor->algorithm))) { | ||
| 87 | PKCS12err(PKCS12_F_PKCS12_GEN_MAC,PKCS12_R_UNKNOWN_DIGEST_ALGORITHM); | ||
| 88 | return 0; | ||
| 89 | } | ||
| 90 | if(!PKCS12_key_gen (pass, passlen, salt, saltlen, PKCS12_MAC_ID, iter, | ||
| 91 | PKCS12_MAC_KEY_LENGTH, key, md_type)) { | ||
| 92 | PKCS12err(PKCS12_F_PKCS12_GEN_MAC,PKCS12_R_KEY_GEN_ERROR); | ||
| 93 | return 0; | ||
| 94 | } | ||
| 95 | HMAC_CTX_init(&hmac); | ||
| 96 | HMAC_Init_ex(&hmac, key, PKCS12_MAC_KEY_LENGTH, md_type, NULL); | ||
| 97 | HMAC_Update(&hmac, p12->authsafes->d.data->data, | ||
| 98 | p12->authsafes->d.data->length); | ||
| 99 | HMAC_Final(&hmac, mac, maclen); | ||
| 100 | HMAC_CTX_cleanup(&hmac); | ||
| 101 | return 1; | ||
| 102 | } | ||
| 103 | |||
| 104 | /* Verify the mac */ | ||
| 105 | int PKCS12_verify_mac (PKCS12 *p12, const char *pass, int passlen) | ||
| 106 | { | ||
| 107 | unsigned char mac[EVP_MAX_MD_SIZE]; | ||
| 108 | unsigned int maclen; | ||
| 109 | if(p12->mac == NULL) { | ||
| 110 | PKCS12err(PKCS12_F_VERIFY_MAC,PKCS12_R_MAC_ABSENT); | ||
| 111 | return 0; | ||
| 112 | } | ||
| 113 | if (!PKCS12_gen_mac (p12, pass, passlen, mac, &maclen)) { | ||
| 114 | PKCS12err(PKCS12_F_VERIFY_MAC,PKCS12_R_MAC_GENERATION_ERROR); | ||
| 115 | return 0; | ||
| 116 | } | ||
| 117 | if ((maclen != (unsigned int)p12->mac->dinfo->digest->length) | ||
| 118 | || memcmp (mac, p12->mac->dinfo->digest->data, maclen)) return 0; | ||
| 119 | return 1; | ||
| 120 | } | ||
| 121 | |||
| 122 | /* Set a mac */ | ||
| 123 | |||
| 124 | int PKCS12_set_mac (PKCS12 *p12, const char *pass, int passlen, | ||
| 125 | unsigned char *salt, int saltlen, int iter, const EVP_MD *md_type) | ||
| 126 | { | ||
| 127 | unsigned char mac[EVP_MAX_MD_SIZE]; | ||
| 128 | unsigned int maclen; | ||
| 129 | |||
| 130 | if (!md_type) md_type = EVP_sha1(); | ||
| 131 | if (PKCS12_setup_mac (p12, iter, salt, saltlen, md_type) == | ||
| 132 | PKCS12_ERROR) { | ||
| 133 | PKCS12err(PKCS12_F_PKCS12_SET_MAC,PKCS12_R_MAC_SETUP_ERROR); | ||
| 134 | return 0; | ||
| 135 | } | ||
| 136 | if (!PKCS12_gen_mac (p12, pass, passlen, mac, &maclen)) { | ||
| 137 | PKCS12err(PKCS12_F_PKCS12_SET_MAC,PKCS12_R_MAC_GENERATION_ERROR); | ||
| 138 | return 0; | ||
| 139 | } | ||
| 140 | if (!(M_ASN1_OCTET_STRING_set (p12->mac->dinfo->digest, mac, maclen))) { | ||
| 141 | PKCS12err(PKCS12_F_PKCS12_SET_MAC,PKCS12_R_MAC_STRING_SET_ERROR); | ||
| 142 | return 0; | ||
| 143 | } | ||
| 144 | return 1; | ||
| 145 | } | ||
| 146 | |||
| 147 | /* Set up a mac structure */ | ||
| 148 | int PKCS12_setup_mac (PKCS12 *p12, int iter, unsigned char *salt, int saltlen, | ||
| 149 | const EVP_MD *md_type) | ||
| 150 | { | ||
| 151 | if (!(p12->mac = PKCS12_MAC_DATA_new())) return PKCS12_ERROR; | ||
| 152 | if (iter > 1) { | ||
| 153 | if(!(p12->mac->iter = M_ASN1_INTEGER_new())) { | ||
| 154 | PKCS12err(PKCS12_F_PKCS12_SETUP_MAC, ERR_R_MALLOC_FAILURE); | ||
| 155 | return 0; | ||
| 156 | } | ||
| 157 | if (!ASN1_INTEGER_set(p12->mac->iter, iter)) { | ||
| 158 | PKCS12err(PKCS12_F_PKCS12_SETUP_MAC, ERR_R_MALLOC_FAILURE); | ||
| 159 | return 0; | ||
| 160 | } | ||
| 161 | } | ||
| 162 | if (!saltlen) saltlen = PKCS12_SALT_LEN; | ||
| 163 | p12->mac->salt->length = saltlen; | ||
| 164 | if (!(p12->mac->salt->data = OPENSSL_malloc (saltlen))) { | ||
| 165 | PKCS12err(PKCS12_F_PKCS12_SETUP_MAC, ERR_R_MALLOC_FAILURE); | ||
| 166 | return 0; | ||
| 167 | } | ||
| 168 | if (!salt) { | ||
| 169 | if (RAND_pseudo_bytes (p12->mac->salt->data, saltlen) < 0) | ||
| 170 | return 0; | ||
| 171 | } | ||
| 172 | else memcpy (p12->mac->salt->data, salt, saltlen); | ||
| 173 | p12->mac->dinfo->algor->algorithm = OBJ_nid2obj(EVP_MD_type(md_type)); | ||
| 174 | if (!(p12->mac->dinfo->algor->parameter = ASN1_TYPE_new())) { | ||
| 175 | PKCS12err(PKCS12_F_PKCS12_SETUP_MAC, ERR_R_MALLOC_FAILURE); | ||
| 176 | return 0; | ||
| 177 | } | ||
| 178 | p12->mac->dinfo->algor->parameter->type = V_ASN1_NULL; | ||
| 179 | |||
| 180 | return 1; | ||
| 181 | } | ||
| 182 | #endif | ||
diff --git a/src/lib/libcrypto/pkcs12/p12_npas.c b/src/lib/libcrypto/pkcs12/p12_npas.c new file mode 100644 index 0000000000..af708a2743 --- /dev/null +++ b/src/lib/libcrypto/pkcs12/p12_npas.c | |||
| @@ -0,0 +1,217 @@ | |||
| 1 | /* p12_npas.c */ | ||
| 2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
| 3 | * project 1999. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include <stdlib.h> | ||
| 61 | #include <string.h> | ||
| 62 | #include <openssl/pem.h> | ||
| 63 | #include <openssl/err.h> | ||
| 64 | #include <openssl/pkcs12.h> | ||
| 65 | |||
| 66 | /* PKCS#12 password change routine */ | ||
| 67 | |||
| 68 | static int newpass_p12(PKCS12 *p12, char *oldpass, char *newpass); | ||
| 69 | static int newpass_bags(STACK_OF(PKCS12_SAFEBAG) *bags, char *oldpass, | ||
| 70 | char *newpass); | ||
| 71 | static int newpass_bag(PKCS12_SAFEBAG *bag, char *oldpass, char *newpass); | ||
| 72 | static int alg_get(X509_ALGOR *alg, int *pnid, int *piter, int *psaltlen); | ||
| 73 | |||
| 74 | /* | ||
| 75 | * Change the password on a PKCS#12 structure. | ||
| 76 | */ | ||
| 77 | |||
| 78 | int PKCS12_newpass(PKCS12 *p12, char *oldpass, char *newpass) | ||
| 79 | { | ||
| 80 | |||
| 81 | /* Check for NULL PKCS12 structure */ | ||
| 82 | |||
| 83 | if(!p12) { | ||
| 84 | PKCS12err(PKCS12_F_PKCS12_NEWPASS,PKCS12_R_INVALID_NULL_PKCS12_POINTER); | ||
| 85 | return 0; | ||
| 86 | } | ||
| 87 | |||
| 88 | /* Check the mac */ | ||
| 89 | |||
| 90 | if (!PKCS12_verify_mac(p12, oldpass, -1)) { | ||
| 91 | PKCS12err(PKCS12_F_PKCS12_NEWPASS,PKCS12_R_MAC_VERIFY_FAILURE); | ||
| 92 | return 0; | ||
| 93 | } | ||
| 94 | |||
| 95 | if (!newpass_p12(p12, oldpass, newpass)) { | ||
| 96 | PKCS12err(PKCS12_F_PKCS12_NEWPASS,PKCS12_R_PARSE_ERROR); | ||
| 97 | return 0; | ||
| 98 | } | ||
| 99 | |||
| 100 | return 1; | ||
| 101 | |||
| 102 | } | ||
| 103 | |||
| 104 | /* Parse the outer PKCS#12 structure */ | ||
| 105 | |||
| 106 | static int newpass_p12(PKCS12 *p12, char *oldpass, char *newpass) | ||
| 107 | { | ||
| 108 | STACK_OF(PKCS7) *asafes, *newsafes; | ||
| 109 | STACK_OF(PKCS12_SAFEBAG) *bags; | ||
| 110 | int i, bagnid, pbe_nid = 0, pbe_iter = 0, pbe_saltlen = 0; | ||
| 111 | PKCS7 *p7, *p7new; | ||
| 112 | ASN1_OCTET_STRING *p12_data_tmp = NULL, *macnew = NULL; | ||
| 113 | unsigned char mac[EVP_MAX_MD_SIZE]; | ||
| 114 | unsigned int maclen; | ||
| 115 | |||
| 116 | if (!(asafes = PKCS12_unpack_authsafes(p12))) return 0; | ||
| 117 | if(!(newsafes = sk_PKCS7_new_null())) return 0; | ||
| 118 | for (i = 0; i < sk_PKCS7_num (asafes); i++) { | ||
| 119 | p7 = sk_PKCS7_value(asafes, i); | ||
| 120 | bagnid = OBJ_obj2nid(p7->type); | ||
| 121 | if (bagnid == NID_pkcs7_data) { | ||
| 122 | bags = PKCS12_unpack_p7data(p7); | ||
| 123 | } else if (bagnid == NID_pkcs7_encrypted) { | ||
| 124 | bags = PKCS12_unpack_p7encdata(p7, oldpass, -1); | ||
| 125 | alg_get(p7->d.encrypted->enc_data->algorithm, | ||
| 126 | &pbe_nid, &pbe_iter, &pbe_saltlen); | ||
| 127 | } else continue; | ||
| 128 | if (!bags) { | ||
| 129 | sk_PKCS7_pop_free(asafes, PKCS7_free); | ||
| 130 | return 0; | ||
| 131 | } | ||
| 132 | if (!newpass_bags(bags, oldpass, newpass)) { | ||
| 133 | sk_PKCS12_SAFEBAG_pop_free(bags, PKCS12_SAFEBAG_free); | ||
| 134 | sk_PKCS7_pop_free(asafes, PKCS7_free); | ||
| 135 | return 0; | ||
| 136 | } | ||
| 137 | /* Repack bag in same form with new password */ | ||
| 138 | if (bagnid == NID_pkcs7_data) p7new = PKCS12_pack_p7data(bags); | ||
| 139 | else p7new = PKCS12_pack_p7encdata(pbe_nid, newpass, -1, NULL, | ||
| 140 | pbe_saltlen, pbe_iter, bags); | ||
| 141 | sk_PKCS12_SAFEBAG_pop_free(bags, PKCS12_SAFEBAG_free); | ||
| 142 | if(!p7new) { | ||
| 143 | sk_PKCS7_pop_free(asafes, PKCS7_free); | ||
| 144 | return 0; | ||
| 145 | } | ||
| 146 | sk_PKCS7_push(newsafes, p7new); | ||
| 147 | } | ||
| 148 | sk_PKCS7_pop_free(asafes, PKCS7_free); | ||
| 149 | |||
| 150 | /* Repack safe: save old safe in case of error */ | ||
| 151 | |||
| 152 | p12_data_tmp = p12->authsafes->d.data; | ||
| 153 | if(!(p12->authsafes->d.data = ASN1_OCTET_STRING_new())) goto saferr; | ||
| 154 | if(!PKCS12_pack_authsafes(p12, newsafes)) goto saferr; | ||
| 155 | |||
| 156 | if(!PKCS12_gen_mac(p12, newpass, -1, mac, &maclen)) goto saferr; | ||
| 157 | if(!(macnew = ASN1_OCTET_STRING_new())) goto saferr; | ||
| 158 | if(!ASN1_OCTET_STRING_set(macnew, mac, maclen)) goto saferr; | ||
| 159 | ASN1_OCTET_STRING_free(p12->mac->dinfo->digest); | ||
| 160 | p12->mac->dinfo->digest = macnew; | ||
| 161 | ASN1_OCTET_STRING_free(p12_data_tmp); | ||
| 162 | |||
| 163 | return 1; | ||
| 164 | |||
| 165 | saferr: | ||
| 166 | /* Restore old safe */ | ||
| 167 | ASN1_OCTET_STRING_free(p12->authsafes->d.data); | ||
| 168 | ASN1_OCTET_STRING_free(macnew); | ||
| 169 | p12->authsafes->d.data = p12_data_tmp; | ||
| 170 | return 0; | ||
| 171 | |||
| 172 | } | ||
| 173 | |||
| 174 | |||
| 175 | static int newpass_bags(STACK_OF(PKCS12_SAFEBAG) *bags, char *oldpass, | ||
| 176 | char *newpass) | ||
| 177 | { | ||
| 178 | int i; | ||
| 179 | for (i = 0; i < sk_PKCS12_SAFEBAG_num(bags); i++) { | ||
| 180 | if (!newpass_bag(sk_PKCS12_SAFEBAG_value(bags, i), | ||
| 181 | oldpass, newpass)) | ||
| 182 | return 0; | ||
| 183 | } | ||
| 184 | return 1; | ||
| 185 | } | ||
| 186 | |||
| 187 | /* Change password of safebag: only needs handle shrouded keybags */ | ||
| 188 | |||
| 189 | static int newpass_bag(PKCS12_SAFEBAG *bag, char *oldpass, char *newpass) | ||
| 190 | { | ||
| 191 | PKCS8_PRIV_KEY_INFO *p8; | ||
| 192 | X509_SIG *p8new; | ||
| 193 | int p8_nid, p8_saltlen, p8_iter; | ||
| 194 | |||
| 195 | if(M_PKCS12_bag_type(bag) != NID_pkcs8ShroudedKeyBag) return 1; | ||
| 196 | |||
| 197 | if (!(p8 = PKCS8_decrypt(bag->value.shkeybag, oldpass, -1))) return 0; | ||
| 198 | alg_get(bag->value.shkeybag->algor, &p8_nid, &p8_iter, &p8_saltlen); | ||
| 199 | if(!(p8new = PKCS8_encrypt(p8_nid, NULL, newpass, -1, NULL, p8_saltlen, | ||
| 200 | p8_iter, p8))) return 0; | ||
| 201 | X509_SIG_free(bag->value.shkeybag); | ||
| 202 | bag->value.shkeybag = p8new; | ||
| 203 | return 1; | ||
| 204 | } | ||
| 205 | |||
| 206 | static int alg_get(X509_ALGOR *alg, int *pnid, int *piter, int *psaltlen) | ||
| 207 | { | ||
| 208 | PBEPARAM *pbe; | ||
| 209 | unsigned char *p; | ||
| 210 | p = alg->parameter->value.sequence->data; | ||
| 211 | pbe = d2i_PBEPARAM(NULL, &p, alg->parameter->value.sequence->length); | ||
| 212 | *pnid = OBJ_obj2nid(alg->algorithm); | ||
| 213 | *piter = ASN1_INTEGER_get(pbe->iter); | ||
| 214 | *psaltlen = pbe->salt->length; | ||
| 215 | PBEPARAM_free(pbe); | ||
| 216 | return 0; | ||
| 217 | } | ||
diff --git a/src/lib/libcrypto/pkcs12/p12_p8d.c b/src/lib/libcrypto/pkcs12/p12_p8d.c new file mode 100644 index 0000000000..3c6f377933 --- /dev/null +++ b/src/lib/libcrypto/pkcs12/p12_p8d.c | |||
| @@ -0,0 +1,68 @@ | |||
| 1 | /* p12_p8d.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 | #include "cryptlib.h" | ||
| 61 | #include <openssl/pkcs12.h> | ||
| 62 | |||
| 63 | PKCS8_PRIV_KEY_INFO *PKCS8_decrypt(X509_SIG *p8, const char *pass, int passlen) | ||
| 64 | { | ||
| 65 | return PKCS12_item_decrypt_d2i(p8->algor, ASN1_ITEM_rptr(PKCS8_PRIV_KEY_INFO), pass, | ||
| 66 | passlen, p8->digest, 1); | ||
| 67 | } | ||
| 68 | |||
diff --git a/src/lib/libcrypto/pkcs12/p12_p8e.c b/src/lib/libcrypto/pkcs12/p12_p8e.c new file mode 100644 index 0000000000..3d47956652 --- /dev/null +++ b/src/lib/libcrypto/pkcs12/p12_p8e.c | |||
| @@ -0,0 +1,97 @@ | |||
| 1 | /* p12_p8e.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 | #include "cryptlib.h" | ||
| 61 | #include <openssl/pkcs12.h> | ||
| 62 | |||
| 63 | X509_SIG *PKCS8_encrypt(int pbe_nid, const EVP_CIPHER *cipher, | ||
| 64 | const char *pass, int passlen, | ||
| 65 | unsigned char *salt, int saltlen, int iter, | ||
| 66 | PKCS8_PRIV_KEY_INFO *p8inf) | ||
| 67 | { | ||
| 68 | X509_SIG *p8 = NULL; | ||
| 69 | X509_ALGOR *pbe; | ||
| 70 | |||
| 71 | if (!(p8 = X509_SIG_new())) { | ||
| 72 | PKCS12err(PKCS12_F_PKCS8_ENCRYPT, ERR_R_MALLOC_FAILURE); | ||
| 73 | goto err; | ||
| 74 | } | ||
| 75 | |||
| 76 | if(pbe_nid == -1) pbe = PKCS5_pbe2_set(cipher, iter, salt, saltlen); | ||
| 77 | else pbe = PKCS5_pbe_set(pbe_nid, iter, salt, saltlen); | ||
| 78 | if(!pbe) { | ||
| 79 | PKCS12err(PKCS12_F_PKCS8_ENCRYPT, ERR_R_ASN1_LIB); | ||
| 80 | goto err; | ||
| 81 | } | ||
| 82 | X509_ALGOR_free(p8->algor); | ||
| 83 | p8->algor = pbe; | ||
| 84 | M_ASN1_OCTET_STRING_free(p8->digest); | ||
| 85 | p8->digest = PKCS12_item_i2d_encrypt(pbe, ASN1_ITEM_rptr(PKCS8_PRIV_KEY_INFO), | ||
| 86 | pass, passlen, p8inf, 1); | ||
| 87 | if(!p8->digest) { | ||
| 88 | PKCS12err(PKCS12_F_PKCS8_ENCRYPT, PKCS12_R_ENCRYPT_ERROR); | ||
| 89 | goto err; | ||
| 90 | } | ||
| 91 | |||
| 92 | return p8; | ||
| 93 | |||
| 94 | err: | ||
| 95 | X509_SIG_free(p8); | ||
| 96 | return NULL; | ||
| 97 | } | ||
diff --git a/src/lib/libcrypto/pkcs12/p12_utl.c b/src/lib/libcrypto/pkcs12/p12_utl.c new file mode 100644 index 0000000000..243ec76be9 --- /dev/null +++ b/src/lib/libcrypto/pkcs12/p12_utl.c | |||
| @@ -0,0 +1,146 @@ | |||
| 1 | /* p12_utl.c */ | ||
| 2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
| 3 | * project 1999. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/pkcs12.h> | ||
| 62 | |||
| 63 | /* Cheap and nasty Unicode stuff */ | ||
| 64 | |||
| 65 | unsigned char *asc2uni(const char *asc, int asclen, unsigned char **uni, int *unilen) | ||
| 66 | { | ||
| 67 | int ulen, i; | ||
| 68 | unsigned char *unitmp; | ||
| 69 | if (asclen == -1) asclen = strlen(asc); | ||
| 70 | ulen = asclen*2 + 2; | ||
| 71 | if (!(unitmp = OPENSSL_malloc(ulen))) return NULL; | ||
| 72 | for (i = 0; i < ulen - 2; i+=2) { | ||
| 73 | unitmp[i] = 0; | ||
| 74 | unitmp[i + 1] = asc[i>>1]; | ||
| 75 | } | ||
| 76 | /* Make result double null terminated */ | ||
| 77 | unitmp[ulen - 2] = 0; | ||
| 78 | unitmp[ulen - 1] = 0; | ||
| 79 | if (unilen) *unilen = ulen; | ||
| 80 | if (uni) *uni = unitmp; | ||
| 81 | return unitmp; | ||
| 82 | } | ||
| 83 | |||
| 84 | char *uni2asc(unsigned char *uni, int unilen) | ||
| 85 | { | ||
| 86 | int asclen, i; | ||
| 87 | char *asctmp; | ||
| 88 | asclen = unilen / 2; | ||
| 89 | /* If no terminating zero allow for one */ | ||
| 90 | if (!unilen || uni[unilen - 1]) asclen++; | ||
| 91 | uni++; | ||
| 92 | if (!(asctmp = OPENSSL_malloc(asclen))) return NULL; | ||
| 93 | for (i = 0; i < unilen; i+=2) asctmp[i>>1] = uni[i]; | ||
| 94 | asctmp[asclen - 1] = 0; | ||
| 95 | return asctmp; | ||
| 96 | } | ||
| 97 | |||
| 98 | int i2d_PKCS12_bio(BIO *bp, PKCS12 *p12) | ||
| 99 | { | ||
| 100 | return ASN1_item_i2d_bio(ASN1_ITEM_rptr(PKCS12), bp, p12); | ||
| 101 | } | ||
| 102 | |||
| 103 | #ifndef OPENSSL_NO_FP_API | ||
| 104 | int i2d_PKCS12_fp(FILE *fp, PKCS12 *p12) | ||
| 105 | { | ||
| 106 | return ASN1_item_i2d_fp(ASN1_ITEM_rptr(PKCS12), fp, p12); | ||
| 107 | } | ||
| 108 | #endif | ||
| 109 | |||
| 110 | PKCS12 *d2i_PKCS12_bio(BIO *bp, PKCS12 **p12) | ||
| 111 | { | ||
| 112 | return ASN1_item_d2i_bio(ASN1_ITEM_rptr(PKCS12), bp, p12); | ||
| 113 | } | ||
| 114 | #ifndef OPENSSL_NO_FP_API | ||
| 115 | PKCS12 *d2i_PKCS12_fp(FILE *fp, PKCS12 **p12) | ||
| 116 | { | ||
| 117 | return ASN1_item_d2i_fp(ASN1_ITEM_rptr(PKCS12), fp, p12); | ||
| 118 | } | ||
| 119 | #endif | ||
| 120 | |||
| 121 | PKCS12_SAFEBAG *PKCS12_x5092certbag(X509 *x509) | ||
| 122 | { | ||
| 123 | return PKCS12_item_pack_safebag(x509, ASN1_ITEM_rptr(X509), | ||
| 124 | NID_x509Certificate, NID_certBag); | ||
| 125 | } | ||
| 126 | |||
| 127 | PKCS12_SAFEBAG *PKCS12_x509crl2certbag(X509_CRL *crl) | ||
| 128 | { | ||
| 129 | return PKCS12_item_pack_safebag(crl, ASN1_ITEM_rptr(X509_CRL), | ||
| 130 | NID_x509Crl, NID_crlBag); | ||
| 131 | } | ||
| 132 | |||
| 133 | X509 *PKCS12_certbag2x509(PKCS12_SAFEBAG *bag) | ||
| 134 | { | ||
| 135 | if(M_PKCS12_bag_type(bag) != NID_certBag) return NULL; | ||
| 136 | if(M_PKCS12_cert_bag_type(bag) != NID_x509Certificate) return NULL; | ||
| 137 | return ASN1_item_unpack(bag->value.bag->value.octet, ASN1_ITEM_rptr(X509)); | ||
| 138 | } | ||
| 139 | |||
| 140 | X509_CRL *PKCS12_certbag2x509crl(PKCS12_SAFEBAG *bag) | ||
| 141 | { | ||
| 142 | if(M_PKCS12_bag_type(bag) != NID_crlBag) return NULL; | ||
| 143 | if(M_PKCS12_cert_bag_type(bag) != NID_x509Crl) return NULL; | ||
| 144 | return ASN1_item_unpack(bag->value.bag->value.octet, | ||
| 145 | ASN1_ITEM_rptr(X509_CRL)); | ||
| 146 | } | ||
diff --git a/src/lib/libcrypto/pkcs12/pk12err.c b/src/lib/libcrypto/pkcs12/pk12err.c new file mode 100644 index 0000000000..a33b37b1c7 --- /dev/null +++ b/src/lib/libcrypto/pkcs12/pk12err.c | |||
| @@ -0,0 +1,146 @@ | |||
| 1 | /* crypto/pkcs12/pk12err.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/pkcs12.h> | ||
| 64 | |||
| 65 | /* BEGIN ERROR CODES */ | ||
| 66 | #ifndef OPENSSL_NO_ERR | ||
| 67 | |||
| 68 | #define ERR_FUNC(func) ERR_PACK(ERR_LIB_PKCS12,func,0) | ||
| 69 | #define ERR_REASON(reason) ERR_PACK(ERR_LIB_PKCS12,0,reason) | ||
| 70 | |||
| 71 | static ERR_STRING_DATA PKCS12_str_functs[]= | ||
| 72 | { | ||
| 73 | {ERR_FUNC(PKCS12_F_PARSE_BAGS), "PARSE_BAGS"}, | ||
| 74 | {ERR_FUNC(PKCS12_F_PKCS12_ADD_FRIENDLYNAME), "PKCS12_ADD_FRIENDLYNAME"}, | ||
| 75 | {ERR_FUNC(PKCS12_F_PKCS12_ADD_FRIENDLYNAME_ASC), "PKCS12_add_friendlyname_asc"}, | ||
| 76 | {ERR_FUNC(PKCS12_F_PKCS12_ADD_FRIENDLYNAME_UNI), "PKCS12_add_friendlyname_uni"}, | ||
| 77 | {ERR_FUNC(PKCS12_F_PKCS12_ADD_LOCALKEYID), "PKCS12_add_localkeyid"}, | ||
| 78 | {ERR_FUNC(PKCS12_F_PKCS12_CREATE), "PKCS12_create"}, | ||
| 79 | {ERR_FUNC(PKCS12_F_PKCS12_DECRYPT_D2I), "PKCS12_DECRYPT_D2I"}, | ||
| 80 | {ERR_FUNC(PKCS12_F_PKCS12_GEN_MAC), "PKCS12_gen_mac"}, | ||
| 81 | {ERR_FUNC(PKCS12_F_PKCS12_I2D_ENCRYPT), "PKCS12_I2D_ENCRYPT"}, | ||
| 82 | {ERR_FUNC(PKCS12_F_PKCS12_INIT), "PKCS12_init"}, | ||
| 83 | {ERR_FUNC(PKCS12_F_PKCS12_KEY_GEN_ASC), "PKCS12_key_gen_asc"}, | ||
| 84 | {ERR_FUNC(PKCS12_F_PKCS12_KEY_GEN_UNI), "PKCS12_key_gen_uni"}, | ||
| 85 | {ERR_FUNC(PKCS12_F_PKCS12_MAKE_KEYBAG), "PKCS12_MAKE_KEYBAG"}, | ||
| 86 | {ERR_FUNC(PKCS12_F_PKCS12_MAKE_SHKEYBAG), "PKCS12_MAKE_SHKEYBAG"}, | ||
| 87 | {ERR_FUNC(PKCS12_F_PKCS12_NEWPASS), "PKCS12_newpass"}, | ||
| 88 | {ERR_FUNC(PKCS12_F_PKCS12_PACK_P7DATA), "PKCS12_pack_p7data"}, | ||
| 89 | {ERR_FUNC(PKCS12_F_PKCS12_PACK_P7ENCDATA), "PKCS12_pack_p7encdata"}, | ||
| 90 | {ERR_FUNC(PKCS12_F_PKCS12_PACK_SAFEBAG), "PKCS12_PACK_SAFEBAG"}, | ||
| 91 | {ERR_FUNC(PKCS12_F_PKCS12_PARSE), "PKCS12_parse"}, | ||
| 92 | {ERR_FUNC(PKCS12_F_PKCS12_PBE_CRYPT), "PKCS12_pbe_crypt"}, | ||
| 93 | {ERR_FUNC(PKCS12_F_PKCS12_PBE_KEYIVGEN), "PKCS12_PBE_keyivgen"}, | ||
| 94 | {ERR_FUNC(PKCS12_F_PKCS12_SETUP_MAC), "PKCS12_setup_mac"}, | ||
| 95 | {ERR_FUNC(PKCS12_F_PKCS12_SET_MAC), "PKCS12_set_mac"}, | ||
| 96 | {ERR_FUNC(PKCS12_F_PKCS12_UNPACK_AUTHSAFES), "PKCS12_unpack_authsafes"}, | ||
| 97 | {ERR_FUNC(PKCS12_F_PKCS12_UNPACK_P7DATA), "PKCS12_unpack_p7data"}, | ||
| 98 | {ERR_FUNC(PKCS12_F_PKCS8_ADD_KEYUSAGE), "PKCS8_add_keyusage"}, | ||
| 99 | {ERR_FUNC(PKCS12_F_PKCS8_ENCRYPT), "PKCS8_encrypt"}, | ||
| 100 | {ERR_FUNC(PKCS12_F_VERIFY_MAC), "VERIFY_MAC"}, | ||
| 101 | {0,NULL} | ||
| 102 | }; | ||
| 103 | |||
| 104 | static ERR_STRING_DATA PKCS12_str_reasons[]= | ||
| 105 | { | ||
| 106 | {ERR_REASON(PKCS12_R_CANT_PACK_STRUCTURE),"cant pack structure"}, | ||
| 107 | {ERR_REASON(PKCS12_R_CONTENT_TYPE_NOT_DATA),"content type not data"}, | ||
| 108 | {ERR_REASON(PKCS12_R_DECODE_ERROR) ,"decode error"}, | ||
| 109 | {ERR_REASON(PKCS12_R_ENCODE_ERROR) ,"encode error"}, | ||
| 110 | {ERR_REASON(PKCS12_R_ENCRYPT_ERROR) ,"encrypt error"}, | ||
| 111 | {ERR_REASON(PKCS12_R_ERROR_SETTING_ENCRYPTED_DATA_TYPE),"error setting encrypted data type"}, | ||
| 112 | {ERR_REASON(PKCS12_R_INVALID_NULL_ARGUMENT),"invalid null argument"}, | ||
| 113 | {ERR_REASON(PKCS12_R_INVALID_NULL_PKCS12_POINTER),"invalid null pkcs12 pointer"}, | ||
| 114 | {ERR_REASON(PKCS12_R_IV_GEN_ERROR) ,"iv gen error"}, | ||
| 115 | {ERR_REASON(PKCS12_R_KEY_GEN_ERROR) ,"key gen error"}, | ||
| 116 | {ERR_REASON(PKCS12_R_MAC_ABSENT) ,"mac absent"}, | ||
| 117 | {ERR_REASON(PKCS12_R_MAC_GENERATION_ERROR),"mac generation error"}, | ||
| 118 | {ERR_REASON(PKCS12_R_MAC_SETUP_ERROR) ,"mac setup error"}, | ||
| 119 | {ERR_REASON(PKCS12_R_MAC_STRING_SET_ERROR),"mac string set error"}, | ||
| 120 | {ERR_REASON(PKCS12_R_MAC_VERIFY_ERROR) ,"mac verify error"}, | ||
| 121 | {ERR_REASON(PKCS12_R_MAC_VERIFY_FAILURE) ,"mac verify failure"}, | ||
| 122 | {ERR_REASON(PKCS12_R_PARSE_ERROR) ,"parse error"}, | ||
| 123 | {ERR_REASON(PKCS12_R_PKCS12_ALGOR_CIPHERINIT_ERROR),"pkcs12 algor cipherinit error"}, | ||
| 124 | {ERR_REASON(PKCS12_R_PKCS12_CIPHERFINAL_ERROR),"pkcs12 cipherfinal error"}, | ||
| 125 | {ERR_REASON(PKCS12_R_PKCS12_PBE_CRYPT_ERROR),"pkcs12 pbe crypt error"}, | ||
| 126 | {ERR_REASON(PKCS12_R_UNKNOWN_DIGEST_ALGORITHM),"unknown digest algorithm"}, | ||
| 127 | {ERR_REASON(PKCS12_R_UNSUPPORTED_PKCS12_MODE),"unsupported pkcs12 mode"}, | ||
| 128 | {0,NULL} | ||
| 129 | }; | ||
| 130 | |||
| 131 | #endif | ||
| 132 | |||
| 133 | void ERR_load_PKCS12_strings(void) | ||
| 134 | { | ||
| 135 | static int init=1; | ||
| 136 | |||
| 137 | if (init) | ||
| 138 | { | ||
| 139 | init=0; | ||
| 140 | #ifndef OPENSSL_NO_ERR | ||
| 141 | ERR_load_strings(0,PKCS12_str_functs); | ||
| 142 | ERR_load_strings(0,PKCS12_str_reasons); | ||
| 143 | #endif | ||
| 144 | |||
| 145 | } | ||
| 146 | } | ||
diff --git a/src/lib/libcrypto/pkcs12/pkcs12.h b/src/lib/libcrypto/pkcs12/pkcs12.h new file mode 100644 index 0000000000..fb8af82d4f --- /dev/null +++ b/src/lib/libcrypto/pkcs12/pkcs12.h | |||
| @@ -0,0 +1,323 @@ | |||
| 1 | /* pkcs12.h */ | ||
| 2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
| 3 | * project 1999. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | #ifndef HEADER_PKCS12_H | ||
| 60 | #define HEADER_PKCS12_H | ||
| 61 | |||
| 62 | #include <openssl/bio.h> | ||
| 63 | #include <openssl/x509.h> | ||
| 64 | |||
| 65 | #ifdef __cplusplus | ||
| 66 | extern "C" { | ||
| 67 | #endif | ||
| 68 | |||
| 69 | #define PKCS12_KEY_ID 1 | ||
| 70 | #define PKCS12_IV_ID 2 | ||
| 71 | #define PKCS12_MAC_ID 3 | ||
| 72 | |||
| 73 | /* Default iteration count */ | ||
| 74 | #ifndef PKCS12_DEFAULT_ITER | ||
| 75 | #define PKCS12_DEFAULT_ITER PKCS5_DEFAULT_ITER | ||
| 76 | #endif | ||
| 77 | |||
| 78 | #define PKCS12_MAC_KEY_LENGTH 20 | ||
| 79 | |||
| 80 | #define PKCS12_SALT_LEN 8 | ||
| 81 | |||
| 82 | /* Uncomment out next line for unicode password and names, otherwise ASCII */ | ||
| 83 | |||
| 84 | /*#define PBE_UNICODE*/ | ||
| 85 | |||
| 86 | #ifdef PBE_UNICODE | ||
| 87 | #define PKCS12_key_gen PKCS12_key_gen_uni | ||
| 88 | #define PKCS12_add_friendlyname PKCS12_add_friendlyname_uni | ||
| 89 | #else | ||
| 90 | #define PKCS12_key_gen PKCS12_key_gen_asc | ||
| 91 | #define PKCS12_add_friendlyname PKCS12_add_friendlyname_asc | ||
| 92 | #endif | ||
| 93 | |||
| 94 | /* MS key usage constants */ | ||
| 95 | |||
| 96 | #define KEY_EX 0x10 | ||
| 97 | #define KEY_SIG 0x80 | ||
| 98 | |||
| 99 | typedef struct { | ||
| 100 | X509_SIG *dinfo; | ||
| 101 | ASN1_OCTET_STRING *salt; | ||
| 102 | ASN1_INTEGER *iter; /* defaults to 1 */ | ||
| 103 | } PKCS12_MAC_DATA; | ||
| 104 | |||
| 105 | typedef struct { | ||
| 106 | ASN1_INTEGER *version; | ||
| 107 | PKCS12_MAC_DATA *mac; | ||
| 108 | PKCS7 *authsafes; | ||
| 109 | } PKCS12; | ||
| 110 | |||
| 111 | PREDECLARE_STACK_OF(PKCS12_SAFEBAG) | ||
| 112 | |||
| 113 | typedef struct { | ||
| 114 | ASN1_OBJECT *type; | ||
| 115 | union { | ||
| 116 | struct pkcs12_bag_st *bag; /* secret, crl and certbag */ | ||
| 117 | struct pkcs8_priv_key_info_st *keybag; /* keybag */ | ||
| 118 | X509_SIG *shkeybag; /* shrouded key bag */ | ||
| 119 | STACK_OF(PKCS12_SAFEBAG) *safes; | ||
| 120 | ASN1_TYPE *other; | ||
| 121 | }value; | ||
| 122 | STACK_OF(X509_ATTRIBUTE) *attrib; | ||
| 123 | } PKCS12_SAFEBAG; | ||
| 124 | |||
| 125 | DECLARE_STACK_OF(PKCS12_SAFEBAG) | ||
| 126 | DECLARE_ASN1_SET_OF(PKCS12_SAFEBAG) | ||
| 127 | DECLARE_PKCS12_STACK_OF(PKCS12_SAFEBAG) | ||
| 128 | |||
| 129 | typedef struct pkcs12_bag_st { | ||
| 130 | ASN1_OBJECT *type; | ||
| 131 | union { | ||
| 132 | ASN1_OCTET_STRING *x509cert; | ||
| 133 | ASN1_OCTET_STRING *x509crl; | ||
| 134 | ASN1_OCTET_STRING *octet; | ||
| 135 | ASN1_IA5STRING *sdsicert; | ||
| 136 | ASN1_TYPE *other; /* Secret or other bag */ | ||
| 137 | }value; | ||
| 138 | } PKCS12_BAGS; | ||
| 139 | |||
| 140 | #define PKCS12_ERROR 0 | ||
| 141 | #define PKCS12_OK 1 | ||
| 142 | |||
| 143 | /* Compatibility macros */ | ||
| 144 | |||
| 145 | #define M_PKCS12_x5092certbag PKCS12_x5092certbag | ||
| 146 | #define M_PKCS12_x509crl2certbag PKCS12_x509crl2certbag | ||
| 147 | |||
| 148 | #define M_PKCS12_certbag2x509 PKCS12_certbag2x509 | ||
| 149 | #define M_PKCS12_certbag2x509crl PKCS12_certbag2x509crl | ||
| 150 | |||
| 151 | #define M_PKCS12_unpack_p7data PKCS12_unpack_p7data | ||
| 152 | #define M_PKCS12_pack_authsafes PKCS12_pack_authsafes | ||
| 153 | #define M_PKCS12_unpack_authsafes PKCS12_unpack_authsafes | ||
| 154 | #define M_PKCS12_unpack_p7encdata PKCS12_unpack_p7encdata | ||
| 155 | |||
| 156 | #define M_PKCS12_decrypt_skey PKCS12_decrypt_skey | ||
| 157 | #define M_PKCS8_decrypt PKCS8_decrypt | ||
| 158 | |||
| 159 | #define M_PKCS12_bag_type(bg) OBJ_obj2nid((bg)->type) | ||
| 160 | #define M_PKCS12_cert_bag_type(bg) OBJ_obj2nid((bg)->value.bag->type) | ||
| 161 | #define M_PKCS12_crl_bag_type M_PKCS12_cert_bag_type | ||
| 162 | |||
| 163 | #define PKCS12_get_attr(bag, attr_nid) \ | ||
| 164 | PKCS12_get_attr_gen(bag->attrib, attr_nid) | ||
| 165 | |||
| 166 | #define PKCS8_get_attr(p8, attr_nid) \ | ||
| 167 | PKCS12_get_attr_gen(p8->attributes, attr_nid) | ||
| 168 | |||
| 169 | #define PKCS12_mac_present(p12) ((p12)->mac ? 1 : 0) | ||
| 170 | |||
| 171 | |||
| 172 | PKCS12_SAFEBAG *PKCS12_x5092certbag(X509 *x509); | ||
| 173 | PKCS12_SAFEBAG *PKCS12_x509crl2certbag(X509_CRL *crl); | ||
| 174 | X509 *PKCS12_certbag2x509(PKCS12_SAFEBAG *bag); | ||
| 175 | X509_CRL *PKCS12_certbag2x509crl(PKCS12_SAFEBAG *bag); | ||
| 176 | |||
| 177 | PKCS12_SAFEBAG *PKCS12_item_pack_safebag(void *obj, const ASN1_ITEM *it, int nid1, | ||
| 178 | int nid2); | ||
| 179 | PKCS12_SAFEBAG *PKCS12_MAKE_KEYBAG(PKCS8_PRIV_KEY_INFO *p8); | ||
| 180 | PKCS8_PRIV_KEY_INFO *PKCS8_decrypt(X509_SIG *p8, const char *pass, int passlen); | ||
| 181 | PKCS8_PRIV_KEY_INFO *PKCS12_decrypt_skey(PKCS12_SAFEBAG *bag, const char *pass, | ||
| 182 | int passlen); | ||
| 183 | X509_SIG *PKCS8_encrypt(int pbe_nid, const EVP_CIPHER *cipher, | ||
| 184 | const char *pass, int passlen, | ||
| 185 | unsigned char *salt, int saltlen, int iter, | ||
| 186 | PKCS8_PRIV_KEY_INFO *p8); | ||
| 187 | PKCS12_SAFEBAG *PKCS12_MAKE_SHKEYBAG(int pbe_nid, const char *pass, | ||
| 188 | int passlen, unsigned char *salt, | ||
| 189 | int saltlen, int iter, | ||
| 190 | PKCS8_PRIV_KEY_INFO *p8); | ||
| 191 | PKCS7 *PKCS12_pack_p7data(STACK_OF(PKCS12_SAFEBAG) *sk); | ||
| 192 | STACK_OF(PKCS12_SAFEBAG) *PKCS12_unpack_p7data(PKCS7 *p7); | ||
| 193 | PKCS7 *PKCS12_pack_p7encdata(int pbe_nid, const char *pass, int passlen, | ||
| 194 | unsigned char *salt, int saltlen, int iter, | ||
| 195 | STACK_OF(PKCS12_SAFEBAG) *bags); | ||
| 196 | STACK_OF(PKCS12_SAFEBAG) *PKCS12_unpack_p7encdata(PKCS7 *p7, const char *pass, int passlen); | ||
| 197 | |||
| 198 | int PKCS12_pack_authsafes(PKCS12 *p12, STACK_OF(PKCS7) *safes); | ||
| 199 | STACK_OF(PKCS7) *PKCS12_unpack_authsafes(PKCS12 *p12); | ||
| 200 | |||
| 201 | int PKCS12_add_localkeyid(PKCS12_SAFEBAG *bag, unsigned char *name, int namelen); | ||
| 202 | int PKCS12_add_friendlyname_asc(PKCS12_SAFEBAG *bag, const char *name, | ||
| 203 | int namelen); | ||
| 204 | int PKCS12_add_CSPName_asc(PKCS12_SAFEBAG *bag, const char *name, | ||
| 205 | int namelen); | ||
| 206 | int PKCS12_add_friendlyname_uni(PKCS12_SAFEBAG *bag, const unsigned char *name, | ||
| 207 | int namelen); | ||
| 208 | int PKCS8_add_keyusage(PKCS8_PRIV_KEY_INFO *p8, int usage); | ||
| 209 | ASN1_TYPE *PKCS12_get_attr_gen(STACK_OF(X509_ATTRIBUTE) *attrs, int attr_nid); | ||
| 210 | char *PKCS12_get_friendlyname(PKCS12_SAFEBAG *bag); | ||
| 211 | unsigned char *PKCS12_pbe_crypt(X509_ALGOR *algor, const char *pass, | ||
| 212 | int passlen, unsigned char *in, int inlen, | ||
| 213 | unsigned char **data, int *datalen, int en_de); | ||
| 214 | void * PKCS12_item_decrypt_d2i(X509_ALGOR *algor, const ASN1_ITEM *it, | ||
| 215 | const char *pass, int passlen, ASN1_OCTET_STRING *oct, int zbuf); | ||
| 216 | ASN1_OCTET_STRING *PKCS12_item_i2d_encrypt(X509_ALGOR *algor, const ASN1_ITEM *it, | ||
| 217 | const char *pass, int passlen, | ||
| 218 | void *obj, int zbuf); | ||
| 219 | PKCS12 *PKCS12_init(int mode); | ||
| 220 | int PKCS12_key_gen_asc(const char *pass, int passlen, unsigned char *salt, | ||
| 221 | int saltlen, int id, int iter, int n, | ||
| 222 | unsigned char *out, const EVP_MD *md_type); | ||
| 223 | int PKCS12_key_gen_uni(unsigned char *pass, int passlen, unsigned char *salt, int saltlen, int id, int iter, int n, unsigned char *out, const EVP_MD *md_type); | ||
| 224 | int PKCS12_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen, | ||
| 225 | ASN1_TYPE *param, const EVP_CIPHER *cipher, const EVP_MD *md_type, | ||
| 226 | int en_de); | ||
| 227 | int PKCS12_gen_mac(PKCS12 *p12, const char *pass, int passlen, | ||
| 228 | unsigned char *mac, unsigned int *maclen); | ||
| 229 | int PKCS12_verify_mac(PKCS12 *p12, const char *pass, int passlen); | ||
| 230 | int PKCS12_set_mac(PKCS12 *p12, const char *pass, int passlen, | ||
| 231 | unsigned char *salt, int saltlen, int iter, | ||
| 232 | const EVP_MD *md_type); | ||
| 233 | int PKCS12_setup_mac(PKCS12 *p12, int iter, unsigned char *salt, | ||
| 234 | int saltlen, const EVP_MD *md_type); | ||
| 235 | unsigned char *asc2uni(const char *asc, int asclen, unsigned char **uni, int *unilen); | ||
| 236 | char *uni2asc(unsigned char *uni, int unilen); | ||
| 237 | |||
| 238 | DECLARE_ASN1_FUNCTIONS(PKCS12) | ||
| 239 | DECLARE_ASN1_FUNCTIONS(PKCS12_MAC_DATA) | ||
| 240 | DECLARE_ASN1_FUNCTIONS(PKCS12_SAFEBAG) | ||
| 241 | DECLARE_ASN1_FUNCTIONS(PKCS12_BAGS) | ||
| 242 | |||
| 243 | DECLARE_ASN1_ITEM(PKCS12_SAFEBAGS) | ||
| 244 | DECLARE_ASN1_ITEM(PKCS12_AUTHSAFES) | ||
| 245 | |||
| 246 | void PKCS12_PBE_add(void); | ||
| 247 | int PKCS12_parse(PKCS12 *p12, const char *pass, EVP_PKEY **pkey, X509 **cert, | ||
| 248 | STACK_OF(X509) **ca); | ||
| 249 | PKCS12 *PKCS12_create(char *pass, char *name, EVP_PKEY *pkey, X509 *cert, | ||
| 250 | STACK_OF(X509) *ca, int nid_key, int nid_cert, int iter, | ||
| 251 | int mac_iter, int keytype); | ||
| 252 | int i2d_PKCS12_bio(BIO *bp, PKCS12 *p12); | ||
| 253 | int i2d_PKCS12_fp(FILE *fp, PKCS12 *p12); | ||
| 254 | PKCS12 *d2i_PKCS12_bio(BIO *bp, PKCS12 **p12); | ||
| 255 | PKCS12 *d2i_PKCS12_fp(FILE *fp, PKCS12 **p12); | ||
| 256 | int PKCS12_newpass(PKCS12 *p12, char *oldpass, char *newpass); | ||
| 257 | |||
| 258 | /* BEGIN ERROR CODES */ | ||
| 259 | /* The following lines are auto generated by the script mkerr.pl. Any changes | ||
| 260 | * made after this point may be overwritten when the script is next run. | ||
| 261 | */ | ||
| 262 | void ERR_load_PKCS12_strings(void); | ||
| 263 | |||
| 264 | /* Error codes for the PKCS12 functions. */ | ||
| 265 | |||
| 266 | /* Function codes. */ | ||
| 267 | #define PKCS12_F_PARSE_BAGS 103 | ||
| 268 | #define PKCS12_F_PKCS12_ADD_FRIENDLYNAME 100 | ||
| 269 | #define PKCS12_F_PKCS12_ADD_FRIENDLYNAME_ASC 127 | ||
| 270 | #define PKCS12_F_PKCS12_ADD_FRIENDLYNAME_UNI 102 | ||
| 271 | #define PKCS12_F_PKCS12_ADD_LOCALKEYID 104 | ||
| 272 | #define PKCS12_F_PKCS12_CREATE 105 | ||
| 273 | #define PKCS12_F_PKCS12_DECRYPT_D2I 106 | ||
| 274 | #define PKCS12_F_PKCS12_GEN_MAC 107 | ||
| 275 | #define PKCS12_F_PKCS12_I2D_ENCRYPT 108 | ||
| 276 | #define PKCS12_F_PKCS12_INIT 109 | ||
| 277 | #define PKCS12_F_PKCS12_KEY_GEN_ASC 110 | ||
| 278 | #define PKCS12_F_PKCS12_KEY_GEN_UNI 111 | ||
| 279 | #define PKCS12_F_PKCS12_MAKE_KEYBAG 112 | ||
| 280 | #define PKCS12_F_PKCS12_MAKE_SHKEYBAG 113 | ||
| 281 | #define PKCS12_F_PKCS12_NEWPASS 128 | ||
| 282 | #define PKCS12_F_PKCS12_PACK_P7DATA 114 | ||
| 283 | #define PKCS12_F_PKCS12_PACK_P7ENCDATA 115 | ||
| 284 | #define PKCS12_F_PKCS12_PACK_SAFEBAG 117 | ||
| 285 | #define PKCS12_F_PKCS12_PARSE 118 | ||
| 286 | #define PKCS12_F_PKCS12_PBE_CRYPT 119 | ||
| 287 | #define PKCS12_F_PKCS12_PBE_KEYIVGEN 120 | ||
| 288 | #define PKCS12_F_PKCS12_SETUP_MAC 122 | ||
| 289 | #define PKCS12_F_PKCS12_SET_MAC 123 | ||
| 290 | #define PKCS12_F_PKCS12_UNPACK_AUTHSAFES 129 | ||
| 291 | #define PKCS12_F_PKCS12_UNPACK_P7DATA 130 | ||
| 292 | #define PKCS12_F_PKCS8_ADD_KEYUSAGE 124 | ||
| 293 | #define PKCS12_F_PKCS8_ENCRYPT 125 | ||
| 294 | #define PKCS12_F_VERIFY_MAC 126 | ||
| 295 | |||
| 296 | /* Reason codes. */ | ||
| 297 | #define PKCS12_R_CANT_PACK_STRUCTURE 100 | ||
| 298 | #define PKCS12_R_CONTENT_TYPE_NOT_DATA 121 | ||
| 299 | #define PKCS12_R_DECODE_ERROR 101 | ||
| 300 | #define PKCS12_R_ENCODE_ERROR 102 | ||
| 301 | #define PKCS12_R_ENCRYPT_ERROR 103 | ||
| 302 | #define PKCS12_R_ERROR_SETTING_ENCRYPTED_DATA_TYPE 120 | ||
| 303 | #define PKCS12_R_INVALID_NULL_ARGUMENT 104 | ||
| 304 | #define PKCS12_R_INVALID_NULL_PKCS12_POINTER 105 | ||
| 305 | #define PKCS12_R_IV_GEN_ERROR 106 | ||
| 306 | #define PKCS12_R_KEY_GEN_ERROR 107 | ||
| 307 | #define PKCS12_R_MAC_ABSENT 108 | ||
| 308 | #define PKCS12_R_MAC_GENERATION_ERROR 109 | ||
| 309 | #define PKCS12_R_MAC_SETUP_ERROR 110 | ||
| 310 | #define PKCS12_R_MAC_STRING_SET_ERROR 111 | ||
| 311 | #define PKCS12_R_MAC_VERIFY_ERROR 112 | ||
| 312 | #define PKCS12_R_MAC_VERIFY_FAILURE 113 | ||
| 313 | #define PKCS12_R_PARSE_ERROR 114 | ||
| 314 | #define PKCS12_R_PKCS12_ALGOR_CIPHERINIT_ERROR 115 | ||
| 315 | #define PKCS12_R_PKCS12_CIPHERFINAL_ERROR 116 | ||
| 316 | #define PKCS12_R_PKCS12_PBE_CRYPT_ERROR 117 | ||
| 317 | #define PKCS12_R_UNKNOWN_DIGEST_ALGORITHM 118 | ||
| 318 | #define PKCS12_R_UNSUPPORTED_PKCS12_MODE 119 | ||
| 319 | |||
| 320 | #ifdef __cplusplus | ||
| 321 | } | ||
| 322 | #endif | ||
| 323 | #endif | ||
