我是一名软件工程师,正在构建一个将由政府机构使用的 Android 应用程序。
我们合同中的一项要求是应用程序必须符合 FIPS 140。 https://en.wikipedia.org/wiki/FIPS_140
为了符合 FIPS,我们的应用程序必须在 android 应用程序关闭时将 RAM 中的所有密码对象归零并清除。(通过从 RAM 中清零和清除密码,我们减少了攻击者的机会窗口。即这减轻了冷启动攻击风险:https : //en.wikipedia.org/wiki/Cold_boot_attack)
为了满足这一要求,我们最初遵循以下两个 SO 帖子中的建议将用户密码捕获为 CharArray 而不是字符串
//First collect the password from Edit Text as a []char
int pl = passwordEditText.length();
char[] password = new char[pl];
passwordEditText.getText().getChars(0, pl, password, 0);
//Now set the password on viewmodel
viewModel.setPassword(password)
Run Code Online (Sandbox Code Playgroud)
获得密码后,我们使用它来调用第 3 方网络服务库,该库获取数据以显示在屏幕上。
视图模型伪代码:
public DataObject getData(char[] password){
return this.webService.getData(password);
}
Run Code Online (Sandbox Code Playgroud)
当用户完成我们的应用程序时,我们调用以下方法将密码归零和清除
视图模型伪代码:
public zeroPassword(){
Arrays.fill(this.password, 0);
this.password = null; …Run Code Online (Sandbox Code Playgroud)