diff options
Diffstat (limited to 'src/lib/libcrypto/asn1/d2i_pr.c')
-rw-r--r-- | src/lib/libcrypto/asn1/d2i_pr.c | 66 |
1 files changed, 36 insertions, 30 deletions
diff --git a/src/lib/libcrypto/asn1/d2i_pr.c b/src/lib/libcrypto/asn1/d2i_pr.c index 5e6003ca5b..c356e3fda5 100644 --- a/src/lib/libcrypto/asn1/d2i_pr.c +++ b/src/lib/libcrypto/asn1/d2i_pr.c | |||
@@ -5,21 +5,21 @@ | |||
5 | * This package is an SSL implementation written | 5 | * This package is an SSL implementation written |
6 | * by Eric Young (eay@cryptsoft.com). | 6 | * by Eric Young (eay@cryptsoft.com). |
7 | * The implementation was written so as to conform with Netscapes SSL. | 7 | * The implementation was written so as to conform with Netscapes SSL. |
8 | * | 8 | * |
9 | * This library is free for commercial and non-commercial use as long as | 9 | * This library is free for commercial and non-commercial use as long as |
10 | * the following conditions are aheared to. The following conditions | 10 | * the following conditions are aheared to. The following conditions |
11 | * apply to all code found in this distribution, be it the RC4, RSA, | 11 | * apply to all code found in this distribution, be it the RC4, RSA, |
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation |
13 | * included with this distribution is covered by the same copyright terms | 13 | * included with this distribution is covered by the same copyright terms |
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). |
15 | * | 15 | * |
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | 16 | * Copyright remains Eric Young's, and as such any Copyright notices in |
17 | * the code are not to be removed. | 17 | * the code are not to be removed. |
18 | * If this package is used in a product, Eric Young should be given attribution | 18 | * If this package is used in a product, Eric Young should be given attribution |
19 | * as the author of the parts of the library used. | 19 | * as the author of the parts of the library used. |
20 | * This can be in the form of a textual message at program startup or | 20 | * This can be in the form of a textual message at program startup or |
21 | * in documentation (online or textual) provided with the package. | 21 | * in documentation (online or textual) provided with the package. |
22 | * | 22 | * |
23 | * Redistribution and use in source and binary forms, with or without | 23 | * Redistribution and use in source and binary forms, with or without |
24 | * modification, are permitted provided that the following conditions | 24 | * modification, are permitted provided that the following conditions |
25 | * are met: | 25 | * are met: |
@@ -34,10 +34,10 @@ | |||
34 | * Eric Young (eay@cryptsoft.com)" | 34 | * Eric Young (eay@cryptsoft.com)" |
35 | * The word 'cryptographic' can be left out if the rouines from the library | 35 | * The word 'cryptographic' can be left out if the rouines from the library |
36 | * being used are not cryptographic related :-). | 36 | * being used are not cryptographic related :-). |
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | 37 | * 4. If you include any Windows specific code (or a derivative thereof) from |
38 | * the apps directory (application code) you must include an acknowledgement: | 38 | * the apps directory (application code) you must include an acknowledgement: |
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" |
40 | * | 40 | * |
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND |
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
@@ -49,7 +49,7 @@ | |||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
51 | * SUCH DAMAGE. | 51 | * SUCH DAMAGE. |
52 | * | 52 | * |
53 | * The licence and distribution terms for any publically available version or | 53 | * The licence and distribution terms for any publically available version or |
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be |
55 | * copied and put under another distribution licence | 55 | * copied and put under another distribution licence |
@@ -68,18 +68,18 @@ | |||
68 | #include <openssl/asn1.h> | 68 | #include <openssl/asn1.h> |
69 | #include "asn1_locl.h" | 69 | #include "asn1_locl.h" |
70 | 70 | ||
71 | EVP_PKEY *d2i_PrivateKey(int type, EVP_PKEY **a, const unsigned char **pp, | 71 | EVP_PKEY * |
72 | long length) | 72 | d2i_PrivateKey(int type, EVP_PKEY **a, const unsigned char **pp, long length) |
73 | { | 73 | { |
74 | EVP_PKEY *ret; | 74 | EVP_PKEY *ret; |
75 | 75 | ||
76 | if ((a == NULL) || (*a == NULL)) { | 76 | if ((a == NULL) || (*a == NULL)) { |
77 | if ((ret=EVP_PKEY_new()) == NULL) { | 77 | if ((ret = EVP_PKEY_new()) == NULL) { |
78 | ASN1err(ASN1_F_D2I_PRIVATEKEY,ERR_R_EVP_LIB); | 78 | ASN1err(ASN1_F_D2I_PRIVATEKEY, ERR_R_EVP_LIB); |
79 | return(NULL); | 79 | return (NULL); |
80 | } | 80 | } |
81 | } else { | 81 | } else { |
82 | ret= *a; | 82 | ret = *a; |
83 | #ifndef OPENSSL_NO_ENGINE | 83 | #ifndef OPENSSL_NO_ENGINE |
84 | if (ret->engine) { | 84 | if (ret->engine) { |
85 | ENGINE_finish(ret->engine); | 85 | ENGINE_finish(ret->engine); |
@@ -89,40 +89,44 @@ EVP_PKEY *d2i_PrivateKey(int type, EVP_PKEY **a, const unsigned char **pp, | |||
89 | } | 89 | } |
90 | 90 | ||
91 | if (!EVP_PKEY_set_type(ret, type)) { | 91 | if (!EVP_PKEY_set_type(ret, type)) { |
92 | ASN1err(ASN1_F_D2I_PRIVATEKEY,ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE); | 92 | ASN1err(ASN1_F_D2I_PRIVATEKEY, ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE); |
93 | goto err; | 93 | goto err; |
94 | } | 94 | } |
95 | 95 | ||
96 | if (!ret->ameth->old_priv_decode || | 96 | if (!ret->ameth->old_priv_decode || |
97 | !ret->ameth->old_priv_decode(ret, pp, length)) { | 97 | !ret->ameth->old_priv_decode(ret, pp, length)) { |
98 | if (ret->ameth->priv_decode) { | 98 | if (ret->ameth->priv_decode) { |
99 | PKCS8_PRIV_KEY_INFO *p8=NULL; | 99 | PKCS8_PRIV_KEY_INFO *p8 = NULL; |
100 | p8=d2i_PKCS8_PRIV_KEY_INFO(NULL,pp,length); | 100 | p8 = d2i_PKCS8_PRIV_KEY_INFO(NULL, pp, length); |
101 | if (!p8) goto err; | 101 | if (!p8) |
102 | goto err; | ||
102 | EVP_PKEY_free(ret); | 103 | EVP_PKEY_free(ret); |
103 | ret = EVP_PKCS82PKEY(p8); | 104 | ret = EVP_PKCS82PKEY(p8); |
104 | PKCS8_PRIV_KEY_INFO_free(p8); | 105 | PKCS8_PRIV_KEY_INFO_free(p8); |
105 | |||
106 | } else { | 106 | } else { |
107 | ASN1err(ASN1_F_D2I_PRIVATEKEY,ERR_R_ASN1_LIB); | 107 | ASN1err(ASN1_F_D2I_PRIVATEKEY, ERR_R_ASN1_LIB); |
108 | goto err; | 108 | goto err; |
109 | } | 109 | } |
110 | } | 110 | } |
111 | if (a != NULL) (*a)=ret; | 111 | if (a != NULL) |
112 | return(ret); | 112 | (*a) = ret; |
113 | return (ret); | ||
114 | |||
113 | err: | 115 | err: |
114 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) EVP_PKEY_free(ret); | 116 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) |
115 | return(NULL); | 117 | EVP_PKEY_free(ret); |
118 | return (NULL); | ||
116 | } | 119 | } |
117 | 120 | ||
118 | /* This works like d2i_PrivateKey() except it automatically works out the type */ | 121 | /* This works like d2i_PrivateKey() except it automatically works out the type */ |
119 | 122 | ||
120 | EVP_PKEY *d2i_AutoPrivateKey(EVP_PKEY **a, const unsigned char **pp, | 123 | EVP_PKEY * |
121 | long length) | 124 | d2i_AutoPrivateKey(EVP_PKEY **a, const unsigned char **pp, long length) |
122 | { | 125 | { |
123 | STACK_OF(ASN1_TYPE) *inkey; | 126 | STACK_OF(ASN1_TYPE) *inkey; |
124 | const unsigned char *p; | 127 | const unsigned char *p; |
125 | int keytype; | 128 | int keytype; |
129 | |||
126 | p = *pp; | 130 | p = *pp; |
127 | /* Dirty trick: read in the ASN1 data into a STACK_OF(ASN1_TYPE): | 131 | /* Dirty trick: read in the ASN1 data into a STACK_OF(ASN1_TYPE): |
128 | * by analyzing it we can determine the passed structure: this | 132 | * by analyzing it we can determine the passed structure: this |
@@ -132,25 +136,27 @@ EVP_PKEY *d2i_AutoPrivateKey(EVP_PKEY **a, const unsigned char **pp, | |||
132 | /* Since we only need to discern "traditional format" RSA and DSA | 136 | /* Since we only need to discern "traditional format" RSA and DSA |
133 | * keys we can just count the elements. | 137 | * keys we can just count the elements. |
134 | */ | 138 | */ |
135 | if(sk_ASN1_TYPE_num(inkey) == 6) | 139 | if (sk_ASN1_TYPE_num(inkey) == 6) |
136 | keytype = EVP_PKEY_DSA; | 140 | keytype = EVP_PKEY_DSA; |
137 | else if (sk_ASN1_TYPE_num(inkey) == 4) | 141 | else if (sk_ASN1_TYPE_num(inkey) == 4) |
138 | keytype = EVP_PKEY_EC; | 142 | keytype = EVP_PKEY_EC; |
139 | else if (sk_ASN1_TYPE_num(inkey) == 3) { | 143 | else if (sk_ASN1_TYPE_num(inkey) == 3) { |
140 | /* This seems to be PKCS8, not traditional format */ | 144 | /* This seems to be PKCS8, not traditional format */ |
141 | PKCS8_PRIV_KEY_INFO *p8 = d2i_PKCS8_PRIV_KEY_INFO(NULL,pp,length); | 145 | PKCS8_PRIV_KEY_INFO *p8 = d2i_PKCS8_PRIV_KEY_INFO( |
146 | NULL, pp, length); | ||
142 | EVP_PKEY *ret; | 147 | EVP_PKEY *ret; |
143 | 148 | ||
144 | sk_ASN1_TYPE_pop_free(inkey, ASN1_TYPE_free); | 149 | sk_ASN1_TYPE_pop_free(inkey, ASN1_TYPE_free); |
145 | if (!p8) { | 150 | if (!p8) { |
146 | ASN1err(ASN1_F_D2I_AUTOPRIVATEKEY,ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE); | 151 | ASN1err(ASN1_F_D2I_AUTOPRIVATEKEY, |
152 | ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE); | ||
147 | return NULL; | 153 | return NULL; |
148 | } | 154 | } |
149 | ret = EVP_PKCS82PKEY(p8); | 155 | ret = EVP_PKCS82PKEY(p8); |
150 | PKCS8_PRIV_KEY_INFO_free(p8); | 156 | PKCS8_PRIV_KEY_INFO_free(p8); |
151 | if (a) { | 157 | if (a) { |
152 | *a = ret; | 158 | *a = ret; |
153 | } | 159 | } |
154 | return ret; | 160 | return ret; |
155 | } else | 161 | } else |
156 | keytype = EVP_PKEY_RSA; | 162 | keytype = EVP_PKEY_RSA; |