diff options
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libcrypto/asn1/a_set.c | 19 | ||||
| -rw-r--r-- | src/lib/libcrypto/asn1/a_sign.c | 96 | ||||
| -rw-r--r-- | src/lib/libcrypto/asn1/a_strex.c | 350 | ||||
| -rw-r--r-- | src/lib/libcrypto/asn1/a_strnid.c | 175 | ||||
| -rw-r--r-- | src/lib/libssl/src/crypto/asn1/a_set.c | 19 | ||||
| -rw-r--r-- | src/lib/libssl/src/crypto/asn1/a_sign.c | 96 | ||||
| -rw-r--r-- | src/lib/libssl/src/crypto/asn1/a_strex.c | 350 | ||||
| -rw-r--r-- | src/lib/libssl/src/crypto/asn1/a_strnid.c | 175 |
8 files changed, 758 insertions, 522 deletions
diff --git a/src/lib/libcrypto/asn1/a_set.c b/src/lib/libcrypto/asn1/a_set.c index 8a97984893..3aeb7e54ff 100644 --- a/src/lib/libcrypto/asn1/a_set.c +++ b/src/lib/libcrypto/asn1/a_set.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 |
| @@ -104,7 +104,7 @@ i2d_ASN1_SET(STACK_OF(OPENSSL_BLOCK) *a, unsigned char **pp, i2d_of_void *i2d, | |||
| 104 | if (pp == NULL) | 104 | if (pp == NULL) |
| 105 | return r; | 105 | return r; |
| 106 | 106 | ||
| 107 | p= *pp; | 107 | p = *pp; |
| 108 | ASN1_put_object(&p, 1, ret, ex_tag, ex_class); | 108 | ASN1_put_object(&p, 1, ret, ex_tag, ex_class); |
| 109 | 109 | ||
| 110 | /* Modified by gp@nsj.co.jp */ | 110 | /* Modified by gp@nsj.co.jp */ |
| @@ -179,7 +179,7 @@ d2i_ASN1_SET(STACK_OF(OPENSSL_BLOCK) **a, const unsigned char **pp, long length, | |||
| 179 | } else | 179 | } else |
| 180 | ret = *a; | 180 | ret = *a; |
| 181 | 181 | ||
| 182 | c.p= *pp; | 182 | c.p = *pp; |
| 183 | c.max = (length == 0) ? 0 : (c.p + length); | 183 | c.max = (length == 0) ? 0 : (c.p + length); |
| 184 | 184 | ||
| 185 | c.inf = ASN1_get_object(&c.p, &c.slen, &c.tag, &c.xclass, c.max - c.p); | 185 | c.inf = ASN1_get_object(&c.p, &c.slen, &c.tag, &c.xclass, c.max - c.p); |
| @@ -216,13 +216,14 @@ d2i_ASN1_SET(STACK_OF(OPENSSL_BLOCK) **a, const unsigned char **pp, long length, | |||
| 216 | asn1_add_error(*pp, (int)(c.p - *pp)); | 216 | asn1_add_error(*pp, (int)(c.p - *pp)); |
| 217 | goto err; | 217 | goto err; |
| 218 | } | 218 | } |
| 219 | if (!sk_OPENSSL_BLOCK_push(ret,s)) | 219 | if (!sk_OPENSSL_BLOCK_push(ret, s)) |
| 220 | goto err; | 220 | goto err; |
| 221 | } | 221 | } |
| 222 | if (a != NULL) | 222 | if (a != NULL) |
| 223 | *a = ret; | 223 | *a = ret; |
| 224 | *pp = c.p; | 224 | *pp = c.p; |
| 225 | return ret; | 225 | return ret; |
| 226 | |||
| 226 | err: | 227 | err: |
| 227 | if (ret != NULL && (a == NULL || *a != ret)) { | 228 | if (ret != NULL && (a == NULL || *a != ret)) { |
| 228 | if (free_func != NULL) | 229 | if (free_func != NULL) |
diff --git a/src/lib/libcrypto/asn1/a_sign.c b/src/lib/libcrypto/asn1/a_sign.c index 046f3b4a99..40c6809669 100644 --- a/src/lib/libcrypto/asn1/a_sign.c +++ b/src/lib/libcrypto/asn1/a_sign.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 |
| @@ -63,7 +63,7 @@ | |||
| 63 | * are met: | 63 | * are met: |
| 64 | * | 64 | * |
| 65 | * 1. Redistributions of source code must retain the above copyright | 65 | * 1. Redistributions of source code must retain the above copyright |
| 66 | * notice, this list of conditions and the following disclaimer. | 66 | * notice, this list of conditions and the following disclaimer. |
| 67 | * | 67 | * |
| 68 | * 2. Redistributions in binary form must reproduce the above copyright | 68 | * 2. Redistributions in binary form must reproduce the above copyright |
| 69 | * notice, this list of conditions and the following disclaimer in | 69 | * notice, this list of conditions and the following disclaimer in |
| @@ -125,9 +125,9 @@ | |||
| 125 | #include <openssl/buffer.h> | 125 | #include <openssl/buffer.h> |
| 126 | #include "asn1_locl.h" | 126 | #include "asn1_locl.h" |
| 127 | 127 | ||
| 128 | int ASN1_item_sign(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2, | 128 | int |
| 129 | ASN1_BIT_STRING *signature, void *asn, EVP_PKEY *pkey, | 129 | ASN1_item_sign(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2, |
| 130 | const EVP_MD *type) | 130 | ASN1_BIT_STRING *signature, void *asn, EVP_PKEY *pkey, const EVP_MD *type) |
| 131 | { | 131 | { |
| 132 | EVP_MD_CTX ctx; | 132 | EVP_MD_CTX ctx; |
| 133 | EVP_MD_CTX_init(&ctx); | 133 | EVP_MD_CTX_init(&ctx); |
| @@ -137,16 +137,16 @@ int ASN1_item_sign(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2, | |||
| 137 | } | 137 | } |
| 138 | return ASN1_item_sign_ctx(it, algor1, algor2, signature, asn, &ctx); | 138 | return ASN1_item_sign_ctx(it, algor1, algor2, signature, asn, &ctx); |
| 139 | } | 139 | } |
| 140 | |||
| 141 | 140 | ||
| 142 | int ASN1_item_sign_ctx(const ASN1_ITEM *it, | 141 | |
| 143 | X509_ALGOR *algor1, X509_ALGOR *algor2, | 142 | int |
| 144 | ASN1_BIT_STRING *signature, void *asn, EVP_MD_CTX *ctx) | 143 | ASN1_item_sign_ctx(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2, |
| 144 | ASN1_BIT_STRING *signature, void *asn, EVP_MD_CTX *ctx) | ||
| 145 | { | 145 | { |
| 146 | const EVP_MD *type; | 146 | const EVP_MD *type; |
| 147 | EVP_PKEY *pkey; | 147 | EVP_PKEY *pkey; |
| 148 | unsigned char *buf_in=NULL,*buf_out=NULL; | 148 | unsigned char *buf_in = NULL, *buf_out = NULL; |
| 149 | size_t inl=0,outl=0,outll=0; | 149 | size_t inl = 0, outl = 0, outll = 0; |
| 150 | int signid, paramtype; | 150 | int signid, paramtype; |
| 151 | int rv; | 151 | int rv; |
| 152 | 152 | ||
| @@ -154,13 +154,14 @@ int ASN1_item_sign_ctx(const ASN1_ITEM *it, | |||
| 154 | pkey = EVP_PKEY_CTX_get0_pkey(ctx->pctx); | 154 | pkey = EVP_PKEY_CTX_get0_pkey(ctx->pctx); |
| 155 | 155 | ||
| 156 | if (!type || !pkey) { | 156 | if (!type || !pkey) { |
| 157 | ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX, ASN1_R_CONTEXT_NOT_INITIALISED); | 157 | ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX, |
| 158 | ASN1_R_CONTEXT_NOT_INITIALISED); | ||
| 158 | return 0; | 159 | return 0; |
| 159 | } | 160 | } |
| 160 | 161 | ||
| 161 | if (pkey->ameth->item_sign) { | 162 | if (pkey->ameth->item_sign) { |
| 162 | rv = pkey->ameth->item_sign(ctx, it, asn, algor1, algor2, | 163 | rv = pkey->ameth->item_sign(ctx, it, asn, algor1, algor2, |
| 163 | signature); | 164 | signature); |
| 164 | if (rv == 1) | 165 | if (rv == 1) |
| 165 | outl = signature->length; | 166 | outl = signature->length; |
| 166 | /* Return value meanings: | 167 | /* Return value meanings: |
| @@ -173,22 +174,19 @@ int ASN1_item_sign_ctx(const ASN1_ITEM *it, | |||
| 173 | ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX, ERR_R_EVP_LIB); | 174 | ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX, ERR_R_EVP_LIB); |
| 174 | if (rv <= 1) | 175 | if (rv <= 1) |
| 175 | goto err; | 176 | goto err; |
| 176 | } | 177 | } else |
| 177 | else | ||
| 178 | rv = 2; | 178 | rv = 2; |
| 179 | 179 | ||
| 180 | if (rv == 2) { | 180 | if (rv == 2) { |
| 181 | if (type->flags & EVP_MD_FLAG_PKEY_METHOD_SIGNATURE) { | 181 | if (type->flags & EVP_MD_FLAG_PKEY_METHOD_SIGNATURE) { |
| 182 | if (!pkey->ameth || | 182 | if (!pkey->ameth || |
| 183 | !OBJ_find_sigid_by_algs(&signid, | 183 | !OBJ_find_sigid_by_algs(&signid, |
| 184 | EVP_MD_nid(type), | 184 | EVP_MD_nid(type), pkey->ameth->pkey_id)) { |
| 185 | pkey->ameth->pkey_id)) { | ||
| 186 | ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX, | 185 | ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX, |
| 187 | ASN1_R_DIGEST_AND_KEY_TYPE_NOT_SUPPORTED); | 186 | ASN1_R_DIGEST_AND_KEY_TYPE_NOT_SUPPORTED); |
| 188 | return 0; | 187 | return 0; |
| 189 | } | 188 | } |
| 190 | } | 189 | } else |
| 191 | else | ||
| 192 | signid = type->pkey_type; | 190 | signid = type->pkey_type; |
| 193 | 191 | ||
| 194 | if (pkey->ameth->pkey_flags & ASN1_PKEY_SIGPARAM_NULL) | 192 | if (pkey->ameth->pkey_flags & ASN1_PKEY_SIGPARAM_NULL) |
| @@ -197,43 +195,49 @@ int ASN1_item_sign_ctx(const ASN1_ITEM *it, | |||
| 197 | paramtype = V_ASN1_UNDEF; | 195 | paramtype = V_ASN1_UNDEF; |
| 198 | 196 | ||
| 199 | if (algor1) | 197 | if (algor1) |
| 200 | X509_ALGOR_set0(algor1, OBJ_nid2obj(signid), paramtype, NULL); | 198 | X509_ALGOR_set0(algor1, |
| 199 | OBJ_nid2obj(signid), paramtype, NULL); | ||
| 201 | if (algor2) | 200 | if (algor2) |
| 202 | X509_ALGOR_set0(algor2, OBJ_nid2obj(signid), paramtype, NULL); | 201 | X509_ALGOR_set0(algor2, |
| 202 | OBJ_nid2obj(signid), paramtype, NULL); | ||
| 203 | 203 | ||
| 204 | } | 204 | } |
| 205 | 205 | ||
| 206 | inl=ASN1_item_i2d(asn,&buf_in, it); | 206 | inl = ASN1_item_i2d(asn, &buf_in, it); |
| 207 | outll=outl=EVP_PKEY_size(pkey); | 207 | outll = outl = EVP_PKEY_size(pkey); |
| 208 | buf_out=malloc((unsigned int)outl); | 208 | buf_out = malloc((unsigned int)outl); |
| 209 | if ((buf_in == NULL) || (buf_out == NULL)) { | 209 | if ((buf_in == NULL) || (buf_out == NULL)) { |
| 210 | outl=0; | 210 | outl = 0; |
| 211 | ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX,ERR_R_MALLOC_FAILURE); | 211 | ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX, ERR_R_MALLOC_FAILURE); |
| 212 | goto err; | 212 | goto err; |
| 213 | } | 213 | } |
| 214 | 214 | ||
| 215 | if (!EVP_DigestSignUpdate(ctx, buf_in, inl) | 215 | if (!EVP_DigestSignUpdate(ctx, buf_in, inl) || |
| 216 | || !EVP_DigestSignFinal(ctx, buf_out, &outl)) { | 216 | !EVP_DigestSignFinal(ctx, buf_out, &outl)) { |
| 217 | outl=0; | 217 | outl = 0; |
| 218 | ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX,ERR_R_EVP_LIB); | 218 | ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX, ERR_R_EVP_LIB); |
| 219 | goto err; | 219 | goto err; |
| 220 | } | 220 | } |
| 221 | if (signature->data != NULL) free(signature->data); | 221 | if (signature->data != NULL) |
| 222 | signature->data=buf_out; | 222 | free(signature->data); |
| 223 | buf_out=NULL; | 223 | signature->data = buf_out; |
| 224 | signature->length=outl; | 224 | buf_out = NULL; |
| 225 | signature->length = outl; | ||
| 225 | /* In the interests of compatibility, I'll make sure that | 226 | /* In the interests of compatibility, I'll make sure that |
| 226 | * the bit string has a 'not-used bits' value of 0 | 227 | * the bit string has a 'not-used bits' value of 0 |
| 227 | */ | 228 | */ |
| 228 | signature->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); | 229 | signature->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); |
| 229 | signature->flags|=ASN1_STRING_FLAG_BITS_LEFT; | 230 | signature->flags |= ASN1_STRING_FLAG_BITS_LEFT; |
| 231 | |||
| 230 | err: | 232 | err: |
| 231 | EVP_MD_CTX_cleanup(ctx); | 233 | EVP_MD_CTX_cleanup(ctx); |
| 232 | if (buf_in != NULL) { | 234 | if (buf_in != NULL) { |
| 233 | OPENSSL_cleanse((char *)buf_in,(unsigned int)inl); free(buf_in); | 235 | OPENSSL_cleanse((char *)buf_in, (unsigned int)inl); |
| 236 | free(buf_in); | ||
| 234 | } | 237 | } |
| 235 | if (buf_out != NULL) { | 238 | if (buf_out != NULL) { |
| 236 | OPENSSL_cleanse((char *)buf_out,outll); free(buf_out); | 239 | OPENSSL_cleanse((char *)buf_out, outll); |
| 240 | free(buf_out); | ||
| 237 | } | 241 | } |
| 238 | return(outl); | 242 | return (outl); |
| 239 | } | 243 | } |
diff --git a/src/lib/libcrypto/asn1/a_strex.c b/src/lib/libcrypto/asn1/a_strex.c index e92c166303..248eac28f6 100644 --- a/src/lib/libcrypto/asn1/a_strex.c +++ b/src/lib/libcrypto/asn1/a_strex.c | |||
| @@ -10,7 +10,7 @@ | |||
| 10 | * are met: | 10 | * are met: |
| 11 | * | 11 | * |
| 12 | * 1. Redistributions of source code must retain the above copyright | 12 | * 1. Redistributions of source code must retain the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer. | 13 | * notice, this list of conditions and the following disclaimer. |
| 14 | * | 14 | * |
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | 15 | * 2. Redistributions in binary form must reproduce the above copyright |
| 16 | * notice, this list of conditions and the following disclaimer in | 16 | * notice, this list of conditions and the following disclaimer in |
| @@ -71,7 +71,6 @@ | |||
| 71 | * options. | 71 | * options. |
| 72 | */ | 72 | */ |
| 73 | 73 | ||
| 74 | |||
| 75 | #define CHARTYPE_BS_ESC (ASN1_STRFLGS_ESC_2253 | CHARTYPE_FIRST_ESC_2253 | CHARTYPE_LAST_ESC_2253) | 74 | #define CHARTYPE_BS_ESC (ASN1_STRFLGS_ESC_2253 | CHARTYPE_FIRST_ESC_2253 | CHARTYPE_LAST_ESC_2253) |
| 76 | 75 | ||
| 77 | #define ESC_FLAGS (ASN1_STRFLGS_ESC_2253 | \ | 76 | #define ESC_FLAGS (ASN1_STRFLGS_ESC_2253 | \ |
| @@ -84,27 +83,36 @@ | |||
| 84 | * and a FILE pointer. | 83 | * and a FILE pointer. |
| 85 | */ | 84 | */ |
| 86 | #if 0 /* never used */ | 85 | #if 0 /* never used */ |
| 87 | static int send_mem_chars(void *arg, const void *buf, int len) | 86 | static int |
| 87 | send_mem_chars(void *arg, const void *buf, int len) | ||
| 88 | { | 88 | { |
| 89 | unsigned char **out = arg; | 89 | unsigned char **out = arg; |
| 90 | if(!out) return 1; | 90 | |
| 91 | if (!out) | ||
| 92 | return 1; | ||
| 91 | memcpy(*out, buf, len); | 93 | memcpy(*out, buf, len); |
| 92 | *out += len; | 94 | *out += len; |
| 93 | return 1; | 95 | return 1; |
| 94 | } | 96 | } |
| 95 | #endif | 97 | #endif |
| 96 | 98 | ||
| 97 | static int send_bio_chars(void *arg, const void *buf, int len) | 99 | static int |
| 100 | send_bio_chars(void *arg, const void *buf, int len) | ||
| 98 | { | 101 | { |
| 99 | if(!arg) return 1; | 102 | if (!arg) |
| 100 | if(BIO_write(arg, buf, len) != len) return 0; | 103 | return 1; |
| 104 | if (BIO_write(arg, buf, len) != len) | ||
| 105 | return 0; | ||
| 101 | return 1; | 106 | return 1; |
| 102 | } | 107 | } |
| 103 | 108 | ||
| 104 | static int send_fp_chars(void *arg, const void *buf, int len) | 109 | static int |
| 110 | send_fp_chars(void *arg, const void *buf, int len) | ||
| 105 | { | 111 | { |
| 106 | if(!arg) return 1; | 112 | if (!arg) |
| 107 | if(fwrite(buf, 1, len, arg) != (unsigned int)len) return 0; | 113 | return 1; |
| 114 | if (fwrite(buf, 1, len, arg) != (unsigned int)len) | ||
| 115 | return 0; | ||
| 108 | return 1; | 116 | return 1; |
| 109 | } | 117 | } |
| 110 | 118 | ||
| @@ -117,50 +125,63 @@ typedef int char_io(void *arg, const void *buf, int len); | |||
| 117 | * 4 byte forms. | 125 | * 4 byte forms. |
| 118 | */ | 126 | */ |
| 119 | 127 | ||
| 120 | static int do_esc_char(unsigned long c, unsigned char flags, char *do_quotes, char_io *io_ch, void *arg) | 128 | static int |
| 129 | do_esc_char(unsigned long c, unsigned char flags, char *do_quotes, | ||
| 130 | char_io *io_ch, void *arg) | ||
| 121 | { | 131 | { |
| 122 | unsigned char chflgs, chtmp; | 132 | unsigned char chflgs, chtmp; |
| 123 | char tmphex[HEX_SIZE(long)+3]; | 133 | char tmphex[HEX_SIZE(long) + 3]; |
| 124 | 134 | ||
| 125 | if(c > 0xffffffffL) | 135 | if (c > 0xffffffffL) |
| 126 | return -1; | 136 | return -1; |
| 127 | if(c > 0xffff) { | 137 | if (c > 0xffff) { |
| 128 | snprintf(tmphex, sizeof tmphex, "\\W%08lX", c); | 138 | snprintf(tmphex, sizeof tmphex, "\\W%08lX", c); |
| 129 | if(!io_ch(arg, tmphex, 10)) return -1; | 139 | if (!io_ch(arg, tmphex, 10)) |
| 140 | return -1; | ||
| 130 | return 10; | 141 | return 10; |
| 131 | } | 142 | } |
| 132 | if(c > 0xff) { | 143 | if (c > 0xff) { |
| 133 | snprintf(tmphex, sizeof tmphex, "\\U%04lX", c); | 144 | snprintf(tmphex, sizeof tmphex, "\\U%04lX", c); |
| 134 | if(!io_ch(arg, tmphex, 6)) return -1; | 145 | if (!io_ch(arg, tmphex, 6)) |
| 146 | return -1; | ||
| 135 | return 6; | 147 | return 6; |
| 136 | } | 148 | } |
| 137 | chtmp = (unsigned char)c; | 149 | chtmp = (unsigned char)c; |
| 138 | if(chtmp > 0x7f) chflgs = flags & ASN1_STRFLGS_ESC_MSB; | 150 | if (chtmp > 0x7f) |
| 139 | else chflgs = char_type[chtmp] & flags; | 151 | chflgs = flags & ASN1_STRFLGS_ESC_MSB; |
| 140 | if(chflgs & CHARTYPE_BS_ESC) { | 152 | else |
| 153 | chflgs = char_type[chtmp] & flags; | ||
| 154 | if (chflgs & CHARTYPE_BS_ESC) { | ||
| 141 | /* If we don't escape with quotes, signal we need quotes */ | 155 | /* If we don't escape with quotes, signal we need quotes */ |
| 142 | if(chflgs & ASN1_STRFLGS_ESC_QUOTE) { | 156 | if (chflgs & ASN1_STRFLGS_ESC_QUOTE) { |
| 143 | if(do_quotes) *do_quotes = 1; | 157 | if (do_quotes) |
| 144 | if(!io_ch(arg, &chtmp, 1)) return -1; | 158 | *do_quotes = 1; |
| 159 | if (!io_ch(arg, &chtmp, 1)) | ||
| 160 | return -1; | ||
| 145 | return 1; | 161 | return 1; |
| 146 | } | 162 | } |
| 147 | if(!io_ch(arg, "\\", 1)) return -1; | 163 | if (!io_ch(arg, "\\", 1)) |
| 148 | if(!io_ch(arg, &chtmp, 1)) return -1; | 164 | return -1; |
| 165 | if (!io_ch(arg, &chtmp, 1)) | ||
| 166 | return -1; | ||
| 149 | return 2; | 167 | return 2; |
| 150 | } | 168 | } |
| 151 | if(chflgs & (ASN1_STRFLGS_ESC_CTRL|ASN1_STRFLGS_ESC_MSB)) { | 169 | if (chflgs & (ASN1_STRFLGS_ESC_CTRL|ASN1_STRFLGS_ESC_MSB)) { |
| 152 | snprintf(tmphex, sizeof tmphex, "\\%02X", chtmp); | 170 | snprintf(tmphex, sizeof tmphex, "\\%02X", chtmp); |
| 153 | if(!io_ch(arg, tmphex, 3)) return -1; | 171 | if (!io_ch(arg, tmphex, 3)) |
| 172 | return -1; | ||
| 154 | return 3; | 173 | return 3; |
| 155 | } | 174 | } |
| 156 | /* If we get this far and do any escaping at all must escape | 175 | /* If we get this far and do any escaping at all must escape |
| 157 | * the escape character itself: backslash. | 176 | * the escape character itself: backslash. |
| 158 | */ | 177 | */ |
| 159 | if (chtmp == '\\' && flags & ESC_FLAGS) { | 178 | if (chtmp == '\\' && flags & ESC_FLAGS) { |
| 160 | if(!io_ch(arg, "\\\\", 2)) return -1; | 179 | if (!io_ch(arg, "\\\\", 2)) |
| 180 | return -1; | ||
| 161 | return 2; | 181 | return 2; |
| 162 | } | 182 | } |
| 163 | if(!io_ch(arg, &chtmp, 1)) return -1; | 183 | if (!io_ch(arg, &chtmp, 1)) |
| 184 | return -1; | ||
| 164 | return 1; | 185 | return 1; |
| 165 | } | 186 | } |
| 166 | 187 | ||
| @@ -172,61 +193,72 @@ static int do_esc_char(unsigned long c, unsigned char flags, char *do_quotes, ch | |||
| 172 | * and converts to or from UTF8 as appropriate. | 193 | * and converts to or from UTF8 as appropriate. |
| 173 | */ | 194 | */ |
| 174 | 195 | ||
| 175 | static int do_buf(unsigned char *buf, int buflen, | 196 | static int |
| 176 | int type, unsigned char flags, char *quotes, char_io *io_ch, void *arg) | 197 | do_buf(unsigned char *buf, int buflen, int type, unsigned char flags, |
| 198 | char *quotes, char_io *io_ch, void *arg) | ||
| 177 | { | 199 | { |
| 178 | int i, outlen, len; | 200 | int i, outlen, len; |
| 179 | unsigned char orflags, *p, *q; | 201 | unsigned char orflags, *p, *q; |
| 180 | unsigned long c; | 202 | unsigned long c; |
| 203 | |||
| 181 | p = buf; | 204 | p = buf; |
| 182 | q = buf + buflen; | 205 | q = buf + buflen; |
| 183 | outlen = 0; | 206 | outlen = 0; |
| 184 | while(p != q) { | 207 | while (p != q) { |
| 185 | if(p == buf && flags & ASN1_STRFLGS_ESC_2253) orflags = CHARTYPE_FIRST_ESC_2253; | 208 | if (p == buf && flags & ASN1_STRFLGS_ESC_2253) |
| 186 | else orflags = 0; | 209 | orflags = CHARTYPE_FIRST_ESC_2253; |
| 187 | switch(type & BUF_TYPE_WIDTH_MASK) { | 210 | else |
| 188 | case 4: | 211 | orflags = 0; |
| 212 | switch (type & BUF_TYPE_WIDTH_MASK) { | ||
| 213 | case 4: | ||
| 189 | c = ((unsigned long)*p++) << 24; | 214 | c = ((unsigned long)*p++) << 24; |
| 190 | c |= ((unsigned long)*p++) << 16; | 215 | c |= ((unsigned long)*p++) << 16; |
| 191 | c |= ((unsigned long)*p++) << 8; | 216 | c |= ((unsigned long)*p++) << 8; |
| 192 | c |= *p++; | 217 | c |= *p++; |
| 193 | break; | 218 | break; |
| 194 | 219 | ||
| 195 | case 2: | 220 | case 2: |
| 196 | c = ((unsigned long)*p++) << 8; | 221 | c = ((unsigned long)*p++) << 8; |
| 197 | c |= *p++; | 222 | c |= *p++; |
| 198 | break; | 223 | break; |
| 199 | 224 | ||
| 200 | case 1: | 225 | case 1: |
| 201 | c = *p++; | 226 | c = *p++; |
| 202 | break; | 227 | break; |
| 203 | 228 | ||
| 204 | case 0: | 229 | case 0: |
| 205 | i = UTF8_getc(p, buflen, &c); | 230 | i = UTF8_getc(p, buflen, &c); |
| 206 | if(i < 0) return -1; /* Invalid UTF8String */ | 231 | if (i < 0) |
| 232 | return -1; /* Invalid UTF8String */ | ||
| 207 | p += i; | 233 | p += i; |
| 208 | break; | 234 | break; |
| 209 | default: | 235 | default: |
| 210 | return -1; /* invalid width */ | 236 | return -1; /* invalid width */ |
| 211 | } | 237 | } |
| 212 | if (p == q && flags & ASN1_STRFLGS_ESC_2253) orflags = CHARTYPE_LAST_ESC_2253; | 238 | if (p == q && flags & ASN1_STRFLGS_ESC_2253) |
| 213 | if(type & BUF_TYPE_CONVUTF8) { | 239 | orflags = CHARTYPE_LAST_ESC_2253; |
| 240 | if (type & BUF_TYPE_CONVUTF8) { | ||
| 214 | unsigned char utfbuf[6]; | 241 | unsigned char utfbuf[6]; |
| 215 | int utflen; | 242 | int utflen; |
| 216 | utflen = UTF8_putc(utfbuf, sizeof utfbuf, c); | 243 | utflen = UTF8_putc(utfbuf, sizeof utfbuf, c); |
| 217 | for(i = 0; i < utflen; i++) { | 244 | for (i = 0; i < utflen; i++) { |
| 218 | /* We don't need to worry about setting orflags correctly | 245 | /* We don't need to worry about setting orflags correctly |
| 219 | * because if utflen==1 its value will be correct anyway | 246 | * because if utflen==1 its value will be correct anyway |
| 220 | * otherwise each character will be > 0x7f and so the | 247 | * otherwise each character will be > 0x7f and so the |
| 221 | * character will never be escaped on first and last. | 248 | * character will never be escaped on first and last. |
| 222 | */ | 249 | */ |
| 223 | len = do_esc_char(utfbuf[i], (unsigned char)(flags | orflags), quotes, io_ch, arg); | 250 | len = do_esc_char(utfbuf[i], |
| 224 | if(len < 0) return -1; | 251 | (unsigned char)(flags | orflags), quotes, |
| 252 | io_ch, arg); | ||
| 253 | if (len < 0) | ||
| 254 | return -1; | ||
| 225 | outlen += len; | 255 | outlen += len; |
| 226 | } | 256 | } |
| 227 | } else { | 257 | } else { |
| 228 | len = do_esc_char(c, (unsigned char)(flags | orflags), quotes, io_ch, arg); | 258 | len = do_esc_char(c, (unsigned char)(flags | orflags), |
| 229 | if(len < 0) return -1; | 259 | quotes, io_ch, arg); |
| 260 | if (len < 0) | ||
| 261 | return -1; | ||
| 230 | outlen += len; | 262 | outlen += len; |
| 231 | } | 263 | } |
| 232 | } | 264 | } |
| @@ -235,18 +267,20 @@ static int do_buf(unsigned char *buf, int buflen, | |||
| 235 | 267 | ||
| 236 | /* This function hex dumps a buffer of characters */ | 268 | /* This function hex dumps a buffer of characters */ |
| 237 | 269 | ||
| 238 | static int do_hex_dump(char_io *io_ch, void *arg, unsigned char *buf, int buflen) | 270 | static int |
| 271 | do_hex_dump(char_io *io_ch, void *arg, unsigned char *buf, int buflen) | ||
| 239 | { | 272 | { |
| 240 | static const char hexdig[] = "0123456789ABCDEF"; | 273 | static const char hexdig[] = "0123456789ABCDEF"; |
| 241 | unsigned char *p, *q; | 274 | unsigned char *p, *q; |
| 242 | char hextmp[2]; | 275 | char hextmp[2]; |
| 243 | if(arg) { | 276 | if (arg) { |
| 244 | p = buf; | 277 | p = buf; |
| 245 | q = buf + buflen; | 278 | q = buf + buflen; |
| 246 | while(p != q) { | 279 | while (p != q) { |
| 247 | hextmp[0] = hexdig[*p >> 4]; | 280 | hextmp[0] = hexdig[*p >> 4]; |
| 248 | hextmp[1] = hexdig[*p & 0xf]; | 281 | hextmp[1] = hexdig[*p & 0xf]; |
| 249 | if(!io_ch(arg, hextmp, 2)) return -1; | 282 | if (!io_ch(arg, hextmp, 2)) |
| 283 | return -1; | ||
| 250 | p++; | 284 | p++; |
| 251 | } | 285 | } |
| 252 | } | 286 | } |
| @@ -259,7 +293,8 @@ static int do_hex_dump(char_io *io_ch, void *arg, unsigned char *buf, int buflen | |||
| 259 | * #01234 format. | 293 | * #01234 format. |
| 260 | */ | 294 | */ |
| 261 | 295 | ||
| 262 | static int do_dump(unsigned long lflags, char_io *io_ch, void *arg, ASN1_STRING *str) | 296 | static int |
| 297 | do_dump(unsigned long lflags, char_io *io_ch, void *arg, ASN1_STRING *str) | ||
| 263 | { | 298 | { |
| 264 | /* Placing the ASN1_STRING in a temp ASN1_TYPE allows | 299 | /* Placing the ASN1_STRING in a temp ASN1_TYPE allows |
| 265 | * the DER encoding to readily obtained | 300 | * the DER encoding to readily obtained |
| @@ -268,23 +303,27 @@ static int do_dump(unsigned long lflags, char_io *io_ch, void *arg, ASN1_STRING | |||
| 268 | unsigned char *der_buf, *p; | 303 | unsigned char *der_buf, *p; |
| 269 | int outlen, der_len; | 304 | int outlen, der_len; |
| 270 | 305 | ||
| 271 | if(!io_ch(arg, "#", 1)) return -1; | 306 | if (!io_ch(arg, "#", 1)) |
| 307 | return -1; | ||
| 272 | /* If we don't dump DER encoding just dump content octets */ | 308 | /* If we don't dump DER encoding just dump content octets */ |
| 273 | if(!(lflags & ASN1_STRFLGS_DUMP_DER)) { | 309 | if (!(lflags & ASN1_STRFLGS_DUMP_DER)) { |
| 274 | outlen = do_hex_dump(io_ch, arg, str->data, str->length); | 310 | outlen = do_hex_dump(io_ch, arg, str->data, str->length); |
| 275 | if(outlen < 0) return -1; | 311 | if (outlen < 0) |
| 312 | return -1; | ||
| 276 | return outlen + 1; | 313 | return outlen + 1; |
| 277 | } | 314 | } |
| 278 | t.type = str->type; | 315 | t.type = str->type; |
| 279 | t.value.ptr = (char *)str; | 316 | t.value.ptr = (char *)str; |
| 280 | der_len = i2d_ASN1_TYPE(&t, NULL); | 317 | der_len = i2d_ASN1_TYPE(&t, NULL); |
| 281 | der_buf = malloc(der_len); | 318 | der_buf = malloc(der_len); |
| 282 | if(!der_buf) return -1; | 319 | if (!der_buf) |
| 320 | return -1; | ||
| 283 | p = der_buf; | 321 | p = der_buf; |
| 284 | i2d_ASN1_TYPE(&t, &p); | 322 | i2d_ASN1_TYPE(&t, &p); |
| 285 | outlen = do_hex_dump(io_ch, arg, der_buf, der_len); | 323 | outlen = do_hex_dump(io_ch, arg, der_buf, der_len); |
| 286 | free(der_buf); | 324 | free(der_buf); |
| 287 | if(outlen < 0) return -1; | 325 | if (outlen < 0) |
| 326 | return -1; | ||
| 288 | return outlen + 1; | 327 | return outlen + 1; |
| 289 | } | 328 | } |
| 290 | 329 | ||
| @@ -311,86 +350,102 @@ static const signed char tag2nbyte[] = { | |||
| 311 | * occurred. | 350 | * occurred. |
| 312 | */ | 351 | */ |
| 313 | 352 | ||
| 314 | static int do_print_ex(char_io *io_ch, void *arg, unsigned long lflags, ASN1_STRING *str) | 353 | static int |
| 354 | do_print_ex(char_io *io_ch, void *arg, unsigned long lflags, ASN1_STRING *str) | ||
| 315 | { | 355 | { |
| 316 | int outlen, len; | 356 | int outlen, len; |
| 317 | int type; | 357 | int type; |
| 318 | char quotes; | 358 | char quotes; |
| 319 | unsigned char flags; | 359 | unsigned char flags; |
| 360 | |||
| 320 | quotes = 0; | 361 | quotes = 0; |
| 321 | /* Keep a copy of escape flags */ | 362 | /* Keep a copy of escape flags */ |
| 322 | flags = (unsigned char)(lflags & ESC_FLAGS); | 363 | flags = (unsigned char)(lflags & ESC_FLAGS); |
| 323 | |||
| 324 | type = str->type; | 364 | type = str->type; |
| 325 | |||
| 326 | outlen = 0; | 365 | outlen = 0; |
| 327 | 366 | ||
| 328 | 367 | if (lflags & ASN1_STRFLGS_SHOW_TYPE) { | |
| 329 | if(lflags & ASN1_STRFLGS_SHOW_TYPE) { | ||
| 330 | const char *tagname; | 368 | const char *tagname; |
| 331 | tagname = ASN1_tag2str(type); | 369 | tagname = ASN1_tag2str(type); |
| 332 | outlen += strlen(tagname); | 370 | outlen += strlen(tagname); |
| 333 | if(!io_ch(arg, tagname, outlen) || !io_ch(arg, ":", 1)) return -1; | 371 | if (!io_ch(arg, tagname, outlen) || !io_ch(arg, ":", 1)) |
| 372 | return -1; | ||
| 334 | outlen++; | 373 | outlen++; |
| 335 | } | 374 | } |
| 336 | 375 | ||
| 337 | /* Decide what to do with type, either dump content or display it */ | 376 | /* Decide what to do with type, either dump content or display it */ |
| 338 | 377 | ||
| 339 | /* Dump everything */ | 378 | /* Dump everything */ |
| 340 | if(lflags & ASN1_STRFLGS_DUMP_ALL) type = -1; | 379 | if (lflags & ASN1_STRFLGS_DUMP_ALL) |
| 380 | type = -1; | ||
| 341 | /* Ignore the string type */ | 381 | /* Ignore the string type */ |
| 342 | else if(lflags & ASN1_STRFLGS_IGNORE_TYPE) type = 1; | 382 | else if (lflags & ASN1_STRFLGS_IGNORE_TYPE) |
| 383 | type = 1; | ||
| 343 | else { | 384 | else { |
| 344 | /* Else determine width based on type */ | 385 | /* Else determine width based on type */ |
| 345 | if((type > 0) && (type < 31)) type = tag2nbyte[type]; | 386 | if ((type > 0) && (type < 31)) |
| 346 | else type = -1; | 387 | type = tag2nbyte[type]; |
| 347 | if((type == -1) && !(lflags & ASN1_STRFLGS_DUMP_UNKNOWN)) type = 1; | 388 | else |
| 389 | type = -1; | ||
| 390 | if ((type == -1) && !(lflags & ASN1_STRFLGS_DUMP_UNKNOWN)) | ||
| 391 | type = 1; | ||
| 348 | } | 392 | } |
| 349 | 393 | ||
| 350 | if(type == -1) { | 394 | if (type == -1) { |
| 351 | len = do_dump(lflags, io_ch, arg, str); | 395 | len = do_dump(lflags, io_ch, arg, str); |
| 352 | if(len < 0) return -1; | 396 | if (len < 0) |
| 397 | return -1; | ||
| 353 | outlen += len; | 398 | outlen += len; |
| 354 | return outlen; | 399 | return outlen; |
| 355 | } | 400 | } |
| 356 | 401 | ||
| 357 | if(lflags & ASN1_STRFLGS_UTF8_CONVERT) { | 402 | if (lflags & ASN1_STRFLGS_UTF8_CONVERT) { |
| 358 | /* Note: if string is UTF8 and we want | 403 | /* Note: if string is UTF8 and we want |
| 359 | * to convert to UTF8 then we just interpret | 404 | * to convert to UTF8 then we just interpret |
| 360 | * it as 1 byte per character to avoid converting | 405 | * it as 1 byte per character to avoid converting |
| 361 | * twice. | 406 | * twice. |
| 362 | */ | 407 | */ |
| 363 | if(!type) type = 1; | 408 | if (!type) |
| 364 | else type |= BUF_TYPE_CONVUTF8; | 409 | type = 1; |
| 410 | else | ||
| 411 | type |= BUF_TYPE_CONVUTF8; | ||
| 365 | } | 412 | } |
| 366 | 413 | ||
| 367 | len = do_buf(str->data, str->length, type, flags, "es, io_ch, NULL); | 414 | len = do_buf(str->data, str->length, type, flags, "es, io_ch, NULL); |
| 368 | if(len < 0) return -1; | 415 | if (len < 0) |
| 416 | return -1; | ||
| 369 | outlen += len; | 417 | outlen += len; |
| 370 | if(quotes) outlen += 2; | 418 | if (quotes) |
| 371 | if(!arg) return outlen; | 419 | outlen += 2; |
| 372 | if(quotes && !io_ch(arg, "\"", 1)) return -1; | 420 | if (!arg) |
| 373 | if(do_buf(str->data, str->length, type, flags, NULL, io_ch, arg) < 0) | 421 | return outlen; |
| 422 | if (quotes && !io_ch(arg, "\"", 1)) | ||
| 423 | return -1; | ||
| 424 | if (do_buf(str->data, str->length, type, flags, NULL, io_ch, arg) < 0) | ||
| 425 | return -1; | ||
| 426 | if (quotes && !io_ch(arg, "\"", 1)) | ||
| 374 | return -1; | 427 | return -1; |
| 375 | if(quotes && !io_ch(arg, "\"", 1)) return -1; | ||
| 376 | return outlen; | 428 | return outlen; |
| 377 | } | 429 | } |
| 378 | 430 | ||
| 379 | /* Used for line indenting: print 'indent' spaces */ | 431 | /* Used for line indenting: print 'indent' spaces */ |
| 380 | 432 | ||
| 381 | static int do_indent(char_io *io_ch, void *arg, int indent) | 433 | static int |
| 434 | do_indent(char_io *io_ch, void *arg, int indent) | ||
| 382 | { | 435 | { |
| 383 | int i; | 436 | int i; |
| 384 | for(i = 0; i < indent; i++) | 437 | for (i = 0; i < indent; i++) |
| 385 | if(!io_ch(arg, " ", 1)) return 0; | 438 | if (!io_ch(arg, " ", 1)) |
| 439 | return 0; | ||
| 386 | return 1; | 440 | return 1; |
| 387 | } | 441 | } |
| 388 | 442 | ||
| 389 | #define FN_WIDTH_LN 25 | 443 | #define FN_WIDTH_LN 25 |
| 390 | #define FN_WIDTH_SN 10 | 444 | #define FN_WIDTH_SN 10 |
| 391 | 445 | ||
| 392 | static int do_name_ex(char_io *io_ch, void *arg, X509_NAME *n, | 446 | static int |
| 393 | int indent, unsigned long flags) | 447 | do_name_ex(char_io *io_ch, void *arg, X509_NAME *n, int indent, |
| 448 | unsigned long flags) | ||
| 394 | { | 449 | { |
| 395 | int i, prev = -1, orflags, cnt; | 450 | int i, prev = -1, orflags, cnt; |
| 396 | int fn_opt, fn_nid; | 451 | int fn_opt, fn_nid; |
| @@ -402,18 +457,22 @@ static int do_name_ex(char_io *io_ch, void *arg, X509_NAME *n, | |||
| 402 | int outlen, len; | 457 | int outlen, len; |
| 403 | char *sep_dn, *sep_mv, *sep_eq; | 458 | char *sep_dn, *sep_mv, *sep_eq; |
| 404 | int sep_dn_len, sep_mv_len, sep_eq_len; | 459 | int sep_dn_len, sep_mv_len, sep_eq_len; |
| 405 | if(indent < 0) indent = 0; | 460 | |
| 461 | if (indent < 0) | ||
| 462 | indent = 0; | ||
| 406 | outlen = indent; | 463 | outlen = indent; |
| 407 | if(!do_indent(io_ch, arg, indent)) return -1; | 464 | if (!do_indent(io_ch, arg, indent)) |
| 465 | return -1; | ||
| 466 | |||
| 408 | switch (flags & XN_FLAG_SEP_MASK) { | 467 | switch (flags & XN_FLAG_SEP_MASK) { |
| 409 | case XN_FLAG_SEP_MULTILINE: | 468 | case XN_FLAG_SEP_MULTILINE: |
| 410 | sep_dn = "\n"; | 469 | sep_dn = "\n"; |
| 411 | sep_dn_len = 1; | 470 | sep_dn_len = 1; |
| 412 | sep_mv = " + "; | 471 | sep_mv = " + "; |
| 413 | sep_mv_len = 3; | 472 | sep_mv_len = 3; |
| 414 | break; | 473 | break; |
| 415 | 474 | ||
| 416 | case XN_FLAG_SEP_COMMA_PLUS: | 475 | case XN_FLAG_SEP_COMMA_PLUS: |
| 417 | sep_dn = ","; | 476 | sep_dn = ","; |
| 418 | sep_dn_len = 1; | 477 | sep_dn_len = 1; |
| 419 | sep_mv = "+"; | 478 | sep_mv = "+"; |
| @@ -421,7 +480,7 @@ static int do_name_ex(char_io *io_ch, void *arg, X509_NAME *n, | |||
| 421 | indent = 0; | 480 | indent = 0; |
| 422 | break; | 481 | break; |
| 423 | 482 | ||
| 424 | case XN_FLAG_SEP_CPLUS_SPC: | 483 | case XN_FLAG_SEP_CPLUS_SPC: |
| 425 | sep_dn = ", "; | 484 | sep_dn = ", "; |
| 426 | sep_dn_len = 2; | 485 | sep_dn_len = 2; |
| 427 | sep_mv = " + "; | 486 | sep_mv = " + "; |
| @@ -429,7 +488,7 @@ static int do_name_ex(char_io *io_ch, void *arg, X509_NAME *n, | |||
| 429 | indent = 0; | 488 | indent = 0; |
| 430 | break; | 489 | break; |
| 431 | 490 | ||
| 432 | case XN_FLAG_SEP_SPLUS_SPC: | 491 | case XN_FLAG_SEP_SPLUS_SPC: |
| 433 | sep_dn = "; "; | 492 | sep_dn = "; "; |
| 434 | sep_dn_len = 2; | 493 | sep_dn_len = 2; |
| 435 | sep_mv = " + "; | 494 | sep_mv = " + "; |
| @@ -437,11 +496,11 @@ static int do_name_ex(char_io *io_ch, void *arg, X509_NAME *n, | |||
| 437 | indent = 0; | 496 | indent = 0; |
| 438 | break; | 497 | break; |
| 439 | 498 | ||
| 440 | default: | 499 | default: |
| 441 | return -1; | 500 | return -1; |
| 442 | } | 501 | } |
| 443 | 502 | ||
| 444 | if(flags & XN_FLAG_SPC_EQ) { | 503 | if (flags & XN_FLAG_SPC_EQ) { |
| 445 | sep_eq = " = "; | 504 | sep_eq = " = "; |
| 446 | sep_eq_len = 3; | 505 | sep_eq_len = 3; |
| 447 | } else { | 506 | } else { |
| @@ -451,19 +510,23 @@ static int do_name_ex(char_io *io_ch, void *arg, X509_NAME *n, | |||
| 451 | 510 | ||
| 452 | fn_opt = flags & XN_FLAG_FN_MASK; | 511 | fn_opt = flags & XN_FLAG_FN_MASK; |
| 453 | 512 | ||
| 454 | cnt = X509_NAME_entry_count(n); | 513 | cnt = X509_NAME_entry_count(n); |
| 455 | for(i = 0; i < cnt; i++) { | 514 | for (i = 0; i < cnt; i++) { |
| 456 | if(flags & XN_FLAG_DN_REV) | 515 | if (flags & XN_FLAG_DN_REV) |
| 457 | ent = X509_NAME_get_entry(n, cnt - i - 1); | 516 | ent = X509_NAME_get_entry(n, cnt - i - 1); |
| 458 | else ent = X509_NAME_get_entry(n, i); | 517 | else |
| 459 | if(prev != -1) { | 518 | ent = X509_NAME_get_entry(n, i); |
| 460 | if(prev == ent->set) { | 519 | if (prev != -1) { |
| 461 | if(!io_ch(arg, sep_mv, sep_mv_len)) return -1; | 520 | if (prev == ent->set) { |
| 521 | if (!io_ch(arg, sep_mv, sep_mv_len)) | ||
| 522 | return -1; | ||
| 462 | outlen += sep_mv_len; | 523 | outlen += sep_mv_len; |
| 463 | } else { | 524 | } else { |
| 464 | if(!io_ch(arg, sep_dn, sep_dn_len)) return -1; | 525 | if (!io_ch(arg, sep_dn, sep_dn_len)) |
| 526 | return -1; | ||
| 465 | outlen += sep_dn_len; | 527 | outlen += sep_dn_len; |
| 466 | if(!do_indent(io_ch, arg, indent)) return -1; | 528 | if (!do_indent(io_ch, arg, indent)) |
| 529 | return -1; | ||
| 467 | outlen += indent; | 530 | outlen += indent; |
| 468 | } | 531 | } |
| 469 | } | 532 | } |
| @@ -471,17 +534,18 @@ static int do_name_ex(char_io *io_ch, void *arg, X509_NAME *n, | |||
| 471 | fn = X509_NAME_ENTRY_get_object(ent); | 534 | fn = X509_NAME_ENTRY_get_object(ent); |
| 472 | val = X509_NAME_ENTRY_get_data(ent); | 535 | val = X509_NAME_ENTRY_get_data(ent); |
| 473 | fn_nid = OBJ_obj2nid(fn); | 536 | fn_nid = OBJ_obj2nid(fn); |
| 474 | if(fn_opt != XN_FLAG_FN_NONE) { | 537 | if (fn_opt != XN_FLAG_FN_NONE) { |
| 475 | int objlen, fld_len; | 538 | int objlen, fld_len; |
| 476 | if((fn_opt == XN_FLAG_FN_OID) || (fn_nid==NID_undef) ) { | 539 | if ((fn_opt == XN_FLAG_FN_OID) || |
| 540 | (fn_nid == NID_undef)) { | ||
| 477 | OBJ_obj2txt(objtmp, sizeof objtmp, fn, 1); | 541 | OBJ_obj2txt(objtmp, sizeof objtmp, fn, 1); |
| 478 | fld_len = 0; /* XXX: what should this be? */ | 542 | fld_len = 0; /* XXX: what should this be? */ |
| 479 | objbuf = objtmp; | 543 | objbuf = objtmp; |
| 480 | } else { | 544 | } else { |
| 481 | if(fn_opt == XN_FLAG_FN_SN) { | 545 | if (fn_opt == XN_FLAG_FN_SN) { |
| 482 | fld_len = FN_WIDTH_SN; | 546 | fld_len = FN_WIDTH_SN; |
| 483 | objbuf = OBJ_nid2sn(fn_nid); | 547 | objbuf = OBJ_nid2sn(fn_nid); |
| 484 | } else if(fn_opt == XN_FLAG_FN_LN) { | 548 | } else if (fn_opt == XN_FLAG_FN_LN) { |
| 485 | fld_len = FN_WIDTH_LN; | 549 | fld_len = FN_WIDTH_LN; |
| 486 | objbuf = OBJ_nid2ln(fn_nid); | 550 | objbuf = OBJ_nid2ln(fn_nid); |
| 487 | } else { | 551 | } else { |
| @@ -490,24 +554,30 @@ static int do_name_ex(char_io *io_ch, void *arg, X509_NAME *n, | |||
| 490 | } | 554 | } |
| 491 | } | 555 | } |
| 492 | objlen = strlen(objbuf); | 556 | objlen = strlen(objbuf); |
| 493 | if(!io_ch(arg, objbuf, objlen)) return -1; | 557 | if (!io_ch(arg, objbuf, objlen)) |
| 558 | return -1; | ||
| 494 | if ((objlen < fld_len) && (flags & XN_FLAG_FN_ALIGN)) { | 559 | if ((objlen < fld_len) && (flags & XN_FLAG_FN_ALIGN)) { |
| 495 | if (!do_indent(io_ch, arg, fld_len - objlen)) return -1; | 560 | if (!do_indent(io_ch, arg, fld_len - objlen)) |
| 561 | return -1; | ||
| 496 | outlen += fld_len - objlen; | 562 | outlen += fld_len - objlen; |
| 497 | } | 563 | } |
| 498 | if(!io_ch(arg, sep_eq, sep_eq_len)) return -1; | 564 | if (!io_ch(arg, sep_eq, sep_eq_len)) |
| 565 | return -1; | ||
| 499 | outlen += objlen + sep_eq_len; | 566 | outlen += objlen + sep_eq_len; |
| 500 | } | 567 | } |
| 501 | /* If the field name is unknown then fix up the DER dump | 568 | /* If the field name is unknown then fix up the DER dump |
| 502 | * flag. We might want to limit this further so it will | 569 | * flag. We might want to limit this further so it will |
| 503 | * DER dump on anything other than a few 'standard' fields. | 570 | * DER dump on anything other than a few 'standard' fields. |
| 504 | */ | 571 | */ |
| 505 | if((fn_nid == NID_undef) && (flags & XN_FLAG_DUMP_UNKNOWN_FIELDS)) | 572 | if ((fn_nid == NID_undef) && |
| 506 | orflags = ASN1_STRFLGS_DUMP_ALL; | 573 | (flags & XN_FLAG_DUMP_UNKNOWN_FIELDS)) |
| 507 | else orflags = 0; | 574 | orflags = ASN1_STRFLGS_DUMP_ALL; |
| 508 | 575 | else | |
| 576 | orflags = 0; | ||
| 577 | |||
| 509 | len = do_print_ex(io_ch, arg, flags | orflags, val); | 578 | len = do_print_ex(io_ch, arg, flags | orflags, val); |
| 510 | if(len < 0) return -1; | 579 | if (len < 0) |
| 580 | return -1; | ||
| 511 | outlen += len; | 581 | outlen += len; |
| 512 | } | 582 | } |
| 513 | return outlen; | 583 | return outlen; |
| @@ -515,36 +585,41 @@ static int do_name_ex(char_io *io_ch, void *arg, X509_NAME *n, | |||
| 515 | 585 | ||
| 516 | /* Wrappers round the main functions */ | 586 | /* Wrappers round the main functions */ |
| 517 | 587 | ||
| 518 | int X509_NAME_print_ex(BIO *out, X509_NAME *nm, int indent, unsigned long flags) | 588 | int |
| 589 | X509_NAME_print_ex(BIO *out, X509_NAME *nm, int indent, unsigned long flags) | ||
| 519 | { | 590 | { |
| 520 | if(flags == XN_FLAG_COMPAT) | 591 | if (flags == XN_FLAG_COMPAT) |
| 521 | return X509_NAME_print(out, nm, indent); | 592 | return X509_NAME_print(out, nm, indent); |
| 522 | return do_name_ex(send_bio_chars, out, nm, indent, flags); | 593 | return do_name_ex(send_bio_chars, out, nm, indent, flags); |
| 523 | } | 594 | } |
| 524 | 595 | ||
| 525 | #ifndef OPENSSL_NO_FP_API | 596 | #ifndef OPENSSL_NO_FP_API |
| 526 | int X509_NAME_print_ex_fp(FILE *fp, X509_NAME *nm, int indent, unsigned long flags) | 597 | int |
| 598 | X509_NAME_print_ex_fp(FILE *fp, X509_NAME *nm, int indent, unsigned long flags) | ||
| 527 | { | 599 | { |
| 528 | if(flags == XN_FLAG_COMPAT) { | 600 | if (flags == XN_FLAG_COMPAT) { |
| 529 | BIO *btmp; | 601 | BIO *btmp; |
| 530 | int ret; | 602 | int ret; |
| 531 | btmp = BIO_new_fp(fp, BIO_NOCLOSE); | 603 | btmp = BIO_new_fp(fp, BIO_NOCLOSE); |
| 532 | if(!btmp) return -1; | 604 | if (!btmp) |
| 605 | return -1; | ||
| 533 | ret = X509_NAME_print(btmp, nm, indent); | 606 | ret = X509_NAME_print(btmp, nm, indent); |
| 534 | BIO_free(btmp); | 607 | BIO_free(btmp); |
| 535 | return ret; | 608 | return ret; |
| 536 | } | 609 | } |
| 537 | return do_name_ex(send_fp_chars, fp, nm, indent, flags); | 610 | return do_name_ex(send_fp_chars, fp, nm, indent, flags); |
| 538 | } | 611 | } |
| 539 | #endif | 612 | #endif |
| 540 | 613 | ||
| 541 | int ASN1_STRING_print_ex(BIO *out, ASN1_STRING *str, unsigned long flags) | 614 | int |
| 615 | ASN1_STRING_print_ex(BIO *out, ASN1_STRING *str, unsigned long flags) | ||
| 542 | { | 616 | { |
| 543 | return do_print_ex(send_bio_chars, out, flags, str); | 617 | return do_print_ex(send_bio_chars, out, flags, str); |
| 544 | } | 618 | } |
| 545 | 619 | ||
| 546 | #ifndef OPENSSL_NO_FP_API | 620 | #ifndef OPENSSL_NO_FP_API |
| 547 | int ASN1_STRING_print_ex_fp(FILE *fp, ASN1_STRING *str, unsigned long flags) | 621 | int |
| 622 | ASN1_STRING_print_ex_fp(FILE *fp, ASN1_STRING *str, unsigned long flags) | ||
| 548 | { | 623 | { |
| 549 | return do_print_ex(send_fp_chars, fp, flags, str); | 624 | return do_print_ex(send_fp_chars, fp, flags, str); |
| 550 | } | 625 | } |
| @@ -554,20 +629,27 @@ int ASN1_STRING_print_ex_fp(FILE *fp, ASN1_STRING *str, unsigned long flags) | |||
| 554 | * in output string or a negative error code | 629 | * in output string or a negative error code |
| 555 | */ | 630 | */ |
| 556 | 631 | ||
| 557 | int ASN1_STRING_to_UTF8(unsigned char **out, ASN1_STRING *in) | 632 | int |
| 633 | ASN1_STRING_to_UTF8(unsigned char **out, ASN1_STRING *in) | ||
| 558 | { | 634 | { |
| 559 | ASN1_STRING stmp, *str = &stmp; | 635 | ASN1_STRING stmp, *str = &stmp; |
| 560 | int mbflag, type, ret; | 636 | int mbflag, type, ret; |
| 561 | if(!in) return -1; | 637 | |
| 638 | if (!in) | ||
| 639 | return -1; | ||
| 562 | type = in->type; | 640 | type = in->type; |
| 563 | if((type < 0) || (type > 30)) return -1; | 641 | if ((type < 0) || (type > 30)) |
| 642 | return -1; | ||
| 564 | mbflag = tag2nbyte[type]; | 643 | mbflag = tag2nbyte[type]; |
| 565 | if(mbflag == -1) return -1; | 644 | if (mbflag == -1) |
| 645 | return -1; | ||
| 566 | mbflag |= MBSTRING_FLAG; | 646 | mbflag |= MBSTRING_FLAG; |
| 567 | stmp.data = NULL; | 647 | stmp.data = NULL; |
| 568 | stmp.length = 0; | 648 | stmp.length = 0; |
| 569 | ret = ASN1_mbstring_copy(&str, in->data, in->length, mbflag, B_ASN1_UTF8STRING); | 649 | ret = ASN1_mbstring_copy(&str, in->data, in->length, mbflag, |
| 570 | if(ret < 0) return ret; | 650 | B_ASN1_UTF8STRING); |
| 651 | if (ret < 0) | ||
| 652 | return ret; | ||
| 571 | *out = stmp.data; | 653 | *out = stmp.data; |
| 572 | return stmp.length; | 654 | return stmp.length; |
| 573 | } | 655 | } |
diff --git a/src/lib/libcrypto/asn1/a_strnid.c b/src/lib/libcrypto/asn1/a_strnid.c index 6c59dcc8ec..d1b804aec1 100644 --- a/src/lib/libcrypto/asn1/a_strnid.c +++ b/src/lib/libcrypto/asn1/a_strnid.c | |||
| @@ -10,7 +10,7 @@ | |||
| 10 | * are met: | 10 | * are met: |
| 11 | * | 11 | * |
| 12 | * 1. Redistributions of source code must retain the above copyright | 12 | * 1. Redistributions of source code must retain the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer. | 13 | * notice, this list of conditions and the following disclaimer. |
| 14 | * | 14 | * |
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | 15 | * 2. Redistributions in binary form must reproduce the above copyright |
| 16 | * notice, this list of conditions and the following disclaimer in | 16 | * notice, this list of conditions and the following disclaimer in |
| @@ -66,7 +66,7 @@ | |||
| 66 | static STACK_OF(ASN1_STRING_TABLE) *stable = NULL; | 66 | static STACK_OF(ASN1_STRING_TABLE) *stable = NULL; |
| 67 | static void st_free(ASN1_STRING_TABLE *tbl); | 67 | static void st_free(ASN1_STRING_TABLE *tbl); |
| 68 | static int sk_table_cmp(const ASN1_STRING_TABLE * const *a, | 68 | static int sk_table_cmp(const ASN1_STRING_TABLE * const *a, |
| 69 | const ASN1_STRING_TABLE * const *b); | 69 | const ASN1_STRING_TABLE * const *b); |
| 70 | 70 | ||
| 71 | 71 | ||
| 72 | /* This is the global mask for the mbstring functions: this is use to | 72 | /* This is the global mask for the mbstring functions: this is use to |
| @@ -76,12 +76,14 @@ static int sk_table_cmp(const ASN1_STRING_TABLE * const *a, | |||
| 76 | 76 | ||
| 77 | static unsigned long global_mask = 0xFFFFFFFFL; | 77 | static unsigned long global_mask = 0xFFFFFFFFL; |
| 78 | 78 | ||
| 79 | void ASN1_STRING_set_default_mask(unsigned long mask) | 79 | void |
| 80 | ASN1_STRING_set_default_mask(unsigned long mask) | ||
| 80 | { | 81 | { |
| 81 | global_mask = mask; | 82 | global_mask = mask; |
| 82 | } | 83 | } |
| 83 | 84 | ||
| 84 | unsigned long ASN1_STRING_get_default_mask(void) | 85 | unsigned long |
| 86 | ASN1_STRING_get_default_mask(void) | ||
| 85 | { | 87 | { |
| 86 | return global_mask; | 88 | return global_mask; |
| 87 | } | 89 | } |
| @@ -95,47 +97,59 @@ unsigned long ASN1_STRING_get_default_mask(void) | |||
| 95 | * default: the default value, Printable, T61, BMP. | 97 | * default: the default value, Printable, T61, BMP. |
| 96 | */ | 98 | */ |
| 97 | 99 | ||
| 98 | int ASN1_STRING_set_default_mask_asc(const char *p) | 100 | int |
| 101 | ASN1_STRING_set_default_mask_asc(const char *p) | ||
| 99 | { | 102 | { |
| 100 | unsigned long mask; | 103 | unsigned long mask; |
| 101 | char *end; | 104 | char *end; |
| 102 | if(!strncmp(p, "MASK:", 5)) { | 105 | |
| 103 | if(!p[5]) return 0; | 106 | if (!strncmp(p, "MASK:", 5)) { |
| 107 | if (!p[5]) | ||
| 108 | return 0; | ||
| 104 | mask = strtoul(p + 5, &end, 0); | 109 | mask = strtoul(p + 5, &end, 0); |
| 105 | if(*end) return 0; | 110 | if (*end) |
| 106 | } else if(!strcmp(p, "nombstr")) | 111 | return 0; |
| 107 | mask = ~((unsigned long)(B_ASN1_BMPSTRING|B_ASN1_UTF8STRING)); | 112 | } else if (!strcmp(p, "nombstr")) |
| 108 | else if(!strcmp(p, "pkix")) | 113 | mask = ~((unsigned long)(B_ASN1_BMPSTRING|B_ASN1_UTF8STRING)); |
| 109 | mask = ~((unsigned long)B_ASN1_T61STRING); | 114 | else if (!strcmp(p, "pkix")) |
| 110 | else if(!strcmp(p, "utf8only")) mask = B_ASN1_UTF8STRING; | 115 | mask = ~((unsigned long)B_ASN1_T61STRING); |
| 111 | else if(!strcmp(p, "default")) | 116 | else if (!strcmp(p, "utf8only")) |
| 112 | mask = 0xFFFFFFFFL; | 117 | mask = B_ASN1_UTF8STRING; |
| 113 | else return 0; | 118 | else if (!strcmp(p, "default")) |
| 119 | mask = 0xFFFFFFFFL; | ||
| 120 | else | ||
| 121 | return 0; | ||
| 114 | ASN1_STRING_set_default_mask(mask); | 122 | ASN1_STRING_set_default_mask(mask); |
| 115 | return 1; | 123 | return 1; |
| 116 | } | 124 | } |
| 117 | 125 | ||
| 118 | /* The following function generates an ASN1_STRING based on limits in a table. | 126 | /* The following function generates an ASN1_STRING based on limits in a table. |
| 119 | * Frequently the types and length of an ASN1_STRING are restricted by a | 127 | * Frequently the types and length of an ASN1_STRING are restricted by a |
| 120 | * corresponding OID. For example certificates and certificate requests. | 128 | * corresponding OID. For example certificates and certificate requests. |
| 121 | */ | 129 | */ |
| 122 | 130 | ||
| 123 | ASN1_STRING *ASN1_STRING_set_by_NID(ASN1_STRING **out, const unsigned char *in, | 131 | ASN1_STRING * |
| 124 | int inlen, int inform, int nid) | 132 | ASN1_STRING_set_by_NID(ASN1_STRING **out, const unsigned char *in, int inlen, |
| 133 | int inform, int nid) | ||
| 125 | { | 134 | { |
| 126 | ASN1_STRING_TABLE *tbl; | 135 | ASN1_STRING_TABLE *tbl; |
| 127 | ASN1_STRING *str = NULL; | 136 | ASN1_STRING *str = NULL; |
| 128 | unsigned long mask; | 137 | unsigned long mask; |
| 129 | int ret; | 138 | int ret; |
| 130 | if(!out) out = &str; | 139 | if (!out) |
| 140 | out = &str; | ||
| 131 | tbl = ASN1_STRING_TABLE_get(nid); | 141 | tbl = ASN1_STRING_TABLE_get(nid); |
| 132 | if(tbl) { | 142 | if (tbl) { |
| 133 | mask = tbl->mask; | 143 | mask = tbl->mask; |
| 134 | if(!(tbl->flags & STABLE_NO_MASK)) mask &= global_mask; | 144 | if (!(tbl->flags & STABLE_NO_MASK)) |
| 145 | mask &= global_mask; | ||
| 135 | ret = ASN1_mbstring_ncopy(out, in, inlen, inform, mask, | 146 | ret = ASN1_mbstring_ncopy(out, in, inlen, inform, mask, |
| 136 | tbl->minsize, tbl->maxsize); | 147 | tbl->minsize, tbl->maxsize); |
| 137 | } else ret = ASN1_mbstring_copy(out, in, inlen, inform, DIRSTRING_TYPE & global_mask); | 148 | } else |
| 138 | if(ret <= 0) return NULL; | 149 | ret = ASN1_mbstring_copy(out, in, inlen, inform, |
| 150 | DIRSTRING_TYPE & global_mask); | ||
| 151 | if (ret <= 0) | ||
| 152 | return NULL; | ||
| 139 | return *out; | 153 | return *out; |
| 140 | } | 154 | } |
| 141 | 155 | ||
| @@ -158,99 +172,116 @@ ASN1_STRING *ASN1_STRING_set_by_NID(ASN1_STRING **out, const unsigned char *in, | |||
| 158 | /* This table must be kept in NID order */ | 172 | /* This table must be kept in NID order */ |
| 159 | 173 | ||
| 160 | static const ASN1_STRING_TABLE tbl_standard[] = { | 174 | static const ASN1_STRING_TABLE tbl_standard[] = { |
| 161 | {NID_commonName, 1, ub_common_name, DIRSTRING_TYPE, 0}, | 175 | {NID_commonName, 1, ub_common_name, DIRSTRING_TYPE, 0}, |
| 162 | {NID_countryName, 2, 2, B_ASN1_PRINTABLESTRING, STABLE_NO_MASK}, | 176 | {NID_countryName, 2, 2, B_ASN1_PRINTABLESTRING, STABLE_NO_MASK}, |
| 163 | {NID_localityName, 1, ub_locality_name, DIRSTRING_TYPE, 0}, | 177 | {NID_localityName, 1, ub_locality_name, DIRSTRING_TYPE, 0}, |
| 164 | {NID_stateOrProvinceName, 1, ub_state_name, DIRSTRING_TYPE, 0}, | 178 | {NID_stateOrProvinceName, 1, ub_state_name, DIRSTRING_TYPE, 0}, |
| 165 | {NID_organizationName, 1, ub_organization_name, DIRSTRING_TYPE, 0}, | 179 | {NID_organizationName, 1, ub_organization_name, DIRSTRING_TYPE, 0}, |
| 166 | {NID_organizationalUnitName, 1, ub_organization_unit_name, DIRSTRING_TYPE, 0}, | 180 | {NID_organizationalUnitName, 1, ub_organization_unit_name, DIRSTRING_TYPE, 0}, |
| 167 | {NID_pkcs9_emailAddress, 1, ub_email_address, B_ASN1_IA5STRING, STABLE_NO_MASK}, | 181 | {NID_pkcs9_emailAddress, 1, ub_email_address, B_ASN1_IA5STRING, STABLE_NO_MASK}, |
| 168 | {NID_pkcs9_unstructuredName, 1, -1, PKCS9STRING_TYPE, 0}, | 182 | {NID_pkcs9_unstructuredName, 1, -1, PKCS9STRING_TYPE, 0}, |
| 169 | {NID_pkcs9_challengePassword, 1, -1, PKCS9STRING_TYPE, 0}, | 183 | {NID_pkcs9_challengePassword, 1, -1, PKCS9STRING_TYPE, 0}, |
| 170 | {NID_pkcs9_unstructuredAddress, 1, -1, DIRSTRING_TYPE, 0}, | 184 | {NID_pkcs9_unstructuredAddress, 1, -1, DIRSTRING_TYPE, 0}, |
| 171 | {NID_givenName, 1, ub_name, DIRSTRING_TYPE, 0}, | 185 | {NID_givenName, 1, ub_name, DIRSTRING_TYPE, 0}, |
| 172 | {NID_surname, 1, ub_name, DIRSTRING_TYPE, 0}, | 186 | {NID_surname, 1, ub_name, DIRSTRING_TYPE, 0}, |
| 173 | {NID_initials, 1, ub_name, DIRSTRING_TYPE, 0}, | 187 | {NID_initials, 1, ub_name, DIRSTRING_TYPE, 0}, |
| 174 | {NID_serialNumber, 1, ub_serial_number, B_ASN1_PRINTABLESTRING, STABLE_NO_MASK}, | 188 | {NID_serialNumber, 1, ub_serial_number, B_ASN1_PRINTABLESTRING, STABLE_NO_MASK}, |
| 175 | {NID_friendlyName, -1, -1, B_ASN1_BMPSTRING, STABLE_NO_MASK}, | 189 | {NID_friendlyName, -1, -1, B_ASN1_BMPSTRING, STABLE_NO_MASK}, |
| 176 | {NID_name, 1, ub_name, DIRSTRING_TYPE, 0}, | 190 | {NID_name, 1, ub_name, DIRSTRING_TYPE, 0}, |
| 177 | {NID_dnQualifier, -1, -1, B_ASN1_PRINTABLESTRING, STABLE_NO_MASK}, | 191 | {NID_dnQualifier, -1, -1, B_ASN1_PRINTABLESTRING, STABLE_NO_MASK}, |
| 178 | {NID_domainComponent, 1, -1, B_ASN1_IA5STRING, STABLE_NO_MASK}, | 192 | {NID_domainComponent, 1, -1, B_ASN1_IA5STRING, STABLE_NO_MASK}, |
| 179 | {NID_ms_csp_name, -1, -1, B_ASN1_BMPSTRING, STABLE_NO_MASK} | 193 | {NID_ms_csp_name, -1, -1, B_ASN1_BMPSTRING, STABLE_NO_MASK} |
| 180 | }; | 194 | }; |
| 181 | 195 | ||
| 182 | static int sk_table_cmp(const ASN1_STRING_TABLE * const *a, | 196 | static int |
| 183 | const ASN1_STRING_TABLE * const *b) | 197 | sk_table_cmp(const ASN1_STRING_TABLE * const *a, |
| 198 | const ASN1_STRING_TABLE * const *b) | ||
| 184 | { | 199 | { |
| 185 | return (*a)->nid - (*b)->nid; | 200 | return (*a)->nid - (*b)->nid; |
| 186 | } | 201 | } |
| 187 | 202 | ||
| 188 | DECLARE_OBJ_BSEARCH_CMP_FN(ASN1_STRING_TABLE, ASN1_STRING_TABLE, table); | 203 | DECLARE_OBJ_BSEARCH_CMP_FN(ASN1_STRING_TABLE, ASN1_STRING_TABLE, table); |
| 189 | 204 | ||
| 190 | static int table_cmp(const ASN1_STRING_TABLE *a, const ASN1_STRING_TABLE *b) | 205 | static int |
| 206 | table_cmp(const ASN1_STRING_TABLE *a, const ASN1_STRING_TABLE *b) | ||
| 191 | { | 207 | { |
| 192 | return a->nid - b->nid; | 208 | return a->nid - b->nid; |
| 193 | } | 209 | } |
| 194 | 210 | ||
| 195 | IMPLEMENT_OBJ_BSEARCH_CMP_FN(ASN1_STRING_TABLE, ASN1_STRING_TABLE, table); | 211 | IMPLEMENT_OBJ_BSEARCH_CMP_FN(ASN1_STRING_TABLE, ASN1_STRING_TABLE, table); |
| 196 | 212 | ||
| 197 | ASN1_STRING_TABLE *ASN1_STRING_TABLE_get(int nid) | 213 | ASN1_STRING_TABLE * |
| 214 | ASN1_STRING_TABLE_get(int nid) | ||
| 198 | { | 215 | { |
| 199 | int idx; | 216 | int idx; |
| 200 | ASN1_STRING_TABLE *ttmp; | 217 | ASN1_STRING_TABLE *ttmp; |
| 201 | ASN1_STRING_TABLE fnd; | 218 | ASN1_STRING_TABLE fnd; |
| 219 | |||
| 202 | fnd.nid = nid; | 220 | fnd.nid = nid; |
| 203 | ttmp = OBJ_bsearch_table(&fnd, tbl_standard, | 221 | ttmp = OBJ_bsearch_table(&fnd, tbl_standard, |
| 204 | sizeof(tbl_standard)/sizeof(ASN1_STRING_TABLE)); | 222 | sizeof(tbl_standard)/sizeof(ASN1_STRING_TABLE)); |
| 205 | if(ttmp) return ttmp; | 223 | if (ttmp) |
| 206 | if(!stable) return NULL; | 224 | return ttmp; |
| 225 | if (!stable) | ||
| 226 | return NULL; | ||
| 207 | idx = sk_ASN1_STRING_TABLE_find(stable, &fnd); | 227 | idx = sk_ASN1_STRING_TABLE_find(stable, &fnd); |
| 208 | if(idx < 0) return NULL; | 228 | if (idx < 0) |
| 229 | return NULL; | ||
| 209 | return sk_ASN1_STRING_TABLE_value(stable, idx); | 230 | return sk_ASN1_STRING_TABLE_value(stable, idx); |
| 210 | } | 231 | } |
| 211 | 232 | ||
| 212 | int ASN1_STRING_TABLE_add(int nid, | 233 | int |
| 213 | long minsize, long maxsize, unsigned long mask, | 234 | ASN1_STRING_TABLE_add(int nid, long minsize, long maxsize, unsigned long mask, |
| 214 | unsigned long flags) | 235 | unsigned long flags) |
| 215 | { | 236 | { |
| 216 | ASN1_STRING_TABLE *tmp; | 237 | ASN1_STRING_TABLE *tmp; |
| 217 | char new_nid = 0; | 238 | char new_nid = 0; |
| 239 | |||
| 218 | flags &= ~STABLE_FLAGS_MALLOC; | 240 | flags &= ~STABLE_FLAGS_MALLOC; |
| 219 | if(!stable) stable = sk_ASN1_STRING_TABLE_new(sk_table_cmp); | 241 | if (!stable) |
| 220 | if(!stable) { | 242 | stable = sk_ASN1_STRING_TABLE_new(sk_table_cmp); |
| 243 | if (!stable) { | ||
| 221 | ASN1err(ASN1_F_ASN1_STRING_TABLE_ADD, ERR_R_MALLOC_FAILURE); | 244 | ASN1err(ASN1_F_ASN1_STRING_TABLE_ADD, ERR_R_MALLOC_FAILURE); |
| 222 | return 0; | 245 | return 0; |
| 223 | } | 246 | } |
| 224 | if(!(tmp = ASN1_STRING_TABLE_get(nid))) { | 247 | if (!(tmp = ASN1_STRING_TABLE_get(nid))) { |
| 225 | tmp = malloc(sizeof(ASN1_STRING_TABLE)); | 248 | tmp = malloc(sizeof(ASN1_STRING_TABLE)); |
| 226 | if(!tmp) { | 249 | if (!tmp) { |
| 227 | ASN1err(ASN1_F_ASN1_STRING_TABLE_ADD, | 250 | ASN1err(ASN1_F_ASN1_STRING_TABLE_ADD, |
| 228 | ERR_R_MALLOC_FAILURE); | 251 | ERR_R_MALLOC_FAILURE); |
| 229 | return 0; | 252 | return 0; |
| 230 | } | 253 | } |
| 231 | tmp->flags = flags | STABLE_FLAGS_MALLOC; | 254 | tmp->flags = flags | STABLE_FLAGS_MALLOC; |
| 232 | tmp->nid = nid; | 255 | tmp->nid = nid; |
| 233 | new_nid = 1; | 256 | new_nid = 1; |
| 234 | } else tmp->flags = (tmp->flags & STABLE_FLAGS_MALLOC) | flags; | 257 | } else tmp->flags = (tmp->flags & STABLE_FLAGS_MALLOC) | flags; |
| 235 | if(minsize != -1) tmp->minsize = minsize; | 258 | if (minsize != -1) |
| 236 | if(maxsize != -1) tmp->maxsize = maxsize; | 259 | tmp->minsize = minsize; |
| 260 | if (maxsize != -1) | ||
| 261 | tmp->maxsize = maxsize; | ||
| 237 | tmp->mask = mask; | 262 | tmp->mask = mask; |
| 238 | if(new_nid) sk_ASN1_STRING_TABLE_push(stable, tmp); | 263 | if (new_nid) |
| 264 | sk_ASN1_STRING_TABLE_push(stable, tmp); | ||
| 239 | return 1; | 265 | return 1; |
| 240 | } | 266 | } |
| 241 | 267 | ||
| 242 | void ASN1_STRING_TABLE_cleanup(void) | 268 | void |
| 269 | ASN1_STRING_TABLE_cleanup(void) | ||
| 243 | { | 270 | { |
| 244 | STACK_OF(ASN1_STRING_TABLE) *tmp; | 271 | STACK_OF(ASN1_STRING_TABLE) *tmp; |
| 272 | |||
| 245 | tmp = stable; | 273 | tmp = stable; |
| 246 | if(!tmp) return; | 274 | if (!tmp) |
| 275 | return; | ||
| 247 | stable = NULL; | 276 | stable = NULL; |
| 248 | sk_ASN1_STRING_TABLE_pop_free(tmp, st_free); | 277 | sk_ASN1_STRING_TABLE_pop_free(tmp, st_free); |
| 249 | } | 278 | } |
| 250 | 279 | ||
| 251 | static void st_free(ASN1_STRING_TABLE *tbl) | 280 | static void |
| 281 | st_free(ASN1_STRING_TABLE *tbl) | ||
| 252 | { | 282 | { |
| 253 | if(tbl->flags & STABLE_FLAGS_MALLOC) free(tbl); | 283 | if (tbl->flags & STABLE_FLAGS_MALLOC) |
| 284 | free(tbl); | ||
| 254 | } | 285 | } |
| 255 | 286 | ||
| 256 | 287 | ||
| @@ -264,7 +295,7 @@ main() | |||
| 264 | int i, last_nid = -1; | 295 | int i, last_nid = -1; |
| 265 | 296 | ||
| 266 | for (tmp = tbl_standard, i = 0; | 297 | for (tmp = tbl_standard, i = 0; |
| 267 | i < sizeof(tbl_standard)/sizeof(ASN1_STRING_TABLE); i++, tmp++) { | 298 | i < sizeof(tbl_standard) / sizeof(ASN1_STRING_TABLE); i++, tmp++) { |
| 268 | if (tmp->nid < last_nid) { | 299 | if (tmp->nid < last_nid) { |
| 269 | last_nid = 0; | 300 | last_nid = 0; |
| 270 | break; | 301 | break; |
| @@ -278,9 +309,9 @@ main() | |||
| 278 | } | 309 | } |
| 279 | 310 | ||
| 280 | for (tmp = tbl_standard, i = 0; | 311 | for (tmp = tbl_standard, i = 0; |
| 281 | i < sizeof(tbl_standard)/sizeof(ASN1_STRING_TABLE); i++, tmp++) { | 312 | i < sizeof(tbl_standard) / sizeof(ASN1_STRING_TABLE); i++, tmp++) { |
| 282 | printf("Index %d, NID %d, Name=%s\n", i, tmp->nid, | 313 | printf("Index %d, NID %d, Name=%s\n", i, tmp->nid, |
| 283 | OBJ_nid2ln(tmp->nid)); | 314 | OBJ_nid2ln(tmp->nid)); |
| 284 | } | 315 | } |
| 285 | 316 | ||
| 286 | } | 317 | } |
diff --git a/src/lib/libssl/src/crypto/asn1/a_set.c b/src/lib/libssl/src/crypto/asn1/a_set.c index 8a97984893..3aeb7e54ff 100644 --- a/src/lib/libssl/src/crypto/asn1/a_set.c +++ b/src/lib/libssl/src/crypto/asn1/a_set.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 |
| @@ -104,7 +104,7 @@ i2d_ASN1_SET(STACK_OF(OPENSSL_BLOCK) *a, unsigned char **pp, i2d_of_void *i2d, | |||
| 104 | if (pp == NULL) | 104 | if (pp == NULL) |
| 105 | return r; | 105 | return r; |
| 106 | 106 | ||
| 107 | p= *pp; | 107 | p = *pp; |
| 108 | ASN1_put_object(&p, 1, ret, ex_tag, ex_class); | 108 | ASN1_put_object(&p, 1, ret, ex_tag, ex_class); |
| 109 | 109 | ||
| 110 | /* Modified by gp@nsj.co.jp */ | 110 | /* Modified by gp@nsj.co.jp */ |
| @@ -179,7 +179,7 @@ d2i_ASN1_SET(STACK_OF(OPENSSL_BLOCK) **a, const unsigned char **pp, long length, | |||
| 179 | } else | 179 | } else |
| 180 | ret = *a; | 180 | ret = *a; |
| 181 | 181 | ||
| 182 | c.p= *pp; | 182 | c.p = *pp; |
| 183 | c.max = (length == 0) ? 0 : (c.p + length); | 183 | c.max = (length == 0) ? 0 : (c.p + length); |
| 184 | 184 | ||
| 185 | c.inf = ASN1_get_object(&c.p, &c.slen, &c.tag, &c.xclass, c.max - c.p); | 185 | c.inf = ASN1_get_object(&c.p, &c.slen, &c.tag, &c.xclass, c.max - c.p); |
| @@ -216,13 +216,14 @@ d2i_ASN1_SET(STACK_OF(OPENSSL_BLOCK) **a, const unsigned char **pp, long length, | |||
| 216 | asn1_add_error(*pp, (int)(c.p - *pp)); | 216 | asn1_add_error(*pp, (int)(c.p - *pp)); |
| 217 | goto err; | 217 | goto err; |
| 218 | } | 218 | } |
| 219 | if (!sk_OPENSSL_BLOCK_push(ret,s)) | 219 | if (!sk_OPENSSL_BLOCK_push(ret, s)) |
| 220 | goto err; | 220 | goto err; |
| 221 | } | 221 | } |
| 222 | if (a != NULL) | 222 | if (a != NULL) |
| 223 | *a = ret; | 223 | *a = ret; |
| 224 | *pp = c.p; | 224 | *pp = c.p; |
| 225 | return ret; | 225 | return ret; |
| 226 | |||
| 226 | err: | 227 | err: |
| 227 | if (ret != NULL && (a == NULL || *a != ret)) { | 228 | if (ret != NULL && (a == NULL || *a != ret)) { |
| 228 | if (free_func != NULL) | 229 | if (free_func != NULL) |
diff --git a/src/lib/libssl/src/crypto/asn1/a_sign.c b/src/lib/libssl/src/crypto/asn1/a_sign.c index 046f3b4a99..40c6809669 100644 --- a/src/lib/libssl/src/crypto/asn1/a_sign.c +++ b/src/lib/libssl/src/crypto/asn1/a_sign.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 |
| @@ -63,7 +63,7 @@ | |||
| 63 | * are met: | 63 | * are met: |
| 64 | * | 64 | * |
| 65 | * 1. Redistributions of source code must retain the above copyright | 65 | * 1. Redistributions of source code must retain the above copyright |
| 66 | * notice, this list of conditions and the following disclaimer. | 66 | * notice, this list of conditions and the following disclaimer. |
| 67 | * | 67 | * |
| 68 | * 2. Redistributions in binary form must reproduce the above copyright | 68 | * 2. Redistributions in binary form must reproduce the above copyright |
| 69 | * notice, this list of conditions and the following disclaimer in | 69 | * notice, this list of conditions and the following disclaimer in |
| @@ -125,9 +125,9 @@ | |||
| 125 | #include <openssl/buffer.h> | 125 | #include <openssl/buffer.h> |
| 126 | #include "asn1_locl.h" | 126 | #include "asn1_locl.h" |
| 127 | 127 | ||
| 128 | int ASN1_item_sign(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2, | 128 | int |
| 129 | ASN1_BIT_STRING *signature, void *asn, EVP_PKEY *pkey, | 129 | ASN1_item_sign(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2, |
| 130 | const EVP_MD *type) | 130 | ASN1_BIT_STRING *signature, void *asn, EVP_PKEY *pkey, const EVP_MD *type) |
| 131 | { | 131 | { |
| 132 | EVP_MD_CTX ctx; | 132 | EVP_MD_CTX ctx; |
| 133 | EVP_MD_CTX_init(&ctx); | 133 | EVP_MD_CTX_init(&ctx); |
| @@ -137,16 +137,16 @@ int ASN1_item_sign(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2, | |||
| 137 | } | 137 | } |
| 138 | return ASN1_item_sign_ctx(it, algor1, algor2, signature, asn, &ctx); | 138 | return ASN1_item_sign_ctx(it, algor1, algor2, signature, asn, &ctx); |
| 139 | } | 139 | } |
| 140 | |||
| 141 | 140 | ||
| 142 | int ASN1_item_sign_ctx(const ASN1_ITEM *it, | 141 | |
| 143 | X509_ALGOR *algor1, X509_ALGOR *algor2, | 142 | int |
| 144 | ASN1_BIT_STRING *signature, void *asn, EVP_MD_CTX *ctx) | 143 | ASN1_item_sign_ctx(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2, |
| 144 | ASN1_BIT_STRING *signature, void *asn, EVP_MD_CTX *ctx) | ||
| 145 | { | 145 | { |
| 146 | const EVP_MD *type; | 146 | const EVP_MD *type; |
| 147 | EVP_PKEY *pkey; | 147 | EVP_PKEY *pkey; |
| 148 | unsigned char *buf_in=NULL,*buf_out=NULL; | 148 | unsigned char *buf_in = NULL, *buf_out = NULL; |
| 149 | size_t inl=0,outl=0,outll=0; | 149 | size_t inl = 0, outl = 0, outll = 0; |
| 150 | int signid, paramtype; | 150 | int signid, paramtype; |
| 151 | int rv; | 151 | int rv; |
| 152 | 152 | ||
| @@ -154,13 +154,14 @@ int ASN1_item_sign_ctx(const ASN1_ITEM *it, | |||
| 154 | pkey = EVP_PKEY_CTX_get0_pkey(ctx->pctx); | 154 | pkey = EVP_PKEY_CTX_get0_pkey(ctx->pctx); |
| 155 | 155 | ||
| 156 | if (!type || !pkey) { | 156 | if (!type || !pkey) { |
| 157 | ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX, ASN1_R_CONTEXT_NOT_INITIALISED); | 157 | ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX, |
| 158 | ASN1_R_CONTEXT_NOT_INITIALISED); | ||
| 158 | return 0; | 159 | return 0; |
| 159 | } | 160 | } |
| 160 | 161 | ||
| 161 | if (pkey->ameth->item_sign) { | 162 | if (pkey->ameth->item_sign) { |
| 162 | rv = pkey->ameth->item_sign(ctx, it, asn, algor1, algor2, | 163 | rv = pkey->ameth->item_sign(ctx, it, asn, algor1, algor2, |
| 163 | signature); | 164 | signature); |
| 164 | if (rv == 1) | 165 | if (rv == 1) |
| 165 | outl = signature->length; | 166 | outl = signature->length; |
| 166 | /* Return value meanings: | 167 | /* Return value meanings: |
| @@ -173,22 +174,19 @@ int ASN1_item_sign_ctx(const ASN1_ITEM *it, | |||
| 173 | ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX, ERR_R_EVP_LIB); | 174 | ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX, ERR_R_EVP_LIB); |
| 174 | if (rv <= 1) | 175 | if (rv <= 1) |
| 175 | goto err; | 176 | goto err; |
| 176 | } | 177 | } else |
| 177 | else | ||
| 178 | rv = 2; | 178 | rv = 2; |
| 179 | 179 | ||
| 180 | if (rv == 2) { | 180 | if (rv == 2) { |
| 181 | if (type->flags & EVP_MD_FLAG_PKEY_METHOD_SIGNATURE) { | 181 | if (type->flags & EVP_MD_FLAG_PKEY_METHOD_SIGNATURE) { |
| 182 | if (!pkey->ameth || | 182 | if (!pkey->ameth || |
| 183 | !OBJ_find_sigid_by_algs(&signid, | 183 | !OBJ_find_sigid_by_algs(&signid, |
| 184 | EVP_MD_nid(type), | 184 | EVP_MD_nid(type), pkey->ameth->pkey_id)) { |
| 185 | pkey->ameth->pkey_id)) { | ||
| 186 | ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX, | 185 | ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX, |
| 187 | ASN1_R_DIGEST_AND_KEY_TYPE_NOT_SUPPORTED); | 186 | ASN1_R_DIGEST_AND_KEY_TYPE_NOT_SUPPORTED); |
| 188 | return 0; | 187 | return 0; |
| 189 | } | 188 | } |
| 190 | } | 189 | } else |
| 191 | else | ||
| 192 | signid = type->pkey_type; | 190 | signid = type->pkey_type; |
| 193 | 191 | ||
| 194 | if (pkey->ameth->pkey_flags & ASN1_PKEY_SIGPARAM_NULL) | 192 | if (pkey->ameth->pkey_flags & ASN1_PKEY_SIGPARAM_NULL) |
| @@ -197,43 +195,49 @@ int ASN1_item_sign_ctx(const ASN1_ITEM *it, | |||
| 197 | paramtype = V_ASN1_UNDEF; | 195 | paramtype = V_ASN1_UNDEF; |
| 198 | 196 | ||
| 199 | if (algor1) | 197 | if (algor1) |
| 200 | X509_ALGOR_set0(algor1, OBJ_nid2obj(signid), paramtype, NULL); | 198 | X509_ALGOR_set0(algor1, |
| 199 | OBJ_nid2obj(signid), paramtype, NULL); | ||
| 201 | if (algor2) | 200 | if (algor2) |
| 202 | X509_ALGOR_set0(algor2, OBJ_nid2obj(signid), paramtype, NULL); | 201 | X509_ALGOR_set0(algor2, |
| 202 | OBJ_nid2obj(signid), paramtype, NULL); | ||
| 203 | 203 | ||
| 204 | } | 204 | } |
| 205 | 205 | ||
| 206 | inl=ASN1_item_i2d(asn,&buf_in, it); | 206 | inl = ASN1_item_i2d(asn, &buf_in, it); |
| 207 | outll=outl=EVP_PKEY_size(pkey); | 207 | outll = outl = EVP_PKEY_size(pkey); |
| 208 | buf_out=malloc((unsigned int)outl); | 208 | buf_out = malloc((unsigned int)outl); |
| 209 | if ((buf_in == NULL) || (buf_out == NULL)) { | 209 | if ((buf_in == NULL) || (buf_out == NULL)) { |
| 210 | outl=0; | 210 | outl = 0; |
| 211 | ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX,ERR_R_MALLOC_FAILURE); | 211 | ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX, ERR_R_MALLOC_FAILURE); |
| 212 | goto err; | 212 | goto err; |
| 213 | } | 213 | } |
| 214 | 214 | ||
| 215 | if (!EVP_DigestSignUpdate(ctx, buf_in, inl) | 215 | if (!EVP_DigestSignUpdate(ctx, buf_in, inl) || |
| 216 | || !EVP_DigestSignFinal(ctx, buf_out, &outl)) { | 216 | !EVP_DigestSignFinal(ctx, buf_out, &outl)) { |
| 217 | outl=0; | 217 | outl = 0; |
| 218 | ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX,ERR_R_EVP_LIB); | 218 | ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX, ERR_R_EVP_LIB); |
| 219 | goto err; | 219 | goto err; |
| 220 | } | 220 | } |
| 221 | if (signature->data != NULL) free(signature->data); | 221 | if (signature->data != NULL) |
| 222 | signature->data=buf_out; | 222 | free(signature->data); |
| 223 | buf_out=NULL; | 223 | signature->data = buf_out; |
| 224 | signature->length=outl; | 224 | buf_out = NULL; |
| 225 | signature->length = outl; | ||
| 225 | /* In the interests of compatibility, I'll make sure that | 226 | /* In the interests of compatibility, I'll make sure that |
| 226 | * the bit string has a 'not-used bits' value of 0 | 227 | * the bit string has a 'not-used bits' value of 0 |
| 227 | */ | 228 | */ |
| 228 | signature->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); | 229 | signature->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); |
| 229 | signature->flags|=ASN1_STRING_FLAG_BITS_LEFT; | 230 | signature->flags |= ASN1_STRING_FLAG_BITS_LEFT; |
| 231 | |||
| 230 | err: | 232 | err: |
| 231 | EVP_MD_CTX_cleanup(ctx); | 233 | EVP_MD_CTX_cleanup(ctx); |
| 232 | if (buf_in != NULL) { | 234 | if (buf_in != NULL) { |
| 233 | OPENSSL_cleanse((char *)buf_in,(unsigned int)inl); free(buf_in); | 235 | OPENSSL_cleanse((char *)buf_in, (unsigned int)inl); |
| 236 | free(buf_in); | ||
| 234 | } | 237 | } |
| 235 | if (buf_out != NULL) { | 238 | if (buf_out != NULL) { |
| 236 | OPENSSL_cleanse((char *)buf_out,outll); free(buf_out); | 239 | OPENSSL_cleanse((char *)buf_out, outll); |
| 240 | free(buf_out); | ||
| 237 | } | 241 | } |
| 238 | return(outl); | 242 | return (outl); |
| 239 | } | 243 | } |
diff --git a/src/lib/libssl/src/crypto/asn1/a_strex.c b/src/lib/libssl/src/crypto/asn1/a_strex.c index e92c166303..248eac28f6 100644 --- a/src/lib/libssl/src/crypto/asn1/a_strex.c +++ b/src/lib/libssl/src/crypto/asn1/a_strex.c | |||
| @@ -10,7 +10,7 @@ | |||
| 10 | * are met: | 10 | * are met: |
| 11 | * | 11 | * |
| 12 | * 1. Redistributions of source code must retain the above copyright | 12 | * 1. Redistributions of source code must retain the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer. | 13 | * notice, this list of conditions and the following disclaimer. |
| 14 | * | 14 | * |
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | 15 | * 2. Redistributions in binary form must reproduce the above copyright |
| 16 | * notice, this list of conditions and the following disclaimer in | 16 | * notice, this list of conditions and the following disclaimer in |
| @@ -71,7 +71,6 @@ | |||
| 71 | * options. | 71 | * options. |
| 72 | */ | 72 | */ |
| 73 | 73 | ||
| 74 | |||
| 75 | #define CHARTYPE_BS_ESC (ASN1_STRFLGS_ESC_2253 | CHARTYPE_FIRST_ESC_2253 | CHARTYPE_LAST_ESC_2253) | 74 | #define CHARTYPE_BS_ESC (ASN1_STRFLGS_ESC_2253 | CHARTYPE_FIRST_ESC_2253 | CHARTYPE_LAST_ESC_2253) |
| 76 | 75 | ||
| 77 | #define ESC_FLAGS (ASN1_STRFLGS_ESC_2253 | \ | 76 | #define ESC_FLAGS (ASN1_STRFLGS_ESC_2253 | \ |
| @@ -84,27 +83,36 @@ | |||
| 84 | * and a FILE pointer. | 83 | * and a FILE pointer. |
| 85 | */ | 84 | */ |
| 86 | #if 0 /* never used */ | 85 | #if 0 /* never used */ |
| 87 | static int send_mem_chars(void *arg, const void *buf, int len) | 86 | static int |
| 87 | send_mem_chars(void *arg, const void *buf, int len) | ||
| 88 | { | 88 | { |
| 89 | unsigned char **out = arg; | 89 | unsigned char **out = arg; |
| 90 | if(!out) return 1; | 90 | |
| 91 | if (!out) | ||
| 92 | return 1; | ||
| 91 | memcpy(*out, buf, len); | 93 | memcpy(*out, buf, len); |
| 92 | *out += len; | 94 | *out += len; |
| 93 | return 1; | 95 | return 1; |
| 94 | } | 96 | } |
| 95 | #endif | 97 | #endif |
| 96 | 98 | ||
| 97 | static int send_bio_chars(void *arg, const void *buf, int len) | 99 | static int |
| 100 | send_bio_chars(void *arg, const void *buf, int len) | ||
| 98 | { | 101 | { |
| 99 | if(!arg) return 1; | 102 | if (!arg) |
| 100 | if(BIO_write(arg, buf, len) != len) return 0; | 103 | return 1; |
| 104 | if (BIO_write(arg, buf, len) != len) | ||
| 105 | return 0; | ||
| 101 | return 1; | 106 | return 1; |
| 102 | } | 107 | } |
| 103 | 108 | ||
| 104 | static int send_fp_chars(void *arg, const void *buf, int len) | 109 | static int |
| 110 | send_fp_chars(void *arg, const void *buf, int len) | ||
| 105 | { | 111 | { |
| 106 | if(!arg) return 1; | 112 | if (!arg) |
| 107 | if(fwrite(buf, 1, len, arg) != (unsigned int)len) return 0; | 113 | return 1; |
| 114 | if (fwrite(buf, 1, len, arg) != (unsigned int)len) | ||
| 115 | return 0; | ||
| 108 | return 1; | 116 | return 1; |
| 109 | } | 117 | } |
| 110 | 118 | ||
| @@ -117,50 +125,63 @@ typedef int char_io(void *arg, const void *buf, int len); | |||
| 117 | * 4 byte forms. | 125 | * 4 byte forms. |
| 118 | */ | 126 | */ |
| 119 | 127 | ||
| 120 | static int do_esc_char(unsigned long c, unsigned char flags, char *do_quotes, char_io *io_ch, void *arg) | 128 | static int |
| 129 | do_esc_char(unsigned long c, unsigned char flags, char *do_quotes, | ||
| 130 | char_io *io_ch, void *arg) | ||
| 121 | { | 131 | { |
| 122 | unsigned char chflgs, chtmp; | 132 | unsigned char chflgs, chtmp; |
| 123 | char tmphex[HEX_SIZE(long)+3]; | 133 | char tmphex[HEX_SIZE(long) + 3]; |
| 124 | 134 | ||
| 125 | if(c > 0xffffffffL) | 135 | if (c > 0xffffffffL) |
| 126 | return -1; | 136 | return -1; |
| 127 | if(c > 0xffff) { | 137 | if (c > 0xffff) { |
| 128 | snprintf(tmphex, sizeof tmphex, "\\W%08lX", c); | 138 | snprintf(tmphex, sizeof tmphex, "\\W%08lX", c); |
| 129 | if(!io_ch(arg, tmphex, 10)) return -1; | 139 | if (!io_ch(arg, tmphex, 10)) |
| 140 | return -1; | ||
| 130 | return 10; | 141 | return 10; |
| 131 | } | 142 | } |
| 132 | if(c > 0xff) { | 143 | if (c > 0xff) { |
| 133 | snprintf(tmphex, sizeof tmphex, "\\U%04lX", c); | 144 | snprintf(tmphex, sizeof tmphex, "\\U%04lX", c); |
| 134 | if(!io_ch(arg, tmphex, 6)) return -1; | 145 | if (!io_ch(arg, tmphex, 6)) |
| 146 | return -1; | ||
| 135 | return 6; | 147 | return 6; |
| 136 | } | 148 | } |
| 137 | chtmp = (unsigned char)c; | 149 | chtmp = (unsigned char)c; |
| 138 | if(chtmp > 0x7f) chflgs = flags & ASN1_STRFLGS_ESC_MSB; | 150 | if (chtmp > 0x7f) |
| 139 | else chflgs = char_type[chtmp] & flags; | 151 | chflgs = flags & ASN1_STRFLGS_ESC_MSB; |
| 140 | if(chflgs & CHARTYPE_BS_ESC) { | 152 | else |
| 153 | chflgs = char_type[chtmp] & flags; | ||
| 154 | if (chflgs & CHARTYPE_BS_ESC) { | ||
| 141 | /* If we don't escape with quotes, signal we need quotes */ | 155 | /* If we don't escape with quotes, signal we need quotes */ |
| 142 | if(chflgs & ASN1_STRFLGS_ESC_QUOTE) { | 156 | if (chflgs & ASN1_STRFLGS_ESC_QUOTE) { |
| 143 | if(do_quotes) *do_quotes = 1; | 157 | if (do_quotes) |
| 144 | if(!io_ch(arg, &chtmp, 1)) return -1; | 158 | *do_quotes = 1; |
| 159 | if (!io_ch(arg, &chtmp, 1)) | ||
| 160 | return -1; | ||
| 145 | return 1; | 161 | return 1; |
| 146 | } | 162 | } |
| 147 | if(!io_ch(arg, "\\", 1)) return -1; | 163 | if (!io_ch(arg, "\\", 1)) |
| 148 | if(!io_ch(arg, &chtmp, 1)) return -1; | 164 | return -1; |
| 165 | if (!io_ch(arg, &chtmp, 1)) | ||
| 166 | return -1; | ||
| 149 | return 2; | 167 | return 2; |
| 150 | } | 168 | } |
| 151 | if(chflgs & (ASN1_STRFLGS_ESC_CTRL|ASN1_STRFLGS_ESC_MSB)) { | 169 | if (chflgs & (ASN1_STRFLGS_ESC_CTRL|ASN1_STRFLGS_ESC_MSB)) { |
| 152 | snprintf(tmphex, sizeof tmphex, "\\%02X", chtmp); | 170 | snprintf(tmphex, sizeof tmphex, "\\%02X", chtmp); |
| 153 | if(!io_ch(arg, tmphex, 3)) return -1; | 171 | if (!io_ch(arg, tmphex, 3)) |
| 172 | return -1; | ||
| 154 | return 3; | 173 | return 3; |
| 155 | } | 174 | } |
| 156 | /* If we get this far and do any escaping at all must escape | 175 | /* If we get this far and do any escaping at all must escape |
| 157 | * the escape character itself: backslash. | 176 | * the escape character itself: backslash. |
| 158 | */ | 177 | */ |
| 159 | if (chtmp == '\\' && flags & ESC_FLAGS) { | 178 | if (chtmp == '\\' && flags & ESC_FLAGS) { |
| 160 | if(!io_ch(arg, "\\\\", 2)) return -1; | 179 | if (!io_ch(arg, "\\\\", 2)) |
| 180 | return -1; | ||
| 161 | return 2; | 181 | return 2; |
| 162 | } | 182 | } |
| 163 | if(!io_ch(arg, &chtmp, 1)) return -1; | 183 | if (!io_ch(arg, &chtmp, 1)) |
| 184 | return -1; | ||
| 164 | return 1; | 185 | return 1; |
| 165 | } | 186 | } |
| 166 | 187 | ||
| @@ -172,61 +193,72 @@ static int do_esc_char(unsigned long c, unsigned char flags, char *do_quotes, ch | |||
| 172 | * and converts to or from UTF8 as appropriate. | 193 | * and converts to or from UTF8 as appropriate. |
| 173 | */ | 194 | */ |
| 174 | 195 | ||
| 175 | static int do_buf(unsigned char *buf, int buflen, | 196 | static int |
| 176 | int type, unsigned char flags, char *quotes, char_io *io_ch, void *arg) | 197 | do_buf(unsigned char *buf, int buflen, int type, unsigned char flags, |
| 198 | char *quotes, char_io *io_ch, void *arg) | ||
| 177 | { | 199 | { |
| 178 | int i, outlen, len; | 200 | int i, outlen, len; |
| 179 | unsigned char orflags, *p, *q; | 201 | unsigned char orflags, *p, *q; |
| 180 | unsigned long c; | 202 | unsigned long c; |
| 203 | |||
| 181 | p = buf; | 204 | p = buf; |
| 182 | q = buf + buflen; | 205 | q = buf + buflen; |
| 183 | outlen = 0; | 206 | outlen = 0; |
| 184 | while(p != q) { | 207 | while (p != q) { |
| 185 | if(p == buf && flags & ASN1_STRFLGS_ESC_2253) orflags = CHARTYPE_FIRST_ESC_2253; | 208 | if (p == buf && flags & ASN1_STRFLGS_ESC_2253) |
| 186 | else orflags = 0; | 209 | orflags = CHARTYPE_FIRST_ESC_2253; |
| 187 | switch(type & BUF_TYPE_WIDTH_MASK) { | 210 | else |
| 188 | case 4: | 211 | orflags = 0; |
| 212 | switch (type & BUF_TYPE_WIDTH_MASK) { | ||
| 213 | case 4: | ||
| 189 | c = ((unsigned long)*p++) << 24; | 214 | c = ((unsigned long)*p++) << 24; |
| 190 | c |= ((unsigned long)*p++) << 16; | 215 | c |= ((unsigned long)*p++) << 16; |
| 191 | c |= ((unsigned long)*p++) << 8; | 216 | c |= ((unsigned long)*p++) << 8; |
| 192 | c |= *p++; | 217 | c |= *p++; |
| 193 | break; | 218 | break; |
| 194 | 219 | ||
| 195 | case 2: | 220 | case 2: |
| 196 | c = ((unsigned long)*p++) << 8; | 221 | c = ((unsigned long)*p++) << 8; |
| 197 | c |= *p++; | 222 | c |= *p++; |
| 198 | break; | 223 | break; |
| 199 | 224 | ||
| 200 | case 1: | 225 | case 1: |
| 201 | c = *p++; | 226 | c = *p++; |
| 202 | break; | 227 | break; |
| 203 | 228 | ||
| 204 | case 0: | 229 | case 0: |
| 205 | i = UTF8_getc(p, buflen, &c); | 230 | i = UTF8_getc(p, buflen, &c); |
| 206 | if(i < 0) return -1; /* Invalid UTF8String */ | 231 | if (i < 0) |
| 232 | return -1; /* Invalid UTF8String */ | ||
| 207 | p += i; | 233 | p += i; |
| 208 | break; | 234 | break; |
| 209 | default: | 235 | default: |
| 210 | return -1; /* invalid width */ | 236 | return -1; /* invalid width */ |
| 211 | } | 237 | } |
| 212 | if (p == q && flags & ASN1_STRFLGS_ESC_2253) orflags = CHARTYPE_LAST_ESC_2253; | 238 | if (p == q && flags & ASN1_STRFLGS_ESC_2253) |
| 213 | if(type & BUF_TYPE_CONVUTF8) { | 239 | orflags = CHARTYPE_LAST_ESC_2253; |
| 240 | if (type & BUF_TYPE_CONVUTF8) { | ||
| 214 | unsigned char utfbuf[6]; | 241 | unsigned char utfbuf[6]; |
| 215 | int utflen; | 242 | int utflen; |
| 216 | utflen = UTF8_putc(utfbuf, sizeof utfbuf, c); | 243 | utflen = UTF8_putc(utfbuf, sizeof utfbuf, c); |
| 217 | for(i = 0; i < utflen; i++) { | 244 | for (i = 0; i < utflen; i++) { |
| 218 | /* We don't need to worry about setting orflags correctly | 245 | /* We don't need to worry about setting orflags correctly |
| 219 | * because if utflen==1 its value will be correct anyway | 246 | * because if utflen==1 its value will be correct anyway |
| 220 | * otherwise each character will be > 0x7f and so the | 247 | * otherwise each character will be > 0x7f and so the |
| 221 | * character will never be escaped on first and last. | 248 | * character will never be escaped on first and last. |
| 222 | */ | 249 | */ |
| 223 | len = do_esc_char(utfbuf[i], (unsigned char)(flags | orflags), quotes, io_ch, arg); | 250 | len = do_esc_char(utfbuf[i], |
| 224 | if(len < 0) return -1; | 251 | (unsigned char)(flags | orflags), quotes, |
| 252 | io_ch, arg); | ||
| 253 | if (len < 0) | ||
| 254 | return -1; | ||
| 225 | outlen += len; | 255 | outlen += len; |
| 226 | } | 256 | } |
| 227 | } else { | 257 | } else { |
| 228 | len = do_esc_char(c, (unsigned char)(flags | orflags), quotes, io_ch, arg); | 258 | len = do_esc_char(c, (unsigned char)(flags | orflags), |
| 229 | if(len < 0) return -1; | 259 | quotes, io_ch, arg); |
| 260 | if (len < 0) | ||
| 261 | return -1; | ||
| 230 | outlen += len; | 262 | outlen += len; |
| 231 | } | 263 | } |
| 232 | } | 264 | } |
| @@ -235,18 +267,20 @@ static int do_buf(unsigned char *buf, int buflen, | |||
| 235 | 267 | ||
| 236 | /* This function hex dumps a buffer of characters */ | 268 | /* This function hex dumps a buffer of characters */ |
| 237 | 269 | ||
| 238 | static int do_hex_dump(char_io *io_ch, void *arg, unsigned char *buf, int buflen) | 270 | static int |
| 271 | do_hex_dump(char_io *io_ch, void *arg, unsigned char *buf, int buflen) | ||
| 239 | { | 272 | { |
| 240 | static const char hexdig[] = "0123456789ABCDEF"; | 273 | static const char hexdig[] = "0123456789ABCDEF"; |
| 241 | unsigned char *p, *q; | 274 | unsigned char *p, *q; |
| 242 | char hextmp[2]; | 275 | char hextmp[2]; |
| 243 | if(arg) { | 276 | if (arg) { |
| 244 | p = buf; | 277 | p = buf; |
| 245 | q = buf + buflen; | 278 | q = buf + buflen; |
| 246 | while(p != q) { | 279 | while (p != q) { |
| 247 | hextmp[0] = hexdig[*p >> 4]; | 280 | hextmp[0] = hexdig[*p >> 4]; |
| 248 | hextmp[1] = hexdig[*p & 0xf]; | 281 | hextmp[1] = hexdig[*p & 0xf]; |
| 249 | if(!io_ch(arg, hextmp, 2)) return -1; | 282 | if (!io_ch(arg, hextmp, 2)) |
| 283 | return -1; | ||
| 250 | p++; | 284 | p++; |
| 251 | } | 285 | } |
| 252 | } | 286 | } |
| @@ -259,7 +293,8 @@ static int do_hex_dump(char_io *io_ch, void *arg, unsigned char *buf, int buflen | |||
| 259 | * #01234 format. | 293 | * #01234 format. |
| 260 | */ | 294 | */ |
| 261 | 295 | ||
| 262 | static int do_dump(unsigned long lflags, char_io *io_ch, void *arg, ASN1_STRING *str) | 296 | static int |
| 297 | do_dump(unsigned long lflags, char_io *io_ch, void *arg, ASN1_STRING *str) | ||
| 263 | { | 298 | { |
| 264 | /* Placing the ASN1_STRING in a temp ASN1_TYPE allows | 299 | /* Placing the ASN1_STRING in a temp ASN1_TYPE allows |
| 265 | * the DER encoding to readily obtained | 300 | * the DER encoding to readily obtained |
| @@ -268,23 +303,27 @@ static int do_dump(unsigned long lflags, char_io *io_ch, void *arg, ASN1_STRING | |||
| 268 | unsigned char *der_buf, *p; | 303 | unsigned char *der_buf, *p; |
| 269 | int outlen, der_len; | 304 | int outlen, der_len; |
| 270 | 305 | ||
| 271 | if(!io_ch(arg, "#", 1)) return -1; | 306 | if (!io_ch(arg, "#", 1)) |
| 307 | return -1; | ||
| 272 | /* If we don't dump DER encoding just dump content octets */ | 308 | /* If we don't dump DER encoding just dump content octets */ |
| 273 | if(!(lflags & ASN1_STRFLGS_DUMP_DER)) { | 309 | if (!(lflags & ASN1_STRFLGS_DUMP_DER)) { |
| 274 | outlen = do_hex_dump(io_ch, arg, str->data, str->length); | 310 | outlen = do_hex_dump(io_ch, arg, str->data, str->length); |
| 275 | if(outlen < 0) return -1; | 311 | if (outlen < 0) |
| 312 | return -1; | ||
| 276 | return outlen + 1; | 313 | return outlen + 1; |
| 277 | } | 314 | } |
| 278 | t.type = str->type; | 315 | t.type = str->type; |
| 279 | t.value.ptr = (char *)str; | 316 | t.value.ptr = (char *)str; |
| 280 | der_len = i2d_ASN1_TYPE(&t, NULL); | 317 | der_len = i2d_ASN1_TYPE(&t, NULL); |
| 281 | der_buf = malloc(der_len); | 318 | der_buf = malloc(der_len); |
| 282 | if(!der_buf) return -1; | 319 | if (!der_buf) |
| 320 | return -1; | ||
| 283 | p = der_buf; | 321 | p = der_buf; |
| 284 | i2d_ASN1_TYPE(&t, &p); | 322 | i2d_ASN1_TYPE(&t, &p); |
| 285 | outlen = do_hex_dump(io_ch, arg, der_buf, der_len); | 323 | outlen = do_hex_dump(io_ch, arg, der_buf, der_len); |
| 286 | free(der_buf); | 324 | free(der_buf); |
| 287 | if(outlen < 0) return -1; | 325 | if (outlen < 0) |
| 326 | return -1; | ||
| 288 | return outlen + 1; | 327 | return outlen + 1; |
| 289 | } | 328 | } |
| 290 | 329 | ||
| @@ -311,86 +350,102 @@ static const signed char tag2nbyte[] = { | |||
| 311 | * occurred. | 350 | * occurred. |
| 312 | */ | 351 | */ |
| 313 | 352 | ||
| 314 | static int do_print_ex(char_io *io_ch, void *arg, unsigned long lflags, ASN1_STRING *str) | 353 | static int |
| 354 | do_print_ex(char_io *io_ch, void *arg, unsigned long lflags, ASN1_STRING *str) | ||
| 315 | { | 355 | { |
| 316 | int outlen, len; | 356 | int outlen, len; |
| 317 | int type; | 357 | int type; |
| 318 | char quotes; | 358 | char quotes; |
| 319 | unsigned char flags; | 359 | unsigned char flags; |
| 360 | |||
| 320 | quotes = 0; | 361 | quotes = 0; |
| 321 | /* Keep a copy of escape flags */ | 362 | /* Keep a copy of escape flags */ |
| 322 | flags = (unsigned char)(lflags & ESC_FLAGS); | 363 | flags = (unsigned char)(lflags & ESC_FLAGS); |
| 323 | |||
| 324 | type = str->type; | 364 | type = str->type; |
| 325 | |||
| 326 | outlen = 0; | 365 | outlen = 0; |
| 327 | 366 | ||
| 328 | 367 | if (lflags & ASN1_STRFLGS_SHOW_TYPE) { | |
| 329 | if(lflags & ASN1_STRFLGS_SHOW_TYPE) { | ||
| 330 | const char *tagname; | 368 | const char *tagname; |
| 331 | tagname = ASN1_tag2str(type); | 369 | tagname = ASN1_tag2str(type); |
| 332 | outlen += strlen(tagname); | 370 | outlen += strlen(tagname); |
| 333 | if(!io_ch(arg, tagname, outlen) || !io_ch(arg, ":", 1)) return -1; | 371 | if (!io_ch(arg, tagname, outlen) || !io_ch(arg, ":", 1)) |
| 372 | return -1; | ||
| 334 | outlen++; | 373 | outlen++; |
| 335 | } | 374 | } |
| 336 | 375 | ||
| 337 | /* Decide what to do with type, either dump content or display it */ | 376 | /* Decide what to do with type, either dump content or display it */ |
| 338 | 377 | ||
| 339 | /* Dump everything */ | 378 | /* Dump everything */ |
| 340 | if(lflags & ASN1_STRFLGS_DUMP_ALL) type = -1; | 379 | if (lflags & ASN1_STRFLGS_DUMP_ALL) |
| 380 | type = -1; | ||
| 341 | /* Ignore the string type */ | 381 | /* Ignore the string type */ |
| 342 | else if(lflags & ASN1_STRFLGS_IGNORE_TYPE) type = 1; | 382 | else if (lflags & ASN1_STRFLGS_IGNORE_TYPE) |
| 383 | type = 1; | ||
| 343 | else { | 384 | else { |
| 344 | /* Else determine width based on type */ | 385 | /* Else determine width based on type */ |
| 345 | if((type > 0) && (type < 31)) type = tag2nbyte[type]; | 386 | if ((type > 0) && (type < 31)) |
| 346 | else type = -1; | 387 | type = tag2nbyte[type]; |
| 347 | if((type == -1) && !(lflags & ASN1_STRFLGS_DUMP_UNKNOWN)) type = 1; | 388 | else |
| 389 | type = -1; | ||
| 390 | if ((type == -1) && !(lflags & ASN1_STRFLGS_DUMP_UNKNOWN)) | ||
| 391 | type = 1; | ||
| 348 | } | 392 | } |
| 349 | 393 | ||
| 350 | if(type == -1) { | 394 | if (type == -1) { |
| 351 | len = do_dump(lflags, io_ch, arg, str); | 395 | len = do_dump(lflags, io_ch, arg, str); |
| 352 | if(len < 0) return -1; | 396 | if (len < 0) |
| 397 | return -1; | ||
| 353 | outlen += len; | 398 | outlen += len; |
| 354 | return outlen; | 399 | return outlen; |
| 355 | } | 400 | } |
| 356 | 401 | ||
| 357 | if(lflags & ASN1_STRFLGS_UTF8_CONVERT) { | 402 | if (lflags & ASN1_STRFLGS_UTF8_CONVERT) { |
| 358 | /* Note: if string is UTF8 and we want | 403 | /* Note: if string is UTF8 and we want |
| 359 | * to convert to UTF8 then we just interpret | 404 | * to convert to UTF8 then we just interpret |
| 360 | * it as 1 byte per character to avoid converting | 405 | * it as 1 byte per character to avoid converting |
| 361 | * twice. | 406 | * twice. |
| 362 | */ | 407 | */ |
| 363 | if(!type) type = 1; | 408 | if (!type) |
| 364 | else type |= BUF_TYPE_CONVUTF8; | 409 | type = 1; |
| 410 | else | ||
| 411 | type |= BUF_TYPE_CONVUTF8; | ||
| 365 | } | 412 | } |
| 366 | 413 | ||
| 367 | len = do_buf(str->data, str->length, type, flags, "es, io_ch, NULL); | 414 | len = do_buf(str->data, str->length, type, flags, "es, io_ch, NULL); |
| 368 | if(len < 0) return -1; | 415 | if (len < 0) |
| 416 | return -1; | ||
| 369 | outlen += len; | 417 | outlen += len; |
| 370 | if(quotes) outlen += 2; | 418 | if (quotes) |
| 371 | if(!arg) return outlen; | 419 | outlen += 2; |
| 372 | if(quotes && !io_ch(arg, "\"", 1)) return -1; | 420 | if (!arg) |
| 373 | if(do_buf(str->data, str->length, type, flags, NULL, io_ch, arg) < 0) | 421 | return outlen; |
| 422 | if (quotes && !io_ch(arg, "\"", 1)) | ||
| 423 | return -1; | ||
| 424 | if (do_buf(str->data, str->length, type, flags, NULL, io_ch, arg) < 0) | ||
| 425 | return -1; | ||
| 426 | if (quotes && !io_ch(arg, "\"", 1)) | ||
| 374 | return -1; | 427 | return -1; |
| 375 | if(quotes && !io_ch(arg, "\"", 1)) return -1; | ||
| 376 | return outlen; | 428 | return outlen; |
| 377 | } | 429 | } |
| 378 | 430 | ||
| 379 | /* Used for line indenting: print 'indent' spaces */ | 431 | /* Used for line indenting: print 'indent' spaces */ |
| 380 | 432 | ||
| 381 | static int do_indent(char_io *io_ch, void *arg, int indent) | 433 | static int |
| 434 | do_indent(char_io *io_ch, void *arg, int indent) | ||
| 382 | { | 435 | { |
| 383 | int i; | 436 | int i; |
| 384 | for(i = 0; i < indent; i++) | 437 | for (i = 0; i < indent; i++) |
| 385 | if(!io_ch(arg, " ", 1)) return 0; | 438 | if (!io_ch(arg, " ", 1)) |
| 439 | return 0; | ||
| 386 | return 1; | 440 | return 1; |
| 387 | } | 441 | } |
| 388 | 442 | ||
| 389 | #define FN_WIDTH_LN 25 | 443 | #define FN_WIDTH_LN 25 |
| 390 | #define FN_WIDTH_SN 10 | 444 | #define FN_WIDTH_SN 10 |
| 391 | 445 | ||
| 392 | static int do_name_ex(char_io *io_ch, void *arg, X509_NAME *n, | 446 | static int |
| 393 | int indent, unsigned long flags) | 447 | do_name_ex(char_io *io_ch, void *arg, X509_NAME *n, int indent, |
| 448 | unsigned long flags) | ||
| 394 | { | 449 | { |
| 395 | int i, prev = -1, orflags, cnt; | 450 | int i, prev = -1, orflags, cnt; |
| 396 | int fn_opt, fn_nid; | 451 | int fn_opt, fn_nid; |
| @@ -402,18 +457,22 @@ static int do_name_ex(char_io *io_ch, void *arg, X509_NAME *n, | |||
| 402 | int outlen, len; | 457 | int outlen, len; |
| 403 | char *sep_dn, *sep_mv, *sep_eq; | 458 | char *sep_dn, *sep_mv, *sep_eq; |
| 404 | int sep_dn_len, sep_mv_len, sep_eq_len; | 459 | int sep_dn_len, sep_mv_len, sep_eq_len; |
| 405 | if(indent < 0) indent = 0; | 460 | |
| 461 | if (indent < 0) | ||
| 462 | indent = 0; | ||
| 406 | outlen = indent; | 463 | outlen = indent; |
| 407 | if(!do_indent(io_ch, arg, indent)) return -1; | 464 | if (!do_indent(io_ch, arg, indent)) |
| 465 | return -1; | ||
| 466 | |||
| 408 | switch (flags & XN_FLAG_SEP_MASK) { | 467 | switch (flags & XN_FLAG_SEP_MASK) { |
| 409 | case XN_FLAG_SEP_MULTILINE: | 468 | case XN_FLAG_SEP_MULTILINE: |
| 410 | sep_dn = "\n"; | 469 | sep_dn = "\n"; |
| 411 | sep_dn_len = 1; | 470 | sep_dn_len = 1; |
| 412 | sep_mv = " + "; | 471 | sep_mv = " + "; |
| 413 | sep_mv_len = 3; | 472 | sep_mv_len = 3; |
| 414 | break; | 473 | break; |
| 415 | 474 | ||
| 416 | case XN_FLAG_SEP_COMMA_PLUS: | 475 | case XN_FLAG_SEP_COMMA_PLUS: |
| 417 | sep_dn = ","; | 476 | sep_dn = ","; |
| 418 | sep_dn_len = 1; | 477 | sep_dn_len = 1; |
| 419 | sep_mv = "+"; | 478 | sep_mv = "+"; |
| @@ -421,7 +480,7 @@ static int do_name_ex(char_io *io_ch, void *arg, X509_NAME *n, | |||
| 421 | indent = 0; | 480 | indent = 0; |
| 422 | break; | 481 | break; |
| 423 | 482 | ||
| 424 | case XN_FLAG_SEP_CPLUS_SPC: | 483 | case XN_FLAG_SEP_CPLUS_SPC: |
| 425 | sep_dn = ", "; | 484 | sep_dn = ", "; |
| 426 | sep_dn_len = 2; | 485 | sep_dn_len = 2; |
| 427 | sep_mv = " + "; | 486 | sep_mv = " + "; |
| @@ -429,7 +488,7 @@ static int do_name_ex(char_io *io_ch, void *arg, X509_NAME *n, | |||
| 429 | indent = 0; | 488 | indent = 0; |
| 430 | break; | 489 | break; |
| 431 | 490 | ||
| 432 | case XN_FLAG_SEP_SPLUS_SPC: | 491 | case XN_FLAG_SEP_SPLUS_SPC: |
| 433 | sep_dn = "; "; | 492 | sep_dn = "; "; |
| 434 | sep_dn_len = 2; | 493 | sep_dn_len = 2; |
| 435 | sep_mv = " + "; | 494 | sep_mv = " + "; |
| @@ -437,11 +496,11 @@ static int do_name_ex(char_io *io_ch, void *arg, X509_NAME *n, | |||
| 437 | indent = 0; | 496 | indent = 0; |
| 438 | break; | 497 | break; |
| 439 | 498 | ||
| 440 | default: | 499 | default: |
| 441 | return -1; | 500 | return -1; |
| 442 | } | 501 | } |
| 443 | 502 | ||
| 444 | if(flags & XN_FLAG_SPC_EQ) { | 503 | if (flags & XN_FLAG_SPC_EQ) { |
| 445 | sep_eq = " = "; | 504 | sep_eq = " = "; |
| 446 | sep_eq_len = 3; | 505 | sep_eq_len = 3; |
| 447 | } else { | 506 | } else { |
| @@ -451,19 +510,23 @@ static int do_name_ex(char_io *io_ch, void *arg, X509_NAME *n, | |||
| 451 | 510 | ||
| 452 | fn_opt = flags & XN_FLAG_FN_MASK; | 511 | fn_opt = flags & XN_FLAG_FN_MASK; |
| 453 | 512 | ||
| 454 | cnt = X509_NAME_entry_count(n); | 513 | cnt = X509_NAME_entry_count(n); |
| 455 | for(i = 0; i < cnt; i++) { | 514 | for (i = 0; i < cnt; i++) { |
| 456 | if(flags & XN_FLAG_DN_REV) | 515 | if (flags & XN_FLAG_DN_REV) |
| 457 | ent = X509_NAME_get_entry(n, cnt - i - 1); | 516 | ent = X509_NAME_get_entry(n, cnt - i - 1); |
| 458 | else ent = X509_NAME_get_entry(n, i); | 517 | else |
| 459 | if(prev != -1) { | 518 | ent = X509_NAME_get_entry(n, i); |
| 460 | if(prev == ent->set) { | 519 | if (prev != -1) { |
| 461 | if(!io_ch(arg, sep_mv, sep_mv_len)) return -1; | 520 | if (prev == ent->set) { |
| 521 | if (!io_ch(arg, sep_mv, sep_mv_len)) | ||
| 522 | return -1; | ||
| 462 | outlen += sep_mv_len; | 523 | outlen += sep_mv_len; |
| 463 | } else { | 524 | } else { |
| 464 | if(!io_ch(arg, sep_dn, sep_dn_len)) return -1; | 525 | if (!io_ch(arg, sep_dn, sep_dn_len)) |
| 526 | return -1; | ||
| 465 | outlen += sep_dn_len; | 527 | outlen += sep_dn_len; |
| 466 | if(!do_indent(io_ch, arg, indent)) return -1; | 528 | if (!do_indent(io_ch, arg, indent)) |
| 529 | return -1; | ||
| 467 | outlen += indent; | 530 | outlen += indent; |
| 468 | } | 531 | } |
| 469 | } | 532 | } |
| @@ -471,17 +534,18 @@ static int do_name_ex(char_io *io_ch, void *arg, X509_NAME *n, | |||
| 471 | fn = X509_NAME_ENTRY_get_object(ent); | 534 | fn = X509_NAME_ENTRY_get_object(ent); |
| 472 | val = X509_NAME_ENTRY_get_data(ent); | 535 | val = X509_NAME_ENTRY_get_data(ent); |
| 473 | fn_nid = OBJ_obj2nid(fn); | 536 | fn_nid = OBJ_obj2nid(fn); |
| 474 | if(fn_opt != XN_FLAG_FN_NONE) { | 537 | if (fn_opt != XN_FLAG_FN_NONE) { |
| 475 | int objlen, fld_len; | 538 | int objlen, fld_len; |
| 476 | if((fn_opt == XN_FLAG_FN_OID) || (fn_nid==NID_undef) ) { | 539 | if ((fn_opt == XN_FLAG_FN_OID) || |
| 540 | (fn_nid == NID_undef)) { | ||
| 477 | OBJ_obj2txt(objtmp, sizeof objtmp, fn, 1); | 541 | OBJ_obj2txt(objtmp, sizeof objtmp, fn, 1); |
| 478 | fld_len = 0; /* XXX: what should this be? */ | 542 | fld_len = 0; /* XXX: what should this be? */ |
| 479 | objbuf = objtmp; | 543 | objbuf = objtmp; |
| 480 | } else { | 544 | } else { |
| 481 | if(fn_opt == XN_FLAG_FN_SN) { | 545 | if (fn_opt == XN_FLAG_FN_SN) { |
| 482 | fld_len = FN_WIDTH_SN; | 546 | fld_len = FN_WIDTH_SN; |
| 483 | objbuf = OBJ_nid2sn(fn_nid); | 547 | objbuf = OBJ_nid2sn(fn_nid); |
| 484 | } else if(fn_opt == XN_FLAG_FN_LN) { | 548 | } else if (fn_opt == XN_FLAG_FN_LN) { |
| 485 | fld_len = FN_WIDTH_LN; | 549 | fld_len = FN_WIDTH_LN; |
| 486 | objbuf = OBJ_nid2ln(fn_nid); | 550 | objbuf = OBJ_nid2ln(fn_nid); |
| 487 | } else { | 551 | } else { |
| @@ -490,24 +554,30 @@ static int do_name_ex(char_io *io_ch, void *arg, X509_NAME *n, | |||
| 490 | } | 554 | } |
| 491 | } | 555 | } |
| 492 | objlen = strlen(objbuf); | 556 | objlen = strlen(objbuf); |
| 493 | if(!io_ch(arg, objbuf, objlen)) return -1; | 557 | if (!io_ch(arg, objbuf, objlen)) |
| 558 | return -1; | ||
| 494 | if ((objlen < fld_len) && (flags & XN_FLAG_FN_ALIGN)) { | 559 | if ((objlen < fld_len) && (flags & XN_FLAG_FN_ALIGN)) { |
| 495 | if (!do_indent(io_ch, arg, fld_len - objlen)) return -1; | 560 | if (!do_indent(io_ch, arg, fld_len - objlen)) |
| 561 | return -1; | ||
| 496 | outlen += fld_len - objlen; | 562 | outlen += fld_len - objlen; |
| 497 | } | 563 | } |
| 498 | if(!io_ch(arg, sep_eq, sep_eq_len)) return -1; | 564 | if (!io_ch(arg, sep_eq, sep_eq_len)) |
| 565 | return -1; | ||
| 499 | outlen += objlen + sep_eq_len; | 566 | outlen += objlen + sep_eq_len; |
| 500 | } | 567 | } |
| 501 | /* If the field name is unknown then fix up the DER dump | 568 | /* If the field name is unknown then fix up the DER dump |
| 502 | * flag. We might want to limit this further so it will | 569 | * flag. We might want to limit this further so it will |
| 503 | * DER dump on anything other than a few 'standard' fields. | 570 | * DER dump on anything other than a few 'standard' fields. |
| 504 | */ | 571 | */ |
| 505 | if((fn_nid == NID_undef) && (flags & XN_FLAG_DUMP_UNKNOWN_FIELDS)) | 572 | if ((fn_nid == NID_undef) && |
| 506 | orflags = ASN1_STRFLGS_DUMP_ALL; | 573 | (flags & XN_FLAG_DUMP_UNKNOWN_FIELDS)) |
| 507 | else orflags = 0; | 574 | orflags = ASN1_STRFLGS_DUMP_ALL; |
| 508 | 575 | else | |
| 576 | orflags = 0; | ||
| 577 | |||
| 509 | len = do_print_ex(io_ch, arg, flags | orflags, val); | 578 | len = do_print_ex(io_ch, arg, flags | orflags, val); |
| 510 | if(len < 0) return -1; | 579 | if (len < 0) |
| 580 | return -1; | ||
| 511 | outlen += len; | 581 | outlen += len; |
| 512 | } | 582 | } |
| 513 | return outlen; | 583 | return outlen; |
| @@ -515,36 +585,41 @@ static int do_name_ex(char_io *io_ch, void *arg, X509_NAME *n, | |||
| 515 | 585 | ||
| 516 | /* Wrappers round the main functions */ | 586 | /* Wrappers round the main functions */ |
| 517 | 587 | ||
| 518 | int X509_NAME_print_ex(BIO *out, X509_NAME *nm, int indent, unsigned long flags) | 588 | int |
| 589 | X509_NAME_print_ex(BIO *out, X509_NAME *nm, int indent, unsigned long flags) | ||
| 519 | { | 590 | { |
| 520 | if(flags == XN_FLAG_COMPAT) | 591 | if (flags == XN_FLAG_COMPAT) |
| 521 | return X509_NAME_print(out, nm, indent); | 592 | return X509_NAME_print(out, nm, indent); |
| 522 | return do_name_ex(send_bio_chars, out, nm, indent, flags); | 593 | return do_name_ex(send_bio_chars, out, nm, indent, flags); |
| 523 | } | 594 | } |
| 524 | 595 | ||
| 525 | #ifndef OPENSSL_NO_FP_API | 596 | #ifndef OPENSSL_NO_FP_API |
| 526 | int X509_NAME_print_ex_fp(FILE *fp, X509_NAME *nm, int indent, unsigned long flags) | 597 | int |
| 598 | X509_NAME_print_ex_fp(FILE *fp, X509_NAME *nm, int indent, unsigned long flags) | ||
| 527 | { | 599 | { |
| 528 | if(flags == XN_FLAG_COMPAT) { | 600 | if (flags == XN_FLAG_COMPAT) { |
| 529 | BIO *btmp; | 601 | BIO *btmp; |
| 530 | int ret; | 602 | int ret; |
| 531 | btmp = BIO_new_fp(fp, BIO_NOCLOSE); | 603 | btmp = BIO_new_fp(fp, BIO_NOCLOSE); |
| 532 | if(!btmp) return -1; | 604 | if (!btmp) |
| 605 | return -1; | ||
| 533 | ret = X509_NAME_print(btmp, nm, indent); | 606 | ret = X509_NAME_print(btmp, nm, indent); |
| 534 | BIO_free(btmp); | 607 | BIO_free(btmp); |
| 535 | return ret; | 608 | return ret; |
| 536 | } | 609 | } |
| 537 | return do_name_ex(send_fp_chars, fp, nm, indent, flags); | 610 | return do_name_ex(send_fp_chars, fp, nm, indent, flags); |
| 538 | } | 611 | } |
| 539 | #endif | 612 | #endif |
| 540 | 613 | ||
| 541 | int ASN1_STRING_print_ex(BIO *out, ASN1_STRING *str, unsigned long flags) | 614 | int |
| 615 | ASN1_STRING_print_ex(BIO *out, ASN1_STRING *str, unsigned long flags) | ||
| 542 | { | 616 | { |
| 543 | return do_print_ex(send_bio_chars, out, flags, str); | 617 | return do_print_ex(send_bio_chars, out, flags, str); |
| 544 | } | 618 | } |
| 545 | 619 | ||
| 546 | #ifndef OPENSSL_NO_FP_API | 620 | #ifndef OPENSSL_NO_FP_API |
| 547 | int ASN1_STRING_print_ex_fp(FILE *fp, ASN1_STRING *str, unsigned long flags) | 621 | int |
| 622 | ASN1_STRING_print_ex_fp(FILE *fp, ASN1_STRING *str, unsigned long flags) | ||
| 548 | { | 623 | { |
| 549 | return do_print_ex(send_fp_chars, fp, flags, str); | 624 | return do_print_ex(send_fp_chars, fp, flags, str); |
| 550 | } | 625 | } |
| @@ -554,20 +629,27 @@ int ASN1_STRING_print_ex_fp(FILE *fp, ASN1_STRING *str, unsigned long flags) | |||
| 554 | * in output string or a negative error code | 629 | * in output string or a negative error code |
| 555 | */ | 630 | */ |
| 556 | 631 | ||
| 557 | int ASN1_STRING_to_UTF8(unsigned char **out, ASN1_STRING *in) | 632 | int |
| 633 | ASN1_STRING_to_UTF8(unsigned char **out, ASN1_STRING *in) | ||
| 558 | { | 634 | { |
| 559 | ASN1_STRING stmp, *str = &stmp; | 635 | ASN1_STRING stmp, *str = &stmp; |
| 560 | int mbflag, type, ret; | 636 | int mbflag, type, ret; |
| 561 | if(!in) return -1; | 637 | |
| 638 | if (!in) | ||
| 639 | return -1; | ||
| 562 | type = in->type; | 640 | type = in->type; |
| 563 | if((type < 0) || (type > 30)) return -1; | 641 | if ((type < 0) || (type > 30)) |
| 642 | return -1; | ||
| 564 | mbflag = tag2nbyte[type]; | 643 | mbflag = tag2nbyte[type]; |
| 565 | if(mbflag == -1) return -1; | 644 | if (mbflag == -1) |
| 645 | return -1; | ||
| 566 | mbflag |= MBSTRING_FLAG; | 646 | mbflag |= MBSTRING_FLAG; |
| 567 | stmp.data = NULL; | 647 | stmp.data = NULL; |
| 568 | stmp.length = 0; | 648 | stmp.length = 0; |
| 569 | ret = ASN1_mbstring_copy(&str, in->data, in->length, mbflag, B_ASN1_UTF8STRING); | 649 | ret = ASN1_mbstring_copy(&str, in->data, in->length, mbflag, |
| 570 | if(ret < 0) return ret; | 650 | B_ASN1_UTF8STRING); |
| 651 | if (ret < 0) | ||
| 652 | return ret; | ||
| 571 | *out = stmp.data; | 653 | *out = stmp.data; |
| 572 | return stmp.length; | 654 | return stmp.length; |
| 573 | } | 655 | } |
diff --git a/src/lib/libssl/src/crypto/asn1/a_strnid.c b/src/lib/libssl/src/crypto/asn1/a_strnid.c index 6c59dcc8ec..d1b804aec1 100644 --- a/src/lib/libssl/src/crypto/asn1/a_strnid.c +++ b/src/lib/libssl/src/crypto/asn1/a_strnid.c | |||
| @@ -10,7 +10,7 @@ | |||
| 10 | * are met: | 10 | * are met: |
| 11 | * | 11 | * |
| 12 | * 1. Redistributions of source code must retain the above copyright | 12 | * 1. Redistributions of source code must retain the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer. | 13 | * notice, this list of conditions and the following disclaimer. |
| 14 | * | 14 | * |
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | 15 | * 2. Redistributions in binary form must reproduce the above copyright |
| 16 | * notice, this list of conditions and the following disclaimer in | 16 | * notice, this list of conditions and the following disclaimer in |
| @@ -66,7 +66,7 @@ | |||
| 66 | static STACK_OF(ASN1_STRING_TABLE) *stable = NULL; | 66 | static STACK_OF(ASN1_STRING_TABLE) *stable = NULL; |
| 67 | static void st_free(ASN1_STRING_TABLE *tbl); | 67 | static void st_free(ASN1_STRING_TABLE *tbl); |
| 68 | static int sk_table_cmp(const ASN1_STRING_TABLE * const *a, | 68 | static int sk_table_cmp(const ASN1_STRING_TABLE * const *a, |
| 69 | const ASN1_STRING_TABLE * const *b); | 69 | const ASN1_STRING_TABLE * const *b); |
| 70 | 70 | ||
| 71 | 71 | ||
| 72 | /* This is the global mask for the mbstring functions: this is use to | 72 | /* This is the global mask for the mbstring functions: this is use to |
| @@ -76,12 +76,14 @@ static int sk_table_cmp(const ASN1_STRING_TABLE * const *a, | |||
| 76 | 76 | ||
| 77 | static unsigned long global_mask = 0xFFFFFFFFL; | 77 | static unsigned long global_mask = 0xFFFFFFFFL; |
| 78 | 78 | ||
| 79 | void ASN1_STRING_set_default_mask(unsigned long mask) | 79 | void |
| 80 | ASN1_STRING_set_default_mask(unsigned long mask) | ||
| 80 | { | 81 | { |
| 81 | global_mask = mask; | 82 | global_mask = mask; |
| 82 | } | 83 | } |
| 83 | 84 | ||
| 84 | unsigned long ASN1_STRING_get_default_mask(void) | 85 | unsigned long |
| 86 | ASN1_STRING_get_default_mask(void) | ||
| 85 | { | 87 | { |
| 86 | return global_mask; | 88 | return global_mask; |
| 87 | } | 89 | } |
| @@ -95,47 +97,59 @@ unsigned long ASN1_STRING_get_default_mask(void) | |||
| 95 | * default: the default value, Printable, T61, BMP. | 97 | * default: the default value, Printable, T61, BMP. |
| 96 | */ | 98 | */ |
| 97 | 99 | ||
| 98 | int ASN1_STRING_set_default_mask_asc(const char *p) | 100 | int |
| 101 | ASN1_STRING_set_default_mask_asc(const char *p) | ||
| 99 | { | 102 | { |
| 100 | unsigned long mask; | 103 | unsigned long mask; |
| 101 | char *end; | 104 | char *end; |
| 102 | if(!strncmp(p, "MASK:", 5)) { | 105 | |
| 103 | if(!p[5]) return 0; | 106 | if (!strncmp(p, "MASK:", 5)) { |
| 107 | if (!p[5]) | ||
| 108 | return 0; | ||
| 104 | mask = strtoul(p + 5, &end, 0); | 109 | mask = strtoul(p + 5, &end, 0); |
| 105 | if(*end) return 0; | 110 | if (*end) |
| 106 | } else if(!strcmp(p, "nombstr")) | 111 | return 0; |
| 107 | mask = ~((unsigned long)(B_ASN1_BMPSTRING|B_ASN1_UTF8STRING)); | 112 | } else if (!strcmp(p, "nombstr")) |
| 108 | else if(!strcmp(p, "pkix")) | 113 | mask = ~((unsigned long)(B_ASN1_BMPSTRING|B_ASN1_UTF8STRING)); |
| 109 | mask = ~((unsigned long)B_ASN1_T61STRING); | 114 | else if (!strcmp(p, "pkix")) |
| 110 | else if(!strcmp(p, "utf8only")) mask = B_ASN1_UTF8STRING; | 115 | mask = ~((unsigned long)B_ASN1_T61STRING); |
| 111 | else if(!strcmp(p, "default")) | 116 | else if (!strcmp(p, "utf8only")) |
| 112 | mask = 0xFFFFFFFFL; | 117 | mask = B_ASN1_UTF8STRING; |
| 113 | else return 0; | 118 | else if (!strcmp(p, "default")) |
| 119 | mask = 0xFFFFFFFFL; | ||
| 120 | else | ||
| 121 | return 0; | ||
| 114 | ASN1_STRING_set_default_mask(mask); | 122 | ASN1_STRING_set_default_mask(mask); |
| 115 | return 1; | 123 | return 1; |
| 116 | } | 124 | } |
| 117 | 125 | ||
| 118 | /* The following function generates an ASN1_STRING based on limits in a table. | 126 | /* The following function generates an ASN1_STRING based on limits in a table. |
| 119 | * Frequently the types and length of an ASN1_STRING are restricted by a | 127 | * Frequently the types and length of an ASN1_STRING are restricted by a |
| 120 | * corresponding OID. For example certificates and certificate requests. | 128 | * corresponding OID. For example certificates and certificate requests. |
| 121 | */ | 129 | */ |
| 122 | 130 | ||
| 123 | ASN1_STRING *ASN1_STRING_set_by_NID(ASN1_STRING **out, const unsigned char *in, | 131 | ASN1_STRING * |
| 124 | int inlen, int inform, int nid) | 132 | ASN1_STRING_set_by_NID(ASN1_STRING **out, const unsigned char *in, int inlen, |
| 133 | int inform, int nid) | ||
| 125 | { | 134 | { |
| 126 | ASN1_STRING_TABLE *tbl; | 135 | ASN1_STRING_TABLE *tbl; |
| 127 | ASN1_STRING *str = NULL; | 136 | ASN1_STRING *str = NULL; |
| 128 | unsigned long mask; | 137 | unsigned long mask; |
| 129 | int ret; | 138 | int ret; |
| 130 | if(!out) out = &str; | 139 | if (!out) |
| 140 | out = &str; | ||
| 131 | tbl = ASN1_STRING_TABLE_get(nid); | 141 | tbl = ASN1_STRING_TABLE_get(nid); |
| 132 | if(tbl) { | 142 | if (tbl) { |
| 133 | mask = tbl->mask; | 143 | mask = tbl->mask; |
| 134 | if(!(tbl->flags & STABLE_NO_MASK)) mask &= global_mask; | 144 | if (!(tbl->flags & STABLE_NO_MASK)) |
| 145 | mask &= global_mask; | ||
| 135 | ret = ASN1_mbstring_ncopy(out, in, inlen, inform, mask, | 146 | ret = ASN1_mbstring_ncopy(out, in, inlen, inform, mask, |
| 136 | tbl->minsize, tbl->maxsize); | 147 | tbl->minsize, tbl->maxsize); |
| 137 | } else ret = ASN1_mbstring_copy(out, in, inlen, inform, DIRSTRING_TYPE & global_mask); | 148 | } else |
| 138 | if(ret <= 0) return NULL; | 149 | ret = ASN1_mbstring_copy(out, in, inlen, inform, |
| 150 | DIRSTRING_TYPE & global_mask); | ||
| 151 | if (ret <= 0) | ||
| 152 | return NULL; | ||
| 139 | return *out; | 153 | return *out; |
| 140 | } | 154 | } |
| 141 | 155 | ||
| @@ -158,99 +172,116 @@ ASN1_STRING *ASN1_STRING_set_by_NID(ASN1_STRING **out, const unsigned char *in, | |||
| 158 | /* This table must be kept in NID order */ | 172 | /* This table must be kept in NID order */ |
| 159 | 173 | ||
| 160 | static const ASN1_STRING_TABLE tbl_standard[] = { | 174 | static const ASN1_STRING_TABLE tbl_standard[] = { |
| 161 | {NID_commonName, 1, ub_common_name, DIRSTRING_TYPE, 0}, | 175 | {NID_commonName, 1, ub_common_name, DIRSTRING_TYPE, 0}, |
| 162 | {NID_countryName, 2, 2, B_ASN1_PRINTABLESTRING, STABLE_NO_MASK}, | 176 | {NID_countryName, 2, 2, B_ASN1_PRINTABLESTRING, STABLE_NO_MASK}, |
| 163 | {NID_localityName, 1, ub_locality_name, DIRSTRING_TYPE, 0}, | 177 | {NID_localityName, 1, ub_locality_name, DIRSTRING_TYPE, 0}, |
| 164 | {NID_stateOrProvinceName, 1, ub_state_name, DIRSTRING_TYPE, 0}, | 178 | {NID_stateOrProvinceName, 1, ub_state_name, DIRSTRING_TYPE, 0}, |
| 165 | {NID_organizationName, 1, ub_organization_name, DIRSTRING_TYPE, 0}, | 179 | {NID_organizationName, 1, ub_organization_name, DIRSTRING_TYPE, 0}, |
| 166 | {NID_organizationalUnitName, 1, ub_organization_unit_name, DIRSTRING_TYPE, 0}, | 180 | {NID_organizationalUnitName, 1, ub_organization_unit_name, DIRSTRING_TYPE, 0}, |
| 167 | {NID_pkcs9_emailAddress, 1, ub_email_address, B_ASN1_IA5STRING, STABLE_NO_MASK}, | 181 | {NID_pkcs9_emailAddress, 1, ub_email_address, B_ASN1_IA5STRING, STABLE_NO_MASK}, |
| 168 | {NID_pkcs9_unstructuredName, 1, -1, PKCS9STRING_TYPE, 0}, | 182 | {NID_pkcs9_unstructuredName, 1, -1, PKCS9STRING_TYPE, 0}, |
| 169 | {NID_pkcs9_challengePassword, 1, -1, PKCS9STRING_TYPE, 0}, | 183 | {NID_pkcs9_challengePassword, 1, -1, PKCS9STRING_TYPE, 0}, |
| 170 | {NID_pkcs9_unstructuredAddress, 1, -1, DIRSTRING_TYPE, 0}, | 184 | {NID_pkcs9_unstructuredAddress, 1, -1, DIRSTRING_TYPE, 0}, |
| 171 | {NID_givenName, 1, ub_name, DIRSTRING_TYPE, 0}, | 185 | {NID_givenName, 1, ub_name, DIRSTRING_TYPE, 0}, |
| 172 | {NID_surname, 1, ub_name, DIRSTRING_TYPE, 0}, | 186 | {NID_surname, 1, ub_name, DIRSTRING_TYPE, 0}, |
| 173 | {NID_initials, 1, ub_name, DIRSTRING_TYPE, 0}, | 187 | {NID_initials, 1, ub_name, DIRSTRING_TYPE, 0}, |
| 174 | {NID_serialNumber, 1, ub_serial_number, B_ASN1_PRINTABLESTRING, STABLE_NO_MASK}, | 188 | {NID_serialNumber, 1, ub_serial_number, B_ASN1_PRINTABLESTRING, STABLE_NO_MASK}, |
| 175 | {NID_friendlyName, -1, -1, B_ASN1_BMPSTRING, STABLE_NO_MASK}, | 189 | {NID_friendlyName, -1, -1, B_ASN1_BMPSTRING, STABLE_NO_MASK}, |
| 176 | {NID_name, 1, ub_name, DIRSTRING_TYPE, 0}, | 190 | {NID_name, 1, ub_name, DIRSTRING_TYPE, 0}, |
| 177 | {NID_dnQualifier, -1, -1, B_ASN1_PRINTABLESTRING, STABLE_NO_MASK}, | 191 | {NID_dnQualifier, -1, -1, B_ASN1_PRINTABLESTRING, STABLE_NO_MASK}, |
| 178 | {NID_domainComponent, 1, -1, B_ASN1_IA5STRING, STABLE_NO_MASK}, | 192 | {NID_domainComponent, 1, -1, B_ASN1_IA5STRING, STABLE_NO_MASK}, |
| 179 | {NID_ms_csp_name, -1, -1, B_ASN1_BMPSTRING, STABLE_NO_MASK} | 193 | {NID_ms_csp_name, -1, -1, B_ASN1_BMPSTRING, STABLE_NO_MASK} |
| 180 | }; | 194 | }; |
| 181 | 195 | ||
| 182 | static int sk_table_cmp(const ASN1_STRING_TABLE * const *a, | 196 | static int |
| 183 | const ASN1_STRING_TABLE * const *b) | 197 | sk_table_cmp(const ASN1_STRING_TABLE * const *a, |
| 198 | const ASN1_STRING_TABLE * const *b) | ||
| 184 | { | 199 | { |
| 185 | return (*a)->nid - (*b)->nid; | 200 | return (*a)->nid - (*b)->nid; |
| 186 | } | 201 | } |
| 187 | 202 | ||
| 188 | DECLARE_OBJ_BSEARCH_CMP_FN(ASN1_STRING_TABLE, ASN1_STRING_TABLE, table); | 203 | DECLARE_OBJ_BSEARCH_CMP_FN(ASN1_STRING_TABLE, ASN1_STRING_TABLE, table); |
| 189 | 204 | ||
| 190 | static int table_cmp(const ASN1_STRING_TABLE *a, const ASN1_STRING_TABLE *b) | 205 | static int |
| 206 | table_cmp(const ASN1_STRING_TABLE *a, const ASN1_STRING_TABLE *b) | ||
| 191 | { | 207 | { |
| 192 | return a->nid - b->nid; | 208 | return a->nid - b->nid; |
| 193 | } | 209 | } |
| 194 | 210 | ||
| 195 | IMPLEMENT_OBJ_BSEARCH_CMP_FN(ASN1_STRING_TABLE, ASN1_STRING_TABLE, table); | 211 | IMPLEMENT_OBJ_BSEARCH_CMP_FN(ASN1_STRING_TABLE, ASN1_STRING_TABLE, table); |
| 196 | 212 | ||
| 197 | ASN1_STRING_TABLE *ASN1_STRING_TABLE_get(int nid) | 213 | ASN1_STRING_TABLE * |
| 214 | ASN1_STRING_TABLE_get(int nid) | ||
| 198 | { | 215 | { |
| 199 | int idx; | 216 | int idx; |
| 200 | ASN1_STRING_TABLE *ttmp; | 217 | ASN1_STRING_TABLE *ttmp; |
| 201 | ASN1_STRING_TABLE fnd; | 218 | ASN1_STRING_TABLE fnd; |
| 219 | |||
| 202 | fnd.nid = nid; | 220 | fnd.nid = nid; |
| 203 | ttmp = OBJ_bsearch_table(&fnd, tbl_standard, | 221 | ttmp = OBJ_bsearch_table(&fnd, tbl_standard, |
| 204 | sizeof(tbl_standard)/sizeof(ASN1_STRING_TABLE)); | 222 | sizeof(tbl_standard)/sizeof(ASN1_STRING_TABLE)); |
| 205 | if(ttmp) return ttmp; | 223 | if (ttmp) |
| 206 | if(!stable) return NULL; | 224 | return ttmp; |
| 225 | if (!stable) | ||
| 226 | return NULL; | ||
| 207 | idx = sk_ASN1_STRING_TABLE_find(stable, &fnd); | 227 | idx = sk_ASN1_STRING_TABLE_find(stable, &fnd); |
| 208 | if(idx < 0) return NULL; | 228 | if (idx < 0) |
| 229 | return NULL; | ||
| 209 | return sk_ASN1_STRING_TABLE_value(stable, idx); | 230 | return sk_ASN1_STRING_TABLE_value(stable, idx); |
| 210 | } | 231 | } |
| 211 | 232 | ||
| 212 | int ASN1_STRING_TABLE_add(int nid, | 233 | int |
| 213 | long minsize, long maxsize, unsigned long mask, | 234 | ASN1_STRING_TABLE_add(int nid, long minsize, long maxsize, unsigned long mask, |
| 214 | unsigned long flags) | 235 | unsigned long flags) |
| 215 | { | 236 | { |
| 216 | ASN1_STRING_TABLE *tmp; | 237 | ASN1_STRING_TABLE *tmp; |
| 217 | char new_nid = 0; | 238 | char new_nid = 0; |
| 239 | |||
| 218 | flags &= ~STABLE_FLAGS_MALLOC; | 240 | flags &= ~STABLE_FLAGS_MALLOC; |
| 219 | if(!stable) stable = sk_ASN1_STRING_TABLE_new(sk_table_cmp); | 241 | if (!stable) |
| 220 | if(!stable) { | 242 | stable = sk_ASN1_STRING_TABLE_new(sk_table_cmp); |
| 243 | if (!stable) { | ||
| 221 | ASN1err(ASN1_F_ASN1_STRING_TABLE_ADD, ERR_R_MALLOC_FAILURE); | 244 | ASN1err(ASN1_F_ASN1_STRING_TABLE_ADD, ERR_R_MALLOC_FAILURE); |
| 222 | return 0; | 245 | return 0; |
| 223 | } | 246 | } |
| 224 | if(!(tmp = ASN1_STRING_TABLE_get(nid))) { | 247 | if (!(tmp = ASN1_STRING_TABLE_get(nid))) { |
| 225 | tmp = malloc(sizeof(ASN1_STRING_TABLE)); | 248 | tmp = malloc(sizeof(ASN1_STRING_TABLE)); |
| 226 | if(!tmp) { | 249 | if (!tmp) { |
| 227 | ASN1err(ASN1_F_ASN1_STRING_TABLE_ADD, | 250 | ASN1err(ASN1_F_ASN1_STRING_TABLE_ADD, |
| 228 | ERR_R_MALLOC_FAILURE); | 251 | ERR_R_MALLOC_FAILURE); |
| 229 | return 0; | 252 | return 0; |
| 230 | } | 253 | } |
| 231 | tmp->flags = flags | STABLE_FLAGS_MALLOC; | 254 | tmp->flags = flags | STABLE_FLAGS_MALLOC; |
| 232 | tmp->nid = nid; | 255 | tmp->nid = nid; |
| 233 | new_nid = 1; | 256 | new_nid = 1; |
| 234 | } else tmp->flags = (tmp->flags & STABLE_FLAGS_MALLOC) | flags; | 257 | } else tmp->flags = (tmp->flags & STABLE_FLAGS_MALLOC) | flags; |
| 235 | if(minsize != -1) tmp->minsize = minsize; | 258 | if (minsize != -1) |
| 236 | if(maxsize != -1) tmp->maxsize = maxsize; | 259 | tmp->minsize = minsize; |
| 260 | if (maxsize != -1) | ||
| 261 | tmp->maxsize = maxsize; | ||
| 237 | tmp->mask = mask; | 262 | tmp->mask = mask; |
| 238 | if(new_nid) sk_ASN1_STRING_TABLE_push(stable, tmp); | 263 | if (new_nid) |
| 264 | sk_ASN1_STRING_TABLE_push(stable, tmp); | ||
| 239 | return 1; | 265 | return 1; |
| 240 | } | 266 | } |
| 241 | 267 | ||
| 242 | void ASN1_STRING_TABLE_cleanup(void) | 268 | void |
| 269 | ASN1_STRING_TABLE_cleanup(void) | ||
| 243 | { | 270 | { |
| 244 | STACK_OF(ASN1_STRING_TABLE) *tmp; | 271 | STACK_OF(ASN1_STRING_TABLE) *tmp; |
| 272 | |||
| 245 | tmp = stable; | 273 | tmp = stable; |
| 246 | if(!tmp) return; | 274 | if (!tmp) |
| 275 | return; | ||
| 247 | stable = NULL; | 276 | stable = NULL; |
| 248 | sk_ASN1_STRING_TABLE_pop_free(tmp, st_free); | 277 | sk_ASN1_STRING_TABLE_pop_free(tmp, st_free); |
| 249 | } | 278 | } |
| 250 | 279 | ||
| 251 | static void st_free(ASN1_STRING_TABLE *tbl) | 280 | static void |
| 281 | st_free(ASN1_STRING_TABLE *tbl) | ||
| 252 | { | 282 | { |
| 253 | if(tbl->flags & STABLE_FLAGS_MALLOC) free(tbl); | 283 | if (tbl->flags & STABLE_FLAGS_MALLOC) |
| 284 | free(tbl); | ||
| 254 | } | 285 | } |
| 255 | 286 | ||
| 256 | 287 | ||
| @@ -264,7 +295,7 @@ main() | |||
| 264 | int i, last_nid = -1; | 295 | int i, last_nid = -1; |
| 265 | 296 | ||
| 266 | for (tmp = tbl_standard, i = 0; | 297 | for (tmp = tbl_standard, i = 0; |
| 267 | i < sizeof(tbl_standard)/sizeof(ASN1_STRING_TABLE); i++, tmp++) { | 298 | i < sizeof(tbl_standard) / sizeof(ASN1_STRING_TABLE); i++, tmp++) { |
| 268 | if (tmp->nid < last_nid) { | 299 | if (tmp->nid < last_nid) { |
| 269 | last_nid = 0; | 300 | last_nid = 0; |
| 270 | break; | 301 | break; |
| @@ -278,9 +309,9 @@ main() | |||
| 278 | } | 309 | } |
| 279 | 310 | ||
| 280 | for (tmp = tbl_standard, i = 0; | 311 | for (tmp = tbl_standard, i = 0; |
| 281 | i < sizeof(tbl_standard)/sizeof(ASN1_STRING_TABLE); i++, tmp++) { | 312 | i < sizeof(tbl_standard) / sizeof(ASN1_STRING_TABLE); i++, tmp++) { |
| 282 | printf("Index %d, NID %d, Name=%s\n", i, tmp->nid, | 313 | printf("Index %d, NID %d, Name=%s\n", i, tmp->nid, |
| 283 | OBJ_nid2ln(tmp->nid)); | 314 | OBJ_nid2ln(tmp->nid)); |
| 284 | } | 315 | } |
| 285 | 316 | ||
| 286 | } | 317 | } |
