├── jitpack.yml ├── .gitignore ├── src ├── main │ ├── java │ │ └── org │ │ │ └── kopi │ │ │ └── ebics │ │ │ ├── interfaces │ │ │ ├── EbicsOrderType.java │ │ │ ├── PasswordCallback.java │ │ │ ├── EbicsPartner.java │ │ │ ├── ContentFactory.java │ │ │ ├── EbicsElement.java │ │ │ ├── Savable.java │ │ │ ├── SerializationManager.java │ │ │ ├── EbicsRootElement.java │ │ │ ├── InitLetter.java │ │ │ ├── TraceManager.java │ │ │ ├── LetterManager.java │ │ │ ├── EbicsBank.java │ │ │ ├── Configuration.java │ │ │ └── EbicsUser.java │ │ │ ├── client │ │ │ ├── EbicsUploadParams.java │ │ │ ├── TransferState.java │ │ │ ├── Partner.java │ │ │ └── HttpRequestSender.java │ │ │ ├── utils │ │ │ └── Constants.java │ │ │ ├── certificate │ │ │ ├── X509Constants.java │ │ │ └── KeyUtil.java │ │ │ ├── exception │ │ │ ├── NoDownloadDataAvailableException.java │ │ │ └── EbicsException.java │ │ │ ├── session │ │ │ ├── OrderType.java │ │ │ ├── Product.java │ │ │ ├── DefaultSerializationManager.java │ │ │ ├── DefaultTraceManager.java │ │ │ └── EbicsSession.java │ │ │ ├── security │ │ │ └── UserPasswordHandler.java │ │ │ ├── io │ │ │ ├── InputStreamContentFactory.java │ │ │ ├── FileContentFactory.java │ │ │ ├── ByteArrayContentFactory.java │ │ │ ├── Joiner.java │ │ │ ├── FileCache.java │ │ │ └── IOUtils.java │ │ │ ├── xml │ │ │ ├── SPRResponseElement.java │ │ │ ├── TransferResponseElement.java │ │ │ ├── DownloadTransferResponseElement.java │ │ │ ├── ReceiptResponseElement.java │ │ │ ├── HPBRequestElement.java │ │ │ ├── HIARequestElement.java │ │ │ ├── HPBResponseOrderDataElement.java │ │ │ ├── INIRequestElement.java │ │ │ ├── DefaultResponseElement.java │ │ │ ├── SignaturePubKeyOrderDataElement.java │ │ │ ├── HIARequestOrderDataElement.java │ │ │ ├── InitializationResponseElement.java │ │ │ ├── KeyManagementResponseElement.java │ │ │ ├── DownloadTransferRequestElement.java │ │ │ ├── UserSignature.java │ │ │ ├── DownloadInitializationResponseElement.java │ │ │ ├── UploadTransferRequestElement.java │ │ │ ├── TransferRequestElement.java │ │ │ ├── UnsecuredRequestElement.java │ │ │ └── ReceiptRequestElement.java │ │ │ ├── letter │ │ │ ├── DefaultLetterManager.java │ │ │ ├── A005Letter.java │ │ │ ├── E002Letter.java │ │ │ └── X002Letter.java │ │ │ └── messages │ │ │ └── Messages.java │ ├── resources │ │ └── org │ │ │ └── kopi │ │ │ └── ebics │ │ │ ├── client │ │ │ ├── messages_fr.properties │ │ │ ├── config.properties │ │ │ └── messages_en.properties │ │ │ ├── exception │ │ │ ├── messages_fr.properties │ │ │ └── messages_en.properties │ │ │ ├── letter │ │ │ ├── messages_en.properties │ │ │ └── messages_fr.properties │ │ │ └── format │ │ │ ├── FileTypes_en.properties │ │ │ └── FileTypes_fr.properties │ └── xsd │ │ ├── ebics_H005.xsd │ │ └── config │ │ └── config.xsdconfig └── test │ └── java │ └── org │ └── kopi │ └── ebics │ ├── exception │ └── ReturnCodeTest.java │ ├── messages │ └── MessagesTest.java │ ├── io │ └── SplitterTest.java │ └── certificate │ └── CertificateManagerTest.java ├── .mvn └── wrapper │ └── maven-wrapper.properties ├── ebics-template.txt ├── .github └── workflows │ └── maven.yml ├── README.md └── pom.xml /jitpack.yml: -------------------------------------------------------------------------------- 1 | jdk: 2 | - openjdk17 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | .idea 3 | *.iml 4 | /client/ 5 | -------------------------------------------------------------------------------- /src/main/java/org/kopi/ebics/interfaces/EbicsOrderType.java: -------------------------------------------------------------------------------- 1 | package org.kopi.ebics.interfaces; 2 | 3 | public interface EbicsOrderType { 4 | 5 | String getCode(); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /src/main/resources/org/kopi/ebics/client/messages_fr.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ebics-java/ebics-java-client/HEAD/src/main/resources/org/kopi/ebics/client/messages_fr.properties -------------------------------------------------------------------------------- /src/main/resources/org/kopi/ebics/exception/messages_fr.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ebics-java/ebics-java-client/HEAD/src/main/resources/org/kopi/ebics/exception/messages_fr.properties -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | wrapperVersion=3.3.4 2 | distributionType=only-script 3 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.11/apache-maven-3.9.11-bin.zip 4 | -------------------------------------------------------------------------------- /ebics-template.txt: -------------------------------------------------------------------------------- 1 | password= 2 | userId= 3 | partnerId= 4 | hostId= 5 | bank.url= 6 | bank.name= 7 | user.name= 8 | user.email= 9 | user.country= 10 | user.org= 11 | languageCode=de 12 | countryCode=DE 13 | productName=EBICS Java Kernel 1.0 -------------------------------------------------------------------------------- /src/main/java/org/kopi/ebics/client/EbicsUploadParams.java: -------------------------------------------------------------------------------- 1 | package org.kopi.ebics.client; 2 | 3 | public record EbicsUploadParams(String orderId, OrderParams orderParams) { 4 | 5 | public record OrderParams(String serviceName, String scope, String option, String messageName, 6 | String messageVersion, boolean signatureFlag) { 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/test/java/org/kopi/ebics/exception/ReturnCodeTest.java: -------------------------------------------------------------------------------- 1 | package org.kopi.ebics.exception; 2 | 3 | import static org.junit.jupiter.api.Assertions.assertEquals; 4 | 5 | import org.junit.jupiter.api.Test; 6 | 7 | class ReturnCodeTest { 8 | 9 | @Test 10 | void test() { 11 | assertEquals(0, ReturnCode.EBICS_OK.getCode()); 12 | assertEquals("EBICS_OK", ReturnCode.EBICS_OK.getSymbolicName()); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /.github/workflows/maven.yml: -------------------------------------------------------------------------------- 1 | name: Java CI with Maven 2 | 3 | on: 4 | push: 5 | branches: [ "master" ] 6 | pull_request: 7 | branches: [ "master" ] 8 | 9 | jobs: 10 | build: 11 | 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - uses: actions/checkout@v4 16 | - name: Set up JDK 17 17 | uses: actions/setup-java@v4 18 | with: 19 | java-version: '17' 20 | distribution: 'temurin' 21 | cache: maven 22 | - name: Build with Maven 23 | run: mvn -B package --file pom.xml 24 | 25 | # Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive 26 | - name: Update dependency graph 27 | uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6 28 | -------------------------------------------------------------------------------- /src/test/java/org/kopi/ebics/messages/MessagesTest.java: -------------------------------------------------------------------------------- 1 | package org.kopi.ebics.messages; 2 | 3 | import static org.junit.jupiter.api.Assertions.assertEquals; 4 | import static org.junit.jupiter.api.Assertions.assertThrows; 5 | 6 | import java.util.Locale; 7 | 8 | import org.junit.jupiter.api.Test; 9 | import org.junit.jupiter.api.function.Executable; 10 | 11 | class MessagesTest { 12 | 13 | @Test 14 | void getString() { 15 | // fallback to english 16 | Messages messages = new Messages("org.kopi.ebics.letter.messages", Locale.CHINA); 17 | assertEquals("dd.MM.yyyy", messages.getString("Letter.dateFormat")); 18 | } 19 | 20 | @Test 21 | void throwWhenUnknownBundle() { 22 | assertThrows(RuntimeException.class, new Executable() { 23 | @Override 24 | public void execute() { 25 | new Messages("org.kopi.ebics.letter.messages_unknown"); 26 | } 27 | }); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/xsd/ebics_H005.xsd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ebics_H005.xsd inkludiert alle Schemadateien des EBICS-Protokolls, um die Eindeutigkeit von Element- und Typnamen im EBCIS Namespace zu erzwingen. 5 | ebics_H005.xsd includes all schema files for the EBICS protocol in order to enforce unique element and type names in the EBICS namespace. 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/main/xsd/config/config.xsdconfig: -------------------------------------------------------------------------------- 1 | 8 | 9 | 10 | org.kopi.ebics.schema.h000 11 | 12 | 13 | 14 | org.kopi.ebics.schema.h003 15 | 16 | 17 | 18 | org.kopi.ebics.schema.h005 19 | 20 | 21 | 22 | org.kopi.ebics.schema.xmldsig 23 | 24 | 25 | 26 | org.kopi.ebics.schema.s001 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/main/java/org/kopi/ebics/utils/Constants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1990-2012 kopiLeft Development SARL, Bizerte, Tunisia 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License version 2.1 as published by the Free Software Foundation. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | * 17 | */ 18 | 19 | package org.kopi.ebics.utils; 20 | 21 | import java.text.SimpleDateFormat; 22 | 23 | /** 24 | * Application constants. 25 | * 26 | * 27 | */ 28 | public interface Constants { 29 | 30 | String APPLICATION_BUNDLE_NAME = "org.kopi.ebics.client.messages"; 31 | SimpleDateFormat DEFAULT_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd"); 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/org/kopi/ebics/interfaces/PasswordCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1990-2012 kopiLeft Development SARL, Bizerte, Tunisia 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License version 2.1 as published by the Free Software Foundation. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | * 17 | */ 18 | 19 | package org.kopi.ebics.interfaces; 20 | 21 | /** 22 | * A way to obtain a password. 23 | * 24 | * 25 | */ 26 | public interface PasswordCallback { 27 | 28 | /** 29 | * Returns the password. 30 | * This may be done via user interaction or by passing a stored password. 31 | * @return the password 32 | */ 33 | char[] getPassword(); 34 | } 35 | -------------------------------------------------------------------------------- /src/main/resources/org/kopi/ebics/client/config.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 1990-2012 kopiLeft Development SARL 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License version 2.1 as published by the Free Software Foundation. 7 | # 8 | # This library is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | # Lesser General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU Lesser General Public 14 | # License along with this library; if not, write to the Free Software 15 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | # 17 | # $Id: config.properties 2 2012-02-28 09:39:55Z bentaher $ 18 | # 19 | 20 | conf.file.name=ebics.properties 21 | keystore.dir.name=keystore 22 | traces.dir.name=traces 23 | serialization.dir.name=serialized 24 | ssltruststore.dir.name=ssl 25 | sslkeystore.dir.name=ssl 26 | sslbankcert.dir.name=ssl 27 | users.dir.name=users 28 | letters.dir.name=letters 29 | signature.version=A005 30 | authentication.version=X002 31 | encryption.version=E002 32 | ebics.version=H003 33 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | EBICS Java Client 2 | ===== 3 | 4 | This library allows to interact with banks using the EBICS (Electronic Banking Internet Communication Standard) 5 | 6 | You can use the `EbicsClient` as command line tool or use it from your Java application. 7 | 8 | Features: 9 | 10 | - EBICS 3.0 11 | - Support for French, German and Swiss banks 12 | - Command line client to do the setup, initialization and to download files from the bank 13 | - Tested extensively with [ZKB](https://zkb.ch) 14 | 15 | How to get started: 16 | 17 | https://github.com/ebics-java/ebics-java-client/wiki/EBICS-Client-HowTo 18 | 19 | You can build it directly from the source with maven or use the releases from [JitPack](https://jitpack.io/#ebics-java/ebics-java-client/). 20 | 21 | Gradle: 22 | ``` 23 | allprojects { 24 | repositories { 25 | ... 26 | maven { url 'https://jitpack.io' } 27 | } 28 | } 29 | 30 | dependencies { 31 | implementation 'com.github.ebics-java:ebics-java-client:2.0.0' 32 | } 33 | ``` 34 | Maven 35 | ``` 36 | 37 | 38 | jitpack.io 39 | https://jitpack.io 40 | 41 | 42 | 43 | 44 | com.github.ebics-java 45 | ebics-java-client 46 | 2.0.0 47 | 48 | ``` 49 | 50 | 51 | -------------------------------------------------------------------------------- /src/main/java/org/kopi/ebics/interfaces/EbicsPartner.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1990-2012 kopiLeft Development SARL, Bizerte, Tunisia 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License version 2.1 as published by the Free Software Foundation. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | * 17 | */ 18 | 19 | package org.kopi.ebics.interfaces; 20 | 21 | /** 22 | * Information about an EBICS customer. 23 | * 24 | * 25 | */ 26 | public interface EbicsPartner { 27 | 28 | /** 29 | * Returns the bank we are customer of. 30 | * @return the bank we are customer of 31 | */ 32 | EbicsBank getBank(); 33 | 34 | /** 35 | * Returns the customers id at the bank. 36 | * @return the customers id at the bank. 37 | */ 38 | String getPartnerId(); 39 | 40 | /** 41 | * Creates the next order number. 42 | * @return the next order number. 43 | */ 44 | String nextOrderId(); 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/org/kopi/ebics/interfaces/ContentFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1990-2012 kopiLeft Development SARL, Bizerte, Tunisia 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License version 2.1 as published by the Free Software Foundation. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | * 17 | */ 18 | 19 | package org.kopi.ebics.interfaces; 20 | 21 | import java.io.IOException; 22 | import java.io.InputStream; 23 | import java.io.Serializable; 24 | 25 | public interface ContentFactory extends Serializable { 26 | 27 | /** 28 | * Returns a new data source of the data to be sent. 29 | * The instance must ensure that the returned stream will 30 | * deliver the identical data during the lifetime of this instance. 31 | * Nevertheless, how often the method will be called. 32 | * @return a new data source of the data to be sent. 33 | * @throws IOException 34 | */ 35 | InputStream getContent() throws IOException; 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/org/kopi/ebics/certificate/X509Constants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1990-2012 kopiLeft Development SARL, Bizerte, Tunisia 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License version 2.1 as published by the Free Software Foundation. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | * 17 | */ 18 | 19 | package org.kopi.ebics.certificate; 20 | 21 | /** 22 | * X509 certificate constants 23 | * 24 | * 25 | */ 26 | public interface X509Constants { 27 | 28 | /** 29 | * Certificates key usage 30 | */ 31 | enum CertificateKeyUsage { 32 | SIGNATURE_KEY_USAGE, AUTHENTICATION_KEY_USAGE, ENCRYPTION_KEY_USAGE, 33 | } 34 | 35 | /** 36 | * Certificate signature algorithm 37 | */ 38 | String SIGNATURE_ALGORITHM = "SHA256WithRSAEncryption"; 39 | 40 | /** 41 | * Default days validity of a certificate 42 | */ 43 | int DEFAULT_DURATION = 10 * 365; 44 | 45 | /** 46 | * EBICS key size 47 | */ 48 | int EBICS_KEY_SIZE = 2048; 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/org/kopi/ebics/interfaces/EbicsElement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1990-2012 kopiLeft Development SARL, Bizerte, Tunisia 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License version 2.1 as published by the Free Software Foundation. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | * 17 | */ 18 | 19 | package org.kopi.ebics.interfaces; 20 | 21 | import java.io.PrintStream; 22 | import java.io.Serializable; 23 | 24 | import org.kopi.ebics.exception.EbicsException; 25 | 26 | 27 | public interface EbicsElement extends Serializable { 28 | 29 | /** 30 | * Returns the name of this EbicsElement 31 | * @return the name of the element 32 | */ 33 | String getName(); 34 | 35 | /** 36 | * Builds the EbicsElement XML fragment 37 | * @throws EbicsException 38 | */ 39 | void build() throws EbicsException; 40 | 41 | /** 42 | * Prints the EbicsElement into 43 | * the given stream. 44 | * @param stream the print stream 45 | */ 46 | void print(PrintStream stream); 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/org/kopi/ebics/exception/NoDownloadDataAvailableException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1990-2012 kopiLeft Development SARL, Bizerte, Tunisia 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License version 2.1 as published by the Free Software Foundation. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | * 17 | */ 18 | 19 | package org.kopi.ebics.exception; 20 | 21 | /** 22 | * Download operation failed due to lack of data. 23 | * 24 | * 25 | */ 26 | public class NoDownloadDataAvailableException extends EbicsException { 27 | public NoDownloadDataAvailableException() { 28 | super(ReturnCode.EBICS_NO_DOWNLOAD_DATA_AVAILABLE); 29 | } 30 | public NoDownloadDataAvailableException(String message) { 31 | super(ReturnCode.EBICS_NO_DOWNLOAD_DATA_AVAILABLE, message); 32 | } 33 | 34 | // -------------------------------------------------------------------- 35 | // DATA MEMBERS 36 | // -------------------------------------------------------------------- 37 | 38 | private static final long serialVersionUID = -5156261061322817326L; 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/org/kopi/ebics/interfaces/Savable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1990-2012 kopiLeft Development SARL, Bizerte, Tunisia 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License version 2.1 as published by the Free Software Foundation. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | * 17 | */ 18 | 19 | package org.kopi.ebics.interfaces; 20 | 21 | import java.io.IOException; 22 | import java.io.ObjectOutputStream; 23 | 24 | /** 25 | * The Savable is an element that can be stored in a disk support, 26 | * files or databases. The save process can be launched via the method 27 | * {@linkplain Savable#save(ObjectOutputStream)} 28 | * 29 | * 30 | */ 31 | public interface Savable { 32 | 33 | /** 34 | * Writes all persistable attributes to the given stream. 35 | * @param oos the given stream. 36 | * @throws IOException save process failed 37 | */ 38 | void save(ObjectOutputStream oos) throws IOException; 39 | 40 | /** 41 | * Returns the save name of this savable object. 42 | * @return the save name 43 | */ 44 | String getSaveName(); 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/org/kopi/ebics/session/OrderType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1990-2012 kopiLeft Development SARL, Bizerte, Tunisia 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License version 2.1 as published by the Free Software Foundation. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | * 17 | */ 18 | 19 | package org.kopi.ebics.session; 20 | 21 | import org.kopi.ebics.interfaces.EbicsOrderType; 22 | 23 | /** 24 | * A BCS order type. 25 | * 26 | * 27 | */ 28 | public enum OrderType implements EbicsOrderType { 29 | HIA, 30 | HAA, 31 | HKD, 32 | HPB, 33 | HPD, 34 | HTD, 35 | INI, 36 | FUL, 37 | FDL, 38 | SPR, 39 | AZV, 40 | C2C, 41 | CCC, 42 | CCT, 43 | CCU, 44 | CD1, 45 | CDB, 46 | CDC, 47 | CDD, 48 | DTE, 49 | EUE, 50 | HAC, 51 | PTK, 52 | STA, 53 | VMK, 54 | ZDF, 55 | ZB6, 56 | Z01, 57 | XKD, 58 | XE2, 59 | XCT, 60 | C52, 61 | C53, 62 | C54; 63 | 64 | @Override 65 | public String getCode() { 66 | return name(); 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/org/kopi/ebics/security/UserPasswordHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1990-2012 kopiLeft Development SARL, Bizerte, Tunisia 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License version 2.1 as published by the Free Software Foundation. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | * 17 | */ 18 | 19 | package org.kopi.ebics.security; 20 | 21 | import org.kopi.ebics.interfaces.PasswordCallback; 22 | 23 | /** 24 | * A simple user password handler that creates a password 25 | * from the user id and a simple suffix. 26 | * 27 | * 28 | */ 29 | public class UserPasswordHandler implements PasswordCallback { 30 | 31 | /** 32 | * Creates a new user password handler from a given user id 33 | * and a given suffix. 34 | * @param userId the user id. 35 | * @param suffix the user suffix. 36 | */ 37 | public UserPasswordHandler(String userId, String suffix) { 38 | this.userId = userId; 39 | this.suffix = suffix; 40 | } 41 | 42 | @Override 43 | public char[] getPassword() { 44 | String pwd; 45 | 46 | pwd = userId + suffix; 47 | return pwd.toCharArray(); 48 | } 49 | 50 | // -------------------------------------------------------------------- 51 | // DATA MEMBERS 52 | // -------------------------------------------------------------------- 53 | 54 | private final String userId; 55 | private final String suffix; 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/org/kopi/ebics/io/InputStreamContentFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1990-2012 kopiLeft Development SARL, Bizerte, Tunisia 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License version 2.1 as published by the Free Software Foundation. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | * 17 | */ 18 | 19 | package org.kopi.ebics.io; 20 | 21 | import java.io.IOException; 22 | import java.io.InputStream; 23 | 24 | import org.kopi.ebics.interfaces.ContentFactory; 25 | 26 | 27 | /** 28 | * Input stream content factory that delivers the its content 29 | * as an InputStream 30 | * This object is serializable in a way to recover interrupted 31 | * file transfers. 32 | * 33 | * 34 | */ 35 | public class InputStreamContentFactory implements ContentFactory { 36 | 37 | /** 38 | * Creates a new ContentFactory from an input stream 39 | * @param input the given input stream. 40 | */ 41 | public InputStreamContentFactory(InputStream input) { 42 | this.input = input; 43 | } 44 | 45 | @Override 46 | public InputStream getContent() throws IOException { 47 | return input; 48 | } 49 | 50 | // -------------------------------------------------------------------- 51 | // DATA MEMBERS 52 | // -------------------------------------------------------------------- 53 | 54 | private final InputStream input; 55 | private static final long serialVersionUID = 2357104115203917168L; 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/org/kopi/ebics/interfaces/SerializationManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1990-2012 kopiLeft Development SARL, Bizerte, Tunisia 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License version 2.1 as published by the Free Software Foundation. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | * 17 | */ 18 | 19 | package org.kopi.ebics.interfaces; 20 | 21 | import java.io.File; 22 | import java.io.ObjectInputStream; 23 | 24 | import org.kopi.ebics.exception.EbicsException; 25 | 26 | 27 | /** 28 | * A mean to serialize and deserialize Object. 29 | * The manager should ensure serialization and deserialization 30 | * operations 31 | * 32 | * 33 | */ 34 | public interface SerializationManager { 35 | 36 | /** 37 | * Serializes a Savable object 38 | * @param object the Savable object$ 39 | * @throws EbicsException serialization fails 40 | */ 41 | void serialize(Savable object) throws EbicsException; 42 | 43 | /** 44 | * Deserializes the given object input stream. 45 | * @param name the name of the serialized object 46 | * @return the corresponding object input stream 47 | * @throws EbicsException deserialization fails 48 | */ 49 | ObjectInputStream deserialize(String name) throws EbicsException; 50 | 51 | /** 52 | * Sets the serialization directory 53 | * @param serializationDir the serialization directory 54 | */ 55 | void setSerializationDirectory(File serializationDir); 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/org/kopi/ebics/io/FileContentFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1990-2012 kopiLeft Development SARL, Bizerte, Tunisia 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License version 2.1 as published by the Free Software Foundation. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | * 17 | */ 18 | 19 | package org.kopi.ebics.io; 20 | 21 | import java.io.File; 22 | import java.io.FileInputStream; 23 | import java.io.IOException; 24 | import java.io.InputStream; 25 | 26 | import org.kopi.ebics.interfaces.ContentFactory; 27 | 28 | 29 | /** 30 | * File content factory that delivers the file content 31 | * as a FileInputStream. This object is 32 | * serializable in a way to recover interrupted file transfers. 33 | * 34 | * 35 | */ 36 | public class FileContentFactory implements ContentFactory { 37 | 38 | /** 39 | * Constructs a new FileContentFactory with 40 | * a given input file 41 | * @param input the input file 42 | */ 43 | public FileContentFactory(File input) { 44 | this.input = input; 45 | } 46 | 47 | @Override 48 | public InputStream getContent() throws IOException { 49 | return new FileInputStream(input); 50 | } 51 | 52 | // -------------------------------------------------------------------- 53 | // DATA MEMBERS 54 | // -------------------------------------------------------------------- 55 | 56 | private final File input; 57 | private static final long serialVersionUID = -7041705645994170039L; 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/org/kopi/ebics/interfaces/EbicsRootElement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1990-2012 kopiLeft Development SARL, Bizerte, Tunisia 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License version 2.1 as published by the Free Software Foundation. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | * 17 | */ 18 | 19 | package org.kopi.ebics.interfaces; 20 | 21 | import java.io.OutputStream; 22 | 23 | import org.kopi.ebics.exception.EbicsException; 24 | 25 | 26 | /** 27 | * An Ebics root element knows its name. 28 | * 29 | * 30 | */ 31 | public interface EbicsRootElement extends EbicsElement { 32 | 33 | /** 34 | * Converts the EbicsElement to a byte array 35 | * @return the equivalent byte array of this EbicsElement 36 | */ 37 | byte[] toByteArray(); 38 | 39 | /** 40 | * Validates the request element according to the 41 | * EBICS XML schema specification 42 | * @throws EbicsException throws an EbicsException when validation fails 43 | */ 44 | void validate() throws EbicsException; 45 | 46 | /** 47 | * Adds a namespace declaration for the EbicsRootElement 48 | * @param prefix namespace prefix 49 | * @param uri namespace uri 50 | */ 51 | void addNamespaceDecl(String prefix, String uri); 52 | 53 | /** 54 | * Saves the EbicsElement into a given output stream. 55 | * @param out the output stream 56 | * @throws EbicsException the save operation fails 57 | */ 58 | void save(OutputStream out) throws EbicsException; 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/org/kopi/ebics/interfaces/InitLetter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1990-2012 kopiLeft Development SARL, Bizerte, Tunisia 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License version 2.1 as published by the Free Software Foundation. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | * 17 | */ 18 | 19 | package org.kopi.ebics.interfaces; 20 | 21 | import java.io.IOException; 22 | import java.io.OutputStream; 23 | import java.security.GeneralSecurityException; 24 | 25 | import org.kopi.ebics.exception.EbicsException; 26 | 27 | 28 | /** 29 | * The InitLetter is an abstract initialization 30 | * letter. The INI, HIA and HPB letters should be an implementation 31 | * of the InitLetter 32 | * 33 | * 34 | */ 35 | public interface InitLetter { 36 | 37 | /** 38 | * Creates an InitLetter for a given EbicsUser 39 | * @param user the ebics user. 40 | * @throws EbicsException 41 | * @throws IOException 42 | * @throws GeneralSecurityException 43 | */ 44 | void create(EbicsUser user) 45 | throws GeneralSecurityException, IOException, EbicsException; 46 | 47 | /** 48 | * Saves the InitLetter to the given output stream. 49 | * @param output the output stream. 50 | * @throws IOException Save error. 51 | */ 52 | void writeTo(OutputStream output) throws IOException; 53 | 54 | /** 55 | * Returns the initialization letter title. 56 | * @return the letter title. 57 | */ 58 | String getTitle(); 59 | 60 | /** 61 | * Returns the letter name. 62 | * @return the letter name. 63 | */ 64 | String getName(); 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/org/kopi/ebics/io/ByteArrayContentFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1990-2012 kopiLeft Development SARL, Bizerte, Tunisia 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License version 2.1 as published by the Free Software Foundation. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | * 17 | */ 18 | 19 | package org.kopi.ebics.io; 20 | 21 | import java.io.ByteArrayInputStream; 22 | import java.io.IOException; 23 | import java.io.InputStream; 24 | import java.nio.charset.StandardCharsets; 25 | 26 | import org.kopi.ebics.interfaces.ContentFactory; 27 | 28 | 29 | /** 30 | * Byte array content factory that delivers the file content 31 | * as a ByteArrayInputStream. This object is 32 | * serializable in a way to recover interrupted file transfers. 33 | * 34 | * 35 | */ 36 | public class ByteArrayContentFactory implements ContentFactory { 37 | 38 | /** 39 | * Constructs a new ByteArrayContentFactory with 40 | * a given byte array content. 41 | * @param content the byte array content 42 | */ 43 | public ByteArrayContentFactory(byte[] content) { 44 | this.content = content; 45 | } 46 | 47 | @Override 48 | public InputStream getContent() throws IOException { 49 | return new ByteArrayInputStream(content); 50 | } 51 | 52 | 53 | @Override 54 | public String toString() { 55 | return new String(content, StandardCharsets.UTF_8); 56 | } 57 | 58 | // -------------------------------------------------------------------- 59 | // DATA MEMBERS 60 | // -------------------------------------------------------------------- 61 | 62 | private final byte[] content; 63 | private static final long serialVersionUID = 4708928447888655116L; 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/org/kopi/ebics/interfaces/TraceManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1990-2012 kopiLeft Development SARL, Bizerte, Tunisia 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License version 2.1 as published by the Free Software Foundation. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | * 17 | */ 18 | 19 | package org.kopi.ebics.interfaces; 20 | 21 | import java.io.File; 22 | 23 | import org.kopi.ebics.exception.EbicsException; 24 | 25 | /** 26 | * A mean to make EBICS transfer logged by saving 27 | * requests and responses from the EBICS bank server. 28 | * This can be done using the trace(EbicsRootElement) 29 | * 30 | * 31 | */ 32 | public interface TraceManager { 33 | 34 | /** 35 | * Saves the EbicsRootElement in the traces 36 | * directory. This directory may be specified by the 37 | * EbicsConfiguration client configuration. 38 | * 39 | * @param element the element to trace 40 | * @throws EbicsException cannot trace the ebics element 41 | * 42 | * @see org.kopi.ebics.interfaces.Configuration#isTraceEnabled() isTraceEnabled() 43 | */ 44 | void trace(EbicsRootElement element) throws EbicsException; 45 | 46 | /** 47 | * Removes an EbicsRootElement from trace 48 | * directory. 49 | * @param element the element to ve removed. 50 | */ 51 | void remove(EbicsRootElement element); 52 | 53 | /** 54 | * Clears the traces created for a given ebics session 55 | */ 56 | void clear(); 57 | 58 | /** 59 | * Sets the trace directory 60 | */ 61 | void setTraceDirectory(File traceDir); 62 | 63 | /** 64 | * Enables or disables the trace feature 65 | * @param enabled is trace enabled? 66 | */ 67 | void setTraceEnabled(boolean enabled); 68 | 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/org/kopi/ebics/xml/SPRResponseElement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1990-2012 kopiLeft Development SARL, Bizerte, Tunisia 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License version 2.1 as published by the Free Software Foundation. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | * 17 | */ 18 | 19 | package org.kopi.ebics.xml; 20 | 21 | import org.kopi.ebics.exception.EbicsException; 22 | import org.kopi.ebics.exception.ReturnCode; 23 | import org.kopi.ebics.interfaces.ContentFactory; 24 | import org.kopi.ebics.schema.h005.EbicsResponseDocument; 25 | import org.kopi.ebics.schema.h005.EbicsResponseDocument.EbicsResponse; 26 | 27 | /** 28 | * The SPRResponseElement is the response element 29 | * for an ebics subscriber revoking. 30 | * 31 | * 32 | */ 33 | public class SPRResponseElement extends DefaultResponseElement { 34 | 35 | /** 36 | * Constructs a new SPR response element. 37 | * @param factory the content factory 38 | */ 39 | public SPRResponseElement(ContentFactory factory) { 40 | super(factory, "SPRResponse.xml"); 41 | } 42 | 43 | @Override 44 | public void build() throws EbicsException { 45 | var doc = parse(factory, EbicsResponseDocument.Factory); 46 | response =doc.getEbicsResponse(); 47 | String code = response.getHeader().getMutable().getReturnCode(); 48 | String text = response.getHeader().getMutable().getReportText(); 49 | returnCode = ReturnCode.toReturnCode(code, text); 50 | report(); 51 | } 52 | 53 | // -------------------------------------------------------------------- 54 | // DATA MEMBERS 55 | // -------------------------------------------------------------------- 56 | 57 | private EbicsResponse response; 58 | private static final long serialVersionUID = 8632578696636481642L; 59 | } 60 | -------------------------------------------------------------------------------- /src/main/resources/org/kopi/ebics/letter/messages_en.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 1990-2012 kopiLeft Development SARL 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License version 2.1 as published by the Free Software Foundation. 7 | # 8 | # This library is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | # Lesser General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU Lesser General Public 14 | # License along with this library; if not, write to the Free Software 15 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | # 17 | # $Id: messages_en.properties 2 2012-02-28 09:39:55Z bentaher $ 18 | # 19 | 20 | #Common for all letters 21 | Letter.bank = Bank: 22 | Letter.date = Date: 23 | Letter.dateFormat = dd.MM.yyyy 24 | Letter.timeFormat = HH:mm 25 | Letter.hostId = Host ID: 26 | Letter.partnerId = Partner ID: 27 | Letter.signature = Signature: 28 | Letter.time = Time: 29 | Letter.userId = User ID: 30 | Letter.username = User Name: 31 | Letter.version = Version: 32 | 33 | #INI letter 34 | INILetter.title = Initialization letter for signature certificate 35 | INILetter.version = A005 Signature 36 | INILetter.certificate = Electronic signature certificate: 37 | INILetter.digest = Signature certificate hash (SHA-256): 38 | INILetter.name = A005Letter 39 | 40 | #HIA letter 41 | HIALetter.x002.title = Initialization letter for authentication certificate 42 | HIALetter.x002.version = X002 Authentication 43 | HIALetter.x002.certificate = Electronic authentication certificate: 44 | HIALetter.x002.digest = Authentication certificate hash (SHA-256): 45 | HIALetter.x002.name = X002Letter 46 | 47 | HIALetter.e002.title = Initialization letter for encryption certificate 48 | HIALetter.e002.version = E002 Encryption 49 | HIALetter.e002.certificate = Electronic encryption certificate: 50 | HIALetter.e002.digest = Encryption certificate hash (SHA-256): 51 | HIALetter.e002.name = E002Letter 52 | -------------------------------------------------------------------------------- /src/main/java/org/kopi/ebics/xml/TransferResponseElement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1990-2012 kopiLeft Development SARL, Bizerte, Tunisia 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License version 2.1 as published by the Free Software Foundation. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | * 17 | */ 18 | 19 | package org.kopi.ebics.xml; 20 | 21 | import org.kopi.ebics.exception.EbicsException; 22 | import org.kopi.ebics.exception.ReturnCode; 23 | import org.kopi.ebics.interfaces.ContentFactory; 24 | import org.kopi.ebics.schema.h005.EbicsResponseDocument; 25 | import org.kopi.ebics.schema.h005.EbicsResponseDocument.EbicsResponse; 26 | 27 | /** 28 | * The TransferResponseElement is the common element 29 | * response for all ebics transfers. 30 | * 31 | * 32 | */ 33 | public class TransferResponseElement extends DefaultResponseElement { 34 | 35 | /** 36 | * Constructs a new TransferResponseElement element. 37 | * @param factory the content factory 38 | * @param name the element name; 39 | */ 40 | public TransferResponseElement(ContentFactory factory, String name) { 41 | super(factory, name); 42 | } 43 | 44 | @Override 45 | public void build() throws EbicsException { 46 | var doc = parse(factory, EbicsResponseDocument.Factory); 47 | response = doc.getEbicsResponse(); 48 | String code = response.getHeader().getMutable().getReturnCode(); 49 | String text = response.getHeader().getMutable().getReportText(); 50 | returnCode = ReturnCode.toReturnCode(code, text); 51 | report(); 52 | } 53 | 54 | // -------------------------------------------------------------------- 55 | // DATA MEMBERS 56 | // -------------------------------------------------------------------- 57 | 58 | protected EbicsResponse response; 59 | private static final long serialVersionUID = 7454118286687793155L; 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/org/kopi/ebics/xml/DownloadTransferResponseElement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1990-2012 kopiLeft Development SARL, Bizerte, Tunisia 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License version 2.1 as published by the Free Software Foundation. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | * 17 | */ 18 | 19 | package org.kopi.ebics.xml; 20 | 21 | import org.kopi.ebics.exception.EbicsException; 22 | import org.kopi.ebics.interfaces.ContentFactory; 23 | import org.kopi.ebics.interfaces.EbicsOrderType; 24 | 25 | /** 26 | * The DTransferResponseElement is the response element 27 | * for all ebics downloads transfers. 28 | * 29 | * 30 | */ 31 | public class DownloadTransferResponseElement extends TransferResponseElement { 32 | 33 | /** 34 | * Constructs a new DTransferResponseElement object. 35 | * @param factory the content factory 36 | * @param orderType the order type 37 | * @param name the element name. 38 | */ 39 | public DownloadTransferResponseElement(ContentFactory factory, 40 | EbicsOrderType orderType, 41 | String name) 42 | { 43 | super(factory, name); 44 | } 45 | 46 | @Override 47 | public void build() throws EbicsException { 48 | super.build(); 49 | 50 | orderData = response.getBody().getDataTransfer().getOrderData().getByteArrayValue(); 51 | } 52 | 53 | /** 54 | * Returns the order data. 55 | * @return the order data. 56 | */ 57 | public byte[] getOrderData() { 58 | return orderData; 59 | } 60 | 61 | // -------------------------------------------------------------------- 62 | // DATA MEMBERS 63 | // -------------------------------------------------------------------- 64 | 65 | private byte[] orderData; 66 | private static final long serialVersionUID = -3317833033395561745L; 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/org/kopi/ebics/xml/ReceiptResponseElement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1990-2012 kopiLeft Development SARL, Bizerte, Tunisia 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License version 2.1 as published by the Free Software Foundation. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | * 17 | */ 18 | 19 | package org.kopi.ebics.xml; 20 | 21 | import org.kopi.ebics.exception.EbicsException; 22 | import org.kopi.ebics.exception.ReturnCode; 23 | import org.kopi.ebics.interfaces.ContentFactory; 24 | import org.kopi.ebics.schema.h005.EbicsResponseDocument; 25 | 26 | /** 27 | * The ReceiptResponseElement is the response element 28 | * for ebics receipt request. 29 | * 30 | * 31 | */ 32 | public class ReceiptResponseElement extends DefaultResponseElement { 33 | 34 | /** 35 | * Constructs a new ReceiptResponseElement object 36 | * @param factory the content factory 37 | * @param name the element name 38 | */ 39 | public ReceiptResponseElement(ContentFactory factory, String name) { 40 | super(factory, name); 41 | } 42 | 43 | @Override 44 | public void build() throws EbicsException { 45 | var doc = parse(factory, EbicsResponseDocument.Factory); 46 | var response = doc.getEbicsResponse(); 47 | String code = response.getHeader().getMutable().getReturnCode(); 48 | String text = response.getHeader().getMutable().getReportText(); 49 | returnCode = ReturnCode.toReturnCode(code, text); 50 | report(); 51 | } 52 | 53 | @Override 54 | public void report() throws EbicsException { 55 | if (!returnCode.equals(ReturnCode.EBICS_DOWNLOAD_POSTPROCESS_DONE)) { 56 | returnCode.throwException(); 57 | } 58 | } 59 | 60 | // -------------------------------------------------------------------- 61 | // DATA MEMBERS 62 | // -------------------------------------------------------------------- 63 | 64 | private static final long serialVersionUID = 2994403708414164919L; 65 | } 66 | -------------------------------------------------------------------------------- /src/main/resources/org/kopi/ebics/letter/messages_fr.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 1990-2012 kopiLeft Development SARL 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License version 2.1 as published by the Free Software Foundation. 7 | # 8 | # This library is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | # Lesser General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU Lesser General Public 14 | # License along with this library; if not, write to the Free Software 15 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | # 17 | # $Id: messages_fr.properties 2 2012-02-28 09:39:55Z bentaher $ 18 | # 19 | 20 | #Common for all letters 21 | Letter.bank = Banque : 22 | Letter.date = Date : 23 | Letter.dateFormat = dd.MM.yyyy 24 | Letter.timeFormat = HH:mm 25 | Letter.hostId = ID H\u00F4te : 26 | Letter.partnerId = ID Partenaire : 27 | Letter.signature = Signature : 28 | Letter.time = Heure : 29 | Letter.userId = ID Utilisateur : 30 | Letter.username = Nom Utilisateur : 31 | Letter.version = Version : 32 | 33 | #INI letter 34 | INILetter.title = Lettre d'initialisation du certificat de signature 35 | INILetter.version = Signature A005 36 | INILetter.certificate = Certificat de signature \u00E9lectronique : 37 | INILetter.digest = Hash du certificat de signature (SHA-256) : 38 | INILetter.name = LettreA005 39 | 40 | #HIA letter 41 | HIALetter.x002.title = Lettre d'initialisation du certificat d'authentification 42 | HIALetter.x002.version = Authentification X002 43 | HIALetter.x002.certificate = Certificat d'authentification \u00E9lectronique : 44 | HIALetter.x002.digest = Hash du certificat d'authentification (SHA-256) : 45 | HIALetter.x002.name = LettreX002 46 | 47 | HIALetter.e002.title = Lettre d'initialisation du certificat de chiffrement 48 | HIALetter.e002.version = Chiffrement E002 49 | HIALetter.e002.certificate = Certificat de chiffrement \u00E9lectronique : 50 | HIALetter.e002.digest = Hash du certificat de chiffrement (SHA-256) : 51 | HIALetter.e002.name = LettreE002 52 | -------------------------------------------------------------------------------- /src/main/java/org/kopi/ebics/xml/HPBRequestElement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1990-2012 kopiLeft Development SARL, Bizerte, Tunisia 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License version 2.1 as published by the Free Software Foundation. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | * 17 | */ 18 | 19 | package org.kopi.ebics.xml; 20 | 21 | import org.kopi.ebics.exception.EbicsException; 22 | import org.kopi.ebics.session.EbicsSession; 23 | 24 | /** 25 | * The HPBRequestElement is the element to be sent when 26 | * a HPB request is needed to retrieve the bank public keys 27 | * 28 | * 29 | */ 30 | public class HPBRequestElement extends DefaultEbicsRootElement { 31 | 32 | /** 33 | * Constructs a new HPB Request element. 34 | * @param session the current ebics session. 35 | */ 36 | public HPBRequestElement(EbicsSession session) { 37 | super(session); 38 | } 39 | 40 | @Override 41 | public String getName() { 42 | return "HPBRequest.xml"; 43 | } 44 | 45 | @Override 46 | public void build() throws EbicsException { 47 | noPubKeyDigestsRequest = new NoPubKeyDigestsRequestElement(session); 48 | noPubKeyDigestsRequest.build(); 49 | var signedInfo = new SignedInfo(session.getUser(), noPubKeyDigestsRequest.getDigest()); 50 | signedInfo.build(); 51 | noPubKeyDigestsRequest.setAuthSignature(signedInfo.getSignatureType()); 52 | var signature = signedInfo.sign(noPubKeyDigestsRequest.toByteArray()); 53 | noPubKeyDigestsRequest.setSignatureValue(signature); 54 | } 55 | 56 | @Override 57 | public byte[] toByteArray() { 58 | return noPubKeyDigestsRequest.toByteArray(); 59 | } 60 | 61 | @Override 62 | public void validate() throws EbicsException { 63 | noPubKeyDigestsRequest.validate(); 64 | } 65 | 66 | // -------------------------------------------------------------------- 67 | // DATA MEMBERS 68 | // -------------------------------------------------------------------- 69 | 70 | private NoPubKeyDigestsRequestElement noPubKeyDigestsRequest; 71 | private static final long serialVersionUID = -5565390370996751973L; 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/org/kopi/ebics/exception/EbicsException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1990-2012 kopiLeft Development SARL, Bizerte, Tunisia 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License version 2.1 as published by the Free Software Foundation. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | * 17 | */ 18 | 19 | package org.kopi.ebics.exception; 20 | 21 | /** 22 | * Common exception for all EBICS errors. 23 | * 24 | * 25 | */ 26 | public class EbicsException extends Exception { 27 | 28 | /** 29 | * A means to construct a server error. 30 | */ 31 | public EbicsException(Throwable cause) { 32 | super(cause); 33 | } 34 | 35 | /** 36 | * A means to construct a server error with an additional message. 37 | * @param message the exception message 38 | */ 39 | public EbicsException(String message) { 40 | super(message); 41 | } 42 | 43 | public EbicsException(String message, Throwable cause) { 44 | super(message, cause); 45 | } 46 | /** 47 | * A means to construct a server error with no additional message. 48 | * @param returnCode the ebics return code. 49 | */ 50 | public EbicsException(ReturnCode returnCode) { 51 | super(returnCode.getText()); 52 | this.returnCode = returnCode; 53 | } 54 | 55 | /** 56 | * A means to construct a server error with an additional message. 57 | * @param returnCode the ebics return code. 58 | * @param message the additional message. 59 | */ 60 | public EbicsException(ReturnCode returnCode, String message) { 61 | super(message); 62 | this.returnCode = returnCode; 63 | } 64 | 65 | /** 66 | * Returns the standardized error code. 67 | * @return the standardized error code. 68 | */ 69 | public ReturnCode getReturnCode() { 70 | return returnCode; 71 | } 72 | 73 | // -------------------------------------------------------------------- 74 | // DATA MEMBERS 75 | // -------------------------------------------------------------------- 76 | 77 | private ReturnCode returnCode; 78 | private static final long serialVersionUID = 2728820344946361669L; 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/org/kopi/ebics/interfaces/LetterManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1990-2012 kopiLeft Development SARL, Bizerte, Tunisia 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License version 2.1 as published by the Free Software Foundation. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | * 17 | */ 18 | 19 | package org.kopi.ebics.interfaces; 20 | 21 | import java.io.IOException; 22 | import java.security.GeneralSecurityException; 23 | 24 | import org.kopi.ebics.exception.EbicsException; 25 | 26 | 27 | /** 28 | * Initialization letters manager. 29 | * Manages the INI, HIA and the HPB letters. 30 | * 31 | * 32 | */ 33 | public interface LetterManager { 34 | 35 | /** 36 | * Creates the initialization letter for the INI request. 37 | * This letter contains information about the signature certificate 38 | * of the given user. 39 | * @param user the ebics user. 40 | * @return the INI letter. 41 | * @throws EbicsException 42 | * @throws IOException 43 | * @throws GeneralSecurityException 44 | */ 45 | InitLetter createA005Letter(EbicsUser user) 46 | throws GeneralSecurityException, IOException, EbicsException; 47 | 48 | /** 49 | * Creates the initialization letter for the HIA request. 50 | * This letter contains information about the encryption 51 | * certificates of the given user. 52 | * @param user the ebics user 53 | * @return the HIA letter 54 | * @throws EbicsException 55 | * @throws IOException 56 | * @throws GeneralSecurityException 57 | */ 58 | InitLetter createE002Letter(EbicsUser user) 59 | throws GeneralSecurityException, IOException, EbicsException; 60 | 61 | /** 62 | * Creates the initialization letter for the HIA request. 63 | * This letter contains information about the authentication 64 | * certificates of the given user. 65 | * @param user the ebics user 66 | * @return the HIA letter 67 | * @throws EbicsException 68 | * @throws IOException 69 | * @throws GeneralSecurityException 70 | */ 71 | InitLetter createX002Letter(EbicsUser user) 72 | throws GeneralSecurityException, IOException, EbicsException; 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/org/kopi/ebics/io/Joiner.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1990-2012 kopiLeft Development SARL, Bizerte, Tunisia 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License version 2.1 as published by the Free Software Foundation. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | * 17 | */ 18 | 19 | package org.kopi.ebics.io; 20 | import java.io.ByteArrayOutputStream; 21 | import java.io.IOException; 22 | import java.io.OutputStream; 23 | import java.security.GeneralSecurityException; 24 | 25 | import org.kopi.ebics.exception.EbicsException; 26 | import org.kopi.ebics.interfaces.EbicsUser; 27 | import org.kopi.ebics.utils.Utils; 28 | 29 | 30 | /** 31 | * A simple mean to join downloaded segments from the 32 | * bank ebics server. 33 | * 34 | * 35 | */ 36 | public class Joiner { 37 | 38 | /** 39 | * Constructs a new Joiner object. 40 | * @param user the ebics user. 41 | */ 42 | public Joiner(EbicsUser user) { 43 | this.user = user; 44 | buffer = new ByteArrayOutputStream(); 45 | } 46 | 47 | public void append(byte[] data) throws EbicsException { 48 | try { 49 | buffer.write(data); 50 | buffer.flush(); 51 | } catch (IOException e) { 52 | throw new EbicsException(e.getMessage()); 53 | } 54 | } 55 | 56 | /** 57 | * Writes the joined part to an output stream. 58 | * @param output the output stream. 59 | * @param transactionKey the transaction key 60 | * @throws EbicsException 61 | */ 62 | public void writeTo(OutputStream output, byte[] transactionKey) 63 | throws EbicsException 64 | { 65 | try { 66 | byte[] decrypted; 67 | 68 | buffer.close(); 69 | decrypted = user.decrypt(buffer.toByteArray(), transactionKey); 70 | output.write(Utils.unzip(decrypted)); 71 | } catch (GeneralSecurityException | IOException e) { 72 | throw new EbicsException(e.getMessage()); 73 | } 74 | } 75 | 76 | // -------------------------------------------------------------------- 77 | // DATA MEMBERS 78 | // -------------------------------------------------------------------- 79 | 80 | private final EbicsUser user; 81 | private final ByteArrayOutputStream buffer; 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/org/kopi/ebics/io/FileCache.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1990-2012 kopiLeft Development SARL, Bizerte, Tunisia 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License version 2.1 as published by the Free Software Foundation. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | * 17 | */ 18 | 19 | package org.kopi.ebics.io; 20 | 21 | import java.io.File; 22 | import java.util.Hashtable; 23 | import java.util.Map; 24 | 25 | /** 26 | * A simple mean to cache created files. 27 | * 28 | * 29 | */ 30 | public class FileCache { 31 | 32 | /** 33 | * Constructs a new FileCache object 34 | * @param isTraceEnabled is trace enabled? 35 | */ 36 | public FileCache(boolean isTraceEnabled) { 37 | this.isTraceEnabled = isTraceEnabled; 38 | cache = new Hashtable<>(); 39 | } 40 | 41 | /** 42 | * Cache a new java.io.File in the cache buffer 43 | * @param file the file to cache 44 | * @return True if the file is cached 45 | */ 46 | public boolean add(File file) { 47 | if (cache.containsKey(file.getName())) { 48 | return false; 49 | } 50 | 51 | cache.put(file.getName(), file); 52 | 53 | return true; 54 | } 55 | 56 | /** 57 | * Removes the given java.io.file from the cache. 58 | * @param filename the file to remove 59 | * @return True if the file is removed 60 | */ 61 | public boolean remove(String filename) { 62 | if (!cache.containsKey(filename)) { 63 | return false; 64 | } 65 | 66 | cache.remove(filename); 67 | 68 | return true; 69 | } 70 | 71 | /** 72 | * Clears the cache buffer 73 | */ 74 | public void clear() { 75 | if (isTraceEnabled) { 76 | for (File file : cache.values()) { 77 | file.delete(); 78 | } 79 | } 80 | 81 | cache.clear(); 82 | } 83 | 84 | /** 85 | * Sets the trace ability. 86 | * @param enabled is trace enabled? 87 | */ 88 | public void setTraceEnabled(boolean enabled) { 89 | this.isTraceEnabled = enabled; 90 | } 91 | 92 | // -------------------------------------------------------------------- 93 | // DATA MEMBERS 94 | // -------------------------------------------------------------------- 95 | 96 | private final Map cache; 97 | private boolean isTraceEnabled; 98 | } 99 | -------------------------------------------------------------------------------- /src/main/java/org/kopi/ebics/letter/DefaultLetterManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1990-2012 kopiLeft Development SARL, Bizerte, Tunisia 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License version 2.1 as published by the Free Software Foundation. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | * 17 | */ 18 | 19 | package org.kopi.ebics.letter; 20 | 21 | import java.io.IOException; 22 | import java.security.GeneralSecurityException; 23 | import java.util.Locale; 24 | 25 | import org.kopi.ebics.exception.EbicsException; 26 | import org.kopi.ebics.interfaces.EbicsUser; 27 | import org.kopi.ebics.interfaces.InitLetter; 28 | import org.kopi.ebics.interfaces.LetterManager; 29 | 30 | 31 | /** 32 | * The DefaultLetterManager is a simple way 33 | * to manage initialization letters. 34 | * 35 | * 36 | */ 37 | public class DefaultLetterManager implements LetterManager { 38 | 39 | /** 40 | * Constructs a new LetterManager 41 | * @param locale the application locale. 42 | */ 43 | public DefaultLetterManager(Locale locale) { 44 | this.locale = locale; 45 | } 46 | 47 | @Override 48 | public InitLetter createA005Letter(EbicsUser user) 49 | throws GeneralSecurityException, IOException, EbicsException 50 | { 51 | A005Letter letter; 52 | 53 | letter = new A005Letter(locale); 54 | letter.create(user); 55 | return letter; 56 | } 57 | 58 | @Override 59 | public InitLetter createE002Letter(EbicsUser user) 60 | throws GeneralSecurityException, IOException, EbicsException 61 | { 62 | E002Letter letter; 63 | 64 | letter = new E002Letter(locale); 65 | letter.create(user); 66 | return letter; 67 | } 68 | 69 | @Override 70 | public InitLetter createX002Letter(EbicsUser user) 71 | throws GeneralSecurityException, IOException, EbicsException 72 | { 73 | X002Letter letter; 74 | 75 | letter = new X002Letter(locale); 76 | letter.create(user); 77 | return letter; 78 | } 79 | 80 | // -------------------------------------------------------------------- 81 | // DATA MEMBERS 82 | // -------------------------------------------------------------------- 83 | 84 | private final Locale locale; 85 | } 86 | -------------------------------------------------------------------------------- /src/main/java/org/kopi/ebics/xml/HIARequestElement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1990-2012 kopiLeft Development SARL, Bizerte, Tunisia 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License version 2.1 as published by the Free Software Foundation. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | * 17 | */ 18 | 19 | package org.kopi.ebics.xml; 20 | 21 | import org.kopi.ebics.exception.EbicsException; 22 | import org.kopi.ebics.session.EbicsSession; 23 | import org.kopi.ebics.session.OrderType; 24 | import org.kopi.ebics.utils.Utils; 25 | 26 | /** 27 | * The HIARequestElement is the root element used 28 | * to send the authentication and encryption keys to the ebics 29 | * bank server 30 | * 31 | * 32 | */ 33 | public class HIARequestElement extends DefaultEbicsRootElement { 34 | 35 | /** 36 | * Constructs a new HIA Request root element 37 | * @param session the current ebics session 38 | * @param orderId the order id, if null a random one is generated. 39 | */ 40 | public HIARequestElement(EbicsSession session, String orderId) { 41 | super(session); 42 | this.orderId = orderId; 43 | } 44 | 45 | @Override 46 | public String getName() { 47 | return "HIARequest.xml"; 48 | } 49 | 50 | @Override 51 | public void build() throws EbicsException { 52 | 53 | var requestOrderData = new HIARequestOrderDataElement(session); 54 | requestOrderData.build(); 55 | unsecuredRequest = new UnsecuredRequestElement(session, OrderType.HIA, 56 | orderId == null ? session.getUser().getPartner().nextOrderId() : orderId, 57 | Utils.zip(requestOrderData.prettyPrint())); 58 | unsecuredRequest.setSaveSuggestedPrefixes("urn:org:ebics:H005", ""); 59 | unsecuredRequest.build(); 60 | } 61 | 62 | @Override 63 | public byte[] toByteArray() { 64 | 65 | return unsecuredRequest.toByteArray(); 66 | } 67 | 68 | @Override 69 | public void validate() throws EbicsException { 70 | unsecuredRequest.validate(); 71 | } 72 | 73 | // -------------------------------------------------------------------- 74 | // DATA MEMBERS 75 | // -------------------------------------------------------------------- 76 | 77 | private final String orderId; 78 | private UnsecuredRequestElement unsecuredRequest; 79 | private static final long serialVersionUID = 1130436605993828777L; 80 | } 81 | -------------------------------------------------------------------------------- /src/main/resources/org/kopi/ebics/exception/messages_en.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 1990-2012 kopiLeft Development SARL 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License version 2.1 as published by the Free Software Foundation. 7 | # 8 | # This library is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | # Lesser General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU Lesser General Public 14 | # License along with this library; if not, write to the Free Software 15 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | # 17 | # $Id: messages_en.properties 2 2012-02-28 09:39:55Z bentaher $ 18 | # 19 | 20 | 000000 = OK 21 | 011000 = Positive acknowledgement received 22 | 011001 = Negative acknowledgement received 23 | 011101 = Segment number not reached 24 | 031001 = Unknown order parameters are ignored 25 | 061001 = Authentication signature error 26 | 061002 = Message not EBICS-conformant 27 | 061099 = Internal EBICS error 28 | 061101 = Synchronisation necessary 29 | 091002 = Subscriber unknown or subscriber state inadmissible 30 | 091003 = Subscriber unknown 31 | 091004 = Subscriber state unknown 32 | 091005 = Order type inadmissible 33 | 091006 = Order type not supported 34 | 091007 = Subscriber possesses no authorisation of signature for the referenced order in the VEU administration 35 | 091008 = Bank key invalid 36 | 091009 = Segment size exceeded 37 | 091010 = XML invalid according to EBICS XML schema 38 | 091011 = The transmitted HostID is unknown on the bank's side 39 | 091101 = Transaction ID invalid 40 | 091102 = Transaction cancelled 41 | 091103 = Suspected Message replay (wrong time/time zone or nonce error) 42 | 091104 = Segment number exceeded 43 | 091112 = Invalid order parameters 44 | 091113 = Message content semantically not compliant to EBICS 45 | 091115 = An order with the same order number was already submitted for this customer (duplicate submission). 46 | 091117 = The bank system does not support the requested order size 47 | 091118 = Submitted number of segments for upload is too high 48 | 091119 = Maximum number of parallel transactions per customer is exceeded 49 | 091120 = The partner ID of the ES file is not identical to the partner ID of the submitter. 50 | 091121 = The specified order attribute is not compatible with the order in the bank system 51 | 091301 = Verification of the ES has failed In the case of asynchronously implemented orders, the error can occur during preliminary verification 52 | 091209 = certificate is not valid because it is not yet in effect 53 | 090005 = No download data available 54 | 090003 = The subscriber is not entitled to submit orders of the selected order type. 55 | -------------------------------------------------------------------------------- /src/main/java/org/kopi/ebics/xml/HPBResponseOrderDataElement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1990-2012 kopiLeft Development SARL, Bizerte, Tunisia 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License version 2.1 as published by the Free Software Foundation. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | * 17 | */ 18 | 19 | package org.kopi.ebics.xml; 20 | 21 | import org.kopi.ebics.exception.EbicsException; 22 | import org.kopi.ebics.interfaces.ContentFactory; 23 | import org.kopi.ebics.schema.h005.HPBResponseOrderDataDocument; 24 | import org.kopi.ebics.schema.h005.HPBResponseOrderDataType; 25 | 26 | /** 27 | * The HPBResponseOrderDataElement contains the public bank 28 | * keys in encrypted mode. The user should decrypt with his encryption 29 | * key to have the bank public keys. 30 | * 31 | * 32 | */ 33 | public class HPBResponseOrderDataElement extends DefaultResponseElement { 34 | 35 | /** 36 | * Creates a new HPBResponseOrderDataElement from a given 37 | * content factory. 38 | * @param factory the content factory. 39 | */ 40 | public HPBResponseOrderDataElement(ContentFactory factory) { 41 | super(factory, "HPBData"); 42 | } 43 | 44 | /** 45 | * Returns the authentication bank certificate. 46 | * @return the authentication bank certificate. 47 | */ 48 | public byte[] getBankX002Certificate() { 49 | return response.getAuthenticationPubKeyInfo().getX509Data().getX509CertificateArray(0); 50 | } 51 | 52 | /** 53 | * Returns the encryption bank certificate. 54 | * @return the encryption bank certificate. 55 | */ 56 | public byte[] getBankE002Certificate() { 57 | return response.getEncryptionPubKeyInfo().getX509Data().getX509CertificateArray(0); 58 | } 59 | 60 | @Override 61 | public void build() throws EbicsException { 62 | parse(factory, HPBResponseOrderDataDocument.Factory); 63 | response = ((HPBResponseOrderDataDocument)document).getHPBResponseOrderData(); 64 | } 65 | 66 | @Override 67 | public String getName() { 68 | return "HPBData.xml"; 69 | } 70 | 71 | // -------------------------------------------------------------------- 72 | // DATA MEMBERS 73 | // -------------------------------------------------------------------- 74 | 75 | private HPBResponseOrderDataType response; 76 | private static final long serialVersionUID = -1305363936881364049L; 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/org/kopi/ebics/xml/INIRequestElement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1990-2012 kopiLeft Development SARL, Bizerte, Tunisia 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License version 2.1 as published by the Free Software Foundation. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | * 17 | */ 18 | 19 | package org.kopi.ebics.xml; 20 | 21 | import org.kopi.ebics.exception.EbicsException; 22 | import org.kopi.ebics.session.EbicsSession; 23 | import org.kopi.ebics.session.OrderType; 24 | import org.kopi.ebics.utils.Utils; 25 | 26 | /** 27 | * The INI request XML element. This root element is to be sent 28 | * to the ebics server to initiate the signature certificate. 29 | * 30 | * 31 | */ 32 | public class INIRequestElement extends DefaultEbicsRootElement { 33 | 34 | /** 35 | * Constructs a new INI request element. 36 | * @param session the ebics session. 37 | * @param orderId the order id, if null a random one is generated. 38 | */ 39 | public INIRequestElement(EbicsSession session, String orderId) { 40 | super(session); 41 | this.orderId = orderId; 42 | } 43 | 44 | @Override 45 | public String getName() { 46 | return "INIRequest.xml"; 47 | } 48 | 49 | @Override 50 | public void build() throws EbicsException { 51 | var signaturePubKey = new SignaturePubKeyOrderDataElement(session); 52 | signaturePubKey.build(); 53 | unsecuredRequest = new UnsecuredRequestElement(session, OrderType.INI, 54 | orderId == null ? session.getUser().getPartner().nextOrderId() : orderId, 55 | Utils.zip(signaturePubKey.prettyPrint())); 56 | unsecuredRequest.build(); 57 | unsecuredRequest.addNamespaceDecl("ds", "http://www.w3.org/2000/09/xmldsig#"); 58 | unsecuredRequest.setSaveSuggestedPrefixes("urn:org:ebics:H005", ""); 59 | 60 | } 61 | 62 | @Override 63 | public byte[] toByteArray() { 64 | return unsecuredRequest.toByteArray(); 65 | } 66 | 67 | @Override 68 | public void validate() throws EbicsException { 69 | unsecuredRequest.validate(); 70 | } 71 | 72 | // -------------------------------------------------------------------- 73 | // DATA MEMBERS 74 | // -------------------------------------------------------------------- 75 | 76 | private final String orderId; 77 | private UnsecuredRequestElement unsecuredRequest; 78 | private static final long serialVersionUID = -1966559247739923555L; 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/org/kopi/ebics/session/Product.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1990-2012 kopiLeft Development SARL, Bizerte, Tunisia 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License version 2.1 as published by the Free Software Foundation. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | * 17 | */ 18 | 19 | package org.kopi.ebics.session; 20 | 21 | import java.io.Serializable; 22 | 23 | /** 24 | * Optional information about the client product. 25 | * 26 | * 27 | */ 28 | public class Product implements Serializable { 29 | 30 | /** 31 | * Creates a new product information element. 32 | * @param name this is the name of the product. It is a mandatory field. 33 | * @param language this is the language. If you use null, the language of the default locale is used. 34 | * @param instituteID the institute, this is an optional value, you can leave this parameter empty. 35 | */ 36 | public Product(String name, 37 | String language, 38 | String instituteID) 39 | { 40 | this.name = name; 41 | this.language = language; 42 | this.instituteID = instituteID; 43 | } 44 | 45 | /** 46 | * @return the name 47 | */ 48 | public String getName() { 49 | return name; 50 | } 51 | 52 | /** 53 | * @param name the name to set 54 | */ 55 | public void setName(String name) { 56 | this.name = name; 57 | } 58 | 59 | /** 60 | * @return the language 61 | */ 62 | public String getLanguage() { 63 | return language; 64 | } 65 | 66 | /** 67 | * @param language the language to set 68 | */ 69 | public void setLanguage(String language) { 70 | this.language = language; 71 | } 72 | 73 | /** 74 | * @return the instituteID 75 | */ 76 | public String getInstituteID() { 77 | return instituteID; 78 | } 79 | 80 | /** 81 | * @param instituteID the instituteID to set 82 | */ 83 | public void setInstituteID(String instituteID) { 84 | this.instituteID = instituteID; 85 | } 86 | 87 | // -------------------------------------------------------------------- 88 | // DATA MEMBERS 89 | // -------------------------------------------------------------------- 90 | 91 | private transient String name; 92 | private String language; 93 | private String instituteID; 94 | 95 | private static final long serialVersionUID = 6400195827756653241L; 96 | 97 | } 98 | -------------------------------------------------------------------------------- /src/main/java/org/kopi/ebics/messages/Messages.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1990-2012 kopiLeft Development SARL, Bizerte, Tunisia 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License version 2.1 as published by the Free Software Foundation. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | * 17 | */ 18 | 19 | package org.kopi.ebics.messages; 20 | 21 | import java.text.MessageFormat; 22 | import java.util.Locale; 23 | import java.util.MissingResourceException; 24 | import java.util.ResourceBundle; 25 | 26 | /** 27 | * A class to manage application messages. 28 | * 29 | */ 30 | public class Messages { 31 | 32 | private static Locale defaultLocale = Locale.ENGLISH; 33 | private final Locale locale; 34 | private final ResourceBundle resourceBundle; 35 | 36 | public Messages(String bundleName, Locale locale) { 37 | this.locale = locale; 38 | this.resourceBundle = getBundle(bundleName, locale); 39 | } 40 | 41 | public Messages(String bundleName) { 42 | this(bundleName, defaultLocale); 43 | } 44 | 45 | /** 46 | * Return the corresponding value of a given key and string parameter. 47 | * @param key the given key 48 | * @param arguments object(s) to format 49 | * @return the corresponding key value 50 | */ 51 | public String getString(String key, Object ... arguments) { 52 | try { 53 | MessageFormat messageFormat = new MessageFormat(resourceBundle.getString(key)); 54 | messageFormat.setLocale(locale); 55 | return messageFormat.format(arguments); 56 | } catch (MissingResourceException e) { 57 | throw new RuntimeException(e); 58 | } 59 | } 60 | 61 | /** 62 | * Return the corresponding value of a given key and parameters. 63 | * @param key the given key 64 | * @return the corresponding key value 65 | */ 66 | public String getString(String key) { 67 | return resourceBundle.getString(key); 68 | } 69 | 70 | private static ResourceBundle getBundle(String bundleName, Locale locale) { 71 | try { 72 | return ResourceBundle.getBundle(bundleName, locale); 73 | } catch (MissingResourceException e) { 74 | try { 75 | return ResourceBundle.getBundle(bundleName, Locale.ENGLISH); 76 | } catch (MissingResourceException e2) { 77 | throw new RuntimeException(e2); 78 | } 79 | } 80 | } 81 | 82 | public static void setLocale(Locale locale) { 83 | Messages.defaultLocale = locale; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/main/java/org/kopi/ebics/session/DefaultSerializationManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1990-2012 kopiLeft Development SARL, Bizerte, Tunisia 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License version 2.1 as published by the Free Software Foundation. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | * 17 | */ 18 | 19 | package org.kopi.ebics.session; 20 | 21 | import java.io.File; 22 | import java.io.FileInputStream; 23 | import java.io.FileOutputStream; 24 | import java.io.IOException; 25 | import java.io.ObjectInputStream; 26 | import java.io.ObjectOutputStream; 27 | 28 | import org.kopi.ebics.exception.EbicsException; 29 | import org.kopi.ebics.interfaces.Savable; 30 | import org.kopi.ebics.interfaces.SerializationManager; 31 | 32 | 33 | /** 34 | * A simple implementation of the SerializationManager. 35 | * The serialization process aims to save object on the user disk 36 | * using a separated file for each object to serialize. 37 | * 38 | * 39 | */ 40 | public class DefaultSerializationManager implements SerializationManager { 41 | 42 | /** 43 | * Constructs a new SerializationManager 44 | * @param serializationDir the serialization directory 45 | */ 46 | public DefaultSerializationManager(File serializationDir) { 47 | this.serializationDir = serializationDir; 48 | } 49 | 50 | /** 51 | * Constructs a new SerializationManager 52 | */ 53 | public DefaultSerializationManager() { 54 | this(null); 55 | } 56 | 57 | @Override 58 | public void serialize(Savable object) throws EbicsException { 59 | try { 60 | var out = new ObjectOutputStream(new FileOutputStream(new File(serializationDir, object.getSaveName()))); 61 | object.save(out); 62 | } catch (IOException e) { 63 | throw new EbicsException(e.getMessage()); 64 | } 65 | } 66 | 67 | @Override 68 | public ObjectInputStream deserialize(String name) throws EbicsException { 69 | try { 70 | return new ObjectInputStream(new FileInputStream(new File(serializationDir, name + ".cer"))); 71 | } catch (IOException e) { 72 | throw new EbicsException(e.getMessage()); 73 | } 74 | } 75 | 76 | @Override 77 | public void setSerializationDirectory(File serializationDir) { 78 | this.serializationDir = serializationDir; 79 | } 80 | 81 | // -------------------------------------------------------------------- 82 | // DATA MEMBERS 83 | // -------------------------------------------------------------------- 84 | 85 | private File serializationDir; 86 | } 87 | -------------------------------------------------------------------------------- /src/main/java/org/kopi/ebics/io/IOUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1990-2012 kopiLeft Development SARL, Bizerte, Tunisia 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License version 2.1 as published by the Free Software Foundation. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | * 17 | */ 18 | 19 | package org.kopi.ebics.io; 20 | 21 | import java.io.ByteArrayOutputStream; 22 | import java.io.File; 23 | import java.io.FileInputStream; 24 | import java.io.IOException; 25 | import java.io.InputStream; 26 | 27 | import org.kopi.ebics.exception.EbicsException; 28 | import org.kopi.ebics.interfaces.ContentFactory; 29 | 30 | 31 | /** 32 | * Some IO utilities for EBICS files management. 33 | * EBICS server 34 | * 35 | * 36 | */ 37 | public final class IOUtils { 38 | 39 | /** 40 | * Creates directories from a given full path. 41 | * Path should use default separator like '/' for UNIX 42 | * systems 43 | */ 44 | public static void createDirectories(File directory) { 45 | directory.mkdirs(); 46 | } 47 | 48 | 49 | /** 50 | * Returns the content of a file as byte array. 51 | * @param file the file 52 | * @return the byte array content of the file 53 | * @throws EbicsException 54 | */ 55 | public static byte[] getFileContent(File file) throws EbicsException { 56 | try { 57 | try (FileInputStream input = new FileInputStream(file)) { 58 | return inputStreamToBytes(input); 59 | } 60 | } catch (IOException e) { 61 | throw new EbicsException(e.getMessage()); 62 | } 63 | } 64 | 65 | /** 66 | * Returns the content of a ContentFactory as a byte array 67 | * @param content 68 | * @return content of a ContentFactory as a byte[] 69 | * @throws EbicsException 70 | */ 71 | public static byte[] getFactoryContent(ContentFactory content) throws EbicsException { 72 | try (InputStream in = content.getContent()) { 73 | return inputStreamToBytes(in); 74 | } catch (IOException e) { 75 | throw new EbicsException(e.getMessage()); 76 | } 77 | } 78 | 79 | private static byte[] inputStreamToBytes(InputStream in) throws IOException { 80 | int len; 81 | ByteArrayOutputStream out = new ByteArrayOutputStream(); 82 | byte[] buffer = new byte[1024]; 83 | while ((len = in.read(buffer)) != -1) { 84 | out.write(buffer, 0, len); 85 | } 86 | out.close(); 87 | return out.toByteArray(); 88 | } 89 | 90 | private IOUtils() { 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/main/java/org/kopi/ebics/letter/A005Letter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1990-2012 kopiLeft Development SARL, Bizerte, Tunisia 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License version 2.1 as published by the Free Software Foundation. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | * 17 | */ 18 | 19 | package org.kopi.ebics.letter; 20 | 21 | import java.io.IOException; 22 | import java.security.GeneralSecurityException; 23 | import java.util.Locale; 24 | 25 | import org.apache.commons.codec.binary.Base64; 26 | import org.kopi.ebics.exception.EbicsException; 27 | import org.kopi.ebics.interfaces.EbicsUser; 28 | 29 | 30 | /** 31 | * The A005Letter is the initialization letter 32 | * for the signature certificate 33 | * 34 | * 35 | */ 36 | public class A005Letter extends AbstractInitLetter { 37 | 38 | /** 39 | * Constructs a new A005Letter 40 | * @param locale the application local 41 | */ 42 | public A005Letter(Locale locale) { 43 | super(locale); 44 | } 45 | 46 | @Override 47 | public void create(EbicsUser user) throws GeneralSecurityException, IOException, EbicsException { 48 | if (user.getPartner().getBank().useCertificate()) { 49 | build(user.getPartner().getBank().getHostId(), 50 | user.getPartner().getBank().getName(), 51 | user.getUserId(), 52 | user.getName(), 53 | user.getPartner().getPartnerId(), 54 | getString("INILetter.version"), 55 | getString("INILetter.certificate"), 56 | Base64.encodeBase64(user.getA005Certificate(), true), 57 | getString("INILetter.digest"), 58 | getHash(user.getA005Certificate())); 59 | } else { 60 | build(user.getPartner().getBank().getHostId(), 61 | user.getPartner().getBank().getName(), 62 | user.getUserId(), 63 | user.getName(), 64 | user.getPartner().getPartnerId(), 65 | getString("INILetter.version"), 66 | getString("INILetter.certificate"), 67 | null, 68 | getString("INILetter.digest"), 69 | getHash(user.getA005PublicKey())); 70 | } 71 | } 72 | 73 | @Override 74 | public String getTitle() { 75 | return getString("INILetter.title"); 76 | } 77 | 78 | @Override 79 | public String getName() { 80 | return getString("INILetter.name") + ".txt"; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/main/resources/org/kopi/ebics/client/messages_en.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 1990-2012 kopiLeft Development SARL 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License version 2.1 as published by the Free Software Foundation. 7 | # 8 | # This library is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | # Lesser General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU Lesser General Public 14 | # License along with this library; if not, write to the Free Software 15 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | # 17 | # $Id: messages_en.properties 2 2012-02-28 09:39:55Z bentaher $ 18 | # 19 | 20 | app.cache.clear = Clearing traces cache 21 | app.quit.banks = Saving {0} bank information 22 | app.quit.error = Error while saving users information 23 | app.quit.partners = Saving {0} partner information 24 | app.quit.users = Saving {0} user information 25 | 26 | download.file.error = Cannot download the requested file 27 | 28 | hia.request.send = Sending authentication and encryption certificates for {0} user 29 | hia.send.error = The authentication and encryption certificates has not been sent for the {0} user 30 | hia.send.success = The authentication and encryption certificates has been sent correctly for {0} user 31 | 32 | hpb.request.send = Retrieving the public bank keys for {0} user 33 | hpb.send.error = Cannot retrieve the bank public keys for {0} user 34 | hpb.send.success = The bank public keys has been retrieved correctly for the {0} user 35 | 36 | http.code.error = Wrong returned HTTP code: {0} 37 | 38 | ini.request.send = Sending the signature certificate for user {0} 39 | ini.send.error = The signature certificate cannot be sent for the {0} user 40 | ini.send.success = The signature certificate has been sent correctly for the {0} user 41 | 42 | init.configuration = Configuration initialization 43 | 44 | upload.file.error = Cannot upload file {0} to the ebics server 45 | upload.segment = Uploading segment number {0} 46 | 47 | user.already.hia.initialized = The authentication and encryption certificates has already been sent for the {0} user 48 | user.already.initialized = The signature certificate has already been sent for the {0} user 49 | user.create.directories = Creating necessary directories for {0} user 50 | user.create.error = Cannot create user 51 | user.create.info = Creating new user {0} 52 | user.create.success = The user {0} was created successfully 53 | user.load.error = Cannot load user 54 | user.load.info = Loading user {0} 55 | user.load.success = The user {0} was loaded successfully 56 | 57 | 58 | spr.request.send = Locking the user {0} 59 | spr.send.error = Error while locking the user {0} 60 | spr.send.success = The user {0} is now locked. Initializations steps should be done again -------------------------------------------------------------------------------- /src/main/java/org/kopi/ebics/letter/E002Letter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1990-2012 kopiLeft Development SARL, Bizerte, Tunisia 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License version 2.1 as published by the Free Software Foundation. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | * 17 | */ 18 | 19 | package org.kopi.ebics.letter; 20 | 21 | import java.io.IOException; 22 | import java.security.GeneralSecurityException; 23 | import java.util.Locale; 24 | 25 | import org.apache.commons.codec.binary.Base64; 26 | import org.kopi.ebics.exception.EbicsException; 27 | import org.kopi.ebics.interfaces.EbicsUser; 28 | 29 | 30 | /** 31 | * The E002Letter is the initialization letter 32 | * for the encryption certificate. 33 | * 34 | * 35 | */ 36 | public class E002Letter extends AbstractInitLetter { 37 | 38 | /** 39 | * Constructs a new E002Letter 40 | * @param locale the application locale 41 | */ 42 | public E002Letter(Locale locale) { 43 | super(locale); 44 | } 45 | 46 | @Override 47 | public void create(EbicsUser user) throws GeneralSecurityException, IOException, EbicsException { 48 | if (user.getPartner().getBank().useCertificate()) { 49 | build(user.getPartner().getBank().getHostId(), 50 | user.getPartner().getBank().getName(), 51 | user.getUserId(), 52 | user.getName(), 53 | user.getPartner().getPartnerId(), 54 | getString("HIALetter.e002.version"), 55 | getString("HIALetter.e002.certificate"), 56 | Base64.encodeBase64(user.getE002Certificate(), true), 57 | getString("HIALetter.e002.digest"), 58 | getHash(user.getE002Certificate())); 59 | } else { 60 | build(user.getPartner().getBank().getHostId(), 61 | user.getPartner().getBank().getName(), 62 | user.getUserId(), 63 | user.getName(), 64 | user.getPartner().getPartnerId(), 65 | getString("HIALetter.e002.version"), 66 | getString("HIALetter.e002.certificate"), 67 | null, 68 | getString("HIALetter.e002.digest"), 69 | getHash(user.getE002PublicKey())); 70 | } 71 | } 72 | 73 | @Override 74 | public String getTitle() { 75 | return getString("HIALetter.e002.title"); 76 | } 77 | 78 | @Override 79 | public String getName() { 80 | return getString("HIALetter.e002.name") + ".txt"; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/org/kopi/ebics/letter/X002Letter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1990-2012 kopiLeft Development SARL, Bizerte, Tunisia 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License version 2.1 as published by the Free Software Foundation. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | * 17 | */ 18 | 19 | package org.kopi.ebics.letter; 20 | 21 | import java.io.IOException; 22 | import java.security.GeneralSecurityException; 23 | import java.util.Locale; 24 | 25 | import org.apache.commons.codec.binary.Base64; 26 | import org.kopi.ebics.exception.EbicsException; 27 | import org.kopi.ebics.interfaces.EbicsUser; 28 | 29 | 30 | /** 31 | * The X002Letter is the initialization letter 32 | * for the authentication certificate. 33 | * 34 | * 35 | */ 36 | public class X002Letter extends AbstractInitLetter { 37 | 38 | /** 39 | * Constructs a new X002Letter 40 | * @param locale the application locale 41 | */ 42 | public X002Letter(Locale locale) { 43 | super(locale); 44 | } 45 | 46 | @Override 47 | public void create(EbicsUser user) throws GeneralSecurityException, IOException, EbicsException { 48 | if (user.getPartner().getBank().useCertificate()) { 49 | build(user.getPartner().getBank().getHostId(), 50 | user.getPartner().getBank().getName(), 51 | user.getUserId(), 52 | user.getName(), 53 | user.getPartner().getPartnerId(), 54 | getString("HIALetter.x002.version"), 55 | getString("HIALetter.x002.certificate"), 56 | Base64.encodeBase64(user.getX002Certificate(), true), 57 | getString("HIALetter.x002.digest"), 58 | getHash(user.getX002Certificate())); 59 | } else { 60 | build(user.getPartner().getBank().getHostId(), 61 | user.getPartner().getBank().getName(), 62 | user.getUserId(), 63 | user.getName(), 64 | user.getPartner().getPartnerId(), 65 | getString("HIALetter.x002.version"), 66 | getString("HIALetter.x002.certificate"), 67 | null, 68 | getString("HIALetter.x002.digest"), 69 | getHash(user.getX002PublicKey())); 70 | } 71 | } 72 | 73 | @Override 74 | public String getTitle() { 75 | return getString("HIALetter.x002.title"); 76 | } 77 | 78 | @Override 79 | public String getName() { 80 | return getString("HIALetter.x002.name") + ".txt"; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/org/kopi/ebics/xml/DefaultResponseElement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1990-2012 kopiLeft Development SARL, Bizerte, Tunisia 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License version 2.1 as published by the Free Software Foundation. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | * 17 | */ 18 | 19 | package org.kopi.ebics.xml; 20 | 21 | import java.io.IOException; 22 | 23 | import org.apache.xmlbeans.XmlException; 24 | import org.apache.xmlbeans.XmlObject; 25 | import org.apache.xmlbeans.impl.schema.DocumentFactory; 26 | import org.kopi.ebics.exception.EbicsException; 27 | import org.kopi.ebics.exception.ReturnCode; 28 | import org.kopi.ebics.interfaces.ContentFactory; 29 | 30 | 31 | /** 32 | * The DefaultResponseElement is the common element for 33 | * all ebics server responses. 34 | * 35 | * 36 | */ 37 | public abstract class DefaultResponseElement extends DefaultEbicsRootElement { 38 | 39 | /** 40 | * Constructs a new ebics response element. 41 | * @param factory the content factory containing the response. 42 | * @param name the element name 43 | */ 44 | protected DefaultResponseElement(ContentFactory factory, String name) { 45 | this.factory = factory; 46 | this.name = name; 47 | } 48 | 49 | /** 50 | * Parses the content of a ContentFactory 51 | * 52 | * @param factory the content factory 53 | * @return the parsed document 54 | * @throws EbicsException parse error 55 | */ 56 | protected T parse(ContentFactory factory, 57 | DocumentFactory documentFactory) throws EbicsException { 58 | try { 59 | var doc = documentFactory.parse(factory.getContent()); 60 | this.document = doc; 61 | return doc; 62 | } catch (XmlException | IOException e) { 63 | throw new EbicsException(e.getMessage()); 64 | } 65 | } 66 | /** 67 | * Reports the return code to the user. 68 | * @throws EbicsException request fails. 69 | */ 70 | public void report() throws EbicsException { 71 | checkReturnCode(returnCode); 72 | } 73 | 74 | protected void checkReturnCode(ReturnCode returnCode) throws EbicsException { 75 | if (!returnCode.isOk()) { 76 | returnCode.throwException(); 77 | } 78 | } 79 | 80 | @Override 81 | public String getName() { 82 | return name + ".xml"; 83 | } 84 | 85 | // -------------------------------------------------------------------- 86 | // DATA MEMBERS 87 | // -------------------------------------------------------------------- 88 | 89 | private final String name; 90 | protected ContentFactory factory; 91 | protected ReturnCode returnCode; 92 | private static final long serialVersionUID = 4014595046719645090L; 93 | } 94 | -------------------------------------------------------------------------------- /src/main/java/org/kopi/ebics/xml/SignaturePubKeyOrderDataElement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1990-2012 kopiLeft Development SARL, Bizerte, Tunisia 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License version 2.1 as published by the Free Software Foundation. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | * 17 | */ 18 | 19 | package org.kopi.ebics.xml; 20 | 21 | import org.ebics.s002.SignaturePubKeyInfoType; 22 | import org.ebics.s002.SignaturePubKeyOrderDataType; 23 | import org.kopi.ebics.exception.EbicsException; 24 | 25 | import org.kopi.ebics.schema.xmldsig.RSAKeyValueType; 26 | import org.kopi.ebics.schema.xmldsig.X509DataType; 27 | import org.kopi.ebics.session.EbicsSession; 28 | 29 | 30 | /** 31 | * The SignaturePubKeyOrderDataElement is the order data 32 | * component for the INI request. 33 | * 34 | * 35 | */ 36 | public class SignaturePubKeyOrderDataElement extends DefaultEbicsRootElement { 37 | 38 | /** 39 | * Creates a new Signature Public Key Order Data element. 40 | * @param session the current ebics session 41 | */ 42 | public SignaturePubKeyOrderDataElement(EbicsSession session) { 43 | super(session); 44 | } 45 | 46 | @Override 47 | public void build() throws EbicsException { 48 | X509DataType x509Data = EbicsXmlFactory.createX509DataType(session.getUser().getDN(), 49 | session.getUser().getA005Certificate()); 50 | 51 | var rsaKeyValue = EbicsXmlFactory.createRSAKeyValueType( 52 | session.getUser().getA005PublicKey().getPublicExponent().toByteArray(), 53 | session.getUser().getA005PublicKey().getModulus().toByteArray()); 54 | //var pubKeyValue = EbicsXmlFactory.createPubKeyValueType(rsaKeyValue, Calendar.getInstance()); 55 | var signaturePubKeyInfo = EbicsXmlFactory.createSignaturePubKeyInfoType(x509Data, null, 56 | // pubKeyValue, 57 | session.getConfiguration().getSignatureVersion()); 58 | var signaturePubKeyOrderData = EbicsXmlFactory.createSignaturePubKeyOrderData( 59 | signaturePubKeyInfo, session.getUser().getPartner().getPartnerId(), 60 | session.getUser().getUserId()); 61 | document = EbicsXmlFactory.createSignaturePubKeyOrderDataDocument(signaturePubKeyOrderData); 62 | } 63 | 64 | @Override 65 | public String getName() { 66 | return "SignaturePubKeyOrderData.xml"; 67 | } 68 | 69 | @Override 70 | public byte[] toByteArray() { 71 | addNamespaceDecl("ds", "http://www.w3.org/2000/09/xmldsig#"); 72 | setSaveSuggestedPrefixes("http://www.ebics.org/S002", ""); 73 | 74 | return super.toByteArray(); 75 | } 76 | 77 | // -------------------------------------------------------------------- 78 | // DATA MEMBERS 79 | // -------------------------------------------------------------------- 80 | 81 | private static final long serialVersionUID = -5523105558015982970L; 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/org/kopi/ebics/interfaces/EbicsBank.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1990-2012 kopiLeft Development SARL, Bizerte, Tunisia 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License version 2.1 as published by the Free Software Foundation. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | * 17 | */ 18 | 19 | package org.kopi.ebics.interfaces; 20 | 21 | import java.io.Serializable; 22 | import java.net.URL; 23 | import java.security.interfaces.RSAPublicKey; 24 | 25 | /** 26 | * Details about EBICS communication with a given bank. 27 | * 28 | * 29 | */ 30 | public interface EbicsBank extends Serializable { 31 | 32 | /** 33 | * Returns the URL needed for communication to the bank. 34 | * @return the URL needed for communication to the bank. 35 | */ 36 | URL getURL(); 37 | 38 | /** 39 | * 40 | */ 41 | boolean useCertificate(); 42 | 43 | /** 44 | * 45 | */ 46 | void setUseCertificate(boolean useCertificate); 47 | 48 | /** 49 | * Returns the encryption key digest you have obtained from the bank. 50 | * Ensure that nobody was able to modify the digest on its way from the bank to you. 51 | * @return the encryption key digest you have obtained from the bank. 52 | */ 53 | byte[] getE002Digest(); 54 | 55 | /** 56 | * Returns the authentication key digest you have obtained from the bank. 57 | * Ensure that nobody was able to modify the digest on its way from the bank to you. 58 | * @return the authentication key digest you have obtained from the bank. 59 | */ 60 | byte[] getX002Digest(); 61 | 62 | /** 63 | * Returns the banks encryption key. 64 | * @return the banks encryption key. 65 | */ 66 | RSAPublicKey getE002Key(); 67 | 68 | /** 69 | * Returns the banks authentication key. 70 | * @return the banks authentication key. 71 | */ 72 | RSAPublicKey getX002Key(); 73 | 74 | /** 75 | * Returns the bank's id. 76 | * @return the bank's id. 77 | */ 78 | String getHostId(); 79 | 80 | /** 81 | * Returns the bank's name. 82 | * @return the bank's name. 83 | */ 84 | String getName(); 85 | 86 | /** 87 | * Keys have been fetched from the bank. 88 | * The getters for the appropriate attributes should return the given values from now on. 89 | * For the sake of performance the values should be persisted for later usage. 90 | * 91 | * @param e002Key the banks encryption key. 92 | * @param x002Key the banks authentication key. 93 | */ 94 | void setBankKeys(RSAPublicKey e002Key, RSAPublicKey x002Key); 95 | 96 | /** 97 | * Sets the bank digests. 98 | * @param e002Digest encryption digest 99 | * @param x002Digest authentication digest 100 | */ 101 | void setDigests(byte[] e002Digest, byte[] x002Digest); 102 | } 103 | -------------------------------------------------------------------------------- /src/main/java/org/kopi/ebics/client/TransferState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1990-2012 kopiLeft Development SARL, Bizerte, Tunisia 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License version 2.1 as published by the Free Software Foundation. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | * 17 | */ 18 | 19 | package org.kopi.ebics.client; 20 | 21 | import java.io.Serializable; 22 | 23 | /** 24 | * Persistable state of a file transfer. 25 | * It may be used to continue a transfer via 26 | * FileTransfer.nextChunk(TransferState) 27 | * in this or a future session. 28 | * 29 | * 30 | */ 31 | public class TransferState implements Serializable { 32 | 33 | public TransferState(int numSegments, byte[] transactionId) { 34 | this.numSegments = numSegments; 35 | this.transactionId = transactionId; 36 | } 37 | 38 | /** 39 | * Returns the next segment number to be transferred. 40 | * @return the next segment number to be transferred. 41 | */ 42 | public int next() { 43 | segmentNumber++; 44 | 45 | if (segmentNumber == numSegments) { 46 | lastSegment = true; 47 | } 48 | 49 | return segmentNumber; 50 | } 51 | 52 | public boolean hasNext() { 53 | return segmentNumber < numSegments; 54 | } 55 | 56 | /** 57 | * Sets the segment number 58 | * @param segmentNumber the segment number 59 | */ 60 | public void setSegmentNumber(int segmentNumber) { 61 | this.segmentNumber = segmentNumber; 62 | } 63 | 64 | /** 65 | * Is the current segment is the last one? 66 | * @return True if it is the last segment 67 | */ 68 | public boolean isLastSegment() { 69 | return lastSegment; 70 | } 71 | 72 | /** 73 | * @return the transactionID 74 | */ 75 | public byte[] getTransactionId() { 76 | return transactionId; 77 | } 78 | 79 | /** 80 | * @param transactionId the transactionID to set 81 | */ 82 | public void setTransactionId(byte[] transactionId) { 83 | this.transactionId = transactionId; 84 | } 85 | 86 | /** 87 | * @return the numSegments 88 | */ 89 | public int getNumSegments() { 90 | return numSegments; 91 | } 92 | 93 | /** 94 | * @param numSegments the numSegments to set 95 | */ 96 | public void setNumSegments(int numSegments) { 97 | this.numSegments = numSegments; 98 | } 99 | 100 | // -------------------------------------------------------------------- 101 | // DATA MEMBERS 102 | // -------------------------------------------------------------------- 103 | 104 | private byte[] transactionId; 105 | private int segmentNumber; 106 | private int numSegments; 107 | private transient boolean lastSegment; 108 | 109 | private static final long serialVersionUID = -3189235892639115408L; 110 | } 111 | -------------------------------------------------------------------------------- /src/main/java/org/kopi/ebics/xml/HIARequestOrderDataElement.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 1990-2012 kopiLeft Development SARL, Bizerte, Tunisia 2 | * 3 | * This library is free software; you can redistribute it and/or 4 | * modify it under the terms of the GNU Lesser General Public 5 | * License version 2.1 as published by the Free Software Foundation. 6 | * 7 | * This library is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 | * Lesser General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public 13 | * License along with this library; if not, write to the Free Software 14 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 15 | * 16 | */ 17 | 18 | package org.kopi.ebics.xml; 19 | 20 | import org.kopi.ebics.exception.EbicsException; 21 | import org.kopi.ebics.schema.h005.AuthenticationPubKeyInfoType; 22 | import org.kopi.ebics.schema.h005.EncryptionPubKeyInfoType; 23 | import org.kopi.ebics.schema.h005.HIARequestOrderDataType; 24 | import org.kopi.ebics.schema.xmldsig.X509DataType; 25 | import org.kopi.ebics.session.EbicsSession; 26 | 27 | /** 28 | * The HIARequestOrderDataElement is the element that contains 29 | * X002 and E002 keys information needed for a HIA request in order to send 30 | * the authentication and encryption user keys to the bank server. 31 | * 32 | * 33 | */ 34 | public class HIARequestOrderDataElement extends DefaultEbicsRootElement { 35 | 36 | /** 37 | * Constructs a new HIA Request Order Data element 38 | * 39 | * @param session the current ebics session 40 | */ 41 | public HIARequestOrderDataElement(EbicsSession session) { 42 | super(session); 43 | } 44 | 45 | @Override 46 | public void build() throws EbicsException { 47 | X509DataType encryptionX509Data = EbicsXmlFactory.createX509DataType( 48 | session.getUser().getDN(), session.getUser().getE002Certificate()); 49 | 50 | X509DataType authX509Data = EbicsXmlFactory.createX509DataType(session.getUser().getDN(), 51 | session.getUser().getX002Certificate()); 52 | 53 | 54 | var encryptionPubKeyInfo = EbicsXmlFactory.createEncryptionPubKeyInfoType(session.getConfiguration().getEncryptionVersion(), 55 | encryptionX509Data); 56 | AuthenticationPubKeyInfoType authenticationPubKeyInfo = EbicsXmlFactory.createAuthenticationPubKeyInfoType( 57 | session.getConfiguration().getAuthenticationVersion(), authX509Data); 58 | 59 | HIARequestOrderDataType request = EbicsXmlFactory.createHIARequestOrderDataType( 60 | authenticationPubKeyInfo, encryptionPubKeyInfo, 61 | session.getUser().getPartner().getPartnerId(), session.getUser().getUserId()); 62 | document = EbicsXmlFactory.createHIARequestOrderDataDocument(request); 63 | } 64 | 65 | @Override 66 | public String getName() { 67 | return "HIARequestOrderData.xml"; 68 | } 69 | 70 | @Override 71 | public byte[] toByteArray() { 72 | addNamespaceDecl("ds", "http://www.w3.org/2000/09/xmldsig#"); 73 | setSaveSuggestedPrefixes("urn:org:ebics:H005", ""); 74 | 75 | return super.toByteArray(); 76 | } 77 | 78 | // -------------------------------------------------------------------- 79 | // DATA MEMBERS 80 | // -------------------------------------------------------------------- 81 | 82 | private static final long serialVersionUID = -7333250823464659004L; 83 | } 84 | -------------------------------------------------------------------------------- /src/main/java/org/kopi/ebics/xml/InitializationResponseElement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1990-2012 kopiLeft Development SARL, Bizerte, Tunisia 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License version 2.1 as published by the Free Software Foundation. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | * 17 | */ 18 | 19 | package org.kopi.ebics.xml; 20 | 21 | import org.kopi.ebics.exception.EbicsException; 22 | import org.kopi.ebics.exception.ReturnCode; 23 | import org.kopi.ebics.interfaces.ContentFactory; 24 | import org.kopi.ebics.interfaces.EbicsOrderType; 25 | import org.kopi.ebics.schema.h005.EbicsResponseDocument; 26 | import org.kopi.ebics.schema.h005.EbicsResponseDocument.EbicsResponse; 27 | 28 | /** 29 | * The InitializationResponseElement is the common 30 | * element for transfer initialization responses. 31 | * 32 | * 33 | */ 34 | public class InitializationResponseElement extends DefaultResponseElement { 35 | 36 | /** 37 | * Constructs a new InitializationResponseElement element. 38 | * @param factory the content factory 39 | * @param orderType the order type 40 | * @param name the element name 41 | */ 42 | public InitializationResponseElement(ContentFactory factory, 43 | EbicsOrderType orderType, 44 | String name) 45 | { 46 | super(factory, name); 47 | this.orderType = orderType; 48 | } 49 | 50 | @Override 51 | public void build() throws EbicsException { 52 | var doc = parse(factory, EbicsResponseDocument.Factory); 53 | response = doc.getEbicsResponse(); 54 | String code = response.getHeader().getMutable().getReturnCode(); 55 | String text = response.getHeader().getMutable().getReportText(); 56 | returnCode = ReturnCode.toReturnCode(code, text); 57 | checkReturnCode(returnCode); 58 | processBodyReturnCode(); 59 | transactionId = response.getHeader().getStatic().getTransactionID(); 60 | } 61 | 62 | protected void processBodyReturnCode() throws EbicsException { 63 | String bodyRetCode = response.getBody().getReturnCode().getStringValue(); 64 | ReturnCode returnCode = ReturnCode.toReturnCode(bodyRetCode, ""); 65 | checkReturnCode(returnCode); 66 | } 67 | 68 | 69 | /** 70 | * Returns the transaction ID. 71 | * @return the transaction ID. 72 | */ 73 | public byte[] getTransactionId() { 74 | return transactionId; 75 | } 76 | 77 | /** 78 | * Returns the order type. 79 | * @return the order type. 80 | */ 81 | public String getOrderType() { 82 | return orderType.getCode(); 83 | } 84 | 85 | // -------------------------------------------------------------------- 86 | // DATA MEMBERS 87 | // -------------------------------------------------------------------- 88 | 89 | protected EbicsResponse response; 90 | private final EbicsOrderType orderType; 91 | private byte[] transactionId; 92 | private static final long serialVersionUID = 7684048385353175772L; 93 | } 94 | -------------------------------------------------------------------------------- /src/main/java/org/kopi/ebics/session/DefaultTraceManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1990-2012 kopiLeft Development SARL, Bizerte, Tunisia 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License version 2.1 as published by the Free Software Foundation. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | * 17 | */ 18 | 19 | package org.kopi.ebics.session; 20 | 21 | import java.io.File; 22 | import java.io.FileOutputStream; 23 | import java.io.IOException; 24 | 25 | import org.kopi.ebics.exception.EbicsException; 26 | import org.kopi.ebics.interfaces.Configuration; 27 | import org.kopi.ebics.interfaces.EbicsRootElement; 28 | import org.kopi.ebics.interfaces.TraceManager; 29 | import org.kopi.ebics.io.FileCache; 30 | 31 | 32 | /** 33 | * The DefaultTraceManager aims to trace an ebics 34 | * transferable element in an instance of java.io.File 35 | * then saved to a trace directory. 36 | * The manager can delete all traces file if the configuration does 37 | * not offer tracing support. 38 | * see {@link Configuration#isTraceEnabled() isTraceEnabled()} 39 | * 40 | * 41 | */ 42 | public class DefaultTraceManager implements TraceManager { 43 | 44 | /** 45 | * Constructs a new TraceManger to manage transfer traces. 46 | * @param traceDir the trace directory 47 | * @param isTraceEnabled is trace enabled? 48 | */ 49 | public DefaultTraceManager(File traceDir, boolean isTraceEnabled) { 50 | this.traceDir = traceDir; 51 | cache = new FileCache(isTraceEnabled); 52 | } 53 | 54 | /** 55 | * Constructs a new TraceManger to manage transfer traces. 56 | * @param isTraceEnabled is trace enabled? 57 | */ 58 | public DefaultTraceManager(boolean isTraceEnabled) { 59 | this(null, isTraceEnabled); 60 | } 61 | 62 | /** 63 | * Constructs a new TraceManger with trace option enabled. 64 | */ 65 | public DefaultTraceManager() { 66 | this(null, true); 67 | } 68 | 69 | @Override 70 | public void trace(EbicsRootElement element) throws EbicsException { 71 | try { 72 | var file = new File(traceDir, element.getName()); 73 | var out = new FileOutputStream(file); 74 | element.save(out); 75 | cache.add(file); 76 | } catch (IOException e) { 77 | throw new EbicsException(e.getMessage()); 78 | } 79 | } 80 | 81 | @Override 82 | public void remove(EbicsRootElement element) { 83 | cache.remove(element.getName()); 84 | } 85 | 86 | @Override 87 | public void clear() { 88 | cache.clear(); 89 | } 90 | 91 | @Override 92 | public void setTraceDirectory(File traceDir) { 93 | this.traceDir = traceDir; 94 | } 95 | 96 | @Override 97 | public void setTraceEnabled(boolean enabled) { 98 | cache.setTraceEnabled(enabled); 99 | } 100 | 101 | // -------------------------------------------------------------------- 102 | // DATA MEMBERS 103 | // -------------------------------------------------------------------- 104 | 105 | private File traceDir; 106 | private final FileCache cache; 107 | } 108 | -------------------------------------------------------------------------------- /src/main/java/org/kopi/ebics/xml/KeyManagementResponseElement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1990-2012 kopiLeft Development SARL, Bizerte, Tunisia 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License version 2.1 as published by the Free Software Foundation. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | * 17 | */ 18 | 19 | package org.kopi.ebics.xml; 20 | 21 | import org.apache.xmlbeans.impl.schema.DocumentFactory; 22 | import org.kopi.ebics.exception.EbicsException; 23 | import org.kopi.ebics.exception.ReturnCode; 24 | import org.kopi.ebics.interfaces.ContentFactory; 25 | import org.kopi.ebics.schema.h005.EbicsKeyManagementResponseDocument; 26 | import org.kopi.ebics.schema.h005.EbicsKeyManagementResponseDocument.EbicsKeyManagementResponse; 27 | 28 | /** 29 | * The KeyManagementResponseElement is the common element 30 | * for ebics key management requests. This element aims to control the 31 | * returned code from the ebics server and throw an exception if it is 32 | * not an EBICS_OK code. 33 | * 34 | * 35 | */ 36 | public class KeyManagementResponseElement extends DefaultResponseElement { 37 | 38 | /** 39 | * Creates a new KeyManagementResponseElement 40 | * from a given ContentFactory 41 | * @param factory the content factory enclosing the ebics response 42 | * @param name the element name 43 | */ 44 | public KeyManagementResponseElement(ContentFactory factory, String name) { 45 | super(factory, name); 46 | } 47 | 48 | /** 49 | * Returns the transaction key of the response. 50 | * @return the transaction key. 51 | */ 52 | public byte[] getTransactionKey() { 53 | return response.getBody().getDataTransfer().getDataEncryptionInfo().getTransactionKey(); 54 | } 55 | 56 | /** 57 | * Returns the order data of the response. 58 | * @return the order data. 59 | */ 60 | public byte[] getOrderData() { 61 | return response.getBody().getDataTransfer().getOrderData().getByteArrayValue(); 62 | } 63 | 64 | @Override 65 | public void build() throws EbicsException { 66 | var doc = parse(factory, EbicsKeyManagementResponseDocument.Factory); 67 | response = doc.getEbicsKeyManagementResponse(); 68 | String code = response.getHeader().getMutable().getReturnCode(); 69 | String text = response.getHeader().getMutable().getReportText(); 70 | returnCode = ReturnCode.toReturnCode(code, text); 71 | report(); 72 | } 73 | 74 | @Override 75 | public void report() throws EbicsException { 76 | super.report(); 77 | // there is a response code also in the body which needs to be checked 78 | var bodyReturnCode = response.getBody().getReturnCode().getStringValue(); 79 | var code = ReturnCode.toReturnCode(bodyReturnCode, "Code " + bodyReturnCode); 80 | checkReturnCode(code); 81 | } 82 | 83 | 84 | // -------------------------------------------------------------------- 85 | // DATA MEMBERS 86 | // -------------------------------------------------------------------- 87 | 88 | private EbicsKeyManagementResponse response; 89 | private static final long serialVersionUID = -3556995397305708927L; 90 | } 91 | -------------------------------------------------------------------------------- /src/main/java/org/kopi/ebics/xml/DownloadTransferRequestElement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1990-2012 kopiLeft Development SARL, Bizerte, Tunisia 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License version 2.1 as published by the Free Software Foundation. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | * 17 | */ 18 | 19 | package org.kopi.ebics.xml; 20 | 21 | import org.kopi.ebics.exception.EbicsException; 22 | import org.kopi.ebics.interfaces.EbicsOrderType; 23 | import org.kopi.ebics.schema.h005.MutableHeaderType; 24 | import org.kopi.ebics.schema.h005.StaticHeaderType; 25 | import org.kopi.ebics.schema.h005.EbicsRequestDocument.EbicsRequest; 26 | import org.kopi.ebics.schema.h005.EbicsRequestDocument.EbicsRequest.Body; 27 | import org.kopi.ebics.schema.h005.EbicsRequestDocument.EbicsRequest.Header; 28 | import org.kopi.ebics.schema.h005.MutableHeaderType.SegmentNumber; 29 | import org.kopi.ebics.session.EbicsSession; 30 | 31 | /** 32 | * The DTransferRequestElement is the common elements 33 | * for all ebics downloads. 34 | * 35 | * 36 | */ 37 | public class DownloadTransferRequestElement extends TransferRequestElement { 38 | 39 | /** 40 | * Constructs a new DTransferRequestElement element. 41 | * @param session the current ebics session 42 | * @param type the order type 43 | * @param segmentNumber the segment number 44 | * @param lastSegment is it the last segment? 45 | * @param transactionId the transaction ID 46 | */ 47 | public DownloadTransferRequestElement(EbicsSession session, 48 | EbicsOrderType type, 49 | int segmentNumber, 50 | boolean lastSegment, 51 | byte[] transactionId) 52 | { 53 | super(session, generateName(type), type, segmentNumber, lastSegment, transactionId); 54 | } 55 | 56 | @Override 57 | public void buildTransfer() throws EbicsException { 58 | EbicsRequest request; 59 | Header header; 60 | Body body; 61 | MutableHeaderType mutable; 62 | SegmentNumber segmentNumber; 63 | StaticHeaderType xstatic; 64 | 65 | segmentNumber = EbicsXmlFactory.createSegmentNumber(this.segmentNumber, lastSegment); 66 | mutable = EbicsXmlFactory.createMutableHeaderType("Transfer", segmentNumber); 67 | xstatic = EbicsXmlFactory.createStaticHeaderType(session.getBankID(), transactionId); 68 | header = EbicsXmlFactory.createEbicsRequestHeader(true, mutable, xstatic); 69 | body = EbicsXmlFactory.createEbicsRequestBody(); 70 | request = EbicsXmlFactory.createEbicsRequest(session.getConfiguration().getRevision(), 71 | session.getConfiguration().getVersion(), 72 | header, 73 | body); 74 | document = EbicsXmlFactory.createEbicsRequestDocument(request); 75 | } 76 | 77 | // -------------------------------------------------------------------- 78 | // DATA MEMBERS 79 | // -------------------------------------------------------------------- 80 | 81 | private static final long serialVersionUID = -7765739964317408967L; 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/org/kopi/ebics/xml/UserSignature.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1990-2012 kopiLeft Development SARL, Bizerte, Tunisia 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License version 2.1 as published by the Free Software Foundation. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | * 17 | */ 18 | 19 | package org.kopi.ebics.xml; 20 | 21 | import java.io.IOException; 22 | import java.security.GeneralSecurityException; 23 | 24 | import org.ebics.s002.OrderSignatureDataType; 25 | import org.ebics.s002.UserSignatureDataSigBookType; 26 | import org.kopi.ebics.exception.EbicsException; 27 | import org.kopi.ebics.interfaces.EbicsUser; 28 | 29 | 30 | /** 31 | * A root EBICS element representing the user signature 32 | * element. The user data is signed with the user signature 33 | * key sent in the INI request to the EBICS bank server 34 | * 35 | * 36 | */ 37 | public class UserSignature extends DefaultEbicsRootElement { 38 | 39 | /** 40 | * Constructs a new UserSignature element for 41 | * an Ebics user and a data to sign 42 | * @param user the ebics user 43 | * @param signatureVersion the signature version 44 | * @param toSign the data to be signed 45 | */ 46 | public UserSignature(EbicsUser user, 47 | String name, 48 | String signatureVersion, 49 | byte[] toSign) 50 | { 51 | this.user = user; 52 | this.toSign = toSign; 53 | this.name = name; 54 | this.signatureVersion = signatureVersion; 55 | } 56 | 57 | @Override 58 | public void build() throws EbicsException { 59 | UserSignatureDataSigBookType userSignatureData; 60 | OrderSignatureDataType orderSignatureData; 61 | byte[] signature; 62 | 63 | try { 64 | signature = user.sign(toSign); 65 | } catch (IOException e) { 66 | throw new EbicsException(e.getMessage()); 67 | } catch (GeneralSecurityException e) { 68 | throw new EbicsException(e.getMessage()); 69 | } 70 | 71 | orderSignatureData = EbicsXmlFactory.createOrderSignatureDataType(signatureVersion, 72 | user.getPartner().getPartnerId(), 73 | user.getUserId(), 74 | signature); 75 | userSignatureData = EbicsXmlFactory.createUserSignatureDataSigBookType(new OrderSignatureDataType[]{orderSignatureData}); 76 | document = EbicsXmlFactory.createUserSignatureDataDocument(userSignatureData); 77 | } 78 | 79 | @Override 80 | public String getName() { 81 | return name + ".xml"; 82 | } 83 | 84 | @Override 85 | public byte[] toByteArray() { 86 | setSaveSuggestedPrefixes("http://www.ebics.org/S001", ""); 87 | 88 | return super.toByteArray(); 89 | } 90 | 91 | // -------------------------------------------------------------------- 92 | // DATA MEMBERS 93 | // -------------------------------------------------------------------- 94 | 95 | private final EbicsUser user; 96 | private final String signatureVersion; 97 | private final byte[] toSign; 98 | private final String name; 99 | private static final long serialVersionUID = 2992372604876703738L; 100 | } 101 | -------------------------------------------------------------------------------- /src/main/resources/org/kopi/ebics/format/FileTypes_en.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 1990-2012 kopiLeft Development SARL 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License version 2.1 as published by the Free Software Foundation. 7 | # 8 | # This library is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | # Lesser General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU Lesser General Public 14 | # License along with this library; if not, write to the Free Software 15 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | # 17 | # $Id: FileTypes_en.properties 2 2012-02-28 09:39:55Z bentaher $ 18 | # 19 | 20 | pain.xxx.cfonb160.dct=Remise de virement domestique France 21 | pain.xxx.cfonb160.ddd=Remise d`avis de pr\u00e9l\u00e8vement domestique France 22 | pain.xxx.cfonb160.dda=Remise d`avis de pr\u00e9l\u00e8vement acc\u00e9l\u00e9r\u00e9 domestique France 23 | pain.xxx.cfonb160.dtg=Remise de t\u00e9l\u00e9r\u00e8glement domestique France 24 | pain.xxx.cfonb160.ict=Remise de virement de tr\u00e9sorerie France (Intra groupe) 25 | pain.xxx.payord912.ict=Remise de virement de tr\u00e9sorerie France (Intra groupe) 26 | pain.xxx.cfonb160.dco=Remise de LCR 27 | pain.xxx.cfonb240.bco=Bon \u00e0 payer de LCR (r\u00e9ponse au relev\u00e9 de LCR) 28 | pain.xxx.payext912.vct=Remise de VCOM 29 | pain.xxx.payext96a.vct=Remise de VCOM 30 | pain.xxx.vcom400.vct=Remise de VCOM 31 | pain.xxx.cfonb320.xct=Remise de virement international 32 | pain.xxx.cfonb320.dct=Remise de virement domestique France 33 | pain.xxx.cfonb320.rft=Remise de virement request for transfer 34 | pain.xxx.cfonb240.tch=Remise de t\u00e9l\u00e9collecte de ch\u00e8que 35 | pain.xxx.cfonb160.dvd=Demande de v\u00e9rification de domiciliation 36 | pain.fin.mt101.dct=Remise de virement domestique France 37 | pain.fin.mt101.mct=Remise de virement 38 | pain.xxx.fff.lch=Remise de lettre ch\u00e8que o\u00f9 est \u00e9gale \u00e0 la longueur des enregistrements 39 | pain.xxx.fff.ech=Remise de ch\u00e8ques \u00e9mis o\u00f9 est \u00e9gale \u00e0 la longueur des enregistrements 40 | pain.001.001.02.sct=Remise de virement SEPA 41 | pain.001.001.02.xct=Remise de virement international 42 | pain.001.001.02.rft=Remise de virement request for transfer 43 | pain.001.001.02.ict=Remise de virement de tr\u00e9sorerie (intra groupe) 44 | pain.001.001.02.mct=Remise de virement 45 | pain.008.001.01.sdd=Remise de SDD CORE 46 | pain.008.001.01.sbb=Remise de SDD BtoB 47 | 48 | camt.xxx.cfonb560.ara=Accus\u00e9 de r\u00e9ception applicatif 49 | camt.xxx.cfonb120.stm=Relev\u00e9 de compte 50 | camt.xxx.cfonb120.rep=Relev\u00e9 de compte intraday 51 | camt.xxx.cfonb240.dri=Retour d`op\u00e9ration 52 | camt.xxx.cfonb240.rct=Relev\u00e9 de virement rejet\u00e9 53 | camt.xxx.cfonb240.rsd=Relev\u00e9 de pr\u00e9l\u00e8vement rejet\u00e9 54 | camt.xxx.cfonb240.rtg=Relev\u00e9 de t\u00e9l\u00e9r\u00e8glement rejet\u00e9 55 | camt.xxx.cfonb240.rti=Relev\u00e9 de TIP rejet\u00e9 56 | camt.xxx.cfonb240.rch=Relev\u00e9 de ch\u00e8que impay\u00e9 57 | camt.xxx.cfonb240.rco=Relev\u00e9 de LCR impay\u00e9 58 | camt.xxx.cfonb240.act=Relev\u00e9 de pr\u00e9l\u00e8vement re\u00e7u 59 | camt.xxx.cfonb240.ard=Relev\u00e9 de pr\u00e9l\u00e8vement re\u00e7u 60 | camt.xxx.cfonb240.atg=Relev\u00e9 de t\u00e9l\u00e9r\u00e8glement re\u00e7u 61 | camt.xxx.cfonb240.ati=Relev\u00e9 de TIP re\u00e7u 62 | camt.xxx.cfonb240.ach=Relev\u00e9 de ch\u00e8que pr\u00e9sent\u00e9 au paiement 63 | camt.xxx.cfonb240.pco=Relev\u00e9 de LCR 64 | camt.xxx.cfonb240.cai=Relev\u00e9 de changement de domiciliation 65 | camt.fin.mt940.stm=Relev\u00e9 de compte 66 | camt.fin.mt942.rep=Relev\u00e9 de mouvements previsionels t\u00e9l\u00e9transmis 67 | pain.002.001.02.ara=Payment Status Report 68 | -------------------------------------------------------------------------------- /src/main/resources/org/kopi/ebics/format/FileTypes_fr.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 1990-2012 kopiLeft Development SARL 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License version 2.1 as published by the Free Software Foundation. 7 | # 8 | # This library is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | # Lesser General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU Lesser General Public 14 | # License along with this library; if not, write to the Free Software 15 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | # 17 | # $Id: FileTypes_fr.properties 2 2012-02-28 09:39:55Z bentaher $ 18 | # 19 | 20 | pain.xxx.cfonb160.dct=Remise de virement domestique France 21 | pain.xxx.cfonb160.ddd=Remise d`avis de pr\u00e9l\u00e8vement domestique France 22 | pain.xxx.cfonb160.dda=Remise d`avis de pr\u00e9l\u00e8vement acc\u00e9l\u00e9r\u00e9 domestique France 23 | pain.xxx.cfonb160.dtg=Remise de t\u00e9l\u00e9r\u00e8glement domestique France 24 | pain.xxx.cfonb160.ict=Remise de virement de tr\u00e9sorerie France (Intra groupe) 25 | pain.xxx.payord912.ict=Remise de virement de tr\u00e9sorerie France (Intra groupe) 26 | pain.xxx.cfonb160.dco=Remise de LCR 27 | pain.xxx.cfonb240.bco=Bon \u00e0 payer de LCR (r\u00e9ponse au relev\u00e9 de LCR) 28 | pain.xxx.payext912.vct=Remise de VCOM 29 | pain.xxx.payext96a.vct=Remise de VCOM 30 | pain.xxx.vcom400.vct=Remise de VCOM 31 | pain.xxx.cfonb320.xct=Remise de virement international 32 | pain.xxx.cfonb320.dct=Remise de virement domestique France 33 | pain.xxx.cfonb320.rft=Remise de virement request for transfer 34 | pain.xxx.cfonb240.tch=Remise de t\u00e9l\u00e9collecte de ch\u00e8que 35 | pain.xxx.cfonb160.dvd=Demande de v\u00e9rification de domiciliation 36 | pain.fin.mt101.dct=Remise de virement domestique France 37 | pain.fin.mt101.mct=Remise de virement 38 | pain.xxx.fff.lch=Remise de lettre ch\u00e8que o\u00f9 est \u00e9gale \u00e0 la longueur des enregistrements 39 | pain.xxx.fff.ech=Remise de ch\u00e8ques \u00e9mis o\u00f9 est \u00e9gale \u00e0 la longueur des enregistrements 40 | pain.001.001.02.sct=Remise de virement SEPA 41 | pain.001.001.02.xct=Remise de virement international 42 | pain.001.001.02.rft=Remise de virement request for transfer 43 | pain.001.001.02.ict=Remise de virement de tr\u00e9sorerie (intra groupe) 44 | pain.001.001.02.mct=Remise de virement 45 | pain.008.001.01.sdd=Remise de SDD CORE 46 | pain.008.001.01.sbb=Remise de SDD BtoB 47 | 48 | camt.xxx.cfonb560.ara=Accus\u00e9 de r\u00e9ception applicatif 49 | camt.xxx.cfonb120.stm=Relev\u00e9 de compte 50 | camt.xxx.cfonb120.rep=Relev\u00e9 de compte intraday 51 | camt.xxx.cfonb240.dri=Retour d`op\u00e9ration 52 | camt.xxx.cfonb240.rct=Relev\u00e9 de virement rejet\u00e9 53 | camt.xxx.cfonb240.rsd=Relev\u00e9 de pr\u00e9l\u00e8vement rejet\u00e9 54 | camt.xxx.cfonb240.rtg=Relev\u00e9 de t\u00e9l\u00e9r\u00e8glement rejet\u00e9 55 | camt.xxx.cfonb240.rti=Relev\u00e9 de TIP rejet\u00e9 56 | camt.xxx.cfonb240.rch=Relev\u00e9 de ch\u00e8que impay\u00e9 57 | camt.xxx.cfonb240.rco=Relev\u00e9 de LCR impay\u00e9 58 | camt.xxx.cfonb240.act=Relev\u00e9 de pr\u00e9l\u00e8vement re\u00e7u 59 | camt.xxx.cfonb240.ard=Relev\u00e9 de pr\u00e9l\u00e8vement re\u00e7u 60 | camt.xxx.cfonb240.atg=Relev\u00e9 de t\u00e9l\u00e9r\u00e8glement re\u00e7u 61 | camt.xxx.cfonb240.ati=Relev\u00e9 de TIP re\u00e7u 62 | camt.xxx.cfonb240.ach=Relev\u00e9 de ch\u00e8que pr\u00e9sent\u00e9 au paiement 63 | camt.xxx.cfonb240.pco=Relev\u00e9 de LCR 64 | camt.xxx.cfonb240.cai=Relev\u00e9 de changement de domiciliation 65 | camt.fin.mt940.stm=Relev\u00e9 de compte 66 | camt.fin.mt942.rep=Relev\u00e9 de mouvements previsionels t\u00e9l\u00e9transmis 67 | pain.002.001.02.ara=Payment Status Report 68 | -------------------------------------------------------------------------------- /src/main/java/org/kopi/ebics/certificate/KeyUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1990-2012 kopiLeft Development SARL, Bizerte, Tunisia 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License version 2.1 as published by the Free Software Foundation. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | * 17 | */ 18 | 19 | package org.kopi.ebics.certificate; 20 | 21 | import java.nio.charset.StandardCharsets; 22 | import java.security.GeneralSecurityException; 23 | import java.security.KeyPair; 24 | import java.security.KeyPairGenerator; 25 | import java.security.MessageDigest; 26 | import java.security.NoSuchAlgorithmException; 27 | import java.security.SecureRandom; 28 | import java.security.interfaces.RSAPublicKey; 29 | 30 | import org.apache.commons.codec.binary.Hex; 31 | import org.kopi.ebics.exception.EbicsException; 32 | import org.kopi.ebics.utils.Utils; 33 | 34 | /** 35 | * Some key utilities 36 | * 37 | * 38 | */ 39 | public final class KeyUtil { 40 | 41 | private KeyUtil() { 42 | } 43 | 44 | /** 45 | * Generates a KeyPair in RSA format. 46 | * 47 | * @param keyLen - key size 48 | * @return KeyPair the key pair 49 | * @throws NoSuchAlgorithmException 50 | */ 51 | public static KeyPair makeKeyPair(int keyLen) throws NoSuchAlgorithmException { 52 | KeyPairGenerator keyGen; 53 | 54 | keyGen = KeyPairGenerator.getInstance("RSA"); 55 | keyGen.initialize(keyLen, Utils.secureRandom); 56 | 57 | return keyGen.generateKeyPair(); 58 | 59 | } 60 | 61 | /** 62 | * Returns the digest value of a given public key. 63 | * 64 | * 65 | *

In Version “H003” of the EBICS protocol the ES of the financial: 66 | * 67 | *

The SHA-256 hash values of the financial institution's public keys for X002 and E002 are 68 | * composed by concatenating the exponent with a blank character and the modulus in hexadecimal 69 | * representation (using lower case letters) without leading zero (as to the hexadecimal 70 | * representation). The resulting string has to be converted into a byte array based on US ASCII 71 | * code. 72 | * 73 | * @param publicKey the public key 74 | * @return the digest value 75 | * @throws EbicsException 76 | */ 77 | public static byte[] getKeyDigest(RSAPublicKey publicKey) throws EbicsException { 78 | String modulus; 79 | String exponent; 80 | String hash; 81 | byte[] digest; 82 | 83 | exponent = Hex.encodeHexString(publicKey.getPublicExponent().toByteArray()); 84 | modulus = Hex.encodeHexString(removeFirstByte(publicKey.getModulus().toByteArray())); 85 | hash = exponent + " " + modulus; 86 | 87 | if (hash.charAt(0) == '0') { 88 | hash = hash.substring(1); 89 | } 90 | 91 | try { 92 | digest = MessageDigest.getInstance("SHA-256", "BC").digest(hash.getBytes( 93 | StandardCharsets.US_ASCII)); 94 | } catch (GeneralSecurityException e) { 95 | throw new EbicsException(e.getMessage()); 96 | } 97 | 98 | return new String(Hex.encodeHex(digest, false)).getBytes(); 99 | } 100 | 101 | /** 102 | * Remove the first byte of an byte array 103 | * 104 | * @return the array 105 | * */ 106 | private static byte[] removeFirstByte(byte[] byteArray) { 107 | byte[] b = new byte[byteArray.length - 1]; 108 | System.arraycopy(byteArray, 1, b, 0, b.length); 109 | return b; 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /src/main/java/org/kopi/ebics/session/EbicsSession.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1990-2012 kopiLeft Development SARL, Bizerte, Tunisia 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License version 2.1 as published by the Free Software Foundation. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | * 17 | */ 18 | 19 | package org.kopi.ebics.session; 20 | 21 | import java.security.interfaces.RSAPublicKey; 22 | import java.util.HashMap; 23 | import java.util.Map; 24 | 25 | import org.kopi.ebics.exception.EbicsException; 26 | import org.kopi.ebics.interfaces.Configuration; 27 | import org.kopi.ebics.interfaces.EbicsUser; 28 | 29 | 30 | /** 31 | * Communication hub for EBICS. 32 | * 33 | * 34 | */ 35 | public class EbicsSession { 36 | 37 | /** 38 | * Constructs a new ebics session 39 | * @param user the ebics user 40 | * @param configuration the ebics client configuration 41 | */ 42 | public EbicsSession(EbicsUser user, Configuration configuration) { 43 | this.user = user; 44 | this.configuration = configuration; 45 | parameters = new HashMap<>(); 46 | } 47 | 48 | /** 49 | * Returns the banks encryption key. 50 | * The key will be fetched automatically form the bank if needed. 51 | * @return the banks encryption key. 52 | */ 53 | public RSAPublicKey getBankE002Key() { 54 | return user.getPartner().getBank().getE002Key(); 55 | } 56 | 57 | /** 58 | * Returns the banks authentication key. 59 | * The key will be fetched automatically form the bank if needed. 60 | * @return the banks authentication key. 61 | */ 62 | public RSAPublicKey getBankX002Key() { 63 | return user.getPartner().getBank().getX002Key(); 64 | } 65 | 66 | /** 67 | * Returns the bank id. 68 | * @return the bank id. 69 | */ 70 | public String getBankID() throws EbicsException { 71 | return user.getPartner().getBank().getHostId(); 72 | } 73 | 74 | /** 75 | * Return the session user. 76 | * @return the session user. 77 | */ 78 | public EbicsUser getUser() { 79 | return user; 80 | } 81 | 82 | /** 83 | * Returns the client application configuration. 84 | * @return the client application configuration. 85 | */ 86 | public Configuration getConfiguration() { 87 | return configuration; 88 | } 89 | 90 | /** 91 | * Sets the optional product identification that will be sent to the bank during each request. 92 | * @param product Product description 93 | */ 94 | public void setProduct(Product product) { 95 | this.product = product; 96 | } 97 | 98 | /** 99 | * @return the product 100 | */ 101 | public Product getProduct() { 102 | return product; 103 | } 104 | 105 | /** 106 | * Adds a session parameter to use it in the transfer process. 107 | * @param key the parameter key 108 | * @param value the parameter value 109 | */ 110 | public void addSessionParam(String key, String value) { 111 | parameters.put(key, value); 112 | } 113 | 114 | /** 115 | * Retrieves a session parameter using its key. 116 | * @param key the parameter key 117 | * @return the session parameter 118 | */ 119 | public String getSessionParam(String key) { 120 | if (key == null) { 121 | return null; 122 | } 123 | 124 | return parameters.get(key); 125 | } 126 | 127 | // -------------------------------------------------------------------- 128 | // DATA MEMBERS 129 | // -------------------------------------------------------------------- 130 | 131 | private final EbicsUser user; 132 | private final Configuration configuration; 133 | private Product product; 134 | private final Map parameters; 135 | } 136 | -------------------------------------------------------------------------------- /src/main/java/org/kopi/ebics/xml/DownloadInitializationResponseElement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1990-2012 kopiLeft Development SARL, Bizerte, Tunisia 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License version 2.1 as published by the Free Software Foundation. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | * 17 | */ 18 | 19 | package org.kopi.ebics.xml; 20 | 21 | import org.kopi.ebics.exception.EbicsException; 22 | import org.kopi.ebics.exception.NoDownloadDataAvailableException; 23 | import org.kopi.ebics.exception.ReturnCode; 24 | import org.kopi.ebics.interfaces.ContentFactory; 25 | import org.kopi.ebics.interfaces.EbicsOrderType; 26 | 27 | /** 28 | * The DInitializationResponseElement is the response element 29 | * for ebics downloads initializations. 30 | * 31 | * 32 | */ 33 | public class DownloadInitializationResponseElement extends InitializationResponseElement { 34 | 35 | /** 36 | * Constructs a new DInitializationResponseElement object 37 | * @param factory the content factory 38 | * @param orderType the order type 39 | * @param name the element name 40 | */ 41 | public DownloadInitializationResponseElement(ContentFactory factory, 42 | EbicsOrderType orderType, 43 | String name) 44 | { 45 | super(factory, orderType, name); 46 | } 47 | 48 | @Override 49 | protected void processBodyReturnCode() throws EbicsException { 50 | String bodyRetCode = response.getBody().getReturnCode().getStringValue(); 51 | returnCode = ReturnCode.toReturnCode(bodyRetCode, ""); 52 | if (returnCode.equals(ReturnCode.EBICS_NO_DOWNLOAD_DATA_AVAILABLE)) { 53 | throw new NoDownloadDataAvailableException(); 54 | } 55 | checkReturnCode(returnCode); 56 | } 57 | 58 | @Override 59 | public void build() throws EbicsException { 60 | super.build(); 61 | numSegments = (int)response.getHeader().getStatic().getNumSegments(); 62 | segmentNumber = (int)response.getHeader().getMutable().getSegmentNumber().getLongValue(); 63 | lastSegment = response.getHeader().getMutable().getSegmentNumber().getLastSegment(); 64 | transactionKey = response.getBody().getDataTransfer().getDataEncryptionInfo().getTransactionKey(); 65 | orderData = response.getBody().getDataTransfer().getOrderData().getByteArrayValue(); 66 | } 67 | 68 | 69 | /** 70 | * Returns the total segments number. 71 | * @return the total segments number. 72 | */ 73 | public int getSegmentsNumber() { 74 | return numSegments; 75 | } 76 | 77 | /** 78 | * Returns The current segment number. 79 | * @return the segment number. 80 | */ 81 | public int getSegmentNumber() { 82 | return segmentNumber; 83 | } 84 | 85 | /** 86 | * Checks if it is the last segment. 87 | * @return True is it is the last segment. 88 | */ 89 | public boolean isLastSegment() { 90 | return lastSegment; 91 | } 92 | 93 | /** 94 | * Returns the transaction key. 95 | * @return the transaction key. 96 | */ 97 | public byte[] getTransactionKey() { 98 | return transactionKey; 99 | } 100 | 101 | /** 102 | * Returns the order data. 103 | * @return the order data. 104 | */ 105 | public byte[] getOrderData() { 106 | return orderData; 107 | } 108 | 109 | // -------------------------------------------------------------------- 110 | // DATA MEMBERS 111 | // -------------------------------------------------------------------- 112 | 113 | private int numSegments; 114 | private int segmentNumber; 115 | private boolean lastSegment; 116 | private byte[] transactionKey; 117 | private byte[] orderData; 118 | private static final long serialVersionUID = -6013011772863903840L; 119 | } 120 | -------------------------------------------------------------------------------- /src/main/java/org/kopi/ebics/xml/UploadTransferRequestElement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1990-2012 kopiLeft Development SARL, Bizerte, Tunisia 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License version 2.1 as published by the Free Software Foundation. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | * 17 | */ 18 | 19 | package org.kopi.ebics.xml; 20 | 21 | import org.kopi.ebics.exception.EbicsException; 22 | import org.kopi.ebics.interfaces.ContentFactory; 23 | import org.kopi.ebics.interfaces.EbicsOrderType; 24 | import org.kopi.ebics.io.IOUtils; 25 | import org.kopi.ebics.schema.h005.DataTransferRequestType; 26 | import org.kopi.ebics.schema.h005.DataTransferRequestType.OrderData; 27 | import org.kopi.ebics.schema.h005.EbicsRequestDocument.EbicsRequest; 28 | import org.kopi.ebics.schema.h005.EbicsRequestDocument.EbicsRequest.Body; 29 | import org.kopi.ebics.schema.h005.EbicsRequestDocument.EbicsRequest.Header; 30 | import org.kopi.ebics.schema.h005.MutableHeaderType; 31 | import org.kopi.ebics.schema.h005.MutableHeaderType.SegmentNumber; 32 | import org.kopi.ebics.schema.h005.StaticHeaderType; 33 | import org.kopi.ebics.session.EbicsSession; 34 | 35 | /** 36 | * The UTransferRequestElement is the root element 37 | * for all ebics upload transfers. 38 | * 39 | * 40 | */ 41 | public class UploadTransferRequestElement extends TransferRequestElement { 42 | 43 | /** 44 | * Constructs a new UTransferRequestElement for ebics upload transfer. 45 | * @param session the current ebics session 46 | * @param orderType the upload order type 47 | * @param segmentNumber the segment number 48 | * @param lastSegment is it the last segment? 49 | * @param transactionId the transaction ID 50 | * @param content the content factory 51 | */ 52 | public UploadTransferRequestElement(EbicsSession session, 53 | EbicsOrderType orderType, 54 | int segmentNumber, 55 | boolean lastSegment, 56 | byte[] transactionId, 57 | ContentFactory content) 58 | { 59 | super(session, generateName(orderType), orderType, segmentNumber, lastSegment, transactionId); 60 | this.content = content; 61 | } 62 | 63 | @Override 64 | public void buildTransfer() throws EbicsException { 65 | EbicsRequest request; 66 | Header header; 67 | Body body; 68 | MutableHeaderType mutable; 69 | SegmentNumber segmentNumber; 70 | StaticHeaderType xstatic; 71 | OrderData orderData; 72 | DataTransferRequestType dataTransfer; 73 | 74 | segmentNumber = EbicsXmlFactory.createSegmentNumber(this.segmentNumber, lastSegment); 75 | mutable = EbicsXmlFactory.createMutableHeaderType("Transfer", segmentNumber); 76 | xstatic = EbicsXmlFactory.createStaticHeaderType(session.getBankID(), transactionId); 77 | header = EbicsXmlFactory.createEbicsRequestHeader(true, mutable, xstatic); 78 | orderData = EbicsXmlFactory.createEbicsRequestOrderData(IOUtils.getFactoryContent(content)); 79 | dataTransfer = EbicsXmlFactory.createDataTransferRequestType(orderData); 80 | body = EbicsXmlFactory.createEbicsRequestBody(dataTransfer); 81 | request = EbicsXmlFactory.createEbicsRequest(session.getConfiguration().getRevision(), 82 | session.getConfiguration().getVersion(), 83 | header, 84 | body); 85 | document = EbicsXmlFactory.createEbicsRequestDocument(request); 86 | } 87 | 88 | // -------------------------------------------------------------------- 89 | // DATA MEMBERS 90 | // -------------------------------------------------------------------- 91 | 92 | private final ContentFactory content; 93 | private static final long serialVersionUID = 8465397978597444978L; 94 | } 95 | -------------------------------------------------------------------------------- /src/main/java/org/kopi/ebics/xml/TransferRequestElement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1990-2012 kopiLeft Development SARL, Bizerte, Tunisia 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License version 2.1 as published by the Free Software Foundation. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | * 17 | */ 18 | 19 | package org.kopi.ebics.xml; 20 | 21 | import java.security.MessageDigest; 22 | import java.security.NoSuchAlgorithmException; 23 | import java.security.NoSuchProviderException; 24 | 25 | import org.kopi.ebics.exception.EbicsException; 26 | import org.kopi.ebics.interfaces.EbicsOrderType; 27 | import org.kopi.ebics.schema.h005.EbicsRequestDocument; 28 | import org.kopi.ebics.session.EbicsSession; 29 | import org.kopi.ebics.utils.Utils; 30 | 31 | 32 | /** 33 | * The TransferRequestElement is the common root element 34 | * for all ebics transfer for the bank server. 35 | * 36 | * 37 | */ 38 | public abstract class TransferRequestElement extends DefaultEbicsRootElement { 39 | 40 | /** 41 | * Constructs a new TransferRequestElement element. 42 | * @param session the current ebics session 43 | * @param name the element name 44 | * @param type the order type 45 | * @param segmentNumber the segment number to be sent 46 | * @param lastSegment is it the last segment? 47 | * @param transactionId the transaction ID 48 | */ 49 | protected TransferRequestElement(EbicsSession session, 50 | String name, 51 | EbicsOrderType type, 52 | int segmentNumber, 53 | boolean lastSegment, 54 | byte[] transactionId) 55 | { 56 | super(session); 57 | this.type = type; 58 | this.name = name; 59 | this.segmentNumber = segmentNumber; 60 | this.lastSegment = lastSegment; 61 | this.transactionId = transactionId; 62 | } 63 | 64 | @Override 65 | public void build() throws EbicsException { 66 | SignedInfo signedInfo; 67 | 68 | buildTransfer(); 69 | signedInfo = new SignedInfo(session.getUser(), getDigest()); 70 | signedInfo.build(); 71 | ((EbicsRequestDocument)document).getEbicsRequest().setAuthSignature(signedInfo.getSignatureType()); 72 | ((EbicsRequestDocument)document).getEbicsRequest().getAuthSignature().setSignatureValue(EbicsXmlFactory.createSignatureValueType(signedInfo.sign(toByteArray()))); 73 | } 74 | 75 | @Override 76 | public String getName() { 77 | return name + ".xml"; 78 | } 79 | 80 | /** 81 | * Returns the digest value of the authenticated XML portions. 82 | * @return the digest value. 83 | * @throws EbicsException Failed to retrieve the digest value. 84 | */ 85 | public byte[] getDigest() throws EbicsException { 86 | addNamespaceDecl("ds", "http://www.w3.org/2000/09/xmldsig#"); 87 | 88 | try { 89 | return MessageDigest.getInstance("SHA-256", "BC").digest(Utils.canonize(toByteArray())); 90 | } catch (NoSuchAlgorithmException | NoSuchProviderException e) { 91 | throw new EbicsException(e.getMessage()); 92 | } 93 | } 94 | 95 | /** 96 | * Returns the order type of the element. 97 | * @return the order type element. 98 | */ 99 | public String getOrderType() { 100 | return type.getCode(); 101 | } 102 | 103 | @Override 104 | public byte[] toByteArray() { 105 | setSaveSuggestedPrefixes("http://www.ebics.org/H003", ""); 106 | 107 | return super.toByteArray(); 108 | } 109 | 110 | /** 111 | * Builds the transfer request. 112 | * @throws EbicsException 113 | */ 114 | public abstract void buildTransfer() throws EbicsException; 115 | 116 | // -------------------------------------------------------------------- 117 | // DATA MEMBERS 118 | // -------------------------------------------------------------------- 119 | 120 | protected int segmentNumber; 121 | protected boolean lastSegment; 122 | protected byte[] transactionId; 123 | private final EbicsOrderType type; 124 | private final String name; 125 | private static final long serialVersionUID = -4212072825371398259L; 126 | } 127 | -------------------------------------------------------------------------------- /src/test/java/org/kopi/ebics/io/SplitterTest.java: -------------------------------------------------------------------------------- 1 | package org.kopi.ebics.io; 2 | 3 | import org.bouncycastle.jce.provider.BouncyCastleProvider; 4 | import org.junit.jupiter.api.Test; 5 | import org.kopi.ebics.exception.EbicsException; 6 | import org.kopi.ebics.session.EbicsSession; 7 | import org.kopi.ebics.session.OrderType; 8 | import org.kopi.ebics.xml.UploadTransferRequestElement; 9 | import org.mockito.Mockito; 10 | 11 | import javax.crypto.SecretKey; 12 | import javax.crypto.SecretKeyFactory; 13 | import javax.crypto.spec.PBEKeySpec; 14 | import javax.crypto.spec.SecretKeySpec; 15 | import java.io.IOException; 16 | import java.security.NoSuchAlgorithmException; 17 | import java.security.Security; 18 | import java.security.spec.InvalidKeySpecException; 19 | import java.util.Random; 20 | 21 | import static org.junit.jupiter.api.Assertions.assertTrue; 22 | 23 | class SplitterTest { 24 | 25 | private static final int ONE_KB = 1000; 26 | private static final int ONE_MB = ONE_KB * ONE_KB; 27 | private static final int CHUNK_SIZE_LIMIT = 700 * ONE_KB; 28 | private static final int REQUEST_SIZE_LIMIT = 1000 * ONE_KB; 29 | private static final Random RANDOM_SEED = new Random(0); 30 | 31 | @Test 32 | void testSplitOneMb() throws NoSuchAlgorithmException, InvalidKeySpecException, EbicsException, IOException { 33 | byte[] b = randomDataArray(ONE_MB); 34 | Splitter splitter = splitAndVerifyContent(b); 35 | verifyActualRequestSize(splitter); 36 | } 37 | 38 | @Test 39 | void testSplitTwoMb() throws NoSuchAlgorithmException, InvalidKeySpecException, EbicsException, IOException { 40 | byte[] b = randomDataArray(2 * ONE_MB); 41 | Splitter splitter = splitAndVerifyContent(b); 42 | verifyActualRequestSize(splitter); 43 | } 44 | 45 | @Test 46 | void testSplitTenMb() throws NoSuchAlgorithmException, InvalidKeySpecException, EbicsException, IOException { 47 | byte[] b = randomDataArray(10 * ONE_MB); 48 | Splitter splitter = splitAndVerifyContent(b); 49 | verifyActualRequestSize(splitter); 50 | } 51 | 52 | @Test 53 | void testSplitFiftyMb() throws NoSuchAlgorithmException, InvalidKeySpecException, EbicsException, IOException { 54 | byte[] b = randomDataArray(50 * ONE_MB); 55 | Splitter splitter = splitAndVerifyContent(b); 56 | verifyActualRequestSize(splitter); 57 | } 58 | 59 | private UploadTransferRequestElement prepareActualRequest(Splitter splitter) throws EbicsException { 60 | EbicsSession ebicsSession = Mockito.mock(EbicsSession.class, Mockito.RETURNS_DEEP_STUBS); 61 | 62 | UploadTransferRequestElement uploader = new UploadTransferRequestElement(ebicsSession, 63 | OrderType.CDD, 64 | 1, 65 | false, 66 | "asda".getBytes(), 67 | splitter.getContent(1) 68 | ); 69 | uploader.build(); 70 | return uploader; 71 | } 72 | 73 | private void verifyActualRequestSize(Splitter splitter) throws EbicsException { 74 | UploadTransferRequestElement fullRequest = prepareActualRequest(splitter); 75 | int actualSize = fullRequest.prettyPrint().length; 76 | assertTrue(actualSize < SplitterTest.REQUEST_SIZE_LIMIT); 77 | } 78 | 79 | private Splitter splitAndVerifyContent(byte[] b) throws InvalidKeySpecException, NoSuchAlgorithmException, EbicsException, IOException { 80 | Splitter splitter = new Splitter(b); 81 | splitter.readInput(true, new SecretKeySpec(secretKey().getEncoded(), "EAS")); 82 | int segmentSize = splitter.getSegmentSize(); 83 | int segmentCount = splitter.getSegmentNumber(); 84 | assertTrue(segmentSize < SplitterTest.CHUNK_SIZE_LIMIT); 85 | for (int i = 1; i <= segmentCount; i++) { 86 | int contentLength = splitter.getContent(i).getContent().available(); 87 | assertTrue(contentLength < SplitterTest.CHUNK_SIZE_LIMIT); 88 | } 89 | return splitter; 90 | } 91 | 92 | private SecretKey secretKey() throws NoSuchAlgorithmException, InvalidKeySpecException { 93 | Security.addProvider(new BouncyCastleProvider()); 94 | 95 | final String password = "test"; 96 | int pswdIterations = 65536; 97 | int keySize = 256; 98 | byte[] saltBytes = {0, 1, 2, 3, 4, 5, 6}; 99 | 100 | SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1"); 101 | PBEKeySpec spec = new PBEKeySpec( 102 | password.toCharArray(), 103 | saltBytes, 104 | pswdIterations, 105 | keySize 106 | ); 107 | 108 | return factory.generateSecret(spec); 109 | } 110 | 111 | private byte[] randomDataArray(int size) { 112 | byte[] b = new byte[size]; 113 | RANDOM_SEED.nextBytes(b); 114 | return b; 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /src/main/java/org/kopi/ebics/client/Partner.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1990-2012 kopiLeft Development SARL, Bizerte, Tunisia 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License version 2.1 as published by the Free Software Foundation. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | * 17 | */ 18 | 19 | package org.kopi.ebics.client; 20 | 21 | import java.io.IOException; 22 | import java.io.ObjectInputStream; 23 | import java.io.ObjectOutputStream; 24 | 25 | import org.kopi.ebics.interfaces.EbicsBank; 26 | import org.kopi.ebics.interfaces.EbicsPartner; 27 | import org.kopi.ebics.interfaces.Savable; 28 | 29 | 30 | /** 31 | * Simple implementation of an EBICS customer. 32 | * This object is not serializable, but it should be persisted every time it needs to be saved. 33 | * Persistence is achieved via save(ObjectOutputStream) and the matching constructor. 34 | * 35 | * 36 | */ 37 | public class Partner implements EbicsPartner, Savable { 38 | 39 | /** 40 | * Reconstructs a persisted EBICS customer. 41 | * @param bank the bank 42 | * @param ois the stream object 43 | * @throws IOException 44 | */ 45 | public Partner(EbicsBank bank, ObjectInputStream ois) throws IOException { 46 | this.bank = bank; 47 | this.partnerId = ois.readUTF(); 48 | this.orderId = ois.readInt(); 49 | } 50 | 51 | /** 52 | * First time constructor. 53 | * @param bank the bank 54 | * @param partnerId the partner ID 55 | */ 56 | public Partner(EbicsBank bank, String partnerId) { 57 | this.bank = bank; 58 | this.partnerId = partnerId; 59 | needSave = true; 60 | } 61 | 62 | /** 63 | * Returns the next order available ID 64 | * @return the next order ID 65 | */ 66 | public Integer getNextOrderId() { 67 | return Integer.valueOf(orderId); 68 | } 69 | 70 | /** 71 | * Sets the order ID 72 | * @param orderId the order ID 73 | */ 74 | public void setOrderId(Integer orderId) { 75 | this.orderId = orderId.intValue(); 76 | needSave = true; 77 | } 78 | 79 | @Override 80 | public void save(ObjectOutputStream oos) throws IOException { 81 | oos.writeUTF(partnerId); 82 | oos.writeInt(orderId); 83 | oos.flush(); 84 | oos.close(); 85 | needSave = false; 86 | } 87 | 88 | /** 89 | * Did any persistable attribute change since last load/save operation. 90 | * @return True if the object needs to be saved. 91 | */ 92 | public boolean needsSave() { 93 | return needSave; 94 | } 95 | 96 | @Override 97 | public EbicsBank getBank() { 98 | return bank; 99 | } 100 | 101 | @Override 102 | public String getPartnerId() { 103 | return partnerId; 104 | } 105 | 106 | /** 107 | * In EBICS XSD schema - ebics_types.xsd, The order ID pattern 108 | * is defined as following: pattern value="[A-Z][A-Z0-9]{3}". 109 | *

This means that the order ID should start with a letter 110 | * followed by three alphanumeric characters. 111 | * 112 | *

The nextOrderId() aims to generate orders from 113 | *A000 to ZZZZ. The sequence cycle is performed infinitely. 114 | * 115 | *

The order index {@link Partner#orderId} is saved whenever it 116 | * changes. 117 | */ 118 | @Override 119 | public String nextOrderId() { 120 | char[] chars = new char[4]; 121 | 122 | orderId += 1; 123 | if (orderId > 36*36*36*36 - 1) { 124 | // ensure that orderId starts with a letter 125 | orderId = 10*36*36*36; 126 | } 127 | chars[3] = ALPHA_NUM_CHARS.charAt(orderId % 36); 128 | chars[2] = ALPHA_NUM_CHARS.charAt((orderId / 36) % 36); 129 | chars[1] = ALPHA_NUM_CHARS.charAt((orderId / 36 / 36) % 36); 130 | chars[0] = ALPHA_NUM_CHARS.charAt(orderId / 36 / 36 / 36); 131 | needSave = true; 132 | 133 | return new String(chars); 134 | } 135 | 136 | @Override 137 | public String getSaveName() { 138 | return "partner-" + partnerId + ".cer"; 139 | } 140 | 141 | // -------------------------------------------------------------------- 142 | // DATA MEMBERS 143 | // -------------------------------------------------------------------- 144 | 145 | private final EbicsBank bank; 146 | private int orderId = 10*36*36*36; 147 | private final String partnerId; 148 | private transient boolean needSave; 149 | 150 | private static final String ALPHA_NUM_CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 151 | } 152 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | org.kopi 5 | ebics 6 | jar 7 | 2.0.0 8 | ebics 9 | https://github.com/ebics-java/ebics-java-client 10 | 11 | 12 | org.apache.xmlbeans 13 | xmlbeans 14 | 5.3.0 15 | 16 | 17 | commons-codec 18 | commons-codec 19 | 1.15 20 | 21 | 22 | org.apache.httpcomponents 23 | httpclient 24 | 4.5.14 25 | 26 | 27 | org.bouncycastle 28 | bcprov-jdk18on 29 | 1.82 30 | 31 | 32 | org.slf4j 33 | slf4j-api 34 | 2.0.17 35 | 36 | 37 | org.slf4j 38 | slf4j-simple 39 | 2.0.17 40 | true 41 | 42 | 43 | org.gnu 44 | gnu-crypto 45 | 2.0.1 46 | 47 | 48 | org.apache.santuario 49 | xmlsec 50 | 4.0.4 51 | 52 | 53 | commons-cli 54 | commons-cli 55 | 1.11.0 56 | 57 | 58 | org.junit.jupiter 59 | junit-jupiter-api 60 | 6.0.0 61 | test 62 | 63 | 64 | org.junit.jupiter 65 | junit-jupiter-engine 66 | 6.0.0 67 | test 68 | 69 | 70 | org.mockito 71 | mockito-core 72 | 3.2.4 73 | test 74 | 75 | 76 | 77 | 78 | 79 | org.apache.xmlbeans 80 | xmlbeans 81 | 5.3.0 82 | 83 | 84 | 85 | compile 86 | 87 | 88 | 89 | 90 | src/main/xsd 91 | 92 | src/main/xsd/config/config.xsdconfig 93 | 94 | 95 | 96 | 97 | 98 | org.apache.maven.plugins 99 | maven-compiler-plugin 100 | 3.14.1 101 | 102 | 17 103 | 104 | 105 | 106 | org.apache.maven.plugins 107 | maven-source-plugin 108 | 3.3.1 109 | 110 | 111 | attach-sources 112 | 113 | jar 114 | 115 | 116 | 117 | 118 | 119 | org.apache.maven.plugins 120 | maven-surefire-plugin 121 | 3.5.4 122 | 123 | 124 | 125 | 126 | UTF-8 127 | 128 | 129 | -------------------------------------------------------------------------------- /src/main/java/org/kopi/ebics/xml/UnsecuredRequestElement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1990-2012 kopiLeft Development SARL, Bizerte, Tunisia 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License version 2.1 as published by the Free Software Foundation. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | * 17 | */ 18 | 19 | package org.kopi.ebics.xml; 20 | 21 | import org.kopi.ebics.exception.EbicsException; 22 | import org.kopi.ebics.interfaces.EbicsOrderType; 23 | import org.kopi.ebics.schema.h005.EmptyMutableHeaderType; 24 | import org.kopi.ebics.schema.h005.OrderDetailsType; 25 | import org.kopi.ebics.schema.h005.ProductElementType; 26 | import org.kopi.ebics.schema.h005.UnsecuredRequestStaticHeaderType; 27 | import org.kopi.ebics.schema.h005.EbicsUnsecuredRequestDocument.EbicsUnsecuredRequest; 28 | import org.kopi.ebics.schema.h005.EbicsUnsecuredRequestDocument.EbicsUnsecuredRequest.Body; 29 | import org.kopi.ebics.schema.h005.EbicsUnsecuredRequestDocument.EbicsUnsecuredRequest.Header; 30 | import org.kopi.ebics.schema.h005.EbicsUnsecuredRequestDocument.EbicsUnsecuredRequest.Body.DataTransfer; 31 | import org.kopi.ebics.schema.h005.EbicsUnsecuredRequestDocument.EbicsUnsecuredRequest.Body.DataTransfer.OrderData; 32 | import org.kopi.ebics.session.EbicsSession; 33 | 34 | /** 35 | * The UnsecuredRequestElement is the common element 36 | * used for key management requests. 37 | * 38 | * 39 | */ 40 | public class UnsecuredRequestElement extends DefaultEbicsRootElement { 41 | 42 | /** 43 | * Constructs a Unsecured Request Element. 44 | * @param session the ebics session. 45 | * @param orderType the order type (INI | HIA). 46 | * @param orderId the order id, if null a random one is generated. 47 | */ 48 | public UnsecuredRequestElement(EbicsSession session, 49 | EbicsOrderType orderType, 50 | String orderId, 51 | byte[] orderData) 52 | { 53 | super(session); 54 | this.orderType = orderType; 55 | this.orderId = orderId; 56 | this.orderData = orderData; 57 | } 58 | 59 | @Override 60 | public void build() throws EbicsException { 61 | Header header; 62 | Body body; 63 | EmptyMutableHeaderType mutable; 64 | UnsecuredRequestStaticHeaderType xstatic; 65 | ProductElementType productType; 66 | OrderDetailsType orderDetails; 67 | DataTransfer dataTransfer; 68 | OrderData orderData; 69 | EbicsUnsecuredRequest request; 70 | 71 | orderDetails = EbicsXmlFactory.createOrderDetailsType(orderType.getCode()); 72 | 73 | productType = EbicsXmlFactory.creatProductElementType(session.getProduct().getLanguage(), 74 | session.getProduct().getName()); 75 | 76 | xstatic = EbicsXmlFactory.createUnsecuredRequestStaticHeaderType(session.getBankID(), 77 | session.getUser().getPartner().getPartnerId(), 78 | session.getUser().getUserId(), 79 | productType, 80 | orderDetails, 81 | session.getUser().getSecurityMedium()); 82 | mutable = EbicsXmlFactory.createEmptyMutableHeaderType(); 83 | 84 | header = EbicsXmlFactory.createHeader(true, 85 | mutable, 86 | xstatic); 87 | 88 | orderData = EbicsXmlFactory.createOrderData(this.orderData); 89 | dataTransfer = EbicsXmlFactory.createDataTransfer(orderData); 90 | body = EbicsXmlFactory.createBody(dataTransfer); 91 | request = EbicsXmlFactory.createEbicsUnsecuredRequest(header, 92 | body, 93 | session.getConfiguration().getRevision(), 94 | session.getConfiguration().getVersion()); 95 | 96 | document = EbicsXmlFactory.createEbicsUnsecuredRequestDocument(request); 97 | } 98 | 99 | @Override 100 | public String getName() { 101 | return "UnsecuredRequest.xml"; 102 | } 103 | 104 | 105 | 106 | // -------------------------------------------------------------------- 107 | // DATA MEMBERS 108 | // -------------------------------------------------------------------- 109 | 110 | private final EbicsOrderType orderType; 111 | private final String orderId; 112 | private final byte[] orderData; 113 | private static final long serialVersionUID = -3548730114599886711L; 114 | } 115 | -------------------------------------------------------------------------------- /src/main/java/org/kopi/ebics/xml/ReceiptRequestElement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1990-2012 kopiLeft Development SARL, Bizerte, Tunisia 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License version 2.1 as published by the Free Software Foundation. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | * 17 | */ 18 | 19 | package org.kopi.ebics.xml; 20 | 21 | import java.security.MessageDigest; 22 | import java.security.NoSuchAlgorithmException; 23 | import java.security.NoSuchProviderException; 24 | 25 | import org.kopi.ebics.exception.EbicsException; 26 | import org.kopi.ebics.schema.h005.EbicsRequestDocument; 27 | import org.kopi.ebics.schema.h005.MutableHeaderType; 28 | import org.kopi.ebics.schema.h005.StaticHeaderType; 29 | import org.kopi.ebics.schema.h005.EbicsRequestDocument.EbicsRequest; 30 | import org.kopi.ebics.schema.h005.EbicsRequestDocument.EbicsRequest.Body; 31 | import org.kopi.ebics.schema.h005.EbicsRequestDocument.EbicsRequest.Header; 32 | import org.kopi.ebics.schema.h005.EbicsRequestDocument.EbicsRequest.Body.TransferReceipt; 33 | import org.kopi.ebics.session.EbicsSession; 34 | import org.kopi.ebics.utils.Utils; 35 | 36 | 37 | /** 38 | * The ReceiptRequestElement is the element containing the 39 | * receipt request to tell the server bank that all segments are received. 40 | * 41 | * 42 | */ 43 | public class ReceiptRequestElement extends DefaultEbicsRootElement { 44 | 45 | /** 46 | * Construct a new ReceiptRequestElement element. 47 | * @param session the current ebics session 48 | * @param name the element name 49 | */ 50 | public ReceiptRequestElement(EbicsSession session, 51 | byte[] transactionId, 52 | String name) 53 | { 54 | super(session); 55 | this.transactionId = transactionId; 56 | this.name = name; 57 | } 58 | 59 | @Override 60 | public void build() throws EbicsException { 61 | EbicsRequest request; 62 | Header header; 63 | Body body; 64 | MutableHeaderType mutable; 65 | StaticHeaderType xstatic; 66 | TransferReceipt transferReceipt; 67 | SignedInfo signedInfo; 68 | 69 | mutable = EbicsXmlFactory.createMutableHeaderType("Receipt", null); 70 | xstatic = EbicsXmlFactory.createStaticHeaderType(session.getBankID(), transactionId); 71 | header = EbicsXmlFactory.createEbicsRequestHeader(true, mutable, xstatic); 72 | transferReceipt = EbicsXmlFactory.createTransferReceipt(true, 0); 73 | body = EbicsXmlFactory.createEbicsRequestBody(transferReceipt); 74 | request = EbicsXmlFactory.createEbicsRequest(session.getConfiguration().getRevision(), 75 | session.getConfiguration().getVersion(), 76 | header, 77 | body); 78 | document = EbicsXmlFactory.createEbicsRequestDocument(request); 79 | signedInfo = new SignedInfo(session.getUser(), getDigest()); 80 | signedInfo.build(); 81 | ((EbicsRequestDocument)document).getEbicsRequest().setAuthSignature(signedInfo.getSignatureType()); 82 | ((EbicsRequestDocument)document).getEbicsRequest().getAuthSignature().setSignatureValue(EbicsXmlFactory.createSignatureValueType(signedInfo.sign(toByteArray()))); 83 | } 84 | 85 | @Override 86 | public byte[] toByteArray() { 87 | setSaveSuggestedPrefixes("http://www.ebics.org/H003", ""); 88 | 89 | return super.toByteArray(); 90 | } 91 | 92 | @Override 93 | public String getName() { 94 | return name + ".xml"; 95 | } 96 | 97 | /** 98 | * Returns the digest value of the authenticated XML portions. 99 | * @return the digest value. 100 | * @throws EbicsException Failed to retrieve the digest value. 101 | */ 102 | public byte[] getDigest() throws EbicsException { 103 | addNamespaceDecl("ds", "http://www.w3.org/2000/09/xmldsig#"); 104 | 105 | try { 106 | return MessageDigest.getInstance("SHA-256", "BC").digest(Utils.canonize(toByteArray())); 107 | } catch (NoSuchAlgorithmException e) { 108 | throw new EbicsException(e.getMessage()); 109 | } catch (NoSuchProviderException e) { 110 | throw new EbicsException(e.getMessage()); 111 | } 112 | } 113 | 114 | // -------------------------------------------------------------------- 115 | // DATA MEMBERS 116 | // -------------------------------------------------------------------- 117 | 118 | private final byte[] transactionId; 119 | private final String name; 120 | private static final long serialVersionUID = -1969616441705744725L; 121 | } 122 | -------------------------------------------------------------------------------- /src/test/java/org/kopi/ebics/certificate/CertificateManagerTest.java: -------------------------------------------------------------------------------- 1 | package org.kopi.ebics.certificate; 2 | 3 | import static org.junit.jupiter.api.Assertions.assertEquals; 4 | import static org.junit.jupiter.api.Assertions.assertNotNull; 5 | 6 | import java.io.IOException; 7 | import java.security.GeneralSecurityException; 8 | import java.security.PrivateKey; 9 | import java.security.Security; 10 | import java.security.cert.X509Certificate; 11 | import java.security.interfaces.RSAPublicKey; 12 | import java.util.Calendar; 13 | import java.util.Date; 14 | 15 | import javax.security.auth.x500.X500Principal; 16 | 17 | import org.apache.xml.security.Init; 18 | import org.bouncycastle.jce.provider.BouncyCastleProvider; 19 | import org.junit.jupiter.api.Test; 20 | import org.kopi.ebics.exception.EbicsException; 21 | import org.kopi.ebics.interfaces.EbicsPartner; 22 | import org.kopi.ebics.interfaces.EbicsUser; 23 | import org.kopi.ebics.interfaces.PasswordCallback; 24 | 25 | class CertificateManagerTest { 26 | static { 27 | Init.init(); 28 | Security.addProvider(new BouncyCastleProvider()); 29 | } 30 | 31 | @Test 32 | void createA005Certificate() throws GeneralSecurityException, IOException { 33 | var user = new EbicsUser() { 34 | @Override 35 | public RSAPublicKey getA005PublicKey() { 36 | return null; 37 | } 38 | 39 | @Override 40 | public RSAPublicKey getE002PublicKey() { 41 | return null; 42 | } 43 | 44 | @Override 45 | public RSAPublicKey getX002PublicKey() { 46 | return null; 47 | } 48 | 49 | @Override 50 | public byte[] getA005Certificate() throws EbicsException { 51 | return new byte[0]; 52 | } 53 | 54 | @Override 55 | public byte[] getX002Certificate() throws EbicsException { 56 | return new byte[0]; 57 | } 58 | 59 | @Override 60 | public byte[] getE002Certificate() throws EbicsException { 61 | return new byte[0]; 62 | } 63 | 64 | @Override 65 | public void setA005Certificate(X509Certificate a005certificate) { 66 | 67 | } 68 | 69 | @Override 70 | public void setX002Certificate(X509Certificate x002certificate) { 71 | 72 | } 73 | 74 | @Override 75 | public void setE002Certificate(X509Certificate e002certificate) { 76 | 77 | } 78 | 79 | @Override 80 | public void setA005PrivateKey(PrivateKey a005Key) { 81 | 82 | } 83 | 84 | @Override 85 | public void setX002PrivateKey(PrivateKey x002Key) { 86 | 87 | } 88 | 89 | @Override 90 | public void setE002PrivateKey(PrivateKey e002Key) { 91 | 92 | } 93 | 94 | @Override 95 | public String getSecurityMedium() { 96 | return ""; 97 | } 98 | 99 | @Override 100 | public EbicsPartner getPartner() { 101 | return null; 102 | } 103 | 104 | @Override 105 | public String getUserId() { 106 | return ""; 107 | } 108 | 109 | @Override 110 | public String getName() { 111 | return "test-name"; 112 | } 113 | 114 | @Override 115 | public String getDN() { 116 | return "CN=test-dn"; 117 | } 118 | 119 | @Override 120 | public PasswordCallback getPasswordCallback() { 121 | return null; 122 | } 123 | 124 | @Override 125 | public byte[] authenticate(byte[] digest) throws GeneralSecurityException { 126 | return new byte[0]; 127 | } 128 | 129 | @Override 130 | public byte[] sign(byte[] digest) throws IOException, GeneralSecurityException { 131 | return new byte[0]; 132 | } 133 | 134 | @Override 135 | public byte[] decrypt(byte[] encryptedKey, byte[] transactionKey) 136 | throws GeneralSecurityException, IOException, EbicsException { 137 | return new byte[0]; 138 | } 139 | 140 | }; 141 | var manager = new CertificateManager(user); 142 | Calendar calendar = Calendar.getInstance(); 143 | calendar.add(Calendar.DAY_OF_YEAR, X509Constants.DEFAULT_DURATION); 144 | 145 | manager.createA005Certificate(new Date(calendar.getTimeInMillis())); 146 | 147 | var cert = manager.getA005Certificate(); 148 | 149 | assertNotNull(cert); 150 | 151 | //System.out.println(cert); 152 | 153 | assertEquals(3, cert.getVersion(), "Certificate version must be 3 (V3)."); 154 | String expectedDN = "CN=test-dn"; 155 | assertEquals(expectedDN, cert.getIssuerX500Principal().getName(X500Principal.RFC2253)); 156 | assertEquals(expectedDN, cert.getSubjectX500Principal().getName(X500Principal.RFC2253)); 157 | assertEquals("SHA256WITHRSA", cert.getSigAlgName()); 158 | } 159 | } 160 | -------------------------------------------------------------------------------- /src/main/java/org/kopi/ebics/client/HttpRequestSender.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1990-2012 kopiLeft Development SARL, Bizerte, Tunisia 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License version 2.1 as published by the Free Software Foundation. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | * 17 | */ 18 | 19 | package org.kopi.ebics.client; 20 | 21 | import java.io.IOException; 22 | import java.io.InputStream; 23 | 24 | import org.apache.http.HttpEntity; 25 | import org.apache.http.HttpHeaders; 26 | import org.apache.http.HttpHost; 27 | import org.apache.http.auth.AuthScope; 28 | import org.apache.http.auth.UsernamePasswordCredentials; 29 | import org.apache.http.client.CredentialsProvider; 30 | import org.apache.http.client.config.RequestConfig; 31 | import org.apache.http.client.entity.EntityBuilder; 32 | import org.apache.http.client.methods.CloseableHttpResponse; 33 | import org.apache.http.client.methods.HttpPost; 34 | import org.apache.http.impl.client.BasicCredentialsProvider; 35 | import org.apache.http.impl.client.CloseableHttpClient; 36 | import org.apache.http.impl.client.HttpClientBuilder; 37 | import org.apache.http.impl.client.ProxyAuthenticationStrategy; 38 | import org.apache.http.util.EntityUtils; 39 | import org.kopi.ebics.interfaces.Configuration; 40 | import org.kopi.ebics.interfaces.ContentFactory; 41 | import org.kopi.ebics.io.ByteArrayContentFactory; 42 | import org.kopi.ebics.session.EbicsSession; 43 | 44 | /** 45 | * A simple HTTP request sender and receiver. The send returns a HTTP code that 46 | * should be analyzed before proceeding ebics request response parse. 47 | * 48 | */ 49 | public class HttpRequestSender { 50 | 51 | private final EbicsSession session; 52 | private ContentFactory response; 53 | private final CloseableHttpClient httpClient; 54 | 55 | /** 56 | * Constructs a new HttpRequestSender with a given ebics 57 | * session. 58 | * 59 | * @param session the ebics session 60 | */ 61 | public HttpRequestSender(EbicsSession session) { 62 | this.session = session; 63 | this.httpClient = createClient(); 64 | } 65 | 66 | private CloseableHttpClient createClient() { 67 | RequestConfig.Builder configBuilder = RequestConfig.copy(RequestConfig.DEFAULT) 68 | .setSocketTimeout(300_000).setConnectTimeout(300_000); 69 | Configuration conf = session.getConfiguration(); 70 | String proxyHost = conf.getProperty("http.proxy.host"); 71 | CredentialsProvider credsProvider = null; 72 | 73 | if (proxyHost != null && !proxyHost.isEmpty()) { 74 | int proxyPort = Integer.parseInt(conf.getProperty("http.proxy.port").trim()); 75 | HttpHost proxy = new HttpHost(proxyHost.trim(), proxyPort); 76 | configBuilder.setProxy(proxy); 77 | 78 | String user = conf.getProperty("http.proxy.user"); 79 | if (user != null && !user.isEmpty()) { 80 | user = user.trim(); 81 | String pwd = conf.getProperty("http.proxy.password").trim(); 82 | credsProvider = new BasicCredentialsProvider(); 83 | credsProvider.setCredentials(new AuthScope(proxyHost, proxyPort), 84 | new UsernamePasswordCredentials(user, pwd)); 85 | } 86 | } 87 | HttpClientBuilder builder = HttpClientBuilder.create() 88 | .setDefaultRequestConfig(configBuilder.build()); 89 | if (credsProvider != null) { 90 | builder.setDefaultCredentialsProvider(credsProvider); 91 | builder.setProxyAuthenticationStrategy(new ProxyAuthenticationStrategy()); 92 | } 93 | return builder.build(); 94 | } 95 | 96 | /** 97 | * Sends the request contained in the ContentFactory. The 98 | * ContentFactory will deliver the request as an 99 | * InputStream. 100 | * 101 | * @param request the ebics request 102 | * @return the HTTP return code 103 | */ 104 | public final int send(ContentFactory request) throws IOException { 105 | InputStream input = request.getContent(); 106 | HttpPost method = new HttpPost( 107 | session.getUser().getPartner().getBank().getURL().toString()); 108 | 109 | HttpEntity requestEntity = EntityBuilder.create().setStream(input).build(); 110 | method.setEntity(requestEntity); 111 | method.setHeader(HttpHeaders.CONTENT_TYPE, "text/xml; charset=ISO-8859-1"); 112 | 113 | try (CloseableHttpResponse response = httpClient.execute(method)) { 114 | this.response = new ByteArrayContentFactory( 115 | EntityUtils.toByteArray(response.getEntity())); 116 | return response.getStatusLine().getStatusCode(); 117 | } 118 | } 119 | 120 | /** 121 | * Returns the content factory of the response body 122 | * 123 | * @return the content factory of the response. 124 | */ 125 | public ContentFactory getResponseBody() { 126 | return response; 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /src/main/java/org/kopi/ebics/interfaces/Configuration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1990-2012 kopiLeft Development SARL, Bizerte, Tunisia 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License version 2.1 as published by the Free Software Foundation. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | * 17 | */ 18 | 19 | package org.kopi.ebics.interfaces; 20 | 21 | import java.io.File; 22 | import java.util.Locale; 23 | 24 | 25 | /** 26 | * EBICS client application configuration. 27 | * 28 | * 29 | */ 30 | public interface Configuration { 31 | 32 | /** 33 | * Returns the root directory of the client application. 34 | * @return the root directory of the client application. 35 | */ 36 | File getRootDirectory(); 37 | 38 | /** 39 | * Returns the EBICS configuration file. 40 | * @return the EBICS configuration file. 41 | */ 42 | File getConfigurationFile(); 43 | 44 | /** 45 | * Returns the property value of a given key from 46 | * the configuration file 47 | * @param key the given key 48 | * @return the property value 49 | */ 50 | String getProperty(String key); 51 | 52 | /** 53 | * Returns the directory path of the key store that contains 54 | * bank and user certificates. 55 | * @param user the ebics user. 56 | * @return the key store directory of a given user. 57 | */ 58 | File getKeystoreDirectory(EbicsUser user); 59 | 60 | /** 61 | * Returns the directory path that contains the traces 62 | * XML transfer files. 63 | * @param user the ebics user 64 | * @return the transfer trace directory 65 | */ 66 | File getTransferTraceDirectory(EbicsUser user); 67 | 68 | /** 69 | * Returns the object serialization directory. 70 | * @return the object serialization directory. 71 | */ 72 | File getSerializationDirectory(); 73 | 74 | /** 75 | * Returns the SSL trusted store directory. 76 | * @return the SSL trusted store directory. 77 | */ 78 | File getSSLTrustedStoreDirectory(); 79 | 80 | /** 81 | * Return the SSL key store directory 82 | * @return the SSL key store directory 83 | */ 84 | File getSSLKeyStoreDirectory(); 85 | 86 | /** 87 | * Returns the SSL bank server certificates. 88 | * @return the SSL bank server certificates. 89 | */ 90 | File getSSLBankCertificates(); 91 | 92 | /** 93 | * Returns the users directory. 94 | * @return the users directory. 95 | */ 96 | File getUsersDirectory(); 97 | 98 | /** 99 | * Returns the Ebics client serialization manager. 100 | * @return the Ebics client serialization manager. 101 | */ 102 | SerializationManager getSerializationManager(); 103 | 104 | /** 105 | * Returns the Ebics client trace manager. 106 | * @return the Ebics client trace manager. 107 | */ 108 | TraceManager getTraceManager(); 109 | 110 | /** 111 | * Returns the letter manager. 112 | * @return the letter manager. 113 | */ 114 | LetterManager getLetterManager(); 115 | 116 | /** 117 | * Returns the initializations letters directory. 118 | * @return the initializations letters directory. 119 | */ 120 | File getLettersDirectory(EbicsUser user); 121 | 122 | /** 123 | * Returns the users directory. 124 | * @return the users directory. 125 | */ 126 | File getUserDirectory(EbicsUser user); 127 | 128 | /** 129 | * Configuration initialization. 130 | * Creates the necessary directories for the ebics configuration. 131 | */ 132 | void init(); 133 | 134 | /** 135 | * Returns the application locale. 136 | * @return the application locale. 137 | */ 138 | Locale getLocale(); 139 | 140 | /** 141 | * Returns the client application signature version 142 | * @return the signature version 143 | */ 144 | String getSignatureVersion(); 145 | 146 | /** 147 | * Returns the client application authentication version 148 | * @return the authentication version 149 | */ 150 | String getAuthenticationVersion(); 151 | 152 | /** 153 | * Returns the client application encryption version 154 | * @return the encryption version 155 | */ 156 | String getEncryptionVersion(); 157 | 158 | /** 159 | * Tells if the client application should keep XML transfer 160 | * files in the transfer log directory 161 | * @return True if the client application should not delete 162 | * the XML transfer files 163 | */ 164 | boolean isTraceEnabled(); 165 | 166 | /** 167 | * Returns if the files to be transferred should be 168 | * compressed or sent without compression. This can 169 | * affect the time of data upload especially for big 170 | * files 171 | * 172 | * @return true if the file compression is enabled 173 | */ 174 | boolean isCompressionEnabled(); 175 | 176 | /** 177 | * Returns the default revision of sent XML. 178 | * @return the default revision of sent XML. 179 | */ 180 | int getRevision(); 181 | 182 | /** 183 | * Returns the version of the EBICS protocol used by the client. 184 | * @return the version of the EBICS protocol. 185 | */ 186 | String getVersion(); 187 | } 188 | -------------------------------------------------------------------------------- /src/main/java/org/kopi/ebics/interfaces/EbicsUser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1990-2012 kopiLeft Development SARL, Bizerte, Tunisia 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License version 2.1 as published by the Free Software Foundation. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | * 17 | */ 18 | 19 | package org.kopi.ebics.interfaces; 20 | 21 | import java.io.IOException; 22 | import java.security.GeneralSecurityException; 23 | import java.security.PrivateKey; 24 | import java.security.cert.X509Certificate; 25 | import java.security.interfaces.RSAPublicKey; 26 | 27 | import org.kopi.ebics.exception.EbicsException; 28 | 29 | 30 | /** 31 | * Things an EBICS user must be able to perform. 32 | * 33 | * 34 | */ 35 | public interface EbicsUser { 36 | 37 | /** 38 | * Returns the public part of the signature key. 39 | * @return the public part of the signature key. 40 | */ 41 | RSAPublicKey getA005PublicKey(); 42 | 43 | /** 44 | * Returns the public part of the encryption key. 45 | * @return the public part of the encryption key. 46 | */ 47 | RSAPublicKey getE002PublicKey(); 48 | 49 | /** 50 | * Return the public part of the transport authentication key. 51 | * @return the public part of the transport authentication key. 52 | */ 53 | RSAPublicKey getX002PublicKey(); 54 | 55 | /** 56 | * Returns the signature certificate. 57 | * @return the encryption certificate. 58 | * @throws EbicsException 59 | */ 60 | byte[] getA005Certificate() throws EbicsException; 61 | 62 | /** 63 | * Returns the authentication certificate. 64 | * @return the encryption certificate. 65 | * @throws EbicsException 66 | */ 67 | byte[] getX002Certificate() throws EbicsException; 68 | 69 | /** 70 | * Returns the encryption certificate. 71 | * @return the encryption certificate. 72 | * @throws EbicsException 73 | */ 74 | byte[] getE002Certificate() throws EbicsException; 75 | 76 | /** 77 | * Sets the signature certificate. 78 | * @param a005certificate the signature certificate. 79 | */ 80 | void setA005Certificate(X509Certificate a005certificate); 81 | 82 | /** 83 | * Sets the authentication certificate. 84 | * @param x002certificate the authentication certificate. 85 | */ 86 | void setX002Certificate(X509Certificate x002certificate); 87 | 88 | /** 89 | * Sets the encryption certificate. 90 | * @param e002certificate the encryption certificate. 91 | */ 92 | void setE002Certificate(X509Certificate e002certificate); 93 | 94 | /** 95 | * Sets the signature private key 96 | * @param a005Key the signature private key 97 | */ 98 | void setA005PrivateKey(PrivateKey a005Key); 99 | 100 | /** 101 | * Sets the authentication private key 102 | * @param x002Key the authentication private key 103 | */ 104 | void setX002PrivateKey(PrivateKey x002Key); 105 | 106 | /** 107 | * Sets the encryption private key 108 | * @param e002Key the encryption private key 109 | */ 110 | void setE002PrivateKey(PrivateKey e002Key); 111 | 112 | /** 113 | * Returns the type to security medium used to store the A005 key. 114 | * @return the type to security medium used to store the A005 key. 115 | */ 116 | String getSecurityMedium(); 117 | 118 | /** 119 | * Returns the customer in whose name we operate. 120 | * @return the customer in whose name we operate. 121 | */ 122 | EbicsPartner getPartner(); 123 | 124 | /** 125 | * Returns the (bank provided) user id. 126 | * @return the (bank provided) user id. 127 | */ 128 | String getUserId(); 129 | 130 | /** 131 | * Returns the user name. 132 | * @return the user name. 133 | */ 134 | String getName(); 135 | 136 | /** 137 | * Returns the distinguished name 138 | * @return the distinguished name 139 | */ 140 | String getDN(); 141 | 142 | /** 143 | * Returns the password callback handler for the current user. 144 | * @return the password callback handler. 145 | */ 146 | PasswordCallback getPasswordCallback(); 147 | 148 | /** 149 | * Signs the given digest with the private X002 key. 150 | * @param digest the given digest 151 | * @return the signature. 152 | * @throws GeneralSecurityException 153 | */ 154 | byte[] authenticate(byte[] digest) throws GeneralSecurityException; 155 | 156 | /** 157 | * Signs the given digest with the private A005 key. 158 | * @param digest 159 | * @return the signature 160 | * @throws IOException 161 | * @throws GeneralSecurityException 162 | */ 163 | byte[] sign(byte[] digest) throws IOException, GeneralSecurityException; 164 | 165 | /** 166 | * Uses the E001 key to decrypt the given secret key. 167 | * @param encryptedKey the given secret key 168 | * @param transactionKey a given transaction key 169 | * @return the decrypted key; 170 | * @throws GeneralSecurityException 171 | * @throws IOException 172 | * @throws EbicsException 173 | */ 174 | byte[] decrypt(byte[] encryptedKey, byte[] transactionKey) 175 | throws GeneralSecurityException, IOException, EbicsException; 176 | } 177 | --------------------------------------------------------------------------------