-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
268 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
modules/cryptoservice/src/main/java/org/jpos/crypto/CryptoServiceKeyStoreException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* jPOS Project [http://jpos.org] | ||
* Copyright (C) 2000-2019 jPOS Software SRL | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package org.jpos.crypto; | ||
|
||
public class CryptoServiceKeyStoreException extends Exception { | ||
private static final long serialVersionUID = -392344903153648787L; | ||
|
||
public CryptoServiceKeyStoreException() { | ||
} | ||
|
||
public CryptoServiceKeyStoreException(String message) { | ||
super(message); | ||
} | ||
|
||
public CryptoServiceKeyStoreException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
|
||
public CryptoServiceKeyStoreException(Throwable cause) { | ||
super(cause); | ||
} | ||
|
||
public CryptoServiceKeyStoreException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { | ||
super(message, cause, enableSuppression, writableStackTrace); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
modules/cryptoservice/src/main/java/org/jpos/crypto/CryptoServiceKeyStoreProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* jPOS Project [http://jpos.org] | ||
* Copyright (C) 2000-2019 jPOS Software SRL | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package org.jpos.crypto; | ||
|
||
/** | ||
* Key store | ||
*/ | ||
public interface CryptoServiceKeyStoreProvider { | ||
/** | ||
* Places an encrypted key in the store. | ||
* | ||
* @param id key Id | ||
* @param value key value | ||
* @throws KeyAlreadyExistsException if id already exists in the store. | ||
*/ | ||
void put(String id, String value) throws CryptoServiceKeyStoreException; | ||
|
||
/** | ||
* Get key value | ||
* @param id key Id | ||
* @return key's value or null | ||
*/ | ||
String get (String id) throws CryptoServiceKeyStoreException; | ||
} |
48 changes: 48 additions & 0 deletions
48
...les/cryptoservice/src/main/java/org/jpos/crypto/JESpaceCryptoServiceKeyStoreProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* jPOS Project [http://jpos.org] | ||
* Copyright (C) 2000-2019 jPOS Software SRL | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package org.jpos.crypto; | ||
|
||
import org.jpos.core.Configurable; | ||
import org.jpos.core.Configuration; | ||
import org.jpos.core.ConfigurationException; | ||
import org.jpos.space.Space; | ||
import org.jpos.space.SpaceFactory; | ||
|
||
public class JESpaceCryptoServiceKeyStoreProvider implements CryptoServiceKeyStoreProvider, Configurable { | ||
private Space<String,String> sp; | ||
|
||
@Override | ||
public void put(String id, String value) throws CryptoServiceKeyStoreException { | ||
if (sp.rdp(id) != null) { | ||
throw new KeyAlreadyExistsException(); | ||
} | ||
sp.put(id, value); | ||
} | ||
|
||
@Override | ||
public String get(String id) throws CryptoServiceKeyStoreException { | ||
return sp.rdp(id); | ||
} | ||
|
||
@Override | ||
@SuppressWarnings("unchecked") | ||
public void setConfiguration(Configuration cfg) throws ConfigurationException { | ||
sp = (Space<String,String>) SpaceFactory.getSpace(cfg.get("space", "je:cryptoservice")); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
modules/cryptoservice/src/main/java/org/jpos/crypto/KeyAlreadyExistsException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* jPOS Project [http://jpos.org] | ||
* Copyright (C) 2000-2019 jPOS Software SRL | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package org.jpos.crypto; | ||
|
||
public class KeyAlreadyExistsException extends CryptoServiceKeyStoreException { | ||
|
||
private static final long serialVersionUID = -7413606609749329477L; | ||
|
||
/** | ||
* Key already exists in keystore. | ||
*/ | ||
public KeyAlreadyExistsException() { | ||
super(); | ||
} | ||
|
||
/** | ||
* Key already exists in keystore (with detail). | ||
* | ||
* @param msg the detail message. | ||
*/ | ||
public KeyAlreadyExistsException(String msg) { | ||
super(msg); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
...s/cryptoservice/src/main/java/org/jpos/crypto/SysConfigCryptoServiceKeyStoreProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* jPOS Project [http://jpos.org] | ||
* Copyright (C) 2000-2019 jPOS Software SRL | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package org.jpos.crypto; | ||
|
||
import org.jpos.ee.DB; | ||
import org.jpos.ee.SysConfigManager; | ||
|
||
public class SysConfigCryptoServiceKeyStoreProvider implements CryptoServiceKeyStoreProvider { | ||
@Override | ||
public void put(String id, String value) throws CryptoServiceKeyStoreException { | ||
try { | ||
DB.execWithTransaction(db -> { | ||
SysConfigManager mgr = new SysConfigManager(db, "key."); | ||
if (mgr.get(id, null) != null) | ||
throw new KeyAlreadyExistsException(); | ||
|
||
mgr.put(id, value, "security.read", "security.write"); | ||
return true; | ||
}); | ||
} catch (Exception e) { | ||
throw new CryptoServiceKeyStoreException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public String get(String id) throws CryptoServiceKeyStoreException { | ||
try { | ||
return DB.execWithTransaction(db -> { | ||
SysConfigManager mgr = new SysConfigManager(db, "key."); | ||
return mgr.get(id, null); | ||
}); | ||
} catch (Exception e) { | ||
throw new CryptoServiceKeyStoreException(e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters