first check-in of feisty meow codebase. many things broken still due to recent
[feisty_meow.git] / octopi / library / tentacles / encryption_tentacle.h
1 #ifndef ENCRYPTION_TENTACLE_CLASS
2 #define ENCRYPTION_TENTACLE_CLASS
3
4 /*****************************************************************************\
5 *                                                                             *
6 *  Name   : encryption_tentacle                                               *
7 *  Author : Chris Koeritz                                                     *
8 *                                                                             *
9 *******************************************************************************
10 * Copyright (c) 2004-$now By Author.  This program is free software; you can  *
11 * redistribute it and/or modify it under the terms of the GNU General Public  *
12 * License as published by the Free Software Foundation; either version 2 of   *
13 * the License or (at your option) any later version.  This is online at:      *
14 *     http://www.fsf.org/copyleft/gpl.html                                    *
15 * Please send any updates to: fred@gruntose.com                               *
16 \*****************************************************************************/
17
18 #include "encryption_infoton.h"
19
20 #include <octopus/tentacle_helper.h>
21
22 namespace octopi {
23
24 // forward.
25 class key_repository;
26
27 //! Processes the encryption_infoton object for setting up an encrypted channel.
28
29 /*!
30   NOTE:
31       to use encryption, both the client and the server need to have an
32   encryption_tentacle added as a filter.  it should be the first filter
33   added by users and it must be before any security tentacles (otherwise,
34   the security info would not be encrypted).
35   further, an unwrapping_tentacle (see encryption_wrapper.h) must also
36   be added.  it must *not* be added as a filter.  this is what allows the
37   octopus to reconstitute the encoded infotons when encryption is active.
38 */
39
40 class encryption_tentacle
41 : public tentacle_helper<encryption_infoton>
42 {
43 public:
44   encryption_tentacle();
45     //!< this tentacle will implement the server side.
46     /*!< it will expect only to see public keys from clients and to respond
47     with encrypted blowfish keys. */
48
49   encryption_tentacle(const basis::byte_array &rsa_key);
50     //!< this is the client side tentacle.
51     /*!< it will only deal with unwrapping a server's response with the
52     encrypted blowfish key.  the "rsa_key" is the private key that will be
53     used for decrypting the key response. */
54
55   encryption_tentacle(int key_size);
56     //!< automatically creates a private key of the "key_size".
57     /*!< this is for use by the client side's encryption needs. */
58
59   virtual ~encryption_tentacle();
60
61   DEFINE_CLASS_NAME("encryption_tentacle");
62
63   virtual basis::outcome reconstitute(const structures::string_array &classifier,
64           basis::byte_array &packed_form, infoton * &reformed);
65     //!< recreates a "reformed" infoton from a packed form.
66     /*!< the "classifier" is provided as well as the packed infoton data
67     in "packed_form".  this will only succeed if the classifier's first name
68     is understood here. */
69
70   virtual basis::outcome consume(infoton &to_chow, const octopus_request_id &item_id,
71           basis::byte_array &transformed);
72     //!< the base class handles the processing of the request in "to_chow".
73     /*!< it will generally perform all the services needed to start
74     the encrypted connection up.  the "transformed" array will be filled
75     with the actual infoton if decryption is successful.  if the outcome
76     is ENCRYPTION_MISMATCH, then the infoton is not encrypted but was
77     expected to be. */
78
79   virtual void expunge(const octopus_entity &to_remove);
80     //!< throws out any keys we were maintaining for this entity.
81
82   key_repository &keys() const;
83     //!< provides access to our list of keys.
84     /*!< this is very private info, but it's needed for encrypting items
85     going back to the client. */
86
87   const crypto::rsa_crypto &private_key() const;
88     //!< provides access to the key held here.
89     /*!< this is an important object; do not expose it externally. */
90
91 private:
92   bool _server_side;  //!< true if we're acting as a server.
93   key_repository *_keys;  //!< our table of keys that we've agreed on.
94   crypto::rsa_crypto *_rsa_private;  //!< the private key for a client side.
95 };
96
97 } //namespace.
98
99 #endif  // outer guard.
100