@@ -453,6 +453,7 @@ static CK_ULONG get_EC_point(EVP_PKEY *pubkey, CK_BYTE_PTR *buf)
453
453
EC_KEY * ec = NULL ;
454
454
int i2dlen = 0 ;
455
455
unsigned char * octp = NULL , * octbuf = NULL ;
456
+ ASN1_OCTET_STRING * wrapped = NULL ;
456
457
457
458
if ( pubkey && EVP_PKEY_base_id (pubkey )== EVP_PKEY_EC ) {
458
459
@@ -508,7 +509,7 @@ static CK_ULONG get_EC_point(EVP_PKEY *pubkey, CK_BYTE_PTR *buf)
508
509
/* DER-encoded of point in octbuf */
509
510
/* now wrap this into OCTET_STRING */
510
511
511
- ASN1_OCTET_STRING * wrapped = ASN1_OCTET_STRING_new ();
512
+ wrapped = ASN1_OCTET_STRING_new ();
512
513
513
514
if (wrapped == NULL ) {
514
515
P_ERR ();
@@ -551,6 +552,7 @@ static CK_ULONG get_EC_point(EVP_PKEY *pubkey, CK_BYTE_PTR *buf)
551
552
}
552
553
error :
553
554
if (octbuf != NULL ) { OPENSSL_free (octbuf ); }
555
+ if (wrapped != NULL ) { ASN1_OCTET_STRING_free (wrapped ); }
554
556
555
557
return rv ;
556
558
}
@@ -624,50 +626,50 @@ static CK_ULONG get_ED_point(EVP_PKEY *pubkey, CK_BYTE_PTR *buf)
624
626
625
627
const uint8_t * pk ;
626
628
int pklen ;
627
-
629
+
628
630
X509_PUBKEY_get0_param (NULL , & pk , & pklen , NULL , x509_pk ); /* nothing to test, always returns 1 */
629
631
630
632
if ( (point = ASN1_OCTET_STRING_new ()) == NULL ) {
631
633
P_ERR ();
632
634
goto error ;
633
635
}
634
636
ASN1_OCTET_STRING_set (point , pk , pklen ); /* assign */
635
-
637
+
636
638
len = i2d_ASN1_OCTET_STRING (point , buf );
637
639
if (len < 0 ) {
638
640
P_ERR ();
639
641
goto error ;
640
642
}
641
643
642
644
rv = len ;
643
-
645
+
644
646
error :
645
647
if (point ) { ASN1_OCTET_STRING_free (point ); }
646
648
if (x509_pk ) { X509_PUBKEY_free (x509_pk ); }
647
- if (pkeybuf ) { OPENSSL_free (pkeybuf ); }
649
+ if (pkeybuf ) { OPENSSL_free (pkeybuf ); }
648
650
return rv ;
649
651
}
650
652
651
653
static CK_ULONG get_ED_params (EVP_PKEY * pubkey , CK_BYTE_PTR * buf )
652
654
{
653
655
CK_ULONG rv = 0 ;
654
656
ASN1_OBJECT * obj = NULL ;
655
-
657
+
656
658
obj = OBJ_nid2obj (EVP_PKEY_base_id (pubkey ));
657
659
if (!obj ) {
658
660
P_ERR ();
659
661
goto error ;
660
662
}
661
663
662
- assert ( * buf == NULL ); /* make sure we point to nowhere */
664
+ assert ( * buf == NULL ); /* make sure we point to nowhere */
663
665
int len = i2d_ASN1_OBJECT (obj , buf );
664
666
if (len < 0 ) {
665
667
P_ERR ();
666
668
goto error ;
667
669
}
668
670
669
671
rv = len ;
670
-
672
+
671
673
error :
672
674
if (obj ) { ASN1_OBJECT_free (obj ); }
673
675
return rv ;
@@ -870,7 +872,6 @@ static CK_ULONG get_EVP_PKEY_sha1(EVP_PKEY *pubkey, CK_BYTE_PTR *buf) {
870
872
}
871
873
/* get0 on ec_point & ec_group, we can safely forget */
872
874
}
873
- EC_KEY_free (ec );
874
875
}
875
876
}
876
877
break ;
@@ -904,7 +905,7 @@ static CK_ULONG get_EVP_PKEY_sha1(EVP_PKEY *pubkey, CK_BYTE_PTR *buf) {
904
905
}
905
906
}
906
907
break ;
907
-
908
+
908
909
909
910
case EVP_PKEY_DH : {
910
911
DH * dh ;
@@ -1043,7 +1044,7 @@ static CK_OBJECT_HANDLE _importpubk( pkcs11Context * p11Context,
1043
1044
{0L , NULL , 0L },
1044
1045
{0L , NULL , 0L },
1045
1046
};
1046
-
1047
+
1047
1048
size_t pubk_template_len_max = (sizeof (pubktemplate )/sizeof (CK_ATTRIBUTE ));
1048
1049
size_t pubk_template_len_min = pubk_template_len_max - 12 ;
1049
1050
size_t pubk_num_elems = pubk_template_len_min ;
@@ -1077,7 +1078,7 @@ static CK_OBJECT_HANDLE _importpubk( pkcs11Context * p11Context,
1077
1078
case CKA_VERIFY :
1078
1079
case CKA_VERIFY_RECOVER : /* not in template onwards */
1079
1080
case CKA_DERIVE :
1080
- case CKA_TRUSTED :
1081
+ case CKA_TRUSTED :
1081
1082
case CKA_PRIVATE :
1082
1083
case CKA_WRAP_TEMPLATE :
1083
1084
case CKA_COPYABLE :
@@ -1089,7 +1090,7 @@ static CK_OBJECT_HANDLE _importpubk( pkcs11Context * p11Context,
1089
1090
case CKA_PUBLIC_KEY_INFO :
1090
1091
{
1091
1092
size_t next_pubk_num_elems = pubk_num_elems ;
1092
-
1093
+
1093
1094
CK_ATTRIBUTE_PTR match = lsearch ( & attrs [i ],
1094
1095
pubktemplate ,
1095
1096
& next_pubk_num_elems ,
@@ -1108,7 +1109,7 @@ static CK_OBJECT_HANDLE _importpubk( pkcs11Context * p11Context,
1108
1109
else {
1109
1110
/* everything was copied by lsearch */
1110
1111
/* just increment array length */
1111
- pubk_num_elems = next_pubk_num_elems ;
1112
+ pubk_num_elems = next_pubk_num_elems ;
1112
1113
}
1113
1114
} else {
1114
1115
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,
1125
1126
break ;
1126
1127
}
1127
1128
}
1128
-
1129
+
1129
1130
retCode = p11Context -> FunctionList .C_CreateObject (p11Context -> Session ,
1130
1131
pubktemplate ,
1131
1132
pubk_num_elems ,
@@ -1229,7 +1230,7 @@ static CK_OBJECT_HANDLE _importpubk( pkcs11Context * p11Context,
1229
1230
case CKA_VERIFY :
1230
1231
case CKA_VERIFY_RECOVER : /* not in template onwards */
1231
1232
case CKA_DERIVE :
1232
- case CKA_TRUSTED :
1233
+ case CKA_TRUSTED :
1233
1234
case CKA_PRIVATE :
1234
1235
case CKA_COPYABLE :
1235
1236
case CKA_MODIFIABLE :
@@ -1240,7 +1241,7 @@ static CK_OBJECT_HANDLE _importpubk( pkcs11Context * p11Context,
1240
1241
case CKA_PUBLIC_KEY_INFO :
1241
1242
{
1242
1243
size_t next_pubk_num_elems = pubk_num_elems ;
1243
-
1244
+
1244
1245
CK_ATTRIBUTE_PTR match = lsearch ( & attrs [i ],
1245
1246
pubktemplate ,
1246
1247
& next_pubk_num_elems ,
@@ -1259,7 +1260,7 @@ static CK_OBJECT_HANDLE _importpubk( pkcs11Context * p11Context,
1259
1260
else {
1260
1261
/* everything was copied by lsearch */
1261
1262
/* just increment array length */
1262
- pubk_num_elems = next_pubk_num_elems ;
1263
+ pubk_num_elems = next_pubk_num_elems ;
1263
1264
}
1264
1265
} else {
1265
1266
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,
1380
1381
case CKA_PUBLIC_KEY_INFO :
1381
1382
{
1382
1383
size_t next_pubk_num_elems = pubk_num_elems ;
1383
-
1384
+
1384
1385
CK_ATTRIBUTE_PTR match = lsearch ( & attrs [i ],
1385
1386
pubktemplate ,
1386
1387
& next_pubk_num_elems ,
@@ -1399,7 +1400,7 @@ static CK_OBJECT_HANDLE _importpubk( pkcs11Context * p11Context,
1399
1400
else {
1400
1401
/* everything was copied by lsearch */
1401
1402
/* just increment array length */
1402
- pubk_num_elems = next_pubk_num_elems ;
1403
+ pubk_num_elems = next_pubk_num_elems ;
1403
1404
}
1404
1405
} else {
1405
1406
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,
1416
1417
break ;
1417
1418
}
1418
1419
}
1419
-
1420
+
1420
1421
retCode = p11Context -> FunctionList .C_CreateObject (p11Context -> Session ,
1421
1422
pubktemplate ,
1422
1423
pubk_num_elems ,
@@ -1500,7 +1501,7 @@ static CK_OBJECT_HANDLE _importpubk( pkcs11Context * p11Context,
1500
1501
case CKA_VERIFY :
1501
1502
case CKA_VERIFY_RECOVER : /* not in template onwards */
1502
1503
case CKA_DERIVE :
1503
- case CKA_TRUSTED :
1504
+ case CKA_TRUSTED :
1504
1505
case CKA_PRIVATE :
1505
1506
case CKA_COPYABLE :
1506
1507
case CKA_MODIFIABLE :
@@ -1511,7 +1512,7 @@ static CK_OBJECT_HANDLE _importpubk( pkcs11Context * p11Context,
1511
1512
case CKA_PUBLIC_KEY_INFO :
1512
1513
{
1513
1514
size_t next_pubk_num_elems = pubk_num_elems ;
1514
-
1515
+
1515
1516
CK_ATTRIBUTE_PTR match = lsearch ( & attrs [i ],
1516
1517
pubktemplate ,
1517
1518
& next_pubk_num_elems ,
@@ -1530,7 +1531,7 @@ static CK_OBJECT_HANDLE _importpubk( pkcs11Context * p11Context,
1530
1531
else {
1531
1532
/* everything was copied by lsearch */
1532
1533
/* just increment array length */
1533
- pubk_num_elems = next_pubk_num_elems ;
1534
+ pubk_num_elems = next_pubk_num_elems ;
1534
1535
}
1535
1536
} else {
1536
1537
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,
1547
1548
break ;
1548
1549
}
1549
1550
}
1550
-
1551
+
1551
1552
retCode = p11Context -> FunctionList .C_CreateObject (p11Context -> Session ,
1552
1553
pubktemplate ,
1553
1554
pubk_num_elems ,
@@ -1595,9 +1596,9 @@ static CK_OBJECT_HANDLE _importpubk( pkcs11Context * p11Context,
1595
1596
{0L , NULL , 0L },
1596
1597
{0L , NULL , 0L },
1597
1598
{0L , NULL , 0L },
1598
- {0L , NULL , 0L },
1599
1599
{0L , NULL , 0L },
1600
- {0L , NULL , 0L },
1600
+ {0L , NULL , 0L },
1601
+ {0L , NULL , 0L },
1601
1602
};
1602
1603
1603
1604
size_t pubk_template_len_max = (sizeof (pubktemplate )/sizeof (CK_ATTRIBUTE ));
@@ -1633,7 +1634,7 @@ static CK_OBJECT_HANDLE _importpubk( pkcs11Context * p11Context,
1633
1634
case CKA_VERIFY :
1634
1635
case CKA_VERIFY_RECOVER : /* not in template onwards */
1635
1636
case CKA_DERIVE :
1636
- case CKA_TRUSTED :
1637
+ case CKA_TRUSTED :
1637
1638
case CKA_PRIVATE :
1638
1639
case CKA_WRAP_TEMPLATE :
1639
1640
case CKA_COPYABLE :
@@ -1645,7 +1646,7 @@ static CK_OBJECT_HANDLE _importpubk( pkcs11Context * p11Context,
1645
1646
case CKA_PUBLIC_KEY_INFO :
1646
1647
{
1647
1648
size_t next_pubk_num_elems = pubk_num_elems ;
1648
-
1649
+
1649
1650
CK_ATTRIBUTE_PTR match = lsearch ( & attrs [i ],
1650
1651
pubktemplate ,
1651
1652
& next_pubk_num_elems ,
@@ -1664,7 +1665,7 @@ static CK_OBJECT_HANDLE _importpubk( pkcs11Context * p11Context,
1664
1665
else {
1665
1666
/* everything was copied by lsearch */
1666
1667
/* just increment array length */
1667
- pubk_num_elems = next_pubk_num_elems ;
1668
+ pubk_num_elems = next_pubk_num_elems ;
1668
1669
}
1669
1670
} else {
1670
1671
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,
1681
1682
break ;
1682
1683
}
1683
1684
}
1684
-
1685
+
1685
1686
retCode = p11Context -> FunctionList .C_CreateObject (p11Context -> Session ,
1686
1687
pubktemplate ,
1687
1688
pubk_num_elems ,
@@ -1705,7 +1706,7 @@ static CK_OBJECT_HANDLE _importpubk( pkcs11Context * p11Context,
1705
1706
break ;
1706
1707
}
1707
1708
1708
- OPENSSL_free (pubk );
1709
+ EVP_PKEY_free (pubk );
1709
1710
1710
1711
}
1711
1712
return pubkhandle ;
@@ -1734,4 +1735,3 @@ inline CK_OBJECT_HANDLE pkcs11_importpubk_from_buffer( pkcs11Context * p11Contex
1734
1735
CK_ULONG numattrs ) {
1735
1736
return _importpubk (p11Context , NULL , buffer , len , label , attrs , numattrs , source_buffer );
1736
1737
}
1737
-
0 commit comments