diff options
author | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2010-12-16 17:30:42 +0100 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2010-12-16 17:30:42 +0100 |
commit | 6eb6bbfe8e504a611145f454f4045e8f49fd5e44 (patch) | |
tree | baba850cc86ee2d9d61de89da1cdfe408ad8694a /lib/opencdk | |
parent | bdcfdac13179eccee6294402f2654fece149f82b (diff) | |
download | gnutls-6eb6bbfe8e504a611145f454f4045e8f49fd5e44.tar.gz |
Indented code. Use same indentation but with -nut to avoid usage of tabs. In several editors tabs can be configured not to be 8 spaces and this produces artifacts with the current indentation that is a mixture of tabs and spaces.
Diffstat (limited to 'lib/opencdk')
-rw-r--r-- | lib/opencdk/armor.c | 232 | ||||
-rw-r--r-- | lib/opencdk/context.h | 2 | ||||
-rw-r--r-- | lib/opencdk/dummy.c | 4 | ||||
-rw-r--r-- | lib/opencdk/filters.h | 8 | ||||
-rw-r--r-- | lib/opencdk/hash.c | 22 | ||||
-rw-r--r-- | lib/opencdk/kbnode.c | 170 | ||||
-rw-r--r-- | lib/opencdk/keydb.c | 1292 | ||||
-rw-r--r-- | lib/opencdk/keydb.h | 24 | ||||
-rw-r--r-- | lib/opencdk/literal.c | 78 | ||||
-rw-r--r-- | lib/opencdk/main.c | 56 | ||||
-rw-r--r-- | lib/opencdk/main.h | 36 | ||||
-rw-r--r-- | lib/opencdk/misc.c | 28 | ||||
-rw-r--r-- | lib/opencdk/new-packet.c | 86 | ||||
-rw-r--r-- | lib/opencdk/opencdk.h | 286 | ||||
-rw-r--r-- | lib/opencdk/packet.h | 2 | ||||
-rw-r--r-- | lib/opencdk/pubkey.c | 54 | ||||
-rw-r--r-- | lib/opencdk/read-packet.c | 334 | ||||
-rw-r--r-- | lib/opencdk/seskey.c | 28 | ||||
-rw-r--r-- | lib/opencdk/sig-check.c | 288 | ||||
-rw-r--r-- | lib/opencdk/stream.c | 218 | ||||
-rw-r--r-- | lib/opencdk/stream.h | 2 | ||||
-rw-r--r-- | lib/opencdk/verify.c | 110 | ||||
-rw-r--r-- | lib/opencdk/write-packet.c | 126 |
23 files changed, 1743 insertions, 1743 deletions
diff --git a/lib/opencdk/armor.c b/lib/opencdk/armor.c index da14a74874..b731226f9a 100644 --- a/lib/opencdk/armor.c +++ b/lib/opencdk/armor.c @@ -184,7 +184,7 @@ base64_encode (char *out, const byte * in, size_t len, size_t olen) *out++ = b64chars[in[0] >> 2]; fragment = (in[0] << 4) & 0x30; if (len > 1) - fragment |= in[1] >> 4; + fragment |= in[1] >> 4; *out++ = b64chars[fragment]; *out++ = (len < 2) ? '=' : b64chars[(in[1] << 2) & 0x3c]; *out++ = '='; @@ -213,43 +213,43 @@ base64_decode (byte * out, const char *in) { digit1 = in[0]; if (digit1 > 127 || b64val (digit1) == BAD) - { - gnutls_assert (); - return -1; - } + { + gnutls_assert (); + return -1; + } digit2 = in[1]; if (digit2 > 127 || b64val (digit2) == BAD) - { - gnutls_assert (); - return -1; - } + { + gnutls_assert (); + return -1; + } digit3 = in[2]; if (digit3 > 127 || ((digit3 != '=') && (b64val (digit3) == BAD))) - { - gnutls_assert (); - return -1; - } + { + gnutls_assert (); + return -1; + } digit4 = in[3]; if (digit4 > 127 || ((digit4 != '=') && (b64val (digit4) == BAD))) - { - gnutls_assert (); - return -1; - } + { + gnutls_assert (); + return -1; + } in += 4; /* digits are already sanity-checked */ *out++ = (b64val (digit1) << 2) | (b64val (digit2) >> 4); len++; if (digit3 != '=') - { - *out++ = ((b64val (digit2) << 4) & 0xf0) | (b64val (digit3) >> 2); - len++; - if (digit4 != '=') - { - *out++ = ((b64val (digit3) << 6) & 0xc0) | b64val (digit4); - len++; - } - } + { + *out++ = ((b64val (digit2) << 4) & 0xf0) | (b64val (digit3) >> 2); + len++; + if (digit4 != '=') + { + *out++ = ((b64val (digit3) << 6) & 0xc0) | b64val (digit4); + len++; + } + } } while (*in && digit4 != '='); @@ -273,22 +273,22 @@ compress_get_algo (cdk_stream_t inp, int *r_zipalgo) { nread = _cdk_stream_gets (inp, buf, DIM (buf) - 1); if (!nread || nread == -1) - break; + break; if (nread == 1 && !cdk_stream_eof (inp) - && (nread = _cdk_stream_gets (inp, buf, DIM (buf) - 1)) > 0) - { - base64_decode (plain, buf); - if (!(*plain & 0x80)) - break; - pkttype = *plain & 0x40 ? (*plain & 0x3f) : ((*plain >> 2) & 0xf); - if (pkttype == CDK_PKT_COMPRESSED && r_zipalgo) - { - _gnutls_buffers_log ("armor compressed (algo=%d)\n", - *(plain + 1)); - *r_zipalgo = *(plain + 1); - } - break; - } + && (nread = _cdk_stream_gets (inp, buf, DIM (buf) - 1)) > 0) + { + base64_decode (plain, buf); + if (!(*plain & 0x80)) + break; + pkttype = *plain & 0x40 ? (*plain & 0x3f) : ((*plain >> 2) & 0xf); + if (pkttype == CDK_PKT_COMPRESSED && r_zipalgo) + { + _gnutls_buffers_log ("armor compressed (algo=%d)\n", + *(plain + 1)); + *r_zipalgo = *(plain + 1); + } + break; + } } return 0; } @@ -307,10 +307,10 @@ check_armor (cdk_stream_t inp, int *r_zipalgo) { buf[nread] = '\0'; if (strstr (buf, "-----BEGIN PGP")) - { - compress_get_algo (inp, r_zipalgo); - check = 1; - } + { + compress_get_algo (inp, r_zipalgo); + check = 1; + } cdk_stream_seek (inp, 0); } return check; @@ -325,7 +325,7 @@ is_armored (int ctb) if (!(ctb & 0x80)) { gnutls_assert (); - return 1; /* invalid packet: assume it is armored */ + return 1; /* invalid packet: assume it is armored */ } pkttype = ctb & 0x40 ? (ctb & 0x3f) : ((ctb >> 2) & 0xf); switch (pkttype) @@ -338,7 +338,7 @@ is_armored (int ctb) case CDK_PKT_SIGNATURE: case CDK_PKT_LITERAL: case CDK_PKT_COMPRESSED: - return 0; /* seems to be a regular packet: not armored */ + return 0; /* seems to be a regular packet: not armored */ } return 1; } @@ -402,12 +402,12 @@ armor_encode (void *data, FILE * in, FILE * out) { nread = fread (raw, 1, DIM (raw) - 1, in); if (!nread) - break; + break; if (ferror (in)) - { - gnutls_assert (); - return CDK_File_Error; - } + { + gnutls_assert (); + return CDK_File_Error; + } afx->crc = update_crc (afx->crc, (byte *) raw, nread); base64_encode (buf, (byte *) raw, nread, DIM (buf) - 1); fprintf (out, "%s%s", buf, lf); @@ -442,14 +442,14 @@ cdk_armor_filter_use (cdk_stream_t inp) zipalgo = 0; c = cdk_stream_getc (inp); if (c == EOF) - return 0; /* EOF, doesn't matter whether armored or not */ + return 0; /* EOF, doesn't matter whether armored or not */ cdk_stream_seek (inp, 0); check = is_armored (c); if (check) { check = check_armor (inp, &zipalgo); if (zipalgo) - _cdk_stream_set_compress_algo (inp, zipalgo); + _cdk_stream_set_compress_algo (inp, zipalgo); } return check; } @@ -469,7 +469,7 @@ search_header (const char *buf, const char **array) for (i = 0; (s = array[i]); i++) { if (!strncmp (s, buf + 5, strlen (s))) - return i; + return i; } return -1; } @@ -508,16 +508,16 @@ armor_decode (void *data, FILE * in, FILE * out) { s = fgets (buf, DIM (buf) - 1, in); if (!s) - break; + break; afx->idx = search_header (buf, armor_begin); if (afx->idx >= 0) - pgp_data = 1; + pgp_data = 1; } if (feof (in) || !pgp_data) { gnutls_assert (); - return CDK_Armor_Error; /* no data found */ + return CDK_Armor_Error; /* no data found */ } /* Parse header until the empty line is reached */ @@ -525,33 +525,33 @@ armor_decode (void *data, FILE * in, FILE * out) { s = fgets (buf, DIM (buf) - 1, in); if (!s) - return CDK_EOF; + return CDK_EOF; if (strlen (s) == strlen (LF)) - { - rc = 0; - break; /* empty line */ - } + { + rc = 0; + break; /* empty line */ + } /* From RFC2440: OpenPGP should consider improperly formatted Armor Headers to be corruption of the ASCII Armor. A colon and a single space separate the key and value. */ if (!strstr (buf, ": ")) - { - gnutls_assert (); - return CDK_Armor_Error; - } + { + gnutls_assert (); + return CDK_Armor_Error; + } rc = CDK_General_Error; for (i = 0; (s = valid_headers[i]); i++) - { - if (!strncmp (s, buf, strlen (s))) - rc = 0; - } + { + if (!strncmp (s, buf, strlen (s))) + rc = 0; + } if (rc) - { - /* From RFC2440: Unknown keys should be reported to the user, - but OpenPGP should continue to process the message. */ - _cdk_log_info ("unknown header: `%s'\n", buf); - rc = 0; - } + { + /* From RFC2440: Unknown keys should be reported to the user, + but OpenPGP should continue to process the message. */ + _cdk_log_info ("unknown header: `%s'\n", buf); + rc = 0; + } } /* Read the data body */ @@ -559,23 +559,23 @@ armor_decode (void *data, FILE * in, FILE * out) { s = fgets (buf, DIM (buf) - 1, in); if (!s) - break; + break; buf[strlen (buf) - strlen (LF)] = '\0'; if (buf[0] == '=' && strlen (s) == 5) - { /* CRC */ - memset (crcbuf, 0, sizeof (crcbuf)); - base64_decode (crcbuf, buf + 1); - crc2 = (crcbuf[0] << 16) | (crcbuf[1] << 8) | crcbuf[2]; - break; /* stop here */ - } + { /* CRC */ + memset (crcbuf, 0, sizeof (crcbuf)); + base64_decode (crcbuf, buf + 1); + crc2 = (crcbuf[0] << 16) | (crcbuf[1] << 8) | crcbuf[2]; + break; /* stop here */ + } else - { - nread = base64_decode (raw, buf); - if (nread == -1 || nread == 0) - break; - afx->crc = update_crc (afx->crc, raw, nread); - fwrite (raw, 1, nread, out); - } + { + nread = base64_decode (raw, buf); + if (nread == -1 || nread == 0) + break; + afx->crc = update_crc (afx->crc, raw, nread); + fwrite (raw, 1, nread, out); + } } /* Search the tail of the message */ @@ -586,7 +586,7 @@ armor_decode (void *data, FILE * in, FILE * out) rc = CDK_General_Error; afx->idx2 = search_header (buf, armor_end); if (afx->idx2 >= 0) - rc = 0; + rc = 0; } /* This catches error when no tail was found or the header is @@ -598,7 +598,7 @@ armor_decode (void *data, FILE * in, FILE * out) if (!afx->crc_okay && !rc) { _gnutls_buffers_log ("file crc=%08X afx_crc=%08X\n", - (unsigned int) crc2, (unsigned int) afx->crc); + (unsigned int) crc2, (unsigned int) afx->crc); rc = CDK_Armor_CRC_Error; } @@ -642,7 +642,7 @@ cdk_file_armor (cdk_ctx_t hd, const char *file, const char *output) cdk_stream_set_armor_flag (out, CDK_ARMOR_MESSAGE); if (hd->opt.compress) rc = cdk_stream_set_compress_flag (out, hd->compress.algo, - hd->compress.level); + hd->compress.level); if (!rc) rc = cdk_stream_set_literal_flag (out, 0, file); if (!rc) @@ -697,13 +697,13 @@ cdk_file_dearmor (const char *file, const char *output) rc = cdk_stream_set_literal_flag (inp, 0, NULL); zipalgo = cdk_stream_is_compressed (inp); if (zipalgo) - rc = cdk_stream_set_compress_flag (inp, zipalgo, 0); + rc = cdk_stream_set_compress_flag (inp, zipalgo, 0); if (!rc) - rc = cdk_stream_set_armor_flag (inp, 0); + rc = cdk_stream_set_armor_flag (inp, 0); if (!rc) - rc = cdk_stream_kick_off (inp, out); + rc = cdk_stream_kick_off (inp, out); if (!rc) - rc = _cdk_stream_get_errno (inp); + rc = _cdk_stream_get_errno (inp); } cdk_stream_close (inp); @@ -724,12 +724,12 @@ _cdk_filter_armor (void *data, int ctl, FILE * in, FILE * out) { armor_filter_t *afx = data; if (afx) - { - _gnutls_buffers_log ("free armor filter\n"); - afx->idx = afx->idx2 = 0; - afx->crc = afx->crc_okay = 0; - return 0; - } + { + _gnutls_buffers_log ("free armor filter\n"); + afx->idx = afx->idx2 = 0; + afx->crc = afx->crc_okay = 0; + return 0; + } } gnutls_assert (); @@ -750,8 +750,8 @@ _cdk_filter_armor (void *data, int ctl, FILE * in, FILE * out) **/ cdk_error_t cdk_armor_encode_buffer (const byte * inbuf, size_t inlen, - char *outbuf, size_t outlen, - size_t * nwritten, int type) + char *outbuf, size_t outlen, + size_t * nwritten, int type) { const char *head, *tail, *le; byte tempbuf[48]; @@ -805,17 +805,17 @@ cdk_armor_encode_buffer (const byte * inbuf, size_t inlen, for (off = 0; off < inlen;) { if (rest > 48) - { - memcpy (tempbuf, inbuf + off, 48); - off += 48; - len = 48; - } + { + memcpy (tempbuf, inbuf + off, 48); + off += 48; + len = 48; + } else - { - memcpy (tempbuf, inbuf + off, rest); - off += rest; - len = rest; - } + { + memcpy (tempbuf, inbuf + off, rest); + off += rest; + len = rest; + } rest -= len; base64_encode (tempout, tempbuf, len, DIM (tempout) - 1); memcpy (outbuf + pos, tempout, strlen (tempout)); diff --git a/lib/opencdk/context.h b/lib/opencdk/context.h index 0b4aee293d..7c32ea7d8a 100644 --- a/lib/opencdk/context.h +++ b/lib/opencdk/context.h @@ -133,7 +133,7 @@ struct cdk_dek_s int algo; int keylen; int use_mdc; - byte key[32]; /* 256-bit */ + byte key[32]; /* 256-bit */ }; struct cdk_strlist_s diff --git a/lib/opencdk/dummy.c b/lib/opencdk/dummy.c index 0ede7ed41d..be44a35170 100644 --- a/lib/opencdk/dummy.c +++ b/lib/opencdk/dummy.c @@ -8,8 +8,8 @@ cdk_error_t _cdk_proc_packets (cdk_ctx_t hd, cdk_stream_t inp, cdk_stream_t data, - const char *output, cdk_stream_t outstream, - digest_hd_st * md) + const char *output, cdk_stream_t outstream, + digest_hd_st * md) { return 0; } diff --git a/lib/opencdk/filters.h b/lib/opencdk/filters.h index d948d1436f..fc770eaabc 100644 --- a/lib/opencdk/filters.h +++ b/lib/opencdk/filters.h @@ -55,7 +55,7 @@ typedef struct typedef struct { - const char *le; /* line endings */ + const char *le; /* line endings */ const char *hdrlines; u32 crc; int crc_okay; @@ -65,7 +65,7 @@ typedef struct typedef struct { cdk_lit_format_t mode; - char *orig_filename; /* This original name of the input file. */ + char *orig_filename; /* This original name of the input file. */ char *filename; digest_hd_st md; int md_initialized; @@ -82,7 +82,7 @@ typedef struct byte inbuf[8192]; size_t outbufsize; byte outbuf[8192]; - int algo; /* compress algo */ + int algo; /* compress algo */ int level; } compress_filter_t; @@ -105,6 +105,6 @@ int _cdk_filter_text (void *opaque, int ctl, FILE * in, FILE * out); /*-- compress.c --*/ cdk_error_t _cdk_filter_compress (void *opaque, int ctl, - FILE * in, FILE * out); + FILE * in, FILE * out); #endif /* CDK_FILTERS_H */ diff --git a/lib/opencdk/hash.c b/lib/opencdk/hash.c index 9ac9d9c682..349845d653 100644 --- a/lib/opencdk/hash.c +++ b/lib/opencdk/hash.c @@ -52,10 +52,10 @@ hash_encode (void *data, FILE * in, FILE * out) { err = _gnutls_hash_init (&mfx->md, mfx->digest_algo); if (err < 0) - { - gnutls_assert (); - return map_gnutls_error (err); - } + { + gnutls_assert (); + return map_gnutls_error (err); + } mfx->md_initialized = 1; } @@ -64,7 +64,7 @@ hash_encode (void *data, FILE * in, FILE * out) { nread = fread (buf, 1, BUFSIZE, in); if (!nread) - break; + break; _gnutls_hash (&mfx->md, buf, nread); } @@ -81,12 +81,12 @@ _cdk_filter_hash (void *data, int ctl, FILE * in, FILE * out) { md_filter_t *mfx = data; if (mfx) - { - _cdk_log_debug ("free hash filter\n"); - _gnutls_hash_deinit (&mfx->md, NULL); - mfx->md_initialized = 0; - return 0; - } + { + _cdk_log_debug ("free hash filter\n"); + _gnutls_hash_deinit (&mfx->md, NULL); + mfx->md_initialized = 0; + return 0; + } } gnutls_assert (); diff --git a/lib/opencdk/kbnode.c b/lib/opencdk/kbnode.c index b93c5c9a8e..e2ebab2f38 100644 --- a/lib/opencdk/kbnode.c +++ b/lib/opencdk/kbnode.c @@ -78,7 +78,7 @@ cdk_kbnode_release (cdk_kbnode_t node) { n2 = node->next; if (!node->is_cloned) - cdk_pkt_release (node->pkt); + cdk_pkt_release (node->pkt); cdk_free (node); node = n2; } @@ -122,7 +122,7 @@ _cdk_kbnode_add (cdk_kbnode_t root, cdk_kbnode_t node) **/ void cdk_kbnode_insert (cdk_kbnode_t root, cdk_kbnode_t node, - cdk_packet_type_t pkttype) + cdk_packet_type_t pkttype) { if (!pkttype) { @@ -134,12 +134,12 @@ cdk_kbnode_insert (cdk_kbnode_t root, cdk_kbnode_t node, cdk_kbnode_t n1; for (n1 = root; n1->next; n1 = n1->next) - if (pkttype != n1->next->pkt->pkttype) - { - node->next = n1->next; - n1->next = node; - return; - } + if (pkttype != n1->next->pkt->pkttype) + { + node->next = n1->next; + n1->next = node; + return; + } /* No such packet, append */ node->next = NULL; n1->next = node; @@ -158,14 +158,14 @@ cdk_kbnode_insert (cdk_kbnode_t root, cdk_kbnode_t node, **/ cdk_kbnode_t cdk_kbnode_find_prev (cdk_kbnode_t root, cdk_kbnode_t node, - cdk_packet_type_t pkttype) + cdk_packet_type_t pkttype) { cdk_kbnode_t n1; for (n1 = NULL; root && root != node; root = root->next) { if (!pkttype || root->pkt->pkttype == pkttype) - n1 = root; + n1 = root; } return n1; } @@ -189,18 +189,18 @@ cdk_kbnode_find_next (cdk_kbnode_t node, cdk_packet_type_t pkttype) for (node = node->next; node; node = node->next) { if (!pkttype) - return node; + return node; else if (pkttype == CDK_PKT_USER_ID && - (node->pkt->pkttype == CDK_PKT_PUBLIC_KEY || - node->pkt->pkttype == CDK_PKT_SECRET_KEY)) - return NULL; + (node->pkt->pkttype == CDK_PKT_PUBLIC_KEY || + node->pkt->pkttype == CDK_PKT_SECRET_KEY)) + return NULL; else if (pkttype == CDK_PKT_SIGNATURE && - (node->pkt->pkttype == CDK_PKT_USER_ID || - node->pkt->pkttype == CDK_PKT_PUBLIC_KEY || - node->pkt->pkttype == CDK_PKT_SECRET_KEY)) - return NULL; + (node->pkt->pkttype == CDK_PKT_USER_ID || + node->pkt->pkttype == CDK_PKT_PUBLIC_KEY || + node->pkt->pkttype == CDK_PKT_SECRET_KEY)) + return NULL; else if (node->pkt->pkttype == pkttype) - return node; + return node; } return NULL; } @@ -219,7 +219,7 @@ cdk_kbnode_find (cdk_kbnode_t node, cdk_packet_type_t pkttype) for (; node; node = node->next) { if (node->pkt->pkttype == pkttype) - return node; + return node; } return NULL; } @@ -258,15 +258,15 @@ cdk_kbnode_walk (cdk_kbnode_t root, cdk_kbnode_t * ctx, int all) do { if (!*ctx) - { - *ctx = root; - n = root; - } + { + *ctx = root; + n = root; + } else - { - n = (*ctx)->next; - *ctx = n; - } + { + n = (*ctx)->next; + *ctx = n; + } } while (!all && n && n->is_deleted); return n; @@ -292,18 +292,18 @@ cdk_kbnode_commit (cdk_kbnode_t * root) for (n = *root, nl = NULL; n; n = nl->next) { if (n->is_deleted) - { - if (n == *root) - *root = nl = n->next; - else - nl->next = n->next; - if (!n->is_cloned) - cdk_pkt_release (n->pkt); - cdk_free (n); - changed = 1; - } + { + if (n == *root) + *root = nl = n->next; + else + nl->next = n->next; + if (!n->is_cloned) + cdk_pkt_release (n->pkt); + cdk_free (n); + changed = 1; + } else - nl = n; + nl = n; } return changed; } @@ -324,17 +324,17 @@ cdk_kbnode_remove (cdk_kbnode_t * root, cdk_kbnode_t node) for (n = *root, nl = NULL; n; n = nl->next) { if (n == node) - { - if (n == *root) - *root = nl = n->next; - else - nl->next = n->next; - if (!n->is_cloned) - cdk_pkt_release (n->pkt); - cdk_free (n); - } + { + if (n == *root) + *root = nl = n->next; + else + nl->next = n->next; + if (!n->is_cloned) + cdk_pkt_release (n->pkt); + cdk_free (n); + } else - nl = n; + nl = n; } } @@ -358,18 +358,18 @@ cdk_kbnode_move (cdk_kbnode_t * root, cdk_kbnode_t node, cdk_kbnode_t where) for (prev = *root; prev && prev->next != node; prev = prev->next) ; if (!prev) - return; /* Node is not in the list */ + return; /* Node is not in the list */ if (!where) - { /* Move node before root */ + { /* Move node before root */ if (node == *root) - return; + return; prev->next = node->next; node->next = *root; *root = node; return; } - if (node == where) /* Move it after where. */ + if (node == where) /* Move it after where. */ return; tmp = node->next; node->next = where->next; @@ -405,7 +405,7 @@ cdk_kbnode_get_packet (cdk_kbnode_t node) **/ cdk_error_t cdk_kbnode_read_from_mem (cdk_kbnode_t * ret_node, - const byte * buf, size_t buflen) + const byte * buf, size_t buflen) { cdk_stream_t inp; cdk_error_t rc; @@ -439,7 +439,7 @@ cdk_kbnode_read_from_mem (cdk_kbnode_t * ret_node, */ cdk_error_t cdk_kbnode_write_to_mem_alloc (cdk_kbnode_t node, - byte ** r_buf, size_t * r_buflen) + byte ** r_buf, size_t * r_buflen) { cdk_kbnode_t n; cdk_stream_t s; @@ -466,20 +466,20 @@ cdk_kbnode_write_to_mem_alloc (cdk_kbnode_t node, { /* Skip all packets which cannot occur in a key composition. */ if (n->pkt->pkttype != CDK_PKT_PUBLIC_KEY && - n->pkt->pkttype != CDK_PKT_PUBLIC_SUBKEY && - n->pkt->pkttype != CDK_PKT_SECRET_KEY && - n->pkt->pkttype != CDK_PKT_SECRET_SUBKEY && - n->pkt->pkttype != CDK_PKT_SIGNATURE && - n->pkt->pkttype != CDK_PKT_USER_ID && - n->pkt->pkttype != CDK_PKT_ATTRIBUTE) - continue; + n->pkt->pkttype != CDK_PKT_PUBLIC_SUBKEY && + n->pkt->pkttype != CDK_PKT_SECRET_KEY && + n->pkt->pkttype != CDK_PKT_SECRET_SUBKEY && + n->pkt->pkttype != CDK_PKT_SIGNATURE && + n->pkt->pkttype != CDK_PKT_USER_ID && + n->pkt->pkttype != CDK_PKT_ATTRIBUTE) + continue; rc = cdk_pkt_write (s, n->pkt); if (rc) - { - cdk_stream_close (s); - gnutls_assert (); - return rc; - } + { + cdk_stream_close (s); + gnutls_assert (); + return rc; + } } cdk_stream_seek (s, 0); @@ -527,27 +527,27 @@ cdk_kbnode_write_to_mem (cdk_kbnode_t node, byte * buf, size_t * r_nbytes) { /* Skip all packets which cannot occur in a key composition. */ if (n->pkt->pkttype != CDK_PKT_PUBLIC_KEY && - n->pkt->pkttype != CDK_PKT_PUBLIC_SUBKEY && - n->pkt->pkttype != CDK_PKT_SECRET_KEY && - n->pkt->pkttype != CDK_PKT_SECRET_SUBKEY && - n->pkt->pkttype != CDK_PKT_SIGNATURE && - n->pkt->pkttype != CDK_PKT_USER_ID && - n->pkt->pkttype != CDK_PKT_ATTRIBUTE) - continue; + n->pkt->pkttype != CDK_PKT_PUBLIC_SUBKEY && + n->pkt->pkttype != CDK_PKT_SECRET_KEY && + n->pkt->pkttype != CDK_PKT_SECRET_SUBKEY && + n->pkt->pkttype != CDK_PKT_SIGNATURE && + n->pkt->pkttype != CDK_PKT_USER_ID && + n->pkt->pkttype != CDK_PKT_ATTRIBUTE) + continue; rc = cdk_pkt_write (s, n->pkt); if (rc) - { - cdk_stream_close (s); - gnutls_assert (); - return rc; - } + { + cdk_stream_close (s); + gnutls_assert (); + return rc; + } } cdk_stream_seek (s, 0); len = cdk_stream_get_length (s); if (!buf) { - *r_nbytes = len; /* Only return the length of the buffer */ + *r_nbytes = len; /* Only return the length of the buffer */ cdk_stream_close (s); return 0; } @@ -580,7 +580,7 @@ cdk_kbnode_write_to_mem (cdk_kbnode_t node, byte * buf, size_t * r_nbytes) **/ cdk_error_t cdk_kbnode_hash (cdk_kbnode_t node, digest_hd_st * md, int is_v4, - cdk_packet_type_t pkttype, int flags) + cdk_packet_type_t pkttype, int flags) { cdk_packet_t pkt; @@ -598,10 +598,10 @@ cdk_kbnode_hash (cdk_kbnode_t node, digest_hd_st * md, int is_v4, { pkt = cdk_kbnode_find_packet (node, pkttype); if (!pkt) - { - gnutls_assert (); - return CDK_Inv_Packet; - } + { + gnutls_assert (); + return CDK_Inv_Packet; + } } switch (pkttype) diff --git a/lib/opencdk/keydb.c b/lib/opencdk/keydb.c index ab7e65d0ba..7ef91e4caf 100644 --- a/lib/opencdk/keydb.c +++ b/lib/opencdk/keydb.c @@ -119,21 +119,21 @@ keydb_idx_build (const char *file) rc = cdk_pkt_read (inp, pkt); if (rc) - { - _cdk_log_debug ("index build failed packet off=%lu\n", pos); - /* FIXME: The index is incomplete */ - break; - } + { + _cdk_log_debug ("index build failed packet off=%lu\n", pos); + /* FIXME: The index is incomplete */ + break; + } if (pkt->pkttype == CDK_PKT_PUBLIC_KEY || - pkt->pkttype == CDK_PKT_PUBLIC_SUBKEY) - { - _cdk_u32tobuf (pos, buf); - cdk_pk_get_keyid (pkt->pkt.public_key, keyid); - _cdk_u32tobuf (keyid[0], buf + 4); - _cdk_u32tobuf (keyid[1], buf + 8); - cdk_pk_get_fingerprint (pkt->pkt.public_key, buf + 12); - cdk_stream_write (out, buf, 4 + 8 + KEY_FPR_LEN); - } + pkt->pkttype == CDK_PKT_PUBLIC_SUBKEY) + { + _cdk_u32tobuf (pos, buf); + cdk_pk_get_keyid (pkt->pkt.public_key, keyid); + _cdk_u32tobuf (keyid[0], buf + 4); + _cdk_u32tobuf (keyid[1], buf + 8); + cdk_pk_get_fingerprint (pkt->pkt.public_key, buf + 12); + cdk_stream_write (out, buf, 4 + 8 + KEY_FPR_LEN); + } cdk_pkt_free (pkt); } @@ -187,10 +187,10 @@ cdk_keydb_idx_rebuild (cdk_keydb_hd_t db, cdk_keydb_search_t dbs) { dbs->idx_name = keydb_idx_mkname (db->name); if (!dbs->idx_name) - { - gnutls_assert (); - return CDK_Out_Of_Core; - } + { + gnutls_assert (); + return CDK_Out_Of_Core; + } } rc = keydb_idx_build (db->name); if (!rc) @@ -223,7 +223,7 @@ keydb_idx_parse (cdk_stream_t inp, key_idx_t * r_idx) while (!cdk_stream_eof (inp)) { if (cdk_stream_read (inp, buf, 4) == CDK_EOF) - break; + break; idx->offset = _cdk_buftou32 (buf); cdk_stream_read (inp, buf, 4); idx->keyid[0] = _cdk_buftou32 (buf); @@ -239,7 +239,7 @@ keydb_idx_parse (cdk_stream_t inp, key_idx_t * r_idx) static cdk_error_t keydb_idx_search (cdk_stream_t inp, u32 * keyid, const byte * fpr, - off_t * r_off) + off_t * r_off) { key_idx_t idx; @@ -262,15 +262,15 @@ keydb_idx_search (cdk_stream_t inp, u32 * keyid, const byte * fpr, while (keydb_idx_parse (inp, &idx) != CDK_EOF) { if (keyid && KEYID_CMP (keyid, idx->keyid)) - { - *r_off = idx->offset; - break; - } + { + *r_off = idx->offset; + break; + } else if (fpr && !memcmp (idx->fpr, fpr, KEY_FPR_LEN)) - { - *r_off = idx->offset; - break; - } + { + *r_off = idx->offset; + break; + } cdk_free (idx); idx = NULL; } @@ -289,7 +289,7 @@ keydb_idx_search (cdk_stream_t inp, u32 * keyid, const byte * fpr, */ cdk_error_t cdk_keydb_new_from_mem (cdk_keydb_hd_t * r_db, int secret, - const void *data, size_t datlen) + const void *data, size_t datlen) { cdk_keydb_hd_t db; cdk_error_t rc; @@ -397,7 +397,7 @@ cdk_keydb_new (cdk_keydb_hd_t * r_hd, int type, void *data, size_t count) case CDK_DBTYPE_PK_KEYRING: case CDK_DBTYPE_SK_KEYRING: return cdk_keydb_new_from_file (r_hd, type == CDK_DBTYPE_SK_KEYRING, - (const char *) data); + (const char *) data); case CDK_DBTYPE_DATA: return cdk_keydb_new_from_mem (r_hd, 0, data, count); @@ -465,15 +465,15 @@ _cdk_keydb_open (cdk_keydb_hd_t hd, cdk_stream_t * ret_kr) cdk_stream_seek (kr, 0); } else if (hd->type == CDK_DBTYPE_PK_KEYRING || - hd->type == CDK_DBTYPE_SK_KEYRING) + hd->type == CDK_DBTYPE_SK_KEYRING) { rc = cdk_stream_open (hd->name, &kr); if (rc) - goto leave; + goto leave; if (cdk_armor_filter_use (kr)) - cdk_stream_set_armor_flag (kr, 0); + cdk_stream_set_armor_flag (kr, 0); } else { @@ -497,28 +497,28 @@ find_by_keyid (cdk_kbnode_t knode, cdk_keydb_search_t ks) for (node = knode; node; node = node->next) { if (node->pkt->pkttype == CDK_PKT_PUBLIC_KEY || - node->pkt->pkttype == CDK_PKT_PUBLIC_SUBKEY || - node->pkt->pkttype == CDK_PKT_SECRET_KEY || - node->pkt->pkttype == CDK_PKT_SECRET_SUBKEY) - { - _cdk_pkt_get_keyid (node->pkt, keyid); - switch (ks->type) - { - case CDK_DBSEARCH_SHORT_KEYID: - if (keyid[1] == ks->u.keyid[1]) - return 1; - break; - - case CDK_DBSEARCH_KEYID: - if (KEYID_CMP (keyid, ks->u.keyid)) - return 1; - break; - - default: - _cdk_log_debug ("find_by_keyid: invalid mode = %d\n", ks->type); - return 0; - } - } + node->pkt->pkttype == CDK_PKT_PUBLIC_SUBKEY || + node->pkt->pkttype == CDK_PKT_SECRET_KEY || + node->pkt->pkttype == CDK_PKT_SECRET_SUBKEY) + { + _cdk_pkt_get_keyid (node->pkt, keyid); + switch (ks->type) + { + case CDK_DBSEARCH_SHORT_KEYID: + if (keyid[1] == ks->u.keyid[1]) + return 1; + break; + + case CDK_DBSEARCH_KEYID: + if (KEYID_CMP (keyid, ks->u.keyid)) + return 1; + break; + + default: + _cdk_log_debug ("find_by_keyid: invalid mode = %d\n", ks->type); + return 0; + } + } } return 0; } @@ -536,15 +536,15 @@ find_by_fpr (cdk_kbnode_t knode, cdk_keydb_search_t ks) for (node = knode; node; node = node->next) { if (node->pkt->pkttype == CDK_PKT_PUBLIC_KEY || - node->pkt->pkttype == CDK_PKT_PUBLIC_SUBKEY || - node->pkt->pkttype == CDK_PKT_SECRET_KEY || - node->pkt->pkttype == CDK_PKT_SECRET_SUBKEY) - { - _cdk_pkt_get_fingerprint (node->pkt, fpr); - if (!memcmp (ks->u.fpr, fpr, KEY_FPR_LEN)) - return 1; - break; - } + node->pkt->pkttype == CDK_PKT_PUBLIC_SUBKEY || + node->pkt->pkttype == CDK_PKT_SECRET_KEY || + node->pkt->pkttype == CDK_PKT_SECRET_SUBKEY) + { + _cdk_pkt_get_fingerprint (node->pkt, fpr); + if (!memcmp (ks->u.fpr, fpr, KEY_FPR_LEN)) + return 1; + break; + } } return 0; @@ -561,32 +561,32 @@ find_by_pattern (cdk_kbnode_t knode, cdk_keydb_search_t ks) for (node = knode; node; node = node->next) { if (node->pkt->pkttype != CDK_PKT_USER_ID) - continue; + continue; if (node->pkt->pkt.user_id->attrib_img != NULL) - continue; /* Skip attribute packets. */ + continue; /* Skip attribute packets. */ uidlen = node->pkt->pkt.user_id->len; name = node->pkt->pkt.user_id->name; switch (ks->type) - { - case CDK_DBSEARCH_EXACT: - if (name && - (strlen (ks->u.pattern) == uidlen && - !strncmp (ks->u.pattern, name, uidlen))) - return 1; - break; - - case CDK_DBSEARCH_SUBSTR: - if (uidlen > 65536) - break; - if (name && strlen (ks->u.pattern) > uidlen) - break; - if (name && _cdk_memistr (name, uidlen, ks->u.pattern)) - return 1; - break; - - default: /* Invalid mode */ - return 0; - } + { + case CDK_DBSEARCH_EXACT: + if (name && + (strlen (ks->u.pattern) == uidlen && + !strncmp (ks->u.pattern, name, uidlen))) + return 1; + break; + + case CDK_DBSEARCH_SUBSTR: + if (uidlen > 65536) + break; + if (name && strlen (ks->u.pattern) > uidlen) + break; + if (name && _cdk_memistr (name, uidlen, ks->u.pattern)) + return 1; + break; + + default: /* Invalid mode */ + return 0; + } } return 0; } @@ -616,29 +616,29 @@ keydb_cache_find (cdk_keydb_search_t desc) for (t = cache; t; t = t->next) { switch (desc->type) - { - case CDK_DBSEARCH_SHORT_KEYID: - case CDK_DBSEARCH_KEYID: - if (KEYID_CMP (desc->u.keyid, desc->u.keyid)) - return t; - break; - - case CDK_DBSEARCH_EXACT: - if (strlen (desc->u.pattern) == strlen (desc->u.pattern) && - !strcmp (desc->u.pattern, desc->u.pattern)) - return t; - break; - - case CDK_DBSEARCH_SUBSTR: - if (strstr (desc->u.pattern, desc->u.pattern)) - return t; - break; - - case CDK_DBSEARCH_FPR: - if (!memcmp (desc->u.fpr, desc->u.fpr, KEY_FPR_LEN)) - return t; - break; - } + { + case CDK_DBSEARCH_SHORT_KEYID: + case CDK_DBSEARCH_KEYID: + if (KEYID_CMP (desc->u.keyid, desc->u.keyid)) + return t; + break; + + case CDK_DBSEARCH_EXACT: + if (strlen (desc->u.pattern) == strlen (desc->u.pattern) && + !strcmp (desc->u.pattern, desc->u.pattern)) + return t; + break; + + case CDK_DBSEARCH_SUBSTR: + if (strstr (desc->u.pattern, desc->u.pattern)) + return t; + break; + + case CDK_DBSEARCH_FPR: + if (!memcmp (desc->u.fpr, desc->u.fpr, KEY_FPR_LEN)) + return t; + break; + } } return NULL; @@ -651,7 +651,7 @@ keydb_cache_add (cdk_keydb_search_t dbs, off_t offset) key_table_t k; if (dbs->ncache > KEYDB_CACHE_ENTRIES) - return 0; /* FIXME: we should replace the last entry. */ + return 0; /* FIXME: we should replace the last entry. */ k = cdk_calloc (1, sizeof *k); if (!k) { @@ -665,7 +665,7 @@ keydb_cache_add (cdk_keydb_search_t dbs, off_t offset) dbs->cache = k; dbs->ncache++; _cdk_log_debug ("cache: add entry off=%d type=%d\n", (int) offset, - (int) dbs->type); + (int) dbs->type); return 0; } @@ -692,20 +692,20 @@ idx_init (cdk_keydb_hd_t db, cdk_keydb_search_t dbs) { rc = keydb_idx_build (db->name); if (!rc) - rc = cdk_stream_open (dbs->idx_name, &dbs->idx); + rc = cdk_stream_open (dbs->idx_name, &dbs->idx); if (!rc) - { - _cdk_log_debug ("create key index table\n"); - } + { + _cdk_log_debug ("create key index table\n"); + } else - { - /* This is no real error, it just means we can't create - the index at the given directory. maybe we've no write - access. in this case, we simply disable the index. */ - _cdk_log_debug ("disable key index table err=%d\n", rc); - rc = 0; - dbs->no_cache = 1; - } + { + /* This is no real error, it just means we can't create + the index at the given directory. maybe we've no write + access. in this case, we simply disable the index. */ + _cdk_log_debug ("disable key index table err=%d\n", rc); + rc = 0; + dbs->no_cache = 1; + } } leave: @@ -724,7 +724,7 @@ leave: **/ cdk_error_t cdk_keydb_search_start (cdk_keydb_search_t * st, cdk_keydb_hd_t db, int type, - void *desc) + void *desc) { u32 *keyid; char *p, tmp[3]; @@ -765,11 +765,11 @@ cdk_keydb_search_start (cdk_keydb_search_t * st, cdk_keydb_hd_t db, int type, cdk_free ((*st)->u.pattern); (*st)->u.pattern = cdk_strdup (desc); if (!(*st)->u.pattern) - { - cdk_free (*st); - gnutls_assert (); - return CDK_Out_Of_Core; - } + { + cdk_free (*st); + gnutls_assert (); + return CDK_Out_Of_Core; + } break; case CDK_DBSEARCH_SHORT_KEYID: @@ -794,59 +794,59 @@ cdk_keydb_search_start (cdk_keydb_search_t * st, cdk_keydb_hd_t db, int type, /* Override the type with the actual db search type. */ (*st)->type = classify_data (desc, strlen (desc)); switch ((*st)->type) - { - case CDK_DBSEARCH_SUBSTR: - case CDK_DBSEARCH_EXACT: - cdk_free ((*st)->u.pattern); - p = (*st)->u.pattern = cdk_strdup (desc); - if (!p) - { - cdk_free (*st); - gnutls_assert (); - return CDK_Out_Of_Core; - } - break; - - case CDK_DBSEARCH_SHORT_KEYID: - case CDK_DBSEARCH_KEYID: - p = desc; - if (!strncmp (p, "0x", 2)) - p += 2; - if (strlen (p) == 8) - { - (*st)->u.keyid[0] = 0; - (*st)->u.keyid[1] = strtoul (p, NULL, 16); - } - else if (strlen (p) == 16) - { - (*st)->u.keyid[0] = strtoul (p, NULL, 16); - (*st)->u.keyid[1] = strtoul (p + 8, NULL, 16); - } - else - { /* Invalid key ID object. */ - cdk_free (*st); - gnutls_assert (); - return CDK_Inv_Mode; - } - break; - - case CDK_DBSEARCH_FPR: - p = desc; - if (strlen (p) != 2 * KEY_FPR_LEN) - { - cdk_free (*st); - gnutls_assert (); - return CDK_Inv_Mode; - } - for (i = 0; i < KEY_FPR_LEN; i++) - { - tmp[0] = p[2 * i]; - tmp[1] = p[2 * i + 1]; - tmp[2] = 0x00; - (*st)->u.fpr[i] = strtoul (tmp, NULL, 16); - } - break; - } + { + case CDK_DBSEARCH_SUBSTR: + case CDK_DBSEARCH_EXACT: + cdk_free ((*st)->u.pattern); + p = (*st)->u.pattern = cdk_strdup (desc); + if (!p) + { + cdk_free (*st); + gnutls_assert (); + return CDK_Out_Of_Core; + } + break; + + case CDK_DBSEARCH_SHORT_KEYID: + case CDK_DBSEARCH_KEYID: + p = desc; + if (!strncmp (p, "0x", 2)) + p += 2; + if (strlen (p) == 8) + { + (*st)->u.keyid[0] = 0; + (*st)->u.keyid[1] = strtoul (p, NULL, 16); + } + else if (strlen (p) == 16) + { + (*st)->u.keyid[0] = strtoul (p, NULL, 16); + (*st)->u.keyid[1] = strtoul (p + 8, NULL, 16); + } + else + { /* Invalid key ID object. */ + cdk_free (*st); + gnutls_assert (); + return CDK_Inv_Mode; + } + break; + + case CDK_DBSEARCH_FPR: + p = desc; + if (strlen (p) != 2 * KEY_FPR_LEN) + { + cdk_free (*st); + gnutls_assert (); + return CDK_Inv_Mode; + } + for (i = 0; i < KEY_FPR_LEN; i++) + { + tmp[0] = p[2 * i]; + tmp[1] = p[2 * i + 1]; + tmp[2] = 0x00; + (*st)->u.fpr[i] = strtoul (tmp, NULL, 16); + } + break; + } break; default: @@ -862,7 +862,7 @@ cdk_keydb_search_start (cdk_keydb_search_t * st, cdk_keydb_hd_t db, int type, static cdk_error_t keydb_pos_from_cache (cdk_keydb_hd_t hd, cdk_keydb_search_t ks, - int *r_cache_hit, off_t * r_off) + int *r_cache_hit, off_t * r_off) { key_table_t c; @@ -892,25 +892,25 @@ keydb_pos_from_cache (cdk_keydb_hd_t hd, cdk_keydb_search_t ks, if (ks->idx) { if (ks->type == CDK_DBSEARCH_KEYID) - { - if (keydb_idx_search (ks->idx, ks->u.keyid, NULL, r_off)) - { - gnutls_assert (); - return CDK_Error_No_Key; - } - _cdk_log_debug ("cache: found keyid entry in idx table.\n"); - *r_cache_hit = 1; - } + { + if (keydb_idx_search (ks->idx, ks->u.keyid, NULL, r_off)) + { + gnutls_assert (); + return CDK_Error_No_Key; + } + _cdk_log_debug ("cache: found keyid entry in idx table.\n"); + *r_cache_hit = 1; + } else if (ks->type == CDK_DBSEARCH_FPR) - { - if (keydb_idx_search (ks->idx, NULL, ks->u.fpr, r_off)) - { - gnutls_assert (); - return CDK_Error_No_Key; - } - _cdk_log_debug ("cache: found fpr entry in idx table.\n"); - *r_cache_hit = 1; - } + { + if (keydb_idx_search (ks->idx, NULL, ks->u.fpr, r_off)) + { + gnutls_assert (); + return CDK_Error_No_Key; + } + _cdk_log_debug ("cache: found fpr entry in idx table.\n"); + *r_cache_hit = 1; + } } return 0; @@ -943,7 +943,7 @@ cdk_keydb_search_release (cdk_keydb_search_t st) **/ cdk_error_t cdk_keydb_search (cdk_keydb_search_t st, cdk_keydb_hd_t hd, - cdk_kbnode_t * ret_key) + cdk_kbnode_t * ret_key) { cdk_stream_t kr; cdk_kbnode_t knode; @@ -974,7 +974,7 @@ cdk_keydb_search (cdk_keydb_search_t st, cdk_keydb_hd_t hd, and continue our normal search procedure. */ rc = keydb_pos_from_cache (hd, st, &cache_hit, &off); if (rc) - cache_hit = 0; + cache_hit = 0; } knode = NULL; @@ -982,53 +982,53 @@ cdk_keydb_search (cdk_keydb_search_t st, cdk_keydb_hd_t hd, while (!key_found && !rc) { if (cache_hit && st->type != CDK_DBSEARCH_NEXT) - cdk_stream_seek (kr, off); + cdk_stream_seek (kr, off); else if (st->type == CDK_DBSEARCH_NEXT) - cdk_stream_seek (kr, st->off); + cdk_stream_seek (kr, st->off); pos = cdk_stream_tell (kr); rc = cdk_keydb_get_keyblock (kr, &knode); if (rc) - { - if (rc == CDK_EOF) - break; - else - { - gnutls_assert (); - return rc; - } - } + { + if (rc == CDK_EOF) + break; + else + { + gnutls_assert (); + return rc; + } + } switch (st->type) - { - case CDK_DBSEARCH_SHORT_KEYID: - case CDK_DBSEARCH_KEYID: - key_found = find_by_keyid (knode, st); - break; - - case CDK_DBSEARCH_FPR: - key_found = find_by_fpr (knode, st); - break; - - case CDK_DBSEARCH_EXACT: - case CDK_DBSEARCH_SUBSTR: - key_found = find_by_pattern (knode, st); - break; - - case CDK_DBSEARCH_NEXT: - st->off = cdk_stream_tell (kr); - key_found = knode ? 1 : 0; - break; - } + { + case CDK_DBSEARCH_SHORT_KEYID: + case CDK_DBSEARCH_KEYID: + key_found = find_by_keyid (knode, st); + break; + + case CDK_DBSEARCH_FPR: + key_found = find_by_fpr (knode, st); + break; + + case CDK_DBSEARCH_EXACT: + case CDK_DBSEARCH_SUBSTR: + key_found = find_by_pattern (knode, st); + break; + + case CDK_DBSEARCH_NEXT: + st->off = cdk_stream_tell (kr); + key_found = knode ? 1 : 0; + break; + } if (key_found) - { - if (!keydb_cache_find (st)) - keydb_cache_add (st, pos); - break; - } + { + if (!keydb_cache_find (st)) + keydb_cache_add (st, pos); + break; + } cdk_kbnode_release (knode); knode = NULL; @@ -1068,7 +1068,7 @@ cdk_keydb_get_bykeyid (cdk_keydb_hd_t hd, u32 * keyid, cdk_kbnode_t * ret_key) cdk_error_t cdk_keydb_get_byfpr (cdk_keydb_hd_t hd, const byte * fpr, - cdk_kbnode_t * r_key) + cdk_kbnode_t * r_key) { cdk_error_t rc; cdk_keydb_search_t st; @@ -1090,7 +1090,7 @@ cdk_keydb_get_byfpr (cdk_keydb_hd_t hd, const byte * fpr, cdk_error_t cdk_keydb_get_bypattern (cdk_keydb_hd_t hd, const char *patt, - cdk_kbnode_t * ret_key) + cdk_kbnode_t * ret_key) { cdk_error_t rc; cdk_keydb_search_t st; @@ -1126,12 +1126,12 @@ keydb_check_key (cdk_packet_t pkt) is_sk = 0; } else if (pkt->pkttype == CDK_PKT_SECRET_KEY || - pkt->pkttype == CDK_PKT_SECRET_SUBKEY) + pkt->pkttype == CDK_PKT_SECRET_SUBKEY) { pk = pkt->pkt.secret_key->pk; is_sk = 1; } - else /* No key object. */ + else /* No key object. */ return 0; valid = !pk->is_revoked && !pk->has_expired; if (is_sk) @@ -1150,9 +1150,9 @@ kbnode_find_valid (cdk_kbnode_t root, cdk_packet_type_t pkttype) for (n = root; n; n = n->next) { if (n->pkt->pkttype != pkttype) - continue; + continue; if (keydb_check_key (n->pkt)) - return n; + return n; } return NULL; @@ -1182,21 +1182,21 @@ keydb_find_byusage (cdk_kbnode_t root, int req_usage, int is_pk) for (node = root; node; node = node->next) { if (is_pk && (node->pkt->pkttype == CDK_PKT_PUBLIC_KEY || - node->pkt->pkttype == CDK_PKT_PUBLIC_SUBKEY) - && keydb_check_key (node->pkt) - && (node->pkt->pkt.public_key->pubkey_usage & req_usage)) - { - if (node->pkt->pkt.public_key->timestamp > timestamp) - key = node; - } + node->pkt->pkttype == CDK_PKT_PUBLIC_SUBKEY) + && keydb_check_key (node->pkt) + && (node->pkt->pkt.public_key->pubkey_usage & req_usage)) + { + if (node->pkt->pkt.public_key->timestamp > timestamp) + key = node; + } if (!is_pk && (node->pkt->pkttype == CDK_PKT_SECRET_KEY || - node->pkt->pkttype == CDK_PKT_SECRET_SUBKEY) - && keydb_check_key (node->pkt) - && (node->pkt->pkt.secret_key->pk->pubkey_usage & req_usage)) - { - if (node->pkt->pkt.secret_key->pk->timestamp > timestamp) - key = node; - } + node->pkt->pkttype == CDK_PKT_SECRET_SUBKEY) + && keydb_check_key (node->pkt) + && (node->pkt->pkt.secret_key->pk->pubkey_usage & req_usage)) + { + if (node->pkt->pkt.secret_key->pk->timestamp > timestamp) + key = node; + } } return key; @@ -1212,11 +1212,11 @@ keydb_find_bykeyid (cdk_kbnode_t root, const u32 * keyid, int search_mode) for (node = root; node; node = node->next) { if (!_cdk_pkt_get_keyid (node->pkt, kid)) - continue; + continue; if (search_mode == CDK_DBSEARCH_SHORT_KEYID && kid[1] == keyid[1]) - return node; + return node; else if (kid[0] == keyid[0] && kid[1] == keyid[1]) - return node; + return node; } return NULL; } @@ -1224,7 +1224,7 @@ keydb_find_bykeyid (cdk_kbnode_t root, const u32 * keyid, int search_mode) cdk_error_t _cdk_keydb_get_sk_byusage (cdk_keydb_hd_t hd, const char *name, - cdk_seckey_t * ret_sk, int usage) + cdk_seckey_t * ret_sk, int usage) { cdk_kbnode_t knode = NULL; cdk_kbnode_t node, sk_node, pk_node; @@ -1279,14 +1279,14 @@ _cdk_keydb_get_sk_byusage (cdk_keydb_hd_t hd, const char *name, for (node = knode; node; node = node->next) { if (node->pkt->pkttype == CDK_PKT_USER_ID) - { - s = node->pkt->pkt.user_id->name; - if (sk && !sk->pk->uid && _cdk_memistr (s, strlen (s), name)) - { - _cdk_copy_userid (&sk->pk->uid, node->pkt->pkt.user_id); - break; - } - } + { + s = node->pkt->pkt.user_id->name; + if (sk && !sk->pk->uid && _cdk_memistr (s, strlen (s), name)) + { + _cdk_copy_userid (&sk->pk->uid, node->pkt->pkt.user_id); + break; + } + } } /* To find the self signature, we need the primary public key because @@ -1312,7 +1312,7 @@ _cdk_keydb_get_sk_byusage (cdk_keydb_hd_t hd, const char *name, cdk_error_t _cdk_keydb_get_pk_byusage (cdk_keydb_hd_t hd, const char *name, - cdk_pubkey_t * ret_pk, int usage) + cdk_pubkey_t * ret_pk, int usage) { cdk_kbnode_t knode, node, pk_node; cdk_pkt_pubkey_t pk; @@ -1356,14 +1356,14 @@ _cdk_keydb_get_pk_byusage (cdk_keydb_hd_t hd, const char *name, for (node = knode; node; node = node->next) { if (node->pkt->pkttype == CDK_PKT_USER_ID) - { - s = node->pkt->pkt.user_id->name; - if (pk && !pk->uid && _cdk_memistr (s, strlen (s), name)) - { - _cdk_copy_userid (&pk->uid, node->pkt->pkt.user_id); - break; - } - } + { + s = node->pkt->pkt.user_id->name; + if (pk && !pk->uid && _cdk_memistr (s, strlen (s), name)) + { + _cdk_copy_userid (&pk->uid, node->pkt->pkt.user_id); + break; + } + } } /* Same as in the sk code, the selected key can be a sub key @@ -1536,10 +1536,10 @@ find_selfsig_node (cdk_kbnode_t key, cdk_pkt_pubkey_t pk) for (n = key; n; n = n->next) { if (is_selfsig (n, keyid) && n->pkt->pkt.signature->timestamp > ts) - { - ts = n->pkt->pkt.signature->timestamp; - sig = n; - } + { + ts = n->pkt->pkt.signature->timestamp; + sig = n; + } } return sig; @@ -1550,19 +1550,19 @@ key_usage_to_cdk_usage (unsigned int usage) { unsigned key_usage = 0; - if (usage & 0x01) /* cert + sign data */ + if (usage & 0x01) /* cert + sign data */ key_usage |= CDK_KEY_USG_CERT_SIGN; - if (usage & 0x02) /* cert + sign data */ + if (usage & 0x02) /* cert + sign data */ key_usage |= CDK_KEY_USG_DATA_SIGN; - if (usage & 0x04) /* encrypt comm. + storage */ + if (usage & 0x04) /* encrypt comm. + storage */ key_usage |= CDK_KEY_USG_COMM_ENCR; - if (usage & 0x08) /* encrypt comm. + storage */ + if (usage & 0x08) /* encrypt comm. + storage */ key_usage |= CDK_KEY_USG_STORAGE_ENCR; - if (usage & 0x10) /* encrypt comm. + storage */ + if (usage & 0x10) /* encrypt comm. + storage */ key_usage |= CDK_KEY_USG_SPLIT_KEY; if (usage & 0x20) key_usage |= CDK_KEY_USG_AUTH; - if (usage & 0x80) /* encrypt comm. + storage */ + if (usage & 0x80) /* encrypt comm. + storage */ key_usage |= CDK_KEY_USG_SHARED_KEY; return key_usage; @@ -1588,78 +1588,78 @@ keydb_merge_selfsig (cdk_kbnode_t key, u32 * keyid) for (node = key; node; node = node->next) { if (!is_selfsig (node, keyid)) - continue; + continue; unode = cdk_kbnode_find_prev (key, node, CDK_PKT_USER_ID); if (!unode) - { - gnutls_assert (); - return CDK_Error_No_Key; - } + { + gnutls_assert (); + return CDK_Error_No_Key; + } uid = unode->pkt->pkt.user_id; sig = node->pkt->pkt.signature; s = cdk_subpkt_find (sig->hashed, CDK_SIGSUBPKT_PRIMARY_UID); if (s) - uid->is_primary = 1; + uid->is_primary = 1; s = cdk_subpkt_find (sig->hashed, CDK_SIGSUBPKT_FEATURES); if (s && s->size == 1 && s->d[0] & 0x01) - uid->mdc_feature = 1; + uid->mdc_feature = 1; s = cdk_subpkt_find (sig->hashed, CDK_SIGSUBPKT_KEY_EXPIRE); if (s && s->size == 4) - key_expire = _cdk_buftou32 (s->d); + key_expire = _cdk_buftou32 (s->d); s = cdk_subpkt_find (sig->hashed, CDK_SIGSUBPKT_PREFS_SYM); if (s) - { - symalg = s->d; - nsymalg = s->size; - n += s->size + 1; - } + { + symalg = s->d; + nsymalg = s->size; + n += s->size + 1; + } s = cdk_subpkt_find (sig->hashed, CDK_SIGSUBPKT_PREFS_HASH); if (s) - { - hashalg = s->d; - nhashalg = s->size; - n += s->size + 1; - } + { + hashalg = s->d; + nhashalg = s->size; + n += s->size + 1; + } s = cdk_subpkt_find (sig->hashed, CDK_SIGSUBPKT_PREFS_ZIP); if (s) - { - compalg = s->d; - ncompalg = s->size; - n += s->size + 1; - } + { + compalg = s->d; + ncompalg = s->size; + n += s->size + 1; + } if (uid->prefs != NULL) - cdk_free (uid->prefs); + cdk_free (uid->prefs); if (!n || !hashalg || !compalg || !symalg) - uid->prefs = NULL; + uid->prefs = NULL; else - { - uid->prefs = cdk_calloc (1, sizeof (*uid->prefs) * (n + 1)); - if (!uid->prefs) - { - gnutls_assert (); - return CDK_Out_Of_Core; - } - n = 0; - for (; nsymalg; nsymalg--, n++) - { - uid->prefs[n].type = CDK_PREFTYPE_SYM; - uid->prefs[n].value = *symalg++; - } - for (; nhashalg; nhashalg--, n++) - { - uid->prefs[n].type = CDK_PREFTYPE_HASH; - uid->prefs[n].value = *hashalg++; - } - for (; ncompalg; ncompalg--, n++) - { - uid->prefs[n].type = CDK_PREFTYPE_ZIP; - uid->prefs[n].value = *compalg++; - } - - uid->prefs[n].type = CDK_PREFTYPE_NONE; /* end of list marker */ - uid->prefs[n].value = 0; - uid->prefs_size = n; - } + { + uid->prefs = cdk_calloc (1, sizeof (*uid->prefs) * (n + 1)); + if (!uid->prefs) + { + gnutls_assert (); + return CDK_Out_Of_Core; + } + n = 0; + for (; nsymalg; nsymalg--, n++) + { + uid->prefs[n].type = CDK_PREFTYPE_SYM; + uid->prefs[n].value = *symalg++; + } + for (; nhashalg; nhashalg--, n++) + { + uid->prefs[n].type = CDK_PREFTYPE_HASH; + uid->prefs[n].value = *hashalg++; + } + for (; ncompalg; ncompalg--, n++) + { + uid->prefs[n].type = CDK_PREFTYPE_ZIP; + uid->prefs[n].value = *compalg++; + } + + uid->prefs[n].type = CDK_PREFTYPE_NONE; /* end of list marker */ + uid->prefs[n].value = 0; + uid->prefs_size = n; + } } /* Now we add the extracted information to the primary key. */ @@ -1668,17 +1668,17 @@ keydb_merge_selfsig (cdk_kbnode_t key, u32 * keyid) { cdk_pkt_pubkey_t pk = kbnode->pkt->pkt.public_key; if (uid && uid->prefs && n) - { - if (pk->prefs != NULL) - cdk_free (pk->prefs); - pk->prefs = _cdk_copy_prefs (uid->prefs); - pk->prefs_size = n; - } + { + if (pk->prefs != NULL) + cdk_free (pk->prefs); + pk->prefs = _cdk_copy_prefs (uid->prefs); + pk->prefs_size = n; + } if (key_expire) - { - pk->expiredate = pk->timestamp + key_expire; - pk->has_expired = pk->expiredate > (u32) time (NULL) ? 0 : 1; - } + { + pk->expiredate = pk->timestamp + key_expire; + pk->has_expired = pk->expiredate > (u32) time (NULL) ? 0 : 1; + } pk->is_invalid = 0; } @@ -1716,10 +1716,10 @@ keydb_parse_allsigs (cdk_kbnode_t knode, cdk_keydb_hd_t hd, int check) for (node = knode; node; node = node->next) { if (node->pkt->pkttype == CDK_PKT_USER_ID) - node->pkt->pkt.user_id->is_revoked = 0; + node->pkt->pkt.user_id->is_revoked = 0; else if (node->pkt->pkttype == CDK_PKT_PUBLIC_KEY || - node->pkt->pkttype == CDK_PKT_PUBLIC_SUBKEY) - node->pkt->pkt.public_key->is_revoked = 0; + node->pkt->pkttype == CDK_PKT_PUBLIC_SUBKEY) + node->pkt->pkt.public_key->is_revoked = 0; } kb = cdk_kbnode_find (knode, CDK_PKT_PUBLIC_KEY); @@ -1733,109 +1733,109 @@ keydb_parse_allsigs (cdk_kbnode_t knode, cdk_keydb_hd_t hd, int check) for (node = knode; node; node = node->next) { if (node->pkt->pkttype == CDK_PKT_SIGNATURE) - { - sig = node->pkt->pkt.signature; - /* Revocation certificates for primary keys */ - if (sig->sig_class == 0x20) - { - kb = cdk_kbnode_find_prev (knode, node, CDK_PKT_PUBLIC_KEY); - if (kb) - { - kb->pkt->pkt.public_key->is_revoked = 1; - if (check) - _cdk_pk_check_sig (hd, kb, node, NULL, NULL); - } - else - { - gnutls_assert (); - return CDK_Error_No_Key; - } - } - /* Revocation certificates for subkeys */ - else if (sig->sig_class == 0x28) - { - kb = cdk_kbnode_find_prev (knode, node, CDK_PKT_PUBLIC_SUBKEY); - if (kb) - { - kb->pkt->pkt.public_key->is_revoked = 1; - if (check) - _cdk_pk_check_sig (hd, kb, node, NULL, NULL); - } - else - { - gnutls_assert (); - return CDK_Error_No_Key; - } - } - /* Revocation certifcates for user ID's */ - else if (sig->sig_class == 0x30) - { - if (sig->keyid[0] != keyid[0] || sig->keyid[1] != keyid[1]) - continue; /* revokes an earlier signature, no userID. */ - kb = cdk_kbnode_find_prev (knode, node, CDK_PKT_USER_ID); - if (kb) - { - kb->pkt->pkt.user_id->is_revoked = 1; - if (check) - _cdk_pk_check_sig (hd, kb, node, NULL, NULL); - } - else - { - gnutls_assert (); - return CDK_Error_No_Key; - } - } - /* Direct certificates for primary keys */ - else if (sig->sig_class == 0x1F) - { - kb = cdk_kbnode_find_prev (knode, node, CDK_PKT_PUBLIC_KEY); - if (kb) - { - pk = kb->pkt->pkt.public_key; - pk->is_invalid = 0; - s = cdk_subpkt_find (node->pkt->pkt.signature->hashed, - CDK_SIGSUBPKT_KEY_EXPIRE); - if (s) - { - expiredate = _cdk_buftou32 (s->d); - pk->expiredate = pk->timestamp + expiredate; - pk->has_expired = pk->expiredate > curtime ? 0 : 1; - } - if (check) - _cdk_pk_check_sig (hd, kb, node, NULL, NULL); - } - else - { - gnutls_assert (); - return CDK_Error_No_Key; - } - } - /* Direct certificates for subkeys */ - else if (sig->sig_class == 0x18) - { - kb = cdk_kbnode_find_prev (knode, node, CDK_PKT_PUBLIC_SUBKEY); - if (kb) - { - pk = kb->pkt->pkt.public_key; - pk->is_invalid = 0; - s = cdk_subpkt_find (node->pkt->pkt.signature->hashed, - CDK_SIGSUBPKT_KEY_EXPIRE); - if (s) - { - expiredate = _cdk_buftou32 (s->d); - pk->expiredate = pk->timestamp + expiredate; - pk->has_expired = pk->expiredate > curtime ? 0 : 1; - } - if (check) - _cdk_pk_check_sig (hd, kb, node, NULL, NULL); - } - else - { - gnutls_assert (); - return CDK_Error_No_Key; - } - } - } + { + sig = node->pkt->pkt.signature; + /* Revocation certificates for primary keys */ + if (sig->sig_class == 0x20) + { + kb = cdk_kbnode_find_prev (knode, node, CDK_PKT_PUBLIC_KEY); + if (kb) + { + kb->pkt->pkt.public_key->is_revoked = 1; + if (check) + _cdk_pk_check_sig (hd, kb, node, NULL, NULL); + } + else + { + gnutls_assert (); + return CDK_Error_No_Key; + } + } + /* Revocation certificates for subkeys */ + else if (sig->sig_class == 0x28) + { + kb = cdk_kbnode_find_prev (knode, node, CDK_PKT_PUBLIC_SUBKEY); + if (kb) + { + kb->pkt->pkt.public_key->is_revoked = 1; + if (check) + _cdk_pk_check_sig (hd, kb, node, NULL, NULL); + } + else + { + gnutls_assert (); + return CDK_Error_No_Key; + } + } + /* Revocation certifcates for user ID's */ + else if (sig->sig_class == 0x30) + { + if (sig->keyid[0] != keyid[0] || sig->keyid[1] != keyid[1]) + continue; /* revokes an earlier signature, no userID. */ + kb = cdk_kbnode_find_prev (knode, node, CDK_PKT_USER_ID); + if (kb) + { + kb->pkt->pkt.user_id->is_revoked = 1; + if (check) + _cdk_pk_check_sig (hd, kb, node, NULL, NULL); + } + else + { + gnutls_assert (); + return CDK_Error_No_Key; + } + } + /* Direct certificates for primary keys */ + else if (sig->sig_class == 0x1F) + { + kb = cdk_kbnode_find_prev (knode, node, CDK_PKT_PUBLIC_KEY); + if (kb) + { + pk = kb->pkt->pkt.public_key; + pk->is_invalid = 0; + s = cdk_subpkt_find (node->pkt->pkt.signature->hashed, + CDK_SIGSUBPKT_KEY_EXPIRE); + if (s) + { + expiredate = _cdk_buftou32 (s->d); + pk->expiredate = pk->timestamp + expiredate; + pk->has_expired = pk->expiredate > curtime ? 0 : 1; + } + if (check) + _cdk_pk_check_sig (hd, kb, node, NULL, NULL); + } + else + { + gnutls_assert (); + return CDK_Error_No_Key; + } + } + /* Direct certificates for subkeys */ + else if (sig->sig_class == 0x18) + { + kb = cdk_kbnode_find_prev (knode, node, CDK_PKT_PUBLIC_SUBKEY); + if (kb) + { + pk = kb->pkt->pkt.public_key; + pk->is_invalid = 0; + s = cdk_subpkt_find (node->pkt->pkt.signature->hashed, + CDK_SIGSUBPKT_KEY_EXPIRE); + if (s) + { + expiredate = _cdk_buftou32 (s->d); + pk->expiredate = pk->timestamp + expiredate; + pk->has_expired = pk->expiredate > curtime ? 0 : 1; + } + if (check) + _cdk_pk_check_sig (hd, kb, node, NULL, NULL); + } + else + { + gnutls_assert (); + return CDK_Error_No_Key; + } + } + } } node = cdk_kbnode_find (knode, CDK_PKT_PUBLIC_KEY); if (node && node->pkt->pkt.public_key->version == 3) @@ -1844,24 +1844,24 @@ keydb_parse_allsigs (cdk_kbnode_t knode, cdk_keydb_hd_t hd, int check) we say the key is valid when we have at least a self signature. */ pk = node->pkt->pkt.public_key; for (node = knode; node; node = node->next) - { - if (is_selfsig (node, keyid)) - { - pk->is_invalid = 0; - break; - } - } + { + if (is_selfsig (node, keyid)) + { + pk->is_invalid = 0; + break; + } + } } if (node && (node->pkt->pkt.public_key->is_revoked || - node->pkt->pkt.public_key->has_expired)) + node->pkt->pkt.public_key->has_expired)) { /* If the primary key has been revoked, mark all subkeys as invalid because without a primary key they are not useable */ for (node = knode; node; node = node->next) - { - if (node->pkt->pkttype == CDK_PKT_PUBLIC_SUBKEY) - node->pkt->pkt.public_key->is_invalid = 1; - } + { + if (node->pkt->pkttype == CDK_PKT_PUBLIC_SUBKEY) + node->pkt->pkt.public_key->is_invalid = 1; + } } return 0; @@ -1878,13 +1878,13 @@ add_key_usage (cdk_kbnode_t knode, u32 keyid[2], unsigned int usage) { pkt = cdk_kbnode_get_packet (p); if ((pkt->pkttype == CDK_PKT_PUBLIC_SUBKEY - || pkt->pkttype == CDK_PKT_PUBLIC_KEY) - && pkt->pkt.public_key->keyid[0] == keyid[0] - && pkt->pkt.public_key->keyid[1] == keyid[1]) - { - pkt->pkt.public_key->pubkey_usage = usage; - return; - } + || pkt->pkttype == CDK_PKT_PUBLIC_KEY) + && pkt->pkt.public_key->keyid[0] == keyid[0] + && pkt->pkt.public_key->keyid[1] == keyid[1]) + { + pkt->pkt.public_key->pubkey_usage = usage; + return; + } } return; } @@ -1921,83 +1921,83 @@ cdk_keydb_get_keyblock (cdk_stream_t inp, cdk_kbnode_t * r_knode) old_off = cdk_stream_tell (inp); rc = cdk_pkt_read (inp, pkt); if (rc) - { - cdk_pkt_release (pkt); - if (rc == CDK_EOF) - break; - else - { /* Release all packets we reached so far. */ - _cdk_log_debug ("keydb_get_keyblock: error %d\n", rc); - cdk_kbnode_release (knode); - gnutls_assert (); - return rc; - } - } + { + cdk_pkt_release (pkt); + if (rc == CDK_EOF) + break; + else + { /* Release all packets we reached so far. */ + _cdk_log_debug ("keydb_get_keyblock: error %d\n", rc); + cdk_kbnode_release (knode); + gnutls_assert (); + return rc; + } + } if (pkt->pkttype == CDK_PKT_PUBLIC_KEY || - pkt->pkttype == CDK_PKT_PUBLIC_SUBKEY || - pkt->pkttype == CDK_PKT_SECRET_KEY || - pkt->pkttype == CDK_PKT_SECRET_SUBKEY) - { - if (key_seen && (pkt->pkttype == CDK_PKT_PUBLIC_KEY || - pkt->pkttype == CDK_PKT_SECRET_KEY)) - { - /* The next key starts here so set the file pointer - and leave the loop. */ - cdk_stream_seek (inp, old_off); - cdk_pkt_release (pkt); - break; - } - if (pkt->pkttype == CDK_PKT_PUBLIC_KEY || - pkt->pkttype == CDK_PKT_SECRET_KEY) - { - _cdk_pkt_get_keyid (pkt, main_keyid); - key_seen = 1; - } - else if (pkt->pkttype == CDK_PKT_PUBLIC_SUBKEY || - pkt->pkttype == CDK_PKT_SECRET_SUBKEY) - { - if (pkt->pkttype == CDK_PKT_PUBLIC_SUBKEY) - { - pkt->pkt.public_key->main_keyid[0] = main_keyid[0]; - pkt->pkt.public_key->main_keyid[1] = main_keyid[1]; - } - else - { - pkt->pkt.secret_key->main_keyid[0] = main_keyid[0]; - pkt->pkt.secret_key->main_keyid[1] = main_keyid[1]; - } - } - /* We save this for the signature */ - _cdk_pkt_get_keyid (pkt, keyid); - got_key = 1; - } + pkt->pkttype == CDK_PKT_PUBLIC_SUBKEY || + pkt->pkttype == CDK_PKT_SECRET_KEY || + pkt->pkttype == CDK_PKT_SECRET_SUBKEY) + { + if (key_seen && (pkt->pkttype == CDK_PKT_PUBLIC_KEY || + pkt->pkttype == CDK_PKT_SECRET_KEY)) + { + /* The next key starts here so set the file pointer + and leave the loop. */ + cdk_stream_seek (inp, old_off); + cdk_pkt_release (pkt); + break; + } + if (pkt->pkttype == CDK_PKT_PUBLIC_KEY || + pkt->pkttype == CDK_PKT_SECRET_KEY) + { + _cdk_pkt_get_keyid (pkt, main_keyid); + key_seen = 1; + } + else if (pkt->pkttype == CDK_PKT_PUBLIC_SUBKEY || + pkt->pkttype == CDK_PKT_SECRET_SUBKEY) + { + if (pkt->pkttype == CDK_PKT_PUBLIC_SUBKEY) + { + pkt->pkt.public_key->main_keyid[0] = main_keyid[0]; + pkt->pkt.public_key->main_keyid[1] = main_keyid[1]; + } + else + { + pkt->pkt.secret_key->main_keyid[0] = main_keyid[0]; + pkt->pkt.secret_key->main_keyid[1] = main_keyid[1]; + } + } + /* We save this for the signature */ + _cdk_pkt_get_keyid (pkt, keyid); + got_key = 1; + } else if (pkt->pkttype == CDK_PKT_USER_ID) - ; + ; else if (pkt->pkttype == CDK_PKT_SIGNATURE) - { - cdk_subpkt_t s; - - pkt->pkt.signature->key[0] = keyid[0]; - pkt->pkt.signature->key[1] = keyid[1]; - if (pkt->pkt.signature->sig_class == 0x1F && - pkt->pkt.signature->revkeys) - revkeys = pkt->pkt.signature->revkeys; - - s = - cdk_subpkt_find (pkt->pkt.signature->hashed, - CDK_SIGSUBPKT_KEY_FLAGS); - if (s) - { - unsigned int key_usage = key_usage_to_cdk_usage (s->d[0]); - add_key_usage (knode, pkt->pkt.signature->key, key_usage); - } - } + { + cdk_subpkt_t s; + + pkt->pkt.signature->key[0] = keyid[0]; + pkt->pkt.signature->key[1] = keyid[1]; + if (pkt->pkt.signature->sig_class == 0x1F && + pkt->pkt.signature->revkeys) + revkeys = pkt->pkt.signature->revkeys; + + s = + cdk_subpkt_find (pkt->pkt.signature->hashed, + CDK_SIGSUBPKT_KEY_FLAGS); + if (s) + { + unsigned int key_usage = key_usage_to_cdk_usage (s->d[0]); + add_key_usage (knode, pkt->pkt.signature->key, key_usage); + } + } node = cdk_kbnode_new (pkt); if (!knode) - knode = node; + knode = node; else - _cdk_kbnode_add (knode, node); + _cdk_kbnode_add (knode, node); } if (got_key) @@ -2005,11 +2005,11 @@ cdk_keydb_get_keyblock (cdk_stream_t inp, cdk_kbnode_t * r_knode) keydb_merge_selfsig (knode, main_keyid); rc = keydb_parse_allsigs (knode, NULL, 0); if (revkeys) - { - node = cdk_kbnode_find (knode, CDK_PKT_PUBLIC_KEY); - if (node) - node->pkt->pkt.public_key->revkeys = revkeys; - } + { + node = cdk_kbnode_find (knode, CDK_PKT_PUBLIC_KEY); + if (node) + node->pkt->pkt.public_key->revkeys = revkeys; + } } else cdk_kbnode_release (knode); @@ -2033,7 +2033,7 @@ classify_data (const byte * buf, size_t len) unsigned int i; if (buf[0] == '0' && (buf[1] == 'x' || buf[1] == 'X')) - { /* Skip hex prefix. */ + { /* Skip hex prefix. */ buf += 2; len -= 2; } @@ -2045,7 +2045,7 @@ classify_data (const byte * buf, size_t len) for (i = 0; i < len; i++) { if (!isxdigit (buf[i])) - return CDK_DBSEARCH_SUBSTR; + return CDK_DBSEARCH_SUBSTR; } if (i != len) return CDK_DBSEARCH_SUBSTR; @@ -2092,57 +2092,57 @@ cdk_keydb_export (cdk_keydb_hd_t hd, cdk_stream_t out, cdk_strlist_t remusr) { rc = cdk_keydb_search_start (&st, hd, CDK_DBSEARCH_AUTO, r->d); if (rc) - { - gnutls_assert (); - return rc; - } + { + gnutls_assert (); + return rc; + } rc = cdk_keydb_search (st, hd, &knode); cdk_keydb_search_release (st); if (rc) - { - gnutls_assert (); - return rc; - } + { + gnutls_assert (); + return rc; + } node = cdk_kbnode_find (knode, CDK_PKT_PUBLIC_KEY); if (!node) - { - gnutls_assert (); - return CDK_Error_No_Key; - } + { + gnutls_assert (); + return CDK_Error_No_Key; + } /* If the key is a version 3 key, use the old packet format for the output. */ if (node->pkt->pkt.public_key->version == 3) - old_ctb = 1; + old_ctb = 1; else - old_ctb = 0; + old_ctb = 0; for (node = knode; node; node = node->next) - { - /* No specified format; skip them */ - if (node->pkt->pkttype == CDK_PKT_RING_TRUST) - continue; - /* We never export local signed signatures */ - if (node->pkt->pkttype == CDK_PKT_SIGNATURE && - !node->pkt->pkt.signature->flags.exportable) - continue; - /* Filter out invalid signatures */ - if (node->pkt->pkttype == CDK_PKT_SIGNATURE && - (!KEY_CAN_SIGN (node->pkt->pkt.signature->pubkey_algo))) - continue; - - /* Adjust the ctb flag if needed. */ - node->pkt->old_ctb = old_ctb; - rc = cdk_pkt_write (out, node->pkt); - if (rc) - { - cdk_kbnode_release (knode); - gnutls_assert (); - return rc; - } - } + { + /* No specified format; skip them */ + if (node->pkt->pkttype == CDK_PKT_RING_TRUST) + continue; + /* We never export local signed signatures */ + if (node->pkt->pkttype == CDK_PKT_SIGNATURE && + !node->pkt->pkt.signature->flags.exportable) + continue; + /* Filter out invalid signatures */ + if (node->pkt->pkttype == CDK_PKT_SIGNATURE && + (!KEY_CAN_SIGN (node->pkt->pkt.signature->pubkey_algo))) + continue; + + /* Adjust the ctb flag if needed. */ + node->pkt->old_ctb = old_ctb; + rc = cdk_pkt_write (out, node->pkt); + if (rc) + { + cdk_kbnode_release (knode); + gnutls_assert (); + return rc; + } + } cdk_kbnode_release (knode); knode = NULL; } @@ -2160,7 +2160,7 @@ find_key_packet (cdk_kbnode_t knode, int *r_is_sk) { pkt = cdk_kbnode_find_packet (knode, CDK_PKT_SECRET_KEY); if (r_is_sk) - *r_is_sk = pkt ? 1 : 0; + *r_is_sk = pkt ? 1 : 0; } return pkt; } @@ -2215,7 +2215,7 @@ cdk_keydb_import (cdk_keydb_hd_t hd, cdk_kbnode_t knode) chk = NULL; cdk_keydb_get_bykeyid (hd, keyid, &chk); if (chk) - { /* FIXME: search for new signatures */ + { /* FIXME: search for new signatures */ cdk_kbnode_release (chk); return 0; } @@ -2238,28 +2238,28 @@ cdk_keydb_import (cdk_keydb_hd_t hd, cdk_kbnode_t knode) for (node = knode; node; node = node->next) { if (node->pkt->pkttype == CDK_PKT_RING_TRUST) - continue; /* No uniformed syntax for this packet */ + continue; /* No uniformed syntax for this packet */ if (node->pkt->pkttype == CDK_PKT_SIGNATURE && - !node->pkt->pkt.signature->flags.exportable) - { - _cdk_log_debug ("key db import: skip local signature\n"); - continue; - } + !node->pkt->pkt.signature->flags.exportable) + { + _cdk_log_debug ("key db import: skip local signature\n"); + continue; + } if (!is_key_node (node)) - { - _cdk_log_debug ("key db import: skip invalid node of type %d\n", - node->pkt->pkttype); - continue; - } + { + _cdk_log_debug ("key db import: skip invalid node of type %d\n", + node->pkt->pkttype); + continue; + } rc = cdk_pkt_write (out, node->pkt); if (rc) - { - cdk_stream_close (out); - gnutls_assert (); - return rc; - } + { + cdk_stream_close (out); + gnutls_assert (); + return rc; + } } cdk_stream_close (out); @@ -2365,17 +2365,17 @@ cdk_keydb_check_sk (cdk_keydb_hd_t hd, u32 * keyid) while (!cdk_pkt_read (db, pkt)) { if (pkt->pkttype != CDK_PKT_SECRET_KEY && - pkt->pkttype != CDK_PKT_SECRET_SUBKEY) - { - cdk_pkt_free (pkt); - continue; - } + pkt->pkttype != CDK_PKT_SECRET_SUBKEY) + { + cdk_pkt_free (pkt); + continue; + } cdk_sk_get_keyid (pkt->pkt.secret_key, kid); if (KEYID_CMP (kid, keyid)) - { - cdk_pkt_release (pkt); - return 0; - } + { + cdk_pkt_release (pkt); + return 0; + } cdk_pkt_free (pkt); } cdk_pkt_release (pkt); @@ -2398,7 +2398,7 @@ cdk_keydb_check_sk (cdk_keydb_hd_t hd, u32 * keyid) **/ cdk_error_t cdk_listkey_start (cdk_listkey_t * r_ctx, cdk_keydb_hd_t db, - const char *patt, cdk_strlist_t fpatt) + const char *patt, cdk_strlist_t fpatt) { cdk_listkey_t ctx; cdk_stream_t inp; @@ -2432,16 +2432,16 @@ cdk_listkey_start (cdk_listkey_t * r_ctx, cdk_keydb_hd_t db, { ctx->u.patt = cdk_strdup (patt); if (!ctx->u.patt) - { - gnutls_assert (); - return CDK_Out_Of_Core; - } + { + gnutls_assert (); + return CDK_Out_Of_Core; + } } else if (fpatt) { cdk_strlist_t l; for (l = fpatt; l; l = l->next) - cdk_strlist_add (&ctx->u.fpatt, l->d); + cdk_strlist_add (&ctx->u.fpatt, l->d); } ctx->type = patt ? 1 : 0; ctx->init = 1; @@ -2500,33 +2500,33 @@ cdk_listkey_next (cdk_listkey_t ctx, cdk_kbnode_t * ret_key) cdk_error_t rc; for (;;) - { - rc = cdk_keydb_get_keyblock (ctx->inp, &node); - if (rc) - { - gnutls_assert (); - return rc; - } - memset (&ks, 0, sizeof (ks)); - ks.type = CDK_DBSEARCH_SUBSTR; - ks.u.pattern = ctx->u.patt; - if (find_by_pattern (node, &ks)) - { - *ret_key = node; - return 0; - } - cdk_kbnode_release (node); - node = NULL; - } + { + rc = cdk_keydb_get_keyblock (ctx->inp, &node); + if (rc) + { + gnutls_assert (); + return rc; + } + memset (&ks, 0, sizeof (ks)); + ks.type = CDK_DBSEARCH_SUBSTR; + ks.u.pattern = ctx->u.patt; + if (find_by_pattern (node, &ks)) + { + *ret_key = node; + return 0; + } + cdk_kbnode_release (node); + node = NULL; + } } else { if (!ctx->t) - ctx->t = ctx->u.fpatt; + ctx->t = ctx->u.fpatt; else if (ctx->t->next) - ctx->t = ctx->t->next; + ctx->t = ctx->t->next; else - return CDK_EOF; + return CDK_EOF; return cdk_keydb_get_bypattern (ctx->db, ctx->t->d, ret_key); } gnutls_assert (); diff --git a/lib/opencdk/keydb.h b/lib/opencdk/keydb.h index fb2bf4903f..e88f054d89 100644 --- a/lib/opencdk/keydb.h +++ b/lib/opencdk/keydb.h @@ -17,36 +17,36 @@ typedef struct key_table_s *key_table_t; typedef struct cdk_keydb_search_s { - off_t off; /* last file offset */ + off_t off; /* last file offset */ union { - char *pattern; /* A search is performed by pattern. */ - u32 keyid[2]; /* A search by keyid. */ - byte fpr[KEY_FPR_LEN]; /* A search by fingerprint. */ + char *pattern; /* A search is performed by pattern. */ + u32 keyid[2]; /* A search by keyid. */ + byte fpr[KEY_FPR_LEN]; /* A search by fingerprint. */ } u; int type; struct key_table_s *cache; size_t ncache; - unsigned int no_cache:1; /* disable the index cache. */ + unsigned int no_cache:1; /* disable the index cache. */ cdk_stream_t idx; - char *idx_name; /* name of the index file or NULL. */ + char *idx_name; /* name of the index file or NULL. */ } cdk_keydb_search_s; /* Internal key database handle. */ struct cdk_keydb_hd_s { - int type; /* type of the key db handle. */ - int fp_ref; /* 1=means it is a reference and shall not be closed. */ + int type; /* type of the key db handle. */ + int fp_ref; /* 1=means it is a reference and shall not be closed. */ cdk_stream_t fp; - char *name; /* name of the underlying file or NULL. */ - unsigned int secret:1; /* contain secret keys. */ - unsigned int isopen:1; /* the underlying stream is opened. */ + char *name; /* name of the underlying file or NULL. */ + unsigned int secret:1; /* contain secret keys. */ + unsigned int isopen:1; /* the underlying stream is opened. */ /* structure to store some stats about the keydb. */ struct { - size_t new_keys; /* amount of new keys that were imported. */ + size_t new_keys; /* amount of new keys that were imported. */ } stats; }; diff --git a/lib/opencdk/literal.c b/lib/opencdk/literal.c index 769f117e74..4c8f966124 100644 --- a/lib/opencdk/literal.c +++ b/lib/opencdk/literal.c @@ -104,16 +104,16 @@ literal_decode (void *data, FILE * in, FILE * out) from the original name and cut off the OpenPGP extension. If this is not possible, we return an error. */ if (!stristr (pfx->orig_filename, ".gpg") && - !stristr (pfx->orig_filename, ".pgp") && - !stristr (pfx->orig_filename, ".asc")) - { - cdk_pkt_release (pkt); - cdk_stream_close (si); - cdk_stream_close (so); - _cdk_log_debug - ("literal filter: no file name and no PGP extension\n"); - return CDK_Inv_Mode; - } + !stristr (pfx->orig_filename, ".pgp") && + !stristr (pfx->orig_filename, ".asc")) + { + cdk_pkt_release (pkt); + cdk_stream_close (si); + cdk_stream_close (so); + _cdk_log_debug + ("literal filter: no file name and no PGP extension\n"); + return CDK_Inv_Mode; + } _cdk_log_debug ("literal filter: derrive file name from original\n"); pfx->filename = dup_trim_filename (pfx->orig_filename); pfx->filename[strlen (pfx->filename) - 4] = '\0'; @@ -122,29 +122,29 @@ literal_decode (void *data, FILE * in, FILE * out) while (!feof (in)) { _cdk_log_debug ("literal_decode: part on %d size %lu\n", - (int) pfx->blkmode.on, pfx->blkmode.size); + (int) pfx->blkmode.on, pfx->blkmode.size); if (pfx->blkmode.on) - bufsize = pfx->blkmode.size; + bufsize = pfx->blkmode.size; else - bufsize = pt->len < DIM (buf) ? pt->len : DIM (buf); + bufsize = pt->len < DIM (buf) ? pt->len : DIM (buf); nread = cdk_stream_read (pt->buf, buf, bufsize); if (nread == EOF) - { - rc = CDK_File_Error; - break; - } + { + rc = CDK_File_Error; + break; + } if (pfx->md_initialized) - _gnutls_hash (&pfx->md, buf, nread); + _gnutls_hash (&pfx->md, buf, nread); cdk_stream_write (so, buf, nread); pt->len -= nread; if (pfx->blkmode.on) - { - pfx->blkmode.size = _cdk_pkt_read_len (in, &pfx->blkmode.on); - if ((ssize_t) pfx->blkmode.size == EOF) - return CDK_Inv_Packet; - } + { + pfx->blkmode.size = _cdk_pkt_read_len (in, &pfx->blkmode.on); + if ((ssize_t) pfx->blkmode.size == EOF) + return CDK_Inv_Packet; + } if (pt->len <= 0 && !pfx->blkmode.on) - break; + break; } cdk_stream_close (si); @@ -191,7 +191,7 @@ literal_encode (void *data, FILE * in, FILE * out) { pfx->filename = cdk_strdup ("_CONSOLE"); if (!pfx->filename) - return CDK_Out_Of_Core; + return CDK_Out_Of_Core; } rc = _cdk_stream_fpopen (in, STREAMCTL_READ, &si); @@ -237,14 +237,14 @@ _cdk_filter_literal (void *data, int ctl, FILE * in, FILE * out) { literal_filter_t *pfx = data; if (pfx) - { - _cdk_log_debug ("free literal filter\n"); - cdk_free (pfx->filename); - pfx->filename = NULL; - cdk_free (pfx->orig_filename); - pfx->orig_filename = NULL; - return 0; - } + { + _cdk_log_debug ("free literal filter\n"); + cdk_free (pfx->filename); + pfx->filename = NULL; + cdk_free (pfx->orig_filename); + pfx->orig_filename = NULL; + return 0; + } } return CDK_Inv_Mode; } @@ -264,7 +264,7 @@ text_encode (void *data, FILE * in, FILE * out) { s = fgets (buf, DIM (buf) - 1, in); if (!s) - break; + break; _cdk_trim_string (buf, 1); fwrite (buf, 1, strlen (buf), out); } @@ -287,7 +287,7 @@ text_decode (void *data, FILE * in, FILE * out) { s = fgets (buf, DIM (buf) - 1, in); if (!s) - break; + break; _cdk_trim_string (buf, 0); fwrite (buf, 1, strlen (buf), out); fwrite (tfx->lf, 1, strlen (tfx->lf), out); @@ -308,10 +308,10 @@ _cdk_filter_text (void *data, int ctl, FILE * in, FILE * out) { text_filter_t *tfx = data; if (tfx) - { - _cdk_log_debug ("free text filter\n"); - tfx->lf = NULL; - } + { + _cdk_log_debug ("free text filter\n"); + tfx->lf = NULL; + } } return CDK_Inv_Mode; } diff --git a/lib/opencdk/main.c b/lib/opencdk/main.c index 3052bf1387..1dd0ea23eb 100644 --- a/lib/opencdk/main.c +++ b/lib/opencdk/main.c @@ -94,9 +94,9 @@ handle_set_compress (cdk_ctx_t hd, int algo, int level) else { if (level > 0 && level < 10) - hd->compress.level = level; + hd->compress.level = level; else - hd->compress.level = 6; + hd->compress.level = 6; } } @@ -125,59 +125,59 @@ cdk_handle_control (cdk_ctx_t hd, int action, int cmd, ...) { case CDK_CTL_ARMOR: if (set) - hd->opt.armor = va_arg (arg_ptr, int); + hd->opt.armor = va_arg (arg_ptr, int); else - val = hd->opt.armor; + val = hd->opt.armor; break; case CDK_CTL_DIGEST: if (set) - handle_set_digest (hd, va_arg (arg_ptr, int)); + handle_set_digest (hd, va_arg (arg_ptr, int)); else - val = hd->digest_algo; + val = hd->digest_algo; break; case CDK_CTL_OVERWRITE: if (set) - hd->opt.overwrite = va_arg (arg_ptr, int); + hd->opt.overwrite = va_arg (arg_ptr, int); else - val = hd->opt.overwrite; + val = hd->opt.overwrite; break; case CDK_CTL_COMPRESS: if (set) - { - int algo = va_arg (arg_ptr, int); - int level = va_arg (arg_ptr, int); - handle_set_compress (hd, algo, level); - } + { + int algo = va_arg (arg_ptr, int); + int level = va_arg (arg_ptr, int); + handle_set_compress (hd, algo, level); + } else - val = hd->compress.algo; + val = hd->compress.algo; break; case CDK_CTL_S2K: if (set) - { - int mode = va_arg (arg_ptr, int); - int digest = va_arg (arg_ptr, int); - handle_set_s2k (hd, mode, digest); - } + { + int mode = va_arg (arg_ptr, int); + int digest = va_arg (arg_ptr, int); + handle_set_s2k (hd, mode, digest); + } else - val = hd->_s2k.mode; + val = hd->_s2k.mode; break; case CDK_CTL_FORCE_DIGEST: if (set) - hd->opt.force_digest = va_arg (arg_ptr, int); + hd->opt.force_digest = va_arg (arg_ptr, int); else - val = hd->opt.force_digest; + val = hd->opt.force_digest; break; case CDK_CTL_BLOCKMODE_ON: if (set) - hd->opt.blockmode = va_arg (arg_ptr, int); + hd->opt.blockmode = va_arg (arg_ptr, int); else - val = hd->opt.blockmode; + val = hd->opt.blockmode; break; default: @@ -309,8 +309,8 @@ cdk_handle_get_keydb (cdk_ctx_t hd, int type) **/ void cdk_handle_set_passphrase_cb (cdk_ctx_t hd, - char *(*cb) (void *opa, const char *prompt), - void *cb_value) + char *(*cb) (void *opa, const char *prompt), + void *cb_value) { if (!hd) return; @@ -351,9 +351,9 @@ cdk_handle_free (cdk_ctx_t hd) if (hd->db.close_db) { if (hd->db.pub) - cdk_keydb_free (hd->db.pub); + cdk_keydb_free (hd->db.pub); if (hd->db.sec) - cdk_keydb_free (hd->db.sec); + cdk_keydb_free (hd->db.sec); hd->db.pub = hd->db.sec = NULL; } cdk_free (hd); diff --git a/lib/opencdk/main.h b/lib/opencdk/main.h index fe324fedc8..bc7d5230fe 100644 --- a/lib/opencdk/main.h +++ b/lib/opencdk/main.h @@ -47,7 +47,7 @@ cdk_error_t map_gnutls_error (int err); /* This is the default block size for the partial length packet mode. */ #define DEF_BLOCKSIZE 8192 -#define DEF_BLOCKBITS 13 /* 2^13 = 8192 */ +#define DEF_BLOCKBITS 13 /* 2^13 = 8192 */ /* For now SHA-1 is used to create fingerprint for keys. But if this will ever change, it is a good idea to @@ -107,9 +107,9 @@ FILE *_cdk_tmpfile (void); /*-- proc-packet.c --*/ cdk_error_t _cdk_proc_packets (cdk_ctx_t hd, cdk_stream_t inp, - cdk_stream_t data, - const char *output, cdk_stream_t outstream, - digest_hd_st * md); + cdk_stream_t data, + const char *output, cdk_stream_t outstream, + digest_hd_st * md); cdk_error_t _cdk_pkt_write2 (cdk_stream_t out, int pkttype, void *pktctx); /*-- pubkey.c --*/ @@ -126,15 +126,15 @@ void _cdk_pkt_detach_free (cdk_packet_t pkt, int *r_pkttype, void **ctx); /*-- sig-check.c --*/ cdk_error_t _cdk_sig_check (cdk_pkt_pubkey_t pk, cdk_pkt_signature_t sig, - digest_hd_st * digest, int *r_expired); + digest_hd_st * digest, int *r_expired); cdk_error_t _cdk_hash_sig_data (cdk_pkt_signature_t sig, digest_hd_st * hd); cdk_error_t _cdk_hash_userid (cdk_pkt_userid_t uid, int sig_version, - digest_hd_st * md); + digest_hd_st * md); cdk_error_t _cdk_hash_pubkey (cdk_pkt_pubkey_t pk, digest_hd_st * md, - int use_fpr); + int use_fpr); cdk_error_t _cdk_pk_check_sig (cdk_keydb_hd_t hd, cdk_kbnode_t knode, - cdk_kbnode_t snode, int *is_selfsig, - char **ret_uid); + cdk_kbnode_t snode, int *is_selfsig, + char **ret_uid); /*-- kbnode.c --*/ void _cdk_kbnode_add (cdk_kbnode_t root, cdk_kbnode_t node); @@ -142,31 +142,31 @@ void _cdk_kbnode_clone (cdk_kbnode_t node); /*-- sesskey.c --*/ cdk_error_t _cdk_digest_encode_pkcs1 (byte ** r_md, size_t * r_mdlen, - int pk_algo, - const byte * md, - int digest_algo, unsigned nbits); + int pk_algo, + const byte * md, + int digest_algo, unsigned nbits); cdk_error_t _cdk_sk_unprotect_auto (cdk_ctx_t hd, cdk_pkt_seckey_t sk); /*-- keydb.c --*/ int _cdk_keydb_is_secret (cdk_keydb_hd_t db); cdk_error_t _cdk_keydb_get_pk_byusage (cdk_keydb_hd_t hd, const char *name, - cdk_pkt_pubkey_t * ret_pk, int usage); + cdk_pkt_pubkey_t * ret_pk, int usage); cdk_error_t _cdk_keydb_get_sk_byusage (cdk_keydb_hd_t hd, const char *name, - cdk_pkt_seckey_t * ret_sk, int usage); + cdk_pkt_seckey_t * ret_sk, int usage); cdk_error_t _cdk_keydb_check_userid (cdk_keydb_hd_t hd, u32 * keyid, - const char *id); + const char *id); /*-- sign.c --*/ int _cdk_sig_hash_for (cdk_pkt_pubkey_t pk); void _cdk_trim_string (char *s, int canon); cdk_error_t _cdk_sig_create (cdk_pkt_pubkey_t pk, cdk_pkt_signature_t sig); cdk_error_t _cdk_sig_complete (cdk_pkt_signature_t sig, cdk_pkt_seckey_t sk, - digest_hd_st * hd); + digest_hd_st * hd); /*-- stream.c --*/ void _cdk_stream_set_compress_algo (cdk_stream_t s, int algo); cdk_error_t _cdk_stream_open_mode (const char *file, const char *mode, - cdk_stream_t * ret_s); + cdk_stream_t * ret_s); void *_cdk_stream_get_opaque (cdk_stream_t s, int fid); const char *_cdk_stream_get_fname (cdk_stream_t s); FILE *_cdk_stream_get_fp (cdk_stream_t s); @@ -177,7 +177,7 @@ cdk_error_t _cdk_stream_set_blockmode (cdk_stream_t s, size_t nbytes); int _cdk_stream_get_blockmode (cdk_stream_t s); int _cdk_stream_puts (cdk_stream_t s, const char *buf); cdk_error_t _cdk_stream_fpopen (FILE * fp, unsigned write_mode, - cdk_stream_t * ret_out); + cdk_stream_t * ret_out); /*-- verify.c --*/ void _cdk_result_verify_free (cdk_verify_result_t res); diff --git a/lib/opencdk/misc.c b/lib/opencdk/misc.c index a6f69187b3..a2608addea 100644 --- a/lib/opencdk/misc.c +++ b/lib/opencdk/misc.c @@ -140,16 +140,16 @@ _cdk_memistr (const char *buf, size_t buflen, const char *sub) for (t = (byte *) buf, n = buflen, s = (byte *) sub; n; t++, n--) { if (toupper (*t) == toupper (*s)) - { - for (buf = t++, buflen = n--, s++; - n && toupper (*t) == toupper ((byte) * s); t++, s++, n--) - ; - if (!*s) - return buf; - t = (byte *) buf; - n = buflen; - s = (byte *) sub; - } + { + for (buf = t++, buflen = n--, s++; + n && toupper (*t) == toupper ((byte) * s); t++, s++, n--) + ; + if (!*s) + return buf; + t = (byte *) buf; + n = buflen; + s = (byte *) sub; + } } return NULL; @@ -175,9 +175,9 @@ void _cdk_trim_string (char *s, int canon) { while (s && *s && - (s[strlen (s) - 1] == '\t' || - s[strlen (s) - 1] == '\r' || - s[strlen (s) - 1] == '\n' || s[strlen (s) - 1] == ' ')) + (s[strlen (s) - 1] == '\t' || + s[strlen (s) - 1] == '\r' || + s[strlen (s) - 1] == '\n' || s[strlen (s) - 1] == ' ')) s[strlen (s) - 1] = '\0'; if (canon) strcat (s, "\r\n"); @@ -226,7 +226,7 @@ _cdk_tmpfile (void) /* We need to make sure the file will be deleted when it is closed. */ fd = _open (buf, _O_CREAT | _O_EXCL | _O_TEMPORARY | - _O_RDWR | _O_BINARY, _S_IREAD | _S_IWRITE); + _O_RDWR | _O_BINARY, _S_IREAD | _S_IWRITE); if (fd == -1) return NULL; fp = fdopen (fd, "w+b"); diff --git a/lib/opencdk/new-packet.c b/lib/opencdk/new-packet.c index 55b0cfd1a3..b4e09331d0 100644 --- a/lib/opencdk/new-packet.c +++ b/lib/opencdk/new-packet.c @@ -290,7 +290,7 @@ cdk_pkt_alloc (cdk_packet_t * r_pkt, cdk_packet_type_t pkttype) case CDK_PKT_USER_ID: pkt->pkt.user_id = cdk_calloc (1, sizeof pkt->pkt.user_id); if (!pkt->pkt.user_id) - return CDK_Out_Of_Core; + return CDK_Out_Of_Core; pkt->pkt.user_id->name = NULL; break; @@ -298,40 +298,40 @@ cdk_pkt_alloc (cdk_packet_t * r_pkt, cdk_packet_type_t pkttype) case CDK_PKT_PUBLIC_SUBKEY: pkt->pkt.public_key = cdk_calloc (1, sizeof *pkt->pkt.public_key); if (!pkt->pkt.public_key) - return CDK_Out_Of_Core; + return CDK_Out_Of_Core; break; case CDK_PKT_SECRET_KEY: case CDK_PKT_SECRET_SUBKEY: pkt->pkt.secret_key = cdk_calloc (1, sizeof *pkt->pkt.secret_key); pkt->pkt.secret_key->pk = - cdk_calloc (1, sizeof *pkt->pkt.secret_key->pk); + cdk_calloc (1, sizeof *pkt->pkt.secret_key->pk); if (!pkt->pkt.secret_key || !pkt->pkt.secret_key->pk) - return CDK_Out_Of_Core; + return CDK_Out_Of_Core; break; case CDK_PKT_SIGNATURE: pkt->pkt.signature = cdk_calloc (1, sizeof *pkt->pkt.signature); if (!pkt->pkt.signature) - return CDK_Out_Of_Core; + return CDK_Out_Of_Core; break; case CDK_PKT_PUBKEY_ENC: pkt->pkt.pubkey_enc = cdk_calloc (1, sizeof *pkt->pkt.pubkey_enc); if (!pkt->pkt.pubkey_enc) - return CDK_Out_Of_Core; + return CDK_Out_Of_Core; break; case CDK_PKT_MDC: pkt->pkt.mdc = cdk_calloc (1, sizeof *pkt->pkt.mdc); if (!pkt->pkt.mdc) - return CDK_Out_Of_Core; + return CDK_Out_Of_Core; break; case CDK_PKT_ONEPASS_SIG: pkt->pkt.onepass_sig = cdk_calloc (1, sizeof *pkt->pkt.onepass_sig); if (!pkt->pkt.onepass_sig) - return CDK_Out_Of_Core; + return CDK_Out_Of_Core; break; case CDK_PKT_LITERAL: @@ -339,7 +339,7 @@ cdk_pkt_alloc (cdk_packet_t * r_pkt, cdk_packet_type_t pkttype) bytes, otherwise the result would be useless. */ pkt->pkt.literal = cdk_calloc (1, sizeof *pkt->pkt.literal); if (!pkt->pkt.literal) - return CDK_Out_Of_Core; + return CDK_Out_Of_Core; pkt->pkt.literal->name = NULL; break; @@ -448,7 +448,7 @@ _cdk_copy_seckey (cdk_pkt_seckey_t * dst, cdk_pkt_seckey_t src) { k->encdata = cdk_calloc (1, src->enclen + 1); if (!k->encdata) - return CDK_Out_Of_Core; + return CDK_Out_Of_Core; memcpy (k->encdata, src->encdata, src->enclen); } @@ -522,7 +522,7 @@ _cdk_pubkey_compare (cdk_pkt_pubkey_t a, cdk_pkt_pubkey_t b) for (i = 0; i < na; i++) { if (_gnutls_mpi_cmp (a->mpi[i], b->mpi[i])) - return -1; + return -1; } return 0; @@ -580,7 +580,7 @@ cdk_subpkt_type_count (cdk_subpkt_t ctx, size_t type) for (s = ctx; s; s = s->next) { if (s->type == type) - count++; + count++; } return count; @@ -605,7 +605,7 @@ cdk_subpkt_find_nth (cdk_subpkt_t ctx, size_t type, size_t idx) for (s = ctx; s; s = s->next) { if (s->type == type && pos++ == idx) - return s; + return s; } return NULL; @@ -686,20 +686,20 @@ _cdk_subpkt_get_array (cdk_subpkt_t s, int count, size_t * r_nbytes) if (!s) { if (r_nbytes) - *r_nbytes = 0; + *r_nbytes = 0; return NULL; } for (n = 0, list = s; list; list = list->next) { - n++; /* type */ + n++; /* type */ n += list->size; if (list->size < 192) - n++; + n++; else if (list->size < 8384) - n += 2; + n += 2; else - n += 5; + n += 5; } buf = cdk_calloc (1, n + 1); if (!buf) @@ -708,22 +708,22 @@ _cdk_subpkt_get_array (cdk_subpkt_t s, int count, size_t * r_nbytes) n = 0; for (list = s; list; list = list->next) { - nbytes = 1 + list->size; /* type */ + nbytes = 1 + list->size; /* type */ if (nbytes < 192) - buf[n++] = nbytes; + buf[n++] = nbytes; else if (nbytes < 8384) - { - buf[n++] = nbytes / 256 + 192; - buf[n++] = nbytes % 256; - } + { + buf[n++] = nbytes / 256 + 192; + buf[n++] = nbytes % 256; + } else - { - buf[n++] = 0xFF; - buf[n++] = nbytes >> 24; - buf[n++] = nbytes >> 16; - buf[n++] = nbytes >> 8; - buf[n++] = nbytes; - } + { + buf[n++] = 0xFF; + buf[n++] = nbytes >> 24; + buf[n++] = nbytes >> 16; + buf[n++] = nbytes >> 8; + buf[n++] = nbytes; + } buf[n++] = list->type; memcpy (buf + n, list->d, list->size); n += list->size; @@ -753,15 +753,15 @@ _cdk_subpkt_copy (cdk_subpkt_t * r_dst, cdk_subpkt_t src) { node = cdk_subpkt_new (p->size); if (node) - { - memcpy (node->d, p->d, p->size); - node->type = p->type; - node->size = p->size; - } + { + memcpy (node->d, p->d, p->size); + node->type = p->type; + node->size = p->size; + } if (!root) - root = node; + root = node; else - cdk_subpkt_add (root, node); + cdk_subpkt_add (root, node); } *r_dst = root; return 0; @@ -779,7 +779,7 @@ _cdk_subpkt_copy (cdk_subpkt_t * r_dst, cdk_subpkt_t src) **/ void cdk_subpkt_init (cdk_subpkt_t node, size_t type, - const void *buf, size_t buflen) + const void *buf, size_t buflen) { if (!node) return; @@ -792,8 +792,8 @@ cdk_subpkt_init (cdk_subpkt_t node, size_t type, /* FIXME: We need to think of a public interface for it. */ const byte * cdk_key_desig_revoker_walk (cdk_desig_revoker_t root, - cdk_desig_revoker_t * ctx, - int *r_class, int *r_algid) + cdk_desig_revoker_t * ctx, + int *r_class, int *r_algid) { cdk_desig_revoker_t n; @@ -834,9 +834,9 @@ cdk_subpkt_find_next (cdk_subpkt_t root, size_t type) for (node = root->next; node; node = node->next) { if (!type) - return node; + return node; else if (node->type == type) - return node; + return node; } return NULL; diff --git a/lib/opencdk/opencdk.h b/lib/opencdk/opencdk.h index d7bd415b60..6516824a1e 100644 --- a/lib/opencdk/opencdk.h +++ b/lib/opencdk/opencdk.h @@ -26,7 +26,7 @@ #ifndef OPENCDK_H #define OPENCDK_H -#include <stddef.h> /* for size_t */ +#include <stddef.h> /* for size_t */ #include <stdarg.h> #include <gnutls_int.h> #include <gnutls_mem.h> @@ -142,23 +142,23 @@ extern "C" enum cdk_control_flags { - CDK_CTLF_SET = 0, /* Value to set an option */ - CDK_CTLF_GET = 1, /* Value to get an option */ - CDK_CTL_DIGEST = 10, /* Option to set the digest algorithm. */ - CDK_CTL_ARMOR = 12, /* Option to enable armor output. */ - CDK_CTL_COMPRESS = 13, /* Option to enable compression. */ - CDK_CTL_COMPAT = 14, /* Option to switch in compat mode. */ - CDK_CTL_OVERWRITE = 15, /* Option to enable file overwritting. */ - CDK_CTL_S2K = 16, /* Option to set S2K values. */ - CDK_CTL_FORCE_DIGEST = 19, /* Force the use of a digest algorithm. */ - CDK_CTL_BLOCKMODE_ON = 20 /* Enable partial body lengths */ + CDK_CTLF_SET = 0, /* Value to set an option */ + CDK_CTLF_GET = 1, /* Value to get an option */ + CDK_CTL_DIGEST = 10, /* Option to set the digest algorithm. */ + CDK_CTL_ARMOR = 12, /* Option to enable armor output. */ + CDK_CTL_COMPRESS = 13, /* Option to enable compression. */ + CDK_CTL_COMPAT = 14, /* Option to switch in compat mode. */ + CDK_CTL_OVERWRITE = 15, /* Option to enable file overwritting. */ + CDK_CTL_S2K = 16, /* Option to set S2K values. */ + CDK_CTL_FORCE_DIGEST = 19, /* Force the use of a digest algorithm. */ + CDK_CTL_BLOCKMODE_ON = 20 /* Enable partial body lengths */ }; /* Specifies all valid log levels. */ enum cdk_log_level_t { - CDK_LOG_NONE = 0, /* No log message will be shown. */ + CDK_LOG_NONE = 0, /* No log message will be shown. */ CDK_LOG_INFO = 1, CDK_LOG_DEBUG = 2, CDK_LOG_DEBUG_PKT = 3 @@ -171,7 +171,7 @@ extern "C" CDK_COMPRESS_NONE = 0, CDK_COMPRESS_ZIP = 1, CDK_COMPRESS_ZLIB = 2, - CDK_COMPRESS_BZIP2 = 3 /* Not supported in this version */ + CDK_COMPRESS_BZIP2 = 3 /* Not supported in this version */ }; /* All valid public key algorithms valid in OpenPGP */ @@ -179,8 +179,8 @@ extern "C" { CDK_PK_UNKNOWN = 0, CDK_PK_RSA = 1, - CDK_PK_RSA_E = 2, /* RSA-E and RSA-S are deprecated use RSA instead */ - CDK_PK_RSA_S = 3, /* and use the key flags in the self signatures. */ + CDK_PK_RSA_E = 2, /* RSA-E and RSA-S are deprecated use RSA instead */ + CDK_PK_RSA_S = 3, /* and use the key flags in the self signatures. */ CDK_PK_ELG_E = 16, CDK_PK_DSA = 17 }; @@ -201,9 +201,9 @@ extern "C" enum cdk_pref_type_t { CDK_PREFTYPE_NONE = 0, - CDK_PREFTYPE_SYM = 1, /* Symmetric ciphers */ - CDK_PREFTYPE_HASH = 2, /* Message digests */ - CDK_PREFTYPE_ZIP = 3 /* Compression algorithms */ + CDK_PREFTYPE_SYM = 1, /* Symmetric ciphers */ + CDK_PREFTYPE_HASH = 2, /* Message digests */ + CDK_PREFTYPE_ZIP = 3 /* Compression algorithms */ }; @@ -248,18 +248,18 @@ extern "C" enum cdk_keydb_flag_t { /* Valid database search modes */ - CDK_DBSEARCH_EXACT = 1, /* Exact string search */ - CDK_DBSEARCH_SUBSTR = 2, /* Sub string search */ - CDK_DBSEARCH_SHORT_KEYID = 3, /* 32-bit keyid search */ - CDK_DBSEARCH_KEYID = 4, /* 64-bit keyid search */ - CDK_DBSEARCH_FPR = 5, /* 160-bit fingerprint search */ - CDK_DBSEARCH_NEXT = 6, /* Enumerate all keys */ - CDK_DBSEARCH_AUTO = 7, /* Try to classify the string */ + CDK_DBSEARCH_EXACT = 1, /* Exact string search */ + CDK_DBSEARCH_SUBSTR = 2, /* Sub string search */ + CDK_DBSEARCH_SHORT_KEYID = 3, /* 32-bit keyid search */ + CDK_DBSEARCH_KEYID = 4, /* 64-bit keyid search */ + CDK_DBSEARCH_FPR = 5, /* 160-bit fingerprint search */ + CDK_DBSEARCH_NEXT = 6, /* Enumerate all keys */ + CDK_DBSEARCH_AUTO = 7, /* Try to classify the string */ /* Valid database types */ - CDK_DBTYPE_PK_KEYRING = 100, /* A file with one or more public keys */ - CDK_DBTYPE_SK_KEYRING = 101, /* A file with one or more secret keys */ - CDK_DBTYPE_DATA = 102, /* A buffer with at least one public key */ - CDK_DBTYPE_STREAM = 103 /* A stream is used to read keys from */ + CDK_DBTYPE_PK_KEYRING = 100, /* A file with one or more public keys */ + CDK_DBTYPE_SK_KEYRING = 101, /* A file with one or more secret keys */ + CDK_DBTYPE_DATA = 102, /* A buffer with at least one public key */ + CDK_DBTYPE_STREAM = 103 /* A stream is used to read keys from */ }; @@ -294,9 +294,9 @@ extern "C" enum cdk_key_flag_t { CDK_KEY_VALID = 0, - CDK_KEY_INVALID = 1, /* Missing or wrong self signature */ - CDK_KEY_EXPIRED = 2, /* Key is expired. */ - CDK_KEY_REVOKED = 4, /* Key has been revoked. */ + CDK_KEY_INVALID = 1, /* Missing or wrong self signature */ + CDK_KEY_EXPIRED = 2, /* Key is expired. */ + CDK_KEY_REVOKED = 4, /* Key has been revoked. */ CDK_KEY_NOSIGNER = 8 }; @@ -326,7 +326,7 @@ extern "C" CDK_SIGSTAT_GOOD = 1, CDK_SIGSTAT_BAD = 2, CDK_SIGSTAT_NOKEY = 3, - CDK_SIGSTAT_VALID = 4, /* True if made with a valid key. */ + CDK_SIGSTAT_VALID = 4, /* True if made with a valid key. */ /* FIXME: We need indicators for revoked/expires signatures. */ /* Signature modes */ @@ -416,7 +416,7 @@ extern "C" unsigned valid:1; unsigned missing_key:1; } flags; - unsigned int key[2]; /* only valid for key signatures */ + unsigned int key[2]; /* only valid for key signatures */ }; typedef struct cdk_pkt_signature_s *cdk_pkt_signature_t; @@ -429,7 +429,7 @@ extern "C" unsigned mdc_feature:1; cdk_prefitem_t prefs; size_t prefs_size; - unsigned char *attrib_img; /* Tag 17 if not null */ + unsigned char *attrib_img; /* Tag 17 if not null */ size_t attrib_len; cdk_pkt_signature_t selfsig; char *name; @@ -474,7 +474,7 @@ extern "C" struct { unsigned char algo; - unsigned char sha1chk; /* SHA1 is used instead of a 16 bit checksum */ + unsigned char sha1chk; /* SHA1 is used instead of a 16 bit checksum */ cdk_s2k_t s2k; unsigned char iv[16]; unsigned char ivlen; @@ -557,9 +557,9 @@ extern "C" /* Structure which represents a single OpenPGP packet. */ struct cdk_packet_s { - size_t pktlen; /* real packet length */ - size_t pktsize; /* length with all headers */ - int old_ctb; /* 1 if RFC1991 mode is used */ + size_t pktlen; /* real packet length */ + size_t pktsize; /* length with all headers */ + int old_ctb; /* 1 if RFC1991 mode is used */ cdk_packet_type_t pkttype; union { @@ -590,7 +590,7 @@ extern "C" The user can directly use the file name, the rest is done internally. */ cdk_error_t cdk_handle_set_keyring (cdk_ctx_t hd, int type, - const char *kringname); + const char *kringname); /* Return keydb handle stored in the session handle. */ cdk_keydb_hd_t cdk_handle_get_keydb (cdk_ctx_t hd, int type); @@ -598,9 +598,9 @@ extern "C" /* Set a passphrase callback for the given session handle. */ void cdk_handle_set_passphrase_cb (cdk_ctx_t hd, - char *(*cb) (void *opa, - const char *prompt), - void *cb_value); + char *(*cb) (void *opa, + const char *prompt), + void *cb_value); /* shortcuts for some controls */ @@ -630,18 +630,18 @@ extern "C" /* This context holds all information of the verification process. */ struct cdk_verify_result_s { - int sig_ver; /* Version of the signature. */ - int sig_status; /* The status (GOOD, BAD) of the signature */ - int sig_flags; /* May contain expired or revoked flags */ - unsigned int keyid[2]; /* The issuer key ID */ - unsigned int created; /* Timestamp when the sig was created. */ + int sig_ver; /* Version of the signature. */ + int sig_status; /* The status (GOOD, BAD) of the signature */ + int sig_flags; /* May contain expired or revoked flags */ + unsigned int keyid[2]; /* The issuer key ID */ + unsigned int created; /* Timestamp when the sig was created. */ unsigned int expires; int pubkey_algo; int digest_algo; - char *user_id; /* NULL or user ID which issued the signature. */ - char *policy_url; /* If set, the policy the sig was created under. */ - size_t sig_len; /* Size of the signature data inbits. */ - unsigned char *sig_data; /* Raw signature data. */ + char *user_id; /* NULL or user ID which issued the signature. */ + char *policy_url; /* If set, the policy the sig was created under. */ + size_t sig_len; /* Size of the signature data inbits. */ + unsigned char *sig_data; /* Raw signature data. */ }; typedef struct cdk_verify_result_s *cdk_verify_result_t; @@ -671,19 +671,19 @@ extern "C" cdk_subpkt_t cdk_subpkt_find_next (cdk_subpkt_t root, size_t type); size_t cdk_subpkt_type_count (cdk_subpkt_t ctx, size_t type); cdk_subpkt_t cdk_subpkt_find_nth (cdk_subpkt_t ctx, size_t type, - size_t index); + size_t index); cdk_error_t cdk_subpkt_add (cdk_subpkt_t root, cdk_subpkt_t node); const unsigned char *cdk_subpkt_get_data (cdk_subpkt_t ctx, - size_t * r_type, - size_t * r_nbytes); + size_t * r_type, + size_t * r_nbytes); void cdk_subpkt_init (cdk_subpkt_t node, size_t type, const void *buf, - size_t buflen); + size_t buflen); /* Designated Revoker routines */ const unsigned char *cdk_key_desig_revoker_walk (cdk_desig_revoker_t root, - cdk_desig_revoker_t * ctx, - int *r_class, - int *r_algid); + cdk_desig_revoker_t * ctx, + int *r_class, + int *r_algid); #define is_RSA(a) ((a) == CDK_PK_RSA \ || (a) == CDK_PK_RSA_E \ @@ -694,22 +694,22 @@ extern "C" /* Encrypt the given session key @SK with the public key @PK and write the contents into the packet @PKE. */ cdk_error_t cdk_pk_encrypt (cdk_pubkey_t pk, cdk_pkt_pubkey_enc_t pke, - bigint_t sk); + bigint_t sk); /* Decrypt the given encrypted session key in @PKE with the secret key @SK and store it in @R_SK. */ cdk_error_t cdk_pk_decrypt (cdk_seckey_t sk, cdk_pkt_pubkey_enc_t pke, - bigint_t * r_sk); + bigint_t * r_sk); /* Sign the given message digest @MD with the secret key @SK and store the signature in the packet @SIG. */ cdk_error_t cdk_pk_sign (cdk_seckey_t sk, cdk_pkt_signature_t sig, - const unsigned char *md); + const unsigned char *md); /* Verify the given signature in @SIG with the public key @PK and compare it against the message digest @MD. */ cdk_error_t cdk_pk_verify (cdk_pubkey_t pk, cdk_pkt_signature_t sig, - const unsigned char *md); + const unsigned char *md); /* Use cdk_pk_get_npkey() and cdk_pk_get_nskey to find out how much multiprecision integers a key consists of. */ @@ -718,13 +718,13 @@ extern "C" in the buffer @BUF. @R_NWRITTEN will contain the length in octets. Optional @R_NBITS may contain the size in bits. */ cdk_error_t cdk_pk_get_mpi (cdk_pubkey_t pk, size_t idx, - unsigned char *buf, size_t buflen, - size_t * r_nwritten, size_t * r_nbits); + unsigned char *buf, size_t buflen, + size_t * r_nwritten, size_t * r_nbits); /* Same as the function above but of the secret key. */ cdk_error_t cdk_sk_get_mpi (cdk_seckey_t sk, size_t idx, - unsigned char *buf, size_t buflen, - size_t * r_nwritten, size_t * r_nbits); + unsigned char *buf, size_t buflen, + size_t * r_nwritten, size_t * r_nbits); /* Helper to get the exact number of multi precision integers for the given object. */ @@ -742,20 +742,20 @@ extern "C" /* Same as above, but with additional sanity checks of the buffer size. */ cdk_error_t cdk_pk_to_fingerprint (cdk_pubkey_t pk, - unsigned char *fpr, size_t fprlen, - size_t * r_nout); + unsigned char *fpr, size_t fprlen, + size_t * r_nout); /* Derive the keyid from the fingerprint. This is only possible for modern, version 4 keys. */ unsigned int cdk_pk_fingerprint_get_keyid (const unsigned char *fpr, - size_t fprlen, - unsigned int *keyid); + size_t fprlen, + unsigned int *keyid); /* Various functions to get the keyid from the specific packet type. */ unsigned int cdk_pk_get_keyid (cdk_pubkey_t pk, unsigned int *keyid); unsigned int cdk_sk_get_keyid (cdk_seckey_t sk, unsigned int *keyid); unsigned int cdk_sig_get_keyid (cdk_pkt_signature_t sig, - unsigned int *keyid); + unsigned int *keyid); /* Key release functions. */ void cdk_pk_release (cdk_pubkey_t pk); @@ -771,11 +771,11 @@ extern "C" /* String to Key routines. */ cdk_error_t cdk_s2k_new (cdk_s2k_t * ret_s2k, int mode, int digest_algo, - const unsigned char *salt); + const unsigned char *salt); void cdk_s2k_free (cdk_s2k_t s2k); cdk_error_t cdk_file_armor (cdk_ctx_t hd, const char *file, - const char *output); + const char *output); cdk_error_t cdk_file_dearmor (const char *file, const char *output); int cdk_armor_filter_use (cdk_stream_t inp); @@ -783,9 +783,9 @@ extern "C" If @outbuf and @outlen are NULL, the function returns the calculated size of the base64 encoded data in @nwritten. */ cdk_error_t cdk_armor_encode_buffer (const unsigned char *inbuf, - size_t inlen, char *outbuf, - size_t outlen, size_t * nwritten, - int type); + size_t inlen, char *outbuf, + size_t outlen, size_t * nwritten, + int type); /* This context contain user callbacks for different stream operations. @@ -805,7 +805,7 @@ extern "C" /* Return a stream object which is associated to a socket. */ cdk_error_t cdk_stream_sockopen (const char *host, unsigned short port, - cdk_stream_t * ret_out); + cdk_stream_t * ret_out); /* Return a stream object which is associated to an existing file. */ cdk_error_t cdk_stream_open (const char *file, cdk_stream_t * ret_s); @@ -817,11 +817,11 @@ extern "C" /* Return a stream object with custom callback functions for the various core operations. */ cdk_error_t cdk_stream_new_from_cbs (cdk_stream_cbs_t cbs, void *opa, - cdk_stream_t * ret_s); + cdk_stream_t * ret_s); cdk_error_t cdk_stream_create (const char *file, cdk_stream_t * ret_s); cdk_error_t cdk_stream_tmp_new (cdk_stream_t * r_out); cdk_error_t cdk_stream_tmp_from_mem (const void *buf, size_t buflen, - cdk_stream_t * r_out); + cdk_stream_t * r_out); void cdk_stream_tmp_set_mode (cdk_stream_t s, int val); cdk_error_t cdk_stream_flush (cdk_stream_t s); cdk_error_t cdk_stream_enable_cache (cdk_stream_t s, int val); @@ -839,19 +839,19 @@ extern "C" /* Push the literal filter for the given stream. */ cdk_error_t cdk_stream_set_literal_flag (cdk_stream_t s, - cdk_lit_format_t mode, - const char *fname); + cdk_lit_format_t mode, + const char *fname); cdk_error_t cdk_stream_set_compress_flag (cdk_stream_t s, int algo, - int level); + int level); cdk_error_t cdk_stream_set_hash_flag (cdk_stream_t s, int algo); cdk_error_t cdk_stream_set_text_flag (cdk_stream_t s, const char *lf); cdk_error_t cdk_stream_kick_off (cdk_stream_t inp, cdk_stream_t out); cdk_error_t cdk_stream_mmap (cdk_stream_t s, unsigned char **ret_buf, - size_t * ret_buflen); + size_t * ret_buflen); cdk_error_t cdk_stream_mmap_part (cdk_stream_t s, off_t off, size_t len, - unsigned char **ret_buf, - size_t * ret_buflen); + unsigned char **ret_buf, + size_t * ret_buflen); /* Read from the stream but restore the file pointer after reading the requested amount of bytes. */ @@ -861,36 +861,36 @@ extern "C" the function does not support all combinations, the dedicated functions should be preferred. */ cdk_error_t cdk_keydb_new (cdk_keydb_hd_t * r_hd, int type, void *data, - size_t count); + size_t count); /* Create a new key db handle from a memory buffer. */ cdk_error_t cdk_keydb_new_from_mem (cdk_keydb_hd_t * r_hd, int secret, - const void *data, size_t datlen); + const void *data, size_t datlen); /* Create a new key db which uses an existing file. */ cdk_error_t cdk_keydb_new_from_file (cdk_keydb_hd_t * r_hd, int secret, - const char *fname); + const char *fname); /* Uses a stream as the key db input. For searching it is important that the seek function is supported on the stream. Furthermore, the stream is not closed in cdk_keydb_free(). The caller must do it. */ cdk_error_t cdk_keydb_new_from_stream (cdk_keydb_hd_t * r_hd, int secret, - cdk_stream_t in); + cdk_stream_t in); /* Check that a secret key with the given key ID is available. */ cdk_error_t cdk_keydb_check_sk (cdk_keydb_hd_t hd, unsigned int *keyid); /* Prepare the key db search. */ cdk_error_t cdk_keydb_search_start (cdk_keydb_search_t * st, - cdk_keydb_hd_t db, int type, - void *desc); + cdk_keydb_hd_t db, int type, + void *desc); void cdk_keydb_search_release (cdk_keydb_search_t st); /* Return a key which matches a valid description given in cdk_keydb_search_start(). */ cdk_error_t cdk_keydb_search (cdk_keydb_search_t st, cdk_keydb_hd_t hd, - cdk_kbnode_t * ret_key); + cdk_kbnode_t * ret_key); /* Release the key db handle and all its resources. */ void cdk_keydb_free (cdk_keydb_hd_t hd); @@ -898,35 +898,35 @@ extern "C" /* The following functions will try to find a key in the given key db handle either by keyid, by fingerprint or by some pattern. */ cdk_error_t cdk_keydb_get_bykeyid (cdk_keydb_hd_t hd, unsigned int *keyid, - cdk_kbnode_t * ret_pk); + cdk_kbnode_t * ret_pk); cdk_error_t cdk_keydb_get_byfpr (cdk_keydb_hd_t hd, - const unsigned char *fpr, - cdk_kbnode_t * ret_pk); + const unsigned char *fpr, + cdk_kbnode_t * ret_pk); cdk_error_t cdk_keydb_get_bypattern (cdk_keydb_hd_t hd, const char *patt, - cdk_kbnode_t * ret_pk); + cdk_kbnode_t * ret_pk); /* These function, in contrast to most other key db functions, only return the public or secret key packet without the additional signatures and user IDs. */ cdk_error_t cdk_keydb_get_pk (cdk_keydb_hd_t khd, unsigned int *keyid, - cdk_pubkey_t * ret_pk); + cdk_pubkey_t * ret_pk); cdk_error_t cdk_keydb_get_sk (cdk_keydb_hd_t khd, unsigned int *keyid, - cdk_seckey_t * ret_sk); + cdk_seckey_t * ret_sk); /* Try to read the next key block from the given input stream. The key will be returned in @RET_KEY on success. */ cdk_error_t cdk_keydb_get_keyblock (cdk_stream_t inp, - cdk_kbnode_t * ret_key); + cdk_kbnode_t * ret_key); /* Rebuild the key db index if possible. */ cdk_error_t cdk_keydb_idx_rebuild (cdk_keydb_hd_t db, - cdk_keydb_search_t dbs); + cdk_keydb_search_t dbs); /* Export one or more keys from the given key db handle into the stream @OUT. The export is done by substring search and uses the string list @REMUSR for the pattern. */ cdk_error_t cdk_keydb_export (cdk_keydb_hd_t hd, cdk_stream_t out, - cdk_strlist_t remusr); + cdk_strlist_t remusr); /* Import the given key node @knode into the key db. */ cdk_error_t cdk_keydb_import (cdk_keydb_hd_t hd, cdk_kbnode_t knode); @@ -937,7 +937,7 @@ extern "C" /* Start the key list process. Either use @PATT for a pattern search or @FPATT for a list of pattern. */ cdk_error_t cdk_listkey_start (cdk_listkey_t * r_ctx, cdk_keydb_hd_t db, - const char *patt, cdk_strlist_t fpatt); + const char *patt, cdk_strlist_t fpatt); void cdk_listkey_close (cdk_listkey_t ctx); /* Return the next key which matches the pattern. */ @@ -945,40 +945,40 @@ extern "C" cdk_kbnode_t cdk_kbnode_new (cdk_packet_t pkt); cdk_error_t cdk_kbnode_read_from_mem (cdk_kbnode_t * ret_node, - const unsigned char *buf, - size_t buflen); + const unsigned char *buf, + size_t buflen); cdk_error_t cdk_kbnode_write_to_mem (cdk_kbnode_t node, - unsigned char *buf, size_t * r_nbytes); + unsigned char *buf, size_t * r_nbytes); cdk_error_t cdk_kbnode_write_to_mem_alloc (cdk_kbnode_t node, - unsigned char **r_buf, - size_t * r_buflen); + unsigned char **r_buf, + size_t * r_buflen); void cdk_kbnode_release (cdk_kbnode_t node); void cdk_kbnode_delete (cdk_kbnode_t node); void cdk_kbnode_insert (cdk_kbnode_t root, cdk_kbnode_t node, - cdk_packet_type_t pkttype); + cdk_packet_type_t pkttype); int cdk_kbnode_commit (cdk_kbnode_t * root); void cdk_kbnode_remove (cdk_kbnode_t * root, cdk_kbnode_t node); void cdk_kbnode_move (cdk_kbnode_t * root, cdk_kbnode_t node, - cdk_kbnode_t where); + cdk_kbnode_t where); cdk_kbnode_t cdk_kbnode_walk (cdk_kbnode_t root, cdk_kbnode_t * ctx, - int all); + int all); cdk_packet_t cdk_kbnode_find_packet (cdk_kbnode_t node, - cdk_packet_type_t pkttype); + cdk_packet_type_t pkttype); cdk_packet_t cdk_kbnode_get_packet (cdk_kbnode_t node); cdk_kbnode_t cdk_kbnode_find (cdk_kbnode_t node, cdk_packet_type_t pkttype); cdk_kbnode_t cdk_kbnode_find_prev (cdk_kbnode_t root, cdk_kbnode_t node, - cdk_packet_type_t pkttype); + cdk_packet_type_t pkttype); cdk_kbnode_t cdk_kbnode_find_next (cdk_kbnode_t node, - cdk_packet_type_t pkttype); + cdk_packet_type_t pkttype); cdk_error_t cdk_kbnode_hash (cdk_kbnode_t node, digest_hd_st * md, - int is_v4, cdk_packet_type_t pkttype, - int flags); + int is_v4, cdk_packet_type_t pkttype, + int flags); /* Check each signature in the key node and return a summary of the key status in @r_status. Values of cdk_key_flag_t are used. */ cdk_error_t cdk_pk_check_sigs (cdk_kbnode_t knode, cdk_keydb_hd_t hd, - int *r_status); + int *r_status); /* Check the self signature of the key to make sure it is valid. */ cdk_error_t cdk_pk_check_self_sig (cdk_kbnode_t knode, int *r_status); @@ -991,75 +991,75 @@ extern "C" MDC feature. */ int cdk_pklist_use_mdc (cdk_keylist_t pkl); cdk_error_t cdk_pklist_build (cdk_keylist_t * ret_pkl, cdk_keydb_hd_t hd, - cdk_strlist_t remusr, int use); + cdk_strlist_t remusr, int use); void cdk_pklist_release (cdk_keylist_t pkl); /* Secret key lists */ cdk_error_t cdk_sklist_build (cdk_keylist_t * ret_skl, - cdk_keydb_hd_t db, cdk_ctx_t hd, - cdk_strlist_t locusr, - int unlock, unsigned int use); + cdk_keydb_hd_t db, cdk_ctx_t hd, + cdk_strlist_t locusr, + int unlock, unsigned int use); void cdk_sklist_release (cdk_keylist_t skl); cdk_error_t cdk_sklist_write (cdk_keylist_t skl, cdk_stream_t outp, - digest_hd_st * mdctx, int sigclass, - int sigver); + digest_hd_st * mdctx, int sigclass, + int sigver); cdk_error_t cdk_sklist_write_onepass (cdk_keylist_t skl, cdk_stream_t outp, - int sigclass, int mdalgo); + int sigclass, int mdalgo); /* Encrypt the given stream @INP with the recipients given in @REMUSR. If @REMUSR is NULL, symmetric encryption will be used. The output will be written to @OUT. */ cdk_error_t cdk_stream_encrypt (cdk_ctx_t hd, cdk_strlist_t remusr, - cdk_stream_t inp, cdk_stream_t out); + cdk_stream_t inp, cdk_stream_t out); /* Decrypt the @INP stream into @OUT. */ cdk_error_t cdk_stream_decrypt (cdk_ctx_t hd, cdk_stream_t inp, - cdk_stream_t out); + cdk_stream_t out); /* Same as the function above but it works on files. */ cdk_error_t cdk_file_encrypt (cdk_ctx_t hd, cdk_strlist_t remusr, - const char *file, const char *output); + const char *file, const char *output); cdk_error_t cdk_file_decrypt (cdk_ctx_t hd, const char *file, - const char *output); + const char *output); /* Generic function to transform data. The mode can be either sign, verify, encrypt, decrypt, import or export. The meanings of the parameters are similar to the functions above. @OUTBUF will contain the output and @OUTSIZE the length of it. */ cdk_error_t cdk_data_transform (cdk_ctx_t hd, enum cdk_crypto_mode_t mode, - cdk_strlist_t locusr, cdk_strlist_t remusr, - const void *inbuf, size_t insize, - unsigned char **outbuf, size_t * outsize, - int modval); + cdk_strlist_t locusr, cdk_strlist_t remusr, + const void *inbuf, size_t insize, + unsigned char **outbuf, size_t * outsize, + int modval); /* Sign the stream @INP. Optionally, the output will be encrypted if @REMUSR is not NULL and the @ENCRYPTFLAG is set. The output will be written to @OUT. @LOCUSR contains one ore more pattern for the secret key(s) to use. */ cdk_error_t cdk_stream_sign (cdk_ctx_t hd, cdk_stream_t inp, - cdk_stream_t out, cdk_strlist_t locusr, - cdk_strlist_t remusr, int encryptflag, - int sigmode); + cdk_stream_t out, cdk_strlist_t locusr, + cdk_strlist_t remusr, int encryptflag, + int sigmode); /* Same as the function above but it works on files. */ cdk_error_t cdk_file_sign (cdk_ctx_t hd, cdk_strlist_t locusr, - cdk_strlist_t remusr, - const char *file, const char *output, - int sigmode, int encryptflag); + cdk_strlist_t remusr, + const char *file, const char *output, + int sigmode, int encryptflag); cdk_error_t cdk_stream_verify (cdk_ctx_t hd, cdk_stream_t inp, - cdk_stream_t data, cdk_stream_t out); + cdk_stream_t data, cdk_stream_t out); /* Verify the given file @FILE. For a detached signature, @DATA_FILE contains the actual file data and @FILE is only the signature. If the @OUTPUT is not NULL, the plaintext will be written to this file. */ cdk_error_t cdk_file_verify (cdk_ctx_t hd, const char *file, - const char *data_file, const char *output); + const char *data_file, const char *output); int cdk_trustdb_get_validity (cdk_stream_t inp, cdk_pkt_userid_t id, - int *r_val); + int *r_val); int cdk_trustdb_get_ownertrust (cdk_stream_t inp, cdk_pubkey_t pk, - int *r_val, int *r_flags); + int *r_val, int *r_flags); void cdk_strlist_free (cdk_strlist_t sl); cdk_strlist_t cdk_strlist_add (cdk_strlist_t * list, const char *string); @@ -1073,4 +1073,4 @@ extern "C" } #endif -#endif /* OPENCDK_H */ +#endif /* OPENCDK_H */ diff --git a/lib/opencdk/packet.h b/lib/opencdk/packet.h index aca38e06cb..eda8735d0f 100644 --- a/lib/opencdk/packet.h +++ b/lib/opencdk/packet.h @@ -43,7 +43,7 @@ cdk_error_t _cdk_copy_pubkey (cdk_pkt_pubkey_t * dst, cdk_pkt_pubkey_t src); cdk_error_t _cdk_copy_seckey (cdk_pkt_seckey_t * dst, cdk_pkt_seckey_t src); cdk_error_t _cdk_copy_pk_to_sk (cdk_pkt_pubkey_t pk, cdk_pkt_seckey_t sk); cdk_error_t _cdk_copy_signature (cdk_pkt_signature_t * dst, - cdk_pkt_signature_t src); + cdk_pkt_signature_t src); cdk_error_t _cdk_pubkey_compare (cdk_pkt_pubkey_t a, cdk_pkt_pubkey_t b); #endif /* CDK_PACKET_H */ diff --git a/lib/opencdk/pubkey.c b/lib/opencdk/pubkey.c index dc2e2ea788..835e6b531b 100644 --- a/lib/opencdk/pubkey.c +++ b/lib/opencdk/pubkey.c @@ -49,13 +49,13 @@ sig_to_datum (gnutls_datum_t * r_sig, cdk_pkt_signature_t sig) { err = _gnutls_mpi_dprint (sig->mpi[0], r_sig); if (err < 0) - rc = map_gnutls_error (err); + rc = map_gnutls_error (err); } else if (is_DSA (sig->pubkey_algo)) { err = _gnutls_encode_ber_rs (r_sig, sig->mpi[0], sig->mpi[1]); if (err < 0) - rc = map_gnutls_error (err); + rc = map_gnutls_error (err); } else rc = CDK_Inv_Algo; @@ -106,7 +106,7 @@ cdk_pk_verify (cdk_pubkey_t pk, cdk_pkt_signature_t sig, const byte * md) } rc = _cdk_digest_encode_pkcs1 (&encmd, &enclen, pk->pubkey_algo, md, - sig->digest_algo, cdk_pk_get_nbits (pk)); + sig->digest_algo, cdk_pk_get_nbits (pk)); if (rc) { gnutls_assert (); @@ -193,7 +193,7 @@ cdk_pk_get_nskey (int algo) int ret; if (is_RSA (algo)) - ret = RSA_PRIVATE_PARAMS - 2; /* we don't have exp1 and exp2 */ + ret = RSA_PRIVATE_PARAMS - 2; /* we don't have exp1 and exp2 */ else if (is_DSA (algo)) ret = DSA_PRIVATE_PARAMS; else if (is_ELG (algo)) @@ -278,7 +278,7 @@ _cdk_pk_algo_usage (int algo) */ static cdk_error_t mpi_to_buffer (bigint_t a, byte * buf, size_t buflen, - size_t * r_nwritten, size_t * r_nbits) + size_t * r_nwritten, size_t * r_nbits) { size_t nbits; int err; @@ -323,8 +323,8 @@ mpi_to_buffer (bigint_t a, byte * buf, size_t buflen, **/ cdk_error_t cdk_pk_get_mpi (cdk_pubkey_t pk, size_t idx, - byte * buf, size_t buflen, size_t * r_nwritten, - size_t * r_nbits) + byte * buf, size_t buflen, size_t * r_nwritten, + size_t * r_nbits) { if (!pk || !r_nwritten) return CDK_Inv_Value; @@ -349,8 +349,8 @@ cdk_pk_get_mpi (cdk_pubkey_t pk, size_t idx, **/ cdk_error_t cdk_sk_get_mpi (cdk_pkt_seckey_t sk, size_t idx, - byte * buf, size_t buflen, size_t * r_nwritten, - size_t * r_nbits) + byte * buf, size_t buflen, size_t * r_nwritten, + size_t * r_nbits) { if (!sk || !r_nwritten) return CDK_Inv_Value; @@ -431,7 +431,7 @@ cdk_pk_get_fingerprint (cdk_pubkey_t pk, byte * fpr) return CDK_Inv_Value; if (pk->version < 4 && is_RSA (pk->pubkey_algo)) - md_algo = GNUTLS_DIG_MD5; /* special */ + md_algo = GNUTLS_DIG_MD5; /* special */ else md_algo = GNUTLS_DIG_SHA1; dlen = _gnutls_hash_get_algo_len (md_algo); @@ -461,7 +461,7 @@ cdk_pk_get_fingerprint (cdk_pubkey_t pk, byte * fpr) **/ cdk_error_t cdk_pk_to_fingerprint (cdk_pubkey_t pk, - byte * fprbuf, size_t fprbuflen, size_t * r_nout) + byte * fprbuf, size_t fprbuflen, size_t * r_nout) { size_t key_fprlen; cdk_error_t err; @@ -541,23 +541,23 @@ cdk_pk_get_keyid (cdk_pubkey_t pk, u32 * keyid) if (pk && (!pk->keyid[0] || !pk->keyid[1])) { if (pk->version < 4 && is_RSA (pk->pubkey_algo)) - { - byte p[MAX_MPI_BYTES]; - size_t n; - - n = MAX_MPI_BYTES; - _gnutls_mpi_print (pk->mpi[0], p, &n); - pk->keyid[0] = - p[n - 8] << 24 | p[n - 7] << 16 | p[n - 6] << 8 | p[n - 5]; - pk->keyid[1] = - p[n - 4] << 24 | p[n - 3] << 16 | p[n - 2] << 8 | p[n - 1]; - } + { + byte p[MAX_MPI_BYTES]; + size_t n; + + n = MAX_MPI_BYTES; + _gnutls_mpi_print (pk->mpi[0], p, &n); + pk->keyid[0] = + p[n - 8] << 24 | p[n - 7] << 16 | p[n - 6] << 8 | p[n - 5]; + pk->keyid[1] = + p[n - 4] << 24 | p[n - 3] << 16 | p[n - 2] << 8 | p[n - 1]; + } else if (pk->version == 4) - { - cdk_pk_get_fingerprint (pk, buf); - pk->keyid[0] = _cdk_buftou32 (buf + 12); - pk->keyid[1] = _cdk_buftou32 (buf + 16); - } + { + cdk_pk_get_fingerprint (pk, buf); + pk->keyid[0] = _cdk_buftou32 (buf + 12); + pk->keyid[1] = _cdk_buftou32 (buf + 16); + } } lowbits = pk ? pk->keyid[1] : 0; if (keyid && pk) diff --git a/lib/opencdk/read-packet.c b/lib/opencdk/read-packet.c index 6e7fcefd56..313e779b35 100644 --- a/lib/opencdk/read-packet.c +++ b/lib/opencdk/read-packet.c @@ -92,12 +92,12 @@ read_s2k (cdk_stream_t inp, cdk_s2k_t s2k) else if (s2k->mode == CDK_S2K_SALTED || s2k->mode == CDK_S2K_ITERSALTED) { if (stream_read (inp, s2k->salt, DIM (s2k->salt), &nread)) - return CDK_Inv_Packet; + return CDK_Inv_Packet; if (nread != DIM (s2k->salt)) - return CDK_Inv_Packet; + return CDK_Inv_Packet; if (s2k->mode == CDK_S2K_ITERSALTED) - s2k->count = cdk_stream_getc (inp); + s2k->count = cdk_stream_getc (inp); } else if (s2k->mode == CDK_S2K_GNU_EXT) { @@ -130,14 +130,14 @@ read_mpi (cdk_stream_t inp, bigint_t * ret_m, int secure) if (nbits > MAX_MPI_BITS || nbits == 0) { _gnutls_write_log ("read_mpi: too large %d bits\n", (int) nbits); - return CDK_MPI_Error; /* Sanity check */ + return CDK_MPI_Error; /* Sanity check */ } rc = stream_read (inp, buf + 2, nread, &nread); if (!rc && nread != ((nbits + 7) / 8)) { _gnutls_write_log ("read_mpi: too short %d < %d\n", (int) nread, - (int) ((nbits + 7) / 8)); + (int) ((nbits + 7) / 8)); return CDK_MPI_Error; } @@ -166,14 +166,14 @@ _cdk_pkt_read_len (FILE * inp, size_t * ret_partial) if (c1 == EOF) return (size_t) EOF; if (c1 < 224 || c1 == 255) - *ret_partial = 0; /* End of partial data */ + *ret_partial = 0; /* End of partial data */ if (c1 < 192) pktlen = c1; else if (c1 >= 192 && c1 <= 223) { c2 = fgetc (inp); if (c2 == EOF) - return (size_t) EOF; + return (size_t) EOF; pktlen = ((c1 - 192) << 8) + c2 + 192; } else if (c1 == 255) @@ -208,7 +208,7 @@ read_pubkey_enc (cdk_stream_t inp, size_t pktlen, cdk_pkt_pubkey_enc_t pke) pke->keyid[0] = read_32 (inp); pke->keyid[1] = read_32 (inp); if (!pke->keyid[0] && !pke->keyid[1]) - pke->throw_keyid = 1; /* RFC2440 "speculative" keyID */ + pke->throw_keyid = 1; /* RFC2440 "speculative" keyID */ pke->pubkey_algo = _pgp_pub_algo_to_cdk (cdk_stream_getc (inp)); nenc = cdk_pk_get_nenc (pke->pubkey_algo); if (!nenc) @@ -217,7 +217,7 @@ read_pubkey_enc (cdk_stream_t inp, size_t pktlen, cdk_pkt_pubkey_enc_t pke) { cdk_error_t rc = read_mpi (inp, &pke->mpi[i], 0); if (rc) - return rc; + return rc; } return 0; @@ -281,7 +281,7 @@ read_public_key (cdk_stream_t inp, size_t pktlen, cdk_pkt_pubkey_t pk) if (DEBUG_PKT) _gnutls_write_log ("read_public_key: %d octets\n", (int) pktlen); - pk->is_invalid = 1; /* default to detect missing self signatures */ + pk->is_invalid = 1; /* default to detect missing self signatures */ pk->is_revoked = 0; pk->has_expired = 0; @@ -293,7 +293,7 @@ read_public_key (cdk_stream_t inp, size_t pktlen, cdk_pkt_pubkey_t pk) { ndays = read_16 (inp); if (ndays) - pk->expiredate = pk->timestamp + ndays * 86400L; + pk->expiredate = pk->timestamp + ndays * 86400L; } pk->pubkey_algo = _pgp_pub_algo_to_cdk (cdk_stream_getc (inp)); @@ -302,14 +302,14 @@ read_public_key (cdk_stream_t inp, size_t pktlen, cdk_pkt_pubkey_t pk) { gnutls_assert (); _gnutls_write_log ("invalid public key algorithm %d\n", - pk->pubkey_algo); + pk->pubkey_algo); return CDK_Inv_Algo; } for (i = 0; i < npkey; i++) { cdk_error_t rc = read_mpi (inp, &pk->mpi[i], 0); if (rc) - return rc; + return rc; } /* This value is just for the first run and will be @@ -353,24 +353,24 @@ read_secret_key (cdk_stream_t inp, size_t pktlen, cdk_pkt_seckey_t sk) sk->protect.algo = _pgp_cipher_to_gnutls (cdk_stream_getc (inp)); sk->protect.s2k = cdk_calloc (1, sizeof *sk->protect.s2k); if (!sk->protect.s2k) - return CDK_Out_Of_Core; + return CDK_Out_Of_Core; rc = read_s2k (inp, sk->protect.s2k); if (rc) - return rc; + return rc; /* refer to --export-secret-subkeys in gpg(1) */ if (sk->protect.s2k->mode == CDK_S2K_GNU_EXT) - sk->protect.ivlen = 0; + sk->protect.ivlen = 0; else - { - sk->protect.ivlen = gnutls_cipher_get_block_size (sk->protect.algo); - if (!sk->protect.ivlen) - return CDK_Inv_Packet; - rc = stream_read (inp, sk->protect.iv, sk->protect.ivlen, &nread); - if (rc) - return rc; - if (nread != sk->protect.ivlen) - return CDK_Inv_Packet; - } + { + sk->protect.ivlen = gnutls_cipher_get_block_size (sk->protect.algo); + if (!sk->protect.ivlen) + return CDK_Inv_Packet; + rc = stream_read (inp, sk->protect.iv, sk->protect.ivlen, &nread); + if (rc) + return rc; + if (nread != sk->protect.ivlen) + return CDK_Inv_Packet; + } } else sk->protect.algo = _pgp_cipher_to_gnutls (sk->s2k_usage); @@ -379,16 +379,16 @@ read_secret_key (cdk_stream_t inp, size_t pktlen, cdk_pkt_seckey_t sk) sk->csum = 0; nskey = cdk_pk_get_nskey (sk->pk->pubkey_algo); if (!nskey) - { - gnutls_assert (); - return CDK_Inv_Algo; - } + { + gnutls_assert (); + return CDK_Inv_Algo; + } for (i = 0; i < nskey; i++) - { - rc = read_mpi (inp, &sk->mpi[i], 1); - if (rc) - return rc; - } + { + rc = read_mpi (inp, &sk->mpi[i], 1); + if (rc) + return rc; + } sk->csum = read_16 (inp); sk->is_protected = 0; } @@ -397,16 +397,16 @@ read_secret_key (cdk_stream_t inp, size_t pktlen, cdk_pkt_seckey_t sk) /* The length of each multiprecision integer is stored in plaintext. */ nskey = cdk_pk_get_nskey (sk->pk->pubkey_algo); if (!nskey) - { - gnutls_assert (); - return CDK_Inv_Algo; - } + { + gnutls_assert (); + return CDK_Inv_Algo; + } for (i = 0; i < nskey; i++) - { - rc = read_mpi (inp, &sk->mpi[i], 1); - if (rc) - return rc; - } + { + rc = read_mpi (inp, &sk->mpi[i], 1); + if (rc) + return rc; + } sk->csum = read_16 (inp); sk->is_protected = 1; } @@ -418,38 +418,38 @@ read_secret_key (cdk_stream_t inp, size_t pktlen, cdk_pkt_seckey_t sk) p2 -= p1; sk->enclen = pktlen - p2; if (sk->enclen < 2) - return CDK_Inv_Packet; /* at least 16 bits for the checksum! */ + return CDK_Inv_Packet; /* at least 16 bits for the checksum! */ sk->encdata = cdk_calloc (1, sk->enclen + 1); if (!sk->encdata) - return CDK_Out_Of_Core; + return CDK_Out_Of_Core; if (stream_read (inp, sk->encdata, sk->enclen, &nread)) - return CDK_Inv_Packet; + return CDK_Inv_Packet; /* Handle the GNU S2K extensions we know (just gnu-dummy right now): */ if (sk->protect.s2k->mode == CDK_S2K_GNU_EXT) - { - unsigned char gnumode; - if ((sk->enclen < strlen ("GNU") + 1) || - (0 != memcmp ("GNU", sk->encdata, strlen ("GNU")))) - return CDK_Inv_Packet; - gnumode = sk->encdata[strlen ("GNU")]; - /* we only handle gnu-dummy (mode 1). - mode 2 should refer to external smart cards. - */ - if (gnumode != 1) - return CDK_Inv_Packet; - /* gnu-dummy should have no more data */ - if (sk->enclen != strlen ("GNU") + 1) - return CDK_Inv_Packet; - } + { + unsigned char gnumode; + if ((sk->enclen < strlen ("GNU") + 1) || + (0 != memcmp ("GNU", sk->encdata, strlen ("GNU")))) + return CDK_Inv_Packet; + gnumode = sk->encdata[strlen ("GNU")]; + /* we only handle gnu-dummy (mode 1). + mode 2 should refer to external smart cards. + */ + if (gnumode != 1) + return CDK_Inv_Packet; + /* gnu-dummy should have no more data */ + if (sk->enclen != strlen ("GNU") + 1) + return CDK_Inv_Packet; + } nskey = cdk_pk_get_nskey (sk->pk->pubkey_algo); if (!nskey) - { - gnutls_assert (); - return CDK_Inv_Algo; - } + { + gnutls_assert (); + return CDK_Inv_Algo; + } /* We mark each MPI entry with NULL to indicate a protected key. */ for (i = 0; i < nskey; i++) - sk->mpi[i] = NULL; + sk->mpi[i] = NULL; sk->is_protected = 1; } @@ -510,16 +510,16 @@ read_attribute (cdk_stream_t inp, size_t pktlen, cdk_pkt_userid_t attr) else if (len >= 192) { if (pktlen < 2) - { - cdk_free (buf); - return CDK_Inv_Packet; - } + { + cdk_free (buf); + return CDK_Inv_Packet; + } len = ((len - 192) << 8) + *p + 192; p++; pktlen--; } - if (*p != 1) /* Currently only 1, meaning an image, is defined. */ + if (*p != 1) /* Currently only 1, meaning an image, is defined. */ { cdk_free (buf); return CDK_Inv_Packet; @@ -595,7 +595,7 @@ read_subpkt (cdk_stream_t inp, cdk_subpkt_t * r_ctx, size_t * r_nbytes) c1 = cdk_stream_getc (inp); n++; if (c1 == 0) - return 0; + return 0; size = ((c - 192) << 8) + c1 + 192; } else if (c < 192) @@ -659,61 +659,61 @@ parse_sig_subpackets (cdk_pkt_signature_t sig) for (node = sig->unhashed; node; node = node->next) { if (node->type == CDK_SIGSUBPKT_ISSUER && node->size >= 8) - { - sig->keyid[0] = _cdk_buftou32 (node->d); - sig->keyid[1] = _cdk_buftou32 (node->d + 4); - } + { + sig->keyid[0] = _cdk_buftou32 (node->d); + sig->keyid[1] = _cdk_buftou32 (node->d + 4); + } else if (node->type == CDK_SIGSUBPKT_EXPORTABLE && node->d[0] == 0) - { - /* Sometimes this packet might be placed in the unhashed area */ - sig->flags.exportable = 0; - } + { + /* Sometimes this packet might be placed in the unhashed area */ + sig->flags.exportable = 0; + } } for (node = sig->hashed; node; node = node->next) { if (node->type == CDK_SIGSUBPKT_SIG_CREATED && node->size >= 4) - sig->timestamp = _cdk_buftou32 (node->d); + sig->timestamp = _cdk_buftou32 (node->d); else if (node->type == CDK_SIGSUBPKT_SIG_EXPIRE && node->size >= 4) - { - sig->expiredate = _cdk_buftou32 (node->d); - if (sig->expiredate > 0 && sig->expiredate < (u32) time (NULL)) - sig->flags.expired = 1; - } + { + sig->expiredate = _cdk_buftou32 (node->d); + if (sig->expiredate > 0 && sig->expiredate < (u32) time (NULL)) + sig->flags.expired = 1; + } else if (node->type == CDK_SIGSUBPKT_POLICY) - sig->flags.policy_url = 1; + sig->flags.policy_url = 1; else if (node->type == CDK_SIGSUBPKT_NOTATION) - sig->flags.notation = 1; + sig->flags.notation = 1; else if (node->type == CDK_SIGSUBPKT_REVOCABLE && node->d[0] == 0) - sig->flags.revocable = 0; + sig->flags.revocable = 0; else if (node->type == CDK_SIGSUBPKT_EXPORTABLE && node->d[0] == 0) - sig->flags.exportable = 0; + sig->flags.exportable = 0; } if (sig->sig_class == 0x1F) { cdk_desig_revoker_t r, rnode; for (node = sig->hashed; node; node = node->next) - { - if (node->type == CDK_SIGSUBPKT_REV_KEY) - { - if (node->size < 22) - continue; - rnode = cdk_calloc (1, sizeof *rnode); - if (!rnode) - return CDK_Out_Of_Core; - rnode->r_class = node->d[0]; - rnode->algid = node->d[1]; - memcpy (rnode->fpr, node->d + 2, KEY_FPR_LEN); - if (!sig->revkeys) - sig->revkeys = rnode; - else - { - for (r = sig->revkeys; r->next; r = r->next) - ; - r->next = rnode; - } - } - } + { + if (node->type == CDK_SIGSUBPKT_REV_KEY) + { + if (node->size < 22) + continue; + rnode = cdk_calloc (1, sizeof *rnode); + if (!rnode) + return CDK_Out_Of_Core; + rnode->r_class = node->d[0]; + rnode->algid = node->d[1]; + memcpy (rnode->fpr, node->d + 2, KEY_FPR_LEN); + if (!sig->revkeys) + sig->revkeys = rnode; + else + { + for (r = sig->revkeys; r->next; r = r->next) + ; + r->next = rnode; + } + } + } } return 0; @@ -745,7 +745,7 @@ read_signature (cdk_stream_t inp, size_t pktlen, cdk_pkt_signature_t sig) if (sig->version < 4) { if (cdk_stream_getc (inp) != 5) - return CDK_Inv_Packet; + return CDK_Inv_Packet; sig->sig_class = cdk_stream_getc (inp); sig->timestamp = read_32 (inp); sig->keyid[0] = read_32 (inp); @@ -756,13 +756,13 @@ read_signature (cdk_stream_t inp, size_t pktlen, cdk_pkt_signature_t sig) sig->digest_start[1] = cdk_stream_getc (inp); nsig = cdk_pk_get_nsig (sig->pubkey_algo); if (!nsig) - return CDK_Inv_Algo; + return CDK_Inv_Algo; for (i = 0; i < nsig; i++) - { - rc = read_mpi (inp, &sig->mpi[i], 0); - if (rc) - return rc; - } + { + rc = read_mpi (inp, &sig->mpi[i], 0); + if (rc) + return rc; + } } else { @@ -773,38 +773,38 @@ read_signature (cdk_stream_t inp, size_t pktlen, cdk_pkt_signature_t sig) size = sig->hashed_size; sig->hashed = NULL; while (size > 0) - { - rc = read_subpkt (inp, &sig->hashed, &nbytes); - if (rc) - return rc; - size -= nbytes; - } + { + rc = read_subpkt (inp, &sig->hashed, &nbytes); + if (rc) + return rc; + size -= nbytes; + } sig->unhashed_size = read_16 (inp); size = sig->unhashed_size; sig->unhashed = NULL; while (size > 0) - { - rc = read_subpkt (inp, &sig->unhashed, &nbytes); - if (rc) - return rc; - size -= nbytes; - } + { + rc = read_subpkt (inp, &sig->unhashed, &nbytes); + if (rc) + return rc; + size -= nbytes; + } rc = parse_sig_subpackets (sig); if (rc) - return rc; + return rc; sig->digest_start[0] = cdk_stream_getc (inp); sig->digest_start[1] = cdk_stream_getc (inp); nsig = cdk_pk_get_nsig (sig->pubkey_algo); if (!nsig) - return CDK_Inv_Algo; + return CDK_Inv_Algo; for (i = 0; i < nsig; i++) - { - rc = read_mpi (inp, &sig->mpi[i], 0); - if (rc) - return rc; - } + { + rc = read_mpi (inp, &sig->mpi[i], 0); + if (rc) + return rc; + } } return 0; @@ -813,7 +813,7 @@ read_signature (cdk_stream_t inp, size_t pktlen, cdk_pkt_signature_t sig) static cdk_error_t read_literal (cdk_stream_t inp, size_t pktlen, - cdk_pkt_literal_t * ret_pt, int is_partial) + cdk_pkt_literal_t * ret_pt, int is_partial) { cdk_pkt_literal_t pt = *ret_pt; size_t nread; @@ -836,13 +836,13 @@ read_literal (cdk_stream_t inp, size_t pktlen, { *ret_pt = pt = cdk_realloc (pt, sizeof *pt + pt->namelen + 2); if (!pt) - return CDK_Out_Of_Core; + return CDK_Out_Of_Core; pt->name = (char *) pt + sizeof (*pt); rc = stream_read (inp, pt->name, pt->namelen, &nread); if (rc) - return rc; + return rc; if ((int) nread != pt->namelen) - return CDK_Inv_Packet; + return CDK_Inv_Packet; pt->name[pt->namelen] = '\0'; } pt->timestamp = read_32 (inp); @@ -887,7 +887,7 @@ read_old_length (cdk_stream_t inp, int ctb, size_t * r_len, size_t * r_size) /* Read a new CTB and decode the body length. */ static void read_new_length (cdk_stream_t inp, - size_t * r_len, size_t * r_size, size_t * r_partial) + size_t * r_len, size_t * r_size, size_t * r_partial) { int c, c1; @@ -959,17 +959,17 @@ cdk_pkt_read (cdk_stream_t inp, cdk_packet_t pkt) if (!(ctb & 0x80)) { _cdk_log_info ("cdk_pkt_read: no openpgp data found. " - "(ctb=%02X; fpos=%02X)\n", (int) ctb, - (int) cdk_stream_tell (inp)); + "(ctb=%02X; fpos=%02X)\n", (int) ctb, + (int) cdk_stream_tell (inp)); return CDK_Inv_Packet; } - if (ctb & 0x40) /* RFC2440 packet format. */ + if (ctb & 0x40) /* RFC2440 packet format. */ { pkttype = ctb & 0x3f; is_newctb = 1; } - else /* the old RFC1991 packet format. */ + else /* the old RFC1991 packet format. */ { pkttype = ctb & 0x3f; pkttype >>= 2; @@ -997,11 +997,11 @@ cdk_pkt_read (cdk_stream_t inp, cdk_packet_t pkt) { case CDK_PKT_ATTRIBUTE: pkt->pkt.user_id = cdk_calloc (1, sizeof *pkt->pkt.user_id - + pkt->pktlen + 16 + 1); + + pkt->pktlen + 16 + 1); if (!pkt->pkt.user_id) - return CDK_Out_Of_Core; + return CDK_Out_Of_Core; pkt->pkt.user_id->name = - (char *) pkt->pkt.user_id + sizeof (*pkt->pkt.user_id); + (char *) pkt->pkt.user_id + sizeof (*pkt->pkt.user_id); rc = read_attribute (inp, pktlen, pkt->pkt.user_id); pkt->pkttype = CDK_PKT_ATTRIBUTE; @@ -1009,89 +1009,89 @@ cdk_pkt_read (cdk_stream_t inp, cdk_packet_t pkt) case CDK_PKT_USER_ID: pkt->pkt.user_id = cdk_calloc (1, sizeof *pkt->pkt.user_id - + pkt->pktlen + 1); + + pkt->pktlen + 1); if (!pkt->pkt.user_id) - return CDK_Out_Of_Core; + return CDK_Out_Of_Core; pkt->pkt.user_id->name = - (char *) pkt->pkt.user_id + sizeof (*pkt->pkt.user_id); + (char *) pkt->pkt.user_id + sizeof (*pkt->pkt.user_id); rc = read_user_id (inp, pktlen, pkt->pkt.user_id); break; case CDK_PKT_PUBLIC_KEY: pkt->pkt.public_key = cdk_calloc (1, sizeof *pkt->pkt.public_key); if (!pkt->pkt.public_key) - return CDK_Out_Of_Core; + return CDK_Out_Of_Core; rc = read_public_key (inp, pktlen, pkt->pkt.public_key); break; case CDK_PKT_PUBLIC_SUBKEY: pkt->pkt.public_key = cdk_calloc (1, sizeof *pkt->pkt.public_key); if (!pkt->pkt.public_key) - return CDK_Out_Of_Core; + return CDK_Out_Of_Core; rc = read_public_subkey (inp, pktlen, pkt->pkt.public_key); break; case CDK_PKT_SECRET_KEY: pkt->pkt.secret_key = cdk_calloc (1, sizeof *pkt->pkt.secret_key); if (!pkt->pkt.secret_key) - return CDK_Out_Of_Core; + return CDK_Out_Of_Core; pkt->pkt.secret_key->pk = cdk_calloc (1, - sizeof *pkt->pkt.secret_key->pk); + sizeof *pkt->pkt.secret_key->pk); if (!pkt->pkt.secret_key->pk) - return CDK_Out_Of_Core; + return CDK_Out_Of_Core; rc = read_secret_key (inp, pktlen, pkt->pkt.secret_key); break; case CDK_PKT_SECRET_SUBKEY: pkt->pkt.secret_key = cdk_calloc (1, sizeof *pkt->pkt.secret_key); if (!pkt->pkt.secret_key) - return CDK_Out_Of_Core; + return CDK_Out_Of_Core; pkt->pkt.secret_key->pk = cdk_calloc (1, - sizeof *pkt->pkt.secret_key->pk); + sizeof *pkt->pkt.secret_key->pk); if (!pkt->pkt.secret_key->pk) - return CDK_Out_Of_Core; + return CDK_Out_Of_Core; rc = read_secret_subkey (inp, pktlen, pkt->pkt.secret_key); break; case CDK_PKT_LITERAL: pkt->pkt.literal = cdk_calloc (1, sizeof *pkt->pkt.literal); if (!pkt->pkt.literal) - return CDK_Out_Of_Core; + return CDK_Out_Of_Core; rc = read_literal (inp, pktlen, &pkt->pkt.literal, is_partial); break; case CDK_PKT_ONEPASS_SIG: pkt->pkt.onepass_sig = cdk_calloc (1, sizeof *pkt->pkt.onepass_sig); if (!pkt->pkt.onepass_sig) - return CDK_Out_Of_Core; + return CDK_Out_Of_Core; rc = read_onepass_sig (inp, pktlen, pkt->pkt.onepass_sig); break; case CDK_PKT_SIGNATURE: pkt->pkt.signature = cdk_calloc (1, sizeof *pkt->pkt.signature); if (!pkt->pkt.signature) - return CDK_Out_Of_Core; + return CDK_Out_Of_Core; rc = read_signature (inp, pktlen, pkt->pkt.signature); break; case CDK_PKT_PUBKEY_ENC: pkt->pkt.pubkey_enc = cdk_calloc (1, sizeof *pkt->pkt.pubkey_enc); if (!pkt->pkt.pubkey_enc) - return CDK_Out_Of_Core; + return CDK_Out_Of_Core; rc = read_pubkey_enc (inp, pktlen, pkt->pkt.pubkey_enc); break; case CDK_PKT_COMPRESSED: pkt->pkt.compressed = cdk_calloc (1, sizeof *pkt->pkt.compressed); if (!pkt->pkt.compressed) - return CDK_Out_Of_Core; + return CDK_Out_Of_Core; rc = read_compressed (inp, pktlen, pkt->pkt.compressed); break; case CDK_PKT_MDC: pkt->pkt.mdc = cdk_calloc (1, sizeof *pkt->pkt.mdc); if (!pkt->pkt.mdc) - return CDK_Out_Of_Core; + return CDK_Out_Of_Core; rc = read_mdc (inp, pkt->pkt.mdc); break; diff --git a/lib/opencdk/seskey.c b/lib/opencdk/seskey.c index 8830905098..27de038beb 100644 --- a/lib/opencdk/seskey.c +++ b/lib/opencdk/seskey.c @@ -40,7 +40,7 @@ */ static cdk_error_t do_encode_md (byte ** r_frame, size_t * r_flen, const byte * md, int algo, - size_t len, unsigned nbits, const byte * asn, size_t asnlen) + size_t len, unsigned nbits, const byte * asn, size_t asnlen) { byte *frame = NULL; size_t nframe = (nbits + 7) / 8; @@ -81,43 +81,43 @@ do_encode_md (byte ** r_frame, size_t * r_flen, const byte * md, int algo, return 0; } -static const byte md5_asn[18] = /* Object ID is 1.2.840.113549.2.5 */ +static const byte md5_asn[18] = /* Object ID is 1.2.840.113549.2.5 */ { 0x30, 0x20, 0x30, 0x0c, 0x06, 0x08, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x02, 0x05, 0x05, 0x00, 0x04, 0x10 }; -static const byte sha1_asn[15] = /* Object ID is 1.3.14.3.2.26 */ +static const byte sha1_asn[15] = /* Object ID is 1.3.14.3.2.26 */ { 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1a, 0x05, 0x00, 0x04, 0x14 }; -static const byte sha224_asn[19] = /* Object ID is 2.16.840.1.101.3.4.2.4 */ +static const byte sha224_asn[19] = /* Object ID is 2.16.840.1.101.3.4.2.4 */ { 0x30, 0x2D, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x04, 0x05, 0x00, 0x04, 0x1C }; -static const byte sha256_asn[19] = /* Object ID is 2.16.840.1.101.3.4.2.1 */ +static const byte sha256_asn[19] = /* Object ID is 2.16.840.1.101.3.4.2.1 */ { 0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05, 0x00, 0x04, 0x20 }; -static const byte sha512_asn[] = /* Object ID is 2.16.840.1.101.3.4.2.3 */ +static const byte sha512_asn[] = /* Object ID is 2.16.840.1.101.3.4.2.3 */ { 0x30, 0x51, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03, 0x05, 0x00, 0x04, 0x40 }; -static const byte sha384_asn[] = /* Object ID is 2.16.840.1.101.3.4.2.2 */ +static const byte sha384_asn[] = /* Object ID is 2.16.840.1.101.3.4.2.2 */ { 0x30, 0x41, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x02, 0x05, 0x00, 0x04, 0x30 }; -static const byte rmd160_asn[15] = /* Object ID is 1.3.36.3.2.1 */ +static const byte rmd160_asn[15] = /* Object ID is 1.3.36.3.2.1 */ { 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x24, 0x03, 0x02, 0x01, 0x05, 0x00, 0x04, 0x14 }; @@ -158,7 +158,7 @@ _gnutls_get_digest_oid (gnutls_digest_algorithm_t algo, const byte ** data) /* Encode the given digest into a pkcs#1 compatible format. */ cdk_error_t _cdk_digest_encode_pkcs1 (byte ** r_md, size_t * r_mdlen, int pk_algo, - const byte * md, int digest_algo, unsigned nbits) + const byte * md, int digest_algo, unsigned nbits) { size_t dlen; @@ -169,10 +169,10 @@ _cdk_digest_encode_pkcs1 (byte ** r_md, size_t * r_mdlen, int pk_algo, if (dlen <= 0) return CDK_Inv_Algo; if (is_DSA (pk_algo)) - { /* DSS does not use a special encoding. */ + { /* DSS does not use a special encoding. */ *r_md = cdk_malloc (dlen + 1); if (!*r_md) - return CDK_Out_Of_Core; + return CDK_Out_Of_Core; *r_mdlen = dlen; memcpy (*r_md, md, dlen); return 0; @@ -185,10 +185,10 @@ _cdk_digest_encode_pkcs1 (byte ** r_md, size_t * r_mdlen, int pk_algo, asnlen = _gnutls_get_digest_oid (digest_algo, &asn); if (asnlen < 0) - return asnlen; + return asnlen; rc = do_encode_md (r_md, r_mdlen, md, digest_algo, dlen, - nbits, asn, asnlen); + nbits, asn, asnlen); return rc; } return 0; @@ -207,7 +207,7 @@ _cdk_digest_encode_pkcs1 (byte ** r_md, size_t * r_mdlen, int pk_algo, **/ cdk_error_t cdk_s2k_new (cdk_s2k_t * ret_s2k, int mode, int digest_algo, - const byte * salt) + const byte * salt) { cdk_s2k_t s2k; diff --git a/lib/opencdk/sig-check.c b/lib/opencdk/sig-check.c index cf007d4e34..c1a9154396 100644 --- a/lib/opencdk/sig-check.c +++ b/lib/opencdk/sig-check.c @@ -38,7 +38,7 @@ static int hash_mpibuf (cdk_pubkey_t pk, digest_hd_st * md, int usefpr) { - byte buf[MAX_MPI_BYTES]; /* FIXME: do not use hardcoded length. */ + byte buf[MAX_MPI_BYTES]; /* FIXME: do not use hardcoded length. */ size_t nbytes; size_t i, npkey; int err; @@ -53,15 +53,15 @@ hash_mpibuf (cdk_pubkey_t pk, digest_hd_st * md, int usefpr) err = _gnutls_mpi_print_pgp (pk->mpi[i], buf, &nbytes); if (err < 0) - { - gnutls_assert (); - return map_gnutls_error (err); - } + { + gnutls_assert (); + return map_gnutls_error (err); + } if (!usefpr || pk->version == 4) - _gnutls_hash (md, buf, nbytes); - else /* without the prefix. */ - _gnutls_hash (md, buf + 2, nbytes - 2); + _gnutls_hash (md, buf, nbytes); + else /* without the prefix. */ + _gnutls_hash (md, buf + 2, nbytes - 2); } return 0; } @@ -105,7 +105,7 @@ _cdk_hash_pubkey (cdk_pubkey_t pk, digest_hd_st * md, int usefpr) /* Convert the expiration date into days. */ if (pk->expiredate) - a = (u16) ((pk->expiredate - pk->timestamp) / 86400L); + a = (u16) ((pk->expiredate - pk->timestamp) / 86400L); buf[i++] = a >> 8; buf[i++] = a; } @@ -178,24 +178,24 @@ _cdk_hash_sig_data (cdk_pkt_signature_t sig, digest_hd_st * md) tmp = _gnutls_hash_algo_to_pgp (sig->digest_algo); _gnutls_hash (md, &tmp, 1); if (sig->hashed != NULL) - { - byte *p = _cdk_subpkt_get_array (sig->hashed, 0, &n); - assert (p != NULL); - buf[0] = n >> 8; - buf[1] = n >> 0; - _gnutls_hash (md, buf, 2); - _gnutls_hash (md, p, n); - cdk_free (p); - sig->hashed_size = n; - n = sig->hashed_size + 6; - } + { + byte *p = _cdk_subpkt_get_array (sig->hashed, 0, &n); + assert (p != NULL); + buf[0] = n >> 8; + buf[1] = n >> 0; + _gnutls_hash (md, buf, 2); + _gnutls_hash (md, p, n); + cdk_free (p); + sig->hashed_size = n; + n = sig->hashed_size + 6; + } else - { - tmp = 0x00; - _gnutls_hash (md, &tmp, 1); - _gnutls_hash (md, &tmp, 1); - n = 6; - } + { + tmp = 0x00; + _gnutls_hash (md, &tmp, 1); + _gnutls_hash (md, &tmp, 1); + n = 6; + } _gnutls_hash (md, &sig->version, 1); tmp = 0xff; _gnutls_hash (md, &tmp, 1); @@ -232,7 +232,7 @@ cache_sig_result (cdk_pkt_signature_t sig, int res) Use the digest handle @digest. */ cdk_error_t _cdk_sig_check (cdk_pubkey_t pk, cdk_pkt_signature_t sig, - digest_hd_st * digest, int *r_expired) + digest_hd_st * digest, int *r_expired) { cdk_error_t rc; byte md[MAX_DIGEST_LEN]; @@ -274,8 +274,8 @@ _cdk_sig_check (cdk_pubkey_t pk, cdk_pkt_signature_t sig, @knode is the key node and @snode the signature node. */ cdk_error_t _cdk_pk_check_sig (cdk_keydb_hd_t keydb, - cdk_kbnode_t knode, cdk_kbnode_t snode, int *is_selfsig, - char **ret_uid) + cdk_kbnode_t knode, cdk_kbnode_t snode, int *is_selfsig, + char **ret_uid) { digest_hd_st md; int err; @@ -312,74 +312,74 @@ _cdk_pk_check_sig (cdk_keydb_hd_t keydb, is_expired = 0; if (sig->sig_class == 0x20) - { /* key revocation */ + { /* key revocation */ cdk_kbnode_hash (knode, &md, 0, 0, 0); rc = _cdk_sig_check (pk, sig, &md, &is_expired); } else if (sig->sig_class == 0x28) - { /* subkey revocation */ + { /* subkey revocation */ node = cdk_kbnode_find_prev (knode, snode, CDK_PKT_PUBLIC_SUBKEY); if (!node) - { /* no subkey for subkey revocation packet */ - gnutls_assert (); - rc = CDK_Error_No_Key; - goto fail; - } + { /* no subkey for subkey revocation packet */ + gnutls_assert (); + rc = CDK_Error_No_Key; + goto fail; + } cdk_kbnode_hash (knode, &md, 0, 0, 0); cdk_kbnode_hash (node, &md, 0, 0, 0); rc = _cdk_sig_check (pk, sig, &md, &is_expired); } else if (sig->sig_class == 0x18 || sig->sig_class == 0x19) - { /* primary/secondary key binding */ + { /* primary/secondary key binding */ node = cdk_kbnode_find_prev (knode, snode, CDK_PKT_PUBLIC_SUBKEY); if (!node) - { /* no subkey for subkey binding packet */ - gnutls_assert (); - rc = CDK_Error_No_Key; - goto fail; - } + { /* no subkey for subkey binding packet */ + gnutls_assert (); + rc = CDK_Error_No_Key; + goto fail; + } cdk_kbnode_hash (knode, &md, 0, 0, 0); cdk_kbnode_hash (node, &md, 0, 0, 0); rc = _cdk_sig_check (pk, sig, &md, &is_expired); } else if (sig->sig_class == 0x1F) - { /* direct key signature */ + { /* direct key signature */ cdk_kbnode_hash (knode, &md, 0, 0, 0); rc = _cdk_sig_check (pk, sig, &md, &is_expired); } else - { /* all other classes */ + { /* all other classes */ cdk_pkt_userid_t uid; node = cdk_kbnode_find_prev (knode, snode, CDK_PKT_USER_ID); if (!node) - { /* no user ID for key signature packet */ - gnutls_assert (); - rc = CDK_Error_No_Key; - goto fail; - } + { /* no user ID for key signature packet */ + gnutls_assert (); + rc = CDK_Error_No_Key; + goto fail; + } uid = node->pkt->pkt.user_id; if (ret_uid) - { - *ret_uid = uid->name; - } + { + *ret_uid = uid->name; + } cdk_kbnode_hash (knode, &md, 0, 0, 0); cdk_kbnode_hash (node, &md, sig->version == 4, 0, 0); if (pk->keyid[0] == sig->keyid[0] && pk->keyid[1] == sig->keyid[1]) - { - rc = _cdk_sig_check (pk, sig, &md, &is_expired); - if (is_selfsig) - *is_selfsig = 1; - } + { + rc = _cdk_sig_check (pk, sig, &md, &is_expired); + if (is_selfsig) + *is_selfsig = 1; + } else if (keydb != NULL) - { - cdk_pubkey_t sig_pk; - rc = cdk_keydb_get_pk (keydb, sig->keyid, &sig_pk); - if (!rc) - rc = _cdk_sig_check (sig_pk, sig, &md, &is_expired); - cdk_pk_release (sig_pk); - } + { + cdk_pubkey_t sig_pk; + rc = cdk_keydb_get_pk (keydb, sig->keyid, &sig_pk); + if (!rc) + rc = _cdk_sig_check (sig_pk, sig, &md, &is_expired); + cdk_pk_release (sig_pk); + } } fail: _gnutls_hash_deinit (&md, NULL); @@ -395,17 +395,17 @@ struct verify_uid static int uid_list_add_sig (struct verify_uid **list, const char *uid, - unsigned int flag) + unsigned int flag) { if (*list == NULL) { *list = cdk_calloc (1, sizeof (struct verify_uid)); if (*list == NULL) - return CDK_Out_Of_Core; + return CDK_Out_Of_Core; (*list)->name = uid; if (flag != 0) - (*list)->nsigs++; + (*list)->nsigs++; } else { @@ -415,30 +415,30 @@ uid_list_add_sig (struct verify_uid **list, const char *uid, p = *list; while (p != NULL) - { - if (strcmp (uid, p->name) == 0) - { - found = 1; - break; - } - prev_p = p; - p = p->next; - } + { + if (strcmp (uid, p->name) == 0) + { + found = 1; + break; + } + prev_p = p; + p = p->next; + } if (found == 0) - { /* not found add to the last */ - prev_p->next = cdk_calloc (1, sizeof (struct verify_uid)); - if (prev_p->next == NULL) - return CDK_Out_Of_Core; - prev_p->next->name = uid; - if (flag != 0) - prev_p->next->nsigs++; - } + { /* not found add to the last */ + prev_p->next = cdk_calloc (1, sizeof (struct verify_uid)); + if (prev_p->next == NULL) + return CDK_Out_Of_Core; + prev_p->next->name = uid; + if (flag != 0) + prev_p->next->nsigs++; + } else - { /* found... increase sigs */ - if (flag != 0) - p->nsigs++; - } + { /* found... increase sigs */ + if (flag != 0) + p->nsigs++; + } } return CDK_Success; @@ -474,12 +474,12 @@ uid_list_all_signed (struct verify_uid *list) while (p != NULL) { if (p->nsigs == 0) - { - return 0; - } + { + return 0; + } p = p->next; } - return 1; /* all signed */ + return 1; /* all signed */ } /** @@ -530,42 +530,42 @@ cdk_pk_check_sigs (cdk_kbnode_t key, cdk_keydb_hd_t keydb, int *r_status) for (node = key; node; node = node->next) { if (node->pkt->pkttype != CDK_PKT_SIGNATURE) - continue; + continue; sig = node->pkt->pkt.signature; rc = _cdk_pk_check_sig (keydb, key, node, &is_selfsig, &uid_name); if (rc && rc != CDK_Error_No_Key) - { - /* It might be possible that a single signature has been - corrupted, thus we do not consider it a problem when - one ore more signatures are bad. But at least the self - signature has to be valid. */ - if (is_selfsig) - { - key_status |= CDK_KEY_INVALID; - break; - } - } + { + /* It might be possible that a single signature has been + corrupted, thus we do not consider it a problem when + one ore more signatures are bad. But at least the self + signature has to be valid. */ + if (is_selfsig) + { + key_status |= CDK_KEY_INVALID; + break; + } + } _cdk_log_debug ("signature %s: signer %08X keyid %08X\n", - rc == CDK_Bad_Sig ? "BAD" : "good", - (unsigned int) sig->keyid[1], (unsigned int) keyid); + rc == CDK_Bad_Sig ? "BAD" : "good", + (unsigned int) sig->keyid[1], (unsigned int) keyid); if (IS_UID_SIG (sig) && uid_name != NULL) - { - /* add every uid in the uid list. Only consider valid: - * - verification was ok - * - not a selfsig - */ - rc = - uid_list_add_sig (&uid_list, uid_name, - (rc == CDK_Success && is_selfsig == 0) ? 1 : 0); - if (rc != CDK_Success) - { - gnutls_assert (); - goto exit; - } - } + { + /* add every uid in the uid list. Only consider valid: + * - verification was ok + * - not a selfsig + */ + rc = + uid_list_add_sig (&uid_list, uid_name, + (rc == CDK_Success && is_selfsig == 0) ? 1 : 0); + if (rc != CDK_Success) + { + gnutls_assert (); + goto exit; + } + } } @@ -609,40 +609,40 @@ cdk_pk_check_self_sig (cdk_kbnode_t key, int *r_status) { pkt = cdk_kbnode_get_packet (p); if (pkt->pkttype != CDK_PKT_PUBLIC_SUBKEY - && pkt->pkttype != CDK_PKT_PUBLIC_KEY) - continue; + && pkt->pkttype != CDK_PKT_PUBLIC_KEY) + continue; /* FIXME: we should set expire/revoke here also but callers expect CDK_KEY_VALID=0 if the key is okay. */ sig_ok = 0; for (node = p; node; node = node->next) - { - if (node->pkt->pkttype != CDK_PKT_SIGNATURE) - continue; - sig = node->pkt->pkt.signature; - - cdk_sig_get_keyid (sig, sigid); - if (sigid[0] != keyid[0] || sigid[1] != keyid[1]) - continue; - /* FIXME: Now we check all self signatures. */ - rc = _cdk_pk_check_sig (NULL, p, node, &is_selfsig, NULL); - if (rc) - { - *r_status = CDK_KEY_INVALID; - return rc; - } - else /* For each valid self sig we increase this counter. */ - sig_ok++; - } + { + if (node->pkt->pkttype != CDK_PKT_SIGNATURE) + continue; + sig = node->pkt->pkt.signature; + + cdk_sig_get_keyid (sig, sigid); + if (sigid[0] != keyid[0] || sigid[1] != keyid[1]) + continue; + /* FIXME: Now we check all self signatures. */ + rc = _cdk_pk_check_sig (NULL, p, node, &is_selfsig, NULL); + if (rc) + { + *r_status = CDK_KEY_INVALID; + return rc; + } + else /* For each valid self sig we increase this counter. */ + sig_ok++; + } /* A key without a self signature is not valid. At least one * signature for the given key has to be found. */ if (!sig_ok) - { - *r_status = CDK_KEY_INVALID; - return CDK_General_Error; - } + { + *r_status = CDK_KEY_INVALID; + return CDK_General_Error; + } } /* No flags indicate a valid key. */ diff --git a/lib/opencdk/stream.c b/lib/opencdk/stream.c index 01fd8855f1..29bea09bac 100644 --- a/lib/opencdk/stream.c +++ b/lib/opencdk/stream.c @@ -48,7 +48,7 @@ static cdk_error_t stream_flush (cdk_stream_t s); static cdk_error_t stream_filter_write (cdk_stream_t s); static int stream_cache_flush (cdk_stream_t s, FILE * fp); struct stream_filter_s *filter_add (cdk_stream_t s, filter_fnct_t fnc, - int type); + int type); /* FIXME: The read/write/putc/getc function cannot directly @@ -74,7 +74,7 @@ cdk_stream_open (const char *file, cdk_stream_t * ret_s) /* Helper function to allow to open a stream in different modes. */ cdk_error_t _cdk_stream_open_mode (const char *file, const char *mode, - cdk_stream_t * ret_s) + cdk_stream_t * ret_s) { cdk_stream_t s; @@ -125,7 +125,7 @@ _cdk_stream_open_mode (const char *file, const char *mode, */ cdk_error_t cdk_stream_new_from_cbs (cdk_stream_cbs_t cbs, void *opa, - cdk_stream_t * ret_s) + cdk_stream_t * ret_s) { cdk_stream_t s; @@ -192,11 +192,11 @@ cdk_stream_new (const char *file, cdk_stream_t * ret_s) { s->fname = cdk_strdup (file); if (!s->fname) - { - cdk_free (s); - gnutls_assert (); - return CDK_Out_Of_Core; - } + { + cdk_free (s); + gnutls_assert (); + return CDK_Out_Of_Core; + } } s->fp = _cdk_tmpfile (); if (!s->fp) @@ -410,19 +410,19 @@ cdk_stream_flush (cdk_stream_t s) if (!s->flags.filtrated) { if (!cdk_stream_get_length (s)) - return 0; + return 0; rc = cdk_stream_seek (s, 0); if (!rc) - rc = stream_flush (s); + rc = stream_flush (s); if (!rc) - rc = stream_filter_write (s); + rc = stream_filter_write (s); s->flags.filtrated = 1; if (rc) - { - s->error = rc; - gnutls_assert (); - return rc; - } + { + s->error = rc; + gnutls_assert (); + return rc; + } } return 0; } @@ -460,16 +460,16 @@ cdk_stream_close (cdk_stream_t s) } _gnutls_read_log ("close stream ref=%d `%s'\n", - s->fp_ref, s->fname ? s->fname : "[temp]"); + s->fp_ref, s->fname ? s->fname : "[temp]"); /* In the user callback mode, we call the release cb if possible and just free the stream. */ if (s->cbs_hd) { if (s->cbs.release) - rc = s->cbs.release (s->cbs_hd); + rc = s->cbs.release (s->cbs_hd); else - rc = 0; + rc = 0; cdk_free (s); gnutls_assert (); return rc; @@ -487,7 +487,7 @@ cdk_stream_close (cdk_stream_t s) err = fclose (s->fp); s->fp = NULL; if (err) - rc = CDK_File_Error; + rc = CDK_File_Error; } /* Iterate over the filter list and use the cleanup flag to @@ -497,7 +497,7 @@ cdk_stream_close (cdk_stream_t s) { f2 = f->next; if (f->fnct) - f->fnct (f->opaque, STREAMCTL_FREE, NULL, NULL); + f->fnct (f->opaque, STREAMCTL_FREE, NULL, NULL); cdk_free (f); f = f2; } @@ -627,7 +627,7 @@ filter_search (cdk_stream_t s, filter_fnct_t fnc) for (f = s->filters; f; f = f->next) { if (f->fnct == fnc) - return f; + return f; } return NULL; @@ -757,7 +757,7 @@ stream_fp_replace (cdk_stream_t s, FILE ** tmp) assert (s); _gnutls_read_log ("replace stream fd=%d with fd=%d\n", - fileno (s->fp), fileno (*tmp)); + fileno (s->fp), fileno (*tmp)); rc = fclose (s->fp); if (rc) { @@ -790,40 +790,40 @@ stream_filter_write (cdk_stream_t s) for (f = s->filters; f; f = f->next) { if (!f->flags.enabled) - continue; + continue; /* if there is no next filter, create the final output file */ _gnutls_read_log ("filter [write]: last filter=%d fname=%s\n", - f->next ? 1 : 0, s->fname); + f->next ? 1 : 0, s->fname); if (!f->next && s->fname) - f->tmp = fopen (s->fname, "w+b"); + f->tmp = fopen (s->fname, "w+b"); else - f->tmp = _cdk_tmpfile (); + f->tmp = _cdk_tmpfile (); if (!f->tmp) - { - rc = CDK_File_Error; - break; - } + { + rc = CDK_File_Error; + break; + } /* If there is no next filter, flush the cache. We also do this when the next filter is the armor filter because this filter is special and before it starts, all data should be written. */ if ((!f->next || f->next->type == fARMOR) && s->cache.size) - { - rc = stream_cache_flush (s, f->tmp); - if (rc) - break; - } + { + rc = stream_cache_flush (s, f->tmp); + if (rc) + break; + } rc = f->fnct (f->opaque, f->ctl, s->fp, f->tmp); _gnutls_read_log ("filter [write]: type=%d rc=%d\n", f->type, rc); if (!rc) - rc = stream_fp_replace (s, &f->tmp); + rc = stream_fp_replace (s, &f->tmp); if (!rc) - rc = cdk_stream_seek (s, 0); + rc = cdk_stream_seek (s, 0); if (rc) - { - _gnutls_read_log ("filter [close]: fd=%d\n", fileno (f->tmp)); - fclose (f->tmp); - break; - } + { + _gnutls_read_log ("filter [close]: fd=%d\n", fileno (f->tmp)); + fclose (f->tmp); + break; + } } return rc; } @@ -848,46 +848,46 @@ stream_filter_read (cdk_stream_t s) for (f = s->filters; f; f = f->next) { if (!f->flags.enabled) - continue; + continue; if (f->flags.error) - { - _gnutls_read_log ("filter %s [read]: has the error flag; skipped\n", - s->fname ? s->fname : "[temp]"); - continue; - } + { + _gnutls_read_log ("filter %s [read]: has the error flag; skipped\n", + s->fname ? s->fname : "[temp]"); + continue; + } f->tmp = _cdk_tmpfile (); if (!f->tmp) - { - rc = CDK_File_Error; - break; - } + { + rc = CDK_File_Error; + break; + } rc = f->fnct (f->opaque, f->ctl, s->fp, f->tmp); _gnutls_read_log ("filter %s [read]: type=%d rc=%d\n", - s->fname ? s->fname : "[temp]", f->type, rc); + s->fname ? s->fname : "[temp]", f->type, rc); if (rc) - { - f->flags.error = 1; - break; - } + { + f->flags.error = 1; + break; + } f->flags.error = 0; /* If the filter is read-only, do not replace the FP because the contents were not altered in any way. */ if (!f->flags.rdonly) - { - rc = stream_fp_replace (s, &f->tmp); - if (rc) - break; - } + { + rc = stream_fp_replace (s, &f->tmp); + if (rc) + break; + } else - { - fclose (f->tmp); - f->tmp = NULL; - } + { + fclose (f->tmp); + f->tmp = NULL; + } rc = cdk_stream_seek (s, 0); if (rc) - break; + break; /* Disable the filter after it was successfully used. The idea is the following: let's say the armor filter was pushed and later more filters were added. The second time the filter code @@ -911,7 +911,7 @@ _cdk_stream_get_opaque (cdk_stream_t s, int fid) for (f = s->filters; f; f = f->next) { if ((int) f->type == fid) - return f->opaque; + return f->opaque; } return NULL; } @@ -943,7 +943,7 @@ cdk_stream_read (cdk_stream_t s, void *buf, size_t buflen) if (s->cbs_hd) { if (s->cbs.read) - return s->cbs.read (s->cbs_hd, buf, buflen); + return s->cbs.read (s->cbs_hd, buf, buflen); return 0; } @@ -951,20 +951,20 @@ cdk_stream_read (cdk_stream_t s, void *buf, size_t buflen) { s->error = CDK_Inv_Mode; gnutls_assert (); - return EOF; /* This is a write stream */ + return EOF; /* This is a write stream */ } if (!s->flags.no_filter && !s->cache.on && !s->flags.filtrated) { rc = stream_filter_read (s); if (rc) - { - s->error = rc; - if (feof (s->fp)) - s->flags.eof = 1; - gnutls_assert (); - return EOF; - } + { + s->error = rc; + if (feof (s->fp)) + s->flags.eof = 1; + gnutls_assert (); + return EOF; + } s->flags.filtrated = 1; } @@ -1031,13 +1031,13 @@ cdk_stream_write (cdk_stream_t s, const void *buf, size_t count) if (s->cbs_hd) { if (s->cbs.write) - return s->cbs.write (s->cbs_hd, buf, count); + return s->cbs.write (s->cbs_hd, buf, count); return 0; } if (!s->flags.write) { - s->error = CDK_Inv_Mode; /* this is a read stream */ + s->error = CDK_Inv_Mode; /* this is a read stream */ gnutls_assert (); return EOF; } @@ -1051,17 +1051,17 @@ cdk_stream_write (cdk_stream_t s, const void *buf, size_t count) fit into it. We allocate more memory to avoid to resize it the next time the function is used. */ if (s->cache.size + count > s->cache.alloced) - { - byte *old = s->cache.buf; - - s->cache.buf = - cdk_calloc (1, s->cache.alloced + count + STREAM_BUFSIZE); - s->cache.alloced += (count + STREAM_BUFSIZE); - memcpy (s->cache.buf, old, s->cache.size); - cdk_free (old); - _gnutls_read_log ("stream: enlarge cache to %d octets\n", - (int) s->cache.alloced); - } + { + byte *old = s->cache.buf; + + s->cache.buf = + cdk_calloc (1, s->cache.alloced + count + STREAM_BUFSIZE); + s->cache.alloced += (count + STREAM_BUFSIZE); + memcpy (s->cache.buf, old, s->cache.size); + cdk_free (old); + _gnutls_read_log ("stream: enlarge cache to %d octets\n", + (int) s->cache.alloced); + } memcpy (s->cache.buf + s->cache.size, buf, count); s->cache.size += count; return count; @@ -1114,7 +1114,7 @@ cdk_stream_seek (cdk_stream_t s, off_t offset) if (s->cbs_hd) { if (s->cbs.seek) - return s->cbs.seek (s->cbs_hd, offset); + return s->cbs.seek (s->cbs_hd, offset); return 0; } @@ -1192,7 +1192,7 @@ cdk_stream_set_armor_flag (cdk_stream_t s, int armor_type) **/ cdk_error_t cdk_stream_set_literal_flag (cdk_stream_t s, cdk_lit_format_t mode, - const char *fname) + const char *fname) { struct stream_filter_s *f; const char *orig_fname; @@ -1350,7 +1350,7 @@ cdk_stream_enable_cache (cdk_stream_t s, int val) s->cache.buf = cdk_calloc (1, STREAM_BUFSIZE); s->cache.alloced = STREAM_BUFSIZE; _gnutls_read_log ("stream: allocate cache of %d octets\n", - STREAM_BUFSIZE); + STREAM_BUFSIZE); } return 0; } @@ -1368,10 +1368,10 @@ stream_cache_flush (cdk_stream_t s, FILE * fp) { nwritten = fwrite (s->cache.buf, 1, s->cache.size, fp); if (!nwritten) - { - gnutls_assert (); - return CDK_File_Error; - } + { + gnutls_assert (); + return CDK_File_Error; + } s->cache.size = 0; s->cache.on = 0; wipemem (s->cache.buf, s->cache.alloced); @@ -1405,13 +1405,13 @@ cdk_stream_kick_off (cdk_stream_t inp, cdk_stream_t out) { nread = cdk_stream_read (inp, buf, DIM (buf)); if (!nread || nread == EOF) - break; + break; nwritten = cdk_stream_write (out, buf, nread); if (!nwritten || nwritten == EOF) - { /* In case of errors, we leave the loop. */ - rc = inp->error; - break; - } + { /* In case of errors, we leave the loop. */ + rc = inp->error; + break; + } } wipemem (buf, sizeof (buf)); @@ -1432,7 +1432,7 @@ cdk_stream_kick_off (cdk_stream_t inp, cdk_stream_t out) **/ cdk_error_t cdk_stream_mmap_part (cdk_stream_t s, off_t off, size_t len, - byte ** ret_buf, size_t * ret_buflen) + byte ** ret_buf, size_t * ret_buflen) { cdk_error_t rc; off_t oldpos; @@ -1554,10 +1554,10 @@ _cdk_stream_gets (cdk_stream_t s, char *buf, size_t count) { c = cdk_stream_getc (s); if (c == EOF || c == '\r' || c == '\n') - { - buf[i++] = '\0'; - break; - } + { + buf[i++] = '\0'; + break; + } buf[i++] = c; count--; } @@ -1580,7 +1580,7 @@ _cdk_stream_set_blockmode (cdk_stream_t s, size_t nbytes) assert (s); _gnutls_read_log ("stream: activate block mode with blocksize %d\n", - (int) nbytes); + (int) nbytes); s->blkmode = nbytes; return 0; } diff --git a/lib/opencdk/stream.h b/lib/opencdk/stream.h index 491e330099..50553b6946 100644 --- a/lib/opencdk/stream.h +++ b/lib/opencdk/stream.h @@ -41,7 +41,7 @@ enum /* Type definition for the filter function. */ typedef cdk_error_t (*filter_fnct_t) (void *opaque, int ctl, FILE * in, - FILE * out); + FILE * out); /* The stream filter context structure. */ struct stream_filter_s diff --git a/lib/opencdk/verify.c b/lib/opencdk/verify.c index ee5fb2be66..957eb98cfc 100644 --- a/lib/opencdk/verify.c +++ b/lib/opencdk/verify.c @@ -60,7 +60,7 @@ struct static cdk_error_t file_verify_clearsign (cdk_ctx_t, const char *, - const char *); + const char *); /** @@ -74,7 +74,7 @@ static cdk_error_t file_verify_clearsign (cdk_ctx_t, const char *, */ cdk_error_t cdk_stream_verify (cdk_ctx_t hd, cdk_stream_t inp, cdk_stream_t data, - cdk_stream_t out) + cdk_stream_t out) { /* FIXME: out is not currently used. */ if (cdk_armor_filter_use (inp)) @@ -93,7 +93,7 @@ cdk_stream_verify (cdk_ctx_t hd, cdk_stream_t inp, cdk_stream_t data, **/ cdk_error_t cdk_file_verify (cdk_ctx_t hd, const char *file, const char *data_file, - const char *output) + const char *output) { struct stat stbuf; cdk_stream_t inp, data; @@ -113,13 +113,13 @@ cdk_file_verify (cdk_ctx_t hd, const char *file, const char *data_file, { n = cdk_stream_peek (inp, (byte *) buf, DIM (buf) - 1); if (!n || n == -1) - return CDK_EOF; + return CDK_EOF; buf[n] = '\0'; if (strstr (buf, "BEGIN PGP SIGNED MESSAGE")) - { - cdk_stream_close (inp); - return file_verify_clearsign (hd, file, output); - } + { + cdk_stream_close (inp); + return file_verify_clearsign (hd, file, output); + } cdk_stream_set_armor_flag (inp, 0); } @@ -127,10 +127,10 @@ cdk_file_verify (cdk_ctx_t hd, const char *file, const char *data_file, { rc = cdk_stream_open (data_file, &data); if (rc) - { - cdk_stream_close (inp); - return rc; - } + { + cdk_stream_close (inp); + return rc; + } } else data = NULL; @@ -183,14 +183,14 @@ file_verify_clearsign (cdk_ctx_t hd, const char *file, const char *output) { rc = cdk_stream_create (output, &out); if (rc) - return rc; + return rc; } rc = cdk_stream_open (file, &inp); if (rc) { if (output) - cdk_stream_close (out); + cdk_stream_close (out); return rc; } @@ -199,12 +199,12 @@ file_verify_clearsign (cdk_ctx_t hd, const char *file, const char *output) { nbytes = _cdk_stream_gets (inp, buf, DIM (buf) - 1); if (!nbytes || nbytes == -1) - break; + break; if (!strncmp (buf, s, strlen (s))) - { - is_signed = 1; - break; - } + { + is_signed = 1; + break; + } } if (cdk_stream_eof (inp) && !is_signed) @@ -217,20 +217,20 @@ file_verify_clearsign (cdk_ctx_t hd, const char *file, const char *output) { nbytes = _cdk_stream_gets (inp, buf, DIM (buf) - 1); if (!nbytes || nbytes == -1) - break; - if (nbytes == 1) /* Empty line */ - break; + break; + if (nbytes == 1) /* Empty line */ + break; else if (!strncmp (buf, "Hash: ", 6)) - { - for (i = 0; digest_table[i].name; i++) - { - if (!strcmp (buf + 6, digest_table[i].name)) - { - digest_algo = digest_table[i].algo; - break; - } - } - } + { + for (i = 0; digest_table[i].name; i++) + { + if (!strcmp (buf + 6, digest_table[i].name)) + { + digest_algo = digest_table[i].algo; + break; + } + } + } } if (digest_algo && _gnutls_hash_get_algo_len (digest_algo) <= 0) @@ -255,27 +255,27 @@ file_verify_clearsign (cdk_ctx_t hd, const char *file, const char *output) { nbytes = _cdk_stream_gets (inp, buf, DIM (buf) - 1); if (!nbytes || nbytes == -1) - break; + break; if (!strncmp (buf, s, strlen (s))) - break; + break; else - { - cdk_stream_peek (inp, (byte *) chk, DIM (chk) - 1); - i = strncmp (chk, s, strlen (s)); - if (strlen (buf) == 0 && i == 0) - continue; /* skip last '\n' */ - _cdk_trim_string (buf, i == 0 ? 0 : 1); - _gnutls_hash (&md, buf, strlen (buf)); - } - if (!strncmp (buf, "- ", 2)) /* FIXME: handle it recursive. */ - memmove (buf, buf + 2, nbytes - 2); + { + cdk_stream_peek (inp, (byte *) chk, DIM (chk) - 1); + i = strncmp (chk, s, strlen (s)); + if (strlen (buf) == 0 && i == 0) + continue; /* skip last '\n' */ + _cdk_trim_string (buf, i == 0 ? 0 : 1); + _gnutls_hash (&md, buf, strlen (buf)); + } + if (!strncmp (buf, "- ", 2)) /* FIXME: handle it recursive. */ + memmove (buf, buf + 2, nbytes - 2); if (out) - { - if (strstr (buf, "\r\n")) - buf[strlen (buf) - 2] = '\0'; - cdk_stream_write (out, buf, strlen (buf)); - _cdk_stream_puts (out, _cdk_armor_get_lineend ()); - } + { + if (strstr (buf, "\r\n")) + buf[strlen (buf) - 2] = '\0'; + cdk_stream_write (out, buf, strlen (buf)); + _cdk_stream_puts (out, _cdk_armor_get_lineend ()); + } } /* We create a temporary stream object to store the @@ -290,12 +290,12 @@ file_verify_clearsign (cdk_ctx_t hd, const char *file, const char *output) { nbytes = _cdk_stream_gets (inp, buf, DIM (buf) - 1); if (!nbytes || nbytes == -1) - break; + break; if (nbytes < (int) (DIM (buf) - 3)) - { - buf[nbytes - 1] = '\n'; - buf[nbytes] = '\0'; - } + { + buf[nbytes - 1] = '\n'; + buf[nbytes] = '\0'; + } cdk_stream_write (tmp, buf, nbytes); } diff --git a/lib/opencdk/write-packet.c b/lib/opencdk/write-packet.c index 265c40ddcb..12f432eb05 100644 --- a/lib/opencdk/write-packet.c +++ b/lib/opencdk/write-packet.c @@ -137,7 +137,7 @@ write_mpibuf (cdk_stream_t out, bigint_t mpi[MAX_CDK_PK_PARTS], size_t count) { rc = write_mpi (out, mpi[i]); if (rc) - return rc; + return rc; } return 0; } @@ -163,13 +163,13 @@ pkt_encode_len (cdk_stream_t out, size_t pktlen) pktlen -= 192; rc = stream_putc (out, (pktlen / 256) + 192); if (!rc) - rc = stream_putc (out, (pktlen % 256)); + rc = stream_putc (out, (pktlen % 256)); } else { rc = stream_putc (out, 255); if (!rc) - rc = write_32 (out, pktlen); + rc = write_32 (out, pktlen); } return rc; @@ -217,11 +217,11 @@ write_head_old (cdk_stream_t out, size_t size, int type) if (!rc) { if (size < 256) - rc = stream_putc (out, size); + rc = stream_putc (out, size); else if (size < 65536) - rc = write_16 (out, size); + rc = write_16 (out, size); else - rc = write_32 (out, size); + rc = write_32 (out, size); } return rc; @@ -301,7 +301,7 @@ write_mdc (cdk_stream_t out, cdk_pkt_mdc_t mdc) _gnutls_write_log ("write_mdc:\n"); /* This packet requires a fixed header encoding */ - rc = stream_putc (out, 0xD3); /* packet ID and 1 byte length */ + rc = stream_putc (out, 0xD3); /* packet ID and 1 byte length */ if (!rc) rc = stream_putc (out, 0x14); if (!rc) @@ -399,7 +399,7 @@ write_signature (cdk_stream_t out, cdk_pkt_signature_t sig, int old_ctb) { buf = _cdk_subpkt_get_array (sig->hashed, 0, &nbytes); if (!buf) - return CDK_Out_Of_Core; + return CDK_Out_Of_Core; rc = stream_write (out, buf, nbytes); cdk_free (buf); } @@ -409,7 +409,7 @@ write_signature (cdk_stream_t out, cdk_pkt_signature_t sig, int old_ctb) { buf = _cdk_subpkt_get_array (sig->unhashed, 0, &nbytes); if (!buf) - return CDK_Out_Of_Core; + return CDK_Out_Of_Core; rc = stream_write (out, buf, nbytes); cdk_free (buf); } @@ -425,7 +425,7 @@ write_signature (cdk_stream_t out, cdk_pkt_signature_t sig, int old_ctb) static cdk_error_t write_public_key (cdk_stream_t out, cdk_pkt_pubkey_t pk, - int is_subkey, int old_ctb) + int is_subkey, int old_ctb) { int pkttype, ndays = 0; size_t npkey = 0, size = 6; @@ -445,7 +445,7 @@ write_public_key (cdk_stream_t out, cdk_pkt_pubkey_t pk, if (!npkey) return CDK_Inv_Algo; if (pk->version < 4) - size += 2; /* expire date */ + size += 2; /* expire date */ if (is_subkey) old_ctb = 0; size += calc_mpisize (pk->mpi, npkey); @@ -460,7 +460,7 @@ write_public_key (cdk_stream_t out, cdk_pkt_pubkey_t pk, if (!rc && pk->version < 4) { if (pk->expiredate) - ndays = (u16) ((pk->expiredate - pk->timestamp) / 86400L); + ndays = (u16) ((pk->expiredate - pk->timestamp) / 86400L); rc = write_16 (out, ndays); } if (!rc) @@ -491,14 +491,14 @@ calc_s2ksize (cdk_pkt_seckey_t sk) break; } nbytes += sk->protect.ivlen; - nbytes++; /* single cipher byte */ + nbytes++; /* single cipher byte */ return nbytes; } static cdk_error_t write_secret_key (cdk_stream_t out, cdk_pkt_seckey_t sk, - int is_subkey, int old_ctb) + int is_subkey, int old_ctb) { cdk_pkt_pubkey_t pk = NULL; size_t size = 6, npkey, nskey; @@ -536,16 +536,16 @@ write_secret_key (cdk_stream_t out, cdk_pkt_seckey_t sk, if (sk->version == 3 || !sk->is_protected) { if (sk->version == 3) - { - size += 2; /* force simple checksum */ - sk->protect.sha1chk = 0; - } + { + size += 2; /* force simple checksum */ + sk->protect.sha1chk = 0; + } else - size += sk->protect.sha1chk ? 20 : 2; + size += sk->protect.sha1chk ? 20 : 2; size += calc_mpisize (sk->mpi, nskey); } - else /* We do not know anything about the encrypted mpi's so we - treat the data as opaque. */ + else /* We do not know anything about the encrypted mpi's so we + treat the data as opaque. */ size += sk->enclen; pkttype = is_subkey ? CDK_PKT_SECRET_SUBKEY : CDK_PKT_SECRET_KEY; @@ -558,7 +558,7 @@ write_secret_key (cdk_stream_t out, cdk_pkt_seckey_t sk, { u16 ndays = 0; if (pk->expiredate) - ndays = (u16) ((pk->expiredate - pk->timestamp) / 86400L); + ndays = (u16) ((pk->expiredate - pk->timestamp) / 86400L); rc = write_16 (out, ndays); } if (!rc) @@ -570,50 +570,50 @@ write_secret_key (cdk_stream_t out, cdk_pkt_seckey_t sk, if (!rc) { if (sk->is_protected == 0) - rc = stream_putc (out, 0x00); + rc = stream_putc (out, 0x00); else - { - if (is_RSA (pk->pubkey_algo) && pk->version < 4) - rc = stream_putc (out, _gnutls_cipher_to_pgp (sk->protect.algo)); - else if (sk->protect.s2k) - { - s2k_mode = sk->protect.s2k->mode; - rc = stream_putc (out, sk->protect.sha1chk ? 0xFE : 0xFF); - if (!rc) - rc = - stream_putc (out, _gnutls_cipher_to_pgp (sk->protect.algo)); - if (!rc) - rc = stream_putc (out, sk->protect.s2k->mode); - if (!rc) - rc = stream_putc (out, sk->protect.s2k->hash_algo); - if (!rc && (s2k_mode == 1 || s2k_mode == 3)) - { - rc = stream_write (out, sk->protect.s2k->salt, 8); - if (!rc && s2k_mode == 3) - rc = stream_putc (out, sk->protect.s2k->count); - } - } - else - return CDK_Inv_Value; - if (!rc) - rc = stream_write (out, sk->protect.iv, sk->protect.ivlen); - } + { + if (is_RSA (pk->pubkey_algo) && pk->version < 4) + rc = stream_putc (out, _gnutls_cipher_to_pgp (sk->protect.algo)); + else if (sk->protect.s2k) + { + s2k_mode = sk->protect.s2k->mode; + rc = stream_putc (out, sk->protect.sha1chk ? 0xFE : 0xFF); + if (!rc) + rc = + stream_putc (out, _gnutls_cipher_to_pgp (sk->protect.algo)); + if (!rc) + rc = stream_putc (out, sk->protect.s2k->mode); + if (!rc) + rc = stream_putc (out, sk->protect.s2k->hash_algo); + if (!rc && (s2k_mode == 1 || s2k_mode == 3)) + { + rc = stream_write (out, sk->protect.s2k->salt, 8); + if (!rc && s2k_mode == 3) + rc = stream_putc (out, sk->protect.s2k->count); + } + } + else + return CDK_Inv_Value; + if (!rc) + rc = stream_write (out, sk->protect.iv, sk->protect.ivlen); + } } if (!rc && sk->is_protected && pk->version == 4) { if (sk->encdata && sk->enclen) - rc = stream_write (out, sk->encdata, sk->enclen); + rc = stream_write (out, sk->encdata, sk->enclen); } else { if (!rc) - rc = write_mpibuf (out, sk->mpi, nskey); + rc = write_mpibuf (out, sk->mpi, nskey); if (!rc) - { - if (!sk->csum) - sk->csum = _cdk_sk_get_csum (sk); - rc = write_16 (out, sk->csum); - } + { + if (!sk->csum) + sk->csum = _cdk_sk_get_csum (sk); + rc = write_16 (out, sk->csum); + } } return rc; @@ -680,7 +680,7 @@ write_literal (cdk_stream_t out, cdk_pkt_literal_t pt, int old_ctb) { rc = stream_read (pt->buf, buf, DIM (buf), &size); if (!rc) - rc = stream_write (out, buf, size); + rc = stream_write (out, buf, size); } wipemem (buf, sizeof (buf)); @@ -723,7 +723,7 @@ write_onepass_sig (cdk_stream_t out, cdk_pkt_onepass_sig_t sig) static cdk_error_t write_user_id (cdk_stream_t out, cdk_pkt_userid_t id, int old_ctb, - int pkttype) + int pkttype) { cdk_error_t rc; @@ -733,11 +733,11 @@ write_user_id (cdk_stream_t out, cdk_pkt_userid_t id, int old_ctb, if (pkttype == CDK_PKT_ATTRIBUTE) { if (!id->attrib_img) - return CDK_Inv_Value; + return CDK_Inv_Value; rc = - pkt_write_head (out, old_ctb, id->attrib_len + 6, CDK_PKT_ATTRIBUTE); + pkt_write_head (out, old_ctb, id->attrib_len + 6, CDK_PKT_ATTRIBUTE); if (rc) - return rc; + return rc; /* Write subpacket part. */ stream_putc (out, 255); write_32 (out, id->attrib_len + 1); @@ -747,10 +747,10 @@ write_user_id (cdk_stream_t out, cdk_pkt_userid_t id, int old_ctb, else { if (!id->name) - return CDK_Inv_Value; + return CDK_Inv_Value; rc = pkt_write_head (out, old_ctb, id->len, CDK_PKT_USER_ID); if (!rc) - rc = stream_write (out, id->name, id->len); + rc = stream_write (out, id->name, id->len); } return rc; |