| 1 |
/* Microsoft Reference Implementation for TPM 2.0 |
| 2 |
* |
| 3 |
* The copyright in this software is being made available under the BSD License, |
| 4 |
* included below. This software may be subject to other third party and |
| 5 |
* contributor rights, including patent rights, and no such rights are granted |
| 6 |
* under this license. |
| 7 |
* |
| 8 |
* Copyright (c) Microsoft Corporation |
| 9 |
* |
| 10 |
* All rights reserved. |
| 11 |
* |
| 12 |
* BSD License |
| 13 |
* |
| 14 |
* Redistribution and use in source and binary forms, with or without modification, |
| 15 |
* are permitted provided that the following conditions are met: |
| 16 |
* |
| 17 |
* Redistributions of source code must retain the above copyright notice, this list |
| 18 |
* of conditions and the following disclaimer. |
| 19 |
* |
| 20 |
* Redistributions in binary form must reproduce the above copyright notice, this |
| 21 |
* list of conditions and the following disclaimer in the documentation and/or |
| 22 |
* other materials provided with the distribution. |
| 23 |
* |
| 24 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS"" |
| 25 |
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 26 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 27 |
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR |
| 28 |
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 29 |
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 30 |
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
| 31 |
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 32 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 33 |
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 34 |
*/ |
| 35 |
#include "Tpm.h" |
| 36 |
#include "AC_Send_fp.h" |
| 37 |
#include "AC_spt_fp.h" |
| 38 |
|
| 39 |
|
| 40 |
#if CC_AC_Send // Conditional expansion of this file |
| 41 |
|
| 42 |
/*(See part 3 specification) |
| 43 |
// Duplicate a loaded object |
| 44 |
*/ |
| 45 |
// Return Type: TPM_RC |
| 46 |
// TPM_RC_ATTRIBUTES key to duplicate has 'fixedParent' SET |
| 47 |
// TPM_RC_HASH for an RSA key, the nameAlg digest size for the |
| 48 |
// newParent is not compatible with the key size |
| 49 |
// TPM_RC_HIERARCHY 'encryptedDuplication' is SET and 'newParentHandle' |
| 50 |
// specifies Null Hierarchy |
| 51 |
// TPM_RC_KEY 'newParentHandle' references invalid ECC key (public |
| 52 |
// point not on the curve) |
| 53 |
// TPM_RC_SIZE input encryption key size does not match the |
| 54 |
// size specified in symmetric algorithm |
| 55 |
// TPM_RC_SYMMETRIC 'encryptedDuplication' is SET but no symmetric |
| 56 |
// algorithm is provided |
| 57 |
// TPM_RC_TYPE 'newParentHandle' is neither a storage key nor |
| 58 |
// TPM_RH_NULL; or the object has a NULL nameAlg |
| 59 |
// TPM_RC_VALUE for an RSA newParent, the sizes of the digest and |
| 60 |
// the encryption key are too large to be OAEP encoded |
| 61 |
TPM_RC |
| 62 |
TPM2_AC_Send( |
| 63 |
AC_Send_In *in, // IN: input parameter list |
| 64 |
AC_Send_Out *out // OUT: output parameter list |
| 65 |
) |
| 66 |
{ |
| 67 |
NV_REF locator; |
| 68 |
TPM_HANDLE nvAlias = ((in->ac - AC_FIRST) + NV_AC_FIRST); |
| 69 |
NV_INDEX *nvIndex = NvGetIndexInfo(nvAlias, &locator); |
| 70 |
OBJECT *object = HandleToObject(in->sendObject); |
| 71 |
TPM_RC result; |
| 72 |
// Input validation |
| 73 |
// If there is an NV alias, then the index must allow the authorization provided |
| 74 |
if(nvIndex != NULL) |
| 75 |
{ |
| 76 |
// Common access checks, NvWriteAccessCheck() may return |
| 77 |
// TPM_RC_NV_AUTHORIZATION or TPM_RC_NV_LOCKED |
| 78 |
result = NvWriteAccessChecks(in->authHandle, nvAlias, |
| 79 |
nvIndex->publicArea.attributes); |
| 80 |
if(result != TPM_RC_SUCCESS) |
| 81 |
return result; |
| 82 |
} |
| 83 |
// If 'ac' did not have an alias then the authorization had to be with either |
| 84 |
// platform or owner authorization. The type of TPMI_RH_NV_AUTH only allows |
| 85 |
// owner or platform or an NV index. If it was a valid index, it would have had |
| 86 |
// an alias and be processed above, so only success here is if this is a |
| 87 |
// permanent handle. |
| 88 |
else if(HandleGetType(in->authHandle) != TPM_HT_PERMANENT) |
| 89 |
return TPM_RCS_HANDLE + RC_AC_Send_authHandle; |
| 90 |
// Make sure that the object to be duplicated has the right attributes |
| 91 |
if(IS_ATTRIBUTE(object->publicArea.objectAttributes, |
| 92 |
TPMA_OBJECT, encryptedDuplication) |
| 93 |
|| IS_ATTRIBUTE(object->publicArea.objectAttributes, TPMA_OBJECT, |
| 94 |
fixedParent) |
| 95 |
|| IS_ATTRIBUTE(object->publicArea.objectAttributes, TPMA_OBJECT, fixedTPM)) |
| 96 |
return TPM_RCS_ATTRIBUTES + RC_AC_Send_sendObject; |
| 97 |
// Command output |
| 98 |
// Do the implementation dependent send |
| 99 |
return AcSendObject(in->ac, object, &out->acDataOut); |
| 100 |
} |
| 101 |
|
| 102 |
#endif // TPM_CC_AC_Send |