@@ -62,7 +62,6 @@ public final class SunPKCS11 extends AuthProvider {
62
62
private static final long serialVersionUID = -1354835039035306505L ;
63
63
64
64
static final Debug debug = Debug .getInstance ("sunpkcs11" );
65
-
66
65
// the PKCS11 object through which we make the native calls
67
66
final PKCS11 p11 ;
68
67
@@ -913,6 +912,25 @@ public Object run() {
913
912
createPoller ();
914
913
}
915
914
915
+ private static boolean isLegacy (CK_MECHANISM_INFO mechInfo )
916
+ throws PKCS11Exception {
917
+ // assume full support if no mech info available
918
+ // For vendor-specific mechanisms, often no mech info is provided
919
+ boolean partialSupport = false ;
920
+
921
+ if (mechInfo != null ) {
922
+ if ((mechInfo .flags & CKF_DECRYPT ) != 0 ) {
923
+ // non-legacy cipher mechs should support encryption
924
+ partialSupport |= ((mechInfo .flags & CKF_ENCRYPT ) == 0 );
925
+ }
926
+ if ((mechInfo .flags & CKF_VERIFY ) != 0 ) {
927
+ // non-legacy signature mechs should support signing
928
+ partialSupport |= ((mechInfo .flags & CKF_SIGN ) == 0 );
929
+ }
930
+ }
931
+ return partialSupport ;
932
+ }
933
+
916
934
// test if a token is present and initialize this provider for it if so.
917
935
// does nothing if no token is found
918
936
// called from constructor and by poller
@@ -946,24 +964,35 @@ private void initToken(CK_SLOT_INFO slotInfo) throws PKCS11Exception {
946
964
// return a CKM_DES_CBC_PAD.
947
965
final Map <Descriptor ,Integer > supportedAlgs =
948
966
new HashMap <Descriptor ,Integer >();
967
+
949
968
for (int i = 0 ; i < supportedMechanisms .length ; i ++) {
950
969
long longMech = supportedMechanisms [i ];
951
- boolean isEnabled = config . isEnabled (longMech );
970
+ CK_MECHANISM_INFO mechInfo = token . getMechanismInfo (longMech );
952
971
if (showInfo ) {
953
- CK_MECHANISM_INFO mechInfo =
954
- p11 .C_GetMechanismInfo (slotID , longMech );
955
972
System .out .println ("Mechanism " +
956
- Functions .getMechanismName (longMech ) + ":" );
957
- if (isEnabled == false ) {
973
+ Functions .getMechanismName (longMech ) + ":" );
974
+ System .out .println (mechInfo == null ?
975
+ (Constants .INDENT + "info n/a" ) :
976
+ mechInfo );
977
+ }
978
+ if (!config .isEnabled (longMech )) {
979
+ if (showInfo ) {
958
980
System .out .println ("DISABLED in configuration" );
959
981
}
960
- System . out . println ( mechInfo ) ;
982
+ continue ;
961
983
}
962
- if (isEnabled == false ) {
984
+ if (isLegacy (mechInfo )) {
985
+ if (showInfo ) {
986
+ System .out .println ("DISABLED due to legacy" );
987
+ }
963
988
continue ;
964
989
}
990
+
965
991
// we do not know of mechs with the upper 32 bits set
966
992
if (longMech >>> 32 != 0 ) {
993
+ if (showInfo ) {
994
+ System .out .println ("DISABLED due to unknown mech value" );
995
+ }
967
996
continue ;
968
997
}
969
998
int mech = (int )longMech ;
0 commit comments