Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Openssl
提交
b6436ff2
T
Third Party Openssl
项目概览
OpenHarmony
/
Third Party Openssl
1 年多 前同步成功
通知
10
Star
18
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
Third Party Openssl
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
b6436ff2
编写于
5月 31, 1999
作者:
B
Ben Laurie
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
More stack.
上级
02ee237f
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
66 addition
and
50 deletion
+66
-50
crypto/asn1/p7_signi.c
crypto/asn1/p7_signi.c
+16
-10
crypto/pkcs7/pk7_doit.c
crypto/pkcs7/pk7_doit.c
+44
-35
crypto/pkcs7/pkcs7.h
crypto/pkcs7/pkcs7.h
+6
-5
未找到文件。
crypto/asn1/p7_signi.c
浏览文件 @
b6436ff2
...
...
@@ -68,20 +68,24 @@ int i2d_PKCS7_SIGNER_INFO(PKCS7_SIGNER_INFO *a, unsigned char **pp)
M_ASN1_I2D_len
(
a
->
version
,
i2d_ASN1_INTEGER
);
M_ASN1_I2D_len
(
a
->
issuer_and_serial
,
i2d_PKCS7_ISSUER_AND_SERIAL
);
M_ASN1_I2D_len
(
a
->
digest_alg
,
i2d_X509_ALGOR
);
M_ASN1_I2D_len_IMP_SET_opt
(
a
->
auth_attr
,
i2d_X509_ATTRIBUTE
,
0
);
M_ASN1_I2D_len_IMP_SET_opt_type
(
X509_ATTRIBUTE
,
a
->
auth_attr
,
i2d_X509_ATTRIBUTE
,
0
);
M_ASN1_I2D_len
(
a
->
digest_enc_alg
,
i2d_X509_ALGOR
);
M_ASN1_I2D_len
(
a
->
enc_digest
,
i2d_ASN1_OCTET_STRING
);
M_ASN1_I2D_len_IMP_SET_opt
(
a
->
unauth_attr
,
i2d_X509_ATTRIBUTE
,
1
);
M_ASN1_I2D_len_IMP_SET_opt_type
(
X509_ATTRIBUTE
,
a
->
unauth_attr
,
i2d_X509_ATTRIBUTE
,
1
);
M_ASN1_I2D_seq_total
();
M_ASN1_I2D_put
(
a
->
version
,
i2d_ASN1_INTEGER
);
M_ASN1_I2D_put
(
a
->
issuer_and_serial
,
i2d_PKCS7_ISSUER_AND_SERIAL
);
M_ASN1_I2D_put
(
a
->
digest_alg
,
i2d_X509_ALGOR
);
M_ASN1_I2D_put_IMP_SET_opt
(
a
->
auth_attr
,
i2d_X509_ATTRIBUTE
,
0
);
M_ASN1_I2D_put_IMP_SET_opt_type
(
X509_ATTRIBUTE
,
a
->
auth_attr
,
i2d_X509_ATTRIBUTE
,
0
);
M_ASN1_I2D_put
(
a
->
digest_enc_alg
,
i2d_X509_ALGOR
);
M_ASN1_I2D_put
(
a
->
enc_digest
,
i2d_ASN1_OCTET_STRING
);
M_ASN1_I2D_put_IMP_SET_opt
(
a
->
unauth_attr
,
i2d_X509_ATTRIBUTE
,
1
);
M_ASN1_I2D_put_IMP_SET_opt_type
(
X509_ATTRIBUTE
,
a
->
unauth_attr
,
i2d_X509_ATTRIBUTE
,
1
);
M_ASN1_I2D_finish
();
}
...
...
@@ -96,12 +100,14 @@ PKCS7_SIGNER_INFO *d2i_PKCS7_SIGNER_INFO(PKCS7_SIGNER_INFO **a,
M_ASN1_D2I_get
(
ret
->
version
,
d2i_ASN1_INTEGER
);
M_ASN1_D2I_get
(
ret
->
issuer_and_serial
,
d2i_PKCS7_ISSUER_AND_SERIAL
);
M_ASN1_D2I_get
(
ret
->
digest_alg
,
d2i_X509_ALGOR
);
M_ASN1_D2I_get_IMP_set_opt
(
ret
->
auth_attr
,
d2i_X509_ATTRIBUTE
,
X509_ATTRIBUTE_free
,
0
);
M_ASN1_D2I_get_IMP_set_opt_type
(
X509_ATTRIBUTE
,
ret
->
auth_attr
,
d2i_X509_ATTRIBUTE
,
X509_ATTRIBUTE_free
,
0
);
M_ASN1_D2I_get
(
ret
->
digest_enc_alg
,
d2i_X509_ALGOR
);
M_ASN1_D2I_get
(
ret
->
enc_digest
,
d2i_ASN1_OCTET_STRING
);
M_ASN1_D2I_get_IMP_set_opt
(
ret
->
unauth_attr
,
d2i_X509_ATTRIBUTE
,
X509_ATTRIBUTE_free
,
1
);
M_ASN1_D2I_get_IMP_set_opt_type
(
X509_ATTRIBUTE
,
ret
->
unauth_attr
,
d2i_X509_ATTRIBUTE
,
X509_ATTRIBUTE_free
,
1
);
M_ASN1_D2I_Finish
(
a
,
PKCS7_SIGNER_INFO_free
,
ASN1_F_D2I_PKCS7_SIGNER_INFO
);
...
...
@@ -131,10 +137,10 @@ void PKCS7_SIGNER_INFO_free(PKCS7_SIGNER_INFO *a)
ASN1_INTEGER_free
(
a
->
version
);
PKCS7_ISSUER_AND_SERIAL_free
(
a
->
issuer_and_serial
);
X509_ALGOR_free
(
a
->
digest_alg
);
sk_pop_free
(
a
->
auth_attr
,
X509_ATTRIBUTE_free
);
sk_
X509_ATTRIBUTE_
pop_free
(
a
->
auth_attr
,
X509_ATTRIBUTE_free
);
X509_ALGOR_free
(
a
->
digest_enc_alg
);
ASN1_OCTET_STRING_free
(
a
->
enc_digest
);
sk_pop_free
(
a
->
unauth_attr
,
X509_ATTRIBUTE_free
);
sk_
X509_ATTRIBUTE_
pop_free
(
a
->
unauth_attr
,
X509_ATTRIBUTE_free
);
if
(
a
->
pkey
!=
NULL
)
EVP_PKEY_free
(
a
->
pkey
);
Free
((
char
*
)
a
);
...
...
crypto/pkcs7/pk7_doit.c
浏览文件 @
b6436ff2
...
...
@@ -62,8 +62,9 @@
#include <openssl/objects.h>
#include <openssl/x509.h>
static
int
add_attribute
(
STACK
**
sk
,
int
nid
,
int
atrtype
,
void
*
value
);
static
ASN1_TYPE
*
get_attribute
(
STACK
*
sk
,
int
nid
);
static
int
add_attribute
(
STACK_OF
(
X509_ATTRIBUTE
)
**
sk
,
int
nid
,
int
atrtype
,
void
*
value
);
static
ASN1_TYPE
*
get_attribute
(
STACK_OF
(
X509_ATTRIBUTE
)
*
sk
,
int
nid
);
BIO
*
PKCS7_dataInit
(
PKCS7
*
p7
,
BIO
*
bio
)
{
...
...
@@ -462,7 +463,8 @@ int PKCS7_dataFinal(PKCS7 *p7, BIO *bio)
BUF_MEM
*
buf
=
NULL
;
PKCS7_SIGNER_INFO
*
si
;
EVP_MD_CTX
*
mdc
,
ctx_tmp
;
STACK
*
sk
,
*
si_sk
=
NULL
;
STACK_OF
(
X509_ATTRIBUTE
)
*
sk
;
STACK
*
si_sk
=
NULL
;
unsigned
char
*
p
,
*
pp
=
NULL
;
int
x
;
ASN1_OCTET_STRING
*
os
=
NULL
;
...
...
@@ -543,7 +545,7 @@ int PKCS7_dataFinal(PKCS7 *p7, BIO *bio)
/* If there are attributes, we add the digest
* attribute and only sign the attributes */
if
((
sk
!=
NULL
)
&&
(
sk_num
(
sk
)
!=
0
))
if
((
sk
!=
NULL
)
&&
(
sk_
X509_ATTRIBUTE_
num
(
sk
)
!=
0
))
{
unsigned
char
md_data
[
EVP_MAX_MD_SIZE
];
unsigned
int
md_len
;
...
...
@@ -568,12 +570,14 @@ int PKCS7_dataFinal(PKCS7 *p7, BIO *bio)
/* Now sign the mess */
EVP_SignInit
(
&
ctx_tmp
,
md_tmp
);
x
=
i2d_ASN1_SET
(
sk
,
NULL
,
i2d_X509_ATTRIBUTE
,
V_ASN1_SET
,
V_ASN1_UNIVERSAL
,
IS_SET
);
x
=
i2d_ASN1_SET_OF_X509_ATTRIBUTE
(
sk
,
NULL
,
i2d_X509_ATTRIBUTE
,
V_ASN1_SET
,
V_ASN1_UNIVERSAL
,
IS_SET
);
pp
=
(
unsigned
char
*
)
Malloc
(
x
);
p
=
pp
;
i2d_ASN1_SET
(
sk
,
&
p
,
i2d_X509_ATTRIBUTE
,
V_ASN1_SET
,
V_ASN1_UNIVERSAL
,
IS_SET
);
i2d_ASN1_SET_OF_X509_ATTRIBUTE
(
sk
,
&
p
,
i2d_X509_ATTRIBUTE
,
V_ASN1_SET
,
V_ASN1_UNIVERSAL
,
IS_SET
);
EVP_SignUpdate
(
&
ctx_tmp
,
pp
,
x
);
Free
(
pp
);
pp
=
NULL
;
...
...
@@ -628,7 +632,7 @@ int PKCS7_dataVerify(X509_STORE *cert_store, X509_STORE_CTX *ctx, BIO *bio,
PKCS7_ISSUER_AND_SERIAL
*
ias
;
int
ret
=
0
,
i
;
int
md_type
;
STACK
*
sk
;
STACK
_OF
(
X509_ATTRIBUTE
)
*
sk
;
STACK_OF
(
X509
)
*
cert
;
BIO
*
btmp
;
X509
*
x509
;
...
...
@@ -697,7 +701,7 @@ int PKCS7_dataVerify(X509_STORE *cert_store, X509_STORE_CTX *ctx, BIO *bio,
memcpy
(
&
mdc_tmp
,
mdc
,
sizeof
(
mdc_tmp
));
sk
=
si
->
auth_attr
;
if
((
sk
!=
NULL
)
&&
(
sk_num
(
sk
)
!=
0
))
if
((
sk
!=
NULL
)
&&
(
sk_
X509_ATTRIBUTE_
num
(
sk
)
!=
0
))
{
unsigned
char
md_dat
[
EVP_MAX_MD_SIZE
];
unsigned
int
md_len
;
...
...
@@ -731,11 +735,11 @@ for (ii=0; ii<md_len; ii++) printf("%02X",md_dat[ii]); printf(" calc\n");
* shouldn't reorder them or this will break the signature.
* This is done by using the IS_SEQUENCE flag.
*/
i
=
i2d_ASN1_SET
(
sk
,
NULL
,
i2d_X509_ATTRIBUTE
,
i
=
i2d_ASN1_SET
_OF_X509_ATTRIBUTE
(
sk
,
NULL
,
i2d_X509_ATTRIBUTE
,
V_ASN1_SET
,
V_ASN1_UNIVERSAL
,
IS_SEQUENCE
);
pp
=
(
unsigned
char
*
)
Malloc
(
i
);
pp
=
Malloc
(
i
);
p
=
pp
;
i2d_ASN1_SET
(
sk
,
&
p
,
i2d_X509_ATTRIBUTE
,
i2d_ASN1_SET
_OF_X509_ATTRIBUTE
(
sk
,
&
p
,
i2d_X509_ATTRIBUTE
,
V_ASN1_SET
,
V_ASN1_UNIVERSAL
,
IS_SEQUENCE
);
EVP_VerifyUpdate
(
&
mdc_tmp
,
pp
,
i
);
...
...
@@ -785,7 +789,7 @@ ASN1_TYPE *PKCS7_get_attribute(PKCS7_SIGNER_INFO *si, int nid)
return
(
get_attribute
(
si
->
unauth_attr
,
nid
));
}
static
ASN1_TYPE
*
get_attribute
(
STACK
*
sk
,
int
nid
)
static
ASN1_TYPE
*
get_attribute
(
STACK
_OF
(
X509_ATTRIBUTE
)
*
sk
,
int
nid
)
{
int
i
;
X509_ATTRIBUTE
*
xa
;
...
...
@@ -793,9 +797,9 @@ static ASN1_TYPE *get_attribute(STACK *sk, int nid)
o
=
OBJ_nid2obj
(
nid
);
if
(
!
o
||
!
sk
)
return
(
NULL
);
for
(
i
=
0
;
i
<
sk_num
(
sk
);
i
++
)
for
(
i
=
0
;
i
<
sk_
X509_ATTRIBUTE_
num
(
sk
);
i
++
)
{
xa
=
(
X509_ATTRIBUTE
*
)
sk
_value
(
sk
,
i
);
xa
=
sk_X509_ATTRIBUTE
_value
(
sk
,
i
);
if
(
OBJ_cmp
(
xa
->
object
,
o
)
==
0
)
{
if
(
xa
->
set
&&
sk_ASN1_TYPE_num
(
xa
->
value
.
set
))
...
...
@@ -807,40 +811,44 @@ static ASN1_TYPE *get_attribute(STACK *sk, int nid)
return
(
NULL
);
}
ASN1_OCTET_STRING
*
PKCS7_digest_from_attributes
(
STACK
*
sk
)
ASN1_OCTET_STRING
*
PKCS7_digest_from_attributes
(
STACK
_OF
(
X509_ATTRIBUTE
)
*
sk
)
{
ASN1_TYPE
*
astype
;
if
(
!
(
astype
=
get_attribute
(
sk
,
NID_pkcs9_messageDigest
)))
return
NULL
;
return
astype
->
value
.
octet_string
;
}
int
PKCS7_set_signed_attributes
(
PKCS7_SIGNER_INFO
*
p7si
,
STACK
*
sk
)
int
PKCS7_set_signed_attributes
(
PKCS7_SIGNER_INFO
*
p7si
,
STACK_OF
(
X509_ATTRIBUTE
)
*
sk
)
{
int
i
;
if
(
p7si
->
auth_attr
!=
NULL
)
sk_pop_free
(
p7si
->
auth_attr
,
X509_ATTRIBUTE_free
);
p7si
->
auth_attr
=
sk_dup
(
sk
);
for
(
i
=
0
;
i
<
sk_num
(
sk
);
i
++
)
sk_
X509_ATTRIBUTE_
pop_free
(
p7si
->
auth_attr
,
X509_ATTRIBUTE_free
);
p7si
->
auth_attr
=
sk_
X509_ATTRIBUTE_
dup
(
sk
);
for
(
i
=
0
;
i
<
sk_
X509_ATTRIBUTE_
num
(
sk
);
i
++
)
{
if
((
sk_set
(
p7si
->
auth_attr
,
i
,(
char
*
)
X509_ATTRIBUTE_dup
(
(
X509_ATTRIBUTE
*
)
sk_value
(
sk
,
i
))))
==
NULL
)
if
((
sk_X509_ATTRIBUTE_set
(
p7si
->
auth_attr
,
i
,
X509_ATTRIBUTE_dup
(
sk_X509_ATTRIBUTE_value
(
sk
,
i
))))
==
NULL
)
return
(
0
);
}
return
(
1
);
}
int
PKCS7_set_attributes
(
PKCS7_SIGNER_INFO
*
p7si
,
STACK
*
sk
)
int
PKCS7_set_attributes
(
PKCS7_SIGNER_INFO
*
p7si
,
STACK
_OF
(
X509_ATTRIBUTE
)
*
sk
)
{
int
i
;
if
(
p7si
->
unauth_attr
!=
NULL
)
sk_pop_free
(
p7si
->
unauth_attr
,
X509_ATTRIBUTE_free
);
p7si
->
unauth_attr
=
sk_dup
(
sk
);
for
(
i
=
0
;
i
<
sk_num
(
sk
);
i
++
)
sk_X509_ATTRIBUTE_pop_free
(
p7si
->
unauth_attr
,
X509_ATTRIBUTE_free
);
p7si
->
unauth_attr
=
sk_X509_ATTRIBUTE_dup
(
sk
);
for
(
i
=
0
;
i
<
sk_X509_ATTRIBUTE_num
(
sk
);
i
++
)
{
if
((
sk_set
(
p7si
->
unauth_attr
,
i
,(
char
*
)
X509_ATTRIBUTE_dup
(
(
X509_ATTRIBUTE
*
)
sk_value
(
sk
,
i
))))
==
NULL
)
if
((
sk_X509_ATTRIBUTE_set
(
p7si
->
unauth_attr
,
i
,
X509_ATTRIBUTE_dup
(
sk_X509_ATTRIBUTE_value
(
sk
,
i
))))
==
NULL
)
return
(
0
);
}
return
(
1
);
...
...
@@ -858,29 +866,30 @@ int PKCS7_add_attribute(PKCS7_SIGNER_INFO *p7si, int nid, int atrtype,
return
(
add_attribute
(
&
(
p7si
->
unauth_attr
),
nid
,
atrtype
,
value
));
}
static
int
add_attribute
(
STACK
**
sk
,
int
nid
,
int
atrtype
,
void
*
value
)
static
int
add_attribute
(
STACK_OF
(
X509_ATTRIBUTE
)
**
sk
,
int
nid
,
int
atrtype
,
void
*
value
)
{
X509_ATTRIBUTE
*
attr
=
NULL
;
if
(
*
sk
==
NULL
)
{
*
sk
=
sk_new
(
NULL
);
*
sk
=
sk_
X509_ATTRIBUTE_
new
(
NULL
);
new_attrib:
attr
=
X509_ATTRIBUTE_create
(
nid
,
atrtype
,
value
);
sk_
push
(
*
sk
,(
char
*
)
attr
);
sk_
X509_ATTRIBUTE_push
(
*
sk
,
attr
);
}
else
{
int
i
;
for
(
i
=
0
;
i
<
sk_num
(
*
sk
);
i
++
)
for
(
i
=
0
;
i
<
sk_
X509_ATTRIBUTE_
num
(
*
sk
);
i
++
)
{
attr
=
(
X509_ATTRIBUTE
*
)
sk
_value
(
*
sk
,
i
);
attr
=
sk_X509_ATTRIBUTE
_value
(
*
sk
,
i
);
if
(
OBJ_obj2nid
(
attr
->
object
)
==
nid
)
{
X509_ATTRIBUTE_free
(
attr
);
attr
=
X509_ATTRIBUTE_create
(
nid
,
atrtype
,
value
);
sk_
set
(
*
sk
,
i
,(
char
*
)
attr
);
sk_
X509_ATTRIBUTE_set
(
*
sk
,
i
,
attr
);
goto
end
;
}
}
...
...
crypto/pkcs7/pkcs7.h
浏览文件 @
b6436ff2
...
...
@@ -89,10 +89,10 @@ typedef struct pkcs7_signer_info_st
ASN1_INTEGER
*
version
;
/* version 1 */
PKCS7_ISSUER_AND_SERIAL
*
issuer_and_serial
;
X509_ALGOR
*
digest_alg
;
STACK
/* X509_ATTRIBUTE */
*
auth_attr
;
/* [ 0 ] */
STACK
_OF
(
X509_ATTRIBUTE
)
*
auth_attr
;
/* [ 0 ] */
X509_ALGOR
*
digest_enc_alg
;
ASN1_OCTET_STRING
*
enc_digest
;
STACK
/* X509_ATTRIBUTE */
*
unauth_attr
;
/* [ 1 ] */
STACK
_OF
(
X509_ATTRIBUTE
)
*
unauth_attr
;
/* [ 1 ] */
/* The private key to sign with */
EVP_PKEY
*
pkey
;
...
...
@@ -344,15 +344,16 @@ int PKCS7_RECIP_INFO_set(PKCS7_RECIP_INFO *p7i, X509 *x509);
int
PKCS7_set_cipher
(
PKCS7
*
p7
,
const
EVP_CIPHER
*
cipher
);
PKCS7_ISSUER_AND_SERIAL
*
PKCS7_get_issuer_and_serial
(
PKCS7
*
p7
,
int
idx
);
ASN1_OCTET_STRING
*
PKCS7_digest_from_attributes
(
STACK
*
sk
);
ASN1_OCTET_STRING
*
PKCS7_digest_from_attributes
(
STACK
_OF
(
X509_ATTRIBUTE
)
*
sk
);
int
PKCS7_add_signed_attribute
(
PKCS7_SIGNER_INFO
*
p7si
,
int
nid
,
int
type
,
void
*
data
);
int
PKCS7_add_attribute
(
PKCS7_SIGNER_INFO
*
p7si
,
int
nid
,
int
atrtype
,
void
*
value
);
ASN1_TYPE
*
PKCS7_get_attribute
(
PKCS7_SIGNER_INFO
*
si
,
int
nid
);
ASN1_TYPE
*
PKCS7_get_signed_attribute
(
PKCS7_SIGNER_INFO
*
si
,
int
nid
);
int
PKCS7_set_signed_attributes
(
PKCS7_SIGNER_INFO
*
p7si
,
STACK
*
sk
);
int
PKCS7_set_attributes
(
PKCS7_SIGNER_INFO
*
p7si
,
STACK
*
sk
);
int
PKCS7_set_signed_attributes
(
PKCS7_SIGNER_INFO
*
p7si
,
STACK_OF
(
X509_ATTRIBUTE
)
*
sk
);
int
PKCS7_set_attributes
(
PKCS7_SIGNER_INFO
*
p7si
,
STACK_OF
(
X509_ATTRIBUTE
)
*
sk
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录