Return-Path: Received: from mx3.freesources.org (mx3.freesources.org [195.34.172.217]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.server123.net (Postfix) with ESMTPS for ; Wed, 29 Jan 2020 15:14:44 +0100 (CET) References: <9c428b57-b3e7-38e1-d963-4596e46f69ea@freesources.org> <90aad9a7-f557-2c0a-cc55-6dbd20cf792b@redhat.com> From: Jonas Meurer Message-ID: <16f19bb9-afb5-1bba-de25-d3c81544d374@freesources.org> Date: Wed, 29 Jan 2020 15:14:24 +0100 MIME-Version: 1.0 In-Reply-To: <90aad9a7-f557-2c0a-cc55-6dbd20cf792b@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="ghh6CYr0QMoAByDsf4h4RAorwbdzXiD0D" Subject: Re: [dm-crypt] how to get keyslog PBKDF settings via libcryptsetup List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Ondrej Kozina , dm-crypt This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --ghh6CYr0QMoAByDsf4h4RAorwbdzXiD0D Content-Type: multipart/mixed; boundary="I5xeHKA15H9C0pBI0H9BPkz8uL0IqNRlL"; protected-headers="v1" From: Jonas Meurer To: Ondrej Kozina , dm-crypt Message-ID: <16f19bb9-afb5-1bba-de25-d3c81544d374@freesources.org> Subject: Re: [dm-crypt] how to get keyslog PBKDF settings via libcryptsetup References: <9c428b57-b3e7-38e1-d963-4596e46f69ea@freesources.org> <90aad9a7-f557-2c0a-cc55-6dbd20cf792b@redhat.com> In-Reply-To: <90aad9a7-f557-2c0a-cc55-6dbd20cf792b@redhat.com> --I5xeHKA15H9C0pBI0H9BPkz8uL0IqNRlL Content-Type: text/plain; charset=utf-8 Content-Language: de-DE Content-Transfer-Encoding: quoted-printable Hey Ondrej, Ondrej Kozina: > On 1/28/20 3:51 PM, Jonas Meurer wrote: >> Hello dm-crypt folks, >> >> I want to retrieve pbkdf params for active keyslots of LUKS devices. >> First I looked into `crypt_keyslot_get_pbkdf()`, but contrary to what >> the code suggests[1], it doesn't return values for LUKS1 devices. >=20 > No, it should definitely work. What version of library have you tested > it with? Thanks for your comments and confirming that I'm on the right track :) I'm using the latest cryptsetup 2.2.2 version (from the Debian packages).= > So, are you sure *cd contains proper LUKS1 context? At least I hope so. `crypt_get_type(cd)` returns 'LUKS1' and 'LUKS2' respectively. > Probably, you've just switched the condition on > crypt_keyslot_get_pbkdf(). It returns 0 on success and negative value > otherwise. That's how I first understood it that way as well. But after some testing I got the impression that my crypt_pbkdf_type struct contains values if the return code is *not* 0. Anyway, I checked the return codes of `crypt_keyslot_get_pbkdf(cd, ki, &pbkdf_ki)` now for LUKS1 and LUKS2 devices and interestingly, I always get return code '0' for LUKS1 devices and '-2' for LUKS2 devices: Device cont1_crypt (type LUKS2) Active keyslot 0: 2 return code: -2 Active keyslot 1: 2 return code: -2 Device cont3_crypt (type LUKS1) Active keyslot 0: 3 cryptsetup-suspend: couldn't get PBKDF for keyslot 0 of device cont3_crypt: Success return code: 0 Also, the crypt_pbkdf_type struct has values '0' for all integers for LUKS1 and seems to have random values for LUKS2 (probably pointers to random memory pages?). Simplified code: struct crypt_device *cd =3D NULL; crypt_init_by_name(&cd, devices[i]); printf("Device %s (type %s)\n", devices[i], crypt_get_type(cd)); int ks_max =3D crypt_keyslot_max(crypt_get_type(cd)); for (int j =3D 0; j < ks_max; j++) { crypt_keyslot_info ki =3D crypt_keyslot_status(cd, j); if (ki !=3D CRYPT_SLOT_ACTIVE && ki !=3D CRYPT_SLOT_ACTIVE_LAST) continue; printf("Active keyslot %d: %d\n", j, ki); struct crypt_pbkdf_type pbkdf_ki; int res =3D crypt_keyslot_get_pbkdf(cd, ki, &pbkdf_ki); printf(" return code: %d\n", res); } crypt_free(cd); >> Also, looking at the actual return valudes, it seems to return the >> calculated values for a new keyslot, not the ones for the active >> keyslot, right? >=20 > Again, this would be either bug in libcryptsetup or some mistake in you= r > application code. Looking at libcryptsetup code it extracts values > directly from metadata for both LUKS1 and LUKS2. Yep, apparently either I'm doing something wrong or there's a bug in libcryptsetup. Unfortunately I'm not sure which one is true ;) > Do you get same values when you try to modify your code a bit? >=20 > Could you replace crypt_init_by_name() with >=20 > crypt_init(/path/to/luks/metadata/device) > and subsequent > crypt_load() >=20 > Do you get same (wrong) values? Jep, I now tried that with exactly the same results. Cheers jonas --I5xeHKA15H9C0pBI0H9BPkz8uL0IqNRlL-- --ghh6CYr0QMoAByDsf4h4RAorwbdzXiD0D Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEELIzSg9Pv30M4kOeDUmLn/0kQSf4FAl4xk1EACgkQUmLn/0kQ Sf5jFhAAoVcv2T1fX7fG6hPN6kEl3IBxcOQDEYNkdgYW2zDaEnQl/+EhMz5qr+1F MEe2bAAdJ7Ob8KpdjguVFHHpynau39VOnM5XtDu/eQpqMqHEBktnm8OOPGeaKlRq GlbWcb1Q3x5dV+0m8YDD3Fozt022WR75oLJeOIvKeuLVi7Qg0R4G2E7xYxZknOC7 RZnRfRrrmctAvZSwQ6X+wtK6pWSrSDQNr7+O1WJ+4Z8WdSX2P6ekHFOwUdvbicZg q/bp4n/Rxeotq8gtuN112bZxt8azyIxsPUb7BVT+F0kOTQtlmoLMzt3BgWDZBS6B Cus8U3D6KMq5sFO9btxVTkCoyaANVha+yjHrFc+PEPp6alizCY5bVqrxVYytzUP6 rV/IKeoPzNLJCzLS5JaX6f0inXHX4NVZ6Ekbwtpo8Z5EX07SWZsf595TitF4utrv YCxDivLjIfPo8CWjTwLdfE1n1iIhjGi0sDh3yeCSx8oi5iqsA8GZkoYnZ+yrZNEC 4utjA3KiUP57u455ljEzTTWa8ENrQuosHGCu4QxCGSBIPaplZXJ6+jwUmoem5hEi Ce5N+LJ0tFkfuYzxLvI32cqeznVRsBZR4KQej0rTfX+LeiNM1z8o6B1KSkgmCTJd k4vuH1PSGxk6/mGJvL/t9MEcs6XWEoPtMzpKsqmcMKPTb67eil0= =g2hD -----END PGP SIGNATURE----- --ghh6CYr0QMoAByDsf4h4RAorwbdzXiD0D--