- static int pwpkt_type;
- /*
- * Show password prompt, having first obtained it via a TIS
- * or CryptoCard exchange if we're doing TIS or CryptoCard
- * authentication.
- */
- pwpkt_type = SSH1_CMSG_AUTH_PASSWORD;
- if (agent_exists()) {
- /*
- * Attempt RSA authentication using Pageant.
- */
- static unsigned char request[5], *response, *p;
- static int responselen;
- static int i, nkeys;
- static int authed = FALSE;
- void *r;
-
- logevent("Pageant is running. Requesting keys.");
-
- /* Request the keys held by the agent. */
- PUT_32BIT(request, 1);
- request[4] = SSH1_AGENTC_REQUEST_RSA_IDENTITIES;
- agent_query(request, 5, &r, &responselen);
- response = (unsigned char *)r;
- if (response && responselen >= 5 &&
- response[4] == SSH1_AGENT_RSA_IDENTITIES_ANSWER) {
- p = response + 5;
- nkeys = GET_32BIT(p); p += 4;
- { char buf[64]; sprintf(buf, "Pageant has %d SSH1 keys", nkeys);
- logevent(buf); }
- for (i = 0; i < nkeys; i++) {
- static struct RSAKey key;
- static Bignum challenge;
- static char *commentp;
- static int commentlen;
-
- { char buf[64]; sprintf(buf, "Trying Pageant key #%d", i);
- logevent(buf); }
- p += 4;
- p += ssh1_read_bignum(p, &key.exponent);
- p += ssh1_read_bignum(p, &key.modulus);
- commentlen = GET_32BIT(p); p += 4;
- commentp = p; p += commentlen;
- send_packet(SSH1_CMSG_AUTH_RSA,
- PKT_BIGNUM, key.modulus, PKT_END);
- crWaitUntil(ispkt);
- if (pktin.type != SSH1_SMSG_AUTH_RSA_CHALLENGE) {
- logevent("Key refused");
- continue;
- }
- logevent("Received RSA challenge");
- ssh1_read_bignum(pktin.body, &challenge);
- {
- char *agentreq, *q, *ret;
- int len, retlen;
- len = 1 + 4; /* message type, bit count */
- len += ssh1_bignum_length(key.exponent);
- len += ssh1_bignum_length(key.modulus);
- len += ssh1_bignum_length(challenge);
- len += 16; /* session id */
- len += 4; /* response format */
- agentreq = smalloc(4 + len);
- PUT_32BIT(agentreq, len);
- q = agentreq + 4;
- *q++ = SSH1_AGENTC_RSA_CHALLENGE;
- PUT_32BIT(q, ssh1_bignum_bitcount(key.modulus));
- q += 4;
- q += ssh1_write_bignum(q, key.exponent);
- q += ssh1_write_bignum(q, key.modulus);
- q += ssh1_write_bignum(q, challenge);
- memcpy(q, session_id, 16); q += 16;
- PUT_32BIT(q, 1); /* response format */
- agent_query(agentreq, len+4, &ret, &retlen);
- sfree(agentreq);
- if (ret) {
- if (ret[4] == SSH1_AGENT_RSA_RESPONSE) {
- logevent("Sending Pageant's response");
- send_packet(SSH1_CMSG_AUTH_RSA_RESPONSE,
- PKT_DATA, ret+5, 16, PKT_END);
- sfree(ret);
- crWaitUntil(ispkt);
- if (pktin.type == SSH1_SMSG_SUCCESS) {
- logevent("Pageant's response accepted");
- if (flags & FLAG_VERBOSE) {
- c_write_str("Authenticated using RSA key \"");
- c_write(commentp, commentlen);
- c_write_str("\" from agent\r\n");
- }
- authed = TRUE;
- } else
- logevent("Pageant's response not accepted");
- } else {
- logevent("Pageant failed to answer challenge");
- sfree(ret);
- }
- } else {
- logevent("No reply received from Pageant");
- }
- }
- freebn(key.exponent);
- freebn(key.modulus);
- freebn(challenge);
- if (authed)
- break;
- }
- }
- if (authed)
- break;
- }
- if (*cfg.keyfile && !tried_publickey)
- pwpkt_type = SSH1_CMSG_AUTH_RSA;
-
- if (pktin.type == SSH1_SMSG_FAILURE &&
- cfg.try_tis_auth &&
- (supported_auths_mask & (1<<SSH1_AUTH_TIS))) {
- pwpkt_type = SSH1_CMSG_AUTH_TIS_RESPONSE;
- logevent("Requested TIS authentication");
- send_packet(SSH1_CMSG_AUTH_TIS, PKT_END);
- crWaitUntil(ispkt);
- if (pktin.type != SSH1_SMSG_AUTH_TIS_CHALLENGE) {
- logevent("TIS authentication declined");
- if (flags & FLAG_INTERACTIVE)
- c_write_str("TIS authentication refused.\r\n");
- } else {
- int challengelen = ((pktin.body[0] << 24) |
- (pktin.body[1] << 16) |
- (pktin.body[2] << 8) |
- (pktin.body[3]));
- logevent("Received TIS challenge");
- if (challengelen > sizeof(prompt)-1)
- challengelen = sizeof(prompt)-1; /* prevent overrun */
- memcpy(prompt, pktin.body+4, challengelen);
- prompt[challengelen] = '\0';
- }
- }
- if (pktin.type == SSH1_SMSG_FAILURE &&
- cfg.try_tis_auth &&
- (supported_auths_mask & (1<<SSH1_AUTH_CCARD))) {
- pwpkt_type = SSH1_CMSG_AUTH_CCARD_RESPONSE;
- logevent("Requested CryptoCard authentication");
- send_packet(SSH1_CMSG_AUTH_CCARD, PKT_END);
- crWaitUntil(ispkt);
- if (pktin.type != SSH1_SMSG_AUTH_CCARD_CHALLENGE) {
- logevent("CryptoCard authentication declined");
- c_write_str("CryptoCard authentication refused.\r\n");
- } else {
- int challengelen = ((pktin.body[0] << 24) |
- (pktin.body[1] << 16) |
- (pktin.body[2] << 8) |
- (pktin.body[3]));
- logevent("Received CryptoCard challenge");
- if (challengelen > sizeof(prompt)-1)
- challengelen = sizeof(prompt)-1; /* prevent overrun */
- memcpy(prompt, pktin.body+4, challengelen);
- strncpy(prompt + challengelen, "\r\nResponse : ",
- sizeof(prompt)-challengelen);
- prompt[sizeof(prompt)-1] = '\0';
- }
- }
- if (pwpkt_type == SSH1_CMSG_AUTH_PASSWORD) {
- sprintf(prompt, "%.90s@%.90s's password: ",
- username, savedhost);
- }
- if (pwpkt_type == SSH1_CMSG_AUTH_RSA) {
- char *comment = NULL;
- if (flags & FLAG_VERBOSE)
- c_write_str("Trying public key authentication.\r\n");
- if (!rsakey_encrypted(cfg.keyfile, &comment)) {
- if (flags & FLAG_VERBOSE)
- c_write_str("No passphrase required.\r\n");
- goto tryauth;
- }
- sprintf(prompt, "Passphrase for key \"%.100s\": ", comment);
- sfree(comment);
- }
+ static int pwpkt_type;
+ /*
+ * Show password prompt, having first obtained it via a TIS
+ * or CryptoCard exchange if we're doing TIS or CryptoCard
+ * authentication.
+ */
+ pwpkt_type = SSH1_CMSG_AUTH_PASSWORD;
+ if (agent_exists()) {
+ /*
+ * Attempt RSA authentication using Pageant.
+ */
+ static unsigned char request[5], *response, *p;
+ static int responselen;
+ static int i, nkeys;
+ static int authed = FALSE;
+ void *r;
+
+ logevent("Pageant is running. Requesting keys.");
+
+ /* Request the keys held by the agent. */
+ PUT_32BIT(request, 1);
+ request[4] = SSH1_AGENTC_REQUEST_RSA_IDENTITIES;
+ agent_query(request, 5, &r, &responselen);
+ response = (unsigned char *) r;
+ if (response && responselen >= 5 &&
+ response[4] == SSH1_AGENT_RSA_IDENTITIES_ANSWER) {
+ p = response + 5;
+ nkeys = GET_32BIT(p);
+ p += 4;
+ {
+ char buf[64];
+ sprintf(buf, "Pageant has %d SSH1 keys", nkeys);
+ logevent(buf);
+ }
+ for (i = 0; i < nkeys; i++) {
+ static struct RSAKey key;
+ static Bignum challenge;
+ static char *commentp;
+ static int commentlen;
+
+ {
+ char buf[64];
+ sprintf(buf, "Trying Pageant key #%d", i);
+ logevent(buf);
+ }
+ p += 4;
+ p += ssh1_read_bignum(p, &key.exponent);
+ p += ssh1_read_bignum(p, &key.modulus);
+ commentlen = GET_32BIT(p);
+ p += 4;
+ commentp = p;
+ p += commentlen;
+ send_packet(SSH1_CMSG_AUTH_RSA,
+ PKT_BIGNUM, key.modulus, PKT_END);
+ crWaitUntil(ispkt);
+ if (pktin.type != SSH1_SMSG_AUTH_RSA_CHALLENGE) {
+ logevent("Key refused");
+ continue;
+ }
+ logevent("Received RSA challenge");
+ ssh1_read_bignum(pktin.body, &challenge);
+ {
+ char *agentreq, *q, *ret;
+ void *vret;
+ int len, retlen;
+ len = 1 + 4; /* message type, bit count */
+ len += ssh1_bignum_length(key.exponent);
+ len += ssh1_bignum_length(key.modulus);
+ len += ssh1_bignum_length(challenge);
+ len += 16; /* session id */
+ len += 4; /* response format */
+ agentreq = smalloc(4 + len);
+ PUT_32BIT(agentreq, len);
+ q = agentreq + 4;
+ *q++ = SSH1_AGENTC_RSA_CHALLENGE;
+ PUT_32BIT(q, bignum_bitcount(key.modulus));
+ q += 4;
+ q += ssh1_write_bignum(q, key.exponent);
+ q += ssh1_write_bignum(q, key.modulus);
+ q += ssh1_write_bignum(q, challenge);
+ memcpy(q, session_id, 16);
+ q += 16;
+ PUT_32BIT(q, 1); /* response format */
+ agent_query(agentreq, len + 4, &vret, &retlen);
+ ret = vret;
+ sfree(agentreq);
+ if (ret) {
+ if (ret[4] == SSH1_AGENT_RSA_RESPONSE) {
+ logevent("Sending Pageant's response");
+ send_packet(SSH1_CMSG_AUTH_RSA_RESPONSE,
+ PKT_DATA, ret + 5, 16,
+ PKT_END);
+ sfree(ret);
+ crWaitUntil(ispkt);
+ if (pktin.type == SSH1_SMSG_SUCCESS) {
+ logevent
+ ("Pageant's response accepted");
+ if (flags & FLAG_VERBOSE) {
+ c_write_str
+ ("Authenticated using RSA key \"");
+ c_write(commentp, commentlen);
+ c_write_str("\" from agent\r\n");
+ }
+ authed = TRUE;
+ } else
+ logevent
+ ("Pageant's response not accepted");
+ } else {
+ logevent
+ ("Pageant failed to answer challenge");
+ sfree(ret);
+ }
+ } else {
+ logevent("No reply received from Pageant");
+ }
+ }
+ freebn(key.exponent);
+ freebn(key.modulus);
+ freebn(challenge);
+ if (authed)
+ break;
+ }
+ }
+ if (authed)
+ break;
+ }
+ if (*cfg.keyfile && !tried_publickey)
+ pwpkt_type = SSH1_CMSG_AUTH_RSA;
+
+ if (pktin.type == SSH1_SMSG_FAILURE &&
+ cfg.try_tis_auth &&
+ (supported_auths_mask & (1 << SSH1_AUTH_TIS))) {
+ pwpkt_type = SSH1_CMSG_AUTH_TIS_RESPONSE;
+ logevent("Requested TIS authentication");
+ send_packet(SSH1_CMSG_AUTH_TIS, PKT_END);
+ crWaitUntil(ispkt);
+ if (pktin.type != SSH1_SMSG_AUTH_TIS_CHALLENGE) {
+ logevent("TIS authentication declined");
+ if (flags & FLAG_INTERACTIVE)
+ c_write_str("TIS authentication refused.\r\n");
+ } else {
+ int challengelen = ((pktin.body[0] << 24) |
+ (pktin.body[1] << 16) |
+ (pktin.body[2] << 8) |
+ (pktin.body[3]));
+ logevent("Received TIS challenge");
+ if (challengelen > sizeof(prompt) - 1)
+ challengelen = sizeof(prompt) - 1; /* prevent overrun */
+ memcpy(prompt, pktin.body + 4, challengelen);
+ prompt[challengelen] = '\0';
+ }
+ }
+ if (pktin.type == SSH1_SMSG_FAILURE &&
+ cfg.try_tis_auth &&
+ (supported_auths_mask & (1 << SSH1_AUTH_CCARD))) {
+ pwpkt_type = SSH1_CMSG_AUTH_CCARD_RESPONSE;
+ logevent("Requested CryptoCard authentication");
+ send_packet(SSH1_CMSG_AUTH_CCARD, PKT_END);
+ crWaitUntil(ispkt);
+ if (pktin.type != SSH1_SMSG_AUTH_CCARD_CHALLENGE) {
+ logevent("CryptoCard authentication declined");
+ c_write_str("CryptoCard authentication refused.\r\n");
+ } else {
+ int challengelen = ((pktin.body[0] << 24) |
+ (pktin.body[1] << 16) |
+ (pktin.body[2] << 8) |
+ (pktin.body[3]));
+ logevent("Received CryptoCard challenge");
+ if (challengelen > sizeof(prompt) - 1)
+ challengelen = sizeof(prompt) - 1; /* prevent overrun */
+ memcpy(prompt, pktin.body + 4, challengelen);
+ strncpy(prompt + challengelen, "\r\nResponse : ",
+ sizeof(prompt) - challengelen);
+ prompt[sizeof(prompt) - 1] = '\0';
+ }
+ }
+ if (pwpkt_type == SSH1_CMSG_AUTH_PASSWORD) {
+ sprintf(prompt, "%.90s@%.90s's password: ",
+ username, savedhost);
+ }
+ if (pwpkt_type == SSH1_CMSG_AUTH_RSA) {
+ char *comment = NULL;
+ if (flags & FLAG_VERBOSE)
+ c_write_str("Trying public key authentication.\r\n");
+ if (!rsakey_encrypted(cfg.keyfile, &comment)) {
+ if (flags & FLAG_VERBOSE)
+ c_write_str("No passphrase required.\r\n");
+ goto tryauth;
+ }
+ sprintf(prompt, "Passphrase for key \"%.100s\": ", comment);
+ sfree(comment);
+ }