X-Git-Url: http://git.silcnet.org/gitweb/?a=blobdiff_plain;f=apps%2Fsilc%2Fclientutil.c;h=71b628bc4aacf7d35d8b689140700ef790cd3ce6;hb=a818c5b5411bbc4436d1c5f011236985c96bb787;hp=6834916a62bcbde683a1cc52c00c0000fd64674f;hpb=2f8b86e0ca6551ed22ca1de45558b0bf93ab3470;p=silc.git diff --git a/apps/silc/clientutil.c b/apps/silc/clientutil.c index 6834916a..71b628bc 100644 --- a/apps/silc/clientutil.c +++ b/apps/silc/clientutil.c @@ -124,53 +124,6 @@ int silc_get_number_of_emails() return num; } -/* Returns the username of the user. If the global variable LOGNAME - does not exists we will get the name from the password file. */ - -char *silc_get_username() -{ - char *logname = NULL; - - logname = strdup(getenv("LOGNAME")); - if (!logname) { - logname = getlogin(); - if (!logname) { - struct passwd *pw; - - pw = getpwuid(getuid()); - if (!pw) { - fprintf(stderr, "silc_get_username: %s\n", strerror(errno)); - return NULL; - } - - logname = strdup(pw->pw_name); - } - } - - return logname; -} - -/* Returns the real name of ther user. */ - -char *silc_get_real_name() -{ - char *realname = NULL; - struct passwd *pw; - - pw = getpwuid(getuid()); - if (!pw) { - fprintf(stderr, "silc_get_username: %s\n", strerror(errno)); - return NULL; - } - - if (strchr(pw->pw_gecos, ',')) - *strchr(pw->pw_gecos, ',') = 0; - - realname = strdup(pw->pw_gecos); - - return realname; -} - /* Returns time til next minute changes. Used to update the clock when needed. */ @@ -226,21 +179,27 @@ int silc_client_ask_yes_no(SilcClient client, char *prompt) void silc_client_list_ciphers() { - + char *ciphers = silc_cipher_get_supported(); + fprintf(stdout, "%s\n", ciphers); + silc_free(ciphers); } /* Lists supported (builtin) hash functions */ void silc_client_list_hash_funcs() { - + char *hash = silc_hash_get_supported(); + fprintf(stdout, "%s\n", hash); + silc_free(hash); } /* Lists supported PKCS algorithms */ void silc_client_list_pkcs() { - + char *pkcs = silc_pkcs_get_supported(); + fprintf(stdout, "%s\n", pkcs); + silc_free(pkcs); } /* Displays input prompt on command line and takes input data from user */ @@ -374,7 +333,7 @@ int silc_client_create_key_pair(char *pkcs_name, int bits, SilcPrivateKey prv_key; SilcRng rng; unsigned char *key; - unsigned int key_len; + SilcUInt32 key_len; char line[256]; char *pkfile = NULL, *prvfile = NULL; @@ -398,7 +357,7 @@ New pair of keys will be created. Please, answer to following questions.\n\ } if (!silc_pkcs_is_supported(pkcs_name)) { - fprintf(stderr, "Unsupported PKCS `%s'", pkcs_name); + fprintf(stderr, "Unknown PKCS `%s'", pkcs_name); return FALSE; } @@ -482,7 +441,7 @@ New pair of keys will be created. Please, answer to following questions.\n\ if (ret_prv_key) *ret_prv_key = prv_key; - printf("Public key has been save into `%s'.\n", pkfile); + printf("Public key has been saved into `%s'.\n", pkfile); printf("Private key has been saved into `%s'.\n", prvfile); printf("Press to continue...\n"); getchar(); @@ -752,3 +711,61 @@ int silc_client_load_keys(SilcClient client) return TRUE; } + +/* Dumps the public key on screen. Used from the command line option. */ + +int silc_client_show_key(char *keyfile) +{ + SilcPublicKey public_key; + SilcPublicKeyIdentifier ident; + char *fingerprint; + unsigned char *pk; + SilcUInt32 pk_len; + SilcPKCS pkcs; + int key_len = 0; + + if (silc_pkcs_load_public_key(keyfile, &public_key, + SILC_PKCS_FILE_PEM) == FALSE) + if (silc_pkcs_load_public_key(keyfile, &public_key, + SILC_PKCS_FILE_BIN) == FALSE) { + fprintf(stderr, "Could not load public key file `%s'\n", keyfile); + return FALSE; + } + + ident = silc_pkcs_decode_identifier(public_key->identifier); + + pk = silc_pkcs_public_key_encode(public_key, &pk_len); + fingerprint = silc_hash_fingerprint(NULL, pk, pk_len); + + if (silc_pkcs_alloc(public_key->name, &pkcs)) { + key_len = silc_pkcs_public_key_set(pkcs, public_key); + silc_pkcs_free(pkcs); + } + + printf("Public key file : %s\n", keyfile); + printf("Algorithm : %s\n", public_key->name); + if (key_len) + printf("Key length (bits) : %d\n", key_len); + if (ident->realname) + printf("Real name : %s\n", ident->realname); + if (ident->username) + printf("Username : %s\n", ident->username); + if (ident->host) + printf("Hostname : %s\n", ident->host); + if (ident->email) + printf("Email : %s\n", ident->email); + if (ident->org) + printf("Organization : %s\n", ident->org); + if (ident->country) + printf("Country : %s\n", ident->country); + printf("Fingerprint (SHA1) : %s\n", fingerprint); + + fflush(stdout); + + silc_free(fingerprint); + silc_free(pk); + silc_pkcs_public_key_free(public_key); + silc_pkcs_free_identifier(ident); + + return TRUE; +}