Authen-Passphrase

 view release on metacpan or  search on metacpan

lib/Authen/Passphrase/VMSPurdy.pm  view on Meta::CPAN

				or croak "not a valid raw hash";
			$self->{hash} = "$value";
		} elsif($attr eq "hash_hex") {
			croak "hash specified redundantly"
				if exists($self->{hash}) ||
					defined($passphrase);
			$value =~ m#\A[0-9A-Fa-f]{16}\z#
				or croak "not a valid hexadecimal hash";
			$self->{hash} = pack("H*", $value);
		} elsif($attr eq "passphrase") {
			croak "passphrase specified redundantly"
				if exists($self->{hash}) ||
					defined($passphrase);
			$self->_passphrase_acceptable($value)
				or croak "can't accept that passphrase";
			$passphrase = $value;
		} else {
			croak "unrecognised attribute `$attr'";
		}
	}
	$self->{algorithm} = "PURDY_S" unless exists $self->{algorithm};
	croak "username not specified" unless exists $self->{username};
	croak "salt not specified" unless exists $self->{salt};
	$self->{hash} = $self->_hash_of($passphrase)
		if defined $passphrase;
	croak "hash not specified" unless exists $self->{hash};
	return $self;
}

=item Authen::Passphrase::VMSPurdy->from_crypt(PASSWD)

Generates a new passphrase recogniser object using the VMS Purdy
polynomial algorithm family, from a crypt string.  The string must
consist of an algorithm identifier, the salt in hexadecimal, the hash
in hexadecimal, then the username.  The salt must be given as four
hexadecimal digits, the first two giving the least-significant byte and
the last two giving the most-significant byte, with most-significant
nybble first within each byte.  The algorithm identifier must be
"B<$VMS1$>" for "B<PURDY>", "B<$VMS2$>" for "B<PURDY_V>", or "B<$VMS3$>"
for "B<PURDY_S>".  The whole crypt string must be uppercase.

=cut

my %decode_crypt_alg_num = (
	"1" => "PURDY",
	"2" => "PURDY_V",
	"3" => "PURDY_S",
);

sub from_crypt {
	my($class, $passwd) = @_;
	if($passwd =~ /\A\$VMS([123])\$/) {
		my $alg = $1;
		$passwd =~ /\A\$VMS[123]\$([0-9A-F]{4})
			    ([0-9A-F]{16})([_\$0-9A-Z]{1,31})\z/x
			or croak "malformed \$VMS${alg}\$ data";
		my($salt, $hash, $un) = ($1, $2, $3);
		return $class->new(algorithm => $decode_crypt_alg_num{$alg},
			username => $un, salt_hex => $salt, hash_hex => $hash);
	}
	return $class->SUPER::from_crypt($passwd);
}

=item Authen::Passphrase::VMSPurdy->from_rfc2307(USERPASSWORD)

Generates a new passphrase recogniser object using the VMS Purdy
polynomial algorithm family, from an RFC 2307 string.  The string must
consist of "B<{CRYPT}>" (case insensitive) followed by an acceptable
crypt string.

=back

=head1 METHODS

=over

=item $ppr->algorithm

Returns the algorithm variant identifier string.  It may be "B<PURDY>"
(the original), "B<PURDY_V>" (modified to use full length of the
username), and "B<PURDY_S>" (extra rotations to avoid aliasing when
processing long strings).

=cut

sub algorithm {
	my($self) = @_;
	return $self->{algorithm};
}

=item $ppr->username

Returns the username string.  All alphabetic characters in it are
uppercase, which is the canonical form.

=cut

sub username {
	my($self) = @_;
	return $self->{username};
}

=item $ppr->salt

Returns the salt, as an integer.

=cut

sub salt {
	my($self) = @_;
	return $self->{salt};
}

=item $ppr->salt_hex

Returns the salt, as a string of four hexadecimal digits.  The first
two digits give the least-significant byte and the last two give the
most-significant byte, with most-significant nybble first within each
byte.

=cut



( run in 0.899 second using v1.01-cache-2.11-cpan-364913b4093 )