-
Notifications
You must be signed in to change notification settings - Fork 17
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
Cfssl backend #54
Open
XANi
wants to merge
7
commits into
duritong:main
Choose a base branch
from
efigence:cfssl-backend
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Cfssl backend #54
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ab738ee
cfssl format for generating certs from remote CA
XANi 5df1407
cfssl format documentation
XANi 55baabc
better input handling, add dates to cert info
XANi 1d1f831
document output key format #11988
XANi d44f98f
fix formatting
XANi 1713abe
add support to generating selfsigned certs
XANi 1aba5f5
allow generating certs with no hosts, only CN, like CA or client certs
XANi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -215,6 +215,110 @@ Output render options are: | |
certonly If set to true the x509 format will return only the certificate | ||
keyonly If set to true the x509 format will return only the private key | ||
|
||
### cfssl | ||
|
||
This format will use [CFSSL](https://github.com/cloudflare/cfssl) to generate certificates and then sign it via remote CFSSL API server, for example: | ||
|
||
`trocla set testcert cfssl '{"CN" : "test.example.com","hosts":["test.example.com"],"names":[{"O":"Testorg","OU":"testcert"}],}'` | ||
|
||
Format for options is same config as CFSSL uses. That means all names must be in `hosts` key including CN. Plaintext pass is not used. | ||
|
||
Key type is set to RSA 2048 if not set in trocla call. `names` list can be set as default in trocla config or passed to trocla call to override default | ||
|
||
Required configuration: | ||
|
||
* cfssl installed in /usr/bin/cfssl (that's where Debian packages install it) or anywhere in PATH that trocla sees. | ||
* cfssl CA configuration (example of it is in`lib/trocla/ca-config.json` | ||
* cfssl config keys showing server URL and CA configuration | ||
|
||
Trocla config minimum setup: | ||
|
||
```yaml | ||
formats: | ||
cfssl: | ||
server_url: https://certserver.example.com:8443 | ||
cfssl_config_path: /etc/trocla/trocla-ca-config.json | ||
``` | ||
|
||
#### Basic usage | ||
|
||
call trocla with hash describing cert to sign: | ||
```json | ||
{ | ||
"CN": "*.example.com", | ||
"hosts": [ | ||
"*.example.com", | ||
"example.com", | ||
"10.0.0.1" | ||
], | ||
"key": { | ||
"algo": "rsa", | ||
"size": 2048 | ||
}, | ||
"names": [ | ||
{ | ||
"C": "AB", | ||
"L": "Nowherecity", | ||
"O": "Someorg", | ||
"OU": "IT dept", | ||
"ST": "nowhere", | ||
"emailAddress": "[email protected]" | ||
} | ||
] | ||
} | ||
``` | ||
and it will be signed using `server` cfssl profile | ||
|
||
`names` can be skipped if `default_names` key is specified in trocla config. `key` defaults to RSA 2048 and can be set globally via `default_key` key | ||
|
||
#### Additional generation options | ||
|
||
all other parameters are passed directly to cfssl | ||
|
||
##### profile | ||
|
||
Changes CFSSL profile. Defaults to 'server' | ||
|
||
##### selfsigned | ||
|
||
When set to true switches mode to generate selfsigned certs. Example: | ||
|
||
`trocla set testcerts cfssl '{"ca":{"expiry":"96h"},"selfsigned":true,"CN" : "test.example.com","hosts":["test.example.com"],"names":[{"O":"Testorg","OU":"testcert"}],}'` | ||
|
||
will generate selfsigned cert with lifetime 96 hours | ||
|
||
#### Additional trocla config options | ||
|
||
##### default_names | ||
|
||
Array to use if no `names` key is provided when requesting the certificate. For example: | ||
|
||
```yaml | ||
default_names: | ||
- C: AB | ||
L: Nowherecity | ||
O: Someorg | ||
OU: IT dept | ||
ST: nowhere | ||
emailAddress: [email protected] | ||
|
||
``` | ||
#### intermediates | ||
|
||
Intermediates to add to the cert hash. Are **not** checked in any way | ||
|
||
#### Output | ||
|
||
Resulting hash will have those keys, in PEM format: | ||
|
||
* `cert` - cert itself | ||
* `key` - key to the cert | ||
* `csr` - CSR of the key | ||
* `intermediates` - intermediates needed for cert to work | ||
* `not_before` - stringified start date of cert ( 2019-02-28 13:31:00 UTC ) | ||
* `not_after` - stringified end date of cert ( 2019-04-28 13:31:00 UTC ) | ||
|
||
|
||
## Installation | ||
|
||
* Debian has trocla within its sid-release: `apt-get install trocla` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{ | ||
"signing": { | ||
"default": { | ||
"expiry": "12h" | ||
}, | ||
"profiles": { | ||
"server": { | ||
"expiry": "87600h", | ||
"usages": [ | ||
"signing", | ||
"key encipherment", | ||
"server auth" | ||
] | ||
}, | ||
"client": { | ||
"expiry": "87600h", | ||
"usages": [ | ||
"signing", | ||
"key encipherment", | ||
"client auth" | ||
] | ||
}, | ||
"client-server": { | ||
"expiry": "87600h", | ||
"usages": [ | ||
"signing", | ||
"key encipherment", | ||
"server auth", | ||
"client auth" | ||
] | ||
}, | ||
"ca": { | ||
"expiry": "87600h", | ||
"ca_constraint": { | ||
"is_ca": true, | ||
"max_path_len": 0, | ||
"max_path_len_zero": true | ||
}, | ||
"usages": [ | ||
"cert sign", | ||
"crl sign" | ||
] | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
class Trocla::Formats::Cfssl < Trocla::Formats::Base | ||
require 'json' | ||
require 'open3' | ||
def format(plain_password,options={}) | ||
#no dig method on jruby 1.9 used by puppet ;/ | ||
if @trocla.config['formats'] && @trocla.config['formats']['cfssl'] | ||
@cfssl_config = @trocla.config['formats']['cfssl'] | ||
else | ||
raise "cfssl format needs server parameters in formats -> cfssl config in the config file" | ||
end | ||
if !options.is_a?(Hash) | ||
options = YAML.load(options) | ||
end | ||
selfsigned = false | ||
if options['selfsigned'] | ||
selfsigned = true | ||
options.delete('selfsigned') | ||
end | ||
options['names'] ||= @cfssl_config['default_names'] | ||
options['key'] ||= @cfssl_config['default_key'] || { 'algo' => 'rsa', 'size' => 2048 } | ||
if selfsigned | ||
options['profile'] ||= 'ca' | ||
else | ||
options['profile'] ||= 'server' | ||
end | ||
|
||
|
||
if plain_password.is_a?(Hash) && plain_password['cert'] && plain_password['key'] | ||
# just an import, don't generate any new keys | ||
# if cert does not have expiry info, add them (for certs imported manually) | ||
if !plain_password['not_before'] | ||
cert = OpenSSL::X509::Certificate.new plain_password['cert'] | ||
plain_password['not_before'] = cert.not_before | ||
plain_password['not_after'] = cert.not_after | ||
end | ||
return plain_password | ||
end | ||
@cfssl_config['cfssl_config_path'] ||= File.expand_path(File.join(File.dirname(__FILE__),'..','ca-config.json')) | ||
if !options['CN'] || !options['names'] | ||
raise "options passed should contain CN and names (if names are not defined in default config)" | ||
end | ||
# CA certs and client certs do not need to have list of hosts | ||
if !options.key?('hosts') && !selfsigned | ||
raise "options passed should contain hosts key with list of domains/IPs to sign. If you you really do not want hosts (client certs etc), pass hosts => false" | ||
end | ||
if options.key?('hosts') && !options['hosts'] | ||
options.delete('hosts') | ||
end | ||
json_csr = JSON.dump(options) | ||
if selfsigned | ||
cfssl_cmd = ['cfssl','gencert','-initca=true','-config',@cfssl_config['cfssl_config_path'],'-profile', options['profile'], '-'] | ||
else | ||
cfssl_cmd = ['cfssl','gencert','-config',@cfssl_config['cfssl_config_path'],'-profile', options['profile'], '-remote',@cfssl_config['server_url'],'-'] | ||
end | ||
cfssl_stdout,cfssl_stderr = Open3.capture3( | ||
*cfssl_cmd, | ||
:stdin_data=>json_csr | ||
) | ||
certdata = JSON.load(cfssl_stdout) | ||
if !certdata.is_a?(Hash) || !certdata['cert'] | ||
raise "cfssl: did not get cert data from server: stdin: #{json_csr} -> stdout: #{cfssl_stdout}, stderr #{cfssl_stderr}, config:#{@cfssl_config['cfssl_config_path']}" | ||
end | ||
if @cfssl_config['intermediates'] || options['intermediates'] | ||
certdata['intermediate'] ||= options['intermediates'] || @cfssl_config['intermediates'] | ||
end | ||
# parse cert and extract validity date | ||
cert = OpenSSL::X509::Certificate.new certdata['cert'] | ||
certdata['not_before'] = cert.not_before | ||
certdata['not_after'] = cert.not_after | ||
return certdata | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm should we define that at all? Or is thi the default place where your cfssl daemon might be running?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
default config of the daemon is localhost on port 8888:
so I used that as an example