summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/pem
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/pem')
-rw-r--r--src/lib/libcrypto/pem/Makefile.ssl2
-rw-r--r--src/lib/libcrypto/pem/pem.h8
-rw-r--r--src/lib/libcrypto/pem/pem_info.c5
-rw-r--r--src/lib/libcrypto/pem/pem_lib.c26
-rw-r--r--src/lib/libcrypto/pem/pem_pk8.c2
-rw-r--r--src/lib/libcrypto/pem/pem_seal.c2
6 files changed, 26 insertions, 19 deletions
diff --git a/src/lib/libcrypto/pem/Makefile.ssl b/src/lib/libcrypto/pem/Makefile.ssl
index 5075d9107b..d3043eb401 100644
--- a/src/lib/libcrypto/pem/Makefile.ssl
+++ b/src/lib/libcrypto/pem/Makefile.ssl
@@ -71,7 +71,7 @@ lint:
71 lint -DLINT $(INCLUDES) $(SRC)>fluff 71 lint -DLINT $(INCLUDES) $(SRC)>fluff
72 72
73depend: 73depend:
74 $(MAKEDEPEND) $(CFLAG) $(INCLUDES) $(DEPFLAG) $(LIBSRC) 74 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(LIBSRC)
75 75
76dclean: 76dclean:
77 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new 77 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
diff --git a/src/lib/libcrypto/pem/pem.h b/src/lib/libcrypto/pem/pem.h
index 3785fca77d..d330cbf9a3 100644
--- a/src/lib/libcrypto/pem/pem.h
+++ b/src/lib/libcrypto/pem/pem.h
@@ -149,7 +149,7 @@ typedef struct pem_recip_st
149 149
150 int cipher; 150 int cipher;
151 int key_enc; 151 int key_enc;
152 char iv[8]; 152 /* char iv[8]; unused and wrong size */
153 } PEM_USER; 153 } PEM_USER;
154 154
155typedef struct pem_ctx_st 155typedef struct pem_ctx_st
@@ -165,7 +165,8 @@ typedef struct pem_ctx_st
165 165
166 struct { 166 struct {
167 int cipher; 167 int cipher;
168 unsigned char iv[8]; 168 /* unused, and wrong size
169 unsigned char iv[8]; */
169 } DEK_info; 170 } DEK_info;
170 171
171 PEM_USER *originator; 172 PEM_USER *originator;
@@ -187,7 +188,8 @@ typedef struct pem_ctx_st
187 EVP_CIPHER *dec; /* date encryption cipher */ 188 EVP_CIPHER *dec; /* date encryption cipher */
188 int key_len; /* key length */ 189 int key_len; /* key length */
189 unsigned char *key; /* key */ 190 unsigned char *key; /* key */
190 unsigned char iv[8]; /* the iv */ 191 /* unused, and wrong size
192 unsigned char iv[8]; */
191 193
192 194
193 int data_enc; /* is the data encrypted */ 195 int data_enc; /* is the data encrypted */
diff --git a/src/lib/libcrypto/pem/pem_info.c b/src/lib/libcrypto/pem/pem_info.c
index 9a6dffb45c..9e4af29c95 100644
--- a/src/lib/libcrypto/pem/pem_info.c
+++ b/src/lib/libcrypto/pem/pem_info.c
@@ -324,6 +324,7 @@ int PEM_X509_INFO_write_bio(BIO *bp, X509_INFO *xi, EVP_CIPHER *enc,
324 } 324 }
325 325
326 /* create the right magic header stuff */ 326 /* create the right magic header stuff */
327 OPENSSL_assert(strlen(objstr)+23+2*enc->iv_len+13 <= sizeof buf);
327 buf[0]='\0'; 328 buf[0]='\0';
328 PEM_proc_type(buf,PEM_TYPE_ENCRYPTED); 329 PEM_proc_type(buf,PEM_TYPE_ENCRYPTED);
329 PEM_dek_info(buf,objstr,enc->iv_len,(char *)iv); 330 PEM_dek_info(buf,objstr,enc->iv_len,(char *)iv);
@@ -358,7 +359,7 @@ int PEM_X509_INFO_write_bio(BIO *bp, X509_INFO *xi, EVP_CIPHER *enc,
358 ret=1; 359 ret=1;
359 360
360err: 361err:
361 memset((char *)&ctx,0,sizeof(ctx)); 362 OPENSSL_cleanse((char *)&ctx,sizeof(ctx));
362 memset(buf,0,PEM_BUFSIZE); 363 OPENSSL_cleanse(buf,PEM_BUFSIZE);
363 return(ret); 364 return(ret);
364 } 365 }
diff --git a/src/lib/libcrypto/pem/pem_lib.c b/src/lib/libcrypto/pem/pem_lib.c
index 50f5733654..3bec2d7e9f 100644
--- a/src/lib/libcrypto/pem/pem_lib.c
+++ b/src/lib/libcrypto/pem/pem_lib.c
@@ -138,7 +138,7 @@ void PEM_proc_type(char *buf, int type)
138 138
139void PEM_dek_info(char *buf, const char *type, int len, char *str) 139void PEM_dek_info(char *buf, const char *type, int len, char *str)
140 { 140 {
141 static unsigned char map[17]="0123456789ABCDEF"; 141 static const unsigned char map[17]="0123456789ABCDEF";
142 long i; 142 long i;
143 int j; 143 int j;
144 144
@@ -251,7 +251,7 @@ int PEM_bytes_read_bio(unsigned char **pdata, long *plen, char **pnm, const char
251 ret = 1; 251 ret = 1;
252 252
253err: 253err:
254 if (!pnm) OPENSSL_free(nm); 254 if (!ret || !pnm) OPENSSL_free(nm);
255 OPENSSL_free(header); 255 OPENSSL_free(header);
256 if (!ret) OPENSSL_free(data); 256 if (!ret) OPENSSL_free(data);
257 return ret; 257 return ret;
@@ -306,6 +306,7 @@ int PEM_ASN1_write_bio(int (*i2d)(), const char *name, BIO *bp, char *x,
306 goto err; 306 goto err;
307 } 307 }
308 /* dzise + 8 bytes are needed */ 308 /* dzise + 8 bytes are needed */
309 /* actually it needs the cipher block size extra... */
309 data=(unsigned char *)OPENSSL_malloc((unsigned int)dsize+20); 310 data=(unsigned char *)OPENSSL_malloc((unsigned int)dsize+20);
310 if (data == NULL) 311 if (data == NULL)
311 { 312 {
@@ -335,13 +336,16 @@ int PEM_ASN1_write_bio(int (*i2d)(), const char *name, BIO *bp, char *x,
335 kstr=(unsigned char *)buf; 336 kstr=(unsigned char *)buf;
336 } 337 }
337 RAND_add(data,i,0);/* put in the RSA key. */ 338 RAND_add(data,i,0);/* put in the RSA key. */
339 OPENSSL_assert(enc->iv_len <= sizeof iv);
338 if (RAND_pseudo_bytes(iv,enc->iv_len) < 0) /* Generate a salt */ 340 if (RAND_pseudo_bytes(iv,enc->iv_len) < 0) /* Generate a salt */
339 goto err; 341 goto err;
340 /* The 'iv' is used as the iv and as a salt. It is 342 /* The 'iv' is used as the iv and as a salt. It is
341 * NOT taken from the BytesToKey function */ 343 * NOT taken from the BytesToKey function */
342 EVP_BytesToKey(enc,EVP_md5(),iv,kstr,klen,1,key,NULL); 344 EVP_BytesToKey(enc,EVP_md5(),iv,kstr,klen,1,key,NULL);
343 345
344 if (kstr == (unsigned char *)buf) memset(buf,0,PEM_BUFSIZE); 346 if (kstr == (unsigned char *)buf) OPENSSL_cleanse(buf,PEM_BUFSIZE);
347
348 OPENSSL_assert(strlen(objstr)+23+2*enc->iv_len+13 <= sizeof buf);
345 349
346 buf[0]='\0'; 350 buf[0]='\0';
347 PEM_proc_type(buf,PEM_TYPE_ENCRYPTED); 351 PEM_proc_type(buf,PEM_TYPE_ENCRYPTED);
@@ -364,13 +368,13 @@ int PEM_ASN1_write_bio(int (*i2d)(), const char *name, BIO *bp, char *x,
364 i=PEM_write_bio(bp,name,buf,data,i); 368 i=PEM_write_bio(bp,name,buf,data,i);
365 if (i <= 0) ret=0; 369 if (i <= 0) ret=0;
366err: 370err:
367 memset(key,0,sizeof(key)); 371 OPENSSL_cleanse(key,sizeof(key));
368 memset(iv,0,sizeof(iv)); 372 OPENSSL_cleanse(iv,sizeof(iv));
369 memset((char *)&ctx,0,sizeof(ctx)); 373 OPENSSL_cleanse((char *)&ctx,sizeof(ctx));
370 memset(buf,0,PEM_BUFSIZE); 374 OPENSSL_cleanse(buf,PEM_BUFSIZE);
371 if (data != NULL) 375 if (data != NULL)
372 { 376 {
373 memset(data,0,(unsigned int)dsize); 377 OPENSSL_cleanse(data,(unsigned int)dsize);
374 OPENSSL_free(data); 378 OPENSSL_free(data);
375 } 379 }
376 return(ret); 380 return(ret);
@@ -411,8 +415,8 @@ int PEM_do_header(EVP_CIPHER_INFO *cipher, unsigned char *data, long *plen,
411 EVP_DecryptUpdate(&ctx,data,&i,data,j); 415 EVP_DecryptUpdate(&ctx,data,&i,data,j);
412 o=EVP_DecryptFinal_ex(&ctx,&(data[i]),&j); 416 o=EVP_DecryptFinal_ex(&ctx,&(data[i]),&j);
413 EVP_CIPHER_CTX_cleanup(&ctx); 417 EVP_CIPHER_CTX_cleanup(&ctx);
414 memset((char *)buf,0,sizeof(buf)); 418 OPENSSL_cleanse((char *)buf,sizeof(buf));
415 memset((char *)key,0,sizeof(key)); 419 OPENSSL_cleanse((char *)key,sizeof(key));
416 j+=i; 420 j+=i;
417 if (!o) 421 if (!o)
418 { 422 {
@@ -693,7 +697,7 @@ int PEM_read_bio(BIO *bp, char **name, char **header, unsigned char **data,
693 if (strncmp(buf,"-----END ",9) == 0) 697 if (strncmp(buf,"-----END ",9) == 0)
694 break; 698 break;
695 if (i > 65) break; 699 if (i > 65) break;
696 if (!BUF_MEM_grow(dataB,i+bl+9)) 700 if (!BUF_MEM_grow_clean(dataB,i+bl+9))
697 { 701 {
698 PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE); 702 PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE);
699 goto err; 703 goto err;
diff --git a/src/lib/libcrypto/pem/pem_pk8.c b/src/lib/libcrypto/pem/pem_pk8.c
index f44182ffb5..db38a2a79d 100644
--- a/src/lib/libcrypto/pem/pem_pk8.c
+++ b/src/lib/libcrypto/pem/pem_pk8.c
@@ -136,7 +136,7 @@ static int do_pk8pkey(BIO *bp, EVP_PKEY *x, int isder, int nid, const EVP_CIPHER
136 kstr = buf; 136 kstr = buf;
137 } 137 }
138 p8 = PKCS8_encrypt(nid, enc, kstr, klen, NULL, 0, 0, p8inf); 138 p8 = PKCS8_encrypt(nid, enc, kstr, klen, NULL, 0, 0, p8inf);
139 if(kstr == buf) memset(buf, 0, klen); 139 if(kstr == buf) OPENSSL_cleanse(buf, klen);
140 PKCS8_PRIV_KEY_INFO_free(p8inf); 140 PKCS8_PRIV_KEY_INFO_free(p8inf);
141 if(isder) ret = i2d_PKCS8_bio(bp, p8); 141 if(isder) ret = i2d_PKCS8_bio(bp, p8);
142 else ret = PEM_write_bio_PKCS8(bp, p8); 142 else ret = PEM_write_bio_PKCS8(bp, p8);
diff --git a/src/lib/libcrypto/pem/pem_seal.c b/src/lib/libcrypto/pem/pem_seal.c
index ae463a301d..56e08abd70 100644
--- a/src/lib/libcrypto/pem/pem_seal.c
+++ b/src/lib/libcrypto/pem/pem_seal.c
@@ -112,7 +112,7 @@ int PEM_SealInit(PEM_ENCODE_SEAL_CTX *ctx, EVP_CIPHER *type, EVP_MD *md_type,
112 ret=npubk; 112 ret=npubk;
113err: 113err:
114 if (s != NULL) OPENSSL_free(s); 114 if (s != NULL) OPENSSL_free(s);
115 memset(key,0,EVP_MAX_KEY_LENGTH); 115 OPENSSL_cleanse(key,EVP_MAX_KEY_LENGTH);
116 return(ret); 116 return(ret);
117 } 117 }
118 118