Class ValueLinkApi
- java.lang.Object
-
- org.apache.ofbiz.accounting.thirdparty.valuelink.ValueLinkApi
-
public class ValueLinkApi extends Object
ValueLinkApi - Implementation of ValueLink Encryption and Transport
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
ValueLinkApi()
protected
ValueLinkApi(Delegator delegator, Properties props)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static byte[]
copyBytes(byte[] source, byte[] target, int position)
Copies a byte[] into another byte[] starting at a specific positionKeyPair
createKeys()
Create a set of public/private keys using ValueLinks defined parametersprotected byte[]
cryptoViaKek(byte[] content, int mode)
actual kek encryption/decryption codeString
decryptPin(String pin)
Decrypt an encrypted pin using the configured keysbyte[]
decryptViaKek(byte[] content)
Ue the KEK to decrypt a valueString
encryptPin(String pin)
Encrypt the defined pin using the configured keysbyte[]
encryptViaKek(byte[] content)
Use the KEK to encrypt a value usually the MWKbyte[]
generateKek(PrivateKey privateKey)
Generate a key exchange key for use in encrypting the mwkbyte[]
generateMwk()
Generate a new MWKbyte[]
generateMwk(byte[] desBytes)
Generate a new MWKbyte[]
generateMwk(SecretKey mwkdes3)
Generate a new MWKBigDecimal
getAmount(String amount)
Returns a BigDecimal from a ValueLink formatted amount StringString
getAmount(BigDecimal amount)
Returns a ValueLink formatted amount Stringstatic byte[]
getByteRange(byte[] bytes, int offset, int length)
Returns a new byte[] from the offset of the defined byte[] with a specific number of bytesprotected static Cipher
getCipher(Key key, int mode, IvParameterSpec iv)
String
getCurrency(String currency)
String
getDateString()
Returns a date string formatted as directed by ValueLinkprotected SecretKey
getDesEdeKey(byte[] rawKey)
protected DHParameterSpec
getDHParameterSpec()
GenericValue
getGenericValue()
Gets the cached value object for this merchant's keysMap<String,Object>
getInitialRequestMap(Map<String,Object> context)
Creates a Map of initial request values (MerchID, AltMerchNo, Modes, MerchTime, TermTxnNo, EncryptID) Note: For 2010 (assign working key) transaction, the EncryptID will need to be adjustedstatic ValueLinkApi
getInstance(Delegator delegator, Properties props)
Obtain an instance of the ValueLinkApi; this method will always return an existing reference if one is availablestatic ValueLinkApi
getInstance(Delegator delegator, Properties props, boolean reload)
Obtain an instance of the ValueLinkApiprotected byte[]
getKek()
protected SecretKey
getKekKey()
protected byte[]
getMwk()
protected SecretKey
getMwkKey()
protected byte[]
getPinCheckSum(byte[] pinBytes)
PrivateKey
getPrivateKey()
Get merchant Private Keyprotected byte[]
getPrivateKeyBytes()
protected byte[]
getRandomBytes(int length)
PublicKey
getValueLinkPublicKey()
Get a public key object for the ValueLink supplied public keyLong
getWorkingKeyIndex()
Returns the current working key indexStringBuffer
outputKeyCreation(boolean kekOnly, String kekTest)
Output the creation of public/private keys + KEK to the console for manual database update @protected Map<String,Object>
parseResponse(String response)
void
reload()
Reloads the keys in the object cache; use this when re-creating keysMap<String,Object>
send(String url, Map<String,Object> request)
Transmit a request to ValueLinkMap<String,Object>
send(Map<String,Object> request)
Transmit a request to ValueLink
-
-
-
Field Detail
-
module
public static final String module
-
delegator
protected Delegator delegator
-
props
protected Properties props
-
kek
protected SecretKey kek
-
mwk
protected SecretKey mwk
-
merchantId
protected String merchantId
-
terminalId
protected String terminalId
-
mwkIndex
protected Long mwkIndex
-
debug
protected boolean debug
-
-
Constructor Detail
-
ValueLinkApi
protected ValueLinkApi()
-
ValueLinkApi
protected ValueLinkApi(Delegator delegator, Properties props)
-
-
Method Detail
-
getInstance
public static ValueLinkApi getInstance(Delegator delegator, Properties props, boolean reload)
Obtain an instance of the ValueLinkApi- Parameters:
delegator
- Delegator used to query the encryption keysprops
- Properties to use for the Api (usually payment.properties)reload
- When true, will replace an existing instance in the cache and reload all properties- Returns:
- ValueLinkApi reference
-
getInstance
public static ValueLinkApi getInstance(Delegator delegator, Properties props)
Obtain an instance of the ValueLinkApi; this method will always return an existing reference if one is available- Parameters:
delegator
- Delegator used to query the encryption keysprops
- Properties to use for the Api (usually payment.properties)- Returns:
- Obtain an instance of the ValueLinkApi
-
encryptPin
public String encryptPin(String pin)
Encrypt the defined pin using the configured keys- Parameters:
pin
- Plain text String of the pin- Returns:
- Hex String of the encrypted pin (EAN) for transmission to ValueLink
-
decryptPin
public String decryptPin(String pin)
Decrypt an encrypted pin using the configured keys- Parameters:
pin
- Hex String of the encrypted pin (EAN)- Returns:
- Plain text String of the pin @
-
send
public Map<String,Object> send(Map<String,Object> request) throws HttpClientException
Transmit a request to ValueLink- Parameters:
request
- Map of request parameters- Returns:
- Map of response parameters
- Throws:
HttpClientException
-
send
public Map<String,Object> send(String url, Map<String,Object> request) throws HttpClientException
Transmit a request to ValueLink- Parameters:
url
- override URL from what is defined in the propertiesrequest
- request Map of request parameters- Returns:
- Map of response parameters
- Throws:
HttpClientException
-
outputKeyCreation
public StringBuffer outputKeyCreation(boolean kekOnly, String kekTest)
Output the creation of public/private keys + KEK to the console for manual database update @
-
createKeys
public KeyPair createKeys() throws NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeySpecException
Create a set of public/private keys using ValueLinks defined parameters- Returns:
- KeyPair object containing both public and private keys
- Throws:
NoSuchAlgorithmException
InvalidAlgorithmParameterException
InvalidKeySpecException
-
generateKek
public byte[] generateKek(PrivateKey privateKey) throws NoSuchAlgorithmException, InvalidKeySpecException, InvalidKeyException
Generate a key exchange key for use in encrypting the mwk- Parameters:
privateKey
- The private key for the merchant- Returns:
- byte array containing the kek
- Throws:
NoSuchAlgorithmException
InvalidKeySpecException
InvalidKeyException
-
getValueLinkPublicKey
public PublicKey getValueLinkPublicKey() throws NoSuchAlgorithmException, InvalidKeySpecException
Get a public key object for the ValueLink supplied public key- Returns:
- PublicKey object of ValueLinks's public key
- Throws:
NoSuchAlgorithmException
InvalidKeySpecException
-
getPrivateKey
public PrivateKey getPrivateKey() throws InvalidKeySpecException, NoSuchAlgorithmException
Get merchant Private Key- Returns:
- PrivateKey object for the merchant
- Throws:
InvalidKeySpecException
NoSuchAlgorithmException
-
generateMwk
public byte[] generateMwk()
Generate a new MWK- Returns:
- Hex String of the new encrypted MWK ready for transmission to ValueLink @
-
generateMwk
public byte[] generateMwk(byte[] desBytes)
Generate a new MWK- Parameters:
desBytes
- byte array of the DES key (24 bytes)- Returns:
- Hex String of the new encrypted MWK ready for transmission to ValueLink @
-
generateMwk
public byte[] generateMwk(SecretKey mwkdes3)
Generate a new MWK- Parameters:
mwkdes3
- pre-generated DES3 SecretKey- Returns:
- Hex String of the new encrypted MWK ready for transmission to ValueLink @
-
encryptViaKek
public byte[] encryptViaKek(byte[] content)
Use the KEK to encrypt a value usually the MWK- Parameters:
content
- byte array to encrypt- Returns:
- encrypted byte array
-
decryptViaKek
public byte[] decryptViaKek(byte[] content)
Ue the KEK to decrypt a value- Parameters:
content
- byte array to decrypt- Returns:
- decrypted byte array
-
getDateString
public String getDateString()
Returns a date string formatted as directed by ValueLink- Returns:
- ValueLink formatted date String
-
getWorkingKeyIndex
public Long getWorkingKeyIndex()
Returns the current working key index- Returns:
- Long number of the current working key index
-
getAmount
public String getAmount(BigDecimal amount)
Returns a ValueLink formatted amount String- Parameters:
amount
- BigDecimal value to format- Returns:
- Formatted String
-
getAmount
public BigDecimal getAmount(String amount)
Returns a BigDecimal from a ValueLink formatted amount String- Parameters:
amount
- The ValueLink formatted amount String- Returns:
- BigDecimal object
-
getInitialRequestMap
public Map<String,Object> getInitialRequestMap(Map<String,Object> context)
Creates a Map of initial request values (MerchID, AltMerchNo, Modes, MerchTime, TermTxnNo, EncryptID) Note: For 2010 (assign working key) transaction, the EncryptID will need to be adjusted- Returns:
- Map containing the inital request values
-
getGenericValue
public GenericValue getGenericValue()
Gets the cached value object for this merchant's keys- Returns:
- Cached GenericValue object
-
reload
public void reload()
Reloads the keys in the object cache; use this when re-creating keys
-
getDHParameterSpec
protected DHParameterSpec getDHParameterSpec()
-
cryptoViaKek
protected byte[] cryptoViaKek(byte[] content, int mode) throws GeneralException
actual kek encryption/decryption code- Throws:
GeneralException
-
getCipher
protected static Cipher getCipher(Key key, int mode, IvParameterSpec iv) throws GeneralException
- Throws:
GeneralException
-
getPinCheckSum
protected byte[] getPinCheckSum(byte[] pinBytes)
-
getRandomBytes
protected byte[] getRandomBytes(int length)
-
getMwkKey
protected SecretKey getMwkKey()
-
getKekKey
protected SecretKey getKekKey()
-
getDesEdeKey
protected SecretKey getDesEdeKey(byte[] rawKey)
-
getMwk
protected byte[] getMwk()
-
getKek
protected byte[] getKek()
-
getPrivateKeyBytes
protected byte[] getPrivateKeyBytes()
-
getByteRange
public static byte[] getByteRange(byte[] bytes, int offset, int length)
Returns a new byte[] from the offset of the defined byte[] with a specific number of bytes- Parameters:
bytes
- The byte[] to extract fromoffset
- The starting postitionlength
- The number of bytes to copy- Returns:
- a new byte[]
-
copyBytes
public static byte[] copyBytes(byte[] source, byte[] target, int position)
Copies a byte[] into another byte[] starting at a specific position- Parameters:
source
- byte[] to copy fromtarget
- byte[] coping intoposition
- the position on target where source will be copied to- Returns:
- a new byte[]
-
-