Rust-Suruga: suruga — A Rust implementation of TLS 1.2

suruga is Rust implementation of TLS 1.2.

It currently implements some core parts of TLS 1.2, NIST P-256 ECDHE and chacha20-poly1305.

Usage

extern crate suruga;

use std::io::prelude::*;
use std::net::TcpStream;

fn main() {
    test().unwrap();
}

fn test() -> suruga::tls_result::TlsResult<()> {
    let stream = try!(TcpStream::connect("www.google.com:443"));
    let mut client = try!(suruga::TlsClient::from_tcp(stream));
    let _len = try!(client.write(b"GET / HTTP/1.1\r\nHost: www.google.com\r\n\r\n"));

    let mut msg = vec![0u8; 100];
    try!(client.read(&mut msg));
    let msg = String::from_utf8_lossy(&msg);
    println!("msg: {}", msg);

    try!(client.close());

    Ok(())
}

Comments

  • Implement certificate parser / validation
    Implement certificate parser / validation

    Aug 26, 2014

    Yes, the most dangerous code in the world! I currently only implemented DER parser a bit. I have to implement ASN.1 tree -> certificate parser and certificate validator. Not sure how macros work well for this..

    Reply
  • (WIP) X.509 certificate parser
    (WIP) X.509 certificate parser

    Mar 18, 2015

    WIP of #2. not intended to merge yet.

    der todos:

    • from_tlv refactor
    • reduce clone: slices rather than owning vectors
    • re-re-review chrono routine (datetime depends on it, so cert validation may rely on it)

    x509 todos:

    • prepare proper testsuite (currently using nist pkix. use other suites too), test integration
    • more validation impl & test
    • rsa.. boring
    Reply
  • Upgrade to rustc 1.1.0-dev (435622028 2015-05-04)
    Upgrade to rustc 1.1.0-dev (435622028 2015-05-04)

    May 13, 2015

                                                                                                                                                                                                           
    Reply
  • Rust nightly
    Rust nightly

    Jan 30, 2015

    This will probably be an ongoing issue seeing how Rust changes all the time. Currently doesn't work with nightly rustc 1.0.0-nightly (c5961ad06 2015-01-28 21:49:38 +0000).

    src/cipher/ecdhe.rs:2:5: 2:23 error: unresolved import `std::io::BufReader`. Could not find `io` in `std`
    src/cipher/ecdhe.rs:2 use std::io::BufReader;
                              ^~~~~~~~~~~~~~~~~~
    src/handshake.rs:1:5: 1:23 error: unresolved import `std::io::MemReader`. Could not find `io` in `std`
    src/handshake.rs:1 use std::io::MemReader;
                           ^~~~~~~~~~~~~~~~~~
    src/client.rs:1:5: 1:33 error: unresolved import `std::io::net::tcp::TcpStream`. Could not find `io` in `std`
    src/client.rs:1 use std::io::net::tcp::TcpStream;
                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
    src/client.rs:4:15: 4:23 error: unresolved import `std::io::IoResult`. Could not find `io` in `std`
    src/client.rs:4 use std::io::{IoResult, IoError, OtherIoError};
                                  ^~~~~~~~
    src/client.rs:4:25: 4:32 error: unresolved import `std::io::IoError`. Could not find `io` in `std`
    src/client.rs:4 use std::io::{IoResult, IoError, OtherIoError};
                                            ^~~~~~~
    src/client.rs:4:34: 4:46 error: unresolved import `std::io::OtherIoError`. Could not find `io` in `std`
    src/client.rs:4 use std::io::{IoResult, IoError, OtherIoError};
                                                     ^~~~~~~~~~~~
    src/tls_result.rs:2:5: 2:21 error: unresolved import `std::io::IoError`. Could not find `io` in `std`
    src/tls_result.rs:2 use std::io::IoError;
    

    Fixed somewhat in #4 but needs more work (cargo test in particular).

    Reply
  • Make it work with rustc 1.0.0-nightly
    Make it work with rustc 1.0.0-nightly

    Jan 30, 2015

    at rustc 1.0.0-nightly (c5961ad06 2015-01-28 21:49:38 +0000)

    Renamed std::io to std::old_io since io is moving somewhere. Added a couple of missing new trait requirements.

    cargo test is still failing:

    src/crypto/p256.rs:615:26: 615:32 error: type `[u32]` does not implement any method in scope named `fmt`
    src/crypto/p256.rs:615                 self.v[].fmt(a)
                                                    ^~~~~~
    src/crypto/p256.rs:615:32: 615:32 help: methods from traits can only be called if the trait is in scope; the following trait is implemented but not in scope, perhaps add a `use` for it:
    src/crypto/p256.rs:615:32: 615:32 help: candidate #1: use `core::fmt::Debug`
    src/crypto/poly1305.rs:348:24: 348:30 error: type `[u32]` does not implement any method in scope named `fmt`
    src/crypto/poly1305.rs:348             (self.v[]).fmt(a)
                                                      ^~~~~~
    src/crypto/poly1305.rs:348:30: 348:30 help: methods from traits can only be called if the trait is in scope; the following trait is implemented but not in scope, perhaps add a `use` for it:
    src/crypto/poly1305.rs:348:30: 348:30 help: candidate #1: use `core::fmt::Debug`
    
    Reply
  • Update for language changes (Rust RFC 49)
    Update for language changes (Rust RFC 49)

    Sep 9, 2014

                                                                                                                                                                                                           
    Reply
  • Make some code more idiomatic
    Make some code more idiomatic

    Aug 13, 2014

                                                                                                                                                                                                           
    Reply
  • Update usage for nightly
    Update usage for nightly

    Jan 30, 2015

    Couple of changes to make it work with nighly rustc 1.0.0-nightly (c5961ad06 2015-01-28 21:49:38 +0000)

    Reply