summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjsing <>2018-03-17 14:55:39 +0000
committerjsing <>2018-03-17 14:55:39 +0000
commit53236ab726f2cb84436bc0cc39769e610cad136d (patch)
tree5be15ff9269fc26dff6867c5918dcb7f2e3f9d19
parent5d52c81e051f774e2609496afe66914cc601d068 (diff)
downloadopenbsd-53236ab726f2cb84436bc0cc39769e610cad136d.tar.gz
openbsd-53236ab726f2cb84436bc0cc39769e610cad136d.tar.bz2
openbsd-53236ab726f2cb84436bc0cc39769e610cad136d.zip
Provide X509_PUBKEY_get0() by splitting X509_PUBKEY_get() and turning it
into a wrapper that calls X509_PUBKEY_get0() and up refs.
-rw-r--r--src/lib/libcrypto/Symbols.list1
-rw-r--r--src/lib/libcrypto/asn1/x_pubkey.c22
-rw-r--r--src/lib/libcrypto/x509/x509.h3
3 files changed, 19 insertions, 7 deletions
diff --git a/src/lib/libcrypto/Symbols.list b/src/lib/libcrypto/Symbols.list
index 1b330c7dbf..ea1f420475 100644
--- a/src/lib/libcrypto/Symbols.list
+++ b/src/lib/libcrypto/Symbols.list
@@ -2759,6 +2759,7 @@ X509_PKEY_new
2759X509_POLICY_NODE_print 2759X509_POLICY_NODE_print
2760X509_PUBKEY_free 2760X509_PUBKEY_free
2761X509_PUBKEY_get 2761X509_PUBKEY_get
2762X509_PUBKEY_get0
2762X509_PUBKEY_get0_param 2763X509_PUBKEY_get0_param
2763X509_PUBKEY_it 2764X509_PUBKEY_it
2764X509_PUBKEY_new 2765X509_PUBKEY_new
diff --git a/src/lib/libcrypto/asn1/x_pubkey.c b/src/lib/libcrypto/asn1/x_pubkey.c
index 738507bbb6..ea67419cb2 100644
--- a/src/lib/libcrypto/asn1/x_pubkey.c
+++ b/src/lib/libcrypto/asn1/x_pubkey.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x_pubkey.c,v 1.26 2017/01/29 17:49:22 beck Exp $ */ 1/* $OpenBSD: x_pubkey.c,v 1.27 2018/03/17 14:55:39 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -175,17 +175,15 @@ error:
175} 175}
176 176
177EVP_PKEY * 177EVP_PKEY *
178X509_PUBKEY_get(X509_PUBKEY *key) 178X509_PUBKEY_get0(X509_PUBKEY *key)
179{ 179{
180 EVP_PKEY *ret = NULL; 180 EVP_PKEY *ret = NULL;
181 181
182 if (key == NULL) 182 if (key == NULL)
183 goto error; 183 goto error;
184 184
185 if (key->pkey != NULL) { 185 if (key->pkey != NULL)
186 CRYPTO_add(&key->pkey->references, 1, CRYPTO_LOCK_EVP_PKEY);
187 return key->pkey; 186 return key->pkey;
188 }
189 187
190 if (key->public_key == NULL) 188 if (key->public_key == NULL)
191 goto error; 189 goto error;
@@ -220,7 +218,6 @@ X509_PUBKEY_get(X509_PUBKEY *key)
220 key->pkey = ret; 218 key->pkey = ret;
221 CRYPTO_w_unlock(CRYPTO_LOCK_EVP_PKEY); 219 CRYPTO_w_unlock(CRYPTO_LOCK_EVP_PKEY);
222 } 220 }
223 CRYPTO_add(&ret->references, 1, CRYPTO_LOCK_EVP_PKEY);
224 221
225 return ret; 222 return ret;
226 223
@@ -229,6 +226,19 @@ error:
229 return (NULL); 226 return (NULL);
230} 227}
231 228
229EVP_PKEY *
230X509_PUBKEY_get(X509_PUBKEY *key)
231{
232 EVP_PKEY *pkey;
233
234 if ((pkey = X509_PUBKEY_get0(key)) == NULL)
235 return (NULL);
236
237 CRYPTO_add(&pkey->references, 1, CRYPTO_LOCK_EVP_PKEY);
238
239 return pkey;
240}
241
232/* Now two pseudo ASN1 routines that take an EVP_PKEY structure 242/* Now two pseudo ASN1 routines that take an EVP_PKEY structure
233 * and encode or decode as X509_PUBKEY 243 * and encode or decode as X509_PUBKEY
234 */ 244 */
diff --git a/src/lib/libcrypto/x509/x509.h b/src/lib/libcrypto/x509/x509.h
index 2b096ed3b3..a4aa849e31 100644
--- a/src/lib/libcrypto/x509/x509.h
+++ b/src/lib/libcrypto/x509/x509.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: x509.h,v 1.42 2018/03/17 14:33:20 jsing Exp $ */ 1/* $OpenBSD: x509.h,v 1.43 2018/03/17 14:55:39 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -806,6 +806,7 @@ extern const ASN1_ITEM X509_PUBKEY_it;
806 806
807int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey); 807int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey);
808EVP_PKEY * X509_PUBKEY_get(X509_PUBKEY *key); 808EVP_PKEY * X509_PUBKEY_get(X509_PUBKEY *key);
809EVP_PKEY * X509_PUBKEY_get0(X509_PUBKEY *key);
809int X509_get_pubkey_parameters(EVP_PKEY *pkey, 810int X509_get_pubkey_parameters(EVP_PKEY *pkey,
810 STACK_OF(X509) *chain); 811 STACK_OF(X509) *chain);
811int i2d_PUBKEY(EVP_PKEY *a,unsigned char **pp); 812int i2d_PUBKEY(EVP_PKEY *a,unsigned char **pp);