|
4 | 4 | #include <algorithm> |
5 | 5 | #include <chrono> |
6 | 6 | #include <cstring> |
| 7 | +#include <openssl/evp.h> |
7 | 8 | #include <openssl/rand.h> |
8 | 9 | #include <openssl/sha.h> |
| 10 | +#include <openssl/x509.h> |
9 | 11 |
|
10 | 12 | namespace tor::protocol { |
11 | 13 |
|
@@ -157,8 +159,30 @@ CertsHandler::create_certs_cell( |
157 | 159 | // Type 2: RSA identity cert (self-signed X.509) |
158 | 160 | auto cert2 = rsa_identity.create_identity_cert(); |
159 | 161 | if (!cert2) { |
| 162 | + LOG_WARN("OR CERTS: failed to create RSA identity cert"); |
160 | 163 | return std::unexpected(LinkProtocolError::CertificateError); |
161 | 164 | } |
| 165 | + LOG_INFO("OR CERTS: Type 2 RSA identity cert: {} bytes", cert2->size()); |
| 166 | + |
| 167 | + // Debug: verify the cert round-trips correctly |
| 168 | + { |
| 169 | + const unsigned char* p = cert2->data(); |
| 170 | + X509* x509_check = d2i_X509(nullptr, &p, static_cast<long>(cert2->size())); |
| 171 | + if (x509_check) { |
| 172 | + EVP_PKEY* pk = X509_get0_pubkey(x509_check); |
| 173 | + if (pk) { |
| 174 | + int key_type = EVP_PKEY_base_id(pk); |
| 175 | + int key_bits = EVP_PKEY_bits(pk); |
| 176 | + LOG_INFO("OR CERTS: Type 2 cert key: type={} bits={} (expect type=6[RSA] bits=1024)", |
| 177 | + key_type, key_bits); |
| 178 | + } else { |
| 179 | + LOG_WARN("OR CERTS: Type 2 cert has NULL public key!"); |
| 180 | + } |
| 181 | + X509_free(x509_check); |
| 182 | + } else { |
| 183 | + LOG_WARN("OR CERTS: Type 2 cert failed DER parse!"); |
| 184 | + } |
| 185 | + } |
162 | 186 |
|
163 | 187 | // Type 4: Ed25519 signing key, certified by identity key |
164 | 188 | auto cert4 = build_ed25519_cert( |
@@ -203,7 +227,23 @@ CertsHandler::create_certs_cell( |
203 | 227 | payload.write_u16(static_cast<uint16_t>(cert7->size())); |
204 | 228 | payload.write_bytes(*cert7); |
205 | 229 |
|
206 | | - return core::VariableCell(0, core::CellCommand::CERTS, payload.take()); |
| 230 | + auto payload_data = payload.take(); |
| 231 | + LOG_INFO("OR CERTS: total payload {} bytes: N={} cert2={} cert4={} cert5={} cert7={}", |
| 232 | + payload_data.size(), 4, cert2->size(), cert4.size(), cert5.size(), cert7->size()); |
| 233 | + |
| 234 | + // Dump first 20 hex bytes of the payload for debugging |
| 235 | + { |
| 236 | + std::string hex; |
| 237 | + for (size_t i = 0; i < std::min(payload_data.size(), size_t(40)); ++i) { |
| 238 | + char buf[4]; |
| 239 | + snprintf(buf, sizeof(buf), "%02x", payload_data[i]); |
| 240 | + hex += buf; |
| 241 | + if (i < 39) hex += " "; |
| 242 | + } |
| 243 | + LOG_INFO("OR CERTS: payload hex: {}", hex); |
| 244 | + } |
| 245 | + |
| 246 | + return core::VariableCell(0, core::CellCommand::CERTS, std::move(payload_data)); |
207 | 247 | } |
208 | 248 |
|
209 | 249 | std::expected<std::vector<crypto::TorCertificate>, LinkProtocolError> |
|
0 commit comments