(1) 什么是SASL和Cyrus SASL
SASL (Simple Authentication Security Layer) is an Internet
standards-track method for remote computers to authenticate. The Cyrus
SASL library makes supporting various SASL mechanisms easy for both
client and server writers. 
The Cyrus project is the implementation of an enterprise mail system
by the Carnegie Mellon University Computing Services Department. We are
interested in scalable, easy to administer systems. 
(2) Cyrus SASL组成部分
SASL是一个胶合(glue)库,通过这个库把 应用层   与  形式多样的 认证系统整合 在一起。这有点类似于 PAM,但是后者是认证方式,决定什么人可以访问什么服务而SASL是认证过程,侧重于信任建立过程,这个过程可以调用PAM来建立信任关系。
应用层
应用层是SASL库的使用者 , 既可以是客户应用程序,也可以是服务应用程序,或者两者都是(在代理的情况下)。 应用层负责SASL认证协商的连线和传达,具体的认证交给SASL库 。 应用层的例子有Cyrus IMAPd,OpenLDAP,Sendmail,Mutt,sieveshell,cyradm等 。
SASL胶合层(Glue Layer)
负责如下的工作:
加载插件;
从应用层获取必要的认证属性,以选择适当的认证机制(或者限制可用的认证机制);
给应用层列出可用的插件;
为特定的认证请求选择最好的认证机制;
在应用层和被选的认证机制间路由认证数据;
为应用层提供SASL协商信息,比如认证的用户,请求的认证ID,安全层的强度等。
SASL还提供一些别的服务给应用层和插件,一些是常用的工具,比如MIME Base64编码解码,随机数生成;还有一些是和认证相关的,比如口令验证服务。
最后,SASL还允许应用层和认证机制层访问两种特殊类型的插件:Auxiliary Property或者
auxprop插件,它提供了简单的数据库接口,可返回用户属性,比如口令,home目录,邮件地址等;Username
Canoicalization,提供了一个站点相关的用户正名服务(使用户名称规范化),或者其他的任务.
SASL认证机制(SASL Mechanisms)
有三种类型的机制:
Password Verification Mechanisms  - 接收远程的口令,传递给SASL胶合层,由口令验证器验证,这种机制的例子有 PLAIN
Shared Secret Mechanisms  - 不是直接传递口令明文,而是服务方发起一个认证,客户证明自己知道这个口令,这需要服务方和客户方都保存有口令.这种机制的例子有 CRAM-MD5,DIGEST-MD5以及SRP ;
Kerberos Mechanisms  - 使用信任的第三方来验证客户。
Auxiliary Property(auxprop)
为胶合层提供数据库服务,Cyrus SASL支持两种auxprop插件:SASLdb和SQL。auxprop通常用于共享密码机制。
Username Canonicalization
不是很常用,一般用于为应用层提供用户的规范名称。
口令验证服务
根据用户名和口令的明文,判断是否验证正确。 口令验证服务器通过SASL选项pwcheck_method来选择,有两类主要的口令验证器:
auxprop - 使用auxprop插件获取口令,比较和用户提供的口令是否相符;
saslauthd  - 呼叫saslauthd服务进程,验证用户。saslauthd支持很多识别方式,比如PAM,LDAP,Kerberos数据库等 。
(3) SASL 术语
认证ID(Authentication identifier)和授权ID(Authorization identifier)
userid(user id, authorization id) - 用户ID,授权ID,说明执行操作的授权个体。
authid(authentication id) - 认证ID,证明某人确系某人。
比如小王休假,小李暂时接替他的工作。那么为了有小王的权限,小李认证时使用自己的帐号,即authid,执行具体的操作时需要有小王的user id,这样才能做他的工作。
一般userid和authid是相同的。
Realms
A realm is an abstract set of users and certain mechanisms authenticate users in a certain realm. 
最简单的情况是单服务单机器的情况,realm就是FQDN(Full-qualified domain name),如果应用层没有提供,则很多SASL机制采用默认的。
如果要多机共享口令,则通常选择域名,比如CMU.EDU。单个站点也可以支持多个不同的realms。为了把不同realm的用户加入sasldb,可以在saslpasswd2命令中用u选项,SQL插件通过宏'%r'在查询串中加入realm。
(4) SASL工作流程
PLAIN机制,sasl_checkpass(),以及明文口令
auxprop - 根据auxiliary property插件提供的userPassword属性验证用户,数据库通常保存在/etc/sasldb2;
saslauthd  -  通过saslauthd验证用户,-a选项指示saslauthd的具体机制,-n指示saslauthd的线程数;
Courier-IMAP - 通过Courier-IMAP的authdaemond检查口令,类似于saslauthd;
pwcheck - 使用独立辅助服务进程来验证 ;
write your own - 自己写一个验证方式。
共享密码机制
CRAM-MD5和DIGEST-MD5使用这种机制,注意,这些方式不能使用saslauthd。 如果不想用这些方式,可从插件目录移走这些插件,或者用mech_list禁用它们。
为了简单起见,SASL库把口令的明文形式保存在/etc/sasldb2中。
Kerberos mechanisms
The Cyrus SASL library also comes with two mechanisms that make use
of Kerberos: KERBEROS_V4, which should be able to use any Kerberos v4
implementation, and GSSAPI (tested against MIT Kerberos 5, Heimdal
Kerberos 5 and CyberSafe Kerberos 5). These mechanisms make use of the
kerberos infrastructure and thus have no password database.
Applications
that wish to use a kerberos mechanism will need access to a service
key, stored either in a "srvtab" file (Kerberos 4) or a "keytab" file
(Kerberos 5). Currently, the keytab file location is not configurable
and defaults to the system default (probably /etc/krb5.keytab). 
The Kerberos 4 srvtab file location is configurable; by default it
is /etc/srvtab, but this is modifiable by the "srvtab" option.
Different SASL applications can use different srvtab files. 
A SASL application must be able to read its srvtab or keytab file. 
OTP机制和基于OPIE的OTP
The Cyrus SASL library also supports the One-Time-Password (OTP)
mechanism. This mechanism is similar to CRAM-MD5 and DIGEST-MD5 in that
is uses a shared secret and a challenge/response exchange. However, OTP
is more secure than the other shared secret mechanisms in that the
secret is used to generate a sequence of one-time (single use)
passwords which prevents reply attacks, and that secret need not be
stored on the system. These one-time passwords are stored in the
/etc/sasldb2 database. See the Shared secrets mechanisms section for a
discussion of the /etc/sasldb2 database. 
For sites with an existing OTP infrastructure using OPIE, Cyrus SASL
can be configured to use OPIE v2.4 instead of using its own database
and server-side routines. OPIE should be configured with the
--disable-user-locking option if the SASL server application will not
be running as "root".
OPIE uses its own "opiekeys" database for
storing the data necessary for generating the server challenges. The
location of the opiekeys file is configurable in SASL; by default it is
/etc/opiekeys, but this is modifiable by the "opiekeys" option. 
A SASL server application must be able to read and write the opiekeys file. 
(5) 如何配置选项
缺省配置文件保存在/usr/lib/sasl2/App.conf里 ,这里App.conf为应用层名字, 比如Sendmail为/usr/lib/sasl2/Sendmail.conf
标准的Cyrus SASL配置文件类似于:
srvtab: /var/app/srvtag
pwcheck_method: saslauthd
应用层可重新定义SASL库的选项,这因应用层而异,比如Cyrus imapd保存配置文件为/etc/imapd.conf。
(6) Cyrus SASL 测试
Cyrus SASL库带了两个测试程序: sasl2-sample-server和sasl2-samle-client,分别对应着服务程序和客户程序,可对SASL的配置进行测试 。两个程序都带了三个参数:
-p TCP监听或者连接的端口号,缺省为12345
-s 服务名称,缺省为rcmd
-m 认证的机制
此外sasl2-sample-client还要求有一个服务程序主机名称或者IP地址的参数。
首先我们给测试服务程序提供一个配置文件,sample.conf,保存 在/usr/lib/sasl2目录下,内容如下:
pwcheck_method: auxprop
auxprop_plugin: sasldb
mech_list: plain login ntlm cram-md5 digest-md5
然后我们给sasl2db(在/etc/sasldb2)添加测试帐号,比如marchday:
[root@research sasl2]# saslpasswd2 -c marchday
Password: 
Again (for verification): 
然后我们启动服务程序:
$ sasl2-sample-server -p 9000
打开另一个终端窗口,进行测试:
$ sasl2-sample-client -p 9000 -m PLAIN localhost
如果没别的问题,应该可以看到successful authentication。^_^
你还可以测试别的Mechanisms,这里就不再举例了。
参考资料:
http://www.sendmail.org/~ca/email/cyrus/sysadmin.html

http://asg.web.cmu.edu/sasl/
Cyrus SASL Library Documatation
以Sendmail为例:
应用程序------>SASL 为客户服务的配置/usr/lib/sasl2/Sendmail.conf
       pwcheck_method:pam
       pam---->/etc/pam.d/smtp.sendmail
                     ---->
                      #%PAM-1.0
           auth       required     pam_stack.so service=system-auth
           account    required     pam_stack.so service=system-auth

为APP提供选择具体的认证方法的机会,认证中介、认证代理....

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/27493/showart_401782.html

Cyrus SASL Libary学习相关推荐

  1. WIN10 VS2019 编译Cyrus SASL

    环境 下载安装Visual Studio 2019 安装时在[工作负载]必须勾选[使用C++的桌面开发] 下载cyrus-sasl源码 从Github上clone或者下载zip包,我本来是需要2.1. ...

  2. 【博学谷学习记录】超强总结,用心分享丨大数据超神之路(五):Hadooop基础篇

    文章目录 前言 1.编译源码 1.1 官网下载编译后的包 1.2 手动编译 1.2.1 安装编译相关的依赖 1.2.2 手动安装cmake3.13.5 1.2.3 手动安装snappy1.1.3 1. ...

  3. vulnHub-sick0s1.1学习 两种解法

    下载地址 https://www.vulnhub.com/?q=SickOS1.1 主机发现 nmap 192.168.52.0/24 Nmap scan report for localhost ( ...

  4. SASL - 简单认证和安全层

    SASL - 简单认证和安全层 SASL是一种用来扩充C/S模式验证能力的机制认证机制,  全称Simple Authentication and Security Layer. 当你设定sasl时, ...

  5. 集成OpenLDAP与Kerberos实现统一认证(三):基于SASL/GSSAPI深度集成

    文章目录 1. 写作背景 2. 既定目标 3. 重要概念 3.1 SASL 3.2 GSSAPI 3.3 SASL与GSSAPI的关系 3.4 saslauthd 3.5 Kerberos化 4. 核 ...

  6. 物联网学习篇:Python SDK接入阿里云物联网平台,接收服务端订阅消息

    1. 下载SDK SDK下载链接 下载之后,可见得到了一个 qpid-proton-0.29.0.tar.gz 的压缩包. 有两个方法: 1. 直接运用SCP软件拖进服务器中: 2. 直接用wget下 ...

  7. pop3 postfix 命令_postfix+pop3+imap+cyrus

    1.安装postfix软件包 2.安装smtp认证包 3.安装pop3和imap服务包 4.安装webmail软件包(webmail需要web服务器的支持) Postfix 一.Postfix邮件服务 ...

  8. linux编译安装的报错,linux编译安装时常见错误解决办法

    This article is post on https://coderwall.com/p/ggmpfa 原文链接:http://www.bkjia.com/PHPjc/1008013.html ...

  9. Linux下java web服务器搭建(JDK1.6、MySQL5.1、Apache2.2+2...

    2019独角兽企业重金招聘Python工程师标准>>> 系统:Red Hat Enterprise Linux 5 32位(自带Httpd) 软件准备: 1. jdk-6u31-li ...

最新文章

  1. ewebeditor下利用ckplayer增加html5 (mp4)全平台的支持
  2. 51Nod1230 幸运数
  3. 将Quartz与Spring集成
  4. leetcode 173. 二叉搜索树迭代器
  5. (08)VHDL实现2路选择器
  6. android os跑电量咋关,android 优化耗电量
  7. UC伯克利超酷研究:舞痴和舞王之间,只差一个神经网络
  8. excel文本写入 npoi_C#使用NPOI读写excel
  9. python面试专题--with 关键字与上下文管理
  10. 网络攻防“三剑客”正式加盟墨者安全 担任首席安全顾问...
  11. 1154 Vertex Coloring
  12. 2021-04-26 PNP三极管
  13. 只有 assignment、call、increment、decrement 和 new 对象表达式可用作语句
  14. 机器学习及其应用2013, 机器学习及其应用2015
  15. Enovia文件协作服务器安装,Enovia用户操作手册.doc
  16. Luvwgyx的娱乐场-题解
  17. python实现kd树以及最近邻查找算法
  18. OA系统十五:请假申请一:【请假申请】这个内嵌界面的数据库设计;(即请假申请这个线型工作流程的数据库设计!)
  19. PDFbox的head is mandatory问题
  20. PTA旅游规划(迪杰斯特拉算法)

热门文章

  1. devstack安装openstack
  2. 有趣的6种图片灰度转换算法
  3. ICS共享上网方案与配置
  4. 谷歌漏洞披露规则增加30天补丁缓冲期;Reddit 公开漏洞奖励计划
  5. Sophos 修复 Cyberoam OS 中的 SQL 注入漏洞
  6. 因多年不受重视,研究员公开2个未修复 Tor 0day且承诺再放3个
  7. SMBleed:Windows SMB 协议再被曝严重漏洞
  8. PPP 守护进程 RCE 漏洞已存在17年,可控制几乎所有的 Linux 系统
  9. SuperTuxKart 0.10 测试版发布
  10. Spring-Session基于Redis管理Session