• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include "TpmBuildSwitches.h"
2 #include <stdlib.h>
3 #include <stdio.h>
4 #include <stdint.h>
5 #include <ctype.h>
6 #include <string.h>
7 #ifdef TPM_WINDOWS
8 #include <windows.h>
9 #include <winsock.h>
10 #endif
11 
12 extern "C" {
13 #include "Implementation.h"	/* kgold */
14 #include "TpmTcpProtocol.h"
15 #include "Manufacture_fp.h"
16 #include "Platform_fp.h"
17 #include "Simulator_fp.h"
18 #ifdef TPM_WINDOWS
19 #include "TcpServer_fp.h"
20 #endif
21 #ifdef TPM_POSIX
22 #include "TcpServerPosix_fp.h"
23 #endif
24 }
25 
LLVMFuzzerTestOneInput(const uint8_t * Data,size_t Size)26 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
27   int pipefd[2];
28 
29   if (Data == NULL || Size == 0) {
30     return 0;
31   }
32 
33   if (pipe(pipefd) == -1) {
34     perror("creating pipe");
35     exit(EXIT_FAILURE);
36   }
37 
38   if (write(pipefd[1], Data, Size) != (ssize_t)Size) {
39     perror("write to pipe");
40     exit(EXIT_FAILURE);
41   }
42 
43   close(pipefd[1]);
44 
45   _plat__NVEnable(NULL);
46   if (TPM_Manufacture(1) != 0) {
47     dprintf(STDERR_FILENO, "[FAILED] manufacturing\n");
48     exit(1);
49   }
50   // Coverage test - repeated manufacturing attempt
51   if (TPM_Manufacture(0) != 1) {
52     dprintf(STDERR_FILENO, "[FAILED] Coverage test - repeated manufacturing attempt\n");
53     exit(2);
54   }
55   // Coverage test - re-manufacturing
56   TPM_TearDown();
57   if (TPM_Manufacture(1) != 0) {
58     dprintf(STDERR_FILENO, "[FAILED] Coverage test - re-manufacturing\n");
59     exit(3);
60   }
61   // Disable NV memory
62   _plat__NVDisable();
63   /* power on the TPM kgold MS simulator comes up powered off */
64   _rpc__Signal_PowerOn(FALSE);
65   _rpc__Signal_NvOn();
66 
67   // From TSS2 MSSIM simulator_setup
68   // tcti_platform_command (tctiContext, MS_SIM_POWER_ON);
69   _rpc__Signal_PowerOn(FALSE);
70   // tcti_platform_command (tctiContext, MS_SIM_NV_ON);
71   _rpc__Signal_NvOn();
72 
73   TpmServer(pipefd[0]);
74 
75   close(pipefd[0]);
76 
77   return 0;
78 }
79