/* * Copyright (C) 2013 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include #include "drm/DrmAPI.h" #include "hardware/CryptoAPI.h" extern "C" { android::DrmFactory *createDrmFactory(); android::CryptoFactory *createCryptoFactory(); } namespace android { class MockDrmFactory : public DrmFactory { public: MockDrmFactory() {} virtual ~MockDrmFactory() {} bool isCryptoSchemeSupported(const uint8_t uuid[16]); bool isContentTypeSupported(const String8 &mimeType); status_t createDrmPlugin(const uint8_t uuid[16], DrmPlugin **plugin); }; class MockCryptoFactory : public CryptoFactory { public: MockCryptoFactory() {} virtual ~MockCryptoFactory() {} bool isCryptoSchemeSupported(const uint8_t uuid[16]) const; status_t createPlugin( const uint8_t uuid[16], const void *data, size_t size, CryptoPlugin **plugin); }; class MockDrmPlugin : public DrmPlugin { public: MockDrmPlugin() {} virtual ~MockDrmPlugin() {} // from DrmPlugin status_t openSession(Vector &sessionId); status_t closeSession(Vector const &sessionId); status_t getKeyRequest(Vector const &sessionId, Vector const &initData, String8 const &mimeType, KeyType keyType, KeyedVector const &optionalParameters, Vector &request, String8 &defaultUrl, KeyRequestType *keyRequestType); status_t provideKeyResponse(Vector const &sessionId, Vector const &response, Vector &keySetId); status_t removeKeys(Vector const &keySetId); status_t restoreKeys(Vector const &sessionId, Vector const &keySetId); status_t queryKeyStatus(Vector const &sessionId, KeyedVector &infoMap) const; status_t getProvisionRequest(String8 const &certType, String8 const &certAuthority, Vector &request, String8 &defaultUrl); status_t provideProvisionResponse(Vector const &response, Vector &certificate, Vector &wrappedKey); status_t getSecureStops(List > &secureStops); status_t getSecureStop(Vector const &ssid, Vector &secureStop); status_t releaseSecureStops(Vector const &ssRelease); status_t releaseAllSecureStops(); status_t getPropertyString(String8 const &name, String8 &value ) const; status_t getPropertyByteArray(String8 const &name, Vector &value ) const; status_t setPropertyString(String8 const &name, String8 const &value ); status_t setPropertyByteArray(String8 const &name, Vector const &value ); status_t setCipherAlgorithm(Vector const &sessionId, String8 const &algorithm); status_t setMacAlgorithm(Vector const &sessionId, String8 const &algorithm); status_t encrypt(Vector const &sessionId, Vector const &keyId, Vector const &input, Vector const &iv, Vector &output); status_t decrypt(Vector const &sessionId, Vector const &keyId, Vector const &input, Vector const &iv, Vector &output); status_t sign(Vector const &sessionId, Vector const &keyId, Vector const &message, Vector &signature); status_t verify(Vector const &sessionId, Vector const &keyId, Vector const &message, Vector const &signature, bool &match); status_t signRSA(Vector const &sessionId, String8 const &algorithm, Vector const &message, Vector const &wrappedKey, Vector &signature); private: String8 vectorToString(Vector const &vector) const; String8 arrayToString(uint8_t const *array, size_t len) const; String8 stringMapToString(KeyedVector map) const; SortedVector > mSessions; SortedVector > mKeySets; static const ssize_t kNotFound = -1; ssize_t findSession(Vector const &sessionId) const; ssize_t findKeySet(Vector const &keySetId) const; Mutex mLock; KeyedVector mStringProperties; KeyedVector > mByteArrayProperties; }; class MockCryptoPlugin : public CryptoPlugin { bool requiresSecureDecoderComponent(const char *mime) const; ssize_t decrypt(bool secure, const uint8_t key[16], const uint8_t iv[16], Mode mode, const Pattern &pattern, const void *srcPtr, const SubSample *subSamples, size_t numSubSamples, void *dstPtr, AString *errorDetailMsg); private: String8 subSamplesToString(CryptoPlugin::SubSample const *subSamples, size_t numSubSamples) const; String8 arrayToString(uint8_t const *array, size_t len) const; }; };