moving the shell functions into a jruby script
This commit is contained in:
parent
de9f279ed4
commit
9f5054d2a3
3 changed files with 100 additions and 320 deletions
|
@ -5,9 +5,19 @@ require 'java'
|
|||
Dir[File.join(BASE_DIR,'lib/*jar')].each {|j| require j }
|
||||
Dir[File.join(BASE_DIR,'target/*jar')].each {|j| require j }
|
||||
|
||||
require 'openssl'
|
||||
require 'stringio'
|
||||
require 'optparse'
|
||||
|
||||
import java.io.BufferedInputStream
|
||||
import java.io.FileInputStream
|
||||
import java.security.cert.X509Certificate
|
||||
import java.security.cert.CertificateFactory
|
||||
|
||||
import org.bouncycastle.asn1.DEROctetString
|
||||
import org.bouncycastle.asn1.ASN1Encodable
|
||||
import org.bouncycastle.x509.extension.X509ExtensionUtil
|
||||
|
||||
module Trie
|
||||
include_package 'com.redhat.trie'
|
||||
end
|
||||
|
@ -44,12 +54,31 @@ def write_children(io, node)
|
|||
end
|
||||
end
|
||||
|
||||
def get_end(node)
|
||||
return node if node.getChildren().length == 0
|
||||
# PrettyPrint a PathNode or HuffNode tree
|
||||
def printTree(node, tab)
|
||||
nodeRep = " " * tab
|
||||
|
||||
nodeRep += "Node [#{node.getId}]"
|
||||
nodeRep += ", Weight [#{node.getWeight}]" if node.respond_to? :getWeight
|
||||
nodeRep += ", Value = [#{node.getValue}]" if node.respond_to? :getValue
|
||||
node.getParents.each do |parent|
|
||||
nodeRep += " ^ [#{parent.getId}]"
|
||||
end if node.respond_to? :getParents
|
||||
node.getChildren.each do |child|
|
||||
return get_end(child.getConnection())
|
||||
nodeRep += " v [#{child.getName} {#{child.getId}}]"
|
||||
end if node.respond_to? :getChildren
|
||||
|
||||
puts nodeRep
|
||||
|
||||
node.getChildren.each do |child|
|
||||
printTree(child.getConnection, tab+1)
|
||||
end if node.respond_to? :getChildren
|
||||
if node.respond_to?(:getLeft) and node.respond_to?(:getRight)
|
||||
printTree(node.getLeft, tab+1) if node.getLeft != nil
|
||||
printTree(node.getRight, tab+1) if node.getRight != nil
|
||||
end
|
||||
end
|
||||
|
||||
def parse_args(args)
|
||||
options = {
|
||||
:content_list => './src/test/resources/contents.list',
|
||||
|
@ -63,9 +92,15 @@ def parse_args(args)
|
|||
opts.on('--contents FILE', "use FILE instead of #{options[:content_list]}") do |o|
|
||||
options[:content_list] = o
|
||||
end
|
||||
opts.on('--cert FILE', "read contents from certificate FILE") do |o|
|
||||
options[:certificate] = o
|
||||
end
|
||||
opts.on('--test PATH', "validate PATH, instead of [#{options[:test_url]}]") do |o|
|
||||
options[:test_url] = o
|
||||
end
|
||||
opts.on('--print', "print the tree of contents") do |o|
|
||||
options[:printTree] = o
|
||||
end
|
||||
end
|
||||
|
||||
opts.parse!(args)
|
||||
|
@ -73,6 +108,36 @@ def parse_args(args)
|
|||
return options
|
||||
end
|
||||
|
||||
# ick, using java to do SSL
|
||||
def object_from_oid(cert, oid)
|
||||
return unless cert
|
||||
cert.getNonCriticalExtensionOIDs.each do |o|
|
||||
if o == oid
|
||||
return X509ExtensionUtil.fromExtensionValue(cert.getExtensionValue(o))
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
# ick, using java to do SSL
|
||||
def value_from_oid(filename, oid)
|
||||
bis = BufferedInputStream.new(FileInputStream.new(filename))
|
||||
cf = CertificateFactory.getInstance("X.509")
|
||||
cert = cf.generateCertificate(bis) # this is an X509Certificate
|
||||
|
||||
object_from_oid(cert, oid)
|
||||
end
|
||||
|
||||
# not working on jRuby. :-(
|
||||
# https://github.com/jruby/jruby/issues/389
|
||||
def value_from_oid_bunk(filename, oid)
|
||||
cert = OpenSSL::X509::Certificate.new(File.read(filename))
|
||||
ext = cert.extensions.detect {|ext| ext.oid == oid }
|
||||
return if ext.nil?
|
||||
|
||||
return OpenSSL::ASN1.decode(OpenSSL::ASN1.decode(ext.to_der).value[1].value).value
|
||||
end
|
||||
|
||||
def main(args)
|
||||
options = parse_args(args)
|
||||
|
||||
|
@ -80,8 +145,15 @@ def main(args)
|
|||
|
||||
puts print_dot(pt(options[:content_list]).getRootPathNode()).read() if options[:dot]
|
||||
|
||||
#pn = pt.getRootPathNode
|
||||
#Trie::Util.printTree(pn, 0)
|
||||
if options[:printTree]
|
||||
pn = pt.getRootPathNode
|
||||
printTree(pn, 0)
|
||||
end
|
||||
if options[:certificate]
|
||||
data = value_from_oid(options[:certificate], '1.3.6.1.4.1.2312.9.7')
|
||||
pt = Trie::PathTree.new(data.getOctets)
|
||||
puts pt.toList()
|
||||
end
|
||||
end
|
||||
|
||||
main(ARGV) if $0 == __FILE__
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue