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 1013 by michael, Sun Oct 18 14:26:49 2009 UTC vs.
ircd-hybrid/trunk/src/rsa.c (file contents), Revision 1752 by michael, Wed Jan 16 19:17:40 2013 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>
30 – #include <openssl/md5.h>
30   #include <openssl/bn.h>
31   #include <openssl/evp.h>
32   #include <openssl/err.h>
# Line 35 | Line 34
34  
35   #include "memory.h"
36   #include "rsa.h"
37 < #include "s_conf.h"
38 < #include "s_log.h"
40 < #include "client.h" /* CIPHERKEYLEN .. eww */
41 < #include "ircd.h" /* bio_spare_fd */
37 > #include "conf.h"
38 > #include "log.h"
39  
43 – static void binary_to_hex(unsigned char *bin, char *hex, int length);
40  
41   /*
42   * report_crypto_errors - Dump crypto error list to log
# Line 48 | Line 44 | static void binary_to_hex(unsigned char
44   void
45   report_crypto_errors(void)
46   {
47 <  unsigned long e   = 0;
52 <  unsigned long cnt = 0;
53 <
54 <  ERR_load_crypto_strings();
47 >  unsigned long e = 0;
48  
49 <  while ((cnt < 100) && (e = ERR_get_error()))
50 <  {
58 <    ilog(L_CRIT, "SSL error: %s", ERR_error_string(e, 0));
59 <    cnt++;
60 <  }
49 >  while ((e = ERR_get_error()))
50 >    ilog(LOG_TYPE_IRCD, "SSL error: %s", ERR_error_string(e, 0));
51   }
52  
63 – /*
64 – * verify_private_key - reread private key and verify against inmem key
65 – */
66 – int
67 – verify_private_key(void)
68 – {
69 –  BIO *file;
70 –  RSA *key;
71 –  RSA *mkey;
72 –
73 –  /* If the rsa_private_key directive isn't found, error out. */
74 –  if (ServerInfo.rsa_private_key == NULL)
75 –  {
76 –    ilog(L_NOTICE, "rsa_private_key in serverinfo{} is not defined.");
77 –    return -1;
78 –  }
79 –
80 –  /* If rsa_private_key_file isn't available, error out. */
81 –  if (ServerInfo.rsa_private_key_file == NULL)
82 –  {
83 –    ilog(L_NOTICE, "Internal error: rsa_private_key_file isn't defined.");
84 –    return -1;
85 –  }
86 –
87 –  if (bio_spare_fd > -1)
88 –    close(bio_spare_fd);
89 –
90 –  file = BIO_new_file(ServerInfo.rsa_private_key_file, "r");
91 –
92 –  /*
93 –   * If BIO_new_file returned NULL (according to OpenSSL docs), then
94 –   * an error occurred.
95 –   */
96 –  if (file == NULL)
97 –  {
98 –    bio_spare_fd = save_spare_fd("SSL private key validation");
99 –    ilog(L_NOTICE, "Failed to open private key file - can't validate it");
100 –    return -1;
101 –  }
102 –
103 –  /*
104 –   * jdc -- Let's do this a little differently.  According to the
105 –   *        OpenSSL documentation, you need to METHOD_free(key) before
106 –   *        assigning it.  Don't believe me?  Check out the following
107 –   *        URL:  http://www.openssl.org/docs/crypto/pem.html#BUGS
108 –   * P.S. -- I have no idea why the key= assignment has to be typecasted.
109 –   *         For some reason the system thinks PEM_read_bio_RSAPrivateKey
110 –   *         is returning an int, not a RSA *.
111 –   * androsyn -- Thats because you didn't have a prototype and including
112 –   *             pem.h breaks things for some reason..
113 –   */
114 –  key = (RSA *) PEM_read_bio_RSAPrivateKey(file, NULL, 0, NULL);
115 –
116 –  if (key == NULL)
117 –  {
118 –    ilog(L_NOTICE, "PEM_read_bio_RSAPrivateKey() failed; possibly not RSA?");
119 –    report_crypto_errors();
120 –    return -1;
121 –  }
122 –
123 –  BIO_set_close(file, BIO_CLOSE);
124 –  BIO_free(file);
125 –  bio_spare_fd = save_spare_fd("SSL private key validation");
126 –
127 –  mkey = ServerInfo.rsa_private_key;
128 –
129 –  /*
130 –   * Compare the in-memory key to the key we just loaded above.  If
131 –   * any of the portions don't match, then logically we have a different
132 –   * in-memory key vs. the one we just loaded.  This is bad, mmmkay?
133 –   */
134 –  if (mkey->pad != key->pad)
135 –    ilog(L_CRIT, "Private key corrupted: pad %i != pad %i",
136 –                 mkey->pad, key->pad);
137 –  
138 –  if (mkey->version != key->version)
139 –  {
140 – #if (OPENSSL_VERSION_NUMBER >= 0x00907000)
141 –    ilog(L_CRIT, "Private key corrupted: version %li != version %li",
142 –                 mkey->version, key->version);
143 – #else
144 –    ilog(L_CRIT, "Private key corrupted: version %i != version %i",
145 –                 mkey->version, key->version);
146 – #endif
147 –  }    
148 –
149 –  if (BN_cmp(mkey->n, key->n))
150 –    ilog(L_CRIT, "Private key corrupted: n differs");
151 –  if (BN_cmp(mkey->e, key->e))
152 –    ilog(L_CRIT, "Private key corrupted: e differs");
153 –  if (BN_cmp(mkey->d, key->d))
154 –    ilog(L_CRIT, "Private key corrupted: d differs");
155 –  if (BN_cmp(mkey->p, key->p))
156 –    ilog(L_CRIT, "Private key corrupted: p differs");
157 –  if (BN_cmp(mkey->q, key->q))
158 –    ilog(L_CRIT, "Private key corrupted: q differs");
159 –  if (BN_cmp(mkey->dmp1, key->dmp1))
160 –    ilog(L_CRIT, "Private key corrupted: dmp1 differs");
161 –  if (BN_cmp(mkey->dmq1, key->dmq1))
162 –    ilog(L_CRIT, "Private key corrupted: dmq1 differs");
163 –  if (BN_cmp(mkey->iqmp, key->iqmp))
164 –    ilog(L_CRIT, "Private key corrupted: iqmp differs");
165 –
166 –  RSA_free(key);
167 –  return 0;
168 – }
169 –
170 –
53   static void
54   binary_to_hex(unsigned char *bin, char *hex, int length)
55   {
56    static const char trans[] = "0123456789ABCDEF";
57    int i;
58  
59 <  for(i = 0; i < length; i++)
59 >  for (i = 0; i < length; i++)
60    {
61      hex[i  << 1]      = trans[bin[i] >> 4];
62      hex[(i << 1) + 1] = trans[bin[i] & 0xf];
# Line 208 | Line 90 | generate_challenge(char **r_challenge, c
90    int ret = -1;
91  
92    if (!rsa)
93 <        return -1;
93 >    return -1;
94 >
95    get_randomness(secret, 32);
96    *r_response = MyMalloc(65);
97    binary_to_hex(secret, *r_response, 32);
# Line 227 | Line 110 | generate_challenge(char **r_challenge, c
110      report_crypto_errors();
111      return -1;
112    }
113 +
114    return 0;
115   }
116 + #endif

Diff Legend

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