Skip to content

Instantly share code, notes, and snippets.

@wchristian
Created August 4, 2023 13:29
Show Gist options
  • Save wchristian/905289b92dbd205e2e72eb293867b5a6 to your computer and use it in GitHub Desktop.
Save wchristian/905289b92dbd205e2e72eb293867b5a6 to your computer and use it in GitHub Desktop.
* Perl script text executable
#!/usr/bin/env perl
use lib 't/lib', 'blib/lib', 'lib';
use 5.010;
use strictures 2;
use Test::More;
use Convert::ASN1 ();
use Net::Prometheus;
use Devel::Gladiator 'walk_arena';
use Devel::FindRef;
use Data::Dumper::Compact::Term 'ddc';
my $i = 0;
run();
sub count { my ($class) = @_; ( Net::Prometheus::PerlCollector::count_heap 2 )[3]{$class} || 0 }
sub count_is { my ( $class, $count ) = @_; is count($class), $count, "$count times $class" }
sub run {
my %dump1 = map { ( "$_" => $_ ) } @{ walk_arena() };
make_asn1() for 1 .. 10;
say "walk";
my %dump2 = map { $dump1{$_} ? () : ( "$_" => $_ ) } @{ walk_arena() };
say "end walk";
%dump1 = ();
my @keys = grep /ASN1/, keys %dump2;
say "loop";
for my $key (@keys) {
my $track = Devel::FindRef::track $dump2{$key};
next if $track !~ /global/;
print $track;
last;
}
say "end loop";
%dump2 = ();
note $_ for split /\n/, Net::Prometheus->new->render( { perl_collector_detail => 2 } );
count_is "Convert::ASN1::parser", 0;
done_testing;
return;
}
sub make_asn1 {
say "run $i";
$i++;
my $asn = Convert::ASN1->new;
$asn->prepare( schema() ) or die "Internal error in " . __PACKAGE__ . ": " . $asn->error;
obliterate($asn);
$Convert::ASN1::parser::yyval = undef;
@Convert::ASN1::parser::yyvs = ();
say "end run $i";
return;
}
sub obliterate {
my ($t) = @_;
my $r = ref $t;
if ( $r eq 'ARRAY' or $r eq "Convert::ASN1::parser" ) #
{ obliterate($_) for splice @$t; }
elsif ( $r eq 'HASH' or $r eq "Convert::ASN1" ) #
{ my @v = values %$t; %$t = (); obliterate($_) for @v; }
}
sub schema { # from Crypt::PKCS10
<<ASN1
DirectoryString ::= CHOICE {
teletexString TeletexString,
printableString PrintableString,
bmpString BMPString,
universalString UniversalString,
utf8String UTF8String,
ia5String IA5String,
integer INTEGER}
Algorithms ::= ANY
Name ::= SEQUENCE OF RelativeDistinguishedName
RelativeDistinguishedName ::= SET OF AttributeTypeAndValue
AttributeTypeAndValue ::= SEQUENCE {
type OBJECT IDENTIFIER,
value DirectoryString}
Attributes ::= SET OF Attribute
Attribute ::= SEQUENCE {
type OBJECT IDENTIFIER,
values SET OF ANY}
AlgorithmIdentifier ::= SEQUENCE {
algorithm OBJECT IDENTIFIER,
parameters Algorithms OPTIONAL}
SubjectPublicKeyInfo ::= SEQUENCE {
algorithm AlgorithmIdentifier,
subjectPublicKey BIT STRING}
--- Certificate Request ---
CertificationRequest ::= SEQUENCE {
certificationRequestInfo CertificationRequestInfo,
signatureAlgorithm AlgorithmIdentifier,
signature BIT STRING},
CertificationRequestInfo ::= SEQUENCE {
version INTEGER ,
subject Name OPTIONAL,
subjectPKInfo SubjectPublicKeyInfo,
attributes [0] Attributes OPTIONAL}
--- Extensions ---
BasicConstraints ::= SEQUENCE {
cA BOOLEAN OPTIONAL, -- DEFAULT FALSE,
pathLenConstraint INTEGER OPTIONAL}
OS_Version ::= IA5String
emailAddress ::= IA5String
EnrollmentCSP ::= SEQUENCE {
KeySpec INTEGER,
Name BMPString,
Signature BIT STRING}
ENROLLMENT_CSP_PROVIDER ::= SEQUENCE { -- MSDN
keySpec INTEGER,
cspName BMPString,
signature BIT STRING}
ENROLLMENT_NAME_VALUE_PAIR ::= EnrollmentNameValuePair -- MSDN: SEQUENCE OF
EnrollmentNameValuePair ::= SEQUENCE { -- MSDN
name BMPString,
value BMPString}
ClientInformation ::= SEQUENCE { -- MSDN
clientId INTEGER,
MachineName UTF8String,
UserName UTF8String,
ProcessName UTF8String}
extensionRequest ::= SEQUENCE OF Extension
Extension ::= SEQUENCE {
extnID OBJECT IDENTIFIER,
critical BOOLEAN OPTIONAL,
extnValue OCTET STRING}
SubjectKeyIdentifier ::= OCTET STRING
certificateTemplate ::= SEQUENCE {
templateID OBJECT IDENTIFIER,
templateMajorVersion INTEGER OPTIONAL, -- (0..4294967295)
templateMinorVersion INTEGER OPTIONAL} -- (0..4294967295)
EnhancedKeyUsage ::= SEQUENCE OF OBJECT IDENTIFIER
KeyUsage ::= BIT STRING
netscapeCertType ::= BIT STRING
ApplicationCertPolicies ::= SEQUENCE OF PolicyInformation -- Microsoft
PolicyInformation ::= SEQUENCE {
policyIdentifier OBJECT IDENTIFIER,
policyQualifiers SEQUENCE OF PolicyQualifierInfo OPTIONAL}
PolicyQualifierInfo ::= SEQUENCE {
policyQualifierId OBJECT IDENTIFIER,
qualifier ANY}
certificatePolicies ::= SEQUENCE OF certPolicyInformation -- RFC 3280
certPolicyInformation ::= SEQUENCE {
policyIdentifier CertPolicyId,
policyQualifier SEQUENCE OF certPolicyQualifierInfo OPTIONAL}
CertPolicyId ::= OBJECT IDENTIFIER
certPolicyQualifierInfo ::= SEQUENCE {
policyQualifierId CertPolicyQualifierId,
qualifier ANY DEFINED BY policyQualifierId}
CertPolicyQualifierId ::= OBJECT IDENTIFIER
CertPolicyQualifier ::= CHOICE {
cPSuri CPSuri,
userNotice UserNotice }
CPSuri ::= IA5String
UserNotice ::= SEQUENCE {
noticeRef NoticeReference OPTIONAL,
explicitText DisplayText OPTIONAL}
NoticeReference ::= SEQUENCE {
organization DisplayText,
noticeNumbers SEQUENCE OF INTEGER }
DisplayText ::= CHOICE {
ia5String IA5String,
visibleString VisibleString,
bmpString BMPString,
utf8String UTF8String }
unstructuredName ::= CHOICE {
Ia5String IA5String,
directoryString DirectoryString}
unstructuredAddress ::= CHOICE {
Ia5String IA5String,
directoryString DirectoryString}
challengePassword ::= DirectoryString
subjectAltName ::= SEQUENCE OF GeneralName
GeneralName ::= CHOICE {
otherName [0] AnotherName,
rfc822Name [1] IA5String,
dNSName [2] IA5String,
x400Address [3] ANY, --ORAddress,
directoryName [4] Name,
ediPartyName [5] EDIPartyName,
uniformResourceIdentifier [6] IA5String,
iPAddress [7] OCTET STRING,
registeredID [8] OBJECT IDENTIFIER}
AnotherName ::= SEQUENCE {
type OBJECT IDENTIFIER,
value [0] EXPLICIT ANY }
EDIPartyName ::= SEQUENCE {
nameAssigner [0] DirectoryString OPTIONAL,
partyName [1] DirectoryString }
certificateTemplateName ::= CHOICE {
octets OCTET STRING,
directoryString DirectoryString}
rsaKey ::= SEQUENCE {
modulus INTEGER,
publicExponent INTEGER}
dsaKey ::= INTEGER
dsaPars ::= SEQUENCE {
P INTEGER,
Q INTEGER,
G INTEGER}
eccName ::= OBJECT IDENTIFIER
ecdsaSigValue ::= SEQUENCE {
r INTEGER,
s INTEGER}
rsassaPssParam ::= SEQUENCE {
digestAlgorithm [0] EXPLICIT AlgorithmIdentifier OPTIONAL,
maskGenAlgorithm [1] EXPLICIT AlgorithmIdentifier OPTIONAL,
saltLength [2] EXPLICIT INTEGER OPTIONAL,
trailerField [3] EXPLICIT INTEGER OPTIONAL}
ASN1
;
}
__END__
Convert::ASN1=HASH(0xa0bcef7b0) [refcount 2] is
+- referenced by REF(0xa0d0a2430) [refcount 2], which is
| +- the array element 10 of ARRAY(0xa06832350) [refcount 2], which is
| | the array element 35 of ARRAY(0xa067fd540) [refcount 1], which is
| | not found anywhere I looked :(
| +- the array element 43 of ARRAY(0xa067fd540) [refcount 1], which was seen before.
+- referenced by REF(0xa0bd35590) [refcount 1], which is
the hash member '1.3.6.1.5.5.7.2.1' of HASH(0xa0bd35578) [refcount 1], which is
referenced by REF(0xa0bd35560) [refcount 1], which is
the hash member 'qualifier' of HASH(0xa0bd35548) [refcount 1], which is
referenced by REF(0xa0bb8bb00) [refcount 1], which is
the hash member 'handlers' of HASH(0xa0baf07d8) [refcount 2], which is
+- referenced by REF(0xa0bd35608) [refcount 1], which is
| the hash member 'options' of Convert::ASN1=HASH(0xa0bcddc50) [refcount 2], which is
| +- referenced by REF(0xa0d0a2448) [refcount 1], which is
| | the array element 11 of ARRAY(0xa06832350) [refcount 2], which was seen before.
| +- referenced by REF(0xa0bd355c0) [refcount 1], which is
| the hash member '1.3.6.1.5.5.7.2.2' of HASH(0xa0bd35578) [refcount 1], which was seen before.
+- referenced by REF(0xa0bd35530) [refcount 1], which is
the hash member 'options' of Convert::ASN1=HASH(0xa0bcef7b0) [refcount 2], which is
+- referenced by REF(0xa0d0a2430) [refcount 2], which was seen before.
+- referenced by REF(0xa0bd35590) [refcount 1], which was seen before.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment