Skip to content

Commit c188b0d

Browse files
stefanbergersrajiv
authored andcommitted
Add tools for accessing NVRAM areas
This patch adds 5 tools for accessing and managing NVRAM areas: - tpm_nvdefine - tpm_nvrelease - tpm_nvread - tpm_nvwrite - tpm_nvinfo It uses as many of the same options that have been introduced in other tools and introduces a couple of new ones for providing the owner and NVRAM area password via command line as well as the index, size and permissions of NVRAM areas. v3: - addressing Kent's comments - replaced 0xFFFFFFFF constant with TPM_NV_INDEX_LOCK - allowing TPM_NV_INDEX0 (=0) to be used as a valid index - allowing write sizes of 0 to index 0 v2: - tpm_nvdefine: changed the 'd' short parameter to an 'a' - added --list-only parameter to tpm_nvinfo to only display the defined NVRAM areas' indices - removed initialization values from all static variables - converted parameters and functions from 'int' to 'unsigned int' since no negative values are needed - fixes to functions parsing values - tpm_nvread -i <index> now displays all the content of the NVRAM area without having to give a size Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
1 parent bbe8e7f commit c188b0d

File tree

12 files changed

+1847
-1
lines changed

12 files changed

+1847
-1
lines changed

‎include/tpm_tspi.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,21 @@ TSS_RESULT pcrcompositeSetPcrValue(TSS_HPCRS a_hPcrs, UINT32 a_Idx,
120120
#ifdef TSS_LIB_IS_12
121121
TSS_RESULT unloadVersionInfo(UINT64 *offset, BYTE *blob, TPM_CAP_VERSION_INFO *v);
122122
TSS_RESULT pcrcompositeSetPcrLocality(TSS_HPCRS a_hPcrs, UINT32 localityValue);
123+
124+
TSS_RESULT NVDefineSpace(TSS_HNVSTORE hNVStore,
125+
TSS_HPCRS hReadPcrComposite,
126+
TSS_HPCRS hWritePcrComposite);
127+
128+
TSS_RESULT NVReleaseSpace(TSS_HNVSTORE hNVStore);
129+
130+
TSS_RESULT NVWriteValue(TSS_HNVSTORE hNVStore, UINT32 offset,
131+
UINT32 ulDataLength, BYTE *rgbDataToWrite);
132+
133+
TSS_RESULT NVReadValue(TSS_HNVSTORE hNVStore, UINT32 offset,
134+
UINT32 *ulDataLength, BYTE **rgbDataRead);
135+
136+
TSS_RESULT unloadNVDataPublic(UINT64 *offset, BYTE *blob, UINT32 bloblen,
137+
TPM_NV_DATA_PUBLIC *v);
123138
#endif
124139

125140
#endif

‎include/tpm_utils.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,7 @@ void logGenericOptions( );
110110
void logCmdHelp( const char *a_pszCmd );
111111
void logCmdHelpEx( const char *a_pszCmd, char *a_pszArgs[], char *a_pszArgDescs[] );
112112
char *logBool( BOOL aValue );
113+
void logOwnerPassCmdOption( );
114+
void logNVIndexCmdOption( );
115+
113116
#endif

‎lib/tpm_log.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,16 @@ void logUnicodeCmdOption()
151151
logCmdOption("-u, --unicode", _("Use TSS UNICODE encoding for passwords to comply with applications using TSS popup boxes"));
152152
}
153153

154+
void logOwnerPassCmdOption()
155+
{
156+
logCmdOption("-o, --pwdo", _("Owner password"));
157+
}
158+
159+
void logNVIndexCmdOption()
160+
{
161+
logCmdOption("-i, --index", _("Index of the NVRAM area"));
162+
}
163+
154164
void logCmdHelp(const char *aCmd)
155165
{
156166
logMsg(_("Usage: %s [options]\n"), aCmd);

‎lib/tpm_tspi.c

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,4 +647,71 @@ pcrcompositeSetPcrLocality(TSS_HPCRS a_hPcrs, UINT32 localityValue)
647647

648648
return result;
649649
}
650+
651+
TSS_RESULT
652+
NVDefineSpace(TSS_HNVSTORE hNVStore, TSS_HPCRS hReadPcrComposite ,
653+
TSS_HPCRS hWritePcrComposite)
654+
{
655+
TSS_RESULT result =
656+
Tspi_NV_DefineSpace(hNVStore, hReadPcrComposite,
657+
hWritePcrComposite);
658+
659+
tspiResult("Tspi_NV_DefineSpace", result);
660+
661+
return result;
662+
}
663+
664+
TSS_RESULT
665+
NVReleaseSpace(TSS_HNVSTORE hNVStore)
666+
{
667+
TSS_RESULT result =
668+
Tspi_NV_ReleaseSpace(hNVStore);
669+
670+
tspiResult("Tspi_NV_ReleaseSpace", result);
671+
672+
return result;
673+
}
674+
675+
TSS_RESULT
676+
NVWriteValue(TSS_HNVSTORE hNVStore, UINT32 offset,
677+
UINT32 ulDataLength, BYTE *rgbDataToWrite)
678+
{
679+
TSS_RESULT result =
680+
Tspi_NV_WriteValue(hNVStore, offset,
681+
ulDataLength, rgbDataToWrite);
682+
683+
tspiResult("Tspi_NV_WriteValue", result);
684+
685+
return result;
686+
}
687+
688+
TSS_RESULT
689+
NVReadValue(TSS_HNVSTORE hNVStore, UINT32 offset,
690+
UINT32 *ulDataLength, BYTE **rgbDataRead)
691+
{
692+
TSS_RESULT result =
693+
Tspi_NV_ReadValue(hNVStore, offset,
694+
ulDataLength, rgbDataRead);
695+
696+
tspiResult("Tspi_NV_ReadValue", result);
697+
698+
return result;
699+
}
700+
701+
TSS_RESULT
702+
unloadNVDataPublic(UINT64 *offset, BYTE *blob, UINT32 blob_len, TPM_NV_DATA_PUBLIC *v)
703+
{
704+
UINT64 off = *offset;
705+
TSS_RESULT result;
706+
result = Trspi_UnloadBlob_NV_DATA_PUBLIC(&off, blob, NULL);
707+
if (result == TSS_SUCCESS) {
708+
if (off > blob_len)
709+
return TSS_E_BAD_PARAMETER;
710+
result = Trspi_UnloadBlob_NV_DATA_PUBLIC(offset, blob, v);
711+
}
712+
tspiResult("Trspi_UnloadBlob_NV_DATA_PUBLIC", result);
713+
return result;
714+
}
715+
716+
650717
#endif

‎src/tpm_mgmt/Makefile.am

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,15 @@ sbin_PROGRAMS = tpm_changeownerauth \
3939
tpm_selftest
4040

4141
if TSS_LIB_IS_12
42-
sbin_PROGRAMS += tpm_revokeek tpm_setoperatorauth tpm_resetdalock tpm_restrictsrk
42+
sbin_PROGRAMS += tpm_nvdefine \
43+
tpm_nvinfo \
44+
tpm_nvread \
45+
tpm_nvrelease \
46+
tpm_nvwrite \
47+
tpm_resetdalock \
48+
tpm_restrictsrk \
49+
tpm_revokeek \
50+
tpm_setoperatorauth
4351
AM_CPPFLAGS = -I$(top_srcdir)/include -D_LINUX -DTSS_LIB_IS_12
4452
else
4553
AM_CPPFLAGS = -I$(top_srcdir)/include -D_LINUX
@@ -54,6 +62,11 @@ tpm_changeownerauth_SOURCES = tpm_changeauth.c
5462
tpm_clear_SOURCES = tpm_clear.c
5563
tpm_createek_SOURCES = tpm_createek.c
5664
tpm_getpubek_SOURCES = tpm_getpubek.c
65+
tpm_nvdefine_SOURCES = tpm_nvdefine.c tpm_nvcommon.c
66+
tpm_nvinfo_SOURCES = tpm_nvinfo.c tpm_nvcommon.c
67+
tpm_nvrelease_SOURCES = tpm_nvrelease.c tpm_nvcommon.c
68+
tpm_nvread_SOURCES = tpm_nvread.c tpm_nvcommon.c
69+
tpm_nvwrite_SOURCES = tpm_nvwrite.c tpm_nvcommon.c
5770
tpm_restrictpubek_SOURCES = tpm_restrictpubek.c
5871
tpm_setactive_SOURCES = tpm_activate.c
5972
tpm_setclearable_SOURCES = tpm_clearable.c

0 commit comments

Comments
 (0)