• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // This file was extracted from the TCG Published
2 // Trusted Platform Module Library
3 // Part 3: Commands
4 // Family "2.0"
5 // Level 00 Revision 01.16
6 // October 30, 2014
7 
8 #include "InternalRoutines.h"
9 #include "Attest_spt_fp.h"
10 #include "Certify_fp.h"
11 //
12 //
13 //     Error Returns               Meaning
14 //
15 //     TPM_RC_KEY                  key referenced by signHandle is not a signing key
16 //     TPM_RC_SCHEME               inScheme is not compatible with signHandle
17 //     TPM_RC_VALUE                digest generated for inScheme is greater or has larger size than the
18 //                                 modulus of signHandle, or the buffer for the result in signature is too
19 //                                 small (for an RSA key); invalid commit status (for an ECC key with a
20 //                                 split scheme).
21 //
22 TPM_RC
TPM2_Certify(Certify_In * in,Certify_Out * out)23 TPM2_Certify(
24    Certify_In      *in,             // IN: input parameter list
25    Certify_Out     *out             // OUT: output parameter list
26    )
27 {
28    TPM_RC                 result;
29    TPMS_ATTEST            certifyInfo;
30 
31 // Command Output
32 
33    // Filling in attest information
34    // Common fields
35    result = FillInAttestInfo(in->signHandle,
36                              &in->inScheme,
37                              &in->qualifyingData,
38                              &certifyInfo);
39    if(result != TPM_RC_SUCCESS)
40    {
41        if(result == TPM_RC_KEY)
42            return TPM_RC_KEY + RC_Certify_signHandle;
43        else
44            return RcSafeAddToResult(result, RC_Certify_inScheme);
45    }
46    // Certify specific fields
47    // Attestation type
48    certifyInfo.type = TPM_ST_ATTEST_CERTIFY;
49    // Certified object name
50    certifyInfo.attested.certify.name.t.size =
51        ObjectGetName(in->objectHandle,
52                      &certifyInfo.attested.certify.name.t.name);
53    // Certified object qualified name
54    ObjectGetQualifiedName(in->objectHandle,
55                           &certifyInfo.attested.certify.qualifiedName);
56 
57    // Sign attestation structure. A NULL signature will be returned if
58    // signHandle is TPM_RH_NULL. A TPM_RC_NV_UNAVAILABLE, TPM_RC_NV_RATE,
59    // TPM_RC_VALUE, TPM_RC_SCHEME or TPM_RC_ATTRIBUTES error may be returned
60    // by SignAttestInfo()
61    result = SignAttestInfo(in->signHandle,
62                            &in->inScheme,
63                            &certifyInfo,
64                            &in->qualifyingData,
65                            &out->certifyInfo,
66                            &out->signature);
67 
68    // TPM_RC_ATTRIBUTES cannot be returned here as FillInAttestInfo would already
69    // have returned TPM_RC_KEY
70    pAssert(result != TPM_RC_ATTRIBUTES);
71 
72    if(result != TPM_RC_SUCCESS)
73        return result;
74 
75    // orderly state should be cleared because of the reporting of clock info
76    // if signing happens
77    if(in->signHandle != TPM_RH_NULL)
78        g_clearOrderly = TRUE;
79 
80    return TPM_RC_SUCCESS;
81 }
82