-
Notifications
You must be signed in to change notification settings - Fork 681
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
x509_certificate and key_rsa resource #1567
Conversation
def private? | ||
return if @key.nil? | ||
@key.private? | ||
end |
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.
So are we saying that a certificate is valid if it is public? I think we may need to refine what we mean by 'valid' just so it is clear. In the DoD sense, a key is 'valid' is it was issues and signed by an approved known trusted CA - i.e. one of the valid root or intermediate authorities.
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.
Certificates check the following: certificate? && (now >= not_before && now <= not_after)
lib/resources/x509.rb
Outdated
[email protected]? | ||
end | ||
|
||
# @see https://tools.ietf.org/html/rfc5280#page-23 |
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.
Small thing, If possible I would like to be able to say, its(... OU, CN, O, L, or CN ) { should match *DOD*}
def private? | ||
return if @key.nil? | ||
@key.private? | ||
end |
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.
http://iasecontent.disa.mil/pki-pke/Certificates_PKCS7_v5.0u1_DoD.zip has examples of valid DoD certs which should give a good idea about the things we would scan for.
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.
Would be good to verify what specifically needs to be done to use that.
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.
Overall I think this looks good, I added a couple of comments and a few examples of things that I may be able to make a bit more clear - i.e. what does valid mean? Valid may be a combination of things, signed by and issued by an organization of name x or be signed with a signature that matches a specific email. I added a link to the PKCS#7 dod public certs so you can look at them to see how the three certs are connected to each other - i.e. through issuer and subject - and that may clarify that we want to make 'valid' a different keyword for the core test. The only real question I have is what does 'valid' test?
One part that I would also have is the ability to check a certificates md5,sha-1, and she-256 fingerprints. That would be another way to validate that the cert is the real thing. DOD has published locations where you can get fingerprint lists of released and issued certs. |
As discussed with @trickyearlobe I am going to merge his efforts with my efforts |
dbed14e
to
9152908
Compare
I refactored my implementation to use the base implementation from @trickyearlobe |
1c52b29
to
7f16ea5
Compare
cc @DeltaWhy for a review request |
ac78b87
to
a7561ab
Compare
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.
This looks really awesome, @chris-rock and @trickyearlobe. I have some comments/questions I've left in my review. I'll be happy to re-review when ready.
docs/resources/key_rsa.md
Outdated
|
||
### private_key (String) | ||
|
||
The `provate_key` property returns the private key or the RSA key pair. |
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.
Spelling error: private_key
instead of provate_key
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.
Also should have an example like the other methods for consistency.
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.
Thank you. I agree.
docs/resources/x509_certificate.md
Outdated
its('issuer_cn') { should match "CN=Acme Trust CA" } | ||
end | ||
|
||
### parsed.XX |
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.
Should be issuer.XX
?
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.
correct :-)
lib/resources/x509_certificate.rb
Outdated
example " | ||
describe x509_certificate('/etc/pki/www.mywebsite.com.pem') do | ||
its('subject') { should match /CN=My Website/ } | ||
its('days_remaining') { should be > 30 } |
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.
validity_in_days
? I don't see a days_remaining
method.
docs/resources/x509_certificate.md
Outdated
An `x509_certificate` resource block declares a certificate `key file` to be tested. | ||
|
||
describe x509_certificate('mycertificate.pem') do | ||
its('days_remaining') { should be > 30 } |
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.
validity_in_days
? I don't see a days_remaining
method.
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.
Oh yeah, it is validity_in_days
|
||
### serial (Integer) | ||
|
||
The `serial` property exposes the serial number of the certificate. The serial number is set by the CA during the signing process and should be unique within that CA. |
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.
Let's include an example for consistency with the rest of the documentation.
docs/resources/x509_certificate.md
Outdated
its('extensions').length) {should eq 3 } | ||
|
||
# Check what extension categories we have | ||
its('extensions) { should include 'keyUsage' } |
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.
Missing closing '
on each of the remaining lines in the its
argument.
docs/resources/x509_certificate.md
Outdated
its('extensions) { should include 'subjectAltName' } | ||
|
||
# Check examples of basic 'keyUsage' | ||
its('extensions['keyUsage']) { should include "Digital Signature" } |
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.
Any particular reason you're using hash notation instead of method/dot notation for these examples?
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.
nope, will change it
lib/resources/key_rsa.rb
Outdated
@key = nil | ||
@passphrase = passphrase | ||
|
||
return skip_resource 'Unable to find private key' unless @key_file.exist? |
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.
Since a provided key could be public, should this instead say:
"Unable to find key file #{@key_path}"
lib/resources/key_rsa.rb
Outdated
begin | ||
@key = OpenSSL::PKey.read(@key_file.content, @passphrase) | ||
rescue OpenSSL::PKey::RSAError => _ | ||
return skip_resource 'Unable to load private key' |
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.
Same comment as above re: public vs. private keys.
lib/resources/x509_certificate.rb
Outdated
@extensions = nil | ||
|
||
file = inspec.file(filename) | ||
return if file.nil? || !file.exist? || file.content.nil? |
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.
We skip_resource
in the key_rsa
resource if the file doesn't exist or is nil. We should probably do the same here, yes?
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.
Great idea @adamleff
Berksfile
Outdated
@@ -5,3 +5,4 @@ cookbook 'apt' | |||
cookbook 'os_prepare', path: './test/cookbooks/os_prepare' | |||
cookbook 'runit', github: 'hw-cookbooks/runit' | |||
cookbook 'ssh-hardening', git: 'https://github.com/dev-sec/chef-ssh-hardening.git' | |||
cookbook 'openssl', '~> 6' |
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.
Switch to openssl cookbook 7.x since chef-boneyard/openssl#54 is solved now
docs/resources/key_rsa.md
Outdated
|
||
### private_key (String) | ||
|
||
The `provate_key` property returns the private key or the RSA key pair. |
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.
Thank you. I agree.
docs/resources/x509_certificate.md
Outdated
An `x509_certificate` resource block declares a certificate `key file` to be tested. | ||
|
||
describe x509_certificate('mycertificate.pem') do | ||
its('days_remaining') { should be > 30 } |
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.
Oh yeah, it is validity_in_days
docs/resources/x509_certificate.md
Outdated
its('issuer_cn') { should match "CN=Acme Trust CA" } | ||
end | ||
|
||
### parsed.XX |
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.
correct :-)
docs/resources/x509_certificate.md
Outdated
its('extensions) { should include 'subjectAltName' } | ||
|
||
# Check examples of basic 'keyUsage' | ||
its('extensions['keyUsage']) { should include "Digital Signature" } |
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.
nope, will change it
lib/resources/x509_certificate.rb
Outdated
@extensions = nil | ||
|
||
file = inspec.file(filename) | ||
return if file.nil? || !file.exist? || file.content.nil? |
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.
Great idea @adamleff
* Includes unit tests * Includes 2 new resources * Includes documentation Signed-off-by: Richard Nixon <[email protected]>
a7561ab
to
9f09410
Compare
@adamleff I've addressed all your feedback. Let me know if there is anything else I can do. |
9dcc3a1
to
84a3e3d
Compare
Signed-off-by: Christoph Hartmann <[email protected]>
Signed-off-by: Christoph Hartmann <[email protected]>
84a3e3d
to
a96059a
Compare
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.
This is wonderful! I'm super-excited for these new resources. Excellent work.
This PR fixes #1459
Now you can define tests like:
which will result in:
TODO: