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q6lhbYX7Wf/bmc=\n-----END CERTIFICATE-----\n" static gchar *always_fail_cb (gpointer data __attribute__((unused)), const gchar *prompt __attribute__((unused)), int echo __attribute__((unused))) { return NULL; } static gchar *give_passphrase_cb (gpointer data, const gchar *prompt __attribute__((unused)), unsigned failed_attempts) { if (failed_attempts == 0) /* Return a copy of the passphrase that will be freed by volume_key */ return g_strdup (data); return NULL; } static void free_passphrase_cb (gpointer data) { g_free (data); } int main (void) { struct libvk_volume *volume = NULL; struct libvk_ui *ui = NULL; CERTCertificate *cert = NULL; gchar *passphrase_copy = NULL; gchar *cert_data_copy = NULL; GError *error = NULL; gpointer packet_data = NULL; gsize packet_data_size = 0; if (!NSS_IsInitialized()) if (NSS_NoDB_Init(NULL) != SECSuccess) { g_warning ("Failed to initialize NSS\n"); return 1; } volume = libvk_volume_open (DEVICE, &error); if (!volume) { g_print ("%s\n", error->message); return 1; } ui = libvk_ui_new (); libvk_ui_set_generic_cb (ui, always_fail_cb, NULL, NULL); passphrase_copy = g_strdup (PASSPHRASE); libvk_ui_set_passphrase_cb (ui, give_passphrase_cb, passphrase_copy, free_passphrase_cb); if (libvk_volume_get_secret (volume, LIBVK_SECRET_DEFAULT, ui, &error) != 0) { libvk_volume_free (volume); libvk_ui_free (ui); g_print ("%s\n", error->message); return 1; } cert_data_copy = g_strdup (CERT_DATA); cert = CERT_DecodeCertFromPackage (cert_data_copy, strlen(cert_data_copy)); if (!cert) { libvk_volume_free (volume); libvk_ui_free (ui); g_free (cert_data_copy); g_print ("Failed to decode the certificate data\n"); return 1; } packet_data = libvk_volume_create_packet_asymmetric_with_format (volume, &packet_data_size, LIBVK_SECRET_DEFAULT, cert, ui, LIBVK_PACKET_FORMAT_ASYMMETRIC_WRAP_SECRET_ONLY, &error); if (!packet_data) { g_print ("Failed to get escrow data: %s\n", error->message); g_clear_error (&error); return 1; } g_print ("Packet data generated!\n"); CERT_DestroyCertificate (cert); libvk_volume_free (volume); libvk_ui_free (ui); g_free (cert_data_copy); return 0; }