ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/rsa.c
(Generate patch)

Comparing:
ircd-hybrid-7.2/src/rsa.c (file contents), Revision 1016 by michael, Tue Oct 27 18:53:47 2009 UTC vs.
ircd-hybrid/trunk/src/rsa.c (file contents), Revision 1592 by michael, Sat Oct 27 21:02:32 2012 UTC

# Line 23 | Line 23
23   */
24  
25   #include "stdinc.h"
26 <
26 > #ifdef HAVE_LIBCRYPTO
27   #include <openssl/pem.h>
28   #include <openssl/rand.h>
29   #include <openssl/rsa.h>
# Line 34 | Line 34
34  
35   #include "memory.h"
36   #include "rsa.h"
37 < #include "s_conf.h"
38 < #include "s_log.h"
39 < #include "client.h" /* CIPHERKEYLEN .. eww */
40 < #include "ircd.h" /* bio_spare_fd */
37 > #include "conf.h"
38 > #include "log.h"
39  
40  
41   /*
# Line 49 | Line 47 | report_crypto_errors(void)
47    unsigned long e   = 0;
48    unsigned long cnt = 0;
49  
52  ERR_load_crypto_strings();
53
50    while ((cnt < 100) && (e = ERR_get_error()))
51    {
52 <    ilog(L_CRIT, "SSL error: %s", ERR_error_string(e, 0));
52 >    ilog(LOG_TYPE_IRCD, "SSL error: %s", ERR_error_string(e, 0));
53      cnt++;
54    }
55   }
56  
61 /*
62 * verify_private_key - reread private key and verify against inmem key
63 */
64 int
65 verify_private_key(void)
66 {
67  BIO *file;
68  RSA *key;
69  RSA *mkey;
70
71  /* If the rsa_private_key directive isn't found, error out. */
72  if (ServerInfo.rsa_private_key == NULL)
73  {
74    ilog(L_NOTICE, "rsa_private_key in serverinfo{} is not defined.");
75    return -1;
76  }
77
78  /* If rsa_private_key_file isn't available, error out. */
79  if (ServerInfo.rsa_private_key_file == NULL)
80  {
81    ilog(L_NOTICE, "Internal error: rsa_private_key_file isn't defined.");
82    return -1;
83  }
84
85  if (bio_spare_fd > -1)
86    close(bio_spare_fd);
87
88  file = BIO_new_file(ServerInfo.rsa_private_key_file, "r");
89
90  /*
91   * If BIO_new_file returned NULL (according to OpenSSL docs), then
92   * an error occurred.
93   */
94  if (file == NULL)
95  {
96    bio_spare_fd = save_spare_fd("SSL private key validation");
97    ilog(L_NOTICE, "Failed to open private key file - can't validate it");
98    return -1;
99  }
100
101  key = PEM_read_bio_RSAPrivateKey(file, NULL, 0, NULL);
102
103  if (key == NULL)
104  {
105    ilog(L_NOTICE, "PEM_read_bio_RSAPrivateKey() failed; possibly not RSA?");
106    report_crypto_errors();
107    return -1;
108  }
109
110  BIO_set_close(file, BIO_CLOSE);
111  BIO_free(file);
112  bio_spare_fd = save_spare_fd("SSL private key validation");
113
114  mkey = ServerInfo.rsa_private_key;
115
116  /*
117   * Compare the in-memory key to the key we just loaded above.  If
118   * any of the portions don't match, then logically we have a different
119   * in-memory key vs. the one we just loaded.  This is bad, mmmkay?
120   */
121  if (mkey->pad != key->pad)
122    ilog(L_CRIT, "Private key corrupted: pad %i != pad %i",
123                 mkey->pad, key->pad);
124  
125  if (mkey->version != key->version)
126    ilog(L_CRIT, "Private key corrupted: version %li != version %li",
127                 mkey->version, key->version);
128
129  if (BN_cmp(mkey->n, key->n))
130    ilog(L_CRIT, "Private key corrupted: n differs");
131  if (BN_cmp(mkey->e, key->e))
132    ilog(L_CRIT, "Private key corrupted: e differs");
133  if (BN_cmp(mkey->d, key->d))
134    ilog(L_CRIT, "Private key corrupted: d differs");
135  if (BN_cmp(mkey->p, key->p))
136    ilog(L_CRIT, "Private key corrupted: p differs");
137  if (BN_cmp(mkey->q, key->q))
138    ilog(L_CRIT, "Private key corrupted: q differs");
139  if (BN_cmp(mkey->dmp1, key->dmp1))
140    ilog(L_CRIT, "Private key corrupted: dmp1 differs");
141  if (BN_cmp(mkey->dmq1, key->dmq1))
142    ilog(L_CRIT, "Private key corrupted: dmq1 differs");
143  if (BN_cmp(mkey->iqmp, key->iqmp))
144    ilog(L_CRIT, "Private key corrupted: iqmp differs");
145
146  RSA_free(key);
147  return 0;
148 }
149
150
57   static void
58   binary_to_hex(unsigned char *bin, char *hex, int length)
59   {
# Line 188 | Line 94 | generate_challenge(char **r_challenge, c
94    int ret = -1;
95  
96    if (!rsa)
97 <        return -1;
97 >    return -1;
98 >
99    get_randomness(secret, 32);
100    *r_response = MyMalloc(65);
101    binary_to_hex(secret, *r_response, 32);
# Line 207 | Line 114 | generate_challenge(char **r_challenge, c
114      report_crypto_errors();
115      return -1;
116    }
117 +
118    return 0;
119   }
120 + #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)