Dieses Blog durchsuchen

Posts mit dem Label Java werden angezeigt. Alle Posts anzeigen
Posts mit dem Label Java werden angezeigt. Alle Posts anzeigen

Dienstag, 28. April 2015

Script for grabbing a root ca cert of a website

If you are using self signed certs or you are using certs, which are not part of the standard cacerts of your JDK you need to get the root ca cert from the desired website. To do so you might use the following script:

#!/bin/bash
ADDRESS=$1
echo -n | openssl s_client -connect $ADDRESS:443 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ./$ADDRESS.cert 



now you should have a cert file, which you could easily add to your cacert file of the jdk with this command:


keytool -importcert -alias startcom -file $ADDRESS.cert -keystore cacerts -storepass changeit

cacerts is located in JAVA_HOME/jre/lib/security (i.e. Mac OSX /Library/Java/JavaVirtualMachines/jdkX.X.X_XX.jdk/Contents/Home/jre/lib/security/cacerts)

This command adds your cert to the cacerts of the jdk and allows any java app using the jdk to connect via ssl to the desired website. Downsite of this trick is if you move to another server or workstation you might always need to patch the cacerts with your cert. 
So the best way is to prepare a keystore with your add on certs and add it to the Java System property

-Djavax.net.ssl.keyStore=/tmp/mykeystore.jks
or even in your Java Code by using System.setProperty. This will ensure that your java prog uses trusts the certs you want to trust.



Freitag, 24. Februar 2012

Quick ref of managed Beans config in Spring

Within your service


@ManagedResource
(objectName="bean:name=SampleService",
description="Properties Service", log=true)
public class SampleImpl implements ISampleService

      @ManagedAttribute
      public void setName(String name) {
            ...
      }


Within your startup of your weblogic or whatever app container

 
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=8088
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false



Startup jconsole and enter the hostname and the port within the "Remote Process" field.

done.


The full address to the remote process is

service:jmx:rmi:///jndi/rmi://SERVERNAME:PORT/jmxrmi



Dienstag, 16. Februar 2010

Java File Format Version

Once you're moving around for a while in Java based environments you might have seen an error like this

java.lang.UnsupportedClassVersionError: Bad version number in .class file


If you hit this kind of error than its time to realize that Java byte code might differ between JDK versions :-) You'll find a long list of explanations about the Java Class file format all over in the web (http://en.wikipedia.org/wiki/Class_%28file_format%29).
Here is a list of class file versions and the corresponding JDK

J2SE 6.0 = 50 (0x32 hex),
J2SE 5.0 = 49 (0x31 hex),
JDK 1.4 = 48 (0x30 hex),
JDK 1.3 = 47 (0x2F hex),
JDK 1.2 = 46 (0x2E hex),
JDK 1.1 = 45 (0x2D hex).

Ok thanks for the list but how do I get the version out of an existing class file?
Answer:

 javap -v MyClass | more

this will print out something like this:

 class MyClass extends java.lang.Object
  minor version: 0
  major version: 50
....

Montag, 1. Februar 2010

Keystore für Java Web Start Code Signing

Hier mal eine kleine Anleitung für die Erstellung eines Keystores, der zum Code Signing benutzt werden kann.


1. Neuen Keystore anlegen

keytool -genkey -keyalg RSA -keystore keystore.ks -alias myalias

Hier wird man nun nach allem möglichen Informationen gefragt, die später Inhalt des Zertifikates sind. Diese Informationen bekommen die Endbenutzer zu sehen, wenn sie z.B. auf eine Java Web Start Anwendung zugreifen, die mit diesem keystore signiert wurde.


2. Certrequest generieren

keytool -certreq -keystore keystore.ks -file csr.txt -alias myalias

Dieser Request muss nun von einer vertrauenswürdigen RootCa unterschrieben werden.


3. Generiertes Zertifikat für den Request importieren

keytool -import -file my.cert -alias myalias -trustcacerts -keystore keystore.ks

Es kann passieren das hier eventuell eine Fehlermeldung auftritt diese Fehlermeldung leigt meist am Inhalt des emfpangenen Zeritifkats. Hier darf nur der Text mit Begin und End drin stehen. Alle anderen Sachen haben hier nichts zu suchen.
Wenn es trotzdem nicht klappt, kann das Certificat auch erst im IE unter Datenschutz ->Zertifiakte importiert werden und danache als p7b (PKCS) exportiert werden.


4. RootCa Cert importieren

keytool -import -file rootca.cer -alias myrootca -trustcacerts -keystore keystore.ks

Das RootCa Zertifikat ist notwendig, falls die RootCa nicht im allgemeinen Java trusted RootCa File enthalten ist (cacerts). Mit dem oben aufgeführten Befehl wird das RootCa Zertifikat mit in den neu erstellten Keystore aufgenommen. Das RootCa Zertifikat kann einfach aus einer vorhandenen SSL Seite exportiert werden.