Introduction | ssl-certificate-rust | Spatie       

 SPATIE  

ssl-certificate-rust
====================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Ssl-certificate-rust](https://spatie.be/docs/ssl-certificate-rust/v1)  Introduction

 Version   v1      

 Other versions for crawler [v1](https://spatie.be/docs/ssl-certificate-rust/v1) 

  Introduction    
- [ Introduction ](https://spatie.be/docs/ssl-certificate-rust/v1/introduction)
- [ Support us ](https://spatie.be/docs/ssl-certificate-rust/v1/support-us)
- [ Installation ](https://spatie.be/docs/ssl-certificate-rust/v1/installation-and-setup)
- [ Usage ](https://spatie.be/docs/ssl-certificate-rust/v1/usage)
- [ Downloading certificates ](https://spatie.be/docs/ssl-certificate-rust/v1/downloading-certificates)
- [ Testing ](https://spatie.be/docs/ssl-certificate-rust/v1/testing)
- [ Changelog ](https://spatie.be/docs/ssl-certificate-rust/v1/changelog)

  Ssl-certificate-rust 
======================

 Read and validate SSL certificates 

### Useful links

- [Repository](https://github.com/spatie/ssl-certificate-rust)
- [Discussions](https://github.com/spatie/ssl-certificate-rust/discussions)

Introduction
------------

###  On this page 

1. [ Downloading invalid certificates ](#content-downloading-invalid-certificates)

The class provided by this package makes it incredibly easy to query the properties on an SSL certificate. We have three options for fetching a certificate. Here's an example:

```
use spatie_ssl_certificate::SslCertificate;

// fetch the certificate using a URL
let certificate = SslCertificate::create_for_host_name("spatie.be")?;

// or from a certificate file
let certificate = SslCertificate::create_from_file(path_to_certificate_file)?;

// or from a string
let certificate = SslCertificate::create_from_string(&certificate_data)?;

certificate.is_valid(None); // returns true if the certificate is currently valid

certificate.expiration_date(); // returns an OffsetDateTime
certificate.valid_from_date(); // returns an OffsetDateTime

certificate.days_until_expiration_date(); // returns the days between today and expiration_date
certificate.lifespan_in_days(); // returns the days between valid_from_date and expiration_date

certificate.issuer(); // returns "Let's Encrypt Authority X3"
certificate.organization(); // returns the organization name when available
certificate.subject_organization(); // returns the subject organization name when available
certificate.public_key_algorithm(); // returns the public key algorithm
certificate.public_key_size(); // returns the public key size
certificate.signature_algorithm(); // returns the signature algorithm
```

This is the Rust version of [spatie/ssl-certificate](https://github.com/spatie/ssl-certificate).

Downloading invalid certificates
--------------------------------------------------------------------------------------------------------------------------------------------------------

If you want to download certificates even if they are invalid (for example, if they are expired), you can turn off verification explicitly:

```
let certificate = Downloader::download_certificate_from_url(
    "expired.badssl.com",
    Duration::from_secs(timeout_in_seconds),
    false,
)?;
```

This disables both chain and peer name verification. Use it only to inspect a certificate, never to authenticate a server. Handshake signatures are still checked by rustls.

Continue with [installation](installation-and-setup) and [usage](usage).

 A good
match?
-------------

### What we do best

- All things Laravel
- Custom frontend components
- Building APIs
- AI-powered features
- Simplifying things
- Clean solutions
- Integrating services

### Not our cup of tea

- WordPress themes
- Cutting corners
- Free mockups to win a job
- "Just execute the briefing"

 In short: we'd like to be a **substantial part** of your project.

 [ Get in touch via email ](mailto:info@spatie.be?subject=A%20good%20match%21&body=Tell%20us%20as%20much%20as%20you%20can%20about%0A-%20your%20online%20project%0A-%20your%20planning%0A-%20your%20budget%0A-%20%E2%80%A6%0A%0AAnything%20that%20helps%20us%20to%20start%20straightforward%21)
