시큐어 코딩

사이트를 개발할때 ip주소, port, db정보 등이 외부에 노출되지 않기 위해 개발 코드에 적지 않는다

properties객체를 이용하여(환경설정파일 이용하여) 암호화하여 사용한다

 

port.properties 파일 생성

#key=value

port=포트번호
ip=ip주소 

 

예시) 

클라이언트 수정

Properties props = new Properties();
String filename="port.properties의 절대경로";
FileInputStream in = new FileInputStream(filename);
String ip = "";
String service = "";

if(in!=null && in.available() >0) {
	props.load(in);
	ip = props.getProperty("ip");
	service = props.getProperty("port");
}
//Socket(String host,int port)
int port=Integer.parseInt(service);
//ip,port 값을 직접 넣지 x
s = new Socket(ip,port);
...

 

서버 수정

Properties props = new Properties();//파일의 정보를 메모리에 로드시키기 위해
String filename="port.properties의 절대경로";
FileInputStream in = new FileInputStream(filename); 

String service="";//불러올 포트번호를 저장

//파일에 정보가 들어있으면서 현재 이 파일을 불러올 수 있는 상태라면
if(in!=null && in.available()>0) {//-1이면 불러오지 못하는 상태
	props.load(in);
	service=props.getProperty("port");//<->setProperty
}
int port=Integer.parseInt(service);

try {
	ss = new ServerSocket(port);
...

 

+ Recent posts