An attempt to fix wrong length exception from security.Store on some systems
git-svn-id: https://svn.libreccm.org/ccm/trunk@5314 8810af33-2d31-482b-a856-94f89814c4dfmaster
parent
156aeb36e7
commit
d2cb5336e6
|
|
@ -35,8 +35,10 @@ import org.apache.log4j.Logger;
|
||||||
* @author Vadim Nasardinov (vadimn@redhat.com)
|
* @author Vadim Nasardinov (vadimn@redhat.com)
|
||||||
* @since 2003-12-18
|
* @since 2003-12-18
|
||||||
* @version $Revision: #7 $ $DateTime: 2004/08/16 18:10:38 $
|
* @version $Revision: #7 $ $DateTime: 2004/08/16 18:10:38 $
|
||||||
**/
|
*
|
||||||
|
*/
|
||||||
final class Store implements KeyStorage {
|
final class Store implements KeyStorage {
|
||||||
|
|
||||||
final static Store INSTANCE = new Store();
|
final static Store INSTANCE = new Store();
|
||||||
|
|
||||||
private final static Logger s_log = Logger.getLogger(Store.class);
|
private final static Logger s_log = Logger.getLogger(Store.class);
|
||||||
|
|
@ -51,7 +53,8 @@ final class Store implements KeyStorage {
|
||||||
|
|
||||||
private byte[] m_secret;
|
private byte[] m_secret;
|
||||||
|
|
||||||
Store() {}
|
Store() {
|
||||||
|
}
|
||||||
|
|
||||||
static byte[] newKey() {
|
static byte[] newKey() {
|
||||||
byte[] key = new byte[SecurityConfig.SECRET_KEY_BYTES];
|
byte[] key = new byte[SecurityConfig.SECRET_KEY_BYTES];
|
||||||
|
|
@ -61,8 +64,7 @@ final class Store implements KeyStorage {
|
||||||
|
|
||||||
public synchronized void init() {
|
public synchronized void init() {
|
||||||
if (hasBeenInitialized()) {
|
if (hasBeenInitialized()) {
|
||||||
throw new UncheckedWrapperException
|
throw new UncheckedWrapperException("key store had been initialized");
|
||||||
("key store had been initialized");
|
|
||||||
}
|
}
|
||||||
init(ID_VALUE, OWNER_VALUE, newKey());
|
init(ID_VALUE, OWNER_VALUE, newKey());
|
||||||
}
|
}
|
||||||
|
|
@ -75,17 +77,23 @@ final class Store implements KeyStorage {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is exposed as package-scoped solely for the purpose of
|
* This method is exposed as package-scoped solely for the purpose of
|
||||||
* white-box unit-testing.
|
* white-box unit-testing.
|
||||||
*
|
*
|
||||||
* @throws NullPointerException if any of the parameters is null.
|
* @throws NullPointerException if any of the parameters is null.
|
||||||
**/
|
*
|
||||||
|
*/
|
||||||
void init(BigInteger id, String owner, byte[] store) {
|
void init(BigInteger id, String owner, byte[] store) {
|
||||||
if ( id == null ) { throw new NullPointerException("id"); }
|
if (id == null) {
|
||||||
if ( owner == null ) { throw new NullPointerException("owner"); }
|
throw new NullPointerException("id");
|
||||||
if ( store == null ) { throw new NullPointerException("store"); }
|
}
|
||||||
|
if (owner == null) {
|
||||||
|
throw new NullPointerException("owner");
|
||||||
|
}
|
||||||
|
if (store == null) {
|
||||||
|
throw new NullPointerException("store");
|
||||||
|
}
|
||||||
if (store.length < 1) {
|
if (store.length < 1) {
|
||||||
throw new IllegalArgumentException("empty store");
|
throw new IllegalArgumentException("empty store");
|
||||||
}
|
}
|
||||||
|
|
@ -101,20 +109,23 @@ final class Store implements KeyStorage {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
synchronized byte[] loadSecret() {
|
synchronized byte[] loadSecret() {
|
||||||
if ( m_secret != null ) { return m_secret; }
|
if (m_secret != null) {
|
||||||
|
return m_secret;
|
||||||
|
}
|
||||||
|
|
||||||
DataObject dobj = SessionManager.getSession().retrieve
|
DataObject dobj = SessionManager.getSession().retrieve(new OID(TYPE,
|
||||||
(new OID(TYPE, ID_VALUE));
|
ID_VALUE));
|
||||||
m_secret = (byte[]) dobj.get(STORE);
|
m_secret = (byte[]) dobj.get(STORE);
|
||||||
if (m_secret == null) {
|
if (m_secret == null) {
|
||||||
throw new IllegalStateException
|
throw new IllegalStateException("the store is null");
|
||||||
("the store is null");
|
|
||||||
}
|
}
|
||||||
if ( m_secret.length != SecurityConfig.SECRET_KEY_BYTES * 2 - 1 ) {
|
if (m_secret.length != SecurityConfig.SECRET_KEY_BYTES * 2 - 1
|
||||||
throw new IllegalArgumentException
|
&& m_secret.length != SecurityConfig.SECRET_KEY_BYTES) {
|
||||||
("wrong length. expected=" + SecurityConfig.SECRET_KEY_BYTES +
|
throw new IllegalArgumentException("wrong length. expected="
|
||||||
", but got " + m_secret.length);
|
+ SecurityConfig.SECRET_KEY_BYTES
|
||||||
|
+ ", but got " + m_secret.length);
|
||||||
}
|
}
|
||||||
return m_secret;
|
return m_secret;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue