monotone

monotone Mtn Source Tree

Root/src/key_store.hh

1// Copyright (C) 2005 Timothy Brownawell <tbrownaw@gmail.com>
2//
3// This program is made available under the GNU GPL version 2.0 or
4// greater. See the accompanying file COPYING for details.
5//
6// This program is distributed WITHOUT ANY WARRANTY; without even the
7// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8// PURPOSE.
9
10#ifndef __KEY_STORE_H__
11#define __KEY_STORE_H__
12
13#include <boost/scoped_ptr.hpp>
14
15#include <botan/botan.h>
16#if BOTAN_VERSION_CODE >= BOTAN_VERSION_CODE_FOR(1,7,7)
17#include <botan/rng.h>
18#else
19#include <botan/libstate.h>
20#endif
21
22#include "vector.hh"
23#include "vocab.hh"
24#include "paths.hh"
25
26class app_state;
27struct globish;
28class database;
29
30struct keypair
31{
32 rsa_pub_key pub;
33 rsa_priv_key priv;
34 keypair()
35 {}
36 keypair(rsa_pub_key const & a,
37 rsa_priv_key const & b)
38 : pub(a), priv(b)
39 {}
40};
41
42struct key_store_state;
43
44class key_store
45{
46private:
47 boost::scoped_ptr<key_store_state> s;
48
49public:
50 key_id signing_key;
51 bool have_signing_key() const;
52
53 explicit key_store(app_state & a);
54 ~key_store();
55
56#if BOTAN_VERSION_CODE >= BOTAN_VERSION_CODE_FOR(1,7,7)
57 Botan::RandomNumberGenerator & get_rng();
58#endif
59
60 system_path const & get_key_dir() const;
61
62 // Basic key I/O
63
64 void get_key_ids(std::vector<key_id> & priv);
65
66 bool key_pair_exists(key_id const & ident);
67 bool key_pair_exists(key_name const & name);
68
69 void get_key_pair(key_id const & ident,
70 keypair & kp);
71 bool maybe_get_key_pair(key_id const & ident,
72 keypair & kp);
73 void get_key_pair(key_id const & hash,
74 key_name & ident,
75 keypair & kp);
76 bool maybe_get_key_pair(key_id const & hash,
77 key_name & ident,
78 keypair & kp);
79
80 bool put_key_pair(key_name const & name,
81 keypair const & kp);
82
83 void delete_key(key_id const & ident);
84
85 // Crypto operations
86
87 void cache_decrypted_key(key_id const & id);
88
89 enum create_key_pair_mode { create_quiet, create_verbose };
90 void create_key_pair(database & db, key_name const & ident,
91 create_key_pair_mode create_mode = create_verbose,
92 utf8 const * maybe_passphrase = NULL,
93 key_id * const maybe_hash = NULL);
94
95 // This is always your own key, so you probably want to
96 // always use the given name.
97 void change_key_passphrase(key_id const & id);
98
99 void decrypt_rsa(key_id const & id,
100 rsa_oaep_sha_data const & ciphertext,
101 std::string & plaintext);
102
103 void make_signature(database & db, key_id const & id,
104 std::string const & tosign,
105 rsa_sha1_signature & signature);
106
107 // Interoperation with ssh-agent
108
109 void add_key_to_agent(key_id const & id);
110 void export_key_for_agent(key_id const & id,
111 std::ostream & os);
112
113 // Migration from old databases
114
115 void migrate_old_key_pair(key_name const & id,
116 old_arc4_rsa_priv_key const & old_priv,
117 rsa_pub_key const & pub);
118};
119
120#endif
121
122// Local Variables:
123// mode: C++
124// fill-column: 76
125// c-file-style: "gnu"
126// indent-tabs-mode: nil
127// End:
128// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status