4. 证书与消息格式
4.1 ASN.1 编码
某些定义取自 X.501 和 X.509.
Dass DEFINITIONS ::=
BEGIN
--CCITT Definitions:
joint-iso-ccitt OBJECT IDENTIFIER ::= {2}
ds OBJECT IDENTIFIER ::= {joint-iso-ccitt 5}
algorithm OBJECT IDENTIFIER ::= {ds 8}
encryptionAlgorithm OBJECT IDENTIFIER ::= {algorithm 1}
hashAlgorithm OBJECT IDENTIFIER ::= {algorithm 2}
signatureAlgorithm OBJECT IDENTIFIER ::= {algorithm 3}
rsa OBJECT IDENTIFIER ::= {encryptionAlgorithm 1}
iso OBJECT IDENTIFIER ::= {1}
identified-organization OBJECT IDENTIFIER ::= {iso 3}
ecma OBJECT IDENTIFIER ::= {identified-organization 12}
member-company OBJECT IDENTIFIER ::= {ecma 2}
digital OBJECT IDENTIFIER ::= {member-company 1011}
--1989 OSI Implementors Workshop "Stable" Agreements
oiw OBJECT IDENTIFIER ::= {identified-organization 14}
dssig OBJECT IDENTIFIER ::= {oiw 7}
oiwAlgorithm OBJECT IDENTIFIER ::= {dssig 2}
oiwEncryptionAlgorithm OBJECT IDENTIFIER ::= {oiwAlgorithm 1}
oiwHashAlgorithm OBJECT IDENTIFIER ::= {oiwAlgorithm 2}
oiwSignatureAlgorithm OBJECT IDENTIFIER ::= {oiwAlgorithm 3}
oiwMD2 OBJECT IDENTIFIER ::= {oiwHashAlgorithm 1}
--null parameter
oiwMD2withRSA OBJECT IDENTIFIER ::= {oiwSignatureAlgorithm 1}
--null parameter
--X.501 definitions
AttributeType ::= OBJECT IDENTIFIER
AttributeValue ::= ANY
AttributeValueAssertion ::= SEQUENCE {AttributeType,AttributeValue}
Name ::= CHOICE { --only one for now
RDNSequence
}
RDNSequence ::= SEQUENCE OF RelativeDistinguishedName
DistinguishedName ::= RDNSequence
RelativeDistinguishedName ::= SET OF AttributeValueAssertion
--X.509 definitions (with proposed 1992 extensions presumed)
ENCRYPTED MACRO ::=
BEGIN
TYPE NOTATION ::= type(ToBeEnciphered)
VALUE NOTATION ::= value(VALUE BIT STRING)
END -- of ENCRYPTED
SIGNED MACRO ::=
BEGIN
TYPE NOTATION ::= type (ToBeSigned)
VALUE NOTATION ::= value (VALUE
SEQUENCE{
ToBeSigned,
AlgorithmIdentifier, --of the algorithm used to
--generate the signature
ENCRYPTED OCTET STRING --where the octet string is the
--result of the hashing of the
--value of "ToBeSigned"
}
)
END -- of SIGNED
SIGNATURE MACRO ::=
BEGIN
TYPE NOTATION ::= type (OfSignature)
VALUE NOTATION ::= value (VALUE
SEQUENCE {
AlgorithmIdentifier, --of the algorithm used to compute
ENCRYPTED OCTET STRING -- the signature where the octet
-- string is a function (e.g., a
-- compressed or hashed version)
-- of the value 'OfSignature',
-- which may include the
-- identifier of the algorithm
-- used to compute the signature
}
)
END -- of SIGNATURE
Certificate ::= SIGNED SEQUENCE {
version [0] Version DEFAULT v1988,
serialNumber CertificateSerialNumber,
signature AlgorithmIdentifier,
issuer Name,
valid Validity,
subject Name,
subjectPublicKey SubjectPublicKeyInfo,
issuerUID [1] IMPLICIT UID OPTIONAL, -- v1992
subjectUID [2] IMPLICIT UID OPTIONAL -- v1992
}
--The Algorithm Identifier for both the signature field
--and in the signature itself is:
-- oiwMD2withRSA (1.3.14.7.2.3.1)
Version ::= INTEGER {v1988(0), v1992(1)}
CertificateSerialNumber ::= INTEGER
Validity ::= SEQUENCE {
NotBefore UTCTime,
NotAfter UTCTime
}
AlgorithmIdentifier ::= SEQUENCE {
algorithm OBJECT IDENTIFIER,
parameter ANY DEFINED BY algorithm OPTIONAL
}
--The algorithms we support in one context or another are:
--oiwMD2withRSA (1.3.14.7.2.3.1) with parameter NULL
--rsa (2.5.8.1.1) with parameter keysize INTEGER which is
-- the keysize in bits
--decDEA (1.3.12.1001.7.1.2) with optional parameter
-- missing
--decDEAMAC (1.3.12.2.1011.7.3.3) with optional parameter
-- missing
SubjectPublicKeyInfo ::= SEQUENCE {
algorithm AlgorithmIdentifier, -- rsa (2.5.8.1.1)
subjectPublicKey BIT STRING
-- the "bits" further decode into a DASS public key
}
UID ::= BIT STRING
-- the following definitions are for Digital specified Algorithms
cryptoAlgorithm OBJECT IDENTIFIER ::= {digital 7}
decEncryptionAlgorithm OBJECT IDENTIFIER ::= {cryptoAlgorithm 1}
decHashAlgorithm OBJECT IDENTIFIER ::= {cryptoAlgorithm 2}
decSignatureAlgorithm OBJECT IDENTIFIER ::= {cryptoAlgorithm 3}
decDASSLessness OBJECT IDENTIFIER ::= {cryptoAlgorithm 6}
decMD2withRSA OBJECT IDENTIFIER ::= {decSignatureAlgorithm 1}
decMD4withRSA OBJECT IDENTIFIER ::= {decSignatureAlgorithm 2}
decDEAMAC OBJECT IDENTIFIER ::= {decSignatureAlgorithm 3}
decDEA OBJECT IDENTIFIER ::= {decEncryptionAlgorithm 2}
decMD2 OBJECT IDENTIFIER ::= {decHashAlgorithm 1}
decMD4 OBJECT IDENTIFIER ::= {decHashAlgorithm 2}
ShortPosixTime ::= INTEGER -- number of seconds since base time
LongPosixTime ::= SEQUENCE {
INTEGER, -- number of seconds since base time
INTEGER -- number of nanoseconds since second
}
ShortPosixValidity ::= SEQUENCE {
notBefore ShortPosixTime,
notAfter ShortPosixTime }
-- Note: Annex C of X.509 prescribes the following format for the
-- representation of a public key, but does not give the structure
-- a name.
DASSPublicKey ::= SEQUENCE {
modulus INTEGER,
exponent INTEGER
}
DASSPrivateKey ::= SEQUENCE {
p INTEGER , -- prime p
q [0] IMPLICIT INTEGER OPTIONAL , -- prime q
mod[1] IMPLICIT INTEGER OPTIONAL, -- modulus
exp [2] IMPLICIT INTEGER OPTIONAL, -- public exponent
dp [3] IMPLICIT INTEGER OPTIONAL , -- exponent mod p
dq [4] IMPLICIT INTEGER OPTIONAL , -- exponent mod q
cr [5] IMPLICIT INTEGER OPTIONAL , -- Chinese
--remainder coefficient
uid[6] IMPLICIT UID OPTIONAL,
more[7] IMPLICIT BIT STRING OPTIONAL --Reserved for
--future use
}
LocalUserName ::= OCTET STRING
ChannelId ::= OCTET STRING
VersionNumber ::= OCTET STRING (SIZE(3))
-- first octet is major version
-- second octet is minor version
-- third octet is ECO rev.
versionZero VersionNumber ::= '000000'H
Authenticator ::= SIGNED SEQUENCE {
type BIT STRING,
-- first bit `delegation required'
-- second bit `Mutual Authentication Requested'
whenSigned LongPosixTime ,
channelId [3] IMPLICIT ChannelId OPTIONAL
-- channel bindings are included when doing the
-- signature, but excluded when transmitting the
-- Authenticator
}
-- uses decDEAMAC (1.3.12.2.1011.7.3.3)
EncryptedKey ::= SEQUENCE {
algorithm AlgorithmIdentifier,
-- uses rsa (2.5.8.1.1)
encryptedAuthKey BIT STRING
-- as defined in section 4.4.5
}
SignatureOnEncryptedKey ::= SIGNATURE EncryptedKey
-- uses oiwMD2withRSA (1.3.14.7.2.3.1)
-- Signature bits computed over EncryptedKey structure
LoginTicket ::= SIGNED SEQUENCE {
version [0] IMPLICIT VersionNumber DEFAULT versionZero,
validity ShortPosixValidity ,
subjectUID UID ,
delegatingPublicKey SubjectPublicKeyInfo
}
-- uses oiwMD2withRSA (1.3.14.7.2.3.1)
Delegator ::= SEQUENCE {
algorithm AlgorithmIdentifier
-- decDEA encryption (1.3.12.1001.7.1.2)
encryptedPrivKey ENCRYPTED DASSPrivateKey,
-- (only p is included)
}
UserClaimant ::= SEQUENCE {
userTicket [0] IMPLICIT LoginTicket,
evidence CHOICE {
delegator [1] IMPLICIT Delegator ,
-- encrypted delegation private key
-- under DES authenticating key
-- present if delegating
sharedKeyTicketSignature [2]
IMPLICIT SignatureOnEncryptedKey
-- present if not delegating
} ,
userName [3] IMPLICIT Name OPTIONAL
-- name of user principal
}
EncryptedKeyandUserName ::= SEQUENCE {
encryptedKey EncryptedKey ,
username LocalUserName
}
SignatureOnEncryptedKeyandUserName ::=
SIGNATURE EncryptedKeyandUserName
-- uses oiwMD2withRSA (1.3.14.7.2.3.1)
-- Signature bits computed over
-- EncryptedKeyandUserName structure
-- using node private key
}
NodeClaimant ::= SEQUENCE {
nodeTicket Signature[0] IMPLICIT
SignatureOnEncryptedKeyandUserName,
nodeName [1] IMPLICIT Name OPTIONAL,
username [2] IMPLICIT LocalUserName OPTIONAL
}
AuthenticationToken ::= SEQUENCE {
version [0] IMPLICIT VersionNumber DEFAULT versionZero,
authenticator [1] IMPLICIT Authenticator ,
encryptedKey [2] IMPLICIT EncryptedKey OPTIONAL ,
-- required if initiating token
userclaimant [3] IMPLICIT UserClaimant OPTIONAL ,
-- missing if only doing node authentication
-- required if not doing node authentication
nodeclaimant [4] IMPLICIT NodeClaimant OPTIONAL
-- missing if only doing principal authentication
-- required if not doing principal authentication
}
MutualAuthenticationToken ::= CHOICE {
v1Response [0] IMPLICIT OCTET STRING (SIZE(6))
-- Constructed as follows: A single DES block
-- of eight octets is constructed from the two
-- integers in the timestamp. First four bytes
-- are the high order integer encoded MSB
-- first; Last four bytes are the low order
-- integer encoded MSB first. The block is
-- encrypted using the shared DES key, and
-- the first six bytes are the OCTET STRING.
-- With the [0] type and 6-byte length, the
-- MutualAuthenticationToken has a fixed
-- length of eight bytes.
}
END
4.2 编码规则
每当一个结构要被签名时, 它必须总是以相同的方式构造. 这一点在接收方必须重建被签名的结构才能验证签名的情况下尤为重要. 下面列出的规则取自 X.509.
-
必须使用长度编码的确定形式 (definite form), 并以最少数量的八位组编码;
-
对于字符串类型, 不得使用构造形式的编码;
-
如果类型的值就是其默认值, 则该值应当省略;
-
Set 类型的各组成部分应当按照其标签值的升序编码;
-
Set-of 类型的各组成部分应当按照其八位组值的升序编码;
-
如果 Boolean 类型的值为真, 则其编码的内容八位组应设为 `FF'16;
-
在 BitString 值编码的最后一个八位组中, 任何未使用的位 (如果有) 都应当设为零;
-
Real 类型的编码应当使得基数 8,10 和 16 不被使用, 并且二进制缩放因子为零.
4.3 版本号与向前兼容性
LoginTicket 和 AuthenticationToken 结构包含一个三字节的版本标识符, 旨在便利向本架构未来修订版本的过渡. 默认值, 也是本版本架构实现应当始终提供的值, 是 0.0.0
(三个零八位组). 第一个字节是主版本号. 本版本架构的实现应当拒绝处理该字节不为零的数据结构, 因为改变它表示某些附属数据结构的解释已经改变. 第二个字节是次版本号. 本版本架构的实现应当忽略该字节的值. 未来某个版本的架构可能会设置一个非零的值, 并可能基于该不同的值规定对结构其余部分的一些不同处理. 这样的改变将是向后兼容且可互操作的. 第三个字节是 ECO 修订号. 任何实现都不应基于该字节的值做出任何处理决策. 不过可以将其记录, 以帮助调试互操作问题.
在 CDC 协议中, 也存在三字节的版本编号方案, 其中已定义了版本 1.0.0 和 2.0.0. 实现应当遵循上面的相同规则, 并拒绝大于 2 的主版本号.
ASN.1 本质上是可扩展的, 因为它允许以明确的方式将新字段 "追加" 到现有数据结构的末尾. 鼓励 DASS 的实现忽略任何此类附加字段, 以增强与架构未来版本的向后兼容性. 遗憾的是, 常见的 ASN.1 编译器缺乏这种能力, 因此这种行为无法合理地被要求, 并且可能会限制未来扩展的选择.
4.4 加密编码
前面各节中列出的一些子结构被规定为包含加密信息的 ENCRYPTED OCTET STRING (加密八位组串). DASS 使用 DES,RSA 和 MD2 密码体制. 这些密码体制中的每一个都规定了在存在密钥的情况下从八位组串到另一个八位组串的函数 (MD2 除外, 它是无密钥的). 本节描述如何构造执行 DES 和 RSA 操作所针对的八位组串.
4.4.1 算法独立性与密钥奇偶性
DASS 为秘密密钥加密定义的所有编码都基于 DES. 然而, 意图是其他密码体制可以在不更改任何格式或算法的情况下被替换. 这样一种密码体制所需的 "外形尺寸" 是: 它有一个 64 位的密钥, 并在 64 位的块上运算 (这似乎是密码体制的一种常见外形尺寸). 正因如此, DASS 中所有地方的 DES 密钥都
被视为 64 位长, 而不是 56 位. 只有在算法本身的运算中, 密钥的 8 位才会被丢弃, 并由密钥的奇偶校验位替代. 选择密钥总是涉及选取一个 64 位的随机数.
4.4.2 口令哈希
加密的凭证使用下一节所述的 DES 加密. 该加密的密钥由用户的口令和名称通过以下算法导出:
a) 按照 BER 和 X.509 编码规则, 将用户名称最右边的 RDN 规范化. 对于任何大小写不敏感的字符串类型, 映射为大写; 在匹配与空格数量无关的地方, 将所有多个空格折叠为单个空格, 并删除前导和尾随空格.
注意: 使用 RDN 是为哈希计算添加 "盐" (salt), 这样别人就无法预先计算出字典中所有单词的哈希, 然后对所有名称套用它们. 从名称的最后一个 RDN 派生盐是一种折中. 如果它从整个名称派生, 那么当命名空间的一个分支被重命名时, 所有加密密钥都会作废. 如果它独立于名称, 那么与登录代理的交互将需要额外的两条消息来获取盐. 采用这种方案, 加密密钥会在最后一个 RDN 变更时作废; 并且如果最终 RDN 对大量用户是共同的, 针对他们的字典攻击会更容易; 但常见情况会按预期工作.
b) 将 TEMP 计算为口令与上述 RDN 的拼接的 MD2 消息摘要.
c) 重复以下操作 40 次: 使用 TEMP 的前 64 位作为 DES 密钥来加密后 64 位; 将结果与 TEMP 的前 64 位异或; 并将新的 TEMP 计算为 128 位结果的 MD2.
d) 使用结果的最后 64 位 (称为 hash1) 作为密钥来解密加密凭证. 使用前 64 位 (称为 hash2) 作为对口令知识的证明, 呈现给登录代理 (如果有).
4.4.3 数字 DEA 加密
DES 加密用于以下地方:
-
在加密凭证结构的加密中
-
用于加密认证令牌中的委派者
-
用于加密相互认证器中的时间
在前两种情况下, 编码为 ASN.1 的变长信息块被加密. 这是通过将信息块分成 8 个八位组的块, 必要时用零字节填充最后一个块, 并使用 DES 的 CBC 模式加密结果来完成的. 使用零 IV.
在第三种情况下, 加密的是一个定长 (8 字节) 的量 (一个时间戳). 时间戳使用 "大端" 顺序映射为字节串, 并用 DES 的 ECB 模式加密该块.
4.4.4 数字 MAC 签名
DES 签名用于认证器 (Authenticator). 在这里, 签名是在一个 ASN.1 结构上计算的. 签名是用零 IV 计算的该结构的 CBC 残差, 该结构被填充到 8 字节的倍数.
4.4.5 RSA 加密
RSA 加密用于加密共享密钥 (Encrypted Shared Key). RSA 加密最好被理解为作用于整数块而非八位组串, 其结果也是整数. 由于 RSA 加密置换了从零到 (模数-1) 之间的整数, 它通常被视为作用于大小为 (密钥位数-1) 的块并产生大小为 (密钥位数) 的块, 其中密钥位数是能够表示模数的最小位数.
DASS 只支持大小为 8 位倍数的密钥 (这一限制只是为了支持与某些现有实现的互操作. 如果密钥大小不是 8 位的倍数, 高位字节可能无法容纳像规定的 '64' 那样大的值. 只要两个高位字节合起来非零, 这就不是问题, 但某些早期实现会检查 '64' 这个值, 并且不会与使用其他值的实现互操作).
加密共享密钥结构的布局如下:
-
要共享的 DES 密钥放在最后 8 个字节
-
用大端字节顺序编码的 POSIX 格式创建时间 (4 字节) 放在接下来的 4 个 (从末尾算起) 字节
-
POSIX 格式过期时间 (4 字节) 放在接下来的 4 个 (从末尾算起) 字节
-
4 个零字节放在接下来的 4 个 (从末尾算起) 字节
-
第一个字节包含常量 '64' (十进制)
-
所有剩余字节用随机字节填充 (系统的安全性不依赖于这些字节的密码学随机性, 但它们不应是频繁重复或可预测的值. 重复使用最后字节中的 DES 密钥就很好).
将 RSA 算法应用于通过将上述字节视为一个大端整数而形成的整数, 并将得到的整数通过以大端顺序布置字节而转换为 BIT STRING.
在解密时, 过程相反; 解密者应当验证四个显式为零的字节, 但不应验证高位字节或随机字节的内容.
4.4.6 oiwMD2withRSA 签名
RSA-MD2 签名用于证书,登录票据,共享密钥票据和节点票据. 在所有情况下, 都是使用 RSA 私钥在一个 ASN.1 编码的字符串上计算签名. 做法如下:
-
对 ASN.1 编码的字符串应用 MD2 算法, 产生一个 128 位的消息摘要
-
将消息摘要放在 RSA 块的低字节 (大端)
-
接下来最低的两个字节是 OCTET STRING 的 ASN.1 'T' 和 'L'.
-
RSA 块的其余部分用零填充
-
执行 RSA 运算, 并通过以大端顺序布置字节将得到的整数转换为八位组串.
在验证时, 应当接受类似上面的值, 或者消息摘要存在但 'T' 和 'L' 缺失 (为零) 的值, 以与该加密算法的较早定义向后兼容.
4.4.7 decMD2withRSA 签名
本算法与上述 oiwMD2withRSA 算法相同. 我们从 Digital 空间分配了一个算法对象标识符, 以防该 OID 的定义发生变化. 除非 oiwMD2withRSA 的含义变得不稳定, 否则不会使用它.