Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-1-5]: src/crypto/dist/ssh Pull up revision 1.2 (requested by itoj...



details:   https://anonhg.NetBSD.org/src/rev/9ba954137180
branches:  netbsd-1-5
changeset: 490694:9ba954137180
user:      he <he%NetBSD.org@localhost>
date:      Mon Feb 26 20:26:20 2001 +0000

description:
Pull up revision 1.2 (requested by itojun):
  Update SSH to version found on trunk as of 26 Feb 2001.

diffstat:

 crypto/dist/ssh/atomicio.c |   72 ++++
 crypto/dist/ssh/authfd.c   |  571 ++++++++++++++++++++++++++++++++++++++
 crypto/dist/ssh/hostfile.c |  216 ++++++++++++++
 crypto/dist/ssh/key.c      |  666 +++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 1525 insertions(+), 0 deletions(-)

diffs (truncated from 1541 to 300 lines):

diff -r 9cce0dace44e -r 9ba954137180 crypto/dist/ssh/atomicio.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/crypto/dist/ssh/atomicio.c        Mon Feb 26 20:26:20 2001 +0000
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 1995,1999 Theo de Raadt
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "includes.h"
+RCSID("$OpenBSD: atomicio.c,v 1.8 2001/01/21 19:05:40 markus Exp $");
+
+#include "xmalloc.h"
+#include "atomicio.h"
+
+ssize_t
+atomic_read(int fd, void *v, size_t n)
+{
+       char *s = v;
+       ssize_t res, pos = 0;
+
+       while (n > pos) {
+               res = read(fd, s + pos, n - pos);
+               switch (res) {
+               case -1:
+                       if (errno == EINTR || errno == EAGAIN)
+                               continue;
+               case 0:
+                       return (res);
+               default:
+                       pos += res;
+               }
+       }
+       return (pos);
+}
+
+ssize_t
+atomic_write(int fd, const void *v, size_t n)
+{
+       const char *s = v;
+       ssize_t res, pos = 0;
+
+       while (n > pos) {
+               res = write(fd, s + pos, n - pos);
+               switch (res) {
+               case -1:
+                       if (errno == EINTR || errno == EAGAIN)
+                               continue;
+               case 0:
+                       return (res);
+               default:
+                       pos += res;
+               }
+       }
+       return (pos);
+}
diff -r 9cce0dace44e -r 9ba954137180 crypto/dist/ssh/authfd.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/crypto/dist/ssh/authfd.c  Mon Feb 26 20:26:20 2001 +0000
@@ -0,0 +1,571 @@
+/*
+ * Author: Tatu Ylonen <ylo%cs.hut.fi@localhost>
+ * Copyright (c) 1995 Tatu Ylonen <ylo%cs.hut.fi@localhost>, Espoo, Finland
+ *                    All rights reserved
+ * Functions for connecting the local authentication agent.
+ *
+ * As far as I am concerned, the code I have written for this software
+ * can be used freely for any purpose.  Any derived versions of this
+ * software must be clearly marked as such, and if the derived work is
+ * incompatible with the protocol description in the RFC file, it must be
+ * called by a name other than "ssh" or "Secure Shell".
+ *
+ * SSH2 implementation,
+ * Copyright (c) 2000 Markus Friedl.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "includes.h"
+RCSID("$OpenBSD: authfd.c,v 1.35 2001/02/04 15:32:22 stevesk Exp $");
+
+#include <openssl/evp.h>
+
+#include "ssh.h"
+#include "rsa.h"
+#include "buffer.h"
+#include "bufaux.h"
+#include "xmalloc.h"
+#include "getput.h"
+#include "key.h"
+#include "authfd.h"
+#include "cipher.h"
+#include "kex.h"
+#include "compat.h"
+#include "log.h"
+#include "atomicio.h"
+
+/* helper */
+int    decode_reply(int type);
+
+/* macro to check for "agent failure" message */
+#define agent_failed(x) \
+    ((x == SSH_AGENT_FAILURE) || (x == SSH_COM_AGENT2_FAILURE))
+
+/* Returns the number of the authentication fd, or -1 if there is none. */
+
+int
+ssh_get_authentication_socket(void)
+{
+       const char *authsocket;
+       int sock, len;
+       struct sockaddr_un sunaddr;
+
+       authsocket = getenv(SSH_AUTHSOCKET_ENV_NAME);
+       if (!authsocket)
+               return -1;
+
+       sunaddr.sun_family = AF_UNIX;
+       strlcpy(sunaddr.sun_path, authsocket, sizeof(sunaddr.sun_path));
+       sunaddr.sun_len = len = SUN_LEN(&sunaddr)+1;
+
+       sock = socket(AF_UNIX, SOCK_STREAM, 0);
+       if (sock < 0)
+               return -1;
+
+       /* close on exec */
+       if (fcntl(sock, F_SETFD, 1) == -1) {
+               close(sock);
+               return -1;
+       }
+       if (connect(sock, (struct sockaddr *) & sunaddr, len) < 0) {
+               close(sock);
+               return -1;
+       }
+       return sock;
+}
+
+static int
+ssh_request_reply(AuthenticationConnection *auth, Buffer *request, Buffer *reply)
+{
+       int l, len;
+       char buf[1024];
+
+       /* Get the length of the message, and format it in the buffer. */
+       len = buffer_len(request);
+       PUT_32BIT(buf, len);
+
+       /* Send the length and then the packet to the agent. */
+       if (atomic_write(auth->fd, buf, 4) != 4 ||
+           atomic_write(auth->fd, buffer_ptr(request),
+           buffer_len(request)) != buffer_len(request)) {
+               error("Error writing to authentication socket.");
+               return 0;
+       }
+       /*
+        * Wait for response from the agent.  First read the length of the
+        * 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.");
+                       return 0;
+               }
+               len -= l;
+       }
+
+       /* Extract the length, and check it for sanity. */
+       len = GET_32BIT(buf);
+       if (len > 256 * 1024)
+               fatal("Authentication response too long: %d", len);
+
+       /* Read the rest of the response in to the buffer. */
+       buffer_clear(reply);
+       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.");
+                       return 0;
+               }
+               buffer_append(reply, (char *) buf, l);
+               len -= l;
+       }
+       return 1;
+}
+
+/*
+ * Closes the agent socket if it should be closed (depends on how it was
+ * obtained).  The argument must have been returned by
+ * ssh_get_authentication_socket().
+ */
+
+void
+ssh_close_authentication_socket(int sock)
+{
+       if (getenv(SSH_AUTHSOCKET_ENV_NAME))
+               close(sock);
+}
+
+/*
+ * Opens and connects a private socket for communication with the
+ * authentication agent.  Returns the file descriptor (which must be
+ * shut down and closed by the caller when no longer needed).
+ * Returns NULL if an error occurred and the connection could not be
+ * opened.
+ */
+
+AuthenticationConnection *
+ssh_get_authentication_connection(void)
+{
+       AuthenticationConnection *auth;
+       int sock;
+
+       sock = ssh_get_authentication_socket();
+
+       /*
+        * Fail if we couldn't obtain a connection.  This happens if we
+        * exited due to a timeout.
+        */
+       if (sock < 0)
+               return NULL;
+
+       auth = xmalloc(sizeof(*auth));
+       auth->fd = sock;
+       buffer_init(&auth->identities);
+       auth->howmany = 0;
+
+       return auth;
+}
+
+/*
+ * Closes the connection to the authentication agent and frees any associated
+ * memory.
+ */
+
+void
+ssh_close_authentication_connection(AuthenticationConnection *auth)
+{
+       buffer_free(&auth->identities);
+       close(auth->fd);
+       xfree(auth);
+}
+
+/*
+ * Returns the first authentication identity held by the agent.
+ */
+
+int
+ssh_get_num_identities(AuthenticationConnection *auth, int version)
+{
+       int type, code1 = 0, code2 = 0;
+       Buffer request;
+
+       switch(version){
+       case 1:
+               code1 = SSH_AGENTC_REQUEST_RSA_IDENTITIES;
+               code2 = SSH_AGENT_RSA_IDENTITIES_ANSWER;
+               break;



Home | Main Index | Thread Index | Old Index