• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2013 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 DRM_H_
18 
19 #define DRM_H_
20 
21 #include "SharedLibrary.h"
22 
23 #include <media/IDrm.h>
24 #include <media/IDrmClient.h>
25 #include <utils/threads.h>
26 
27 namespace android {
28 
29 struct DrmFactory;
30 struct DrmPlugin;
31 
32 struct Drm : public BnDrm,
33              public IBinder::DeathRecipient,
34              public DrmPluginListener {
35     Drm();
36     virtual ~Drm();
37 
38     virtual status_t initCheck() const;
39 
40     virtual bool isCryptoSchemeSupported(const uint8_t uuid[16], const String8 &mimeType);
41 
42     virtual status_t createPlugin(const uint8_t uuid[16]);
43 
44     virtual status_t destroyPlugin();
45 
46     virtual status_t openSession(Vector<uint8_t> &sessionId);
47 
48     virtual status_t closeSession(Vector<uint8_t> const &sessionId);
49 
50     virtual status_t
51         getKeyRequest(Vector<uint8_t> const &sessionId,
52                       Vector<uint8_t> const &initData,
53                       String8 const &mimeType, DrmPlugin::KeyType keyType,
54                       KeyedVector<String8, String8> const &optionalParameters,
55                       Vector<uint8_t> &request, String8 &defaultUrl);
56 
57     virtual status_t provideKeyResponse(Vector<uint8_t> const &sessionId,
58                                         Vector<uint8_t> const &response,
59                                         Vector<uint8_t> &keySetId);
60 
61     virtual status_t removeKeys(Vector<uint8_t> const &keySetId);
62 
63     virtual status_t restoreKeys(Vector<uint8_t> const &sessionId,
64                                  Vector<uint8_t> const &keySetId);
65 
66     virtual status_t queryKeyStatus(Vector<uint8_t> const &sessionId,
67                                     KeyedVector<String8, String8> &infoMap) const;
68 
69     virtual status_t getProvisionRequest(String8 const &certType,
70                                          String8 const &certAuthority,
71                                          Vector<uint8_t> &request,
72                                          String8 &defaulUrl);
73 
74     virtual status_t provideProvisionResponse(Vector<uint8_t> const &response,
75                                               Vector<uint8_t> &certificate,
76                                               Vector<uint8_t> &wrappedKey);
77 
78     virtual status_t unprovisionDevice();
79 
80     virtual status_t getSecureStops(List<Vector<uint8_t> > &secureStops);
81     virtual status_t getSecureStop(Vector<uint8_t> const &ssid, Vector<uint8_t> &secureStop);
82 
83     virtual status_t releaseSecureStops(Vector<uint8_t> const &ssRelease);
84     virtual status_t releaseAllSecureStops();
85 
86     virtual status_t getPropertyString(String8 const &name, String8 &value ) const;
87     virtual status_t getPropertyByteArray(String8 const &name,
88                                           Vector<uint8_t> &value ) const;
89     virtual status_t setPropertyString(String8 const &name, String8 const &value ) const;
90     virtual status_t setPropertyByteArray(String8 const &name,
91                                           Vector<uint8_t> const &value ) const;
92 
93     virtual status_t setCipherAlgorithm(Vector<uint8_t> const &sessionId,
94                                         String8 const &algorithm);
95 
96     virtual status_t setMacAlgorithm(Vector<uint8_t> const &sessionId,
97                                      String8 const &algorithm);
98 
99     virtual status_t encrypt(Vector<uint8_t> const &sessionId,
100                              Vector<uint8_t> const &keyId,
101                              Vector<uint8_t> const &input,
102                              Vector<uint8_t> const &iv,
103                              Vector<uint8_t> &output);
104 
105     virtual status_t decrypt(Vector<uint8_t> const &sessionId,
106                              Vector<uint8_t> const &keyId,
107                              Vector<uint8_t> const &input,
108                              Vector<uint8_t> const &iv,
109                              Vector<uint8_t> &output);
110 
111     virtual status_t sign(Vector<uint8_t> const &sessionId,
112                           Vector<uint8_t> const &keyId,
113                           Vector<uint8_t> const &message,
114                           Vector<uint8_t> &signature);
115 
116     virtual status_t verify(Vector<uint8_t> const &sessionId,
117                             Vector<uint8_t> const &keyId,
118                             Vector<uint8_t> const &message,
119                             Vector<uint8_t> const &signature,
120                             bool &match);
121 
122     virtual status_t signRSA(Vector<uint8_t> const &sessionId,
123                              String8 const &algorithm,
124                              Vector<uint8_t> const &message,
125                              Vector<uint8_t> const &wrappedKey,
126                              Vector<uint8_t> &signature);
127 
128     virtual status_t setListener(const sp<IDrmClient>& listener);
129 
130     virtual void sendEvent(DrmPlugin::EventType eventType, int extra,
131                            Vector<uint8_t> const *sessionId,
132                            Vector<uint8_t> const *data);
133 
134     virtual void binderDied(const wp<IBinder> &the_late_who);
135 
136 private:
137     mutable Mutex mLock;
138 
139     status_t mInitCheck;
140 
141     sp<IDrmClient> mListener;
142     mutable Mutex mEventLock;
143     mutable Mutex mNotifyLock;
144 
145     sp<SharedLibrary> mLibrary;
146     DrmFactory *mFactory;
147     DrmPlugin *mPlugin;
148 
149     static KeyedVector<Vector<uint8_t>, String8> mUUIDToLibraryPathMap;
150     static KeyedVector<String8, wp<SharedLibrary> > mLibraryPathToOpenLibraryMap;
151     static Mutex mMapLock;
152 
153     void findFactoryForScheme(const uint8_t uuid[16]);
154     bool loadLibraryForScheme(const String8 &path, const uint8_t uuid[16]);
155     void closeFactory();
156 
157 
158     DISALLOW_EVIL_CONSTRUCTORS(Drm);
159 };
160 
161 }  // namespace android
162 
163 #endif  // CRYPTO_H_
164