[svn] GnuPG - r4796 - in trunk: . common jnlib scd sm
svn author wk
cvs at cvs.gnupg.org
Thu Jun 26 21:09:10 CEST 2008
Author: wk
Date: 2008-06-26 21:09:07 +0200 (Thu, 26 Jun 2008)
New Revision: 4796
Modified:
trunk/NEWS
trunk/TODO
trunk/common/ChangeLog
trunk/common/estream.c
trunk/jnlib/ChangeLog
trunk/jnlib/stringhelp.c
trunk/scd/ChangeLog
trunk/scd/app-dinsig.c
trunk/sm/ChangeLog
trunk/sm/gpgsm.c
trunk/sm/gpgsm.h
trunk/sm/keylist.c
trunk/sm/qualified.c
trunk/sm/sign.c
Log:
Start support of TCOS 3 cards.
Support restriction attribute.
Fix utf-8 printing problems.
Use AES by default.
[The diff below has been truncated]
Modified: trunk/common/ChangeLog
===================================================================
--- trunk/common/ChangeLog 2008-06-25 17:44:26 UTC (rev 4795)
+++ trunk/common/ChangeLog 2008-06-26 19:09:07 UTC (rev 4796)
@@ -1,3 +1,9 @@
+2008-06-26 Werner Koch <wk at g10code.com>
+
+ * estream.c (es_write_sanitized): Loose check for control
+ characters to better cope with utf-8. The range 0x80..0x9f is
+ nowadays not anymore accidently used for control charaters.
+
2008-06-25 Marcus Brinkmann <marcus at g10code.de>
Revert last three changes related to handle translation.
Modified: trunk/jnlib/ChangeLog
===================================================================
--- trunk/jnlib/ChangeLog 2008-06-25 17:44:26 UTC (rev 4795)
+++ trunk/jnlib/ChangeLog 2008-06-26 19:09:07 UTC (rev 4796)
@@ -1,3 +1,9 @@
+2008-06-26 Werner Koch <wk at g10code.com>
+
+ * stringhelp.c (print_sanitized_buffer2): Loose check for control
+ characters to better cope with utf-8. The range 0x80..0x9f is
+ nowadays not anymore accidently used for control charaters.
+
2008-06-13 Werner Koch <wk at g10code.com>
* dotlock.c: Reformat code and implement locking for W32.
Modified: trunk/scd/ChangeLog
===================================================================
--- trunk/scd/ChangeLog 2008-06-25 17:44:26 UTC (rev 4795)
+++ trunk/scd/ChangeLog 2008-06-26 19:09:07 UTC (rev 4796)
@@ -1,3 +1,7 @@
+2008-06-25 Werner Koch <wk at g10code.com>
+
+ * app-dinsig.c (do_sign): Allow for SHA256.
+
2008-06-24 Werner Koch <wk at g10code.com>
* app-common.h (app_ctx_s): Renamed reset_mode parameter of
Modified: trunk/sm/ChangeLog
===================================================================
--- trunk/sm/ChangeLog 2008-06-25 17:44:26 UTC (rev 4795)
+++ trunk/sm/ChangeLog 2008-06-26 19:09:07 UTC (rev 4796)
@@ -1,3 +1,16 @@
+2008-06-25 Werner Koch <wk at g10code.com>
+
+ * sign.c (gpgsm_sign): Revamp the hash algorithm selection.
+ * gpgsm.h (struct certlist_s): Add field HASH_ALGO and HASH_ALGO_OID.
+
+ * qualified.c (gpgsm_qualified_consent): Fix double free.
+
+ * gpgsm.c (main): Change default cipher algo to AES.
+
+ * keylist.c (print_utf8_extn_raw, print_utf8_extn): New.
+ (list_cert_raw, list_cert_std): Print the TeleSec restriction
+ extension.
+
2008-06-23 Werner Koch <wk at g10code.com>
* encrypt.c (encode_session_key): Replace xmalloc by xtrymalloc.
Modified: trunk/NEWS
===================================================================
--- trunk/NEWS 2008-06-25 17:44:26 UTC (rev 4795)
+++ trunk/NEWS 2008-06-26 19:09:07 UTC (rev 4796)
@@ -25,7 +25,9 @@
* New control statement %ask-passphrase for the unattended key
generation of gpg2.
+ * gpgsm now uses AES by default.
+
Noteworthy changes in version 2.0.9 (2008-03-26)
------------------------------------------------
Modified: trunk/TODO
===================================================================
--- trunk/TODO 2008-06-25 17:44:26 UTC (rev 4795)
+++ trunk/TODO 2008-06-26 19:09:07 UTC (rev 4796)
@@ -66,7 +66,8 @@
We should check the card status in open-card to make this smoother.
Needs to be integrated with the status file update, though. It is
not a real problem because application will get a card removed
- status and should the send a reset to try solving the problem.
+ status and should then send a reset to try solving the problem.
+** Resolve fixme in do_sign of app-dinsig.
** Add a regression test to check the extkeyusage.
Modified: trunk/common/estream.c
===================================================================
--- trunk/common/estream.c 2008-06-25 17:44:26 UTC (rev 4795)
+++ trunk/common/estream.c 2008-06-26 19:09:07 UTC (rev 4796)
@@ -3074,7 +3074,7 @@
for (; length; length--, p++, count++)
{
if (*p < 0x20
- || (*p >= 0x7f && *p < 0xa0)
+ || *p == 0x7f
|| (delimiters
&& (strchr (delimiters, *p) || *p == '\\')))
{
Modified: trunk/jnlib/stringhelp.c
===================================================================
--- trunk/jnlib/stringhelp.c 2008-06-25 17:44:26 UTC (rev 4795)
+++ trunk/jnlib/stringhelp.c 2008-06-26 19:09:07 UTC (rev 4796)
@@ -406,9 +406,8 @@
for (; length; length--, p++, count++)
{
- /* Fixme: Check whether *p < 0xa0 is correct for utf8 encoding. */
if (*p < 0x20
- || (*p >= 0x7f && *p < 0xa0)
+ || *p == 0x7f
|| *p == delim
|| *p == delim2
|| ((delim || delim2) && *p=='\\'))
Modified: trunk/scd/app-dinsig.c
===================================================================
--- trunk/scd/app-dinsig.c 2008-06-25 17:44:26 UTC (rev 4795)
+++ trunk/scd/app-dinsig.c 2008-06-26 19:09:07 UTC (rev 4796)
@@ -1,5 +1,5 @@
/* app-dinsig.c - The DINSIG (DIN V 66291-1) card application.
- * Copyright (C) 2002, 2004, 2005, 2007 Free Software Foundation, Inc.
+ * Copyright (C) 2002, 2004, 2005, 2007, 2008 Free Software Foundation, Inc.
*
* This file is part of GnuPG.
*
@@ -397,14 +397,20 @@
static unsigned char rmd160_prefix[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 };
+ static unsigned char sha256_prefix[19] = /* OID 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 };
int rc;
int fid;
- unsigned char data[35]; /* Must be large enough for a SHA-1 digest
- + the largest OID _prefix above. */
+ unsigned char data[19+32]; /* Must be large enough for a SHA-256 digest
+ + the largest OID _prefix above. */
+ int datalen;
if (!keyidstr || !*keyidstr)
return gpg_error (GPG_ERR_INV_VALUE);
- if (indatalen != 20 && indatalen != 16 && indatalen != 35)
+ if (indatalen != 20 && indatalen != 16 && indatalen != 32
+ && indatalen != (15+20) && indatalen != (19+32))
return gpg_error (GPG_ERR_INV_VALUE);
/* Check that the provided ID is vaid. This is not really needed
@@ -421,7 +427,8 @@
return gpg_error (GPG_ERR_NOT_FOUND);
/* Prepare the DER object from INDATA. */
- if (indatalen == 35)
+ datalen = 35;
+ if (indatalen == 15+20)
{
/* Alright, the caller was so kind to send us an already
prepared DER object. Check that it is what we want and that
@@ -434,25 +441,104 @@
return gpg_error (GPG_ERR_UNSUPPORTED_ALGORITHM);
memcpy (data, indata, indatalen);
}
+ else if (indatalen == 19+32)
+ {
+ /* Alright, the caller was so kind to send us an already
+ prepared DER object. Check that it is what we want and that
+ it matches the hash algorithm. */
+ datalen = indatalen;
+ if (hashalgo == GCRY_MD_SHA256 && !memcmp (indata, sha256_prefix, 19))
+ ;
+ else if (hashalgo == GCRY_MD_SHA1 && !memcmp (indata, sha256_prefix, 19))
+ {
+ /* Fixme: This is a kludge. A better solution is not to use
+ SHA1 as default but use an autodetection. However this
+ needs changes in all app-*.c */
+ hashalgo = GCRY_MD_SHA256;
+ datalen = indatalen;
+ }
+ else
+ return gpg_error (GPG_ERR_UNSUPPORTED_ALGORITHM);
+ memcpy (data, indata, indatalen);
+ }
else
{
+ int len = 15;
if (hashalgo == GCRY_MD_SHA1)
- memcpy (data, sha1_prefix, 15);
+ memcpy (data, sha1_prefix, len);
else if (hashalgo == GCRY_MD_RMD160)
- memcpy (data, rmd160_prefix, 15);
+ memcpy (data, rmd160_prefix, len);
+ else if (hashalgo == GCRY_MD_SHA256)
+ {
+ len = 19;
+ datalen = len + indatalen;
+ memcpy (data, sha256_prefix, len);
+ }
else
return gpg_error (GPG_ERR_UNSUPPORTED_ALGORITHM);
- memcpy (data+15, indata, indatalen);
+ memcpy (data+len, indata, indatalen);
}
rc = verify_pin (app, pincb, pincb_arg);
if (!rc)
- rc = iso7816_compute_ds (app->slot, data, 35, outdata, outdatalen);
+ rc = iso7816_compute_ds (app->slot, data, datalen, outdata, outdatalen);
return rc;
}
+#if 0
+#warning test function - works but may brick your card
+/* Handle the PASSWD command. CHVNOSTR is currently ignored; we
+ always use VHV0. RESET_MODE is not yet implemented. */
+static gpg_error_t
+do_change_pin (app_t app, ctrl_t ctrl, const char *chvnostr,
+ unsigned int flags,
+ gpg_error_t (*pincb)(void*, const char *, char **),
+ void *pincb_arg)
+{
+ gpg_error_t err;
+ char *pinvalue;
+ const char *oldpin;
+ size_t oldpinlen;
+ if ((flags & APP_CHANGE_FLAG_RESET))
+ return gpg_error (GPG_ERR_NOT_IMPLEMENTED);
+
+ if ((flags & APP_CHANGE_FLAG_NULLPIN))
+ {
+ /* With the nullpin flag, we do not verify the PIN - it would fail
+ if the Nullpin is still set. */
+ oldpin = "\0\0\0\0\0";
+ oldpinlen = 6;
+ }
+ else
+ {
+ err = verify_pin (app, pincb, pincb_arg);
+ if (err)
+ return err;
+ oldpin = NULL;
+ oldpinlen = 0;
+ }
+
+ /* TRANSLATORS: Do not translate the "|*|" prefixes but
+ keep it at the start of the string. We need this elsewhere
+ to get some infos on the string. */
+ err = pincb (pincb_arg, _("|N|Initial New PIN"), &pinvalue);
+ if (err)
+ {
+ log_error (_("error getting new PIN: %s\n"), gpg_strerror (err));
+ return err;
+ }
+
+ err = iso7816_change_reference_data (app->slot, 0x81,
+ oldpin, oldpinlen,
+ pinvalue, strlen (pinvalue));
+ xfree (pinvalue);
+ return err;
+}
+
+
+
/* Select the DINSIG application on the card in SLOT. This function
must be used before any other DINSIG application functions. */
gpg_error_t
@@ -475,7 +561,7 @@
app->fnc.sign = do_sign;
app->fnc.auth = NULL;
app->fnc.decipher = NULL;
- app->fnc.change_pin = NULL;
+ app->fnc.change_pin = NULL /*do_change_pin*/;
app->fnc.check_pin = NULL;
app->force_chv1 = 1;
Modified: trunk/sm/gpgsm.c
===================================================================
--- trunk/sm/gpgsm.c 2008-06-25 17:44:26 UTC (rev 4795)
+++ trunk/sm/gpgsm.c 2008-06-26 19:09:07 UTC (rev 4796)
@@ -987,7 +987,7 @@
create_dotlock (NULL); /* register locking cleanup */
i18n_init();
- opt.def_cipher_algoid = "3DES"; /*des-EDE3-CBC*/
+ opt.def_cipher_algoid = "AES"; /*des-EDE3-CBC*/
opt.homedir = default_homedir ();
Modified: trunk/sm/gpgsm.h
===================================================================
--- trunk/sm/gpgsm.h 2008-06-25 17:44:26 UTC (rev 4795)
+++ trunk/sm/gpgsm.h 2008-06-26 19:09:07 UTC (rev 4796)
@@ -207,6 +207,8 @@
ksba_cert_t cert;
int is_encrypt_to; /* True if the certificate has been set through
the --encrypto-to option. */
+ int hash_algo; /* Used to track the hash algorithm to use. */
+ const char *hash_algo_oid; /* And the corresponding OID. */
};
typedef struct certlist_s *certlist_t;
Modified: trunk/sm/keylist.c
===================================================================
--- trunk/sm/keylist.c 2008-06-25 17:44:26 UTC (rev 4795)
+++ trunk/sm/keylist.c 2008-06-26 19:09:07 UTC (rev 4796)
@@ -1,6 +1,6 @@
/* keylist.c - Print certificates in various formats.
* Copyright (C) 1998, 1999, 2000, 2001, 2003,
- * 2004, 2005 Free Software Foundation, Inc.
+ * 2004, 2005, 2008 Free Software Foundation, Inc.
*
* This file is part of GnuPG.
*
@@ -35,6 +35,7 @@
#include "keydb.h"
#include "../kbx/keybox.h" /* for KEYBOX_FLAG_* */
#include "i18n.h"
+#include "tlv.h"
struct list_external_parm_s
{
@@ -77,12 +78,18 @@
};
+/* Do not print this extension in the list of extensions. This is set
+ for oids which are already available via ksba fucntions. */
+#define OID_FLAG_SKIP 1
+/* The extension is a simple UTF8String and should be printed. */
+#define OID_FLAG_UTF8 2
+
/* A table mapping OIDs to a descriptive string. */
static struct
{
char *oid;
char *name;
- unsigned int flag;
+ unsigned int flag; /* A flag as described above. */
} oidtranstbl[] = {
/* Algorithms. */
@@ -115,7 +122,11 @@
{ "0.2.262.1.10.12.4", "telesecCRLFilteredExt" },
{ "0.2.262.1.10.12.5", "telesecCRLFilterExt"},
{ "0.2.262.1.10.12.6", "telesecNamingAuthorityExt" },
+#define OIDSTR_restriction \
+ "1.3.36.8.3.8"
+ { OIDSTR_restriction, "restriction", OID_FLAG_UTF8 },
+
/* PKIX private extensions. */
{ "1.3.6.1.5.5.7.1.1", "authorityInfoAccess" },
{ "1.3.6.1.5.5.7.1.2", "biometricInfo" },
@@ -135,12 +146,12 @@
{ "1.3.6.1.5.5.7.48.5", "caRepository" },
/* X.509 id-ce */
- { "2.5.29.14", "subjectKeyIdentifier", 1},
- { "2.5.29.15", "keyUsage", 1 },
+ { "2.5.29.14", "subjectKeyIdentifier", OID_FLAG_SKIP},
+ { "2.5.29.15", "keyUsage", OID_FLAG_SKIP},
{ "2.5.29.16", "privateKeyUsagePeriod" },
- { "2.5.29.17", "subjectAltName", 1 },
- { "2.5.29.18", "issuerAltName", 1 },
- { "2.5.29.19", "basicConstraints", 1},
+ { "2.5.29.17", "subjectAltName", OID_FLAG_SKIP},
+ { "2.5.29.18", "issuerAltName", OID_FLAG_SKIP},
+ { "2.5.29.19", "basicConstraints", OID_FLAG_SKIP},
{ "2.5.29.20", "cRLNumber" },
{ "2.5.29.21", "cRLReason" },
{ "2.5.29.22", "expirationDate" },
@@ -150,13 +161,13 @@
{ "2.5.29.28", "issuingDistributionPoint" },
{ "2.5.29.29", "certificateIssuer" },
{ "2.5.29.30", "nameConstraints" },
- { "2.5.29.31", "cRLDistributionPoints", 1 },
- { "2.5.29.32", "certificatePolicies", 1 },
+ { "2.5.29.31", "cRLDistributionPoints", OID_FLAG_SKIP},
+ { "2.5.29.32", "certificatePolicies", OID_FLAG_SKIP},
{ "2.5.29.32.0", "anyPolicy" },
{ "2.5.29.33", "policyMappings" },
- { "2.5.29.35", "authorityKeyIdentifier", 1 },
+ { "2.5.29.35", "authorityKeyIdentifier", OID_FLAG_SKIP},
{ "2.5.29.36", "policyConstraints" },
- { "2.5.29.37", "extKeyUsage", 1 },
+ { "2.5.29.37", "extKeyUsage", OID_FLAG_SKIP},
{ "2.5.29.46", "freshestCRL" },
{ "2.5.29.54", "inhibitAnyPolicy" },
@@ -561,6 +572,59 @@
}
+static void
+print_utf8_extn_raw (estream_t fp, int indent,
+ const unsigned char *der, size_t derlen)
+{
+ gpg_error_t err;
+ int class, tag, constructed, ndef;
+ size_t objlen, hdrlen;
+
+ if (indent < 0)
+ indent = - indent;
+
+ err = parse_ber_header (&der, &derlen, &class, &tag, &constructed,
+ &ndef, &objlen, &hdrlen);
+ if (!err && (objlen > derlen || tag != TAG_UTF8_STRING))
+ err = gpg_error (GPG_ERR_INV_OBJ);
+ if (err)
+ {
+ es_fprintf (fp, "%*s[%s]\n", indent, "", gpg_strerror (err));
+ return;
+ }
+ es_fprintf (fp, "%*s(%.*s)\n", indent, "", objlen, der);
+}
+
+
+static void
+print_utf8_extn (estream_t fp, int indent,
+ const unsigned char *der, size_t derlen)
+{
+ gpg_error_t err;
+ int class, tag, constructed, ndef;
+ size_t objlen, hdrlen;
+ int indent_all;
+
+ if ((indent_all = (indent < 0)))
+ indent = - indent;
+
+ err = parse_ber_header (&der, &derlen, &class, &tag, &constructed,
+ &ndef, &objlen, &hdrlen);
+ if (!err && (objlen > derlen || tag != TAG_UTF8_STRING))
+ err = gpg_error (GPG_ERR_INV_OBJ);
+ if (err)
+ {
+ es_fprintf (fp, "%*s[Error - %s]\n",
+ indent_all? indent:0, "", gpg_strerror (err));
+ return;
+ }
+ es_fprintf (fp, "%*s\"", indent_all? indent:0, "");
+ /* Fixme: we should implement word wrapping */
+ es_write_sanitized (fp, der, objlen, "\"", NULL);
+ es_fputs ("\"\n", fp);
+}
+
+
/* List one certificate in raw mode useful to have a closer look at
the certificate. This one does no beautification and only minimal
output sanitation. It is mainly useful for debugging. */
@@ -581,6 +645,7 @@
const char *oid, *s;
ksba_name_t name, name2;
unsigned int reason;
+ const unsigned char *cert_der = NULL;
es_fprintf (fp, " ID: 0x%08lX\n",
gpgsm_get_short_fingerprint (cert));
@@ -892,11 +957,19 @@
unsigned int flag;
s = get_oid_desc (oid, &flag);
+ if ((flag & OID_FLAG_SKIP))
+ continue;
- if (!(flag & 1))
- es_fprintf (fp, " %s: %s%s%s%s [%d octets]\n",
- i? "critExtn":" extn",
- oid, s?" (":"", s?s:"", s?")":"", (int)len);
+ es_fprintf (fp, " %s: %s%s%s%s [%d octets]\n",
+ i? "critExtn":" extn",
+ oid, s?" (":"", s?s:"", s?")":"", (int)len);
+ if ((flag & OID_FLAG_UTF8))
+ {
+ if (!cert_der)
+ cert_der = ksba_cert_get_image (cert, NULL);
+ assert (cert_der);
+ print_utf8_extn_raw (fp, -15, cert_der+off, len);
+ }
}
@@ -938,7 +1011,11 @@
int is_ca, chainlen;
unsigned int kusage;
char *string, *p, *pend;
+ size_t off, len;
+ const char *oid;
+ const unsigned char *cert_der = NULL;
+
es_fprintf (fp, " ID: 0x%08lX\n",
gpgsm_get_short_fingerprint (cert));
@@ -1053,6 +1130,21 @@
es_putc ('\n', fp);
}
+ /* Print restrictions. */
+ for (idx=0; !(err=ksba_cert_get_extension (cert, idx,
+ &oid, NULL, &off, &len));idx++)
+ {
+ if (!strcmp (oid, OIDSTR_restriction) )
+ {
+ if (!cert_der)
+ cert_der = ksba_cert_get_image (cert, NULL);
+ assert (cert_der);
+ es_fputs (" restriction: ", fp);
+ print_utf8_extn (fp, 15, cert_der+off, len);
+ }
+ }
+
+ /* Print policies. */
err = ksba_cert_get_cert_policies (cert, &string);
if (gpg_err_code (err) != GPG_ERR_NO_DATA)
{
Modified: trunk/sm/qualified.c
===================================================================
--- trunk/sm/qualified.c 2008-06-25 17:44:26 UTC (rev 4795)
+++ trunk/sm/qualified.c 2008-06-26 19:09:07 UTC (rev 4796)
@@ -215,7 +215,6 @@
err = 0;
i18n_switchback (orig_codeset);
- xfree (orig_codeset);
xfree (subject);
if (err)
Modified: trunk/sm/sign.c
===================================================================
--- trunk/sm/sign.c 2008-06-25 17:44:26 UTC (rev 4795)
+++ trunk/sm/sign.c 2008-06-26 19:09:07 UTC (rev 4796)
@@ -1,5 +1,5 @@
/* sign.c - Sign a message
- * Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
+ * Copyright (C) 2001, 2002, 2003, 2008 Free Software Foundation, Inc.
*
* This file is part of GnuPG.
*
@@ -396,7 +396,45 @@
release_signerlist = 1;
}
+ /* Figure out the hash algorithm to use. We do not want to use the
+ one for the certificate but if possible an OID for the plain
+ algorithm. */
+ for (i=0, cl=signerlist; cl; cl = cl->next, i++)
+ {
More information about the Gnupg-commits
mailing list