summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/pkcs12/p12_attr.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/lib/libcrypto/pkcs12/p12_attr.c62
1 files changed, 36 insertions, 26 deletions
diff --git a/src/lib/libcrypto/pkcs12/p12_attr.c b/src/lib/libcrypto/pkcs12/p12_attr.c
index 67ffb392ab..05e9b11fd1 100644
--- a/src/lib/libcrypto/pkcs12/p12_attr.c
+++ b/src/lib/libcrypto/pkcs12/p12_attr.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: p12_attr.c,v 1.8 2014/06/12 15:49:30 deraadt Exp $ */ 1/* $OpenBSD: p12_attr.c,v 1.9 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,24 +62,26 @@
62 62
63/* Add a local keyid to a safebag */ 63/* Add a local keyid to a safebag */
64 64
65int PKCS12_add_localkeyid(PKCS12_SAFEBAG *bag, unsigned char *name, 65int
66 int namelen) 66PKCS12_add_localkeyid(PKCS12_SAFEBAG *bag, unsigned char *name, int namelen)
67{ 67{
68 if (X509at_add1_attr_by_NID(&bag->attrib, NID_localKeyID, 68 if (X509at_add1_attr_by_NID(&bag->attrib, NID_localKeyID,
69 V_ASN1_OCTET_STRING, name, namelen)) 69 V_ASN1_OCTET_STRING, name, namelen))
70 return 1; 70 return 1;
71 else 71 else
72 return 0; 72 return 0;
73} 73}
74 74
75/* Add key usage to PKCS#8 structure */ 75/* Add key usage to PKCS#8 structure */
76 76
77int PKCS8_add_keyusage(PKCS8_PRIV_KEY_INFO *p8, int usage) 77int
78PKCS8_add_keyusage(PKCS8_PRIV_KEY_INFO *p8, int usage)
78{ 79{
79 unsigned char us_val; 80 unsigned char us_val;
81
80 us_val = (unsigned char) usage; 82 us_val = (unsigned char) usage;
81 if (X509at_add1_attr_by_NID(&p8->attributes, NID_key_usage, 83 if (X509at_add1_attr_by_NID(&p8->attributes, NID_key_usage,
82 V_ASN1_BIT_STRING, &us_val, 1)) 84 V_ASN1_BIT_STRING, &us_val, 1))
83 return 1; 85 return 1;
84 else 86 else
85 return 0; 87 return 0;
@@ -87,59 +89,67 @@ int PKCS8_add_keyusage(PKCS8_PRIV_KEY_INFO *p8, int usage)
87 89
88/* Add a friendlyname to a safebag */ 90/* Add a friendlyname to a safebag */
89 91
90int PKCS12_add_friendlyname_asc(PKCS12_SAFEBAG *bag, const char *name, 92int
91 int namelen) 93PKCS12_add_friendlyname_asc(PKCS12_SAFEBAG *bag, const char *name, int namelen)
92{ 94{
93 if (X509at_add1_attr_by_NID(&bag->attrib, NID_friendlyName, 95 if (X509at_add1_attr_by_NID(&bag->attrib, NID_friendlyName,
94 MBSTRING_ASC, (unsigned char *)name, namelen)) 96 MBSTRING_ASC, (unsigned char *)name, namelen))
95 return 1; 97 return 1;
96 else 98 else
97 return 0; 99 return 0;
98} 100}
99 101
100 102
101int PKCS12_add_friendlyname_uni(PKCS12_SAFEBAG *bag, 103int
102 const unsigned char *name, int namelen) 104PKCS12_add_friendlyname_uni(PKCS12_SAFEBAG *bag, const unsigned char *name,
105 int namelen)
103{ 106{
104 if (X509at_add1_attr_by_NID(&bag->attrib, NID_friendlyName, 107 if (X509at_add1_attr_by_NID(&bag->attrib, NID_friendlyName,
105 MBSTRING_BMP, name, namelen)) 108 MBSTRING_BMP, name, namelen))
106 return 1; 109 return 1;
107 else 110 else
108 return 0; 111 return 0;
109} 112}
110 113
111int PKCS12_add_CSPName_asc(PKCS12_SAFEBAG *bag, const char *name, 114int
112 int namelen) 115PKCS12_add_CSPName_asc(PKCS12_SAFEBAG *bag, const char *name, int namelen)
113{ 116{
114 if (X509at_add1_attr_by_NID(&bag->attrib, NID_ms_csp_name, 117 if (X509at_add1_attr_by_NID(&bag->attrib, NID_ms_csp_name,
115 MBSTRING_ASC, (unsigned char *)name, namelen)) 118 MBSTRING_ASC, (unsigned char *)name, namelen))
116 return 1; 119 return 1;
117 else 120 else
118 return 0; 121 return 0;
119} 122}
120 123
121ASN1_TYPE *PKCS12_get_attr_gen(STACK_OF(X509_ATTRIBUTE) *attrs, int attr_nid) 124ASN1_TYPE *
125PKCS12_get_attr_gen(STACK_OF(X509_ATTRIBUTE) *attrs, int attr_nid)
122{ 126{
123 X509_ATTRIBUTE *attrib; 127 X509_ATTRIBUTE *attrib;
124 int i; 128 int i;
125 if (!attrs) return NULL; 129
130 if (!attrs)
131 return NULL;
126 for (i = 0; i < sk_X509_ATTRIBUTE_num (attrs); i++) { 132 for (i = 0; i < sk_X509_ATTRIBUTE_num (attrs); i++) {
127 attrib = sk_X509_ATTRIBUTE_value (attrs, i); 133 attrib = sk_X509_ATTRIBUTE_value (attrs, i);
128 if (OBJ_obj2nid (attrib->object) == attr_nid) { 134 if (OBJ_obj2nid (attrib->object) == attr_nid) {
129 if (sk_ASN1_TYPE_num (attrib->value.set)) 135 if (sk_ASN1_TYPE_num (attrib->value.set))
130 return sk_ASN1_TYPE_value(attrib->value.set, 0); 136 return sk_ASN1_TYPE_value(attrib->value.set, 0);
131 else return NULL; 137 else
138 return NULL;
132 } 139 }
133 } 140 }
134 return NULL; 141 return NULL;
135} 142}
136 143
137char *PKCS12_get_friendlyname(PKCS12_SAFEBAG *bag) 144char *
145PKCS12_get_friendlyname(PKCS12_SAFEBAG *bag)
138{ 146{
139 ASN1_TYPE *atype; 147 ASN1_TYPE *atype;
140 if (!(atype = PKCS12_get_attr(bag, NID_friendlyName))) return NULL; 148
141 if (atype->type != V_ASN1_BMPSTRING) return NULL; 149 if (!(atype = PKCS12_get_attr(bag, NID_friendlyName)))
150 return NULL;
151 if (atype->type != V_ASN1_BMPSTRING)
152 return NULL;
142 return OPENSSL_uni2asc(atype->value.bmpstring->data, 153 return OPENSSL_uni2asc(atype->value.bmpstring->data,
143 atype->value.bmpstring->length); 154 atype->value.bmpstring->length);
144} 155}
145