_("This version of OpenConnect was built without TPM support\n"));
return -EINVAL;
#else
- ret = load_tpm1_key(vpninfo, &fdata, &pkey, &pkey_sig);
+ ret = load_tpm1_key(vpninfo, &fdata, password, &pkey, &pkey_sig);
if (ret)
goto out;
}
int load_tpm1_key(struct openconnect_info *vpninfo, gnutls_datum_t *fdata,
+ const char *password,
gnutls_privkey_t *pkey, gnutls_datum_t *pkey_sig)
{
static const TSS_UUID SRK_UUID = TSS_UUID_SRK;
gnutls_datum_t asn1;
unsigned int tss_len;
char *pass;
+ unsigned int tries;
int ofs, err;
+ if (vpninfo->tpm1) {
+ vpn_progress(vpninfo, PRG_ERR,
+ _("TPM1 is in use.\n"));
+ return -EBUSY;
+ }
+
err = gnutls_pem_base64_decode_alloc("TSS KEY BLOB", fdata, &asn1);
if (err) {
vpn_progress(vpninfo, PRG_ERR,
goto out_srk;
}
- pass = vpninfo->cert_password;
- vpninfo->cert_password = NULL;
- while (1) {
+ pass = NULL;
+ if (password && (pass = strdup(password)) == NULL) {
+ vpn_progress(vpninfo, PRG_ERR,
+ _("Out of memory.\n"));
+ goto out_srk;
+ }
+
+ for (tries = 0; ; tries++) {
static const char nullpass[20];
/* We don't seem to get the error here... */
err = Tspi_Policy_SetSecret(vpninfo->tpm1->srk_policy,
TSS_SECRET_MODE_SHA1,
sizeof(nullpass), (BYTE *)nullpass);
+
+ free_pass(&pass);
+
if (err) {
vpn_progress(vpninfo, PRG_ERR,
_("Failed to set TPM PIN: %s\n"),
goto out_srkpol;
}
- free_pass(&pass);
-
/* ... we get it here instead. */
err = Tspi_Context_LoadKeyByBlob(vpninfo->tpm1->tpm_context, vpninfo->tpm1->srk,
tss_len, asn1.data + ofs,
if (!err)
break;
- if (pass)
+ if (tries > 0 || password)
vpn_progress(vpninfo, PRG_ERR,
_("Failed to load TPM key blob: %s\n"),
Trspi_Error_String(err));