version 1.20, 2000/06/20 01:39:38 |
version 1.21, 2000/06/26 09:22:29 |
|
|
|
|
#include <openssl/rsa.h> |
#include <openssl/rsa.h> |
|
|
|
/* helper */ |
|
int ssh_agent_get_reply(AuthenticationConnection *auth); |
|
|
/* Returns the number of the authentication fd, or -1 if there is none. */ |
/* Returns the number of the authentication fd, or -1 if there is none. */ |
|
|
int |
int |
|
|
{ |
{ |
Buffer buffer; |
Buffer buffer; |
unsigned char buf[8192]; |
unsigned char buf[8192]; |
int len, l, type; |
int len; |
|
|
/* Format a message to the agent. */ |
/* Format a message to the agent. */ |
buffer_init(&buffer); |
buffer_init(&buffer); |
|
|
atomicio(write, auth->fd, buffer_ptr(&buffer), |
atomicio(write, auth->fd, buffer_ptr(&buffer), |
buffer_len(&buffer)) != buffer_len(&buffer)) { |
buffer_len(&buffer)) != buffer_len(&buffer)) { |
error("Error writing to authentication socket."); |
error("Error writing to authentication socket."); |
error_cleanup: |
|
buffer_free(&buffer); |
buffer_free(&buffer); |
return 0; |
return 0; |
} |
} |
/* Wait for response from the agent. First read the length of the |
buffer_free(&buffer); |
response packet. */ |
return ssh_agent_get_reply(auth); |
len = 4; |
|
while (len > 0) { |
|
l = read(auth->fd, buf + 4 - len, len); |
|
if (l <= 0) { |
|
error("Error reading response length from authentication socket."); |
|
goto error_cleanup; |
|
} |
|
len -= l; |
|
} |
|
|
|
/* Extract the length, and check it for sanity. */ |
|
len = GET_32BIT(buf); |
|
if (len > 256 * 1024) |
|
fatal("Add identity response too long: %d", len); |
|
|
|
/* Read the rest of the response in tothe buffer. */ |
|
buffer_clear(&buffer); |
|
while (len > 0) { |
|
l = len; |
|
if (l > sizeof(buf)) |
|
l = sizeof(buf); |
|
l = read(auth->fd, buf, l); |
|
if (l <= 0) { |
|
error("Error reading response from authentication socket."); |
|
goto error_cleanup; |
|
} |
|
buffer_append(&buffer, (char *) buf, l); |
|
len -= l; |
|
} |
|
|
|
/* Get the type of the packet. */ |
|
type = buffer_get_char(&buffer); |
|
switch (type) { |
|
case SSH_AGENT_FAILURE: |
|
buffer_free(&buffer); |
|
return 0; |
|
case SSH_AGENT_SUCCESS: |
|
buffer_free(&buffer); |
|
return 1; |
|
default: |
|
fatal("Bad response to add identity from authentication agent: %d", |
|
type); |
|
} |
|
/* NOTREACHED */ |
|
return 0; |
|
} |
} |
|
|
/* |
/* |
|
|
ssh_remove_identity(AuthenticationConnection *auth, RSA *key) |
ssh_remove_identity(AuthenticationConnection *auth, RSA *key) |
{ |
{ |
Buffer buffer; |
Buffer buffer; |
unsigned char buf[8192]; |
unsigned char buf[5]; |
int len, l, type; |
int len; |
|
|
/* Format a message to the agent. */ |
/* Format a message to the agent. */ |
buffer_init(&buffer); |
buffer_init(&buffer); |
|
|
atomicio(write, auth->fd, buffer_ptr(&buffer), |
atomicio(write, auth->fd, buffer_ptr(&buffer), |
buffer_len(&buffer)) != buffer_len(&buffer)) { |
buffer_len(&buffer)) != buffer_len(&buffer)) { |
error("Error writing to authentication socket."); |
error("Error writing to authentication socket."); |
error_cleanup: |
|
buffer_free(&buffer); |
buffer_free(&buffer); |
return 0; |
return 0; |
} |
} |
/* |
buffer_free(&buffer); |
* Wait for response from the agent. First read the length of the |
return ssh_agent_get_reply(auth); |
* response packet. |
|
*/ |
|
len = 4; |
|
while (len > 0) { |
|
l = read(auth->fd, buf + 4 - len, len); |
|
if (l <= 0) { |
|
error("Error reading response length from authentication socket."); |
|
goto error_cleanup; |
|
} |
|
len -= l; |
|
} |
|
|
|
/* Extract the length, and check it for sanity. */ |
|
len = GET_32BIT(buf); |
|
if (len > 256 * 1024) |
|
fatal("Remove identity response too long: %d", len); |
|
|
|
/* Read the rest of the response in tothe buffer. */ |
|
buffer_clear(&buffer); |
|
while (len > 0) { |
|
l = len; |
|
if (l > sizeof(buf)) |
|
l = sizeof(buf); |
|
l = read(auth->fd, buf, l); |
|
if (l <= 0) { |
|
error("Error reading response from authentication socket."); |
|
goto error_cleanup; |
|
} |
|
buffer_append(&buffer, (char *) buf, l); |
|
len -= l; |
|
} |
|
|
|
/* Get the type of the packet. */ |
|
type = buffer_get_char(&buffer); |
|
switch (type) { |
|
case SSH_AGENT_FAILURE: |
|
buffer_free(&buffer); |
|
return 0; |
|
case SSH_AGENT_SUCCESS: |
|
buffer_free(&buffer); |
|
return 1; |
|
default: |
|
fatal("Bad response to remove identity from authentication agent: %d", |
|
type); |
|
} |
|
/* NOTREACHED */ |
|
return 0; |
|
} |
} |
|
|
/* |
/* |
|
|
int |
int |
ssh_remove_all_identities(AuthenticationConnection *auth) |
ssh_remove_all_identities(AuthenticationConnection *auth) |
{ |
{ |
Buffer buffer; |
unsigned char buf[5]; |
unsigned char buf[8192]; |
|
int len, l, type; |
|
|
|
/* Get the length of the message, and format it in the buffer. */ |
/* Get the length of the message, and format it in the buffer. */ |
PUT_32BIT(buf, 1); |
PUT_32BIT(buf, 1); |
|
|
error("Error writing to authentication socket."); |
error("Error writing to authentication socket."); |
return 0; |
return 0; |
} |
} |
|
return ssh_agent_get_reply(auth); |
|
} |
|
|
|
/* |
|
* Read for reply from agent. returns 1 for success, 0 on error |
|
*/ |
|
|
|
int |
|
ssh_agent_get_reply(AuthenticationConnection *auth) |
|
{ |
|
Buffer buffer; |
|
unsigned char buf[8192]; |
|
int len, l, type; |
|
|
/* |
/* |
* Wait for response from the agent. First read the length of the |
* Wait for response from the agent. First read the length of the |
* response packet. |
* response packet. |
|
|
l = read(auth->fd, buf + 4 - len, len); |
l = read(auth->fd, buf + 4 - len, len); |
if (l <= 0) { |
if (l <= 0) { |
error("Error reading response length from authentication socket."); |
error("Error reading response length from authentication socket."); |
|
buffer_free(&buffer); |
return 0; |
return 0; |
} |
} |
len -= l; |
len -= l; |
|
|
/* Extract the length, and check it for sanity. */ |
/* Extract the length, and check it for sanity. */ |
len = GET_32BIT(buf); |
len = GET_32BIT(buf); |
if (len > 256 * 1024) |
if (len > 256 * 1024) |
fatal("Remove identity response too long: %d", len); |
fatal("Response from agent too long: %d", len); |
|
|
/* Read the rest of the response into the buffer. */ |
/* Read the rest of the response in to the buffer. */ |
buffer_init(&buffer); |
buffer_init(&buffer); |
while (len > 0) { |
while (len > 0) { |
l = len; |
l = len; |
|
|
|
|
/* Get the type of the packet. */ |
/* Get the type of the packet. */ |
type = buffer_get_char(&buffer); |
type = buffer_get_char(&buffer); |
|
buffer_free(&buffer); |
switch (type) { |
switch (type) { |
case SSH_AGENT_FAILURE: |
case SSH_AGENT_FAILURE: |
buffer_free(&buffer); |
|
return 0; |
return 0; |
case SSH_AGENT_SUCCESS: |
case SSH_AGENT_SUCCESS: |
buffer_free(&buffer); |
|
return 1; |
return 1; |
default: |
default: |
fatal("Bad response to remove identity from authentication agent: %d", |
fatal("Bad response from authentication agent: %d", type); |
type); |
|
} |
} |
/* NOTREACHED */ |
/* NOTREACHED */ |
return 0; |
return 0; |