aesm_client/
error.rs

1/* Copyright (c) Fortanix, Inc.
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7use std::io::Error as IoError;
8use std::result::Result as StdResult;
9use thiserror::Error as ThisError;
10
11pub type Result<T> = StdResult<T, Error>;
12
13// These numbers are from psw/ae/inc/internal/aesm_error.h and (surprisingly)
14// not from psw/ae/inc/aeerror.h
15#[derive(Debug, Copy, Clone)]
16#[allow(non_camel_case_types)]
17pub enum AesmError {
18    UnexpectedError_1,
19    NoDeviceError_2,
20    ParameterError_3,
21    EpidblobError_4,
22    EpidRevokedError_5,
23    GetLicensetokenError_6,
24    SessionInvalid_7,
25    MaxNumSessionReached_8,
26    PsdaUnavailable_9,
27    EphSessionFailed_10,
28    LongTermPairingFailed_11,
29    NetworkError_12,
30    NetworkBusyError_13,
31    ProxySettingAssist_14,
32    FileAccessError_15,
33    SgxProvisionFailed_16,
34    ServiceStopped_17,
35    Busy_18,
36    BackendServerBusy_19,
37    UpdateAvailable_20,
38    OutOfMemoryError_21,
39    MsgError_22,
40    ThreadError_23,
41    SgxDeviceNotAvailable_24,
42    EnableSgxDeviceFailed_25,
43    PlatformInfoBlobInvalidSig_26,
44    ServiceNotAvailable_27,
45    KdfMismatch_28,
46    OutOfEpc_29,
47    ServiceUnavailable_30,
48    UnrecognizedPlatform_31,
49    EcdsaIdMismatch_32,
50    PathnameBufferOverflow_33,
51    ErrorStoredKey_34,
52    PubKeyIdMismatch_35,
53    InvalidPceSigScheme_36,
54    AttKeyBlobError_37,
55    UnsupportedAttKeyId_38,
56    UnsupportedLoadingPolicy_39,
57    InterfaceUnavailable_40,
58    PlatformLibUnavailable_41,
59    AttKeyNotInitialized_42,
60    AttKeyCertDataInvalid_43,
61    NoPlatformCertData_44,
62    ReportError_45,
63    EnclaveLost_46,
64    InvalidReport_47,
65    EnclaveLoadError_48,
66    UnableToGenerateQeReport_49,
67    KeyCertificationError_50,
68    Unknown(u32),
69}
70
71impl From<u32> for AesmError {
72    fn from(n: u32) -> AesmError {
73        use self::AesmError::*;
74        match n {
75            1 => UnexpectedError_1,
76            2 => NoDeviceError_2,
77            3 => ParameterError_3,
78            4 => EpidblobError_4,
79            5 => EpidRevokedError_5,
80            6 => GetLicensetokenError_6,
81            7 => SessionInvalid_7,
82            8 => MaxNumSessionReached_8,
83            9 => PsdaUnavailable_9,
84            10 => EphSessionFailed_10,
85            11 => LongTermPairingFailed_11,
86            12 => NetworkError_12,
87            13 => NetworkBusyError_13,
88            14 => ProxySettingAssist_14,
89            15 => FileAccessError_15,
90            16 => SgxProvisionFailed_16,
91            17 => ServiceStopped_17,
92            18 => Busy_18,
93            19 => BackendServerBusy_19,
94            20 => UpdateAvailable_20,
95            21 => OutOfMemoryError_21,
96            22 => MsgError_22,
97            23 => ThreadError_23,
98            24 => SgxDeviceNotAvailable_24,
99            25 => EnableSgxDeviceFailed_25,
100            26 => PlatformInfoBlobInvalidSig_26,
101            27 => ServiceNotAvailable_27,
102            28 => KdfMismatch_28,
103            29 => OutOfEpc_29,
104            30 => ServiceUnavailable_30,
105            31 => UnrecognizedPlatform_31,
106            32 => EcdsaIdMismatch_32,
107            33 => PathnameBufferOverflow_33,
108            34 => ErrorStoredKey_34,
109            35 => PubKeyIdMismatch_35,
110            36 => InvalidPceSigScheme_36,
111            37 => AttKeyBlobError_37,
112            38 => UnsupportedAttKeyId_38,
113            39 => UnsupportedLoadingPolicy_39,
114            40 => InterfaceUnavailable_40,
115            41 => PlatformLibUnavailable_41,
116            42 => AttKeyNotInitialized_42,
117            43 => AttKeyCertDataInvalid_43,
118            44 => NoPlatformCertData_44,
119            45 => ReportError_45,
120            46 => EnclaveLost_46,
121            47 => InvalidReport_47,
122            48 => EnclaveLoadError_48,
123            49 => UnableToGenerateQeReport_49,
124            50 => KeyCertificationError_50,
125            _ => Unknown(n),
126        }
127    }
128}
129
130#[derive(ThisError, Debug)]
131pub enum Error {
132    #[error("aesm error code {:?}", _0)]
133    AesmCode(AesmError),
134    #[error("error communicating with aesm")]
135    AesmCommunication(#[source] IoError),
136    #[error("missing expected {} payload in response from aesm", _0)]
137    AesmBadResponse(String),
138    #[error("invalid quote type {}", _0)]
139    InvalidQuoteType(u32),
140    #[error("invalid quote size")]
141    InvalidQuoteSize,
142    #[error("invalid token size")]
143    InvalidTokenSize,
144}
145
146impl From<IoError> for Error {
147    fn from(err: IoError) -> Error {
148        Error::AesmCommunication(err)
149    }
150}
151
152impl Error {
153    pub fn aesm_code(code: u32) -> Error {
154        Error::AesmCode(code.into())
155    }
156
157    pub fn aesm_bad_response(expected: &str) -> Error {
158        Error::AesmBadResponse(expected.to_owned())
159    }
160}