IBR-DTN  1.0.0
QRCodeProtocol.cpp
Go to the documentation of this file.
1 /*
2  * QRCodeProtocol.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 
26 #include "core/BundleCore.h"
27 
28 namespace dtn
29 {
30  namespace security
31  {
33  : KeyExchangeProtocol(manager, 4)
34  {
35  }
36 
38  {
39  }
40 
42  {
43  // get existing security key
45 
46  // get key fingerprint
47  const std::string fingerprint = key.getFingerprint();
48 
49  // prepare a response
50  KeyExchangeData response(KeyExchangeData::COMPLETE, session);
51 
52  if (fingerprint == data.str())
53  {
54  // store existing key with HIGH trust level
55  session.putKey(key.getData(), key.type, SecurityKey::HIGH);
56 
57  // finish the key-exchange
58  manager.finish(session);
59  }
60  else
61  {
62  // signal error
63  throw ibrcommon::Exception("fingerprint is missing");
64  }
65  }
66 
68  {
69  throw ibrcommon::Exception("invalid step");
70  }
71  } /* namespace security */
72 } /* namespace dtn */
static SecurityKeyManager & getInstance()
const dtn::data::EID & getPeer() const
void putKey(const std::string &data, const dtn::security::SecurityKey::KeyType type, const dtn::security::SecurityKey::TrustLevel trust) const
QRCodeProtocol(KeyExchangeManager &manager)
virtual const std::string getData() const
Definition: SecurityKey.cpp:64
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 begin(KeyExchangeSession &session, KeyExchangeData &data)
virtual const std::string getFingerprint() const
virtual void step(KeyExchangeSession &session, KeyExchangeData &data)