1 #define _XOPEN_SOURCE 600
10 #define TLS_PREFIX SRCDIR "/server/tls/"
11 #define NSS_DIR TLS_PREFIX "client_nss"
13 void usage(const char *command
) {
14 const char *name
= NULL
;
16 name
= strrchr(command
, '/');
19 if (!name
) name
= command
;
21 fprintf(stderr
, "Usage: %s {openssl|nss} {sw|hw ID}\n"
22 "\tID\tIdentifier of cryptographic material in hardware engine\n",
27 int main(int argc
, char **argv
) {
28 struct isds_ctx
*ctx
= NULL
;
30 struct isds_pki_credentials
*pki_credentials
= NULL
;
33 /* Software: OpenSSL, GnuTLS */
34 struct isds_pki_credentials pki_software_ossl
= {
37 .key_format
= PKI_FORMAT_PEM
,
38 .key
= TLS_PREFIX
"client.key",
39 .certificate_format
= PKI_FORMAT_PEM
,
40 .certificate
= TLS_PREFIX
"client.cert"
44 struct isds_pki_credentials pki_software_nss
= {
47 .key_format
= PKI_FORMAT_PEM
,
49 .certificate_format
= PKI_FORMAT_PEM
,
50 .certificate
= "The Client Material"
53 /* Hardware engine: OpenSSL */
54 struct isds_pki_credentials pki_hardware_ossl
= {
57 .key_format
= PKI_FORMAT_ENG
,
59 .certificate_format
= PKI_FORMAT_ENG
,
63 /* Hardware engine: NSS */
64 struct isds_pki_credentials pki_hardware_nss
= {
67 .key_format
= PKI_FORMAT_PEM
,
69 .certificate_format
= PKI_FORMAT_PEM
,
70 .certificate
= "OpenSC Card (Bob Tester):Certificate"
73 setlocale(LC_ALL
, "");
76 if (argc
< 3 || !argv
[1] || !argv
[2]) usage(argv
[0]);
77 if (!strcmp(argv
[1], "openssl")) {
79 if (!strcmp(argv
[2], "sw")) pki_credentials
= &pki_software_ossl
;
80 else if (!strcmp(argv
[2], "hw")) {
81 pki_credentials
= &pki_hardware_ossl
;
82 if (argc
< 4 || !argv
[3]) usage(argv
[0]);
83 pki_credentials
->key
= argv
[3];
84 } else usage(argv
[0]);
85 } else if (!strcmp(argv
[1], "nss")) {
87 if (!strcmp(argv
[2], "sw")) pki_credentials
= &pki_software_nss
;
88 else if (!strcmp(argv
[2], "hw")) {
89 pki_credentials
= &pki_hardware_nss
;
90 if (argc
< 4 || !argv
[3]) usage(argv
[0]);
91 pki_credentials
->certificate
= argv
[3];
92 } else usage(argv
[0]);
99 printf("isds_init() failed: %s\n", isds_strerror(err
));
103 isds_set_logging(ILF_ALL
, ILL_ALL
);
105 ctx
= isds_ctx_create();
107 printf("isds_ctx_create() failed");
110 err
= isds_set_timeout(ctx
, 10000);
112 printf("isds_set_timeout() failed: %s\n", isds_strerror(err
));
115 /* err = isds_set_opt(ctx, IOPT_TLS_VERIFY_SERVER, 0);
117 printf("isds_set_opt(IOPT_TLS_VERIFY_SERVER) failed: %s\n",
123 if (setenv("SSL_DIR", NSS_DIR
, 0)) {
124 printf("setenv(\"SSL_DIR\", \"%s\") failed\n", NSS_DIR
);
127 err
= isds_set_opt(ctx
, IOPT_TLS_CA_FILE
, TLS_PREFIX
"ca.cert");
129 printf("isds_set_opt(IOPT_TLS_CA_FILE) failed: %s\n",
134 err
= isds_login(ctx
, "https://localhost:1443/", username(), password(),
135 pki_credentials
, NULL
);
137 printf("isds_login() failed: %s: %s\n", isds_strerror(err
),
138 isds_long_message(ctx
));
140 printf("Logged in :)\n");
144 err
= isds_logout(ctx
);
146 printf("isds_logout() failed: %s\n", isds_strerror(err
));
150 err
= isds_ctx_free(&ctx
);
152 printf("isds_ctx_free() failed: %s\n", isds_strerror(err
));
156 err
= isds_cleanup();
158 printf("isds_cleanup() failed: %s\n", isds_strerror(err
));