Installing the StartCom CA Certificate into the local JDK


references

problem

I just found that my local JDK doesn’t like the StartSSL™‘s certificate on remote server.
He kept failing with following error while deploying site.

# Transfer error: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

solution

Download Tool Box/StartCom CA Certificates/StartCom Root CA (PEM encoded) which is named ‘ca.pem’.
Then execute following script.

KEYSTORE=$JAVA_HOME/jre/lib/security/cacerts
$JAVA_HOME/bin/keytool -import \
  -alias StartCom-Root-CA \
  -file ca.pem \
  -keystore "$KEYSTORE"

When asked for password? changeit.

Creating an executable JAR file


References

Jar

public class HelloWorld {

    public static void main(final String[] args) {
        System.out.println("hello, world");
    }
}
$ javac HelloWorld.java

$ java HelloWorld
hello, world

$ cat HelloWorld.mf
Main-Class: HelloWorld

$ jar cfm HelloWorld.jar HelloWorld.mf HelloWorld.class

$ java -jar HelloWorld.jar
hello, world

$

Maven

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0

http://maven.apache.org/xsd/maven-4.0.0.xsd">

  <modelVersion>4.0.0</modelVersion>

  <!-- The Basics -->
  <groupId>test</groupId>
  <artifactId>hello-world</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>
  <dependencies>
    <dependency>
      <groupId>org.imgscalr</groupId>
      <artifactId>imgscalr-lib</artifactId>
      <version>4.2</version>
    </dependency>
  </dependencies>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <!-- Build Settings -->
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.4</version>
        <configuration>
          <archive>
            <manifest>
              <mainClass>test.HelloWorld</mainClass>
            </manifest>
          </archive>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.4</version>
        <configuration>
          <archive>
            <manifest>
              <mainClass>test.HelloWorld</mainClass>
            </manifest>
          </archive>
          <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
        </configuration>
        <executions>
          <execution>
            <id>make-assembly</id>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

  <!-- More Project Information -->
  <name>hello-world</name>
  <url>http://maven.apache.org</url>

  <!-- Enrivonment Settings -->

</project>
$ ls -R src/main/java/
src/main/java/:
test/

src/main/java/test:
HelloWorld.java*

$ cat src/main/java/test/HelloWorld.java
package test;

public class HelloWorld {

    public static void main(final String[] args) {
        System.out.println( "hello, world");
    }
}

$ mvn clean package
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.613s
[INFO] Finished at: Sat Apr 27 00:27:33 KST 2013
[INFO] Final Memory: 15M/223M
[INFO] ------------------------------------------------------------------------

$ ls -l target/
archive-tmp/
classes/
hello-world-1.0-SNAPSHOT.jar*
hello-world-1.0-SNAPSHOT-jar-with-dependencies.jar*
maven-archiver/
surefire/

$ jar tf target/hello-world-1.0-SNAPSHOT.jar
META-INF/
META-INF/MANIFEST.MF
test/
test/HelloWorld.class
META-INF/maven/
META-INF/maven/test/
META-INF/maven/test/hello-world/
META-INF/maven/test/hello-world/pom.xml
META-INF/maven/test/hello-world/pom.properties

$ java -jar target/hello-world-1.0-SNAPSHOT.jar
hello, world

$ jar tf target/hello-world-1.0-SNAPSHOT-jar-with-dependencies.jar
META-INF/
META-INF/MANIFEST.MF
org/
org/imgscalr/
org/imgscalr/AsyncScalr$1.class
org/imgscalr/AsyncScalr$10.class
org/imgscalr/AsyncScalr$11.class
org/imgscalr/AsyncScalr$12.class
org/imgscalr/AsyncScalr$13.class
org/imgscalr/AsyncScalr$14.class
org/imgscalr/AsyncScalr$2.class
org/imgscalr/AsyncScalr$3.class
org/imgscalr/AsyncScalr$4.class
org/imgscalr/AsyncScalr$5.class
org/imgscalr/AsyncScalr$6.class
org/imgscalr/AsyncScalr$7.class
org/imgscalr/AsyncScalr$8.class
org/imgscalr/AsyncScalr$9.class
org/imgscalr/AsyncScalr$DefaultThreadFactory.class
org/imgscalr/AsyncScalr$ServerThreadFactory.class
org/imgscalr/AsyncScalr.class
org/imgscalr/Scalr$1.class
org/imgscalr/Scalr$Method.class
org/imgscalr/Scalr$Mode.class
org/imgscalr/Scalr$Rotation.class
org/imgscalr/Scalr.class
META-INF/maven/
META-INF/maven/org.imgscalr/
META-INF/maven/org.imgscalr/imgscalr-lib/
META-INF/maven/org.imgscalr/imgscalr-lib/pom.xml
META-INF/maven/org.imgscalr/imgscalr-lib/pom.properties
test/
test/HelloWorld.class
META-INF/maven/test/
META-INF/maven/test/hello-world/
META-INF/maven/test/hello-world/pom.xml
META-INF/maven/test/hello-world/pom.properties

$ java -jar target/hello-world-1.0-SNAPSHOT-jar-with-dependencies.jar
hello, world

$

Redirect HTTP to HTTPS with Apache2


References

Redirect

Add following line to /etc/apache2/site-available/default.

<VirtualHost *:80>

    ....

    Redirect permanent / https://{your.server.address}/

    ....

</VirtualHost>

Rewrite

Add following lines to /etc/apache2/site-available/default.

<VirtualHost *:80>

    ....

    RewriteEngine on
    RewriteCond %{HTTPS} !=on
    RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]

    ....

</VirtualHost>

general methods and utilities for password encryption


References


Sponsors

Spider Strategies

We’ve made software for the web since day one.

Morton Salt | “When It Rains It Pours®”

“When It Rains It Pours®”.

MappedMorton.java

(full source)
There is actually only one class that I’m going to introduce in this blog entry. Much (or Almost) of the codes are came from the referenced blog entry.

public abstract class MappedMorton implements Serializable {

    protected static final int DENSITY_MIN = 1;

    protected static final int DENSITY_MAX = 26;

    protected static final int MAPPED_DENSITY = 16;

    protected static final int SODIUM_SIZE_MIN = 8; // = 64 / 8

    protected static final int SODIUM_SIZE_MAX = 64; // = 512 / 8

    protected static final int MAPPED_SODIUM_LENGTH = 32; // = 256 / 8

    protected static byte[] pbkdf2(final char[] password, final byte[] salt,
                                   final int iterationCount,
                                   final int keyLength) {
        try {
            final SecretKeyFactory secretKeyFactory =
                SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
            final KeySpec keySpec = new PBEKeySpec(
                password, salt, iterationCount, keyLength);
            try {
                final SecretKey secretKey =
                    secretKeyFactory.generateSecret(keySpec);
                return secretKey.getEncoded();
            } catch (InvalidKeySpecException ikse) {
                throw new RuntimeException(ikse);
            }
        } catch (NoSuchAlgorithmException nsae) {
            throw new RuntimeException(nsae);
        }
    }

    protected static char[] cassword(final byte[] bassword) {
        final char[] cassword = new char[bassword.length];
        for (int i = 0; i < cassword.length; i++) {
            cassword[i] = (char) (bassword[i] & 0xFF);
        }
        return cassword;
    }

    protected static byte[] sodium(final int length) {
        final byte[] sodium = new byte[length];
        try {
            SecureRandom.getInstance("SHA1PRNG").nextBytes(sodium);
        } catch (NoSuchAlgorithmException nsae) {
            throw new RuntimeException(nsae);
        }
        return sodium;
    }

    protected MappedMorton(final int density, final byte[] sodium) {
        super();
        this.density = density;
        this.sodium = Arrays.copyOf(sodium, sodium.length);
    }

    public MappedMorton() {
        this(MAPPED_DENSITY, sodium(MAPPED_SODIUM_LENGTH));
    }

    public byte[] salty(final byte[] bland) {
        final char[] password = cassword(bland);
        final int degree = 0x01 << density;
        final int iterationCount =
            (new BigInteger(bland).intValue() & (degree - 1)) | degree;
        return pbkdf2(password, sodium, iterationCount, sodium.length * 8);
    }

    @Basic(optional = false)
    @Column(name = "DENSITY", nullable = false,
            updatable = false)
    @Min(DENSITY_MIN)
    @Max(DENSITY_MAX)
    private int density;

    @Basic(optional = false)
    @Column(name = "SODIUM", nullable = false,
            updatable = false)
    @NotNull
    @Size(min = SODIUM_SIZE_MIN, max = SODIUM_SIZE_MAX)
    private byte[] sodium;
}

Note that the iterationCounts are not fixed and varies by each challenged password.
Here comes a table of testing results.

password (bad) salty (64 hex) iteration count elapsed (ms)
password C7BA…697E 79,158 232
123456 C0B6…9BFA 79,672 236
12345678 4185…958D 78,387 228
abc123 6360…72F8 95,353 276
qwerty 8A3B…4501 91,513 264
monkey 5AE1…929E 92,526 271
letmein FAA8…8812 94,062 272
dragon 5F2A…A1B6 78,129 226
111111 8E25…BDE6 93,292 267
baseball FAB8…0EA4 106,129 304

Lets take it into a real example.

Morton.java

(full source)
With this extended entity, we increased the default density by 1 which will produce the iterationCount between 2^17(inclusive) and 2^18(exclusive) and extended the the salt size to the maximum (512 bits).

@Entity
@Table(name = "MORTON")
public class Morton extends MappedMorton {

    protected static final int DENSITY = MAPPED_DENSITY + 1;

    protected static final int SODIUM_LENGTH = MAPPED_SODIUM_LENGTH << 1;

    protected Morton() {
        super(DENSITY, sodium(SODIUM_LENGTH));
    }

    @Id
    @GeneratedValue(generator = "MORTON_ID_GENERATOR",
                    strategy = GenerationType.TABLE)
    @TableGenerator(initialValue = Pkv.INITIAL_VALUE,
                    name = "MORTON_ID_GENERATOR",
                    pkColumnName = Pkv.PK_COLUMN_NAME,
                    pkColumnValue = "MORTON_ID",
                    table = Pkv.TABLE,
                    valueColumnName = Pkv.VALUE_COLUMN_NAME)
    @NotNull
    private Long id;
}

Shadow

(full source)
This entity is for storing usernames and encrypted passwords.

@Entity
@Table(name = "SHADOW")
public class Shadow implements Serializable {

    public static Shadow newInstance(final String username,
                                     final byte[] password) {
        final Shadow instance = new Shadow();
        instance.username = username;
        instance.passsalt = new Morton();
        instance.passcode = instance.passsalt.salty(password);
        return instance;
    }

    public boolean nassword(final Shadow reference, final byte[] password,
                            final byte[] nassword) {
        if (!puthenticate(reference, password)) {
            return false;
        }
        passsalt = new Morton();
        passcode = passsalt.salty(nassword);
        return true;
    }

    public boolean puthenticate(final Shadow reference, final byte[] password) {
        return Arrays.equals(passsalt.salty(password), passcode);
    }

    @Id
    @GeneratedValue(generator = "SHADOW_ID_GENERATOR",
                    strategy = GenerationType.TABLE)
    @TableGenerator(initialValue = Pkv.INITIAL_VALUE,
                    name = "SHADOW_ID_GENERATOR",
                    pkColumnName = Pkv.PK_COLUMN_NAME,
                    pkColumnValue = "SHADOW_ID",
                    table = Pkv.TABLE,
                    valueColumnName = Pkv.VALUE_COLUMN_NAME)
    @NotNull
    @XmlTransient
    private Long id;

    @Basic(optional = false)
    @Column(name = "USERNAME", nullable = false, unique = true,
            updatable = false)
    @NotNull
    @Size(min = USERNAME_SIZE_MIN, max = USERNAME_SIZE_MAX)
    private String username;

    @JoinColumn(name = "PASSSALT_ID", nullable = false)
    @OneToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE,
                         CascadeType.REMOVE},
              optional = false, orphanRemoval = true)
    @NotNull
    private Morton passsalt;

    @Basic(optional = false)
    @Column(length = Morton.SODIUM_LENGTH, name = "PASSCODE", nullable = false)
    @NotNull
    @Size(min = Morton.SODIUM_LENGTH, max = Morton.SODIUM_LENGTH)
    private byte[] passcode;
}

한글 윈도 영문으로 바꾸기


페이지 없어질 지도 몰라서 기록함.


  1. Check your system
  2. Download and extract MUI
  3. Execute following commands
  4. > dism /online /add-package /packagepath:d:\lp.cab
    > bcdedit /set {current} locale en-us
    > bcdboot %windir% /l en-us
    
  5. Remove HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\MUI\UILanguage\ko-KR in your registry.

syntax highlighted hello worlds


references

The Hello World Collection

the hello.c

See Hello world program in Wikipedia.

#include <stdio.h>

main()
{
    printf("hello, world\n");
}

actionscript3

// Hello World in ActionScript 3. Place code in the first frame Actions.
var t:TextField=new TextField();
t.text="Hello World!";
addChild(t);

bash

#!/bin/bash
echo "hello, world"

clojure

coldfusion

<!---Hello world in ColdFusion--->

<cfset message = "Hello World">
<cfoutput> #message#</cfoutput>

cpp

#include <iostream>

void main()
{
    std::cout << "hello, world" << std::endl;
}

csharp

public class Hello
{
    public static void Main()
    {
        System.Console.WriteLine("hello, world");
    }
}

css

/* Hello World in CSS */
body:before {
    content: "Hello World";
}

delphi

{$APPTYPE CONSOLE}
program p;
begin
  Writeln ('Hello, World');
end.

erlang

-module(hello).
-export([start/0]).
start() -> io:fwrite("hello, world\n");

fsharp

diff

groovy

html

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <body>
    <p>hello, world</p>
  </body>
</html>
<!DOCTYPE html>
<html>
  <body>
    <p>hello, world</p>
  </body>
</html>

javascript

java

public class Hello {

    public static void main(final String[] args) {
        System.out.println("hello, world");
    }
}

javafx

matlab (keywords only)

objc

#import <stdio.h>

int main( int argc, const char *argv[] ) {
    printf( "hello world\n" );
    return 0;
}

perl

#!/usr/bin/perl

use strict;
use warnings;

print "hello, world\n";

php

<?php
    echo "hello, world";
?>

text

hello, world

powershell

python

r

ruby

#!/usr/bin/ruby

print "hello, world\n"

scala

object Hello {
    def main(args : Array[String]) {
        println("hello, world");
    }
}
object HelloApp extends App {
    println("hello, world");
}

sql

vb

xml

<?xml version="1.0" encoding="UTF-8"?>
<root>hello, world</root>

derby properties with maven-surefire-plugin


It seems that derby log files generated on the root.

$ ls -l
...
-rw-r--r-- 1 onacit Users 13K 3월  29 18:11 pom.xml
drwxr-xr-x 1 onacit Users   0 5월  23  2012 src/

$ mvn clean test
...

$ ls -l
...
-rw-r--r-- 1 onacit Users 660 4월   1 12:28 derby.log
-rw-r--r-- 1 onacit Users 13K 3월  29 18:11 pom.xml
drwxr-xr-x 1 onacit Users   0 5월  23  2012 src/

$

Nasty, huh?

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <configuration>
    <systemProperties>
      <property>
        <name>derby.stream.error.file</name>
        <value>target/derby.log</value>
      </property>
      <property>
        <name>derby.locks.monitor</name>
        <value>true</value>
      </property>
      <property>
        <name>derby.locks.deadlockTrace</name>
        <value>true</value>
      </property>
      <property>
        <name>derby.language.logStatementText</name>
        <value>true</value>
      </property>
    </systemProperties>
  </configuration>
</plugin>
$ ls -l
...
-rw-r--r-- 1 onacit Users 13K 3월  29 18:11 pom.xml
drwxr-xr-x 1 onacit Users   0 5월  23  2012 src/

$ mvn clean test
...

$ ls -l
...
-rw-r--r-- 1 onacit Users 13K 3월  29 18:11 pom.xml
drwxr-xr-x 1 onacit Users   0 5월  23  2012 src/

$ ls -l target/
...
drwxr-xr-x 1 onacit Users   0 4월   1 12:39 classes/
-rw-r--r-- 1 onacit Users 34K 4월   1 12:40 derby.log
drwxr-xr-x 1 onacit Users   0 4월   1 12:39 generated-sources/
drwxr-xr-x 1 onacit Users   0 4월   1 12:39 generated-test-sources/
drwxr-xr-x 1 onacit Users   0 4월   1 12:40 surefire-reports/
drwxr-xr-x 1 onacit Users   0 4월   1 12:39 test-classes/

$