Kyle Zhang | de0a90b | 2023-06-15 00:16:42 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2023 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 | #define LOG_TAG "DrmRemotelyProvisionedComponent" |
| 18 | #include "DrmRemotelyProvisionedComponent.h" |
| 19 | #include <log/log.h> |
| 20 | |
| 21 | namespace android::mediadrm { |
| 22 | DrmRemotelyProvisionedComponent::DrmRemotelyProvisionedComponent(std::shared_ptr<IDrmPlugin> drm, |
| 23 | std::string drmVendor, |
| 24 | std::string drmDesc) |
| 25 | : mDrm(std::move(drm)), mDrmVendor(std::move(drmVendor)), mDrmDesc(std::move(drmDesc)) {} |
| 26 | ScopedAStatus DrmRemotelyProvisionedComponent::getHardwareInfo(RpcHardwareInfo* info) { |
| 27 | info->versionNumber = 3; |
| 28 | info->rpcAuthorName = mDrmVendor; |
| 29 | info->supportedEekCurve = RpcHardwareInfo::CURVE_NONE; |
| 30 | info->supportedNumKeysInCsr = RpcHardwareInfo::MIN_SUPPORTED_NUM_KEYS_IN_CSR; |
| 31 | info->uniqueId = mDrmDesc; |
| 32 | return ScopedAStatus::ok(); |
| 33 | } |
| 34 | |
| 35 | ScopedAStatus DrmRemotelyProvisionedComponent::generateEcdsaP256KeyPair(bool, MacedPublicKey*, |
| 36 | std::vector<uint8_t>*) { |
| 37 | return ScopedAStatus(AStatus_fromServiceSpecificErrorWithMessage( |
| 38 | IRemotelyProvisionedComponent::STATUS_REMOVED, |
| 39 | "generateEcdsaP256KeyPair not supported.")); |
| 40 | } |
| 41 | |
| 42 | ScopedAStatus DrmRemotelyProvisionedComponent::generateCertificateRequest( |
| 43 | bool, const std::vector<MacedPublicKey>&, const std::vector<uint8_t>&, |
| 44 | const std::vector<uint8_t>&, DeviceInfo*, ProtectedData*, std::vector<uint8_t>*) { |
| 45 | return ScopedAStatus(AStatus_fromServiceSpecificErrorWithMessage( |
| 46 | IRemotelyProvisionedComponent::STATUS_REMOVED, |
| 47 | "generateCertificateRequest not supported.")); |
| 48 | } |
| 49 | |
| 50 | ScopedAStatus DrmRemotelyProvisionedComponent::generateCertificateRequestV2( |
| 51 | const std::vector<MacedPublicKey>&, const std::vector<uint8_t>& challenge, |
| 52 | std::vector<uint8_t>* csr) { |
| 53 | // extract csr using setPropertyByteArray/getPropertyByteArray |
| 54 | auto status = mDrm->setPropertyByteArray("certificateSigningRequestChallenge", challenge); |
| 55 | if (!status.isOk()) { |
| 56 | ALOGE("setPropertyByteArray certificateSigningRequestChallenge failed. Details: [%s].", |
| 57 | status.getDescription().c_str()); |
| 58 | return status; |
| 59 | } |
| 60 | |
| 61 | status = mDrm->getPropertyByteArray("certificateSigningRequest", csr); |
| 62 | if (!status.isOk()) { |
| 63 | ALOGE("getPropertyByteArray certificateSigningRequest failed. Details: [%s].", |
| 64 | status.getDescription().c_str()); |
| 65 | return status; |
| 66 | } |
| 67 | |
| 68 | return ScopedAStatus::ok(); |
| 69 | } |
| 70 | } // namespace android::mediadrm |