Makefile.am | 2 +- cipher/rsa.c | 58 +++++++++++++++++++++++++++++++++++++++++++++------ configure.ac | 4 +-- doc/gnupg1.texi | 2 +- doc/gpg.texi | 3 ++ g10/gpg.c | 9 +++++++- g10/options.skel | 37 +++++++++++--------------------- g10/trustdb.c | 3 ++ po/ru.po | 60 ++++++++++++++++++++++++++--------------------------- util/strgutil.c | 26 +++++++++++++++++++++++ 10 files changed, 136 insertions(+), 68 deletions(-) diff --git a/Makefile.am b/Makefile.am index 00f2fa0..d1cd847 100644 --- a/Makefile.am +++ b/Makefile.am @@ -27,7 +27,7 @@ else checks = checks endif -SUBDIRS = m4 intl zlib util mpi cipher tools g10 keyserver po doc ${checks} +SUBDIRS = m4 util mpi cipher tools g10 keyserver po doc ${checks} EXTRA_DIST = scripts/config.rpath PROJECTS BUGS config.h.in autogen.sh DISTCLEANFILES = diff --git a/cipher/rsa.c b/cipher/rsa.c index 1cdc600..f0d9f69 100644 --- a/cipher/rsa.c +++ b/cipher/rsa.c @@ -188,19 +188,54 @@ generate( RSA_secret_key *sk, unsigned nbits ) /**************** - * Test wether the secret key is valid. - * Returns: true if this is a valid key. + * Test whether the secret key is valid. + * Returns: nonzero if this is a valid key. */ static int check_secret_key( RSA_secret_key *sk ) { - int rc; - MPI temp = mpi_alloc( mpi_get_nlimbs(sk->p)*2 ); - + int rc = 0; + MPI temp = mpi_alloc_secure ( mpi_get_nlimbs(sk->p) + mpi_get_nlimbs(sk->q) ); + MPI p_1 = mpi_copy (sk->p); /* (p-1) */ + MPI q_1 = mpi_copy (sk->p); /* (q-1) */ + MPI p_1_q_1 = mpi_alloc_secure ( mpi_get_nlimbs(sk->p) + mpi_get_nlimbs(sk->q) ); /* (p-1)(q-1) */ + + /* Calculate (p-1)(q-1). */ + mpi_sub_ui(p_1, p_1, 1); + mpi_sub_ui(q_1, q_1, 1); + mpi_mul(p_1_q_1, p_1, q_1); + + /* Check pq = n. */ mpi_mul(temp, sk->p, sk->q ); - rc = mpi_cmp( temp, sk->n ); + if( 0 != mpi_cmp(temp, sk->n ) ) + goto end; + + /* Check gcd(e, (p-1)(q-1)) = 1. */ + if( ! mpi_gcd(temp, sk->e, p_1_q_1) ) + goto end; + + /* Check de == 1 (mod (p-1)) and (mod (q-1)), i.e. d = e^-1. */ + mpi_mulm(temp, sk->d, sk->e, p_1); + if( 0 != mpi_cmp_ui(temp, 1)) + goto end; + mpi_mulm(temp, sk->d, sk->e, q_1); + if( 0 != mpi_cmp_ui(temp, 1)) + goto end; + + /* Check up == 1 (mod q). */ + mpi_mulm(temp, sk->u, sk->p, sk->q); + if( 0 != mpi_cmp_ui(temp, 1)) + goto end; + + /* Success. Fall through to deallocation code. */ + rc = 1; + + end: mpi_free(temp); - return !rc; + mpi_free(p_1); + mpi_free(q_1); + mpi_free(p_1_q_1); + return rc; } @@ -414,6 +449,8 @@ int rsa_sign( int algo, MPI *resarr, MPI data, MPI *skey ) { RSA_secret_key sk; + RSA_public_key pk; + MPI orig = mpi_alloc( mpi_get_nlimbs( data ) ); if( algo != 1 && algo != 3 ) return G10ERR_PUBKEY_ALGO; @@ -427,6 +464,13 @@ rsa_sign( int algo, MPI *resarr, MPI data, MPI *skey ) resarr[0] = mpi_alloc( mpi_get_nlimbs( sk.n ) ); secret( resarr[0], data, &sk ); + /* Check against wrong computation. */ + pk.n = sk.n; + pk.e = sk.e; + public( orig, resarr[0], &pk); + if ( 0 != mpi_cmp( orig, data ) ) + return G10ERR_BAD_SECKEY; + return 0; } diff --git a/configure.ac b/configure.ac index 800f64d..58a1683 100644 --- a/configure.ac +++ b/configure.ac @@ -844,7 +844,7 @@ dnl Checks for libraries. AM_PO_SUBDIRS AM_GNU_GETTEXT_VERSION([0.16.1]) if test "$try_gettext" = yes; then - AM_GNU_GETTEXT(,[need-ngettext]) + AM_GNU_GETTEXT(,[need-ngettext],[external]) # gettext requires some extra checks. These really should be part of # the basic AM_GNU_GETTEXT macro. TODO: move other gettext-specific # function checks to here. @@ -1415,7 +1415,6 @@ fi AC_CONFIG_FILES([ Makefile m4/Makefile -intl/Makefile po/Makefile.in util/Makefile mpi/Makefile @@ -1427,7 +1426,6 @@ keyserver/gpgkeys_test doc/Makefile tools/Makefile tools/gpg-zip -zlib/Makefile checks/Makefile ]) AC_OUTPUT diff --git a/doc/gnupg1.texi b/doc/gnupg1.texi index 5a219b3..b87eb66 100644 --- a/doc/gnupg1.texi +++ b/doc/gnupg1.texi @@ -48,7 +48,7 @@ section entitled ``Copying''. @dircategory GNU Utilities @direntry -* gpg: (gpg). OpenPGP encryption and signing tool (v1). +* gpg: (gnupg1). OpenPGP encryption and signing tool (v1). @end direntry diff --git a/doc/gpg.texi b/doc/gpg.texi index cc048b1..a62f199 100644 --- a/doc/gpg.texi +++ b/doc/gpg.texi @@ -1161,6 +1161,9 @@ the Latin 1 set. @item koi8-r The usual Russian set (rfc1489). +@item cp1251 +The cp1251 aka windows-1251 Cyrillic set. + @item utf-8 Bypass all translations and assume that the OS uses native UTF-8 encoding. diff --git a/g10/gpg.c b/g10/gpg.c index d91f466..59c4aaf 100644 --- a/g10/gpg.c +++ b/g10/gpg.c @@ -1731,6 +1731,13 @@ reopen_std(void) if(did_stdin==2 || did_stdout==2 || did_stderr==2) exit(3); + + gid_t gid = getgid(); + if(getegid() != gid && setgid(gid)) + { + fprintf(complain,"gpg: fatal: failed to reset gid: %s\n", strerror(errno)); + exit(3); + } #endif /* HAVE_STAT && !HAVE_W32_SYSTEM */ } @@ -3346,7 +3353,7 @@ main (int argc, char **argv ) break; case aExportOwnerTrust: rc = setup_trustdb( 0, trustdb_name ); break; case aListTrustDB: rc = setup_trustdb( argc? 1:0, trustdb_name ); break; - default: rc = setup_trustdb(1, trustdb_name ); break; + default: rc = setup_trustdb( opt.trust_model != TM_ALWAYS, trustdb_name ); break; } if( rc ) log_error(_("failed to initialize the TrustDB: %s\n"), g10_errstr(rc)); diff --git a/g10/options.skel b/g10/options.skel index 954d584..db3071f 100644 --- a/g10/options.skel +++ b/g10/options.skel @@ -22,20 +22,17 @@ # # See the man page for a list of options. -# Uncomment the following option to get rid of the copyright notice - -#no-greeting +# Comment out the following option to reenable the copyright notice. +no-greeting # If you have more than 1 secret key in your keyring, you may want to # uncomment the following option and set your preferred keyid. - #default-key 621CC013 # If you do not pass a recipient to gpg, it will ask for one. Using # this option you can encrypt to a default key. Key validation will # not be done in this case. The second form uses the default key as # default recipient. - #default-recipient some-user-id #default-recipient-self @@ -44,20 +41,17 @@ # mail client that does not automatically encrypt mail to your key. # In the example, this option allows you to read your local copy of # encrypted mail that you've sent to others. - #encrypt-to some-key-id # By default GnuPG creates version 3 signatures for data files. This # is not strictly OpenPGP compliant but PGP 6 and most versions of PGP # 7 require them. To disable this behavior, you may use this option # or --openpgp. - #no-force-v3-sigs # Because some mailers change lines starting with "From " to ">From " # it is good to handle such lines in a special way when creating # cleartext signatures; all other PGP versions do it this way too. - #no-escape-from-lines # If you do not use the Latin-1 (ISO-8859-1) charset, you should tell @@ -67,7 +61,6 @@ # translation. Note that future version of GnuPG will change to UTF-8 # as default character set. In most cases this option is not required # as GnuPG is able to figure out the correct charset at runtime. - #charset utf-8 # Group names may be defined like this: @@ -79,13 +72,11 @@ # cannot make an group that points to another group. Note also that # if there are spaces in the recipient name, this will appear as two # recipients. In these cases it is better to use the key ID. - #group mynames = paige 0x12345678 joe patti # Lock the file only once for the lifetime of a process. If you do # not define this, the lock will be obtained and released every time # it is needed, which is usually preferable. - #lock-once # GnuPG can send and receive keys to and from a keyserver. These @@ -114,7 +105,6 @@ # such a "server", which spreads the load over a number of physical # servers. To see the IP address of the server actually used, you may use # the "--keyserver-options debug". - keyserver hkp://keys.gnupg.net #keyserver mailto:pgp-public-keys@keys.nl.pgp.net #keyserver ldap://keyserver.pgp.com @@ -149,17 +139,14 @@ keyserver hkp://keys.gnupg.net # # no-include-attributes : do not include attribute IDs (aka "photo IDs") # when sending keys to the keyserver. - #keyserver-options auto-key-retrieve # Display photo user IDs in key listings - -# list-options show-photos +#list-options show-photos # Display photo user IDs when a signature from a key with a photo is # verified - -# verify-options show-photos +#verify-options show-photos # Use this program to display photo user IDs # @@ -182,14 +169,14 @@ keyserver hkp://keys.gnupg.net # to use your regular JPEG image viewer. # # Some other viewers: -# photo-viewer "qiv %i" -# photo-viewer "ee %i" +#photo-viewer "qiv %i" +#photo-viewer "ee %i" # # This one saves a copy of the photo ID in your home directory: -# photo-viewer "cat > ~/photoid-for-key-%k.%t" +#photo-viewer "cat > ~/photoid-for-key-%k.%t" # # Use your MIME handler to view photos: -# photo-viewer "metamail -q -d -b -c %T -s 'KeyID 0x%k' -f GnuPG" +#photo-viewer "metamail -q -d -b -c %T -s 'KeyID 0x%k' -f GnuPG" # Passphrase agent # @@ -197,9 +184,8 @@ keyserver hkp://keys.gnupg.net # the new Assuan based one (currently available in the "newpg" package # at ftp.gnupg.org/gcrypt/alpha/aegypten/). To make use of the agent, # you have to run an agent as daemon and use the option -# -# use-agent -# +#use-agent + # which tries to use the agent but will fallback to the regular mode # if there is a problem connecting to the agent. The normal way to # locate the agent is by looking at the environment variable @@ -236,3 +222,6 @@ keyserver hkp://keys.gnupg.net # # Try CERT, then PKA, then LDAP, then hkp://subkeys.net: #auto-key-locate cert pka ldap hkp://subkeys.pgp.net + +# Comment out the next line to reenable the warning about "using insecure memory". +no-secmem-warning diff --git a/g10/trustdb.c b/g10/trustdb.c index 10f82ef..a67b285 100644 --- a/g10/trustdb.c +++ b/g10/trustdb.c @@ -1055,6 +1055,9 @@ get_validity (PKT_public_key *pk, PKT_user_id *uid) u32 kid[2]; PKT_public_key *main_pk; + if (opt.trust_model == TM_ALWAYS) + return TRUST_ULTIMATE; + if(uid) namehash_from_uid(uid); diff --git a/po/ru.po b/po/ru.po index cba666e..b203aed 100644 --- a/po/ru.po +++ b/po/ru.po @@ -31,14 +31,14 @@ msgid "no entropy gathering module detected\n" msgstr "не найден модуль накопления энтропии\n" #: cipher/random.c:401 -#, fuzzy, c-format +#, c-format msgid "can't lock `%s': %s\n" -msgstr "невозможно заблокировать `%s'\n" +msgstr "невозможно заблокировать `%s': %s\n" #: cipher/random.c:406 -#, fuzzy, c-format +#, c-format msgid "waiting for lock on `%s'...\n" -msgstr "сохранение секретного ключа в `%s'\n" +msgstr "ожидание блокировки `%s'...\n" #: cipher/random.c:446 g10/card-util.c:681 g10/card-util.c:750 #: g10/dearmor.c:59 g10/dearmor.c:108 g10/encode.c:182 g10/encode.c:472 @@ -278,12 +278,12 @@ msgstr "ключ сгенерирован (%d секунд)\n" #: g10/app-openpgp.c:1959 msgid "invalid structure of OpenPGP card (DO 0x93)\n" -msgstr "недопутимая структура OpenPGP карты (DO 0x93)\n" +msgstr "недопустимая структура OpenPGP карты (DO 0x93)\n" #: g10/app-openpgp.c:2085 -#, fuzzy, c-format +#, c-format msgid "card does not support digest algorithm %s\n" -msgstr "%s подпись, хэш-функция %s\n" +msgstr "карта не поддерживает хэш-функцию %s\n" #: g10/app-openpgp.c:2132 #, c-format @@ -449,7 +449,7 @@ msgstr "Фамилия владельца карты:" #: g10/card-util.c:545 msgid "Cardholder's given name: " -msgstr "Имя влдаельца карты:" +msgstr "Имя владельца карты:" #: g10/card-util.c:563 #, c-format @@ -635,9 +635,8 @@ msgid "change a CA fingerprint" msgstr "сменить отпечаток CA" #: g10/card-util.c:1337 -#, fuzzy msgid "toggle the signature force PIN flag" -msgstr "переключение флага force PIN" +msgstr "переключение флага signature force PIN" #: g10/card-util.c:1338 msgid "generate new keys" @@ -648,9 +647,8 @@ msgid "menu to change or unblock the PIN" msgstr "меню изменения или разблокировки PIN" #: g10/card-util.c:1340 -#, fuzzy msgid "verify the PIN and list all data" -msgstr "проверить PIN и показать все данные" +msgstr "проверить PIN и вывести перечень всех данных" #: g10/card-util.c:1460 g10/keyedit.c:1619 msgid "Command> " @@ -805,7 +803,7 @@ msgstr "ВНИМАНИЕ: `%s' пустой файл\n" #: g10/encode.c:454 msgid "you can only encrypt to RSA keys of 2048 bits or less in --pgp2 mode\n" -msgstr "в режиме --pgp2 ключ RSA для ширования должен быть не более 2048 бит\n" +msgstr "в режиме --pgp2 ключ RSA для шифрования должен быть не более 2048 бит\n" #: g10/encode.c:478 #, c-format @@ -1691,7 +1689,7 @@ msgstr "--encrypt [filename]" #: g10/gpg.c:3406 msgid "--symmetric --encrypt [filename]" -msgstr "--symmetric --encrypt [имяфайла]" +msgstr "--symmetric --encrypt [имя файла]" #: g10/gpg.c:3408 msgid "you cannot use --symmetric --encrypt with --s2k-mode 0\n" @@ -1712,7 +1710,7 @@ msgstr "--sign --encrypt [filename]" #: g10/gpg.c:3457 msgid "--symmetric --sign --encrypt [filename]" -msgstr "--symmetric --sign --encrypt [имяфайла]" +msgstr "--symmetric --sign --encrypt [имя файла]" #: g10/gpg.c:3459 msgid "you cannot use --symmetric --sign --encrypt with --s2k-mode 0\n" @@ -1841,7 +1839,7 @@ msgstr "нет секретного подключа для открытого #: g10/getkey.c:2620 #, c-format msgid "using subkey %s instead of primary key %s\n" -msgstr "использую подклключ %s вместо главного ключа %s\n" +msgstr "использую подключ %s вместо главного ключа %s\n" #: g10/getkey.c:2667 #, c-format @@ -1862,7 +1860,7 @@ msgstr "при несоответствии отметки времени - то #: g10/gpgv.c:75 msgid "|FD|write status info to this FD" -msgstr "|FD|выводить инфромацию в файл с дескриптором FD" +msgstr "|FD|выводить информацию в файл с дескриптором FD" #: g10/gpgv.c:99 msgid "Usage: gpgv [options] [files] (-h for help)" @@ -1901,7 +1899,7 @@ msgstr "" #: g10/helptext.c:60 msgid "If you want to use this untrusted key anyway, answer \"yes\"." msgstr "" -"Если Вы хотите использовать данный недоверяемый ключ - ответьте \"yes\"." +"Если Вы хотите использовать данный недоверенный ключ - ответьте \"yes\"." #: g10/helptext.c:64 msgid "" @@ -2475,7 +2473,7 @@ msgstr "ключ %s: \"%s\" %d подпись очищена\n" #: g10/import.c:931 #, c-format msgid "key %s: \"%s\" %d signatures cleaned\n" -msgstr "ключ %s: \"%s\" %d очищеных подписей\n" +msgstr "ключ %s: \"%s\" %d очищенных подписей\n" #: g10/import.c:934 #, c-format @@ -2586,7 +2584,7 @@ msgstr "ключ %s: неправильный отзыв подключа\n" #: g10/import.c:1486 #, c-format msgid "key %s: removed multiple subkey revocation\n" -msgstr "ключ %s: удалена многожественность подключей отзыва\n" +msgstr "ключ %s: удалена множественность подключей отзыва\n" #: g10/import.c:1528 #, c-format @@ -3609,7 +3607,7 @@ msgstr "пропуск v3 самоподписи на User ID \"%s\"\n" #: g10/keyedit.c:4058 msgid "Enter your preferred keyserver URL: " -msgstr "Введите URL предпочтаемого сервера ключей: " +msgstr "Введите URL предпочитаемого сервера ключей: " #: g10/keyedit.c:4138 msgid "Are you sure you want to replace it? (y/N) " @@ -4287,7 +4285,7 @@ msgstr "%lu ключей закешировано за это время (%lu п #: g10/keyring.c:1432 #, c-format msgid "%lu keys cached (%lu signatures)\n" -msgstr "%lu ключей закешированно (%lu подписей)\n" +msgstr "%lu ключей закешировано (%lu подписей)\n" #: g10/keyring.c:1503 #, c-format @@ -4485,7 +4483,7 @@ msgstr "сеансовый ключ зашифрован %s \n" #: g10/mainproc.c:304 #, c-format msgid "passphrase generated with unknown digest algorithm %d\n" -msgstr "пароль создан с незнакомой хеш-фкнкцией %d\n" +msgstr "пароль создан с незнакомой хеш-функцией %d\n" #: g10/mainproc.c:385 #, c-format @@ -5104,11 +5102,11 @@ msgstr "Все равно использовать данный ключ? (y/N)" #: g10/pkclist.c:503 msgid "WARNING: Using untrusted key!\n" -msgstr "ВНИМАНИЕ: Использование недоверяемого ключа!\n" +msgstr "ВНИМАНИЕ: Использование недоверенного ключа!\n" #: g10/pkclist.c:510 msgid "WARNING: this key might be revoked (revocation key not present)\n" -msgstr "ВНИМАНИЕ: возможно данный ключ отозван (ключ отзыва отсутвтует)\n" +msgstr "ВНИМАНИЕ: возможно данный ключ отозван (ключ отзыва отсутствует)\n" #: g10/pkclist.c:519 msgid "WARNING: This key has been revoked by its designated revoker!\n" @@ -5348,11 +5346,11 @@ msgstr "секретный ключ \"%s\" не найден: %s\n" #: g10/revoke.c:498 #, c-format msgid "no corresponding public key: %s\n" -msgstr "нет соотвествующего открытого ключа: %s\n" +msgstr "нет соответствующего открытого ключа: %s\n" #: g10/revoke.c:509 msgid "public key does not match secret key!\n" -msgstr "открытый ключ не соотвествует секретному!\n" +msgstr "открытый ключ не соответствует секретному!\n" #: g10/revoke.c:516 msgid "Create a revocation certificate for this key? (y/N) " @@ -5380,7 +5378,7 @@ msgstr "" "\n" "Поместите его в скрытое место; если посторонний получит доступ\n" "к данному сертификату, он может использовать его, чтобы сделать\n" -"Ваш ключ непригодным к использованию. Можно распечатьтать данный\n" +"Ваш ключ непригодным к использованию. Можно распечатать данный\n" "сертификат и спрятать подальше, на случай если Ваш основной\n" "носитель будет повреждён, но будьте осторожны: система печати\n" "Вашей машины может сохранить данные и сделать их доступными для других!\n" @@ -5445,7 +5443,7 @@ msgstr "ВНИМАНИЕ: обнаружен слабый ключ - смени #: g10/seckey-cert.c:364 msgid "generating the deprecated 16-bit checksum for secret key protection\n" msgstr "" -"создание нерекомендуемой 16-битной контрольной суммы для защиты ключа\n" +"создание не рекомендуемой 16-битной контрольной суммы для защиты ключа\n" #: g10/seskey.c:51 msgid "weak key created - retrying\n" @@ -5939,7 +5937,7 @@ msgstr "проверка таблицы доверий\n" #: g10/trustdb.c:2168 #, c-format msgid "%d keys processed (%d validity counts cleared)\n" -msgstr "%d ключей обработано (%d дейсвующих записей очищено)\n" +msgstr "%d ключей обработано (%d действующих записей очищено)\n" #: g10/trustdb.c:2233 msgid "no ultimately trusted keys found\n" @@ -6140,7 +6138,7 @@ msgstr "ошибка удаления файла" #: util/errors.c:91 msgid "unexpected data" -msgstr "неожидавшиеся данные" +msgstr "неожиданные данные" #: util/errors.c:92 msgid "timestamp conflict" diff --git a/util/strgutil.c b/util/strgutil.c index f19bab5..a4f00f5 100644 --- a/util/strgutil.c +++ b/util/strgutil.c @@ -69,6 +69,25 @@ static ushort koi8_unicode[128] = { 0x042c,0x042b,0x0417,0x0428,0x042d,0x0429,0x0427,0x042a }; +static ushort cp1251_unicode[128] = { + 0x0402,0x0403,0x201a,0x0453,0x201e,0x2026,0x2020,0x2021, + 0x20ac,0x2030,0x0409,0x2039,0x040a,0x040c,0x040b,0x040f, + 0x0452,0x2018,0x2019,0x201c,0x201d,0x2022,0x2013,0x2014, + 0xffff,0x2122,0x0459,0x203a,0x045a,0x045c,0x045b,0x045f, + 0x00a0,0x040e,0x045e,0x0408,0x00a4,0x0490,0x00a6,0x00a7, + 0x0401,0x00a9,0x0404,0x00ab,0x00ac,0x00ad,0x00ae,0x0407, + 0x00b0,0x00b1,0x0406,0x0456,0x0491,0x00b5,0x00b6,0x00b7, + 0x0451,0x2116,0x0454,0x00bb,0x0458,0x0405,0x0455,0x0457, + 0x0410,0x0411,0x0412,0x0413,0x0414,0x0415,0x0416,0x0417, + 0x0418,0x0419,0x041a,0x041b,0x041c,0x041d,0x041e,0x041f, + 0x0420,0x0421,0x0422,0x0423,0x0424,0x0425,0x0426,0x0427, + 0x0428,0x0429,0x042a,0x042b,0x042c,0x042d,0x042e,0x042f, + 0x0430,0x0431,0x0432,0x0433,0x0434,0x0435,0x0436,0x0437, + 0x0438,0x0439,0x043a,0x043b,0x043c,0x043d,0x043e,0x043f, + 0x0440,0x0441,0x0442,0x0443,0x0444,0x0445,0x0446,0x0447, + 0x0448,0x0449,0x044a,0x044b,0x044c,0x044d,0x044e,0x044f +}; + static ushort latin2_unicode[128] = { 0x0080,0x0081,0x0082,0x0083,0x0084,0x0085,0x0086,0x0087, 0x0088,0x0089,0x008A,0x008B,0x008C,0x008D,0x008E,0x008F, @@ -649,6 +668,13 @@ set_native_charset( const char *newset ) active_charset = koi8_unicode; use_iconv = 0; } + else if( !ascii_strcasecmp( newset, "cp1251" ) + || !ascii_strcasecmp (newset, "windows-1251" ) ) { + active_charset_name = "cp1251"; + no_translation = 0; + active_charset = cp1251_unicode; + use_iconv = 0; + } else return G10ERR_GENERAL; #endif /*!USE_GNUPG_ICONV*/