x509.h 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665
  1. /*
  2. * Copyright (C) 2003-2016 Free Software Foundation, Inc.
  3. * Copyright (C) 2015-2016 Red Hat, Inc.
  4. *
  5. * Author: Nikos Mavrogiannopoulos
  6. *
  7. * This file is part of GnuTLS.
  8. *
  9. * The GnuTLS is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public License
  11. * as published by the Free Software Foundation; either version 2.1 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This library is distributed in the hope that it will be useful, but
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>
  21. *
  22. */
  23. /* This file contains the types and prototypes for the X.509
  24. * certificate and CRL handling functions.
  25. */
  26. #ifndef GNUTLS_X509_H
  27. #define GNUTLS_X509_H
  28. #include <gnutls/gnutls.h>
  29. /* *INDENT-OFF* */
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif
  33. /* *INDENT-ON* */
  34. /* Some OIDs usually found in Distinguished names, or
  35. * in Subject Directory Attribute extensions.
  36. */
  37. #define GNUTLS_OID_X520_COUNTRY_NAME "2.5.4.6"
  38. #define GNUTLS_OID_X520_ORGANIZATION_NAME "2.5.4.10"
  39. #define GNUTLS_OID_X520_ORGANIZATIONAL_UNIT_NAME "2.5.4.11"
  40. #define GNUTLS_OID_X520_COMMON_NAME "2.5.4.3"
  41. #define GNUTLS_OID_X520_LOCALITY_NAME "2.5.4.7"
  42. #define GNUTLS_OID_X520_STATE_OR_PROVINCE_NAME "2.5.4.8"
  43. #define GNUTLS_OID_X520_INITIALS "2.5.4.43"
  44. #define GNUTLS_OID_X520_GENERATION_QUALIFIER "2.5.4.44"
  45. #define GNUTLS_OID_X520_SURNAME "2.5.4.4"
  46. #define GNUTLS_OID_X520_GIVEN_NAME "2.5.4.42"
  47. #define GNUTLS_OID_X520_TITLE "2.5.4.12"
  48. #define GNUTLS_OID_X520_DN_QUALIFIER "2.5.4.46"
  49. #define GNUTLS_OID_X520_PSEUDONYM "2.5.4.65"
  50. #define GNUTLS_OID_X520_POSTALCODE "2.5.4.17"
  51. #define GNUTLS_OID_X520_NAME "2.5.4.41"
  52. #define GNUTLS_OID_LDAP_DC "0.9.2342.19200300.100.1.25"
  53. #define GNUTLS_OID_LDAP_UID "0.9.2342.19200300.100.1.1"
  54. /* The following should not be included in DN.
  55. */
  56. #define GNUTLS_OID_PKCS9_EMAIL "1.2.840.113549.1.9.1"
  57. #define GNUTLS_OID_PKIX_DATE_OF_BIRTH "1.3.6.1.5.5.7.9.1"
  58. #define GNUTLS_OID_PKIX_PLACE_OF_BIRTH "1.3.6.1.5.5.7.9.2"
  59. #define GNUTLS_OID_PKIX_GENDER "1.3.6.1.5.5.7.9.3"
  60. #define GNUTLS_OID_PKIX_COUNTRY_OF_CITIZENSHIP "1.3.6.1.5.5.7.9.4"
  61. #define GNUTLS_OID_PKIX_COUNTRY_OF_RESIDENCE "1.3.6.1.5.5.7.9.5"
  62. /* Key purpose Object Identifiers.
  63. */
  64. #define GNUTLS_KP_TLS_WWW_SERVER "1.3.6.1.5.5.7.3.1"
  65. #define GNUTLS_KP_TLS_WWW_CLIENT "1.3.6.1.5.5.7.3.2"
  66. #define GNUTLS_KP_CODE_SIGNING "1.3.6.1.5.5.7.3.3"
  67. #define GNUTLS_KP_MS_SMART_CARD_LOGON "1.3.6.1.4.1.311.20.2.2"
  68. #define GNUTLS_KP_EMAIL_PROTECTION "1.3.6.1.5.5.7.3.4"
  69. #define GNUTLS_KP_TIME_STAMPING "1.3.6.1.5.5.7.3.8"
  70. #define GNUTLS_KP_OCSP_SIGNING "1.3.6.1.5.5.7.3.9"
  71. #define GNUTLS_KP_IPSEC_IKE "1.3.6.1.5.5.7.3.17"
  72. #define GNUTLS_KP_ANY "2.5.29.37.0"
  73. #define GNUTLS_KP_FLAG_DISALLOW_ANY 1
  74. #define GNUTLS_OID_AIA "1.3.6.1.5.5.7.1.1"
  75. #define GNUTLS_OID_AD_OCSP "1.3.6.1.5.5.7.48.1"
  76. #define GNUTLS_OID_AD_CAISSUERS "1.3.6.1.5.5.7.48.2"
  77. #define GNUTLS_FSAN_SET 0
  78. #define GNUTLS_FSAN_APPEND 1
  79. #define GNUTLS_FSAN_ENCODE_OCTET_STRING (1<<1)
  80. #define GNUTLS_FSAN_ENCODE_UTF8_STRING (1<<2)
  81. #define GNUTLS_X509EXT_OID_SUBJECT_KEY_ID "2.5.29.14"
  82. #define GNUTLS_X509EXT_OID_KEY_USAGE "2.5.29.15"
  83. #define GNUTLS_X509EXT_OID_PRIVATE_KEY_USAGE_PERIOD "2.5.29.16"
  84. #define GNUTLS_X509EXT_OID_SAN "2.5.29.17"
  85. #define GNUTLS_X509EXT_OID_IAN "2.5.29.18"
  86. #define GNUTLS_X509EXT_OID_BASIC_CONSTRAINTS "2.5.29.19"
  87. #define GNUTLS_X509EXT_OID_NAME_CONSTRAINTS "2.5.29.30"
  88. #define GNUTLS_X509EXT_OID_CRL_DIST_POINTS "2.5.29.31"
  89. #define GNUTLS_X509EXT_OID_CRT_POLICY "2.5.29.32"
  90. #define GNUTLS_X509EXT_OID_AUTHORITY_KEY_ID "2.5.29.35"
  91. #define GNUTLS_X509EXT_OID_EXTENDED_KEY_USAGE "2.5.29.37"
  92. #define GNUTLS_X509EXT_OID_INHIBIT_ANYPOLICY "2.5.29.52"
  93. #define GNUTLS_X509EXT_OID_AUTHORITY_INFO_ACCESS "1.3.6.1.5.5.7.1.1"
  94. #define GNUTLS_X509EXT_OID_PROXY_CRT_INFO "1.3.6.1.5.5.7.1.14"
  95. #define GNUTLS_X509EXT_OID_TLSFEATURES "1.3.6.1.5.5.7.1.24"
  96. #define GNUTLS_X509_OID_POLICY_ANY "2.5.29.54"
  97. /* Certificate handling functions.
  98. */
  99. /**
  100. * gnutls_certificate_import_flags:
  101. * @GNUTLS_X509_CRT_LIST_IMPORT_FAIL_IF_EXCEED: Fail if the
  102. * certificates in the buffer are more than the space allocated for
  103. * certificates. The error code will be %GNUTLS_E_SHORT_MEMORY_BUFFER.
  104. * @GNUTLS_X509_CRT_LIST_FAIL_IF_UNSORTED: Fail if the certificates
  105. * in the buffer are not ordered starting from subject to issuer.
  106. * The error code will be %GNUTLS_E_CERTIFICATE_LIST_UNSORTED.
  107. * @GNUTLS_X509_CRT_LIST_SORT: Sort the certificate chain if unsorted.
  108. *
  109. * Enumeration of different certificate import flags.
  110. */
  111. typedef enum gnutls_certificate_import_flags {
  112. GNUTLS_X509_CRT_LIST_IMPORT_FAIL_IF_EXCEED = 1,
  113. GNUTLS_X509_CRT_LIST_FAIL_IF_UNSORTED = 1<<1,
  114. GNUTLS_X509_CRT_LIST_SORT = 1<<2
  115. } gnutls_certificate_import_flags;
  116. int gnutls_x509_crt_init(gnutls_x509_crt_t * cert);
  117. void gnutls_x509_crt_deinit(gnutls_x509_crt_t cert);
  118. /**
  119. * gnutls_certificate_import_flags:
  120. * @GNUTLS_X509_CRT_FLAG_IGNORE_SANITY: Ignore any sanity checks at the
  121. * import of the certificate; i.e., ignore checks such as version/field
  122. * matching and strict time field checks. Intended to be used for debugging.
  123. *
  124. * Enumeration of different certificate flags.
  125. */
  126. typedef enum gnutls_x509_crt_flags {
  127. GNUTLS_X509_CRT_FLAG_IGNORE_SANITY = 1
  128. } gnutls_x509_crt_flags;
  129. void gnutls_x509_crt_set_flags(gnutls_x509_crt_t cert, unsigned flags);
  130. unsigned gnutls_x509_crt_equals(gnutls_x509_crt_t cert1, gnutls_x509_crt_t cert2);
  131. unsigned gnutls_x509_crt_equals2(gnutls_x509_crt_t cert1, gnutls_datum_t * der);
  132. int gnutls_x509_crt_import(gnutls_x509_crt_t cert,
  133. const gnutls_datum_t * data,
  134. gnutls_x509_crt_fmt_t format);
  135. int gnutls_x509_crt_list_import2(gnutls_x509_crt_t ** certs,
  136. unsigned int *size,
  137. const gnutls_datum_t * data,
  138. gnutls_x509_crt_fmt_t format,
  139. unsigned int flags);
  140. int gnutls_x509_crt_list_import(gnutls_x509_crt_t * certs,
  141. unsigned int *cert_max,
  142. const gnutls_datum_t * data,
  143. gnutls_x509_crt_fmt_t format,
  144. unsigned int flags);
  145. int gnutls_x509_crt_import_url(gnutls_x509_crt_t crt,
  146. const char *url, unsigned int flags
  147. /* GNUTLS_PKCS11_OBJ_FLAG_* */
  148. );
  149. int gnutls_x509_crt_export(gnutls_x509_crt_t cert,
  150. gnutls_x509_crt_fmt_t format,
  151. void *output_data, size_t * output_data_size);
  152. int gnutls_x509_crt_export2(gnutls_x509_crt_t cert,
  153. gnutls_x509_crt_fmt_t format,
  154. gnutls_datum_t * out);
  155. int gnutls_x509_crt_get_private_key_usage_period(gnutls_x509_crt_t
  156. cert,
  157. time_t *
  158. activation,
  159. time_t *
  160. expiration, unsigned int
  161. *critical);
  162. int gnutls_x509_crt_get_issuer_dn(gnutls_x509_crt_t cert,
  163. char *buf, size_t * buf_size);
  164. int gnutls_x509_crt_get_issuer_dn2(gnutls_x509_crt_t cert,
  165. gnutls_datum_t * dn);
  166. int gnutls_x509_crt_get_issuer_dn3(gnutls_x509_crt_t cert,
  167. gnutls_datum_t * dn, unsigned flags);
  168. int gnutls_x509_crt_get_issuer_dn_oid(gnutls_x509_crt_t cert,
  169. unsigned indx, void *oid,
  170. size_t * oid_size);
  171. int gnutls_x509_crt_get_issuer_dn_by_oid(gnutls_x509_crt_t cert,
  172. const char *oid, unsigned indx,
  173. unsigned int raw_flag,
  174. void *buf, size_t * buf_size);
  175. int gnutls_x509_crt_get_dn(gnutls_x509_crt_t cert, char *buf,
  176. size_t * buf_size);
  177. int gnutls_x509_crt_get_dn2(gnutls_x509_crt_t cert, gnutls_datum_t * dn);
  178. int gnutls_x509_crt_get_dn3(gnutls_x509_crt_t cert, gnutls_datum_t * dn, unsigned flags);
  179. int gnutls_x509_crt_get_dn_oid(gnutls_x509_crt_t cert, unsigned indx,
  180. void *oid, size_t * oid_size);
  181. int gnutls_x509_crt_get_dn_by_oid(gnutls_x509_crt_t cert,
  182. const char *oid, unsigned indx,
  183. unsigned int raw_flag, void *buf,
  184. size_t * buf_size);
  185. unsigned gnutls_x509_crt_check_hostname(gnutls_x509_crt_t cert,
  186. const char *hostname);
  187. unsigned gnutls_x509_crt_check_hostname2(gnutls_x509_crt_t cert,
  188. const char *hostname, unsigned int flags);
  189. unsigned
  190. gnutls_x509_crt_check_email(gnutls_x509_crt_t cert,
  191. const char *email, unsigned int flags);
  192. unsigned
  193. gnutls_x509_crt_check_ip(gnutls_x509_crt_t cert,
  194. const unsigned char *ip, unsigned int ip_size,
  195. unsigned int flags);
  196. int gnutls_x509_crt_get_signature_algorithm(gnutls_x509_crt_t cert);
  197. int gnutls_x509_crt_get_signature(gnutls_x509_crt_t cert,
  198. char *sig, size_t * sizeof_sig);
  199. int gnutls_x509_crt_get_version(gnutls_x509_crt_t cert);
  200. int gnutls_x509_crt_get_pk_oid(gnutls_x509_crt_t cert, char *oid, size_t *oid_size);
  201. int gnutls_x509_crt_get_signature_oid(gnutls_x509_crt_t cert, char *oid, size_t *oid_size);
  202. /**
  203. * gnutls_keyid_flags_t:
  204. * @GNUTLS_KEYID_USE_SHA1: Use SHA1 as the key ID algorithm (default).
  205. * @GNUTLS_KEYID_USE_SHA256: Use SHA256 as the key ID algorithm.
  206. * @GNUTLS_KEYID_USE_BEST_KNOWN: Use the best known algorithm to calculate key ID. Using that option will make your program behavior depend on the version of gnutls linked with. That option has a cap of 64-bytes key IDs.
  207. *
  208. * Enumeration of different flags for the key ID functions.
  209. */
  210. typedef enum {
  211. GNUTLS_KEYID_USE_SHA1 = 0,
  212. GNUTLS_KEYID_USE_SHA256 = (1<<0),
  213. GNUTLS_KEYID_USE_BEST_KNOWN = (1<<30)
  214. } gnutls_keyid_flags_t;
  215. int gnutls_x509_crt_get_key_id(gnutls_x509_crt_t crt,
  216. unsigned int flags,
  217. unsigned char *output_data,
  218. size_t * output_data_size);
  219. int gnutls_x509_crt_set_private_key_usage_period(gnutls_x509_crt_t
  220. crt,
  221. time_t activation,
  222. time_t expiration);
  223. int gnutls_x509_crt_set_authority_key_id(gnutls_x509_crt_t cert,
  224. const void *id, size_t id_size);
  225. int gnutls_x509_crt_get_authority_key_id(gnutls_x509_crt_t cert,
  226. void *id,
  227. size_t * id_size,
  228. unsigned int *critical);
  229. int gnutls_x509_crt_get_authority_key_gn_serial(gnutls_x509_crt_t
  230. cert,
  231. unsigned int seq,
  232. void *alt,
  233. size_t * alt_size,
  234. unsigned int
  235. *alt_type,
  236. void *serial,
  237. size_t *
  238. serial_size, unsigned int
  239. *critical);
  240. int gnutls_x509_crt_get_subject_key_id(gnutls_x509_crt_t cert,
  241. void *ret,
  242. size_t * ret_size,
  243. unsigned int *critical);
  244. int gnutls_x509_crt_get_subject_unique_id(gnutls_x509_crt_t crt,
  245. char *buf, size_t * buf_size);
  246. int gnutls_x509_crt_get_issuer_unique_id(gnutls_x509_crt_t crt,
  247. char *buf, size_t * buf_size);
  248. void gnutls_x509_crt_set_pin_function(gnutls_x509_crt_t crt,
  249. gnutls_pin_callback_t fn,
  250. void *userdata);
  251. /**
  252. * gnutls_info_access_what_t:
  253. * @GNUTLS_IA_ACCESSMETHOD_OID: Get accessMethod OID.
  254. * @GNUTLS_IA_ACCESSLOCATION_GENERALNAME_TYPE: Get accessLocation name type.
  255. * @GNUTLS_IA_URI: Get accessLocation URI value.
  256. * @GNUTLS_IA_OCSP_URI: get accessLocation URI value for OCSP.
  257. * @GNUTLS_IA_CAISSUERS_URI: get accessLocation URI value for caIssuers.
  258. *
  259. * Enumeration of types for the @what parameter of
  260. * gnutls_x509_crt_get_authority_info_access().
  261. */
  262. typedef enum gnutls_info_access_what_t {
  263. GNUTLS_IA_ACCESSMETHOD_OID = 1,
  264. GNUTLS_IA_ACCESSLOCATION_GENERALNAME_TYPE = 2,
  265. /* use 100-108 for the generalName types, populate as needed */
  266. GNUTLS_IA_URI = 106,
  267. /* quick-access variants that match both OID and name type. */
  268. GNUTLS_IA_UNKNOWN = 10000,
  269. GNUTLS_IA_OCSP_URI = 10006,
  270. GNUTLS_IA_CAISSUERS_URI = 10106
  271. } gnutls_info_access_what_t;
  272. int gnutls_x509_crt_get_authority_info_access(gnutls_x509_crt_t
  273. crt,
  274. unsigned int seq,
  275. int what,
  276. gnutls_datum_t *
  277. data, unsigned int
  278. *critical);
  279. typedef struct gnutls_name_constraints_st *gnutls_x509_name_constraints_t;
  280. unsigned gnutls_x509_name_constraints_check(gnutls_x509_name_constraints_t nc,
  281. gnutls_x509_subject_alt_name_t type,
  282. const gnutls_datum_t * name);
  283. unsigned gnutls_x509_name_constraints_check_crt(gnutls_x509_name_constraints_t nc,
  284. gnutls_x509_subject_alt_name_t type,
  285. gnutls_x509_crt_t crt);
  286. int gnutls_x509_name_constraints_init(gnutls_x509_name_constraints_t *nc);
  287. void gnutls_x509_name_constraints_deinit(gnutls_x509_name_constraints_t nc);
  288. #define GNUTLS_EXT_FLAG_APPEND 1
  289. #define GNUTLS_NAME_CONSTRAINTS_FLAG_APPEND GNUTLS_EXT_FLAG_APPEND
  290. int gnutls_x509_crt_get_name_constraints(gnutls_x509_crt_t crt,
  291. gnutls_x509_name_constraints_t nc,
  292. unsigned int flags,
  293. unsigned int *critical);
  294. int gnutls_x509_name_constraints_add_permitted(gnutls_x509_name_constraints_t nc,
  295. gnutls_x509_subject_alt_name_t type,
  296. const gnutls_datum_t * name);
  297. int gnutls_x509_name_constraints_add_excluded(gnutls_x509_name_constraints_t nc,
  298. gnutls_x509_subject_alt_name_t type,
  299. const gnutls_datum_t * name);
  300. int gnutls_x509_crt_set_name_constraints(gnutls_x509_crt_t crt,
  301. gnutls_x509_name_constraints_t nc,
  302. unsigned int critical);
  303. int gnutls_x509_name_constraints_get_permitted(gnutls_x509_name_constraints_t nc,
  304. unsigned idx,
  305. unsigned *type, gnutls_datum_t * name);
  306. int gnutls_x509_name_constraints_get_excluded(gnutls_x509_name_constraints_t nc,
  307. unsigned idx,
  308. unsigned *type, gnutls_datum_t * name);
  309. int gnutls_x509_cidr_to_rfc5280(const char *cidr, gnutls_datum_t *cidr_rfc5280);
  310. #define GNUTLS_CRL_REASON_SUPERSEEDED GNUTLS_CRL_REASON_SUPERSEDED,
  311. /**
  312. * gnutls_x509_crl_reason_flags_t:
  313. * @GNUTLS_CRL_REASON_PRIVILEGE_WITHDRAWN: The privileges were withdrawn from the owner.
  314. * @GNUTLS_CRL_REASON_CERTIFICATE_HOLD: The certificate is on hold.
  315. * @GNUTLS_CRL_REASON_CESSATION_OF_OPERATION: The end-entity is no longer operating.
  316. * @GNUTLS_CRL_REASON_SUPERSEDED: There is a newer certificate of the owner.
  317. * @GNUTLS_CRL_REASON_AFFILIATION_CHANGED: The end-entity affiliation has changed.
  318. * @GNUTLS_CRL_REASON_CA_COMPROMISE: The CA was compromised.
  319. * @GNUTLS_CRL_REASON_KEY_COMPROMISE: The certificate's key was compromised.
  320. * @GNUTLS_CRL_REASON_UNUSED: The key was never used.
  321. * @GNUTLS_CRL_REASON_AA_COMPROMISE: AA compromised.
  322. *
  323. * Enumeration of types for the CRL revocation reasons.
  324. */
  325. typedef enum gnutls_x509_crl_reason_flags_t {
  326. GNUTLS_CRL_REASON_UNSPECIFIED = 0,
  327. GNUTLS_CRL_REASON_PRIVILEGE_WITHDRAWN = 1,
  328. GNUTLS_CRL_REASON_CERTIFICATE_HOLD = 2,
  329. GNUTLS_CRL_REASON_CESSATION_OF_OPERATION = 4,
  330. GNUTLS_CRL_REASON_SUPERSEDED = 8,
  331. GNUTLS_CRL_REASON_AFFILIATION_CHANGED = 16,
  332. GNUTLS_CRL_REASON_CA_COMPROMISE = 32,
  333. GNUTLS_CRL_REASON_KEY_COMPROMISE = 64,
  334. GNUTLS_CRL_REASON_UNUSED = 128,
  335. GNUTLS_CRL_REASON_AA_COMPROMISE = 32768
  336. } gnutls_x509_crl_reason_flags_t;
  337. int gnutls_x509_crt_get_crl_dist_points(gnutls_x509_crt_t cert,
  338. unsigned int seq,
  339. void *ret,
  340. size_t * ret_size,
  341. unsigned int *reason_flags,
  342. unsigned int *critical);
  343. int gnutls_x509_crt_set_crl_dist_points2(gnutls_x509_crt_t crt,
  344. gnutls_x509_subject_alt_name_t
  345. type, const void *data,
  346. unsigned int data_size,
  347. unsigned int reason_flags);
  348. int gnutls_x509_crt_set_crl_dist_points(gnutls_x509_crt_t crt,
  349. gnutls_x509_subject_alt_name_t
  350. type,
  351. const void *data_string,
  352. unsigned int reason_flags);
  353. int gnutls_x509_crt_cpy_crl_dist_points(gnutls_x509_crt_t dst,
  354. gnutls_x509_crt_t src);
  355. int gnutls_x509_crl_sign2(gnutls_x509_crl_t crl,
  356. gnutls_x509_crt_t issuer,
  357. gnutls_x509_privkey_t issuer_key,
  358. gnutls_digest_algorithm_t dig,
  359. unsigned int flags);
  360. time_t gnutls_x509_crt_get_activation_time(gnutls_x509_crt_t cert);
  361. #define GNUTLS_X509_NO_WELL_DEFINED_EXPIRATION ((time_t)4294197631)
  362. time_t gnutls_x509_crt_get_expiration_time(gnutls_x509_crt_t cert);
  363. int gnutls_x509_crt_get_serial(gnutls_x509_crt_t cert,
  364. void *result, size_t * result_size);
  365. typedef struct gnutls_x509_spki_st *gnutls_x509_spki_t;
  366. int gnutls_x509_spki_init(gnutls_x509_spki_t *spki);
  367. void gnutls_x509_spki_deinit(gnutls_x509_spki_t spki);
  368. int gnutls_x509_spki_get_rsa_pss_params(gnutls_x509_spki_t spki,
  369. gnutls_digest_algorithm_t *dig, unsigned int *salt_size);
  370. void gnutls_x509_spki_set_rsa_pss_params(gnutls_x509_spki_t spki,
  371. gnutls_digest_algorithm_t dig, unsigned int salt_size);
  372. int gnutls_x509_crt_get_pk_algorithm(gnutls_x509_crt_t cert,
  373. unsigned int *bits);
  374. int gnutls_x509_crt_set_spki(gnutls_x509_crt_t crt, const gnutls_x509_spki_t spki,
  375. unsigned int flags);
  376. int gnutls_x509_crt_get_spki(gnutls_x509_crt_t cert, gnutls_x509_spki_t spki,
  377. unsigned int flags);
  378. int gnutls_x509_crt_get_pk_rsa_raw(gnutls_x509_crt_t crt,
  379. gnutls_datum_t * m, gnutls_datum_t * e);
  380. int gnutls_x509_crt_get_pk_dsa_raw(gnutls_x509_crt_t crt,
  381. gnutls_datum_t * p,
  382. gnutls_datum_t * q,
  383. gnutls_datum_t * g, gnutls_datum_t * y);
  384. int gnutls_x509_crt_get_pk_ecc_raw(gnutls_x509_crt_t crt,
  385. gnutls_ecc_curve_t * curve,
  386. gnutls_datum_t * x,
  387. gnutls_datum_t * y);
  388. int gnutls_x509_crt_get_subject_alt_name(gnutls_x509_crt_t cert,
  389. unsigned int seq,
  390. void *san,
  391. size_t * san_size,
  392. unsigned int *critical);
  393. int gnutls_x509_crt_get_subject_alt_name2(gnutls_x509_crt_t cert,
  394. unsigned int seq,
  395. void *san,
  396. size_t * san_size,
  397. unsigned int *san_type,
  398. unsigned int *critical);
  399. int gnutls_x509_crt_get_subject_alt_othername_oid(gnutls_x509_crt_t
  400. cert,
  401. unsigned int seq,
  402. void *oid,
  403. size_t * oid_size);
  404. int gnutls_x509_crt_get_issuer_alt_name(gnutls_x509_crt_t cert,
  405. unsigned int seq,
  406. void *ian,
  407. size_t * ian_size,
  408. unsigned int *critical);
  409. int gnutls_x509_crt_get_issuer_alt_name2(gnutls_x509_crt_t cert,
  410. unsigned int seq,
  411. void *ian,
  412. size_t * ian_size,
  413. unsigned int *ian_type,
  414. unsigned int *critical);
  415. int gnutls_x509_crt_get_issuer_alt_othername_oid(gnutls_x509_crt_t
  416. cert,
  417. unsigned int seq,
  418. void *ret,
  419. size_t * ret_size);
  420. int gnutls_x509_crt_get_ca_status(gnutls_x509_crt_t cert,
  421. unsigned int *critical);
  422. int gnutls_x509_crt_get_basic_constraints(gnutls_x509_crt_t cert,
  423. unsigned int *critical,
  424. unsigned int *ca, int *pathlen);
  425. /* The key_usage flags are defined in gnutls.h. They are the
  426. * GNUTLS_KEY_* definitions.
  427. */
  428. int gnutls_x509_crt_get_key_usage(gnutls_x509_crt_t cert,
  429. unsigned int *key_usage,
  430. unsigned int *critical);
  431. int gnutls_x509_crt_set_key_usage(gnutls_x509_crt_t crt,
  432. unsigned int usage);
  433. int gnutls_x509_crt_set_authority_info_access(gnutls_x509_crt_t
  434. crt, int what,
  435. gnutls_datum_t * data);
  436. int gnutls_x509_crt_get_inhibit_anypolicy(gnutls_x509_crt_t cert,
  437. unsigned int *skipcerts,
  438. unsigned int *critical);
  439. int
  440. gnutls_x509_crt_set_inhibit_anypolicy(gnutls_x509_crt_t crt, unsigned int skipcerts);
  441. int gnutls_x509_crt_get_proxy(gnutls_x509_crt_t cert,
  442. unsigned int *critical,
  443. int *pathlen,
  444. char **policyLanguage,
  445. char **policy, size_t * sizeof_policy);
  446. typedef struct gnutls_x509_tlsfeatures_st *gnutls_x509_tlsfeatures_t;
  447. int gnutls_x509_tlsfeatures_init(gnutls_x509_tlsfeatures_t *features);
  448. void gnutls_x509_tlsfeatures_deinit(gnutls_x509_tlsfeatures_t);
  449. int gnutls_x509_tlsfeatures_get(gnutls_x509_tlsfeatures_t f, unsigned idx, unsigned int *feature);
  450. int gnutls_x509_crt_set_tlsfeatures(gnutls_x509_crt_t crt,
  451. gnutls_x509_tlsfeatures_t features);
  452. int gnutls_x509_crt_get_tlsfeatures(gnutls_x509_crt_t cert,
  453. gnutls_x509_tlsfeatures_t features,
  454. unsigned int flags,
  455. unsigned int *critical);
  456. unsigned gnutls_x509_tlsfeatures_check_crt(gnutls_x509_tlsfeatures_t feat,
  457. gnutls_x509_crt_t crt);
  458. #define GNUTLS_MAX_QUALIFIERS 8
  459. /**
  460. * gnutls_x509_qualifier_t:
  461. * @GNUTLS_X509_QUALIFIER_UNKNOWN: Unknown qualifier.
  462. * @GNUTLS_X509_QUALIFIER_URI: A URL
  463. * @GNUTLS_X509_QUALIFIER_NOICE: A text notice.
  464. *
  465. * Enumeration of types for the X.509 qualifiers, of the certificate policy extension.
  466. */
  467. typedef enum gnutls_x509_qualifier_t {
  468. GNUTLS_X509_QUALIFIER_UNKNOWN = 0, GNUTLS_X509_QUALIFIER_URI,
  469. GNUTLS_X509_QUALIFIER_NOTICE
  470. } gnutls_x509_qualifier_t;
  471. typedef struct gnutls_x509_policy_st {
  472. char *oid;
  473. unsigned int qualifiers;
  474. struct {
  475. gnutls_x509_qualifier_t type;
  476. char *data;
  477. unsigned int size;
  478. } qualifier[GNUTLS_MAX_QUALIFIERS];
  479. } gnutls_x509_policy_st;
  480. void gnutls_x509_policy_release(struct gnutls_x509_policy_st
  481. *policy);
  482. int gnutls_x509_crt_get_policy(gnutls_x509_crt_t crt, unsigned indx, struct gnutls_x509_policy_st
  483. *policy, unsigned int *critical);
  484. int gnutls_x509_crt_set_policy(gnutls_x509_crt_t crt, const struct gnutls_x509_policy_st
  485. *policy, unsigned int critical);
  486. int gnutls_x509_dn_oid_known(const char *oid);
  487. #define GNUTLS_X509_DN_OID_RETURN_OID 1
  488. const char *gnutls_x509_dn_oid_name(const char *oid, unsigned int flags);
  489. /* Read extensions by OID. */
  490. int gnutls_x509_crt_get_extension_oid(gnutls_x509_crt_t cert,
  491. unsigned indx, void *oid,
  492. size_t * oid_size);
  493. int gnutls_x509_crt_get_extension_by_oid(gnutls_x509_crt_t cert,
  494. const char *oid, unsigned indx,
  495. void *buf,
  496. size_t * buf_size,
  497. unsigned int *critical);
  498. int gnutls_x509_crq_get_signature_algorithm(gnutls_x509_crq_t crq);
  499. int
  500. gnutls_x509_crq_get_extension_by_oid2(gnutls_x509_crq_t crq,
  501. const char *oid, unsigned indx,
  502. gnutls_datum_t *output,
  503. unsigned int *critical);
  504. /* Read extensions by sequence number. */
  505. int gnutls_x509_crt_get_extension_info(gnutls_x509_crt_t cert,
  506. unsigned indx, void *oid,
  507. size_t * oid_size,
  508. unsigned int *critical);
  509. int gnutls_x509_crt_get_extension_data(gnutls_x509_crt_t cert,
  510. unsigned indx, void *data,
  511. size_t * sizeof_data);
  512. int
  513. gnutls_x509_crt_get_extension_data2(gnutls_x509_crt_t cert,
  514. unsigned indx, gnutls_datum_t * data);
  515. int gnutls_x509_crt_set_extension_by_oid(gnutls_x509_crt_t crt,
  516. const char *oid,
  517. const void *buf,
  518. size_t sizeof_buf,
  519. unsigned int critical);
  520. /* X.509 Certificate writing.
  521. */
  522. int gnutls_x509_crt_set_dn(gnutls_x509_crt_t crt, const char *dn,
  523. const char **err);
  524. int gnutls_x509_crt_set_dn_by_oid(gnutls_x509_crt_t crt,
  525. const char *oid,
  526. unsigned int raw_flag,
  527. const void *name,
  528. unsigned int sizeof_name);
  529. int gnutls_x509_crt_set_issuer_dn_by_oid(gnutls_x509_crt_t crt,
  530. const char *oid,
  531. unsigned int raw_flag,
  532. const void *name,
  533. unsigned int sizeof_name);
  534. int gnutls_x509_crt_set_issuer_dn(gnutls_x509_crt_t crt,
  535. const char *dn, const char **err);
  536. int gnutls_x509_crt_set_version(gnutls_x509_crt_t crt,
  537. unsigned int version);
  538. int gnutls_x509_crt_set_key(gnutls_x509_crt_t crt,
  539. gnutls_x509_privkey_t key);
  540. int gnutls_x509_crt_set_ca_status(gnutls_x509_crt_t crt, unsigned int ca);
  541. int gnutls_x509_crt_set_basic_constraints(gnutls_x509_crt_t crt,
  542. unsigned int ca,
  543. int pathLenConstraint);
  544. int
  545. gnutls_x509_crt_set_subject_unique_id(gnutls_x509_crt_t cert, const void *id,
  546. size_t id_size);
  547. int
  548. gnutls_x509_crt_set_issuer_unique_id(gnutls_x509_crt_t cert, const void *id,
  549. size_t id_size);
  550. int gnutls_x509_crt_set_subject_alternative_name(gnutls_x509_crt_t
  551. crt,
  552. gnutls_x509_subject_alt_name_t
  553. type, const char
  554. *data_string);
  555. int gnutls_x509_crt_set_subject_alt_name(gnutls_x509_crt_t crt,
  556. gnutls_x509_subject_alt_name_t
  557. type, const void *data,
  558. unsigned int data_size,
  559. unsigned int flags);
  560. int
  561. gnutls_x509_crt_set_subject_alt_othername(gnutls_x509_crt_t crt,
  562. const char *oid,
  563. const void *data,
  564. unsigned int data_size,
  565. unsigned int flags);
  566. int gnutls_x509_crt_set_issuer_alt_name(gnutls_x509_crt_t crt,
  567. gnutls_x509_subject_alt_name_t
  568. type, const void *data,
  569. unsigned int data_size,
  570. unsigned int flags);
  571. int
  572. gnutls_x509_crt_set_issuer_alt_othername(gnutls_x509_crt_t crt,
  573. const char *oid,
  574. const void *data,
  575. unsigned int data_size,
  576. unsigned int flags);
  577. int gnutls_x509_crt_sign(gnutls_x509_crt_t crt,
  578. gnutls_x509_crt_t issuer,
  579. gnutls_x509_privkey_t issuer_key);
  580. int gnutls_x509_crt_sign2(gnutls_x509_crt_t crt,
  581. gnutls_x509_crt_t issuer,
  582. gnutls_x509_privkey_t issuer_key,
  583. gnutls_digest_algorithm_t dig,
  584. unsigned int flags);
  585. int gnutls_x509_crt_set_activation_time(gnutls_x509_crt_t cert,
  586. time_t act_time);
  587. int gnutls_x509_crt_set_expiration_time(gnutls_x509_crt_t cert,
  588. time_t exp_time);
  589. int gnutls_x509_crt_set_serial(gnutls_x509_crt_t cert,
  590. const void *serial, size_t serial_size);
  591. int gnutls_x509_crt_set_subject_key_id(gnutls_x509_crt_t cert,
  592. const void *id, size_t id_size);
  593. int gnutls_x509_crt_set_proxy_dn(gnutls_x509_crt_t crt,
  594. gnutls_x509_crt_t eecrt,
  595. unsigned int raw_flag,
  596. const void *name,
  597. unsigned int sizeof_name);
  598. int gnutls_x509_crt_set_proxy(gnutls_x509_crt_t crt,
  599. int pathLenConstraint,
  600. const char *policyLanguage,
  601. const char *policy, size_t sizeof_policy);
  602. int gnutls_x509_crt_print(gnutls_x509_crt_t cert,
  603. gnutls_certificate_print_formats_t
  604. format, gnutls_datum_t * out);
  605. int gnutls_x509_crl_print(gnutls_x509_crl_t crl,
  606. gnutls_certificate_print_formats_t
  607. format, gnutls_datum_t * out);
  608. /* Access to internal Certificate fields.
  609. */
  610. int gnutls_x509_crt_get_raw_issuer_dn(gnutls_x509_crt_t cert,
  611. gnutls_datum_t * start);
  612. int gnutls_x509_crt_get_raw_dn(gnutls_x509_crt_t cert,
  613. gnutls_datum_t * start);
  614. /* RDN handling.
  615. */
  616. int gnutls_x509_rdn_get(const gnutls_datum_t * idn,
  617. char *buf, size_t * sizeof_buf);
  618. int
  619. gnutls_x509_rdn_get2(const gnutls_datum_t * idn,
  620. gnutls_datum_t *str, unsigned flags);
  621. int gnutls_x509_rdn_get_oid(const gnutls_datum_t * idn,
  622. unsigned indx, void *buf, size_t * sizeof_buf);
  623. int gnutls_x509_rdn_get_by_oid(const gnutls_datum_t * idn,
  624. const char *oid, unsigned indx,
  625. unsigned int raw_flag, void *buf,
  626. size_t * sizeof_buf);
  627. typedef struct gnutls_x509_dn_st *gnutls_x509_dn_t;
  628. typedef struct gnutls_x509_ava_st {
  629. gnutls_datum_t oid;
  630. gnutls_datum_t value;
  631. unsigned long value_tag;
  632. } gnutls_x509_ava_st;
  633. int gnutls_x509_crt_get_subject(gnutls_x509_crt_t cert,
  634. gnutls_x509_dn_t * dn);
  635. int gnutls_x509_crt_get_issuer(gnutls_x509_crt_t cert,
  636. gnutls_x509_dn_t * dn);
  637. int gnutls_x509_dn_get_rdn_ava(gnutls_x509_dn_t dn, int irdn,
  638. int iava, gnutls_x509_ava_st * ava);
  639. int gnutls_x509_dn_get_str(gnutls_x509_dn_t dn, gnutls_datum_t *str);
  640. #define GNUTLS_X509_DN_FLAG_COMPAT 1
  641. int gnutls_x509_dn_get_str2(gnutls_x509_dn_t dn, gnutls_datum_t *str, unsigned flags);
  642. int
  643. gnutls_x509_dn_set_str(gnutls_x509_dn_t dn, const char *str, const char **err);
  644. int gnutls_x509_dn_init(gnutls_x509_dn_t * dn);
  645. int gnutls_x509_dn_import(gnutls_x509_dn_t dn,
  646. const gnutls_datum_t * data);
  647. int gnutls_x509_dn_export(gnutls_x509_dn_t dn,
  648. gnutls_x509_crt_fmt_t format,
  649. void *output_data, size_t * output_data_size);
  650. int gnutls_x509_dn_export2(gnutls_x509_dn_t dn,
  651. gnutls_x509_crt_fmt_t format,
  652. gnutls_datum_t * out);
  653. void gnutls_x509_dn_deinit(gnutls_x509_dn_t dn);
  654. /* CRL handling functions.
  655. */
  656. int gnutls_x509_crl_init(gnutls_x509_crl_t * crl);
  657. void gnutls_x509_crl_deinit(gnutls_x509_crl_t crl);
  658. int gnutls_x509_crl_import(gnutls_x509_crl_t crl,
  659. const gnutls_datum_t * data,
  660. gnutls_x509_crt_fmt_t format);
  661. int gnutls_x509_crl_export(gnutls_x509_crl_t crl,
  662. gnutls_x509_crt_fmt_t format,
  663. void *output_data, size_t * output_data_size);
  664. int gnutls_x509_crl_export2(gnutls_x509_crl_t crl,
  665. gnutls_x509_crt_fmt_t format,
  666. gnutls_datum_t * out);
  667. int
  668. gnutls_x509_crl_get_raw_issuer_dn(gnutls_x509_crl_t crl,
  669. gnutls_datum_t * dn);
  670. int gnutls_x509_crl_get_issuer_dn(gnutls_x509_crl_t crl,
  671. char *buf, size_t * sizeof_buf);
  672. int gnutls_x509_crl_get_issuer_dn2(gnutls_x509_crl_t crl,
  673. gnutls_datum_t * dn);
  674. int gnutls_x509_crl_get_issuer_dn3(gnutls_x509_crl_t crl,
  675. gnutls_datum_t * dn, unsigned flags);
  676. int gnutls_x509_crl_get_issuer_dn_by_oid(gnutls_x509_crl_t crl,
  677. const char *oid, unsigned indx,
  678. unsigned int raw_flag,
  679. void *buf, size_t * sizeof_buf);
  680. int gnutls_x509_crl_get_dn_oid(gnutls_x509_crl_t crl, unsigned indx,
  681. void *oid, size_t * sizeof_oid);
  682. int gnutls_x509_crl_get_signature_algorithm(gnutls_x509_crl_t crl);
  683. int gnutls_x509_crl_get_signature(gnutls_x509_crl_t crl,
  684. char *sig, size_t * sizeof_sig);
  685. int gnutls_x509_crl_get_version(gnutls_x509_crl_t crl);
  686. int gnutls_x509_crl_get_signature_oid(gnutls_x509_crl_t crl, char *oid, size_t *oid_size);
  687. time_t gnutls_x509_crl_get_this_update(gnutls_x509_crl_t crl);
  688. time_t gnutls_x509_crl_get_next_update(gnutls_x509_crl_t crl);
  689. int gnutls_x509_crl_get_crt_count(gnutls_x509_crl_t crl);
  690. int gnutls_x509_crl_get_crt_serial(gnutls_x509_crl_t crl, unsigned indx,
  691. unsigned char *serial,
  692. size_t * serial_size, time_t * t);
  693. typedef struct gnutls_x509_crl_iter * gnutls_x509_crl_iter_t;
  694. int gnutls_x509_crl_iter_crt_serial(gnutls_x509_crl_t crl,
  695. gnutls_x509_crl_iter_t *,
  696. unsigned char *serial,
  697. size_t * serial_size, time_t * t);
  698. void gnutls_x509_crl_iter_deinit(gnutls_x509_crl_iter_t);
  699. #define gnutls_x509_crl_get_certificate_count gnutls_x509_crl_get_crt_count
  700. #define gnutls_x509_crl_get_certificate gnutls_x509_crl_get_crt_serial
  701. unsigned gnutls_x509_crl_check_issuer(gnutls_x509_crl_t crl,
  702. gnutls_x509_crt_t issuer);
  703. int gnutls_x509_crl_list_import2(gnutls_x509_crl_t ** crls,
  704. unsigned int *size,
  705. const gnutls_datum_t * data,
  706. gnutls_x509_crt_fmt_t format,
  707. unsigned int flags);
  708. int gnutls_x509_crl_list_import(gnutls_x509_crl_t * crls,
  709. unsigned int *crl_max,
  710. const gnutls_datum_t * data,
  711. gnutls_x509_crt_fmt_t format,
  712. unsigned int flags);
  713. /* CRL writing.
  714. */
  715. int gnutls_x509_crl_set_version(gnutls_x509_crl_t crl,
  716. unsigned int version);
  717. int gnutls_x509_crl_set_this_update(gnutls_x509_crl_t crl,
  718. time_t act_time);
  719. int gnutls_x509_crl_set_next_update(gnutls_x509_crl_t crl,
  720. time_t exp_time);
  721. int gnutls_x509_crl_set_crt_serial(gnutls_x509_crl_t crl,
  722. const void *serial,
  723. size_t serial_size,
  724. time_t revocation_time);
  725. int gnutls_x509_crl_set_crt(gnutls_x509_crl_t crl,
  726. gnutls_x509_crt_t crt, time_t revocation_time);
  727. int gnutls_x509_crl_get_authority_key_id(gnutls_x509_crl_t crl,
  728. void *id,
  729. size_t * id_size,
  730. unsigned int *critical);
  731. int gnutls_x509_crl_get_authority_key_gn_serial(gnutls_x509_crl_t
  732. crl,
  733. unsigned int seq,
  734. void *alt,
  735. size_t * alt_size,
  736. unsigned int
  737. *alt_type,
  738. void *serial,
  739. size_t *
  740. serial_size, unsigned int
  741. *critical);
  742. int gnutls_x509_crl_get_number(gnutls_x509_crl_t crl, void *ret,
  743. size_t * ret_size, unsigned int *critical);
  744. int gnutls_x509_crl_get_extension_oid(gnutls_x509_crl_t crl,
  745. unsigned indx, void *oid,
  746. size_t * sizeof_oid);
  747. int gnutls_x509_crl_get_extension_info(gnutls_x509_crl_t crl,
  748. unsigned indx, void *oid,
  749. size_t * sizeof_oid,
  750. unsigned int *critical);
  751. int gnutls_x509_crl_get_extension_data(gnutls_x509_crl_t crl,
  752. unsigned indx, void *data,
  753. size_t * sizeof_data);
  754. int
  755. gnutls_x509_crl_get_extension_data2(gnutls_x509_crl_t crl,
  756. unsigned indx, gnutls_datum_t * data);
  757. int gnutls_x509_crl_set_authority_key_id(gnutls_x509_crl_t crl,
  758. const void *id, size_t id_size);
  759. int gnutls_x509_crl_set_number(gnutls_x509_crl_t crl,
  760. const void *nr, size_t nr_size);
  761. /* X.509 Certificate verification functions.
  762. */
  763. /**
  764. * gnutls_certificate_verify_flags:
  765. * @GNUTLS_VERIFY_DISABLE_CA_SIGN: If set a signer does not have to be
  766. * a certificate authority. This flag should normally be disabled,
  767. * unless you know what this means.
  768. * @GNUTLS_VERIFY_DISABLE_TRUSTED_TIME_CHECKS: If set a signer in the trusted
  769. * list is never checked for expiration or activation.
  770. * @GNUTLS_VERIFY_DO_NOT_ALLOW_X509_V1_CA_CRT: Do not allow trusted CA
  771. * certificates that have version 1. This option is to be used
  772. * to deprecate all certificates of version 1.
  773. * @GNUTLS_VERIFY_DO_NOT_ALLOW_SAME: If a certificate is not signed by
  774. * anyone trusted but exists in the trusted CA list do not treat it
  775. * as trusted.
  776. * @GNUTLS_VERIFY_ALLOW_UNSORTED_CHAIN: A certificate chain is tolerated
  777. * if unsorted (the case with many TLS servers out there). This is the
  778. * default since GnuTLS 3.1.4.
  779. * @GNUTLS_VERIFY_DO_NOT_ALLOW_UNSORTED_CHAIN: Do not tolerate an unsorted
  780. * certificate chain.
  781. * @GNUTLS_VERIFY_ALLOW_ANY_X509_V1_CA_CRT: Allow CA certificates that
  782. * have version 1 (both root and intermediate). This might be
  783. * dangerous since those haven't the basicConstraints
  784. * extension.
  785. * @GNUTLS_VERIFY_ALLOW_SIGN_RSA_MD2: Allow certificates to be signed
  786. * using the broken MD2 algorithm.
  787. * @GNUTLS_VERIFY_ALLOW_SIGN_RSA_MD5: Allow certificates to be signed
  788. * using the broken MD5 algorithm.
  789. * @GNUTLS_VERIFY_ALLOW_SIGN_WITH_SHA1: Allow certificates to be signed
  790. * using the broken SHA1 hash algorithm.
  791. * @GNUTLS_VERIFY_ALLOW_BROKEN: Allow certificates to be signed
  792. * using any broken algorithm.
  793. * @GNUTLS_VERIFY_DISABLE_TIME_CHECKS: Disable checking of activation
  794. * and expiration validity periods of certificate chains. Don't set
  795. * this unless you understand the security implications.
  796. * @GNUTLS_VERIFY_DISABLE_CRL_CHECKS: Disable checking for validity
  797. * using certificate revocation lists or the available OCSP data.
  798. * @GNUTLS_VERIFY_DO_NOT_ALLOW_WILDCARDS: When including a hostname
  799. * check in the verification, do not consider any wildcards.
  800. * @GNUTLS_VERIFY_DO_NOT_ALLOW_IP_MATCHES: When verifying a hostname
  801. * prevent textual IP addresses from matching IP addresses in the
  802. * certificate. Treat the input only as a DNS name.
  803. * @GNUTLS_VERIFY_USE_TLS1_RSA: This indicates that a (raw) RSA signature is provided
  804. * as in the TLS 1.0 protocol. Not all functions accept this flag.
  805. * @GNUTLS_VERIFY_IGNORE_UNKNOWN_CRIT_EXTENSIONS: This signals the verification
  806. * process, not to fail on unknown critical extensions.
  807. *
  808. * Enumeration of different certificate verify flags. Additional
  809. * verification profiles can be set using GNUTLS_PROFILE_TO_VFLAGS()
  810. * and %gnutls_certificate_verification_profiles_t.
  811. */
  812. typedef enum gnutls_certificate_verify_flags {
  813. GNUTLS_VERIFY_DISABLE_CA_SIGN = 1 << 0,
  814. GNUTLS_VERIFY_DO_NOT_ALLOW_IP_MATCHES = 1<<1,
  815. GNUTLS_VERIFY_DO_NOT_ALLOW_SAME = 1 << 2,
  816. GNUTLS_VERIFY_ALLOW_ANY_X509_V1_CA_CRT = 1 << 3,
  817. GNUTLS_VERIFY_ALLOW_SIGN_RSA_MD2 = 1 << 4,
  818. GNUTLS_VERIFY_ALLOW_SIGN_RSA_MD5 = 1 << 5,
  819. GNUTLS_VERIFY_DISABLE_TIME_CHECKS = 1 << 6,
  820. GNUTLS_VERIFY_DISABLE_TRUSTED_TIME_CHECKS = 1 << 7,
  821. GNUTLS_VERIFY_DO_NOT_ALLOW_X509_V1_CA_CRT = 1 << 8,
  822. GNUTLS_VERIFY_DISABLE_CRL_CHECKS = 1 << 9,
  823. GNUTLS_VERIFY_ALLOW_UNSORTED_CHAIN = 1 << 10,
  824. GNUTLS_VERIFY_DO_NOT_ALLOW_UNSORTED_CHAIN = 1 << 11,
  825. GNUTLS_VERIFY_DO_NOT_ALLOW_WILDCARDS = 1 << 12,
  826. GNUTLS_VERIFY_USE_TLS1_RSA = 1 << 13,
  827. GNUTLS_VERIFY_IGNORE_UNKNOWN_CRIT_EXTENSIONS = 1 << 14,
  828. GNUTLS_VERIFY_ALLOW_SIGN_WITH_SHA1 = 1 << 15
  829. /* cannot exceed 2^24 due to GNUTLS_PROFILE_TO_VFLAGS() */
  830. } gnutls_certificate_verify_flags;
  831. #define GNUTLS_VERIFY_ALLOW_BROKEN (GNUTLS_VERIFY_ALLOW_SIGN_RSA_MD2|GNUTLS_VERIFY_ALLOW_SIGN_RSA_MD5)
  832. /**
  833. * gnutls_certificate_verification_profiles_t:
  834. * @GNUTLS_PROFILE_VERY_WEAK: A verification profile that
  835. * corresponds to @GNUTLS_SEC_PARAM_VERY_WEAK (64 bits)
  836. * @GNUTLS_PROFILE_LOW: A verification profile that
  837. * corresponds to @GNUTLS_SEC_PARAM_LOW (80 bits)
  838. * @GNUTLS_PROFILE_LEGACY: A verification profile that
  839. * corresponds to @GNUTLS_SEC_PARAM_LEGACY (96 bits)
  840. * @GNUTLS_PROFILE_MEDIUM: A verification profile that
  841. * corresponds to @GNUTLS_SEC_PARAM_MEDIUM (112 bits)
  842. * @GNUTLS_PROFILE_HIGH: A verification profile that
  843. * corresponds to @GNUTLS_SEC_PARAM_HIGH (128 bits)
  844. * @GNUTLS_PROFILE_ULTRA: A verification profile that
  845. * corresponds to @GNUTLS_SEC_PARAM_ULTRA (256 bits)
  846. % * @GNUTLS_PROFILE_SUITEB128: A verification profile that
  847. * applies the SUITEB128 rules
  848. * @GNUTLS_PROFILE_SUITEB192: A verification profile that
  849. * applies the SUITEB192 rules
  850. *
  851. * Enumeration of different certificate verification profiles.
  852. */
  853. typedef enum gnutls_certificate_verification_profiles_t {
  854. GNUTLS_PROFILE_VERY_WEAK = 1,
  855. GNUTLS_PROFILE_LOW = 2,
  856. GNUTLS_PROFILE_LEGACY = 4,
  857. GNUTLS_PROFILE_MEDIUM = 5,
  858. GNUTLS_PROFILE_HIGH = 6,
  859. GNUTLS_PROFILE_ULTRA = 7,
  860. GNUTLS_PROFILE_SUITEB128=32,
  861. GNUTLS_PROFILE_SUITEB192=33
  862. /*GNUTLS_PROFILE_MAX=255*/
  863. } gnutls_certificate_verification_profiles_t;
  864. #define GNUTLS_PROFILE_TO_VFLAGS(x) \
  865. (((unsigned)x)<<24)
  866. #define GNUTLS_VFLAGS_PROFILE_MASK (0xff000000)
  867. #define GNUTLS_VFLAGS_TO_PROFILE(x) \
  868. ((((unsigned)x)>>24)&0xff)
  869. unsigned gnutls_x509_crt_check_issuer(gnutls_x509_crt_t cert,
  870. gnutls_x509_crt_t issuer);
  871. int gnutls_x509_crt_list_verify(const gnutls_x509_crt_t *
  872. cert_list, unsigned cert_list_length,
  873. const gnutls_x509_crt_t * CA_list,
  874. unsigned CA_list_length,
  875. const gnutls_x509_crl_t * CRL_list,
  876. unsigned CRL_list_length,
  877. unsigned int flags, unsigned int *verify);
  878. int gnutls_x509_crt_verify(gnutls_x509_crt_t cert,
  879. const gnutls_x509_crt_t * CA_list,
  880. unsigned CA_list_length, unsigned int flags,
  881. unsigned int *verify);
  882. int gnutls_x509_crl_verify(gnutls_x509_crl_t crl,
  883. const gnutls_x509_crt_t * CA_list,
  884. unsigned CA_list_length, unsigned int flags,
  885. unsigned int *verify);
  886. int
  887. gnutls_x509_crt_verify_data2(gnutls_x509_crt_t crt,
  888. gnutls_sign_algorithm_t algo,
  889. unsigned int flags,
  890. const gnutls_datum_t * data,
  891. const gnutls_datum_t * signature);
  892. int gnutls_x509_crt_check_revocation(gnutls_x509_crt_t cert,
  893. const gnutls_x509_crl_t *
  894. crl_list, unsigned crl_list_length);
  895. int gnutls_x509_crt_get_fingerprint(gnutls_x509_crt_t cert,
  896. gnutls_digest_algorithm_t algo,
  897. void *buf, size_t * buf_size);
  898. int gnutls_x509_crt_get_key_purpose_oid(gnutls_x509_crt_t cert,
  899. unsigned indx, void *oid,
  900. size_t * oid_size,
  901. unsigned int *critical);
  902. int gnutls_x509_crt_set_key_purpose_oid(gnutls_x509_crt_t cert,
  903. const void *oid,
  904. unsigned int critical);
  905. unsigned gnutls_x509_crt_check_key_purpose(gnutls_x509_crt_t cert,
  906. const char *purpose, unsigned flags);
  907. /* Private key handling.
  908. */
  909. /* Flags for the gnutls_x509_privkey_export_pkcs8() function.
  910. */
  911. #define GNUTLS_PKCS8_PLAIN GNUTLS_PKCS_PLAIN
  912. #define GNUTLS_PKCS8_USE_PKCS12_3DES GNUTLS_PKCS_PKCS12_3DES
  913. #define GNUTLS_PKCS8_USE_PKCS12_ARCFOUR GNUTLS_PKCS_PKCS12_ARCFOUR
  914. #define GNUTLS_PKCS8_USE_PKCS12_RC2_40 GNUTLS_PKCS_PKCS12_RC2_40
  915. /**
  916. * gnutls_pkcs_encrypt_flags_t:
  917. * @GNUTLS_PKCS_PLAIN: Unencrypted private key.
  918. * @GNUTLS_PKCS_NULL_PASSWORD: Some schemas distinguish between an empty and a NULL password.
  919. * @GNUTLS_PKCS_PKCS12_3DES: PKCS-12 3DES.
  920. * @GNUTLS_PKCS_PKCS12_ARCFOUR: PKCS-12 ARCFOUR.
  921. * @GNUTLS_PKCS_PKCS12_RC2_40: PKCS-12 RC2-40.
  922. * @GNUTLS_PKCS_PBES2_3DES: PBES2 3DES.
  923. * @GNUTLS_PKCS_PBES2_AES_128: PBES2 AES-128.
  924. * @GNUTLS_PKCS_PBES2_AES_192: PBES2 AES-192.
  925. * @GNUTLS_PKCS_PBES2_AES_256: PBES2 AES-256.
  926. * @GNUTLS_PKCS_PBES2_DES: PBES2 single DES.
  927. * @GNUTLS_PKCS_PBES2_DES_MD5: PBES1 with single DES; for compatibility with openssl only.
  928. *
  929. * Enumeration of different PKCS encryption flags.
  930. */
  931. typedef enum gnutls_pkcs_encrypt_flags_t {
  932. GNUTLS_PKCS_PLAIN = 1,
  933. GNUTLS_PKCS_PKCS12_3DES = 1<<1,
  934. GNUTLS_PKCS_PKCS12_ARCFOUR = 1<<2,
  935. GNUTLS_PKCS_PKCS12_RC2_40 = 1<<3,
  936. GNUTLS_PKCS_PBES2_3DES = 1<<4,
  937. GNUTLS_PKCS_PBES2_AES_128 = 1<<5,
  938. GNUTLS_PKCS_PBES2_AES_192 = 1<<6,
  939. GNUTLS_PKCS_PBES2_AES_256 = 1<<7,
  940. GNUTLS_PKCS_NULL_PASSWORD = 1<<8,
  941. GNUTLS_PKCS_PBES2_DES = 1<<9,
  942. GNUTLS_PKCS_PBES1_DES_MD5 = 1<<10
  943. } gnutls_pkcs_encrypt_flags_t;
  944. #define GNUTLS_PKCS_CIPHER_MASK(x) ((x)&(~(GNUTLS_PKCS_NULL_PASSWORD)))
  945. #define GNUTLS_PKCS_USE_PKCS12_3DES GNUTLS_PKCS_PKCS12_3DES
  946. #define GNUTLS_PKCS_USE_PKCS12_ARCFOUR GNUTLS_PKCS_PKCS12_ARCFOUR
  947. #define GNUTLS_PKCS_USE_PKCS12_RC2_40 GNUTLS_PKCS_PKCS12_RC2_40
  948. #define GNUTLS_PKCS_USE_PBES2_3DES GNUTLS_PKCS_PBES2_3DES
  949. #define GNUTLS_PKCS_USE_PBES2_AES_128 GNUTLS_PKCS_PBES2_AES_128
  950. #define GNUTLS_PKCS_USE_PBES2_AES_192 GNUTLS_PKCS_PBES2_AES_192
  951. #define GNUTLS_PKCS_USE_PBES2_AES_256 GNUTLS_PKCS_PBES2_AES_256
  952. const char *gnutls_pkcs_schema_get_name(unsigned int schema);
  953. const char *gnutls_pkcs_schema_get_oid(unsigned int schema);
  954. int gnutls_x509_privkey_init(gnutls_x509_privkey_t * key);
  955. void gnutls_x509_privkey_deinit(gnutls_x509_privkey_t key);
  956. gnutls_sec_param_t
  957. gnutls_x509_privkey_sec_param(gnutls_x509_privkey_t key);
  958. void gnutls_x509_privkey_set_pin_function(gnutls_x509_privkey_t key,
  959. gnutls_pin_callback_t fn,
  960. void *userdata);
  961. int gnutls_x509_privkey_cpy(gnutls_x509_privkey_t dst,
  962. gnutls_x509_privkey_t src);
  963. int gnutls_x509_privkey_import(gnutls_x509_privkey_t key,
  964. const gnutls_datum_t * data,
  965. gnutls_x509_crt_fmt_t format);
  966. int gnutls_x509_privkey_import_pkcs8(gnutls_x509_privkey_t key,
  967. const gnutls_datum_t * data,
  968. gnutls_x509_crt_fmt_t format,
  969. const char *password,
  970. unsigned int flags);
  971. int gnutls_x509_privkey_import_openssl(gnutls_x509_privkey_t key,
  972. const gnutls_datum_t * data,
  973. const char *password);
  974. int
  975. gnutls_pkcs8_info(const gnutls_datum_t * data, gnutls_x509_crt_fmt_t format,
  976. unsigned int *schema, unsigned int *cipher,
  977. void *salt, unsigned int *salt_size,
  978. unsigned int *iter_count, char **oid);
  979. int gnutls_x509_privkey_import2(gnutls_x509_privkey_t key,
  980. const gnutls_datum_t * data,
  981. gnutls_x509_crt_fmt_t format,
  982. const char *password, unsigned int flags);
  983. int gnutls_x509_privkey_import_rsa_raw(gnutls_x509_privkey_t key,
  984. const gnutls_datum_t * m,
  985. const gnutls_datum_t * e,
  986. const gnutls_datum_t * d,
  987. const gnutls_datum_t * p,
  988. const gnutls_datum_t * q,
  989. const gnutls_datum_t * u);
  990. int gnutls_x509_privkey_import_rsa_raw2(gnutls_x509_privkey_t key,
  991. const gnutls_datum_t * m,
  992. const gnutls_datum_t * e,
  993. const gnutls_datum_t * d,
  994. const gnutls_datum_t * p,
  995. const gnutls_datum_t * q,
  996. const gnutls_datum_t * u,
  997. const gnutls_datum_t * e1,
  998. const gnutls_datum_t * e2);
  999. int gnutls_x509_privkey_import_ecc_raw(gnutls_x509_privkey_t key,
  1000. gnutls_ecc_curve_t curve,
  1001. const gnutls_datum_t * x,
  1002. const gnutls_datum_t * y,
  1003. const gnutls_datum_t * k);
  1004. int gnutls_x509_privkey_fix(gnutls_x509_privkey_t key);
  1005. int gnutls_x509_privkey_export_dsa_raw(gnutls_x509_privkey_t key,
  1006. gnutls_datum_t * p,
  1007. gnutls_datum_t * q,
  1008. gnutls_datum_t * g,
  1009. gnutls_datum_t * y,
  1010. gnutls_datum_t * x);
  1011. int gnutls_x509_privkey_import_dsa_raw(gnutls_x509_privkey_t key,
  1012. const gnutls_datum_t * p,
  1013. const gnutls_datum_t * q,
  1014. const gnutls_datum_t * g,
  1015. const gnutls_datum_t * y,
  1016. const gnutls_datum_t * x);
  1017. int gnutls_x509_privkey_get_pk_algorithm(gnutls_x509_privkey_t key);
  1018. int gnutls_x509_privkey_get_pk_algorithm2(gnutls_x509_privkey_t
  1019. key, unsigned int *bits);
  1020. int gnutls_x509_privkey_get_spki(gnutls_x509_privkey_t key,
  1021. gnutls_x509_spki_t spki,
  1022. unsigned int flags);
  1023. int
  1024. gnutls_x509_privkey_set_spki(gnutls_x509_privkey_t key,
  1025. const gnutls_x509_spki_t spki,
  1026. unsigned int flags);
  1027. int gnutls_x509_privkey_get_key_id(gnutls_x509_privkey_t key,
  1028. unsigned int flags,
  1029. unsigned char *output_data,
  1030. size_t * output_data_size);
  1031. int gnutls_x509_privkey_generate(gnutls_x509_privkey_t key,
  1032. gnutls_pk_algorithm_t algo,
  1033. unsigned int bits, unsigned int flags);
  1034. void gnutls_x509_privkey_set_flags(gnutls_x509_privkey_t key, unsigned int flags);
  1035. /**
  1036. * gnutls_keygen_types_t:
  1037. * @GNUTLS_KEYGEN_SEED: Specifies the seed to be used in key generation.
  1038. * @GNUTLS_KEYGEN_DIGEST: The size field specifies the hash algorithm to be used in key generation.
  1039. * @GNUTLS_KEYGEN_SPKI: data points to a %gnutls_x509_spki_t structure; it is not used after the key generation call.
  1040. *
  1041. * Enumeration of different key exchange algorithms.
  1042. */
  1043. typedef enum {
  1044. GNUTLS_KEYGEN_SEED = 1,
  1045. GNUTLS_KEYGEN_DIGEST = 2,
  1046. GNUTLS_KEYGEN_SPKI = 3
  1047. } gnutls_keygen_types_t;
  1048. typedef struct {
  1049. gnutls_keygen_types_t type;
  1050. unsigned char *data;
  1051. unsigned int size;
  1052. } gnutls_keygen_data_st;
  1053. int
  1054. gnutls_x509_privkey_generate2(gnutls_x509_privkey_t key,
  1055. gnutls_pk_algorithm_t algo, unsigned int bits,
  1056. unsigned int flags, const gnutls_keygen_data_st *data, unsigned data_size);
  1057. int gnutls_x509_privkey_verify_seed(gnutls_x509_privkey_t key, gnutls_digest_algorithm_t, const void *seed, size_t seed_size);
  1058. int gnutls_x509_privkey_get_seed(gnutls_x509_privkey_t key, gnutls_digest_algorithm_t*, void *seed, size_t *seed_size);
  1059. int gnutls_x509_privkey_verify_params(gnutls_x509_privkey_t key);
  1060. int gnutls_x509_privkey_export(gnutls_x509_privkey_t key,
  1061. gnutls_x509_crt_fmt_t format,
  1062. void *output_data,
  1063. size_t * output_data_size);
  1064. int gnutls_x509_privkey_export2(gnutls_x509_privkey_t key,
  1065. gnutls_x509_crt_fmt_t format,
  1066. gnutls_datum_t * out);
  1067. int gnutls_x509_privkey_export_pkcs8(gnutls_x509_privkey_t key,
  1068. gnutls_x509_crt_fmt_t format,
  1069. const char *password,
  1070. unsigned int flags,
  1071. void *output_data,
  1072. size_t * output_data_size);
  1073. int gnutls_x509_privkey_export2_pkcs8(gnutls_x509_privkey_t key,
  1074. gnutls_x509_crt_fmt_t format,
  1075. const char *password,
  1076. unsigned int flags,
  1077. gnutls_datum_t * out);
  1078. int gnutls_x509_privkey_export_rsa_raw2(gnutls_x509_privkey_t key,
  1079. gnutls_datum_t * m,
  1080. gnutls_datum_t * e,
  1081. gnutls_datum_t * d,
  1082. gnutls_datum_t * p,
  1083. gnutls_datum_t * q,
  1084. gnutls_datum_t * u,
  1085. gnutls_datum_t * e1,
  1086. gnutls_datum_t * e2);
  1087. int gnutls_x509_privkey_export_rsa_raw(gnutls_x509_privkey_t key,
  1088. gnutls_datum_t * m,
  1089. gnutls_datum_t * e,
  1090. gnutls_datum_t * d,
  1091. gnutls_datum_t * p,
  1092. gnutls_datum_t * q,
  1093. gnutls_datum_t * u);
  1094. int gnutls_x509_privkey_export_ecc_raw(gnutls_x509_privkey_t key,
  1095. gnutls_ecc_curve_t * curve,
  1096. gnutls_datum_t * x,
  1097. gnutls_datum_t * y,
  1098. gnutls_datum_t * k);
  1099. int gnutls_x509_privkey_sign_data(gnutls_x509_privkey_t key,
  1100. gnutls_digest_algorithm_t digest,
  1101. unsigned int flags,
  1102. const gnutls_datum_t * data,
  1103. void *signature,
  1104. size_t * signature_size);
  1105. /* Certificate request stuff.
  1106. */
  1107. int gnutls_x509_crq_sign2(gnutls_x509_crq_t crq,
  1108. gnutls_x509_privkey_t key,
  1109. gnutls_digest_algorithm_t dig,
  1110. unsigned int flags);
  1111. int gnutls_x509_crq_print(gnutls_x509_crq_t crq,
  1112. gnutls_certificate_print_formats_t
  1113. format, gnutls_datum_t * out);
  1114. int gnutls_x509_crq_verify(gnutls_x509_crq_t crq, unsigned int flags);
  1115. int gnutls_x509_crq_init(gnutls_x509_crq_t * crq);
  1116. void gnutls_x509_crq_deinit(gnutls_x509_crq_t crq);
  1117. int gnutls_x509_crq_import(gnutls_x509_crq_t crq,
  1118. const gnutls_datum_t * data,
  1119. gnutls_x509_crt_fmt_t format);
  1120. int gnutls_x509_crq_get_private_key_usage_period(gnutls_x509_crq_t
  1121. cert,
  1122. time_t *
  1123. activation,
  1124. time_t *
  1125. expiration, unsigned int
  1126. *critical);
  1127. int gnutls_x509_crq_get_dn(gnutls_x509_crq_t crq, char *buf,
  1128. size_t * sizeof_buf);
  1129. int gnutls_x509_crq_get_dn2(gnutls_x509_crq_t crq, gnutls_datum_t * dn);
  1130. int gnutls_x509_crq_get_dn3(gnutls_x509_crq_t crq, gnutls_datum_t * dn, unsigned flags);
  1131. int gnutls_x509_crq_get_dn_oid(gnutls_x509_crq_t crq, unsigned indx,
  1132. void *oid, size_t * sizeof_oid);
  1133. int gnutls_x509_crq_get_dn_by_oid(gnutls_x509_crq_t crq,
  1134. const char *oid, unsigned indx,
  1135. unsigned int raw_flag, void *buf,
  1136. size_t * sizeof_buf);
  1137. int gnutls_x509_crq_set_dn(gnutls_x509_crq_t crq, const char *dn,
  1138. const char **err);
  1139. int gnutls_x509_crq_set_dn_by_oid(gnutls_x509_crq_t crq,
  1140. const char *oid,
  1141. unsigned int raw_flag,
  1142. const void *data,
  1143. unsigned int sizeof_data);
  1144. int gnutls_x509_crq_set_version(gnutls_x509_crq_t crq,
  1145. unsigned int version);
  1146. int gnutls_x509_crq_get_version(gnutls_x509_crq_t crq);
  1147. int gnutls_x509_crq_set_key(gnutls_x509_crq_t crq,
  1148. gnutls_x509_privkey_t key);
  1149. int
  1150. gnutls_x509_crq_set_extension_by_oid(gnutls_x509_crq_t crq,
  1151. const char *oid, const void *buf,
  1152. size_t sizeof_buf,
  1153. unsigned int critical);
  1154. int gnutls_x509_crq_set_challenge_password(gnutls_x509_crq_t crq,
  1155. const char *pass);
  1156. int gnutls_x509_crq_get_challenge_password(gnutls_x509_crq_t crq,
  1157. char *pass,
  1158. size_t * sizeof_pass);
  1159. int gnutls_x509_crq_set_attribute_by_oid(gnutls_x509_crq_t crq,
  1160. const char *oid,
  1161. void *buf, size_t sizeof_buf);
  1162. int gnutls_x509_crq_get_attribute_by_oid(gnutls_x509_crq_t crq,
  1163. const char *oid, unsigned indx,
  1164. void *buf, size_t * sizeof_buf);
  1165. int gnutls_x509_crq_export(gnutls_x509_crq_t crq,
  1166. gnutls_x509_crt_fmt_t format,
  1167. void *output_data, size_t * output_data_size);
  1168. int gnutls_x509_crq_export2(gnutls_x509_crq_t crq,
  1169. gnutls_x509_crt_fmt_t format,
  1170. gnutls_datum_t * out);
  1171. int gnutls_x509_crt_set_crq(gnutls_x509_crt_t crt, gnutls_x509_crq_t crq);
  1172. int gnutls_x509_crt_set_crq_extensions(gnutls_x509_crt_t crt,
  1173. gnutls_x509_crq_t crq);
  1174. int
  1175. gnutls_x509_crt_set_crq_extension_by_oid(gnutls_x509_crt_t crt,
  1176. gnutls_x509_crq_t crq, const char *oid,
  1177. unsigned flags);
  1178. int gnutls_x509_crq_set_private_key_usage_period(gnutls_x509_crq_t
  1179. crq,
  1180. time_t activation,
  1181. time_t expiration);
  1182. int gnutls_x509_crq_set_key_rsa_raw(gnutls_x509_crq_t crq,
  1183. const gnutls_datum_t * m,
  1184. const gnutls_datum_t * e);
  1185. int gnutls_x509_crq_set_subject_alt_name(gnutls_x509_crq_t crq,
  1186. gnutls_x509_subject_alt_name_t
  1187. nt, const void *data,
  1188. unsigned int data_size,
  1189. unsigned int flags);
  1190. int
  1191. gnutls_x509_crq_set_subject_alt_othername(gnutls_x509_crq_t crq,
  1192. const char *oid,
  1193. const void *data,
  1194. unsigned int data_size,
  1195. unsigned int flags);
  1196. int gnutls_x509_crq_set_key_usage(gnutls_x509_crq_t crq,
  1197. unsigned int usage);
  1198. int gnutls_x509_crq_set_basic_constraints(gnutls_x509_crq_t crq,
  1199. unsigned int ca,
  1200. int pathLenConstraint);
  1201. int gnutls_x509_crq_set_key_purpose_oid(gnutls_x509_crq_t crq,
  1202. const void *oid,
  1203. unsigned int critical);
  1204. int gnutls_x509_crq_get_key_purpose_oid(gnutls_x509_crq_t crq,
  1205. unsigned indx, void *oid,
  1206. size_t * sizeof_oid,
  1207. unsigned int *critical);
  1208. int gnutls_x509_crq_get_extension_data(gnutls_x509_crq_t crq,
  1209. unsigned indx, void *data,
  1210. size_t * sizeof_data);
  1211. int
  1212. gnutls_x509_crq_get_extension_data2(gnutls_x509_crq_t crq,
  1213. unsigned indx,
  1214. gnutls_datum_t * data);
  1215. int gnutls_x509_crq_get_extension_info(gnutls_x509_crq_t crq,
  1216. unsigned indx, void *oid,
  1217. size_t * sizeof_oid,
  1218. unsigned int *critical);
  1219. int gnutls_x509_crq_get_attribute_data(gnutls_x509_crq_t crq,
  1220. unsigned indx, void *data,
  1221. size_t * sizeof_data);
  1222. int gnutls_x509_crq_get_attribute_info(gnutls_x509_crq_t crq,
  1223. unsigned indx, void *oid,
  1224. size_t * sizeof_oid);
  1225. int gnutls_x509_crq_get_pk_algorithm(gnutls_x509_crq_t crq,
  1226. unsigned int *bits);
  1227. int gnutls_x509_crq_get_spki(gnutls_x509_crq_t crq, gnutls_x509_spki_t spki,
  1228. unsigned int flags);
  1229. int gnutls_x509_crq_set_spki(gnutls_x509_crq_t crq, const gnutls_x509_spki_t spki,
  1230. unsigned int flags);
  1231. int gnutls_x509_crq_get_signature_oid(gnutls_x509_crq_t crq, char *oid, size_t *oid_size);
  1232. int gnutls_x509_crq_get_pk_oid(gnutls_x509_crq_t crq, char *oid, size_t *oid_size);
  1233. int gnutls_x509_crq_get_key_id(gnutls_x509_crq_t crq,
  1234. unsigned int flags,
  1235. unsigned char *output_data,
  1236. size_t * output_data_size);
  1237. int gnutls_x509_crq_get_key_rsa_raw(gnutls_x509_crq_t crq,
  1238. gnutls_datum_t * m,
  1239. gnutls_datum_t * e);
  1240. int gnutls_x509_crq_get_key_usage(gnutls_x509_crq_t crq,
  1241. unsigned int *key_usage,
  1242. unsigned int *critical);
  1243. int gnutls_x509_crq_get_basic_constraints(gnutls_x509_crq_t crq,
  1244. unsigned int *critical,
  1245. unsigned int *ca, int *pathlen);
  1246. int gnutls_x509_crq_get_subject_alt_name(gnutls_x509_crq_t crq,
  1247. unsigned int seq,
  1248. void *ret,
  1249. size_t * ret_size,
  1250. unsigned int *ret_type,
  1251. unsigned int *critical);
  1252. int gnutls_x509_crq_get_subject_alt_othername_oid(gnutls_x509_crq_t
  1253. crq,
  1254. unsigned int seq,
  1255. void *ret,
  1256. size_t * ret_size);
  1257. int gnutls_x509_crq_get_extension_by_oid(gnutls_x509_crq_t crq,
  1258. const char *oid, unsigned indx,
  1259. void *buf,
  1260. size_t * sizeof_buf,
  1261. unsigned int *critical);
  1262. int gnutls_x509_crq_get_tlsfeatures(gnutls_x509_crq_t crq,
  1263. gnutls_x509_tlsfeatures_t features,
  1264. unsigned flags,
  1265. unsigned int *critical);
  1266. int gnutls_x509_crq_set_tlsfeatures(gnutls_x509_crq_t crq,
  1267. gnutls_x509_tlsfeatures_t features);
  1268. int
  1269. gnutls_x509_crt_get_extension_by_oid2(gnutls_x509_crt_t cert,
  1270. const char *oid, unsigned indx,
  1271. gnutls_datum_t *output,
  1272. unsigned int *critical);
  1273. typedef struct gnutls_x509_trust_list_st *gnutls_x509_trust_list_t;
  1274. typedef struct gnutls_x509_trust_list_iter *gnutls_x509_trust_list_iter_t;
  1275. int
  1276. gnutls_x509_trust_list_init(gnutls_x509_trust_list_t * list,
  1277. unsigned int size);
  1278. void
  1279. gnutls_x509_trust_list_deinit(gnutls_x509_trust_list_t list,
  1280. unsigned int all);
  1281. int gnutls_x509_trust_list_get_issuer(gnutls_x509_trust_list_t
  1282. list, gnutls_x509_crt_t cert,
  1283. gnutls_x509_crt_t * issuer,
  1284. unsigned int flags);
  1285. int gnutls_x509_trust_list_get_issuer_by_dn(gnutls_x509_trust_list_t list,
  1286. const gnutls_datum_t *dn,
  1287. gnutls_x509_crt_t *issuer,
  1288. unsigned int flags);
  1289. int gnutls_x509_trust_list_get_issuer_by_subject_key_id(gnutls_x509_trust_list_t list,
  1290. const gnutls_datum_t *dn,
  1291. const gnutls_datum_t *spki,
  1292. gnutls_x509_crt_t *issuer,
  1293. unsigned int flags);
  1294. /**
  1295. * gnutls_trust_list_flags_t:
  1296. * @GNUTLS_TL_VERIFY_CRL: If any CRLs are provided they will be verified for validity
  1297. * prior to be added. The CA certificates that will be used for verification are the
  1298. * ones already added in the trusted list.
  1299. * @GNUTLS_TL_USE_IN_TLS: Internal flag used by GnuTLS. If provided the trust list
  1300. * structure will cache a copy of CA DNs to be used in the certificate request
  1301. * TLS message.
  1302. * @GNUTLS_TL_NO_DUPLICATES: If this flag is specified, a function adding certificates
  1303. * will check and eliminate any duplicates.
  1304. * @GNUTLS_TL_NO_DUPLICATE_KEY: If this flag is specified, a certificate sharing the
  1305. * same key as a previously added on will not be added.
  1306. * @GNUTLS_TL_GET_COPY: The semantics of this flag are documented to the functions which
  1307. * are applicable. In general, on returned value, the function will provide a copy
  1308. * if this flag is provided, rather than a pointer to internal data.
  1309. *
  1310. * Enumeration of different certificate trust list flags.
  1311. */
  1312. typedef enum gnutls_trust_list_flags_t {
  1313. GNUTLS_TL_VERIFY_CRL = 1,
  1314. #define GNUTLS_TL_VERIFY_CRL 1
  1315. GNUTLS_TL_USE_IN_TLS = (1<<1),
  1316. #define GNUTLS_TL_USE_IN_TLS (1<<1)
  1317. GNUTLS_TL_NO_DUPLICATES = (1<<2),
  1318. #define GNUTLS_TL_NO_DUPLICATES (1<<2)
  1319. GNUTLS_TL_NO_DUPLICATE_KEY = (1<<3),
  1320. #define GNUTLS_TL_NO_DUPLICATE_KEY (1<<3)
  1321. GNUTLS_TL_GET_COPY = (1<<4)
  1322. #define GNUTLS_TL_GET_COPY (1<<4)
  1323. } gnutls_trust_list_flags_t;
  1324. int
  1325. gnutls_x509_trust_list_add_cas(gnutls_x509_trust_list_t list,
  1326. const gnutls_x509_crt_t * clist,
  1327. unsigned clist_size, unsigned int flags);
  1328. int gnutls_x509_trust_list_remove_cas(gnutls_x509_trust_list_t
  1329. list,
  1330. const gnutls_x509_crt_t *
  1331. clist, unsigned clist_size);
  1332. int gnutls_x509_trust_list_add_named_crt(gnutls_x509_trust_list_t
  1333. list,
  1334. gnutls_x509_crt_t cert,
  1335. const void *name,
  1336. size_t name_size,
  1337. unsigned int flags);
  1338. int
  1339. gnutls_x509_trust_list_add_crls(gnutls_x509_trust_list_t list,
  1340. const gnutls_x509_crl_t *
  1341. crl_list, unsigned crl_size,
  1342. unsigned int flags,
  1343. unsigned int verification_flags);
  1344. int
  1345. gnutls_x509_trust_list_iter_get_ca(gnutls_x509_trust_list_t list,
  1346. gnutls_x509_trust_list_iter_t *iter,
  1347. gnutls_x509_crt_t *crt);
  1348. void gnutls_x509_trust_list_iter_deinit(gnutls_x509_trust_list_iter_t iter);
  1349. typedef int gnutls_verify_output_function(gnutls_x509_crt_t cert, gnutls_x509_crt_t issuer, /* The issuer if verification failed
  1350. * because of him. might be null.
  1351. */
  1352. gnutls_x509_crl_t crl, /* The CRL that caused verification failure
  1353. * if any. Might be null.
  1354. */
  1355. unsigned int
  1356. verification_output);
  1357. int gnutls_x509_trust_list_verify_named_crt
  1358. (gnutls_x509_trust_list_t list, gnutls_x509_crt_t cert,
  1359. const void *name, size_t name_size, unsigned int flags,
  1360. unsigned int *verify, gnutls_verify_output_function func);
  1361. int
  1362. gnutls_x509_trust_list_verify_crt2(gnutls_x509_trust_list_t list,
  1363. gnutls_x509_crt_t * cert_list,
  1364. unsigned int cert_list_size,
  1365. gnutls_typed_vdata_st * data,
  1366. unsigned int elements,
  1367. unsigned int flags,
  1368. unsigned int *voutput,
  1369. gnutls_verify_output_function func);
  1370. int
  1371. gnutls_x509_trust_list_verify_crt(gnutls_x509_trust_list_t list,
  1372. gnutls_x509_crt_t * cert_list,
  1373. unsigned int cert_list_size,
  1374. unsigned int flags,
  1375. unsigned int *verify,
  1376. gnutls_verify_output_function func);
  1377. /* trust list convenience functions */
  1378. int
  1379. gnutls_x509_trust_list_add_trust_mem(gnutls_x509_trust_list_t
  1380. list,
  1381. const gnutls_datum_t * cas,
  1382. const gnutls_datum_t * crls,
  1383. gnutls_x509_crt_fmt_t type,
  1384. unsigned int tl_flags,
  1385. unsigned int tl_vflags);
  1386. int
  1387. gnutls_x509_trust_list_add_trust_file(gnutls_x509_trust_list_t
  1388. list, const char *ca_file,
  1389. const char *crl_file,
  1390. gnutls_x509_crt_fmt_t type,
  1391. unsigned int tl_flags,
  1392. unsigned int tl_vflags);
  1393. int
  1394. gnutls_x509_trust_list_add_trust_dir(gnutls_x509_trust_list_t list,
  1395. const char *ca_dir,
  1396. const char *crl_dir,
  1397. gnutls_x509_crt_fmt_t type,
  1398. unsigned int tl_flags,
  1399. unsigned int tl_vflags);
  1400. int
  1401. gnutls_x509_trust_list_remove_trust_file(gnutls_x509_trust_list_t
  1402. list,
  1403. const char *ca_file,
  1404. gnutls_x509_crt_fmt_t type);
  1405. int
  1406. gnutls_x509_trust_list_remove_trust_mem(gnutls_x509_trust_list_t
  1407. list,
  1408. const gnutls_datum_t *
  1409. cas, gnutls_x509_crt_fmt_t type);
  1410. int
  1411. gnutls_x509_trust_list_add_system_trust(gnutls_x509_trust_list_t
  1412. list,
  1413. unsigned int tl_flags,
  1414. unsigned int tl_vflags);
  1415. void gnutls_certificate_set_trust_list
  1416. (gnutls_certificate_credentials_t res,
  1417. gnutls_x509_trust_list_t tlist, unsigned flags);
  1418. void gnutls_certificate_get_trust_list
  1419. (gnutls_certificate_credentials_t res,
  1420. gnutls_x509_trust_list_t *tlist);
  1421. typedef struct gnutls_x509_ext_st {
  1422. char *oid;
  1423. unsigned int critical;
  1424. gnutls_datum_t data;
  1425. } gnutls_x509_ext_st;
  1426. void gnutls_x509_ext_deinit(gnutls_x509_ext_st *ext);
  1427. int
  1428. gnutls_x509_ext_print(gnutls_x509_ext_st *exts, unsigned int exts_size,
  1429. gnutls_certificate_print_formats_t format,
  1430. gnutls_datum_t * out);
  1431. #include <gnutls/pkcs7.h>
  1432. /* *INDENT-OFF* */
  1433. #ifdef __cplusplus
  1434. }
  1435. #endif
  1436. /* *INDENT-ON* */
  1437. #endif /* GNUTLS_X509_H */