Skip to content
This repository has been archived by the owner on Jun 13, 2022. It is now read-only.

Commit

Permalink
add editorconfig and fix whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
ciphax committed Jul 11, 2018
1 parent e41ead5 commit 847f847
Show file tree
Hide file tree
Showing 10 changed files with 598 additions and 585 deletions.
10 changes: 5 additions & 5 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/.git/
/.gitignore
/.travis-yml
/target
/LICENSE.txt
/.git/
/.gitignore
/.travis-yml
/target
/LICENSE.txt
/README.md
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = false
indent_style = tab
indent_size = 4
trim_trailing_whitespace = true

[*.yml]
indent_style = space
indent_size = 2
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ repository = "https://github.com/kegato/letsencrypt-inwx"
depends = ""
extended-description = "A small cli utility for automating the letsencrypt dns-01 challenge for domains hosted by inwx. The dns-01 challenge is required for obtaining wildcard certificates from letsencrypt."
assets = [
["target/release/letsencrypt-inwx", "usr/bin/", "755"],
["etc/certbot-inwx-auth", "usr/lib/letsencrypt-inwx/", "755"],
["etc/certbot-inwx-cleanup", "usr/lib/letsencrypt-inwx/", "755"]
["target/release/letsencrypt-inwx", "usr/bin/", "755"],
["etc/certbot-inwx-auth", "usr/lib/letsencrypt-inwx/", "755"],
["etc/certbot-inwx-cleanup", "usr/lib/letsencrypt-inwx/", "755"]
]

[dependencies]
Expand Down
20 changes: 10 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
FROM ekidd/rust-musl-builder:stable as builder
COPY . .
RUN cargo install cargo-deb
RUN cargo deb --target x86_64-unknown-linux-musl

FROM certbot/certbot:rolling
VOLUME /etc/letsencrypt
COPY --from=builder /home/rust/src/target/x86_64-unknown-linux-musl/release/letsencrypt-inwx /usr/bin/
COPY etc/* /usr/lib/letsencrypt-inwx/

FROM ekidd/rust-musl-builder:stable as builder
COPY . .
RUN cargo install cargo-deb
RUN cargo deb --target x86_64-unknown-linux-musl

FROM certbot/certbot:rolling
VOLUME /etc/letsencrypt
COPY --from=builder /home/rust/src/target/x86_64-unknown-linux-musl/release/letsencrypt-inwx /usr/bin/
COPY etc/* /usr/lib/letsencrypt-inwx/

ENTRYPOINT ["/bin/sh", "/usr/lib/letsencrypt-inwx/docker-entrypoint.sh"]
40 changes: 20 additions & 20 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
MIT License
Copyright (c) 2018 Matthias Herzog
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
MIT License

Copyright (c) 2018 Matthias Herzog

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
98 changes: 49 additions & 49 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
# letsencrypt-inwx [![Build Status](https://travis-ci.org/kegato/letsencrypt-inwx.svg?branch=master)](https://travis-ci.org/kegato/letsencrypt-inwx) [![Docker Build Status](https://img.shields.io/docker/build/kegato/letsencrypt-inwx.svg)](https://hub.docker.com/r/kegato/letsencrypt-inwx/) [![Crates.io](https://img.shields.io/crates/v/letsencrypt-inwx.svg)](https://crates.io/crates/letsencrypt-inwx)

A small cli utility for automating the letsencrypt dns-01 challenge for domains hosted by inwx. This allows you to obtain wildcard certificates from letsencrypt.

## Installation
### Ubuntu / Debian
- Build the .deb package or download it from [releases](https://github.com/kegato/letsencrypt-inwx/releases/latest) and install it with `sudo dpkg -i <path_to_the_deb_file>`

### Other linux
- Build the executable or download it from [releases](https://github.com/kegato/letsencrypt-inwx/releases/latest) and copy it to `/usr/bin/`
- Copy both certbot scripts from `./etc/` to `/usr/lib/letsencrypt-inwx/`

### With cargo
- Run `cargo install letsencrypt-inwx`

## Usage
### With certbot
- Put your inwx login data seperated by a newline into `/etc/letsencrypt-inwx-cred`
- Make sure the file is only readable for root `sudo chmod 600 /etc/letsencrypt-inwx-cred`
- You can now get certificates from [certbot](https://certbot.eff.org/) by running `sudo certbot certonly -n --agree-tos --email <your_email> --server https://acme-v02.api.letsencrypt.org/directory --preferred-challenges=dns-01 --manual --manual-auth-hook /usr/lib/letsencrypt-inwx/certbot-inwx-auth --manual-cleanup-hook /usr/lib/letsencrypt-inwx/certbot-inwx-cleanup --manual-public-ip-logging-ok -d <your_domain>`

#### Notes
- You need atleast certbot 0.22.0 to issue wildcard certificates.
- You can put your inwx login data into `~/.config/letsencrypt-inwx-cred` if you want to run certbot as non-root user

### With Docker and certbot
- Put your inwx login data into a docker env file like this
```sh
INWX_USER=username
INWX_PASSWD=password
```
- Generate your certificate by running `docker run --rm -it --env-file <your-env-file> -v /etc/letsencrypt:/etc/letsencrypt kegato/letsencrypt-inwx certonly --email <your_email> --preferred-challenges=dns-01 --manual --manual-auth-hook /usr/lib/letsencrypt-inwx/certbot-inwx-auth --manual-cleanup-hook /usr/lib/letsencrypt-inwx/certbot-inwx-cleanup --manual-public-ip-logging-ok -d <your_domain>`
- Your certificate is now at `/etc/letsencrypt/live/<your_domain>/`
- You can renew your certificate by running `docker run --rm -it --env-file <your-env-file> -v /etc/letsencrypt:/etc/letsencrypt kegato/letsencrypt-inwx renew`

### Manually
- Put your inwx login data seperated by a newline into a file
- Create a txt record with `letsencrypt-inwx create -c <credential_file> -d _acme-challenge.your-domain.com -v <acme_token>`
- Delete it with `letsencrypt-inwx delete -c <credential_file> -d _acme-challenge.your-domain.com`

## Building
### Requirements
`libssl-dev` and `pkg-config` are required when building on Ubuntu / Debian see [here](https://github.com/sfackler/rust-openssl).

### .deb package
- Install [cargo-deb](https://github.com/mmstick/cargo-deb) by running `cargo install cargo-deb`
- Run `cargo deb` to build the package

### only the executable
# letsencrypt-inwx [![Build Status](https://travis-ci.org/kegato/letsencrypt-inwx.svg?branch=master)](https://travis-ci.org/kegato/letsencrypt-inwx) [![Docker Build Status](https://img.shields.io/docker/build/kegato/letsencrypt-inwx.svg)](https://hub.docker.com/r/kegato/letsencrypt-inwx/) [![Crates.io](https://img.shields.io/crates/v/letsencrypt-inwx.svg)](https://crates.io/crates/letsencrypt-inwx)

A small cli utility for automating the letsencrypt dns-01 challenge for domains hosted by inwx. This allows you to obtain wildcard certificates from letsencrypt.

## Installation
### Ubuntu / Debian
- Build the .deb package or download it from [releases](https://github.com/kegato/letsencrypt-inwx/releases/latest) and install it with `sudo dpkg -i <path_to_the_deb_file>`

### Other linux
- Build the executable or download it from [releases](https://github.com/kegato/letsencrypt-inwx/releases/latest) and copy it to `/usr/bin/`
- Copy both certbot scripts from `./etc/` to `/usr/lib/letsencrypt-inwx/`

### With cargo
- Run `cargo install letsencrypt-inwx`

## Usage
### With certbot
- Put your inwx login data seperated by a newline into `/etc/letsencrypt-inwx-cred`
- Make sure the file is only readable for root `sudo chmod 600 /etc/letsencrypt-inwx-cred`
- You can now get certificates from [certbot](https://certbot.eff.org/) by running `sudo certbot certonly -n --agree-tos --email <your_email> --server https://acme-v02.api.letsencrypt.org/directory --preferred-challenges=dns-01 --manual --manual-auth-hook /usr/lib/letsencrypt-inwx/certbot-inwx-auth --manual-cleanup-hook /usr/lib/letsencrypt-inwx/certbot-inwx-cleanup --manual-public-ip-logging-ok -d <your_domain>`

#### Notes
- You need atleast certbot 0.22.0 to issue wildcard certificates.
- You can put your inwx login data into `~/.config/letsencrypt-inwx-cred` if you want to run certbot as non-root user

### With Docker and certbot
- Put your inwx login data into a docker env file like this
```sh
INWX_USER=username
INWX_PASSWD=password
```
- Generate your certificate by running `docker run --rm -it --env-file <your-env-file> -v /etc/letsencrypt:/etc/letsencrypt kegato/letsencrypt-inwx certonly --email <your_email> --preferred-challenges=dns-01 --manual --manual-auth-hook /usr/lib/letsencrypt-inwx/certbot-inwx-auth --manual-cleanup-hook /usr/lib/letsencrypt-inwx/certbot-inwx-cleanup --manual-public-ip-logging-ok -d <your_domain>`
- Your certificate is now at `/etc/letsencrypt/live/<your_domain>/`
- You can renew your certificate by running `docker run --rm -it --env-file <your-env-file> -v /etc/letsencrypt:/etc/letsencrypt kegato/letsencrypt-inwx renew`

### Manually
- Put your inwx login data seperated by a newline into a file
- Create a txt record with `letsencrypt-inwx create -c <credential_file> -d _acme-challenge.your-domain.com -v <acme_token>`
- Delete it with `letsencrypt-inwx delete -c <credential_file> -d _acme-challenge.your-domain.com`

## Building
### Requirements
`libssl-dev` and `pkg-config` are required when building on Ubuntu / Debian see [here](https://github.com/sfackler/rust-openssl).

### .deb package
- Install [cargo-deb](https://github.com/mmstick/cargo-deb) by running `cargo install cargo-deb`
- Run `cargo deb` to build the package

### only the executable
- Run `cargo build --release` to build the `letsencrypt-inwx` executable
56 changes: 28 additions & 28 deletions src/dns.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
use trust_dns_resolver::config::{ResolverConfig, ResolverOpts};
use trust_dns_resolver::Resolver;

pub fn check_txt_record(domain: &str, value: &str) -> bool {
let mut opts = ResolverOpts::default();
opts.cache_size = 0;

let resolver = match Resolver::new(ResolverConfig::default(), opts) {
Ok(resolver) => resolver,
_ => return false
};

let result = match resolver.txt_lookup(domain) {
Ok(result) => result,
_ => return false
};

for record in result.iter() {
for data in record.txt_data().iter() {
let data = String::from_utf8_lossy(data);
if data == value {
return true;
}
}
}

false
use trust_dns_resolver::config::{ResolverConfig, ResolverOpts};
use trust_dns_resolver::Resolver;

pub fn check_txt_record(domain: &str, value: &str) -> bool {
let mut opts = ResolverOpts::default();
opts.cache_size = 0;

let resolver = match Resolver::new(ResolverConfig::default(), opts) {
Ok(resolver) => resolver,
_ => return false
};

let result = match resolver.txt_lookup(domain) {
Ok(result) => result,
_ => return false
};

for record in result.iter() {
for data in record.txt_data().iter() {
let data = String::from_utf8_lossy(data);

if data == value {
return true;
}
}
}

false
}
Loading

0 comments on commit 847f847

Please sign in to comment.