⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 在卡片上管理密码的工具。密码被标注并集体加密存储在卡片上。因此这是一个安全存储密码的方法
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * GNU POC (passwords on card) - manage passwords on smartcards * Copyright (C) 2001 Henning Koester <henning@crackinghacking.de> * * Please report bugs to bug-poc@gnu.org * * This file is part of POC. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *//* $Id: main.c,v 1.9 2001/08/18 15:41:35 henning Exp henning $ */#include <config.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <ctype.h>#include <getopt.h>#include "lang.h"#include "cipher.h"#include "poc.h"#include "poc_types.h"#include "backup_card.h"#include "change.h"#include "format.h"#include "password.h"#include "misc.h"/* Available ciphers. */static char CIPHERS[] = "AES, BLOWFISH, plaintext";/****************************************************************************** * * Function    : usage * * Description : This function gives the user an overview about the available *               options. * * Input       : [1] progname (char) *                   The program's name (argv[0]). * * Return      : 1 * *****************************************************************************/static void usage(const char * const progname) {  printf("GNU %s version %s\n", PACKAGE, VERSION);  printf("Copyright (C) 2001 Henning Koester <henning@crackinghacking.de>\n");  printf("This program comes with ABSOLUTELY NO WARRANTY.\n");  printf("This is free software, and you are welcome to redistribute it\n");  printf("under certain conditions. See the file COPYING for details.\n\n");  printf("CIPHER: %s\n", CIPHERS);  printf("Usage: %s [COMMAND] [OPTION]\n", progname);  printf("\nCommands:\n");  printf("     --backup=FILE        backup the card to FILE\n");  printf(" -c, --change-cardkey     change cardkey\n");  printf(" -f, --format-card        format card\n");  printf(" -l DESCRIPTION, --list-password=DESCRIPTION\n");  printf("                          list the password with the given description\n");  printf("                          if DESCRIPTION is 'all' then all passwords\n");  printf(" -s, --save-password      save a password\n");  printf(" -r DESCRIPTION, --remove-password=DESCRIPTION\n");  printf("                          remove the password with the given description\n");  printf("     --restore=FILE       restore a backuped card from FILE\n");  printf("\nStandard Commands:\n");  printf(" -h, --help               print this message and exit\n");  printf(" -V, --version            display the program version\n");	  printf("\nOptions:\n");  printf("     --cipher=CIPHER      cipher for enciphering the card\n");  printf("                          CIPHER can be one of the above, or 'plaintext'\n");  printf("                          if not specified, 'AES' will be used\n");  printf(" -p NUM, --port=NUM       com-port (NUM = 1...4)\n");  printf("     --security=LEVEL     security level can be 1(normal), 2(high)\n");  printf(" -v, --verbose            be verbose\n");  printf("\nReport bugs to <bug-poc@gnu.org>\n");  exit(1);}/****************************************************************************** * * Function    : print_version * * Description : This function prints the programs version along with a  *               copyright notice. * * Input       : none * * Return      : none * *****************************************************************************/static void print_version(void) {  printf("GNU %s version %s\n", PACKAGE, VERSION);  printf("Copyright (C) 2001 Henning Koester <henning@crackinghacking.de>\n");  printf("This program comes with ABSOLUTELY NO WARRANTY.\n");  printf("This is free software, and you are welcome to redistribute it\n");  printf("under certain conditions. See the file COPYING for details.\n\n");}/****************************************************************************** * * Function    : get_name * * Description : This function checks whether 'data' contains one of name's  *               elements. Used to test whether the user has selected an  *               available cipher. * * Input       : [1] data (char) *               [2] names (char) * * Return      : Pointer to the appropriate element in names, or NULL if *               'data' wasn't found in 'names'. * *****************************************************************************/static char *get_name(const char * const data, char * const names) {  char *p;                 /* Used to split 'names' with strtok(3). */  p = strtok(names, " ");  /* Get first value of 'names'. */  /* Loop, to check every element element of 'names'. */  while (p != NULL) {    /* Remove the comma at the end, if necessary. */    if (p[strlen(p) - 1] == ',')      p[strlen(p) - 1] = '\0';    /* Check whether p (selected element of 'names') is equal to 'data'. */    if (strcasecmp(p, data) == 0)       return(p);   /* Return the pointer to the correct element of 'names'. */    p = strtok(NULL, " ");   /* Get next element. */  }  /* 'data' wasn't found in 'names', so we'll return NULL. */  return(NULL);}/****************************************************************************** * * Function    : check_crypto_settings * * Description : This function checks whether the user has selected cipher  *               and/or security-level settings. The function will set *               default settings if the user didn't force special settings. * * Input       : [1] card_crypt_ctx (char) *                   Information about data encryption (cipher, security-level) * * Return      : nothing is returned. * *****************************************************************************/static voidcheck_crypto_settings(crypt_context * const card_crypt_ctx) {  /*    * Check the cipher settings.   *   * If the user didn't select a cipher with the --cipher option, we   * will check whether the environment variable specifies one.   */  if ((card_crypt_ctx->cipher == NULL) && (getenv(ENV_CIPHER) != NULL)) {        /*      * Found environment variable.     * Now check whether it's a valid cipher.     */    if ( (card_crypt_ctx->cipher = get_name(getenv(ENV_CIPHER), CIPHERS)) ==	 NULL) {      /* No valid cipher. Print an error and exit. */      print_err(STR_WRONG_CIPHER_ENV);      exit(1);    }  } else          /*      * Neither the --cipher options specified a cipher, nor the environment     * variable. So we will use the default, namely 'AES'.     */    card_crypt_ctx->cipher = "AES";    /*   * Check for security level settings.   *   * If the user didn't select a security level with the --security option,   * we will check whether the environment variable specifies one.   */    if ((card_crypt_ctx->sec_level == 0) && (getenv(ENV_SL) != NULL)) {    /*     * Found environment variable.     * Check whether it's valid.     */    if ((atoi(getenv(ENV_SL)) != SL_NORMAL) && 	(atoi(getenv(ENV_SL)) != SL_HIGH)) {      /* Invalid security-level setting. Print error and exit. */      print_err(STR_WRONG_SEC_LEVEL_ENV);      exit(1);    } else {   /* Valid setting. */      card_crypt_ctx->sec_level = atoi(getenv(ENV_SL));      return;    }  }  if (card_crypt_ctx->sec_level != 0)    return;    /* Use the default security-level. */  card_crypt_ctx->sec_level = SL_NORMAL;}/* Program's name */char *progname;/*************** *** OPTIONS *** ***************//* 1 means: make a backup          */static bool backup_card_flg      = 0;/* 1 means: change card's key      */static bool change_cardkey_flg   = 0;/* 1 means: format card            */static bool format_card_flg      = 0;/* 1 means: list password(s)       */static bool list_password_flg    = 0;/* 1 means: save a new password to the card */static bool save_password_flg    = 0;/* 1 means: remove a password from the card */static bool remove_password_flg  = 0;/* 1 means: restore a backuped card */static bool restore_card_flg     = 0;/* Give more information output    */bool verbose_flg                 = 0;/* Information on data encryption. */static crypt_context card_crypt_ctx;/* Description contains the description of the password which should be    listet (if the -l, --list-password option was set) or the description   of the password which should be removed (-r, --remove-password). */static char description[DESCR_LENGTH];/* File contains the file to which the card will be backup or from which   the card will be restored. */static char file[FILENAME_MAX];

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -