!118 Add TLCP feature
From: @s-c-c Reviewed-by: @zhujianwei001 Signed-off-by: @zhujianwei001
This commit is contained in:
commit
52438f6cdd
108
Backport-Add-documents-for-SM2-cert-verification.patch
Normal file
108
Backport-Add-documents-for-SM2-cert-verification.patch
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
From 400e9ffc906d66318e4f9364494809d5a519c718 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Paul Yang <yang.yang@baishancloud.com>
|
||||||
|
Date: Wed, 13 Mar 2019 17:22:31 +0800
|
||||||
|
Subject: [PATCH 06/15] Add documents for SM2 cert verification
|
||||||
|
|
||||||
|
This follows #8321 which added the SM2 certificate verification feature.
|
||||||
|
This commit adds the related docs - the newly added 2 APIs and options
|
||||||
|
in apps/verify.
|
||||||
|
|
||||||
|
Reviewed-by: Paul Dale <paul.dale@oracle.com>
|
||||||
|
(Merged from https://github.com/openssl/openssl/pull/8465)
|
||||||
|
---
|
||||||
|
doc/man1/verify.pod | 14 ++++++++++++
|
||||||
|
doc/man3/X509_get0_sm2_id.pod | 43 +++++++++++++++++++++++++++++++++++
|
||||||
|
2 files changed, 57 insertions(+)
|
||||||
|
create mode 100644 doc/man3/X509_get0_sm2_id.pod
|
||||||
|
|
||||||
|
diff --git a/doc/man1/verify.pod b/doc/man1/verify.pod
|
||||||
|
index da2b702..a6b6b2b 100644
|
||||||
|
--- a/doc/man1/verify.pod
|
||||||
|
+++ b/doc/man1/verify.pod
|
||||||
|
@@ -50,6 +50,8 @@ B<openssl> B<verify>
|
||||||
|
[B<-verify_name name>]
|
||||||
|
[B<-x509_strict>]
|
||||||
|
[B<-show_chain>]
|
||||||
|
+[B<-sm2-id string>]
|
||||||
|
+[B<-sm2-hex-id hex-string>]
|
||||||
|
[B<->]
|
||||||
|
[certificates]
|
||||||
|
|
||||||
|
@@ -319,6 +321,16 @@ Display information about the certificate chain that has been built (if
|
||||||
|
successful). Certificates in the chain that came from the untrusted list will be
|
||||||
|
flagged as "untrusted".
|
||||||
|
|
||||||
|
+=item B<-sm2-id>
|
||||||
|
+
|
||||||
|
+Specify the ID string to use when verifying an SM2 certificate. The ID string is
|
||||||
|
+required by the SM2 signature algorithm for signing and verification.
|
||||||
|
+
|
||||||
|
+=item B<-sm2-hex-id>
|
||||||
|
+
|
||||||
|
+Specify a binary ID string to use when signing or verifying using an SM2
|
||||||
|
+certificate. The argument for this option is string of hexadecimal digits.
|
||||||
|
+
|
||||||
|
=item B<->
|
||||||
|
|
||||||
|
Indicates the last option. All arguments following this are assumed to be
|
||||||
|
@@ -774,6 +786,8 @@ The B<-show_chain> option was added in OpenSSL 1.1.0.
|
||||||
|
The B<-issuer_checks> option is deprecated as of OpenSSL 1.1.0 and
|
||||||
|
is silently ignored.
|
||||||
|
|
||||||
|
+The B<-sm2-id> and B<-sm2-hex-id> options were added in OpenSSL 3.0.0.
|
||||||
|
+
|
||||||
|
=head1 COPYRIGHT
|
||||||
|
|
||||||
|
Copyright 2000-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||||
|
diff --git a/doc/man3/X509_get0_sm2_id.pod b/doc/man3/X509_get0_sm2_id.pod
|
||||||
|
new file mode 100644
|
||||||
|
index 0000000..84da71e
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/doc/man3/X509_get0_sm2_id.pod
|
||||||
|
@@ -0,0 +1,43 @@
|
||||||
|
+=pod
|
||||||
|
+
|
||||||
|
+=head1 NAME
|
||||||
|
+
|
||||||
|
+X509_get0_sm2_id, X509_set_sm2_id - get or set SM2 ID for certificate operations
|
||||||
|
+
|
||||||
|
+=head1 SYNOPSIS
|
||||||
|
+
|
||||||
|
+ #include <openssl/x509.h>
|
||||||
|
+
|
||||||
|
+ ASN1_OCTET_STRING *X509_get0_sm2_id(X509 *x);
|
||||||
|
+ void X509_set_sm2_id(X509 *x, ASN1_OCTET_STRING *sm2_id);
|
||||||
|
+
|
||||||
|
+=head1 DESCRIPTION
|
||||||
|
+
|
||||||
|
+X509_get0_sm2_id() gets the ID value of an SM2 certificate B<x> by returning an
|
||||||
|
+B<ASN1_OCTET_STRING> object which should not be freed by the caller.
|
||||||
|
+X509_set_sm2_id() sets the B<sm2_id> value to an SM2 certificate B<x>.
|
||||||
|
+
|
||||||
|
+=head1 NOTES
|
||||||
|
+
|
||||||
|
+SM2 signature algorithm requires an ID value when generating and verifying a
|
||||||
|
+signature. The functions described in this manual provide the user with the
|
||||||
|
+ability to set and retrieve the SM2 ID value.
|
||||||
|
+
|
||||||
|
+=head1 RETURN VALUES
|
||||||
|
+
|
||||||
|
+X509_set_sm2_id() does not return a value.
|
||||||
|
+
|
||||||
|
+=head1 SEE ALSO
|
||||||
|
+
|
||||||
|
+L<X509_verify(3)>, L<SM2(7)>
|
||||||
|
+
|
||||||
|
+=head1 COPYRIGHT
|
||||||
|
+
|
||||||
|
+Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||||
|
+
|
||||||
|
+Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||||
|
+this file except in compliance with the License. You can obtain a copy
|
||||||
|
+in the file LICENSE in the source distribution or at
|
||||||
|
+L<https://www.openssl.org/source/license.html>.
|
||||||
|
+
|
||||||
|
+=cut
|
||||||
|
--
|
||||||
|
2.20.1 (Apple Git-117)
|
||||||
|
|
||||||
127
Backport-Add-test-cases-for-SM2-cert-verification.patch
Normal file
127
Backport-Add-test-cases-for-SM2-cert-verification.patch
Normal file
@ -0,0 +1,127 @@
|
|||||||
|
From c08251384c0405c151a90b315b8f333c38c74eb2 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Paul Yang <yang.yang@baishancloud.com>
|
||||||
|
Date: Wed, 13 Mar 2019 16:54:11 +0800
|
||||||
|
Subject: [PATCH 05/15] Add test cases for SM2 cert verification
|
||||||
|
|
||||||
|
This follows #8321 which added the SM2 certificate verification feature.
|
||||||
|
This commit adds some test cases for #8321.
|
||||||
|
|
||||||
|
Reviewed-by: Paul Dale <paul.dale@oracle.com>
|
||||||
|
(Merged from https://github.com/openssl/openssl/pull/8465)
|
||||||
|
---
|
||||||
|
test/certs/sm2-ca-cert.pem | 14 +++++++++++++
|
||||||
|
test/certs/{sm2.crt => sm2.pem} | 0
|
||||||
|
test/recipes/20-test_pkeyutl.t | 37 +++++++++++++--------------------
|
||||||
|
test/recipes/25-test_verify.t | 14 ++++++++++++-
|
||||||
|
4 files changed, 42 insertions(+), 23 deletions(-)
|
||||||
|
create mode 100644 test/certs/sm2-ca-cert.pem
|
||||||
|
rename test/certs/{sm2.crt => sm2.pem} (100%)
|
||||||
|
|
||||||
|
diff --git a/test/certs/sm2-ca-cert.pem b/test/certs/sm2-ca-cert.pem
|
||||||
|
new file mode 100644
|
||||||
|
index 0000000..5677ac6
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/test/certs/sm2-ca-cert.pem
|
||||||
|
@@ -0,0 +1,14 @@
|
||||||
|
+-----BEGIN CERTIFICATE-----
|
||||||
|
+MIICJDCCAcqgAwIBAgIJAOlkpDpSrmVbMAoGCCqBHM9VAYN1MGgxCzAJBgNVBAYT
|
||||||
|
+AkNOMQswCQYDVQQIDAJMTjERMA8GA1UEBwwIU2hlbnlhbmcxETAPBgNVBAoMCFRl
|
||||||
|
+c3QgT3JnMRAwDgYDVQQLDAdUZXN0IE9VMRQwEgYDVQQDDAtUZXN0IFNNMiBDQTAe
|
||||||
|
+Fw0xOTAyMTkwNzA1NDhaFw0yMzAzMzAwNzA1NDhaMGgxCzAJBgNVBAYTAkNOMQsw
|
||||||
|
+CQYDVQQIDAJMTjERMA8GA1UEBwwIU2hlbnlhbmcxETAPBgNVBAoMCFRlc3QgT3Jn
|
||||||
|
+MRAwDgYDVQQLDAdUZXN0IE9VMRQwEgYDVQQDDAtUZXN0IFNNMiBDQTBZMBMGByqG
|
||||||
|
+SM49AgEGCCqBHM9VAYItA0IABHRYnqErofBdXPptvvO7+BSVJxcpHuTGnZ+UPrbU
|
||||||
|
+5kVEUMaUnNOeMJZl/vRGimZCm/AkReJmRfnb15ESHR+ssp6jXTBbMB0GA1UdDgQW
|
||||||
|
+BBTFjcWu/zJgSZ5SKUlU5Vx4/0W5dDAfBgNVHSMEGDAWgBTFjcWu/zJgSZ5SKUlU
|
||||||
|
+5Vx4/0W5dDAMBgNVHRMEBTADAQH/MAsGA1UdDwQEAwIBBjAKBggqgRzPVQGDdQNI
|
||||||
|
+ADBFAiEAs6byi1nSQtFELOw/2tQIv5AEsZFR5MJ/oB2ztXzs2LYCIEfIw4xlUH6X
|
||||||
|
+YFhs4RnIa0K9Ng1ebsGPrifYkudwBIk3
|
||||||
|
+-----END CERTIFICATE-----
|
||||||
|
diff --git a/test/certs/sm2.crt b/test/certs/sm2.pem
|
||||||
|
similarity index 100%
|
||||||
|
rename from test/certs/sm2.crt
|
||||||
|
rename to test/certs/sm2.pem
|
||||||
|
diff --git a/test/recipes/20-test_pkeyutl.t b/test/recipes/20-test_pkeyutl.t
|
||||||
|
index 1457530..a36d41e 100644
|
||||||
|
--- a/test/recipes/20-test_pkeyutl.t
|
||||||
|
+++ b/test/recipes/20-test_pkeyutl.t
|
||||||
|
@@ -17,32 +17,25 @@ setup("test_pkeyutl");
|
||||||
|
|
||||||
|
plan tests => 2;
|
||||||
|
|
||||||
|
-sub sign
|
||||||
|
-{
|
||||||
|
- # Utilize the sm2.crt as the TBS file
|
||||||
|
- return run(app(([ 'openssl', 'pkeyutl', '-sign',
|
||||||
|
- '-in', srctop_file('test', 'certs', 'sm2.crt'),
|
||||||
|
- '-inkey', srctop_file('test', 'certs', 'sm2.key'),
|
||||||
|
- '-out', 'signature.sm2', '-rawin',
|
||||||
|
- '-digest', 'sm3', '-pkeyopt', 'sm2_id:someid'])));
|
||||||
|
-}
|
||||||
|
-
|
||||||
|
-sub verify
|
||||||
|
-{
|
||||||
|
- # Utilize the sm2.crt as the TBS file
|
||||||
|
- return run(app(([ 'openssl', 'pkeyutl', '-verify', '-certin',
|
||||||
|
- '-in', srctop_file('test', 'certs', 'sm2.crt'),
|
||||||
|
- '-inkey', srctop_file('test', 'certs', 'sm2.crt'),
|
||||||
|
- '-sigfile', 'signature.sm2', '-rawin',
|
||||||
|
- '-digest', 'sm3', '-pkeyopt', 'sm2_id:someid'])));
|
||||||
|
-}
|
||||||
|
+# For the tests below we use the cert itself as the TBS file
|
||||||
|
|
||||||
|
SKIP: {
|
||||||
|
skip "Skipping tests that require EC, SM2 or SM3", 2
|
||||||
|
if disabled("ec") || disabled("sm2") || disabled("sm3");
|
||||||
|
|
||||||
|
- ok(sign, "Sign a piece of data using SM2");
|
||||||
|
- ok(verify, "Verify an SM2 signature against a piece of data");
|
||||||
|
+ # SM2
|
||||||
|
+ ok(run(app(([ 'openssl', 'pkeyutl', '-sign',
|
||||||
|
+ '-in', srctop_file('test', 'certs', 'sm2.pem'),
|
||||||
|
+ '-inkey', srctop_file('test', 'certs', 'sm2.key'),
|
||||||
|
+ '-out', 'signature.dat', '-rawin',
|
||||||
|
+ '-digest', 'sm3', '-pkeyopt', 'sm2_id:someid']))),
|
||||||
|
+ "Sign a piece of data using SM2");
|
||||||
|
+ ok(run(app(([ 'openssl', 'pkeyutl', '-verify', '-certin',
|
||||||
|
+ '-in', srctop_file('test', 'certs', 'sm2.pem'),
|
||||||
|
+ '-inkey', srctop_file('test', 'certs', 'sm2.pem'),
|
||||||
|
+ '-sigfile', 'signature.dat', '-rawin',
|
||||||
|
+ '-digest', 'sm3', '-pkeyopt', 'sm2_id:someid']))),
|
||||||
|
+ "Verify an SM2 signature against a piece of data");
|
||||||
|
}
|
||||||
|
|
||||||
|
-unlink 'signature.sm2';
|
||||||
|
+unlink 'signature.dat';
|
||||||
|
diff --git a/test/recipes/25-test_verify.t b/test/recipes/25-test_verify.t
|
||||||
|
index ffa48ed..b340833 100644
|
||||||
|
--- a/test/recipes/25-test_verify.t
|
||||||
|
+++ b/test/recipes/25-test_verify.t
|
||||||
|
@@ -27,7 +27,7 @@ sub verify {
|
||||||
|
run(app([@args]));
|
||||||
|
}
|
||||||
|
|
||||||
|
-plan tests => 146;
|
||||||
|
+plan tests => 148;
|
||||||
|
|
||||||
|
# Canonical success
|
||||||
|
ok(verify("ee-cert", "sslserver", ["root-cert"], ["ca-cert"]),
|
||||||
|
@@ -409,3 +409,15 @@ SKIP: {
|
||||||
|
"ED25519 signature");
|
||||||
|
|
||||||
|
}
|
||||||
|
+
|
||||||
|
+SKIP: {
|
||||||
|
+ skip "SM2 is not supported by this OpenSSL build", 1
|
||||||
|
+ if disabled("sm2");
|
||||||
|
+
|
||||||
|
+ # Test '-sm2-id' and '-sm2-hex-id' option
|
||||||
|
+ ok(verify("sm2", "any", ["sm2-ca-cert"], [], "-sm2-id", "1234567812345678"),
|
||||||
|
+ "SM2 ID test");
|
||||||
|
+ ok(verify("sm2", "any", ["sm2-ca-cert"], [], "-sm2-hex-id",
|
||||||
|
+ "31323334353637383132333435363738"),
|
||||||
|
+ "SM2 hex ID test");
|
||||||
|
+}
|
||||||
|
--
|
||||||
|
2.20.1 (Apple Git-117)
|
||||||
|
|
||||||
29
Backport-Fix-a-document-description-in-apps-req.patch
Normal file
29
Backport-Fix-a-document-description-in-apps-req.patch
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
From 7e64be50900c4aa8cd040c4e3999540883bdeeb6 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Paul Yang <kaishen.yy@antfin.com>
|
||||||
|
Date: Thu, 26 Sep 2019 10:57:23 +0800
|
||||||
|
Subject: [PATCH 13/15] Fix a document description in apps/req
|
||||||
|
|
||||||
|
Reviewed-by: Matt Caswell <matt@openssl.org>
|
||||||
|
(Merged from https://github.com/openssl/openssl/pull/9958)
|
||||||
|
---
|
||||||
|
doc/man1/req.pod | 4 ++--
|
||||||
|
1 file changed, 2 insertions(+), 2 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/doc/man1/req.pod b/doc/man1/req.pod
|
||||||
|
index 7b00bad..e117ec6 100644
|
||||||
|
--- a/doc/man1/req.pod
|
||||||
|
+++ b/doc/man1/req.pod
|
||||||
|
@@ -348,8 +348,8 @@ string is required by the SM2 signature algorithm for signing and verification.
|
||||||
|
|
||||||
|
=item B<-sm2-hex-id>
|
||||||
|
|
||||||
|
-Specify a binary ID string to use when signing or verifying using an SM2
|
||||||
|
-certificate. The argument for this option is string of hexadecimal digits.
|
||||||
|
+Specify a binary ID string to use when verifying an SM2 certificate request. The
|
||||||
|
+argument for this option is string of hexadecimal digits.
|
||||||
|
|
||||||
|
=back
|
||||||
|
|
||||||
|
--
|
||||||
|
2.20.1 (Apple Git-117)
|
||||||
|
|
||||||
121
Backport-Fix-a-double-free-issue-when-signing-SM2-cert.patch
Normal file
121
Backport-Fix-a-double-free-issue-when-signing-SM2-cert.patch
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
From a63238684c1d2e15f417f766f44418a8b52ef383 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Paul Yang <kaishen.yy@antfin.com>
|
||||||
|
Date: Sat, 21 Sep 2019 00:32:57 +0800
|
||||||
|
Subject: [PATCH 12/15] Fix a double free issue when signing SM2 cert
|
||||||
|
|
||||||
|
If the SM2 ID value has not been passed correctly when signing an SM2
|
||||||
|
certificate/certificate request, a double free occurs. For instance:
|
||||||
|
|
||||||
|
openssl req -x509 ... -sm2-id 1234567812345678
|
||||||
|
|
||||||
|
The '-sm2-id' should not be used in this scenario, while the '-sigopt' is
|
||||||
|
the correct one to use. Documentation has also been updated to make the
|
||||||
|
options more clear.
|
||||||
|
|
||||||
|
Reviewed-by: Matt Caswell <matt@openssl.org>
|
||||||
|
(Merged from https://github.com/openssl/openssl/pull/9958)
|
||||||
|
---
|
||||||
|
apps/req.c | 48 ++++++++++++++++++++++++++++++------------------
|
||||||
|
doc/man1/req.pod | 4 ++--
|
||||||
|
2 files changed, 32 insertions(+), 20 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/apps/req.c b/apps/req.c
|
||||||
|
index 96f1edd..95dd0e4 100644
|
||||||
|
--- a/apps/req.c
|
||||||
|
+++ b/apps/req.c
|
||||||
|
@@ -1756,15 +1756,19 @@ int do_X509_sign(X509 *x, EVP_PKEY *pkey, const EVP_MD *md,
|
||||||
|
#endif
|
||||||
|
|
||||||
|
rv = do_sign_init(mctx, pkey, md, sigopts);
|
||||||
|
- if (rv > 0)
|
||||||
|
+ if (rv > 0) {
|
||||||
|
rv = X509_sign_ctx(x, mctx);
|
||||||
|
#ifndef OPENSSL_NO_SM2
|
||||||
|
- /* only in SM2 case we need to free the pctx explicitly */
|
||||||
|
- if (ec_pkey_is_sm2(pkey)) {
|
||||||
|
- pctx = EVP_MD_CTX_pkey_ctx(mctx);
|
||||||
|
- EVP_PKEY_CTX_free(pctx);
|
||||||
|
- }
|
||||||
|
+ /*
|
||||||
|
+ * only in SM2 case we need to free the pctx explicitly
|
||||||
|
+ * if do_sign_init() fails, pctx is already freed in it
|
||||||
|
+ */
|
||||||
|
+ if (ec_pkey_is_sm2(pkey)) {
|
||||||
|
+ pctx = EVP_MD_CTX_pkey_ctx(mctx);
|
||||||
|
+ EVP_PKEY_CTX_free(pctx);
|
||||||
|
+ }
|
||||||
|
#endif
|
||||||
|
+ }
|
||||||
|
EVP_MD_CTX_free(mctx);
|
||||||
|
return rv > 0 ? 1 : 0;
|
||||||
|
}
|
||||||
|
@@ -1779,15 +1783,19 @@ int do_X509_REQ_sign(X509_REQ *x, EVP_PKEY *pkey, const EVP_MD *md,
|
||||||
|
#endif
|
||||||
|
|
||||||
|
rv = do_sign_init(mctx, pkey, md, sigopts);
|
||||||
|
- if (rv > 0)
|
||||||
|
+ if (rv > 0) {
|
||||||
|
rv = X509_REQ_sign_ctx(x, mctx);
|
||||||
|
#ifndef OPENSSL_NO_SM2
|
||||||
|
- /* only in SM2 case we need to free the pctx explicitly */
|
||||||
|
- if (ec_pkey_is_sm2(pkey)) {
|
||||||
|
- pctx = EVP_MD_CTX_pkey_ctx(mctx);
|
||||||
|
- EVP_PKEY_CTX_free(pctx);
|
||||||
|
- }
|
||||||
|
+ /*
|
||||||
|
+ * only in SM2 case we need to free the pctx explicitly
|
||||||
|
+ * if do_sign_init() fails, pctx is already freed in it
|
||||||
|
+ */
|
||||||
|
+ if (ec_pkey_is_sm2(pkey)) {
|
||||||
|
+ pctx = EVP_MD_CTX_pkey_ctx(mctx);
|
||||||
|
+ EVP_PKEY_CTX_free(pctx);
|
||||||
|
+ }
|
||||||
|
#endif
|
||||||
|
+ }
|
||||||
|
EVP_MD_CTX_free(mctx);
|
||||||
|
return rv > 0 ? 1 : 0;
|
||||||
|
}
|
||||||
|
@@ -1802,15 +1810,19 @@ int do_X509_CRL_sign(X509_CRL *x, EVP_PKEY *pkey, const EVP_MD *md,
|
||||||
|
#endif
|
||||||
|
|
||||||
|
rv = do_sign_init(mctx, pkey, md, sigopts);
|
||||||
|
- if (rv > 0)
|
||||||
|
+ if (rv > 0) {
|
||||||
|
rv = X509_CRL_sign_ctx(x, mctx);
|
||||||
|
#ifndef OPENSSL_NO_SM2
|
||||||
|
- /* only in SM2 case we need to free the pctx explicitly */
|
||||||
|
- if (ec_pkey_is_sm2(pkey)) {
|
||||||
|
- pctx = EVP_MD_CTX_pkey_ctx(mctx);
|
||||||
|
- EVP_PKEY_CTX_free(pctx);
|
||||||
|
- }
|
||||||
|
+ /*
|
||||||
|
+ * only in SM2 case we need to free the pctx explicitly
|
||||||
|
+ * if do_sign_init() fails, no need to double free pctx
|
||||||
|
+ */
|
||||||
|
+ if (ec_pkey_is_sm2(pkey)) {
|
||||||
|
+ pctx = EVP_MD_CTX_pkey_ctx(mctx);
|
||||||
|
+ EVP_PKEY_CTX_free(pctx);
|
||||||
|
+ }
|
||||||
|
#endif
|
||||||
|
+ }
|
||||||
|
EVP_MD_CTX_free(mctx);
|
||||||
|
return rv > 0 ? 1 : 0;
|
||||||
|
}
|
||||||
|
diff --git a/doc/man1/req.pod b/doc/man1/req.pod
|
||||||
|
index 3b9fcc3..7b00bad 100644
|
||||||
|
--- a/doc/man1/req.pod
|
||||||
|
+++ b/doc/man1/req.pod
|
||||||
|
@@ -343,8 +343,8 @@ for key generation operations.
|
||||||
|
|
||||||
|
=item B<-sm2-id>
|
||||||
|
|
||||||
|
-Specify the ID string to use when verifying an SM2 certificate. The ID string is
|
||||||
|
-required by the SM2 signature algorithm for signing and verification.
|
||||||
|
+Specify the ID string to use when verifying an SM2 certificate request. The ID
|
||||||
|
+string is required by the SM2 signature algorithm for signing and verification.
|
||||||
|
|
||||||
|
=item B<-sm2-hex-id>
|
||||||
|
|
||||||
|
--
|
||||||
|
2.20.1 (Apple Git-117)
|
||||||
|
|
||||||
43
Backport-Fix-a-memleak-in-apps-verify.patch
Normal file
43
Backport-Fix-a-memleak-in-apps-verify.patch
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
From 1c243548ef736329b08344ad9191803e5a93ec17 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Paul Yang <yang.yang@baishancloud.com>
|
||||||
|
Date: Wed, 13 Mar 2019 18:04:05 +0800
|
||||||
|
Subject: [PATCH 07/15] Fix a memleak in apps/verify
|
||||||
|
|
||||||
|
Reviewed-by: Paul Dale <paul.dale@oracle.com>
|
||||||
|
(Merged from https://github.com/openssl/openssl/pull/8465)
|
||||||
|
---
|
||||||
|
apps/verify.c | 4 ++++
|
||||||
|
1 file changed, 4 insertions(+)
|
||||||
|
|
||||||
|
diff --git a/apps/verify.c b/apps/verify.c
|
||||||
|
index 09b31cf..5052d80 100644
|
||||||
|
--- a/apps/verify.c
|
||||||
|
+++ b/apps/verify.c
|
||||||
|
@@ -80,6 +80,7 @@ int verify_main(int argc, char **argv)
|
||||||
|
OPTION_CHOICE o;
|
||||||
|
unsigned char *sm2_id = NULL;
|
||||||
|
size_t sm2_idlen = 0;
|
||||||
|
+ int sm2_free = 0;
|
||||||
|
|
||||||
|
if ((vpm = X509_VERIFY_PARAM_new()) == NULL)
|
||||||
|
goto end;
|
||||||
|
@@ -174,6 +175,7 @@ int verify_main(int argc, char **argv)
|
||||||
|
break;
|
||||||
|
case OPT_SM2HEXID:
|
||||||
|
/* try to parse the input as hex string first */
|
||||||
|
+ sm2_free = 1;
|
||||||
|
sm2_id = OPENSSL_hexstr2buf(opt_arg(), (long *)&sm2_idlen);
|
||||||
|
if (sm2_id == NULL) {
|
||||||
|
BIO_printf(bio_err, "Invalid hex string input\n");
|
||||||
|
@@ -216,6 +218,8 @@ int verify_main(int argc, char **argv)
|
||||||
|
}
|
||||||
|
|
||||||
|
end:
|
||||||
|
+ if (sm2_free)
|
||||||
|
+ OPENSSL_free(sm2_id);
|
||||||
|
X509_VERIFY_PARAM_free(vpm);
|
||||||
|
X509_STORE_free(store);
|
||||||
|
sk_X509_pop_free(untrusted, X509_free);
|
||||||
|
--
|
||||||
|
2.20.1 (Apple Git-117)
|
||||||
|
|
||||||
67
Backport-Fix-no-ec-no-sm2-and-no-sm3.patch
Normal file
67
Backport-Fix-no-ec-no-sm2-and-no-sm3.patch
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
From 380cf570be1ded495141e16ceab7afb7f7c57ab7 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Matt Caswell <matt@openssl.org>
|
||||||
|
Date: Thu, 28 Feb 2019 13:47:26 +0000
|
||||||
|
Subject: [PATCH 02/15] Fix no-ec, no-sm2 and no-sm3
|
||||||
|
|
||||||
|
Reviewed-by: Richard Levitte <levitte@openssl.org>
|
||||||
|
(Merged from https://github.com/openssl/openssl/pull/8372)
|
||||||
|
---
|
||||||
|
apps/pkeyutl.c | 11 +++++++----
|
||||||
|
test/recipes/20-test_pkeyutl.t | 9 +++++++--
|
||||||
|
2 files changed, 14 insertions(+), 6 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/apps/pkeyutl.c b/apps/pkeyutl.c
|
||||||
|
index bca0464..1d3d57b 100644
|
||||||
|
--- a/apps/pkeyutl.c
|
||||||
|
+++ b/apps/pkeyutl.c
|
||||||
|
@@ -473,14 +473,16 @@ static EVP_PKEY_CTX *init_ctx(const char *kdfalg, int *pkeysize,
|
||||||
|
}
|
||||||
|
ctx = EVP_PKEY_CTX_new_id(kdfnid, impl);
|
||||||
|
} else {
|
||||||
|
- EC_KEY *eckey = NULL;
|
||||||
|
- const EC_GROUP *group = NULL;
|
||||||
|
- int nid;
|
||||||
|
-
|
||||||
|
if (pkey == NULL)
|
||||||
|
goto end;
|
||||||
|
+
|
||||||
|
+#ifndef OPENSSL_NO_EC
|
||||||
|
/* SM2 needs a special treatment */
|
||||||
|
if (EVP_PKEY_id(pkey) == EVP_PKEY_EC) {
|
||||||
|
+ EC_KEY *eckey = NULL;
|
||||||
|
+ const EC_GROUP *group = NULL;
|
||||||
|
+ int nid;
|
||||||
|
+
|
||||||
|
if ((eckey = EVP_PKEY_get0_EC_KEY(pkey)) == NULL
|
||||||
|
|| (group = EC_KEY_get0_group(eckey)) == NULL
|
||||||
|
|| (nid = EC_GROUP_get_curve_name(group)) == 0)
|
||||||
|
@@ -488,6 +490,7 @@ static EVP_PKEY_CTX *init_ctx(const char *kdfalg, int *pkeysize,
|
||||||
|
if (nid == NID_sm2)
|
||||||
|
EVP_PKEY_set_alias_type(pkey, EVP_PKEY_SM2);
|
||||||
|
}
|
||||||
|
+#endif
|
||||||
|
*pkeysize = EVP_PKEY_size(pkey);
|
||||||
|
ctx = EVP_PKEY_CTX_new(pkey, impl);
|
||||||
|
if (ppkey != NULL)
|
||||||
|
diff --git a/test/recipes/20-test_pkeyutl.t b/test/recipes/20-test_pkeyutl.t
|
||||||
|
index a051138..1457530 100644
|
||||||
|
--- a/test/recipes/20-test_pkeyutl.t
|
||||||
|
+++ b/test/recipes/20-test_pkeyutl.t
|
||||||
|
@@ -37,7 +37,12 @@ sub verify
|
||||||
|
'-digest', 'sm3', '-pkeyopt', 'sm2_id:someid'])));
|
||||||
|
}
|
||||||
|
|
||||||
|
-ok(sign, "Sign a piece of data using SM2");
|
||||||
|
-ok(verify, "Verify an SM2 signature against a piece of data");
|
||||||
|
+SKIP: {
|
||||||
|
+ skip "Skipping tests that require EC, SM2 or SM3", 2
|
||||||
|
+ if disabled("ec") || disabled("sm2") || disabled("sm3");
|
||||||
|
+
|
||||||
|
+ ok(sign, "Sign a piece of data using SM2");
|
||||||
|
+ ok(verify, "Verify an SM2 signature against a piece of data");
|
||||||
|
+}
|
||||||
|
|
||||||
|
unlink 'signature.sm2';
|
||||||
|
--
|
||||||
|
2.20.1 (Apple Git-117)
|
||||||
|
|
||||||
44
Backport-Guard-some-SM2-functions-with-OPENSSL_NO_SM2.patch
Normal file
44
Backport-Guard-some-SM2-functions-with-OPENSSL_NO_SM2.patch
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
From 908570d02b683195ddfdc8e8c324638bfaa0d2c2 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Matt Caswell <matt@openssl.org>
|
||||||
|
Date: Thu, 14 Mar 2019 11:14:38 +0000
|
||||||
|
Subject: [PATCH 04/15] Guard some SM2 functions with OPENSSL_NO_SM2
|
||||||
|
|
||||||
|
Fixes the no-ec build
|
||||||
|
|
||||||
|
Reviewed-by: Richard Levitte <levitte@openssl.org>
|
||||||
|
(Merged from https://github.com/openssl/openssl/pull/8481)
|
||||||
|
---
|
||||||
|
include/openssl/x509.h | 2 ++
|
||||||
|
util/libcrypto.num | 4 ++--
|
||||||
|
2 files changed, 4 insertions(+), 2 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/include/openssl/x509.h b/include/openssl/x509.h
|
||||||
|
index 5f17057..5c88251 100644
|
||||||
|
--- a/include/openssl/x509.h
|
||||||
|
+++ b/include/openssl/x509.h
|
||||||
|
@@ -573,8 +573,10 @@ void X509_get0_signature(const ASN1_BIT_STRING **psig,
|
||||||
|
const X509_ALGOR **palg, const X509 *x);
|
||||||
|
int X509_get_signature_nid(const X509 *x);
|
||||||
|
|
||||||
|
+# ifndef OPENSSL_NO_SM2
|
||||||
|
void X509_set_sm2_id(X509 *x, ASN1_OCTET_STRING *sm2_id);
|
||||||
|
ASN1_OCTET_STRING *X509_get0_sm2_id(X509 *x);
|
||||||
|
+# endif
|
||||||
|
|
||||||
|
int X509_trusted(const X509 *x);
|
||||||
|
int X509_alias_set1(X509 *x, const unsigned char *name, int len);
|
||||||
|
diff --git a/util/libcrypto.num b/util/libcrypto.num
|
||||||
|
index 8635ac4..233d1c7 100644
|
||||||
|
--- a/util/libcrypto.num
|
||||||
|
+++ b/util/libcrypto.num
|
||||||
|
@@ -4626,5 +4626,5 @@ FIPS_drbg_get_strength 6379 1_1_0g EXIST::FUNCTION:
|
||||||
|
FIPS_rand_strength 6380 1_1_0g EXIST::FUNCTION:
|
||||||
|
FIPS_drbg_get_blocklength 6381 1_1_0g EXIST::FUNCTION:
|
||||||
|
FIPS_drbg_init 6382 1_1_0g EXIST::FUNCTION:
|
||||||
|
-X509_set_sm2_id 6383 1_1_1m EXIST::FUNCTION:
|
||||||
|
-X509_get0_sm2_id 6384 1_1_1m EXIST::FUNCTION:
|
||||||
|
+X509_set_sm2_id 6383 1_1_1m EXIST::FUNCTION:SM2
|
||||||
|
+X509_get0_sm2_id 6384 1_1_1m EXIST::FUNCTION:SM2
|
||||||
|
--
|
||||||
|
2.20.1 (Apple Git-117)
|
||||||
|
|
||||||
@ -0,0 +1,320 @@
|
|||||||
|
From 0717cc33d72b011cce4f53661c58d628b684275c Mon Sep 17 00:00:00 2001
|
||||||
|
From: Paul Yang <yang.yang@baishancloud.com>
|
||||||
|
Date: Mon, 1 Apr 2019 10:21:53 +0900
|
||||||
|
Subject: [PATCH 09/15] Make X509_set_sm2_id consistent with other setters
|
||||||
|
|
||||||
|
This commit makes the X509_set_sm2_id to 'set0' behaviour, which means
|
||||||
|
the memory management is passed to X509 and user doesn't need to free
|
||||||
|
the sm2_id parameter later. API name also changes to X509_set0_sm2_id.
|
||||||
|
|
||||||
|
Document and test case are also updated.
|
||||||
|
|
||||||
|
Reviewed-by: Matt Caswell <matt@openssl.org>
|
||||||
|
(Merged from https://github.com/openssl/openssl/pull/8626)
|
||||||
|
---
|
||||||
|
apps/verify.c | 40 +++++++++++++++++++-----------
|
||||||
|
crypto/x509/x_all.c | 5 +++-
|
||||||
|
crypto/x509/x_x509.c | 13 +++++++---
|
||||||
|
doc/man3/X509_get0_sm2_id.pod | 12 ++++++---
|
||||||
|
include/crypto/x509.h | 2 +-
|
||||||
|
include/openssl/x509.h | 2 +-
|
||||||
|
test/verify_extra_test.c | 46 +++++++++++++++++++++++++++++++++++
|
||||||
|
util/libcrypto.num | 2 +-
|
||||||
|
8 files changed, 97 insertions(+), 25 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/apps/verify.c b/apps/verify.c
|
||||||
|
index 5052d80..9000567 100644
|
||||||
|
--- a/apps/verify.c
|
||||||
|
+++ b/apps/verify.c
|
||||||
|
@@ -246,27 +246,37 @@ static int check(X509_STORE *ctx, const char *file,
|
||||||
|
|
||||||
|
if (sm2id != NULL) {
|
||||||
|
#ifndef OPENSSL_NO_SM2
|
||||||
|
- ASN1_OCTET_STRING v;
|
||||||
|
+ ASN1_OCTET_STRING *v;
|
||||||
|
|
||||||
|
- v.data = sm2id;
|
||||||
|
- v.length = sm2idlen;
|
||||||
|
+ v = ASN1_OCTET_STRING_new();
|
||||||
|
+ if (v == NULL) {
|
||||||
|
+ BIO_printf(bio_err, "error: SM2 ID allocation failed\n");
|
||||||
|
+ goto end;
|
||||||
|
+ }
|
||||||
|
|
||||||
|
- X509_set_sm2_id(x, &v);
|
||||||
|
+ if (!ASN1_OCTET_STRING_set(v, sm2id, sm2idlen)) {
|
||||||
|
+ BIO_printf(bio_err, "error: setting SM2 ID failed\n");
|
||||||
|
+ ASN1_OCTET_STRING_free(v);
|
||||||
|
+ goto end;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ X509_set0_sm2_id(x, v);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
csc = X509_STORE_CTX_new();
|
||||||
|
if (csc == NULL) {
|
||||||
|
- printf("error %s: X.509 store context allocation failed\n",
|
||||||
|
- (file == NULL) ? "stdin" : file);
|
||||||
|
+ BIO_printf(bio_err, "error %s: X.509 store context allocation failed\n",
|
||||||
|
+ (file == NULL) ? "stdin" : file);
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
|
X509_STORE_set_flags(ctx, vflags);
|
||||||
|
if (!X509_STORE_CTX_init(csc, ctx, x, uchain)) {
|
||||||
|
X509_STORE_CTX_free(csc);
|
||||||
|
- printf("error %s: X.509 store context initialization failed\n",
|
||||||
|
- (file == NULL) ? "stdin" : file);
|
||||||
|
+ BIO_printf(bio_err,
|
||||||
|
+ "error %s: X.509 store context initialization failed\n",
|
||||||
|
+ (file == NULL) ? "stdin" : file);
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
if (tchain != NULL)
|
||||||
|
@@ -275,28 +285,30 @@ static int check(X509_STORE *ctx, const char *file,
|
||||||
|
X509_STORE_CTX_set0_crls(csc, crls);
|
||||||
|
i = X509_verify_cert(csc);
|
||||||
|
if (i > 0 && X509_STORE_CTX_get_error(csc) == X509_V_OK) {
|
||||||
|
- printf("%s: OK\n", (file == NULL) ? "stdin" : file);
|
||||||
|
+ BIO_printf(bio_out, "%s: OK\n", (file == NULL) ? "stdin" : file);
|
||||||
|
ret = 1;
|
||||||
|
if (show_chain) {
|
||||||
|
int j;
|
||||||
|
|
||||||
|
chain = X509_STORE_CTX_get1_chain(csc);
|
||||||
|
num_untrusted = X509_STORE_CTX_get_num_untrusted(csc);
|
||||||
|
- printf("Chain:\n");
|
||||||
|
+ BIO_printf(bio_out, "Chain:\n");
|
||||||
|
for (j = 0; j < sk_X509_num(chain); j++) {
|
||||||
|
X509 *cert = sk_X509_value(chain, j);
|
||||||
|
- printf("depth=%d: ", j);
|
||||||
|
+ BIO_printf(bio_out, "depth=%d: ", j);
|
||||||
|
X509_NAME_print_ex_fp(stdout,
|
||||||
|
X509_get_subject_name(cert),
|
||||||
|
0, get_nameopt());
|
||||||
|
if (j < num_untrusted)
|
||||||
|
- printf(" (untrusted)");
|
||||||
|
- printf("\n");
|
||||||
|
+ BIO_printf(bio_out, " (untrusted)");
|
||||||
|
+ BIO_printf(bio_out, "\n");
|
||||||
|
}
|
||||||
|
sk_X509_pop_free(chain, X509_free);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
- printf("error %s: verification failed\n", (file == NULL) ? "stdin" : file);
|
||||||
|
+ BIO_printf(bio_err,
|
||||||
|
+ "error %s: verification failed\n",
|
||||||
|
+ (file == NULL) ? "stdin" : file);
|
||||||
|
}
|
||||||
|
X509_STORE_CTX_free(csc);
|
||||||
|
|
||||||
|
diff --git a/crypto/x509/x_all.c b/crypto/x509/x_all.c
|
||||||
|
index 60a2892..9c8aea5 100644
|
||||||
|
--- a/crypto/x509/x_all.c
|
||||||
|
+++ b/crypto/x509/x_all.c
|
||||||
|
@@ -72,7 +72,10 @@ static int x509_verify_sm2(X509 *x, EVP_PKEY *pkey, int mdnid, int pknid)
|
||||||
|
ret = 0;
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
- if (EVP_PKEY_CTX_set1_id(pctx, x->sm2_id.data, x->sm2_id.length) != 1) {
|
||||||
|
+ /* NOTE: we tolerate no actual ID, to provide maximum flexibility */
|
||||||
|
+ if (x->sm2_id != NULL
|
||||||
|
+ && EVP_PKEY_CTX_set1_id(pctx, x->sm2_id->data,
|
||||||
|
+ x->sm2_id->length) != 1) {
|
||||||
|
X509err(X509_F_X509_VERIFY_SM2, ERR_R_EVP_LIB);
|
||||||
|
ret = 0;
|
||||||
|
goto err;
|
||||||
|
diff --git a/crypto/x509/x_x509.c b/crypto/x509/x_x509.c
|
||||||
|
index 1beab78..fb03bb2 100644
|
||||||
|
--- a/crypto/x509/x_x509.c
|
||||||
|
+++ b/crypto/x509/x_x509.c
|
||||||
|
@@ -72,6 +72,9 @@ static int x509_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
|
||||||
|
#ifndef OPENSSL_NO_RFC3779
|
||||||
|
ret->rfc3779_addr = NULL;
|
||||||
|
ret->rfc3779_asid = NULL;
|
||||||
|
+#endif
|
||||||
|
+#ifndef OPENSSL_NO_SM2
|
||||||
|
+ ret->sm2_id = NULL;
|
||||||
|
#endif
|
||||||
|
ret->aux = NULL;
|
||||||
|
ret->crldp = NULL;
|
||||||
|
@@ -91,6 +94,9 @@ static int x509_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
|
||||||
|
#ifndef OPENSSL_NO_RFC3779
|
||||||
|
sk_IPAddressFamily_pop_free(ret->rfc3779_addr, IPAddressFamily_free);
|
||||||
|
ASIdentifiers_free(ret->rfc3779_asid);
|
||||||
|
+#endif
|
||||||
|
+#ifndef OPENSSL_NO_SM2
|
||||||
|
+ ASN1_OCTET_STRING_free(ret->sm2_id);
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
|
||||||
|
@@ -247,13 +253,14 @@ int X509_get_signature_nid(const X509 *x)
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef OPENSSL_NO_SM2
|
||||||
|
-void X509_set_sm2_id(X509 *x, ASN1_OCTET_STRING *sm2_id)
|
||||||
|
+void X509_set0_sm2_id(X509 *x, ASN1_OCTET_STRING *sm2_id)
|
||||||
|
{
|
||||||
|
- x->sm2_id = *sm2_id;
|
||||||
|
+ ASN1_OCTET_STRING_free(x->sm2_id);
|
||||||
|
+ x->sm2_id = sm2_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
ASN1_OCTET_STRING *X509_get0_sm2_id(X509 *x)
|
||||||
|
{
|
||||||
|
- return &x->sm2_id;
|
||||||
|
+ return x->sm2_id;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
diff --git a/doc/man3/X509_get0_sm2_id.pod b/doc/man3/X509_get0_sm2_id.pod
|
||||||
|
index 84da71e..9698c86 100644
|
||||||
|
--- a/doc/man3/X509_get0_sm2_id.pod
|
||||||
|
+++ b/doc/man3/X509_get0_sm2_id.pod
|
||||||
|
@@ -2,20 +2,24 @@
|
||||||
|
|
||||||
|
=head1 NAME
|
||||||
|
|
||||||
|
-X509_get0_sm2_id, X509_set_sm2_id - get or set SM2 ID for certificate operations
|
||||||
|
+X509_get0_sm2_id, X509_set0_sm2_id - get or set SM2 ID for certificate operations
|
||||||
|
|
||||||
|
=head1 SYNOPSIS
|
||||||
|
|
||||||
|
#include <openssl/x509.h>
|
||||||
|
|
||||||
|
ASN1_OCTET_STRING *X509_get0_sm2_id(X509 *x);
|
||||||
|
- void X509_set_sm2_id(X509 *x, ASN1_OCTET_STRING *sm2_id);
|
||||||
|
+ void X509_set0_sm2_id(X509 *x, ASN1_OCTET_STRING *sm2_id);
|
||||||
|
|
||||||
|
=head1 DESCRIPTION
|
||||||
|
|
||||||
|
X509_get0_sm2_id() gets the ID value of an SM2 certificate B<x> by returning an
|
||||||
|
B<ASN1_OCTET_STRING> object which should not be freed by the caller.
|
||||||
|
-X509_set_sm2_id() sets the B<sm2_id> value to an SM2 certificate B<x>.
|
||||||
|
+
|
||||||
|
+X509_set0_sm2_id() sets the B<sm2_id> value to an SM2 certificate B<x>. Calling
|
||||||
|
+this function transfers the memory management of the value to the X509 object,
|
||||||
|
+and therefore the value that has been passed in should not be freed by the
|
||||||
|
+caller after this function has been called.
|
||||||
|
|
||||||
|
=head1 NOTES
|
||||||
|
|
||||||
|
@@ -25,7 +29,7 @@ ability to set and retrieve the SM2 ID value.
|
||||||
|
|
||||||
|
=head1 RETURN VALUES
|
||||||
|
|
||||||
|
-X509_set_sm2_id() does not return a value.
|
||||||
|
+X509_set0_sm2_id() does not return a value.
|
||||||
|
|
||||||
|
=head1 SEE ALSO
|
||||||
|
|
||||||
|
diff --git a/include/crypto/x509.h b/include/crypto/x509.h
|
||||||
|
index 418c427..5c314a8 100644
|
||||||
|
--- a/include/crypto/x509.h
|
||||||
|
+++ b/include/crypto/x509.h
|
||||||
|
@@ -186,7 +186,7 @@ struct x509_st {
|
||||||
|
CRYPTO_RWLOCK *lock;
|
||||||
|
volatile int ex_cached;
|
||||||
|
# ifndef OPENSSL_NO_SM2
|
||||||
|
- ASN1_OCTET_STRING sm2_id;
|
||||||
|
+ ASN1_OCTET_STRING *sm2_id;
|
||||||
|
# endif
|
||||||
|
} /* X509 */ ;
|
||||||
|
|
||||||
|
diff --git a/include/openssl/x509.h b/include/openssl/x509.h
|
||||||
|
index 5c88251..a02cf50 100644
|
||||||
|
--- a/include/openssl/x509.h
|
||||||
|
+++ b/include/openssl/x509.h
|
||||||
|
@@ -574,7 +574,7 @@ void X509_get0_signature(const ASN1_BIT_STRING **psig,
|
||||||
|
int X509_get_signature_nid(const X509 *x);
|
||||||
|
|
||||||
|
# ifndef OPENSSL_NO_SM2
|
||||||
|
-void X509_set_sm2_id(X509 *x, ASN1_OCTET_STRING *sm2_id);
|
||||||
|
+void X509_set0_sm2_id(X509 *x, ASN1_OCTET_STRING *sm2_id);
|
||||||
|
ASN1_OCTET_STRING *X509_get0_sm2_id(X509 *x);
|
||||||
|
# endif
|
||||||
|
|
||||||
|
diff --git a/test/verify_extra_test.c b/test/verify_extra_test.c
|
||||||
|
index b9959e0..763ea4f 100644
|
||||||
|
--- a/test/verify_extra_test.c
|
||||||
|
+++ b/test/verify_extra_test.c
|
||||||
|
@@ -8,6 +8,7 @@
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
+#include <string.h>
|
||||||
|
#include <openssl/crypto.h>
|
||||||
|
#include <openssl/bio.h>
|
||||||
|
#include <openssl/x509.h>
|
||||||
|
@@ -231,6 +232,48 @@ static int test_self_signed_bad(void)
|
||||||
|
return test_self_signed(bad_f, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
+#ifndef OPENSSL_NO_SM2
|
||||||
|
+static int test_sm2_id(void)
|
||||||
|
+{
|
||||||
|
+ /* we only need an X509 structure, no matter if it's a real SM2 cert */
|
||||||
|
+ X509 *x = NULL;
|
||||||
|
+ BIO *bio = NULL;
|
||||||
|
+ int ret = 0;
|
||||||
|
+ ASN1_OCTET_STRING *v = NULL, *v2 = NULL;
|
||||||
|
+ char *sm2id = "this is an ID";
|
||||||
|
+
|
||||||
|
+ bio = BIO_new_file(bad_f, "r");
|
||||||
|
+ if (bio == NULL)
|
||||||
|
+ goto err;
|
||||||
|
+
|
||||||
|
+ x = PEM_read_bio_X509(bio, NULL, 0, NULL);
|
||||||
|
+ if (x == NULL)
|
||||||
|
+ goto err;
|
||||||
|
+
|
||||||
|
+ v = ASN1_OCTET_STRING_new();
|
||||||
|
+ if (v == NULL)
|
||||||
|
+ goto err;
|
||||||
|
+
|
||||||
|
+ if (!ASN1_OCTET_STRING_set(v, (unsigned char *)sm2id, (int)strlen(sm2id))) {
|
||||||
|
+ ASN1_OCTET_STRING_free(v);
|
||||||
|
+ goto err;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ X509_set0_sm2_id(x, v);
|
||||||
|
+
|
||||||
|
+ v2 = X509_get0_sm2_id(x);
|
||||||
|
+ if (!TEST_ptr(v2)
|
||||||
|
+ || !TEST_int_eq(ASN1_OCTET_STRING_cmp(v, v2), 0))
|
||||||
|
+ goto err;
|
||||||
|
+
|
||||||
|
+ ret = 1;
|
||||||
|
+ err:
|
||||||
|
+ X509_free(x);
|
||||||
|
+ BIO_free(bio);
|
||||||
|
+ return ret;
|
||||||
|
+}
|
||||||
|
+#endif
|
||||||
|
+
|
||||||
|
int setup_tests(void)
|
||||||
|
{
|
||||||
|
if (!TEST_ptr(roots_f = test_get_argument(0))
|
||||||
|
@@ -245,5 +288,8 @@ int setup_tests(void)
|
||||||
|
ADD_TEST(test_store_ctx);
|
||||||
|
ADD_TEST(test_self_signed_good);
|
||||||
|
ADD_TEST(test_self_signed_bad);
|
||||||
|
+#ifndef OPENSSL_NO_SM2
|
||||||
|
+ ADD_TEST(test_sm2_id);
|
||||||
|
+#endif
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
diff --git a/util/libcrypto.num b/util/libcrypto.num
|
||||||
|
index 233d1c7..d7abe91 100644
|
||||||
|
--- a/util/libcrypto.num
|
||||||
|
+++ b/util/libcrypto.num
|
||||||
|
@@ -4626,5 +4626,5 @@ FIPS_drbg_get_strength 6379 1_1_0g EXIST::FUNCTION:
|
||||||
|
FIPS_rand_strength 6380 1_1_0g EXIST::FUNCTION:
|
||||||
|
FIPS_drbg_get_blocklength 6381 1_1_0g EXIST::FUNCTION:
|
||||||
|
FIPS_drbg_init 6382 1_1_0g EXIST::FUNCTION:
|
||||||
|
-X509_set_sm2_id 6383 1_1_1m EXIST::FUNCTION:SM2
|
||||||
|
+X509_set0_sm2_id 6383 1_1_1m EXIST::FUNCTION:SM2
|
||||||
|
X509_get0_sm2_id 6384 1_1_1m EXIST::FUNCTION:SM2
|
||||||
|
--
|
||||||
|
2.20.1 (Apple Git-117)
|
||||||
|
|
||||||
@ -0,0 +1,30 @@
|
|||||||
|
From f0dd65378296590d87250bf2130bad567483ee3d Mon Sep 17 00:00:00 2001
|
||||||
|
From: Matt Caswell <matt@openssl.org>
|
||||||
|
Date: Wed, 3 Apr 2019 09:44:41 +0100
|
||||||
|
Subject: [PATCH 08/15] Skip the correct number of tests if SM2 is disabled
|
||||||
|
|
||||||
|
Fixes no-sm2 (and also no-sm3 and no-ec)
|
||||||
|
|
||||||
|
Reviewed-by: Richard Levitte <levitte@openssl.org>
|
||||||
|
Reviewed-by: Paul Dale <paul.dale@oracle.com>
|
||||||
|
(Merged from https://github.com/openssl/openssl/pull/8650)
|
||||||
|
---
|
||||||
|
test/recipes/25-test_verify.t | 2 +-
|
||||||
|
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||||
|
|
||||||
|
diff --git a/test/recipes/25-test_verify.t b/test/recipes/25-test_verify.t
|
||||||
|
index b340833..d254bd8 100644
|
||||||
|
--- a/test/recipes/25-test_verify.t
|
||||||
|
+++ b/test/recipes/25-test_verify.t
|
||||||
|
@@ -411,7 +411,7 @@ SKIP: {
|
||||||
|
}
|
||||||
|
|
||||||
|
SKIP: {
|
||||||
|
- skip "SM2 is not supported by this OpenSSL build", 1
|
||||||
|
+ skip "SM2 is not supported by this OpenSSL build", 2
|
||||||
|
if disabled("sm2");
|
||||||
|
|
||||||
|
# Test '-sm2-id' and '-sm2-hex-id' option
|
||||||
|
--
|
||||||
|
2.20.1 (Apple Git-117)
|
||||||
|
|
||||||
1189
Backport-Support-SM2-certificate-signing.patch
Normal file
1189
Backport-Support-SM2-certificate-signing.patch
Normal file
File diff suppressed because it is too large
Load Diff
579
Backport-Support-SM2-certificate-verification.patch
Normal file
579
Backport-Support-SM2-certificate-verification.patch
Normal file
@ -0,0 +1,579 @@
|
|||||||
|
From 7d86ccd1282aeff8f6d564c5d37625ffcc048f2d Mon Sep 17 00:00:00 2001
|
||||||
|
From: =?UTF-8?q?=E6=9D=A8=E6=B4=8B?= <yang.yang@baishancloud.com>
|
||||||
|
Date: Fri, 26 Oct 2018 21:34:08 +0800
|
||||||
|
Subject: [PATCH 03/15] Support SM2 certificate verification
|
||||||
|
|
||||||
|
Reviewed-by: Tim Hudson <tjh@openssl.org>
|
||||||
|
(Merged from https://github.com/openssl/openssl/pull/8321)
|
||||||
|
---
|
||||||
|
apps/verify.c | 45 +++++++++++++--
|
||||||
|
crypto/asn1/a_verify.c | 3 +-
|
||||||
|
crypto/err/openssl.txt | 2 +
|
||||||
|
crypto/objects/obj_dat.h | 17 ++++--
|
||||||
|
crypto/objects/obj_mac.num | 1 +
|
||||||
|
crypto/objects/obj_xref.h | 4 +-
|
||||||
|
crypto/objects/obj_xref.txt | 2 +
|
||||||
|
crypto/objects/objects.txt | 2 +
|
||||||
|
crypto/x509/x509_err.c | 2 +
|
||||||
|
crypto/x509/x_all.c | 110 ++++++++++++++++++++++++++++++++++++
|
||||||
|
crypto/x509/x_x509.c | 12 ++++
|
||||||
|
fuzz/oids.txt | 1 +
|
||||||
|
include/crypto/x509.h | 5 +-
|
||||||
|
include/openssl/obj_mac.h | 7 ++-
|
||||||
|
include/openssl/x509.h | 3 +
|
||||||
|
include/openssl/x509err.h | 2 +
|
||||||
|
util/libcrypto.num | 2 +
|
||||||
|
17 files changed, 204 insertions(+), 16 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/apps/verify.c b/apps/verify.c
|
||||||
|
index 1f93856..09b31cf 100644
|
||||||
|
--- a/apps/verify.c
|
||||||
|
+++ b/apps/verify.c
|
||||||
|
@@ -21,7 +21,8 @@
|
||||||
|
static int cb(int ok, X509_STORE_CTX *ctx);
|
||||||
|
static int check(X509_STORE *ctx, const char *file,
|
||||||
|
STACK_OF(X509) *uchain, STACK_OF(X509) *tchain,
|
||||||
|
- STACK_OF(X509_CRL) *crls, int show_chain);
|
||||||
|
+ STACK_OF(X509_CRL) *crls, int show_chain,
|
||||||
|
+ unsigned char *sm2id, size_t sm2idlen);
|
||||||
|
static int v_verbose = 0, vflags = 0;
|
||||||
|
|
||||||
|
typedef enum OPTION_choice {
|
||||||
|
@@ -29,7 +30,7 @@ typedef enum OPTION_choice {
|
||||||
|
OPT_ENGINE, OPT_CAPATH, OPT_CAFILE, OPT_NOCAPATH, OPT_NOCAFILE,
|
||||||
|
OPT_UNTRUSTED, OPT_TRUSTED, OPT_CRLFILE, OPT_CRL_DOWNLOAD, OPT_SHOW_CHAIN,
|
||||||
|
OPT_V_ENUM, OPT_NAMEOPT,
|
||||||
|
- OPT_VERBOSE
|
||||||
|
+ OPT_VERBOSE, OPT_SM2ID, OPT_SM2HEXID
|
||||||
|
} OPTION_CHOICE;
|
||||||
|
|
||||||
|
const OPTIONS verify_options[] = {
|
||||||
|
@@ -56,6 +57,12 @@ const OPTIONS verify_options[] = {
|
||||||
|
OPT_V_OPTIONS,
|
||||||
|
#ifndef OPENSSL_NO_ENGINE
|
||||||
|
{"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"},
|
||||||
|
+#endif
|
||||||
|
+#ifndef OPENSSL_NO_SM2
|
||||||
|
+ {"sm2-id", OPT_SM2ID, 's',
|
||||||
|
+ "Specify an ID string to verify an SM2 certificate"},
|
||||||
|
+ {"sm2-hex-id", OPT_SM2HEXID, 's',
|
||||||
|
+ "Specify a hex ID string to verify an SM2 certificate"},
|
||||||
|
#endif
|
||||||
|
{NULL}
|
||||||
|
};
|
||||||
|
@@ -71,6 +78,8 @@ int verify_main(int argc, char **argv)
|
||||||
|
int noCApath = 0, noCAfile = 0;
|
||||||
|
int vpmtouched = 0, crl_download = 0, show_chain = 0, i = 0, ret = 1;
|
||||||
|
OPTION_CHOICE o;
|
||||||
|
+ unsigned char *sm2_id = NULL;
|
||||||
|
+ size_t sm2_idlen = 0;
|
||||||
|
|
||||||
|
if ((vpm = X509_VERIFY_PARAM_new()) == NULL)
|
||||||
|
goto end;
|
||||||
|
@@ -158,6 +167,19 @@ int verify_main(int argc, char **argv)
|
||||||
|
case OPT_VERBOSE:
|
||||||
|
v_verbose = 1;
|
||||||
|
break;
|
||||||
|
+ case OPT_SM2ID:
|
||||||
|
+ /* we assume the input is not a hex string */
|
||||||
|
+ sm2_id = (unsigned char *)opt_arg();
|
||||||
|
+ sm2_idlen = strlen((const char *)sm2_id);
|
||||||
|
+ break;
|
||||||
|
+ case OPT_SM2HEXID:
|
||||||
|
+ /* try to parse the input as hex string first */
|
||||||
|
+ sm2_id = OPENSSL_hexstr2buf(opt_arg(), (long *)&sm2_idlen);
|
||||||
|
+ if (sm2_id == NULL) {
|
||||||
|
+ BIO_printf(bio_err, "Invalid hex string input\n");
|
||||||
|
+ goto end;
|
||||||
|
+ }
|
||||||
|
+ break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
argc = opt_num_rest();
|
||||||
|
@@ -183,12 +205,13 @@ int verify_main(int argc, char **argv)
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
if (argc < 1) {
|
||||||
|
- if (check(store, NULL, untrusted, trusted, crls, show_chain) != 1)
|
||||||
|
+ if (check(store, NULL, untrusted, trusted, crls, show_chain,
|
||||||
|
+ sm2_id, sm2_idlen) != 1)
|
||||||
|
ret = -1;
|
||||||
|
} else {
|
||||||
|
for (i = 0; i < argc; i++)
|
||||||
|
if (check(store, argv[i], untrusted, trusted, crls,
|
||||||
|
- show_chain) != 1)
|
||||||
|
+ show_chain, sm2_id, sm2_idlen) != 1)
|
||||||
|
ret = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@@ -204,7 +227,8 @@ int verify_main(int argc, char **argv)
|
||||||
|
|
||||||
|
static int check(X509_STORE *ctx, const char *file,
|
||||||
|
STACK_OF(X509) *uchain, STACK_OF(X509) *tchain,
|
||||||
|
- STACK_OF(X509_CRL) *crls, int show_chain)
|
||||||
|
+ STACK_OF(X509_CRL) *crls, int show_chain,
|
||||||
|
+ unsigned char *sm2id, size_t sm2idlen)
|
||||||
|
{
|
||||||
|
X509 *x = NULL;
|
||||||
|
int i = 0, ret = 0;
|
||||||
|
@@ -216,6 +240,17 @@ static int check(X509_STORE *ctx, const char *file,
|
||||||
|
if (x == NULL)
|
||||||
|
goto end;
|
||||||
|
|
||||||
|
+ if (sm2id != NULL) {
|
||||||
|
+#ifndef OPENSSL_NO_SM2
|
||||||
|
+ ASN1_OCTET_STRING v;
|
||||||
|
+
|
||||||
|
+ v.data = sm2id;
|
||||||
|
+ v.length = sm2idlen;
|
||||||
|
+
|
||||||
|
+ X509_set_sm2_id(x, &v);
|
||||||
|
+#endif
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
csc = X509_STORE_CTX_new();
|
||||||
|
if (csc == NULL) {
|
||||||
|
printf("error %s: X.509 store context allocation failed\n",
|
||||||
|
diff --git a/crypto/asn1/a_verify.c b/crypto/asn1/a_verify.c
|
||||||
|
index 4b5f542..f543aa1 100644
|
||||||
|
--- a/crypto/asn1/a_verify.c
|
||||||
|
+++ b/crypto/asn1/a_verify.c
|
||||||
|
@@ -94,7 +94,7 @@ int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a,
|
||||||
|
int mdnid, pknid;
|
||||||
|
size_t inll = 0;
|
||||||
|
|
||||||
|
- if (!pkey) {
|
||||||
|
+ if (pkey == NULL) {
|
||||||
|
ASN1err(ASN1_F_ASN1_ITEM_VERIFY, ERR_R_PASSED_NULL_PARAMETER);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
@@ -150,7 +150,6 @@ int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a,
|
||||||
|
ret = 0;
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
-
|
||||||
|
}
|
||||||
|
|
||||||
|
inl = ASN1_item_i2d(asn, &buf_in, it);
|
||||||
|
diff --git a/crypto/err/openssl.txt b/crypto/err/openssl.txt
|
||||||
|
index 902e97b..5e71e65 100644
|
||||||
|
--- a/crypto/err/openssl.txt
|
||||||
|
+++ b/crypto/err/openssl.txt
|
||||||
|
@@ -1766,8 +1766,10 @@ X509_F_X509_STORE_NEW:158:X509_STORE_new
|
||||||
|
X509_F_X509_TO_X509_REQ:126:X509_to_X509_REQ
|
||||||
|
X509_F_X509_TRUST_ADD:133:X509_TRUST_add
|
||||||
|
X509_F_X509_TRUST_SET:141:X509_TRUST_set
|
||||||
|
+X509_F_X509_VERIFY:161:X509_verify
|
||||||
|
X509_F_X509_VERIFY_CERT:127:X509_verify_cert
|
||||||
|
X509_F_X509_VERIFY_PARAM_NEW:159:X509_VERIFY_PARAM_new
|
||||||
|
+X509_F_X509_VERIFY_SM2:162:x509_verify_sm2
|
||||||
|
|
||||||
|
#Reason codes
|
||||||
|
ASN1_R_ADDING_OBJECT:171:adding object
|
||||||
|
diff --git a/crypto/objects/obj_dat.h b/crypto/objects/obj_dat.h
|
||||||
|
index 24b49a2..eb4cce4 100644
|
||||||
|
--- a/crypto/objects/obj_dat.h
|
||||||
|
+++ b/crypto/objects/obj_dat.h
|
||||||
|
@@ -2,7 +2,7 @@
|
||||||
|
* WARNING: do not edit!
|
||||||
|
* Generated by crypto/objects/obj_dat.pl
|
||||||
|
*
|
||||||
|
- * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
|
||||||
|
+ * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
|
||||||
|
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||||
|
* this file except in compliance with the License. You can obtain a copy
|
||||||
|
* in the file LICENSE in the source distribution or at
|
||||||
|
@@ -10,7 +10,7 @@
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Serialized OID's */
|
||||||
|
-static const unsigned char so[7762] = {
|
||||||
|
+static const unsigned char so[7770] = {
|
||||||
|
0x2A,0x86,0x48,0x86,0xF7,0x0D, /* [ 0] OBJ_rsadsi */
|
||||||
|
0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01, /* [ 6] OBJ_pkcs */
|
||||||
|
0x2A,0x86,0x48,0x86,0xF7,0x0D,0x02,0x02, /* [ 13] OBJ_md2 */
|
||||||
|
@@ -1076,9 +1076,10 @@ static const unsigned char so[7762] = {
|
||||||
|
0x2A,0x85,0x03,0x07,0x01,0x02,0x01,0x01,0x04, /* [ 7736] OBJ_id_tc26_gost_3410_2012_256_paramSetD */
|
||||||
|
0x2A,0x86,0x48,0x86,0xF7,0x0D,0x02,0x0C, /* [ 7745] OBJ_hmacWithSHA512_224 */
|
||||||
|
0x2A,0x86,0x48,0x86,0xF7,0x0D,0x02,0x0D, /* [ 7753] OBJ_hmacWithSHA512_256 */
|
||||||
|
+ 0x2A,0x81,0x1C,0xCF,0x55,0x01,0x83,0x75, /* [ 7761] OBJ_SM2_with_SM3 */
|
||||||
|
};
|
||||||
|
|
||||||
|
-#define NUM_NID 1195
|
||||||
|
+#define NUM_NID 1196
|
||||||
|
static const ASN1_OBJECT nid_objs[NUM_NID] = {
|
||||||
|
{"UNDEF", "undefined", NID_undef},
|
||||||
|
{"rsadsi", "RSA Data Security, Inc.", NID_rsadsi, 6, &so[0]},
|
||||||
|
@@ -2275,9 +2276,10 @@ static const ASN1_OBJECT nid_objs[NUM_NID] = {
|
||||||
|
{"magma-mac", "magma-mac", NID_magma_mac},
|
||||||
|
{"hmacWithSHA512-224", "hmacWithSHA512-224", NID_hmacWithSHA512_224, 8, &so[7745]},
|
||||||
|
{"hmacWithSHA512-256", "hmacWithSHA512-256", NID_hmacWithSHA512_256, 8, &so[7753]},
|
||||||
|
+ {"SM2-SM3", "SM2-with-SM3", NID_SM2_with_SM3, 8, &so[7761]},
|
||||||
|
};
|
||||||
|
|
||||||
|
-#define NUM_SN 1186
|
||||||
|
+#define NUM_SN 1187
|
||||||
|
static const unsigned int sn_objs[NUM_SN] = {
|
||||||
|
364, /* "AD_DVCS" */
|
||||||
|
419, /* "AES-128-CBC" */
|
||||||
|
@@ -2543,6 +2545,7 @@ static const unsigned int sn_objs[NUM_SN] = {
|
||||||
|
1100, /* "SHAKE128" */
|
||||||
|
1101, /* "SHAKE256" */
|
||||||
|
1172, /* "SM2" */
|
||||||
|
+ 1195, /* "SM2-SM3" */
|
||||||
|
1143, /* "SM3" */
|
||||||
|
1134, /* "SM4-CBC" */
|
||||||
|
1137, /* "SM4-CFB" */
|
||||||
|
@@ -3467,7 +3470,7 @@ static const unsigned int sn_objs[NUM_SN] = {
|
||||||
|
1093, /* "x509ExtAdmission" */
|
||||||
|
};
|
||||||
|
|
||||||
|
-#define NUM_LN 1186
|
||||||
|
+#define NUM_LN 1187
|
||||||
|
static const unsigned int ln_objs[NUM_LN] = {
|
||||||
|
363, /* "AD Time Stamping" */
|
||||||
|
405, /* "ANSI X9.62" */
|
||||||
|
@@ -3623,6 +3626,7 @@ static const unsigned int ln_objs[NUM_LN] = {
|
||||||
|
1119, /* "RSA-SHA3-512" */
|
||||||
|
188, /* "S/MIME" */
|
||||||
|
167, /* "S/MIME Capabilities" */
|
||||||
|
+ 1195, /* "SM2-with-SM3" */
|
||||||
|
1006, /* "SNILS" */
|
||||||
|
387, /* "SNMPv2" */
|
||||||
|
1025, /* "SSH Client" */
|
||||||
|
@@ -4657,7 +4661,7 @@ static const unsigned int ln_objs[NUM_LN] = {
|
||||||
|
125, /* "zlib compression" */
|
||||||
|
};
|
||||||
|
|
||||||
|
-#define NUM_OBJ 1071
|
||||||
|
+#define NUM_OBJ 1072
|
||||||
|
static const unsigned int obj_objs[NUM_OBJ] = {
|
||||||
|
0, /* OBJ_undef 0 */
|
||||||
|
181, /* OBJ_iso 1 */
|
||||||
|
@@ -5126,6 +5130,7 @@ static const unsigned int obj_objs[NUM_OBJ] = {
|
||||||
|
1139, /* OBJ_sm4_ctr 1 2 156 10197 1 104 7 */
|
||||||
|
1172, /* OBJ_sm2 1 2 156 10197 1 301 */
|
||||||
|
1143, /* OBJ_sm3 1 2 156 10197 1 401 */
|
||||||
|
+ 1195, /* OBJ_SM2_with_SM3 1 2 156 10197 1 501 */
|
||||||
|
1144, /* OBJ_sm3WithRSAEncryption 1 2 156 10197 1 504 */
|
||||||
|
776, /* OBJ_seed_ecb 1 2 410 200004 1 3 */
|
||||||
|
777, /* OBJ_seed_cbc 1 2 410 200004 1 4 */
|
||||||
|
diff --git a/crypto/objects/obj_mac.num b/crypto/objects/obj_mac.num
|
||||||
|
index 1b6a9c6..8b797b0 100644
|
||||||
|
--- a/crypto/objects/obj_mac.num
|
||||||
|
+++ b/crypto/objects/obj_mac.num
|
||||||
|
@@ -1192,3 +1192,4 @@ magma_cfb 1191
|
||||||
|
magma_mac 1192
|
||||||
|
hmacWithSHA512_224 1193
|
||||||
|
hmacWithSHA512_256 1194
|
||||||
|
+SM2_with_SM3 1195
|
||||||
|
diff --git a/crypto/objects/obj_xref.h b/crypto/objects/obj_xref.h
|
||||||
|
index 5c3561a..1acfcde 100644
|
||||||
|
--- a/crypto/objects/obj_xref.h
|
||||||
|
+++ b/crypto/objects/obj_xref.h
|
||||||
|
@@ -2,7 +2,7 @@
|
||||||
|
* WARNING: do not edit!
|
||||||
|
* Generated by objxref.pl
|
||||||
|
*
|
||||||
|
- * Copyright 1998-2021 The OpenSSL Project Authors. All Rights Reserved.
|
||||||
|
+ * Copyright 1998-2022 The OpenSSL Project Authors. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||||
|
* this file except in compliance with the License. You can obtain a copy
|
||||||
|
@@ -79,6 +79,7 @@ static const nid_triple sigoid_srt[] = {
|
||||||
|
{NID_RSA_SHA3_256, NID_sha3_256, NID_rsaEncryption},
|
||||||
|
{NID_RSA_SHA3_384, NID_sha3_384, NID_rsaEncryption},
|
||||||
|
{NID_RSA_SHA3_512, NID_sha3_512, NID_rsaEncryption},
|
||||||
|
+ {NID_SM2_with_SM3, NID_sm3, NID_sm2},
|
||||||
|
};
|
||||||
|
|
||||||
|
static const nid_triple *const sigoid_srt_xref[] = {
|
||||||
|
@@ -125,4 +126,5 @@ static const nid_triple *const sigoid_srt_xref[] = {
|
||||||
|
&sigoid_srt[45],
|
||||||
|
&sigoid_srt[46],
|
||||||
|
&sigoid_srt[47],
|
||||||
|
+ &sigoid_srt[48],
|
||||||
|
};
|
||||||
|
diff --git a/crypto/objects/obj_xref.txt b/crypto/objects/obj_xref.txt
|
||||||
|
index ca3e744..f3dd8ed 100644
|
||||||
|
--- a/crypto/objects/obj_xref.txt
|
||||||
|
+++ b/crypto/objects/obj_xref.txt
|
||||||
|
@@ -64,3 +64,5 @@ dhSinglePass_cofactorDH_sha224kdf_scheme sha224 dh_cofactor_kdf
|
||||||
|
dhSinglePass_cofactorDH_sha256kdf_scheme sha256 dh_cofactor_kdf
|
||||||
|
dhSinglePass_cofactorDH_sha384kdf_scheme sha384 dh_cofactor_kdf
|
||||||
|
dhSinglePass_cofactorDH_sha512kdf_scheme sha512 dh_cofactor_kdf
|
||||||
|
+
|
||||||
|
+SM2_with_SM3 sm3 sm2
|
||||||
|
diff --git a/crypto/objects/objects.txt b/crypto/objects/objects.txt
|
||||||
|
index c49d4c5..be9da47 100644
|
||||||
|
--- a/crypto/objects/objects.txt
|
||||||
|
+++ b/crypto/objects/objects.txt
|
||||||
|
@@ -385,6 +385,8 @@ sm-scheme 301 : SM2 : sm2
|
||||||
|
sm-scheme 401 : SM3 : sm3
|
||||||
|
sm-scheme 504 : RSA-SM3 : sm3WithRSAEncryption
|
||||||
|
|
||||||
|
+sm-scheme 501 : SM2-SM3 : SM2-with-SM3
|
||||||
|
+
|
||||||
|
# From RFC4231
|
||||||
|
rsadsi 2 8 : : hmacWithSHA224
|
||||||
|
rsadsi 2 9 : : hmacWithSHA256
|
||||||
|
diff --git a/crypto/x509/x509_err.c b/crypto/x509/x509_err.c
|
||||||
|
index bdd1e67..c91ad7c 100644
|
||||||
|
--- a/crypto/x509/x509_err.c
|
||||||
|
+++ b/crypto/x509/x509_err.c
|
||||||
|
@@ -105,9 +105,11 @@ static const ERR_STRING_DATA X509_str_functs[] = {
|
||||||
|
{ERR_PACK(ERR_LIB_X509, X509_F_X509_TO_X509_REQ, 0), "X509_to_X509_REQ"},
|
||||||
|
{ERR_PACK(ERR_LIB_X509, X509_F_X509_TRUST_ADD, 0), "X509_TRUST_add"},
|
||||||
|
{ERR_PACK(ERR_LIB_X509, X509_F_X509_TRUST_SET, 0), "X509_TRUST_set"},
|
||||||
|
+ {ERR_PACK(ERR_LIB_X509, X509_F_X509_VERIFY, 0), "X509_verify"},
|
||||||
|
{ERR_PACK(ERR_LIB_X509, X509_F_X509_VERIFY_CERT, 0), "X509_verify_cert"},
|
||||||
|
{ERR_PACK(ERR_LIB_X509, X509_F_X509_VERIFY_PARAM_NEW, 0),
|
||||||
|
"X509_VERIFY_PARAM_new"},
|
||||||
|
+ {ERR_PACK(ERR_LIB_X509, X509_F_X509_VERIFY_SM2, 0), "x509_verify_sm2"},
|
||||||
|
{0, NULL}
|
||||||
|
};
|
||||||
|
|
||||||
|
diff --git a/crypto/x509/x_all.c b/crypto/x509/x_all.c
|
||||||
|
index a4e9cda..60a2892 100644
|
||||||
|
--- a/crypto/x509/x_all.c
|
||||||
|
+++ b/crypto/x509/x_all.c
|
||||||
|
@@ -19,10 +19,120 @@
|
||||||
|
#include <openssl/dsa.h>
|
||||||
|
#include <openssl/x509v3.h>
|
||||||
|
|
||||||
|
+#ifndef OPENSSL_NO_SM2
|
||||||
|
+
|
||||||
|
+# include "crypto/asn1.h"
|
||||||
|
+# include "crypto/evp.h"
|
||||||
|
+
|
||||||
|
+static int x509_verify_sm2(X509 *x, EVP_PKEY *pkey, int mdnid, int pknid)
|
||||||
|
+{
|
||||||
|
+ EVP_MD_CTX *ctx = NULL;
|
||||||
|
+ unsigned char *buf_in = NULL;
|
||||||
|
+ int ret = -1, inl = 0;
|
||||||
|
+ size_t inll = 0;
|
||||||
|
+ EVP_PKEY_CTX *pctx = NULL;
|
||||||
|
+ const EVP_MD *type = EVP_get_digestbynid(mdnid);
|
||||||
|
+
|
||||||
|
+ if (type == NULL) {
|
||||||
|
+ X509err(X509_F_X509_VERIFY_SM2,
|
||||||
|
+ ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM);
|
||||||
|
+ goto err;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ if (pkey == NULL) {
|
||||||
|
+ X509err(X509_F_X509_VERIFY_SM2, ERR_R_PASSED_NULL_PARAMETER);
|
||||||
|
+ return -1;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ if (x->signature.type == V_ASN1_BIT_STRING && x->signature.flags & 0x7) {
|
||||||
|
+ X509err(X509_F_X509_VERIFY_SM2, ASN1_R_INVALID_BIT_STRING_BITS_LEFT);
|
||||||
|
+ return -1;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ ctx = EVP_MD_CTX_new();
|
||||||
|
+ if (ctx == NULL) {
|
||||||
|
+ X509err(X509_F_X509_VERIFY_SM2, ERR_R_MALLOC_FAILURE);
|
||||||
|
+ goto err;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ /* Check public key OID matches public key type */
|
||||||
|
+ if (EVP_PKEY_type(pknid) != pkey->ameth->pkey_id) {
|
||||||
|
+ X509err(X509_F_X509_VERIFY_SM2, ASN1_R_WRONG_PUBLIC_KEY_TYPE);
|
||||||
|
+ goto err;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ if (!EVP_PKEY_set_alias_type(pkey, EVP_PKEY_SM2)) {
|
||||||
|
+ X509err(X509_F_X509_VERIFY_SM2, ERR_R_EVP_LIB);
|
||||||
|
+ ret = 0;
|
||||||
|
+ goto err;
|
||||||
|
+ }
|
||||||
|
+ pctx = EVP_PKEY_CTX_new(pkey, NULL);
|
||||||
|
+ if (pctx == NULL) {
|
||||||
|
+ X509err(X509_F_X509_VERIFY_SM2, ERR_R_EVP_LIB);
|
||||||
|
+ ret = 0;
|
||||||
|
+ goto err;
|
||||||
|
+ }
|
||||||
|
+ if (EVP_PKEY_CTX_set1_id(pctx, x->sm2_id.data, x->sm2_id.length) != 1) {
|
||||||
|
+ X509err(X509_F_X509_VERIFY_SM2, ERR_R_EVP_LIB);
|
||||||
|
+ ret = 0;
|
||||||
|
+ goto err;
|
||||||
|
+ }
|
||||||
|
+ EVP_MD_CTX_set_pkey_ctx(ctx, pctx);
|
||||||
|
+
|
||||||
|
+ if (!EVP_DigestVerifyInit(ctx, NULL, type, NULL, pkey)) {
|
||||||
|
+ X509err(X509_F_X509_VERIFY_SM2, ERR_R_EVP_LIB);
|
||||||
|
+ ret = 0;
|
||||||
|
+ goto err;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ inl = ASN1_item_i2d((ASN1_VALUE *)&x->cert_info, &buf_in,
|
||||||
|
+ ASN1_ITEM_rptr(X509_CINF));
|
||||||
|
+ if (inl <= 0) {
|
||||||
|
+ X509err(X509_F_X509_VERIFY_SM2, ERR_R_INTERNAL_ERROR);
|
||||||
|
+ goto err;
|
||||||
|
+ }
|
||||||
|
+ if (buf_in == NULL) {
|
||||||
|
+ X509err(X509_F_X509_VERIFY_SM2, ERR_R_MALLOC_FAILURE);
|
||||||
|
+ goto err;
|
||||||
|
+ }
|
||||||
|
+ inll = inl;
|
||||||
|
+
|
||||||
|
+ ret = EVP_DigestVerify(ctx, x->signature.data,
|
||||||
|
+ (size_t)x->signature.length, buf_in, inl);
|
||||||
|
+ if (ret <= 0) {
|
||||||
|
+ X509err(X509_F_X509_VERIFY_SM2, ERR_R_EVP_LIB);
|
||||||
|
+ goto err;
|
||||||
|
+ }
|
||||||
|
+ ret = 1;
|
||||||
|
+ err:
|
||||||
|
+ OPENSSL_clear_free(buf_in, inll);
|
||||||
|
+ EVP_MD_CTX_free(ctx);
|
||||||
|
+ EVP_PKEY_CTX_free(pctx);
|
||||||
|
+ return ret;
|
||||||
|
+}
|
||||||
|
+#endif
|
||||||
|
+
|
||||||
|
int X509_verify(X509 *a, EVP_PKEY *r)
|
||||||
|
{
|
||||||
|
+#ifndef OPENSSL_NO_SM2
|
||||||
|
+ int mdnid, pknid;
|
||||||
|
+#endif
|
||||||
|
+
|
||||||
|
if (X509_ALGOR_cmp(&a->sig_alg, &a->cert_info.signature))
|
||||||
|
return 0;
|
||||||
|
+
|
||||||
|
+#ifndef OPENSSL_NO_SM2
|
||||||
|
+ /* Convert signature OID into digest and public key OIDs */
|
||||||
|
+ if (!OBJ_find_sigid_algs(OBJ_obj2nid(a->sig_alg.algorithm),
|
||||||
|
+ &mdnid, &pknid)) {
|
||||||
|
+ X509err(X509_F_X509_VERIFY, ASN1_R_UNKNOWN_SIGNATURE_ALGORITHM);
|
||||||
|
+ return 0;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ if (pknid == NID_sm2)
|
||||||
|
+ return x509_verify_sm2(a, r, mdnid, pknid);
|
||||||
|
+#endif
|
||||||
|
+
|
||||||
|
return (ASN1_item_verify(ASN1_ITEM_rptr(X509_CINF), &a->sig_alg,
|
||||||
|
&a->signature, &a->cert_info, r));
|
||||||
|
}
|
||||||
|
diff --git a/crypto/x509/x_x509.c b/crypto/x509/x_x509.c
|
||||||
|
index 7aa8b77..1beab78 100644
|
||||||
|
--- a/crypto/x509/x_x509.c
|
||||||
|
+++ b/crypto/x509/x_x509.c
|
||||||
|
@@ -245,3 +245,15 @@ int X509_get_signature_nid(const X509 *x)
|
||||||
|
{
|
||||||
|
return OBJ_obj2nid(x->sig_alg.algorithm);
|
||||||
|
}
|
||||||
|
+
|
||||||
|
+#ifndef OPENSSL_NO_SM2
|
||||||
|
+void X509_set_sm2_id(X509 *x, ASN1_OCTET_STRING *sm2_id)
|
||||||
|
+{
|
||||||
|
+ x->sm2_id = *sm2_id;
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+ASN1_OCTET_STRING *X509_get0_sm2_id(X509 *x)
|
||||||
|
+{
|
||||||
|
+ return &x->sm2_id;
|
||||||
|
+}
|
||||||
|
+#endif
|
||||||
|
diff --git a/fuzz/oids.txt b/fuzz/oids.txt
|
||||||
|
index eda55e4..8dfdea9 100644
|
||||||
|
--- a/fuzz/oids.txt
|
||||||
|
+++ b/fuzz/oids.txt
|
||||||
|
@@ -1063,3 +1063,4 @@ OBJ_id_tc26_gost_3410_2012_256_paramSetC="\x2A\x85\x03\x07\x01\x02\x01\x01\x03"
|
||||||
|
OBJ_id_tc26_gost_3410_2012_256_paramSetD="\x2A\x85\x03\x07\x01\x02\x01\x01\x04"
|
||||||
|
OBJ_hmacWithSHA512_224="\x2A\x86\x48\x86\xF7\x0D\x02\x0C"
|
||||||
|
OBJ_hmacWithSHA512_256="\x2A\x86\x48\x86\xF7\x0D\x02\x0D"
|
||||||
|
+OBJ_SM2_with_SM3="\x2A\x81\x1C\xCF\x55\x01\x83\x75"
|
||||||
|
diff --git a/include/crypto/x509.h b/include/crypto/x509.h
|
||||||
|
index 243ea74..418c427 100644
|
||||||
|
--- a/include/crypto/x509.h
|
||||||
|
+++ b/include/crypto/x509.h
|
||||||
|
@@ -177,7 +177,7 @@ struct x509_st {
|
||||||
|
STACK_OF(DIST_POINT) *crldp;
|
||||||
|
STACK_OF(GENERAL_NAME) *altname;
|
||||||
|
NAME_CONSTRAINTS *nc;
|
||||||
|
-#ifndef OPENSSL_NO_RFC3779
|
||||||
|
+# ifndef OPENSSL_NO_RFC3779
|
||||||
|
STACK_OF(IPAddressFamily) *rfc3779_addr;
|
||||||
|
struct ASIdentifiers_st *rfc3779_asid;
|
||||||
|
# endif
|
||||||
|
@@ -185,6 +185,9 @@ struct x509_st {
|
||||||
|
X509_CERT_AUX *aux;
|
||||||
|
CRYPTO_RWLOCK *lock;
|
||||||
|
volatile int ex_cached;
|
||||||
|
+# ifndef OPENSSL_NO_SM2
|
||||||
|
+ ASN1_OCTET_STRING sm2_id;
|
||||||
|
+# endif
|
||||||
|
} /* X509 */ ;
|
||||||
|
|
||||||
|
/*
|
||||||
|
diff --git a/include/openssl/obj_mac.h b/include/openssl/obj_mac.h
|
||||||
|
index eb812ed..9b125c1 100644
|
||||||
|
--- a/include/openssl/obj_mac.h
|
||||||
|
+++ b/include/openssl/obj_mac.h
|
||||||
|
@@ -2,7 +2,7 @@
|
||||||
|
* WARNING: do not edit!
|
||||||
|
* Generated by crypto/objects/objects.pl
|
||||||
|
*
|
||||||
|
- * Copyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved.
|
||||||
|
+ * Copyright 2000-2022 The OpenSSL Project Authors. All Rights Reserved.
|
||||||
|
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||||
|
* this file except in compliance with the License. You can obtain a copy
|
||||||
|
* in the file LICENSE in the source distribution or at
|
||||||
|
@@ -1179,6 +1179,11 @@
|
||||||
|
#define NID_sm3WithRSAEncryption 1144
|
||||||
|
#define OBJ_sm3WithRSAEncryption OBJ_sm_scheme,504L
|
||||||
|
|
||||||
|
+#define SN_SM2_with_SM3 "SM2-SM3"
|
||||||
|
+#define LN_SM2_with_SM3 "SM2-with-SM3"
|
||||||
|
+#define NID_SM2_with_SM3 1195
|
||||||
|
+#define OBJ_SM2_with_SM3 OBJ_sm_scheme,501L
|
||||||
|
+
|
||||||
|
#define LN_hmacWithSHA224 "hmacWithSHA224"
|
||||||
|
#define NID_hmacWithSHA224 798
|
||||||
|
#define OBJ_hmacWithSHA224 OBJ_rsadsi,2L,8L
|
||||||
|
diff --git a/include/openssl/x509.h b/include/openssl/x509.h
|
||||||
|
index 3ff86ec..5f17057 100644
|
||||||
|
--- a/include/openssl/x509.h
|
||||||
|
+++ b/include/openssl/x509.h
|
||||||
|
@@ -573,6 +573,9 @@ void X509_get0_signature(const ASN1_BIT_STRING **psig,
|
||||||
|
const X509_ALGOR **palg, const X509 *x);
|
||||||
|
int X509_get_signature_nid(const X509 *x);
|
||||||
|
|
||||||
|
+void X509_set_sm2_id(X509 *x, ASN1_OCTET_STRING *sm2_id);
|
||||||
|
+ASN1_OCTET_STRING *X509_get0_sm2_id(X509 *x);
|
||||||
|
+
|
||||||
|
int X509_trusted(const X509 *x);
|
||||||
|
int X509_alias_set1(X509 *x, const unsigned char *name, int len);
|
||||||
|
int X509_keyid_set1(X509 *x, const unsigned char *id, int len);
|
||||||
|
diff --git a/include/openssl/x509err.h b/include/openssl/x509err.h
|
||||||
|
index cd08673..06d75f0 100644
|
||||||
|
--- a/include/openssl/x509err.h
|
||||||
|
+++ b/include/openssl/x509err.h
|
||||||
|
@@ -81,8 +81,10 @@ int ERR_load_X509_strings(void);
|
||||||
|
# define X509_F_X509_TO_X509_REQ 126
|
||||||
|
# define X509_F_X509_TRUST_ADD 133
|
||||||
|
# define X509_F_X509_TRUST_SET 141
|
||||||
|
+# define X509_F_X509_VERIFY 161
|
||||||
|
# define X509_F_X509_VERIFY_CERT 127
|
||||||
|
# define X509_F_X509_VERIFY_PARAM_NEW 159
|
||||||
|
+# define X509_F_X509_VERIFY_SM2 162
|
||||||
|
|
||||||
|
/*
|
||||||
|
* X509 reason codes.
|
||||||
|
diff --git a/util/libcrypto.num b/util/libcrypto.num
|
||||||
|
index 1566231..8635ac4 100644
|
||||||
|
--- a/util/libcrypto.num
|
||||||
|
+++ b/util/libcrypto.num
|
||||||
|
@@ -4626,3 +4626,5 @@ FIPS_drbg_get_strength 6379 1_1_0g EXIST::FUNCTION:
|
||||||
|
FIPS_rand_strength 6380 1_1_0g EXIST::FUNCTION:
|
||||||
|
FIPS_drbg_get_blocklength 6381 1_1_0g EXIST::FUNCTION:
|
||||||
|
FIPS_drbg_init 6382 1_1_0g EXIST::FUNCTION:
|
||||||
|
+X509_set_sm2_id 6383 1_1_1m EXIST::FUNCTION:
|
||||||
|
+X509_get0_sm2_id 6384 1_1_1m EXIST::FUNCTION:
|
||||||
|
--
|
||||||
|
2.20.1 (Apple Git-117)
|
||||||
|
|
||||||
127
Backport-Support-parsing-of-SM2-ID-in-hexdecimal.patch
Normal file
127
Backport-Support-parsing-of-SM2-ID-in-hexdecimal.patch
Normal file
@ -0,0 +1,127 @@
|
|||||||
|
From 1d9e832e41858b13a96899d842afd183f1c66c48 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Paul Yang <kaishen.yy@antfin.com>
|
||||||
|
Date: Tue, 30 Jul 2019 23:05:44 +0800
|
||||||
|
Subject: [PATCH 11/15] Support parsing of SM2 ID in hexdecimal
|
||||||
|
|
||||||
|
The current EVP_PEKY_ctrl for SM2 has no capability of parsing an ID
|
||||||
|
input in hexdecimal.
|
||||||
|
|
||||||
|
The newly added ctrl string is called: sm2_hex_id
|
||||||
|
|
||||||
|
Test cases and documentation are updated.
|
||||||
|
|
||||||
|
Reviewed-by: Tim Hudson <tjh@openssl.org>
|
||||||
|
Reviewed-by: Richard Levitte <levitte@openssl.org>
|
||||||
|
(Merged from https://github.com/openssl/openssl/pull/9584)
|
||||||
|
---
|
||||||
|
crypto/sm2/sm2_pmeth.c | 19 +++++++++++++++++++
|
||||||
|
doc/man1/pkeyutl.pod | 7 +++++++
|
||||||
|
include/openssl/ec.h | 1 -
|
||||||
|
test/recipes/25-test_req.t | 15 +++++++++++++--
|
||||||
|
4 files changed, 39 insertions(+), 3 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/crypto/sm2/sm2_pmeth.c b/crypto/sm2/sm2_pmeth.c
|
||||||
|
index 837bdc1..9551d70 100644
|
||||||
|
--- a/crypto/sm2/sm2_pmeth.c
|
||||||
|
+++ b/crypto/sm2/sm2_pmeth.c
|
||||||
|
@@ -232,6 +232,10 @@ static int pkey_sm2_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
|
||||||
|
static int pkey_sm2_ctrl_str(EVP_PKEY_CTX *ctx,
|
||||||
|
const char *type, const char *value)
|
||||||
|
{
|
||||||
|
+ uint8_t *hex_id;
|
||||||
|
+ long hex_len = 0;
|
||||||
|
+ int ret = 0;
|
||||||
|
+
|
||||||
|
if (strcmp(type, "ec_paramgen_curve") == 0) {
|
||||||
|
int nid = NID_undef;
|
||||||
|
|
||||||
|
@@ -255,6 +259,21 @@ static int pkey_sm2_ctrl_str(EVP_PKEY_CTX *ctx,
|
||||||
|
} else if (strcmp(type, "sm2_id") == 0) {
|
||||||
|
return pkey_sm2_ctrl(ctx, EVP_PKEY_CTRL_SET1_ID,
|
||||||
|
(int)strlen(value), (void *)value);
|
||||||
|
+ } else if (strcmp(type, "sm2_hex_id") == 0) {
|
||||||
|
+ /*
|
||||||
|
+ * TODO(3.0): reconsider the name "sm2_hex_id", OR change
|
||||||
|
+ * OSSL_PARAM_construct_from_text() / OSSL_PARAM_allocate_from_text()
|
||||||
|
+ * to handle infix "_hex_"
|
||||||
|
+ */
|
||||||
|
+ hex_id = OPENSSL_hexstr2buf((const char *)value, &hex_len);
|
||||||
|
+ if (hex_id == NULL) {
|
||||||
|
+ SM2err(SM2_F_PKEY_SM2_CTRL_STR, ERR_R_PASSED_INVALID_ARGUMENT);
|
||||||
|
+ return 0;
|
||||||
|
+ }
|
||||||
|
+ ret = pkey_sm2_ctrl(ctx, EVP_PKEY_CTRL_SET1_ID, (int)hex_len,
|
||||||
|
+ (void *)hex_id);
|
||||||
|
+ OPENSSL_free(hex_id);
|
||||||
|
+ return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
return -2;
|
||||||
|
diff --git a/doc/man1/pkeyutl.pod b/doc/man1/pkeyutl.pod
|
||||||
|
index f0f80af..1a742ab 100644
|
||||||
|
--- a/doc/man1/pkeyutl.pod
|
||||||
|
+++ b/doc/man1/pkeyutl.pod
|
||||||
|
@@ -329,6 +329,13 @@ This sets the ID string used in SM2 sign or verify operations. While verifying
|
||||||
|
an SM2 signature, the ID string must be the same one used when signing the data.
|
||||||
|
Otherwise the verification will fail.
|
||||||
|
|
||||||
|
+=item B<sm2_hex_id:hex_string>
|
||||||
|
+
|
||||||
|
+This sets the ID string used in SM2 sign or verify operations. While verifying
|
||||||
|
+an SM2 signature, the ID string must be the same one used when signing the data.
|
||||||
|
+Otherwise the verification will fail. The ID string provided with this option
|
||||||
|
+should be a valid hexadecimal value.
|
||||||
|
+
|
||||||
|
=back
|
||||||
|
|
||||||
|
=head1 EXAMPLES
|
||||||
|
diff --git a/include/openssl/ec.h b/include/openssl/ec.h
|
||||||
|
index 24baf53..e8c8869 100644
|
||||||
|
--- a/include/openssl/ec.h
|
||||||
|
+++ b/include/openssl/ec.h
|
||||||
|
@@ -1444,7 +1444,6 @@ void EC_KEY_METHOD_get_verify(const EC_KEY_METHOD *meth,
|
||||||
|
# define EVP_PKEY_CTX_set1_id(ctx, id, id_len) \
|
||||||
|
EVP_PKEY_CTX_ctrl(ctx, -1, -1, \
|
||||||
|
EVP_PKEY_CTRL_SET1_ID, (int)id_len, (void*)(id))
|
||||||
|
-
|
||||||
|
# define EVP_PKEY_CTX_get1_id(ctx, id) \
|
||||||
|
EVP_PKEY_CTX_ctrl(ctx, -1, -1, \
|
||||||
|
EVP_PKEY_CTRL_GET1_ID, 0, (void*)(id))
|
||||||
|
diff --git a/test/recipes/25-test_req.t b/test/recipes/25-test_req.t
|
||||||
|
index 8289959..d53e577 100644
|
||||||
|
--- a/test/recipes/25-test_req.t
|
||||||
|
+++ b/test/recipes/25-test_req.t
|
||||||
|
@@ -182,10 +182,10 @@ subtest "generating certificate requests" => sub {
|
||||||
|
};
|
||||||
|
|
||||||
|
subtest "generating SM2 certificate requests" => sub {
|
||||||
|
- plan tests => 2;
|
||||||
|
+ plan tests => 4;
|
||||||
|
|
||||||
|
SKIP: {
|
||||||
|
- skip "SM2 is not supported by this OpenSSL build", 2
|
||||||
|
+ skip "SM2 is not supported by this OpenSSL build", 4
|
||||||
|
if disabled("sm2");
|
||||||
|
ok(run(app(["openssl", "req", "-config", srctop_file("test", "test.cnf"),
|
||||||
|
"-new", "-key", srctop_file("test", "certs", "sm2.key"),
|
||||||
|
@@ -197,6 +197,17 @@ subtest "generating SM2 certificate requests" => sub {
|
||||||
|
"-verify", "-in", "testreq.pem", "-noout",
|
||||||
|
"-sm2-id", "1234567812345678", "-sm3"])),
|
||||||
|
"Verifying signature on SM2 certificate request");
|
||||||
|
+
|
||||||
|
+ ok(run(app(["openssl", "req", "-config", srctop_file("test", "test.cnf"),
|
||||||
|
+ "-new", "-key", srctop_file("test", "certs", "sm2.key"),
|
||||||
|
+ "-sigopt", "sm2_hex_id:DEADBEEF",
|
||||||
|
+ "-out", "testreq.pem", "-sm3"])),
|
||||||
|
+ "Generating SM2 certificate request with hex id");
|
||||||
|
+
|
||||||
|
+ ok(run(app(["openssl", "req", "-config", srctop_file("test", "test.cnf"),
|
||||||
|
+ "-verify", "-in", "testreq.pem", "-noout",
|
||||||
|
+ "-sm2-hex-id", "DEADBEEF", "-sm3"])),
|
||||||
|
+ "Verifying signature on SM2 certificate request");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
--
|
||||||
|
2.20.1 (Apple Git-117)
|
||||||
|
|
||||||
482
Backport-Support-raw-input-data-in-apps-pkeyutl.patch
Normal file
482
Backport-Support-raw-input-data-in-apps-pkeyutl.patch
Normal file
@ -0,0 +1,482 @@
|
|||||||
|
From b14bf717ccb166cce13173a817106effb02f6c2e Mon Sep 17 00:00:00 2001
|
||||||
|
From: Paul Yang <yang.yang@baishancloud.com>
|
||||||
|
Date: Wed, 16 Jan 2019 16:16:28 +0800
|
||||||
|
Subject: [PATCH 01/15] Support raw input data in apps/pkeyutl
|
||||||
|
|
||||||
|
Some signature algorithms require special treatment for digesting, such
|
||||||
|
as SM2. This patch adds the ability of handling raw input data in
|
||||||
|
apps/pkeyutl other than accepting only pre-hashed input data.
|
||||||
|
|
||||||
|
Beside, SM2 requries an ID string when signing or verifying a piece of data,
|
||||||
|
this patch also adds the ability for apps/pkeyutil to specify that ID
|
||||||
|
string.
|
||||||
|
|
||||||
|
Reviewed-by: Matt Caswell <matt@openssl.org>
|
||||||
|
(Merged from https://github.com/openssl/openssl/pull/8186)
|
||||||
|
---
|
||||||
|
apps/pkeyutl.c | 168 +++++++++++++++++++++++++++++----
|
||||||
|
crypto/sm2/sm2_pmeth.c | 3 +
|
||||||
|
doc/man1/pkeyutl.pod | 45 +++++++++
|
||||||
|
test/certs/sm2.crt | 13 +++
|
||||||
|
test/certs/sm2.key | 5 +
|
||||||
|
test/recipes/20-test_pkeyutl.t | 43 +++++++++
|
||||||
|
6 files changed, 260 insertions(+), 17 deletions(-)
|
||||||
|
create mode 100644 test/certs/sm2.crt
|
||||||
|
create mode 100644 test/certs/sm2.key
|
||||||
|
create mode 100644 test/recipes/20-test_pkeyutl.t
|
||||||
|
|
||||||
|
diff --git a/apps/pkeyutl.c b/apps/pkeyutl.c
|
||||||
|
index 831e14d..bca0464 100644
|
||||||
|
--- a/apps/pkeyutl.c
|
||||||
|
+++ b/apps/pkeyutl.c
|
||||||
|
@@ -22,7 +22,7 @@
|
||||||
|
static EVP_PKEY_CTX *init_ctx(const char *kdfalg, int *pkeysize,
|
||||||
|
const char *keyfile, int keyform, int key_type,
|
||||||
|
char *passinarg, int pkey_op, ENGINE *e,
|
||||||
|
- const int impl);
|
||||||
|
+ const int impl, EVP_PKEY **ppkey);
|
||||||
|
|
||||||
|
static int setup_peer(EVP_PKEY_CTX *ctx, int peerform, const char *file,
|
||||||
|
ENGINE *e);
|
||||||
|
@@ -31,6 +31,11 @@ static int do_keyop(EVP_PKEY_CTX *ctx, int pkey_op,
|
||||||
|
unsigned char *out, size_t *poutlen,
|
||||||
|
const unsigned char *in, size_t inlen);
|
||||||
|
|
||||||
|
+static int do_raw_keyop(int pkey_op, EVP_PKEY_CTX *ctx,
|
||||||
|
+ const EVP_MD *md, EVP_PKEY *pkey, BIO *in,
|
||||||
|
+ unsigned char *sig, int siglen,
|
||||||
|
+ unsigned char **out, size_t *poutlen);
|
||||||
|
+
|
||||||
|
typedef enum OPTION_choice {
|
||||||
|
OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
|
||||||
|
OPT_ENGINE, OPT_ENGINE_IMPL, OPT_IN, OPT_OUT,
|
||||||
|
@@ -38,12 +43,15 @@ typedef enum OPTION_choice {
|
||||||
|
OPT_VERIFY, OPT_VERIFYRECOVER, OPT_REV, OPT_ENCRYPT, OPT_DECRYPT,
|
||||||
|
OPT_DERIVE, OPT_SIGFILE, OPT_INKEY, OPT_PEERKEY, OPT_PASSIN,
|
||||||
|
OPT_PEERFORM, OPT_KEYFORM, OPT_PKEYOPT, OPT_KDF, OPT_KDFLEN,
|
||||||
|
- OPT_R_ENUM
|
||||||
|
+ OPT_R_ENUM, OPT_RAWIN, OPT_DIGEST
|
||||||
|
} OPTION_CHOICE;
|
||||||
|
|
||||||
|
const OPTIONS pkeyutl_options[] = {
|
||||||
|
{"help", OPT_HELP, '-', "Display this summary"},
|
||||||
|
{"in", OPT_IN, '<', "Input file - default stdin"},
|
||||||
|
+ {"rawin", OPT_RAWIN, '-', "Indicate the input data is in raw form"},
|
||||||
|
+ {"digest", OPT_DIGEST, 's',
|
||||||
|
+ "Specify the digest algorithm when signing the raw input data"},
|
||||||
|
{"out", OPT_OUT, '>', "Output file - default stdout"},
|
||||||
|
{"pubin", OPT_PUBIN, '-', "Input is a public key"},
|
||||||
|
{"certin", OPT_CERTIN, '-', "Input is a cert with a public key"},
|
||||||
|
@@ -80,6 +88,7 @@ int pkeyutl_main(int argc, char **argv)
|
||||||
|
BIO *in = NULL, *out = NULL;
|
||||||
|
ENGINE *e = NULL;
|
||||||
|
EVP_PKEY_CTX *ctx = NULL;
|
||||||
|
+ EVP_PKEY *pkey = NULL;
|
||||||
|
char *infile = NULL, *outfile = NULL, *sigfile = NULL, *passinarg = NULL;
|
||||||
|
char hexdump = 0, asn1parse = 0, rev = 0, *prog;
|
||||||
|
unsigned char *buf_in = NULL, *buf_out = NULL, *sig = NULL;
|
||||||
|
@@ -94,6 +103,8 @@ int pkeyutl_main(int argc, char **argv)
|
||||||
|
const char *kdfalg = NULL;
|
||||||
|
int kdflen = 0;
|
||||||
|
STACK_OF(OPENSSL_STRING) *pkeyopts = NULL;
|
||||||
|
+ int rawin = 0;
|
||||||
|
+ const EVP_MD *md = NULL;
|
||||||
|
|
||||||
|
prog = opt_init(argc, argv, pkeyutl_options);
|
||||||
|
while ((o = opt_next()) != OPT_EOF) {
|
||||||
|
@@ -192,12 +203,39 @@ int pkeyutl_main(int argc, char **argv)
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
+ case OPT_RAWIN:
|
||||||
|
+ rawin = 1;
|
||||||
|
+ break;
|
||||||
|
+ case OPT_DIGEST:
|
||||||
|
+ if (!opt_md(opt_arg(), &md))
|
||||||
|
+ goto end;
|
||||||
|
+ break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
argc = opt_num_rest();
|
||||||
|
if (argc != 0)
|
||||||
|
goto opthelp;
|
||||||
|
|
||||||
|
+ if (rawin && pkey_op != EVP_PKEY_OP_SIGN && pkey_op != EVP_PKEY_OP_VERIFY) {
|
||||||
|
+ BIO_printf(bio_err,
|
||||||
|
+ "%s: -rawin can only be used with -sign or -verify\n",
|
||||||
|
+ prog);
|
||||||
|
+ goto opthelp;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ if (md != NULL && !rawin) {
|
||||||
|
+ BIO_printf(bio_err,
|
||||||
|
+ "%s: -digest can only be used with -rawin\n",
|
||||||
|
+ prog);
|
||||||
|
+ goto opthelp;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ if (rawin && rev) {
|
||||||
|
+ BIO_printf(bio_err, "%s: -rev cannot be used with raw input\n",
|
||||||
|
+ prog);
|
||||||
|
+ goto opthelp;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
if (kdfalg != NULL) {
|
||||||
|
if (kdflen == 0) {
|
||||||
|
BIO_printf(bio_err,
|
||||||
|
@@ -214,7 +252,7 @@ int pkeyutl_main(int argc, char **argv)
|
||||||
|
goto opthelp;
|
||||||
|
}
|
||||||
|
ctx = init_ctx(kdfalg, &keysize, inkey, keyform, key_type,
|
||||||
|
- passinarg, pkey_op, e, engine_impl);
|
||||||
|
+ passinarg, pkey_op, e, engine_impl, &pkey);
|
||||||
|
if (ctx == NULL) {
|
||||||
|
BIO_printf(bio_err, "%s: Error initializing context\n", prog);
|
||||||
|
ERR_print_errors(bio_err);
|
||||||
|
@@ -277,7 +315,8 @@ int pkeyutl_main(int argc, char **argv)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- if (in != NULL) {
|
||||||
|
+ /* Raw input data is handled elsewhere */
|
||||||
|
+ if (in != NULL && !rawin) {
|
||||||
|
/* Read the input data */
|
||||||
|
buf_inlen = bio_to_mem(&buf_in, keysize * 10, in);
|
||||||
|
if (buf_inlen < 0) {
|
||||||
|
@@ -296,8 +335,9 @@ int pkeyutl_main(int argc, char **argv)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- /* Sanity check the input */
|
||||||
|
- if (buf_inlen > EVP_MAX_MD_SIZE
|
||||||
|
+ /* Sanity check the input if the input is not raw */
|
||||||
|
+ if (!rawin
|
||||||
|
+ && buf_inlen > EVP_MAX_MD_SIZE
|
||||||
|
&& (pkey_op == EVP_PKEY_OP_SIGN
|
||||||
|
|| pkey_op == EVP_PKEY_OP_VERIFY)) {
|
||||||
|
BIO_printf(bio_err,
|
||||||
|
@@ -306,8 +346,13 @@ int pkeyutl_main(int argc, char **argv)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pkey_op == EVP_PKEY_OP_VERIFY) {
|
||||||
|
- rv = EVP_PKEY_verify(ctx, sig, (size_t)siglen,
|
||||||
|
- buf_in, (size_t)buf_inlen);
|
||||||
|
+ if (rawin) {
|
||||||
|
+ rv = do_raw_keyop(pkey_op, ctx, md, pkey, in, sig, siglen,
|
||||||
|
+ NULL, 0);
|
||||||
|
+ } else {
|
||||||
|
+ rv = EVP_PKEY_verify(ctx, sig, (size_t)siglen,
|
||||||
|
+ buf_in, (size_t)buf_inlen);
|
||||||
|
+ }
|
||||||
|
if (rv == 1) {
|
||||||
|
BIO_puts(out, "Signature Verified Successfully\n");
|
||||||
|
ret = 0;
|
||||||
|
@@ -320,14 +365,20 @@ int pkeyutl_main(int argc, char **argv)
|
||||||
|
buf_outlen = kdflen;
|
||||||
|
rv = 1;
|
||||||
|
} else {
|
||||||
|
- rv = do_keyop(ctx, pkey_op, NULL, (size_t *)&buf_outlen,
|
||||||
|
- buf_in, (size_t)buf_inlen);
|
||||||
|
- }
|
||||||
|
- if (rv > 0 && buf_outlen != 0) {
|
||||||
|
- buf_out = app_malloc(buf_outlen, "buffer output");
|
||||||
|
- rv = do_keyop(ctx, pkey_op,
|
||||||
|
- buf_out, (size_t *)&buf_outlen,
|
||||||
|
- buf_in, (size_t)buf_inlen);
|
||||||
|
+ if (rawin) {
|
||||||
|
+ /* rawin allocates the buffer in do_raw_keyop() */
|
||||||
|
+ rv = do_raw_keyop(pkey_op, ctx, md, pkey, in, NULL, 0,
|
||||||
|
+ &buf_out, (size_t *)&buf_outlen);
|
||||||
|
+ } else {
|
||||||
|
+ rv = do_keyop(ctx, pkey_op, NULL, (size_t *)&buf_outlen,
|
||||||
|
+ buf_in, (size_t)buf_inlen);
|
||||||
|
+ if (rv > 0 && buf_outlen != 0) {
|
||||||
|
+ buf_out = app_malloc(buf_outlen, "buffer output");
|
||||||
|
+ rv = do_keyop(ctx, pkey_op,
|
||||||
|
+ buf_out, (size_t *)&buf_outlen,
|
||||||
|
+ buf_in, (size_t)buf_inlen);
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
}
|
||||||
|
if (rv <= 0) {
|
||||||
|
if (pkey_op != EVP_PKEY_OP_DERIVE) {
|
||||||
|
@@ -364,7 +415,7 @@ int pkeyutl_main(int argc, char **argv)
|
||||||
|
static EVP_PKEY_CTX *init_ctx(const char *kdfalg, int *pkeysize,
|
||||||
|
const char *keyfile, int keyform, int key_type,
|
||||||
|
char *passinarg, int pkey_op, ENGINE *e,
|
||||||
|
- const int engine_impl)
|
||||||
|
+ const int engine_impl, EVP_PKEY **ppkey)
|
||||||
|
{
|
||||||
|
EVP_PKEY *pkey = NULL;
|
||||||
|
EVP_PKEY_CTX *ctx = NULL;
|
||||||
|
@@ -422,10 +473,25 @@ static EVP_PKEY_CTX *init_ctx(const char *kdfalg, int *pkeysize,
|
||||||
|
}
|
||||||
|
ctx = EVP_PKEY_CTX_new_id(kdfnid, impl);
|
||||||
|
} else {
|
||||||
|
+ EC_KEY *eckey = NULL;
|
||||||
|
+ const EC_GROUP *group = NULL;
|
||||||
|
+ int nid;
|
||||||
|
+
|
||||||
|
if (pkey == NULL)
|
||||||
|
goto end;
|
||||||
|
+ /* SM2 needs a special treatment */
|
||||||
|
+ if (EVP_PKEY_id(pkey) == EVP_PKEY_EC) {
|
||||||
|
+ if ((eckey = EVP_PKEY_get0_EC_KEY(pkey)) == NULL
|
||||||
|
+ || (group = EC_KEY_get0_group(eckey)) == NULL
|
||||||
|
+ || (nid = EC_GROUP_get_curve_name(group)) == 0)
|
||||||
|
+ goto end;
|
||||||
|
+ if (nid == NID_sm2)
|
||||||
|
+ EVP_PKEY_set_alias_type(pkey, EVP_PKEY_SM2);
|
||||||
|
+ }
|
||||||
|
*pkeysize = EVP_PKEY_size(pkey);
|
||||||
|
ctx = EVP_PKEY_CTX_new(pkey, impl);
|
||||||
|
+ if (ppkey != NULL)
|
||||||
|
+ *ppkey = pkey;
|
||||||
|
EVP_PKEY_free(pkey);
|
||||||
|
}
|
||||||
|
|
||||||
|
@@ -522,3 +588,71 @@ static int do_keyop(EVP_PKEY_CTX *ctx, int pkey_op,
|
||||||
|
}
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
+
|
||||||
|
+#define TBUF_MAXSIZE 2048
|
||||||
|
+
|
||||||
|
+static int do_raw_keyop(int pkey_op, EVP_PKEY_CTX *ctx,
|
||||||
|
+ const EVP_MD *md, EVP_PKEY *pkey, BIO *in,
|
||||||
|
+ unsigned char *sig, int siglen,
|
||||||
|
+ unsigned char **out, size_t *poutlen)
|
||||||
|
+{
|
||||||
|
+ int rv = 0;
|
||||||
|
+ EVP_MD_CTX *mctx = NULL;
|
||||||
|
+ unsigned char tbuf[TBUF_MAXSIZE];
|
||||||
|
+ int tbuf_len = 0;
|
||||||
|
+
|
||||||
|
+ if ((mctx = EVP_MD_CTX_new()) == NULL) {
|
||||||
|
+ BIO_printf(bio_err, "Error: out of memory\n");
|
||||||
|
+ return rv;
|
||||||
|
+ }
|
||||||
|
+ EVP_MD_CTX_set_pkey_ctx(mctx, ctx);
|
||||||
|
+
|
||||||
|
+ switch(pkey_op) {
|
||||||
|
+ case EVP_PKEY_OP_VERIFY:
|
||||||
|
+ if (EVP_DigestVerifyInit(mctx, NULL, md, NULL, pkey) != 1)
|
||||||
|
+ goto end;
|
||||||
|
+ for (;;) {
|
||||||
|
+ tbuf_len = BIO_read(in, tbuf, TBUF_MAXSIZE);
|
||||||
|
+ if (tbuf_len == 0)
|
||||||
|
+ break;
|
||||||
|
+ if (tbuf_len < 0) {
|
||||||
|
+ BIO_printf(bio_err, "Error reading raw input data\n");
|
||||||
|
+ goto end;
|
||||||
|
+ }
|
||||||
|
+ rv = EVP_DigestVerifyUpdate(mctx, tbuf, (size_t)tbuf_len);
|
||||||
|
+ if (rv != 1) {
|
||||||
|
+ BIO_printf(bio_err, "Error verifying raw input data\n");
|
||||||
|
+ goto end;
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+ rv = EVP_DigestVerifyFinal(mctx, sig, (size_t)siglen);
|
||||||
|
+ break;
|
||||||
|
+ case EVP_PKEY_OP_SIGN:
|
||||||
|
+ if (EVP_DigestSignInit(mctx, NULL, md, NULL, pkey) != 1)
|
||||||
|
+ goto end;
|
||||||
|
+ for (;;) {
|
||||||
|
+ tbuf_len = BIO_read(in, tbuf, TBUF_MAXSIZE);
|
||||||
|
+ if (tbuf_len == 0)
|
||||||
|
+ break;
|
||||||
|
+ if (tbuf_len < 0) {
|
||||||
|
+ BIO_printf(bio_err, "Error reading raw input data\n");
|
||||||
|
+ goto end;
|
||||||
|
+ }
|
||||||
|
+ rv = EVP_DigestSignUpdate(mctx, tbuf, (size_t)tbuf_len);
|
||||||
|
+ if (rv != 1) {
|
||||||
|
+ BIO_printf(bio_err, "Error signing raw input data\n");
|
||||||
|
+ goto end;
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+ rv = EVP_DigestSignFinal(mctx, NULL, poutlen);
|
||||||
|
+ if (rv == 1 && out != NULL) {
|
||||||
|
+ *out = app_malloc(*poutlen, "buffer output");
|
||||||
|
+ rv = EVP_DigestSignFinal(mctx, *out, poutlen);
|
||||||
|
+ }
|
||||||
|
+ break;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ end:
|
||||||
|
+ EVP_MD_CTX_free(mctx);
|
||||||
|
+ return rv;
|
||||||
|
+}
|
||||||
|
diff --git a/crypto/sm2/sm2_pmeth.c b/crypto/sm2/sm2_pmeth.c
|
||||||
|
index 0e722b9..837bdc1 100644
|
||||||
|
--- a/crypto/sm2/sm2_pmeth.c
|
||||||
|
+++ b/crypto/sm2/sm2_pmeth.c
|
||||||
|
@@ -252,6 +252,9 @@ static int pkey_sm2_ctrl_str(EVP_PKEY_CTX *ctx,
|
||||||
|
else
|
||||||
|
return -2;
|
||||||
|
return EVP_PKEY_CTX_set_ec_param_enc(ctx, param_enc);
|
||||||
|
+ } else if (strcmp(type, "sm2_id") == 0) {
|
||||||
|
+ return pkey_sm2_ctrl(ctx, EVP_PKEY_CTRL_SET1_ID,
|
||||||
|
+ (int)strlen(value), (void *)value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return -2;
|
||||||
|
diff --git a/doc/man1/pkeyutl.pod b/doc/man1/pkeyutl.pod
|
||||||
|
index f6fd48d..f0f80af 100644
|
||||||
|
--- a/doc/man1/pkeyutl.pod
|
||||||
|
+++ b/doc/man1/pkeyutl.pod
|
||||||
|
@@ -10,6 +10,8 @@ pkeyutl - public key algorithm utility
|
||||||
|
B<openssl> B<pkeyutl>
|
||||||
|
[B<-help>]
|
||||||
|
[B<-in file>]
|
||||||
|
+[B<-rawin>]
|
||||||
|
+[B<-digest algorithm>]
|
||||||
|
[B<-out file>]
|
||||||
|
[B<-sigfile file>]
|
||||||
|
[B<-inkey file>]
|
||||||
|
@@ -54,6 +56,23 @@ Print out a usage message.
|
||||||
|
This specifies the input filename to read data from or standard input
|
||||||
|
if this option is not specified.
|
||||||
|
|
||||||
|
+=item B<-rawin>
|
||||||
|
+
|
||||||
|
+This indicates that the input data is raw data, which is not hashed by any
|
||||||
|
+message digest algorithm. The user can specify a digest algorithm by using
|
||||||
|
+the B<-digest> option. This option can only be used with B<-sign> and
|
||||||
|
+B<-verify>.
|
||||||
|
+
|
||||||
|
+=item B<-digest algorithm>
|
||||||
|
+
|
||||||
|
+This specifies the digest algorithm which is used to hash the input data before
|
||||||
|
+signing or verifying it with the input key. This option could be omitted if the
|
||||||
|
+signature algorithm does not require one (for instance, EdDSA). If this option
|
||||||
|
+is omitted but the signature algorithm requires one, a default value will be
|
||||||
|
+used. For signature algorithms like RSA, DSA and ECDSA, SHA-256 will be the
|
||||||
|
+default digest algorithm. For SM2, it will be SM3. If this option is present,
|
||||||
|
+then the B<-rawin> option must be also specified to B<pkeyutl>.
|
||||||
|
+
|
||||||
|
=item B<-out filename>
|
||||||
|
|
||||||
|
Specifies the output filename to write to or standard output by
|
||||||
|
@@ -296,6 +315,22 @@ the B<-pkeyopt> B<digest> option.
|
||||||
|
The X25519 and X448 algorithms support key derivation only. Currently there are
|
||||||
|
no additional options.
|
||||||
|
|
||||||
|
+=head1 SM2
|
||||||
|
+
|
||||||
|
+The SM2 algorithm supports sign, verify, encrypt and decrypt operations. For
|
||||||
|
+the sign and verify operations, SM2 requires an ID string to be passed in. The
|
||||||
|
+following B<pkeyopt> value is supported:
|
||||||
|
+
|
||||||
|
+=over 4
|
||||||
|
+
|
||||||
|
+=item B<sm2_id:string>
|
||||||
|
+
|
||||||
|
+This sets the ID string used in SM2 sign or verify operations. While verifying
|
||||||
|
+an SM2 signature, the ID string must be the same one used when signing the data.
|
||||||
|
+Otherwise the verification will fail.
|
||||||
|
+
|
||||||
|
+=back
|
||||||
|
+
|
||||||
|
=head1 EXAMPLES
|
||||||
|
|
||||||
|
Sign some data using a private key:
|
||||||
|
@@ -329,6 +364,16 @@ Decrypt some data using a private key with OAEP padding using SHA256:
|
||||||
|
openssl pkeyutl -decrypt -in file -inkey key.pem -out secret \
|
||||||
|
-pkeyopt rsa_padding_mode:oaep -pkeyopt rsa_oaep_md:sha256
|
||||||
|
|
||||||
|
+Sign some data using an L<SM2(7)> private key and a specific ID:
|
||||||
|
+
|
||||||
|
+ openssl pkeyutl -sign -in file -inkey sm2.key -out sig -rawin -digest sm3 \
|
||||||
|
+ -pkeyopt sm2_id:someid
|
||||||
|
+
|
||||||
|
+Verify some data using an L<SM2(7)> certificate and a specific ID:
|
||||||
|
+
|
||||||
|
+ openssl pkeyutl -verify -certin -in file -inkey sm2.cert -sigfile sig \
|
||||||
|
+ -rawin -digest sm3 -pkeyopt sm2_id:someid
|
||||||
|
+
|
||||||
|
=head1 SEE ALSO
|
||||||
|
|
||||||
|
L<genpkey(1)>, L<pkey(1)>, L<rsautl(1)>
|
||||||
|
diff --git a/test/certs/sm2.crt b/test/certs/sm2.crt
|
||||||
|
new file mode 100644
|
||||||
|
index 0000000..189abb1
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/test/certs/sm2.crt
|
||||||
|
@@ -0,0 +1,13 @@
|
||||||
|
+-----BEGIN CERTIFICATE-----
|
||||||
|
+MIIB6DCCAY6gAwIBAgIJAKH2BR6ITHZeMAoGCCqBHM9VAYN1MGgxCzAJBgNVBAYT
|
||||||
|
+AkNOMQswCQYDVQQIDAJMTjERMA8GA1UEBwwIU2hlbnlhbmcxETAPBgNVBAoMCFRl
|
||||||
|
+c3QgT3JnMRAwDgYDVQQLDAdUZXN0IE9VMRQwEgYDVQQDDAtUZXN0IFNNMiBDQTAe
|
||||||
|
+Fw0xOTAyMTkwNzA1NDhaFw0yMzAzMzAwNzA1NDhaMG8xCzAJBgNVBAYTAkNOMQsw
|
||||||
|
+CQYDVQQIDAJMTjERMA8GA1UEBwwIU2hlbnlhbmcxETAPBgNVBAoMCFRlc3QgT3Jn
|
||||||
|
+MRAwDgYDVQQLDAdUZXN0IE9VMRswGQYDVQQDDBJUZXN0IFNNMiBTaWduIENlcnQw
|
||||||
|
+WTATBgcqhkjOPQIBBggqgRzPVQGCLQNCAAQwqeNkWp7fiu1KZnuDkAucpM8piEzE
|
||||||
|
+TL1ymrcrOBvv8mhNNkeb20asbWgFQI2zOrSM99/sXGn9rM2/usM/MlcaoxowGDAJ
|
||||||
|
+BgNVHRMEAjAAMAsGA1UdDwQEAwIGwDAKBggqgRzPVQGDdQNIADBFAiEA9edBnAqT
|
||||||
|
+TNuGIUIvXsj6/nP+AzXA9HGtAIY4nrqW8LkCIHyZzhRTlxYtgfqkDl0OK5QQRCZH
|
||||||
|
+OZOfmtx613VyzXwc
|
||||||
|
+-----END CERTIFICATE-----
|
||||||
|
diff --git a/test/certs/sm2.key b/test/certs/sm2.key
|
||||||
|
new file mode 100644
|
||||||
|
index 0000000..1efd364
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/test/certs/sm2.key
|
||||||
|
@@ -0,0 +1,5 @@
|
||||||
|
+-----BEGIN PRIVATE KEY-----
|
||||||
|
+MIGHAgEAMBMGByqGSM49AgEGCCqBHM9VAYItBG0wawIBAQQgSKhk+4xGyDI+IS2H
|
||||||
|
+WVfFPDxh1qv5+wtrddaIsGNXGZihRANCAAQwqeNkWp7fiu1KZnuDkAucpM8piEzE
|
||||||
|
+TL1ymrcrOBvv8mhNNkeb20asbWgFQI2zOrSM99/sXGn9rM2/usM/Mlca
|
||||||
|
+-----END PRIVATE KEY-----
|
||||||
|
diff --git a/test/recipes/20-test_pkeyutl.t b/test/recipes/20-test_pkeyutl.t
|
||||||
|
new file mode 100644
|
||||||
|
index 0000000..a051138
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/test/recipes/20-test_pkeyutl.t
|
||||||
|
@@ -0,0 +1,43 @@
|
||||||
|
+#! /usr/bin/env perl
|
||||||
|
+# Copyright 2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||||
|
+#
|
||||||
|
+# Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||||
|
+# this file except in compliance with the License. You can obtain a copy
|
||||||
|
+# in the file LICENSE in the source distribution or at
|
||||||
|
+# https://www.openssl.org/source/license.html
|
||||||
|
+
|
||||||
|
+use strict;
|
||||||
|
+use warnings;
|
||||||
|
+
|
||||||
|
+use File::Spec;
|
||||||
|
+use OpenSSL::Test qw/:DEFAULT srctop_file/;
|
||||||
|
+use OpenSSL::Test::Utils;
|
||||||
|
+
|
||||||
|
+setup("test_pkeyutl");
|
||||||
|
+
|
||||||
|
+plan tests => 2;
|
||||||
|
+
|
||||||
|
+sub sign
|
||||||
|
+{
|
||||||
|
+ # Utilize the sm2.crt as the TBS file
|
||||||
|
+ return run(app(([ 'openssl', 'pkeyutl', '-sign',
|
||||||
|
+ '-in', srctop_file('test', 'certs', 'sm2.crt'),
|
||||||
|
+ '-inkey', srctop_file('test', 'certs', 'sm2.key'),
|
||||||
|
+ '-out', 'signature.sm2', '-rawin',
|
||||||
|
+ '-digest', 'sm3', '-pkeyopt', 'sm2_id:someid'])));
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+sub verify
|
||||||
|
+{
|
||||||
|
+ # Utilize the sm2.crt as the TBS file
|
||||||
|
+ return run(app(([ 'openssl', 'pkeyutl', '-verify', '-certin',
|
||||||
|
+ '-in', srctop_file('test', 'certs', 'sm2.crt'),
|
||||||
|
+ '-inkey', srctop_file('test', 'certs', 'sm2.crt'),
|
||||||
|
+ '-sigfile', 'signature.sm2', '-rawin',
|
||||||
|
+ '-digest', 'sm3', '-pkeyopt', 'sm2_id:someid'])));
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+ok(sign, "Sign a piece of data using SM2");
|
||||||
|
+ok(verify, "Verify an SM2 signature against a piece of data");
|
||||||
|
+
|
||||||
|
+unlink 'signature.sm2';
|
||||||
|
--
|
||||||
|
2.20.1 (Apple Git-117)
|
||||||
|
|
||||||
191
Backport-Update-expired-SCT-certificates.patch
Normal file
191
Backport-Update-expired-SCT-certificates.patch
Normal file
@ -0,0 +1,191 @@
|
|||||||
|
From acb105a848fd0a282550f6132dc131575cc5a655 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Tomas Mraz <tomas@openssl.org>
|
||||||
|
Date: Wed, 1 Jun 2022 12:47:44 +0200
|
||||||
|
Subject: [PATCH 14/15] Update expired SCT certificates
|
||||||
|
|
||||||
|
Reviewed-by: Matt Caswell <matt@openssl.org>
|
||||||
|
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
|
||||||
|
(Merged from https://github.com/openssl/openssl/pull/18446)
|
||||||
|
---
|
||||||
|
test/certs/embeddedSCTs1-key.pem | 38 ++++++++++++++++---------
|
||||||
|
test/certs/embeddedSCTs1.pem | 35 ++++++++++++-----------
|
||||||
|
test/certs/embeddedSCTs1.sct | 12 ++++----
|
||||||
|
test/certs/embeddedSCTs1_issuer-key.pem | 15 ++++++++++
|
||||||
|
test/certs/embeddedSCTs1_issuer.pem | 30 +++++++++----------
|
||||||
|
5 files changed, 79 insertions(+), 51 deletions(-)
|
||||||
|
create mode 100644 test/certs/embeddedSCTs1_issuer-key.pem
|
||||||
|
|
||||||
|
diff --git a/test/certs/embeddedSCTs1-key.pem b/test/certs/embeddedSCTs1-key.pem
|
||||||
|
index e3e66d5..28dd206 100644
|
||||||
|
--- a/test/certs/embeddedSCTs1-key.pem
|
||||||
|
+++ b/test/certs/embeddedSCTs1-key.pem
|
||||||
|
@@ -1,15 +1,27 @@
|
||||||
|
-----BEGIN RSA PRIVATE KEY-----
|
||||||
|
-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
-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
-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
-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
-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
-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
-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
-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
-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
-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
-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
-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
-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
|
||||||
|
-----END RSA PRIVATE KEY-----
|
||||||
|
diff --git a/test/certs/embeddedSCTs1.pem b/test/certs/embeddedSCTs1.pem
|
||||||
|
index d1e8512..d2a111f 100644
|
||||||
|
--- a/test/certs/embeddedSCTs1.pem
|
||||||
|
+++ b/test/certs/embeddedSCTs1.pem
|
||||||
|
@@ -1,20 +1,21 @@
|
||||||
|
-----BEGIN CERTIFICATE-----
|
||||||
|
-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
-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
-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
-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
-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
-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
-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
-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
-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
-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
-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
-BgorBgEEAdZ5AgQCBHwEegB4AHYA3xwuwRUAlFJHqWFoMl3cXHlZ6PfG04j8AC4L
|
||||||
|
-vT9012QAAAE92yffkwAABAMARzBFAiBIL2dRrzXbplQ2vh/WZA89v5pBQpSVkkUw
|
||||||
|
-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
-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
-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
-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
|
||||||
|
+YT6yTEIzJuO07Xp61qnB1CE2TrinUWlyC46Zkw==
|
||||||
|
-----END CERTIFICATE-----
|
||||||
|
diff --git a/test/certs/embeddedSCTs1.sct b/test/certs/embeddedSCTs1.sct
|
||||||
|
index 59362dc..35c9eb9 100644
|
||||||
|
--- a/test/certs/embeddedSCTs1.sct
|
||||||
|
+++ b/test/certs/embeddedSCTs1.sct
|
||||||
|
@@ -2,11 +2,11 @@ Signed Certificate Timestamp:
|
||||||
|
Version : v1 (0x0)
|
||||||
|
Log ID : DF:1C:2E:C1:15:00:94:52:47:A9:61:68:32:5D:DC:5C:
|
||||||
|
79:59:E8:F7:C6:D3:88:FC:00:2E:0B:BD:3F:74:D7:64
|
||||||
|
- Timestamp : Apr 5 17:04:16.275 2013 GMT
|
||||||
|
+ Timestamp : Jan 1 00:00:00.000 2020 GMT
|
||||||
|
Extensions: none
|
||||||
|
Signature : ecdsa-with-SHA256
|
||||||
|
- 30:45:02:20:48:2F:67:51:AF:35:DB:A6:54:36:BE:1F:
|
||||||
|
- D6:64:0F:3D:BF:9A:41:42:94:95:92:45:30:28:8F:A3:
|
||||||
|
- E5:E2:3E:06:02:21:00:E4:ED:C0:DB:3A:C5:72:B1:E2:
|
||||||
|
- F5:E8:AB:6A:68:06:53:98:7D:CF:41:02:7D:FE:FF:A1:
|
||||||
|
- 05:51:9D:89:ED:BF:08
|
||||||
|
\ No newline at end of file
|
||||||
|
+ 30:45:02:20:7C:33:E8:F1:10:2B:9B:FB:DC:48:46:7A:
|
||||||
|
+ D3:C4:35:BB:E5:D0:E7:94:01:BB:AE:D2:64:4B:99:C4:
|
||||||
|
+ BA:5B:50:CD:02:21:00:D1:B2:07:13:B9:DE:0F:0F:2F:
|
||||||
|
+ 02:82:0F:A5:1D:E0:12:ED:4C:60:48:A0:5B:58:0C:E7:
|
||||||
|
+ 60:EB:A8:AF:03:5E:C3
|
||||||
|
\ No newline at end of file
|
||||||
|
diff --git a/test/certs/embeddedSCTs1_issuer-key.pem b/test/certs/embeddedSCTs1_issuer-key.pem
|
||||||
|
new file mode 100644
|
||||||
|
index 0000000..9326e38
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/test/certs/embeddedSCTs1_issuer-key.pem
|
||||||
|
@@ -0,0 +1,15 @@
|
||||||
|
+-----BEGIN RSA PRIVATE KEY-----
|
||||||
|
+MIICXAIBAAKBgQDVimhTYhCicRmTbneDIRgcKkATxtB7jHbrkVfT0PtLO1FuzsvR
|
||||||
|
+yY2RxS90P6tjXVUJnNE6uvMa5UFEJFGnTHgW8iQ8+EjPKDHM5nugSlojgZ88ujfm
|
||||||
|
+JNnDvbKZuDnd/iYx0ss6hPx7srXFL8/BT/9Ab1zURmnLsvfP34b7arnRsQIDAQAB
|
||||||
|
+AoGAJLR6xEJp+5IXRFlLn7WTkFvO0ddtxJ7bXhiIkTctyruyfqp7LF9Jv1G2m3PK
|
||||||
|
+QPUtBc73w/GYkfnwIwdfJbOmPHL7XyEGHZYmEXgIgEtw6LXvAv0G5JpUnNwsSBfL
|
||||||
|
+GfSQqI5Z5ytyzlJXkMcTGA2kTgNAYc73h4EnU+pwUnDPdAECQQD2aj+4LtYk1XPq
|
||||||
|
+r3gjgI6MoGvgYJfPmAtZhxxVbhXQKciFUCAcBiwlQdHIdLWE9j65ctmZRWidKifr
|
||||||
|
+4O4nz+TBAkEA3djNW/rTQq5fKZy+mCF1WYnIU/3yhJaptzRqLm7AHqe7+hdrGXJw
|
||||||
|
++mCtU8T3L/Ms8bH1yFBZhmkp1PbR8gl48QJAQo70YyWThiN5yfxXcQ96cZWrTdIJ
|
||||||
|
+b3NcLXSHPLQdhDqlBQ1dfvRT3ERpC8IqfZ2d162kBPhwh3MpkVcSPQK0gQJAC/dY
|
||||||
|
+xGBYKt2a9nSk9zG+0bCT5Kvq++ngh6hFHfINXNnxUsEWns3EeEzkrIMQTj7QqszN
|
||||||
|
+lBt5aL2dawZRNrv6EQJBAOo4STF9KEwQG0HLC/ryh1FeB0OBA5yIepXze+eJVKei
|
||||||
|
+T0cCECOQJKfWHEzYJYDJhyEFF/sYp9TXwKSDjOifrsU=
|
||||||
|
+-----END RSA PRIVATE KEY-----
|
||||||
|
diff --git a/test/certs/embeddedSCTs1_issuer.pem b/test/certs/embeddedSCTs1_issuer.pem
|
||||||
|
index 1fa449d..6aa9455 100644
|
||||||
|
--- a/test/certs/embeddedSCTs1_issuer.pem
|
||||||
|
+++ b/test/certs/embeddedSCTs1_issuer.pem
|
||||||
|
@@ -1,18 +1,18 @@
|
||||||
|
-----BEGIN CERTIFICATE-----
|
||||||
|
-MIIC0DCCAjmgAwIBAgIBADANBgkqhkiG9w0BAQUFADBVMQswCQYDVQQGEwJHQjEk
|
||||||
|
+MIIC0jCCAjugAwIBAgIBADANBgkqhkiG9w0BAQsFADBVMQswCQYDVQQGEwJHQjEk
|
||||||
|
MCIGA1UEChMbQ2VydGlmaWNhdGUgVHJhbnNwYXJlbmN5IENBMQ4wDAYDVQQIEwVX
|
||||||
|
-YWxlczEQMA4GA1UEBxMHRXJ3IFdlbjAeFw0xMjA2MDEwMDAwMDBaFw0yMjA2MDEw
|
||||||
|
-MDAwMDBaMFUxCzAJBgNVBAYTAkdCMSQwIgYDVQQKExtDZXJ0aWZpY2F0ZSBUcmFu
|
||||||
|
-c3BhcmVuY3kgQ0ExDjAMBgNVBAgTBVdhbGVzMRAwDgYDVQQHEwdFcncgV2VuMIGf
|
||||||
|
-MA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDVimhTYhCicRmTbneDIRgcKkATxtB7
|
||||||
|
-jHbrkVfT0PtLO1FuzsvRyY2RxS90P6tjXVUJnNE6uvMa5UFEJFGnTHgW8iQ8+EjP
|
||||||
|
-KDHM5nugSlojgZ88ujfmJNnDvbKZuDnd/iYx0ss6hPx7srXFL8/BT/9Ab1zURmnL
|
||||||
|
-svfP34b7arnRsQIDAQABo4GvMIGsMB0GA1UdDgQWBBRfnYgNyHPmVNT4DdjmsMEk
|
||||||
|
-tEfDVTB9BgNVHSMEdjB0gBRfnYgNyHPmVNT4DdjmsMEktEfDVaFZpFcwVTELMAkG
|
||||||
|
-A1UEBhMCR0IxJDAiBgNVBAoTG0NlcnRpZmljYXRlIFRyYW5zcGFyZW5jeSBDQTEO
|
||||||
|
-MAwGA1UECBMFV2FsZXMxEDAOBgNVBAcTB0VydyBXZW6CAQAwDAYDVR0TBAUwAwEB
|
||||||
|
-/zANBgkqhkiG9w0BAQUFAAOBgQAGCMxKbWTyIF4UbASydvkrDvqUpdryOvw4BmBt
|
||||||
|
-OZDQoeojPUApV2lGOwRmYef6HReZFSCa6i4Kd1F2QRIn18ADB8dHDmFYT9czQiRy
|
||||||
|
-f1HWkLxHqd81TbD26yWVXeGJPE3VICskovPkQNJ0tU4b03YmnKliibduyqQQkOFP
|
||||||
|
-OwqULg==
|
||||||
|
+YWxlczEQMA4GA1UEBxMHRXJ3IFdlbjAgFw0yMjA2MDExMDM4MDJaGA8yMTIyMDUw
|
||||||
|
+ODEwMzgwMlowVTELMAkGA1UEBhMCR0IxJDAiBgNVBAoTG0NlcnRpZmljYXRlIFRy
|
||||||
|
+YW5zcGFyZW5jeSBDQTEOMAwGA1UECBMFV2FsZXMxEDAOBgNVBAcTB0VydyBXZW4w
|
||||||
|
+gZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBANWKaFNiEKJxGZNud4MhGBwqQBPG
|
||||||
|
+0HuMduuRV9PQ+0s7UW7Oy9HJjZHFL3Q/q2NdVQmc0Tq68xrlQUQkUadMeBbyJDz4
|
||||||
|
+SM8oMczme6BKWiOBnzy6N+Yk2cO9spm4Od3+JjHSyzqE/HuytcUvz8FP/0BvXNRG
|
||||||
|
+acuy98/fhvtqudGxAgMBAAGjga8wgawwHQYDVR0OBBYEFF+diA3Ic+ZU1PgN2Oaw
|
||||||
|
+wSS0R8NVMH0GA1UdIwR2MHSAFF+diA3Ic+ZU1PgN2OawwSS0R8NVoVmkVzBVMQsw
|
||||||
|
+CQYDVQQGEwJHQjEkMCIGA1UEChMbQ2VydGlmaWNhdGUgVHJhbnNwYXJlbmN5IENB
|
||||||
|
+MQ4wDAYDVQQIEwVXYWxlczEQMA4GA1UEBxMHRXJ3IFdlboIBADAMBgNVHRMEBTAD
|
||||||
|
+AQH/MA0GCSqGSIb3DQEBCwUAA4GBAD0aYh9OkFYfXV7kBfhrtD0PJG2U47OV/1qq
|
||||||
|
++uFpqB0S1WO06eJT0pzYf1ebUcxjBkajbJZm/FHT85VthZ1lFHsky87aFD8XlJCo
|
||||||
|
+2IOhKOkvvWKPUdFLoO/ZVXqEVKkcsS1eXK1glFvb07eJZya3JVG0KdMhV2YoDg6c
|
||||||
|
+Doud4XrO
|
||||||
|
-----END CERTIFICATE-----
|
||||||
|
--
|
||||||
|
2.20.1 (Apple Git-117)
|
||||||
|
|
||||||
28
Backport-ct_test.c-Update-the-epoch-time.patch
Normal file
28
Backport-ct_test.c-Update-the-epoch-time.patch
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
From 7dbefac7fa259eee188017f6dbcfd11376fe6345 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Tomas Mraz <tomas@openssl.org>
|
||||||
|
Date: Wed, 1 Jun 2022 13:06:46 +0200
|
||||||
|
Subject: [PATCH 15/15] ct_test.c: Update the epoch time
|
||||||
|
|
||||||
|
Reviewed-by: Matt Caswell <matt@openssl.org>
|
||||||
|
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
|
||||||
|
(Merged from https://github.com/openssl/openssl/pull/18446)
|
||||||
|
---
|
||||||
|
test/ct_test.c | 2 +-
|
||||||
|
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||||
|
|
||||||
|
diff --git a/test/ct_test.c b/test/ct_test.c
|
||||||
|
index 78d11ca..535897d 100644
|
||||||
|
--- a/test/ct_test.c
|
||||||
|
+++ b/test/ct_test.c
|
||||||
|
@@ -63,7 +63,7 @@ static CT_TEST_FIXTURE *set_up(const char *const test_case_name)
|
||||||
|
if (!TEST_ptr(fixture = OPENSSL_zalloc(sizeof(*fixture))))
|
||||||
|
goto end;
|
||||||
|
fixture->test_case_name = test_case_name;
|
||||||
|
- fixture->epoch_time_in_ms = 1473269626000ULL; /* Sep 7 17:33:46 2016 GMT */
|
||||||
|
+ fixture->epoch_time_in_ms = 1580335307000ULL; /* Wed 29 Jan 2020 10:01:47 PM UTC */
|
||||||
|
if (!TEST_ptr(fixture->ctlog_store = CTLOG_STORE_new())
|
||||||
|
|| !TEST_int_eq(
|
||||||
|
CTLOG_STORE_load_default_file(fixture->ctlog_store), 1))
|
||||||
|
--
|
||||||
|
2.20.1 (Apple Git-117)
|
||||||
|
|
||||||
6353
Feature-Support-TLCP-protocol.patch
Normal file
6353
Feature-Support-TLCP-protocol.patch
Normal file
File diff suppressed because it is too large
Load Diff
25
openssl.spec
25
openssl.spec
@ -2,7 +2,7 @@
|
|||||||
Name: openssl
|
Name: openssl
|
||||||
Epoch: 1
|
Epoch: 1
|
||||||
Version: 1.1.1m
|
Version: 1.1.1m
|
||||||
Release: 2
|
Release: 3
|
||||||
Summary: Cryptography and SSL/TLS Toolkit
|
Summary: Cryptography and SSL/TLS Toolkit
|
||||||
License: OpenSSL and SSLeay
|
License: OpenSSL and SSLeay
|
||||||
URL: https://www.openssl.org/
|
URL: https://www.openssl.org/
|
||||||
@ -13,6 +13,22 @@ Patch2: openssl-1.1.1-fips.patch
|
|||||||
Patch3: CVE-2022-0778-Add-a-negative-testcase-for-BN_mod_sqrt.patch
|
Patch3: CVE-2022-0778-Add-a-negative-testcase-for-BN_mod_sqrt.patch
|
||||||
Patch4: CVE-2022-0778-Fix-possible-infinite-loop-in-BN_mod_sqrt.patch
|
Patch4: CVE-2022-0778-Fix-possible-infinite-loop-in-BN_mod_sqrt.patch
|
||||||
Patch5: CVE-2022-1292.patch
|
Patch5: CVE-2022-1292.patch
|
||||||
|
Patch6: Backport-Support-raw-input-data-in-apps-pkeyutl.patch
|
||||||
|
Patch7: Backport-Fix-no-ec-no-sm2-and-no-sm3.patch
|
||||||
|
Patch8: Backport-Support-SM2-certificate-verification.patch
|
||||||
|
Patch9: Backport-Guard-some-SM2-functions-with-OPENSSL_NO_SM2.patch
|
||||||
|
Patch10: Backport-Add-test-cases-for-SM2-cert-verification.patch
|
||||||
|
Patch11: Backport-Add-documents-for-SM2-cert-verification.patch
|
||||||
|
Patch12: Backport-Fix-a-memleak-in-apps-verify.patch
|
||||||
|
Patch13: Backport-Skip-the-correct-number-of-tests-if-SM2-is-disabled.patch
|
||||||
|
Patch14: Backport-Make-X509_set_sm2_id-consistent-with-other-setters.patch
|
||||||
|
Patch15: Backport-Support-SM2-certificate-signing.patch
|
||||||
|
Patch16: Backport-Support-parsing-of-SM2-ID-in-hexdecimal.patch
|
||||||
|
Patch17: Backport-Fix-a-double-free-issue-when-signing-SM2-cert.patch
|
||||||
|
Patch18: Backport-Fix-a-document-description-in-apps-req.patch
|
||||||
|
Patch19: Backport-Update-expired-SCT-certificates.patch
|
||||||
|
Patch20: Backport-ct_test.c-Update-the-epoch-time.patch
|
||||||
|
Patch21: Feature-Support-TLCP-protocol.patch
|
||||||
|
|
||||||
BuildRequires: gcc perl make lksctp-tools-devel coreutils util-linux zlib-devel
|
BuildRequires: gcc perl make lksctp-tools-devel coreutils util-linux zlib-devel
|
||||||
Requires: coreutils %{name}-libs%{?_isa} = %{epoch}:%{version}-%{release}
|
Requires: coreutils %{name}-libs%{?_isa} = %{epoch}:%{version}-%{release}
|
||||||
@ -75,7 +91,7 @@ RPM_OPT_FLAGS="$RPM_OPT_FLAGS -Wa,--noexecstack -DPURIFY $RPM_LD_FLAGS"
|
|||||||
zlib enable-camellia enable-seed enable-rfc3779 enable-sctp \
|
zlib enable-camellia enable-seed enable-rfc3779 enable-sctp \
|
||||||
enable-cms enable-md2 enable-rc5 enable-ssl3 enable-ssl3-method \
|
enable-cms enable-md2 enable-rc5 enable-ssl3 enable-ssl3-method \
|
||||||
enable-weak-ssl-ciphers \
|
enable-weak-ssl-ciphers \
|
||||||
no-mdc2 no-ec2m enable-sm2 enable-sm4 \
|
no-mdc2 no-ec2m enable-sm2 enable-sm3 enable-sm4 enable-tlcp \
|
||||||
shared ${sslarch} $RPM_OPT_FLAGS '-DDEVRANDOM="\"/dev/urandom\""'
|
shared ${sslarch} $RPM_OPT_FLAGS '-DDEVRANDOM="\"/dev/urandom\""'
|
||||||
|
|
||||||
%make_build all
|
%make_build all
|
||||||
@ -209,6 +225,11 @@ make test || :
|
|||||||
%ldconfig_scriptlets libs
|
%ldconfig_scriptlets libs
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Thu Jun 9 2022 shichuchao <shichuchao@huawei.com> - 1:1.1.1m-3
|
||||||
|
- support sm2 certificate sign and verify
|
||||||
|
- fix ct test errors
|
||||||
|
- add TLCP feature
|
||||||
|
|
||||||
* Mon May 16 2022 zhouchenchen <zhouchenchen@huawei.com> - 1:1.1.1m-2
|
* Mon May 16 2022 zhouchenchen <zhouchenchen@huawei.com> - 1:1.1.1m-2
|
||||||
- fix the CVE-2022-1292
|
- fix the CVE-2022-1292
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user