int main(int argc, char *argv[]) { Gsasl *ctx; (void)argc; (void)argv; if (gsasl_init(&ctx) == GSASL_OK) { (void)gsasl_client_support_p(ctx, "CRAM-MD5"); gsasl_done(ctx); return 0; } return 0; }
void doit (void) { Gsasl *ctx = NULL; const char *str; const char *p; int res; res = gsasl_init (&ctx); if (res != GSASL_OK) { fail ("gsasl_init() failed (%d):\n%s\n", res, gsasl_strerror (res)); return; } str = "FOO BAR FOO"; p = gsasl_client_suggest_mechanism (ctx, str); if (debug) printf ("gsasl_client_suggest_mechanism(%s) = %s\n", str, p ? p : "(null)"); if (p) fail ("FAIL: not null?!\n"); if (gsasl_client_support_p (ctx, "EXTERNAL")) { str = "FOO BAR EXTERNAL BAR FOO"; p = gsasl_client_suggest_mechanism (ctx, str); if (debug) printf ("gsasl_client_suggest_mechanism(%s) = %s\n", str, p); if (!p || strcmp (p, "EXTERNAL") != 0) fail ("FAIL: not external?!\n"); } if (gsasl_client_support_p (ctx, "CRAM-MD5")) { str = "FOO BAR CRAM-MD5 BAR FOO"; p = gsasl_client_suggest_mechanism (ctx, str); if (debug) printf ("gsasl_client_suggest_mechanism(%s) = %s\n", str, p); if (!p || strcmp (p, "CRAM-MD5") != 0) fail ("FAIL: not cram-md5?!\n"); } if (gsasl_client_support_p (ctx, "PLAIN") && gsasl_client_support_p (ctx, "CRAM-MD5")) { str = "FOO PLAIN CRAM-MD5 BAR FOO"; p = gsasl_client_suggest_mechanism (ctx, str); if (debug) printf ("gsasl_client_suggest_mechanism(%s) = %s\n", str, p); if (!p || strcmp (p, "CRAM-MD5") != 0) fail ("FAIL: not cram-md5?!\n"); } if (gsasl_client_support_p (ctx, "PLAIN")) { str = "FOO PLAIN BAR FOO"; p = gsasl_client_suggest_mechanism (ctx, str); if (debug) printf ("gsasl_client_suggest_mechanism(%s) = %s\n", str, p); if (!p || strcmp (p, "PLAIN") != 0) fail ("FAIL: not plain?!\n"); } if (gsasl_client_support_p (ctx, "PLAIN") && gsasl_client_support_p (ctx, "CRAM-MD5") && gsasl_client_support_p (ctx, "DIGEST-MD5")) { str = "FOO PLAIN CRAM-MD5 DIGEST-MD5 FOO"; p = gsasl_client_suggest_mechanism (ctx, str); if (debug) printf ("gsasl_client_suggest_mechanism(%s) = %s\n", str, p); if (!p || strcmp (p, "CRAM-MD5") != 0) fail ("FAIL: not cram-md5?!\n"); } gsasl_done (ctx); }
void doit (void) { Gsasl *ctx = NULL; Gsasl_session *server = NULL, *client = NULL; char *s1 = NULL, *s2 = NULL; int rc, res1, res2; if (getenv ("GNUGSS") && strcmp (getenv ("GNUGSS"), "no") == 0) { fail ("Not using GNU GSS, skipping self-test.\n"); exit (77); } rc = gsasl_init (&ctx); if (rc != GSASL_OK) { fail ("gsasl_init() failed (%d):\n%s\n", rc, gsasl_strerror (rc)); return; } if (!gsasl_client_support_p (ctx, "GS2-KRB5") || !gsasl_server_support_p (ctx, "GS2-KRB5")) { gsasl_done (ctx); fail ("No support for GS2-KRB5.\n"); exit (77); } gsasl_callback_set (ctx, callback); for (i = 0; i < 5; i++) { bool client_first = (i % 2) == 0; rc = gsasl_server_start (ctx, "GS2-KRB5", &server); if (rc != GSASL_OK) { fail ("gsasl_server_start() failed (%d):\n%s\n", rc, gsasl_strerror (rc)); return; } rc = gsasl_client_start (ctx, "GS2-KRB5", &client); if (rc != GSASL_OK) { fail ("gsasl_client_start() failed (%d):\n%s\n", rc, gsasl_strerror (rc)); return; } if (client_first) { rc = gsasl_step64 (client, NULL, &s1); if (rc != GSASL_OK && rc != GSASL_NEEDS_MORE) { fail ("gsasl_step64 failed (%d):\n%s\n", rc, gsasl_strerror (rc)); return; } if (debug) printf ("C: %s [%c]\n", s1, ret_char (rc)); } do { res1 = gsasl_step64 (server, s1, &s2); if (s1 == NULL && res1 == GSASL_OK) fail ("gsasl_step64 direct success?\n"); if (s1) { gsasl_free (s1); s1 = NULL; } if (res1 != GSASL_OK && res1 != GSASL_NEEDS_MORE) { fail ("gsasl_step64 (1) failed (%d):\n%s\n", res1, gsasl_strerror (res1)); return; } if (debug) printf ("S: %s [%c]\n", s2, ret_char (res1)); res2 = gsasl_step64 (client, s2, &s1); gsasl_free (s2); if (res2 != GSASL_OK && res2 != GSASL_NEEDS_MORE) { fail ("gsasl_step64 (2) failed (%d):\n%s\n", res2, gsasl_strerror (res2)); return; } if (debug) printf ("C: %s [%c]\n", s1, ret_char (res2)); } while (res1 != GSASL_OK || res2 != GSASL_OK); if (s1) { gsasl_free (s1); s1 = NULL; } if (debug) printf ("\n"); gsasl_finish (client); gsasl_finish (server); } gsasl_done (ctx); }
void doit (void) { Gsasl_ctx *ctx = NULL; Gsasl_session_ctx *xctx = NULL; char output[MAX_LINE_LENGTH]; size_t outputlen; int i, j; int res; if (!gsasl_check_version (GSASL_VERSION)) fail ("gsasl_check_version failure"); success ("Header version %s library version %s\n", GSASL_VERSION, gsasl_check_version (NULL)); res = gsasl_init (&ctx); if (res != GSASL_OK) { fail ("gsasl_init() failed (%d):\n%s\n", res, gsasl_strerror (res)); return; } gsasl_client_callback_authentication_id_set (ctx, client_callback_authentication_id); gsasl_client_callback_authorization_id_set (ctx, client_callback_authorization_id); gsasl_client_callback_password_set (ctx, client_callback_password); gsasl_server_callback_validate_set (ctx, server_callback_validate); gsasl_server_callback_retrieve_set (ctx, server_callback_retrieve); gsasl_client_callback_service_set (ctx, client_callback_service); gsasl_client_callback_anonymous_set (ctx, client_callback_anonymous); gsasl_server_callback_anonymous_set (ctx, server_callback_anonymous); gsasl_server_callback_external_set (ctx, server_callback_external); gsasl_client_callback_passcode_set (ctx, client_callback_passcode); gsasl_client_callback_pin_set (ctx, client_callback_pin); gsasl_server_callback_securid_set (ctx, server_callback_securid); outputlen = sizeof (output); res = gsasl_client_listmech (ctx, output, &outputlen); if (res != GSASL_OK) fail ("gsasl_client_listmech() failed (%d):\n%s\n", res, gsasl_strerror (res)); outputlen = sizeof (output); res = gsasl_server_listmech (ctx, output, &outputlen); if (res != GSASL_OK) fail ("gsasl_server_listmech() failed (%d):\n%s\n", res, gsasl_strerror (res)); for (i = 0; i < sizeof (sasltv) / sizeof (sasltv[0]); i++) { gsasl_application_data_set (ctx, &i); if (debug) printf ("Entry %d %s mechanism %s:\n", i, sasltv[i].clientp ? "client" : "server", sasltv[i].mech); if (sasltv[i].clientp) res = gsasl_client_support_p (ctx, sasltv[i].mech); else res = gsasl_server_support_p (ctx, sasltv[i].mech); if (!res) continue; if (sasltv[i].clientp) res = gsasl_client_start (ctx, sasltv[i].mech, &xctx); else res = gsasl_server_start (ctx, sasltv[i].mech, &xctx); if (res != GSASL_OK) { fail ("SASL %s start for mechanism %s failed (%d):\n%s\n", sasltv[i].clientp ? "client" : "server", sasltv[i].mech, res, gsasl_strerror (res)); continue; } for (j = 0; sasltv[i].step[j]; j += 2) { if (sasltv[i].clientp) gsasl_client_application_data_set (xctx, &j); else gsasl_server_application_data_set (xctx, &j); if (debug) printf ("Input : %s\n", sasltv[i].step[j] ? sasltv[i].step[j] : ""); output[0] = '\0'; outputlen = sizeof (output); if (sasltv[i].clientp) res = gsasl_client_step_base64 (xctx, sasltv[i].step[j], output, outputlen); else res = gsasl_server_step_base64 (xctx, sasltv[i].step[j], output, outputlen); if (debug) printf ("Output: %s\n", output); if (res != GSASL_OK && res != GSASL_NEEDS_MORE) break; if (strlen (output) != strlen (sasltv[i].step[j + 1] ? sasltv[i].step[j + 1] : "")) { printf ("Expected: %s\n", sasltv[i].step[j + 1] ? sasltv[i].step[j + 1] : ""); fail ("SASL entry %d mechanism %s client step %d length error\n", i, sasltv[i].mech, j); j = -1; break; } if (strcmp (output, sasltv[i].step[j + 1] ? sasltv[i].step[j + 1] : "") != 0) { printf ("Expected: %s\n", sasltv[i].step[j + 1] ? sasltv[i].step[j + 1] : ""); fail ("SASL entry %d mechanism %s client step %d data error\n", i, sasltv[i].mech, j); j = -1; break; } if (strcmp (sasltv[i].mech, "SECURID") != 0 && res == GSASL_OK) break; } if (j != (size_t) - 1 && res == GSASL_OK && sasltv[i].step[j + 2]) fail ("SASL entry %d mechanism %s step %d code ended prematurely\n", i, sasltv[i].mech, j); else if (j != (size_t) - 1 && res == GSASL_NEEDS_MORE) fail ("SASL entry %d mechanism %s step %d table ended prematurely\n", i, sasltv[i].mech, j); else if (j != (size_t) - 1 && res != GSASL_OK) fail ("SASL entry %d mechanism %s step %d failed (%d):\n%s\n", i, sasltv[i].mech, j, res, gsasl_strerror (res)); else printf ("PASS: simple %s %s %d\n", sasltv[i].mech, sasltv[i].clientp ? "client" : "server", i); if (sasltv[i].clientp) gsasl_client_finish (xctx); else gsasl_server_finish (xctx); if (debug) printf ("\n"); } gsasl_done (ctx); }
bool SASLMechanismFactory::isMechanismSupported(const string& name) const { return (gsasl_client_support_p(m_gsaslContext, name.c_str()) != 0 || m_mechs.find(name) != m_mechs.end()); }
void doit (void) { Gsasl *ctx = NULL; Gsasl_session *sctx = NULL; char *out = NULL; int i, j; int res; if (!gsasl_check_version (GSASL_VERSION)) fail ("gsasl_check_version failure"); success ("Header version %s library version %s\n", GSASL_VERSION, gsasl_check_version (NULL)); res = gsasl_init (&ctx); if (res != GSASL_OK) { fail ("gsasl_init() failed (%d):\n%s\n", res, gsasl_strerror (res)); return; } gsasl_callback_set (ctx, cb); res = gsasl_client_mechlist (ctx, &out); if (res != GSASL_OK) fail ("gsasl_client_mechlist() failed (%d):\n%s\n", res, gsasl_strerror (res)); success ("client_mechlist: %s\n", out); gsasl_free (out); out = NULL; res = gsasl_server_mechlist (ctx, &out); if (res != GSASL_OK) fail ("gsasl_server_mechlist() failed (%d):\n%s\n", res, gsasl_strerror (res)); success ("server_mechlist: %s\n", out); gsasl_free (out); out = NULL; for (i = 0; i < sizeof (sasltv) / sizeof (sasltv[0]); i++) { gsasl_callback_hook_set (ctx, &i); if (debug) printf ("Entry %d %s mechanism %s:\n", i, sasltv[i].clientp ? "client" : "server", sasltv[i].mech); if (sasltv[i].clientp) res = gsasl_client_support_p (ctx, sasltv[i].mech); else res = gsasl_server_support_p (ctx, sasltv[i].mech); if (!res) continue; if (sasltv[i].clientp) res = gsasl_client_start (ctx, sasltv[i].mech, &sctx); else res = gsasl_server_start (ctx, sasltv[i].mech, &sctx); if (res != GSASL_OK) { fail ("SASL %s start for mechanism %s failed (%d):\n%s\n", sasltv[i].clientp ? "client" : "server", sasltv[i].mech, res, gsasl_strerror (res)); continue; } for (j = 0; sasltv[i].step[j]; j += 2) { gsasl_session_hook_set (sctx, &j); if (debug) printf ("Input : %s\n", sasltv[i].step[j] ? sasltv[i].step[j] : ""); res = gsasl_step64 (sctx, sasltv[i].step[j], &out); if (debug) printf ("Output: %s\n", out ? out : "(null)"); if (res != GSASL_OK && res != GSASL_NEEDS_MORE) { fail ("gsasl_step64 failed (%d): %s", res, gsasl_strerror (res)); break; } if (strlen (out) != strlen (sasltv[i].step[j + 1] ? sasltv[i].step[j + 1] : "")) { printf ("Expected: %s\n", sasltv[i].step[j + 1] ? sasltv[i].step[j + 1] : ""); fail ("SASL entry %d mechanism %s client step %d length error\n", i, sasltv[i].mech, j); j = -1; break; } if (strcmp (out, sasltv[i].step[j + 1] ? sasltv[i].step[j + 1] : "") != 0) { printf ("Expected: %s\n", sasltv[i].step[j + 1] ? sasltv[i].step[j + 1] : ""); fail ("SASL entry %d mechanism %s client step %d data error\n", i, sasltv[i].mech, j); j = -1; break; } gsasl_free (out); out = NULL; if (strcmp (sasltv[i].mech, "SECURID") != 0 && res == GSASL_OK) break; } if (j != (size_t) - 1 && res == GSASL_OK && sasltv[i].step[j + 2]) fail ("SASL entry %d mechanism %s step %d code ended prematurely\n", i, sasltv[i].mech, j); else if (j != (size_t) - 1 && res == GSASL_NEEDS_MORE) fail ("SASL entry %d mechanism %s step %d table ended prematurely\n", i, sasltv[i].mech, j); else if (j != (size_t) - 1 && res != GSASL_OK) fail ("SASL entry %d mechanism %s step %d failed (%d):\n%s\n", i, sasltv[i].mech, j, res, gsasl_strerror (res)); else printf ("PASS: simple %s %s %d\n", sasltv[i].mech, sasltv[i].clientp ? "client" : "server", i); { size_t outlen; res = gsasl_encode (sctx, "foo", 3, &out, &outlen); if (res != GSASL_OK) fail ("gsasl_encode %d: %s\n", res, gsasl_strerror (res)); if (outlen != 3 && memcmp (out, "foo", outlen) != 0) fail ("gsasl_encode memcmp: %.*s\n", (int) outlen, out); gsasl_free (out); out = NULL; res = gsasl_decode (sctx, "foo", 3, &out, &outlen); if (res != GSASL_OK) fail ("gsasl_decode %d: %s\n", res, gsasl_strerror (res)); if (outlen != 3 && memcmp (out, "foo", outlen) != 0) fail ("gsasl_decode memcmp: %.*s\n", (int) outlen, out); gsasl_free (out); out = NULL; } gsasl_finish (sctx); if (debug) printf ("\n"); } gsasl_done (ctx); /* Sanity check interfaces. */ gsasl_finish (NULL); gsasl_done (NULL); }