#include "keystructs.h"
#include "ll.h"
#include "log.h"
+#include "openpgp.h"
/*
* parse_subpackets - Parse the subpackets of a Type 4 signature.
packetlen = data[offset++];
}
switch (data[offset] & 0x7F) {
- case 2:
+ case OPENPGP_SIGSUB_CREATION:
/*
* Signature creation time.
*/
*creation = data[offset + packetlen - 1];
}
break;
- case 3:
+ case OPENPGP_SIGSUB_EXPIRY:
/*
* Signature expiration time. Might want to output this?
*/
break;
- case 6:
+ case OPENPGP_SIGSUB_REGEX:
/*
* Regular expression for UIDs this sig is over.
*/
break;
- case 16:
+ case OPENPGP_SIGSUB_ISSUER:
if (keyid != NULL) {
*keyid = data[offset+packetlen - 8];
*keyid <<= 8;
*keyid += data[offset+packetlen - 1];
}
break;
- case 20:
+ case OPENPGP_SIGSUB_NOTATION:
/*
* Annotation data.
*/
break;
- case 23:
+ case OPENPGP_SIGSUB_KEYSERVER:
/*
* Key server preferences. Including no-modify.
*/
break;
- case 25:
+ case OPENPGP_SIGSUB_PRIMARYUID:
/*
* Primary UID.
*/
break;
- case 26:
+ case OPENPGP_SIGSUB_POLICYURI:
/*
* Policy URI.
*/
curuid = key->uids;
while (curuid != NULL) {
buf[0] = 0;
- if (curuid->packet->tag == 13) {
+ if (curuid->packet->tag == OPENPGP_PACKET_UID) {
snprintf(buf, 1023, "%.*s",
(int) curuid->packet->length,
curuid->packet->data);
#include "keystructs.h"
#include "mem.h"
#include "merge.h"
+#include "openpgp.h"
#include "parsekey.h"
#include "sendsync.h"
publickey != NULL) {
curuid = publickey->uids;
while (curuid != NULL && buf[0] == 0) {
- if (curuid->packet->tag == 13) {
+ if (curuid->packet->tag == OPENPGP_PACKET_UID) {
snprintf(buf, 1023, "%.*s",
(int) curuid->packet->length,
curuid->packet->data);
#include "mem.h"
#include "merge.h"
#include "onak-conf.h"
+#include "openpgp.h"
#include "parsekey.h"
#include "sendsync.h"
if (dynamic_fetch_key(keyid, &publickey, false) && publickey != NULL) {
curuid = publickey->uids;
while (curuid != NULL && buf[0] == 0) {
- if (curuid->packet->tag == 13) {
+ if (curuid->packet->tag == OPENPGP_PACKET_UID) {
snprintf(buf, 1023, "%.*s",
(int) curuid->packet->length,
curuid->packet->data);
#include "keystructs.h"
#include "log.h"
#include "onak-conf.h"
+#include "openpgp.h"
int list_sigs(struct openpgp_packet_list *sigs, bool html)
{
int imgindx = 0;
while (uids != NULL) {
- if (uids->packet->tag == 13) {
+ if (uids->packet->tag == OPENPGP_PACKET_UID) {
snprintf(buf, 1023, "%.*s",
(int) uids->packet->length,
uids->packet->data);
printf(" %s\n",
(html) ? txt2html(buf) : buf);
- } else if (uids->packet->tag == 17) {
+ } else if (uids->packet->tag == OPENPGP_PACKET_UAT) {
printf(" ");
if (html) {
printf("<img src=\"lookup?op=photo&search="
int length = 0;
while (subkeys != NULL) {
- if (subkeys->packet->tag == 14) {
+ if (subkeys->packet->tag == OPENPGP_PACKET_PUBLICSUBKEY) {
created_time = (subkeys->packet->data[1] << 24) +
(subkeys->packet->data[2] << 16) +
printf("sub %5d%c/%08X %04d/%02d/%02d\n",
length,
- (type == 1) ? 'R' : ((type == 16) ? 'g' :
- ((type == 17) ? 'D' : '?')),
+ (type == OPENPGP_PKALGO_RSA) ? 'R' :
+ ((type == OPENPGP_PKALGO_ELGAMAL) ? 'g' :
+ ((type == OPENPGP_PKALGO_DSA) ? 'D' : '?')),
(uint32_t) (get_packetid(subkeys->packet) &
0xFFFFFFFF),
created->tm_year + 1900,
keyid = get_keyid(keys);
switch (type) {
- case 1:
+ case OPENPGP_PKALGO_RSA:
typech = 'R';
break;
- case 16:
+ case OPENPGP_PKALGO_ELGAMAL:
typech = 'g';
break;
- case 17:
+ case OPENPGP_PKALGO_DSA:
typech = 'D';
break;
- case 20:
+ case OPENPGP_PKALGO_ELGAMAL_SIGN:
typech = 'G';
break;
default:
}
curuid = keys->uids;
- if (curuid != NULL && curuid->packet->tag == 13) {
+ if (curuid != NULL &&
+ curuid->packet->tag == OPENPGP_PACKET_UID) {
snprintf(buf, 1023, "%.*s",
(int) curuid->packet->length,
curuid->packet->data);
for (curuid = keys->uids; curuid != NULL;
curuid = curuid->next) {
- if (curuid->packet->tag == 13) {
+ if (curuid->packet->tag == OPENPGP_PACKET_UID) {
printf("uid:");
for (i = 0; i < (int) curuid->packet->length;
i++) {
--- /dev/null
+/*
+ * openpgp.h - Defines directly related to OpenPGP RFC 4880
+ *
+ * Copyright 2011 Jonathan McDowell <noodles@earth.li>
+ */
+
+#ifndef __OPENPGP_H__
+#define __OPENPGP_H__
+
+#define OPENPGP_PKALGO_RSA 1
+#define OPENPGP_PKALGO_ELGAMAL 16
+#define OPENPGP_PKALGO_DSA 17
+#define OPENPGP_PKALGO_ELGAMAL_SIGN 20
+
+#define OPENPGP_HASH_MD5 1
+#define OPENPGP_HASH_SHA1 2
+#define OPENPGP_HASH_RIPEMD160 3
+#define OPENPGP_HASH_SHA256 8
+#define OPENPGP_HASH_SHA384 9
+#define OPENPGP_HASH_SHA512 10
+#define OPENPGP_HASH_SHA224 11
+
+#define OPENPGP_PACKET_SIGNATURE 2
+#define OPENPGP_PACKET_PUBLICKEY 6
+#define OPENPGP_PACKET_TRUST 12
+#define OPENPGP_PACKET_UID 13
+#define OPENPGP_PACKET_PUBLICSUBKEY 14
+#define OPENPGP_PACKET_UAT 17
+
+#define OPENPGP_SIGTYPE_BINARY 0x00
+#define OPENPGP_SIGTYPE_TEXT 0x01
+#define OPENPGP_SIGTYPE_KEY_REV 0x20
+#define OPENPGP_SIGTYPE_SUBKEY_REV 0x28
+#define OPENPGP_SIGTYPE_CERT_REV 0x30
+
+#define OPENPGP_SIGSUB_CREATION 2
+#define OPENPGP_SIGSUB_EXPIRY 3
+#define OPENPGP_SIGSUB_REGEX 6
+#define OPENPGP_SIGSUB_ISSUER 16
+#define OPENPGP_SIGSUB_NOTATION 20
+#define OPENPGP_SIGSUB_KEYSERVER 23
+#define OPENPGP_SIGSUB_PRIMARYUID 25
+#define OPENPGP_SIGSUB_POLICYURI 26
+
+#endif /* __OPENPGP_H__ */
#include "ll.h"
#include "log.h"
#include "mem.h"
+#include "openpgp.h"
#include "parsekey.h"
/**
while (packets != NULL) {
switch (packets->packet->tag) {
- case 2:
+ case OPENPGP_PACKET_SIGNATURE:
/*
* It's a signature packet. Add it to either the public
* key, to the current UID or the current subkey.
* if it's a revocation.
*/
if (packets->packet->data[0] == 3 &&
- packets->packet->data[2] == 0x20) {
+ packets->packet->data[2] ==
+ OPENPGP_SIGTYPE_KEY_REV) {
/*
* Type 3 key, 0x20 == revocation
*/
curkey->revoked = true;
} else if (packets->packet->data[0] == 4 &&
- packets->packet->data[1] == 0x20) {
+ packets->packet->data[1] ==
+ OPENPGP_SIGTYPE_KEY_REV) {
/*
* Type 4 key, 0x20 == revocation
*/
}
}
break;
- case 6:
+ case OPENPGP_PACKET_PUBLICKEY:
/*
* It's a public key packet, so start a new key in our
* list.
curkey->publickey = packet_dup(packets->packet);
count++;
break;
- case 13:
- case 17:
+ case OPENPGP_PACKET_UID:
+ case OPENPGP_PACKET_UAT:
/*
* It's a UID packet (or a photo id, which is similar).
*/
uid,
packet_dup(packets->packet));
break;
- case 14:
+ case OPENPGP_PACKET_PUBLICSUBKEY:
/*
* It's a subkey packet.
*/
subkey,
packet_dup(packets->packet));
break;
- case 12:
+ case OPENPGP_PACKET_TRUST:
case 61:
/*
* One of:
}
if (rc == 0) {
- if (curpacket->packet->tag == 6) {
+ if (curpacket->packet->tag ==
+ OPENPGP_PACKET_PUBLICKEY) {
keys++;
}
curpacket->packet->data =
#include "log.h"
#include "mem.h"
#include "onak-conf.h"
+#include "openpgp.h"
#include "parsekey.h"
int main(int argc, char *argv[])
tmp = list_end;
list_end = list_end->next;
if (list_end->next == NULL &&
- list_end->packet->tag == 6) {
+ list_end->packet->tag ==
+ OPENPGP_PACKET_PUBLICKEY) {
tmp->next = NULL;
}
}