Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
gbarr committed Apr 6, 2004
0 parents commit b6d70f1
Show file tree
Hide file tree
Showing 21 changed files with 950 additions and 0 deletions.
65 changes: 65 additions & 0 deletions ChangeLog
@@ -0,0 +1,65 @@
2002-05-28 15:22 Graham Barr

* lib/Authen/SASL.pm:

Release 2.02

2002-05-28 14:36 Graham Barr

* MANIFEST, lib/Authen/SASL/Perl/LOGIN.pm:

Add LOGIN mechanism commonly used by SMTP

2002-03-31 15:39 Graham Barr

* lib/Authen/SASL.pm:

Release 2.01

2002-03-22 10:13 Graham Barr

* t/cram_md5.t:

Skip cram_md5 test if Digest::HMAC_MD5 is not installed

2002-02-18 16:56 Graham Barr

* lib/Authen/SASL/Perl.pm:

Add securesocket to the ::Perl base class.

2002-01-28 19:52 Graham Barr

* MANIFEST, lib/Authen/SASL.pm, t/anon.t, t/callback.t,
t/cram_md5.t, t/external.t, t/plain.t:

Add some tests

2002-01-24 15:21 Graham Barr

* lib/Authen/SASL/Perl.pm:

Allow callback to be called on the connection object

2002-01-24 12:04 Graham Barr

* MANIFEST, Makefile.PL, api.txt, compat_pl, example_pl,
lib/Authen/SASL.pm, lib/Authen/SASL.pod,
lib/Authen/SASL/CRAM_MD5.pm, lib/Authen/SASL/EXTERNAL.pm,
lib/Authen/SASL/Perl.pm, lib/Authen/SASL/Perl/ANONYMOUS.pm,
lib/Authen/SASL/Perl/CRAM_MD5.pm, lib/Authen/SASL/Perl/EXTERNAL.pm,
lib/Authen/SASL/Perl/PLAIN.pm:

Initial revision

2002-01-24 12:04 Graham Barr

* MANIFEST, Makefile.PL, api.txt, compat_pl, example_pl,
lib/Authen/SASL.pm, lib/Authen/SASL.pod,
lib/Authen/SASL/CRAM_MD5.pm, lib/Authen/SASL/EXTERNAL.pm,
lib/Authen/SASL/Perl.pm, lib/Authen/SASL/Perl/ANONYMOUS.pm,
lib/Authen/SASL/Perl/CRAM_MD5.pm, lib/Authen/SASL/Perl/EXTERNAL.pm,
lib/Authen/SASL/Perl/PLAIN.pm:

import

21 changes: 21 additions & 0 deletions MANIFEST
@@ -0,0 +1,21 @@
ChangeLog
MANIFEST
Makefile.PL
api.txt
compat_pl
example_pl
lib/Authen/SASL.pm
lib/Authen/SASL.pod
lib/Authen/SASL/CRAM_MD5.pm
lib/Authen/SASL/EXTERNAL.pm
lib/Authen/SASL/Perl.pm
lib/Authen/SASL/Perl/ANONYMOUS.pm
lib/Authen/SASL/Perl/CRAM_MD5.pm
lib/Authen/SASL/Perl/EXTERNAL.pm
lib/Authen/SASL/Perl/LOGIN.pm
lib/Authen/SASL/Perl/PLAIN.pm
t/anon.t
t/callback.t
t/cram_md5.t
t/external.t
t/plain.t
10 changes: 10 additions & 0 deletions Makefile.PL
@@ -0,0 +1,10 @@
# This -*- perl -*- script makes the Makefile

use 5.004;
use ExtUtils::MakeMaker;

WriteMakefile(
VERSION_FROM => 'lib/Authen/SASL.pm',
NAME => 'Authen::SASL',
);

49 changes: 49 additions & 0 deletions api.txt
@@ -0,0 +1,49 @@
Basically the Authen::SASL module gathers some info. When ->client_new
is called the plugin is called to create a $conn object. At that point
it should query the Authen::SASL object for mechanisms and callbacks

Properties are then set on the $conn object by calling $conn->property

Then client_start is called

Currently client_start returns the mechanism name and the initial
string, but I am thinking about changing that to just the initial
string. The mecanism is avaliabe via a method call anyway.


Then we call client_step with a challenge string to get a response
string.


Quite simple really I think.


So the plugin just needs to support

client_new
client_start
client_step
property # set/get for properties
mechanism # returns the name of the chosen mechanism
service # the service name passed to client_new
host # the hostname passed to client_new


properties and callbacks are passed by name, so you will need to convert
them to numbers.

There are three types of call back

user => 'fred'

When the user callback is called, it will just return the string 'fred'

user => \&subname

When the user callback is called, &subname will be called and it will
be passed the $conn object as the first argument.

user => [ \&subname, 1, 2, 3]

When the user callback is called, &subname will be called. It will be passed
the $conn object, followed by all other values in the array
18 changes: 18 additions & 0 deletions compat_pl
@@ -0,0 +1,18 @@
#!/usr/bin/env perl

# short script to check compatability with previous Authen::SASL library

use lib 'lib';
use Authen::SASL;

my $sasl = Authen::SASL->new('CRAM-MD5', password => 'fred');

$sasl->user('gbarr');

$initial = $sasl->initial;
$mech = $sasl->name;

print "$mech;", unpack("H*",$initial),";\n";

print unpack "H*", $sasl->challenge('xyz');
print "\n";
40 changes: 40 additions & 0 deletions example_pl
@@ -0,0 +1,40 @@
#!/usr/bin/env perl

# short example script

use lib 'lib';
use Authen::SASL;

# This part is in the user script

my $sasl = Authen::SASL->new(
mechanism => 'PLAIN CRAM-MD5 EXTERNAL ANONYMOUS',
callback => {
user => 'gbarr',
pass => 'fred',
authname => 'none'
},
);

# $sasl is then passed to a library (eg Net::LDAP)
# which will then do

my $conn = $sasl->client_new("ldap","localhost", "noplaintext noanonymous");

# The library would also set properties on the connection
#$conn->property(
# iplocal => $socket->sockname,
# ipremote => $socket->peername,
#);

# It would then start things off and send this info to the server

my $initial = $conn->client_start;
my $mech = $conn ->mechanism;

print "$mech;", unpack("H*",$initial),";\n";

# When the server want more information, the library would call

print unpack "H*", $conn->client_step("xyz");
print "\n";
93 changes: 93 additions & 0 deletions lib/Authen/SASL.pm
@@ -0,0 +1,93 @@
# Copyright (c) 2002 Graham Barr <gbarr@pobox.com>. All rights reserved.
# This program is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.

package Authen::SASL;

use strict;
use vars qw($VERSION @Plugins);
use Carp;

$VERSION = "2.02";

@Plugins = qw(
Authen::SASL::Cyrus
Authen::SASL::Perl
);

sub new {
my $pkg = shift;
my %opt = ((@_ % 2 ? 'mechanism' : ()), @_);

my $self = bless {
mechanism => $opt{mechanism} || $opt{mech},
callback => {},
}, $pkg;

$self->callback(%{$opt{callback}}) if ref($opt{callback}) eq 'HASH';

# Compat
$self->callback(user => ($self->{user} = $opt{user})) if exists $opt{user};
$self->callback(pass => $opt{password}) if exists $opt{password};
$self->callback(pass => $opt{response}) if exists $opt{response};

$self;
}


sub mechanism {
my $self = shift;
@_ ? $self->{mechanism} = shift
: $self->{mechanism};
}

sub callback {
my $self = shift;

return $self->{callback}{$_[0]} if @_ == 1;

my %new = @_;
@{$self->{callback}}{keys %new} = values %new;

$self->{callback};
}

# The list of packages should not really be hardcoded here
# We need some way to discover what plugins are installed

sub client_new { # $self, $service, $host, $secflags
my $self = shift;

foreach my $pkg (@Plugins) {
if (eval "require $pkg") {
return ($self->{conn} = $pkg->client_new($self, @_));
}
}

croak "Cannot find a SASL Connection library";
}

# Compat.
sub user {
my $self = shift;
my $user = $self->{callback}{user};
$self->{callback}{user} = shift if @_;
$user;
}

sub challenge {
my $self = shift;
$self->{conn}->client_step(@_);
}

sub initial {
my $self = shift;
$self->client_new($self)->client_start;
}

sub name {
my $self = shift;
$self->{conn} ? $self->{conn}->mechanism : ($self->{mechanism} =~ /(\S+)/)[0];
}

1;

0 comments on commit b6d70f1

Please sign in to comment.