2
0

sslbackend.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
  9. *
  10. * This software is licensed as described in the file COPYING, which
  11. * you should have received as part of this distribution. The terms
  12. * are also available at https://curl.se/docs/copyright.html.
  13. *
  14. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. * copies of the Software, and permit persons to whom the Software is
  16. * furnished to do so, under the terms of the COPYING file.
  17. *
  18. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. * KIND, either express or implied.
  20. *
  21. * SPDX-License-Identifier: curl
  22. *
  23. ***************************************************************************/
  24. /* <DESC>
  25. * Shows HTTPS usage with client certs and optional ssl engine use.
  26. * </DESC>
  27. */
  28. #include <assert.h>
  29. #include <ctype.h>
  30. #include <stdio.h>
  31. #include <stdlib.h>
  32. #include <string.h>
  33. #include <curl/curl.h>
  34. /*
  35. * An SSL-enabled libcurl is required for this sample to work (at least one
  36. * SSL backend has to be configured).
  37. *
  38. * **** This example only works with libcurl 7.56.0 and later! ****
  39. */
  40. int main(int argc, char **argv)
  41. {
  42. const char *name = argc > 1 ? argv[1] : "openssl";
  43. CURLsslset result;
  44. if(!strcmp("list", name)) {
  45. const curl_ssl_backend **list;
  46. int i;
  47. result = curl_global_sslset((curl_sslbackend)-1, NULL, &list);
  48. assert(result == CURLSSLSET_UNKNOWN_BACKEND);
  49. for(i = 0; list[i]; i++)
  50. printf("SSL backend #%d: '%s' (ID: %d)\n",
  51. i, list[i]->name, list[i]->id);
  52. return 0;
  53. }
  54. else if(isdigit((int)(unsigned char)*name)) {
  55. int id = atoi(name);
  56. result = curl_global_sslset((curl_sslbackend)id, NULL, NULL);
  57. }
  58. else
  59. result = curl_global_sslset((curl_sslbackend)-1, name, NULL);
  60. if(result == CURLSSLSET_UNKNOWN_BACKEND) {
  61. fprintf(stderr, "Unknown SSL backend id: %s\n", name);
  62. return 1;
  63. }
  64. assert(result == CURLSSLSET_OK);
  65. printf("Version with SSL backend '%s':\n\n\t%s\n", name, curl_version());
  66. return 0;
  67. }