mconnect - KDE Connect protocol implementation in Vala/C
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1893 lines
66 KiB

  1. /* gnutls.vapi
  2. *
  3. * Copyright (C) 2009 Jiří Zárevúcky
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2.1 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with this library; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  18. *
  19. * As a special exception, if you use inline functions from this file, this
  20. * file does not by itself cause the resulting executable to be covered by
  21. * the GNU Lesser General Public License.
  22. *
  23. * Author:
  24. * Jiří Zárevúcky <zarevucky.jiri@gmail.com>
  25. *
  26. */
  27. [CCode (cprefix = "gnutls_", lower_case_cprefix = "gnutls_", cheader_filename = "gnutls/gnutls.h")]
  28. namespace GnuTLS
  29. {
  30. [CCode (cname = "LIBGNUTLS_VERSION")]
  31. public const string VERSION;
  32. [CCode (cname = "LIBGNUTLS_VERSION_MAJOR")]
  33. public const int VERSION_MAJOR;
  34. [CCode (cname = "LIBGNUTLS_VERSION_MINOR")]
  35. public const int VERSION_MINOR;
  36. [CCode (cname = "LIBGNUTLS_VERSION_PATCH")]
  37. public const int VERSION_PATCH;
  38. [CCode (cname = "LIBGNUTLS_VERSION_NUMBER")]
  39. public const int VERSION_NUMBER;
  40. public unowned string? check_version (string? req_version);
  41. [CCode (cname = "gnutls_cipher_algorithm_t", cprefix = "GNUTLS_CIPHER_", has_type_id = false)]
  42. public enum CipherAlgorithm {
  43. UNKNOWN,
  44. NULL,
  45. ARCFOUR_128,
  46. 3DES_CBC,
  47. AES_128_CBC,
  48. AES_256_CBC,
  49. ARCFOUR_40,
  50. CAMELLIA_128_CBC,
  51. CAMELLIA_256_CBC,
  52. RC2_40_CBC,
  53. DES_CBC,
  54. RIJNDAEL_128_CBC, // == AES_128_CBC
  55. RIJNDAEL_256_CBC, // == AES_256_CBC
  56. RIJNDAEL_CBC, // == AES_128_CBC
  57. ARCFOUR; // == ARCFOUR_128
  58. [CCode (cname = "gnutls_cipher_get_key_size")]
  59. public size_t get_key_size ();
  60. [CCode (cname = "gnutls_cipher_get_name")]
  61. public unowned string? get_name ();
  62. [CCode (cname = "gnutls_mac_get_id")]
  63. public static CipherAlgorithm from_name (string name);
  64. [CCode (cname = "gnutls_cipher_list", array_length = "false", array_null_terminated = "true")]
  65. public static unowned CipherAlgorithm[] list ();
  66. }
  67. [CCode (cname = "gnutls_kx_algorithm_t", cprefix = "GNUTLS_KX_", has_type_id = false)]
  68. public enum KXAlgorithm {
  69. UNKNOWN,
  70. RSA,
  71. DHE_DSS,
  72. DHE_RSA,
  73. ANON_DH,
  74. SRP,
  75. RSA_EXPORT,
  76. SRP_RSA,
  77. SRP_DSS,
  78. PSK,
  79. DHE_PSK;
  80. [CCode (cname = "gnutls_kx_get_name")]
  81. public unowned string? get_name ();
  82. [CCode (cname = "gnutls_kx_get_id")]
  83. public static KXAlgorithm from_name (string name);
  84. [CCode (cname = "gnutls_kx_list", array_length = "false", array_null_terminated = "true")]
  85. public static unowned KXAlgorithm[] list ();
  86. }
  87. [CCode (cname = "gnutls_mac_algorithm_t", cprefix = "GNUTLS_MAC_", has_type_id = false)]
  88. public enum MacAlgorithm {
  89. UNKNOWN,
  90. NULL,
  91. MD5,
  92. SHA1,
  93. RMD160,
  94. MD2,
  95. SHA256,
  96. SHA384,
  97. SHA512;
  98. [CCode (cname = "gnutls_mac_get_key_size")]
  99. public size_t get_key_size ();
  100. [CCode (cname = "gnutls_mac_get_name")]
  101. public unowned string? get_name ();
  102. [CCode (cname = "gnutls_mac_get_id")]
  103. public static MacAlgorithm from_name (string name);
  104. [CCode (cname = "gnutls_mac_list", array_length = "false", array_null_terminated = "true")]
  105. public static unowned MacAlgorithm[] list ();
  106. }
  107. [CCode (cname = "gnutls_digest_algorithm_t", cprefix = "GNUTLS_DIG_", has_type_id = false)]
  108. public enum DigestAlgorithm {
  109. NULL,
  110. MD5,
  111. SHA1,
  112. RMD160,
  113. MD2,
  114. SHA224,
  115. SHA256,
  116. SHA384,
  117. SHA512;
  118. [CCode (cname = "gnutls_fingerprint")]
  119. public int fingerprint (/* const */ ref Datum data, void* result, ref size_t result_size);
  120. }
  121. [CCode (cname = "GNUTLS_MAX_ALGORITHM_NUM")]
  122. public const int MAX_ALGORITHM_NUM;
  123. [CCode (cname = "gnutls_pk_algorithm_t", cprefix = "GNUTLS_PK_", has_type_id = false)]
  124. public enum PKAlgorithm {
  125. UNKNOWN,
  126. RSA,
  127. DSA;
  128. [CCode (cname = "gnutls_pk_algorithm_get_name")]
  129. public unowned string? get_name ();
  130. }
  131. [CCode (cname = "gnutls_sign_algorithm_t", cprefix = "GNUTLS_SIGN_", has_type_id = false)]
  132. public enum SignAlgorithm {
  133. UNKNOWN,
  134. RSA_SHA1,
  135. DSA_SHA1,
  136. RSA_MD5,
  137. RSA_MD2,
  138. RSA_RMD160,
  139. RSA_SHA224,
  140. RSA_SHA256,
  141. RSA_SHA384,
  142. RSA_SHA512;
  143. [CCode (cname = "gnutls_sign_algorithm_get_name")]
  144. public unowned string? get_name ();
  145. }
  146. [CCode (cname = "gnutls_compression_method_t", cprefix = "GNUTLS_COMP_", has_type_id = false)]
  147. public enum CompressionMethod {
  148. UNKNOWN,
  149. NULL,
  150. DEFLATE,
  151. ZLIB, // == DEFLATE
  152. LZO; // only available if gnutls-extra has been initialized
  153. [CCode (cname = "gnutls_compression_get_name")]
  154. public unowned string? get_name ();
  155. [CCode (cname = "gnutls_compression_get_id")]
  156. public static CompressionMethod from_name (string name);
  157. [CCode (cname = "gnutls_compression_list", array_length = "false", array_null_terminated = "true")]
  158. public static unowned CompressionMethod[] list ();
  159. }
  160. [CCode (cname = "gnutls_params_type_t", cprefix = "GNUTLS_PARAMS_", has_type_id = false)]
  161. public enum ParamsType {
  162. RSA_EXPORT,
  163. DH
  164. }
  165. [CCode (cname = "gnutls_credentials_type_t", cprefix = "GNUTLS_CRD_", has_type_id = false)]
  166. public enum CredentialsType {
  167. CERTIFICATE,
  168. ANON,
  169. SRP,
  170. PSK,
  171. IA
  172. }
  173. [CCode (cname = "gnutls_alert_level_t", cprefix = "GNUTLS_AL_", has_type_id = false)]
  174. public enum AlertLevel {
  175. WARNING,
  176. FATAL
  177. }
  178. [CCode (cname = "gnutls_alert_description_t", cprefix = "GNUTLS_A_", has_type_id = false)]
  179. public enum AlertDescription {
  180. CLOSE_NOTIFY,
  181. UNEXPECTED_MESSAGE,
  182. BAD_RECORD_MAC,
  183. DECRYPTION_FAILED,
  184. RECORD_OVERFLOW,
  185. DECOMPRESSION_FAILURE,
  186. HANDSHAKE_FAILURE,
  187. SSL3_NO_CERTIFICATE,
  188. BAD_CERTIFICATE,
  189. UNSUPPORTED_CERTIFICATE,
  190. CERTIFICATE_REVOKED,
  191. CERTIFICATE_EXPIRED,
  192. CERTIFICATE_UNKNOWN,
  193. ILLEGAL_PARAMETER,
  194. UNKNOWN_CA,
  195. ACCESS_DENIED,
  196. DECODE_ERROR,
  197. DECRYPT_ERROR,
  198. EXPORT_RESTRICTION,
  199. PROTOCOL_VERSION,
  200. INSUFFICIENT_SECURITY,
  201. INTERNAL_ERROR,
  202. USER_CANCELED,
  203. NO_RENEGOTIATION,
  204. UNSUPPORTED_EXTENSION,
  205. CERTIFICATE_UNOBTAINABLE,
  206. UNRECOGNIZED_NAME,
  207. UNKNOWN_PSK_IDENTITY,
  208. INNER_APPLICATION_FAILURE,
  209. INNER_APPLICATION_VERIFICATION;
  210. [CCode (cname = "gnutls_alert_get_name")]
  211. public unowned string? get_name ();
  212. }
  213. [CCode (cname = "gnutls_handshake_description_t", cprefix = "GNUTLS_HANDSHAKE_", has_type_id = false)]
  214. public enum HandshakeDescription {
  215. HELLO_REQUEST,
  216. CLIENT_HELLO,
  217. SERVER_HELLO,
  218. CERTIFICATE_PKT,
  219. SERVER_KEY_EXCHANGE,
  220. CERTIFICATE_REQUEST,
  221. SERVER_HELLO_DONE,
  222. CERTIFICATE_VERIFY,
  223. CLIENT_KEY_EXCHANGE,
  224. FINISHED,
  225. SUPPLEMENTAL
  226. }
  227. /* Note that the status bits have different meanings
  228. * in openpgp keys and x.509 certificate verification.
  229. */
  230. [Flags]
  231. [CCode (cname = "gnutls_certificate_status_t", cprefix = "GNUTLS_CERT_", has_type_id = false)]
  232. public enum CertificateStatus {
  233. INVALID, // will be set if the certificate was not verified.
  234. REVOKED, // in X.509 this will be set only if CRLs are checked
  235. SIGNER_NOT_FOUND,
  236. SIGNER_NOT_CA,
  237. INSECURE_ALGORITHM
  238. }
  239. [CCode (cname = "gnutls_certificate_request_t", cprefix = "GNUTLS_CERT_", has_type_id = false)]
  240. public enum CertificateRequest {
  241. IGNORE,
  242. REQUEST,
  243. REQUIRE
  244. }
  245. // [CCode (cname = "gnutls_openpgp_crt_status_t", cprefix = "GNUTLS_OPENPGP_", has_type_id = false)]
  246. // public enum OpenPGP.CertificateStatus {
  247. // CERT,
  248. // CERT_FINGERPRINT
  249. // }
  250. //
  251. // [CCode (cname = "gnutls_connection_end_t", cprefix = "GNUTLS_", has_type_id = false)]
  252. // public enum ConnectionEnd {
  253. // SERVER,
  254. // CLIENT
  255. // }
  256. [CCode (cname = "gnutls_close_request_t", cprefix = "GNUTLS_SHUT_", has_type_id = false)]
  257. public enum CloseRequest {
  258. RDWR,
  259. WR
  260. }
  261. [CCode (cname = "gnutls_protocol_t", cprefix = "GNUTLS_", has_type_id = false)]
  262. public enum Protocol {
  263. SSL3,
  264. TLS1, // == TLS1_0
  265. TLS1_0,
  266. TLS1_1,
  267. TLS1_2,
  268. [CCode (cname = "GNUTLS_VERSION_UNKNOWN")]
  269. UNKNOWN;
  270. [CCode (cname = "gnutls_protocol_get_name")]
  271. public unowned string? get_name ();
  272. [CCode (cname = "gnutls_protocol_get_id")]
  273. public static Protocol from_name (string name);
  274. [CCode (cname = "gnutls_protocol_list", array_length = "false", array_null_terminated = "true")]
  275. public static unowned Protocol[] list ();
  276. }
  277. [CCode (cname = "gnutls_certificate_type_t", cprefix = "GNUTLS_CRT_", has_type_id = false)]
  278. public enum CertificateType {
  279. UNKNOWN,
  280. X509,
  281. OPENPGP;
  282. [CCode (cname = "gnutls_certificate_type_get_name")]
  283. public unowned string? get_name ();
  284. [CCode (cname = "gnutls_certificate_type_get_id")]
  285. public static CertificateType from_name (string name);
  286. [CCode (cname = "gnutls_certificate_type_list", array_length = "false", array_null_terminated = "true")]
  287. public static unowned CertificateType[] list ();
  288. }
  289. [CCode (cname = "gnutls_certificate_print_formats_t", cprefix = "GNUTLS_CRT_PRINT_", has_type_id = false)]
  290. public enum CertificatePrintFormats {
  291. FULL,
  292. ONELINE,
  293. UNSIGNED_FULL
  294. }
  295. [Flags]
  296. [CCode (cname = "unsigned int", cprefix = "GNUTLS_KEY_", has_type_id = false)]
  297. public enum KeyUsage
  298. {
  299. DIGITAL_SIGNATURE,
  300. NON_REPUDIATION,
  301. KEY_ENCIPHERMENT,
  302. DATA_ENCIPHERMENT,
  303. KEY_AGREEMENT,
  304. KEY_CERT_SIGN,
  305. CRL_SIGN,
  306. ENCIPHER_ONLY,
  307. DECIPHER_ONLY
  308. }
  309. [CCode (cname = "gnutls_server_name_type_t", cprefix = "GNUTLS_NAME_", has_type_id = false)]
  310. public enum ServerNameType {
  311. DNS;
  312. }
  313. // Diffie Hellman parameter handling.
  314. [Compact]
  315. [CCode (cname = "struct gnutls_dh_params_int", free_function = "gnutls_dh_params_deinit", lower_case_cprefix = "gnutls_dh_params_")]
  316. public class DHParams {
  317. private static int init (out DHParams dh_params);
  318. public static DHParams create ()
  319. {
  320. DHParams result;
  321. var ret = init (out result);
  322. if (ret != 0)
  323. GLib.error ("%s", ((ErrorCode)ret).to_string ());
  324. return result;
  325. }
  326. private int cpy (DHParams source);
  327. public int import_raw (/* const */ ref Datum prime, /* const */ ref Datum generator);
  328. public int export_raw (/* const */ ref Datum prime, /* const */ ref Datum generator, out uint bits);
  329. public int import_pkcs3 (/* const */ ref Datum pkcs3_params, X509.CertificateFormat format);
  330. public int export_pkcs3 (X509.CertificateFormat format, void* params_data, ref size_t params_data_size);
  331. [CCode (cname = "gnutls_dh_params_generate2")]
  332. public int generate (uint bits);
  333. }
  334. [Compact]
  335. [CCode (cname = "struct gnutls_x509_privkey_int", free_function = "gnutls_rsa_params_deinit", lower_case_cprefix = "gnutls_rsa_params_")]
  336. public class RSAParams {
  337. private static int init (out RSAParams dh_params);
  338. public static RSAParams create ()
  339. {
  340. RSAParams result = null;
  341. var ret = init (out result);
  342. if (ret != 0)
  343. GLib.error ("%s", ((ErrorCode)ret).to_string ());
  344. return result;
  345. }
  346. private int cpy (RSAParams source);
  347. public int import_raw (/* const */ ref Datum m, /* const */ ref Datum e, /* const */ ref Datum d, /* const */ ref Datum p, /* const */ ref Datum q, /* const */ ref Datum u);
  348. public int export_raw (/* const */ ref Datum m, /* const */ ref Datum e, /* const */ ref Datum d, /* const */ ref Datum p, /* const */ ref Datum q, /* const */ ref Datum u, out uint bits);
  349. public int import_pkcs1 (/* const */ ref Datum pkcs1_params, X509.CertificateFormat format);
  350. public int export_pkcs1 (X509.CertificateFormat format, void* params_data, ref size_t params_data_size);
  351. public int generate2 (uint bits);
  352. }
  353. [Compact]
  354. [CCode (cname = "struct gnutls_priority_st", free_function = "gnutls_priority_deinit")]
  355. public class Priority {
  356. private static int init (out Priority self, string priority, out char* err_pos);
  357. public static Priority create (string priority, out ErrorCode err = null, out char* err_pos = null)
  358. {
  359. Priority result;
  360. var ret = init (out result, priority, out err_pos);
  361. if (&err != null)
  362. err = (ErrorCode) ret;
  363. return result;
  364. }
  365. }
  366. [SimpleType]
  367. [CCode (cname = "gnutls_datum_t", has_type_id = false)]
  368. public struct Datum {
  369. public void* data;
  370. public uint size;
  371. }
  372. [CCode (cname = "gnutls_params_st", has_type_id = false)]
  373. public struct Params {
  374. public ParamsType type;
  375. [CCode (cname = "params.dh")]
  376. public DHParams dh_params;
  377. [CCode (cname = "params.rsa_export")]
  378. public RSAParams rsa_params;
  379. public bool deinit;
  380. }
  381. [CCode (cname = "gnutls_params_function *", has_target = false)]
  382. public delegate int ParamsFunction (Session session, ParamsType type, Params params);
  383. [CCode (cname = "gnutls_oprfi_callback_func", instance_pos = "1.2")]
  384. public delegate int OprfiCallbackFunc (Session session,
  385. [CCode (array_length_pos = "1.8", array_length_type = "size_t")] /* const */ uint8[] in_oprfi,
  386. [CCode (array_length_pos = "1.8", array_length_type = "size_t")] uint8[] out_oprfi);
  387. /* Supplemental data, RFC 4680. */
  388. [CCode (cname = "gnutls_supplemental_data_format_type_t", has_type_id = false)]
  389. public enum SupplementalDataFormatType {
  390. USER_MAPPING_DATA;
  391. [CCode (cname = "gnutls_supplemental_get_name")]
  392. public unowned string? get_name ();
  393. }
  394. [CCode (cname = "TLS_MASTER_SIZE")]
  395. public const int TLS_MASTER_SIZE;
  396. [CCode (cname = "TLS_RANDOM_SIZE")]
  397. public const int TLS_RANDOM_SIZE;
  398. [CCode (cname = "gnutls_db_store_func", has_target = false)]
  399. public delegate int DBStoreFunc (void* ptr, Datum key, Datum data);
  400. [CCode (cname = "gnutls_db_remove_func", has_target = false)]
  401. public delegate int DBRemoveFunc (void* ptr, Datum key);
  402. [CCode (cname = "gnutls_db_retr_func", has_target = false)]
  403. public delegate Datum DBRetrieveFunc (void* ptr, Datum key);
  404. [CCode (cname = "gnutls_handshake_post_client_hello_func", has_target = false)]
  405. public delegate int HandshakePostClientHelloFunc (Session session);
  406. // External signing callback. Experimental.
  407. [CCode (cname = "gnutls_sign_func", instance_pos = "1.9")]
  408. public delegate int SignFunc (Session session, CertificateType cert_type, /* const */ ref Datum cert, /* const */ ref Datum hash, out Datum signature);
  409. [CCode (cname = "gnutls_pull_func", has_target = false)]
  410. public delegate ssize_t PullFunc (void* transport_ptr, void* buffer, size_t count);
  411. [CCode (cname = "gnutls_push_func", has_target = false)]
  412. public delegate ssize_t PushFunc (void* transport_ptr, void* buffer, size_t count);
  413. [Compact]
  414. [CCode (cname = "struct gnutls_session_int", free_function = "gnutls_deinit")]
  415. public class Session {
  416. [CCode (cname = "gnutls_init")]
  417. private static int init (out Session session, int con_end);
  418. protected static Session? create (int con_end)
  419. {
  420. Session result;
  421. var ret = init (out result, con_end);
  422. if (ret != 0)
  423. GLib.error ("%s", ((ErrorCode)ret).to_string ());
  424. return result;
  425. }
  426. [CCode (cname = "gnutls_credentials_set")]
  427. public int set_credentials (CredentialsType type, void* cred);
  428. [CCode (cname = "gnutls_credentials_clear")]
  429. public void clear_credentials ();
  430. [CCode (cname = "gnutls_handshake")]
  431. public int handshake ();
  432. [CCode (cname = "gnutls_bye")]
  433. public int bye (CloseRequest how);
  434. [CCode (cname = "gnutls_session_is_resumed")]
  435. public bool is_resumed ();
  436. [CCode (cname = "gnutls_alert_get")]
  437. public AlertDescription get_last_alert ();
  438. [CCode (cname = "gnutls_alert_send")]
  439. public int send_alert (AlertLevel level, AlertDescription desc);
  440. [CCode (cname = "gnutls_alert_send_appropriate")]
  441. public int send_appropriate_alert (ErrorCode err);
  442. [CCode (cname = "gnutls_cipher_get")]
  443. public CipherAlgorithm get_cipher ();
  444. [CCode (cname = "gnutls_kx_get")]
  445. public KXAlgorithm get_kx ();
  446. [CCode (cname = "gnutls_mac_get")]
  447. public MacAlgorithm get_mac ();
  448. [CCode (cname = "gnutls_compression_get")]
  449. public CompressionMethod get_compression ();
  450. [CCode (cname = "gnutls_certificate_type_get")]
  451. public CertificateType get_certificate_type ();
  452. [CCode (cname = "gnutls_protocol_get_version")]
  453. public Protocol get_protocol_version ();
  454. [CCode (cname = "gnutls_record_get_max_size")]
  455. public size_t get_max_record_size ();
  456. [CCode (cname = "gnutls_dh_get_prime_bits")]
  457. public int get_dh_prime_bits ();
  458. [CCode (cname = "gnutls_dh_get_secret_bits")]
  459. public int get_dh_secret_bits ();
  460. [CCode (cname = "gnutls_dh_get_peers_public_bits")]
  461. public int get_peers_dh_public_bits ();
  462. [CCode (cname = "gnutls_dh_get_group")]
  463. public int get_dh_group (out Datum raw_gen, out Datum raw_prime);
  464. [CCode (cname = "gnutls_dh_get_pubkey")]
  465. public int get_dh_pubkey (out Datum raw_key);
  466. [CCode (cname = "gnutls_rsa_export_get_pubkey")]
  467. public int get_rsa_export_pubkey (out Datum exponent, out Datum modulus);
  468. [CCode (cname = "gnutls_rsa_export_get_modulus_bits")]
  469. public int get_rsa_export_modulus_bits ();
  470. [CCode (cname = "gnutls_handshake_set_private_extensions")]
  471. public void allow_private_extensions (bool allow);
  472. [CCode (cname = "gnutls_handshake_get_last_out")]
  473. public HandshakeDescription get_last_out_handshake ();
  474. [CCode (cname = "gnutls_handshake_get_last_in")]
  475. public HandshakeDescription get_last_in_handshake ();
  476. [CCode (cname = "gnutls_record_send")]
  477. public ssize_t send (void* buffer, size_t count);
  478. [CCode (cname = "gnutls_record_recv")]
  479. public ssize_t receive (void* buffer, size_t count);
  480. [CCode (cname = "gnutls_record_get_direction")]
  481. public int get_last_direction ();
  482. [CCode (cname = "gnutls_record_check_pending")]
  483. public size_t check_pending ();
  484. [CCode (cname = "gnutls_cipher_set_priority")]
  485. public int set_cipher_priority ([CCode (array_length = "false", array_null_terminated = "true")] CipherAlgorithm[] list);
  486. [CCode (cname = "gnutls_mac_set_priority")]
  487. public int set_mac_priority ([CCode (array_length = "false", array_null_terminated = "true")] MacAlgorithm[] list);
  488. [CCode (cname = "gnutls_compression_set_priority")]
  489. public int set_compression_priority ([CCode (array_length = "false", array_null_terminated = "true")] CompressionMethod[] list);
  490. [CCode (cname = "gnutls_kx_set_priority")]
  491. public int set_kx_priority ([CCode (array_length = "false", array_null_terminated = "true")] KXAlgorithm[] list);
  492. [CCode (cname = "gnutls_protocol_set_priority")]
  493. public int set_protocol_priority ([CCode (array_length = "false", array_null_terminated = "true")] Protocol[] list);
  494. [CCode (cname = "gnutls_certificate_type_set_priority")]
  495. public int set_certificate_type_priority ([CCode (array_length = "false", array_null_terminated = "true")] CertificateType[] list);
  496. [CCode (cname = "gnutls_priority_set")]
  497. public int set_priority (Priority priority);
  498. [CCode (cname = "gnutls_priority_set_direct")]
  499. public int set_priority_from_string (string priority, out unowned string err_pos = null);
  500. [CCode (cname = "gnutls_set_default_priority")]
  501. public int set_default_priority ();
  502. [CCode (cname = "gnutls_set_default_export_priority")]
  503. public int set_default_export_priority ();
  504. [CCode (cname = "GNUTLS_MAX_SESSION_ID")]
  505. public const int MAX_SESSION_ID;
  506. [CCode (cname = "gnutls_session_get_id")]
  507. public int get_id (void* session_id, ref size_t session_id_size);
  508. [CCode (cname = "gnutls_session_get_server_random")]
  509. public void* get_server_random ();
  510. [CCode (cname = "gnutls_session_get_client_random")]
  511. public void* get_client_random ();
  512. [CCode (cname = "gnutls_session_get_master_secret")]
  513. public void* get_master_secret ();
  514. [CCode (cname = "gnutls_transport_set_ptr")]
  515. public void set_transport_ptr (void* ptr);
  516. [CCode (cname = "gnutls_transport_set_ptr2")]
  517. public void set_transport_ptr2 (void* recv_ptr, void* send_ptr);
  518. [CCode (cname = "gnutls_transport_set_lowat")]
  519. public void set_lowat (int num);
  520. [CCode (cname = "gnutls_transport_set_push_function")]
  521. public void set_push_function (PushFunc func);
  522. [CCode (cname = "gnutls_transport_set_pull_function")]
  523. public void set_pull_function (PullFunc func);
  524. [CCode (cname = "gnutls_transport_set_errno")]
  525. public void set_errno (int err);
  526. [CCode (cname = "gnutls_session_set_ptr")]
  527. public void set_ptr (void* ptr);
  528. [CCode (cname = "gnutls_session_get_ptr")]
  529. public void* get_ptr ();
  530. [CCode (cname = "gnutls_auth_get_type")]
  531. public CredentialsType get_auth_type ();
  532. // [CCode (cname = "gnutls_auth_server_get_type")]
  533. // public CredentialsType get_server_auth_type ();
  534. // [CCode (cname = "gnutls_auth_client_get_type")]
  535. // public CredentialsType get_client_auth_type ();
  536. [CCode (cname = "gnutls_sign_callback_set")]
  537. public void set_sign_callback (SignFunc func);
  538. [CCode (cname = "gnutls_sign_callback_get")]
  539. public SignFunc get_sign_callback ();
  540. [CCode (cname = "gnutls_certificate_get_peers", array_length_type = "unsigned int")]
  541. public unowned Datum[]? get_peer_certificates ();
  542. [CCode (cname = "gnutls_certificate_get_ours")]
  543. public unowned Datum? get_our_certificate ();
  544. [CCode (cname = "gnutls_certificate_verify_peers2")]
  545. public int verify_peer_certificate (out CertificateStatus status);
  546. }
  547. [CCode (cname = "struct gnutls_session_int", lower_case_cprefix = "gnutls_", free_function = "gnutls_deinit")]
  548. public class ClientSession: Session {
  549. public static ClientSession create ()
  550. {
  551. return (ClientSession) Session.create (2);
  552. }
  553. [CCode (cname = "gnutls_record_set_max_size")]
  554. public ssize_t set_max_record_size (size_t size);
  555. [CCode (cname = "gnutls_dh_set_prime_bits")]
  556. public void set_dh_prime_bits (uint bits);
  557. [CCode (cname = "gnutls_server_name_get")]
  558. public int get_server_name (void* data, out size_t data_length, out ServerNameType type, uint index);
  559. [CCode (cname = "gnutls_oprfi_enable_client")]
  560. public void enable_oprfi ([CCode (array_length_pos = "0.9", array_length_type = "size_t")] uint8[] data);
  561. [CCode (cname = "gnutls_session_set_data")]
  562. public int set_session_data (void* session_data, size_t session_data_size);
  563. [CCode (cname = "gnutls_session_get_data")]
  564. public int get_session_data (void* session_data, out size_t session_data_size);
  565. [CCode (cname = "gnutls_session_get_data2")]
  566. public int get_session_data2 (out Datum data);
  567. [CCode (cname = "gnutls_openpgp_send_cert")]
  568. public void set_openpgp_send_cert (bool fingerprint_only);
  569. [CCode (cname = "gnutls_psk_client_get_hint")]
  570. public unowned string get_psk_hint ();
  571. [CCode (cname = "gnutls_certificate_client_get_request_status")]
  572. public int get_certificate_request_status ();
  573. }
  574. [CCode (cname = "struct gnutls_session_int", lower_case_cprefix = "gnutls_", free_function = "gnutls_deinit")]
  575. public class ServerSession: Session {
  576. public static ServerSession create ()
  577. {
  578. return (ServerSession) Session.create (1);
  579. }
  580. public int rehandshake ();
  581. [CCode (cname = "gnutls_session_enable_compatibility_mode")]
  582. public void enable_compatibility_mode ();
  583. [CCode (cname = "gnutls_record_disable_padding")]
  584. public void disable_record_padding ();
  585. [CCode (cname = "gnutls_server_name_set")]
  586. public int set_server_name (ServerNameType type, void* data, size_t data_length);
  587. [CCode (cname = "gnutls_oprfi_enable_server")]
  588. public void enable_oprfi (OprfiCallbackFunc cb);
  589. public void db_set_cache_expiration (int seconds);
  590. public void db_remove_session ();
  591. public void db_set_retrieve_function (DBRetrieveFunc func);
  592. public void db_set_remove_function (DBRemoveFunc func);
  593. public void db_set_store_function (DBStoreFunc func);
  594. public void db_set_ptr (void* ptr);
  595. public void* db_get_ptr ();
  596. public int db_check_entry (Datum session_entry);
  597. [CCode (cname = "gnutls_handshake_set_post_client_hello_function")]
  598. public void set_post_client_hello_function (HandshakePostClientHelloFunc func);
  599. [CCode (cname = "gnutls_handshake_set_max_packet_length")]
  600. public void set_max_handshake_packet_length (size_t max);
  601. [CCode (cname = "gnutls_certificate_server_set_request")]
  602. public void set_certificate_request (CertificateRequest req);
  603. [CCode (cname = "gnutls_certificate_send_x509_rdn_sequence")]
  604. public void disable_sending_x509_rdn_sequence (bool disable);
  605. [CCode (cname = "gnutls_psk_server_get_username")]
  606. public unowned string get_psk_username ();
  607. [CCode (cheader_filename = "gnutls/openpgp.h", cname = "gnutls_openpgp_set_recv_key_function")]
  608. public void set_openpgp_recv_key_function (OpenPGP.RecvKeyFunc func);
  609. }
  610. [Compact]
  611. [CCode (cname = "struct gnutls_anon_server_credentials_st", free_function = "gnutls_anon_free_server_credentials")]
  612. public class AnonServerCredentials
  613. {
  614. [CCode (cname = "gnutls_anon_allocate_server_credentials")]
  615. private static int allocate (out AnonServerCredentials credentials);
  616. public static AnonServerCredentials create ()
  617. {
  618. AnonServerCredentials result;
  619. var ret = allocate (out result);
  620. if (ret != 0)
  621. GLib.error ("%s", ((ErrorCode)ret).to_string ());
  622. return result;
  623. }
  624. [CCode (cname = "gnutls_anon_set_server_dh_params")]
  625. public void set_dh_params (DHParams dh_params);
  626. // [CCode (cname = "gnutls_anon_set_server_params_function")]
  627. // public void set_server_params_function (ParamsFunction func);
  628. [CCode (cname = "gnutls_anon_set_params_function")]
  629. public void set_params_function (ParamsFunction func);
  630. }
  631. [Compact]
  632. [CCode (cname = "struct gnutls_anon_client_credentials_st", free_function = "gnutls_anon_free_client_credentials")]
  633. public class AnonClientCredentials
  634. {
  635. [CCode (cname = "gnutls_anon_allocate_client_credentials")]
  636. private static int allocate (out AnonClientCredentials credentials);
  637. public static AnonClientCredentials create ()
  638. {
  639. AnonClientCredentials result;
  640. var ret = allocate (out result);
  641. if (ret != 0)
  642. GLib.error ("%s", ((ErrorCode)ret).to_string ());
  643. return result;
  644. }
  645. }
  646. [CCode (cheader_filename = "gnutls/x509.h", cprefix = "GNUTLS_OID_")]
  647. namespace OID
  648. {
  649. // Some OIDs usually found in Distinguished names, or
  650. // in Subject Directory Attribute extensions.
  651. public const string X520_COUNTRY_NAME;
  652. public const string X520_ORGANIZATION_NAME;
  653. public const string X520_ORGANIZATIONAL_UNIT_NAME;
  654. public const string X520_COMMON_NAME;
  655. public const string X520_LOCALITY_NAME;
  656. public const string X520_STATE_OR_PROVINCE_NAME;
  657. public const string X520_INITIALS;
  658. public const string X520_GENERATION_QUALIFIER;
  659. public const string X520_SURNAME;
  660. public const string X520_GIVEN_NAME;
  661. public const string X520_TITLE;
  662. public const string X520_DN_QUALIFIER;
  663. public const string X520_PSEUDONYM;
  664. public const string LDAP_DC;
  665. public const string LDAP_UID;
  666. // The following should not be included in DN.
  667. public const string PKCS9_EMAIL;
  668. public const string PKIX_DATE_OF_BIRTH;
  669. public const string PKIX_PLACE_OF_BIRTH;
  670. public const string PKIX_GENDER;
  671. public const string PKIX_COUNTRY_OF_CITIZENSHIP;
  672. public const string PKIX_COUNTRY_OF_RESIDENCE;
  673. }
  674. [CCode (cheader_filename = "gnutls/x509.h", cprefix = "GNUTLS_")]
  675. namespace X509
  676. {
  677. // Key purpose Object Identifiers.
  678. public const string KP_TLS_WWW_SERVER;
  679. public const string KP_TLS_WWW_CLIENT;
  680. public const string KP_CODE_SIGNING;
  681. public const string KP_EMAIL_PROTECTION;
  682. public const string KP_TIME_STAMPING;
  683. public const string KP_OCSP_SIGNING;
  684. public const string KP_ANY;
  685. [CCode (cname = "gnutls_x509_crt_fmt_t", cprefix = "GNUTLS_X509_FMT_", has_type_id = false)]
  686. public enum CertificateFormat {
  687. DER,
  688. PEM
  689. }
  690. [Flags]
  691. [CCode (cname = "gnutls_certificate_import_flags", cprefix = "GNUTLS_X509_CRT_", has_type_id = false)]
  692. public enum CertificateImportFlags {
  693. /* Fail if the certificates in the buffer are more than the space
  694. * allocated for certificates. The error code will be
  695. * GNUTLS_E_SHORT_MEMORY_BUFFER.
  696. */
  697. LIST_IMPORT_FAIL_IF_EXCEED // == 1
  698. }
  699. [Flags]
  700. [CCode (cname = "unsigned int", cprefix = "GNUTLS_CRL_REASON_", has_type_id = false)]
  701. public enum RevocationReasons {
  702. UNUSED,
  703. KEY_COMPROMISE,
  704. CA_COMPROMISE,
  705. AFFILIATION_CHANGED,
  706. SUPERSEEDED,
  707. CESSATION_OF_OPERATION,
  708. CERTIFICATE_HOLD,
  709. PRIVILEGE_WITHDRAWN,
  710. AA_COMPROMISE
  711. }
  712. [Flags]
  713. [CCode (cname = "gnutls_certificate_verify_flags", cprefix = "GNUTLS_VERIFY_", has_type_id = false)]
  714. public enum CertificateVerifyFlags
  715. {
  716. // If set a signer does not have to be a certificate authority. This
  717. // flag should normaly be disabled, unless you know what this means.
  718. DISABLE_CA_SIGN,
  719. // Allow only trusted CA certificates that have version 1. This is
  720. // safer than GNUTLS_VERIFY_ALLOW_ANY_X509_V1_CA_CRT, and should be
  721. // used instead. That way only signers in your trusted list will be
  722. // allowed to have certificates of version 1.
  723. ALLOW_X509_V1_CA_CRT,
  724. // If a certificate is not signed by anyone trusted but exists in
  725. // the trusted CA list do not treat it as trusted.
  726. DO_NOT_ALLOW_SAME,
  727. // Allow CA certificates that have version 1 (both root and
  728. // intermediate). This might be dangerous since those haven't the
  729. // basicConstraints extension. Must be used in combination with
  730. // GNUTLS_VERIFY_ALLOW_X509_V1_CA_CRT.
  731. ALLOW_ANY_X509_V1_CA_CRT,
  732. // Allow certificates to be signed using the broken MD2 algorithm.
  733. ALLOW_SIGN_RSA_MD2,
  734. // Allow certificates to be signed using the broken MD5 algorithm.
  735. ALLOW_SIGN_RSA_MD5
  736. }
  737. [CCode (cname = "gnutls_x509_subject_alt_name_t", has_type_id = false)]
  738. public enum SubjectAltName {
  739. DNSNAME,
  740. RFC822NAME,
  741. URI,
  742. IPADDRESS,
  743. OTHERNAME,
  744. DN,
  745. OTHERNAME_XMPP
  746. }
  747. [Compact]
  748. [CCode (cname = "void", cprefix = "gnutls_x509_dn_", free_function = "gnutls_x509_dn_deinit")]
  749. public class DN
  750. {
  751. private static int init (out DN dn);
  752. public static DN create ()
  753. {
  754. DN result;
  755. var ret = init (out result);
  756. if (ret != 0)
  757. GLib.error ("%s", ((ErrorCode)ret).to_string ());
  758. return result;
  759. }
  760. public int get_rdn_ava (int irdn, int iava, out unowned Ava ava);
  761. public int import (ref Datum data);
  762. public int export (CertificateFormat format, void* output, ref size_t output_size);
  763. }
  764. // RDN handling.
  765. public int rdn_get (ref Datum idn, char* buf, ref size_t buf_size);
  766. public int rdn_get_oid (ref Datum idn, int index, void* buf, ref size_t buf_size);
  767. public int rdn_get_by_oid (ref Datum idn, string oid, int index, uint raw_flag, void* buf, ref size_t buf_size);
  768. [SimpleType]
  769. [CCode (cname = "gnutls_x509_ava_st", has_type_id = false)]
  770. public struct Ava
  771. {
  772. [CCode (cname = "oid.data", array_length_cname = "oid.size")]
  773. uint8[] oid;
  774. [CCode (cname = "value.data", array_length_cname = "value.size")]
  775. uint8[] value;
  776. ulong value_tag;
  777. }
  778. [Compact]
  779. [CCode (cname = "struct gnutls_x509_crt_int", cprefix = "gnutls_x509_crt_", free_function = "gnutls_x509_crt_deinit")]
  780. public class Certificate
  781. {
  782. private static int init (out Certificate cert);
  783. public static Certificate create ()
  784. {
  785. Certificate result;
  786. var ret = init (out result);
  787. if (ret != 0)
  788. GLib.error ("%s", ((ErrorCode)ret).to_string ());
  789. return result;
  790. }
  791. public int import (ref Datum data, CertificateFormat format);
  792. public int export (CertificateFormat format, void* output, ref size_t output_size);
  793. public static int list_import ([CCode (array_length = "false")] Certificate[]? certs,
  794. ref uint cert_max, ref Datum data,
  795. CertificateFormat format, bool fail_if_exceed);
  796. public int get_issuer_dn (char* buf, ref size_t buf_size);
  797. public int get_issuer_dn_oid (int index, void* oid, ref size_t oid_size);
  798. public int get_issuer_dn_by_oid (string oid, int index, uint raw_flag, void* buf, ref size_t buf_size);
  799. public int get_dn (char* buf, ref size_t buf_size);
  800. public int get_dn_oid (int index, void* oid, ref size_t oid_size);
  801. public int get_dn_by_oid (string oid, int index, uint raw_flag, void* buf, ref size_t buf_size);
  802. public int get_subject (out DN dn);
  803. public int get_issuer (out DN dn);
  804. public bool check_hostname (string hostname);
  805. public SignAlgorithm get_signature_algorithm ();
  806. public int get_signature (char* sig, ref size_t sig_size);
  807. public int get_version ();
  808. public int get_key_id (uint flags, uchar* output, ref size_t output_size);
  809. public int set_authority_key_id (void* id, size_t id_size);
  810. public int get_authority_key_id (void* ret, ref size_t ret_size, out bool critical);
  811. public int get_subject_key_id (void* ret, ref size_t ret_size, out bool critical);
  812. public int get_crl_dist_points (uint seq, void* ret, ref size_t ret_size, out RevocationReasons reason_flags, out bool critical);
  813. public int set_crl_dist_points (SubjectAltName type, void* data_string, RevocationReasons reason_flags);
  814. public int cpy_crl_dist_points (Certificate source);
  815. public time_t get_activation_time ();
  816. public time_t get_expiration_time ();
  817. public int get_serial (void* result, ref size_t result_size);
  818. public PKAlgorithm get_pk_algorithm (out uint bits);
  819. public int get_pk_rsa_raw (out Datum modulus, out Datum exponent);
  820. public int get_pk_dsa_raw (out Datum p, out Datum q, out Datum g, out Datum y);
  821. public int get_subject_alt_name (uint seq, void* ret, ref size_t ret_size, out bool critical);
  822. public int get_subject_alt_name2 (uint seq, void* ret, ref size_t ret_size, out SubjectAltName ret_type, out bool critical);
  823. public int get_subject_alt_othername_oid (uint seq, void* ret, ref size_t ret_size);
  824. public int get_ca_status (out bool critical);
  825. public int get_basic_constraints (out bool critical, out int ca, out int pathlen);
  826. public int get_key_usage (out KeyUsage key_usage, out bool critical);
  827. public int set_key_usage (KeyUsage usage);
  828. public int get_proxy (out bool critical, out int pathlen, [CCode (array_length = "false")] out char[] policyLanguage, out char[] policy);
  829. public bool dn_oid_known (string oid);
  830. public int get_extension_oid (int index, void* oid, ref size_t oid_size);
  831. public int get_extension_by_oid (string oid, int index, void* buf, ref size_t buf_size, out bool critical);
  832. public int get_extension_info (int index, void* oid, ref size_t oid_size, out bool critical);
  833. public int get_extension_data (int index, void* data, ref size_t data_size);
  834. public int set_extension_by_oid (string oid, void* buf, size_t buf_size, bool critical);
  835. public int set_dn_by_oid (string oid, uint raw_flag, void* name, uint name_size);
  836. public int set_issuer_dn_by_oid (string oid, uint raw_flag, void* name, uint name_size);
  837. public int set_version (uint version);
  838. public int set_key (PrivateKey key);
  839. public int set_ca_status (uint ca);
  840. public int set_basic_constraints (uint ca, int pathLenConstraint);
  841. public int set_subject_alternative_name (SubjectAltName type, string data_string);
  842. public int sign (Certificate issuer, PrivateKey issuer_key);
  843. public int sign2 (Certificate issuer, PrivateKey issuer_key, DigestAlgorithm alg, uint flags);
  844. public int set_activation_time (time_t act_time);
  845. public int set_expiration_time (time_t exp_time);
  846. public int set_serial (void* serial, size_t serial_size);
  847. public int set_subject_key_id (void* id, size_t id_size);
  848. public int set_proxy_dn (Certificate eecrt, uint raw_flag, void* name, uint name_size);
  849. public int set_proxy (int pathLenConstraint, string policyLanguage, [CCode (array_length_type = "size_t")] uint8[] policy);
  850. public int print (CertificatePrintFormats format, out Datum output);
  851. public int get_raw_issuer_dn (out unowned Datum start);
  852. public int get_raw_dn (out unowned Datum start);
  853. public int verify_data (uint flags, ref Datum data, ref Datum signature);
  854. public int set_crq (CertificateRequest crq);
  855. // verification
  856. public int check_issuer (Certificate issuer);
  857. public static int list_verify (Certificate[] cert_list, Certificate[] CA_list, Certificate[] CLR_list, CertificateVerifyFlags flags, out CertificateStatus verify);
  858. public int verify (Certificate[] CA_list, CertificateVerifyFlags flags, out CertificateStatus verify);
  859. public int check_revocation (CRL[] crl_list);
  860. public int get_fingerprint (DigestAlgorithm algo, void* buf, ref size_t buf_size);
  861. public int get_key_purpose_oid (int index, void* oid, ref size_t oid_size, out bool critical);
  862. public int set_key_purpose_oid (string oid, bool critical);
  863. }
  864. [Compact]
  865. [CCode (cname = "struct gnutls_x509_crl_int", free_function = "gnutls_x509_crl_deinit", cprefix = "gnutls_x509_crl_")]
  866. public class CRL
  867. {
  868. private static int init (out CRL crl);
  869. public static CRL create ()
  870. {
  871. CRL result;
  872. var ret = init (out result);
  873. if (ret != 0)
  874. GLib.error ("%s", ((ErrorCode)ret).to_string ());
  875. return result;
  876. }
  877. public int import (ref Datum data, CertificateFormat format);
  878. public int export (CertificateFormat format, void* output, ref size_t output_size);
  879. public int get_issuer_dn (char* buf, ref size_t buf_size);
  880. public int get_issuer_dn_by_oid (string oid, int index, uint raw_flag, void* buf, ref size_t buf_size);
  881. public int get_dn_oid (int index, void* oid, ref size_t oid_size);
  882. public int get_signature_algorithm ();
  883. public int get_signature (char* sig, ref size_t sig_size);
  884. public int get_version ();
  885. public time_t get_this_update ();
  886. public time_t get_next_update ();
  887. public int get_crt_count ();
  888. public int get_crt_serial (int index, uchar* serial, ref size_t serial_size, out time_t t);
  889. // aliases for previous two
  890. public int get_certificate_count ();
  891. public int get_certificate (int index, uchar* serial, ref size_t serial_size, out time_t t);
  892. public int check_issuer (Certificate issuer);
  893. public int verify (Certificate[] ca_list, CertificateVerifyFlags flags, out CertificateStatus verify);
  894. // CRL writing
  895. public int set_version (uint version);
  896. public int sign (Certificate issuer, PrivateKey issuer_key);
  897. public int sign2 (Certificate issuer, PrivateKey issuer_key, DigestAlgorithm algo, uint flags);
  898. public int set_this_update (time_t act_time);
  899. public int set_next_update (time_t exp_time);
  900. public int set_crt_serial (void* serial, size_t serial_size, time_t revocation_time);
  901. public int set_crt (Certificate crt, time_t revocation_time);
  902. public int print (CertificatePrintFormats format, out Datum output);
  903. }
  904. [Compact]
  905. [CCode (cname = "struct gnutls_pkcs7_int", cprefix = "gnutls_pkcs7_", free_function = "gnutls_pkcs7_deinit")]
  906. public class PKCS7
  907. {
  908. private static int init (out PKCS7 pkcs7);
  909. public static PKCS7 create ()
  910. {
  911. PKCS7 result;
  912. var ret = init (out result);
  913. if (ret != 0)
  914. GLib.error ("%s", ((ErrorCode)ret).to_string ());
  915. return result;
  916. }
  917. public int import (ref Datum data, CertificateFormat format);
  918. public int export (CertificateFormat format, void* output, ref size_t output_size);
  919. public int get_crt_count ();
  920. public int get_crt_raw (int index, void* certificate, ref size_t certificate_size);
  921. public int set_crt_raw (ref Datum crt);
  922. public int set_crt (Certificate crt);
  923. public int delete_crt (int index);
  924. public int get_crl_count ();
  925. public int get_crl_raw (int index, void* crl, ref size_t crl_size);
  926. public int set_crl_raw (ref Datum crt);
  927. public int set_crl (CRL crl);
  928. public int delete_crl (int index);
  929. }
  930. // Flags for the gnutls_x509_privkey_export_pkcs8() function.
  931. [Flags]
  932. [CCode (cname = "gnutls_pkcs_encrypt_flags_t", cprefix = "GNUTLS_PKCS_", has_type_id = false)]
  933. public enum PKCSEncryptFlags {
  934. PLAIN,
  935. USE_PKCS12_3DES,
  936. USE_PKCS12_ARCFOUR,
  937. USE_PKCS12_RC2_40,
  938. USE_PBES2_3DES
  939. }
  940. [Compact]
  941. [CCode (cname = "struct gnutls_x509_privkey_int", cprefix = "gnutls_x509_privkey_", free_function = "gnutls_x509_privkey_deinit")]
  942. public class PrivateKey
  943. {
  944. private static int init (out PrivateKey key);
  945. public static PrivateKey create ()
  946. {
  947. PrivateKey result;
  948. var ret = init (out result);
  949. if (ret != 0)
  950. GLib.error ("%s", ((ErrorCode)ret).to_string ());
  951. return result;
  952. }
  953. public int cpy (PrivateKey source);
  954. public int import (ref Datum data, CertificateFormat format);
  955. public int import_pkcs8 (ref Datum data, CertificateFormat format, string? password, PKCSEncryptFlags flags);
  956. public int import_rsa_raw (ref Datum m, ref Datum e, ref Datum d, ref Datum p, ref Datum q, ref Datum u);
  957. public int import_dsa_raw (ref Datum p, ref Datum q, ref Datum g, ref Datum y, ref Datum x);
  958. public int export (CertificateFormat format, void* output, ref size_t output_size);
  959. public int export_pkcs8 (CertificateFormat format, string password, PKCSEncryptFlags flags, void* output, ref size_t output_size);
  960. public int export_rsa_raw (out Datum m, out Datum e, out Datum d, out Datum p, out Datum q, out Datum u);
  961. public int export_dsa_raw (out Datum p, out Datum q, out Datum g, out Datum y, out Datum x);
  962. public int fix ();
  963. public int generate (PKAlgorithm algo, uint bits, uint flags = 0);
  964. public int get_pk_algorithm ();
  965. public int get_key_id (uint flags, uchar* output, ref size_t output_size);
  966. // Signing stuff
  967. public int sign_data (DigestAlgorithm digest, uint flags, ref Datum data, void* signature, ref size_t signature_size);
  968. public int verify_data (uint flags, ref Datum data, ref Datum signature);
  969. public int sign_hash (ref Datum hash, out Datum signature);
  970. }
  971. [Compact]
  972. [CCode (cname = "struct gnutls_x509_crq_int", cprefix = "gnutls_x509_crq_", free_function = "gnutls_x509_crq_deinit")]
  973. public class CertificateRequest
  974. {
  975. private static int init (out CertificateRequest request);
  976. public static CertificateRequest create ()
  977. {
  978. CertificateRequest result;
  979. var ret = init (out result);
  980. if (ret != 0)
  981. GLib.error ("%s", ((ErrorCode)ret).to_string ());
  982. return result;
  983. }
  984. public int import (ref Datum data, CertificateFormat format);
  985. public int export (CertificateFormat format, void* output, ref size_t output_size);
  986. public int get_pk_algorithm (out uint bits);
  987. public int get_dn (char* buf, ref size_t buf_size);
  988. public int get_dn_oid (int index, void* oid, ref size_t oid_size);
  989. public int get_dn_by_oid (string oid, int index, uint raw_flag, void* buf, ref size_t buf_size);
  990. public int set_dn_by_oid (string oid, uint raw_flag, void* name, uint name_size);
  991. public int set_version (uint version);
  992. public int set_key (PrivateKey key);
  993. public int sign (PrivateKey key);
  994. public int sign2 (PrivateKey key, DigestAlgorithm algo, uint flags);
  995. public int set_challenge_password (string pass);
  996. public int get_challenge_password (char* pass, ref size_t pass_size);
  997. public int set_attribute_by_oid (string oid, void* buf, size_t buf_size);
  998. public int get_attribute_by_oid (string oid, int index, void* buf, ref size_t buf_size);
  999. }
  1000. [Compact]
  1001. [CCode (cheader_filename = "gnutls/pkcs12.h", cname = "struct gnutls_pkcs12_int", cprefix = "gnutls_pkcs12_", free_function = "gnutls_pkcs12_deinit")]
  1002. public class PKCS12
  1003. {
  1004. private static int init (out PKCS12 request);
  1005. public static PKCS12 create ()
  1006. {
  1007. PKCS12 result;
  1008. var ret = init (out result);
  1009. if (ret != 0)
  1010. GLib.error ("%s", ((ErrorCode)ret).to_string ());
  1011. return result;
  1012. }
  1013. public int import (ref Datum data, CertificateFormat format, uint flags);
  1014. public int export (CertificateFormat format, void* output, ref size_t output_size);
  1015. public int get_bag (int index, PKCS12Bag bag);
  1016. public int set_bag (PKCS12Bag bag);
  1017. public int generate_mac (string pass);
  1018. public int verify_mac (string pass);
  1019. }
  1020. [CCode (cheader_filename = "gnutls/pkcs12.h", cname = "gnutls_pkcs12_bag_type_t", cprefix = "GNUTLS_BAG_", has_type_id = false)]
  1021. public enum PKCS12BagType {
  1022. EMPTY,
  1023. PKCS8_ENCRYPTED_KEY,
  1024. PKCS8_KEY,
  1025. CERTIFICATE,
  1026. CRL,
  1027. ENCRYPTED,
  1028. UNKNOWN
  1029. }
  1030. [Compact]
  1031. [CCode (cheader_filename = "gnutls/pkcs12.h", cname = "struct gnutls_pkcs12_bag_int", cprefix = "gnutls_pkcs12_bag_", free_function = "gnutls_pkcs12_bag_deinit")]
  1032. public class PKCS12Bag {
  1033. private static int init (out PKCS12Bag request);
  1034. public static PKCS12Bag create ()
  1035. {
  1036. PKCS12Bag result;
  1037. var ret = init (out result);
  1038. if (ret != 0)
  1039. GLib.error ("%s", ((ErrorCode)ret).to_string ());
  1040. return result;
  1041. }
  1042. public int decrypt (string pass);
  1043. public int encrypt (string pass, PKCSEncryptFlags flags);
  1044. public PKCS12BagType get_type (int index);
  1045. public int get_data (int index, out Datum data);
  1046. public int set_data (PKCS12BagType type, ref Datum data);
  1047. public int set_crl (CRL crl);
  1048. public int set_crt (Certificate crt);
  1049. public int get_count ();
  1050. public int get_key_id (int index, out Datum id);
  1051. public int set_key_id (int index, ref Datum id);
  1052. public int get_friendly_name (int index, out unowned string name);
  1053. public int set_friendly_name (int index, string name);
  1054. }
  1055. }
  1056. [CCode (cheader_filename = "gnutls/openpgp.h")]
  1057. namespace OpenPGP
  1058. {
  1059. [CCode (has_target = false)]
  1060. public delegate int RecvKeyFunc (Session session, uint8[] keyfpr, out Datum key);
  1061. [CCode (cname = "gnutls_openpgp_crt_fmt_t", cprefix = "GNUTLS_OPENPGP_FMT_", has_type_id = false)]
  1062. public enum CertificateFormat {
  1063. RAW,
  1064. BASE64
  1065. }
  1066. [Compact]
  1067. [CCode (cname = "struct gnutls_openpgp_crt_int", cprefix = "gnutls_openpgp_crt_", free_function = "gnutls_openpgp_crt_deinit")]
  1068. public class Certificate
  1069. {
  1070. private static int init (out Certificate crt);
  1071. public static Certificate create ()
  1072. {
  1073. Certificate result;
  1074. var ret = init (out result);
  1075. if (ret != 0)
  1076. GLib.error ("%s", ((ErrorCode)ret).to_string ());
  1077. return result;
  1078. }
  1079. public int import (ref Datum data, CertificateFormat format);
  1080. public int export (CertificateFormat format, void* output, ref size_t output_size);
  1081. public int print (CertificatePrintFormats format, out Datum output);
  1082. public int get_key_usage (out KeyUsage key_usage);
  1083. public int get_fingerprint (void* fpr, ref size_t fpr_size);
  1084. public int get_subkey_fingerprint (uint index, void* fpr, ref size_t fpr_size);
  1085. public int get_name (int index, char* buf, ref size_t buf_size);
  1086. public PKAlgorithm get_pk_algorithm (out uint bits);
  1087. public int get_version ();
  1088. public time_t get_creation_time ();
  1089. public time_t get_expiration_time ();
  1090. // keyid is 8 bytes
  1091. public int get_key_id (uchar* keyid);
  1092. public int check_hostname (string hostname);
  1093. public int get_revoked_status ();
  1094. public int get_subkey_count ();
  1095. public int get_subkey_idx (/*const*/ uchar* keyid);
  1096. public int get_subkey_revoked_status (uint idx);
  1097. public PKAlgorithm get_subkey_pk_algorithm (uint idx, out uint bits);
  1098. public time_t get_subkey_creation_time (uint idx);
  1099. public time_t get_subkey_expiration_time (uint idx);
  1100. public int get_subkey_id (uint idx, uchar* keyid);
  1101. public int get_subkey_usage (uint idx, out KeyUsage key_usage);
  1102. public int get_pk_dsa_raw (out Datum p, out Datum q, out Datum g, out Datum y);
  1103. public int get_pk_rsa_raw (out Datum m, out Datum e);
  1104. public int get_subkey_pk_dsa_raw (uint index, out Datum p, out Datum q, out Datum g, out Datum y);
  1105. public int get_subkey_pk_rsa_raw (uint index, out Datum m, out Datum e);
  1106. public int get_preferred_key_id (uchar* keyid);
  1107. public int set_preferred_key_id (/* const */ uchar* keyid);
  1108. public int verify_ring (Keyring keyring, uint flags, out CertificateStatus verify);
  1109. public int verify_self (uint flags, out CertificateStatus verify);
  1110. }
  1111. [Compact]
  1112. [CCode (cname = "struct gnutls_openpgp_privkey_int", cprefix = "gnutls_openpgp_privkey_", free_function = "gnutls_openpgp_privkey_deinit")]
  1113. public class PrivateKey
  1114. {
  1115. private static int init (out PrivateKey key);
  1116. public static PrivateKey create ()
  1117. {
  1118. PrivateKey result = null;
  1119. var ret = init (out result);
  1120. if (ret != 0)
  1121. GLib.error ("%s", ((ErrorCode)ret).to_string ());
  1122. return result;
  1123. }
  1124. public PKAlgorithm get_pk_algorithm (out uint bits);
  1125. public int import (ref Datum data, CertificateFormat format, string pass, uint flags);
  1126. public int export (CertificateFormat format, string password, uint flags, void* output, ref size_t output_size);
  1127. public int sign_hash (ref Datum hash, out Datum signature);
  1128. public int get_fingerprint (void* fpr, ref size_t fpr_size);
  1129. public int get_subkey_fingerprint (uint idx, void* fpr, ref size_t fpr_size);
  1130. public int get_key_id (uchar* keyid);
  1131. public int get_subkey_count ();
  1132. public int get_subkey_idx (/*const*/ uchar* keyid);
  1133. public int get_subkey_revoked_status (uint index);
  1134. public int get_revoked_status ();
  1135. public PKAlgorithm get_subkey_pk_algorithm (uint idx, out uint bits);
  1136. public time_t get_subkey_expiration_time (uint idx);
  1137. public time_t get_subkey_creation_time (uint idx);
  1138. public int get_subkey_id (uint idx, uchar* keyid);
  1139. public int export_subkey_dsa_raw (uint idx, out Datum p, out Datum q, out Datum g, out Datum y, out Datum x);
  1140. public int export_subkey_rsa_raw (uint idx, out Datum m, out Datum e, out Datum d, out Datum p, out Datum q, out Datum u);
  1141. public int export_dsa_raw (out Datum p, out Datum q, out Datum g, out Datum y, out Datum x);
  1142. public int export_rsa_raw (out Datum m, out Datum e, out Datum d, out Datum p, out Datum q, out Datum u);
  1143. public int set_preferred_key_id (/*const*/ uchar* keyid);
  1144. public int get_preferred_key_id (uchar* keyid);
  1145. public int get_auth_subkey (uchar* keyid, uint flag);
  1146. }
  1147. [Compact]
  1148. [CCode (cname = "struct gnutls_openpgp_keyring_int", cprefix = "gnutls_openpgp_keyring_", free_function = "gnutls_openpgp_keyring_deinit")]
  1149. public class Keyring
  1150. {
  1151. private static int init (out Keyring keyring);
  1152. public static Keyring create ()
  1153. {
  1154. Keyring result;
  1155. var ret = init (out result);
  1156. if (ret != 0)
  1157. GLib.error ("%s", ((ErrorCode)ret).to_string ());
  1158. return result;
  1159. }
  1160. public int import (ref Datum data, CertificateFormat format);
  1161. public int check_id (/*const*/ uchar* keyid, uint flags);
  1162. public int get_crt_count ();
  1163. public int get_crt (uint index, out Certificate cert);
  1164. }
  1165. }
  1166. [CCode (cname = "gnutls_certificate_client_retrieve_function *", has_target = false)]
  1167. public delegate int ClientCertificateRetrieveFunction (Session session, Datum[] req_ca_rdn, PKAlgorithm[] pk_algos, out RetrStruct st);
  1168. [CCode (cname = "gnutls_certificate_server_retrieve_function *", has_target = false)]
  1169. public delegate int ServerCertificateRetrieveFunction (Session session, out RetrStruct st);
  1170. [Compact]
  1171. [CCode (cname = "struct gnutls_certificate_credentials_st",
  1172. free_function = "gnutls_certificate_free_credentials",
  1173. cprefix = "gnutls_certificate_")]
  1174. public class CertificateCredentials
  1175. {
  1176. [CCode (cname = "gnutls_certificate_allocate_credentials")]
  1177. private static int allocate (out CertificateCredentials credentials);
  1178. public static CertificateCredentials create ()
  1179. {
  1180. CertificateCredentials result;
  1181. var ret = allocate (out result);
  1182. if (ret != 0)
  1183. GLib.error ("%s", ((ErrorCode)ret).to_string ());
  1184. return result;
  1185. }
  1186. public void free_keys ();
  1187. public void free_cas ();
  1188. public void free_ca_names ();
  1189. public void free_crls ();
  1190. public void set_dh_params (DHParams dh_params);
  1191. public void set_rsa_export_params (RSAParams rsa_params);
  1192. public void set_verify_flags (X509.CertificateVerifyFlags flags);
  1193. public void set_verify_limits (uint max_bits, uint max_depth);
  1194. public int set_x509_trust (X509.Certificate[] ca_list);
  1195. public int set_x509_trust_file (string cafile, X509.CertificateFormat type);
  1196. public int set_x509_trust_mem (/* const */ ref Datum cadata, X509.CertificateFormat type);
  1197. public int set_x509_crl (X509.CRL[] crl_list);
  1198. public int set_x509_crl_file (string crlfile, X509.CertificateFormat type);
  1199. public int set_x509_crl_mem (/* const */ ref Datum crldata, X509.CertificateFormat type);
  1200. public int set_x509_key (X509.Certificate[] cert_list, X509.PrivateKey key);
  1201. public int set_x509_key_file (string certfile, string keyfile, X509.CertificateFormat type);
  1202. public int set_x509_key_mem (/* const */ ref Datum certdata, /* const */ ref Datum keydata, X509.CertificateFormat type);
  1203. public int set_x509_simple_pkcs12_file (string pkcs12file, X509.CertificateFormat type, string? password = null);
  1204. public void get_x509_cas ([CCode (array_length_type = "unsigned int")] out unowned X509.Certificate[] x509_ca_list);
  1205. public void get_x509_crls ([CCode (array_length_type = "unsigned int")] out unowned X509.CRL[] x509_crl_list);
  1206. [CCode (cname = "gnutls_certificate_client_set_retrieve_function")]
  1207. public void set_client_certificate_retrieve_function (ClientCertificateRetrieveFunction func);
  1208. [CCode (cname = "gnutls_certificate_server_set_retrieve_function")]
  1209. public void set_server_certificate_retrieve_function (ServerCertificateRetrieveFunction func);
  1210. [CCode (cname = "gnutls_certificate_set_params_function")]
  1211. public void set_params_function (ParamsFunction func);
  1212. // OpenPGP stuff
  1213. public int set_openpgp_key (OpenPGP.Certificate key, OpenPGP.PrivateKey pkey);
  1214. public int set_openpgp_key_file (string certfile, string keyfile, OpenPGP.CertificateFormat format);
  1215. public int set_openpgp_key_mem (ref Datum cert, ref Datum key, OpenPGP.CertificateFormat format);
  1216. public int set_openpgp_key_file2 (string certfile, string keyfile, string keyid, OpenPGP.CertificateFormat format);
  1217. public int set_openpgp_key_mem2 (ref Datum cert, ref Datum key, string keyid, OpenPGP.CertificateFormat format);
  1218. public int set_openpgp_keyring_mem (uchar* data, size_t data_size, OpenPGP.CertificateFormat format);
  1219. public int set_openpgp_keyring_file (string file, OpenPGP.CertificateFormat format);
  1220. public void get_openpgp_keyring (out unowned OpenPGP.Keyring keyring);
  1221. }
  1222. [CCode (cname = "gnutls_malloc")]
  1223. public void* malloc (size_t size);
  1224. [CCode (cname = "gnutls_secure_malloc")]
  1225. public void* secure_malloc (size_t size);
  1226. [CCode (cname = "gnutls_realloc")]
  1227. public void* realloc (void* ptr, size_t new_size);
  1228. [CCode (cname = "gnutls_calloc")]
  1229. public void* calloc (size_t count, size_t block_size);
  1230. [CCode (cname = "gnutls_free")]
  1231. public void free (void* ptr);
  1232. [CCode (cname = "gnutls_free")]
  1233. public void free_data ([CCode (array_length = false)] owned uint[] data);
  1234. [CCode (cname = "gnutls_strdup")]
  1235. public string strdup (string str);
  1236. [CCode (cname = "gnutls_alloc_function", has_target = false)]
  1237. public delegate void* AllocFunction (size_t size);
  1238. [CCode (cname = "gnutls_calloc_function", has_target = false)]
  1239. public delegate void* CallocFunction (size_t count, size_t block_size);
  1240. [CCode (cname = "gnutls_is_secure_function", has_target = false)]
  1241. public delegate int IsSecureFunction (void* ptr);
  1242. [CCode (cname = "gnutls_free_function", has_target = false)]
  1243. public delegate void FreeFunction (void* ptr);
  1244. [CCode (cname = "gnutls_realloc_function", has_target = false)]
  1245. public delegate void* ReallocFunction (void* ptr, size_t new_size);
  1246. public int global_init ();
  1247. public void global_deinit ();
  1248. [CCode (cname = "gnutls_global_set_mem_functions")]
  1249. public void set_mem_functions (AllocFunction alloc_func, AllocFunction secure_alloc_func,
  1250. IsSecureFunction is_secure_func, ReallocFunction realloc_func,
  1251. FreeFunction free_func);
  1252. [CCode (cname = "gnutls_log_func", has_target = false)]
  1253. public delegate void LogFunc (int level, string msg);
  1254. [CCode (cname = "gnutls_global_set_log_function")]
  1255. public void set_log_function (LogFunc func);
  1256. [CCode (cname = "gnutls_global_set_log_level")]
  1257. public void set_log_level (int level);
  1258. [CCode (cname = "gnutls_transport_set_global_errno")]
  1259. public void set_global_errno (int err);
  1260. // SRP stuff
  1261. [CCode (cname = "gnutls_srp_server_credentials_function *", has_target = false)]
  1262. public delegate int SRPServerCredentialsFunction (Session session, string username,
  1263. out Datum salt, out Datum verifier,
  1264. out Datum generator, out Datum prime);
  1265. [Compact]
  1266. [CCode (cname = "struct gnutls_srp_server_credentials_st", free_function = "gnutls_srp_free_server_credentials")]
  1267. public class SRPServerCredentials
  1268. {
  1269. [CCode (cname = "gnutls_srp_allocate_server_credentials")]
  1270. private static int allocate (out SRPServerCredentials sc);
  1271. public static SRPServerCredentials create ()
  1272. {
  1273. SRPServerCredentials result = null;
  1274. var ret = allocate (out result);
  1275. if (ret != 0)
  1276. GLib.error ("%s", ((ErrorCode)ret).to_string ());
  1277. return result;
  1278. }
  1279. [CCode (cname = "gnutls_srp_set_server_credentials_file")]
  1280. public int set_credentials_file (string password_file, string password_conf_file);
  1281. [CCode (cname = "gnutls_srp_server_get_username")]
  1282. public string get_username ();
  1283. [CCode (cname = "gnutls_srp_set_server_credentials_function")]
  1284. public void set_credentials_function (SRPServerCredentialsFunction func);
  1285. }
  1286. [CCode (cname = "gnutls_srp_client_credentials_function *", has_target = false)]
  1287. public delegate int SRPClientCredentialsFunction (Session session, out string username, out string password);
  1288. [Compact]
  1289. [CCode (cname = "struct gnutls_srp_client_credentials_st", free_function = "gnutls_srp_free_client_credentials")]
  1290. public class SRPClientCredentials
  1291. {
  1292. [CCode (cname = "gnutls_srp_allocate_client_credentials")]
  1293. private static int allocate (out SRPClientCredentials sc);
  1294. public static SRPClientCredentials create ()
  1295. {
  1296. SRPClientCredentials result;
  1297. var ret = allocate (out result);
  1298. if (ret != 0)
  1299. GLib.error ("%s", ((ErrorCode)ret).to_string ());
  1300. return result;
  1301. }
  1302. [CCode (cname = "gnutls_srp_set_client_credentials")]
  1303. public int set_credentials (string username, string password);
  1304. [CCode (cname = "gnutls_srp_set_client_credentials_function")]
  1305. public void set_credentials_function (SRPClientCredentialsFunction func);
  1306. }
  1307. // extern int gnutls_srp_verifier (const char *username,
  1308. // const char *password,
  1309. // const gnutls_datum_t * salt,
  1310. // const gnutls_datum_t * generator,
  1311. // const gnutls_datum_t * prime,
  1312. // gnutls_datum_t * res);
  1313. public int srp_verifier (string username, string password, /* const */ ref Datum salt, /* const */ ref Datum generator, /* const */ ref Datum prime, out Datum result);
  1314. // The static parameters defined in draft-ietf-tls-srp-05
  1315. // Those should be used as input to gnutls_srp_verifier().
  1316. public const Datum srp_2048_group_prime;
  1317. public const Datum srp_2048_group_generator;
  1318. public const Datum srp_1536_group_prime;
  1319. public const Datum srp_1536_group_generator;
  1320. public const Datum srp_1024_group_prime;
  1321. public const Datum srp_1024_group_generator;
  1322. public int srp_base64_encode (/* const */ ref Datum data, [CCode (array_length = "false")] char[] result, ref size_t result_size);
  1323. public int srp_base64_encode_alloc (/* const */ ref Datum data, out Datum result);
  1324. public int srp_base64_decode (/* const */ ref Datum b64_data, [CCode (array_length = false)] uint8[] result, ref size_t result_size);
  1325. public int srp_base64_decode_alloc (/* const */ ref Datum b64_data, out Datum result);
  1326. // PSK stuff
  1327. [CCode (cname = "gnutls_psk_key_flags", cprefix = "GNUTLS_PSK_KEY_", has_type_id = false)]
  1328. public enum PSKKeyFlags
  1329. {
  1330. RAW,
  1331. HEX
  1332. }
  1333. [CCode (cname = "gnutls_psk_server_credentials_function *", has_target = false)]
  1334. public delegate int PSKServerCredentialsFunction (Session session, string username, /* const */ ref Datum key);
  1335. [Compact]
  1336. [CCode (cname = "struct gnutls_psk_server_credentials_st", free_function = "gnutls_psk_free_server_credentials")]
  1337. public class PSKServerCredentials
  1338. {
  1339. [CCode (cname = "gnutls_psk_allocate_server_credentials")]
  1340. private static int allocate (out PSKServerCredentials sc);
  1341. public static PSKServerCredentials create ()
  1342. {
  1343. PSKServerCredentials result;
  1344. var ret = allocate (out result);
  1345. if (ret != 0)
  1346. GLib.error ("%s", ((ErrorCode)ret).to_string ());
  1347. return result;
  1348. }
  1349. [CCode (cname = "gnutls_psk_set_server_credentials_file")]
  1350. public int set_credentials_file (string password_file);
  1351. [CCode (cname = "gnutls_psk_set_server_credentials_hint")]
  1352. public int set_credentials_hint (string hint);
  1353. [CCode (cname = "gnutls_psk_set_server_credentials_function")]
  1354. public void set_credentials_function (PSKServerCredentialsFunction func);
  1355. [CCode (cname = "gnutls_psk_set_server_dh_params")]
  1356. public void set_dh_params (DHParams dh_params);
  1357. [CCode (cname = "gnutls_psk_set_server_params_function")] // also gnutls_psk_set_params_function
  1358. public void set_params_function (ParamsFunction func);
  1359. }
  1360. [CCode (cname = "gnutls_psk_client_credentials_function *", has_target = false)]
  1361. public delegate int PSKClientCredentialsFunction (Session session, out string username, out Datum key);
  1362. [Compact]
  1363. [CCode (cname = "struct gnutls_psk_client_credentials_st", free_function = "gnutls_psk_free_client_credentials")]
  1364. public class PSKClientCredentials
  1365. {
  1366. [CCode (cname = "gnutls_psk_allocate_client_credentials")]
  1367. private static int allocate (out PSKClientCredentials sc);
  1368. public static PSKClientCredentials create ()
  1369. {
  1370. PSKClientCredentials result;
  1371. var ret = allocate (out result);
  1372. if (ret != 0)
  1373. GLib.error ("%s", ((ErrorCode)ret).to_string ());
  1374. return result;
  1375. }
  1376. [CCode (cname = "gnutls_psk_set_client_credentials")]
  1377. public int set_credentials (string username, /* const */ ref Datum key, PSKKeyFlags format);
  1378. [CCode (cname = "gnutls_psk_set_client_credentials_function")]
  1379. public void set_credentials_function (PSKClientCredentialsFunction func);
  1380. }
  1381. public int hex_encode (/* const */ ref Datum data, [CCode (array_length = "false")] char[] result, ref size_t result_size);
  1382. public int hex_decode (/* const */ ref Datum hex_data, [CCode (array_length = "false")] char[] result, ref size_t result_size);
  1383. public int psk_netconf_derive_key (string password, string psk_identity, string psk_identity_hint, out Datum output_key);
  1384. ////
  1385. [SimpleType]
  1386. [CCode (cname = "gnutls_retr_st", has_type_id = false)]
  1387. public struct RetrStruct
  1388. {
  1389. public CertificateType type;
  1390. [CCode (cname = "cert.x509", array_length_cname = "ncerts", array_length_type = "unsigned int")]
  1391. public X509.Certificate[] cert_x509;
  1392. [CCode (cname = "cert.pgp")]
  1393. public OpenPGP.Certificate cert_pgp;
  1394. [CCode (cname = "key.x509")]
  1395. public X509.PrivateKey key_x509;
  1396. [CCode (cname = "key.pgp")]
  1397. public OpenPGP.PrivateKey key_pgp;
  1398. public uint deinit_all;
  1399. }
  1400. public int pem_base64_encode (string msg, /* const */ ref Datum data, void* result, ref size_t result_size);
  1401. public int pem_base64_decode (string header, /* const */ ref Datum b64_data, void* result, ref size_t result_size);
  1402. public int pem_base64_encode_alloc (string msg, /* const */ ref Datum data, out Datum result);
  1403. public int pem_base64_decode_alloc (string header, /* const */ ref Datum b64_data, out Datum result);
  1404. public int hex2bin (string hex_data, size_t hex_size, void* bin_data, ref size_t bin_size);
  1405. // returns cipher suite name or null if index is out of bounds
  1406. public unowned string? cipher_suite_info (size_t index, [CCode (array_length = "false")] char[] cs_id, out KXAlgorithm kx,
  1407. out CipherAlgorithm cipher, out MacAlgorithm mac,
  1408. out Protocol version);
  1409. public unowned string? cipher_suite_get_name (KXAlgorithm kx, CipherAlgorithm cipher, MacAlgorithm mac);
  1410. public int prf (Session session, size_t label_size, string label, bool server_random_first,
  1411. size_t extra_size, void* extra, size_t output_size, void* output);
  1412. public int prf_raw (Session session, size_t label_size, string label,
  1413. size_t seed_size, void* seed, size_t output_size, void* output);
  1414. // Gnutls error codes. The mapping to a TLS alert is also shown in comments.
  1415. [CCode (cname = "int", cprefix = "GNUTLS_E_", lower_case_cprefix = "gnutls_error_", has_type_id = false)]
  1416. public enum ErrorCode {
  1417. SUCCESS,
  1418. UNKNOWN_COMPRESSION_ALGORITHM,
  1419. UNKNOWN_CIPHER_TYPE,
  1420. LARGE_PACKET,
  1421. UNSUPPORTED_VERSION_PACKET, // GNUTLS_A_PROTOCOL_VERSION
  1422. UNEXPECTED_PACKET_LENGTH, // GNUTLS_A_RECORD_OVERFLOW
  1423. INVALID_SESSION,
  1424. FATAL_ALERT_RECEIVED,
  1425. UNEXPECTED_PACKET, // GNUTLS_A_UNEXPECTED_MESSAGE
  1426. WARNING_ALERT_RECEIVED,
  1427. ERROR_IN_FINISHED_PACKET,
  1428. UNEXPECTED_HANDSHAKE_PACKET,
  1429. UNKNOWN_CIPHER_SUITE, // GNUTLS_A_HANDSHAKE_FAILURE
  1430. UNWANTED_ALGORITHM,
  1431. MPI_SCAN_FAILED,
  1432. DECRYPTION_FAILED, // GNUTLS_A_DECRYPTION_FAILED, GNUTLS_A_BAD_RECORD_MAC
  1433. MEMORY_ERROR,
  1434. DECOMPRESSION_FAILED, // GNUTLS_A_DECOMPRESSION_FAILURE
  1435. COMPRESSION_FAILED,
  1436. AGAIN,
  1437. EXPIRED,
  1438. DB_ERROR,
  1439. SRP_PWD_ERROR,
  1440. INSUFFICIENT_CREDENTIALS,
  1441. HASH_FAILED,
  1442. BASE64_DECODING_ERROR,
  1443. MPI_PRINT_FAILED,
  1444. REHANDSHAKE, // GNUTLS_A_NO_RENEGOTIATION
  1445. GOT_APPLICATION_DATA,
  1446. RECORD_LIMIT_REACHED,
  1447. ENCRYPTION_FAILED,
  1448. PK_ENCRYPTION_FAILED,
  1449. PK_DECRYPTION_FAILED,
  1450. PK_SIGN_FAILED,
  1451. X509_UNSUPPORTED_CRITICAL_EXTENSION,
  1452. KEY_USAGE_VIOLATION,
  1453. NO_CERTIFICATE_FOUND, // GNUTLS_A_BAD_CERTIFICATE
  1454. INVALID_REQUEST,
  1455. SHORT_MEMORY_BUFFER,
  1456. INTERRUPTED,
  1457. PUSH_ERROR,
  1458. PULL_ERROR,
  1459. RECEIVED_ILLEGAL_PARAMETER, // GNUTLS_A_ILLEGAL_PARAMETER
  1460. REQUESTED_DATA_NOT_AVAILABLE,
  1461. PKCS1_WRONG_PAD,
  1462. RECEIVED_ILLEGAL_EXTENSION,
  1463. INTERNAL_ERROR,
  1464. DH_PRIME_UNACCEPTABLE,
  1465. FILE_ERROR,
  1466. TOO_MANY_EMPTY_PACKETS,
  1467. UNKNOWN_PK_ALGORITHM,
  1468. // returned if libextra functionality was requested but
  1469. // gnutls_global_init_extra() was not called.
  1470. INIT_LIBEXTRA,
  1471. LIBRARY_VERSION_MISMATCH,
  1472. // returned if you need to generate temporary RSA
  1473. // parameters. These are needed for export cipher suites.
  1474. NO_TEMPORARY_RSA_PARAMS,
  1475. LZO_INIT_FAILED,
  1476. NO_COMPRESSION_ALGORITHMS,
  1477. NO_CIPHER_SUITES,
  1478. OPENPGP_GETKEY_FAILED,
  1479. PK_SIG_VERIFY_FAILED,
  1480. ILLEGAL_SRP_USERNAME,
  1481. SRP_PWD_PARSING_ERROR,
  1482. NO_TEMPORARY_DH_PARAMS,
  1483. // For certificate and key stuff
  1484. ASN1_ELEMENT_NOT_FOUND,
  1485. ASN1_IDENTIFIER_NOT_FOUND,
  1486. ASN1_DER_ERROR,
  1487. ASN1_VALUE_NOT_FOUND,
  1488. ASN1_GENERIC_ERROR,
  1489. ASN1_VALUE_NOT_VALID,
  1490. ASN1_TAG_ERROR,
  1491. ASN1_TAG_IMPLICIT,
  1492. ASN1_TYPE_ANY_ERROR,
  1493. ASN1_SYNTAX_ERROR,
  1494. ASN1_DER_OVERFLOW,
  1495. OPENPGP_UID_REVOKED,
  1496. CERTIFICATE_ERROR,
  1497. CERTIFICATE_KEY_MISMATCH,
  1498. UNSUPPORTED_CERTIFICATE_TYPE, // GNUTLS_A_UNSUPPORTED_CERTIFICATE
  1499. X509_UNKNOWN_SAN,
  1500. OPENPGP_FINGERPRINT_UNSUPPORTED,
  1501. X509_UNSUPPORTED_ATTRIBUTE,
  1502. UNKNOWN_HASH_ALGORITHM,
  1503. UNKNOWN_PKCS_CONTENT_TYPE,
  1504. UNKNOWN_PKCS_BAG_TYPE,
  1505. INVALID_PASSWORD,
  1506. MAC_VERIFY_FAILED, // for PKCS #12 MAC
  1507. CONSTRAINT_ERROR,
  1508. WARNING_IA_IPHF_RECEIVED,
  1509. WARNING_IA_FPHF_RECEIVED,
  1510. IA_VERIFY_FAILED,
  1511. UNKNOWN_ALGORITHM,
  1512. BASE64_ENCODING_ERROR,
  1513. INCOMPATIBLE_CRYPTO_LIBRARY,
  1514. INCOMPATIBLE_LIBTASN1_LIBRARY,
  1515. OPENPGP_KEYRING_ERROR,
  1516. X509_UNSUPPORTED_OID,
  1517. RANDOM_FAILED,
  1518. BASE64_UNEXPECTED_HEADER_ERROR,
  1519. OPENPGP_SUBKEY_ERROR,
  1520. CRYPTO_ALREADY_REGISTERED,
  1521. HANDSHAKE_TOO_LARGE,
  1522. UNIMPLEMENTED_FEATURE,
  1523. APPLICATION_ERROR_MAX, // -65000
  1524. APPLICATION_ERROR_MIN; // -65500
  1525. [CCode (cname = "gnutls_error_is_fatal")]
  1526. public bool is_fatal ();
  1527. [CCode (cname = "gnutls_error_to_alert")]
  1528. public AlertDescription to_alert (out AlertLevel level);
  1529. [CCode (cname = "gnutls_perror")]
  1530. public void print ();
  1531. [CCode (cname = "gnutls_strerror")]
  1532. public unowned string to_string ();
  1533. }
  1534. }