Lines Matching refs:ctx
66 struct x509_parse_context *ctx; in x509_cert_parse() local
80 ctx = kzalloc(sizeof(struct x509_parse_context), GFP_KERNEL); in x509_cert_parse()
81 if (!ctx) in x509_cert_parse()
84 ctx->cert = cert; in x509_cert_parse()
85 ctx->data = (unsigned long)data; in x509_cert_parse()
88 ret = asn1_ber_decoder(&x509_decoder, ctx, data, datalen); in x509_cert_parse()
93 if (ctx->raw_akid) { in x509_cert_parse()
95 ctx->raw_akid_size, ctx->raw_akid_size, ctx->raw_akid); in x509_cert_parse()
96 ret = asn1_ber_decoder(&x509_akid_decoder, ctx, in x509_cert_parse()
97 ctx->raw_akid, ctx->raw_akid_size); in x509_cert_parse()
105 cert->pub->key = kmemdup(ctx->key, ctx->key_size, GFP_KERNEL); in x509_cert_parse()
109 cert->pub->keylen = ctx->key_size; in x509_cert_parse()
111 cert->pub->params = kmemdup(ctx->params, ctx->params_size, GFP_KERNEL); in x509_cert_parse()
115 cert->pub->paramlen = ctx->params_size; in x509_cert_parse()
116 cert->pub->algo = ctx->key_algo; in x509_cert_parse()
139 kfree(ctx); in x509_cert_parse()
143 kfree(ctx); in x509_cert_parse()
159 struct x509_parse_context *ctx = context; in x509_note_OID() local
161 ctx->last_oid = look_up_OID(value, vlen); in x509_note_OID()
162 if (ctx->last_oid == OID__NR) { in x509_note_OID()
166 (unsigned long)value - ctx->data, buffer); in x509_note_OID()
179 struct x509_parse_context *ctx = context; in x509_note_tbs_certificate() local
182 hdrlen, tag, (unsigned long)value - ctx->data, vlen); in x509_note_tbs_certificate()
184 ctx->cert->tbs = value - hdrlen; in x509_note_tbs_certificate()
185 ctx->cert->tbs_size = vlen + hdrlen; in x509_note_tbs_certificate()
196 struct x509_parse_context *ctx = context; in x509_note_pkey_algo() local
198 pr_debug("PubKey Algo: %u\n", ctx->last_oid); in x509_note_pkey_algo()
200 switch (ctx->last_oid) { in x509_note_pkey_algo()
207 ctx->cert->sig->hash_algo = "md4"; in x509_note_pkey_algo()
211 ctx->cert->sig->hash_algo = "sha1"; in x509_note_pkey_algo()
215 ctx->cert->sig->hash_algo = "sha256"; in x509_note_pkey_algo()
219 ctx->cert->sig->hash_algo = "sha384"; in x509_note_pkey_algo()
223 ctx->cert->sig->hash_algo = "sha512"; in x509_note_pkey_algo()
227 ctx->cert->sig->hash_algo = "sha224"; in x509_note_pkey_algo()
231 ctx->cert->sig->hash_algo = "sha1"; in x509_note_pkey_algo()
235 ctx->cert->sig->hash_algo = "sha224"; in x509_note_pkey_algo()
239 ctx->cert->sig->hash_algo = "sha256"; in x509_note_pkey_algo()
243 ctx->cert->sig->hash_algo = "sha384"; in x509_note_pkey_algo()
247 ctx->cert->sig->hash_algo = "sha512"; in x509_note_pkey_algo()
251 ctx->cert->sig->hash_algo = "streebog256"; in x509_note_pkey_algo()
255 ctx->cert->sig->hash_algo = "streebog512"; in x509_note_pkey_algo()
259 ctx->cert->sig->hash_algo = "sm3"; in x509_note_pkey_algo()
264 ctx->cert->sig->pkey_algo = "rsa"; in x509_note_pkey_algo()
265 ctx->cert->sig->encoding = "pkcs1"; in x509_note_pkey_algo()
266 ctx->algo_oid = ctx->last_oid; in x509_note_pkey_algo()
269 ctx->cert->sig->pkey_algo = "ecrdsa"; in x509_note_pkey_algo()
270 ctx->cert->sig->encoding = "raw"; in x509_note_pkey_algo()
271 ctx->algo_oid = ctx->last_oid; in x509_note_pkey_algo()
274 ctx->cert->sig->pkey_algo = "sm2"; in x509_note_pkey_algo()
275 ctx->cert->sig->encoding = "raw"; in x509_note_pkey_algo()
276 ctx->algo_oid = ctx->last_oid; in x509_note_pkey_algo()
279 ctx->cert->sig->pkey_algo = "ecdsa"; in x509_note_pkey_algo()
280 ctx->cert->sig->encoding = "x962"; in x509_note_pkey_algo()
281 ctx->algo_oid = ctx->last_oid; in x509_note_pkey_algo()
292 struct x509_parse_context *ctx = context; in x509_note_signature() local
294 pr_debug("Signature type: %u size %zu\n", ctx->last_oid, vlen); in x509_note_signature()
296 if (ctx->last_oid != ctx->algo_oid) { in x509_note_signature()
298 ctx->algo_oid, ctx->last_oid); in x509_note_signature()
302 if (strcmp(ctx->cert->sig->pkey_algo, "rsa") == 0 || in x509_note_signature()
303 strcmp(ctx->cert->sig->pkey_algo, "ecrdsa") == 0 || in x509_note_signature()
304 strcmp(ctx->cert->sig->pkey_algo, "sm2") == 0 || in x509_note_signature()
305 strcmp(ctx->cert->sig->pkey_algo, "ecdsa") == 0) { in x509_note_signature()
314 ctx->cert->raw_sig = value; in x509_note_signature()
315 ctx->cert->raw_sig_size = vlen; in x509_note_signature()
326 struct x509_parse_context *ctx = context; in x509_note_serial() local
327 ctx->cert->raw_serial = value; in x509_note_serial()
328 ctx->cert->raw_serial_size = vlen; in x509_note_serial()
339 struct x509_parse_context *ctx = context; in x509_extract_name_segment() local
341 switch (ctx->last_oid) { in x509_extract_name_segment()
343 ctx->cn_size = vlen; in x509_extract_name_segment()
344 ctx->cn_offset = (unsigned long)value - ctx->data; in x509_extract_name_segment()
347 ctx->o_size = vlen; in x509_extract_name_segment()
348 ctx->o_offset = (unsigned long)value - ctx->data; in x509_extract_name_segment()
351 ctx->email_size = vlen; in x509_extract_name_segment()
352 ctx->email_offset = (unsigned long)value - ctx->data; in x509_extract_name_segment()
364 static int x509_fabricate_name(struct x509_parse_context *ctx, size_t hdrlen, in x509_fabricate_name() argument
368 const void *name, *data = (const void *)ctx->data; in x509_fabricate_name()
376 if (!ctx->cn_size && !ctx->o_size && !ctx->email_size) { in x509_fabricate_name()
384 if (ctx->cn_size && ctx->o_size) { in x509_fabricate_name()
388 namesize = ctx->cn_size; in x509_fabricate_name()
389 name = data + ctx->cn_offset; in x509_fabricate_name()
390 if (ctx->cn_size >= ctx->o_size && in x509_fabricate_name()
391 memcmp(data + ctx->cn_offset, data + ctx->o_offset, in x509_fabricate_name()
392 ctx->o_size) == 0) in x509_fabricate_name()
394 if (ctx->cn_size >= 7 && in x509_fabricate_name()
395 ctx->o_size >= 7 && in x509_fabricate_name()
396 memcmp(data + ctx->cn_offset, data + ctx->o_offset, 7) == 0) in x509_fabricate_name()
399 buffer = kmalloc(ctx->o_size + 2 + ctx->cn_size + 1, in x509_fabricate_name()
405 data + ctx->o_offset, ctx->o_size); in x509_fabricate_name()
406 buffer[ctx->o_size + 0] = ':'; in x509_fabricate_name()
407 buffer[ctx->o_size + 1] = ' '; in x509_fabricate_name()
408 memcpy(buffer + ctx->o_size + 2, in x509_fabricate_name()
409 data + ctx->cn_offset, ctx->cn_size); in x509_fabricate_name()
410 buffer[ctx->o_size + 2 + ctx->cn_size] = 0; in x509_fabricate_name()
413 } else if (ctx->cn_size) { in x509_fabricate_name()
414 namesize = ctx->cn_size; in x509_fabricate_name()
415 name = data + ctx->cn_offset; in x509_fabricate_name()
416 } else if (ctx->o_size) { in x509_fabricate_name()
417 namesize = ctx->o_size; in x509_fabricate_name()
418 name = data + ctx->o_offset; in x509_fabricate_name()
420 namesize = ctx->email_size; in x509_fabricate_name()
421 name = data + ctx->email_offset; in x509_fabricate_name()
433 ctx->cn_size = 0; in x509_fabricate_name()
434 ctx->o_size = 0; in x509_fabricate_name()
435 ctx->email_size = 0; in x509_fabricate_name()
443 struct x509_parse_context *ctx = context; in x509_note_issuer() local
444 ctx->cert->raw_issuer = value; in x509_note_issuer()
445 ctx->cert->raw_issuer_size = vlen; in x509_note_issuer()
446 return x509_fabricate_name(ctx, hdrlen, tag, &ctx->cert->issuer, vlen); in x509_note_issuer()
453 struct x509_parse_context *ctx = context; in x509_note_subject() local
454 ctx->cert->raw_subject = value; in x509_note_subject()
455 ctx->cert->raw_subject_size = vlen; in x509_note_subject()
456 return x509_fabricate_name(ctx, hdrlen, tag, &ctx->cert->subject, vlen); in x509_note_subject()
466 struct x509_parse_context *ctx = context; in x509_note_params() local
473 if (!ctx->cert->raw_subject || ctx->key) in x509_note_params()
475 ctx->params = value - hdrlen; in x509_note_params()
476 ctx->params_size = vlen + hdrlen; in x509_note_params()
487 struct x509_parse_context *ctx = context; in x509_extract_key_data() local
490 ctx->key_algo = ctx->last_oid; in x509_extract_key_data()
491 switch (ctx->last_oid) { in x509_extract_key_data()
493 ctx->cert->pub->pkey_algo = "rsa"; in x509_extract_key_data()
497 ctx->cert->pub->pkey_algo = "ecrdsa"; in x509_extract_key_data()
500 if (parse_OID(ctx->params, ctx->params_size, &oid) != 0) in x509_extract_key_data()
505 ctx->cert->pub->pkey_algo = "sm2"; in x509_extract_key_data()
508 ctx->cert->pub->pkey_algo = "ecdsa-nist-p192"; in x509_extract_key_data()
511 ctx->cert->pub->pkey_algo = "ecdsa-nist-p256"; in x509_extract_key_data()
514 ctx->cert->pub->pkey_algo = "ecdsa-nist-p384"; in x509_extract_key_data()
527 ctx->key = value + 1; in x509_extract_key_data()
528 ctx->key_size = vlen - 1; in x509_extract_key_data()
542 struct x509_parse_context *ctx = context; in x509_process_extension() local
546 pr_debug("Extension: %u\n", ctx->last_oid); in x509_process_extension()
548 if (ctx->last_oid == OID_subjectKeyIdentifier) { in x509_process_extension()
550 if (ctx->cert->skid || vlen < 3) in x509_process_extension()
557 ctx->cert->raw_skid_size = vlen; in x509_process_extension()
558 ctx->cert->raw_skid = v; in x509_process_extension()
562 ctx->cert->skid = kid; in x509_process_extension()
567 if (ctx->last_oid == OID_authorityKeyIdentifier) { in x509_process_extension()
569 ctx->raw_akid = v; in x509_process_extension()
570 ctx->raw_akid_size = vlen; in x509_process_extension()
676 struct x509_parse_context *ctx = context; in x509_note_not_before() local
677 return x509_decode_time(&ctx->cert->valid_from, hdrlen, tag, value, vlen); in x509_note_not_before()
684 struct x509_parse_context *ctx = context; in x509_note_not_after() local
685 return x509_decode_time(&ctx->cert->valid_to, hdrlen, tag, value, vlen); in x509_note_not_after()
695 struct x509_parse_context *ctx = context; in x509_akid_note_kid() local
700 if (ctx->cert->sig->auth_ids[1]) in x509_akid_note_kid()
707 ctx->cert->sig->auth_ids[1] = kid; in x509_akid_note_kid()
718 struct x509_parse_context *ctx = context; in x509_akid_note_name() local
722 ctx->akid_raw_issuer = value; in x509_akid_note_name()
723 ctx->akid_raw_issuer_size = vlen; in x509_akid_note_name()
734 struct x509_parse_context *ctx = context; in x509_akid_note_serial() local
739 if (!ctx->akid_raw_issuer || ctx->cert->sig->auth_ids[0]) in x509_akid_note_serial()
744 ctx->akid_raw_issuer, in x509_akid_note_serial()
745 ctx->akid_raw_issuer_size); in x509_akid_note_serial()
750 ctx->cert->sig->auth_ids[0] = kid; in x509_akid_note_serial()