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/dist Add the ability to use ssh h...
details: https://anonhg.NetBSD.org/src/rev/615b02e14013
branches: trunk
changeset: 749643:615b02e14013
user: agc <agc%NetBSD.org@localhost>
date: Sat Dec 05 07:08:18 2009 +0000
description:
Add the ability to use ssh host keys (on the fly) to provide RSA keys.
These keys can be used in the same way as normal PGP keys - to sign, verify,
encrypt and decrypt files and data.
% cp configure a
% sudo netpgp --ssh-keys --sign --userid 1e00404a a
Password:
pub 1024/RSA (Encrypt or Sign) 040180871e00404a 2008-08-11
Key fingerprint: c4aa b385 4796 e6ce 606c f0c2 0401 8087 1e00 404a
% sudo chmod 644 a.gpg
% netpgp --ssh-keys --verify a.gpg
netpgp: default key set to "C0596823"
can't open '/etc/ssh/ssh_host_rsa_key'
Good signature for a.gpg made Fri Dec 4 23:04:36 2009
using RSA (Encrypt or Sign) key 040180871e00404a
pub 1024/RSA (Encrypt or Sign) 040180871e00404a 2008-08-11
Key fingerprint: c4aa b385 4796 e6ce 606c f0c2 0401 8087 1e00 404a
uid osx-vm1.crowthorne.alistaircrooks.co.uk (/etc/ssh/ssh_host_rsa_key.pub) <root%osx-vm1.crowthorne.alistaircrooks.co.uk@localhost>
% uname -a
NetBSD osx-vm1.crowthorne.alistaircrooks.co.uk 5.99.20 NetBSD 5.99.20 (ISCSI) #0: Wed Oct 7 17:16:33 PDT 2009
agc%osx-vm1.crowthorne.alistaircrooks.co.uk@localhost:/usr/obj/i386/usr/src/sys/arch/i386/compile/ISCSI i386
%
The ssh host keys do not need to be manipulated in any way - the information
is read from existing files.
diffstat:
crypto/external/bsd/netpgp/dist/src/lib/bufgap.c | 501 ++++++++++++
crypto/external/bsd/netpgp/dist/src/lib/bufgap.h | 90 ++
crypto/external/bsd/netpgp/dist/src/lib/crypto.h | 2 +
crypto/external/bsd/netpgp/dist/src/lib/defs.h | 91 ++
crypto/external/bsd/netpgp/dist/src/lib/fastctype.c | 370 ++++++++
crypto/external/bsd/netpgp/dist/src/lib/fastctype.h | 58 +
crypto/external/bsd/netpgp/dist/src/lib/keyring.c | 57 +-
crypto/external/bsd/netpgp/dist/src/lib/keyring.h | 10 +-
crypto/external/bsd/netpgp/dist/src/lib/misc.c | 21 +-
crypto/external/bsd/netpgp/dist/src/lib/netpgp.c | 108 ++-
crypto/external/bsd/netpgp/dist/src/lib/openssl_crypto.c | 41 +-
crypto/external/bsd/netpgp/dist/src/lib/ops-ssh.h | 41 +
crypto/external/bsd/netpgp/dist/src/lib/packet-print.c | 107 +-
crypto/external/bsd/netpgp/dist/src/lib/reader.c | 7 +-
crypto/external/bsd/netpgp/dist/src/lib/ssh2pgp.c | 446 ++++++++++
crypto/external/bsd/netpgp/dist/src/netpgp/Makefile | 40 +-
crypto/external/bsd/netpgp/dist/src/netpgp/netpgp.c | 6 +
crypto/external/bsd/netpgp/dist/src/netpgpkeys/netpgpkeys.c | 6 +
crypto/external/bsd/netpgp/dist/tst | 9 +-
19 files changed, 1848 insertions(+), 163 deletions(-)
diffs (truncated from 2467 to 300 lines):
diff -r bf6019604e50 -r 615b02e14013 crypto/external/bsd/netpgp/dist/src/lib/bufgap.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/crypto/external/bsd/netpgp/dist/src/lib/bufgap.c Sat Dec 05 07:08:18 2009 +0000
@@ -0,0 +1,501 @@
+/* $NetBSD: bufgap.c,v 1.1 2009/12/05 07:08:18 agc Exp $ */
+
+/*
+ * Copyright © 1996-2009 Alistair Crooks. 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Alistair G. Crooks.
+ * 4. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior written
+ * permission.
+ *
+ * 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 "config.h"
+
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+
+#ifdef HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+
+#include <stdio.h>
+
+#include <stdlib.h>
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
+#include "fastctype.h"
+#include "bufgap.h"
+#include "defs.h"
+
+/* macros to get subscripts in buffer */
+#define AFTSUB(bp, n) ((bp)->buf[n])
+#define BEFSUB(bp, n) ((bp)->buf[(bp)->size - (n) - 1])
+
+/* initial allocation size */
+#ifndef CHUNKSIZE
+#define CHUNKSIZE 256
+#endif
+
+#ifndef KiB
+#define KiB(x) ((x) * 1024)
+#endif
+
+#define BGCHUNKSIZE KiB(4)
+
+#ifndef __UNCONST
+#define __UNCONST(a) ((void *)(unsigned long)(const void *)(a))
+#endif
+
+#ifndef USE_UTF
+#define USE_UTF 0
+#endif
+
+#if !USE_UTF
+#define Rune char
+#define utfbytes(x) strlen(x)
+#define utfrune(a, b) strchr(a, b)
+#define utfnlen(a, b) strnlen(a, b)
+
+static int
+chartorune(Rune *rp, char *s)
+{
+ *rp = s[0];
+ return 1;
+}
+
+static int
+priorrune(Rune *rp, char *s)
+{
+ *rp = s[0];
+ return 1;
+}
+#else
+#include "ure.h"
+#endif
+
+/* save `n' chars of `s' in malloc'd memory */
+static char *
+strnsave(char *s, int n)
+{
+ char *cp;
+
+ NEWARRAY(char, cp, n + 1, "strnsave", return NULL);
+ (void) memcpy(cp, s, n);
+ cp[n] = 0x0;
+ return cp;
+}
+
+/* open a file in a buffer gap structure */
+int
+bufgap_open(bufgap_t *bp, const char *f)
+{
+ struct stat s;
+ int64_t cc;
+ FILE *filep;
+ char *cp;
+
+ (void) memset(bp, 0x0, sizeof(*bp));
+ filep = NULL;
+ if (f != NULL && (filep = fopen(f, "r")) == NULL) {
+ return 0;
+ }
+ if (f == NULL) {
+ bp->size = BGCHUNKSIZE;
+ NEWARRAY(char, bp->buf, bp->size, "f_open", return 0);
+ } else {
+ (void) fstat(fileno(filep), &s);
+ bp->size = (int) ((s.st_size / BGCHUNKSIZE) + 1) * BGCHUNKSIZE;
+ NEWARRAY(char, bp->buf, bp->size, "f_open", return 0);
+ cc = fread(&BEFSUB(bp, s.st_size), sizeof(char),
+ s.st_size, filep);
+ (void) fclose(filep);
+ if (cc != s.st_size) {
+ FREE(bp->buf);
+ FREE(bp);
+ return 0;
+ }
+ bp->name = strnsave(__UNCONST(f), utfbytes(__UNCONST(f)));
+ bp->bbc = s.st_size;
+ cp = &BEFSUB(bp, cc);
+ for (;;) {
+ if ((cp = utfrune(cp, '\n')) == NULL) {
+ break;
+ }
+ bp->blc++;
+ cp++;
+ }
+ bp->bcc = utfnlen(&BEFSUB(bp, cc), cc);
+ }
+ return 1;
+}
+
+/* close a buffer gapped file */
+void
+bufgap_close(bufgap_t *bp)
+{
+ FREE(bp->buf);
+}
+
+/* move forwards `n' chars/bytes in a buffer gap */
+int
+bufgap_forwards(bufgap_t *bp, uint64_t n, int type)
+{
+ Rune r;
+ int rlen;
+
+ switch(type) {
+ case BGChar:
+ if (bp->bcc >= n) {
+ while (n-- > 0) {
+ rlen = chartorune(&r, &BEFSUB(bp, bp->bbc));
+ if (rlen == 1) {
+ AFTSUB(bp, bp->abc) = BEFSUB(bp, bp->bbc);
+ } else {
+ (void) memmove(&AFTSUB(bp, bp->abc), &BEFSUB(bp, bp->bbc), rlen);
+ }
+ bp->acc++;
+ bp->bcc--;
+ bp->abc += rlen;
+ bp->bbc -= rlen;
+ if (r == '\n') {
+ bp->alc++;
+ bp->blc--;
+ }
+ }
+ return 1;
+ }
+ break;
+ case BGByte:
+ if (bp->bbc >= n) {
+ for ( ; n > 0 ; n -= rlen) {
+ rlen = chartorune(&r, &BEFSUB(bp, bp->bbc));
+ if (rlen == 1) {
+ AFTSUB(bp, bp->abc) = BEFSUB(bp, bp->bbc);
+ } else {
+ (void) memmove(&AFTSUB(bp, bp->abc), &BEFSUB(bp, bp->bbc), rlen);
+ }
+ bp->acc++;
+ bp->bcc--;
+ bp->abc += rlen;
+ bp->bbc -= rlen;
+ if (r == '\n') {
+ bp->alc++;
+ bp->blc--;
+ }
+ }
+ return 1;
+ }
+ }
+ return 0;
+}
+
+/* move backwards `n' chars in a buffer gap */
+int
+bufgap_backwards(bufgap_t *bp, uint64_t n, int type)
+{
+ Rune r;
+ int rlen;
+
+ switch(type) {
+ case BGChar:
+ if (bp->acc >= n) {
+ while (n-- > 0) {
+ rlen = priorrune(&r, &AFTSUB(bp, bp->abc));
+ bp->bcc++;
+ bp->acc--;
+ bp->bbc += rlen;
+ bp->abc -= rlen;
+ if (rlen == 1) {
+ BEFSUB(bp, bp->bbc) = AFTSUB(bp, bp->abc);
+ } else {
+ (void) memmove(&BEFSUB(bp, bp->bbc), &AFTSUB(bp, bp->abc), rlen);
+ }
+ if (r == '\n') {
+ bp->blc++;
+ bp->alc--;
+ }
+ }
+ return 1;
+ }
+ break;
+ case BGByte:
+ if (bp->acc >= n) {
+ for ( ; n > 0 ; n -= rlen) {
+ rlen = priorrune(&r, &AFTSUB(bp, bp->abc));
+ bp->bcc++;
+ bp->acc--;
+ bp->bbc += rlen;
+ bp->abc -= rlen;
+ if (rlen == 1) {
+ BEFSUB(bp, bp->bbc) = AFTSUB(bp, bp->abc);
+ } else {
+ (void) memmove(&BEFSUB(bp, bp->bbc), &AFTSUB(bp, bp->abc), rlen);
+ }
+ if (r == '\n') {
+ bp->blc++;
+ bp->alc--;
+ }
+ }
+ return 1;
+ }
+ }
+ return 0;
+}
+
+/* move within a buffer gap */
+int
+bufgap_seek(bufgap_t *bp, int64_t off, int whence, int type)
+{
+ switch(type) {
+ case BGLine:
+ switch(whence) {
+ case BGFromBOF:
+ if (off < 0 || off > (int64_t)(bp->alc + bp->blc)) {
+ return 0;
+ }
+ if (off < (int64_t)bp->alc) {
+ while (off <= (int64_t)bp->alc && bufgap_backwards(bp, 1, BGChar)) {
+ }
+ if (off > 0) {
+ (void) bufgap_forwards(bp, 1, BGChar);
+ }
+ } else if (off > (int64_t)bp->alc) {
+ while (off > (int64_t)bp->alc && bufgap_forwards(bp, 1, BGChar)) {
+ }
+ }
+ return 1;
+ case BGFromHere:
Home |
Main Index |
Thread Index |
Old Index