require_relative 'java/engines/ecc_engine' require_relative 'java/engines/digest_engine' require_relative 'java/engines/x509_engine' require_relative 'java/engines/x509_csr_engine' require_relative 'java/engines/scrypt_engine' require_relative 'java/engines/secure_random_engine' require_relative 'java/engines/cipher_engine' require_relative 'java/engines/secret_key_engine' require_relative 'java/engines/hmac_engine' require_relative 'java/engines/hkdf_engine' require_relative 'java/engines/pbkdf2_engine' require_relative 'java/engines/argon2_engine' require_relative 'java/engines/bcrypt_engine' require_relative 'java/engines/ed25519_engine' require_relative 'java/engines/x25519_engine' require_relative 'java/utils/comparator' require_relative 'java/utils/memory_buffer' require_relative 'java/utils/native_helper' require_relative 'java/engines/asn1_engine' require_relative 'java/engines/compression_engine' require_relative 'java/engines/decompression_engine' require_relative 'java/engines/data_conversion_engine' require_relative 'java/engines/secret_sharing_engine' require_relative 'java/engines/pkcs7_engine' require_relative 'java/engines/rsa_engine' require_relative 'java/engines/crystal_kyber_engine' require_relative 'java/engines/crystal_dilithium_engine' require_relative 'java/keystore/keystore' require 'rbconfig' module Ccrypto module Java class Provider include TR::CondUtils def self.provider_name "Java-BC" #nm = [] #nm << "Java-BC : " #provider_info.each do |k,v| # nm << "#{k.to_s.capitalize} : #{v}" #end #nm.join("\n") end def self.provider_info info = {} info[:ruby_version] = RbConfig::CONFIG["ruby_version"] info[:host] = RbConfig::CONFIG["host"] info[:openssl_version] = OpenSSL::VERSION info[:bouncycastle_info] = JCEProvider::DEFProv.getInfo info end def self.supported_keypair_config(*args, &block) purpose = args.first case purpose when :signing, :sign, :identity [Ccrypto::ECCConfig, Ccrypto::RSAConfig, Ccrypto::ED25519Config, Ccrypto::CrystalDilithiumConfig] when :cipher, :encryption, :enc [Ccrypto::ECCConfig, Ccrypto::RSAConfig, Ccrypto::X25519Config, Ccrypto::CrystalKyberConfig] when :sign_and_encrypt, :sign_and_enc, :sign_and_cipher [Ccrypto::ECCConfig, Ccrypto::RSAConfig] else # all keypair config returned [Ccrypto::ECCConfig, Ccrypto::RSAConfig, Ccrypto::ED25519Config, Ccrypto::CrystalDilithiumConfig, Ccrypto::X25519Config, Ccrypto::CrystalKyberConfig] #raise KeypairEngineException, "Unknown key purpose '#{purpose}'. Supported including: :signing, :cipher or :sign_and_cipher" end end def self.supported_secret_key_config(&block) CipherEngine.supported_cipher_list end def self.load_keystore(*args, &block) Keystore.load_keystore(*args, &block) end def self.load_keystore_file(*args, &block) Keystore.load_keystore_file(*args, &block) end def self.convert_keystore(*args, &block) Keystore.convert_keystore(*args, &block) end def self.convert_keystore_file(*args, &block) Keystore.convert_keystore_file(*args, &block) end def self.load_x509(*args, &block) cert = args.first certType = args[1] || :der case certType when :b64, :base64 ccert = from_b64(cert) when :hex ccert = from_hex(cert) else # binary ccert = cert end X509Engine.bin_to_cert(ccert) end def self.algo_instance(*args, &block) config = args.first if config.is_a?(Class) or config.is_a?(Module) if config == Ccrypto::ECCConfig ECCEngine elsif config == Ccrypto::RSAConfig RSAEngine elsif config == Ccrypto::ECCKeyBundle ECCKeyBundle elsif config == Ccrypto::RSAKeyBundle RSAKeyBundle elsif config == Ccrypto::DigestConfig DigestEngine elsif config == Ccrypto::SecureRandomConfig SecureRandomEngine elsif config == Ccrypto::CipherConfig CipherEngine elsif config == Ccrypto::ECCPublicKey Ccrypto::Java::ECCPublicKey elsif config == Ccrypto::ECCPrivateKey Ccrypto::Java::ECCPrivateKey elsif config == Ccrypto::KeyConfig SecretKeyEngine elsif config == SecretSharingConfig SecretSharingEngine elsif config == ED25519Config ED25519Engine elsif config == X25519Config X25519Engine elsif config == Ccrypto::X25519KeyBundle X25519KeyBundle elsif config == Ccrypto::X509::CertProfile X509Engine elsif config == Ccrypto::HMACConfig HMACEngine elsif config == Ccrypto::PBKDF2Config PBKDF2Engine elsif config == Ccrypto::HKDFConfig HKDFEngine elsif config == Ccrypto::CrystalKyberConfig CrystalKyberEngine elsif config == Ccrypto::CrystalKyberPublicKey CrystalKyberPublicKey elsif config == Ccrypto::CrystalKyberPrivateKey CrystalKyberPrivateKey elsif config == Ccrypto::CrystalDilithiumConfig CrystalDilithiumEngine elsif config == Ccrypto::CrystalDilithiumPublicKey CrystalDilithiumPublicKey elsif config == Ccrypto::CrystalDilithiumPrivateKey CrystalDilithiumPrivateKey else raise CcryptoProviderException, "Config class '#{config}' is not supported for provider '#{self.provider_name}'" end else case config when Ccrypto::ECCConfig ECCEngine.new(*args, &block) when Ccrypto::RSAConfig RSAEngine.new(*args, &block) when Ccrypto::DigestConfig DigestEngine.instance(*args, &block) when Ccrypto::X509::CertProfile X509Engine.new(*args,&block) when Ccrypto::X509::CSRProfile X509CSREngine.new(*args,&block) when Ccrypto::ScryptConfig ScryptEngine.new(*args,&block) when Ccrypto::HKDFConfig HKDFEngine.new(*args,&block) when Ccrypto::PBKDF2Config PBKDF2Engine.new(*args,&block) when Ccrypto::CipherConfig CipherEngine.new(*args, &block) when Ccrypto::HMACConfig HMACEngine.new(*args, &block) when Ccrypto::Argon2Config Argon2Engine.new(*args, &block) when Ccrypto::BCryptConfig BCryptEngine.new(*args, &block) when Ccrypto::SecretSharingConfig SecretSharingEngine.new(*args,&block) when Ccrypto::PKCS7Config PKCS7Engine.new(*args, &block) when Ccrypto::ED25519Config ED25519Engine.new(*args, &block) when Ccrypto::X25519Config X25519Engine.new(*args, &block) when Ccrypto::CrystalKyberConfig CrystalKyberEngine.new(*args, &block) when Ccrypto::CrystalDilithiumConfig CrystalDilithiumEngine.new(*args, &block) else raise CcryptoProviderException, "Config instance '#{config}' is not supported for provider '#{self.provider_name}'" end end end def self.asn1_engine(*args, &block) ASN1Engine end def self.util_instance(*args, &block) algo = args.first case algo when :comparator, :compare, :data_comparator ComparatorUtil when :data_conversion, :converter, :data_converter, :data_conv DataConversionEngine when :memory_buffer, :membuf, :buffer, :mem ManagedMemoryBuffer when :compression, :compressor Compression.new(*(args[1..-1]), &block) when :decompression Decompression.new(*(args[1..-1]), &block) when :native_helper NativeHelper else raise CcryptoProviderException, "Util #{algo} is not supported for provider #{self.provider_name}" end end end end end