Skip to content

Commit 46d5168

Browse files
committed
[WIP]: TPM Support
1 parent 44f2c73 commit 46d5168

File tree

70 files changed

+6428
-259
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+6428
-259
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Copyright Notice:
3+
* Copyright 2021-2025 DMTF. All rights reserved.
4+
* License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
5+
**/
6+
7+
#ifndef __CRYPTLIB_TPM_H__
8+
#define __CRYPTLIB_TPM_H__
9+
10+
#include <stdbool.h>
11+
12+
bool libspdm_tpm_device_init();
13+
14+
bool libspdm_tpm_get_private_key(void *handle, void **context);
15+
16+
bool libspdm_tpm_get_public_key(void *handle, void **context);
17+
18+
bool libspdm_tpm_get_certificate(void *handle, void **context);
19+
20+
bool libspdm_tpm_dump_certificate(void *context, void **buffer, size_t *size);
21+
22+
#endif

os_stub/cryptlib_openssl/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ target_sources(cryptlib_openssl
4848
pk/x509_pqc.c
4949
rand/rand.c
5050
sys_call/crt_wrapper_host.c
51+
tpm/tpm.c
5152
)
5253

5354
target_compile_options(cryptlib_openssl PRIVATE ${OPENSSL_FLAGS})

os_stub/cryptlib_openssl/pk/ec.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ bool libspdm_ec_set_pub_key(void *ec_context, const uint8_t *public_key,
205205
goto cleanup_ctx;
206206
}
207207

208-
if (evp_pkey_copy_downgraded(&evp_pkey, new_evp_pkey) == 1) {
208+
if (EVP_PKEY_set1_EC_KEY(evp_pkey, EVP_PKEY_get1_EC_KEY(new_evp_pkey)) == 1) {
209209
result = true;
210210
}
211211
EVP_PKEY_free(new_evp_pkey);

os_stub/cryptlib_openssl/pk/x509.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2104,6 +2104,26 @@ bool libspdm_x509_verify_cert_chain(const uint8_t *root_cert, size_t root_cert_l
21042104
return verify_flag;
21052105
}
21062106

2107+
static void dump_hex(const unsigned char *buf, long buflen)
2108+
{
2109+
char buffer[4096];
2110+
const unsigned char *p = buf;
2111+
X509 *cert = d2i_X509(NULL, &p, buflen);
2112+
if (!cert) {
2113+
printf("Not an X.509 cert inside this ASN.1 object.\n");
2114+
return;
2115+
}
2116+
2117+
/* Print certificate */
2118+
BIO *bio = BIO_new(BIO_s_mem());
2119+
X509_print(bio, cert);
2120+
int s = BIO_read(bio, (void*) buffer, sizeof(buffer));
2121+
buffer[s] = '\0';
2122+
printf("ROOT CERT: %s\n", buffer);
2123+
X509_free(cert);
2124+
}
2125+
2126+
21072127
/**
21082128
* Get one X509 certificate from cert_chain.
21092129
*
@@ -2172,6 +2192,7 @@ bool libspdm_x509_get_cert_from_cert_chain(const uint8_t *cert_chain,
21722192
if (current_index == cert_index) {
21732193
*cert = current_cert;
21742194
*cert_length = current_cert_len;
2195+
dump_hex((const unsigned char*) *cert, (long) *cert_length);
21752196
return true;
21762197
}
21772198

0 commit comments

Comments
 (0)