Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/lib/rex/proto/kerberos/model/pkinit.rb
Views: 11766
# -*- coding: binary -*-1require 'rasn1'23module Rex4module Proto5module Kerberos6module Model7# Contains the models for PKINIT-related ASN1 structures8# These use the RASN1 library to define the types9module Pkinit10class AlgorithmIdentifier < RASN1::Model11sequence :algorithm_identifier,12content: [objectid(:algorithm),13any(:parameters, optional: true)14]15end1617class Attribute < RASN1::Model18sequence :attribute,19content: [objectid(:attribute_type),20set_of(:attribute_values, RASN1::Types::Any)21]22end2324class AttributeTypeAndValue < RASN1::Model25sequence :attribute_type_and_value,26content: [objectid(:attribute_type),27any(:attribute_value)28]29end3031class Certificate32# Rather than specifying the entire structure of a certificate, we pass this off33# to OpenSSL, effectively providing an interface between RASN and OpenSSL.3435attr_accessor :options3637def initialize(options={})38self.options = options39end4041def to_der42self.options[:openssl_certificate]&.to_der || ''43end4445# RASN1 Glue method - Say if DER can be built (not default value, not optional without value, has a value)46# @return [Boolean]47# @since 0.1248def can_build?49!to_der.empty?50end5152# RASN1 Glue method53def primitive?54false55end5657# RASN1 Glue method58def value59options[:openssl_certificate]60end6162def parse!(str, ber: false)63self.options[:openssl_certificate] = OpenSSL::X509::Certificate.new(str)64to_der.length65end66end6768class ContentInfo < RASN1::Model69sequence :content_info,70content: [objectid(:content_type),71# In our case, expected to be SignedData72any(:signed_data)73]7475def signed_data76if self[:content_type].value == '1.2.840.113549.1.7.2'77SignedData.parse(self[:signed_data].value)78end79end80end8182class DomainParameters < RASN1::Model83sequence :domain_parameters,84content: [integer(:p),85integer(:g),86integer(:q),87integer(:j, optional: true),88#model(:validationParms, ValidationParms) # Not used, so not implemented89]90end9192class EncapsulatedContentInfo < RASN1::Model93sequence :encapsulated_content_info,94content: [objectid(:econtent_type),95octet_string(:econtent, explicit: 0, constructed: true, optional: true)96]9798def econtent99if self[:econtent_type].value == '1.3.6.1.5.2.3.2'100KdcDhKeyInfo.parse(self[:econtent].value)101elsif self[:econtent_type].value == '1.3.6.1.5.2.3.1'102AuthPack.parse(self[:econtent].value)103end104end105end106107class Name108# Rather than specifying the entire structure of a name, we pass this off109# to OpenSSL, effectively providing an interface between RASN and OpenSSL.110attr_accessor :value111112def initialize(options={})113end114115def parse!(str, ber: false)116self.value = OpenSSL::X509::Name.new(str)117to_der.length118end119120def to_der121self.value.to_der122end123end124125class IssuerAndSerialNumber < RASN1::Model126sequence :signer_identifier,127content: [model(:issuer, Name),128integer(:serial_number)129]130end131132class KdcDhKeyInfo < RASN1::Model133sequence :kdc_dh_key_info,134content: [bit_string(:subject_public_key, explicit: 0, constructed: true),135integer(:nonce, implicit: 1, constructed: true),136generalized_time(:dh_key_expiration, explicit: 2, constructed: true)137]138end139140class PkAuthenticator < RASN1::Model141sequence :pk_authenticator,142explicit: 0, constructed: true,143content: [integer(:cusec, constructed: true, explicit: 0),144generalized_time(:ctime, constructed: true, explicit: 1),145integer(:nonce, constructed: true, explicit: 2),146octet_string(:pa_checksum, constructed: true, explicit: 3, optional: true)147]148end149150class SignerInfo < RASN1::Model151sequence :signer_info,152content: [integer(:version),153model(:sid, IssuerAndSerialNumber),154model(:digest_algorithm, AlgorithmIdentifier),155set_of(:signed_attrs, Attribute, implicit: 0, optional: true),156model(:signature_algorithm, AlgorithmIdentifier),157octet_string(:signature),158]159end160161class SignedData < RASN1::Model162sequence :signed_data,163explicit: 0, constructed: true,164content: [integer(:version),165set_of(:digest_algorithms, AlgorithmIdentifier),166model(:encap_content_info, EncapsulatedContentInfo),167set_of(:certificates, Certificate, implicit: 0, optional: true),168# CRLs - not implemented169set_of(:signer_infos, SignerInfo)170]171end172173class SubjectPublicKeyInfo < RASN1::Model174sequence :subject_public_key_info,175explicit: 1, constructed: true, optional: true,176content: [model(:algorithm, AlgorithmIdentifier),177bit_string(:subject_public_key)178]179end180181class AuthPack < RASN1::Model182sequence :auth_pack,183content: [model(:pk_authenticator, PkAuthenticator),184model(:client_public_value, SubjectPublicKeyInfo),185octet_string(:client_dh_nonce, implicit: 3, constructed: true, optional: true)186]187end188end189end190end191end192end193194195196