Source-Changes-HG archive

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

[src/trunk]: src/crypto/external/bsd/netpgp Update hkpd to return its informa...



details:   https://anonhg.NetBSD.org/src/rev/b8492536db56
branches:  trunk
changeset: 757526:b8492536db56
user:      agc <agc%NetBSD.org@localhost>
date:      Thu Sep 02 05:58:00 2010 +0000

description:
Update hkpd to return its information in JSON (via libmj).

Add a C HKP client.

Provide reachover Makefiles for each, but do not hook them up to the build
just yet.

The HKP client and server can be embedded in other programs.

diffstat:

 crypto/external/bsd/netpgp/dist/src/hkpclient/hkpc.1 |  123 +++++++++++++++++
 crypto/external/bsd/netpgp/dist/src/hkpclient/hkpc.c |  135 +++++++++++++++++++
 crypto/external/bsd/netpgp/dist/src/hkpclient/hkpc.h |   34 ++++
 crypto/external/bsd/netpgp/dist/src/hkpclient/main.c |   69 +++++++++
 crypto/external/bsd/netpgp/dist/src/hkpd/Makefile    |    4 +-
 crypto/external/bsd/netpgp/dist/src/hkpd/hkpd.1      |  129 ++++++++++++++++++
 crypto/external/bsd/netpgp/dist/src/hkpd/hkpd.8      |  117 ----------------
 crypto/external/bsd/netpgp/hkpc/Makefile             |   25 +++
 crypto/external/bsd/netpgp/hkpd/Makefile             |   33 ++++
 9 files changed, 550 insertions(+), 119 deletions(-)

diffs (truncated from 714 to 300 lines):

diff -r 7366ea0db8ec -r b8492536db56 crypto/external/bsd/netpgp/dist/src/hkpclient/hkpc.1
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/crypto/external/bsd/netpgp/dist/src/hkpclient/hkpc.1      Thu Sep 02 05:58:00 2010 +0000
@@ -0,0 +1,123 @@
+.\" $NetBSD: hkpc.1,v 1.1 2010/09/02 05:58:01 agc Exp $
+.\"
+.\" Copyright (c) 2010 The NetBSD Foundation, Inc.
+.\" All rights reserved.
+.\"
+.\" This manual page is derived from software contributed to
+.\" The NetBSD Foundation by Alistair Crooks (agc%NetBSD.org@localhost).
+.\"
+.\" 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 NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+.\" ``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 FOUNDATION OR CONTRIBUTORS
+.\" 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.
+.\"
+.Dd September 1, 2010
+.Dt HKPC 1
+.Os
+.Sh NAME
+.Nm hkpc
+.Nd retrieve public key information via HKP
+.Sh SYNOPSIS
+.Nm
+.Op Fl f address-family
+.Op Fl h hostname
+.Op Fl p port
+.Cm [get|index|vindex]
+userid...
+.Sh DESCRIPTION
+The
+.Nm
+command retrieves public key information from the key server daemon
+using the HKP protocol.
+The
+.Xr hkpd 8
+is normally used to retrieve public key information.
+.Pp
+Three types of information can be retrieved from the server:
+.Bl -tag -width vindex
+.It get
+The public key, base64-encoded, corresponding to the given userid
+is returned.
+The userid can be a numeric value, a unique part of the human
+identifier, or left blank.
+The first matching key will be returned, in a format suitable for
+importing to a keyring via the
+.Xr netpgpkeys 1
+command.
+.It index
+the information returned from this command is the same as
+provided by the
+.Xr netpgpkeys 1
+command, using the
+.Dv --list-keys
+modifier.
+.It vindex
+the information returned from this command is the same as
+provided by the
+.Xr netpgpkeys 1
+command, using the
+.Dv --list-sigs
+modifier.
+.El
+.Pp
+For this utility to provide the correct results, an hkpd
+server must be listening using the correct protocol family,
+on the provided port on the appropriate server.
+The default port for the HKP server is
+.Dv 11371 ,
+whilst the hostname defaults to
+.Dv localhost .
+.Pp
+The
+.Dv netpgp
+suite of libraries and commands provides a copnvenient client
+in
+.Xr hkpd 1 .
+.Pp
+The information is sent to the server in the form of
+an HTTP
+.Dv GET
+command, and is returned as a JSON-encoded
+HKP packet.
+.Xr libmj 3
+is used to decode the JSON in the returned HKP packet.
+.Sh EXIT STATUS
+The
+.Nm
+utility will return 0 for success,
+or 1 for failure.
+Output will be printed on stdout.
+.Sh SEE ALSO
+.Xr hkpd 1 ,
+.Xr netpgpkeys 1 ,
+.Xr ssh 1 ,
+.\" .Xr libbz2 3 ,
+.Xr libmj 3 ,
+.Xr libnetpgp 3
+.Sh STANDARDS
+The
+.Nm
+utility is designed to conform to IETF RFC 4880.
+.Sh HISTORY
+The
+.Nm
+command first appeared in
+.Nx 6.0 .
+.Sh AUTHORS
+.An Alistair Crooks Aq agc%NetBSD.org@localhost .
diff -r 7366ea0db8ec -r b8492536db56 crypto/external/bsd/netpgp/dist/src/hkpclient/hkpc.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/crypto/external/bsd/netpgp/dist/src/hkpclient/hkpc.c      Thu Sep 02 05:58:00 2010 +0000
@@ -0,0 +1,135 @@
+/*-
+ * Copyright (c) 2010 Alistair Crooks <agc%NetBSD.org@localhost>
+ * 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 <sys/types.h>
+#include <sys/param.h>
+#include <sys/socket.h>
+
+#include <netinet/in.h>
+
+#include <errno.h>
+#include <inttypes.h>
+#include <netdb.h>
+#include <netpgp.h>
+#include <regex.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "hkpc.h"
+
+/* get a socket and connect it to the server */
+int
+hkpc_connect(const char *hostname, const int port, const int fam)
+{
+        struct addrinfo  hints;
+        struct addrinfo *res;
+        char             portstr[32];
+       int              sock;
+        int              rc = 0;
+
+        (void) memset(&hints, 0, sizeof(hints));
+        hints.ai_family = (fam == 4) ? PF_INET : PF_INET6;
+        hints.ai_socktype = SOCK_STREAM;
+        (void) snprintf(portstr, sizeof(portstr), "%d", port);
+        if ((rc = getaddrinfo(hostname, portstr, &hints, &res)) != 0) {
+                hints.ai_flags = 0;
+                if ((rc = getaddrinfo(hostname, "hkp", &hints, &res)) != 0) {
+                        (void) fprintf(stderr, "getaddrinfo: %s",
+                                       gai_strerror(rc));
+                        return -1;
+                }
+        }
+       if ((sock = socket((fam == 4) ? AF_INET : AF_INET6, SOCK_STREAM, 0)) < 0) {
+                (void) fprintf(stderr, "socket failed %d\n", errno);
+                freeaddrinfo(res);
+                return -1;
+       }
+        if ((rc = connect(sock, res->ai_addr, res->ai_addrlen)) < 0) {
+                (void) fprintf(stderr, "connect failed %d\n", errno);
+                freeaddrinfo(res);
+                return -1;
+        }
+        freeaddrinfo(res);
+        if (rc < 0) {
+                (void) fprintf(stderr, "bind() to %s:%d failed (rc %d)\n",
+                               hostname, port, rc);
+        }
+        return sock;
+}
+
+#define MB(x)  ((x) * 1024 * 1024)
+
+/* get required info from the server */
+int
+hkpc_get(char **info, const char *server, const int port, const int family, const char *type, const char *userid)
+{
+       char    buf[MB(1)];
+       int     sock;
+       int     cc;
+       int     rc;
+
+       if ((sock = hkpc_connect(server, port, family)) < 0) {
+               (void) fprintf(stderr, "hkpc_get: can't connect to server '%s'\n", server);
+               return -1;
+       }
+       cc = snprintf(buf, sizeof(buf), "GET /pks/lookup?op=%s&search=%s&options=json", type, userid);
+       if (write(sock, buf, cc) != cc) {
+               (void) fprintf(stderr, "hkpc_get: short write\n");
+               return -1;
+       }
+       for (cc = 0 ; (rc = read(sock, &buf[cc], sizeof(buf) - cc)) > 0 ; cc += rc) {
+       }
+       *info = calloc(1, cc + 1);
+       (void) memcpy(*info, buf, cc);
+       (*info)[cc] = 0x0;
+       (void) close(sock);
+       return cc;
+}
+
+/* jump over http header, then pass the json to the key-formatting function */
+int
+hkpc_print_key(FILE *fp, const char *op, const char *res)
+{
+       static regex_t  text;
+       static int      compiled;
+       regmatch_t      matches[10];
+       int             ret;
+
+       if (!compiled) {
+               compiled = 1;
+               (void) regcomp(&text, "\r\n\r\n", REG_EXTENDED);
+       }
+       if (regexec(&text, res, 10, matches, 0) != 0) {
+               return 0;
+       }
+       if (strcmp(op, "index") == 0 || strcmp(op, "vindex") == 0) {
+               ret = netpgp_format_json(fp, &res[(int)matches[0].rm_eo], 1);
+       } else {
+               (void) fprintf(fp, "%s\n", &res[(int)matches[0].rm_eo + 1]);
+               ret = 1;
+       }
+       return ret;
+}
diff -r 7366ea0db8ec -r b8492536db56 crypto/external/bsd/netpgp/dist/src/hkpclient/hkpc.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/crypto/external/bsd/netpgp/dist/src/hkpclient/hkpc.h      Thu Sep 02 05:58:00 2010 +0000
@@ -0,0 +1,34 @@
+/*-
+ * Copyright (c) 2010 Alistair Crooks <agc%NetBSD.org@localhost>
+ * 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.
+ */
+#ifndef HKPC_H_
+#define HKPC_H_        20100820
+
+#include <stdio.h>
+
+int hkpc_connect(const char *, const int, const int);



Home | Main Index | Thread Index | Old Index