Example #1
0
void EditDialog::load_win_certs()
{
#ifdef USE_SYSTEM_KEYS
    gnutls_system_key_iter_t iter = NULL;
    char *label;
    char *cert_url;
    char *key_url;
    int ret, idx = -1;
    int row = 0;
    QString prekey = ss->get_key_url();

    if (prekey.isEmpty() == false) {
        ui->userKeyEdit->setText(prekey);
    }

    this->winCerts.clear();
    ui->loadWinCertList->clear();

    do {
        ret =
            gnutls_system_key_iter_get_info(&iter, GNUTLS_CRT_X509, &cert_url, &key_url, &label,
                                            NULL, 0);
        if (ret >= 0) {
            win_cert_st st;
            QString l;
            if (label != NULL)
                l = QString::fromUtf8(label);
            else
                l = QString::fromUtf8(cert_url);
            ui->loadWinCertList->addItem(l);
            if (prekey.isEmpty() == false) {
                if (QString::compare(prekey, QString::fromUtf8(key_url),
                                     Qt::CaseSensitive) == 0) {
                    idx = row;
                }
            }
            row++;

            st.label = l;
            st.key_url = QString::fromUtf8(key_url);
            st.cert_url = QString::fromUtf8(cert_url);
            this->winCerts.push_back(st);
        }
    } while (ret >= 0);

    if (idx != -1) {
        ui->loadWinCertList->setCurrentRow(idx);
        ui->loadWinCertList->item(idx)->setSelected(true);
    }
    gnutls_system_key_iter_deinit(iter);
#endif
}
Example #2
0
static void systemkey_list(FILE * out)
{
	int ret;
	gnutls_system_key_iter_t iter = NULL;
	char *cert_url, *key_url, *label;

	do {
		ret = gnutls_system_key_iter_get_info(&iter, GNUTLS_CRT_X509, &cert_url, &key_url, &label, NULL, 0);
		if (ret >= 0) {
			fprintf(out, "Label:\t%s\nCert:\t%s\nKey:\t%s\n\n", label, cert_url, key_url);
		}
	} while(ret >= 0);

	if (ret < 0 && ret != GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE) {
		fprintf(stderr, "gnutls_system_key_iter_get_url: %s",
			gnutls_strerror(ret));
		exit(1);
	}
	gnutls_system_key_iter_deinit(iter);
	fputs("\n", out);
}