diff options
31 files changed, 253 insertions, 712 deletions
@@ -1,43 +1 @@ -.gradle -build/ -!gradle/wrapper/gradle-wrapper.jar -!**/src/main/**/build/ -!**/src/test/**/build/ -.kotlin - -### IntelliJ IDEA ### -.idea/modules.xml -.idea/jarRepositories.xml -.idea/compiler.xml -.idea/libraries/ -*.iws -*.iml -*.ipr -out/ -!**/src/main/**/out/ -!**/src/test/**/out/ - -### Eclipse ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache -bin/ -!**/src/main/**/bin/ -!**/src/test/**/bin/ - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ - -### VS Code ### -.vscode/ - -### Mac OS ### -.DS_Store
\ No newline at end of file +certs diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 26d3352..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml diff --git a/.idea/dictionaries/project.xml b/.idea/dictionaries/project.xml deleted file mode 100644 index 8a4f4e7..0000000 --- a/.idea/dictionaries/project.xml +++ /dev/null @@ -1,7 +0,0 @@ -<component name="ProjectDictionaryState"> - <dictionary name="project"> - <words> - <w>ebics</w> - </words> - </dictionary> -</component>
\ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml deleted file mode 100644 index 05eca02..0000000 --- a/.idea/gradle.xml +++ /dev/null @@ -1,17 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project version="4"> - <component name="GradleMigrationSettings" migrationVersion="1" /> - <component name="GradleSettings"> - <option name="linkedExternalProjectsSettings"> - <GradleProjectSettings> - <option name="externalProjectPath" value="$PROJECT_DIR$" /> - <option name="gradleJvm" value="21" /> - <option name="modules"> - <set> - <option value="$PROJECT_DIR$" /> - </set> - </option> - </GradleProjectSettings> - </option> - </component> -</project>
\ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index bdbcd2a..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,7 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project version="4"> - <component name="ExternalStorageConfigurationManager" enabled="true" /> - <component name="ProjectRootManager" version="2" languageLevel="JDK_21" project-jdk-name="homebrew-25" project-jdk-type="JavaSDK"> - <output url="file://$PROJECT_DIR$/out" /> - </component> -</project>
\ No newline at end of file diff --git a/src/main/resources/schemas/h005/ebics_H005.xsd b/assets/schemas/h005/ebics_H005.xsd index 149bf26..149bf26 100755 --- a/src/main/resources/schemas/h005/ebics_H005.xsd +++ b/assets/schemas/h005/ebics_H005.xsd diff --git a/src/main/resources/schemas/h005/ebics_hev.xsd b/assets/schemas/h005/ebics_hev.xsd index 8ee8458..8ee8458 100755 --- a/src/main/resources/schemas/h005/ebics_hev.xsd +++ b/assets/schemas/h005/ebics_hev.xsd diff --git a/src/main/resources/schemas/h005/ebics_keymgmt_request_H005.xsd b/assets/schemas/h005/ebics_keymgmt_request_H005.xsd index cb93d3c..cb93d3c 100755 --- a/src/main/resources/schemas/h005/ebics_keymgmt_request_H005.xsd +++ b/assets/schemas/h005/ebics_keymgmt_request_H005.xsd diff --git a/src/main/resources/schemas/h005/ebics_keymgmt_response_H005.xsd b/assets/schemas/h005/ebics_keymgmt_response_H005.xsd index dfc3390..dfc3390 100755 --- a/src/main/resources/schemas/h005/ebics_keymgmt_response_H005.xsd +++ b/assets/schemas/h005/ebics_keymgmt_response_H005.xsd diff --git a/src/main/resources/schemas/h005/ebics_orders_H005.xsd b/assets/schemas/h005/ebics_orders_H005.xsd index 30db121..30db121 100755 --- a/src/main/resources/schemas/h005/ebics_orders_H005.xsd +++ b/assets/schemas/h005/ebics_orders_H005.xsd diff --git a/src/main/resources/schemas/h005/ebics_request_H005.xsd b/assets/schemas/h005/ebics_request_H005.xsd index dc7ad70..dc7ad70 100755 --- a/src/main/resources/schemas/h005/ebics_request_H005.xsd +++ b/assets/schemas/h005/ebics_request_H005.xsd diff --git a/src/main/resources/schemas/h005/ebics_response_H005.xsd b/assets/schemas/h005/ebics_response_H005.xsd index 841286b..841286b 100755 --- a/src/main/resources/schemas/h005/ebics_response_H005.xsd +++ b/assets/schemas/h005/ebics_response_H005.xsd diff --git a/src/main/resources/schemas/h005/ebics_signature_S002.xsd b/assets/schemas/h005/ebics_signature_S002.xsd index 3127faa..3127faa 100755 --- a/src/main/resources/schemas/h005/ebics_signature_S002.xsd +++ b/assets/schemas/h005/ebics_signature_S002.xsd diff --git a/src/main/resources/schemas/h005/ebics_types_H005.xsd b/assets/schemas/h005/ebics_types_H005.xsd index ea13f06..ea13f06 100755 --- a/src/main/resources/schemas/h005/ebics_types_H005.xsd +++ b/assets/schemas/h005/ebics_types_H005.xsd diff --git a/src/main/resources/schemas/h005/xmldsig-core-schema.xsd b/assets/schemas/h005/xmldsig-core-schema.xsd index 1698c2f..1698c2f 100755 --- a/src/main/resources/schemas/h005/xmldsig-core-schema.xsd +++ b/assets/schemas/h005/xmldsig-core-schema.xsd diff --git a/build.gradle.kts b/build.gradle.kts deleted file mode 100644 index 6288bbc..0000000 --- a/build.gradle.kts +++ /dev/null @@ -1,26 +0,0 @@ -plugins { - id("java") -} - -group = "ruhr.scholz" -version = "1.0-SNAPSHOT" - -repositories { - mavenCentral() -} - -dependencies { - testImplementation(platform("org.junit:junit-bom:5.10.0")) - testImplementation("org.junit.jupiter:junit-jupiter") - testRuntimeOnly("org.junit.platform:junit-platform-launcher") - // Source: https://mvnrepository.com/artifact/org.bouncycastle/bcprov-jdk18on - implementation("org.bouncycastle:bcprov-jdk18on:1.83") - // Source: https://mvnrepository.com/artifact/org.bouncycastle/bcpkix-jdk18on - implementation("org.bouncycastle:bcpkix-jdk18on:1.83") - // Source: https://mvnrepository.com/artifact/jakarta.xml.bind/jakarta.xml.bind-api - implementation("jakarta.xml.bind:jakarta.xml.bind-api:4.0.5") -} - -tasks.test { - useJUnitPlatform() -}
\ No newline at end of file diff --git a/certificate.go b/certificate.go new file mode 100644 index 0000000..72a823a --- /dev/null +++ b/certificate.go @@ -0,0 +1,155 @@ +package main + +import ( + "crypto/rand" + "crypto/rsa" + "crypto/sha1" + "crypto/x509" + "crypto/x509/pkix" + "encoding/pem" + "fmt" + "os" + "time" +) + +type EbicsCertificateType int + +const ( + A005 EbicsCertificateType = iota + A006 + X002 + E002 +) + +type EbicsCertificate struct { + x509Certificate []byte + ebicsCertificateType EbicsCertificateType +} + +func GenerateSelfSignedCertificate(ebicsCertificateType EbicsCertificateType, privateKey rsa.PrivateKey) (*EbicsCertificate, error) { + var keyUsage x509.KeyUsage + + switch ebicsCertificateType { + case X002: + keyUsage = x509.KeyUsageDigitalSignature + case E002: + keyUsage = x509.KeyUsageKeyEncipherment + case A005, A006: + keyUsage = x509.KeyUsageContentCommitment + default: + return nil, fmt.Errorf("certificate type not implemented") + } + + template := x509.Certificate{ + Subject: pkix.Name{ + CommonName: "SCHOLZ01", + }, + NotBefore: time.Now(), + NotAfter: time.Date(9999, 12, 31, 23, 59, 59, 0, time.UTC), + KeyUsage: keyUsage, + } + + x509Certificate, err := x509.CreateCertificate(rand.Reader, &template, &template, &privateKey.PublicKey, &privateKey) + if err != nil { + return nil, err + } + + return &EbicsCertificate{ + x509Certificate: x509Certificate, + ebicsCertificateType: ebicsCertificateType, + }, nil +} + +func GetCertificateFingerprintAsString(ebicsCertificate *EbicsCertificate) string { + return fmt.Sprintf("% x", sha1.Sum(ebicsCertificate.x509Certificate)) +} + +func WriteCertificateToFile(ebicsCertificate *EbicsCertificate, path string) error { + f, err := os.Create(path) + if err != nil { + return err + } + defer f.Close() + + return pem.Encode(f, &pem.Block{ + Type: "CERTIFICATE", + Bytes: ebicsCertificate.x509Certificate, + }) +} + +func ReadCertificateFromFile(path string, ebicsCertificateType EbicsCertificateType) (*EbicsCertificate, error) { + data, err := os.ReadFile(path) + if err != nil { + return nil, err + } + + block, _ := pem.Decode(data) + if block == nil { + return nil, fmt.Errorf("no PEM data found") + } + if block.Type != "CERTIFICATE" { + return nil, fmt.Errorf("unexpected PEM type: %s", block.Type) + } + + cert, err := x509.ParseCertificate(block.Bytes) + if err != nil { + return nil, err + } + + var keyUsage x509.KeyUsage + switch ebicsCertificateType { + case X002: + keyUsage = x509.KeyUsageDigitalSignature + case E002: + keyUsage = x509.KeyUsageKeyEncipherment + case A005, A006: + keyUsage = x509.KeyUsageContentCommitment + } + + if cert.KeyUsage != keyUsage { + return nil, fmt.Errorf("expected KeyUsage %s does not match KeyUsage in loaded Certificate (%s)", keyUsage, cert.KeyUsage) + } + + return &EbicsCertificate{ + x509Certificate: cert.Raw, + ebicsCertificateType: ebicsCertificateType, + }, nil +} + +func WriteKeypairToFile(privateKey *rsa.PrivateKey, path string) error { + f, err := os.Create(path) + if err != nil { + return err + } + defer f.Close() + + der, err := x509.MarshalPKCS8PrivateKey(privateKey) + + return pem.Encode(f, &pem.Block{ + Type: "PRIVATE KEY", + Bytes: der, + }) +} + +func ReadKeypairFromFile(path string) (*rsa.PrivateKey, error) { + data, err := os.ReadFile(path) + if err != nil { + return nil, err + } + + block, _ := pem.Decode(data) + if block == nil { + return nil, fmt.Errorf("no PEM data found") + } + if block.Type != "PRIVATE KEY" { + return nil, fmt.Errorf("unexpected PEM type: %s", block.Type) + } + + privateKey, err := x509.ParsePKCS8PrivateKey(block.Bytes) + switch privateKey := privateKey.(type) { + case *rsa.PrivateKey: + return privateKey, nil + default: + return nil, fmt.Errorf("private key type not supported") + } +} diff --git a/certificate_test.go b/certificate_test.go new file mode 100644 index 0000000..3c9dcc5 --- /dev/null +++ b/certificate_test.go @@ -0,0 +1,94 @@ +package main + +import ( + "bytes" + "crypto/rand" + "crypto/rsa" + "path/filepath" + "testing" +) + +func TestGenerateRsaKeypair(t *testing.T) { + privateKey, err := rsa.GenerateKey(rand.Reader, 4096) + if err != nil { + t.Error(err.Error()) + } + + err = WriteKeypairToFile(privateKey, filepath.Join("certs", "key.pem")) + if err != nil { + t.Error(err.Error()) + } + + loadedPrivateKey, err := ReadKeypairFromFile(filepath.Join("certs", "key.pem")) + if err != nil { + t.Error(err.Error()) + } + + if !privateKey.Equal(loadedPrivateKey) { + t.Error("saved and loaded private keys differ") + } +} + +func TestGenerateSelfSignedCertificate(t *testing.T) { + privateKey, err := rsa.GenerateKey(rand.Reader, 4096) + if err != nil { + t.Error(err.Error()) + } + + certificate, err := GenerateSelfSignedCertificate(X002, *privateKey) + if err != nil { + t.Error(err.Error()) + } + err = WriteCertificateToFile(certificate, filepath.Join("certs", "cert.pem")) + if err != nil { + t.Error(err.Error()) + } + + t.Logf("Saved certificate has following fingerprints: %s", GetCertificateFingerprintAsString(certificate)) + + loadedCertificate, err := ReadCertificateFromFile(filepath.Join("certs", "cert.pem"), X002) + if err != nil { + t.Error(err.Error()) + } + + t.Logf("Loaded certificate has following fingerprints: %s", GetCertificateFingerprintAsString(loadedCertificate)) + + if !bytes.Equal(certificate.x509Certificate, loadedCertificate.x509Certificate) { + t.Error("saved and loaded certificates differ") + } +} + +// also generates keys +func TestGenerateSelfSignedCertificateTriplet(t *testing.T) { + var filenamePrefix string + for _, ebicsCertificateType := range []EbicsCertificateType{A005, X002, E002} { + switch ebicsCertificateType { + case X002: + filenamePrefix = "authentication" + case E002: + filenamePrefix = "encryption" + case A005, A006: + filenamePrefix = "signature" + } + + privateKey, err := rsa.GenerateKey(rand.Reader, 4096) + if err != nil { + t.Error(err.Error()) + } + + err = WriteKeypairToFile(privateKey, filepath.Join("certs", filenamePrefix+"_key.pem")) + if err != nil { + t.Error(err.Error()) + } + + certificate, err := GenerateSelfSignedCertificate(ebicsCertificateType, *privateKey) + if err != nil { + t.Error(err.Error()) + } + + err = WriteCertificateToFile(certificate, filepath.Join("certs", filenamePrefix+"_cert.pem")) + if err != nil { + t.Error(err.Error()) + } + } +} @@ -0,0 +1,3 @@ +module go.scholz.ruhr/libebics + +go 1.26.2 diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar Binary files differdeleted file mode 100644 index 249e583..0000000 --- a/gradle/wrapper/gradle-wrapper.jar +++ /dev/null diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties deleted file mode 100644 index dddb17a..0000000 --- a/gradle/wrapper/gradle-wrapper.properties +++ /dev/null @@ -1,6 +0,0 @@ -#Mon Apr 13 13:47:32 CEST 2026 -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-bin.zip -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew deleted file mode 100755 index 1b6c787..0000000 --- a/gradlew +++ /dev/null @@ -1,234 +0,0 @@ -#!/bin/sh - -# -# Copyright © 2015-2021 the original authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -############################################################################## -# -# Gradle start up script for POSIX generated by Gradle. -# -# Important for running: -# -# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is -# noncompliant, but you have some other compliant shell such as ksh or -# bash, then to run this script, type that shell name before the whole -# command line, like: -# -# ksh Gradle -# -# Busybox and similar reduced shells will NOT work, because this script -# requires all of these POSIX shell features: -# * functions; -# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», -# «${var#prefix}», «${var%suffix}», and «$( cmd )»; -# * compound commands having a testable exit status, especially «case»; -# * various built-in commands including «command», «set», and «ulimit». -# -# Important for patching: -# -# (2) This script targets any POSIX shell, so it avoids extensions provided -# by Bash, Ksh, etc; in particular arrays are avoided. -# -# The "traditional" practice of packing multiple parameters into a -# space-separated string is a well documented source of bugs and security -# problems, so this is (mostly) avoided, by progressively accumulating -# options in "$@", and eventually passing that to Java. -# -# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, -# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; -# see the in-line comments for details. -# -# There are tweaks for specific operating systems such as AIX, CygWin, -# Darwin, MinGW, and NonStop. -# -# (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt -# within the Gradle project. -# -# You can find Gradle at https://github.com/gradle/gradle/. -# -############################################################################## - -# Attempt to set APP_HOME - -# Resolve links: $0 may be a link -app_path=$0 - -# Need this for daisy-chained symlinks. -while - APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path - [ -h "$app_path" ] -do - ls=$( ls -ld "$app_path" ) - link=${ls#*' -> '} - case $link in #( - /*) app_path=$link ;; #( - *) app_path=$APP_HOME$link ;; - esac -done - -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit - -APP_NAME="Gradle" -APP_BASE_NAME=${0##*/} - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' - -# Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD=maximum - -warn () { - echo "$*" -} >&2 - -die () { - echo - echo "$*" - echo - exit 1 -} >&2 - -# OS specific support (must be 'true' or 'false'). -cygwin=false -msys=false -darwin=false -nonstop=false -case "$( uname )" in #( - CYGWIN* ) cygwin=true ;; #( - Darwin* ) darwin=true ;; #( - MSYS* | MINGW* ) msys=true ;; #( - NONSTOP* ) nonstop=true ;; -esac - -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar - - -# Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD=$JAVA_HOME/jre/sh/java - else - JAVACMD=$JAVA_HOME/bin/java - fi - if [ ! -x "$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." - fi -else - JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." -fi - -# Increase the maximum file descriptors if we can. -if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then - case $MAX_FD in #( - max*) - MAX_FD=$( ulimit -H -n ) || - warn "Could not query maximum file descriptor limit" - esac - case $MAX_FD in #( - '' | soft) :;; #( - *) - ulimit -n "$MAX_FD" || - warn "Could not set maximum file descriptor limit to $MAX_FD" - esac -fi - -# Collect all arguments for the java command, stacking in reverse order: -# * args from the command line -# * the main class name -# * -classpath -# * -D...appname settings -# * --module-path (only if needed) -# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. - -# For Cygwin or MSYS, switch paths to Windows format before running java -if "$cygwin" || "$msys" ; then - APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) - CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) - - JAVACMD=$( cygpath --unix "$JAVACMD" ) - - # Now convert the arguments - kludge to limit ourselves to /bin/sh - for arg do - if - case $arg in #( - -*) false ;; # don't mess with options #( - /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath - [ -e "$t" ] ;; #( - *) false ;; - esac - then - arg=$( cygpath --path --ignore --mixed "$arg" ) - fi - # Roll the args list around exactly as many times as the number of - # args, so each arg winds up back in the position where it started, but - # possibly modified. - # - # NB: a `for` loop captures its iteration list before it begins, so - # changing the positional parameters here affects neither the number of - # iterations, nor the values presented in `arg`. - shift # remove old arg - set -- "$@" "$arg" # push replacement arg - done -fi - -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. - -set -- \ - "-Dorg.gradle.appname=$APP_BASE_NAME" \ - -classpath "$CLASSPATH" \ - org.gradle.wrapper.GradleWrapperMain \ - "$@" - -# Use "xargs" to parse quoted args. -# -# With -n1 it outputs one arg per line, with the quotes and backslashes removed. -# -# In Bash we could simply go: -# -# readarray ARGS < <( xargs -n1 <<<"$var" ) && -# set -- "${ARGS[@]}" "$@" -# -# but POSIX shell has neither arrays nor command substitution, so instead we -# post-process each arg (as a line of input to sed) to backslash-escape any -# character that might be a shell metacharacter, then use eval to reverse -# that process (while maintaining the separation between arguments), and wrap -# the whole thing up as a single "set" statement. -# -# This will of course break if any of these variables contains a newline or -# an unmatched quote. -# - -eval "set -- $( - printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | - xargs -n1 | - sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | - tr '\n' ' ' - )" '"$@"' - -exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat deleted file mode 100644 index ac1b06f..0000000 --- a/gradlew.bat +++ /dev/null @@ -1,89 +0,0 @@ -@rem
-@rem Copyright 2015 the original author or authors.
-@rem
-@rem Licensed under the Apache License, Version 2.0 (the "License");
-@rem you may not use this file except in compliance with the License.
-@rem You may obtain a copy of the License at
-@rem
-@rem https://www.apache.org/licenses/LICENSE-2.0
-@rem
-@rem Unless required by applicable law or agreed to in writing, software
-@rem distributed under the License is distributed on an "AS IS" BASIS,
-@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-@rem See the License for the specific language governing permissions and
-@rem limitations under the License.
-@rem
-
-@if "%DEBUG%" == "" @echo off
-@rem ##########################################################################
-@rem
-@rem Gradle startup script for Windows
-@rem
-@rem ##########################################################################
-
-@rem Set local scope for the variables with windows NT shell
-if "%OS%"=="Windows_NT" setlocal
-
-set DIRNAME=%~dp0
-if "%DIRNAME%" == "" set DIRNAME=.
-set APP_BASE_NAME=%~n0
-set APP_HOME=%DIRNAME%
-
-@rem Resolve any "." and ".." in APP_HOME to make it shorter.
-for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
-
-@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
-set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
-
-@rem Find java.exe
-if defined JAVA_HOME goto findJavaFromJavaHome
-
-set JAVA_EXE=java.exe
-%JAVA_EXE% -version >NUL 2>&1
-if "%ERRORLEVEL%" == "0" goto execute
-
-echo.
-echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
-echo.
-echo Please set the JAVA_HOME variable in your environment to match the
-echo location of your Java installation.
-
-goto fail
-
-:findJavaFromJavaHome
-set JAVA_HOME=%JAVA_HOME:"=%
-set JAVA_EXE=%JAVA_HOME%/bin/java.exe
-
-if exist "%JAVA_EXE%" goto execute
-
-echo.
-echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
-echo.
-echo Please set the JAVA_HOME variable in your environment to match the
-echo location of your Java installation.
-
-goto fail
-
-:execute
-@rem Setup the command line
-
-set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
-
-
-@rem Execute Gradle
-"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
-
-:end
-@rem End local scope for the variables with windows NT shell
-if "%ERRORLEVEL%"=="0" goto mainEnd
-
-:fail
-rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
-rem the _cmd.exe /c_ return code!
-if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
-exit /b 1
-
-:mainEnd
-if "%OS%"=="Windows_NT" endlocal
-
-:omega
diff --git a/settings.gradle.kts b/settings.gradle.kts deleted file mode 100644 index c622116..0000000 --- a/settings.gradle.kts +++ /dev/null @@ -1 +0,0 @@ -rootProject.name = "libebics"
\ No newline at end of file diff --git a/src/main/java/ruhr/scholz/libebics/security/AuthenticationCertificate.java b/src/main/java/ruhr/scholz/libebics/security/AuthenticationCertificate.java deleted file mode 100644 index 6154c40..0000000 --- a/src/main/java/ruhr/scholz/libebics/security/AuthenticationCertificate.java +++ /dev/null @@ -1,57 +0,0 @@ -package ruhr.scholz.libebics.security; - -import org.bouncycastle.asn1.x500.X500Name; -import org.bouncycastle.asn1.x509.Extension; -import org.bouncycastle.asn1.x509.KeyUsage; -import org.bouncycastle.cert.X509CertificateHolder; -import org.bouncycastle.cert.X509v3CertificateBuilder; -import org.bouncycastle.crypto.AsymmetricCipherKeyPair; -import org.bouncycastle.crypto.util.SubjectPublicKeyInfoFactory; -import org.bouncycastle.operator.ContentSigner; -import org.bouncycastle.operator.DefaultDigestAlgorithmIdentifierFinder; -import org.bouncycastle.operator.DefaultSignatureAlgorithmIdentifierFinder; -import org.bouncycastle.operator.OperatorCreationException; -import org.bouncycastle.operator.bc.BcRSAContentSignerBuilder; - -import java.io.IOException; -import java.math.BigInteger; -import java.security.SecureRandom; -import java.util.Calendar; -import java.util.Date; -import java.util.GregorianCalendar; - -public class AuthenticationCertificate extends EbicsCertificate{ - public enum AuthenticationCertificateType implements EbicsCertificateType { - X002 - } - - public AuthenticationCertificate(AuthenticationCertificateType authenticationCertificateType){ - this.certificateType = authenticationCertificateType; - this.keyPair = generateKeyPair(4096); - this.certificate = generateAuthenticationCertificate(this.keyPair); - } - - private static X509CertificateHolder generateAuthenticationCertificate(AsymmetricCipherKeyPair asymmetricCipherKeyPair){ - GregorianCalendar endCal = new GregorianCalendar(); - endCal.set(9999, Calendar.FEBRUARY, 31, 59, 59, 59); - try { - X509v3CertificateBuilder x509v3CertificateBuilder = new X509v3CertificateBuilder( - new X500Name("CN=SCHOLZ01"), - new BigInteger(160, new SecureRandom()), - new Date(), - endCal.getTime(), - new X500Name("CN=SCHOLZ01"), - SubjectPublicKeyInfoFactory.createSubjectPublicKeyInfo(asymmetricCipherKeyPair.getPublic()) - ); - x509v3CertificateBuilder.addExtension(Extension.keyUsage, true, new KeyUsage(KeyUsage.digitalSignature)); - - ContentSigner contentSigner = new BcRSAContentSignerBuilder( - new DefaultSignatureAlgorithmIdentifierFinder().find("SHA256withRSA"), - new DefaultDigestAlgorithmIdentifierFinder().find("SHA-256") - ).build(asymmetricCipherKeyPair.getPrivate()); - return x509v3CertificateBuilder.build(contentSigner); - } catch (IOException | OperatorCreationException e) { - throw new RuntimeException(e); - } - } -} diff --git a/src/main/java/ruhr/scholz/libebics/security/EbicsCertificate.java b/src/main/java/ruhr/scholz/libebics/security/EbicsCertificate.java deleted file mode 100644 index 375cc0b..0000000 --- a/src/main/java/ruhr/scholz/libebics/security/EbicsCertificate.java +++ /dev/null @@ -1,57 +0,0 @@ -package ruhr.scholz.libebics.security; - -import org.bouncycastle.cert.X509CertificateHolder; -import org.bouncycastle.crypto.AsymmetricCipherKeyPair; -import org.bouncycastle.crypto.digests.SHA256Digest; -import org.bouncycastle.crypto.generators.RSAKeyPairGenerator; -import org.bouncycastle.crypto.params.RSAKeyGenerationParameters; -import org.bouncycastle.util.encoders.Hex; - -import java.io.IOException; -import java.math.BigInteger; -import java.security.SecureRandom; - -public abstract class EbicsCertificate { - X509CertificateHolder certificate; - EbicsCertificateType certificateType; - AsymmetricCipherKeyPair keyPair; - - static AsymmetricCipherKeyPair generateKeyPair(int keySize) { - RSAKeyPairGenerator rsaKeyPairGenerator = new RSAKeyPairGenerator(); - RSAKeyGenerationParameters rsaKeyGenerationParameters = new RSAKeyGenerationParameters( - BigInteger.valueOf(65537), - new SecureRandom(), - keySize, - 80 - ); - rsaKeyPairGenerator.init(rsaKeyGenerationParameters); - return rsaKeyPairGenerator.generateKeyPair(); - } - - byte[] getFingerprint() { - SHA256Digest sha256Digest = new SHA256Digest(); - byte[] encodedCertificate = null; - try { - encodedCertificate = this.certificate.getEncoded(); - } catch (IOException e) { - throw new RuntimeException(e); - } - byte[] fingerprint = new byte[sha256Digest.getDigestSize()]; - - sha256Digest.update(encodedCertificate, 0, encodedCertificate.length); - sha256Digest.doFinal(fingerprint, 0); - - return fingerprint; - } - - String getFingerprintString(boolean prettyPrint) { - if(prettyPrint){ - return Hex.toHexString( - this.getFingerprint()) - .toUpperCase() - .replaceAll("(?<=..)(..)", ":$1"); - } else { - return Hex.toHexString(this.getFingerprint()); - } - } -} diff --git a/src/main/java/ruhr/scholz/libebics/security/EbicsCertificateType.java b/src/main/java/ruhr/scholz/libebics/security/EbicsCertificateType.java deleted file mode 100644 index 01ebe1d..0000000 --- a/src/main/java/ruhr/scholz/libebics/security/EbicsCertificateType.java +++ /dev/null @@ -1,5 +0,0 @@ -package ruhr.scholz.libebics.security; - -public interface EbicsCertificateType { - -} diff --git a/src/main/java/ruhr/scholz/libebics/security/EncryptionCertificate.java b/src/main/java/ruhr/scholz/libebics/security/EncryptionCertificate.java deleted file mode 100644 index db9965b..0000000 --- a/src/main/java/ruhr/scholz/libebics/security/EncryptionCertificate.java +++ /dev/null @@ -1,57 +0,0 @@ -package ruhr.scholz.libebics.security; - -import org.bouncycastle.asn1.x500.X500Name; -import org.bouncycastle.asn1.x509.Extension; -import org.bouncycastle.asn1.x509.KeyUsage; -import org.bouncycastle.cert.X509CertificateHolder; -import org.bouncycastle.cert.X509v3CertificateBuilder; -import org.bouncycastle.crypto.AsymmetricCipherKeyPair; -import org.bouncycastle.crypto.util.SubjectPublicKeyInfoFactory; -import org.bouncycastle.operator.ContentSigner; -import org.bouncycastle.operator.DefaultDigestAlgorithmIdentifierFinder; -import org.bouncycastle.operator.DefaultSignatureAlgorithmIdentifierFinder; -import org.bouncycastle.operator.OperatorCreationException; -import org.bouncycastle.operator.bc.BcRSAContentSignerBuilder; - -import java.io.IOException; -import java.math.BigInteger; -import java.security.SecureRandom; -import java.util.Calendar; -import java.util.Date; -import java.util.GregorianCalendar; - -public class EncryptionCertificate extends EbicsCertificate{ - public enum EncryptionCertificateType implements EbicsCertificateType { - E002 - } - - public EncryptionCertificate(EncryptionCertificateType encryptionCertificateType){ - this.certificateType = encryptionCertificateType; - this.keyPair = generateKeyPair(4096); - this.certificate = generateEncryptionCertificate(this.keyPair); - } - - private static X509CertificateHolder generateEncryptionCertificate(AsymmetricCipherKeyPair asymmetricCipherKeyPair){ - GregorianCalendar endCal = new GregorianCalendar(); - endCal.set(9999, Calendar.FEBRUARY, 31, 59, 59, 59); - try { - X509v3CertificateBuilder x509v3CertificateBuilder = new X509v3CertificateBuilder( - new X500Name("CN=SCHOLZ01"), - new BigInteger(160, new SecureRandom()), - new Date(), - endCal.getTime(), - new X500Name("CN=SCHOLZ01"), - SubjectPublicKeyInfoFactory.createSubjectPublicKeyInfo(asymmetricCipherKeyPair.getPublic()) - ); - x509v3CertificateBuilder.addExtension(Extension.keyUsage, true, new KeyUsage(KeyUsage.keyEncipherment)); - - ContentSigner contentSigner = new BcRSAContentSignerBuilder( - new DefaultSignatureAlgorithmIdentifierFinder().find("SHA256withRSA"), - new DefaultDigestAlgorithmIdentifierFinder().find("SHA-256") - ).build(asymmetricCipherKeyPair.getPrivate()); - return x509v3CertificateBuilder.build(contentSigner); - } catch (IOException | OperatorCreationException e) { - throw new RuntimeException(e); - } - } -} diff --git a/src/main/java/ruhr/scholz/libebics/security/SignatureCertificate.java b/src/main/java/ruhr/scholz/libebics/security/SignatureCertificate.java deleted file mode 100644 index 529651e..0000000 --- a/src/main/java/ruhr/scholz/libebics/security/SignatureCertificate.java +++ /dev/null @@ -1,58 +0,0 @@ -package ruhr.scholz.libebics.security; - -import org.bouncycastle.asn1.x500.X500Name; -import org.bouncycastle.asn1.x509.Extension; -import org.bouncycastle.asn1.x509.KeyUsage; -import org.bouncycastle.cert.X509CertificateHolder; -import org.bouncycastle.cert.X509v3CertificateBuilder; -import org.bouncycastle.crypto.AsymmetricCipherKeyPair; -import org.bouncycastle.crypto.util.SubjectPublicKeyInfoFactory; -import org.bouncycastle.operator.ContentSigner; -import org.bouncycastle.operator.DefaultDigestAlgorithmIdentifierFinder; -import org.bouncycastle.operator.DefaultSignatureAlgorithmIdentifierFinder; -import org.bouncycastle.operator.OperatorCreationException; -import org.bouncycastle.operator.bc.BcRSAContentSignerBuilder; - -import java.io.IOException; -import java.math.BigInteger; -import java.security.SecureRandom; -import java.util.Calendar; -import java.util.Date; -import java.util.GregorianCalendar; - -public class SignatureCertificate extends EbicsCertificate{ - public enum SignatureCertificateType implements EbicsCertificateType { - A005, - A006 - } - - public SignatureCertificate(SignatureCertificateType signatureCertificateType){ - this.certificateType = signatureCertificateType; - this.keyPair = generateKeyPair(4096); - this.certificate = generateSignatureCertificate(this.keyPair); - } - - public static X509CertificateHolder generateSignatureCertificate(AsymmetricCipherKeyPair asymmetricCipherKeyPair){ - GregorianCalendar endCal = new GregorianCalendar(); - endCal.set(9999, Calendar.FEBRUARY, 31, 59, 59, 59); - try { - X509v3CertificateBuilder x509v3CertificateBuilder = new X509v3CertificateBuilder( - new X500Name("CN=SCHOLZ01"), - new BigInteger(160, new SecureRandom()), - new Date(), - endCal.getTime(), - new X500Name("CN=SCHOLZ01"), - SubjectPublicKeyInfoFactory.createSubjectPublicKeyInfo(asymmetricCipherKeyPair.getPublic()) - ); - x509v3CertificateBuilder.addExtension(Extension.keyUsage, true, new KeyUsage(KeyUsage.nonRepudiation)); - - ContentSigner contentSigner = new BcRSAContentSignerBuilder( - new DefaultSignatureAlgorithmIdentifierFinder().find("SHA256withRSA"), - new DefaultDigestAlgorithmIdentifierFinder().find("SHA-256") - ).build(asymmetricCipherKeyPair.getPrivate()); - return x509v3CertificateBuilder.build(contentSigner); - } catch (IOException | OperatorCreationException e) { - throw new RuntimeException(e); - } - } -} diff --git a/src/main/java/ruhr/scholz/libebics/xmlmodel/h005/EbicsUnsecuredRequest.java b/src/main/java/ruhr/scholz/libebics/xmlmodel/h005/EbicsUnsecuredRequest.java deleted file mode 100644 index b26f526..0000000 --- a/src/main/java/ruhr/scholz/libebics/xmlmodel/h005/EbicsUnsecuredRequest.java +++ /dev/null @@ -1,13 +0,0 @@ -package ruhr.scholz.libebics.xmlmodel.h005; - -import jakarta.xml.bind.annotation.XmlAttribute; -import jakarta.xml.bind.annotation.XmlRootElement; - -@XmlRootElement(name = "ebicsUnsecuredRequest", namespace = "urn:org:ebics:H005") -public class EbicsUnsecuredRequest { - @XmlAttribute(name = "Version") - private String version; - - @XmlAttribute(name = "Revision") - private int revision; -} diff --git a/src/test/java/ruhr/scholz/libebics/security/KeyManagementTest.java b/src/test/java/ruhr/scholz/libebics/security/KeyManagementTest.java deleted file mode 100644 index 3ec6a48..0000000 --- a/src/test/java/ruhr/scholz/libebics/security/KeyManagementTest.java +++ /dev/null @@ -1,32 +0,0 @@ -package ruhr.scholz.libebics.security; - -import org.junit.jupiter.api.Test; - -public class KeyManagementTest { - @Test void generateAuthenticationCertificate(){ - new AuthenticationCertificate(AuthenticationCertificate.AuthenticationCertificateType.X002); - } - - @Test void generateSignatureCertificate(){ - new SignatureCertificate(SignatureCertificate.SignatureCertificateType.A005); - } - - @Test void generateEncryptionCertificate(){ - new EncryptionCertificate(EncryptionCertificate.EncryptionCertificateType.E002); - } - - @Test void printAuthenticationCertificateFingerprint(){ - AuthenticationCertificate authenticationCertificate = new AuthenticationCertificate(AuthenticationCertificate.AuthenticationCertificateType.X002); - System.out.println(authenticationCertificate.getFingerprintString(true)); - } - - @Test void printSignatureCertificateFingerprint(){ - SignatureCertificate signatureCertificate = new SignatureCertificate(SignatureCertificate.SignatureCertificateType.A005); - System.out.println(signatureCertificate.getFingerprintString(true)); - } - - @Test void printEncryptionCertificateFingerprint(){ - EncryptionCertificate encryptionCertificate = new EncryptionCertificate(EncryptionCertificate.EncryptionCertificateType.E002); - System.out.println(encryptionCertificate.getFingerprintString(true)); - } -} |
