IBR-DTNSuite  0.12
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 #include <openssl/rsa.h>
34 
35 namespace dtn
36 {
37  namespace security
38  {
40  {
41  static const std::string TAG;
42 
43  public:
45  {
46  public:
47  KeyNotFoundException(std::string what = "Requested key not found.") : ibrcommon::Exception(what)
48  {};
49 
50  virtual ~KeyNotFoundException() throw() {};
51  };
52 
54 
55  virtual ~SecurityKeyManager();
56 
60  virtual void onConfigurationChanged(const dtn::daemon::Configuration &conf) throw ();
61 
64  void store(const dtn::data::EID &ref, const std::string &data, const dtn::security::SecurityKey::KeyType type = dtn::security::SecurityKey::KEY_UNSPEC);
65 
66  private:
68 
76  static int read_private_key(const ibrcommon::File &file, RSA ** rsa);
77 
85  static int read_public_key(const ibrcommon::File &file, RSA ** rsa);
86 
87 
88  static const std::string hash(const dtn::data::EID &eid);
89 
90  ibrcommon::File _path;
91  ibrcommon::File _ca;
92  ibrcommon::File _key;
93  };
94  }
95 }
96 
97 #endif /* SECURITYKEYMANAGER_H_ */