Skip to content

Commit

Permalink
Exclude CKF_EC_OID
Browse files Browse the repository at this point in the history
  • Loading branch information
edewata committed Jan 16, 2024
1 parent e3266ff commit 2c2f044
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
7 changes: 7 additions & 0 deletions src/main/java/org/mozilla/jss/pkcs11/PKCS11Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -4955,6 +4955,13 @@ public interface PKCS11Constants {
*/
public static final long CKF_EC_OID = 0x00800000L;

/**
* Content automatically generated; see NSS documentation for more information.
*
* Source file: /usr/include/nss3/pkcs11t.h
*/
public static final long CKF_EC_NAMEDCURVE = 0x00800000L;

/**
* Content automatically generated; see NSS documentation for more information.
*
Expand Down
24 changes: 20 additions & 4 deletions src/test/java/org/mozilla/jss/tests/TestPKCS11Constants.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
package org.mozilla.jss.tests;

import java.lang.reflect.*;
import java.util.*;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;

public class TestPKCS11Constants {

public static Set<String> EXCLUDE = new HashSet<>(Arrays.asList(
// The following constants are defined differently in NSS and OpenJDK
// so they cannot be compared.
// https://github.com/nss-dev/nss/blob/main/lib/util/pkcs11t.h#L1308
// https://github.com/openjdk/jdk/blob/master/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/wrapper/PKCS11Constants.java#L1045
"CKF_EC_OID",
"CKF_EC_NAMEDCURVE"
));

/**
* This test compares the value of the PKCS11Constants that is maintained
* by JSS against the values maintained by Sun in the equivalent methods.
Expand All @@ -13,8 +26,8 @@ public class TestPKCS11Constants {
*/
public static void main(String[] args) throws Exception {
// Query the two classes to get references to their definitions.
Class jss = Class.forName("org.mozilla.jss.pkcs11.PKCS11Constants");
Class sun = Class.forName("sun.security.pkcs11.wrapper.PKCS11Constants");
Class<?> jss = Class.forName("org.mozilla.jss.pkcs11.PKCS11Constants");
Class<?> sun = Class.forName("sun.security.pkcs11.wrapper.PKCS11Constants");

assert(!jss.equals(sun));

Expand Down Expand Up @@ -44,6 +57,9 @@ public static void main(String[] args) throws Exception {
Arrays.sort(keys_sorted);

for (String key : keys_sorted) {

if (EXCLUDE.contains(key)) continue;

// If the field is present in both, validate that the value
// is the same across JSS and Sun implementation. Otherwise,
// output which implementation it is present in.
Expand Down
3 changes: 1 addition & 2 deletions tools/build_pkcs11_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
'CK_CALLBACK_FUNCTION',
'CK_DECLARE_FUNCTION',
'CK_DECLARE_FUNCTION_POINTER',
'CK_UNAVAILABLE_INFORMATION',
'CKF_EC_NAMEDCURVE' # deprecated in PKCS #11 3.0
'CK_UNAVAILABLE_INFORMATION'
]

logger = logging.getLogger(__name__)
Expand Down

0 comments on commit 2c2f044

Please sign in to comment.