附录 B - 对 GSSAPI 的支持
对 GSSAPI 的支持
为了支持那些需要在各种底层安全机制之间可移植的应用程序, 人们设计了一个 "通用安全服务 API" (Generic Security Service API, 或称 GSSAPI), 它提供对若干预期由多种机制共同提供的安全服务的通用核心访问. GSSAPI 在设计时考虑了 DASS,Kerberos V4 和 Kerberos V5, 并且可以被编写为这些系统之中任意一个或全部的的前端. 希望它也能作为与其他安全系统的接口.
应用程序的可移植性要求所支持的安全服务
具有可比性. 使用 GSSAPI 的应用程序将无法访问底层安全机制的所有特性. 例如, GSSAPI 不允许访问 DASS 的 "节点认证" 特性. 在底层安全机制不支持 GSSAPI 所有特性的范围内, 使用这些特性的应用程序将无法移植到那些安全机制. 例如, Kerberos V4 不支持委派, 因此使用该 GSSAPI 特性的应用程序将无法移植到 Kerberos V4.
本附录解释了如何使用 DASS 提供的原语服务来实现 GSSAPI.
B.1 GSSAPI 概述
GSSAPI 规范的最新草案可作为一份 Internet 草案获取. 以下是对该不断演进文档的简要概述, 不应被视为定论. 这里仅包含那些其实现会是 DASS 特有的 GSSAPI 方面.
GSSAPI 提供了四类函数: 凭证管理 (Credential Management),上下文级调用 (Context-Level Calls),逐消息调用 (Per-message calls) 和支持调用 (Support Calls); 两种对象: 凭证 (Credentials) 和上下文 (Contexts); 以及两类被传输为不透明字节串的数据结构: 令牌 (Tokens) 和消息 (Messages). 凭证持有用于创建令牌的密钥和支持信息. 上下文持有用于对消息签名和加密的密钥和支持信息.
GSSAPI 的凭证管理函数在某种意义上 "不完整", 因为单靠 GSSAPI 无法构建一个有用的安全实现. 需要,但 GSSAPI 并未提供的,基于口令或智能卡创建凭证的函数是必需的. 设想此类函数会由安全机制特定的函数在用户登录时调用, 或通过某个独立的实用程序调用, 而不是从那些意图可移植的应用程序内部调用. 可供可移植应用程序使用的凭证管理函数是:
-
GSS_Acquire_cred: 基于一个名称或进程默认值, 获取对某个现有凭证结构的句柄.
-
GSS_Release_cred: 在使用后释放凭证.
上下文级调用使用凭证来建立上下文. 上下文类似于连接: 它们成对创建, 并且通常用于连接的的两端, 以处理与该连接相关联的消息. 相关的上下文级调用
是:
-
GSS_Init_sec_context: 给定凭证和一个目的地的名称, 创建一个新上下文和一个令牌, 该令牌将允许目的地创建相应的上下文.
-
GSS_Accept_sec_context: 给定凭证和一个传入令牌, 创建与发起端相对应的上下文, 并提供标识发起者的信息.
-
GSS_Delete_sec_context: 在使用后删除一个上下文.
逐消息调用使用上下文, 在持有匹配上下文的双方之间对消息进行签名,验证,加密和解密. 逐消息调用
是:
-
GSS_Sign: 给定一个上下文和一条消息, 产生一个字节串, 它构成对所提供消息的签名.
-
GSS_Verify: 给定一个上下文,一条消息, 以及由 GSS_Sign 返回的字节, 验证该消息是真实的 (自被相应上下文签名以来未被改动).
-
GSS_Seal: 给定一个上下文和一条消息, 产生一个字节串, 其中包含消息和一个签名; 该消息可以被选择性地加密.
-
GSS_Unseal: 给定一个上下文和来自 GSS_Seal 的字节串, 返回原始消息以及一个指示其真实性的状态.
支持调用提供一些实用函数, 例如将名称和状态码转换为可打印的字符串.
B.2 在 DASS 之上实现 GSSAPI
B.2.1 数据结构
GSSAPI 的对象和数据结构并不能整齐地映射到 DASS 架构的对象和数据结构.
本节描述如何使用 DASS 的数据结构和原语来实现这些数据结构
凭证句柄对应于 DASS 中的凭证结构, 其中可移植 API 假定凭证结构本身对应用程序隐藏, 而句柄被传入并传出各个子例程.
上下文初始化令牌对应于 DASS 的令牌. GSSAPI 为令牌规定了一种特定的 ASN.1 编码形式, 其中包含一个机制特定的位串. GSSAPI 的一个实现应当将 DASS 令牌封装在 GSSAPI 的 "包装器" (wrapper) 之内.
上下文句柄在 DASS 中没有对应的结构. DASS 的 Create_token 和 Accept_token 调用返回一个共享密钥和实例标识符. GSSAPI 的一个实现必须将这些值连同一些其他状态信息一起, 打包成一个 "上下文" 不透明结构. 这些数据结构必须用相应的调用分配和释放.
逐消息令牌和密封消息在 DASS 中没有对应的数据结构. 为了完整支持 GSSAPI 功能, DASS 必须被扩展以包含此功能. 这些数据结构由密码学例程在给定上下文结构中的密钥和状态信息以及传给它们的消息时创建. 虽然它们并非 DASS 架构适当的一部分, 但这些数据结构的格式被包含在 C.3 节中.
B.2.2 过程
本节解释如何用 DASS 提供的服务来提供 GSSAPI 的函数. 并非所有 DASS 特性都可通过 GSSAPI 访问.
B.2.2.1 GSS_Acquire_cred
GSSAPI 不提供让用户登录或建立服务器凭证的机制. 它假定某个系统特定的机制创建了那些凭证, 并且应用程序需要某种机制来获取它们. 一个模型实现可能会把所有凭证保存在一个节点全局池中, 按某种凭证名称索引. 池中的凭证会由某个本地策略进行访问控制, 而这不是可移植应用程序所关心的. 那些应用程序只需简单地调用 GSS_Acquire_cred, 如果它们通过了访问控制检查, 就会得到一个可用于后续调用的凭证句柄.
B.2.2.2 GSS_Release_cred
此调用对应于 DASS 的 "delete_credentials" 调用.
B.2.2.3 GSS_Init_sec_context
在一次正常的相互认证过程中, 这个例程会被调用两次. 该过程可以通过查看 "input_context_handle" 是否为零 (在第一次调用时它为零) 来判断这是第一次还是第二次调用. 在第一次调用时, 它将使用 DASS 的 Create_token 服务创建一个令牌, 并且还会分配并填充一个 "上下文" 结构. 该结构将持有由 Create_token 返回的密钥,实例标识符和相互认证令牌, 此外还将持有传入 Init_sec_context 调用的标志. 由 Init_sec_context 返回的令牌, 将是被包含在 GSSAPI 令牌 "包装器" 中的 DASS 令牌. DASS 令牌将包含可选的主体名称.
如果在 GSSAPI 调用中没有请求相互认证, 则由 DASS 返回的相互认证令牌将被忽略, 并且初始调用将返回一个 COMPLETE 状态. 如果请求了相互认证, 该相互认证令牌将被存储在上下文信息中, 并返回一个 CONTINUE_NEEDED 状态.
在对 GSS_Init_sec_context 的第二次调用 (input_context_handle 非零) 时, 返回的令牌将使用 Compare_mutual_token 过程与上下文信息中的那个进行比较, 如果匹配则返回 COMPLETE 状态.
B.2.2.4 GSS_Accept_sec_context
GSSAPI 中的这个例程接受一个传入令牌并创建一个上下文. 它结合了若干 DASS 函数的效果. 它可以这样实现:
-
从传入令牌中移除 GSSAPI "包装器", 并将剩余部分连同凭证一起传给 "Accept_token". Accept_token 产生一个相互认证令牌和一个新的凭证结构. 如果请求了委派, 新的凭证结构将是 GSS_Accept_sec_context 的一个输出. 无论如何, 它都将被用于此过程的后续步骤.
-
使用 DASS 的 Get_principal_name 函数, 从 Accept_token 产生的凭证中提取主体名称. 这个名称是 "GSS_Accept_sec_context" 的输出之一.
-
对新的凭证和检索到的名称应用 DASS 的 Verify_principal_name, 以将该令牌认证为来自具名主体.
-
用 Accept_token 返回的密钥和时间戳以及一个 COMPLETE 状态创建并填充一个上下文结构. 返回该上下文的句柄.
-
如果请求了委派, 则从 GSS_Accept_sec_context 返回新的凭证. 否则, 调用 Delete_credentials.
-
如果请求了相互认证, 则用 GSSAPI "包装器" 封装来自 Accept_token 的相互认证令牌并将其返回. 否则返回一个空串.
B.2.2.5 GSS_Delete_sec_context
该例程只是删除上下文状态. 不需要调用 DASS.
B.2.2.6 GSS_Sign
该例程以一个上下文句柄和一条消息作为输入. 它通过在消息上使用上下文块中的密钥和时间戳计算数字签名来创建一个逐消息令牌 (per_msg_token). 不需要 DASS 服务. 如果请求了额外的密码学服务 (重放检测或排序), 必须在消息前附加一个时间戳或序号, 并与签名一起发送. 此消息的语法列于 C.3 节.
B.2.2.7 GSS_Verify
该例程重复签名例程的计算, 并验证所提供的签名. 如果提供了重放检测或排序服务, 上下文必须维护已经收到的消息的序号或时间戳作为其状态信息的一部分, 并且必须检查这一条消息是否可接受.
B.2.2.8 GSS_Seal
该例程执行与 Sign 相同的功能, 但还会使用共享密钥选择性地加密消息以保护私密性, 并将整个内容封装在 GSSAPI 规定的 ASN.1 包装器中.
B.2.2.9 GSS_Unseal
该例程执行与 GSS_Verify 相同的功能, 但还会解析包含签名和消息的数据结构, 并在必要时解密消息.
B.3 语法
GSSAPI 规范为通过 GSSAPI 生成的令牌和消息推荐了以下 ASN.1 编码:
--optional top-level token definitions to frame -- different mechanisms
GSSAPI DEFINITIONS ::=
BEGIN
MechType ::= OBJECT IDENTIFIER
-- data structure definitions
ContextToken ::=
-- option indication (delegation, etc.) indicated
-- within mechanism-specific token
[APPLICATION 0] IMPLICIT SEQUENCE {
thisMech MechType,
responseExpected BOOLEAN,
innerContextToken ANY DEFINED BY MechType
-- contents mechanism-specific
}
PerMsgToken ::=
-- as emitted by GSS_Sign and processed by
-- GSS_Verify
[APPLICATION 1] IMPLICIT SEQUENCE {
thisMech MechType,
innerMsgToken ANY DEFINED BY MechType
-- contents mechanism-specific
}
SealedMessage ::=
-- as emitted by GSS_Seal and processed by
-- GSS_Unseal
[APPLICATION 2] IMPLICIT SEQUENCE {
sealingToken PERMSGTOKEN,
confFlag BOOLEAN,
userData OCTET STRING
-- encrypted if confFlag TRUE
}
The object identifier for the DASS MechType is 1.3.12.2.1011.7.5.
The innerContextToken of a token is a DASS token or mutual
authentication token.
The innerMsgToken is a null string in the case where the message is
encrypted and the token is included as part of a SealedMessage.
Otherwise, it is an eight octet sequence computed as the CBC residue
computed using a key and string of bytes defined as follows:
- Pad the message provided by the application with 1-8 bytes of
pad to produce a string whose length is a multiple of 8
octets. Each pad byte has a value equal to the number of pad
bytes.
- Compute the key by taking the timestamp of the association
(two four byte integers laid out in big endian order with the
most significant integer first), complementing the high order
bit (to avoid aliasing with mutual authenticators), and
encrypting the block in ECB mode with the shared key of the
association.
The userData field of a SealedMessage is exactly the application
provided byte string if confFlag=FALSE. Otherwise, it is the
application supplied message encrypted as follows:
- Pad the message provided by the application with 1-8 bytes of
pad to produce a string whose length = 4 (mod 8). Each pad
byte has a value equal to the number of pad bytes.
- Append a four byte CRC32 computed over the message + pad.
- Compute a key by taking the timestamp of the association (two
four byte integers laid out in big endian order with the most
significant integer first), complementing the high order bit
(to avoid aliasing with mutual authenticators), and encrypting
the block in ECB mode with the shared key of the association.
- Encrypt the message + pad + CRC32 using CBC and the key
computed in the previous step.
A note of the logic behind the above:
- Because the shared key of an association may be reused by many
associations between the same pair of principals, it is
necessary to bind the association timestamp into the messages
somehow to prevent messages from a previous association being
replayed into a new sequence. The technique above of
generating an association key accomplishes this and has a side
benefit. An implementation may with to keep the long term
keys out of the hands of applications for purposes of
confinement but may wish to put the encryption associated with
an association in process context for reasons of performance.
Defining an association key makes that possible.
- The reason that the association specific key is not specified
as the output of Create_token and Accept_token is that the DCE
RPC security implementation requires that a series of
associations between two principals always have the same key
and we did not want to have to support a different interface
in that application.
- The CRC32 after pad constitutes a cheap integrity check when
data is encrypted.
- The fact that padding is done differently for encrypted and
signed messages means that there are no threats related to
sending the same message encrypted and unencrypted and using
the last block of the encrypted message as a signature on the
unencrypted one.