Skip to content

Commit 651ea3b

Browse files
committed
release 2.5.1: -S flag on p11keygen + bug fix for EC public key import
1 parent 684fae7 commit 651ea3b

File tree

4 files changed

+39
-37
lines changed

4 files changed

+39
-37
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7-
# Unreleased
7+
# [2.5.1]
88
- adding `-S` option flag for `p11keygen`, for enabling key generation when logged in as Security Officer (PR #33)
9+
- fixed a few memory management issues, preventing to import EC public keys when using `p11keygen`, `p11unwrap` and `p11importpubk`.
910

1011
# [2.5.0]
1112
### Added
@@ -127,6 +128,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
127128
### Added
128129
- Initial public release
129130

131+
[2.5.1]: https://github.com/Mastercard/pkcs11-tools/tree/v2.5.1
130132
[2.5.0]: https://github.com/Mastercard/pkcs11-tools/tree/v2.5.0
131133
[2.4.2]: https://github.com/Mastercard/pkcs11-tools/tree/v2.4.2
132134
[2.4.1]: https://github.com/Mastercard/pkcs11-tools/tree/v2.4.1

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ dnl limitations under the License.
1414

1515

1616
AC_PREREQ([2.64])
17-
AC_INIT([pkcs11-tools], [2.5.0], [https://github.com/Mastercard/pkcs11-tools/issues], [pkcs11-tools], [https://github.com/Mastercard/pkcs11-tools])
17+
AC_INIT([pkcs11-tools], [2.5.1], [https://github.com/Mastercard/pkcs11-tools/issues], [pkcs11-tools], [https://github.com/Mastercard/pkcs11-tools])
1818
AC_CONFIG_MACRO_DIR([m4])
1919

2020
dnl adding AM_MAINTAINER_MODE to address autotools issues with git

docs/INSTALL.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,11 @@ On previous FreeBSD versions, you will have to build it. Deploy first the OpenSS
134134
```bash
135135
$ pkg install openssl
136136
```
137-
Then proceed as with Linux.
137+
Then proceed as with Linux. Note that clang should be used instead of gcc.
138138

139139
If you had to install OpenSSL differently (e.g. older versions of FreeBSD), and if the path to OpenSSL libraries is not configured on the system, you need to specify an additional parameter (`LIBCRYPTO_RPATH`) when configuring the pkcs11-tools package, to set a run path to the libraries. See [rtld(1)](https://www.freebsd.org/cgi/man.cgi?query=rtld&apropos=0&sektion=1&manpath=FreeBSD+12.0-RELEASE&arch=default&format=html) for more information.
140140
```bash
141-
$ ./configure PKG_CONFIG_PATH=/opt/openssl-1.1.1/lib/pkgconfig LIBCRYPTO_RPATH=/opt/openssl-1.1.1/lib
141+
$ ./configure CC=clang PKG_CONFIG_PATH=/opt/openssl-1.1.1/lib/pkgconfig LIBCRYPTO_RPATH=/opt/openssl-1.1.1/lib
142142
$ make
143143
$ sudo make install
144144
```

lib/pkcs11_pubk.c

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ static CK_ULONG get_EC_point(EVP_PKEY *pubkey, CK_BYTE_PTR *buf)
453453
EC_KEY* ec=NULL;
454454
int i2dlen=0;
455455
unsigned char *octp = NULL, *octbuf = NULL;
456+
ASN1_OCTET_STRING *wrapped = NULL;
456457

457458
if ( pubkey && EVP_PKEY_base_id(pubkey)==EVP_PKEY_EC ) {
458459

@@ -508,7 +509,7 @@ static CK_ULONG get_EC_point(EVP_PKEY *pubkey, CK_BYTE_PTR *buf)
508509
/* DER-encoded of point in octbuf */
509510
/* now wrap this into OCTET_STRING */
510511

511-
ASN1_OCTET_STRING *wrapped = ASN1_OCTET_STRING_new();
512+
wrapped = ASN1_OCTET_STRING_new();
512513

513514
if(wrapped==NULL) {
514515
P_ERR();
@@ -551,6 +552,7 @@ static CK_ULONG get_EC_point(EVP_PKEY *pubkey, CK_BYTE_PTR *buf)
551552
}
552553
error:
553554
if(octbuf != NULL) { OPENSSL_free(octbuf); }
555+
if(wrapped != NULL) { ASN1_OCTET_STRING_free(wrapped); }
554556

555557
return rv;
556558
}
@@ -624,50 +626,50 @@ static CK_ULONG get_ED_point(EVP_PKEY *pubkey, CK_BYTE_PTR *buf)
624626

625627
const uint8_t *pk;
626628
int pklen;
627-
629+
628630
X509_PUBKEY_get0_param(NULL, &pk, &pklen, NULL, x509_pk); /* nothing to test, always returns 1 */
629631

630632
if( (point = ASN1_OCTET_STRING_new()) == NULL ) {
631633
P_ERR();
632634
goto error;
633635
}
634636
ASN1_OCTET_STRING_set(point, pk, pklen); /* assign */
635-
637+
636638
len = i2d_ASN1_OCTET_STRING(point, buf);
637639
if(len<0) {
638640
P_ERR();
639641
goto error;
640642
}
641643

642644
rv = len;
643-
645+
644646
error:
645647
if(point) { ASN1_OCTET_STRING_free(point); }
646648
if(x509_pk) { X509_PUBKEY_free(x509_pk); }
647-
if(pkeybuf) { OPENSSL_free(pkeybuf); }
649+
if(pkeybuf) { OPENSSL_free(pkeybuf); }
648650
return rv;
649651
}
650652

651653
static CK_ULONG get_ED_params(EVP_PKEY *pubkey, CK_BYTE_PTR *buf)
652654
{
653655
CK_ULONG rv = 0;
654656
ASN1_OBJECT *obj = NULL;
655-
657+
656658
obj = OBJ_nid2obj(EVP_PKEY_base_id(pubkey));
657659
if(!obj) {
658660
P_ERR();
659661
goto error;
660662
}
661663

662-
assert( *buf == NULL ); /* make sure we point to nowhere */
664+
assert( *buf == NULL ); /* make sure we point to nowhere */
663665
int len = i2d_ASN1_OBJECT(obj, buf);
664666
if(len<0) {
665667
P_ERR();
666668
goto error;
667669
}
668670

669671
rv = len;
670-
672+
671673
error:
672674
if(obj) { ASN1_OBJECT_free(obj); }
673675
return rv;
@@ -870,7 +872,6 @@ static CK_ULONG get_EVP_PKEY_sha1(EVP_PKEY *pubkey, CK_BYTE_PTR *buf) {
870872
}
871873
/* get0 on ec_point & ec_group, we can safely forget */
872874
}
873-
EC_KEY_free(ec);
874875
}
875876
}
876877
break;
@@ -904,7 +905,7 @@ static CK_ULONG get_EVP_PKEY_sha1(EVP_PKEY *pubkey, CK_BYTE_PTR *buf) {
904905
}
905906
}
906907
break;
907-
908+
908909

909910
case EVP_PKEY_DH: {
910911
DH *dh;
@@ -1043,7 +1044,7 @@ static CK_OBJECT_HANDLE _importpubk( pkcs11Context * p11Context,
10431044
{0L, NULL, 0L},
10441045
{0L, NULL, 0L},
10451046
};
1046-
1047+
10471048
size_t pubk_template_len_max = (sizeof(pubktemplate)/sizeof(CK_ATTRIBUTE));
10481049
size_t pubk_template_len_min = pubk_template_len_max - 12;
10491050
size_t pubk_num_elems = pubk_template_len_min;
@@ -1077,7 +1078,7 @@ static CK_OBJECT_HANDLE _importpubk( pkcs11Context * p11Context,
10771078
case CKA_VERIFY:
10781079
case CKA_VERIFY_RECOVER: /* not in template onwards */
10791080
case CKA_DERIVE:
1080-
case CKA_TRUSTED:
1081+
case CKA_TRUSTED:
10811082
case CKA_PRIVATE:
10821083
case CKA_WRAP_TEMPLATE:
10831084
case CKA_COPYABLE:
@@ -1089,7 +1090,7 @@ static CK_OBJECT_HANDLE _importpubk( pkcs11Context * p11Context,
10891090
case CKA_PUBLIC_KEY_INFO:
10901091
{
10911092
size_t next_pubk_num_elems = pubk_num_elems;
1092-
1093+
10931094
CK_ATTRIBUTE_PTR match = lsearch( &attrs[i],
10941095
pubktemplate,
10951096
&next_pubk_num_elems,
@@ -1108,7 +1109,7 @@ static CK_OBJECT_HANDLE _importpubk( pkcs11Context * p11Context,
11081109
else {
11091110
/* everything was copied by lsearch */
11101111
/* just increment array length */
1111-
pubk_num_elems = next_pubk_num_elems;
1112+
pubk_num_elems = next_pubk_num_elems;
11121113
}
11131114
} else {
11141115
fprintf(stderr, "***Error: can't update attribute array - skipping 0x%08lx\n", attrs[i].type);
@@ -1125,7 +1126,7 @@ static CK_OBJECT_HANDLE _importpubk( pkcs11Context * p11Context,
11251126
break;
11261127
}
11271128
}
1128-
1129+
11291130
retCode = p11Context->FunctionList.C_CreateObject(p11Context->Session,
11301131
pubktemplate,
11311132
pubk_num_elems,
@@ -1229,7 +1230,7 @@ static CK_OBJECT_HANDLE _importpubk( pkcs11Context * p11Context,
12291230
case CKA_VERIFY:
12301231
case CKA_VERIFY_RECOVER: /* not in template onwards */
12311232
case CKA_DERIVE:
1232-
case CKA_TRUSTED:
1233+
case CKA_TRUSTED:
12331234
case CKA_PRIVATE:
12341235
case CKA_COPYABLE:
12351236
case CKA_MODIFIABLE:
@@ -1240,7 +1241,7 @@ static CK_OBJECT_HANDLE _importpubk( pkcs11Context * p11Context,
12401241
case CKA_PUBLIC_KEY_INFO:
12411242
{
12421243
size_t next_pubk_num_elems = pubk_num_elems;
1243-
1244+
12441245
CK_ATTRIBUTE_PTR match = lsearch( &attrs[i],
12451246
pubktemplate,
12461247
&next_pubk_num_elems,
@@ -1259,7 +1260,7 @@ static CK_OBJECT_HANDLE _importpubk( pkcs11Context * p11Context,
12591260
else {
12601261
/* everything was copied by lsearch */
12611262
/* just increment array length */
1262-
pubk_num_elems = next_pubk_num_elems;
1263+
pubk_num_elems = next_pubk_num_elems;
12631264
}
12641265
} else {
12651266
fprintf(stderr, "***Error: can't update attribute array - skipping 0x%08lx\n", attrs[i].type);
@@ -1380,7 +1381,7 @@ static CK_OBJECT_HANDLE _importpubk( pkcs11Context * p11Context,
13801381
case CKA_PUBLIC_KEY_INFO:
13811382
{
13821383
size_t next_pubk_num_elems = pubk_num_elems;
1383-
1384+
13841385
CK_ATTRIBUTE_PTR match = lsearch( &attrs[i],
13851386
pubktemplate,
13861387
&next_pubk_num_elems,
@@ -1399,7 +1400,7 @@ static CK_OBJECT_HANDLE _importpubk( pkcs11Context * p11Context,
13991400
else {
14001401
/* everything was copied by lsearch */
14011402
/* just increment array length */
1402-
pubk_num_elems = next_pubk_num_elems;
1403+
pubk_num_elems = next_pubk_num_elems;
14031404
}
14041405
} else {
14051406
fprintf(stderr, "***Error: can't update attribute array - skipping 0x%08lx\n", attrs[i].type);
@@ -1416,7 +1417,7 @@ static CK_OBJECT_HANDLE _importpubk( pkcs11Context * p11Context,
14161417
break;
14171418
}
14181419
}
1419-
1420+
14201421
retCode = p11Context->FunctionList.C_CreateObject(p11Context->Session,
14211422
pubktemplate,
14221423
pubk_num_elems,
@@ -1500,7 +1501,7 @@ static CK_OBJECT_HANDLE _importpubk( pkcs11Context * p11Context,
15001501
case CKA_VERIFY:
15011502
case CKA_VERIFY_RECOVER: /* not in template onwards */
15021503
case CKA_DERIVE:
1503-
case CKA_TRUSTED:
1504+
case CKA_TRUSTED:
15041505
case CKA_PRIVATE:
15051506
case CKA_COPYABLE:
15061507
case CKA_MODIFIABLE:
@@ -1511,7 +1512,7 @@ static CK_OBJECT_HANDLE _importpubk( pkcs11Context * p11Context,
15111512
case CKA_PUBLIC_KEY_INFO:
15121513
{
15131514
size_t next_pubk_num_elems = pubk_num_elems;
1514-
1515+
15151516
CK_ATTRIBUTE_PTR match = lsearch( &attrs[i],
15161517
pubktemplate,
15171518
&next_pubk_num_elems,
@@ -1530,7 +1531,7 @@ static CK_OBJECT_HANDLE _importpubk( pkcs11Context * p11Context,
15301531
else {
15311532
/* everything was copied by lsearch */
15321533
/* just increment array length */
1533-
pubk_num_elems = next_pubk_num_elems;
1534+
pubk_num_elems = next_pubk_num_elems;
15341535
}
15351536
} else {
15361537
fprintf(stderr, "***Error: can't update attribute array - skipping 0x%08lx\n", attrs[i].type);
@@ -1547,7 +1548,7 @@ static CK_OBJECT_HANDLE _importpubk( pkcs11Context * p11Context,
15471548
break;
15481549
}
15491550
}
1550-
1551+
15511552
retCode = p11Context->FunctionList.C_CreateObject(p11Context->Session,
15521553
pubktemplate,
15531554
pubk_num_elems,
@@ -1595,9 +1596,9 @@ static CK_OBJECT_HANDLE _importpubk( pkcs11Context * p11Context,
15951596
{0L, NULL, 0L},
15961597
{0L, NULL, 0L},
15971598
{0L, NULL, 0L},
1598-
{0L, NULL, 0L},
15991599
{0L, NULL, 0L},
1600-
{0L, NULL, 0L},
1600+
{0L, NULL, 0L},
1601+
{0L, NULL, 0L},
16011602
};
16021603

16031604
size_t pubk_template_len_max = (sizeof(pubktemplate)/sizeof(CK_ATTRIBUTE));
@@ -1633,7 +1634,7 @@ static CK_OBJECT_HANDLE _importpubk( pkcs11Context * p11Context,
16331634
case CKA_VERIFY:
16341635
case CKA_VERIFY_RECOVER: /* not in template onwards */
16351636
case CKA_DERIVE:
1636-
case CKA_TRUSTED:
1637+
case CKA_TRUSTED:
16371638
case CKA_PRIVATE:
16381639
case CKA_WRAP_TEMPLATE:
16391640
case CKA_COPYABLE:
@@ -1645,7 +1646,7 @@ static CK_OBJECT_HANDLE _importpubk( pkcs11Context * p11Context,
16451646
case CKA_PUBLIC_KEY_INFO:
16461647
{
16471648
size_t next_pubk_num_elems = pubk_num_elems;
1648-
1649+
16491650
CK_ATTRIBUTE_PTR match = lsearch( &attrs[i],
16501651
pubktemplate,
16511652
&next_pubk_num_elems,
@@ -1664,7 +1665,7 @@ static CK_OBJECT_HANDLE _importpubk( pkcs11Context * p11Context,
16641665
else {
16651666
/* everything was copied by lsearch */
16661667
/* just increment array length */
1667-
pubk_num_elems = next_pubk_num_elems;
1668+
pubk_num_elems = next_pubk_num_elems;
16681669
}
16691670
} else {
16701671
fprintf(stderr, "***Error: can't update attribute array - skipping 0x%08lx\n", attrs[i].type);
@@ -1681,7 +1682,7 @@ static CK_OBJECT_HANDLE _importpubk( pkcs11Context * p11Context,
16811682
break;
16821683
}
16831684
}
1684-
1685+
16851686
retCode = p11Context->FunctionList.C_CreateObject(p11Context->Session,
16861687
pubktemplate,
16871688
pubk_num_elems,
@@ -1705,7 +1706,7 @@ static CK_OBJECT_HANDLE _importpubk( pkcs11Context * p11Context,
17051706
break;
17061707
}
17071708

1708-
OPENSSL_free(pubk);
1709+
EVP_PKEY_free(pubk);
17091710

17101711
}
17111712
return pubkhandle;
@@ -1734,4 +1735,3 @@ inline CK_OBJECT_HANDLE pkcs11_importpubk_from_buffer( pkcs11Context * p11Contex
17341735
CK_ULONG numattrs ) {
17351736
return _importpubk(p11Context, NULL, buffer, len, label, attrs, numattrs, source_buffer);
17361737
}
1737-

0 commit comments

Comments
 (0)