Skip to content

Commit

Permalink
add certificates, extensions, templates
Browse files Browse the repository at this point in the history
  • Loading branch information
Bram Verburg committed Jul 2, 2018
1 parent d34f996 commit 19f5ad5
Show file tree
Hide file tree
Showing 16 changed files with 1,079 additions and 17 deletions.
38 changes: 33 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,40 @@ Elixir package for working with certificates, CSRs and key pairs.

Requires Erlang/OTP 20.1 or later.

## Usage

Generate a self-signed CA certificate and private key:

```elixir
iex> ca_key = X509.PrivateKey.new_ec(:secp256r1)
{:ECPrivateKey, ...}
iex> ca = X509.Certificate.self_signed(ca_key,
...> "/C=US/ST=CA/L=San Fransisco/O=Acme/CN=ECDSA Root CA",
...> template: :root_ca
...>)
{:Certificate, ...}
```

Use a CA certificate to issue a server certificate :

```elixir
iex> my_key = X509.PrivateKey.new_ec(:secp256r1)
{:ECPrivateKey, ...}
iex> my_cert = my_key |>
...> X509.PublicKey.derive() |>
...> X509.Certificate.new(
...> "/C=US/ST=CA/L=San Fransisco/O=Acme/CN=Sample",
...> ca, ca_key,
...> extensions: [
...> subject_alt_name: X509.Certificate.Extension.subject_alt_name(["example.org", "www.example.org"])
...> ]
...> )
{:Certificate, ...}
```

## Installation

If [available in Hex](https://hex.pm/docs/publish), the package can be installed
by adding `x509` to your list of dependencies in `mix.exs`:
Add `x509` to your list of dependencies in `mix.exs`:

```elixir
def deps do
Expand All @@ -19,6 +49,4 @@ def deps do
end
```

Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
be found at [https://hexdocs.pm/x509](https://hexdocs.pm/x509).
Documentation can be found at [https://hexdocs.pm/x509](https://hexdocs.pm/x509).
2 changes: 2 additions & 0 deletions lib/x509/asn1.ex
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ defmodule X509.ASN1 do
certification_request_signature_algorithm: :CertificationRequest_signatureAlgorithm,

# Certificates
certificate: :Certificate,
otp_certificate: :OTPCertificate,
tbs_certificate: :TBSCertificate,
otp_tbs_certificate: :OTPTBSCertificate,
signature_algorithm: :SignatureAlgorithm,
validity: :Validity,
Expand Down
Loading

0 comments on commit 19f5ad5

Please sign in to comment.