IBR-DTN  1.0.0
NoneProtocol.cpp
Go to the documentation of this file.
1 /*
2  * NoneProtocol.cpp
3  *
4  * Copyright (C) 2014 IBR, TU Braunschweig
5  *
6  * Written-by: Johannes Morgenroth <morgenroth@ibr.cs.tu-bs.de>
7  * Thomas Schrader <schrader.thomas@gmail.com>
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  */
22 
25 #include "core/BundleCore.h"
26 
27 namespace dtn
28 {
29  namespace security
30  {
32  : KeyExchangeProtocol(manager, 0)
33  {
34  }
35 
37  {
38  }
39 
41  {
42  // prepare request
43  KeyExchangeData request(KeyExchangeData::REQUEST, session);
44 
45  // get local public key
47 
48  // set request parameters
49  request.str(pkey.getData());
50 
51  // send request to the other peer
52  manager.submit(session, request);
53  }
54 
56  {
57  if (data.getAction() == KeyExchangeData::REQUEST)
58  {
59  // write key in tmp file
60  session.putKey(data.str(), SecurityKey::KEY_PUBLIC, SecurityKey::LOW);
61 
62  // prepare response
63  KeyExchangeData response(KeyExchangeData::RESPONSE, session);
64 
65  // get local public key
67 
68  // reply with the own key
69  response.str(pkey.getData());
70 
71  // send bundle to peer
72  manager.submit(session, response);
73 
74  // finish the key-exchange
75  manager.finish(session);
76  }
77  else if (data.getAction() == KeyExchangeData::RESPONSE)
78  {
79  // write key to session
80  session.putKey(data.str(), SecurityKey::KEY_PUBLIC, SecurityKey::LOW);
81 
82  // finish the key-exchange
83  manager.finish(session);
84  }
85  }
86  } /* namespace security */
87 } /* namespace dtn */
static SecurityKeyManager & getInstance()
virtual void begin(KeyExchangeSession &session, KeyExchangeData &data)
static dtn::data::EID local
Definition: BundleCore.h:79
void putKey(const std::string &data, const dtn::security::SecurityKey::KeyType type, const dtn::security::SecurityKey::TrustLevel trust) const
virtual void step(KeyExchangeSession &session, KeyExchangeData &data)
virtual const std::string getData() const
Definition: SecurityKey.cpp:64
NoneProtocol(KeyExchangeManager &manager)
virtual void finish(KeyExchangeSession &session)=0
dtn::security::SecurityKey get(const dtn::data::EID &ref, const dtn::security::SecurityKey::KeyType type=dtn::security::SecurityKey::KEY_UNSPEC) const
virtual void submit(KeyExchangeSession &session, const KeyExchangeData &data)=0