Skip to content

Commit a70973c

Browse files
davidbenjustsmth
authored andcommitted
Trim X509_INFO and move to crypto/pem
X509_INFO only exists to be a return value to PEM_X509_INFO_read. There is no use in letting callers create these objects, since they cannot do anything with it. Only X509_INFO_free is needed. Also cut a ton of unused fields from X509_PKEY. Change-Id: I322589f04883903e1fe5c23c3966ecf631e85b7f Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/64127 Commit-Queue: Bob Beck <[email protected]> Auto-Submit: David Benjamin <[email protected]> Commit-Queue: David Benjamin <[email protected]> Reviewed-by: Bob Beck <[email protected]> (cherry picked from commit fcd464ce97d96fd0278ad3082a8429022ae2c4d7)
1 parent c2343a5 commit a70973c

File tree

6 files changed

+62
-246
lines changed

6 files changed

+62
-246
lines changed

crypto/CMakeLists.txt

-2
Original file line numberDiff line numberDiff line change
@@ -484,9 +484,7 @@ add_library(
484484
x509/x_attrib.c
485485
x509/x_crl.c
486486
x509/x_exten.c
487-
x509/x_info.c
488487
x509/x_name.c
489-
x509/x_pkey.c
490488
x509/x_pubkey.c
491489
x509/x_req.c
492490
x509/x_sig.c

crypto/pem/pem_info.c

+31
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,37 @@
6969
#include <openssl/rsa.h>
7070
#include <openssl/x509.h>
7171

72+
73+
static X509_PKEY *X509_PKEY_new(void) {
74+
return OPENSSL_zalloc(sizeof(X509_PKEY));
75+
}
76+
77+
static void X509_PKEY_free(X509_PKEY *x) {
78+
if (x == NULL) {
79+
return;
80+
}
81+
82+
EVP_PKEY_free(x->dec_pkey);
83+
OPENSSL_free(x);
84+
}
85+
86+
static X509_INFO *X509_INFO_new(void) {
87+
return OPENSSL_zalloc(sizeof(X509_INFO));
88+
}
89+
90+
void X509_INFO_free(X509_INFO *x) {
91+
if (x == NULL) {
92+
return;
93+
}
94+
95+
X509_free(x->x509);
96+
X509_CRL_free(x->crl);
97+
X509_PKEY_free(x->x_pkey);
98+
OPENSSL_free(x->enc_data);
99+
OPENSSL_free(x);
100+
}
101+
102+
72103
STACK_OF(X509_INFO) *PEM_X509_INFO_read(FILE *fp, STACK_OF(X509_INFO) *sk,
73104
pem_password_cb *cb, void *u) {
74105
BIO *b = BIO_new_fp(fp, BIO_NOCLOSE);

crypto/x509/x_info.c

-94
Original file line numberDiff line numberDiff line change
@@ -1,94 +0,0 @@
1-
/* Copyright (C) 1995-1998 Eric Young ([email protected])
2-
* All rights reserved.
3-
*
4-
* This package is an SSL implementation written
5-
* by Eric Young ([email protected]).
6-
* The implementation was written so as to conform with Netscapes SSL.
7-
*
8-
* This library is free for commercial and non-commercial use as long as
9-
* the following conditions are aheared to. The following conditions
10-
* apply to all code found in this distribution, be it the RC4, RSA,
11-
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
12-
* included with this distribution is covered by the same copyright terms
13-
* except that the holder is Tim Hudson ([email protected]).
14-
*
15-
* Copyright remains Eric Young's, and as such any Copyright notices in
16-
* the code are not to be removed.
17-
* If this package is used in a product, Eric Young should be given attribution
18-
* as the author of the parts of the library used.
19-
* This can be in the form of a textual message at program startup or
20-
* in documentation (online or textual) provided with the package.
21-
*
22-
* Redistribution and use in source and binary forms, with or without
23-
* modification, are permitted provided that the following conditions
24-
* are met:
25-
* 1. Redistributions of source code must retain the copyright
26-
* notice, this list of conditions and the following disclaimer.
27-
* 2. Redistributions in binary form must reproduce the above copyright
28-
* notice, this list of conditions and the following disclaimer in the
29-
* documentation and/or other materials provided with the distribution.
30-
* 3. All advertising materials mentioning features or use of this software
31-
* must display the following acknowledgement:
32-
* "This product includes cryptographic software written by
33-
* Eric Young ([email protected])"
34-
* The word 'cryptographic' can be left out if the rouines from the library
35-
* being used are not cryptographic related :-).
36-
* 4. If you include any Windows specific code (or a derivative thereof) from
37-
* the apps directory (application code) you must include an acknowledgement:
38-
* "This product includes software written by Tim Hudson ([email protected])"
39-
*
40-
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
41-
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42-
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
43-
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
44-
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
45-
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
46-
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47-
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
48-
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
49-
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
50-
* SUCH DAMAGE.
51-
*
52-
* The licence and distribution terms for any publically available version or
53-
* derivative of this code cannot be changed. i.e. this code cannot simply be
54-
* copied and put under another distribution licence
55-
* [including the GNU Public Licence.] */
56-
57-
#include <openssl/x509.h>
58-
59-
#include <openssl/asn1.h>
60-
#include <openssl/err.h>
61-
#include <openssl/mem.h>
62-
#include <openssl/thread.h>
63-
#include <assert.h>
64-
65-
X509_INFO *X509_INFO_new(void) {
66-
X509_INFO *ret = NULL;
67-
68-
ret = (X509_INFO *)OPENSSL_zalloc(sizeof(X509_INFO));
69-
if (ret == NULL) {
70-
return NULL;
71-
}
72-
73-
return ret;
74-
}
75-
76-
void X509_INFO_free(X509_INFO *x) {
77-
if (x == NULL) {
78-
return;
79-
}
80-
81-
if (x->x509 != NULL) {
82-
X509_free(x->x509);
83-
}
84-
if (x->crl != NULL) {
85-
X509_CRL_free(x->crl);
86-
}
87-
if (x->x_pkey != NULL) {
88-
X509_PKEY_free(x->x_pkey);
89-
}
90-
if (x->enc_data != NULL) {
91-
OPENSSL_free(x->enc_data);
92-
}
93-
OPENSSL_free(x);
94-
}

crypto/x509/x_pkey.c

-110
This file was deleted.

include/openssl/pem.h

+31-1
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,25 @@ OPENSSL_EXPORT int PEM_ASN1_write_bio(i2d_of_void *i2d, const char *name,
353353
unsigned char *kstr, int klen,
354354
pem_password_cb *cb, void *u);
355355

356+
struct private_key_st {
357+
EVP_PKEY *dec_pkey;
358+
} /* X509_PKEY */;
359+
360+
struct X509_info_st {
361+
X509 *x509;
362+
X509_CRL *crl;
363+
X509_PKEY *x_pkey;
364+
365+
EVP_CIPHER_INFO enc_cipher;
366+
int enc_len;
367+
char *enc_data;
368+
} /* X509_INFO */;
369+
370+
DEFINE_STACK_OF(X509_INFO)
371+
372+
// X509_INFO_free releases memory associated with |info|.
373+
OPENSSL_EXPORT void X509_INFO_free(X509_INFO *info);
374+
356375
OPENSSL_EXPORT STACK_OF(X509_INFO) *PEM_X509_INFO_read_bio(
357376
BIO *bp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u);
358377

@@ -460,7 +479,18 @@ OPENSSL_EXPORT int PEM_write_PKCS8PrivateKey(FILE *fp, const EVP_PKEY *x,
460479

461480

462481
#ifdef __cplusplus
463-
}
482+
} // extern "C"
483+
484+
#if !defined(BORINGSSL_NO_CXX)
485+
extern "C++" {
486+
BSSL_NAMESPACE_BEGIN
487+
488+
BORINGSSL_MAKE_DELETER(X509_INFO, X509_INFO_free)
489+
490+
BSSL_NAMESPACE_END
491+
} // extern "C++"
492+
#endif // !BORINGSSL_NO_CXX
493+
464494
#endif
465495

466496
#define PEM_R_BAD_BASE64_DECODE 100

include/openssl/x509.h

-39
Original file line numberDiff line numberDiff line change
@@ -2737,37 +2737,6 @@ DEFINE_STACK_OF(X509_TRUST)
27372737

27382738
DECLARE_STACK_OF(GENERAL_NAMES)
27392739

2740-
struct private_key_st {
2741-
int version;
2742-
// The PKCS#8 data types
2743-
X509_ALGOR *enc_algor;
2744-
ASN1_OCTET_STRING *enc_pkey; // encrypted pub key
2745-
2746-
// When decrypted, the following will not be NULL
2747-
EVP_PKEY *dec_pkey;
2748-
2749-
// used to encrypt and decrypt
2750-
int key_length;
2751-
char *key_data;
2752-
int key_free; // true if we should auto free key_data
2753-
2754-
// expanded version of 'enc_algor'
2755-
EVP_CIPHER_INFO cipher;
2756-
} /* X509_PKEY */;
2757-
2758-
struct X509_info_st {
2759-
X509 *x509;
2760-
X509_CRL *crl;
2761-
X509_PKEY *x_pkey;
2762-
2763-
EVP_CIPHER_INFO enc_cipher;
2764-
int enc_len;
2765-
char *enc_data;
2766-
2767-
} /* X509_INFO */;
2768-
2769-
DEFINE_STACK_OF(X509_INFO)
2770-
27712740
// X509_verify_cert_error_string returns |err| as a human-readable string, where
27722741
// |err| should be one of the |X509_V_*| values. If |err| is unknown, it returns
27732742
// a default description.
@@ -2783,12 +2752,6 @@ OPENSSL_EXPORT const char *X509_get_default_private_dir(void);
27832752

27842753
OPENSSL_EXPORT int X509_TRUST_set(int *t, int trust);
27852754

2786-
OPENSSL_EXPORT X509_PKEY *X509_PKEY_new(void);
2787-
OPENSSL_EXPORT void X509_PKEY_free(X509_PKEY *a);
2788-
2789-
OPENSSL_EXPORT X509_INFO *X509_INFO_new(void);
2790-
OPENSSL_EXPORT void X509_INFO_free(X509_INFO *a);
2791-
27922755
OPENSSL_EXPORT int X509_REQ_check_private_key(X509_REQ *x509, EVP_PKEY *pkey);
27932756

27942757
OPENSSL_EXPORT int X509_check_private_key(X509 *x509, const EVP_PKEY *pkey);
@@ -3400,12 +3363,10 @@ BORINGSSL_MAKE_DELETER(X509_ATTRIBUTE, X509_ATTRIBUTE_free)
34003363
BORINGSSL_MAKE_DELETER(X509_CRL, X509_CRL_free)
34013364
BORINGSSL_MAKE_UP_REF(X509_CRL, X509_CRL_up_ref)
34023365
BORINGSSL_MAKE_DELETER(X509_EXTENSION, X509_EXTENSION_free)
3403-
BORINGSSL_MAKE_DELETER(X509_INFO, X509_INFO_free)
34043366
BORINGSSL_MAKE_DELETER(X509_LOOKUP, X509_LOOKUP_free)
34053367
BORINGSSL_MAKE_DELETER(X509_OBJECT, X509_OBJECT_free)
34063368
BORINGSSL_MAKE_DELETER(X509_NAME, X509_NAME_free)
34073369
BORINGSSL_MAKE_DELETER(X509_NAME_ENTRY, X509_NAME_ENTRY_free)
3408-
BORINGSSL_MAKE_DELETER(X509_PKEY, X509_PKEY_free)
34093370
BORINGSSL_MAKE_DELETER(X509_PUBKEY, X509_PUBKEY_free)
34103371
BORINGSSL_MAKE_DELETER(X509_REQ, X509_REQ_free)
34113372
BORINGSSL_MAKE_DELETER(X509_REVOKED, X509_REVOKED_free)

0 commit comments

Comments
 (0)