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 를 눌러서  머지 한다