summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortb <>2018-05-30 15:59:33 +0000
committertb <>2018-05-30 15:59:33 +0000
commite5d993a83a8d6ac7bb0256a4a09f128ce3019905 (patch)
tree1da781cec26d49a1339bb21bf801177950d2a9e3 /src
parent358c59aecf17d566f9e65cca771cccd144234716 (diff)
downloadopenbsd-e5d993a83a8d6ac7bb0256a4a09f128ce3019905.tar.gz
openbsd-e5d993a83a8d6ac7bb0256a4a09f128ce3019905.tar.bz2
openbsd-e5d993a83a8d6ac7bb0256a4a09f128ce3019905.zip
Add const to both arguments of X509_certificate_type() and clean up
a little: Use X509_get0_pubkey() in place of X509_get_pubkey() and EVP_PKEY_free(). Check return value of the former in the appropriate place and simplify the logic for dealing with the potentially NULL pkey argument (includes a neat tweak from jsing). Finally, kill an ugly comment that has been rotting for twenty years and merge the lines around it. tested in a bulk build by sthen ok jsing
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/x509/x509.h4
-rw-r--r--src/lib/libcrypto/x509/x509type.c23
2 files changed, 10 insertions, 17 deletions
diff --git a/src/lib/libcrypto/x509/x509.h b/src/lib/libcrypto/x509/x509.h
index 29e00d7a5b..ed6225997a 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.68 2018/05/30 15:35:45 tb Exp $ */ 1/* $OpenBSD: x509.h,v 1.69 2018/05/30 15:59:33 tb 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 *
@@ -1002,7 +1002,7 @@ int X509_set_pubkey(X509 *x, EVP_PKEY *pkey);
1002EVP_PKEY * X509_get_pubkey(X509 *x); 1002EVP_PKEY * X509_get_pubkey(X509 *x);
1003EVP_PKEY * X509_get0_pubkey(const X509 *x); 1003EVP_PKEY * X509_get0_pubkey(const X509 *x);
1004ASN1_BIT_STRING *X509_get0_pubkey_bitstr(const X509 *x); 1004ASN1_BIT_STRING *X509_get0_pubkey_bitstr(const X509 *x);
1005int X509_certificate_type(X509 *x,EVP_PKEY *pubkey /* optional */); 1005int X509_certificate_type(const X509 *x, const EVP_PKEY *pubkey);
1006 1006
1007int X509_REQ_set_version(X509_REQ *x,long version); 1007int X509_REQ_set_version(X509_REQ *x,long version);
1008int X509_REQ_set_subject_name(X509_REQ *req,X509_NAME *name); 1008int X509_REQ_set_subject_name(X509_REQ *req,X509_NAME *name);
diff --git a/src/lib/libcrypto/x509/x509type.c b/src/lib/libcrypto/x509/x509type.c
index d0dcffb290..315a5c2326 100644
--- a/src/lib/libcrypto/x509/x509type.c
+++ b/src/lib/libcrypto/x509/x509type.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x509type.c,v 1.12 2015/06/13 08:38:10 doug Exp $ */ 1/* $OpenBSD: x509type.c,v 1.13 2018/05/30 15:59:33 tb 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 *
@@ -63,27 +63,22 @@
63#include <openssl/x509.h> 63#include <openssl/x509.h>
64 64
65int 65int
66X509_certificate_type(X509 *x, EVP_PKEY *pkey) 66X509_certificate_type(const X509 *x, const EVP_PKEY *pkey)
67{ 67{
68 EVP_PKEY *pk; 68 const EVP_PKEY *pk = pkey;
69 int ret = 0, i; 69 int ret = 0, i;
70 70
71 if (x == NULL) 71 if (x == NULL)
72 return (0); 72 return (0);
73 73
74 if (pkey == NULL) 74 if (pk == NULL) {
75 pk = X509_get_pubkey(x); 75 if ((pk = X509_get0_pubkey(x)) == NULL)
76 else 76 return (0);
77 pk = pkey; 77 }
78
79 if (pk == NULL)
80 return (0);
81 78
82 switch (pk->type) { 79 switch (pk->type) {
83 case EVP_PKEY_RSA: 80 case EVP_PKEY_RSA:
84 ret = EVP_PK_RSA|EVP_PKT_SIGN; 81 ret = EVP_PK_RSA|EVP_PKT_SIGN|EVP_PKT_ENC;
85/* if (!sign only extension) */
86 ret |= EVP_PKT_ENC;
87 break; 82 break;
88 case EVP_PKEY_DSA: 83 case EVP_PKEY_DSA:
89 ret = EVP_PK_DSA|EVP_PKT_SIGN; 84 ret = EVP_PK_DSA|EVP_PKT_SIGN;
@@ -124,7 +119,5 @@ X509_certificate_type(X509 *x, EVP_PKEY *pkey)
124 /* /8 because it's 1024 bits we look for, not bytes */ 119 /* /8 because it's 1024 bits we look for, not bytes */
125 if (EVP_PKEY_size(pk) <= 1024 / 8) 120 if (EVP_PKEY_size(pk) <= 1024 / 8)
126 ret |= EVP_PKT_EXP; 121 ret |= EVP_PKT_EXP;
127 if (pkey == NULL)
128 EVP_PKEY_free(pk);
129 return (ret); 122 return (ret);
130} 123}