java.lang.Object
org.apache.ofbiz.accounting.thirdparty.valuelink.ValueLinkApi

public class ValueLinkApi extends Object
ValueLinkApi - Implementation of ValueLink Encryption and Transport
  • Constructor Details

    • ValueLinkApi

      protected ValueLinkApi()
    • ValueLinkApi

      protected ValueLinkApi(Delegator delegator, Properties props)
  • Method Details

    • 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 keys
      props - 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 keys
      props - 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 properties
      request - 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

      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

      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
    • getCurrency

      public String getCurrency(String currency)
      Gets currency.
      Parameters:
      currency - the currency
      Returns:
      the currency
    • 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()
      using the prime and generator provided by valuelink; create a parameter object
    • 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)
      Get pin check sum byte [ ].
      Parameters:
      pinBytes - the pin bytes
      Returns:
      the byte [ ]
    • getRandomBytes

      protected byte[] getRandomBytes(int length)
      Get random bytes byte [ ].
      Parameters:
      length - the length
      Returns:
      the byte [ ]
    • getMwkKey

      protected SecretKey getMwkKey()
      Gets mwk key.
      Returns:
      the mwk key
    • getKekKey

      protected SecretKey getKekKey()
      Gets kek key.
      Returns:
      the kek key
    • getDesEdeKey

      protected SecretKey getDesEdeKey(byte[] rawKey)
      Gets des ede key.
      Parameters:
      rawKey - the raw key
      Returns:
      the des ede key
    • getMwk

      protected byte[] getMwk()
      Get mwk byte [ ].
      Returns:
      the byte [ ]
    • getKek

      protected byte[] getKek()
      Get kek byte [ ].
      Returns:
      the byte [ ]
    • getPrivateKeyBytes

      protected byte[] getPrivateKeyBytes()
      Get private key bytes byte [ ].
      Returns:
      the byte [ ]
    • parseResponse

      protected Map<String,Object> parseResponse(String response)
      Parse response map.
      Parameters:
      response - the response
      Returns:
      the map
    • 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 from
      offset - The starting postition
      length - 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 from
      target - byte[] coping into
      position - the position on target where source will be copied to
      Returns:
      a new byte[]