Cyrus(3pm)
okay bestie, welcome to the Authen::SASL::Cyrus manual page π this is part 1, so buckle up, we're getting into the XS glue that makes Perl SASL talk to Cyrus SASL. no cap. π¦
π NAME π
Authen::SASL::Cyrus β XS code to glue Perl SASL to Cyrus SASL. that's the whole vibe. β¨
πΈ SYNOPSIS πΈ
here's the quick lil' peek at how you use it, bestie: π
use Authen::SASL;
my $sasl = Authen::SASL->new(
mechanism => 'NAME',
callback => { NAME => VALUE, NAME => VALUE, ... },
);
my $conn = $sasl->client_new(<service>, <server>, <iplocalport>, <ipremoteport>);
my $conn = $sasl->server_new(<service>, <host>, <iplocalport>, <ipremoteport>);
β¨ DESCRIPTION β¨
SASL? it's a generic mechanism for authentication used by several network protocols. Authen::SASL::Cyrus provides an implementation framework that all protocols should be able to share. literally, it's giving shared framework energy. π
The XS framework makes calls into the existing libsasl.so resp. libsasl2 shared library to perform SASL client connection functionality, including loading existing shared library mechanisms. it's lowkey doing a lot. π₯
π CONSTRUCTOR π
okay so the constructor can be called with or without arguments. passing arguments is just a short cut to calling the mechanism and callback methods. no biggie. π
You have to use the Authen::SASL new-constructor to create a SASL object. the Authen::SASL object then holds all necessary variables and callbacks, which you gave when creating the object. client_new and server_new will retrieve needed information from this object. it's giving main character energy, periodt. π
π CALLBACKS π
callbacks are very important, bestie. it depends on the mechanism which callbacks have to be set. and it is not a failure to set callbacks even if they aren't used. (e.g. password-callback when using GSSAPI or KERBEROS_V4). so don't stress. π
The Cyrus-SASL library uses callbacks when the application needs some information. common reasons are getting usernames and passwords. like, it's literally asking for the tea. π΅
Authen::SASL::Cyrus allows Cyrus-SASL to use perl-variables and perl-subs as callback-targets. so you can pass scalars, coderefs, arrayrefs... we'll get to that. π
Currently Authen::SASL::Cyrus supports the following Callback types: (for a more detailed description on what the callback type is used for see the respective man pages)
Remark: All callbacks, which have to return some values (e.g.:**resultinsasl_getsimple_t) do this by returning the value(s). See example below. π
user(client),auth(client),language(client) β these callbacks represent thesasl_getsimple_tfrom the library. β¨- Input: none
- Output:
username,authnameorlanguage
password(client),pass(client) β these callbacks represent thesasl_getsecret_tfrom the library. π- Input: none
- Output:
password
realm<client> β this callback represents thesasl_getrealm_tfrom the library. π¦- Input: a list of available realms
- Output: the chosen realm
- (This has nothing to do with GSSAPI or KERBEROS_V4 realm).
checkpass(server, SASL v2 only) β this callback represents thesasl_server_userdb_checkpass_tfrom the library. β- Input:
username,password - Output: true or false
- Input:
getsecret(server, SASL v1 only) β this callback represents thesasl_server_getsecret_tfrom the library. Sasl will check if the passwords are matching. π- Input:
mechanism,username,default_realm - Output:
secret_phrase (password) - Remark: Programmers that are using should specify both callbacks (
getsecretandcheckpass). Then, depending on your Cyrus SASL library either the one or the other is called. Cyrus SASL v1 ignorescheckpassand Cyrus SASL v2 ignoresgetsecret. π
- Input:
putsecret(SASL v1) andsetpass(SASL v2) β are currently not supported (and won't be, unless someone needs it). πcanonuser(server/client in SASL v2, server only in SASL v1) β this callback name represents thesasl_canon_user_tfrom the library. π¦- Input:
Type of principal,principal,userrealmand maximal allowed length of the output. - Output: canonicalised
principal Type of principalisAUTHIDfor Authentication ID orAUTHZIDfor Authorisation ID.- Remark: This callback is ideal to get the username of the user using your service. If
Authen::SASL::Cyrusis linked to Cyrus SASL v1, which doesn't have a canonuser callback, it will simulate this callback by using the authorize callback internally. Don't worry, the authorize callback is available anyway. π
- Input:
authorize(server) β this callback represents thesasl_authorize_tfrom the library. π- Input:
authenticated_username,requested_username, (default_realmSASL v2 only) - Output:
canonicalised_usernameSASL v1 resp. true or false when using SASL v2 lib There is something TODO, I think. π€
- Input:
setpass(server, SASL v2 only) β this callback represents thesasl_server_userdb_setpass_tfrom the library. π- Input:
username,new_password,flags(0x01CREATE,0x02DISABLE,0x04NOPLAIN) - Out: true or false
- Input:
π¦ Ways to pass a callback π¦
Authen::SASL::Cyrus supports three different ways to pass a callback. pick your fighter. π
CODEREF
If the value passed is a code reference then, when needed, it will be called. it's giving sub { ... } energy. β¨
ARRAYREF
If the value passed is an array reference, the first element in the array must be a code reference. When the callback is called the code reference will be called with the value from the array passed after. so like [ \&code, @args ]. π
SCALAR
All other values passed will be returned directly to the SASL library as the answer to the callback. simple as that. π
β¨ Example of setting callbacks β¨
$sasl = new Authen::SASL (
mechanism => "PLAIN",
callback => {
# Scalar
user => "mannfred",
pass => $password,
language => 1,
# Coderef
auth => sub { return "klaus", }
realm => \&getrealm,
# Arrayref
canonuser => [ \&canon, $self ],
}
);
The last example is ideal for using object methods as callback functions. Then you can do something like this:
sub canon {
my ($this,$type,$realm,$maxlen,$user) = @_;
$this->{_username} = $user if ($type eq "AUTHID");
return $user; }
β¨ METHODS β¨
Okay bestie, this is the part where the actual doing stuff happens. Every method below lives on the connection object you got back from the constructors, so like, keep that reference close to your heart π«Ά
server_new ( SERVICE , HOST = "" , IPLOCALPORT , IPREMOTEPORT )β the constructor for making server-side sasl contexts.
It creates a brand new connection object and blesses it into Authen::SASL::Cyrus, then hands it back to you. And it's on that returned reference that all the methods below are available, okurrr? SERVICE is the name of the service you're implementing, and the underlying mechanism might peek at it. A super classic example of a service is "ldap".
client_new ( SERVICE , HOST , IPLOCALPORT , IPREMOTEPORT )β constructor for creating server-side sasl contexts. (No fr, that's literally what the docs say for this one too, we're just relaying it π)
Same deal: creates and returns a new connection object blessed into Authen::SASL::Cyrus, and that returned reference is where all the following methods hang out. SERVICE is the name of the service being implemented, which the underlying mechanism may use β an example service is "ldap". HOST is the name of the server being contacted, and the underlying mechanism might use that too.
Peep the SYNOPSIS for an example.
Remark: this function andserver_newget called byAuthen::SASLwhen you use its*_newfunction. And since you have to useAuthen::SASLanyway, bestie, normally you do not need to call this one directly. Periodt.
IPLOCALPORT and IPREMOTEPORT arguments are only available when ASC is linked against Cyrus SASL 2.x. These arguments are needed for KERBEROS_V4 and CS 2.x on the server side. Don't know if it's necessary for the client side (that's the original author's uncertainty, not mine, I'm just the messenger π). The format of these arguments in an IPv4 environment should be:
a.b.c.d;port
See sasl_server_new(3) for details.
server_start ( CHALLENGE )βserver_startkicks off the authentication using the chosen mechanism. If the installed Cyrus-SASL doesn't support that mechanism, it fails. And because some mechanisms need the client to start the negotiation, you're allowed to pass the client challenge in as a parameter.client_start ( )β the very first step to be performed. Returns the initial value you pass over to the server. The client has to start the negotiation always β no skipping, no exceptions πserver_step ( CHALLENGE )βserver_stepdoes the next step in the negotiation process. The first parameter you hand it is the client's challenge/response.client_step ( CHALLENGE )
Remark:client_start,client_step,server_startandserver_stepwill return the respective sasl response orundef. The returned value says nothing about the current negotiation status. It is absolutely possible that one of these functions returnsundefand everything is completely fine for SASL β there's just another step needed. So don't panic, babes π
So that means you have to check need_step and code during negotiation. See the example below.
listmech( START , SEPARATOR , END )βlistmechreturns a string containing all the mechanisms allowed for the user set byuser.STARTis the token that gets put at the beginning of the string,SEPARATORis the token used to separate the mechanisms, andENDis the token that gets put at the end of the returned string β¨setpass(user, newpassword, oldpassword, flags)checkpass(user, password)
setpass and checkpass are only available when using the Cyrus-SASL 2.x library.
setpass sets a new password (it depends on the mechanism whether the setpass callback gets called). checkpass checks a password for the user (it calls the checkpass callback).
For both functions, go read the man pages of Cyrus SASL for a detailed description.
Both functions return true on success, false otherwise.
global_listmech ( )β only available when using the Cyrus-SASL 2.x library.
It returns an array with all mechanisms loaded by the library.
encode ( STRING )decode ( STRING )
The Cyrus-SASL developers suggest using the encode and decode functions for every bit of traffic that will run over the network after a successful authentication. Protect your data bestie π
encode returns the encrypted string generated from STRING. decode returns the decrypted string generated from STRING.
It depends on the mechanism you're using how secure that encryption will actually be π
error ( )βerrorreturns an array with all known error messages. Basicly thesasl_errstringfunction is called with the currenterror_code. When using the Cyrus-SASL 2.x library, the string returned bysasl_errdetailis also given back. On top of that, the specialAuthen::SASL::Cyrusadvice is returned if it's been set. And heads up: after you call theerrorfunction, the error code and the special advice get thrown away. Gone. Poof π¨code ( )βcodereturns the current Cyrus-SASL error code.mechanism ( )βmechanismreturns the current authentication mechanism being used.need_step ( )βneed_stepreturns true if the SASL library needs another step. Otherwisefalseis returned. You can also just usecode == 1, but honestlyneed_steplooks smarter I think. That's why we're all using perl, eh? π
πΈ EXAMPLE πΈ
Server-side
# The example uses Cyrus-SASL v2
# Set the SASL_PATH to the location of the SASL-Plugins
# default is /usr/lib/sasl2
$ENV{'SASL_PATH'} = "/opt/products/sasl/2.1.15/lib/sasl2";
#
my $sasl = Authen::SASL->new (
mechanism => "PLAIN",
callback => {
checkpass => \&checkpass,
canonuser => \&canonuser,
}
);
# Creating the Authen::SASL::Cyrus object
my $conn = $sasl->server_new("service","","ip;port local","ip;port remote");
# Clients first string (maybe "", depends on mechanism)
# Client has to start always
sendreply( $conn->server_start( &getreply() ) );
while ($conn->need_step) {
sendreply( $conn->server_step( &getreply() ) );
}
if ($conn->code == 0) {
print "Negotiation succeeded.\n";
} else {
print "Negotiation failed.\n";
}
Client-side
# The example uses Cyrus-SASL v2
# Set the SASL_PATH to the location of the SASL-Plugins
# default is /usr/lib/sasl2
$ENV{'SASL_PATH'} = "/opt/products/sasl/2.1.15/lib/sasl2";
#
my $sasl = Authen::SASL->new (
mechanism => "PLAIN",
callback => {
user => \&getusername,
pass => \&getpassword,
}
);
# Creating the Authen::SASL::Cyrus object
my $conn = $sasl->client_new("service", "hostname.domain.tld");
# Client begins always
sendreply($conn->client_start());
while ($conn->need_step) {
sendreply($conn->client_step( &getreply() ));
}
if ($conn->code == 0) {
print STDERR "Negotiation succeeded.\n";
} else {
print STDERR "Negotiation failed.\n";
}
See t/plain.t for a working script. Go run it bestie, it slaps πββοΈ
π§ͺ TESTING π§ͺ
I tested ASC (server and client) with the following mechanisms:
GSSAPI
Don't forget to create a keytab. Non-root keytabs can be specified through $ENV{'KRB5_KTNAME'} (Heimdal >= 0.6, MIT).
KERBEROS_V4
Available since 0.10 β you have to add IPLOCALPORT and IPREMOTEPORT to the *_new functions.
PLAIN
π SEE ALSO π
Authen::SASL
man pages for sasl_* library functions.
π AUTHOR π
Originally written by Mark Adamson <mark@nb.net>
Cyrus-SASL 2.x support by Leif Johansson
Glue for server_* and many other structural improvements by Patrick Boettcher <patrick.boettcher@desy.de>
Please report any bugs, or post any suggestions, to the authors. They want to hear from you, fr fr π«Ά
π« THANKS π«
- Guillaume Filion for testing the server part and for giving hints about some bugs (documentation).
- Wolfgang Friebel for bother around with rpm building of test releases.
Β©οΈ COPYRIGHT Β©οΈ
Copyright (c) 2003-5 Patrick Boettcher, DESY Zeuthen. All rights reserved. Copyright (c) 2003 Carnegie Mellon University. All rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
And that's the whole page, bestie π You just read perl v5.34.0, dated 2022-02-06, from Cyrus(3pm) β iconic, no cap. Now go authenticate something responsibly π
β¨
π¦ where this page comes from
- ubuntu jammy: libauthen-sasl-cyrus-perl 0.13-server-12build1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms