-
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
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