| 1 |
// Copyright (c) 2014, Google LLC All rights reserved. |
| 2 |
// |
| 3 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
// you may not use this file except in compliance with the License. |
| 5 |
// You may obtain a copy of the License at |
| 6 |
// |
| 7 |
// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
// |
| 9 |
// Unless required by applicable law or agreed to in writing, software |
| 10 |
// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
// See the License for the specific language governing permissions and |
| 13 |
// limitations under the License. |
| 14 |
|
| 15 |
package tpm |
| 16 |
|
| 17 |
import ( |
| 18 |
"strconv" |
| 19 |
) |
| 20 |
|
| 21 |
// A tpmError is an error value from the TPM. |
| 22 |
type tpmError uint32 |
| 23 |
|
| 24 |
// Error produces a string for the given TPM Error code |
| 25 |
func (o tpmError) Error() string { |
| 26 |
if s, ok := tpmErrMsgs[o]; ok { |
| 27 |
return "tpm: " + s |
| 28 |
} |
| 29 |
|
| 30 |
return "tpm: unknown error code " + strconv.Itoa(int(o)) |
| 31 |
} |
| 32 |
|
| 33 |
// These are the TPM error codes from the spec. |
| 34 |
const ( |
| 35 |
_ = iota |
| 36 |
errAuthFail tpmError = iota |
| 37 |
errBadIndex |
| 38 |
errBadParameter |
| 39 |
errAuditFailure |
| 40 |
errClearDisabled |
| 41 |
errDeactivated |
| 42 |
errDisabled |
| 43 |
errDisabledCmd |
| 44 |
errFail |
| 45 |
errBadOrdinal |
| 46 |
errInstallDisabled |
| 47 |
errInvalidKeyHandle |
| 48 |
errKeyNotFound |
| 49 |
errInappropriateEnc |
| 50 |
errMigrateFail |
| 51 |
errInvalidPCRInfo |
| 52 |
errNoSpace |
| 53 |
errNoSRK |
| 54 |
errNotSealedBlob |
| 55 |
errOwnerSet |
| 56 |
errResources |
| 57 |
errShortRandom |
| 58 |
errSize |
| 59 |
errWrongPCRVal |
| 60 |
errBadParamSize |
| 61 |
errSHAThread |
| 62 |
errSHAError |
| 63 |
errFailedSelfTest |
| 64 |
errAuth2Fail |
| 65 |
errBadTag |
| 66 |
errIOError |
| 67 |
errEncryptError |
| 68 |
errDecryptError |
| 69 |
errInvalidAuthHandle |
| 70 |
errNoEndorsement |
| 71 |
errInvalidKeyUsage |
| 72 |
errWrongEntityType |
| 73 |
errInvalidPostInit |
| 74 |
errInappropriateSig |
| 75 |
errBadKeyProperty |
| 76 |
errBadMigration |
| 77 |
errBadScheme |
| 78 |
errBadDatasize |
| 79 |
errBadMode |
| 80 |
errBadPresence |
| 81 |
errBadVersion |
| 82 |
errNoWrapTransport |
| 83 |
errAuditFailUnsuccessful |
| 84 |
errAuditFailSuccessful |
| 85 |
errNotResettable |
| 86 |
errNotLocal |
| 87 |
errBadType |
| 88 |
errInvalidResource |
| 89 |
errNotFIPS |
| 90 |
errInvalidFamily |
| 91 |
errNoNVPermission |
| 92 |
errRequiresSign |
| 93 |
errKeyNotSupported |
| 94 |
errAuthConflict |
| 95 |
errAreaLocked |
| 96 |
errBadLocality |
| 97 |
errReadOnly |
| 98 |
errPerNoWrite |
| 99 |
errFamilyCount |
| 100 |
errWriteLocked |
| 101 |
errBadAttributes |
| 102 |
errInvalidStructure |
| 103 |
errKeyOwnerControl |
| 104 |
errBadCounter |
| 105 |
errNotFullWrite |
| 106 |
errContextGap |
| 107 |
errMaxNVWrites |
| 108 |
errNoOperator |
| 109 |
errResourceMissing |
| 110 |
errDelegateLock |
| 111 |
errDelegateFamily |
| 112 |
errDelegateAdmin |
| 113 |
errTransportNotExclusive |
| 114 |
errOwnerControl |
| 115 |
errDAAResources |
| 116 |
errDAAInputData0 |
| 117 |
errDAAInputData1 |
| 118 |
errDAAIssuerSettings |
| 119 |
errDAASettings |
| 120 |
errDAAState |
| 121 |
errDAAIssuerValidity |
| 122 |
errDAAWrongW |
| 123 |
errBadHandle |
| 124 |
errBadDelegate |
| 125 |
errBadContext |
| 126 |
errTooManyContexts |
| 127 |
errMATicketSignature |
| 128 |
errMADestination |
| 129 |
errMASource |
| 130 |
errMAAuthority |
| 131 |
) |
| 132 |
|
| 133 |
// Extra messages the TPM might return. |
| 134 |
const errDefendLockRunning tpmError = 2051 |
| 135 |
|
| 136 |
// tpmErrMsgs maps tpmError codes to their associated error strings. |
| 137 |
var tpmErrMsgs = map[tpmError]string{ |
| 138 |
errAuthFail: "authentication failed", |
| 139 |
errBadIndex: "the index to a PCR, DIR or other register is incorrect", |
| 140 |
errBadParameter: "one or more parameter is bad", |
| 141 |
errAuditFailure: "an operation completed successfully but the auditing of that operation failed", |
| 142 |
errClearDisabled: "the clear disable flag is set and all clear operations now require physical access", |
| 143 |
errDeactivated: "the TPM is deactivated", |
| 144 |
errDisabled: "the TPM is disabled", |
| 145 |
errDisabledCmd: "the target command has been disabled", |
| 146 |
errFail: "the operation failed", |
| 147 |
errBadOrdinal: "the ordinal was unknown or inconsistent", |
| 148 |
errInstallDisabled: "the ability to install an owner is disabled", |
| 149 |
errInvalidKeyHandle: "the key handle can not be interpreted", |
| 150 |
errKeyNotFound: "the key handle points to an invalid key", |
| 151 |
errInappropriateEnc: "unacceptable encryption scheme", |
| 152 |
errMigrateFail: "migration authorization failed", |
| 153 |
errInvalidPCRInfo: "PCR information could not be interpreted", |
| 154 |
errNoSpace: "no room to load key", |
| 155 |
errNoSRK: "there is no SRK set", |
| 156 |
errNotSealedBlob: "an encrypted blob is invalid or was not created by this TPM", |
| 157 |
errOwnerSet: "there is already an Owner", |
| 158 |
errResources: "the TPM has insufficient internal resources to perform the requested action", |
| 159 |
errShortRandom: "a random string was too short", |
| 160 |
errSize: "the TPM does not have the space to perform the operation", |
| 161 |
errWrongPCRVal: "the named PCR value does not match the current PCR value", |
| 162 |
errBadParamSize: "the paramSize argument to the command has the incorrect value", |
| 163 |
errSHAThread: "there is no existing SHA-1 thread", |
| 164 |
errSHAError: "the calculation is unable to proceed because the existing SHA-1 thread has already encountered an error", |
| 165 |
errFailedSelfTest: "self-test has failed and the TPM has shutdown", |
| 166 |
errAuth2Fail: "the authorization for the second key in a 2 key function failed authorization", |
| 167 |
errBadTag: "the tag value sent to for a command is invalid", |
| 168 |
errIOError: "an IO error occurred transmitting information to the TPM", |
| 169 |
errEncryptError: "the encryption process had a problem", |
| 170 |
errDecryptError: "the decryption process had a problem", |
| 171 |
errInvalidAuthHandle: "an invalid handle was used", |
| 172 |
errNoEndorsement: "the TPM does not have an EK installed", |
| 173 |
errInvalidKeyUsage: "the usage of a key is not allowed", |
| 174 |
errWrongEntityType: "the submitted entity type is not allowed", |
| 175 |
errInvalidPostInit: "the command was received in the wrong sequence relative to Init and a subsequent Startup", |
| 176 |
errInappropriateSig: "signed data cannot include additional DER information", |
| 177 |
errBadKeyProperty: "the key properties in KEY_PARAMs are not supported by this TPM", |
| 178 |
errBadMigration: "the migration properties of this key are incorrect", |
| 179 |
errBadScheme: "the signature or encryption scheme for this key is incorrect or not permitted in this situation", |
| 180 |
errBadDatasize: "the size of the data (or blob) parameter is bad or inconsistent with the referenced key", |
| 181 |
errBadMode: "a mode parameter is bad, such as capArea or subCapArea for GetCapability, physicalPresence parameter for PhysicalPresence, or migrationType for CreateMigrationBlob", |
| 182 |
errBadPresence: "either the physicalPresence or physicalPresenceLock bits have the wrong value", |
| 183 |
errBadVersion: "the TPM cannot perform this version of the capability", |
| 184 |
errNoWrapTransport: "the TPM does not allow for wrapped transport sessions", |
| 185 |
errAuditFailUnsuccessful: "TPM audit construction failed and the underlying command was returning a failure code also", |
| 186 |
errAuditFailSuccessful: "TPM audit construction failed and the underlying command was returning success", |
| 187 |
errNotResettable: "attempt to reset a PCR register that does not have the resettable attribute", |
| 188 |
errNotLocal: "attempt to reset a PCR register that requires locality and locality modifier not part of command transport", |
| 189 |
errBadType: "make identity blob not properly typed", |
| 190 |
errInvalidResource: "when saving context identified resource type does not match actual resource", |
| 191 |
errNotFIPS: "the TPM is attempting to execute a command only available when in FIPS mode", |
| 192 |
errInvalidFamily: "the command is attempting to use an invalid family ID", |
| 193 |
errNoNVPermission: "the permission to manipulate the NV storage is not available", |
| 194 |
errRequiresSign: "the operation requires a signed command", |
| 195 |
errKeyNotSupported: "wrong operation to load an NV key", |
| 196 |
errAuthConflict: "NV_LoadKey blob requires both owner and blob authorization", |
| 197 |
errAreaLocked: "the NV area is locked and not writeable", |
| 198 |
errBadLocality: "the locality is incorrect for the attempted operation", |
| 199 |
errReadOnly: "the NV area is read only and can't be written to", |
| 200 |
errPerNoWrite: "there is no protection on the write to the NV area", |
| 201 |
errFamilyCount: "the family count value does not match", |
| 202 |
errWriteLocked: "the NV area has already been written to", |
| 203 |
errBadAttributes: "the NV area attributes conflict", |
| 204 |
errInvalidStructure: "the structure tag and version are invalid or inconsistent", |
| 205 |
errKeyOwnerControl: "the key is under control of the TPM Owner and can only be evicted by the TPM Owner", |
| 206 |
errBadCounter: "the counter handle is incorrect", |
| 207 |
errNotFullWrite: "the write is not a complete write of the area", |
| 208 |
errContextGap: "the gap between saved context counts is too large", |
| 209 |
errMaxNVWrites: "the maximum number of NV writes without an owner has been exceeded", |
| 210 |
errNoOperator: "no operator AuthData value is set", |
| 211 |
errResourceMissing: "the resource pointed to by context is not loaded", |
| 212 |
errDelegateLock: "the delegate administration is locked", |
| 213 |
errDelegateFamily: "attempt to manage a family other than the delegated family", |
| 214 |
errDelegateAdmin: "delegation table management not enabled", |
| 215 |
errTransportNotExclusive: "there was a command executed outside of an exclusive transport session", |
| 216 |
errOwnerControl: "attempt to context save a owner evict controlled key", |
| 217 |
errDAAResources: "the DAA command has no resources available to execute the command", |
| 218 |
errDAAInputData0: "the consistency check on DAA parameter inputData0 has failed", |
| 219 |
errDAAInputData1: "the consistency check on DAA parameter inputData1 has failed", |
| 220 |
errDAAIssuerSettings: "the consistency check on DAA_issuerSettings has failed", |
| 221 |
errDAASettings: "the consistency check on DAA_tpmSpecific has failed", |
| 222 |
errDAAState: "the atomic process indicated by the submitted DAA command is not the expected process", |
| 223 |
errDAAIssuerValidity: "the issuer's validity check has detected an inconsistency", |
| 224 |
errDAAWrongW: "the consistency check on w has failed", |
| 225 |
errBadHandle: "the handle is incorrect", |
| 226 |
errBadDelegate: "delegation is not correct", |
| 227 |
errBadContext: "the context blob is invalid", |
| 228 |
errTooManyContexts: "too many contexts held by the TPM", |
| 229 |
errMATicketSignature: "migration authority signature validation failure", |
| 230 |
errMADestination: "migration destination not authenticated", |
| 231 |
errMASource: "migration source incorrect", |
| 232 |
errMAAuthority: "incorrect migration authority", |
| 233 |
errDefendLockRunning: "the TPM is defending against dictionary attacks and is in some time-out period", |
| 234 |
} |