Branch data Line data Source code
1 : : /* libsecret - Test TSS interface for libsecret 2 : : * 3 : : * Copyright (C) 2021 Dhanuka Warusadura 4 : : * 5 : : * This library is free software; you can redistribute it and/or modify 6 : : * it under the terms of the GNU Lesser General Public License as 7 : : * published by the Free Software Foundation; either version 2.1 of 8 : : * the License, or (at your option) any later version. 9 : : * 10 : : * This library is distributed in the hope that it will be useful, but 11 : : * WITHOUT ANY WARRANTY; without even the implied warranty of 12 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 : : * Lesser General Public License for more details. 14 : : * 15 : : * You should have received a copy of the GNU Lesser General Public 16 : : * License along with this library; if not, write to the Free Software 17 : : * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 18 : : * MA 02110-1301 USA 19 : : * 20 : : * Author: Dhanuka Warusadura 21 : : */ 22 : : 23 : : #include "egg-tpm2.h" 24 : : 25 : : void 26 : 1 : test_egg_tpm2_generate_master_password(void) 27 : : { 28 : : EggTpm2Context *context; 29 : : GBytes *result; 30 : : 31 : 1 : GError *error = NULL; 32 [ - + ]: 1 : g_assert_no_error(error); 33 : 1 : context = egg_tpm2_initialize(&error); 34 [ - + ]: 1 : g_assert_nonnull(context); 35 : 1 : result = egg_tpm2_generate_master_password(context, &error); 36 [ - + ]: 1 : g_assert_nonnull(result); 37 : 1 : egg_tpm2_finalize(context); 38 : 1 : g_bytes_unref(result); 39 : 1 : } 40 : : 41 : : void 42 : 1 : test_egg_tpm2_decrypt_master_password(void) 43 : : { 44 : : EggTpm2Context *context; 45 : : GBytes *result, *decrypted1, *decrypted2; 46 : : 47 : 1 : GError *error = NULL; 48 [ - + ]: 1 : g_assert_no_error(error); 49 : 1 : context = egg_tpm2_initialize(&error); 50 [ - + ]: 1 : g_assert_nonnull(context); 51 : 1 : result = egg_tpm2_generate_master_password(context, &error); 52 [ - + ]: 1 : g_assert_nonnull(result); 53 : 1 : egg_tpm2_finalize(context); 54 : : 55 : 1 : context = egg_tpm2_initialize(&error); 56 : 1 : decrypted1 = egg_tpm2_decrypt_master_password(context, result, 57 : : &error); 58 [ - + ]: 1 : g_assert_nonnull(decrypted1); 59 : 1 : decrypted2 = egg_tpm2_decrypt_master_password(context, result, 60 : : &error); 61 [ - + ]: 1 : g_assert_nonnull(decrypted2); 62 [ - + ]: 1 : g_assert(g_bytes_equal(decrypted1, decrypted2)); 63 : 1 : egg_tpm2_finalize(context); 64 : 1 : g_bytes_unref(result); 65 : 1 : g_bytes_unref(decrypted1); 66 : 1 : g_bytes_unref(decrypted2); 67 : 1 : } 68 : : 69 : : int 70 : 1 : main (int argc, char *argv[]) 71 : : { 72 : 1 : g_test_init(&argc, &argv, NULL); 73 : 1 : g_test_add_func( 74 : : "/tpm/test_egg_tpm2_generate_master_password", 75 : : test_egg_tpm2_generate_master_password); 76 : 1 : g_test_add_func( 77 : : "/tpm/test_egg_tpm2_decrypt_master_password", 78 : : test_egg_tpm2_decrypt_master_password); 79 : : 80 : 1 : return g_test_run(); 81 : : }