diff options
author | jsing <> | 2014-05-26 12:37:32 +0000 |
---|---|---|
committer | jsing <> | 2014-05-26 12:37:32 +0000 |
commit | 0a3c64a44b2d2d7ba5da3fafde6657ae6f2a6435 (patch) | |
tree | ab5672653bce63a239165b17c0951468b96ecbc1 /src/lib/libcrypto/x509v3/v3_skey.c | |
parent | 043e50e025a8f1c5baa37e18d206b24c27356069 (diff) | |
download | openbsd-0a3c64a44b2d2d7ba5da3fafde6657ae6f2a6435.tar.gz openbsd-0a3c64a44b2d2d7ba5da3fafde6657ae6f2a6435.tar.bz2 openbsd-0a3c64a44b2d2d7ba5da3fafde6657ae6f2a6435.zip |
KNF.
Diffstat (limited to 'src/lib/libcrypto/x509v3/v3_skey.c')
-rw-r--r-- | src/lib/libcrypto/x509v3/v3_skey.c | 75 |
1 files changed, 40 insertions, 35 deletions
diff --git a/src/lib/libcrypto/x509v3/v3_skey.c b/src/lib/libcrypto/x509v3/v3_skey.c index 0a984fbaa8..22da698080 100644 --- a/src/lib/libcrypto/x509v3/v3_skey.c +++ b/src/lib/libcrypto/x509v3/v3_skey.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 |
@@ -61,33 +61,35 @@ | |||
61 | #include "cryptlib.h" | 61 | #include "cryptlib.h" |
62 | #include <openssl/x509v3.h> | 62 | #include <openssl/x509v3.h> |
63 | 63 | ||
64 | static ASN1_OCTET_STRING *s2i_skey_id(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, char *str); | 64 | static ASN1_OCTET_STRING *s2i_skey_id(X509V3_EXT_METHOD *method, |
65 | const X509V3_EXT_METHOD v3_skey_id = { | 65 | X509V3_CTX *ctx, char *str); |
66 | NID_subject_key_identifier, 0, ASN1_ITEM_ref(ASN1_OCTET_STRING), | 66 | const X509V3_EXT_METHOD v3_skey_id = { |
67 | 0,0,0,0, | 67 | NID_subject_key_identifier, 0, ASN1_ITEM_ref(ASN1_OCTET_STRING), |
68 | (X509V3_EXT_I2S)i2s_ASN1_OCTET_STRING, | 68 | 0, 0, 0, 0, |
69 | (X509V3_EXT_S2I)s2i_skey_id, | 69 | (X509V3_EXT_I2S)i2s_ASN1_OCTET_STRING, |
70 | 0,0,0,0, | 70 | (X509V3_EXT_S2I)s2i_skey_id, |
71 | NULL}; | 71 | 0, 0, 0, 0, |
72 | 72 | NULL | |
73 | char *i2s_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method, | 73 | }; |
74 | ASN1_OCTET_STRING *oct) | 74 | |
75 | char * | ||
76 | i2s_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method, ASN1_OCTET_STRING *oct) | ||
75 | { | 77 | { |
76 | return hex_to_string(oct->data, oct->length); | 78 | return hex_to_string(oct->data, oct->length); |
77 | } | 79 | } |
78 | 80 | ||
79 | ASN1_OCTET_STRING *s2i_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method, | 81 | ASN1_OCTET_STRING * |
80 | X509V3_CTX *ctx, char *str) | 82 | s2i_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, char *str) |
81 | { | 83 | { |
82 | ASN1_OCTET_STRING *oct; | 84 | ASN1_OCTET_STRING *oct; |
83 | long length; | 85 | long length; |
84 | 86 | ||
85 | if(!(oct = M_ASN1_OCTET_STRING_new())) { | 87 | if (!(oct = M_ASN1_OCTET_STRING_new())) { |
86 | X509V3err(X509V3_F_S2I_ASN1_OCTET_STRING,ERR_R_MALLOC_FAILURE); | 88 | X509V3err(X509V3_F_S2I_ASN1_OCTET_STRING, ERR_R_MALLOC_FAILURE); |
87 | return NULL; | 89 | return NULL; |
88 | } | 90 | } |
89 | 91 | ||
90 | if(!(oct->data = string_to_hex(str, &length))) { | 92 | if (!(oct->data = string_to_hex(str, &length))) { |
91 | M_ASN1_OCTET_STRING_free(oct); | 93 | M_ASN1_OCTET_STRING_free(oct); |
92 | return NULL; | 94 | return NULL; |
93 | } | 95 | } |
@@ -95,51 +97,54 @@ ASN1_OCTET_STRING *s2i_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method, | |||
95 | oct->length = length; | 97 | oct->length = length; |
96 | 98 | ||
97 | return oct; | 99 | return oct; |
98 | |||
99 | } | 100 | } |
100 | 101 | ||
101 | static ASN1_OCTET_STRING *s2i_skey_id(X509V3_EXT_METHOD *method, | 102 | static ASN1_OCTET_STRING * |
102 | X509V3_CTX *ctx, char *str) | 103 | s2i_skey_id(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, char *str) |
103 | { | 104 | { |
104 | ASN1_OCTET_STRING *oct; | 105 | ASN1_OCTET_STRING *oct; |
105 | ASN1_BIT_STRING *pk; | 106 | ASN1_BIT_STRING *pk; |
106 | unsigned char pkey_dig[EVP_MAX_MD_SIZE]; | 107 | unsigned char pkey_dig[EVP_MAX_MD_SIZE]; |
107 | unsigned int diglen; | 108 | unsigned int diglen; |
108 | 109 | ||
109 | if(strcmp(str, "hash")) return s2i_ASN1_OCTET_STRING(method, ctx, str); | 110 | if (strcmp(str, "hash")) |
111 | return s2i_ASN1_OCTET_STRING(method, ctx, str); | ||
110 | 112 | ||
111 | if(!(oct = M_ASN1_OCTET_STRING_new())) { | 113 | if (!(oct = M_ASN1_OCTET_STRING_new())) { |
112 | X509V3err(X509V3_F_S2I_SKEY_ID,ERR_R_MALLOC_FAILURE); | 114 | X509V3err(X509V3_F_S2I_SKEY_ID, ERR_R_MALLOC_FAILURE); |
113 | return NULL; | 115 | return NULL; |
114 | } | 116 | } |
115 | 117 | ||
116 | if(ctx && (ctx->flags == CTX_TEST)) return oct; | 118 | if (ctx && (ctx->flags == CTX_TEST)) |
119 | return oct; | ||
117 | 120 | ||
118 | if(!ctx || (!ctx->subject_req && !ctx->subject_cert)) { | 121 | if (!ctx || (!ctx->subject_req && !ctx->subject_cert)) { |
119 | X509V3err(X509V3_F_S2I_SKEY_ID,X509V3_R_NO_PUBLIC_KEY); | 122 | X509V3err(X509V3_F_S2I_SKEY_ID, X509V3_R_NO_PUBLIC_KEY); |
120 | goto err; | 123 | goto err; |
121 | } | 124 | } |
122 | 125 | ||
123 | if(ctx->subject_req) | 126 | if (ctx->subject_req) |
124 | pk = ctx->subject_req->req_info->pubkey->public_key; | 127 | pk = ctx->subject_req->req_info->pubkey->public_key; |
125 | else pk = ctx->subject_cert->cert_info->key->public_key; | 128 | else |
129 | pk = ctx->subject_cert->cert_info->key->public_key; | ||
126 | 130 | ||
127 | if(!pk) { | 131 | if (!pk) { |
128 | X509V3err(X509V3_F_S2I_SKEY_ID,X509V3_R_NO_PUBLIC_KEY); | 132 | X509V3err(X509V3_F_S2I_SKEY_ID, X509V3_R_NO_PUBLIC_KEY); |
129 | goto err; | 133 | goto err; |
130 | } | 134 | } |
131 | 135 | ||
132 | if (!EVP_Digest(pk->data, pk->length, pkey_dig, &diglen, EVP_sha1(), NULL)) | 136 | if (!EVP_Digest(pk->data, pk->length, pkey_dig, &diglen, |
137 | EVP_sha1(), NULL)) | ||
133 | goto err; | 138 | goto err; |
134 | 139 | ||
135 | if(!M_ASN1_OCTET_STRING_set(oct, pkey_dig, diglen)) { | 140 | if (!M_ASN1_OCTET_STRING_set(oct, pkey_dig, diglen)) { |
136 | X509V3err(X509V3_F_S2I_SKEY_ID,ERR_R_MALLOC_FAILURE); | 141 | X509V3err(X509V3_F_S2I_SKEY_ID, ERR_R_MALLOC_FAILURE); |
137 | goto err; | 142 | goto err; |
138 | } | 143 | } |
139 | 144 | ||
140 | return oct; | 145 | return oct; |
141 | 146 | ||
142 | err: | 147 | err: |
143 | M_ASN1_OCTET_STRING_free(oct); | 148 | M_ASN1_OCTET_STRING_free(oct); |
144 | return NULL; | 149 | return NULL; |
145 | } | 150 | } |