Cryptography
PATCH 1/1 Cryptography
Hello, all. This patch imports strong cryptography and fixes some issues in authentication system.
1) grub_auth_strcmp and grub_auth_strword are removed. They ended up to be too complex which is security-issue prone. For password I now hardcode maximum length as was suggested and use grub_crypto_memcmp. Logins are now considered non-confidential
2) Ciphers and hashes are imported from libgcrypt. Actual import is automated and imported files are not included in the patch. To import do:
python import_gcry.py <libgcrypt dir> .
Crypto interface is designed for simplicity and small size
3) PBKDF2-SHA512 password support to increase security. To generate the encrypted password do:
grub-pbkdf2 [-c iteration_count]
It may not work on non-unix platforms due to terminal control functions (disabling echo) and /dev/random (retrieving salt). Patches are welcome PBKDF2 is imported from gnulib
4) xnu_uuid is cleanup to use MD5 from libgcrypt through crypto interface
5) Imported devmapper.mod by Simon Peter. Completely UNTESTED. Known issues:
No cipher and hash autoloading if it's looked up by the name. Password and hash modules aren't locked if a cipher/digest is used to prevent accidental unload.
I send the patch and the same is available in my crypto branch
Signature · 2 lines
Regards Vladimir 'phcoder' Serbinenko
=== modified file '.bzrignore'
.bzrignore +1 -0
@@ -31,6 +31,7 @@ grub_fstest_init.h grub-install grub-mk* +grub-pbkdf2 grub-pe2elf grub-probe grub_probe_init.c
=== modified file 'commands/password.c'
password.c +11 -3
@@ -17,6 +17,7 @@*/ #include <grub/auth.h> +#include <grub/crypto.h> #include <grub/list.h> #include <grub/mm.h> #include <grub/misc.h>
@@ -26,18 +27,20 @@static grub_dl_t my_mod; +#define MAX_PASSLEN 1024 +static grub_err_t check_password (const char *user,void *password) { -char entered[1024 ]; +char entered[MAX_PASSLEN ];grub_memset (entered,0 ,sizeof (entered));if (!GRUB_GET_PASSWORD (entered,sizeof (entered) -1 ))return GRUB_ACCESS_DENIED ; -if (grub_auth_strcmp (entered, password) !=0 ) +if (grub_crypto_memcmp (entered, password,MAX_PASSLEN ) !=0 )return GRUB_ACCESS_DENIED ;grub_auth_authenticate (user);
@@ -51,13 +54,18 @@ {grub_err_t err;char *pass; +int copylen;if (argc !=2 )return grub_error (GRUB_ERR_BAD_ARGUMENT ,"Two arguments expected." ); - pass =grub_strdup (args[1 ]); + pass =grub_zalloc (MAX_PASSLEN );if (!pass)return grub_errno; + copylen =grub_strlen (args[1 ]); +if (copylen >=MAX_PASSLEN ) + copylen =MAX_PASSLEN -1 ; +grub_memcpy (pass, args[1 ], copylen); err =grub_auth_register_authentication (args[0 ], check_password, pass);if (err)
=== added file 'commands/password_pbkdf2.c'
password_pbkdf2.c +202 -0
202 lines not on this page · raw message
=== modified file 'commands/xnu_uuid.c'
xnu_uuid.c +12 -301
335 lines not on this page · raw message
=== modified file 'conf/common.rmk'
common.rmk +26 -0
@@ -621,3 +621,29 @@ setjmp_mod_SOURCES = lib/$(target_cpu)/setjmp.S setjmp_mod_ASFLAGS = $(COMMON_ASFLAGS) setjmp_mod_LDFLAGS = $(COMMON_LDFLAGS) + +pkglib_MODULES += crypto.mod +crypto_mod_SOURCES = lib/crypto.c +crypto_mod_CFLAGS = $(COMMON_CFLAGS) +crypto_mod_LDFLAGS = $(COMMON_LDFLAGS) + +pkglib_MODULES += devmapper.mod +devmapper_mod_SOURCES = disk/devmapper.c +devmapper_mod_CFLAGS = $(COMMON_CFLAGS) +devmapper_mod_LDFLAGS = $(COMMON_LDFLAGS) + +pkglib_MODULES += pbkdf2.mod +pbkdf2_mod_SOURCES = lib/pbkdf2.c +pbkdf2_mod_CFLAGS = $(COMMON_CFLAGS) +pbkdf2_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For password_pbkdf2.mod. +pkglib_MODULES += password_pbkdf2.mod +password_pbkdf2_mod_SOURCES = commands/password_pbkdf2.c +password_pbkdf2_mod_CFLAGS = $(COMMON_CFLAGS) +password_pbkdf2_mod_LDFLAGS = $(COMMON_LDFLAGS) + +bin_UTILITIES += grub-pbkdf2 +grub_pbkdf2_SOURCES = util/grub-pbkdf2.c lib/crypto.c gcry/cipher/sha512.c lib/pbkdf2.c util/misc.c kern/err.c + +include $(srcdir)/conf/gcry.mk
=== modified file 'conf/i386-coreboot.rmk'
i386-coreboot.rmk +1 -1
@@ -130,7 +130,7 @@ kern/partition.c kern/reader.c kern/term.c \ kern/rescue_reader.c kern/rescue_parser.c \ lib/arg.c normal/cmdline.c normal/misc.c \ - normal/handler.c normal/auth.c normal/autofs.c \ + normal/handler.c normal/auth.c lib/crypto.c normal/autofs.c \ normal/completion.c normal/datetime.c normal/main.c \ normal/menu_text.c \ normal/menu.c normal/menu_entry.c normal/menu_viewer.c \
=== modified file 'conf/i386-efi.rmk'
i386-efi.rmk +1 -1
@@ -57,7 +57,7 @@ kern/partition.c kern/reader.c kern/term.c \ kern/rescue_reader.c kern/rescue_parser.c \ lib/arg.c normal/cmdline.c normal/command.c normal/datetime.c \ - normal/auth.c normal/autofs.c \ + normal/auth.c lib/crypto.c normal/autofs.c \ normal/completion.c normal/context.c normal/main.c \ normal/menu.c normal/menu_entry.c normal/menu_viewer.c \ normal/menu_text.c \
=== modified file 'conf/i386-ieee1275.rmk'
i386-ieee1275.rmk +1 -1
@@ -85,7 +85,7 @@ kern/partition.c kern/reader.c kern/term.c \ kern/rescue_reader.c kern/rescue_parser.c \ lib/arg.c normal/cmdline.c normal/datetime.c normal/misc.c \ - normal/handler.c normal/auth.c normal/autofs.c \ + normal/handler.c normal/auth.c lib/crypto.c normal/autofs.c \ normal/completion.c normal/main.c normal/menu_text.c \ normal/menu.c normal/menu_entry.c normal/menu_viewer.c \ normal/color.c \
=== modified file 'conf/i386-pc.rmk'
i386-pc.rmk +2 -2
@@ -123,7 +123,7 @@ commands/search.c commands/blocklist.c commands/hexdump.c \ lib/hexdump.c commands/i386/pc/halt.c commands/reboot.c \ lib/envblk.c commands/loadenv.c \ - commands/gptsync.c commands/probe.c commands/xnu_uuid.c \ + commands/gptsync.c commands/probe.c \ commands/i386/cpuid.c \ commands/password.c commands/keystatus.c \ disk/host.c disk/loopback.c disk/scsi.c \
@@ -137,7 +137,7 @@ kern/partition.c kern/reader.c kern/term.c \ kern/rescue_reader.c kern/rescue_parser.c \ lib/arg.c normal/cmdline.c normal/datetime.c normal/misc.c \ - normal/handler.c normal/auth.c normal/autofs.c \ + normal/handler.c normal/auth.c lib/crypto.c normal/autofs.c \ normal/completion.c normal/main.c normal/color.c \ normal/menu.c normal/menu_entry.c normal/menu_viewer.c \ normal/menu_text.c \
=== modified file 'conf/powerpc-ieee1275.rmk'
powerpc-ieee1275.rmk +1 -1
@@ -65,7 +65,7 @@ kern/command.c kern/corecmd.c commands/extcmd.c \ lib/arg.c normal/cmdline.c normal/datetime.c \ normal/completion.c normal/misc.c \ - normal/handler.c normal/auth.c normal/autofs.c normal/main.c \ + normal/handler.c normal/auth.c lib/crypto.c normal/autofs.c normal/main.c \ normal/menu.c \ normal/menu_text.c \ normal/menu_entry.c normal/menu_viewer.c \
=== modified file 'conf/sparc64-ieee1275.rmk'
sparc64-ieee1275.rmk +1 -1
@@ -123,7 +123,7 @@ kern/command.c kern/corecmd.c commands/extcmd.c \ lib/arg.c normal/cmdline.c normal/datetime.c \ normal/completion.c normal/misc.c \ - normal/handler.c normal/auth.c normal/autofs.c normal/main.c \ + normal/handler.c normal/auth.c lib/crypto.c normal/autofs.c normal/main.c \ normal/menu.c \ normal/menu_text.c \ normal/menu_entry.c normal/menu_viewer.c \
=== modified file 'conf/x86_64-efi.rmk'
x86_64-efi.rmk +1 -1
@@ -53,7 +53,7 @@ kern/command.c kern/corecmd.c commands/extcmd.c kern/file.c \ kern/fs.c commands/boot.c kern/main.c kern/misc.c kern/parser.c \ kern/partition.c kern/readerescue.c kern/term.c \ - lib/arg.c normal/cmdline.c normal/misc.c normal/auth.c \ + lib/arg.c normal/cmdline.c normal/misc.c normal/auth.c lib/crypto.c \ normal/autofs.c \ normal/completion.c normal/datetime.c normal/context.c \ normal/main.c \
=== added file 'disk/devmapper.c'
devmapper.c +414 -0
414 lines not on this page · raw message
=== added file 'import_gcry.py'
import_gcry.py +286 -0
286 lines not on this page · raw message
=== modified file 'include/grub/auth.h'
grub/auth.h +1 -6
@@ -15,7 +15,7 @@* You should have received a copy of the GNU General Public License * along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef GRUB_AURH_HEADER +#ifndef GRUB_AUTH_HEADER #define GRUB_AUTH_HEADER 1#include <grub/err.h>
@@ -26,11 +26,6 @@ string, len, \ '*', 0, 0) -/* Like strcmp but untimeable. Accepts NULL as second argument. */ -int grub_auth_strcmp (const char *user_input,const char *template); -/* Like strcmp but untimeable and ignores commas in needle. */ -int grub_auth_strword (const char *haystack,const char *needle); -typedef grub_err_t (*grub_auth_callback_t ) (const char *,void *); grub_err_t grub_auth_register_authentication (const char *user,
=== added file 'include/grub/cipher_wrap.h'
grub/cipher_wrap.h +84 -0
84 lines not on this page · raw message
=== added file 'include/grub/crypto.h'
grub/crypto.h +269 -0
269 lines not on this page · raw message
=== modified file 'include/grub/disk.h'
grub/disk.h +2 -0
@@ -42,6 +42,8 @@GRUB_DISK_DEVICE_PXE_ID ,GRUB_DISK_DEVICE_SCSI_ID ,GRUB_DISK_DEVICE_FILE_ID , +GRUB_DISK_DEVICE_LUKS_ID , + GRUB_DISK_DEVICE_DEVMAP_ID };struct grub_disk ;
=== modified file 'include/grub/err.h'
grub/err.h +2 -1
@@ -54,7 +54,8 @@GRUB_ERR_MENU ,GRUB_ERR_TIMEOUT ,GRUB_ERR_IO , - GRUB_ERR_ACCESS_DENIED +GRUB_ERR_ACCESS_DENIED , + GRUB_ERR_CIPHER_NOT_FOUND } grub_err_t;
=== added file 'lib/crypto.c'
crypto.c +387 -0
387 lines not on this page · raw message
=== added file 'lib/pbkdf2.c'
pbkdf2.c +101 -0
101 lines not on this page · raw message
=== modified file 'normal/auth.c'
auth.c +3 -55
76 lines not on this page · raw message
=== added file 'util/grub-pbkdf2.c'
grub-pbkdf2.c +337 -0
337 lines not on this page · raw message
Quoted 3 lines · Vladimir 'phcoder' Serbinenko
2) Ciphers and hashes are imported from libgcrypt. Actual import is automated and imported files are not included in the patch. To import do:
pythonimport_gcry.py<libgcrypt dir> .
Please don't merge the auto-import script. I have to handle code imports myself.
Quoted 1 line
PBKDF2 is imported from gnulib
Were any modifications needed?
Quoted 3 lines
5) Imported devmapper.mod by Simon Peter. Completely UNTESTED. [...]
+ * Copyright (C) 2007 Simon Peter <[email protected]>
Did Simon write this code for GRUB? I just checked, we have an assignment for past and future changes from him.
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
Quoted 10 lines · Robert Millan
Quoted 4 lines · Vladimir 'phcoder' Serbinenko
2) Ciphers and hashes are imported from libgcrypt. Actual import is automated and imported files are not included in the patch. To import do:
pythonimport_gcry.py<libgcrypt dir> .Please don't merge the auto-import script. I have to handle code imports myself.
import_gcry.py is meant to be run by maintainer or developer in charge, not user.
Quoted 7 lines
Quoted 3 lines
PBKDF2 is imported from gnulib
Were any modifications needed?
1) Standard GRUB'ification (other headers, grub_ prefix)
2) Adaptation to the lack of gnulib abstraction layer on top of gcrypt
3) Support for any hash and not only SHA1
Quoted 9 lines
Quoted 4 lines
5) Imported devmapper.mod by Simon Peter. Completely UNTESTED. [...]
+ * Copyright (C) 2007 Simon Peter <[email protected]>Did Simon write this code for GRUB? I just checked, we have an assignment for past and future changes from him.
AFAICT from this thread:
http://lists.gnu.org/archive/html/grub-devel/2007-09/msg00002.html
he did. CC'ing him
@Simon: Sorry for the delay, just project had a period of low actitivity but this period is over
Signature · 2 lines
Regards Vladimir 'phcoder' Serbinenko
Quoted 1 line · Vladimir 'phcoder' Serbinenko
2) Adaptation to the lack of gnulib abstraction layer on top of gcrypt
It seems that the usual way of importing gc-pbkdf2-sha1.c is by linking it with gc-gnulib.c or gc-libgcrypt.c. Is this option problematic?
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
Quoted 9 lines · Robert Millan
Quoted 2 lines · Vladimir 'phcoder' Serbinenko
2) Adaptation to the lack of gnulib abstraction layer on top of gcrypt
It seems that the usual way of importing
gc-pbkdf2-sha1.cis by linking it withgc-gnulib.corgc-libgcrypt.c. Is this option problematic?
libgcrypt is done like this:
libgcrypt API ----> Common cryptographic algorithms layer (for some algorithms it's quite a passthrough) ---> ciphers
Although we use ciphers from libgcrypt, our middle layer is much simpler and lacks per-cipher integer IDs. Because of it using gc-libgcrypt.c would require an additional level of wrapping and it's much easier to just modify few lines in PBKDF2
Signature · 2 lines
Regards Vladimir 'phcoder' Serbinenko
Quoted 12 lines · Vladimir 'phcoder' Serbinenko
Quoted 9 lines · Robert Millan
Quoted 2 lines · Vladimir 'phcoder' Serbinenko
2) Adaptation to the lack of gnulib abstraction layer on top of gcrypt
It seems that the usual way of importing
gc-pbkdf2-sha1.cis by linking it withgc-gnulib.corgc-libgcrypt.c. Is this option problematic?libgcrypt is done like this:
Quoted 7 lines
libgcrypt API ----> Common cryptographic algorithms layer (for some algorithms it's quite a passthrough) ---> ciphers
Although we use ciphers from libgcrypt, our middle layer is much simpler and lacks per-cipher integer IDs. Because of it using
gc-libgcrypt.cwould require an additional level of wrapping and it's much easier to just modify few lines in PBKDF2
Ok. Then in principle we wouldn't contemplate resyncing this file, right?
What version of libgcrypt should be imported?
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
Quoted 20 lines · Robert Millan
Quoted 18 lines · Vladimir 'phcoder' Serbinenko
Quoted 11 lines · Robert Millan
Quoted 3 lines · Vladimir 'phcoder' Serbinenko
2) Adaptation to the lack of gnulib abstraction layer on top of gcrypt
It seems that the usual way of importing
gc-pbkdf2-sha1.cis by linking it withgc-gnulib.corgc-libgcrypt.c. Is this option problematic?libgcrypt is done like this:
libgcrypt API ----> Common cryptographic algorithms layer (for some algorithms it's quite a passthrough) ---> ciphers
Quoted 9 lines
Quoted 5 lines
Although we use ciphers from libgcrypt, our middle layer is much simpler and lacks per-cipher integer IDs. Because of it using
gc-libgcrypt.cwould require an additional level of wrapping and it's much easier to just modify few lines in PBKDF2Ok. Then in principle we wouldn't contemplate resyncing this file, right?
Unless there will be a cryptographic or legal issue, no. PBKDF2 is a static standard
Quoted 3 lines
What version of libgcrypt should be imported?
I used 1.4.4. Latest ChangeLog entry in cipher/ directory is:
2009-01-22 Werner Koch <[email protected]>
* ecc.c (compute_keygrip): Remove superfluous const.
Latest SVN has latest ChangeLog entry:
2009-08-21 Werner Koch <[email protected]>
* dsa.c (dsa_generate_ext): Release retfactors array before setting it to NULL. Reported by Daiko Ueno.
and ChangeLog doesn't mention anything that would result in a different import, except of the currently unused public-key cryptography files (and which will require adaptations in import_gcry.py to be handled) and unused files md.c/cipher.c included in import for reference. So I recommend importing 1.4.4
Signature · 2 lines
Regards Vladimir 'phcoder' Serbinenko
Import of libgcrypt 1.4.4 ciphers (was: Re: [PATCH] Cryptography)
Quoted 5 lines · Vladimir 'phcoder' Serbinenko
Quoted 2 lines · Robert Millan
Ok. Then in principle we wouldn't contemplate resyncing this file, right?
Unless there will be a cryptographic or legal issue, no. PBKDF2 is a static standard
Alright.
Quoted 5 lines
and ChangeLog doesn't mention anything that would result in a different import, except of the currently unused public-key cryptography files (and which will require adaptations in
import_gcry.pyto be handled) and unused filesmd.c/cipher.cincluded in import for reference. So I recommend importing 1.4.4
I imported ciphers from 1.4.4 in this branch:
sftp://bzr.savannah.gnu.org/srv/bzr/grub/people/robertmh/libgcrypt
also, I integrated your import_gcry.py script with autogen.sh. This way auto-generated files don't have to be hosted in our repository. If in the future original libgcrypt files need modification, this can be committed directly in lib/libgcrypt (provided that we coordinate with libgcrypt maintainers to have those changes merged back, of course).
When you have confirmed that this seems correct to you, I'll write a ChangeLog entry and merge in trunk.
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
Am Montag, den 16.11.2009, 14:48 +0100 schrieb Vladimir 'phcoder' Serbinenko:
Quoted 9 lines
3) PBKDF2-SHA512 password support to increase security. To generate the
encrypted password do:
grub-pbkdf2 [-citeration_count]
It may not work on non-unix platforms due to terminal control functions
(disabling echo) and/dev/random(retrieving salt). Patches are welcome
PBKDF2 is imported from gnulib
I suggest to name it grub-mkpasswd.
Even in the case we only support one password hash this makes it easier for users to find then grub-pbkdf2 and to figure out what it does.
Signature · 2 lines
Felix Zielcke Proud Debian Maintainer and GNU GRUB developer
Quoted 14 lines · Felix Zielcke
Am Montag, den 16.11.2009, 14:48 +0100 schrieb Vladimir 'phcoder' Serbinenko:
Quoted 10 lines
3) PBKDF2-SHA512 password support to increase security. To generate the
encrypted password do:
grub-pbkdf2 [-citeration_count]
It may not work on non-unix platforms due to terminal control functions
(disabling echo) and/dev/random(retrieving salt). Patches are welcome
PBKDF2 is imported from gnulib
Quoted 5 lines
I suggest to name it grub-mkpasswd.
Even in the case we only support one password hash this makes it easier for users to find then grub-pbkdf2 and to figure out what it does.
I plan to add scrypt into grub-extras (partially done) and it will require a separate tool to generate encrypted password (grub-scrypt)
Signature · 2 lines
Regards Vladimir 'phcoder' Serbinenko
grub/cipher_wrap.h
Quoted 3 lines · Vladimir 'phcoder' Serbinenko
=== added file '
include/grub/cipher_wrap.h'grub/cipher_wrap.h +0
-0
Can we avoid cluttering the grub/ namespace with glue code? This could be in lib/<something>/include (see e.g. how lib-linux branch does it).
pbkdf2.c line 2
Quoted 5 lines
pbkdf2.c +2
-0@@ -0,0 +1,101 @@ +/* gc-pbkdf2-sha1.c --- Password-Based Key Derivation Function a'la PKCS#5 +Copyright (C) 2002, 2003, 2004, 2005, 2006, 2009 Free Software Foundation, Inc.
You may import this file from Gnulib and derive from it. Please add a note indicating its origin.
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
Quoted 6 lines · Robert Millan
grub/cipher_wrap.h
Quoted 3 lines · Vladimir 'phcoder' Serbinenko
=== added file '
include/grub/cipher_wrap.h'grub/cipher_wrap.h +0
-0Can we avoid cluttering the grub/ namespace with glue code?
Sorry, what I said is confusing. I didn't mean the grub/ namespace, I mean the "default" namespace (in which grub/* is included but also multiboot.h).
lib-linux has its own namespace where we put things like linux/* and asm/*, I think a similar approach would be desireable for consistency.
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
Quoted 11 lines · Robert Millan
Quoted 8 lines · Robert Millan
grub/cipher_wrap.h
Quoted 4 lines · Vladimir 'phcoder' Serbinenko
=== added file '
include/grub/cipher_wrap.h'grub/cipher_wrap.h +0
-0Can we avoid cluttering the grub/ namespace with glue code?
Quoted 7 lines
Sorry, what I said is confusing. I didn't mean the grub/ namespace, I mean the "default" namespace (in which grub/* is included but also
multiboot.h).lib-linux has its own namespace where we put things like linux/* and asm/*, I think a similar approach would be desireable for consistency.
This and other problems were fixed and now crypto is in experimental except Simon Peter's and Michael Gorven's work
Signature · 2 lines
Regards Vladimir 'φ-coder/phcoder' Serbinenko