| 1518 | |
| 1519 | #[pymethod] |
| 1520 | fn get_ciphers(&self, vm: &VirtualMachine) -> PyResult<PyListRef> { |
| 1521 | // Dynamically generate cipher list from rustls ALL_CIPHER_SUITES |
| 1522 | // This automatically includes all cipher suites supported by the current rustls version |
| 1523 | |
| 1524 | let cipher_list = ALL_CIPHER_SUITES |
| 1525 | .iter() |
| 1526 | .map(|suite| { |
| 1527 | // Extract cipher information using unified helper |
| 1528 | let cipher_info = extract_cipher_info(suite); |
| 1529 | |
| 1530 | // Convert to OpenSSL-style name |
| 1531 | // e.g., "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256" -> "ECDHE-RSA-AES128-GCM-SHA256" |
| 1532 | let openssl_name = normalize_cipher_name(&cipher_info.name); |
| 1533 | |
| 1534 | // Determine key exchange and auth methods |
| 1535 | let (kx, auth) = if cipher_info.protocol == "TLSv1.3" { |
| 1536 | // TLS 1.3 doesn't distinguish - all use modern algos |
| 1537 | ("any", "any") |
| 1538 | } else if cipher_info.name.contains("ECDHE") { |
| 1539 | // TLS 1.2 with ECDHE |
| 1540 | let auth = if cipher_info.name.contains("ECDSA") { |
| 1541 | "ECDSA" |
| 1542 | } else if cipher_info.name.contains("RSA") { |
| 1543 | "RSA" |
| 1544 | } else { |
| 1545 | "any" |
| 1546 | }; |
| 1547 | ("ECDH", auth) |
| 1548 | } else { |
| 1549 | ("any", "any") |
| 1550 | }; |
| 1551 | |
| 1552 | // Build description string |
| 1553 | // Format: "{name} {protocol} Kx={kx} Au={auth} Enc={enc} Mac={mac}" |
| 1554 | let enc = get_cipher_encryption_desc(&openssl_name); |
| 1555 | |
| 1556 | let description = format!( |
| 1557 | "{} {} Kx={} Au={} Enc={} Mac=AEAD", |
| 1558 | openssl_name, cipher_info.protocol, kx, auth, enc |
| 1559 | ); |
| 1560 | |
| 1561 | // Create cipher dict |
| 1562 | let dict = vm.ctx.new_dict(); |
| 1563 | dict.set_item("name", vm.ctx.new_str(openssl_name).into(), vm) |
| 1564 | .unwrap(); |
| 1565 | dict.set_item("protocol", vm.ctx.new_str(cipher_info.protocol).into(), vm) |
| 1566 | .unwrap(); |
| 1567 | dict.set_item("id", vm.ctx.new_int(0).into(), vm).unwrap(); // Placeholder ID |
| 1568 | dict.set_item("strength_bits", vm.ctx.new_int(cipher_info.bits).into(), vm) |
| 1569 | .unwrap(); |
| 1570 | dict.set_item("alg_bits", vm.ctx.new_int(cipher_info.bits).into(), vm) |
| 1571 | .unwrap(); |
| 1572 | dict.set_item("description", vm.ctx.new_str(description).into(), vm) |
| 1573 | .unwrap(); |
| 1574 | dict.into() |
| 1575 | }) |
| 1576 | .collect::<Vec<_>>(); |
| 1577 | |