Skip to content

Commit

Permalink
Checking test certificate while installing vhci
Browse files Browse the repository at this point in the history
usbip.exe install command can present more user-friendly error message
if usbip_test.pfx is not installed.
  • Loading branch information
cezanne committed Jul 19, 2021
1 parent 722001b commit 131894a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
14 changes: 14 additions & 0 deletions userspace/lib/usbip_pki_sign.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,17 @@ sign_file(LPCSTR subject, LPCSTR fpath)

return ret;
}

BOOL
has_certificate(LPCSTR subject)
{
PCCERT_CONTEXT pCertContext;
HCERTSTORE hCertStore;

pCertContext = load_cert_context(subject, &hCertStore);
if (pCertContext == NULL)
return FALSE;
CertFreeCertificateContext(pCertContext);
CertCloseStore(hCertStore, 0);
return TRUE;
}
12 changes: 11 additions & 1 deletion userspace/src/usbip/usbip_install.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,15 +198,22 @@ uninstall_driver_package(drv_info_t *pinfo)
return TRUE;
}

extern BOOL has_certificate(LPCSTR subject);

static int
install_driver_package(drv_info_t *pinfo)
{
char *inf_path;
int res = 0;

if (!has_certificate("USBIP Test")) {
dbg("USBIP Test certificate not found");
return ERR_CERTIFICATE;
}

inf_path = get_source_inf_path(pinfo);
if (inf_path == NULL)
return FALSE;
return ERR_GENERAL;

if (!SetupCopyOEMInf(inf_path, NULL, SPOST_PATH, 0, NULL, 0, NULL, NULL)) {
DWORD err = GetLastError();
Expand Down Expand Up @@ -373,6 +380,9 @@ install_vhci(int type)
case ERR_ACCESS:
err("access denied: make sure you are running as administrator");
break;
case ERR_CERTIFICATE:
err("\"USBIP Test\" certificate not found. Please install first!");
break;
default:
err("cannot install %s driver package", pinfo->name);
}
Expand Down

0 comments on commit 131894a

Please sign in to comment.