z-kovacs commented on code in PR #20542:
URL: https://github.com/apache/pulsar/pull/20542#discussion_r1229305769


##########
bouncy-castle/bc-common/src/main/java/org/apache/pulsar/client/impl/crypto/BcVersionSpecificCryptoUtility.java:
##########
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.client.impl.crypto;
+
+import static 
org.apache.pulsar.client.impl.crypto.BcVersionSpecificCryptoUtilityFactory.createNewInstance;
+import java.security.PrivateKey;
+import java.security.PublicKey;
+import java.util.Optional;
+import javax.crypto.SecretKey;
+import org.apache.pulsar.client.api.PulsarClientException;
+
+/**
+ * Facade to various crypto functions implemented by BouncyCastle FIPS and 
Non-fips module.
+ */
+public interface BcVersionSpecificCryptoUtility {
+
+    BcVersionSpecificCryptoUtility INSTANCE = createNewInstance();
+
+    String RSA = "RSA";
+
+    // Ideally the transformation should also be part of the message property. 
This will prevent client
+    // from assuming hardcoded value. However, it will increase the size of 
the message even further.
+    String RSA_TRANS = "RSA/NONE/OAEPWithSHA1AndMGF1Padding";
+
+
+    byte[] encryptDataKey(String logCtx, String keyName, PublicKey publicKey, 
SecretKey dataKey)
+            throws PulsarClientException.CryptoException;
+
+    Optional<SecretKey> deCryptDataKey(String datakeyAlgorithm, String logCtx, 
String keyName, PrivateKey privateKey,
+                                       byte[] encryotedDataKey);

Review Comment:
   fixed



##########
bouncy-castle/bc-common/src/test/java/org/apache/pulsar/client/impl/crypto/WrappingVersusEncryptionCrossCompatibilityTestBase.java:
##########
@@ -0,0 +1,236 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.client.impl.crypto;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.testng.AssertJUnit.assertEquals;
+import com.google.common.collect.ImmutableMap;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Paths;
+import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
+import java.security.PrivateKey;
+import java.security.PublicKey;
+import java.security.spec.InvalidKeySpecException;
+import java.util.Optional;
+import javax.crypto.KeyGenerator;
+import javax.crypto.SecretKey;
+import javax.crypto.SecretKeyFactory;
+import javax.crypto.spec.SecretKeySpec;
+import org.apache.commons.io.FileUtils;
+import org.apache.pulsar.client.api.PulsarClientException;
+import org.apache.pulsar.common.util.SecurityUtility;
+import org.hamcrest.Matcher;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+public abstract class WrappingVersusEncryptionCrossCompatibilityTestBase {
+
+    //from https://stackoverflow.com/a/140861
+    //TODO use java.format.HexFormat after we move to java17 language features
+    protected static byte[] hexStringToByteArray(String s/* s must be an 
even-length string. */) {
+        int len = s.length();
+        byte[] data = new byte[len / 2];
+        for (int i = 0; i < len; i += 2) {
+            data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4)
+                    + Character.digit(s.charAt(i + 1), 16));
+        }
+        return data;
+    }
+
+    //from https://stackoverflow.com/a/9855338
+    private static final byte[] HEX_ARRAY = 
"0123456789ABCDEF".getBytes(StandardCharsets.US_ASCII);
+
+    //TODO use java.format.HexFormat after we move to java17 language features
+    protected static String bytesToHex(byte[] bytes) {
+        byte[] hexChars = new byte[bytes.length * 2];

Review Comment:
   good shout, fixed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to