summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/pkcs12/p12_utl.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/lib/libcrypto/pkcs12/p12_utl.c87
1 files changed, 56 insertions, 31 deletions
diff --git a/src/lib/libcrypto/pkcs12/p12_utl.c b/src/lib/libcrypto/pkcs12/p12_utl.c
index 372b94e412..618e6c699f 100644
--- a/src/lib/libcrypto/pkcs12/p12_utl.c
+++ b/src/lib/libcrypto/pkcs12/p12_utl.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: p12_utl.c,v 1.9 2014/06/12 15:49:30 deraadt Exp $ */ 1/* $OpenBSD: p12_utl.c,v 1.10 2014/07/08 09:24:53 jsing Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 1999. 3 * project 1999.
4 */ 4 */
@@ -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
@@ -62,81 +62,106 @@
62 62
63/* Cheap and nasty Unicode stuff */ 63/* Cheap and nasty Unicode stuff */
64 64
65unsigned char *OPENSSL_asc2uni(const char *asc, int asclen, unsigned char **uni, int *unilen) 65unsigned char *
66OPENSSL_asc2uni(const char *asc, int asclen, unsigned char **uni, int *unilen)
66{ 67{
67 int ulen, i; 68 int ulen, i;
68 unsigned char *unitmp; 69 unsigned char *unitmp;
69 if (asclen == -1) asclen = strlen(asc); 70
70 ulen = asclen*2 + 2; 71 if (asclen == -1)
71 if (!(unitmp = malloc(ulen))) return NULL; 72 asclen = strlen(asc);
72 for (i = 0; i < ulen - 2; i+=2) { 73 ulen = asclen * 2 + 2;
74 if (!(unitmp = malloc(ulen)))
75 return NULL;
76 for (i = 0; i < ulen - 2; i += 2) {
73 unitmp[i] = 0; 77 unitmp[i] = 0;
74 unitmp[i + 1] = asc[i>>1]; 78 unitmp[i + 1] = asc[i >> 1];
75 } 79 }
76 /* Make result double null terminated */ 80 /* Make result double null terminated */
77 unitmp[ulen - 2] = 0; 81 unitmp[ulen - 2] = 0;
78 unitmp[ulen - 1] = 0; 82 unitmp[ulen - 1] = 0;
79 if (unilen) *unilen = ulen; 83 if (unilen)
80 if (uni) *uni = unitmp; 84 *unilen = ulen;
85 if (uni)
86 *uni = unitmp;
81 return unitmp; 87 return unitmp;
82} 88}
83 89
84char *OPENSSL_uni2asc(unsigned char *uni, int unilen) 90char *
91OPENSSL_uni2asc(unsigned char *uni, int unilen)
85{ 92{
86 int asclen, i; 93 int asclen, i;
87 char *asctmp; 94 char *asctmp;
95
88 asclen = unilen / 2; 96 asclen = unilen / 2;
89 /* If no terminating zero allow for one */ 97 /* If no terminating zero allow for one */
90 if (!unilen || uni[unilen - 1]) asclen++; 98 if (!unilen || uni[unilen - 1])
99 asclen++;
91 uni++; 100 uni++;
92 if (!(asctmp = malloc(asclen))) return NULL; 101 if (!(asctmp = malloc(asclen)))
93 for (i = 0; i < unilen; i+=2) asctmp[i>>1] = uni[i]; 102 return NULL;
103 for (i = 0; i < unilen; i += 2)
104 asctmp[i >> 1] = uni[i];
94 asctmp[asclen - 1] = 0; 105 asctmp[asclen - 1] = 0;
95 return asctmp; 106 return asctmp;
96} 107}
97 108
98int i2d_PKCS12_bio(BIO *bp, PKCS12 *p12) 109int
110i2d_PKCS12_bio(BIO *bp, PKCS12 *p12)
99{ 111{
100 return ASN1_item_i2d_bio(ASN1_ITEM_rptr(PKCS12), bp, p12); 112 return ASN1_item_i2d_bio(ASN1_ITEM_rptr(PKCS12), bp, p12);
101} 113}
102 114
103int i2d_PKCS12_fp(FILE *fp, PKCS12 *p12) 115int
116i2d_PKCS12_fp(FILE *fp, PKCS12 *p12)
104{ 117{
105 return ASN1_item_i2d_fp(ASN1_ITEM_rptr(PKCS12), fp, p12); 118 return ASN1_item_i2d_fp(ASN1_ITEM_rptr(PKCS12), fp, p12);
106} 119}
107 120
108PKCS12 *d2i_PKCS12_bio(BIO *bp, PKCS12 **p12) 121PKCS12 *
122d2i_PKCS12_bio(BIO *bp, PKCS12 **p12)
109{ 123{
110 return ASN1_item_d2i_bio(ASN1_ITEM_rptr(PKCS12), bp, p12); 124 return ASN1_item_d2i_bio(ASN1_ITEM_rptr(PKCS12), bp, p12);
111} 125}
112PKCS12 *d2i_PKCS12_fp(FILE *fp, PKCS12 **p12) 126
127PKCS12 *
128d2i_PKCS12_fp(FILE *fp, PKCS12 **p12)
113{ 129{
114 return ASN1_item_d2i_fp(ASN1_ITEM_rptr(PKCS12), fp, p12); 130 return ASN1_item_d2i_fp(ASN1_ITEM_rptr(PKCS12), fp, p12);
115} 131}
116 132
117PKCS12_SAFEBAG *PKCS12_x5092certbag(X509 *x509) 133PKCS12_SAFEBAG *
134PKCS12_x5092certbag(X509 *x509)
118{ 135{
119 return PKCS12_item_pack_safebag(x509, ASN1_ITEM_rptr(X509), 136 return PKCS12_item_pack_safebag(x509, ASN1_ITEM_rptr(X509),
120 NID_x509Certificate, NID_certBag); 137 NID_x509Certificate, NID_certBag);
121} 138}
122 139
123PKCS12_SAFEBAG *PKCS12_x509crl2certbag(X509_CRL *crl) 140PKCS12_SAFEBAG *
141PKCS12_x509crl2certbag(X509_CRL *crl)
124{ 142{
125 return PKCS12_item_pack_safebag(crl, ASN1_ITEM_rptr(X509_CRL), 143 return PKCS12_item_pack_safebag(crl, ASN1_ITEM_rptr(X509_CRL),
126 NID_x509Crl, NID_crlBag); 144 NID_x509Crl, NID_crlBag);
127} 145}
128 146
129X509 *PKCS12_certbag2x509(PKCS12_SAFEBAG *bag) 147X509 *
148PKCS12_certbag2x509(PKCS12_SAFEBAG *bag)
130{ 149{
131 if(M_PKCS12_bag_type(bag) != NID_certBag) return NULL; 150 if (M_PKCS12_bag_type(bag) != NID_certBag)
132 if(M_PKCS12_cert_bag_type(bag) != NID_x509Certificate) return NULL; 151 return NULL;
133 return ASN1_item_unpack(bag->value.bag->value.octet, ASN1_ITEM_rptr(X509)); 152 if (M_PKCS12_cert_bag_type(bag) != NID_x509Certificate)
153 return NULL;
154 return ASN1_item_unpack(bag->value.bag->value.octet,
155 ASN1_ITEM_rptr(X509));
134} 156}
135 157
136X509_CRL *PKCS12_certbag2x509crl(PKCS12_SAFEBAG *bag) 158X509_CRL *
159PKCS12_certbag2x509crl(PKCS12_SAFEBAG *bag)
137{ 160{
138 if(M_PKCS12_bag_type(bag) != NID_crlBag) return NULL; 161 if (M_PKCS12_bag_type(bag) != NID_crlBag)
139 if(M_PKCS12_cert_bag_type(bag) != NID_x509Crl) return NULL; 162 return NULL;
163 if (M_PKCS12_cert_bag_type(bag) != NID_x509Crl)
164 return NULL;
140 return ASN1_item_unpack(bag->value.bag->value.octet, 165 return ASN1_item_unpack(bag->value.bag->value.octet,
141 ASN1_ITEM_rptr(X509_CRL)); 166 ASN1_ITEM_rptr(X509_CRL));
142} 167}