5 Author: Tatu Ylonen <ylo@cs.hut.fi>
7 Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
10 Created: Thu Apr 6 00:52:24 1995 ylo
12 Adds an identity to the authentication server, or removes an identity.
25 delete_file(AuthenticationConnection *ac, const char *filename)
31 if (!load_public_key(filename, key, &comment))
33 printf("Bad key file %s: %s\n", filename, strerror(errno));
37 if (ssh_remove_identity(ac, key))
38 fprintf(stderr, "Identity removed: %s (%s)\n", filename, comment);
40 fprintf(stderr, "Could not remove identity: %s\n", filename);
46 delete_all(AuthenticationConnection *ac)
48 /* Send a request to remove all identities. */
49 if (ssh_remove_all_identities(ac))
50 fprintf(stderr, "All identities removed.\n");
52 fprintf(stderr, "Failed to remove all identitities.\n");
56 add_file(AuthenticationConnection *ac, const char *filename)
60 char *saved_comment, *comment, *pass;
64 public_key = RSA_new();
65 if (!load_public_key(filename, public_key, &saved_comment))
67 printf("Bad key file %s: %s\n", filename, strerror(errno));
74 while (!load_private_key(filename, pass, key, &comment))
76 /* Free the old passphrase. */
77 memset(pass, 0, strlen(pass));
80 /* Ask for a passphrase. */
81 if (getenv("DISPLAY") && !isatty(fileno(stdin)))
89 printf("Need passphrase for %s (%s).\n", filename, saved_comment);
91 printf("Bad passphrase.\n");
92 pass = read_passphrase("Enter passphrase: ", 1);
93 if (strcmp(pass, "") == 0)
102 memset(pass, 0, strlen(pass));
105 xfree(saved_comment);
107 if (ssh_add_identity(ac, key, comment))
108 fprintf(stderr, "Identity added: %s (%s)\n", filename, comment);
110 fprintf(stderr, "Could not add identity: %s\n", filename);
116 list_identities(AuthenticationConnection *ac)
126 for (status = ssh_get_first_identity(ac, &bits, e, n, &comment);
128 status = ssh_get_next_identity(ac, &bits, e, n, &comment))
139 printf("%s %s\n", buf, comment);
146 printf("The agent has no identities.\n");
150 main(int argc, char **argv)
152 AuthenticationConnection *ac = NULL;
159 /* check if RSA support exists */
160 if (rsa_alive() == 0) {
161 extern char *__progname;
164 "%s: no RSA support in libssl and libcrypto. See ssl(8).\n",
169 /* At first, get a connection to the authentication agent. */
170 ac = ssh_get_authentication_connection();
172 fprintf(stderr, "Could not open a connection to your authentication agent.\n");
176 for (i = 1; i < argc; i++)
178 if (strcmp(argv[i], "-l") == 0)
181 no_files = 0; /* Don't default-add/delete if -l. */
184 if (strcmp(argv[i], "-d") == 0)
189 if (strcmp(argv[i], "-D") == 0)
197 delete_file(ac, argv[i]);
199 add_file(ac, argv[i]);
203 pw = getpwuid(getuid());
206 fprintf(stderr, "No user found with uid %d\n", (int)getuid());
207 ssh_close_authentication_connection(ac);
210 snprintf(buf, sizeof buf, "%s/%s", pw->pw_dir, SSH_CLIENT_IDENTITY);
212 delete_file(ac, buf);
216 ssh_close_authentication_connection(ac);