1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef KEYSTORE_KEYSTORE_ATTESTATION_ID_H_ 18 #define KEYSTORE_KEYSTORE_ATTESTATION_ID_H_ 19 20 #include <utils/Errors.h> 21 #include <vector> 22 23 namespace android { 24 namespace security { 25 26 template <typename T> class StatusOr { 27 public: StatusOr(const status_t error)28 StatusOr(const status_t error) : _status(error), _value() {} StatusOr(const T & value)29 StatusOr(const T& value) : _status(NO_ERROR), _value(value) {} StatusOr(T && value)30 StatusOr(T&& value) : _status(NO_ERROR), _value(value) {} 31 32 operator const T&() const { return _value; } 33 operator T&() { return _value; } 34 operator T &&() && { return std::move(_value); } 35 isOk()36 bool isOk() const { return NO_ERROR == _status; } 37 status()38 ::android::status_t status() const { return _status; } 39 value()40 const T& value() const & { return _value; } value()41 T& value() & { return _value; } value()42 T&& value() && { return std::move(_value); } 43 44 private: 45 ::android::status_t _status; 46 T _value; 47 }; 48 49 /** 50 * Gathers the attestation id for the application determined by uid by querying the package manager 51 * As of this writing uids can be shared in android, which is why the asn.1 encoded attestation 52 * application id may contain more than one package info followed by a set of digests of the 53 * packages signing certificates. 54 * 55 * @returns the asn.1 encoded attestation application id or an error code. Check the result with 56 * .isOk() before accessing. 57 */ 58 StatusOr<std::vector<uint8_t>> gather_attestation_application_id(uid_t uid); 59 60 } // namespace security 61 } // namespace android 62 #endif // KEYSTORE_KEYSTORE_ATTESTATION_ID_H_ 63