Exemple #1
0
int
main (int argc, char *argv[])
{
  int client_id;
  char *token, *url = NULL, *api_key = NULL;
  int ret;

  parse_args (argc, argv, &client_id, &token, &url, &api_key);

  /* Debug. */
  fprintf (stderr, "Input:\n");
  if (url)
    fprintf (stderr, "  validation URL: %s\n", url);
  fprintf (stderr, "  client id: %d\n", client_id);
  fprintf (stderr, "  token: %s\n", token);
  if (api_key != NULL)
    fprintf (stderr, "  api key: %s\n", api_key);

  ret =
    ykclient_verify_otp_v2 (NULL, token, client_id, NULL, 1,
			    (const char **) &url, api_key);

  printf ("Verification output (%d): %s\n", ret, ykclient_strerror (ret));

  if (ret != YKCLIENT_OK)
    return EXIT_FAILURE;

  return EXIT_SUCCESS;
}
Exemple #2
0
int
main (int argc, char *argv[])
{
  unsigned int client_id;
  char *token, *url = NULL, *ca = NULL, *api_key = NULL, *cai = NULL;
  int debug = 0;
  ykclient_rc ret;
  ykclient_t *ykc = NULL;

  parse_args (argc, argv, &client_id, &token, &url, &ca, &cai, &api_key,
	      &debug);

  if (ca || cai)
    {
      ret = ykclient_init (&ykc);
      if (ret != YKCLIENT_OK)
	return EXIT_FAILURE;
    }

  if (ca)
    {
      ykclient_set_ca_path (ykc, ca);
    }

  if (cai)
    {
      ykclient_set_ca_info (ykc, cai);
    }

  if (debug)
    {
      fprintf (stderr, "Input:\n");
      if (url)
	fprintf (stderr, "  validation URL: %s\n", url);
      if (ca)
	fprintf (stderr, "  CA Path: %s\n", ca);
      if (cai)
	fprintf (stderr, "  CA Info: %s\n", cai);
      fprintf (stderr, "  client id: %d\n", client_id);
      fprintf (stderr, "  token: %s\n", token);
      if (api_key != NULL)
	fprintf (stderr, "  api key: %s\n", api_key);
    }

  ret = ykclient_verify_otp_v2 (ykc, token, client_id, NULL, 1,
				(const char **) &url, api_key);

  if (debug)
    printf ("Verification output (%d): %s\n", ret, ykclient_strerror (ret));

  if (ret == YKCLIENT_REPLAYED_OTP)
    return 2;
  else if (ret != YKCLIENT_OK)
    return 3;

  return EXIT_SUCCESS;
}
Exemple #3
0
/*
 * Simple API to validate an OTP (hexkey) using the YubiCloud validation
 * service.
 */
int
ykclient_verify_otp (const char *yubikey_otp,
		     unsigned int client_id,
		     const char *hexkey)
{
  return ykclient_verify_otp_v2 (NULL,
				 yubikey_otp,
				 client_id,
				 hexkey,
				 0,
				 NULL,
				 NULL);
}
	virtual EModRet OnLoginAttempt(CSmartPtr<CAuthBase> Auth) {
		CString const sPassword = Auth->GetPassword();
		CUser *pUser = CZNC::Get().FindUser(Auth->GetUsername());

		if (pUser && CheckToken(pUser, sPassword.Left(DEFAULT_TOKEN_ID_LEN))) {
			DEBUG("yubikey: Lookup for " << sPassword.Left(DEFAULT_TOKEN_ID_LEN));
			// The following call is blocking.
			//int result = ykclient_verify_otp(sPassword.c_str(), CLIENT_ID, NULL);
			int result = ykclient_verify_otp_v2(NULL, sPassword.c_str(), CLIENT_ID, NULL, 0, NULL, NULL);
			DEBUG("yubikey: " << ykclient_strerror(result));

			if (result == YKCLIENT_OK) {
				Auth->AcceptLogin(*pUser);
			} else {
				Auth->RefuseLogin(ykclient_strerror(result));
			}

			return HALT;
		}

		return CONTINUE;
	}