📄 keydb.h
字号:
// keydb.h// interface to public key database// copyright SafeTP Development Group, Inc., 2000 Terms of use are as specified in license.txt#ifndef __KEYDB_H#define __KEYDB_H#include "socketd.h" // IPAddress#include "typ.h" // boolclass DataBlock; // datablok.h// interface to key policiesclass KeyPolicy {public: // ------ logging actions ------ // 'key' was received from 'addr' virtual void keyReceived(IPAddress addr, DataBlock const &key)=0; // the key we received from 'addr' matched what was stored virtual void keyMatched(IPAddress addr)=0; // ------- policy decisions -------- // what to do when a server key doesn't match what we already have enum MismatchAction { MA_ALLOW_ONCE, // use it, don't store it MA_REJECT, // don't use it MA_REPLACE_THIS, // use it, replace stored key for this addr MA_REPLACE_ALL, // use it, replace all stored keys that match NUM_MISMATCH_ACTIONS }; virtual MismatchAction getMismatchAction( IPAddress addr, DataBlock const &sentKey, DataBlock const &storedKey, int storedKeyCopies, IPAddress const *copyAddrs)=0; // what to do when we encounter a never-before seen server enum NewServerAction { NSA_ACCEPT_ONCE, // use it, don't store it NSA_ACCEPT, // use it, store it NSA_REJECT, // don't use it NUM_NEW_SERVER_ACTIONS }; virtual NewServerAction getNewServerAction( IPAddress addr, DataBlock const &sentKey)=0; // what to do if a server's reported IP address differs from the // address we think we connected to (if it is desired to terminate // the connection, throw xsecurity) virtual void serverIPMismatch(IPAddress ipServerReported, IPAddress ipConnectedTo, DataBlock const &serverKeySent)=0;};// interface to key database:// a dictionary mapping IP addresses to keysclass KeyDB {public: // returns true if we have a key for the given addr virtual bool containsKey(IPAddress addr)=0; // returns the key for that addr; containsKey is a precondition virtual DataBlock getKey(IPAddress addr)=0; // set the key for an addr virtual void setKey(IPAddress addr, DataBlock const &key)=0; // get all addresses that have keys matching the given key; caller // must deallocate the returned array virtual IPAddress *getMatchingAddrs(int &numMatching, DataBlock const &key)=0;};// collect a policy and a databasestruct KeyEnvironment {public: KeyPolicy &policy; KeyDB &db;public: KeyEnvironment(KeyPolicy &p, KeyDB &d) : policy(p), db(d) {}};// called when the server sends a public keyvoid handleServerKey(DataBlock const &brandedPublicKey, IPAddress hostAddress, KeyEnvironment &environment); // brandedPublicKey - public key as server claims it is // hostAddress - host's IP address as we know it // environment - key policy and database // throws: if there is a problem with the key, this function should // throw xSecurity#endif // __KEYDB_H
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -