xref: /curl/docs/examples/sslbackend.c (revision c1ab33ed)
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 
34 #include <curl/curl.h>
35 
36 /*
37  * An SSL-enabled libcurl is required for this sample to work (at least one
38  * SSL backend has to be configured).
39  *
40  *  **** This example only works with libcurl 7.56.0 and later! ****
41 */
42 
main(int argc,char ** argv)43 int main(int argc, char **argv)
44 {
45   const char *name = argc > 1 ? argv[1] : "openssl";
46   CURLsslset result;
47 
48   if(!strcmp("list", name)) {
49     const curl_ssl_backend **list;
50     int i;
51 
52     result = curl_global_sslset(CURLSSLBACKEND_NONE, NULL, &list);
53     assert(result == CURLSSLSET_UNKNOWN_BACKEND);
54 
55     for(i = 0; list[i]; i++)
56       printf("SSL backend #%d: '%s' (ID: %d)\n",
57              i, list[i]->name, list[i]->id);
58 
59     return 0;
60   }
61   else if(isdigit((int)(unsigned char)*name)) {
62     int id = atoi(name);
63 
64     result = curl_global_sslset((curl_sslbackend)id, NULL, NULL);
65   }
66   else
67     result = curl_global_sslset(CURLSSLBACKEND_NONE, name, NULL);
68 
69   if(result == CURLSSLSET_UNKNOWN_BACKEND) {
70     fprintf(stderr, "Unknown SSL backend id: %s\n", name);
71     return 1;
72   }
73 
74   assert(result == CURLSSLSET_OK);
75 
76   printf("Version with SSL backend '%s':\n\n\t%s\n", name, curl_version());
77 
78   return 0;
79 }
80