IBR-DTN  1.0.0
SecurityKeyManager.h
Go to the documentation of this file.
1 /*
2  * SecurityKeyManager.h
3  *
4  * Copyright (C) 2011 IBR, TU Braunschweig
5  *
6  * Written-by: Johannes Morgenroth <morgenroth@ibr.cs.tu-bs.de>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21 
22 #ifndef SECURITYKEYMANAGER_H_
23 #define SECURITYKEYMANAGER_H_
24 
25 #include "Configuration.h"
27 #include <ibrdtn/data/EID.h>
29 #include <ibrdtn/data/SDNV.h>
30 #include <ibrcommon/data/File.h>
31 #include <iostream>
32 
33 namespace dtn
34 {
35  namespace security
36  {
38  {
39  static const std::string TAG;
40 
41  public:
42  class PathNotFoundException : public ibrcommon::Exception
43  {
44  public:
45  PathNotFoundException(std::string what = "No security path configured.") : ibrcommon::Exception(what)
46  {};
47 
48  virtual ~PathNotFoundException() throw() {};
49  };
50 
52 
53  virtual ~SecurityKeyManager();
54 
58  virtual void onConfigurationChanged(const dtn::daemon::Configuration &conf) throw ();
59 
64 
69 
74 
78  void store(const dtn::security::SecurityKey &key, const std::string &data);
79 
83  void store(const std::string &prefix, const dtn::security::SecurityKey &key, const std::string &data);
84 
88  void store(const dtn::security::SecurityKey &key);
89 
93  const ibrcommon::File getKeyFile(const std::string &prefix, const dtn::data::EID &peer, const dtn::security::SecurityKey::KeyType type = dtn::security::SecurityKey::KEY_UNSPEC) const;
94 
98  const ibrcommon::File getKeyFile(const dtn::data::EID &peer, const dtn::security::SecurityKey::KeyType type = dtn::security::SecurityKey::KEY_UNSPEC) const;
99 
103  const ibrcommon::File getFilePath(const std::string &keyword, const std::string &extension) const;
104 
108  void remove(const SecurityKey &key);
109 
110  private:
112 
116  static const std::string hash(const dtn::data::EID &eid);
117 
121  static const std::string hash(const std::string &value);
122 
126  void createRSA(const dtn::data::EID &ref, const int bits = 2048);
127 
131  void load(dtn::security::SecurityKey &key) const;
132 
133  ibrcommon::File _path;
134  ibrcommon::File _ca;
135  ibrcommon::File _key;
136  };
137  }
138 }
139 
140 #endif /* SECURITYKEYMANAGER_H_ */
static SecurityKeyManager & getInstance()
const ibrcommon::File getKeyFile(const std::string &prefix, const dtn::data::EID &peer, const dtn::security::SecurityKey::KeyType type=dtn::security::SecurityKey::KEY_UNSPEC) const
const ibrcommon::File getFilePath(const std::string &keyword, const std::string &extension) const
PathNotFoundException(std::string what="No security path configured.")
bool hasKey(const dtn::data::EID &ref, const dtn::security::SecurityKey::KeyType type=dtn::security::SecurityKey::KEY_UNSPEC) const
void store(const dtn::security::SecurityKey &key, const std::string &data)
virtual void onConfigurationChanged(const dtn::daemon::Configuration &conf)