четверг, 24 марта 2016 г.

import openssl keys to JKS

#convert ca chain from PEM to DER
openssl x509 -outform der -in ca-chain.cert.pem -out ca.cert.der

#convert server cert and server private key to pkcs12 storage
openssl pkcs12 -export -in ./hostname.cert.pem -inkey ./hostname.key.pem -out ./hostname.p12 -name mywebservice -passin pass:Secret13 -passout pass:Secret13

#import server cert and private key from pkcs12 to JKS
keytool -importkeystore -srckeystore ./hostname.p12 -srcstoretype PKCS12 -srcstorepass Secret13 -alias mywebservice -deststorepass Secret13 -destkeypass Secret13 -destkeystore server-keystore.jks

#import ca chain
keytool -import -v -trustcacerts -alias ca-cert -file ca.cert.der -keystore ./server-keystore.jks -keypass Secret13

воскресенье, 17 января 2016 г.

include java sources to clojure project

1. Make src-java dir in a root folder of project.
2. Put usual java classes to src-java/ folder
3. Add following lines to the project.clj in root or in uberjar profile.
:java-source-paths ["src-java/"]
:prep-tasks  ["javac" "compile"]

That's it! 

суббота, 9 января 2016 г.

convert pem to jks (java keystore)

after letsencrypt finish we  must convert our keys to jks.
here is some instructions:

openssl pkcs12 -export -in server-cert.pem -inkey server-private.pem -out server.p12 -name localhost -CAfile ca.pem -caname root 

keytool -importkeystore -deststorepass passw12 -destkeypass passw12 -destkeystore server.jks -srckeystore server.p12 -srcstoretype PKCS12 -srcstorepass passw12 -alias localhost

воскресенье, 14 июня 2015 г.

secure rabbitmq server and management console.

CentOS 6.5 x64

1. create file /etc/rabbitmq/rabbitmq.config

{rabbitmq_management, [{listener, [{port, 15672},{ip, ""}]}]},

2. create file /etc/rabbitmq/rabbitmq-env.conf

export RABBITMQ_NODENAME=rabbit@localhost

3. Establish ssh tunnel from your machine to remote rabbitmq server

ssh -L 15672: user@remotehost -p 22

Now, you can connect to admin console using browser http://localhost:15672
This is very useful for hosting machines.

пятница, 7 ноября 2014 г.

clojure: how to send mail with attachment

It is pretty simple. This code can be used to send email via smtp. Attachment filename may be in unicode.


(defproject com.middlesphere/mailer "0.1"
  :description "simple mailer"
  :url "http://www.middlesphere.com"
  :license {:name "Eclipse Public License"
            :url "http://www.eclipse.org/legal/epl-v10.html"}
  :dependencies [[org.clojure/clojure "1.6.0"]
                 [com.draines/postal "1.11.2"]
                 [com.sun.mail/javax.mail "1.5.2"]]
  :main ^:skip-aot mailer.core
  :target-path "target/%s"
  :omit-source true
  :profiles {:uberjar {:aot :all}})


(ns mailer.core
  (:require [clojure.edn :as edn])
  (:use [postal.core])
  (:import (javax.mail.internet MimeUtility)))

(defn show-help-exit
  (println "Usage: java -jar mailer.jar \"config-file\" \"email@email\" \"subject\" \"filename-with-body\" \"filename-with-attach\"\n ")
  (System/exit 0))

(defn -main
  "entry point to program."
  [& args]
  (println "start" (-> (java.text.SimpleDateFormat. "YYYY-mm-dd HH:mm:ss")
                       (.format (java.util.Date.))))

  (when (= "-h" (nth args 0))
  (when (not= 5 (count args))
    (println "error: wrong number of arguments!")

    (let [[config-file email-to subject body-file attach-file] args
          config (edn/read-string (slurp config-file))
          server-cfg {:host (config :host)
                      :port (config :port)}
          server-cfg (if (config :need-auth?)
                       (assoc server-cfg :user (config :user) :pass (config :pass))
          server-cfg (if (config :use-ssl?)
                       (assoc server-cfg :ssl true)
          server-cfg (if (config :use-tls?)
                       (assoc server-cfg :tls true)
      (println (format "config in:%s\nemail: %s\nsubject: %s\nbody in: %s\nattach in: %s\n" config-file email-to subject body-file attach-file))
      (println (send-message server-cfg                            
                             {:from (config :from)
                              :to email-to
                              :subject subject
                              :body [:alternative
                                     {:type (config :body-type)
                                      :content (slurp body-file)}
                                     {:type :attachment
                                      :content (java.io.File. attach-file)
                                      :file-name (MimeUtility/encodeText attach-file)
                                      :content-type (config :content-type)}]})))
    (catch Exception e (str "caught exception: " (.getMessage e))))
  (println "\nend" (-> (java.text.SimpleDateFormat. "YYYY-mm-dd HH:mm:ss")
                       (.format (java.util.Date.)))))


{:from "from@gmail.com"
 :host "smtp.gmail.com"
 :port 465
 :use-ssl? true
 :use-tls? false

 :need-auth? true
 :user "MyLogin"
 :pass "dis is passwd"

 :body-type "text/plain; charset=utf-8"
 :content-type "application/octet-stream"}

Test run

java -jar mailer-0.1-standalone.jar mailer-config.edn "to@gmail.com" "test-subject" "file-with-body.txt" "file-to-be-attached.doc"

вторник, 26 августа 2014 г.

scan hbase with specific row

source: http://stackoverflow.com/questions/16849641/row-keys-through-the-hbase-shell

so if you want to find some row with specific word in it then
hbase(main):003:0> import org.apache.hadoop.hbase.filter.CompareFilter
hbase(main):005:0> import org.apache.hadoop.hbase.filter.SubstringComparator
hbase(main):006:0> scan 'test', {FILTER => org.apache.hadoop.hbase.filter.RowFilter.new(CompareFilter::CompareOp.valueOf('EQUAL'),SubstringComparator.new("word_by_which_you_want_to_search"))}

Also, http://stackoverflow.com/questions/11068418/get-filtered-rows-in-hbase
import org.apache.hadoop.hbase.filter.CompareFilter
import org.apache.hadoop.hbase.filter.SingleColumnValueFilter
import org.apache.hadoop.hbase.filter.SubstringComparator
import org.apache.hadoop.hbase.util.Bytes

scan 'yourTable', {LIMIT => 10, FILTER => SingleColumnValueFilter.new(Bytes.toBytes('family'), Bytes.toBytes('field'), CompareFilter::CompareOp.valueOf('EQUAL'), Bytes.toBytes('AAA')), COLUMNS => 'family:field' }

вторник, 22 июля 2014 г.

cron java and utf-8

If you ever run java application from cron job you might notice that any unicode characters that java application emits looks like ????????

In order to avoid this situation in RHEL-based distros you need to create /etc/environment file and then put here a value of LANG variable. For example: LANG=ru_RU.UTF-8  (without word export or something else)