Skip to content

Commit

Permalink
more changes to netpgpverify on agc-netpgp-standalone branch:
Browse files Browse the repository at this point in the history
+ remove the copy of digest.h from libbn sources, use the one in
libdigest, and fix up lib/verify/Makefile to accommodate

+ get rid of header files we don't need, and pick up header files
from the correct directory

+ remove the hexdump utility routine from the libbn misc support
routines, it's not needed

+ add a comment describing the pubring primary key parser structure
  • Loading branch information
agc committed Nov 2, 2012
1 parent ff87ffd commit cebddc9
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 148 deletions.
93 changes: 0 additions & 93 deletions crypto/external/bsd/netpgp/dist/src/libbn/digest.h

This file was deleted.

42 changes: 0 additions & 42 deletions crypto/external/bsd/netpgp/dist/src/libbn/misc.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -80,45 +80,3 @@ logmessage(const int level, const char *fmt, ...)
} }
} }
#endif #endif

#ifndef _KERNEL
#define LINELEN 16

#define PRIsize "z"

/* show hexadecimal/ascii dump */
void
hexdump(FILE *fp, const char *header, const uint8_t *src, size_t length)
{
size_t i;
char line[LINELEN + 1];

if (src == NULL) {
return;
}
if (fp == NULL) {
fp = stdout;
}
(void) fprintf(fp, "%s%s", (header) ? header : "", (header) ? "\n" : "");
(void) fprintf(fp, "[%" PRIsize "u char%s]\n", length, (length == 1) ? "" : "s");
for (i = 0 ; i < length ; i++) {
if (i % LINELEN == 0) {
(void) fprintf(fp, "%.5" PRIsize "u | ", i);
}
(void) fprintf(fp, "%.02x ", (uint8_t)src[i]);
line[i % LINELEN] = (isprint(src[i])) ? src[i] : '.';
if (i % LINELEN == LINELEN - 1) {
line[LINELEN] = 0x0;
(void) fprintf(fp, " | %s\n", line);
}
}
if (i % LINELEN != 0) {
for ( ; i % LINELEN != 0 ; i++) {
(void) fprintf(fp, " ");
line[i % LINELEN] = ' ';
}
line[LINELEN] = 0x0;
(void) fprintf(fp, " | %s\n", line);
}
}
#endif
1 change: 0 additions & 1 deletion crypto/external/bsd/netpgp/dist/src/libbn/misc.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ void netpgp_deallocate(void */*ptr*/, size_t /*size*/);


#ifndef _KERNEL #ifndef _KERNEL
void logmessage(const int /*level*/, const char */*fmt*/, ...); void logmessage(const int /*level*/, const char */*fmt*/, ...);
void hexdump(FILE */*fp*/, const char */*header*/, const uint8_t */*src*/, size_t /*length*/);
#endif #endif


__END_DECLS __END_DECLS
Expand Down
45 changes: 36 additions & 9 deletions crypto/external/bsd/netpgp/dist/src/libverify/libverify.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -27,13 +27,9 @@
#include <sys/param.h> #include <sys/param.h>
#include <sys/mman.h> #include <sys/mman.h>


#include <netpgp/bn.h>
#include <netpgp/digest.h>

#include <bzlib.h> #include <bzlib.h>
#include <err.h> #include <err.h>
#include <inttypes.h> #include <inttypes.h>
#include <regex.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
Expand All @@ -43,7 +39,9 @@
#include <zlib.h> #include <zlib.h>


#include "array.h" #include "array.h"
#include "bn.h"
#include "b64.h" #include "b64.h"
#include "digest.h"
#include "pgpsum.h" #include "pgpsum.h"
#include "rsa.h" #include "rsa.h"
#include "verify.h" #include "verify.h"
Expand Down Expand Up @@ -356,7 +354,7 @@ fmt_binary_mpi(pgpv_bignum_t *mpi, uint8_t *p, size_t size)


bytes = BITS_TO_BYTES(mpi->bits); bytes = BITS_TO_BYTES(mpi->bits);
if ((size_t)bytes + 2 + 1 > size) { if ((size_t)bytes + 2 + 1 > size) {
fprintf(stderr, "truncated mpi\n"); warn("truncated mpi");
return 0; return 0;
} }
if (mpi->bn == NULL || BN_is_zero(mpi->bn)) { if (mpi->bn == NULL || BN_is_zero(mpi->bn)) {
Expand Down Expand Up @@ -1361,7 +1359,6 @@ fmt_pubkey(char *s, size_t size, pgpv_pubkey_t *pubkey, const char *leader)
if (pubkey->expiry) { if (pubkey->expiry) {
cc += fmt_time(&s[cc], size - cc, " [Expiry ", pubkey->birth + pubkey->expiry, "]", 0); cc += fmt_time(&s[cc], size - cc, " [Expiry ", pubkey->birth + pubkey->expiry, "]", 0);
} }
/* XXX - revoked? */
cc += snprintf(&s[cc], size - cc, "\n"); cc += snprintf(&s[cc], size - cc, "\n");
cc += fmt_fingerprint(&s[cc], size - cc, &pubkey->fingerprint, "fingerprint: "); cc += fmt_fingerprint(&s[cc], size - cc, &pubkey->fingerprint, "fingerprint: ");
return cc; return cc;
Expand Down Expand Up @@ -1549,8 +1546,8 @@ rsa_verify(uint8_t *calculated, unsigned calclen, uint8_t hashalg, pgpv_bignum_t
unsigned prefixlen; unsigned prefixlen;
unsigned decryptc; unsigned decryptc;
unsigned i; unsigned i;
uint8_t decrypted[8192]; /* XXX */ uint8_t decrypted[8192];
uint8_t sigbn[8192]; /* XXX */ uint8_t sigbn[8192];
uint8_t prefix[64]; uint8_t prefix[64];
size_t keysize; size_t keysize;


Expand Down Expand Up @@ -1901,6 +1898,37 @@ get_literal_data(pgpv_cursor_t *cursor, pgpv_litdata_t *litdata, size_t *size)
return litdata->s.data; return litdata->s.data;
} }


/*
RFC 4880 describes the structure of v4 keys as:
Primary-Key
[Revocation Self Signature]
[Direct Key Signature...]
User ID [Signature ...]
[User ID [Signature ...] ...]
[User Attribute [Signature ...] ...]
[[Subkey [Binding-Signature-Revocation]
Primary-Key-Binding-Signature] ...]
and that's implemented below as a recursive descent parser.
It has had to be modified, though: see the comment
some keys out there have user ids where they shouldn't
to look like:
Primary-Key
[Revocation Self Signature]
[Direct Key Signature...]
[User ID [Signature ...]
[User ID [Signature ...] ...]
[User Attribute [Signature ...] ...]
[Subkey [Binding-Signature-Revocation]
Primary-Key-Binding-Signature] ...]
to accommodate keyrings set up by gpg
*/

/* recognise a primary key */ /* recognise a primary key */
static int static int
recog_primary_key(pgpv_t *pgp, pgpv_primarykey_t *primary) recog_primary_key(pgpv_t *pgp, pgpv_primarykey_t *primary)
Expand Down Expand Up @@ -1930,7 +1958,6 @@ recog_primary_key(pgpv_t *pgp, pgpv_primarykey_t *primary)
/* XXX - check it's a good key expiry */ /* XXX - check it's a good key expiry */
primary->primary.expiry = signature.keyexpiry; primary->primary.expiry = signature.keyexpiry;
} }
if (signature.revoked) fprintf(stderr, "agc - revoked1\n");
ARRAY_APPEND(primary->direct_sigs, signature); ARRAY_APPEND(primary->direct_sigs, signature);
} }
/* some keys out there have user ids where they shouldn't */ /* some keys out there have user ids where they shouldn't */
Expand Down
3 changes: 1 addition & 2 deletions crypto/external/bsd/netpgp/dist/src/libverify/pgpsum.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>


#include <netpgp/digest.h> #include "digest.h"

#include "pgpsum.h" #include "pgpsum.h"


/* add the ascii armor line endings (except for last line) */ /* add the ascii armor line endings (except for last line) */
Expand Down
3 changes: 2 additions & 1 deletion crypto/external/bsd/netpgp/lib/verify/Makefile
Original file line number Original file line Diff line number Diff line change
@@ -1,10 +1,11 @@
# $NetBSD: Makefile,v 1.1.2.3 2012/10/30 02:10:42 agc Exp $ # $NetBSD: Makefile,v 1.1.2.4 2012/11/02 00:35:51 agc Exp $


LIB=netpgpverify LIB=netpgpverify
SRCS=libverify.c b64.c pgpsum.c SRCS=libverify.c b64.c pgpsum.c
SRCS+=digest.c tiger.c SRCS+=digest.c tiger.c
SRCS+=bignum.c misc.c SRCS+=bignum.c misc.c
CPPFLAGS+=-I${EXTDIST}/src/libbn CPPFLAGS+=-I${EXTDIST}/src/libbn
CPPFLAGS+=-I${EXTDIST}/src/libdigest
CPPFLAGS+=-I${EXTDIST}/src/librsa CPPFLAGS+=-I${EXTDIST}/src/librsa
MAN=libnetpgpverify.3 MAN=libnetpgpverify.3
WARNS=5 WARNS=5
Expand Down

0 comments on commit cebddc9

Please sign in to comment.