Panda3D
 All Classes Functions Variables Enumerations
prcKeyRegistry.h
1 // Filename: prcKeyRegistry.h
2 // Created by: drose (19Oct04)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef PRCKEYREGISTRY_H
16 #define PRCKEYREGISTRY_H
17 
18 #include "dtoolbase.h"
19 
20 // This file requires OpenSSL to compile, because we use routines in
21 // the OpenSSL library to manage keys and to sign and validate
22 // signatures.
23 
24 #ifdef HAVE_OPENSSL
25 
26 #include <vector>
27 #include "openssl/evp.h"
28 
29 // Some versions of OpenSSL appear to define this as a macro. Yucky.
30 #undef set_key
31 
32 ////////////////////////////////////////////////////////////////////
33 // Class : PrcKeyRegistry
34 // Description : This class records the set of public keys used to
35 // verify the signature on a prc file. The actual
36 // public keys themselves are generated by the
37 // make-prc-key utility; the output of this utility is a
38 // .cxx file which should be named by the
39 // PRC_PUBLIC_KEYS_FILENAME variable in Config.pp.
40 //
41 // This class requires the OpenSSL library.
42 ////////////////////////////////////////////////////////////////////
43 class EXPCL_DTOOLCONFIG PrcKeyRegistry {
44 protected:
45  PrcKeyRegistry();
46  ~PrcKeyRegistry();
47 
48 public:
49  struct KeyDef {
50  const char *_data;
51  size_t _length;
52  time_t _generated_time;
53  };
54 
55  void record_keys(const KeyDef *key_def, int num_keys);
56  void set_key(int n, EVP_PKEY *pkey, time_t generated_time);
57 
58  int get_num_keys() const;
59  EVP_PKEY *get_key(int n) const;
60  time_t get_generated_time(int n) const;
61 
62  static PrcKeyRegistry *get_global_ptr();
63 
64 private:
65 
66  class Key {
67  public:
68  const KeyDef *_def;
69  EVP_PKEY *_pkey;
70  time_t _generated_time;
71  };
72 
73  typedef vector<Key> Keys;
74  Keys _keys;
75 
76  static PrcKeyRegistry *_global_ptr;
77 };
78 
79 #include "prcKeyRegistry.I"
80 
81 #endif // HAVE_OPENSSL
82 
83 #endif
84 
85 
86 
87 
88