51 lines
1.7 KiB
Java
51 lines
1.7 KiB
Java
package sega.a7;
|
|
|
|
import javacard.security.MessageDigest;
|
|
|
|
/**
|
|
* Replaces the RSA private exponent. Both the modulus and the exponent must be
|
|
* written before the new key becomes active; the update is staged in RAM.
|
|
*/
|
|
public class PrikeyExponentWrite extends AuthCommand {
|
|
|
|
public PrikeyExponentWrite(short cmd, AppData data, MakePacket packet,
|
|
MessageDigest sha1, HmacSha1 hmacSha1, Crypt crypt) {
|
|
super(cmd, (short) 302, (short) 46, AppConfig.LEVEL_AUTH,
|
|
data, packet, sha1, hmacSha1, crypt);
|
|
}
|
|
|
|
public short core(byte[] data, short dataOffset, short dataLength) {
|
|
if (m_ee_data.getSflag_ee()) {
|
|
return AppConfig.EEPWRITE_DISABLE;
|
|
}
|
|
|
|
byte[] buffer = m_ee_data.getGeneralBuffer_ramD();
|
|
if (buffer.length < AppConfig.RSA_KEY_SIZE) {
|
|
return AppConfig.FAIL;
|
|
}
|
|
|
|
short decSize = decData(data,
|
|
(short) (dataOffset + AppConfig.HEADER_SIZE),
|
|
AppConfig.RSA_KEY_SIZE, buffer, (short) 0);
|
|
if (decSize < AppConfig.RSA_KEY_SIZE) {
|
|
return AppConfig.FAIL;
|
|
}
|
|
|
|
if (!m_ee_data.setRsaPriKeyExponent_ee(buffer, (short) 0,
|
|
AppConfig.RSA_KEY_SIZE)) {
|
|
return AppConfig.EEP_WRITEFAIL;
|
|
}
|
|
m_ee_data.activeRsaExponentUpdate_ramD();
|
|
|
|
if (m_ee_data.getRsaModulusUpdate_ramD()) {
|
|
byte[] modulus = m_ee_data.getRsaPriModulus_ee();
|
|
byte[] exponent = m_ee_data.getRsaPriExponent_ee();
|
|
if (!changeRsaKey_ee(modulus, (short) 0, (short) modulus.length,
|
|
exponent, (short) 0, (short) exponent.length)) {
|
|
return AppConfig.FAIL;
|
|
}
|
|
}
|
|
return AppConfig.SUCCESS;
|
|
}
|
|
}
|