v3_utf8.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Copyright 2020-2022 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #include <stdio.h>
  10. #include "internal/cryptlib.h"
  11. #include <openssl/asn1.h>
  12. #include <openssl/conf.h>
  13. #include <openssl/x509v3.h>
  14. #include "ext_dat.h"
  15. /*
  16. * Subject Sign Tool (1.2.643.100.111) The name of the tool used to signs the subject (UTF8String)
  17. * This extension is required to obtain the status of a qualified certificate at Russian Federation.
  18. * RFC-style description is available here: https://tools.ietf.org/html/draft-deremin-rfc4491-bis-04#section-5
  19. * Russian Federal Law 63 "Digital Sign" is available here: http://www.consultant.ru/document/cons_doc_LAW_112701/
  20. */
  21. const X509V3_EXT_METHOD ossl_v3_utf8_list[1] = {
  22. EXT_UTF8STRING(NID_subjectSignTool),
  23. };
  24. char *i2s_ASN1_UTF8STRING(X509V3_EXT_METHOD *method,
  25. ASN1_UTF8STRING *utf8)
  26. {
  27. char *tmp;
  28. if (utf8 == NULL || utf8->length == 0) {
  29. ERR_raise(ERR_LIB_X509V3, ERR_R_PASSED_NULL_PARAMETER);
  30. return NULL;
  31. }
  32. if ((tmp = OPENSSL_malloc(utf8->length + 1)) == NULL)
  33. return NULL;
  34. memcpy(tmp, utf8->data, utf8->length);
  35. tmp[utf8->length] = 0;
  36. return tmp;
  37. }
  38. ASN1_UTF8STRING *s2i_ASN1_UTF8STRING(X509V3_EXT_METHOD *method,
  39. X509V3_CTX *ctx, const char *str)
  40. {
  41. ASN1_UTF8STRING *utf8;
  42. if (str == NULL) {
  43. ERR_raise(ERR_LIB_X509V3, X509V3_R_INVALID_NULL_ARGUMENT);
  44. return NULL;
  45. }
  46. if ((utf8 = ASN1_UTF8STRING_new()) == NULL) {
  47. ERR_raise(ERR_LIB_X509V3, ERR_R_ASN1_LIB);
  48. return NULL;
  49. }
  50. if (!ASN1_STRING_set((ASN1_STRING *)utf8, str, strlen(str))) {
  51. ERR_raise(ERR_LIB_X509V3, ERR_R_ASN1_LIB);
  52. ASN1_UTF8STRING_free(utf8);
  53. return NULL;
  54. }
  55. #ifdef CHARSET_EBCDIC
  56. ebcdic2ascii(utf8->data, utf8->data, utf8->length);
  57. #endif /* CHARSET_EBCDIC */
  58. return utf8;
  59. }