This file is indexed.

/usr/share/doc/stoken/examples/sdtid-test.pl is in stoken 0.92-1.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/usr/bin/perl -w

use strict;
use XML::LibXML;

my $stoken = "stoken";
my $tc = "TokenConverter";

# --once means exit after the first try, leaving a sample sdtid file in cwd
my $once = 0;

sub add_str_node($$$)
{
	my ($parent, $name, $value) = @_;
	my $doc = $parent->ownerDocument;
	my $node = $doc->createElement($name);
	$node->appendChild($doc->createTextNode($value));
	$parent->appendChild($node);
}

sub rand_str
{
	my ($len) = @_;
	my $max_rand = 28;
	if (!defined($len)) {
		$len = int(rand() * $max_rand) + 5;
	}

	my $ret = "";
	while (1) {
		my $c = chr(32 + int(rand() * 95));

		# these expand to 2-byte sequences. see mangle_encoding()
		if ($c eq '&' || $c eq '<' || $c eq '>') {
			$len -= 2;
		} else {
			$len--;
		}
		if ($len <= 0) {
			last;
		}
		$ret .= $c;
	}
	return $ret;
}

sub rand_bool()
{
	return int(rand() * 2);
}

sub random_doc()
{
	my $doc = XML::LibXML::Document->new('1.0');
	my $root = $doc->createElement("TKNBatch");
	$doc->setDocumentElement($root);

	my $node = $doc->createElement("TKNHeader");
	$root->appendChild($node);
	add_str_node($node, "Version", "0");
	add_str_node($node, "Origin", rand_str());
	add_str_node($node, "Dest", rand_str());
	add_str_node($node, "Name", rand_str(16));
	add_str_node($node, "FirstToken", rand_str());
	add_str_node($node, "LastToken", rand_str());
# NumTokens: default
	add_str_node($node, "DefAddPIN", rand_bool());
	add_str_node($node, "DefLocalPIN", rand_bool());
	add_str_node($node, "DefCopyProtection", rand_bool());
	add_str_node($node, "DefPinType", rand_bool());
	add_str_node($node, "DefKeypad", rand_bool());
	add_str_node($node, "DefProtLevel", rand_bool());
	add_str_node($node, "DefRevision", rand_bool());
	add_str_node($node, "DefTimeDerivedSeeds", rand_bool());
	add_str_node($node, "DefAppDerivedSeeds", rand_bool());
# DefFormFactor: default
# HeaderMAC: computed

	my $tkn = $doc->createElement("TKN");
	$root->appendChild($tkn);
# SN: random
# Seed: random
	add_str_node($tkn, "UserFirstName", rand_str());
	add_str_node($tkn, "UserLastName", rand_str());
	add_str_node($tkn, "UserLogin", rand_str());

	$node = $doc->createElement("TokenAttributes");
	$tkn->appendChild($node);
# DeviceSerialNumber: blank
	add_str_node($node, "Nickname", rand_str());
# TokenMAC: computed

	$node = $doc->createElement("TKNTrailer");
	$root->appendChild($node);
	add_str_node($node, "BatchSignature", rand_str(100));
	add_str_node($node, "BatchCertificate", rand_str(500));
	return $doc;
}

#
# MAIN
#

# allow running from the source dir
if (-x "../stoken") {
	$ENV{'PATH'} = "..:".$ENV{'PATH'};
}

while (@ARGV != 0) {
	my $a = $ARGV[0];
	shift @ARGV;

	if ($a eq "--once") {
		$once = 1;
	} else {
		die "unknown arg: '$a'";
	}
}

do {
	my $doc = random_doc();
	open(F, ">tpl.xml") or die;
	print F $doc->toString(1);
	close(F);

	system("$stoken export --random --template tpl.xml --sdtid > out.sdtid") == 0
		or die "can't run stoken";
	system("$tc out.sdtid > ctf.txt") == 0 or die "TokenConverter failed";

	system("$stoken show --file ctf.txt --seed | head -n 2 > seed.txt")
		== 0 or die "can't read seed from ctf";
	system("$stoken show --file out.sdtid --seed | head -n 2 > seed-test.txt")
		== 0 or die "can't read seed from sdtid";

	system("cmp seed.txt seed-test.txt") == 0 or die "seed mismatch";
} while (!$once);

exit 0;