Print this page
6429 SMB domain join doesn't work with libreSSL
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/krb5/plugins/preauth/pkinit/pkinit_crypto_openssl.h
+++ new/usr/src/lib/krb5/plugins/preauth/pkinit/pkinit_crypto_openssl.h
1 1 /*
2 2 * COPYRIGHT (C) 2006,2007
3 3 * THE REGENTS OF THE UNIVERSITY OF MICHIGAN
4 4 * ALL RIGHTS RESERVED
5 5 *
6 6 * Permission is granted to use, copy, create derivative works
7 7 * and redistribute this software and such derivative works
8 8 * for any purpose, so long as the name of The University of
9 9 * Michigan is not used in any advertising or publicity
10 10 * pertaining to the use of distribution of this software
11 11 * without specific, written prior authorization. If the
12 12 * above copyright notice or any other identification of the
13 13 * University of Michigan is included in any copy of any
14 14 * portion of this software, then the disclaimer below must
15 15 * also be included.
16 16 *
17 17 * THIS SOFTWARE IS PROVIDED AS IS, WITHOUT REPRESENTATION
18 18 * FROM THE UNIVERSITY OF MICHIGAN AS TO ITS FITNESS FOR ANY
19 19 * PURPOSE, AND WITHOUT WARRANTY BY THE UNIVERSITY OF
20 20 * MICHIGAN OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING
21 21 * WITHOUT LIMITATION THE IMPLIED WARRANTIES OF
22 22 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
23 23 * REGENTS OF THE UNIVERSITY OF MICHIGAN SHALL NOT BE LIABLE
24 24 * FOR ANY DAMAGES, INCLUDING SPECIAL, INDIRECT, INCIDENTAL, OR
25 25 * CONSEQUENTIAL DAMAGES, WITH RESPECT TO ANY CLAIM ARISING
26 26 * OUT OF OR IN CONNECTION WITH THE USE OF THE SOFTWARE, EVEN
27 27 * IF IT HAS BEEN OR IS HEREAFTER ADVISED OF THE POSSIBILITY OF
28 28 * SUCH DAMAGES.
29 29 */
30 30
31 31 /*
32 32 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
33 33 */
34 34
35 35 #ifndef _PKINIT_CRYPTO_OPENSSL_H
36 36 #define _PKINIT_CRYPTO_OPENSSL_H
37 37
38 38 #include <openssl/bn.h>
39 39 #include <openssl/dh.h>
40 40 #include <openssl/x509.h>
41 41 #include <openssl/pkcs7.h>
42 42 #include <openssl/pkcs12.h>
43 43 #include <openssl/obj_mac.h>
44 44 #include <openssl/x509v3.h>
45 45 #include <openssl/err.h>
46 46 #include <openssl/evp.h>
47 47 #include <openssl/asn1_mac.h>
48 48 #include <openssl/sha.h>
49 49 #include <openssl/asn1.h>
50 50 #include <openssl/pem.h>
51 51
52 52 #include "pkinit.h"
53 53
54 54 #define DN_BUF_LEN 256
55 55 #define MAX_CREDS_ALLOWED 20
56 56
57 57 struct _pkinit_cred_info {
58 58 X509 *cert;
59 59 EVP_PKEY *key;
60 60 #ifndef WITHOUT_PKCS11
61 61 CK_BYTE_PTR cert_id;
62 62 int cert_id_len;
63 63 #endif
64 64 };
65 65 typedef struct _pkinit_cred_info * pkinit_cred_info;
66 66
67 67 struct _pkinit_identity_crypto_context {
68 68 pkinit_cred_info creds[MAX_CREDS_ALLOWED+1];
69 69 STACK_OF(X509) *my_certs; /* available user certs */
70 70 int cert_index; /* cert to use out of available certs*/
71 71 EVP_PKEY *my_key; /* available user keys if in filesystem */
72 72 STACK_OF(X509) *trustedCAs; /* available trusted ca certs */
73 73 STACK_OF(X509) *intermediateCAs; /* available intermediate ca certs */
74 74 STACK_OF(X509_CRL) *revoked; /* available crls */
75 75 int pkcs11_method;
76 76 krb5_prompter_fct prompter;
77 77 void *prompter_data;
78 78 #ifndef WITHOUT_PKCS11
79 79 char *p11_module_name;
80 80 CK_SLOT_ID slotid;
81 81 char *token_label;
82 82 char *cert_label;
83 83 char *PIN; /* Solaris Kerberos: */
84 84 /* These are crypto-specific */
85 85 void *p11_module;
86 86 CK_SESSION_HANDLE session;
87 87 CK_FUNCTION_LIST_PTR p11;
88 88 CK_BYTE_PTR cert_id;
89 89 int cert_id_len;
90 90 CK_MECHANISM_TYPE mech;
91 91 /* Solaris Kerberos: need to keep some state */
92 92 uint_t p11flags;
93 93 /*
94 94 * Solaris Kerberos:
95 95 * If PKCS#11 is already being used by the process then C_Finalize should
96 96 * not be called by pkinit as it would invalidate any PKCS#11 sessions the
97 97 * process was using prior to loading the pkinit plugin. "finalize_pkcs11"
98 98 * indicates whether or not C_Finalize should be called by pkinit.
99 99 */
100 100 krb5_boolean finalize_pkcs11;
101 101 #endif
102 102 };
103 103
↓ open down ↓ |
103 lines elided |
↑ open up ↑ |
104 104 /* Solaris Kerberos: need to know if login was done */
105 105 #define C_LOGIN_DONE 0x1 /* The session is logged in. */
106 106 #define C_PROMPTED_USER 0x2 /* The user was prompted for token. */
107 107 #define C_SKIP_PKCS11_AUTH 0x4 /* User does not want to do PKCS11 auth */
108 108
109 109 struct _pkinit_plg_crypto_context {
110 110 DH *dh_1024;
111 111 DH *dh_2048;
112 112 DH *dh_4096;
113 113 ASN1_OBJECT *id_pkinit_authData;
114 - ASN1_OBJECT *id_pkinit_authData9;
115 114 ASN1_OBJECT *id_pkinit_DHKeyData;
116 115 ASN1_OBJECT *id_pkinit_rkeyData;
117 116 ASN1_OBJECT *id_pkinit_san;
118 117 ASN1_OBJECT *id_ms_san_upn;
119 118 ASN1_OBJECT *id_pkinit_KPClientAuth;
120 119 ASN1_OBJECT *id_pkinit_KPKdc;
121 120 ASN1_OBJECT *id_ms_kp_sc_logon;
122 121 ASN1_OBJECT *id_kp_serverAuth;
123 122 };
124 123
125 124 struct _pkinit_req_crypto_context {
126 125 X509 *received_cert;
127 126 DH *dh;
128 127 };
129 128
130 129 #define CERT_MAGIC 0x53534c43
131 130 struct _pkinit_cert_data {
132 131 unsigned int magic;
133 132 pkinit_plg_crypto_context plgctx;
134 133 pkinit_req_crypto_context reqctx;
135 134 pkinit_identity_crypto_context idctx;
136 135 pkinit_cred_info cred;
137 136 unsigned int index; /* Index of this cred in the creds[] array */
138 137 };
139 138
140 139 #define ITER_MAGIC 0x53534c49
141 140 struct _pkinit_cert_iter_data {
142 141 unsigned int magic;
143 142 pkinit_plg_crypto_context plgctx;
144 143 pkinit_req_crypto_context reqctx;
145 144 pkinit_identity_crypto_context idctx;
146 145 unsigned int index;
147 146 };
148 147
149 148 /* Solaris Kerberos */
150 149 static krb5_error_code openssl_init(void);
151 150
152 151 static krb5_error_code pkinit_init_pkinit_oids(pkinit_plg_crypto_context );
153 152 static void pkinit_fini_pkinit_oids(pkinit_plg_crypto_context );
154 153
155 154 static krb5_error_code pkinit_init_dh_params(pkinit_plg_crypto_context );
156 155 static void pkinit_fini_dh_params(pkinit_plg_crypto_context );
157 156
158 157 static krb5_error_code pkinit_init_certs(pkinit_identity_crypto_context ctx);
159 158 static void pkinit_fini_certs(pkinit_identity_crypto_context ctx);
160 159
161 160 static krb5_error_code pkinit_init_pkcs11(pkinit_identity_crypto_context ctx);
162 161 static void pkinit_fini_pkcs11(pkinit_identity_crypto_context ctx);
163 162
164 163 static krb5_error_code pkinit_encode_dh_params
165 164 (BIGNUM *, BIGNUM *, BIGNUM *, unsigned char **, unsigned int *);
166 165 static DH *pkinit_decode_dh_params
167 166 (DH **, unsigned char **, unsigned int );
168 167 static int pkinit_check_dh_params
169 168 (BIGNUM * p1, BIGNUM * p2, BIGNUM * g1, BIGNUM * q1);
170 169
171 170 static krb5_error_code pkinit_sign_data
172 171 (krb5_context context, pkinit_identity_crypto_context cryptoctx,
173 172 unsigned char *data, unsigned int data_len,
174 173 unsigned char **sig, unsigned int *sig_len);
175 174
176 175 static krb5_error_code create_signature
177 176 (unsigned char **, unsigned int *, unsigned char *, unsigned int,
178 177 EVP_PKEY *pkey);
179 178
180 179 static krb5_error_code pkinit_decode_data
181 180 (krb5_context context, pkinit_identity_crypto_context cryptoctx,
182 181 unsigned char *data, unsigned int data_len,
183 182 unsigned char **decoded, unsigned int *decoded_len);
184 183
185 184 static krb5_error_code decode_data
186 185 (unsigned char **, unsigned int *, unsigned char *, unsigned int,
187 186 EVP_PKEY *pkey, X509 *cert);
188 187
189 188 #ifdef DEBUG_DH
190 189 static void print_dh(DH *, char *);
191 190 static void print_pubkey(BIGNUM *, char *);
192 191 #endif
193 192
194 193 static int prepare_enc_data
195 194 (unsigned char *indata, int indata_len, unsigned char **outdata,
196 195 int *outdata_len);
197 196
198 197 static int openssl_callback (int, X509_STORE_CTX *);
199 198 static int openssl_callback_ignore_crls (int, X509_STORE_CTX *);
200 199
201 200 static int pkcs7_decrypt
202 201 (krb5_context context, pkinit_identity_crypto_context id_cryptoctx,
203 202 PKCS7 *p7, BIO *bio);
204 203
205 204 static BIO * pkcs7_dataDecode
206 205 (krb5_context context, pkinit_identity_crypto_context id_cryptoctx,
207 206 PKCS7 *p7);
208 207
209 208 static ASN1_OBJECT * pkinit_pkcs7type2oid
210 209 (pkinit_plg_crypto_context plg_cryptoctx, int pkcs7_type);
211 210
212 211 static krb5_error_code pkinit_create_sequence_of_principal_identifiers
213 212 (krb5_context context, pkinit_plg_crypto_context plg_cryptoctx,
214 213 pkinit_req_crypto_context req_cryptoctx,
215 214 pkinit_identity_crypto_context id_cryptoctx,
216 215 int type, krb5_data **out_data);
217 216
218 217 #ifndef WITHOUT_PKCS11
219 218 static krb5_error_code pkinit_find_private_key
220 219 (pkinit_identity_crypto_context, CK_ATTRIBUTE_TYPE usage,
221 220 CK_OBJECT_HANDLE *objp);
222 221 static krb5_error_code pkinit_login
223 222 (krb5_context context, pkinit_identity_crypto_context id_cryptoctx,
224 223 CK_TOKEN_INFO *tip);
225 224 static void * pkinit_C_LoadModule(const char *modname, CK_FUNCTION_LIST_PTR_PTR p11p);
226 225 static CK_RV pkinit_C_UnloadModule(void *handle);
227 226 #ifdef SILLYDECRYPT
228 227 CK_RV pkinit_C_Decrypt
229 228 (pkinit_identity_crypto_context id_cryptoctx,
230 229 CK_BYTE_PTR pEncryptedData, CK_ULONG ulEncryptedDataLen,
231 230 CK_BYTE_PTR pData, CK_ULONG_PTR pulDataLen);
232 231 #endif
233 232
234 233 static krb5_error_code pkinit_sign_data_pkcs11
235 234 (krb5_context context, pkinit_identity_crypto_context id_cryptoctx,
236 235 unsigned char *data, unsigned int data_len,
237 236 unsigned char **sig, unsigned int *sig_len);
238 237 static krb5_error_code pkinit_decode_data_pkcs11
239 238 (krb5_context context, pkinit_identity_crypto_context id_cryptoctx,
240 239 unsigned char *data, unsigned int data_len,
241 240 unsigned char **decoded_data, unsigned int *decoded_data_len);
242 241 #endif /* WITHOUT_PKCS11 */
243 242
244 243 static krb5_error_code pkinit_sign_data_fs
245 244 (krb5_context context, pkinit_identity_crypto_context id_cryptoctx,
246 245 unsigned char *data, unsigned int data_len,
247 246 unsigned char **sig, unsigned int *sig_len);
248 247 static krb5_error_code pkinit_decode_data_fs
249 248 (krb5_context context, pkinit_identity_crypto_context id_cryptoctx,
250 249 unsigned char *data, unsigned int data_len,
251 250 unsigned char **decoded_data, unsigned int *decoded_data_len);
252 251
253 252 static krb5_error_code der_decode_data
254 253 (unsigned char *, long, unsigned char **, long *);
255 254
256 255 static krb5_error_code
257 256 create_krb5_invalidCertificates(krb5_context context,
258 257 pkinit_plg_crypto_context plg_cryptoctx,
259 258 pkinit_req_crypto_context req_cryptoctx,
260 259 pkinit_identity_crypto_context id_cryptoctx,
261 260 krb5_external_principal_identifier *** ids);
262 261
263 262 static krb5_error_code
264 263 create_identifiers_from_stack(STACK_OF(X509) *sk,
265 264 krb5_external_principal_identifier *** ids);
266 265 #ifdef LONGHORN_BETA_COMPAT
267 266 static int
268 267 wrap_signeddata(unsigned char *data, unsigned int data_len,
269 268 unsigned char **out, unsigned int *out_len,
270 269 int is_longhorn_server);
271 270 #else
272 271 static int
273 272 wrap_signeddata(unsigned char *data, unsigned int data_len,
274 273 unsigned char **out, unsigned int *out_len);
275 274 #endif
276 275
277 276 /* This handy macro borrowed from crypto/x509v3/v3_purp.c */
278 277 #define ku_reject(x, usage) \
279 278 (((x)->ex_flags & EXFLAG_KUSAGE) && !((x)->ex_kusage & (usage)))
280 279
281 280 static char *
282 281 pkinit_pkcs11_code_to_text(int err);
283 282
284 283 #endif /* _PKINIT_CRYPTO_OPENSSL_H */
↓ open down ↓ |
160 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX