Currently I am adding ca filepath into my mqtt server. To consume or publish I need to add this certificate into nifi processor, but I could not find any option for adding certicate in nifi.
So I tried to add one certificate property, but throwing error.
#Chintamani You should import your certs into keystore or truststore for your SSL Context Service.
For Example:
/usr/jdk64/jdk1.8.0_112/bin/keytool -import -file certificate.cer -alias nifi -keystore truststore.jks
/usr/jdk64/jdk1.8.0_112/bin/keytool -import -trustcacerts -alias nifi -file certificate.cer -keystore keystore.jks
I usually put the files in /etc/nifi/ssl/ and be sure to chown them to nifi:nifi. Then in your controller service, put the path to the files, the type (JKS), the password.
https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-ssl-context-service-nar/1.5.0/org.apache.nifi.ssl.StandardRestrictedSSLContextService/index.html
You can't provide the certificate file to Nifi directly. You'll need to create a keystore or truststore that contains your certificate or a certificate higher in the certification path. For instance, if certificate A signed certificate B and certificate B signed your certificate, you could add certificate A or B or your certificate to a truststore. Let's say you used LetsEncrypt.org to sign your certificate. You could browse to LetsEncrypt.org and download their certificate and add that to your truststore. Once you have the certificate file, you can add it to an existing truststore or create a new one in one command using the Java Keytool (available with a JDK or JRE):
keytool -import -alias YOUR_ALIAS -file CERTIFICATE_FILE -storetype TYPE -keystore MY_TRUST_STORE_FILE
For Example:
keytool -import -alias Chintamani_Alias -file Chintamani.cer -storetype JKS -keystore Chintamani.truststore
This command will create Chintamani.truststore with the password you provide if the file doesn't already exist. Then you provide the path to the truststore, the truststore password and set the truststore type (JKS in the example above).
And make sure:
Your MQTT processor is using ssl:// in the Broker Uri
Your StandardSSLContextService or StandardRestrictedSSLContextService is enabled
Your MQTT processor is configured to use your SSL Context Service
or you might see errors like:
o.a.nifi.processors.mqtt.ConsumeMQTT ConsumeMQTT[id=<GUID>] Connection to <YOUR URL>:8883 lost (or was never connected) and connection failed. Yielding processor: java.net.SocketException: Connection reset
? causes: Connection lost (32109) - java.net.SocketException: Connection reset
org.eclipse.paho.client.mqttv3.MqttException: Connection lost
at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:190)
Related
I want to use SSL on my server, therefore I have bout an SSL certificate, however the certificate had two parts one of them is the intermediate.
Now how to create the keystore for them?
What I did is the following:
1- chained both certificates and put them in one file.
2- I have usedd the next command to generate the keystore from the (chained certificate)
keytool -import -alias tomcat -file myCertificate.crt -keystore keystore.p12 -storepass password
3- I have add this code into my spring boot:
server.ssl.key-store: C:/Program Files/Java/jdk1.8.0_231/bin/keystore.p12
server.ssl.key-store-password: password
server.ssl.keyStoreType: PKCS12
server.ssl.keyAlias: tomcat
But I am still having the next issue:
'Alias name [tomcat] does not identify a key entry'
From looking into google I have found out that the issu is my keystore is generating my certificate as trustedCertEntry instead of PrivateKeyEntry.
How to fix this and what am I missing?
I've a web server running on an ec2-instance which internally calls a REST server that is built using Spring Boot. Now, I am trying to get this REST server running under SSL. Here's what I've done so far:
1) Created a CSR & a key file using this command
openssl req -newkey rsa:2048 -nodes -keyout mydomain.key -out mydomain.csr
2) Copied 'csr' to get SSL certificate from GoDaddy.
3) Successfully installed the certificate under Nginx on my ec2-instance.
4) When I hit the home page under https, it works. I no longer get 'Not secure' message from the browser.
5) Login fails because it makes a REST call but REST server is not running under SSL so I am trying to get it running under SSL.
6) Ran following commands:
keytool -import -alias mydomain -keystore tomcat.keystore -trustcacerts -file mydomain.com.chained.crt
keytool -import -alias mydomain-key -keystore tomcat.keystore -trustcacerts -file mydomain.key
The previous command gives me an error message:
"keytool error: java.lang.Exception: Input not an X.509 certificate"
But this was the one created in step 1 above & the same file works under Nginx. What am I missing (other than the fact that I know very little about setting up SSLs!)? I need the second command to specify the value of 'server.ssl.keyAlias' in application.properties, I believe.
Not really an answer but overflowed comment.
You don't need to 'generate' an X.509 cert; you already got that from GoDaddy. If (and only if) the SpringBoot server is accessed by the same name(s) as (external) nginx -- which is unclear to me -- you need to convert the pair of private key AND certificate CHAIN from PEM format to a format Java uses. See:
How to import an existing x509 certificate and private key in Java keystore to use in SSL?
How can I set up a letsencrypt SSL certificate and use it in a Spring Boot application?
How to use .key and .crt file in java that generated by openssl?
Importing the private-key/public-certificate pair in the Java KeyStore
maybe Import key and SSL Certificate into java keystore
Thanks #Dave_thompson_085. Following 2 commands did the trick!
openssl pkcs12 -export -in mydomain.com.chained.crt -inkey mydomain.key -out keystore.p12 -name my-alias -caname root
keytool -importkeystore -deststorepass mypassword -destkeypass mypassword -destkeystore keystore.jks -srckeystore keystore.p12 -srcstoretype PKCS12 -srcstorepass mypassword -alias my-alias
and then in the application.properties I specified following properties:
server.port=8443
server.ssl.enabled=true
security.require-ssl=true
server.ssl.key-store=/etc/nginx/ssl/keystore.jks
server.ssl.key-store-password=mypassword
server.ssl.keyStoreType=JKS
server.ssl.keyAlias=my-alias
I took sample webapp from https://github.com/vdenotaris/spring-boot-security-saml-sample and it is working file. Later. I tried to connect kennisnet staging environment.
Kennisnet details here
https://developers.wiki.kennisnet.nl/index.php?title=KNF:Hoofdpagina/en
I updated metadata which is downloadable from this url https://hub-s.entree.kennisnet.nl/openaselect/profiles/saml2/
I generated smalKeyStore.jks using below commands
keytool -genkey -alias tomcat -keyalg RSA -keystore samlKeyStore.jks
keytool -importkeystore -srckeystore samlKeyStore.jks -destkeystore
samlKeyStore.jks -deststoretype pkcs12
I followed all Spring SAML https threads in stackoverflow and not able to figure it out this issue.
LOGS:
Add the certificate to your JDK so that your application can get the metadata from URL https://aselect-s.entree.kennisnet.nl/openaselect/profiles/saml2.
These are the steps you need to fillow:
Download the certificate for aselect-s.entree.kennisnet.nl
Import the certificate to your JDK/JRE using this command:
keytool -keystore #path to java_home#/lib/security/cacerts -importcert -alias #anything relevent# -file #path to certificate#
Make sure your server is using same java_home where you are importing the certificate, also verify the subjectname in the certificate before importing, it must be "CN = *.entree.kennisnet.nl"
Restart the server.
I have a websocket server (API of jetty 9.0.1.v20130408), which worked fine without ssl. Now I configured my server like this:
SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setKeyStorePath("/src/main/resources/keystore.jks");
sslContextFactory.setKeyStorePassword(password);
sslContextFactory.setTrustStorePath("/src/main/resources/truststore.jks");
sslContextFactory.setTrustStorePassword(password);
ConnectionFactory sslConnFactory = new SslConnectionFactory(sslContextFactory, "http/1.1);
connector.addConnectionFactory(sslConnFactory);
server.addConnector(connector);
No I tried to configurate the client. I thought, that on the client side I need to set path to truststore.jks and the password. But then I get on client.start() the Exception: SSL doesn't have a valid keystore. When I set the keystore, then I get on client.connect java.nio.channels.WritePendingException. Here is the code for my client:
WebSocketClient client = new WebSocketClient(sslContextFactory);
URI wssUri = new URI("wss://localhost:"+port);
sslContextFactory.start();
client.start();
client.connect(myClientSocket, wssUri);
Can anybody help me? I also tried on server side to set setWantClientAuth(false) and setTrustall(true), but it also did not work this way;
ADDED:
I generate my ssl files with keytool.
$ keytool -genkeypair -alias certificatekey -keyalg RSA -validity 365 -keystore keystore.jks
$ keytool -export -alias certificatekey -keystore keystore.jks -rfc -file selfsignedcert.cer
$ keytool -import -alias certificatekey -file selfsignedcert.cer -keystore truststore.jks
This is because UpgradeRequest is sent twice, as reported here
You can ignore the warning for now. Just use 9.0.4 when it is released.
I am new to https configuration in tomcat. I googled a lot but that did not solve my problem.
I have an ec2 machine and tomcat deployed on it. I tried to create self signed certificate , which was easy to generate.I used my domain www.test.com(changed test with my server name) and keystore file was generated. Then I edited conf/server.xml for https configuration as described in ssl howto of tomcat docs.But https is not working. Though when I do "curl https:// localhost :8443 -k " I can get response but it is not working in browser. Takes to long to respond and boom I am done with nothing. Do I need a certificate or It will work with keystore file only? Please tell me .
Please help me out
Thanks
Hi Thanks for you answer, I found my issue and would like explain my resolution
1.) Curl was working but it was not responding in browser . I had to open port 8443 manually from security groups in aws. It was working then :).
2.) For all others if they face with the problem "Failed to establish chain from reply"
i) please check your keystore file. Is it the same used to generate CSR?
ii) Install intermediate certificates provided by your certificate authority.
For some of them you can follow
https://www.sslcertificaten.nl/download/Root_Certificaten/
use alias primary and secondary respectively
$JAVA_HOME/bin/keytool -import -alias primary -keystore sslkey -trustcacerts -file primary_cert.crt -storepass mypass
$JAVA_HOME/bin/keytool -import -alias secondary -keystore sslkey -trustcacerts -file secondary_cert.crt -storepass mypass
iii) finally import your certificate
$JAVA_HOME/bin/keytool -import -alias tomcat -keystore sslkey -trustcacerts -file www_mydomain_com.p7b -storepass mypass
Hope this helps
cheers
If curl works, then the problem is either in the browser or in the servlet - SSL setup should be correct. Check the log files of Tomcat for errors and set breakpoints in your servlets to see what happens.