LunaSysMgr
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Security.h
Go to the documentation of this file.
1 /* @@@LICENSE
2 *
3 * Copyright (c) 2009-2012 Hewlett-Packard Development Company, L.P.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 * LICENSE@@@ */
18 
19 
20 
21 
22 #ifndef SECURITY_H
23 #define SECURITY_H
24 
25 #include "Common.h"
26 
27 #include <string>
28 
29 #include <lunaservice.h>
30 
31 #include "cjson/json.h"
32 
33 #include <QObject>
34 #include <QString>
35 
36 class EASPolicy;
37 
38 class Security : public QObject
39 {
40  Q_OBJECT
41 
42 public:
43 
44  static Security* instance();
45  ~Security();
46 
47  bool passcodeSet() const;
48 
49  std::string getLockMode() const { return m_lockMode; };
50 
51  int setPasscode(const std::string& mode, const std::string& passcode, std::string& errorText);
52  bool matchPasscode(std::string passcode, int& retriesLeft, bool& lockedOut);
53 
54  bool passcodeSatisfiesPolicy(const EASPolicy * const policy) const;
55 
56  enum FailureCode {
57  Success = 0,
67  };
68 
69  static bool cbDeviceWipe (LSHandle *sh, LSMessage *message, void *data);
70 private:
71 
72  Security();
73 
74  void registerService();
75 
76  int validatePasscode(const EASPolicy * const policy, const std::string& mode,
77  const std::string& passcode) const;
78  int validateStrength(QString passcode) const;
79 
80  void readLockMode();
81  std::string readPasscode() const;
82  void readDecryptedPasscode(std::string& passcode) const;
83  void safelyEraseString(std::string& str) const;
84 
85  void eraseDevice();
86 
87  static bool keyManagerConnected(LSHandle* handle, LSMessage* msg, void* ctxt);
88  void initKeyManager();
89  void updateKeyManager(const std::string& oldPasscode);
90 
91 private Q_SLOTS:
92 
93  void slotPolicyChanged (const EASPolicy * const policy);
94 
95 private:
96 
97  int m_numRetries;
98  std::string m_lockMode;
99  LSHandle* m_service;
100 };
101 
102 #endif