Skip to content

Commit

Permalink
Check for fatal errors before parsing DER
Browse files Browse the repository at this point in the history
  • Loading branch information
pzb committed Jan 23, 2016
1 parent cbdd098 commit 8f65332
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
11 changes: 4 additions & 7 deletions lib/certlint/extensions/basicconstraints.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,16 @@ class BasicConstraints < ASN1Ext
def self.lint(content, cert, critical = false)
messages = []
messages += super(content, cert, critical)
if messages.any? { |m| m.start_with? 'F:' }
return messages
end
v = OpenSSL::X509::Extension.new('2.5.29.19', content, critical).value
if v.include? 'CA:TRUE'
unless critical
messages << 'E: basicConstraints must be critical in CA certificates'
end
else
begin
a = OpenSSL::ASN1.decode(content)
rescue OpenSSL::ASN1::ASN1Error
messages << 'E: ASN.1 broken in BasicConstraints'
return messages
end
if a.value.last.is_a? OpenSSL::ASN1::Integer
if OpenSSL::ASN1.decode(content).value.last.is_a? OpenSSL::ASN1::Integer
messages << 'E: Must not include pathLenConstraint on certificates that are not CA:TRUE'
end
end
Expand Down
8 changes: 1 addition & 7 deletions lib/certlint/extensions/certificatepolicies.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,7 @@ def self.lint(content, cert, critical = false)

# the qualifier in PolicyQualifierInfo is
# defined as ANY, so we have to manually check
begin
a = OpenSSL::ASN1.decode(content)
rescue OpenSSL::ASN1::ASN1Error
messages << 'E: ASN.1 broken in CertificatePolicies'
return messages
end
a.value.each do |policy_information|
OpenSSL::ASN1.decode(content).value.each do |policy_information|
# policiyQualifiers are optional
pq = policy_information.value[1]
if pq.nil?
Expand Down
4 changes: 4 additions & 0 deletions lib/certlint/extensions/nameconstraints.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ class NameConstraints < ASN1Ext
def self.lint(content, cert, critical = false)
messages = []
messages += super(content, cert, critical)
# If we are busted, don't continue
if messages.any? { |m| m.start_with? 'F:' }
return messages
end
# Content is a SEQUENCE of GeneralSubtrees which is tagged
# X.509 says "At least one of permittedSubtrees and excludedSubtrees components shall be present."
subtrees = 0
Expand Down
4 changes: 4 additions & 0 deletions lib/certlint/extensions/subjectaltname.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ def self.lint(content, cert, critical = false)
messages << 'W: subjectAltName should not be critical'
end
end
# If we are busted, don't continue
if messages.any? { |m| m.start_with? 'F:' }
return messages
end
# Content is a SEQUENCE of GeneralName (which is explicitly tagged)
at_least_one = false
OpenSSL::ASN1.decode(content).value.each do |genname|
Expand Down

0 comments on commit 8f65332

Please sign in to comment.