Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend key -read and -write functions #279

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,15 @@ To export the public key use:
openssl ec -engine tpm2tss -inform engine -in mykey -pubout -outform pem -out mykey.pub
```

## The TPM Key
The TPM key may be provided as file name, like "mykey" in the examples above.
Additionally, the special file name "-" is supported to read the key from stdin
and write it to stdout after generation.
Providing the key itself instead of the filename is also supported for reading.

This allows engine-users to avoid the use of temporary files with all its
issues and disadvantages (cleanup on error, mktemp()).

## Self Signed certificate generate operation
The following sequence of commands creates self signed certificate using TPM
key. Openssl command sets tpm2tss as engine and generates a self signed
Expand Down
21 changes: 19 additions & 2 deletions src/tpm2-tss-engine-common.c
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,13 @@ tpm2tss_tpm2data_write(const TPM2_DATA *tpm2Data, const char *filename)
uint8_t pubbuf[sizeof(tpm2Data->pub)];
size_t privbuf_len = 0, pubbuf_len = 0;

if ((bio = BIO_new_file(filename, "w")) == NULL) {
if (filename[0] == '-' && filename[1] == 0) {
bio = BIO_new_fp(stdout, BIO_NOCLOSE);
} else {
bio = BIO_new_file(filename, "w");
}

if (bio == NULL) {
ERR(tpm2tss_tpm2data_write, TPM2TSS_R_FILE_WRITE);
goto error;
}
Expand Down Expand Up @@ -349,7 +355,18 @@ tpm2tss_tpm2data_read(const char *filename, TPM2_DATA **tpm2Datap)
char type_oid[64];
BIGNUM *bn_parent;

if ((bio = BIO_new_file(filename, "r")) == NULL) {
if (filename[0] == '-' && filename[1] == 0) {
bio = BIO_new_fp(stdin, BIO_NOCLOSE);
} else {
bio = BIO_new_file(filename, "r");
if (bio == NULL) {
const char *dashes = strstr(filename, "-----BEGIN");
if (dashes)
bio = BIO_new_mem_buf(dashes, strlen(dashes));
}
}

if (bio == NULL) {
ERR(tpm2tss_tpm2data_read, TPM2TSS_R_FILE_READ);
goto error;
}
Expand Down