Print this page
XXXX pkcs11_tpm blithely connects with TCP when it shouldn't.

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/pkcs11/pkcs11_tpm/common/tpm_specific.c
          +++ new/usr/src/lib/pkcs11/pkcs11_tpm/common/tpm_specific.c
↓ open down ↓ 26 lines elided ↑ open up ↑
  27   27  #include <pthread.h>
  28   28  #include <string.h>
  29   29  
  30   30  #include <sys/types.h>
  31   31  #include <sys/stat.h>
  32   32  #include <uuid/uuid.h>
  33   33  #include <fcntl.h>
  34   34  #include <errno.h>
  35   35  #include <pwd.h>
  36   36  #include <syslog.h>
       37 +#include <libscf.h>
  37   38  
  38   39  #include <openssl/rsa.h>
  39   40  
  40   41  #include <tss/platform.h>
  41   42  #include <tss/tss_defines.h>
  42   43  #include <tss/tss_typedef.h>
  43   44  #include <tss/tss_structs.h>
  44   45  #include <tss/tss_error.h>
  45   46  #include <tss/tcs_error.h>
  46   47  #include <tss/tspi.h>
↓ open down ↓ 571 lines elided ↑ open up ↑
 618  619          (void) memcpy(output, random_bytes, bytes);
 619  620          Tspi_Context_FreeMemory(hContext, random_bytes);
 620  621  
 621  622          return (CKR_OK);
 622  623  }
 623  624  
 624  625  TSS_RESULT
 625  626  open_tss_context(TSS_HCONTEXT *pContext)
 626  627  {
 627  628          TSS_RESULT result;
      629 +        char *smf_string;
 628  630  
      631 +        /*
      632 +         * The Tspi_* functions fail if we don't have tcsd running.  Worse,
      633 +         * because Tspi_* uses TCP over localhost, this can accidentally
      634 +         * trigger anti-denial-of-service measures.
      635 +         *
      636 +         * Instead, use SMF to see if tcsd is fully up and running, or if it
      637 +         * exists at all.  If it's not, bail early.
      638 +         */
      639 +        /* XXX KEBE ASKS -> Use a hardwired FMRI string or instance here? */
      640 +        smf_string = smf_get_state("svc:/application/security/tcsd:default");
      641 +        if (smf_string == NULL ||
      642 +            strcmp(smf_string, SCF_STATE_STRING_ONLINE) != 0) {
      643 +                free(smf_string);
      644 +                return (CKR_FUNCTION_FAILED);
      645 +        }
      646 +        free(smf_string);
      647 +
 629  648          if ((result = Tspi_Context_Create(pContext))) {
 630  649                  stlogit("Tspi_Context_Create: 0x%0x - %s",
 631  650                      result, Trspi_Error_String(result));
 632  651                  return (CKR_FUNCTION_FAILED);
 633  652          }
 634  653  
 635  654          if ((result = Tspi_Context_Connect(*pContext, NULL))) {
 636  655                  stlogit("Tspi_Context_Connect: 0x%0x - %s",
 637  656                      result, Trspi_Error_String(result));
 638  657                  Tspi_Context_Close(*pContext);
↓ open down ↓ 1625 lines elided ↑ open up ↑
2264 2283  
2265 2284          if (hPrivateLeafKey != NULL_HKEY) {
2266 2285                  hParentKey = hPrivateRootKey;
2267 2286          } else {
2268 2287                  if ((result = token_load_public_root_key(hContext)))
2269 2288                          return (CKR_FUNCTION_FAILED);
2270 2289  
2271 2290                  hParentKey = hPublicRootKey;
2272 2291          }
2273 2292  
2274      -        *phKey = NULL;
     2293 +        *phKey = (TSS_HKEY)(uintptr_t)NULL;
2275 2294          if (template_attribute_find(key_obj->template, CKA_CLASS,
2276 2295              &attr) == FALSE) {
2277 2296                  return (CKR_TEMPLATE_INCOMPLETE);
2278 2297          }
2279 2298          class = *((CK_ULONG *)attr->pValue);
2280 2299  
2281 2300          rc = template_attribute_find(key_obj->template,
2282 2301              CKA_IBM_OPAQUE, &attr);
2283 2302          /*
2284 2303           * A public key cannot use the OPAQUE data attribute so they
↓ open down ↓ 10 lines elided ↑ open up ↑
2295 2314                      handle, hParentKey, NULL, phKey))) {
2296 2315                          return (rc);
2297 2316                  }
2298 2317          }
2299 2318          /*
2300 2319           * If this is a private key, get the blob and load it in the TPM.
2301 2320           * If it is public, the key is already loaded in software.
2302 2321           */
2303 2322          if (class == CKO_PRIVATE_KEY) {
2304 2323                  /* If we already have a handle, just load it */
2305      -                if (*phKey != NULL) {
     2324 +                if (*phKey != (TSS_HKEY)(uintptr_t)NULL) {
2306 2325                          result = Tspi_Key_LoadKey(*phKey, hParentKey);
2307 2326                          if (result) {
2308 2327                                  stlogit("Tspi_Context_LoadKeyByBlob: "
2309 2328                                      "0x%0x - %s",
2310 2329                                      result, Trspi_Error_String(result));
2311 2330                                  return (CKR_FUNCTION_FAILED);
2312 2331                          }
2313 2332                  } else {
2314 2333                          /* try again to get the CKA_IBM_OPAQUE attr */
2315 2334                          if ((rc = template_attribute_find(key_obj->template,
↓ open down ↓ 523 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX