47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * CDDL HEADER START
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * The contents of this file are subject to the terms of the
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * Common Development and Distribution License (the "License").
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * You may not use this file except in compliance with the License.
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * or http://www.opensolaris.org/os/licensing.
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * See the License for the specific language governing permissions
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * and limitations under the License.
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * When distributing Covered Code, include this CDDL HEADER in each
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * If applicable, add the following below this CDDL HEADER, with the
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * fields enclosed by brackets "[]" replaced with your own identifying
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * information: Portions Copyright [yyyy] [name of copyright owner]
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * CDDL HEADER END
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * Use is subject to license terms.
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersollprint_usage(char *progname, cmdtable_t cmds[])
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll gettext("usage: %s command args ...\n"), progname);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll gettext("where 'command' is one of the following:\n"));
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll (void) fprintf(stderr, "\t%s %s\n", p->name, p->args);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll /* Set up for i18n/l10n. */
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll#if !defined(TEXT_DOMAIN) /* Should be defined by cc -D. */
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll#define TEXT_DOMAIN "SYS_TEST" /* Use this only if it isn't. */
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll for (p = &commands[0]; p->name != NULL; p++) {
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * Utility functions
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersollprint_bytes(BYTE *bytes, size_t len, int formatted)
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll for (i = 0; i < len; i++) {
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * TSS convenience functions
35494a3df11fa3df46e5b76d62ec74e60a048a1eScott Rotondo /* Print the standard error string and error code. */
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll (void) fprintf(stderr, "%s: %s (0x%0x)\n", msg, err_string, ret);
35494a3df11fa3df46e5b76d62ec74e60a048a1eScott Rotondo /* For a few special cases, add a more verbose error message. */
35494a3df11fa3df46e5b76d62ec74e60a048a1eScott Rotondo gettext("Enable the TPM and restart Solaris.\n"));
35494a3df11fa3df46e5b76d62ec74e60a048a1eScott Rotondo "(svc:/application/security/tcsd) is running.\n"));
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersollget_tpm_capability(TSS_HCONTEXT hContext, TSS_HOBJECT hTPM, UINT32 cap,
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll ret = Tspi_TPM_GetCapability(hTPM, cap, sizeof (subcap),
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll print_error(ret, gettext("Get TPM capability"));
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll gettext("Capability 0x%x returned %u bytes "
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll "(expected %u)\n"), cap, datalen, bufsize);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll ret = Tspi_Context_FreeMemory(hContext, data);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll print_error(ret, gettext("Free capability buffer"));
304d8f901e34de2a80ef006bfa8a8a927d23d56cScott Rotondoset_policy_options(TSS_HPOLICY hPolicy, TSS_FLAG mode, char *prompt,
304d8f901e34de2a80ef006bfa8a8a927d23d56cScott Rotondo ret = Tspi_Policy_SetSecret(hPolicy, mode, secret_len, secret);
304d8f901e34de2a80ef006bfa8a8a927d23d56cScott Rotondo print_error(ret, gettext("Set policy secret"));
304d8f901e34de2a80ef006bfa8a8a927d23d56cScott Rotondo unicode_prompt = Trspi_Native_To_UNICODE((BYTE *)prompt, &len);
304d8f901e34de2a80ef006bfa8a8a927d23d56cScott Rotondo print_error(ret, gettext("Set policy prompt"));
304d8f901e34de2a80ef006bfa8a8a927d23d56cScott Rotondoset_object_policy(TSS_HOBJECT handle, TSS_FLAG mode, char *prompt,
304d8f901e34de2a80ef006bfa8a8a927d23d56cScott Rotondo ret = Tspi_GetPolicyObject(handle, TSS_POLICY_USAGE, &hPolicy);
304d8f901e34de2a80ef006bfa8a8a927d23d56cScott Rotondo print_error(ret, gettext("Get object policy"));
304d8f901e34de2a80ef006bfa8a8a927d23d56cScott Rotondo return (set_policy_options(hPolicy, mode, prompt, secret_len, secret));
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersolltpm_preamble(TSS_HCONTEXT *hContext, TSS_HOBJECT *hTPM)
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll print_error(ret, gettext("Create context"));
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll ret = Tspi_Context_Connect(*hContext, NULL);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll print_error(ret, gettext("Connect context"));
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll ret = Tspi_Context_GetTpmObject(*hContext, hTPM);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll print_error(ret, gettext("Get TPM object"));
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll print_error(ret, gettext("Close context"));