1 InsecureBankv2의 LoginActivity.java 파일 분석
- (1) 아이디를 Base64로 디코드
protected void fillData() throws UnsupportedEncodingException, InvalidKeyException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException {
//TODO Auto-generated method stub
SharedPreferences settings = getSharedPreferences(MYPREFS, 0);
final String username = settings.getString("EncryptedUsername", null);
final String password = settings.getString("superSecurePassword", null);
if(username!=null && password!=null)
{
// (1) 아이디를 Base64로 디코드
byte[] usernameBase64Byte = Base64.decode(username, Base64.DEFAULT);
try {
usernameBase64ByteString = new String(usernameBase64Byte, "UTF-8");
} catch (UnsupportedEncodingException e) {
//TODO Auto-generated catch block
e.printStackTrace();
}
Username_Text = (EditText) findViewById(R.id.loginscreen_username);
Password_Text = (EditText) findViewById(R.id.loginscreen_password);
Username_Text.setText(usernameBase64ByteString);
CryptoClass crypt = new CryptoClass();
- (2) 비밀번호를 AES로 복호화
// (2) 비밀번호를 AES로 복호화
String decryptedPassword = crypt.aesDeccryptedString(password);
Password_Text.setText(decryptedPassword);
}
else if (username==null || password==null)
{
// Toast.makeText(this, "No stored credentials found!!", Toast.LENGTH_LONG).show();
}
else
{
// Toast.makeText(this, "No stored credentials found!!", Toast.LENGTH_LONG).show();
}
}
2 InsecureBankv2의 CryptoClass.java 파일 분석
(1) CryptoClass.java 파일에서 AES 암호화에 사용되는 key를 찾는다. key는 어떤 값으로 설정되어 있는가? InsecureBankv2 프로젝트에서 키를 관리하는 방식의 문제점은 무엇인가? 이러한 문제점을 어떻게 완화할 수 있는가?
- 설정 : Key가 String 형태의 평문으로 저장되어 있음
- 문제점 : 역공학으로 코드를 조회할 시 Key값이 노출됨
- 완화 방법 : 난독화, 하드웨어를 사용한 키 관리 공법
public class
CryptoClass {
// The super secret key used by the encryption function
String key = "This is the super secret key 123";
(2) CryptoClass.java 파일에서 초기화 벡터 ivBytes 배열은 0x00으로 초기화되어 있다. 이렇게 0x00으로 초기화된 벡터를 사용하는 경우 어떤 문제점이 있는가? 이러한 문제점을 어떻게 완화할 수 있는가?
- 초기화 벡터는 암호화의 안정성을 높이기 위해 key와 결합하여 사용됨
- 초기화 벡터가 모두 0으로 설정된 것은 없는 것과 마찬가지 !
- 초기화 벡터를 필요할 때 마다 정의된 방식 안에서 Random하게 생성해 사용하도록 해야 함
byte[] ivBytes = {//초기화 백터가 모두 0으로 설정됨)
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};