Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
btwise
openssl
提交
eeb9cdfc
O
openssl
项目概览
btwise
/
openssl
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
openssl
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
eeb9cdfc
编写于
3月 19, 2008
作者:
D
Dr. Stephen Henson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add support for KEK decrypt in cms utility.
上级
16fe5f8b
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
178 addition
and
47 deletion
+178
-47
apps/cms.c
apps/cms.c
+25
-2
crypto/cms/cms.h
crypto/cms/cms.h
+18
-1
crypto/cms/cms_env.c
crypto/cms/cms_env.c
+28
-9
crypto/cms/cms_err.c
crypto/cms/cms_err.c
+8
-2
crypto/cms/cms_smime.c
crypto/cms/cms_smime.c
+78
-33
test/cms-test.pl
test/cms-test.pl
+21
-0
未找到文件。
apps/cms.c
浏览文件 @
eeb9cdfc
...
@@ -465,7 +465,7 @@ int MAIN(int argc, char **argv)
...
@@ -465,7 +465,7 @@ int MAIN(int argc, char **argv)
}
}
else
if
(
operation
==
SMIME_DECRYPT
)
else
if
(
operation
==
SMIME_DECRYPT
)
{
{
if
(
!
recipfile
&&
!
keyfile
)
if
(
!
recipfile
&&
!
keyfile
&&
!
secret_key
)
{
{
BIO_printf
(
bio_err
,
"No recipient certificate or key specified
\n
"
);
BIO_printf
(
bio_err
,
"No recipient certificate or key specified
\n
"
);
badarg
=
1
;
badarg
=
1
;
...
@@ -838,7 +838,30 @@ int MAIN(int argc, char **argv)
...
@@ -838,7 +838,30 @@ int MAIN(int argc, char **argv)
ret
=
4
;
ret
=
4
;
if
(
operation
==
SMIME_DECRYPT
)
if
(
operation
==
SMIME_DECRYPT
)
{
{
if
(
!
CMS_decrypt
(
cms
,
key
,
recip
,
indata
,
out
,
flags
))
if
(
secret_key
)
{
if
(
!
CMS_decrypt_set1_key
(
cms
,
secret_key
,
secret_keylen
,
secret_keyid
,
secret_keyidlen
))
{
BIO_puts
(
bio_err
,
"Error decrypting CMS using secret key
\n
"
);
goto
end
;
}
}
if
(
key
)
{
if
(
!
CMS_decrypt_set1_pkey
(
cms
,
key
,
recip
))
{
BIO_puts
(
bio_err
,
"Error decrypting CMS using private key
\n
"
);
goto
end
;
}
}
if
(
!
CMS_decrypt
(
cms
,
NULL
,
NULL
,
indata
,
out
,
flags
))
{
{
BIO_printf
(
bio_err
,
"Error decrypting CMS structure
\n
"
);
BIO_printf
(
bio_err
,
"Error decrypting CMS structure
\n
"
);
goto
end
;
goto
end
;
...
...
crypto/cms/cms.h
浏览文件 @
eeb9cdfc
...
@@ -167,6 +167,11 @@ int CMS_decrypt(CMS_ContentInfo *cms, EVP_PKEY *pkey, X509 *cert,
...
@@ -167,6 +167,11 @@ int CMS_decrypt(CMS_ContentInfo *cms, EVP_PKEY *pkey, X509 *cert,
BIO
*
data
,
BIO
*
dcont
,
BIO
*
data
,
BIO
*
dcont
,
unsigned
int
flags
);
unsigned
int
flags
);
int
CMS_decrypt_set1_pkey
(
CMS_ContentInfo
*
cms
,
EVP_PKEY
*
pk
,
X509
*
cert
);
int
CMS_decrypt_set1_key
(
CMS_ContentInfo
*
cms
,
unsigned
char
*
key
,
size_t
keylen
,
unsigned
char
*
id
,
size_t
idlen
);
STACK_OF
(
CMS_RecipientInfo
)
*
CMS_get0_RecipientInfos
(
CMS_ContentInfo
*
cms
);
STACK_OF
(
CMS_RecipientInfo
)
*
CMS_get0_RecipientInfos
(
CMS_ContentInfo
*
cms
);
int
CMS_RecipientInfo_type
(
CMS_RecipientInfo
*
ri
);
int
CMS_RecipientInfo_type
(
CMS_RecipientInfo
*
ri
);
CMS_ContentInfo
*
CMS_EnvelopedData_create
(
const
EVP_CIPHER
*
cipher
);
CMS_ContentInfo
*
CMS_EnvelopedData_create
(
const
EVP_CIPHER
*
cipher
);
...
@@ -188,6 +193,12 @@ CMS_RecipientInfo *CMS_add0_recipient_key(CMS_ContentInfo *cms, int nid,
...
@@ -188,6 +193,12 @@ CMS_RecipientInfo *CMS_add0_recipient_key(CMS_ContentInfo *cms, int nid,
ASN1_OBJECT
*
otherTypeId
,
ASN1_OBJECT
*
otherTypeId
,
ASN1_TYPE
*
otherType
);
ASN1_TYPE
*
otherType
);
int
CMS_RecipientInfo_set0_key
(
CMS_RecipientInfo
*
ri
,
unsigned
char
*
key
,
size_t
keylen
);
int
CMS_RecipientInfo_kekri_id_cmp
(
CMS_RecipientInfo
*
ri
,
const
unsigned
char
*
id
,
size_t
idlen
);
int
CMS_RecipientInfo_decrypt
(
CMS_ContentInfo
*
cms
,
CMS_RecipientInfo
*
ri
);
int
CMS_RecipientInfo_decrypt
(
CMS_ContentInfo
*
cms
,
CMS_RecipientInfo
*
ri
);
int
CMS_uncompress
(
CMS_ContentInfo
*
cms
,
BIO
*
dcont
,
BIO
*
out
,
int
CMS_uncompress
(
CMS_ContentInfo
*
cms
,
BIO
*
dcont
,
BIO
*
out
,
...
@@ -297,6 +308,8 @@ void ERR_load_CMS_strings(void);
...
@@ -297,6 +308,8 @@ void ERR_load_CMS_strings(void);
#define CMS_F_CMS_DECRYPT 152
#define CMS_F_CMS_DECRYPT 152
#define CMS_F_CMS_DECRYPTEDCONTENT_DECRYPT_BIO 145
#define CMS_F_CMS_DECRYPTEDCONTENT_DECRYPT_BIO 145
#define CMS_F_CMS_DECRYPTEDCONTENT_ENCRYPT_BIO 143
#define CMS_F_CMS_DECRYPTEDCONTENT_ENCRYPT_BIO 143
#define CMS_F_CMS_DECRYPT_SET1_KEY 167
#define CMS_F_CMS_DECRYPT_SET1_PKEY 168
#define CMS_F_CMS_DIGESTALGORITHM_FIND_CTX 110
#define CMS_F_CMS_DIGESTALGORITHM_FIND_CTX 110
#define CMS_F_CMS_DIGESTALGORITHM_INIT_BIO 111
#define CMS_F_CMS_DIGESTALGORITHM_INIT_BIO 111
#define CMS_F_CMS_DIGESTEDDATA_DO_FINAL 112
#define CMS_F_CMS_DIGESTEDDATA_DO_FINAL 112
...
@@ -322,9 +335,12 @@ void ERR_load_CMS_strings(void);
...
@@ -322,9 +335,12 @@ void ERR_load_CMS_strings(void);
#define CMS_F_CMS_GET0_REVOCATION_CHOICES 120
#define CMS_F_CMS_GET0_REVOCATION_CHOICES 120
#define CMS_F_CMS_GET0_SIGNED 121
#define CMS_F_CMS_GET0_SIGNED 121
#define CMS_F_CMS_RECIPIENTINFO_DECRYPT 150
#define CMS_F_CMS_RECIPIENTINFO_DECRYPT 150
#define CMS_F_CMS_RECIPIENTINFO_KEKI_KEY_CMP 164
#define CMS_F_CMS_RECIPIENTINFO_KEKRI_DECRYPT 161
#define CMS_F_CMS_RECIPIENTINFO_KEKRI_DECRYPT 161
#define CMS_F_CMS_RECIPIENTINFO_KEKRI_ENCRYPT 162
#define CMS_F_CMS_RECIPIENTINFO_KEKRI_ENCRYPT 162
#define CMS_F_CMS_RECIPIENTINFO_KEKRI_GET0_ID 158
#define CMS_F_CMS_RECIPIENTINFO_KEKRI_GET0_ID 158
#define CMS_F_CMS_RECIPIENTINFO_KEKRI_ID_CMP 166
#define CMS_F_CMS_RECIPIENTINFO_KEKRI_KEY_CMP 165
#define CMS_F_CMS_RECIPIENTINFO_KTRI_CERT_CMP 122
#define CMS_F_CMS_RECIPIENTINFO_KTRI_CERT_CMP 122
#define CMS_F_CMS_RECIPIENTINFO_KTRI_DECRYPT 160
#define CMS_F_CMS_RECIPIENTINFO_KTRI_DECRYPT 160
#define CMS_F_CMS_RECIPIENTINFO_KTRI_ENCRYPT 155
#define CMS_F_CMS_RECIPIENTINFO_KTRI_ENCRYPT 155
...
@@ -359,6 +375,7 @@ void ERR_load_CMS_strings(void);
...
@@ -359,6 +375,7 @@ void ERR_load_CMS_strings(void);
#define CMS_R_CONTENT_VERIFY_ERROR 106
#define CMS_R_CONTENT_VERIFY_ERROR 106
#define CMS_R_CTRL_ERROR 107
#define CMS_R_CTRL_ERROR 107
#define CMS_R_CTRL_FAILURE 108
#define CMS_R_CTRL_FAILURE 108
#define CMS_R_DECRYPT_ERROR 159
#define CMS_R_ERROR_GETTING_PUBLIC_KEY 109
#define CMS_R_ERROR_GETTING_PUBLIC_KEY 109
#define CMS_R_ERROR_READING_MESSAGEDIGEST_ATTRIBUTE 110
#define CMS_R_ERROR_READING_MESSAGEDIGEST_ATTRIBUTE 110
#define CMS_R_ERROR_SETTING_KEY 155
#define CMS_R_ERROR_SETTING_KEY 155
...
...
crypto/cms/cms_env.c
浏览文件 @
eeb9cdfc
...
@@ -431,6 +431,24 @@ static int cms_RecipientInfo_ktri_decrypt(CMS_ContentInfo *cms,
...
@@ -431,6 +431,24 @@ static int cms_RecipientInfo_ktri_decrypt(CMS_ContentInfo *cms,
/* Key Encrypted Key (KEK) RecipientInfo routines */
/* Key Encrypted Key (KEK) RecipientInfo routines */
int
CMS_RecipientInfo_kekri_id_cmp
(
CMS_RecipientInfo
*
ri
,
const
unsigned
char
*
id
,
size_t
idlen
)
{
ASN1_OCTET_STRING
tmp_os
;
CMS_KEKRecipientInfo
*
kekri
;
if
(
ri
->
type
!=
CMS_RECIPINFO_KEK
)
{
CMSerr
(
CMS_F_CMS_RECIPIENTINFO_KEKRI_ID_CMP
,
CMS_R_NOT_KEK
);
return
-
2
;
}
kekri
=
ri
->
d
.
kekri
;
tmp_os
.
type
=
V_ASN1_OCTET_STRING
;
tmp_os
.
flags
=
0
;
tmp_os
.
data
=
(
unsigned
char
*
)
id
;
tmp_os
.
length
=
(
int
)
idlen
;
return
ASN1_OCTET_STRING_cmp
(
&
tmp_os
,
kekri
->
kekid
->
keyIdentifier
);
}
/* For now hard code AES key wrap info */
/* For now hard code AES key wrap info */
static
size_t
aes_wrap_keylen
(
int
nid
)
static
size_t
aes_wrap_keylen
(
int
nid
)
...
@@ -605,20 +623,13 @@ int CMS_RecipientInfo_set0_key(CMS_RecipientInfo *ri,
...
@@ -605,20 +623,13 @@ int CMS_RecipientInfo_set0_key(CMS_RecipientInfo *ri,
unsigned
char
*
key
,
size_t
keylen
)
unsigned
char
*
key
,
size_t
keylen
)
{
{
CMS_KEKRecipientInfo
*
kekri
;
CMS_KEKRecipientInfo
*
kekri
;
int
wrap_nid
;
if
(
ri
->
type
!=
CMS_RECIPINFO_KEK
)
if
(
ri
->
type
!=
CMS_RECIPINFO_KEK
)
{
{
CMSerr
(
CMS_F_CMS_RECIPIENTINFO_SET0_KEY
,
CMS_R_NOT_KEK
);
CMSerr
(
CMS_F_CMS_RECIPIENTINFO_SET0_KEY
,
CMS_R_NOT_KEK
);
return
0
;
return
0
;
}
}
kekri
=
ri
->
d
.
kekri
;
kekri
=
ri
->
d
.
kekri
;
wrap_nid
=
OBJ_obj2nid
(
kekri
->
keyEncryptionAlgorithm
->
algorithm
);
if
(
aes_wrap_keylen
(
wrap_nid
)
!=
keylen
)
{
CMSerr
(
CMS_F_CMS_RECIPIENTINFO_SET0_KEY
,
CMS_R_INVALID_KEY_LENGTH
);
return
0
;
}
kekri
->
key
=
key
;
kekri
->
key
=
key
;
kekri
->
keylen
=
keylen
;
kekri
->
keylen
=
keylen
;
return
1
;
return
1
;
...
@@ -695,7 +706,7 @@ static int cms_RecipientInfo_kekri_decrypt(CMS_ContentInfo *cms,
...
@@ -695,7 +706,7 @@ static int cms_RecipientInfo_kekri_decrypt(CMS_ContentInfo *cms,
AES_KEY
actx
;
AES_KEY
actx
;
unsigned
char
*
ukey
=
NULL
;
unsigned
char
*
ukey
=
NULL
;
int
ukeylen
;
int
ukeylen
;
int
r
=
0
;
int
r
=
0
,
wrap_nid
;
ec
=
cms
->
d
.
envelopedData
->
encryptedContentInfo
;
ec
=
cms
->
d
.
envelopedData
->
encryptedContentInfo
;
...
@@ -707,6 +718,14 @@ static int cms_RecipientInfo_kekri_decrypt(CMS_ContentInfo *cms,
...
@@ -707,6 +718,14 @@ static int cms_RecipientInfo_kekri_decrypt(CMS_ContentInfo *cms,
return
0
;
return
0
;
}
}
wrap_nid
=
OBJ_obj2nid
(
kekri
->
keyEncryptionAlgorithm
->
algorithm
);
if
(
aes_wrap_keylen
(
wrap_nid
)
!=
kekri
->
keylen
)
{
CMSerr
(
CMS_F_CMS_RECIPIENTINFO_KEKRI_DECRYPT
,
CMS_R_INVALID_KEY_LENGTH
);
return
0
;
}
/* If encrypted key length is invalid don't bother */
/* If encrypted key length is invalid don't bother */
if
(
kekri
->
encryptedKey
->
length
<
16
)
if
(
kekri
->
encryptedKey
->
length
<
16
)
...
...
crypto/cms/cms_err.c
浏览文件 @
eeb9cdfc
...
@@ -71,7 +71,7 @@
...
@@ -71,7 +71,7 @@
static
ERR_STRING_DATA
CMS_str_functs
[]
=
static
ERR_STRING_DATA
CMS_str_functs
[]
=
{
{
{
ERR_FUNC
(
CMS_F_CHECK_CONTENT
),
"CHECK_CONTENT"
},
{
ERR_FUNC
(
CMS_F_CHECK_CONTENT
),
"CHECK_CONTENT"
},
{
ERR_FUNC
(
CMS_F_CMS_ADD0_RECIPIENT_KEY
),
"CMS_
ADD0_RECIPIENT_KEY
"
},
{
ERR_FUNC
(
CMS_F_CMS_ADD0_RECIPIENT_KEY
),
"CMS_
add0_recipient_key
"
},
{
ERR_FUNC
(
CMS_F_CMS_ADD1_RECIPIENT_CERT
),
"CMS_add1_recipient_cert"
},
{
ERR_FUNC
(
CMS_F_CMS_ADD1_RECIPIENT_CERT
),
"CMS_add1_recipient_cert"
},
{
ERR_FUNC
(
CMS_F_CMS_ADD1_SIGNER
),
"CMS_add1_signer"
},
{
ERR_FUNC
(
CMS_F_CMS_ADD1_SIGNER
),
"CMS_add1_signer"
},
{
ERR_FUNC
(
CMS_F_CMS_ADD1_SIGNINGTIME
),
"CMS_ADD1_SIGNINGTIME"
},
{
ERR_FUNC
(
CMS_F_CMS_ADD1_SIGNINGTIME
),
"CMS_ADD1_SIGNINGTIME"
},
...
@@ -88,6 +88,8 @@ static ERR_STRING_DATA CMS_str_functs[]=
...
@@ -88,6 +88,8 @@ static ERR_STRING_DATA CMS_str_functs[]=
{
ERR_FUNC
(
CMS_F_CMS_DECRYPT
),
"CMS_decrypt"
},
{
ERR_FUNC
(
CMS_F_CMS_DECRYPT
),
"CMS_decrypt"
},
{
ERR_FUNC
(
CMS_F_CMS_DECRYPTEDCONTENT_DECRYPT_BIO
),
"CMS_DECRYPTEDCONTENT_DECRYPT_BIO"
},
{
ERR_FUNC
(
CMS_F_CMS_DECRYPTEDCONTENT_DECRYPT_BIO
),
"CMS_DECRYPTEDCONTENT_DECRYPT_BIO"
},
{
ERR_FUNC
(
CMS_F_CMS_DECRYPTEDCONTENT_ENCRYPT_BIO
),
"CMS_DECRYPTEDCONTENT_ENCRYPT_BIO"
},
{
ERR_FUNC
(
CMS_F_CMS_DECRYPTEDCONTENT_ENCRYPT_BIO
),
"CMS_DECRYPTEDCONTENT_ENCRYPT_BIO"
},
{
ERR_FUNC
(
CMS_F_CMS_DECRYPT_SET1_KEY
),
"CMS_DECRYPT_SET1_KEY"
},
{
ERR_FUNC
(
CMS_F_CMS_DECRYPT_SET1_PKEY
),
"CMS_DECRYPT_SET1_PKEY"
},
{
ERR_FUNC
(
CMS_F_CMS_DIGESTALGORITHM_FIND_CTX
),
"CMS_DIGESTALGORITHM_FIND_CTX"
},
{
ERR_FUNC
(
CMS_F_CMS_DIGESTALGORITHM_FIND_CTX
),
"CMS_DIGESTALGORITHM_FIND_CTX"
},
{
ERR_FUNC
(
CMS_F_CMS_DIGESTALGORITHM_INIT_BIO
),
"CMS_DIGESTALGORITHM_INIT_BIO"
},
{
ERR_FUNC
(
CMS_F_CMS_DIGESTALGORITHM_INIT_BIO
),
"CMS_DIGESTALGORITHM_INIT_BIO"
},
{
ERR_FUNC
(
CMS_F_CMS_DIGESTEDDATA_DO_FINAL
),
"CMS_DIGESTEDDATA_DO_FINAL"
},
{
ERR_FUNC
(
CMS_F_CMS_DIGESTEDDATA_DO_FINAL
),
"CMS_DIGESTEDDATA_DO_FINAL"
},
...
@@ -113,15 +115,18 @@ static ERR_STRING_DATA CMS_str_functs[]=
...
@@ -113,15 +115,18 @@ static ERR_STRING_DATA CMS_str_functs[]=
{
ERR_FUNC
(
CMS_F_CMS_GET0_REVOCATION_CHOICES
),
"CMS_GET0_REVOCATION_CHOICES"
},
{
ERR_FUNC
(
CMS_F_CMS_GET0_REVOCATION_CHOICES
),
"CMS_GET0_REVOCATION_CHOICES"
},
{
ERR_FUNC
(
CMS_F_CMS_GET0_SIGNED
),
"CMS_GET0_SIGNED"
},
{
ERR_FUNC
(
CMS_F_CMS_GET0_SIGNED
),
"CMS_GET0_SIGNED"
},
{
ERR_FUNC
(
CMS_F_CMS_RECIPIENTINFO_DECRYPT
),
"CMS_RecipientInfo_decrypt"
},
{
ERR_FUNC
(
CMS_F_CMS_RECIPIENTINFO_DECRYPT
),
"CMS_RecipientInfo_decrypt"
},
{
ERR_FUNC
(
CMS_F_CMS_RECIPIENTINFO_KEKI_KEY_CMP
),
"CMS_RECIPIENTINFO_KEKI_KEY_CMP"
},
{
ERR_FUNC
(
CMS_F_CMS_RECIPIENTINFO_KEKRI_DECRYPT
),
"CMS_RECIPIENTINFO_KEKRI_DECRYPT"
},
{
ERR_FUNC
(
CMS_F_CMS_RECIPIENTINFO_KEKRI_DECRYPT
),
"CMS_RECIPIENTINFO_KEKRI_DECRYPT"
},
{
ERR_FUNC
(
CMS_F_CMS_RECIPIENTINFO_KEKRI_ENCRYPT
),
"CMS_RECIPIENTINFO_KEKRI_ENCRYPT"
},
{
ERR_FUNC
(
CMS_F_CMS_RECIPIENTINFO_KEKRI_ENCRYPT
),
"CMS_RECIPIENTINFO_KEKRI_ENCRYPT"
},
{
ERR_FUNC
(
CMS_F_CMS_RECIPIENTINFO_KEKRI_GET0_ID
),
"CMS_RECIPIENTINFO_KEKRI_GET0_ID"
},
{
ERR_FUNC
(
CMS_F_CMS_RECIPIENTINFO_KEKRI_GET0_ID
),
"CMS_RECIPIENTINFO_KEKRI_GET0_ID"
},
{
ERR_FUNC
(
CMS_F_CMS_RECIPIENTINFO_KEKRI_ID_CMP
),
"CMS_RecipientInfo_kekri_id_cmp"
},
{
ERR_FUNC
(
CMS_F_CMS_RECIPIENTINFO_KEKRI_KEY_CMP
),
"CMS_RECIPIENTINFO_KEKRI_KEY_CMP"
},
{
ERR_FUNC
(
CMS_F_CMS_RECIPIENTINFO_KTRI_CERT_CMP
),
"CMS_RecipientInfo_ktri_cert_cmp"
},
{
ERR_FUNC
(
CMS_F_CMS_RECIPIENTINFO_KTRI_CERT_CMP
),
"CMS_RecipientInfo_ktri_cert_cmp"
},
{
ERR_FUNC
(
CMS_F_CMS_RECIPIENTINFO_KTRI_DECRYPT
),
"CMS_RECIPIENTINFO_KTRI_DECRYPT"
},
{
ERR_FUNC
(
CMS_F_CMS_RECIPIENTINFO_KTRI_DECRYPT
),
"CMS_RECIPIENTINFO_KTRI_DECRYPT"
},
{
ERR_FUNC
(
CMS_F_CMS_RECIPIENTINFO_KTRI_ENCRYPT
),
"CMS_RECIPIENTINFO_KTRI_ENCRYPT"
},
{
ERR_FUNC
(
CMS_F_CMS_RECIPIENTINFO_KTRI_ENCRYPT
),
"CMS_RECIPIENTINFO_KTRI_ENCRYPT"
},
{
ERR_FUNC
(
CMS_F_CMS_RECIPIENTINFO_KTRI_GET0_ALGS
),
"CMS_RecipientInfo_ktri_get0_algs"
},
{
ERR_FUNC
(
CMS_F_CMS_RECIPIENTINFO_KTRI_GET0_ALGS
),
"CMS_RecipientInfo_ktri_get0_algs"
},
{
ERR_FUNC
(
CMS_F_CMS_RECIPIENTINFO_KTRI_GET0_SIGNER_ID
),
"CMS_RecipientInfo_ktri_get0_signer_id"
},
{
ERR_FUNC
(
CMS_F_CMS_RECIPIENTINFO_KTRI_GET0_SIGNER_ID
),
"CMS_RecipientInfo_ktri_get0_signer_id"
},
{
ERR_FUNC
(
CMS_F_CMS_RECIPIENTINFO_SET0_KEY
),
"CMS_R
ECIPIENTINFO_SET0_KEY
"
},
{
ERR_FUNC
(
CMS_F_CMS_RECIPIENTINFO_SET0_KEY
),
"CMS_R
ecipientInfo_set0_key
"
},
{
ERR_FUNC
(
CMS_F_CMS_RECIPIENTINFO_SET0_PKEY
),
"CMS_RecipientInfo_set0_pkey"
},
{
ERR_FUNC
(
CMS_F_CMS_RECIPIENTINFO_SET0_PKEY
),
"CMS_RecipientInfo_set0_pkey"
},
{
ERR_FUNC
(
CMS_F_CMS_SET1_SIGNERIDENTIFIER
),
"CMS_SET1_SIGNERIDENTIFIER"
},
{
ERR_FUNC
(
CMS_F_CMS_SET1_SIGNERIDENTIFIER
),
"CMS_SET1_SIGNERIDENTIFIER"
},
{
ERR_FUNC
(
CMS_F_CMS_SET_DETACHED
),
"CMS_set_detached"
},
{
ERR_FUNC
(
CMS_F_CMS_SET_DETACHED
),
"CMS_set_detached"
},
...
@@ -153,6 +158,7 @@ static ERR_STRING_DATA CMS_str_reasons[]=
...
@@ -153,6 +158,7 @@ static ERR_STRING_DATA CMS_str_reasons[]=
{
ERR_REASON
(
CMS_R_CONTENT_VERIFY_ERROR
)
,
"content verify error"
},
{
ERR_REASON
(
CMS_R_CONTENT_VERIFY_ERROR
)
,
"content verify error"
},
{
ERR_REASON
(
CMS_R_CTRL_ERROR
)
,
"ctrl error"
},
{
ERR_REASON
(
CMS_R_CTRL_ERROR
)
,
"ctrl error"
},
{
ERR_REASON
(
CMS_R_CTRL_FAILURE
)
,
"ctrl failure"
},
{
ERR_REASON
(
CMS_R_CTRL_FAILURE
)
,
"ctrl failure"
},
{
ERR_REASON
(
CMS_R_DECRYPT_ERROR
)
,
"decrypt error"
},
{
ERR_REASON
(
CMS_R_ERROR_GETTING_PUBLIC_KEY
),
"error getting public key"
},
{
ERR_REASON
(
CMS_R_ERROR_GETTING_PUBLIC_KEY
),
"error getting public key"
},
{
ERR_REASON
(
CMS_R_ERROR_READING_MESSAGEDIGEST_ATTRIBUTE
),
"error reading messagedigest attribute"
},
{
ERR_REASON
(
CMS_R_ERROR_READING_MESSAGEDIGEST_ATTRIBUTE
),
"error reading messagedigest attribute"
},
{
ERR_REASON
(
CMS_R_ERROR_SETTING_KEY
)
,
"error setting key"
},
{
ERR_REASON
(
CMS_R_ERROR_SETTING_KEY
)
,
"error setting key"
},
...
...
crypto/cms/cms_smime.c
浏览文件 @
eeb9cdfc
...
@@ -494,23 +494,11 @@ CMS_ContentInfo *CMS_encrypt(STACK_OF(X509) *certs, BIO *data,
...
@@ -494,23 +494,11 @@ CMS_ContentInfo *CMS_encrypt(STACK_OF(X509) *certs, BIO *data,
return
NULL
;
return
NULL
;
}
}
int
CMS_decrypt
(
CMS_ContentInfo
*
cms
,
EVP_PKEY
*
pk
,
X509
*
cert
,
int
CMS_decrypt_set1_pkey
(
CMS_ContentInfo
*
cms
,
EVP_PKEY
*
pk
,
X509
*
cert
)
BIO
*
dcont
,
BIO
*
out
,
unsigned
int
flags
)
{
int
i
,
r
;
BIO
*
cont
;
if
(
OBJ_obj2nid
(
CMS_get0_type
(
cms
))
!=
NID_pkcs7_enveloped
)
{
CMSerr
(
CMS_F_CMS_DECRYPT
,
CMS_R_TYPE_NOT_ENVELOPED_DATA
);
return
0
;
}
if
(
!
dcont
&&
!
check_content
(
cms
))
return
0
;
if
(
pk
)
{
{
STACK_OF
(
CMS_RecipientInfo
)
*
ris
;
STACK_OF
(
CMS_RecipientInfo
)
*
ris
;
CMS_RecipientInfo
*
ri
;
CMS_RecipientInfo
*
ri
;
int
i
,
r
;
ris
=
CMS_get0_RecipientInfos
(
cms
);
ris
=
CMS_get0_RecipientInfos
(
cms
);
for
(
i
=
0
;
i
<
sk_CMS_RecipientInfo_num
(
ris
);
i
++
)
for
(
i
=
0
;
i
<
sk_CMS_RecipientInfo_num
(
ris
);
i
++
)
{
{
...
@@ -520,26 +508,83 @@ int CMS_decrypt(CMS_ContentInfo *cms, EVP_PKEY *pk, X509 *cert,
...
@@ -520,26 +508,83 @@ int CMS_decrypt(CMS_ContentInfo *cms, EVP_PKEY *pk, X509 *cert,
/* If we have a cert try matching RecipientInfo
/* If we have a cert try matching RecipientInfo
* otherwise try them all.
* otherwise try them all.
*/
*/
if
(
!
cert
||
if
(
!
cert
||
(
CMS_RecipientInfo_ktri_cert_cmp
(
ri
,
cert
)
==
0
))
(
CMS_RecipientInfo_ktri_cert_cmp
(
ri
,
cert
)
==
0
))
{
{
CMS_RecipientInfo_set0_pkey
(
ri
,
pk
);
CMS_RecipientInfo_set0_pkey
(
ri
,
pk
);
r
=
CMS_RecipientInfo_decrypt
(
cms
,
ri
);
r
=
CMS_RecipientInfo_decrypt
(
cms
,
ri
);
CMS_RecipientInfo_set0_pkey
(
ri
,
NULL
);
CMS_RecipientInfo_set0_pkey
(
ri
,
NULL
);
if
(
r
>
0
)
if
(
r
>
0
)
break
;
return
1
;
if
(
cert
)
if
(
cert
)
{
CMSerr
(
CMS_F_CMS_DECRYPT_SET1_PKEY
,
CMS_R_DECRYPT_ERROR
);
return
0
;
return
0
;
}
ERR_clear_error
();
ERR_clear_error
();
}
}
}
}
if
(
i
==
sk_CMS_RecipientInfo_num
(
ris
))
CMSerr
(
CMS_F_CMS_DECRYPT_SET1_PKEY
,
CMS_R_NO_MATCHING_RECIPIENT
);
return
0
;
}
int
CMS_decrypt_set1_key
(
CMS_ContentInfo
*
cms
,
unsigned
char
*
key
,
size_t
keylen
,
unsigned
char
*
id
,
size_t
idlen
)
{
STACK_OF
(
CMS_RecipientInfo
)
*
ris
;
CMS_RecipientInfo
*
ri
;
int
i
,
r
;
ris
=
CMS_get0_RecipientInfos
(
cms
);
for
(
i
=
0
;
i
<
sk_CMS_RecipientInfo_num
(
ris
);
i
++
)
{
ri
=
sk_CMS_RecipientInfo_value
(
ris
,
i
);
if
(
CMS_RecipientInfo_type
(
ri
)
!=
CMS_RECIPINFO_KEK
)
continue
;
/* If we have an id try matching RecipientInfo
* otherwise try them all.
*/
if
(
!
id
||
(
CMS_RecipientInfo_kekri_id_cmp
(
ri
,
id
,
idlen
)
==
0
))
{
CMS_RecipientInfo_set0_key
(
ri
,
key
,
keylen
);
r
=
CMS_RecipientInfo_decrypt
(
cms
,
ri
);
CMS_RecipientInfo_set0_key
(
ri
,
NULL
,
0
);
if
(
r
>
0
)
return
1
;
if
(
id
)
{
{
CMSerr
(
CMS_F_CMS_DECRYPT
,
CMS_R_NO_MATCHING_RECIPIENT
);
CMSerr
(
CMS_F_CMS_DECRYPT_SET1_KEY
,
CMS_R_DECRYPT_ERROR
);
return
0
;
return
0
;
}
}
ERR_clear_error
();
}
}
CMSerr
(
CMS_F_CMS_DECRYPT_SET1_KEY
,
CMS_R_NO_MATCHING_RECIPIENT
);
return
0
;
}
int
CMS_decrypt
(
CMS_ContentInfo
*
cms
,
EVP_PKEY
*
pk
,
X509
*
cert
,
BIO
*
dcont
,
BIO
*
out
,
unsigned
int
flags
)
{
int
r
;
BIO
*
cont
;
if
(
OBJ_obj2nid
(
CMS_get0_type
(
cms
))
!=
NID_pkcs7_enveloped
)
{
CMSerr
(
CMS_F_CMS_DECRYPT
,
CMS_R_TYPE_NOT_ENVELOPED_DATA
);
return
0
;
}
}
if
(
!
dcont
&&
!
check_content
(
cms
))
return
0
;
if
(
pk
&&
!
CMS_decrypt_set1_pkey
(
cms
,
pk
,
cert
))
return
0
;
cont
=
CMS_dataInit
(
cms
,
dcont
);
cont
=
CMS_dataInit
(
cms
,
dcont
);
if
(
!
cont
)
if
(
!
cont
)
return
0
;
return
0
;
...
...
test/cms-test.pl
浏览文件 @
eeb9cdfc
...
@@ -235,6 +235,27 @@ my @smime_cms_tests = (
...
@@ -235,6 +235,27 @@ my @smime_cms_tests = (
"
-decrypt -recip
$smdir
/smrsa1.pem -in test.cms -out smtst.txt
"
"
-decrypt -recip
$smdir
/smrsa1.pem -in test.cms -out smtst.txt
"
],
],
[
"
enveloped content test streaming PEM format, KEK
",
"
-encrypt -in smcont.txt -outform PEM -aes128
"
.
"
-stream -out test.cms
"
.
"
-secretkey 000102030405060708090A0B0C0D0E0F
"
.
"
-secretkeyid C0FEE0
",
"
-decrypt -in test.cms -out smtst.txt -inform PEM
"
.
"
-secretkey 000102030405060708090A0B0C0D0E0F
"
.
"
-secretkeyid C0FEE0
"
],
[
"
enveloped content test streaming PEM format, KEK, key only
",
"
-encrypt -in smcont.txt -outform PEM -aes128
"
.
"
-stream -out test.cms
"
.
"
-secretkey 000102030405060708090A0B0C0D0E0F
"
.
"
-secretkeyid C0FEE0
",
"
-decrypt -in test.cms -out smtst.txt -inform PEM
"
.
"
-secretkey 000102030405060708090A0B0C0D0E0F
"
],
[
[
"
data content test streaming PEM format
",
"
data content test streaming PEM format
",
"
-data_create -in smcont.txt -outform PEM -nodetach
"
"
-data_create -in smcont.txt -outform PEM -nodetach
"
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录