Exemple #1
0
/* Dialog procedure for the property sheet.  This will run under the
   UI thread when a property sheet is being displayed for one of our
   credentials.. */
INT_PTR CALLBACK
pp_cred_dlg_proc(HWND hwnd,
                 UINT uMsg,
                 WPARAM wParam,
                 LPARAM lParam) {

    khui_property_sheet * ps;

    switch (uMsg) {
    case WM_INITDIALOG:
        {
            PROPSHEETPAGE * p;
            wchar_t notavailable[128];

            p = (PROPSHEETPAGE *) lParam;
            ps = (khui_property_sheet *) p->lParam;

#pragma warning(push)
#pragma warning(disable: 4244)
            SetWindowLongPtr(hwnd, DWLP_USER, (LONG_PTR) ps);
#pragma warning(pop)

            if (ps->cred) {
                wchar_t tbuf[512];
                khm_size cb;
                khm_handle ident = NULL;

                LoadString(hResModule, IDS_NOTAVAILABLE,
                           notavailable, ARRAYLENGTH(notavailable));

                cb = sizeof(tbuf);
                if (KHM_SUCCEEDED(kcdb_cred_get_attr_string(ps->cred,
                                                            attr_id_subj_email,
                                                            tbuf,
                                                            &cb,
                                                            KCDB_TS_LONG))) {
                    SetDlgItemText(hwnd, IDC_PP_SUBJ_E, tbuf);
                } else {
                    SetDlgItemText(hwnd, IDC_PP_SUBJ_E, notavailable);
                }

                cb = sizeof(tbuf);
                if (KHM_SUCCEEDED(kcdb_cred_get_attr_string(ps->cred,
                                                            attr_id_subj_display,
                                                            tbuf,
                                                            &cb,
                                                            KCDB_TS_LONG))) {
                    SetDlgItemText(hwnd, IDC_PP_SUBJ_D, tbuf);
                } else {
                    SetDlgItemText(hwnd, IDC_PP_SUBJ_D, notavailable);
                }

                cb = sizeof(tbuf);
                if (KHM_SUCCEEDED(kcdb_cred_get_attr_string(ps->cred,
                                                            attr_id_auth_realm,
                                                            tbuf,
                                                            &cb,
                                                            KCDB_TS_LONG))) {
                    SetDlgItemText(hwnd, IDC_PP_REALM, tbuf);
                } else {
                    SetDlgItemText(hwnd, IDC_PP_REALM, notavailable);
                }

                cb = sizeof(tbuf);
                if (KHM_SUCCEEDED(kcdb_cred_get_attr_string(ps->cred,
                                                            attr_id_issuer_display,
                                                            tbuf,
                                                            &cb,
                                                            KCDB_TS_LONG))) {
                    SetDlgItemText(hwnd, IDC_PP_ISSUER, tbuf);
                } else {
                    SetDlgItemText(hwnd, IDC_PP_ISSUER, notavailable);
                }

                cb = sizeof(tbuf);
                if (KHM_SUCCEEDED(kcdb_cred_get_attr_string(ps->cred,
                                                            KCDB_ATTR_ISSUE,
                                                            tbuf,
                                                            &cb,
                                                            KCDB_TS_LONG))) {
                    SetDlgItemText(hwnd, IDC_PP_NOTBEFORE, tbuf);
                } else {
                    SetDlgItemText(hwnd, IDC_PP_NOTBEFORE, notavailable);
                }

                cb = sizeof(tbuf);
                if (KHM_SUCCEEDED(kcdb_cred_get_attr_string(ps->cred,
                                                            KCDB_ATTR_EXPIRE,
                                                            tbuf,
                                                            &cb,
                                                            KCDB_TS_LONG))) {
                    SetDlgItemText(hwnd, IDC_PP_NOTAFTER, tbuf);
                } else {
                    SetDlgItemText(hwnd, IDC_PP_NOTAFTER, notavailable);
                }

            } else {
#ifdef DEBUG
                /* we really shouldn't get here */
                DebugBreak();
#endif
            }
        }
        return FALSE;

    case WM_COMMAND:
        {
            HCERTSTORE     hStoreHandle = NULL;
            PCCERT_CONTEXT pCertContext = NULL;
            CERT_ID        certId;
            BYTE           sn_buf[1024];
            BYTE           issuer_buf[1024];
            CRYPTUI_VIEWCERTIFICATE_STRUCT vcs;
            wchar_t title_fmt[128];
            wchar_t cert_name[128];
            wchar_t title[256];
            BOOL b;

            khm_size       cb;

            if (wParam != MAKEWPARAM(IDC_PP_DETAILS, BN_CLICKED))
                break;

            ps = (khui_property_sheet *) GetWindowLongPtr(hwnd, DWLP_USER);

            if (ps == NULL || ps->cred == NULL) {
#ifdef DEBUG
                DebugBreak();
#endif
                break;
            }

            /* we need to display the standard UI for this certificate */

            ZeroMemory(&certId, sizeof(certId));

            cb = sizeof(sn_buf);
            if (KHM_FAILED(kcdb_cred_get_attr(ps->cred, attr_id_serial_number,
                                              NULL, sn_buf, &cb))) {
                break;
            }

            certId.IssuerSerialNumber.SerialNumber.cbData = (DWORD)cb;
            certId.IssuerSerialNumber.SerialNumber.pbData = sn_buf;

            cb = sizeof(issuer_buf);
            if (KHM_FAILED(kcdb_cred_get_attr(ps->cred, attr_id_issuer_name,
                                              NULL, issuer_buf, &cb))) {
                break;
            }

            certId.IssuerSerialNumber.Issuer.cbData = (DWORD)cb;
            certId.IssuerSerialNumber.Issuer.pbData = issuer_buf;

            certId.dwIdChoice = CERT_ID_ISSUER_SERIAL_NUMBER;

            if (!(hStoreHandle = CertOpenSystemStore(0, WIN32MYCERT_STORE))) {
                log_printf("Unable to access the system store");
                return TRUE;
            }

            pCertContext = CertFindCertificateInStore(hStoreHandle,
                                                      X509_ASN_ENCODING | PKCS_7_ASN_ENCODING,
                                                      0,
                                                      CERT_FIND_CERT_ID,
                                                      &certId,
                                                      NULL);

            if (!pCertContext) {
                /* the certificate was not found */
                EnableWindow(GetDlgItem(hwnd, IDC_PP_DETAILS), FALSE);
                goto _clean_dt;
            }

            ZeroMemory(&vcs, sizeof(vcs));

            vcs.dwSize = sizeof(vcs);
            vcs.hwndParent = hwnd;
            vcs.dwFlags = 0;

            LoadString(hResModule, IDS_PP_TITLE,
                       title_fmt, ARRAYLENGTH(title_fmt));
            cb = sizeof(cert_name);
            if (KHM_FAILED(kcdb_cred_get_attr(ps->cred, attr_id_auth_realm,
                                              NULL, cert_name, &cb))) {
                cb = sizeof(cert_name);
                if (KHM_FAILED(kcdb_cred_get_attr(ps->cred, attr_id_subj_email,
                                                  NULL, cert_name, &cb))) {
                    cb = sizeof(cert_name);
                    kcdb_get_resource(ps->cred, KCDB_RES_DISPLAYNAME, 0, NULL, NULL,
                                      cert_name, &cb);
                }
            }
            StringCbPrintf(title, sizeof(title), title_fmt, cert_name);

            vcs.szTitle = title;

            vcs.pCertContext = pCertContext;

            CryptUIDlgViewCertificate(&vcs, &b);


        _clean_dt:

            if (pCertContext) {
                CertFreeCertificateContext(pCertContext);
                pCertContext = NULL;
            }

            if (hStoreHandle) {
                CertCloseStore(hStoreHandle, 0);
                hStoreHandle = NULL;
            }

            return TRUE;
        }
        break;
    }

    return FALSE;
}
static void
refresh_identity_config_panels(void) {
    khm_handle ident = NULL;
    kcdb_enumeration e = NULL;

    khui_config_node cfg_iter = NULL;
    khui_config_node cfg_ids = NULL;

    if (KHM_FAILED(khui_cfg_open(NULL, L"KhmIdentities", &cfg_ids)))
        goto _cleanup;

    if (KHM_FAILED(kcdb_identity_begin_enum(KCDB_IDENT_FLAG_CONFIG,
                                            KCDB_IDENT_FLAG_CONFIG,
                                            &e, NULL)))
        goto _done_adding;

    while (KHM_SUCCEEDED(kcdb_enum_next(e, &ident))) {
        khui_config_node cfg_id;
        wchar_t cfgname[KCDB_MAXCCH_NAME];
        khm_size cb;

        cb = sizeof(cfgname);
        if (KHM_FAILED(kcdb_identity_get_short_name(ident, FALSE, cfgname, &cb)))
            continue;

        if (KHM_SUCCEEDED(khui_cfg_open(cfg_ids, cfgname, &cfg_id))) {
            /* it's already there */
            khui_cfg_release(cfg_id);
            continue;
        } else {
            khui_config_node_reg reg;
            wchar_t wshort[KHUI_MAXCCH_SHORT_DESC];
            wchar_t wlong[KHUI_MAXCCH_LONG_DESC];

            wchar_t wfmt[KHUI_MAXCCH_NAME];
            wchar_t widname[KHUI_MAXCCH_SHORT_DESC];
            khm_size cb;

            ZeroMemory(&reg, sizeof(reg));

            reg.name = cfgname;
            reg.short_desc = wshort;
            reg.long_desc = wlong;
            reg.h_module = khm_hInstance;
            reg.dlg_template = MAKEINTRESOURCE(IDD_CFG_IDENTITY);
            reg.dlg_proc = khm_cfg_identity_proc;
            reg.flags = 0;

            cb = sizeof(widname);
            kcdb_get_resource(ident, KCDB_RES_DISPLAYNAME, KCDB_RFS_SHORT,
                              NULL, NULL, widname, &cb);

            LoadString(khm_hInstance, IDS_CFG_IDENTITY_SHORT,
                       wfmt, ARRAYLENGTH(wfmt));
            StringCbPrintf(wshort, sizeof(wshort), wfmt, widname);

            LoadString(khm_hInstance, IDS_CFG_IDENTITY_LONG,
                       wfmt, ARRAYLENGTH(wfmt));
            StringCbPrintf(wlong, sizeof(wlong), wfmt, widname);

            khui_cfg_register(cfg_ids, &reg);

            if (KHM_SUCCEEDED(khui_cfg_open(cfg_ids, cfgname, &cfg_id))) {
                khui_cfg_set_data(cfg_id, ident);
                kcdb_identity_hold(ident);
                khui_cfg_release(cfg_id);
            }
        }
    } /* while enumerating through e */

    kcdb_enum_end(e);

 _done_adding:

    for (khui_cfg_get_first_child(cfg_ids, &cfg_iter);
         cfg_iter;
         khui_cfg_get_next_release(&cfg_iter)) {

        khm_int32 flags = 0;

        ident = khui_cfg_get_data(cfg_iter);

        if (ident == NULL ||
            KHM_FAILED(kcdb_identity_get_flags(ident, &flags)) ||
            (flags & (KCDB_IDENT_FLAG_ACTIVE|
                      KCDB_IDENT_FLAG_CONFIG)) != (KCDB_IDENT_FLAG_ACTIVE |
                                                   KCDB_IDENT_FLAG_CONFIG)) {
            /* this configuration node needs to be removed */

            if (ident)          /* undo the hold done above for for
                                   configuration node data */
                kcdb_identity_release(ident);
            khui_cfg_set_data(cfg_iter, NULL);
            khui_cfg_remove(cfg_iter);
        }
    }

 _cleanup:
    if (cfg_ids) {
        khui_cfg_release(cfg_ids);
    }
}
Exemple #3
0
KHMEXP khm_int32 KHMAPI
kcdb_cred_comp_generic(khm_handle cred1,
		       khm_handle cred2,
		       void * rock)
{
    kcdb_cred_comp_order * o = (kcdb_cred_comp_order *) rock;
    int i;
    khm_int32 r = 0;
    khm_int32 f1, f2;
    khm_int32 t1, t2;
    khm_int32 pt = KCDB_CREDTYPE_INVALID;

    for(i=0; i<o->nFields; i++) {
        if (o->fields[i].order & KCDB_CRED_COMP_INITIAL_FIRST) {

            if (o->fields[i].attrib == KCDB_ATTR_TYPE_NAME ||
                o->fields[i].attrib == KCDB_ATTR_TYPE) {

                khm_handle id1 = NULL;
                khm_handle id2 = NULL;
                khm_handle idpro = NULL;

                kcdb_cred_get_type(cred1, &t1);
                kcdb_cred_get_type(cred2, &t2);

                if (t1 == t2) {
                    continue;
                } else {
                    kcdb_cred_get_identity(cred1, &id1);
                    kcdb_cred_get_identity(cred2, &id2);

                    if (kcdb_identity_is_equal(id1, id2)) {
                        kcdb_identity_get_identpro(id1, &idpro);
                        kcdb_identpro_get_type(idpro, &pt);

                        if (t1 == pt)
                            r = -1;
                        else if (t2 == pt)
                            r = 1;

                        kcdb_identpro_release(idpro);
                    }

                    kcdb_identity_release(id1);
                    kcdb_identity_release(id2);
                }

            } else {

                kcdb_cred_get_flags(cred1, &f1);
                kcdb_cred_get_flags(cred2, &f2);

                if (((f1 ^ f2) & KCDB_CRED_FLAG_INITIAL) == 0)
                    r = 0;
                else if (f1 & KCDB_CRED_FLAG_INITIAL)
                    r = -1;
                else
                    r = 1;

            }

        } else {
            r = 0;
        }

	if (r == 0 &&
	    (o->fields[i].attrib == KCDB_ATTR_ID_DISPLAY_NAME ||
	     o->fields[i].attrib == KCDB_ATTR_ID)) {
	    khm_handle id1 = NULL;
	    khm_handle id2 = NULL;

	    wchar_t idname1[KCDB_IDENT_MAXCCH_NAME] = L"";
	    wchar_t idname2[KCDB_IDENT_MAXCCH_NAME] = L"";
	    khm_size cb;

	    kcdb_cred_get_identity(cred1, &id1);
	    kcdb_cred_get_identity(cred2, &id2);

	    r = (((cb = sizeof(idname1)) &&

		  KHM_SUCCEEDED(kcdb_get_resource(id1, KCDB_RES_DISPLAYNAME,
						  0, NULL, NULL, idname1, &cb)) &&

		  (cb = sizeof(idname2)) &&

		  KHM_SUCCEEDED(kcdb_get_resource(id2, KCDB_RES_DISPLAYNAME,
						  0, NULL, NULL, idname2, &cb)))?

		 _wcsicmp(idname1, idname2) : 0);

	    kcdb_identity_release(id1);
	    kcdb_identity_release(id2);
	}

        if (r == 0)
            r = kcdb_creds_comp_attr(cred1,cred2,o->fields[i].attrib);

        if(r != 0) {
            if(o->fields[i].order & KCDB_CRED_COMP_DECREASING)
                r = -r;
            break;
        }
    }

    return r;
}