Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

where to add certificates and password #97

Open
todaysprint opened this issue Jul 29, 2024 · 1 comment
Open

where to add certificates and password #97

todaysprint opened this issue Jul 29, 2024 · 1 comment

Comments

@todaysprint
Copy link

Please let us know where should i add certs
thanks

@masalachai
Copy link
Owner

masalachai commented Jul 29, 2024

Hi,

You can use rusttls-pemfile to easily load the client certificate chain and key in PEM format and pass them as the 4th parameter to the EppClient::connect() function when establishing a connection.

The username and password should be added when you construct and send a login request using the Login::new() call.

use std::net::ToSocketAddrs;
use std::time::Duration;
use std::fs::File;
use std::io::BufReader;

use epp_client::EppClient;
use epp_client::domain::DomainCheck;
use epp_client::login::Login;
use epp_client::common::Certificate;
use epp_client::common::PrivateKey;

#[tokio::main]
async fn main() {
    let host = "epp-ote.verisign-grs.com";
    let addr = (host, 700).to_socket_addrs().unwrap().next().unwrap();
    let timeout = Duration::from_secs(5);

    let file = File::open("/path/to/certs/fullchain.pem").unwrap();
    let mut reader = BufReader::new(file);
    let cert_list = rustls_pemfile::certs(&mut reader).unwrap();

    let certs: Vec<Certificate> = cert_list.into_iter().map(Certificate).collect();

    let key_file = File::open("/path/to/certs/privatekey.pem").unwrap();
    let mut key_reader = BufReader::new(key_file);
    let mut key_list = rustls_pemfile::pkcs8_private_keys(&mut key_reader).unwrap();

    let key = PrivateKey(key_list.remove(0));

    let mut client = match EppClient::connect("registry".to_string(), addr, host, Some((certs, key)), timeout).await {
        Ok(client) => client,
        Err(e) => panic!("Failed to create EppClient: {}",  e)
    };

    let login = Login::new("username", "password", None, None);
    client.transact(&login, "transaction-id").await.unwrap();

    // Execute an EPP Command against the registry with distinct request and response objects
    let domain_check = DomainCheck { domains: &["eppdev.com", "eppdev.net"] };
    let response = client.transact(&domain_check, "transaction-id").await.unwrap();

    response.res_data.unwrap().list
        .iter()
        .for_each(|chk| println!("Domain: {}, Available: {}", chk.id, chk.available));
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants