question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Apache pulsar Encryption failed using ecdsa

See original GitHub issue

Trying to send encrypted messages from producer but got this exception:

org.apache.pulsar.client.api.PulsarClientException: java.util.concurrent.ExecutionException: org.apache.pulsar.client.api.PulsarClientException: java.lang.NoSuchMethodError: 'org.apache.pulsar.shade.io.netty.buffer.ByteBuf org.apache.pulsar.client.api.MessageCrypto.encrypt(java.util.Set, org.apache.pulsar.client.api.CryptoKeyReader, java.util.function.Supplier, org.apache.pulsar.shade.io.netty.buffer.ByteBuf)'
	at org.apache.pulsar.client.api.PulsarClientException.unwrap(PulsarClientException.java:719)
	at org.apache.pulsar.client.impl.ProducerBase.send(ProducerBase.java:117)
	at org.apache.pulsar.client.impl.TypedMessageBuilderImpl.send(TypedMessageBuilderImpl.java:89)
	at org.apache.pulsar.client.impl.ProducerBase.send(ProducerBase.java:63)
	at com.vz.vmb.PulsarProducer.main(PulsarProducer.java:59)
Caused by: java.util.concurrent.ExecutionException: org.apache.pulsar.client.api.PulsarClientException: java.lang.NoSuchMethodError: 'org.apache.pulsar.shade.io.netty.buffer.ByteBuf org.apache.pulsar.client.api.MessageCrypto.encrypt(java.util.Set, org.apache.pulsar.client.api.CryptoKeyReader, java.util.function.Supplier, org.apache.pulsar.shade.io.netty.buffer.ByteBuf)'
	at java.base/java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:395)
	at java.base/java.util.concurrent.CompletableFuture.get(CompletableFuture.java:1999)
	at org.apache.pulsar.client.impl.ProducerBase.send(ProducerBase.java:115)
	... 3 more
Caused by: org.apache.pulsar.client.api.PulsarClientException: java.lang.NoSuchMethodError: 'org.apache.pulsar.shade.io.netty.buffer.ByteBuf org.apache.pulsar.client.api.MessageCrypto.encrypt(java.util.Set, org.apache.pulsar.client.api.CryptoKeyReader, java.util.function.Supplier, org.apache.pulsar.shade.io.netty.buffer.ByteBuf)'
	at org.apache.pulsar.client.impl.ProducerImpl.sendAsync(ProducerImpl.java:477)
	at org.apache.pulsar.client.impl.ProducerImpl.internalSendAsync(ProducerImpl.java:269)
	at org.apache.pulsar.client.impl.ProducerBase.send(ProducerBase.java:108)
	... 3 more
Caused by: java.lang.NoSuchMethodError: 'org.apache.pulsar.shade.io.netty.buffer.ByteBuf org.apache.pulsar.client.api.MessageCrypto.encrypt(java.util.Set, org.apache.pulsar.client.api.CryptoKeyReader, java.util.function.Supplier, org.apache.pulsar.shade.io.netty.buffer.ByteBuf)'
	at org.apache.pulsar.client.impl.ProducerImpl.encryptMessage(ProducerImpl.java:567)
	at org.apache.pulsar.client.impl.ProducerImpl.sendAsync(ProducerImpl.java:446)
	... 5 more

--------------------------------------------------------------------------------------------------
Followed the Encryption from the apache pulsar documentation and the sampleProducerConsumerTest class from pulsar client.
Generated a public key and the private key 
created a Pulsarclient object
--------------------------------------------------------------------------------------------------
client = PulsarClient.builder()
					.serviceUrl("pulsar+ssl:xxxxxxxxxxxxxxxxx:6651/")
					.tlsTrustCertsFilePath("src/main/resources/ca.cert.pem")
					.enableTls(true)
					.authentication("org.apache.pulsar.client.impl.auth.AuthenticationTls", authParams).build();

Producer<byte[]> producer = client.newProducer()
					.topic("persistent://tenant/namespace/nonprod-topic-1")
					.cryptoKeyReader(new RawFileKeyReader("src/main/resources/test_ecdsa_pubkey.pem", "src/main/resources/test_ecdsa_privkey.pem"))
					.addEncryptionKey("src/main/resources/test_ecdsa_pubkey.pem")
					.enableBatching(false)
					.create();

String message = "Test Messages";
			int i = 2;
			while(true) {
				i = i + 1;
				message = message + " Mesage # " + i;

				producer.send(message.getBytes());
				System.out.println("Printing the Messages " + message);
				producer.flush();
				if (i == 100) {
					break;
				}
			}
			producer.close();
			client.close();

To Reproduce Steps to reproduce the behavior:

1. Go to ' create a producer class in java. add the serviceUrl, generate public key, generate private key, use certificates for tls authentication, and make the topic as encryption enabled'
2. Click on ' run the sample producer'
3. Scroll down to ' console'
4. See error 
'org.apache.pulsar.client.api.PulsarClientException: java.util.concurrent.ExecutionException: org.apache.pulsar.client.api.PulsarClientException: java.lang.NoSuchMethodError: 'org.apache.pulsar.shade.io.netty.buffer.ByteBuf org.apache.pulsar.client.api.MessageCrypto.encrypt(java.util.Set, org.apache.pulsar.client.api.CryptoKeyReader, java.util.function.Supplier, org.apache.pulsar.shade.io.netty.buffer.ByteBuf)'

Expected behavior send message encrypted messages using ecdsa public key and private key,

Desktop (please complete the following information):

  • OS: [e.g. iOS] : I am using macOs Mojave version(10.14.6) -Pulsar-client version: 2.5.1

Additional context here are my dependecies i used

<dependency>
			<groupId>org.apache.pulsar</groupId>
			<artifactId>pulsar-io-netty</artifactId>
			<version>2.5.1</version>
		</dependency>
		<dependency>
			<groupId>org.apache.pulsar</groupId>
			<artifactId>pulsar-client-messagecrypto-bc</artifactId>
			<version>2.5.1</version>
		</dependency>
		
		<dependency>
			<groupId>org.apache.pulsar</groupId>
			<artifactId>pulsar-client</artifactId>
			<version>2.5.1</version>
		</dependency>
		<dependency>
			<groupId>org.apache.pulsar</groupId>
			<artifactId>pulsar-client-admin</artifactId>
			<version>2.5.1</version>
		</dependency>

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:20 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
trexinccommented, Apr 28, 2020

Not sure how you got those errors. With 2.5.1 I get: Class not found for org.apache.pulsar.client.impl.crypto.MessageCryptoBc Which can be resolved by adding the following dependency compile group: ‘org.apache.pulsar’, name: ‘pulsar-client-messagecrypto-bc’, version: ‘2.5.1’

0reactions
jiazhaicommented, Dec 15, 2020

@nhathatrinh The PR #8850 is merged, I would like to close this issue. Thanks for @RobertIndie 's help

Read more comments on GitHub >

github_iconTop Results From Across the Web

[GitHub] [pulsar] RobertIndie edited a comment on issue #6834 ...
... [pulsar] RobertIndie edited a comment on issue #6834: Apache pulsar Encryption failed using ecdsa ... I am having a same issue with...
Read more >
End-to-End Encryption - Apache Pulsar
Applications can use Pulsar end-to-end encryption (E2EE) to encrypt messages on the producer side and decrypt messages on the consumer side.
Read more >
安全 - End-to-End Encryption - 《Apache Pulsar v2.3.2 中文文档 ...
Pulsar 使用动态生成的AES秘钥来加密消息(数据)。 The AES key(data key) is encrypted using application provided ECDSA/RSA key pair, as a result there is no need to ...
Read more >
Multi-Tenancy Systems: Apache Pulsar vs. Kafka | Medium
The client applications use an asymmetric ECDSA and RSA key pair to encrypt and decrypt the AES data key. Security context setup for...
Read more >
Examples with CryptoKeyReader - org.apache.pulsar.client.api ...
the class V1_ProducerConsumerTest method testECDSAEncryption. @Test(groups = "encryption") public void testECDSAEncryption() throws Exception ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found