LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-17-2020, 11:08 PM   #1
abhinav_student
LQ Newbie
 
Registered: Jan 2020
Posts: 10

Rep: Reputation: Disabled
TPM 1.2 getpubek comparison with existing file in system


I am using TPM 1.2 module.

I want to write C code to get public key of that TPM as a file and match it with an existing file in my system.

In linux if we write tpm_getpubek command in CLI, it shows the public key of TPM on terminal.

Help me!
 
Old 01-18-2020, 05:45 PM   #2
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
You could launch the tpm_getpubek command from your C program, redirecting the output to a file. The easiest method should be the system library function, e.g.
Code:
system("tpm_getpubek > somefile");
A cleaner solution is using the trousers software package. The function that corresponds to tpm_getpubek is probably
Tspi_TPM_GetPubEndorsementKey.

Disclaimer: I know close to nothing about TPMs and trousers.
 
Old 01-22-2020, 06:15 AM   #3
abhinav_student
LQ Newbie
 
Registered: Jan 2020
Posts: 10

Original Poster
Rep: Reputation: Disabled
Code modification

Thanks Bernbaush.

I have another question here. In the below code how I can make szTpmPasswd as default instead of user input.
Suppose my password is "abcd1234", how I can make it deafult so that this file can execute automatically. I tried to explicity pass an string to the szTpmPasswd but unable to get my result.

Code :-


#include "tpm_tspi.h"
#include "tpm_utils.h"

static BOOL isWellKnown = FALSE;
TSS_HCONTEXT hContext = 0;

static int parse(const int aOpt, const char *aArg)
{

switch (aOpt) {
case 'z':
logDebug(_("Using TSS_WELL_KNOWN_SECRET to authorize the TPM command\n"));
isWellKnown = TRUE;
break;
default:
return -1;
}
return 0;
}
static void help(const char* aCmd)
{
logCmdHelp(aCmd);
logUnicodeCmdOption();
logCmdOption("-z, --well-known",
_("Use 20 bytes of zeros (TSS_WELL_KNOWN_SECRET) as the TPM secret authorization data"));
}

int main(int argc, char **argv)
{

char *szTpmPasswd = NULL;
int pswd_len;
TSS_RESULT tResult;
TSS_HTPM hTpm;
TSS_HKEY hEk;
TSS_HPOLICY hTpmPolicy;
int iRc = -1;
struct option hOpts[] = {
{"well-known", no_argument, NULL, 'z'},
};
BYTE well_known[] = TSS_WELL_KNOWN_SECRET;

initIntlSys();

if (genericOptHandler
(argc, argv, "z", hOpts,
sizeof(hOpts) / sizeof(struct option), parse, help) != 0)
goto out;

if (contextCreate(&hContext) != TSS_SUCCESS)
goto out;

if (contextConnect(hContext) != TSS_SUCCESS)
goto out_close;

if (contextGetTpm(hContext, &hTpm) != TSS_SUCCESS)
goto out_close;

tResult = tpmGetPubEk(hTpm, FALSE, NULL, &hEk);
if (tResult == TCPA_E_DISABLED_CMD) {
logInfo
(_("Public PubEk access blocked, owner password required\n"));
if (isWellKnown) {
szTpmPasswd = (char *)well_known;
pswd_len = sizeof(well_known);
} else {

// Prompt for owner password
szTpmPasswd = GETPASSWD(_("Enter owner password: "), &pswd_len, FALSE);
if (!szTpmPasswd) {
logMsg(_("Failed to get password\n"));
goto out_close;
}
}

if (policyGet(hTpm, &hTpmPolicy) != TSS_SUCCESS)
goto out_close;

if (policySetSecret
(hTpmPolicy, pswd_len,
(BYTE *)szTpmPasswd) != TSS_SUCCESS)
goto out_close;

tResult = tpmGetPubEk(hTpm, TRUE, NULL, &hEk);
}
if (tResult != TSS_SUCCESS)
goto out_close;

logMsg(_("Public Endorsement Key:\n"));
if (displayKey(hEk) != TSS_SUCCESS)
goto out_close;

iRc = 0;
logSuccess(argv[0]);

out_close:
contextClose(hContext);

out:
if (szTpmPasswd && !isWellKnown)
shredPasswd(szTpmPasswd);

return iRc;
}
 
Old 01-22-2020, 06:21 AM   #4
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
With the caveat that I know close to nothing about trousers and TPMs, I can try to help if you format your code as code.
 
Old 01-22-2020, 06:36 AM   #5
abhinav_student
LQ Newbie
 
Registered: Jan 2020
Posts: 10

Original Poster
Rep: Reputation: Disabled
I am trying to post code with proper indentation but it is not taking.
I will post a text file for this.
Attached Files
File Type: txt t_code.txt (2.2 KB, 12 views)

Last edited by abhinav_student; 01-22-2020 at 06:42 AM.
 
Old 01-22-2020, 07:48 AM   #6
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Sorry, but after looking at your question, I don't understand what you want.

Right now, the default value of szTpmPasswd is TSS_WELL_KNOWN_SECRET. You say you want to set a default password so that the program executes automatically. What do you mean by "automatically"? Normally, a program must be launched by a human or another program to execute.

You also say that you are unable to get your result. What is your result, and what do you get instead of the result?
 
Old 01-25-2020, 03:59 AM   #7
abhinav_student
LQ Newbie
 
Registered: Jan 2020
Posts: 10

Original Poster
Rep: Reputation: Disabled
How to provide well-known(20 bytes 0) value to owner password?

By default it is not taking. For SRK password we can do tpm_takeownership -z command.

I am using tpm-tools and trousers package to configure my TPM.

Last edited by abhinav_student; 01-25-2020 at 04:01 AM.
 
Old 01-25-2020, 05:08 AM   #8
abhinav_student
LQ Newbie
 
Registered: Jan 2020
Posts: 10

Original Poster
Rep: Reputation: Disabled
If possible without using well-known can I pass my own password inside my code? I don want to enter password while execution of the program.
 
Old 01-25-2020, 06:08 AM   #9
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
I suppose you need to change this section:
Code:
		} else {
			// Prompt for owner password
			szTpmPasswd = GETPASSWD(_("Enter owner password: "), &pswd_len, FALSE);
			if (!szTpmPasswd) {
				logMsg(_("Failed to get password\n"));
				goto out_close;
			}
		}
Instead of GETPASSWD, just use a fixed value or an argv value.
 
Old 01-29-2020, 01:13 AM   #10
abhinav_student
LQ Newbie
 
Registered: Jan 2020
Posts: 10

Original Poster
Rep: Reputation: Disabled
Thanks berndbausch.

You provided me a great guidance. Assigning fixed value or an agrv value haven't worked but by making some changes in the header files they worked.

I have one more question, can we compare a system command(for e.g. content of "ifconfig") with an existing file in our system in C program?

If possible could you please help me with the logic?
 
Old 01-29-2020, 03:45 AM   #11
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
What do you mean by "compare"? Do you want to understand if they are equal? If so, one solution would be to use the system call to run the command, redirecting output to a file. Then compare that file to the existing file.
 
Old 01-29-2020, 06:21 AM   #12
abhinav_student
LQ Newbie
 
Registered: Jan 2020
Posts: 10

Original Poster
Rep: Reputation: Disabled
Thank You
 
Old 01-31-2020, 03:30 AM   #13
abhinav_student
LQ Newbie
 
Registered: Jan 2020
Posts: 10

Original Poster
Rep: Reputation: Disabled
Hi,

I have a C program to compare two files(for e.g. "compare.c").

I want to develop a kernel module where I can call this C program("compare.c"). Could you please tell me how to do this. I am new to kernel module.
 
Old 01-31-2020, 04:07 AM   #14
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
I have never written a kernel module, but an internet search comes up with plenty of instructions.
 
Old 01-31-2020, 06:05 AM   #15
abhinav_student
LQ Newbie
 
Registered: Jan 2020
Posts: 10

Original Poster
Rep: Reputation: Disabled
I did the same but unable to filter useful content.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to fix TPM Error in Redhat Linux? samsad Linux - Enterprise 6 02-13-2015 08:38 AM
unlocking USB-attached FDE HDDs - is this possible with TrouSers and tpm-tools? libCognition Linux - Software 0 05-01-2012 06:16 AM
Trying to understand Trusted Computing? TPM module .. ysatxh Linux - Security 4 05-24-2011 03:56 PM
tpm keyring >># make smsoft Linux - Software 2 06-10-2010 10:56 AM
LXer: Linux and the Trusted Platform Module (TPM) LXer Syndicated Linux News 1 09-28-2009 03:00 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:51 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration