Tuesday, August 27, 2013

Difference Between Connection Time out and Socket Time out~!!!

this is easy but easily fogettable

Connection Timeout is is the timeout in making the initial connection

Socket Timeout is the timeout on waiting to read data.

don't forget it~!

Monday, August 26, 2013

oracle query trace


1. first of all need to find session id if you use any tool loke toad or sqldeveloper

SELECT * FROM v$session

2. connect oracle by console

sqlplus '/as sysdba'
                                                                                sessionid  , serial
execute sys.dbms_system.set_sql_trace_in_session(1151,29373,true);

find recently maed using
ls -ltr

tkprof filename.trc customname.txt explain=user/pw sys=no

ex)tkprof neosns_ora_7274.trc t1.txt explain=neo_sns/neo_sns_dba sys=no

execute sys.dbms_system.set_sql_trace_in_session(1151,29373,false);

Wednesday, August 21, 2013

Making Secure Communication With RSA, DES [java]

Today I tried to write secure communication between client and server

i want to use ssl way

step by step I make example

and you just this process if you want secure communication


## Client ##
1. making publicKey and privateKey using RSA
2, making publicKey to Base64 String
3. give it(publicKey) to Server

## Server ##
4. receive publicKey from client and decode Bas64String to byte[]
5. get object publicKey
6. making symmetric-key (Random 16 number)
7. encryting publickey symmetric-key and give it to client

.. and

you can make encrypted  message by using des or any with symmetric-key


The point is symmetric-key is exposed to only one client and one server



/**
 * (c)Copyright 2010-2010, BaruSoft Co., Ltd. All rights reserved <br/>
 *
 * @description <br/>
 *
 * @create 2013. 8. 21.
 * @author jjhangu
 */
package secure;

import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.KeyFactory;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.X509EncodedKeySpec;
import java.util.Formatter;

import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

public class RSACrypt {

public static void main(String[] args) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException, InvalidKeySpecException, NoSuchProviderException, IOException {
final KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA");
final KeyPair keyPair = generator.generateKeyPair();
final PublicKey publicKey = keyPair.getPublic();
final PrivateKey privateKey = keyPair.getPrivate();

/**
* 시나리오 1
*
* Client
* 1. make RSA keys (publicKey, priateKey)
* 2. give publicKey to Server
*
* Server
* 3. make Symmetric-key using publicKey given by client
* 4. give it to client
*
* Client and Server Communicate Using Symmetric-key using DES Algorithm
*
*/

// Client
// 1 making public and private key
final BASE64Encoder encoder = new BASE64Encoder();
final String pubKeyStr = encoder.encode(publicKey.getEncoded());
System.out.println("#######################################");
System.out.println("Client[publicKey] BASE64 ");
System.out.println("#######################################");
System.out.println(pubKeyStr);
System.out.println();
System.out.println();

final String priKeyStr = encoder.encode(privateKey.getEncoded());
System.out.println("#######################################");
System.out.println("Client[privateKey] BASE64 ");
System.out.println("#######################################");
System.out.println(priKeyStr);
System.out.println();
System.out.println();

// give it to public key to server

// Server
// 3. Get Public Key obejct

final BASE64Decoder decoder = new BASE64Decoder();
final byte[] sigBytes2 = decoder.decodeBuffer(pubKeyStr);

// PublicKey from client
final PublicKey publicServerKey = convertKeytoKeyObject(sigBytes2);

final String pubServerKeyStr = encoder.encode(publicServerKey.getEncoded());
System.out.println("#######################################");
System.out.println("Server [publicKey] BASE64 ");
System.out.println("#######################################");
System.out.println(pubServerKeyStr);
System.out.println();
System.out.println();

// 3. make Symmetric-key using publicKey given by client

final Cipher cipher = Cipher.getInstance("RSA");
cipher.init(Cipher.ENCRYPT_MODE, publicServerKey);
final String symmetricKey = "0123456789ABCDEF";

System.out.println("#######################################");
System.out.println("Server [symmetricKey] ");
System.out.println("#######################################");
System.out.println(symmetricKey);
System.out.println();
System.out.println();

final byte[] b0 = cipher.doFinal(symmetricKey.getBytes());

// give symmetricKey to Client

// client decode
cipher.init(Cipher.DECRYPT_MODE, privateKey);
final byte[] b1 = cipher.doFinal(b0);

System.out.println("Client Finally Decode SymmetricKey : " + new String(b1));

// only one client and server will know symmetricKey
// and Server Client will Have Same symmetricKey and Communucating message using des
// algorithm with this symmetricKey
}

public static String bytesToHexString(byte[] bytes) {
final StringBuilder sb = new StringBuilder(bytes.length * 2);

final Formatter formatter = new Formatter(sb);
for (final byte b : bytes) {
formatter.format("%02x", b);
}

return sb.toString();
}

private static PublicKey convertKeytoKeyObject(byte[] publicKey) throws NoSuchAlgorithmException, InvalidKeySpecException, NoSuchProviderException {
final X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec(publicKey);
final KeyFactory keyFact = KeyFactory.getInstance("RSA");
return keyFact.generatePublic(x509KeySpec);
}

}

Wednesday, August 7, 2013

SVN Merge

1. 먼저 원본 프로젝트에서 team->branch 생성하면 브랜치로 변경된다

2. switch 로 브랜치로 이동후 작업을 한다.

3. 다 완료하면 커밋치고

4. switch 로 원본 프로젝트 선택

5. 원본 프로젝트에서 merge 를 눌러서  머지 한다

Sunday, July 28, 2013

Mysql Install

1. yum 방식을 이용한 설치
[의존성 패키지]
mysql / mysql-server / mysql-connector-odbc / mysql-devel
yum -y install mysql mysql-server mysql-connector-odbc mysql-devel
-y 옵션은 [yes/no] 선택시 자동으로 yes를 처리하게해주는 옵션
2. 설정파일 복사
# cp /usr/share/mysql/my-huge.cnf /etc/my.cnf
설치되는 서버의 메모리용량에 따라 최적화된 설정파일을 복사해준다. 보통 2G이상의 메모리를 설치하므로 my-huge.cnf를 복사한다.
my-huge.cnf 1~2G
my-large.cnf 512M
my-medium.cnf 128M~ 256M
my-small.cnf 64M 이하
** UTF8 인코딩 셋을 사용하기 위한 설정파일 내용 변경
# vi /etc/my.cnf
[client]
default-character-set = utf8
[mysqld]
init_connect = SET collation_connection = utf8_general_ci
init_connect = SET NAMES utf8
default-character-set = utf8
character-set-server = utf8
collation-server = utf8_general_ci
[mysqldump]
default-character-set=utf8
[mysql]
default-character-set=utf8
3. DB파일 설치경로
/var/lib/mysql/mysql/ 경로아래에 DB파일이 위치한다.
4. 기본 mysql DB 인스톨 및 권한 변경
mysql_install_db && chown -R mysql:mysql /var/lib/mysql/
5. mysql 데몬 실행
ㄱ) 직접 실행
/etc/rc.d/init.d/mysqld start
/etc/rc.d/init.d/mysqld stop
/etc/rc.d/init.d/mysqld restart
ㄴ) 서비스 등록
chkconfig — add mysqld
chkconfig –level 2345 mysqld on
chmod 755 /etc/rc.d/init.d/mysqld
ㄷ) 자동서비스 선택
[root@localhost test]# ntsysv
[*] mysqld
7. 패스워드 변경 및 등록
ㄱ) sql 에서 실행
mysql > update user set password = password(‘비밀번호’) where user = ‘사용자’;
mysql > flush privileges; (* 적용하기)
ㄴ) 명령어 실행
#mysqladmin -u 사용자 password 비밀번호
8. sql script 실행
#mysql -u 사용자 -p 비밀번호 mysql < 파일명.sql

Monday, July 22, 2013